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

gltf model model does not get parsed #196

Open wilsonXo opened 2 years ago

wilsonXo commented 2 years ago

I hava a gltf model,but wireframe generated incorrect. image

Tried another sample models,such as box triangle,issues remain. hope someone can help me, thks! The following code shown this issues https://github.com/wilsonXo/aps-demo

ITBoomBKStudio commented 2 years ago

Hello. I hope this will help you:

const gltfPhysicsObjectComponent = {
    schema: {
      model: {default: ''},
      body: {type: 'string', default: 'dynamic'},  // dynamic: A freely-moving object
      shape: {type: 'string', default: 'mesh'},  // hull: Wraps a model in a convex hull, like a shrink-wrap
    },
    init() {
        const gltfmodel = document.createElement('a-entity')
        this.el.appendChild(gltfmodel)

        gltfmodel.object3D.position.set(0, 0.1, 0)
        gltfmodel.setAttribute('gltf-model', this.data.model)

        this.el.addEventListener('model-loaded', () => {
            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.setAttribute('ammo-shape', {type: this.data.shape})
        })
    },
  }

  export {gltfPhysicsObjectComponent}
ITBoomBKStudio commented 2 years ago

Import components file:

import {gltfPhysicsObjectComponent} from './components'

Then register an IFRAME component:

AFRAME.registerComponent('physics-object', gltfPhysicsObjectComponent)

Import 3D-model and create entity:

<a-assets>
     <a-asset-item id="SampleGLTF" src="/models/Sample.gltf"></a-asset-item>
</a-assets>

<a-entityphysics-object="model: #SampleGLTF; body: static; shape: mesh"
 scale="1 1 1" id="Sample" position="0 0 0" ></a-entity>

🌟 Enjoy 🌟

ITBoomBKStudio commented 2 years ago

image

arpu commented 2 years ago

@ITBoomBKStudio cool Model!

ITBoomBKStudio commented 2 years ago

@ITBoomBKStudio cool Model!

Thanks. Maybe you know, how to set collider to camera entity? My code works fine for collisions between dynamic bodies and static body (3D model). But my camera (ammo-body='type:kinematic') passes through the walls:(

arpu commented 2 years ago

hmm sorry i am not familiar with the ammo stack

wilsonXo commented 2 years ago

image

lol..............cool, very thks for ur reply,that's help me a lot.

RepSklvska commented 2 years ago

It works, but worked not correctly for my testing project. The mesh shapes looked very different to my gltf models in debug mode. I have no idea

RepSklvska commented 2 years ago

It works, but worked not correctly for my testing project. The mesh shapes looked very different to my gltf models in debug mode. I have no idea

Using the scripts provided by @ITBoomBKStudio , it sometimes works but most times still generated a wrong mesh shape. It can be uncertain for these 2 results without changing code, just refreshing the page. That's weird and I have no idea