Insert3D is the easiest 🥳 and fastest 🚀 way to embed a 3D model in your iOS app. It combines SceneKit and Model I/O into a simple library for creative iOS developers who want to provide a unique experience for their users. This library uniquely supports both:
Use CocoaPods. Add the dependency to your
Podfile and then run
Download and add example OBJ model (example-model.zip)
Copy & Paste into viewDidLoad
var viewer = Insert3DViewer() viewer.width = 380 viewer.height = 380 var model = Insert3DModel() model.mesh = "model/Nachos.obj" model.material = "model/NachosMaterial.jpg" view.Insert3D(viewerSetup: viewer, modelSetup: model)
Create instances of
Insert3DModel() and specify parameters, then pass the instances into the main
view.Insert3D() function to complete setup and display the viewer.
Command + R to Run
Insert3DViewer() set the dimensions and position of the
SCNView subview where the model is a central node.
// Values can be progromatically set and adjusted at any time var viewer = Insert3DViewer() viewer.width = 380 // Width viewer.height = 380 // Height viewer.x = 20 // X position of the top left corner viewer.y = 200 // Y position of the top left corner viewer.background = UIColor.white // Specify background of viewer. White by default // Show the model! view.Insert3D(viewerSetup: viewer, modelSetup: model) // modelSetup is also required
Dimensions using the relative position on screen can be expressed by converting them into
Int. For example, to center align the viewer, set the value for x equal to
Int(UIScreen.main.bounds.size.width*0.5) - viewer.width/2.
Included are default values width = 200, height = 200, x = 0, and y = 0.
Any, providing much flexibility for usage:
Insert3D() know which model you'd like to use, along with how you'd like it configured within the viewer.
// Values can be progromatically set and adjusted at any time. var model = Insert3DModel() model.mesh = "my3DFilePath" // Currently supports OBJ. model.texture = "myTexturePath" // Supports image files already mapped to the model model.autoRotate = true // Set true by default. Rotates on the horizontal axis model.rotationSpeed = 9 // Model makes one full rotation every 9 seconds model.fixed = false // Set false by deafault. Should the model be movable/rotatable by a user? // Show the model! view.Insert3D(viewerSetup: viewer, modelSetup: model) // viewerSetup is also required
NOTE: There are infinite possible customization one could apply to a model, and included here are the basic ones. Consider expanding this repository's functionality via a contribution.
Load via URL
The model and texture paths are a
String. This means you can load a model + texture dynamically using
This project is released under the BSD 2-Clause "Simplified" License