rayfly0225 Posted January 26, 2016 Share Posted January 26, 2016 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 : Quote BABYLON.SceneLoader.ImportMesh("", "Assets/dealer/", "group.babylon", scene, function (newMeshes) { var head = newMeshes[2]; var body= newMeshes[3]; Q1: 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]; Q2: 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. Quote var man = newMeshes; Q3: When i use the "Loading Scene" exported form 3DsMax 2016 like this: Quote BABYLON.SceneLoader.Load("Assets/dealer/", "scene.babylon", engine, function (newScene) { scene = newScene; scene.activeCamera.attachControl(canvas); 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. Sincerely, Ray Quote Link to comment Share on other sites More sharing options...
Dad72 Posted January 26, 2016 Share Posted January 26, 2016 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: newScene.meshes.forEach(function(mesh) { console.log(mesh); }); You can add a light, and what you want in SceneLoader.Load Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted January 26, 2016 Share Posted January 26, 2016 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. Quote Link to comment Share on other sites More sharing options...
rayfly0225 Posted January 27, 2016 Author Share Posted January 27, 2016 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? newScene.meshes.forEach(function(mesh) { console.log(mesh); }); this is my code: //ImportMesh 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; //shadow var shadowGenerator = new BABYLON.ShadowGenerator(2048, light_dir); shadowGenerator.getShadowMap().renderList.push(body,hair); shadowGenerator.usePoissonSampling = true; plane.receiveShadows = true; }); Here are some comparisons in my screenshot: Thanks for your attention. Sincerely, Ray Here are some comparisons in my screenshot: pic1 pic2 pic3 pic4 Quote Link to comment Share on other sites More sharing options...
Dad72 Posted January 27, 2016 Share Posted January 27, 2016 For the shadows you have to add all sub-mesh with a for loop: for(var i = 0, cache = newMeshes.length; i < cache ; i++) { shadowGenerator.getShadowMap().renderList.push(newMeshes); } 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" Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted January 27, 2016 Share Posted January 27, 2016 Actually newMeshes[..] contains meshes and not submeshes. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted January 27, 2016 Share Posted January 27, 2016 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 Q5.Same Quote Link to comment Share on other sites More sharing options...
Dad72 Posted January 27, 2016 Share Posted January 27, 2016 Oops, yes, I thought it was sub-mesh. sorry for the wrong information. Quote Link to comment Share on other sites More sharing options...
rayfly0225 Posted January 28, 2016 Author Share Posted January 28, 2016 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!! Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted January 28, 2016 Share Posted January 28, 2016 Look here: http://www.babylonjs-playground.com/?16 Replace the skull with an url to your assets (like http://....) 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.