From b589a797c55ec8e58522c1259c6d0497c3d45898 Mon Sep 17 00:00:00 2001 From: Lou Amadio Date: Mon, 25 Sep 2023 15:38:07 -0700 Subject: [PATCH] Finish handling complex dae --- src/GeometryMesh.ts | 13 ++-- src/Render.ts | 82 +++++++++++++++++++++++++- test/testdata/basic_with_stl_mesh.urdf | 2 +- test/testdata/r2.urdf | 12 ++-- 4 files changed, 90 insertions(+), 19 deletions(-) diff --git a/src/GeometryMesh.ts b/src/GeometryMesh.ts index 0c3f473..c5013a2 100644 --- a/src/GeometryMesh.ts +++ b/src/GeometryMesh.ts @@ -22,16 +22,13 @@ export class Mesh implements IGeometry { // Get a pointer to the mesh if (meshes.length > 0 && this.transform != undefined) { this.meshes = meshes; + this.meshes[0].parent = this.transform; // find the top level bone in skeletons if (skeletons != undefined && skeletons.length > 0) { let rootBone = skeletons[0].bones.find(b => b.getParent() == undefined); if (rootBone != undefined) { - let t = rootBone.getTransformNode(); - if (t != undefined) { - t.parent = this.transform; - //t.addRotation(0, 0, Math.PI).addRotation(Math.PI/2, 0, 0); - } + rootBone.returnToRest(); } } else { @@ -39,7 +36,7 @@ export class Mesh implements IGeometry { if (this.transform != undefined) { m.addRotation(0, 0, Math.PI).addRotation(Math.PI/2, 0, 0); m.parent = this.transform; - m.scaling = this.scale; + if (this.material != undefined && this.material.material != undefined) { m.material = this.material.material; } @@ -52,12 +49,14 @@ export class Mesh implements IGeometry { public create(scene: BABYLON.Scene, mat : Material | undefined) : void { this.transform = new BABYLON.TransformNode("mesh_mesh", scene); + this.transform.scaling = this.scale; + this.material = mat; if (this.uri.startsWith("file://")) { // Handle relative paths - var filePath = this.uri.substring(7); + var filePath = this.uri.substring(7); if (!filePath.startsWith("/")) { filePath = path.join(__dirname, filePath); } diff --git a/src/Render.ts b/src/Render.ts index 993d845..1639edc 100644 --- a/src/Render.ts +++ b/src/Render.ts @@ -217,12 +217,88 @@ export async function RenderMain() { - + - - `; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + `; const canvas = document.getElementById("renderCanvas") as HTMLCanvasElement; // Get the canvas element const engine = new BABYLON.Engine(canvas, true); // Generate the BABYLON 3D engine diff --git a/test/testdata/basic_with_stl_mesh.urdf b/test/testdata/basic_with_stl_mesh.urdf index 16c07f2..d54d1a7 100644 --- a/test/testdata/basic_with_stl_mesh.urdf +++ b/test/testdata/basic_with_stl_mesh.urdf @@ -3,7 +3,7 @@ - + diff --git a/test/testdata/r2.urdf b/test/testdata/r2.urdf index bec4c46..85d016d 100644 --- a/test/testdata/r2.urdf +++ b/test/testdata/r2.urdf @@ -169,8 +169,7 @@ - - + @@ -184,8 +183,7 @@ - - + @@ -199,8 +197,7 @@ - - + @@ -214,8 +211,7 @@ - - +