Skip to content
This repository has been archived by the owner on May 23, 2024. It is now read-only.

gltf model model does not get parsed #196

Open
wilsonXo opened this issue Nov 23, 2021 · 9 comments
Open

gltf model model does not get parsed #196

wilsonXo opened this issue Nov 23, 2021 · 9 comments

Comments

@wilsonXo
Copy link

wilsonXo commented Nov 23, 2021

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

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

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

image

@arpu
Copy link
Contributor

arpu commented Jan 25, 2022

@ITBoomBKStudio cool Model!

@ITBoomBKStudio
Copy link

@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
Copy link
Contributor

arpu commented Jan 25, 2022

hmm sorry i am not familiar with the ammo stack

@wilsonXo
Copy link
Author

image

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

@RepSklvska
Copy link

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

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants