🔢
Displaying a Model Asset
Learn how to add non-AR asset to your project using our Swift SDK.
Now that you have successfully integrated the echo3D SDK into Xcode, it's time to display a model in your project!
Add a model asset through the console. Here's how:
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.

1
import SwiftUI
2
import SceneKit
3
4
struct ContentView: View { // Creates a SwiftUI View
5
var body: some View { // Creates a SwiftUI body
6
VStack {
7
Text("View Your Echo3D Model!")
8
.font(.headline)
9
10
SceneKitView()
11
.frame(width: 350, height: 350) // Adjust the size as needed
12
}
13
}
14
}
15
16
struct SceneKitView: UIViewRepresentable { // Creates the Scene with 3D Model using SceneKit and Echo3D Swift SDK
17
18
func makeUIView(context: Context) -> SCNView { // Creates a simple scene
19
let sceneView = SCNView()
20
sceneView.autoenablesDefaultLighting = true
21
sceneView.allowsCameraControl = true
22
return sceneView
23
}
24
25
func updateUIView(_ sceneView: SCNView, context: Context) { // Adds 3D Model stored under your Echo3D Accounts API Key
26
let e = Echo3D(); // Create an object of class Echo3D
27
28
e.queryDatabase(api_key: e.api_key, completion: { (entry_list) -> () in // Queries Echo3D's database for 3d Models
29
let entry = entry_list[0]
30
entry.downloadFile(completion: { (storage_id) in // Downloads the specificed 3D model entry and loads it into the scene
31
if let object = try? SCNScene(url: storage_id, options: nil) {
32
let objectNode = object.rootNode
33
sceneView.scene = object
34
sceneView.scene?.rootNode.addChildNode(objectNode)
35
}
36
});
37
});
38
}
39
}
40
41
@main
42
struct SDKTest2_6App: App {
43
var body: some Scene {
44
WindowGroup {
45
ContentView()
46
}
47
}
48
}
Last modified 1mo ago