Construct an object of type Echo3D and use it to access Assets stored under your echo3D account's API Key.
Render your assets however you want.
Example Setup:
import SwiftUI
import SceneKit
struct ContentView: View { // Creates a SwiftUI View
var body: some View { // Creates a SwiftUI body
VStack {
Text("View Your Echo3D Model!")
.font(.headline)
SceneKitView()
.frame(width: 350, height: 350) // Adjust the size as needed
}
}
}
struct SceneKitView: UIViewRepresentable { // Creates the Scene with 3D Model using SceneKit and Echo3D Swift SDK
func makeUIView(context: Context) -> SCNView { // Creates a simple scene
let sceneView = SCNView()
sceneView.autoenablesDefaultLighting = true
sceneView.allowsCameraControl = true
return sceneView
}
func updateUIView(_ sceneView: SCNView, context: Context) { // Adds 3D Model stored under your Echo3D Accounts API Key
let e = Echo3D(); // Create an object of class Echo3D
e.queryDatabase(api_key: e.api_key, completion: { (entry_list) -> () in // Queries Echo3D's database for 3d Models
let entry = entry_list[0]
entry.downloadFile(completion: { (storage_id) in // Downloads the specificed 3D model entry and loads it into the scene
if let object = try? SCNScene(url: storage_id, options: nil) {
let objectNode = object.rootNode
sceneView.scene = object
sceneView.scene?.rootNode.addChildNode(objectNode)
}
});
});
}
}
@main
struct SDKTest2_6App: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}