From 0fd4da1c5f967a985b9c3c37d2269bf8b96cc299 Mon Sep 17 00:00:00 2001 From: aryasalehi <64514807+aryasalehi@users.noreply.github.com> Date: Fri, 14 Oct 2022 15:25:51 +0330 Subject: [PATCH 1/6] Rewrite physics component logic for glbs --- type_templates/glb.js | 46 ++++++++++++++----------------------------- 1 file changed, 15 insertions(+), 31 deletions(-) diff --git a/type_templates/glb.js b/type_templates/glb.js index e89d40e..5f69771 100644 --- a/type_templates/glb.js +++ b/type_templates/glb.js @@ -22,10 +22,18 @@ 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) { + appHasPhysics = value; + } + app.glb = null; const animationMixers = []; const uvScrolls = []; @@ -192,36 +200,12 @@ 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 () => { + physicsId = physics.addGeometry(o); }; - let physicsComponent = app.getComponent('physics'); - if (physicsComponent) { - if (physicsComponent === true) { - physicsComponent = { - type: 'triangleMesh', - }; - } - _addPhysics(physicsComponent); + if (appHasPhysics) { + _addPhysics(); } o.traverse(o => { if (o.isMesh) { @@ -325,4 +309,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 From 2991b23733797826991b6928d1f7db0f0bce5e01 Mon Sep 17 00:00:00 2001 From: aryasalehi Date: Fri, 14 Oct 2022 15:27:22 +0330 Subject: [PATCH 2/6] Revert "Rewrite physics component logic for glbs" This reverts commit 0fd4da1c5f967a985b9c3c37d2269bf8b96cc299. --- type_templates/glb.js | 46 +++++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/type_templates/glb.js b/type_templates/glb.js index 5f69771..e89d40e 100644 --- a/type_templates/glb.js +++ b/type_templates/glb.js @@ -22,18 +22,10 @@ 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) { - appHasPhysics = value; - } - + app.glb = null; const animationMixers = []; const uvScrolls = []; @@ -200,12 +192,36 @@ export default e => { app.add(o); o.updateMatrixWorld(); - // * Physics - const _addPhysics = async () => { - physicsId = physics.addGeometry(o); + 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); + } }; - if (appHasPhysics) { - _addPhysics(); + let physicsComponent = app.getComponent('physics'); + if (physicsComponent) { + if (physicsComponent === true) { + physicsComponent = { + type: 'triangleMesh', + }; + } + _addPhysics(physicsComponent); } o.traverse(o => { if (o.isMesh) { @@ -309,4 +325,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}; \ No newline at end of file +export const components = ${this.components}; From 83b2809cc27702001eb9b83be02d2835385b7d0a Mon Sep 17 00:00:00 2001 From: aryasalehi Date: Fri, 14 Oct 2022 15:29:39 +0330 Subject: [PATCH 3/6] Rewrite physics component logic --- type_templates/glb.js | 46 ++++++++++++++----------------------------- 1 file changed, 15 insertions(+), 31 deletions(-) diff --git a/type_templates/glb.js b/type_templates/glb.js index e89d40e..5f69771 100644 --- a/type_templates/glb.js +++ b/type_templates/glb.js @@ -22,10 +22,18 @@ 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) { + appHasPhysics = value; + } + app.glb = null; const animationMixers = []; const uvScrolls = []; @@ -192,36 +200,12 @@ 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 () => { + physicsId = physics.addGeometry(o); }; - let physicsComponent = app.getComponent('physics'); - if (physicsComponent) { - if (physicsComponent === true) { - physicsComponent = { - type: 'triangleMesh', - }; - } - _addPhysics(physicsComponent); + if (appHasPhysics) { + _addPhysics(); } o.traverse(o => { if (o.isMesh) { @@ -325,4 +309,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 From 0f81996f5e32c18739cecc64bf1e6b2fbe4995ea Mon Sep 17 00:00:00 2001 From: aryasalehi <64514807+aryasalehi@users.noreply.github.com> Date: Fri, 14 Oct 2022 15:47:00 +0330 Subject: [PATCH 4/6] add physicsId --- type_templates/glb.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/type_templates/glb.js b/type_templates/glb.js index 5f69771..edc88db 100644 --- a/type_templates/glb.js +++ b/type_templates/glb.js @@ -202,11 +202,14 @@ export default e => { // * Physics const _addPhysics = async () => { - physicsId = physics.addGeometry(o); + const physicsId = physics.addGeometry(o); + physicsIds.push(physicsId); }; + if (appHasPhysics) { _addPhysics(); } + o.traverse(o => { if (o.isMesh) { o.frustumCulled = false; From 2a27252180a7fe1e743125185c37aafc4f5d0152 Mon Sep 17 00:00:00 2001 From: aryasalehi <64514807+aryasalehi@users.noreply.github.com> Date: Fri, 14 Oct 2022 15:52:55 +0330 Subject: [PATCH 5/6] fix value setting --- type_templates/glb.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/type_templates/glb.js b/type_templates/glb.js index edc88db..1885d82 100644 --- a/type_templates/glb.js +++ b/type_templates/glb.js @@ -31,7 +31,8 @@ export default e => { let appHasPhysics = true; const hasPhysicsComponent = app.hasComponent('physics'); if (hasPhysicsComponent) { - appHasPhysics = value; + const physicsComponent = app.getComponent('physics'); + appHasPhysics = physicsComponent; } app.glb = null; From 250bbbb2ddd485ab24497374dc3f1c4d1f1e2ca2 Mon Sep 17 00:00:00 2001 From: aryasalehi <64514807+aryasalehi@users.noreply.github.com> Date: Fri, 14 Oct 2022 16:07:03 +0330 Subject: [PATCH 6/6] Cleanup --- type_templates/glb.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/type_templates/glb.js b/type_templates/glb.js index 1885d82..39eced8 100644 --- a/type_templates/glb.js +++ b/type_templates/glb.js @@ -27,7 +27,7 @@ export default e => { app.setComponent(key, value); } - // ? true by default + // * true by default let appHasPhysics = true; const hasPhysicsComponent = app.hasComponent('physics'); if (hasPhysicsComponent) {