hen*_*yaz 6 uiimage scenekit swift
此代码摘录(场景,相机,灯光等,从代码中删除)在iOS模拟器上的Swift中工作:
let boxNode = SCNNode()
// Create a box
boxNode.geometry = SCNBox(width: 1, height: 1, length: 1, chamferRadius: 0.1)
let numFaces = 6
scene.rootNode.addChildNode(boxNode)
// create and configure a material for each face
var materials: [SCNMaterial] = Array()
for i in 1...numFaces
{
let material = SCNMaterial()
material.diffuse.contents = UIImage(named: "texture")
materials += material
}
// set the material to the 3d object geometry
boxNode.geometry.materials = materials
Run Code Online (Sandbox Code Playgroud)
它会生成一个框,每个面都是方格图像.
尝试在Wings3D中创建的简单库存几何体,保存到DAE,并在应用程序中加载,给我一个合适的形状,但脸上没有阴影和图像:
let boxNode = SCNNode()
// Load the geometry
let urlToColladaFile = NSBundle.mainBundle().URLForResource("Objects", withExtension:"dae")
let sceneSource = SCNSceneSource(URL:urlToColladaFile, options:nil)
boxNode.geometry = sceneSource.entryWithIdentifier("dodecahedron3-0", withClass:SCNGeometry.self) as SCNGeometry
let numFaces = 10
scene.rootNode.addChildNode(boxNode)
// create and configure a material for each face
var materials: [SCNMaterial] = Array()
for i in 1...numFaces
{
let material = SCNMaterial()
material.diffuse.contents = UIImage(named: "texture")
materials += material
}
// set the material to the 3d object geometry
boxNode.geometry.materials = materials
Run Code Online (Sandbox Code Playgroud)
我错过了什么?
你的几何有纹理坐标吗?您可以通过编程方式(通过检查是否存在具有SCNGeometrySourceSemanticTexcoord语义的源)或在Xcode中内置的SceneKit编辑器中进行验证.
另请注意,您不必为每个几何元素创建一个材质.如果它们完全相同,只需构建一个材质的数组,它将用于整个几何体.
谢谢,mnuages 和 rickster。您的推论使我在 Wings3D 中研究了我的选择,并且我能够在 Wings3D 中解决问题。
简而言之,我需要为实体的每个面创建 UV 贴图。
对于正多面体,我有多种选择:
如果我开始在边缘添加边框或更平滑的倒角,这一切都会变得更加复杂,现在我需要确保 UV 映射对于我处理的每组面都有意义。同样,网上有这方面的教程。
再次感谢!
干杯,亨利
归档时间: |
|
查看次数: |
8140 次 |
最近记录: |