n5ro / aframe-physics-system

Physics system for A-Frame VR, built on CANNON.js.
https://n5ro.github.io/aframe-physics-system/
MIT License
505 stars 136 forks source link

AMMO DRIVER Problem with event body-loaded in Chrome #200

Open martaquintana opened 2 years ago

martaquintana commented 2 years ago

Hello!!

in our application we are trying to change Aframe with cannon to aframe with ammo.

We get load the model well by this way:

First loading the model then the ammo-body. When the model is loaded, the event loads ammo-shape (the collison mesh) and then when the body is loaded we set the restitution.

    const gltfmodel = document.getElementById(this.data.id)
    gltfmodel.setAttribute('gltf-model', this.data.model)
    gltfmodel.setAttribute('shadow', {receive: false})

    // Specify what type of ammo-body (dynamic, static, kinematic)
    gltfmodel.setAttribute('ammo-body', {type: this.data.body})

    // Waiting for model to load before adding ammo-shape (box, cylinder, sphere, capsule, cone, hull)
    gltfmodel.addEventListener('model-loaded', () => {
          gltfmodel.setAttribute('ammo-shape', {type: this.data.shape,
                                              fit: this.data.fit,
                                              halfExtents: this.data.halfExtents,
                                              offset: this.data.offset})
    });

    gltfmodel.addEventListener('body-loaded', () => {

          try {
            var sceneEl = document.querySelector('a-scene');
            //Set robot restitution
            sceneEl.querySelector("#"+toString(this.data.id)).body.setRestitution(this.data.restitution);
            //Set a-plane restitution
            sceneEl.querySelector("#a-plane").body.setRestitution(0.8);
          } catch (e) {}
          }

    })

It works really well in Firefox but the body-loaded event doesn't work quite right for Chrome. This event 'body-loaded' is not picked up properly in chrome, do you have any idea what could be happening?

icurtis1 commented 2 years ago

I ran into this with glTF models. I had to make a custom component to add a body to a glTF model correctly. Check out my reply in the below issue

https://github.com/n5ro/aframe-physics-system/issues/192