From 0d6237007a2feed5d312b5fd9e334d2ddc0fddfa Mon Sep 17 00:00:00 2001 From: shinjeongmin Date: Wed, 22 May 2024 17:11:23 +0900 Subject: [PATCH 1/2] fix: make parse quad indices. cloth is render without broken. --- src/ObjLoader.ts | 46 +++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/src/ObjLoader.ts b/src/ObjLoader.ts index 8a2afba..15f26ed 100644 --- a/src/ObjLoader.ts +++ b/src/ObjLoader.ts @@ -83,26 +83,34 @@ export default class ObjLoader { const cache: Record = {}; let i = 0; for (const faces of cachedFaces) { - for (const faceString of faces) { - // If we already saw this, add to indices list. - if (cache[faceString] !== undefined) { - finalIndices.push(cache[faceString]); - continue; + // calculate triangle count in faces + const triangleCount = faces.length - 2; + for(var j = 0; j < triangleCount; j++) { + const triangleFace : string[] = [faces[0]]; + triangleFace.push(faces[1 + j]); + triangleFace.push(faces[2 + j]); + + for (const faceString of triangleFace) { + // If we already saw this, add to indices list. + if (cache[faceString] !== undefined) { + finalIndices.push(cache[faceString]); + continue; + } + + cache[faceString] = i; + finalIndices.push(i); + + // Need to convert strings to integers, and subtract by 1 to get to zero index. + const [vI, uvI, nI] = faceString + .split("/") + .map((s: string) => Number(s) - 1); + + vI > -1 && finalPosition.push(...cachedVertices[vI]); + uvI > -1 && finalUvs.push(...cachedUvs[uvI]); + nI > -1 && finalNormals.push(...cachedNormals[nI]); + + i += 1; } - - cache[faceString] = i; - finalIndices.push(i); - - // Need to convert strings to integers, and subtract by 1 to get to zero index. - const [vI, uvI, nI] = faceString - .split("/") - .map((s: string) => Number(s) - 1); - - vI > -1 && finalPosition.push(...cachedVertices[vI]); - uvI > -1 && finalUvs.push(...cachedUvs[uvI]); - nI > -1 && finalNormals.push(...cachedNormals[nI]); - - i += 1; } } } From 3f302d68da3c39c7e9ea7bc8c1707dcf26fa5f1f Mon Sep 17 00:00:00 2001 From: shinjeongmin Date: Wed, 22 May 2024 17:23:17 +0900 Subject: [PATCH 2/2] chore: change object_url and some scene setting. --- src/app.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/app.ts b/src/app.ts index 111eee0..452a7e6 100644 --- a/src/app.ts +++ b/src/app.ts @@ -8,7 +8,7 @@ import Cloth from "./Cloth"; // For the simulation to work with collisions, // it is wise to use equal spacing between all the particles. // This is possible to do in Blender even if the cloth as a whole is a rectangle. -const OBJECT_URL: string = "cloth_30_45_l.obj"; +const OBJECT_URL: string = "cloth_20_30_l.obj"; const VERTEX_SPACING = 0.05; (async () => { @@ -23,7 +23,8 @@ const VERTEX_SPACING = 0.05; const mesh = objLoader.parse(objFile); const modelTransformation = new Transformation(); - modelTransformation.scale = [1.0, 1.0, 1.0]; + modelTransformation.translation = [0,0,0]; + modelTransformation.scale = [1, 1, 1]; modelTransformation.rotationXYZ = [0, 1, 0]; // Create Buffers and Bind Groups @@ -35,14 +36,14 @@ const VERTEX_SPACING = 0.05; // Initalize Scene objects const lightModel = new Transformation(); - lightModel.translation = [5.0, 0.0, 0.0]; + lightModel.translation = [5.0, 0.0, 100.0]; lightModel.rotationXYZ = [0, 0, 0]; const perspectiveCamera = new Camera( (2 * Math.PI) / 5, gpuCanvas.aspectRatio, - 0.1, - 100 + 0.01, + 10000 ); perspectiveCamera.translation = [0, 0.0, 2.1];