Jump to content

Question about mesh impostor


Boz
 Share

Recommended Posts

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--

Link to comment
Share on other sites

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 });            });
Link to comment
Share on other sites

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 ?

Link to comment
Share on other sites

  • 2 years later...

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 ;)

Link to comment
Share on other sites

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

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...