From dd10e89ce92628356ddd5a897b5f9a9e5097ae71 Mon Sep 17 00:00:00 2001
From: Sebastian Wolf <65733509+phanlezz@users.noreply.github.com>
Date: Tue, 25 Jun 2024 09:14:54 +0200
Subject: [PATCH] Add more tests to constructVertices, to cover parentMesh and
map lookup
---
.../3DExports/serialize3mf.service.spec.ts | 53 ++++++++++++++++++-
1 file changed, 52 insertions(+), 1 deletion(-)
diff --git a/visualization/app/codeCharta/services/3DExports/serialize3mf.service.spec.ts b/visualization/app/codeCharta/services/3DExports/serialize3mf.service.spec.ts
index fd66cc1728..d47b22c198 100644
--- a/visualization/app/codeCharta/services/3DExports/serialize3mf.service.spec.ts
+++ b/visualization/app/codeCharta/services/3DExports/serialize3mf.service.spec.ts
@@ -62,7 +62,8 @@ describe("serialize3mf service", () => {
vertexIndexToNewVertexIndex = new Map()
vertexIndexes = [0, 1, 2]
testMesh = new Mesh()
- testMesh.geometry.attributes["position"] = new BufferAttribute(new Float32Array(testVertexPositions), 3, false)
+ testMesh.geometry.attributes["position"] = new BufferAttribute(new Float32Array(testVertexPositions), 3)
+ testMesh.matrix.makeScale(2, 2, 2)
})
it("should create correct vertex entries", () => {
@@ -72,6 +73,56 @@ describe("serialize3mf service", () => {
expect(vertexIndexToNewVertexIndex.size).toBe(3)
expect(vertexToNewVertexIndex.size).toBe(3)
expect([...vertexToNewVertexIndex.keys()].toString()).toBe(vertices.toString())
+ const expectedPositions = [
+ [0, 0, 0],
+ [4, 0, 0],
+ [0, 4, 0]
+ ]
+ for (const xyzPos of expectedPositions) {
+ expect(vertices).toContain(``)
+ }
+ })
+
+ it("should apply parent matrix if present", () => {
+ parentMatrix = new Matrix4()
+ parentMatrix.setPosition(1, 1, 1)
+
+ constructVertices(vertices, vertexToNewVertexIndex, vertexIndexToNewVertexIndex, vertexIndexes, testMesh, parentMatrix)
+
+ expect(vertices).toHaveLength(3)
+ expect(vertexIndexToNewVertexIndex.size).toBe(3)
+ expect(vertexToNewVertexIndex.size).toBe(3)
+ expect([...vertexToNewVertexIndex.keys()].toString()).toBe(vertices.toString())
+ const expectedPositions = [
+ [1, 1, 1],
+ [5, 1, 1],
+ [1, 5, 1]
+ ]
+ for (const xyzPos of expectedPositions) {
+ expect(vertices).toContain(``)
+ }
+ })
+
+ it("should not add new entries to indexLookup but vertexLookup if repeated information", () => {
+ const testDoubleVertexPositions = [...testVertexPositions, ...testVertexPositions]
+ const doubleMesh = new Mesh()
+ doubleMesh.geometry.attributes["position"] = new BufferAttribute(new Float32Array(testDoubleVertexPositions), 3)
+ const longerIndex = [1, 2, 3, 4, 5, 6]
+
+ constructVertices(vertices, vertexToNewVertexIndex, vertexIndexToNewVertexIndex, longerIndex, doubleMesh, parentMatrix)
+
+ expect(vertices).toHaveLength(3)
+ expect(vertexIndexToNewVertexIndex.size).toBe(6)
+ expect(vertexToNewVertexIndex.size).toBe(3)
+ expect([...vertexToNewVertexIndex.keys()].toString()).toBe(vertices.toString())
+ const expectedPositions = [
+ [0, 0, 0],
+ [2, 0, 0],
+ [0, 2, 0]
+ ]
+ for (const xyzPos of expectedPositions) {
+ expect(vertices).toContain(``)
+ }
})
})