Created
May 31, 2024 05:38
-
-
Save neeraj-tangariya/eefc8cb912af9025affa34a6e865cbe2 to your computer and use it in GitHub Desktop.
create 3d text in babylonjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var yellowText; | |
var purpleText; | |
var redText; | |
var blackText; | |
function create3DTextTitle(scene, camera, name = null) { | |
yellowText = scene.getMeshByName("Text_Yellow"); | |
purpleText = scene.getMeshByName("Text_Blue"); // Adjusted name from "Text_Blue" | |
redText = scene.getMeshByName("Text_Red"); | |
blackText = scene.getMeshByName("Text_Black"); | |
const rotation = new BABYLON.Vector3( | |
BABYLON.Tools.ToRadians(78.6499), | |
BABYLON.Tools.ToRadians(0.0), | |
BABYLON.Tools.ToRadians(2.7382) | |
); | |
const scaling = new BABYLON.Vector3(6, 6, 6); | |
const position = new BABYLON.Vector3(43.159, 14.063, 65.010); | |
// Set visibility based on the provided name | |
switch (name) { | |
case "yellow": | |
if (yellowText) { | |
yellowText.parent = camera; | |
yellowText.rotation = rotation; | |
yellowText.scaling = scaling; | |
yellowText.position = position; | |
yellowText.isVisible = true; | |
} | |
break; | |
case "purple": | |
if (purpleText) { | |
purpleText.parent = camera; | |
purpleText.rotation = rotation; | |
purpleText.scaling = scaling; | |
purpleText.position = position; | |
purpleText.isVisible = true; | |
} | |
break; | |
case "red": | |
if (redText) { | |
redText.parent = camera; | |
redText.rotation = rotation; | |
redText.scaling = scaling; | |
redText.position = position; | |
redText.isVisible = true; | |
} | |
break; | |
case "black": | |
if (blackText) { | |
blackText.parent = camera; | |
blackText.rotation = rotation; | |
blackText.scaling = scaling; | |
blackText.position = position; | |
blackText.isVisible = true; | |
} | |
break; | |
default: | |
yellowText.isVisible = false; | |
purpleText.isVisible = false; | |
redText.isVisible = false; | |
blackText.isVisible = false; | |
break; | |
} | |
// Hide other text meshes | |
if (yellowText && name !== "yellow") yellowText.isVisible = false; | |
if (purpleText && name !== "purple") purpleText.isVisible = false; | |
if (redText && name !== "red") redText.isVisible = false; | |
if (blackText && name !== "black") blackText.isVisible = false; | |
} | |
create3DTextTitle(scene,camera) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment