1

我需要在ARKit/SceneKit场景中创建一个半球(圆顶)形状,我们在 SceneKit 中有 SCNSphere 基本形状,但不确定如何创建半球(圆顶)。

立即回复将不胜感激。

4

2 回答 2

2

SceneKit 没有现成的半球基元,而且 SceneKit 也不是像 Maya 或 3dsMax 这样的 3D 编辑工具。但是您可以使用 ModelIO 框架生成一个半球:

class func newEllipsoid(withRadii radii: vector_float3, 
                         radialSegments: Int, 
                       verticalSegments: Int, 
                           geometryType: MDLGeometryType, 
                          inwardNormals: Bool, 
                             hemisphere: Bool = true, 
                              allocator: MDLMeshBufferAllocator?) -> Self

当参数hemisphere = true它允许我们只生成椭圆体或球体(圆顶)的上半部分。如果hemisphere = false可以生成完整的椭球体或球体。

于 2020-10-13T09:47:35.370 回答
0
Thanks Andy.  Following is coded on basis of ur suggestion which create dome
    import ModelIO
    
    func adddome() {
    
            let mesh = MDLMesh.newEllipsoid(withRadii: vector_float3(0.1, 0.1, 0.1), radialSegments: 100, verticalSegments: 50, geometryType: MDLGeometryType.lines, inwardNormals: false, hemisphere: true, allocator: nil)
            
            let node = SCNNode()
            node.geometry = MeshToGeometry.convert(mesh) 
            node.geometry?.firstMaterial?.diffuse.contents = UIColor.blue
            node.geometry?.firstMaterial?.specular.contents = UIColor.orange
            node.position = SCNVector3(0, 0, 0)
            sceneView.scene.rootNode.addChildNode(node)
        }
    
    #import <Foundation/Foundation.h>
    #import <ModelIO/MDLMesh.h>
    #import <SceneKit/SceneKit.h>
    #import <SceneKit/ModelIO.h>
    
    @interface MeshToGeometry : NSObject
    + (SCNGeometry*) convert:(MDLMesh*)mesh;
    @end
    
    
    #import "MESHToGEO.h"
    
    @implementation MeshToGeometry
    + (SCNGeometry*) convert:(MDLMesh*)mesh {
        return [SCNGeometry geometryWithMDLMesh:mesh];
    }
    @end
于 2020-10-14T05:37:18.670 回答