Dear All,
Below is the code listing to try out the dynamic texture on imported mesh, but kind of fail on the "targetMesh".
It only works when I'm using Plane mesh "newPlane" produced from the code using BABYLON.Mesh.CreatePlane.
Am I missing something here?
BABYLON.SceneLoader.Load("", "plane.babylon", engine, function (newScene) { newScene.executeWhenReady(function () { var canvas = engine.getRenderingCanvas(); //newScene.activeCamera.attachControl(canvas); // This creates and positions a free camera (non-mesh) var camera = new BABYLON.FreeCamera("camera1", new BABYLON.Vector3(0, 5, -125), newScene); camera.setTarget(BABYLON.Vector3.Zero()); camera.attachControl(canvas, true); newScene.activeCamera = camera; //now here I want to select some meshes from the active scene var targetMesh = newScene.getMeshByName('plane'); if(targetMesh) { // debugger; // Create new standard material var stdMat = new BABYLON.StandardMaterial('Material', newScene); stdMat.alpha = 1; stdMat.backFaceCulling = true; stdMat.specularPower = 64; stdMat.useSpecularOverAlpha = true; stdMat.useAlphaFromDiffuseTexture = false; // emissive definitions; stdMat.emissiveColor = new BABYLON.Color3(0.00, 0.00, 0.00); // ambient definitions; stdMat.ambientColor = new BABYLON.Color3(0.00, 0.00, 0.00); // specular definitions; stdMat.specularColor = new BABYLON.Color3(1.00, 1.00, 1.00); var dynTexture = new BABYLON.DynamicTexture("Dynamic texture", 1024, newScene, true); dynTexture.uScale = 1; dynTexture.vScale = 1; dynTexture.coordinatesMode = 0; dynTexture.uOffset = 0; dynTexture.vOffset = 0; dynTexture.uAng = 0; dynTexture.vAng = 0; dynTexture.level = 1; dynTexture.coordinatesIndex = 0; dynTexture.hasAlpha = false; dynTexture.getAlphaFromRGB = false; // set stdMat diffuse texture stdMat.diffuseTexture = dynTexture; // draw text dynTexture.drawText("Eternalcoding", null, 100, "70px Segoe UI", "red", "#555555"); // set sub mesh material targetMesh.material = stdMat; // calculate mesh size var vectorsWorld = targetMesh.getBoundingInfo().boundingBox.vectorsWorld; var size = vectorsWorld[1].subtract(vectorsWorld[0]).length(); // distance between summit 0 and summit 1 // New Plane var newPlane = BABYLON.Mesh.CreatePlane("New Plane", size, newScene, false); newPlane.scale = 0.5; newPlane.position.z = targetMesh.position.z; newPlane.position.y = targetMesh.position.y; newPlane.position.x = targetMesh.position.x+(size/2); // newPlane.parent = targetMesh; // set sub mesh material newPlane.material = stdMat; stdMat.diffuseTexture.update(); } engine.runRenderLoop(function() { newScene.render(); }); }); });
Here is the "plane.babylon"
{"autoClear":true,"clearColor":[0.0,0.0,0.0],"ambientColor":[0.0,0.0,0.0],"fogMode":0,"fogColor":null,"fogStart":0.0,"fogEnd":0.0,"fogDensity":0.0,"gravity":[0.0,0.0,0.0],"cameras":[{"name":"Camera001","id":"a713edbb-dbb0-4077-a018-06a07e8fb30c","parentId":null,"lockedTargetId":"5523fadc-396d-4b51-b859-4b9df68f56dd","type":"FreeCamera","position":[-202.8126,116.4834,-271.5265],"rotation":[0.0,0.0,0.0],"target":null,"fov":0.6024,"minZ":0.1,"maxZ":10000.0,"speed":1.0,"inertia":0.9,"checkCollisions":false,"applyGravity":false,"ellipsoid":[0.0,0.0,0.0],"autoAnimate":false,"autoAnimateFrom":0,"autoAnimateTo":0,"autoAnimateLoop":false,"animations":[]}],"activeCameraID":"a713edbb-dbb0-4077-a018-06a07e8fb30c","lights":[{"name":"Default light","id":"2baddbc0-0c64-46ee-89ac-aa01cd23c503","parentId":null,"position":null,"direction":[0.0,1.0,0.0],"type":3,"diffuse":[1.0,1.0,1.0],"specular":[1.0,1.0,1.0],"intensity":1.0,"range":3.40282347E+38,"exponent":0.0,"angle":0.0,"groundColor":[0.0,0.0,0.0],"excludedMeshesIds":null,"includedOnlyMeshesIds":null,"autoAnimate":false,"autoAnimateFrom":0,"autoAnimateTo":0,"autoAnimateLoop":false,"animations":null}],"meshes":[{"id":"a2652875-3a25-4d9c-97ab-1d7d038c5f8e","parentId":null,"materialId":null,"isEnabled":true,"isVisible":true,"pickable":false,"pivotMatrix":null,"positions":[-56.0677,0.0,-45.6579,56.0677,0.0,-45.6579,56.0677,0.0,45.6579,56.0677,0.0,45.6579,-56.0677,0.0,45.6579,-56.0677,0.0,-45.6579],"normals":[0.0,1.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0],"uvs":[0.0,1.0,1.0,1.0,1.0,2.0,1.0,2.0,0.0,2.0,0.0,1.0],"uvs2":null,"colors":null,"hasVertexAlpha":false,"matricesIndices":null,"matricesWeights":null,"indices":[0,1,2,3,4,5],"checkCollisions":false,"receiveShadows":true,"infiniteDistance":false,"billboardMode":0,"visibility":1.0,"subMeshes":[{"materialIndex":0,"verticesStart":0,"verticesCount":6,"indexStart":0,"indexCount":6}],"instances":[],"skeletonId":-1,"showBoundingBox":false,"showSubMeshesBoundingBox":false,"applyFog":true,"alphaIndex":1000,"physicsImpostor":0,"physicsMass":0.0,"physicsFriction":0.0,"physicsRestitution":0.0,"name":"plane","position":[0.0,0.0,0.0],"rotation":[-1.5708,0.0,0.0],"scaling":[1.0,1.0,1.0],"rotationQuaternion":null,"actions":null,"animations":[],"autoAnimate":true,"autoAnimateFrom":0,"autoAnimateTo":100,"autoAnimateLoop":true},{"id":"5523fadc-396d-4b51-b859-4b9df68f56dd","parentId":null,"materialId":null,"isEnabled":true,"isVisible":true,"pickable":false,"pivotMatrix":null,"positions":null,"normals":null,"uvs":null,"uvs2":null,"colors":null,"hasVertexAlpha":false,"matricesIndices":null,"matricesWeights":null,"indices":null,"checkCollisions":false,"receiveShadows":true,"infiniteDistance":false,"billboardMode":0,"visibility":1.0,"subMeshes":null,"instances":[],"skeletonId":-1,"showBoundingBox":false,"showSubMeshesBoundingBox":false,"applyFog":true,"alphaIndex":1000,"physicsImpostor":0,"physicsMass":0.0,"physicsFriction":0.0,"physicsRestitution":0.0,"name":"Camera001.Target","position":[-3.9516,-2.5059,23.297],"rotation":[-1.2479,0.5934,0.0],"scaling":[1.0,1.0,1.0],"rotationQuaternion":null,"actions":null,"animations":[],"autoAnimate":true,"autoAnimateFrom":0,"autoAnimateTo":100,"autoAnimateLoop":true}],"sounds":[],"materials":[],"multiMaterials":[],"particleSystems":null,"lensFlareSystems":null,"shadowGenerators":[],"skeletons":[],"actions":null}