sgila Posted April 13, 2016 Share Posted April 13, 2016 I'm a beginning learner of webgl. and renctly there is some problems I can't understand. I created the createScene() function and imported some meshes from one .babylon file. When I want to change some materials' diffuse color or some mesh's position and so on, I try the getMaterialByName() or getMeshByName(), the codes just like mat = scene.getMaterialByName(''abc''); but it does not work, my browser display nothing. If I delete the code above, it turns OK. Anyone could tell me why? Quote Link to comment Share on other sites More sharing options...
zied sellami Posted April 13, 2016 Share Posted April 13, 2016 Can you show us in the the babylonjs-playground http://www.babylonjs-playground.com/ Quote Link to comment Share on other sites More sharing options...
aWeirdo Posted April 13, 2016 Share Posted April 13, 2016 Hi, to change materials, positions, etc, all you have to do is apply it. (Note, if you are changing it Outside(after) the scene loader function, you must define the variable Before loading the mesh, it is good practice to always do that.) var mesh; //loader function mesh = //your loaded mesh; //loader end //Apply new material mesh.material = //your predefined material; //Move mesh every 500ms by 0.5 units on the x axis. setInterval( function() { mesh.position.x += 0.5; }, 500); //Settting a static position, at 2 x, 1 y, 3 z, as an example. mesh.position = new BABYLON.Vector3(2, 1, 3); You can also set it inside the loader function, var mesh; //loader function mesh = //your loaded mesh; mesh.position = new BABYLON.Vector3(2, 1, 3); //loader end sgila 1 Quote Link to comment Share on other sites More sharing options...
sgila Posted April 13, 2016 Author Share Posted April 13, 2016 5 hours ago, aWeirdo said: Hi, to change materials, positions, etc, all you have to do is apply it. (Note, if you are changing it Outside(after) the scene loader function, you must define the variable Before loading the mesh, it is good practice to always do that.) var mesh; //loader function mesh = //your loaded mesh; //loader end //Apply new material mesh.material = //your predefined material; //Move mesh every 500ms by 0.5 units on the x axis. setInterval( function() { mesh.position.x += 0.5; }, 500); //Settting a static position, at 2 x, 1 y, 3 z, as an example. mesh.position = new BABYLON.Vector3(2, 1, 3); You can also set it inside the loader function, var mesh; //loader function mesh = //your loaded mesh; mesh.position = new BABYLON.Vector3(2, 1, 3); //loader end Great thanks for your careful answers. I will try it later today Quote Link to comment Share on other sites More sharing options...
sgila Posted April 14, 2016 Author Share Posted April 14, 2016 @zied sellami @aWeirdo Here is the playground link: http://www.babylonjs-playground.com/#N1ZN2#0 The line11 and 12 go work only when they are in the callback function of BABYLON.SceneLoader.Load I tried to take them to line20 or line28, it goes wrong Else, I found line4 is not nessesary Quote Link to comment Share on other sites More sharing options...
adam Posted April 14, 2016 Share Posted April 14, 2016 myScene.babylon needs to be hosted on a server. Since you are using the playground, it is looking for the file at http://www.babylonjs-playground.com/assets/myScene.babylon. You might be interested in this: Quote Link to comment Share on other sites More sharing options...
webGLmmk Posted April 15, 2016 Share Posted April 15, 2016 On 4/14/2016 at 2:07 AM, sgila said: @zied sellami @aWeirdo Here is the playground link: http://www.babylonjs-playground.com/#N1ZN2#0 The line11 and 12 go work only when they are in the callback function of BABYLON.SceneLoader.Load I tried to take them to line20 or line28, it goes wrong Else, I found line4 is not nessesary Do you use github? If so you can just go to the file on github, click the "raw" button, then copy that URL into the Load function I highly recommend github. Even if you dont use git, you can upload. I'm hosting all my webGL pages there. The best way for people to help here is get your scene working in the playground first-there are lot of posts here, and its the quickest way for members to look at whats going on. 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.