I have been busy to make an application to show OBJ models dynamically with ARKit in swift4. The current problem is whenever I load a model in the application I get wrong direction. one model is upside down, the other is etc ... Below is one example of the problem. As you could see the model should be rotated something like 90 degree around X axis but as I mentioned earlier each model has its own problem.
Could someone help me to solve this?
Update: I am using this framework https://github.com/prolificinteractive/SamMitiAR-iOS I load the model like this:
let virtualObject = SamMitiVirtualObject(refferenceNode: SCNReferenceNode.init(url:modelUrl as URL)! , allowedAlignments: [.horizontal])
and then:
virtualObjectLoader.loadVirtualObject(virtualObject) { loadedObject in
loadedObject.scaleRange = (0.00001)...0.0002
self.sceneView.currentVirtualObject = loadedObject
self.sceneView.currentVirtualObject?.contentNode?.opacity = 0
SceneKitAnimator.animateWithDuration(duration: 0.35, animations: {
self.sceneView.currentVirtualObject?.contentNode?.opacity = 1
})
and this the viewDidLoad
override func viewDidLoad() {
super.viewDidLoad()
sceneView.placingMode = .focusNode
sceneView.samMitiARDelegate = self
sceneView.isAutoFocusEnabled = false
sceneView.isLightingIntensityAutomaticallyUpdated = true
if #available(iOS 12.0, *) {
sceneView.environmentTexturing = .automatic
sceneView.lightingEnvironmentContent = nil
sceneView.baseLightingEnvironmentIntensity = 6
} else {
sceneView.environmentTexturing = .none
sceneView.lightingEnvironmentContent = "art.scnassets/hdr-room.jpg"
sceneView.baseLightingEnvironmentIntensity = 1.5
}
sceneView.initialPreviewObjectOpacity = 0.667
sceneView.initialPreviewObjectMaxSizeRatio = CGSize(width: 0.667, height: 0.667)
sceneView.allowedGestureTypes = [.tap, .pan, .rotation, .pinch]
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
initializeSamMiti()
}
override func viewDidAppear(_ animated: Bool) {
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
// Pause the view's AR session.
sceneView.session.pause()
}
@IBAction func crossButtonDidTouch(_ sender: Any) {
print("close button got touched")
dismiss(animated: true, completion: nil)
}
extension ARViewController: SamMitiARDelegate {
/// Example of using delegate for haptic feedback when object was placed
func samMitiViewDidPlace(_ virtualObject: SamMitiVirtualObject) {
let generator = UIImpactFeedbackGenerator(style: .light)
generator.impactOccurred()
}
/// Example of using delegate for haptic feedback when object scaling is snapped
@objc(samMitiVirtualObject:didSnapToScalingFactor:) func samMitiVirtualObject(_ virtualObject: SamMitiVirtualObject, didSnapToScalingFactor didSnappedToScalingFactor: Float) {
let generator = UIImpactFeedbackGenerator(style: .light)
generator.impactOccurred()
}
/// Example of using delegate for haptic feedback when scaling to bound
func samMitiVirtualObject(_ virtualObject: SamMitiVirtualObject, didScaleToBound: Float) {
let generator = UIImpactFeedbackGenerator(style: .light)
generator.impactOccurred()
}