Как загрузить центр модели .usdz в сцену swift ios? - PullRequest
0 голосов
/ 09 апреля 2020

Пожалуйста, помогите мне, Как загрузить центр модели .usdz в сцену swift ios? Я попытался загрузить модель в центре с середины сцены. Я приложил свой пробный код. Пожалуйста, просмотрите его и помогите мне.

Требуется

  1. Загрузить модель центра экрана
  2. Загрузить большую модель
func addusdz(name:URL) {
       DispatchQueue.main.async {
        do{
            let scene = try! SCNScene(url: name, options: [.checkConsistency: true])
                       for child in scene.rootNode.childNodes {
                           for child1 in child.childNodes {
                               for node in child1.childNodes {

                                   if let s1 = node.geometry?.materials.first?.transparent.contents as? NSNumber {
                                       if node.geometry?.materials.first?.transparent.contents as! NSNumber != 1 {
                                           node.opacity = CGFloat(node.geometry?.materials.first?.transparent.contents as! NSNumber)
                                       }
                                   } else {
                                       print("isCompleted is not a String")
                                   }
                               }
                           }
                       }

                       //addAnimation(node: scene.rootNode)
                       //addAnimation(node: node)
                       self.scnnode = scene.rootNode

        }catch{
            print("Error kalpesh")
        }
            let max = self.scnnode.boundingBox.max
            let min = self.scnnode.boundingBox.min
            let w = CGFloat(max.x - min.x)
            let h = CGFloat(max.y - min.y)
            let l = CGFloat(max.z - min.z)

            var zval = Float()

            if w > h && w > l{
                zval = Float(w)
            } else if h > w && h > l{
                zval = Float(h)
            } else {
                zval = Float(l)
            }
            zval = ((zval) + (zval/2))

            let camera = SCNCamera()
            camera.zFar = 10000
            self.camera = SCNNode()
            self.camera.camera = camera
            self.camera.position = SCNVector3(x: 0, y: Float(h/2), z: zval)
            self.ScnView.scene!.rootNode.addChildNode(self.camera)

            let worldGroundPlaneGeometry = SCNFloor()
            let worldGroundPlane = SCNNode()
            let worldGroundMaterial = SCNMaterial()
            worldGroundMaterial.lightingModel = .constant
            worldGroundMaterial.writesToDepthBuffer = true
            worldGroundMaterial.colorBufferWriteMask = []
            worldGroundMaterial.isDoubleSided = true
            worldGroundPlaneGeometry.materials = [worldGroundMaterial]
            worldGroundPlane.geometry = worldGroundPlaneGeometry
            self.ScnView.scene!.rootNode.addChildNode(worldGroundPlane)
            self.ScnView.scene!.rootNode.addChildNode(self.scnnode)

Текущий результат

Cueent Result

Требуемый результат

Required Result

...