Jump to content

Some Question about Loading Assets


Recommended Posts

Hi All:

I'm a game artist from Taiwan.And study coding 2 months.

I reference the part  "Loading Assets" of the official documentation.Here is my confusion :


BABYLON.SceneLoader.ImportMesh("", "Assets/dealer/", "group.babylon", scene, function (newMeshes) {

var head = newMeshes[2];

var body= newMeshes[3];


I type this code ,but didn't know what does "newMeshes" mean ?

The object which i use  has two part,one is "hair",the other is "body" .

When I type like this" var head = newMeshes[2]; ",the hair is displayed correctly.

Did  it mean that  The numbers in  brackets  are   the  ordinal numbers  of this object?

For example:

one object has two meshes that are "A" and "B",

So could i define the code :

var A = newMeshes[0];

var B = newMeshes[1];



I can use the "hair" and "body" because "var head" and "var body"   in the code.

But how could i var the  whole object in code?

I type like this but it doesn't work correctly.



var man = newMeshes;



When i use the "Loading Scene" exported form 3DsMax 2016  like this:


BABYLON.SceneLoader.Load("Assets/dealer/", "scene.babylon", engine, function (newScene) {

         scene = newScene;


How could i var the objects which is already existed  in this scene in script?

Could i add one directional light with shadow in this scene in script,and how to code?


Thanks for your attention.





Link to comment
Share on other sites

Q1: newMeshes that contains the data of the file you load. newMeshes[0]  Allows you to get all the mesh with the sub-meshs. newMeshes[1] Is a sub-mesh. 

Q2: If your models are elements separate, use SceneLoader.Load (). But for a character mesh, you should create only a single object and not several.

Q3: To have access to all element of your scene you can do:


You can add a light, and what you want in SceneLoader.Load


Link to comment
Share on other sites

Q1. perhaps the best option for you is to search by name like head = newScene.getMeshByName("head")

Q2: In 3dsmax, just add a parent object on top of all other objects and name it like "body". Then you can reach it with var body = newScene.getMeshByName("body"). Other objects will be children of body: body.children is then an array of your meshes

Q3. same here. You can reach any object by name or through a forEach like Dad72 mentioned. Lights with shadows can be added by code or in 3dsmax.

Link to comment
Share on other sites

Dad72 and Deltakosh:

Thanks for your support,but it still has some questions i want to ask.

Q1.newMeshes[0]  Allows us to get all the mesh with the sub-meshs. so is it  just like parent  in newMeshes?

Q2.If newMeshes[0] get all the mesh with the sub-meshs,why couldn't i use it in the renderlist of reflection and shadows?

Q3. Does The renderlist need to list all meshes i want to render? Does it can not be replaced by a parent mesh?    

Q4.How could i modify my code  with variables :"girl","hair","body",and it could also has the reflection and shadows(just like pic1,this effect is that I want to show)?

Q5.Where shoud it be inserted to the code ,and where could i see the log print?


this is my code:

         BABYLON.SceneLoader.ImportMesh("", "Assets/dealer/", "group.babylon", scene, function (newMeshes) {
             var girl = newMeshes[0];
             var hair = newMeshes[2];
             var body= newMeshes[3];
             //girl.position.y = -200;

             var mat = new BABYLON.StandardMaterial("mat", scene);
             mat.diffuseTexture = new BABYLON.Texture("Assets/dealer/ssw_v01_c_character_FaceLow_col.png", scene);
             mat.bumpTexture = new BABYLON.Texture("Assets/dealer/ssw_v01_c_character_FaceLow_nor.png", scene);
             mat.specularColor = BABYLON.Color3.Black();
             mat.diffuseTexture.hasAlpha = true;
             mat.backFaceCulling = false;
             hair.material = mat;

             var mat2 = new BABYLON.StandardMaterial("mat2", scene);
             mat2.diffuseTexture = new BABYLON.Texture("Assets/dealer/ssw_v01_c_character_bodylow_col.png", scene);
             mat2.bumpTexture = new BABYLON.Texture("Assets/dealer/ssw_v01_c_character_bodylow_nor.png", scene);
             mat2.specularColor = BABYLON.Color3.Black();
             mat2.diffuseTexture.hasAlpha = true;
             mat2.backFaceCulling = false;
             body.material = mat2;

             // Mirror
             var plane = BABYLON.Mesh.CreatePlane("plan", 7000, scene);
             plane.position.y = -107;
             plane.rotation = new BABYLON.Vector3(Math.PI / 2, 0, 0);

             //Creation of a mirror material
             var mirrorMaterial = new BABYLON.StandardMaterial("Assets/dealer/ssw_v01_c_character_FaceLow_col.png", scene);
             mirrorMaterial.diffuseColor = new BABYLON.Color3(0.2, 0.2, 0.2);
             mirrorMaterial.reflectionTexture = new BABYLON.MirrorTexture("mirror", 2048, scene, true); 
             mirrorMaterial.reflectionTexture.mirrorPlane = new BABYLON.Plane(0, -1.0, 0, -107.0);
             mirrorMaterial.reflectionTexture.renderList = [body, hair, skybox];
             mirrorMaterial.reflectionTexture.level = 0.6;
             plane.material = mirrorMaterial;

             var shadowGenerator = new BABYLON.ShadowGenerator(2048, light_dir);
             shadowGenerator.usePoissonSampling = true;

             plane.receiveShadows = true;

Here are some comparisons in my screenshot: 


Thanks for your attention.




Here are some comparisons in my screenshot: 












Link to comment
Share on other sites

For the shadows you have to add all sub-mesh with a for loop:

for(var i = 0, cache = newMeshes.length; i < cache ; i++)

To see the results of console.log () click F12 on your keyboard

I think you will better understand what is happening by observing the result in the console of "newMeshes"


Link to comment
Share on other sites

Q1. newMeshes[0]  Allows you to get all the first mesh

Q2.Because this statement is false. It give you the first mesh only. it could be the parent of others meshes (depending on your scene)

Q3. Yep you have to give all the meshes you want because you may want to cast shadows on some part of your hierarchy but not all

Q4.I won't do your homework :) please provide at least a playground so we can work together on it


Link to comment
Share on other sites

14 hours ago, Deltakosh said:

Q4.I won't do your homework :) please provide at least a playground so we can work together on it

I want to share my resources to playground,but i don't know how to upload mine to playground or using it. I'm rookie to code.

After reading the documentation of playground and google it ,I still  didn't find something about how to use with my assets on it.

thanks for your help!!

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.

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.


  • Recently Browsing   0 members

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