Insert3D 是将 3D 模型嵌入您的 iOS 应用中最简单、最快的方式。它将 SceneKit 和 Model I/O 合并成一个简单的库,供想在用户中获得独特体验的创意 iOS 开发者使用。
安装
使用 CocoaPods。将依赖添加到您的 Podfile
中,然后运行 pod install
pod 'Insert3D'
快速入门
- 导入库
import Insert3D
-
下载并添加示例 OBJ 模型(example-model.zip)
-
复制并粘贴到 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)
使用
创建 Insert3DViewer()
和 Insert3DModel()
的实例,并指定参数,然后将这些实例传递给主 view.Insert3D()
函数以完成设置并显示查看器。
Command + R
运行
查看器
Insert3DViewer()
的实例设置包含模型的中央节点的 SCNView
子视图的尺寸和位置。
// 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
尺寸
使用屏幕相对位置表示尺寸可以通过将它们转换为 Int
来表示(详情见此处描述)。
默认值宽度 = 200,高度 = 200,x = 0,y = 0。
背景
背景支持 Any
,为使用提供了很大灵活性。
- 颜色(NSColor 或 UIColor 或 CGColor),指定材料表面的统一颜色。
- 数字(NSNumber),指定材料表面的统一标量值(对如 金属度 等物理属性很有用)。
- 图片(NSImage 或 UIImage 或 CGImage),指定要在材料表面映射的纹理。
- 指定图片文件位置的 NSString 或 NSURL 对象。
- 视频播放器(AVPlayer)或iOS中的实时视频捕获预览(AVCaptureDevice)。
- Core Animation层(CALayer)。
- 纹理(SKTexture,MDLTexture,MTLTexture 或 GLKTextureInfo)。
- SpriteKit场景(SKScene)。
- 特殊格式的图片或六个图片的数组,指定立方体贴画的各个面。
模型
Insert3DModel()
实例让 Insert3D
了解您想使用的模型,以及如何配置它在查看器中的设置。
// 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
注意:您可以为模型应用无限多的自定义设置,这里包括基本的设置。考虑通过贡献来扩展此仓库的功能。
贡献
- 分支( https://github.com/Viktoo/Insert3D/fork )。
- 创建您的新特性分支(git checkout -b my-new-feature)。
- 提交您的更改(git commit -am '添加一些特性')。
- 将更改推送到分支(git push origin my-new-feature)。
- 创建新的拉取请求。
许可证
本项目遵循BSD 2-Clause "简化版" 许可协议发布