Reputation: 101
Here is the properties of model that appears fine.
And here is the properties of model that has problems and appears bigger and above the camera view:
Here is my code to insert the model:
func updateUIView(_ uiView: ARView, context: Context) {
// My Custom Class
guard let model = modelConfirmedForPlacement else { return }
if let modelEntity = model.modelEntity {
print("Adding model to scene: \(model.modelName)")
let anchorEntity = AnchorEntity(plane: .any)
let readyModelEntity = modelEntity.clone(recursive: true)
//Add Gestures Support for Model
readyModelEntity.generateCollisionShapes(recursive: true)
anchorEntity.addChild(readyModelEntity)
uiView.scene.addAnchor(anchorEntity)
// Install Gestures
uiView.installGestures([.all], for: readyModelEntity)
} else {
print("Unable to load modelEntity for: \(model.modelName)")
}
DispatchQueue.main.async {
modelConfirmedForPlacement = nil
}
}
Upvotes: 1
Views: 421
Reputation: 58043
Working units of RealityKit and SceneKit are meters
, but default working units of some 3D apps are centimeters
. Your metrics show the size of a huge RealityKit model's bounding box:
SIMD<Float>(x: 54.915, y: 45.507, z: 28.351)
To assign a new scale for an anchor entity or for a model entity (100...200 times smaller) use this:
let anchorEntity = AnchorEntity()
anchorEntity.scale = [1, 1, 1] * 0.01
To control model's position you must take into consideration a location of model's pivot point. Usually you can do it in 3D authoring app (like Maya or Blender) – a position of pivot point should be at a bottom of a model. In case you can't change pivot's position in 3D authoring app, just move a model's corresponding anchor:
anchorEntity.position.y = -0.5
...or if you want to move a model entity use children's deep hierarchy to get to it:
print(modelEntity)
modelEntity.children[0]..........children[0].position.y = -0.5
Upvotes: 1