How can we create hemisphere shape in SceneKit's scene?

653 views Asked by At

I need to create a hemisphere (dome) Shape in ARKit/SceneKit scene, we have SCNSphere basic shape in SceneKit, but not sure how to create hemisphere (dome).

Immediate reply will be appreciated.

2

There are 2 answers

1
Andy Jazz On

SceneKit has no ready-to-use hemisphere primitive as well as SceneKit isn't a 3D editing tool like Maya or 3dsMax. But you can generate a hemisphere using ModelIO framework:

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

When argument hemisphere = true it allows us generate only the upper half of the ellipsoid or sphere (a dome). If hemisphere = false you can generate a complete ellipsoid or sphere.

0
Amit Singh On
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