7

I'm new to SceneKit and 3D objects. I've been doing some research but I didn't find an answer to my question.

I need to display several 3D objects in an horizontal UICollectionView, one in each cell. I'd like them to be aligned and the same size so I'd like them to fit the parent view, aka the SCNView.

An image to picture the scenario:

3D objects, each in a SCNView, all the same size

I'd like that the bounds of the 3D object visually matches the bounds of the SCNView. I want the 3D object to "fit" in the view, a bit like UIViewContentMode.scaleAspectFit.


Here's my code so far:

let scene=SCNScene(named: file_name)
let node=scene.rootNode.childNode(withName: node_name, recursively: true)!
node.scale=SCNVector3Make(28, 28, 28)
node.position=SCNVector3Make(0, 0.05, -0.5)
scene.rootNode.addChildNode(node)
sceneview.scene=scene
Marie Dm
  • 2,637
  • 3
  • 24
  • 43
  • 1
    "I don't know how to link the SCNView bounds and the SCNScene/SCNNode dimensions/position. " I don't precisely understand your question. Yet, your best bet is to position the node at the center of the scene. And your node position does not appear feasible. – El Tomato Sep 08 '17 at 00:41
  • 1
    @ElTomato This is not very clear indeed. I'd like that visually the bounds of the 3D object matches the bounds of the SCNView. I want the 3D object to "fit" in the view, a bit like `UIViewContentMode.scaleAspectFit`. – Marie Dm Sep 08 '17 at 07:29
  • 1
    There is no such content-fit method to my knowledge. I have never heard of an API that lets you draw the scene boundaries, either. – El Tomato Sep 08 '17 at 07:39
  • 1
    @ElTomato So even by scaling the object and changing its position there's no way to achieve that? – Marie Dm Sep 08 '17 at 07:55
  • 1
    I managed to place them quite well. Although it's working on simulator, it's crashing on device. Seems like that several `SCNView` is too heavy. – Marie Dm Sep 08 '17 at 10:56
  • Have you considered using a SpriteKit overlay scene? – Ramy Al Zuhouri Dec 13 '17 at 14:25
  • No, I don't think I ever used a SpriteKit overlay scene. – Marie Dm Dec 14 '17 at 16:33

0 Answers0