Boz Posted May 26, 2014 Share Posted May 26, 2014 Hello !I know question has been answered several times, but I still have a problem when I try to apply impostor on loaded meshes. Here is part of my code :// Scenevar scene = new BABYLON.Scene(engine);scene.enablePhysics();scene.setGravity(new BABYLON.Vector3(0, -9.81, 0));// Groundvar ground = BABYLON.Mesh.CreateGround("ground", 1000, 1000, 1, scene, false);var groundMaterial = new BABYLON.StandardMaterial("ground", scene);ground.setPhysicsState({ impostor: BABYLON.PhysicsEngine.BoxImpostor, mass: 0, friction: 0.5, restitution: 0.7 });ground.checkCollisions = true;groundMaterial.diffuseTexture = new BABYLON.Texture("textures/ground.jpg", scene);groundMaterial.diffuseTexture.uScale = 60;groundMaterial.diffuseTexture.vScale = 60;ground.position.y = -2.05;ground.receiveShadows = true;ground.material = groundMaterial;// Spherevar sphere = BABYLON.Mesh.CreateSphere("sphere", 10.0, 3.0, scene);sphere.position = new BABYLON.Vector3(10, 6, 0);sphere.setPhysicsState({ impostor: BABYLON.PhysicsEngine.SphereImpostor, mass: 1 });sphere.checkCollisions = false;// MeshBABYLON.SceneLoader.ImportMesh("him", "models/Dude/", "Dude.babylon", scene, function (newMeshes, particleSystems, skeletons) { player.mesh = newMeshes[0]; player.mesh.scaling = new BABYLON.Vector3(0.05, 0.05, 0.05); player.mesh.rotation.y = Math.PI; player.mesh.position = new BABYLON.Vector3(0, 10, 0); player.mesh.setPhysicsState({ impostor: BABYLON.PhysicsEngine.SphereImpostor, mass: 1 });});My scene has physics enabled and sphere succesfully falls and bounces on the ground.But the mesh falls and goes over the ground. I have tried putting it very high on Y axis, but same result.I also tried with BoxImpostor. I understand the more complex way using a compound impostor but for now I just want a SphereImpostor effect, and it does not even work :/ Thank you in advance for your answers !Cheers Pouet-- Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted May 26, 2014 Share Posted May 26, 2014 Could you create a jsfiddle? Quote Link to comment Share on other sites More sharing options...
Boz Posted May 26, 2014 Author Share Posted May 26, 2014 I tried, but with no good success, I have a CORS error preventing my mesh from loading : http://jsfiddle.net/Pouet/3WBKY Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted May 26, 2014 Share Posted May 26, 2014 In this case you are not using the right mesh (newMeshes[0] for dude is an invisible not renderable object used as parent for body parts):BABYLON.SceneLoader.ImportMesh(null, "/scenes/dude/", "dude.babylon", scene, function (newMeshes, particleSystems, skeletons) { var dude = newMeshes[1]; //dude.scaling = new BABYLON.Vector3(0.05, 0.05, 0.05); dude.position = new BABYLON.Vector3(0, 20, 0); dude.setPhysicsState({ impostor: BABYLON.PhysicsEngine.SphereImpostor, mass: 1 }); }); Quote Link to comment Share on other sites More sharing options...
Boz Posted May 27, 2014 Author Share Posted May 27, 2014 Hm, I tried several cases.newMeshes[0] makes an entire mesh appearing, but not sensible to physics, indeed.I tried with assigning to dude newMeshes[1] to newMeshes[5], physics works, but there are only parts of the model (1 = head, 2 = top body, 3 = legs..) Is there a way to get all theses parts in one go ? Quote Link to comment Share on other sites More sharing options...
Boz Posted May 27, 2014 Author Share Posted May 27, 2014 And when I use these parts of my mesh, a big mesh (the entire and unscaled newMeshes[0]) appears in addition of the body part. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted May 28, 2014 Share Posted May 28, 2014 You have to create a compound object like in this demo:https://github.com/BabylonJS/Samples/blob/master/Scenes/Customs/physics.js The compound object will then include all parts of Dude Quote Link to comment Share on other sites More sharing options...
dnlek Posted June 29, 2016 Share Posted June 29, 2016 Hi - I have similar question. I was trying to put 'dude' inside sphere impostor and found this post. How should I create this compound object? Is there a way to sum all meshes into empty mesh? Or do I need to calculate position of each mesh in the parent mesh and put all elements into invisible sphere.. So far I've tried to: 1. assign meshes 1 - end to mesh number 0 - didn't work 2. tried BABYLON.Mesh.createInstance('player') and assign all meshes to this mesh - didn't work 3. created box and assigned all meshes to this box - however sphere impostor doesn't make any sense in this case 4. created sphere and assigned all meshes to this sphere - however dude is behaving as sphere now - not as dude Any suggestions? EDIT - I managed to make it work this way: const ground = BABYLON.Mesh.CreateGroundFromHeightMap('ground', '../assets/heightMap.png', 1000, 1000, 100, 0, 10, scene, false, () => { ground.setPhysicsState(BABYLON.PhysicsEngine.HeightmapImpostor, { mass: 0 }); BABYLON.SceneLoader.ImportMesh('him', '../assets/Dude/', 'dude.babylon', scene, function (newMeshes, particleSystems, skeletons) { player = newMeshes[0]; player.physicsImpostor = new BABYLON.PhysicsImpostor(player, BABYLON.PhysicsEngine.SphereImpostor, { mass: 100, friction: 0.5, restitution: 1 }, scene); for (var i = 1, len = newMeshes.length; i < len; i++) { newMeshes[i].parent = player; newMeshes[i].physicsImpostor = new BABYLON.PhysicsImpostor(newMeshes[i], BABYLON.PhysicsEngine.SphereImpostor, { mass: 10, friction: 0.5, restitution: 1 }, scene); newMeshes[i].showBoundingBox = true; } player.showBoundingBox = true; player.position = new BABYLON.Vector3(0, 40, 0); player.physicsImpostor.forceUpdate(); scene.beginAnimation(skeletons[0], 0, 120, 1.0, true); }); }); However now it behaves funny sometimes and what is worse - dude falls on his face Quote Link to comment Share on other sites More sharing options...
Boz Posted June 30, 2016 Author Share Posted June 30, 2016 As I suggested to you in the chat, try to use moveWithCollisions to move your character along the heightmap The heightmap needs an heightmap impostor but your character does not need any impostor if you use this function Quote Link to comment Share on other sites More sharing options...
dnlek Posted June 30, 2016 Share Posted June 30, 2016 Thanks Pouet! moveWithCollisions worked great. This post was under review all this time - this is why it was posted after our chat discussion. 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.