I am loading one .obj model in Scenekit. When I trying to load small model like (Water bottle), it works very well. But when I am trying to load bigger models ( Like Sofa, Table), it loads perfectly, but going out of boundary from scene.
Is there any way in Scenekit, where we can load the model in scenekit regardless, how big the model is. It should be fitted in the Scene properly. Please have a look on attached screenshots for better idea.
Let me know, if you can provide me some hints to resize it.
let url = "https://s3.ap-south-1.amazonaws.com/p9-platform/product/ccbb5daa-982d-4fa1-b475-971453534686.obj"
let asset = MDLAsset(url: url as URL)
let scene = SCNScene(mdlAsset: asset)
let mesh = asset.object(at:0) as! MDLMesh
let vertexBuffer = mesh.vertexBuffers[0]
let descripter = mesh.vertexDescriptor
let submeshes = mesh.submeshes
for index in 0...(submeshes?.count)! - 1{
let submesh0 = submeshes![index] as! MDLSubmesh
let singleMesh = MDLMesh(vertexBuffer: vertexBuffer, vertexCount: mesh.vertexCount, descriptor: descripter, submeshes: [submesh0])
let geometry = SCNGeometry(mdlMesh: singleMesh)
let Node = SCNNode(geometry: geometry)
let submeshname = submesh0.material?.name as! String
let materialname = "_\(submeshname)" as! String
let nodename = submesh0.name as! String
let revisedName = nodename.replacingOccurrences(of: materialname, with: "")
Node.name = revisedName
scene.rootNode.addChildNode(Node)
}
An SCNNode
has a scale property. I have encountered this issue before, and basically ti just happens when the model is created in a program such as Maya or Blender. The author has made it big so that they can make it more detailed and intricate.
Anyway, what you can try is this:
Node.scale = SCNVector3(0.001, 0.001, 0.001)
Node
should not begin with a capital letter either ^_________^