Jump to content

I'm a beginner of webgl and I have a problem of the method of (scene)


sgila
 Share

Recommended Posts

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?

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...