n5ro / aframe-physics-system

Physics system for A-Frame VR, built on CANNON.js.

Home Page:https://n5ro.github.io/aframe-physics-system/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

gltf model model does not get parsed

wilsonXo opened this issue · comments

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

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}

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 🌟

commented

@ITBoomBKStudio cool Model!

@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:(

commented

hmm sorry i am not familiar with the ammo stack

image

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

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

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