Skip to content

Commit

Permalink
Add more tests to constructVertices, to cover parentMesh and map lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
phanlezz committed Jun 25, 2024
1 parent 4233255 commit dd10e89
Showing 1 changed file with 52 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand All @@ -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(`<vertex x="${xyzPos[0]}" y="${xyzPos[1]}" z="${xyzPos[2]}"/>`)
}
})

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(`<vertex x="${xyzPos[0]}" y="${xyzPos[1]}" z="${xyzPos[2]}"/>`)
}
})

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(`<vertex x="${xyzPos[0]}" y="${xyzPos[1]}" z="${xyzPos[2]}"/>`)
}
})
})

Expand Down

0 comments on commit dd10e89

Please sign in to comment.