Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refine vertex normal optimisation checks #127

Merged
merged 4 commits into from
Aug 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Sources/Polygon.swift
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@ public extension Polygon {
vertices.contains(where: { $0.texcoord != .zero })
}

/// A Boolean value that indicates whether the polygon includes vertex normals that differ from the face normal.
/// A Boolean value that indicates whether the polygon includes vertex normals.
var hasVertexNormals: Bool {
vertices.contains(where: { !$0.normal.isEqual(to: plane.normal) && $0.normal != .zero })
vertices.contains(where: { $0.normal != .zero })
}

/// A Boolean value that indicates whether the polygon includes vertex colors.
Expand Down
19 changes: 13 additions & 6 deletions Tests/MeshExportTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,19 @@ class MeshExportTests: XCTestCase {
vt 1 0
vt 0 0

f 1/1 2/2 3/3 4/4
f 5/1 6/2 7/3 8/4
f 7/1 4/2 3/3 8/4
f 5/1 2/2 1/3 6/4
f 6/1 1/2 4/3 7/4
f 2/1 5/2 8/3 3/4
vn 1 0 0
vn -1 0 0
vn 0 1 0
vn 0 -1 0
vn 0 0 1
vn 0 0 -1

f 1/1/1 2/2/1 3/3/1 4/4/1
f 5/1/2 6/2/2 7/3/2 8/4/2
f 7/1/3 4/2/3 3/3/3 8/4/3
f 5/1/4 2/2/4 1/3/4 6/4/4
f 6/1/5 1/2/5 4/3/5 7/4/5
f 2/1/6 5/2/6 8/3/6 3/4/6
""")
}

Expand Down
15 changes: 4 additions & 11 deletions Tests/SceneKitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,15 @@ class SceneKitTests: XCTestCase {
func testExportCube() {
let cube = Mesh.cube()
let geometry = SCNGeometry(polygons: cube)
XCTAssertEqual(geometry.sources.count, 2)
XCTAssertEqual(geometry.sources.first?.vectorCount, 20)
XCTAssertEqual(geometry.sources.count, 3)
XCTAssertEqual(geometry.sources.first?.vectorCount, 24)
}

func testExportCubeWithoutTexcoords() {
let cube = Mesh.cube().withoutTexcoords()
let geometry = SCNGeometry(polygons: cube)
XCTAssertEqual(geometry.sources.count, 1)
XCTAssertEqual(geometry.sources.first?.vectorCount, 8)
XCTAssertEqual(geometry.sources.count, 2)
XCTAssertEqual(geometry.sources.first?.vectorCount, 24)
}

func testExportSphere() {
Expand All @@ -136,13 +136,6 @@ class SceneKitTests: XCTestCase {
XCTAssertEqual(geometry.sources.first?.vectorCount, 151)
}

func testExportSphereWithoutTexcoordsOrNormals() {
let sphere = Mesh.sphere().withoutTexcoords().smoothingNormals(forAnglesGreaterThan: .zero)
let geometry = SCNGeometry(polygons: sphere)
XCTAssertEqual(geometry.sources.count, 1)
XCTAssertEqual(geometry.sources.first?.vectorCount, 114)
}

func testExportMeshWithColors() throws {
let mesh = Mesh.lathe(.curve([
.point(.unitY, color: .red),
Expand Down
Loading