How to use "Model" and physics impostor in react-babylon?

Hey there,

I’m pretty new to babylonjs and as I’m a react user, I came across react-babylon. I just play around a bit and have a problem now, using some simple blender model (exported as .glb) and adding a physics impostor to it. I saw that there were various ways on how to import a model with react-babylon, so I tried them and got it working to import and display the model. I’m just a bit lost on how to add a physics impostor (probably MeshImpostor?) to that loaded model.
With the standard objects (sphere, box etc.) it did already work, so maybe someone can point me in the right direction?

A sandbox link (to the not yet working project!)

Actually the dropping ball should just interact with the bottle :slight_smile:

Pinging our React Master @brianzinn

hi @faenor sorry for late reply and also that nobody was able to help you. I don’t have much computer access until next month.

I unset the parent and it worked. There was this error in the console:

A physics impostor has been created for an object which has a parent. Babylon physics currently works in local space so unexpected issues may occur. 

You can fix it by clearing the parent:

<Model
  name="bottle"
  rootUrl="/"
  sceneFilename="bottle.glb"
  onModelLoaded={(loadedModel) => {
    const bottle = loadedModel.meshes.find((m) => m.name === "Bottle");
    bottle.parent = null; // comment this line and it doesn't work!
    bottle.physicsImpostor = new PhysicsImpostor(
      bottle,
      PhysicsImpostor.CylinderImpostor,
      { mass: 1 }
    );
    ...
  }}
/>

If you have non-React specific questions best to not include “React” in the question they have a much higher chance to get a response. I would maybe not use the “Model” component, because then you can go with JSX using fromInstance. You can look at the “Model” component in source:
react-babylonjs/Model.tsx at master · brianzinn/react-babylonjs (github.com)

From there you can get a lot of fine-grained control if the models are well known at least.

Thank you so much! I am not entitled to your time, so no worries :slight_smile:

I didn’t have a look on the Model component before (which I probably should have -.-).
At first I tried only to use the useSceneLoader hook as the “Model” component does, just couldn’t figure out I had to use “abstractMesh” and the “fromInstance” prop, but it was close to what is really needed :sweat_smile:
I read in the github issues somewhere about “Model” and it was quite new, so thought maybe that would be the way to go :slight_smile:
Also because the default primitives did work, I assumed I did something wrong with the react component (hence the react tag).

Before posting another question, I will read the docs more thoroughly :slight_smile:

hi @faenor - I fell off the face of the planet there for a couple of weeks. it’s really ok to just ask questions - the documentation is pretty much non-existent, so it’s pretty much expected and I’m really happy to help wherever I can. If you wanted to try with default primitives that would be a good way to go especially when you want the reconciler to push props to your mesh/materials/textures (this is how you can assign to position, rotation, textures, etc. from props). There is a meshmap you can use for “fromInstance” that is helpful as well.