1

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.

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
Amit Singh
  • 63
  • 8

2 Answers2

2

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.

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
  • 1
    Also the ellipsoid `MDLMesh` can be converted to a `SCNGeometry` object using `SCNGeometry(mdlMesh: ellipsoid)` which requires `import SceneKit.ModelIO`. – Drew Nov 20 '21 at 19:58
1
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
Chris
  • 7,579
  • 3
  • 18
  • 38
Amit Singh
  • 63
  • 8