我目前正在尝试在swift中平滑我的obj模型,使用SCNGeometry或MDLMesh都是适用的。
我发现官方文档显示在SCNGeometry中有用于细分和平滑的"subdivisionLevel“属性。然而,它并没有像预期的那样工作。
对于level = 1-2,没有明显的变化
对于level = 3-5,仍然没有明显的变化,但应用程序正在滞后
下面是我的实验和代码的截图,还有什么我可以尝试平滑的吗?
subdivisionLevel=0:http://imgur.com/7BM9wp6
subdivisionLevel=5:http://imgur.com/mipaYMP
(如你所见,锐利的边缘、腰部和手臂仍然在那里)
代码:
//load obj
let path = Bundle.main.path(forResource: "model_longshirt", ofType: "obj")!
let fileUrl = URL(fileURLWithPath: path)
let asset = MDLAsset(url: fileUrl)
guard let object = asset.object(at: 0) as? MDLMesh else {
fatalError("ERROR_FAILED_TO_GET_MESH_FROM_ASSET")
}
//load material
let scatteringFunction = MDLScatteringFunction()
let material = MDLMaterial(name: "baseMaterial2", scatteringFunction: scatteringFunction)
let texPath = Bundle.main.path(forResource: "model_LongSleeve_texture_3", ofType: "jpg")!
let texUrl = URL(fileURLWithPath: texPath)
let materialProperty = MDLMaterialProperty(name: "baseTexture2", semantic: MDLMaterialSemantic.baseColor, url: texUrl)
material.setProperty(materialProperty)
//attach to node
let scnGeometry = SCNGeometry(mdlMesh: object)
scnGeometry.subdivisionLevel = 5
objNode = SCNNode(geometry: scnGeometry)
objNode.geometry?.firstMaterial = scnMaterial任何帮助或提示都将不胜感激。谢谢。
https://stackoverflow.com/questions/44342014
复制相似问题