我正在尝试使我的几何体在SceneKit中看起来平坦而不平滑。正如您在图像中看到的,默认情况下,绿色球体在SceneKit中具有平滑着色。我想要的是另一个图像中的扁平“外观”,其中它表示“扁平”。


我在SceneKit中看不到任何有关如何禁用此功能的选项?这是我的游乐场上的代码:
import Cocoa
import SceneKit
import QuartzCore
import XCPlayground
var sceneView = SCNView(frame:CGRect(x:0, y:0, width:300, height:300))
var scene = SCNScene()
sceneView.backgroundColor = NSColor.darkGrayColor()
sceneView.scene = scene
sceneView.autoenablesDefaultLighting = true
XCPlaygroundPage.currentPage.liveView = sceneView
let g = SCNSphere(radius:1)
g.firstMaterial?.diffuse.contents = NSColor.greenColor()
g.firstMaterial?.litPerPixel = false
g.segmentCount = 5
let node = SCNNode(geometry:g)
node.position = SCNVector3(x:0, y:0, z:0)
scene.rootNode.addChildNode(node)
var spin = CABasicAnimation(keyPath:"rotation")
spin.toValue = NSValue(SCNVector4:SCNVector4(x:1, y:1, z:0, w:CGFloat(2.0*M_PI)))
spin.duration = 3
spin.repeatCount = HUGE
node.addAnimation(spin, forKey:"spin")发布于 2018-03-27 17:19:57
看起来Apple会为你应用正常的平滑效果。当SceneKit遇到平面网格时,可以更多地观察这一点。从网格中移除平滑的法线将使其看起来像低多边形。
如果使用ModelI/O加载三维资源。(为了测试,我创建了MDLMesh表单SCNGeometry)
SCNGeometry* flatGeoUsingModelIO(SCNGeometry *geo){
MDLMesh *mesh = [MDLMesh meshWithSCNGeometry:geo];
MDLMesh *newMesh = [MDLMesh newSubdividedMesh:mesh submeshIndex:0 subdivisionLevels:0];
[newMesh removeAttributeNamed:@"normals"];
//Replace current vertex normals with a non-smooth one. Same result with above line
//[newMesh addNormalsWithAttributeNamed:@"normals" creaseThreshold:1];
SCNGeometry *flatGeo = [SCNGeometry geometryWithMDLMesh:newMesh];
return flatGeo;
}或者您更熟悉SceneKit。
SCNGeometry* flatGeoUsingScnKit(SCNGeometry *geo){
NSArray<SCNGeometrySource*> *SourceArr = geo.geometrySources;
NSMutableArray<SCNGeometrySource*> *newSourceArr = [NSMutableArray new];
for (SCNGeometrySource *source in SourceArr) {
if (source.semantic != SCNGeometrySourceSemanticNormal) {
[newSourceArr addObject:source];
}
}
SCNGeometry *flatGeo = [SCNGeometry geometryWithSources:newSourceArr elements:geo.geometryElements];
return flatGeo;
}这是从右边创建的低多边形SCNSphere。

https://stackoverflow.com/questions/34731942
复制相似问题