قالب وردپرس درنا توس
Home / IOS Development / ios – ARSCNView 3d object Aspect Fit

ios – ARSCNView 3d object Aspect Fit



I develop ARKit Application using 3d models. So for that I have used 3d models and added motions to move, rotate and zoom 3d models.

Now I'm facing only one problem, but I'm not sure if this problem concerns what. Is there a problem in the 3d model or if something is missing in my program.

The problem is the 3d model I use shows very big and goes out of the screen. I'm trying to scale it down, but it's very big.

Here is my code:

  @IBOutlet was mySceneView: ARSCNView!
was selectedNode = SCNNode ()
var prevLoc = CGPoint ()
was touchCount: Int = 0

override func viewDidLoad () {
super.viewDidLoad ()
self.lblTitle.text = self.sceneTitle
let mySCN = SCNScene.init (named: "art.scnassets / (self.sceneImagename) .scn")!
self.mySceneView.scene = mySCN

la cameraNode = SCNNode ()
cameraNode.camera = SCNCamera ()
cameraNode.position = SCNVector3Make (0, 0, 0)
self.mySceneView.scene.rootNode.addChildNode (cameraNode)
self.mySceneView.allowsCameraControl = true
self.mySceneView.autoenablesDefaultLighting = true

let tapGesture = UITapGestureRecognizer (target: self, action: #selector (detailPage.doHandleTap (_ :)))
la panGesture = UIPanGestureRecognizer (target: self, action: #selector (detailPage.doHandlePan (_ :)))
la gesturesArray = NSMutableArray ()
gesturesArray.add (tapGesture)
gesturesArray.add (panGesture)
gesturesArray.addObjects (from: self.mySceneView.gestureRecognizers!)
self.mySceneView.gestureRecognizers = (gesturesArray as! [UIGestureRecognizer])
}

// MARK: - Handle Gesture
@objc func doHandlePan (_ sender: UIPanGestureRecognizer) {
was delta = transmitter.translation (in: self.view)
la loc = sender.location (in: self.view)
if send.state == .began {
self.prevLoc = loc
self.touchCount = sender.numberOfTouches
} other if sending.state == .changed {
delta = CGPoint (x: loc.x - prevLoc.x, y: loc.y - prevLoc.y)
prevLoc = loc
if self.touchCount! = sender.numberOfTouches {
return
}

was rotMat = SCNMatrix4 ()
if touchCount == 2 {
rotMat = SCNMatrix4MakeTranslation (Float (delta.x * 0.025), Float (delta.y * -0.025), 0)
} other {
la rotMatX = SCNMatrix4Rotate (SCNMatrix4Identity, Float ((1
.0 / 100) * delta.y), 1, 0, 0) la rotMatY = SCNMatrix4Rotate (SCNMatrix4Identity, Float ((1.0 / 100) * delta.x), 0, 1, 0) rotMat = SCNMatrix4Mult (rotMatX, rotMatY) } la transMat = SCNMatrix4MakeTranslation (selectedNode.position.x, selectedNode.position.y, selectedNode.position.z) selectedNode.transform = SCNMatrix4Mult (selectedNode.transform, SCNMatrix4Invert (transMat)) la parentNodeTransMat = SCNMatrix4MakeTranslation ((selectedNode.parent? .worldPosition.x)!, (selectedNode.parent? .worldPosition.y) !, (selectedNode.parent? .worldPosition.z)!) la parentNodeMatWOTrans = SCNMatrix4Mult (selectedNode.parent! .worldTransform, SCNMatrix4Invert (parentNodeTransMat)) selectedNode.transform = SCNMatrix4Mult (selectedNode.transform, parentNodeMatWOTrans) la camorbitNodeTransMat = SCNMatrix4MakeTranslation ((self.mySceneView.pointOfView? .worldPosition.x)!, (self.mySceneView.pointOfView? .worldPosition.y) !, (self.mySceneView.pointOfView? la camorbitNodeMatWOTrans = SCNMatrix4Mult (self.mySceneView.pointOfView! .worldTransform, SCNMatrix4Invert (camorbitNodeTransMat)) selectedNode.transform = SCNMatrix4Mult (selectedNode.transform, SCNMatrix4Invert (camorbitNodeMatWOTrans)) selectedNode.transform = SCNMatrix4Mult (selectedNode.transform, rotMat) selectedNode.transform = SCNMatrix4Mult (selectedNode.transform, camorbitNodeMatWOTrans) selectedNode.transform = SCNMatrix4Mult (selectedNode.transform, SCNMatrix4Invert (parentNodeMatWOTrans)) selectedNode.transform = SCNMatrix4Mult (selectedNode.transform, transMat) } } @objc func doHandleTap (_ sender: ExitGestureRecognizer) { leave p = sender.location (in: self.mySceneView) was hitResults = self.mySceneView.hitTest (p, options: zero) if (p.x> self.mySceneView.frame.size.width-100 || p.y < 100) { self.mySceneView.allowsCameraControl = !self.mySceneView.allowsCameraControl } if hitResults.count > 0 { leave the result = hitResults [0] la material = result.node.geometry? .firstMaterial selectedNode = result.node SCNTransaction.start () SCNTransaction.animationDuration = 0.3 SCNTransaction.completionBlock = { SCNTransaction.start () SCNTransaction.animationDuration = 0.3 SCNTransaction.commit () } material? .emission.contents = UIColor.white SCNTransaction.commit () } }

My question is:

Can we put any 3D object model Aspect fits in screen size in the middle of the screen? Please suggest there is something for it.

Any guidelines or suggestions will be appreciated.


Source link