Skip to content

Commit

Permalink
Improve example app
Browse files Browse the repository at this point in the history
  • Loading branch information
nicklockwood committed Sep 23, 2023
1 parent f4e641a commit 83605ae
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 28 deletions.
4 changes: 4 additions & 0 deletions Euclid.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
010A633B2A955BE9000E3306 /* MeshExportTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 010A633A2A955BE9000E3306 /* MeshExportTests.swift */; };
0112D5C928EE29BB00A1C085 /* Euclid+RealityKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0112D5C828EE29BB00A1C085 /* Euclid+RealityKit.swift */; };
0125478027AFD53900C442C3 /* MeshShapeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0125477F27AFD53900C442C3 /* MeshShapeTests.swift */; };
0128EEBB2ABA607A00E60976 /* EuclidMesh.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0128EEBA2ABA607A00E60976 /* EuclidMesh.swift */; };
013312DD21CA532A00626F1B /* PlaneTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 013312DC21CA532A00626F1B /* PlaneTests.swift */; };
013499932902FB5900CED6BE /* Euclid+SIMD.swift in Sources */ = {isa = PBXBuildFile; fileRef = 013499922902FB5900CED6BE /* Euclid+SIMD.swift */; };
0134999729043ACC00CED6BE /* RealityKitViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0134999629043ACC00CED6BE /* RealityKitViewController.swift */; };
Expand Down Expand Up @@ -112,6 +113,7 @@
010A633A2A955BE9000E3306 /* MeshExportTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MeshExportTests.swift; sourceTree = "<group>"; };
0112D5C828EE29BB00A1C085 /* Euclid+RealityKit.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Euclid+RealityKit.swift"; sourceTree = "<group>"; };
0125477F27AFD53900C442C3 /* MeshShapeTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MeshShapeTests.swift; sourceTree = "<group>"; };
0128EEBA2ABA607A00E60976 /* EuclidMesh.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EuclidMesh.swift; sourceTree = "<group>"; };
013312DC21CA532A00626F1B /* PlaneTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlaneTests.swift; sourceTree = "<group>"; };
013499922902FB5900CED6BE /* Euclid+SIMD.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Euclid+SIMD.swift"; sourceTree = "<group>"; };
0134999629043ACC00CED6BE /* RealityKitViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RealityKitViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -312,6 +314,7 @@
isa = PBXGroup;
children = (
016FABEC21C078E400AF60DC /* AppDelegate.swift */,
0128EEBA2ABA607A00E60976 /* EuclidMesh.swift */,
016FABF021C078E400AF60DC /* SceneKitViewController.swift */,
0134999629043ACC00CED6BE /* RealityKitViewController.swift */,
016FABF221C078E400AF60DC /* Main.storyboard */,
Expand Down Expand Up @@ -582,6 +585,7 @@
files = (
016FABF121C078E400AF60DC /* SceneKitViewController.swift in Sources */,
0134999729043ACC00CED6BE /* RealityKitViewController.swift in Sources */,
0128EEBB2ABA607A00E60976 /* EuclidMesh.swift in Sources */,
016FABED21C078E400AF60DC /* AppDelegate.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
2 changes: 1 addition & 1 deletion Euclid.xcodeproj/xcshareddata/xcschemes/Example.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
buildConfiguration = "Release"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
Expand Down
26 changes: 26 additions & 0 deletions Example/EuclidMesh.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// EuclidMesh.swift
// Example
//
// Created by Nick Lockwood on 20/09/2023.
// Copyright © 2023 Nick Lockwood. All rights reserved.
//

import Euclid
import UIKit

let euclidMesh: Mesh = {
let start = CFAbsoluteTimeGetCurrent()

// create some geometry using Euclid
let cube = Mesh.cube(size: 0.8, material: UIColor.red)
let sphere = Mesh.sphere(slices: 120, material: CGImage.checkerboard())
let mesh = cube.subtracting(sphere).makeWatertight()

print("Time:", CFAbsoluteTimeGetCurrent() - start)
print("Polygons:", mesh.polygons.count)
print("Triangles:", mesh.triangulate().polygons.count)
print("Watertight:", mesh.isWatertight)

return mesh
}()
20 changes: 5 additions & 15 deletions Example/RealityKitViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,13 @@ class RealityKitViewController: UIViewController {
arView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
view.addSubview(arView)

// create some geometry using Euclid
let start = CFAbsoluteTimeGetCurrent()
let cube = Mesh.cube(size: 0.8, material: UIColor.red)
let sphere = Mesh.sphere(slices: 120, material: UIColor.blue)
let mesh = cube.subtracting(sphere).makeWatertight()

print("Time:", CFAbsoluteTimeGetCurrent() - start)
print("Polygons:", mesh.polygons.count)
print("Triangles:", mesh.triangulate().polygons.count)
print("Watertight:", mesh.isWatertight)

if #available(macOS 12.0, iOS 15.0, *) {
// create ModelEntity
let entity = try! ModelEntity(mesh)
let anchor = AnchorEntity(world: .zero)
anchor.addChild(entity)
arView.scene.anchors.append(anchor)
if let entity = try? ModelEntity(euclidMesh) {
let anchor = AnchorEntity(world: .zero)
anchor.addChild(entity)
arView.scene.anchors.append(anchor)
}
} else {
let alert = UIAlertController(
title: "Unsupported",
Expand Down
13 changes: 1 addition & 12 deletions Example/SceneKitViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,8 @@ class SceneKitViewController: UIViewController {
// place the camera
cameraNode.position = SCNVector3(x: 0, y: 0, z: 2)

// create some geometry using Euclid
let start = CFAbsoluteTimeGetCurrent()
let cube = Mesh.cube(size: 0.8, material: UIColor.red)
let sphere = Mesh.sphere(slices: 120, material: UIColor.blue)
let mesh = cube.subtracting(sphere).makeWatertight()

print("Time:", CFAbsoluteTimeGetCurrent() - start)
print("Polygons:", mesh.polygons.count)
print("Triangles:", mesh.triangulate().polygons.count)
print("Watertight:", mesh.isWatertight)

// create SCNNode
let geometry = SCNGeometry(mesh)
let geometry = SCNGeometry(euclidMesh)
let node = SCNNode(geometry: geometry)
scene.rootNode.addChildNode(node)

Expand Down

0 comments on commit 83605ae

Please sign in to comment.