Skip to content

Commit

Permalink
Do not automatically strip flat-shaded vertex normals (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
zilmarinen authored Aug 11, 2024
1 parent 9643e62 commit eee79b3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
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

0 comments on commit eee79b3

Please sign in to comment.