diff --git a/type_templates/glb.js b/type_templates/glb.js index e89d40e..39eced8 100644 --- a/type_templates/glb.js +++ b/type_templates/glb.js @@ -22,10 +22,19 @@ export default e => { const localPlayer = useLocalPlayer(); const srcUrl = ${this.srcUrl}; + for (const {key, value} of components) { app.setComponent(key, value); } - + + // * true by default + let appHasPhysics = true; + const hasPhysicsComponent = app.hasComponent('physics'); + if (hasPhysicsComponent) { + const physicsComponent = app.getComponent('physics'); + appHasPhysics = physicsComponent; + } + app.glb = null; const animationMixers = []; const uvScrolls = []; @@ -192,37 +201,16 @@ export default e => { app.add(o); o.updateMatrixWorld(); - const _addPhysics = async physicsComponent => { - let physicsId; - switch (physicsComponent.type) { - case 'triangleMesh': { - physicsId = physics.addGeometry(o); - break; - } - case 'convexMesh': { - physicsId = physics.addConvexGeometry(o); - break; - } - default: { - physicsId = null; - break; - } - } - if (physicsId !== null) { - physicsIds.push(physicsId); - } else { - console.warn('glb unknown physics component', physicsComponent); - } + // * Physics + const _addPhysics = async () => { + const physicsId = physics.addGeometry(o); + physicsIds.push(physicsId); }; - let physicsComponent = app.getComponent('physics'); - if (physicsComponent) { - if (physicsComponent === true) { - physicsComponent = { - type: 'triangleMesh', - }; - } - _addPhysics(physicsComponent); + + if (appHasPhysics) { + _addPhysics(); } + o.traverse(o => { if (o.isMesh) { o.frustumCulled = false; @@ -325,4 +313,4 @@ export const contentId = ${this.contentId}; export const name = ${this.name}; export const description = ${this.description}; export const type = 'glb'; -export const components = ${this.components}; +export const components = ${this.components}; \ No newline at end of file