Arktius Posted March 31, 2016 Share Posted March 31, 2016 Hey guys, I want to edit the loading Object in the following code. I want to rotate it or to set the vertices and normals. I tried it with "this" . BABYLON.SceneLoader.Load(document.getElementById("path").value, document.getElementById("name").value, engine, function (scene) { // Ground var ground = BABYLON.Mesh.CreateGround("ground", 15,15, 1, scene, false); var groundMaterial = new BABYLON.StandardMaterial("ground", scene); groundMaterial.specularColor = BABYLON.Color3.Black(); ground.material = groundMaterial; //ground.rotation.x += Math.PI/2 ; //ground.rotation.y += Math.PI/2 ; // Light var light1 = new BABYLON.HemisphericLight("light1", new BABYLON.Vector3(, 1, ), scene); //newScene light1.intensity = 0.4 ; var cam = new BABYLON.VirtualJoysticksCamera("VJC",new BABYLON.Vector3(, 4, -10) , scene); //Attach a camera to the scene and the canvas scene.activeCamera = cam; cam.attachControl(canvas, false); //this.rotation.y -= 35;<---- ? // Render engine.runRenderLoop(function () { scene.render(); }); // Resize window.addEventListener("resize", function () { engine.resize(); }); }); // Babylon loader Quote Link to comment Share on other sites More sharing options...
Wingnut Posted March 31, 2016 Share Posted March 31, 2016 Hi Arktius! I am not very experienced with sceneLoader, but "exposing" the model (so it can be rotated, and vertices adjusted)... is not always easy. Many users have problems getting a "reference" to a model, after it's loaded. SOME of the problem... is with waiting for the model to complete it's loading. Some of the problem is escaping from the load's callback function. Perhaps, this playground will help: http://www.babylonjs-playground.com/#1GEYSB#2 I wish I was smarter in this subject. But I don't even know when to use .ImportMesh(), or when to use .Load(), or when to use Append(). I have yet to see a clear explanation of it all, too. Every time I load a mesh, the mesh seems "trapped" inside the callback function. In the above demo, I used a scene.executeWhenReady()... to ensure everything was done. Maybe it is necessary, maybe not. Perhaps someday, the puzzling world of sceneLoader... will become less puzzling. I hope this helps. Let's hope smarter people than I... will also comment. Be well. webGLmmk 1 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted April 1, 2016 Share Posted April 1, 2016 Hello and welcome! the Load function callback give you the loaded scene. You can just use scene.getMeshByName for instance to find the mesh you want to control Quote Link to comment Share on other sites More sharing options...
Arktius Posted April 1, 2016 Author Share Posted April 1, 2016 var model = BABYLON.SceneLoader.Load(document.getElementById("pfad").value, document.getElementById("name").value, engine, function (scene) { scene.executeWhenReady(function () { scene.getMeshByName(document.getElementById("name").value).position.y = 8; scene.registerBeforeRender(function () { //Code... }); }); // Render engine.runRenderLoop(function () { scene.render(); }); // Resize window.addEventListener("resize", function () { engine.resize(); }); }); // Babylon loader I get the message,that getMeshByName(...) ISNULL. Same error with .getMeshByID(0) ,(1) or if I move the Code after the SceneLoader. :-/ Quote Link to comment Share on other sites More sharing options...
webGLmmk Posted April 2, 2016 Share Posted April 2, 2016 9 hours ago, Deltakosh said: Hello and welcome! the Load function callback give you the loaded scene. You can just use scene.getMeshByName for instance to find the mesh you want to control @Arktius Not trying to hijack your thread, but I was just about to ask about this. More or less, except at the basic, "how do i alter a mesh inside an imported scene". @Deltakosh I know that SceneLoader.Append is preferred over Load. http://www.babylonjs-playground.com/#F8ZO#10 What I was going to ask is, Is the onSuccess callback the only way to manipulate meshes in an imported scene? Along with Arktius' question, I'm also not able to access the mesh with getMeshById. though I tried it on Append and ImportMesh, not sure if it applies to those anyway. Responses to @Arktius will hopefully answer my questions. In the playground scene above, Load won't even work with my github url & file, though Append and Import Mesh both work. My goal is to use it for a visualization, but was just going to make sure i could do something with it first, like: var speaker1 = mesh.getMeshById("Torus.002"); speaker1.position.y = 100; or however, within the callback. Quote Link to comment Share on other sites More sharing options...
Arktius Posted April 2, 2016 Author Share Posted April 2, 2016 Try this: //shows scene BABYLON.SceneLoader.ImportMesh("", "https://raw.githubusercontent.com/gson78/miscWebGLpages/gh-pages/blender-scenes/", "custom-speakers2.babylon", scene); BABYLON.MeshBuilder.CreateTorus("torus", {thickness: 0.2}, scene); var speaker1 = scene.getMeshByName("torus"); speaker1.position.y = 4; speaker1.position.x = 1; webGLmmk 1 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted April 2, 2016 Share Posted April 2, 2016 what I mentioned should work. So there is something wrong elsewhere can you reproduce the bug on the playground? Alternatively you can also enable the debuglayer to see the names of loaded meshes: scene.debugLayer.show() Quote Link to comment Share on other sites More sharing options...
Arktius Posted April 3, 2016 Author Share Posted April 3, 2016 I used the wrong Meshname . Thanks for advise. But how can I find the Meshnames from a file / are loaded in scene in code? I don't want to add every single Meshname from every file I want to import. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted April 3, 2016 Share Posted April 3, 2016 once loaded, you can go through all meshes with scene.meshes. It's an array of meshes webGLmmk 1 Quote Link to comment Share on other sites More sharing options...
webGLmmk Posted April 3, 2016 Share Posted April 3, 2016 5 hours ago, Deltakosh said: once loaded, you can go through all meshes with scene.meshes. It's an array of meshes I understand. meshes gets passed into the onsuccess callback, array can be accessed within that scope. Success! at least at square one. http://www.babylonjs-playground.com/#F8ZO#12 GameMonetize and Wingnut 2 Quote Link to comment Share on other sites More sharing options...
Arktius Posted April 4, 2016 Author Share Posted April 4, 2016 console.log(scene.meshes); var i = ; while (scene.meshes[i] != null) { console.log("Mesh[" + i.toString() + "]" + scene.meshes[i].name); //alert(scene.meshes[i].name); Messagebox i++; } This shows all the names of meshes. I don't know if a counter exists. The Output is in the console from Browser. (press F12 and look in console) webGLmmk 1 Quote Link to comment Share on other sites More sharing options...
webGLmmk Posted April 4, 2016 Share Posted April 4, 2016 9 hours ago, Arktius said: console.log(scene.meshes); var i = ; while (scene.meshes[i] != null) { console.log("Mesh[" + i.toString() + "]" + scene.meshes[i].name); //alert(scene.meshes[i].name); Messagebox i++; } This shows all the names of meshes. I don't know if a counter exists. The Output is in the console from Browser. (press F12 and look in console) contemplated doing something like that and then just did scene.debugLayer.show() from david's post above. LOVE IT its so great. You just select "meshes tree" and it shows a box with all the mesh names. i may need the console trick someday when i'm not using babylon Quote Link to comment Share on other sites More sharing options...
Arktius Posted April 4, 2016 Author Share Posted April 4, 2016 If you want to alter all meshes from any file, you will use it. =) Edit: The important code was the loop, not console.log() webGLmmk and GameMonetize 2 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.