1

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?

enter image description here

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()
}
Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
Sia
  • 63
  • 1
  • 9
  • Please edit your question and post relevant code – Vadim Kotov Oct 01 '19 at 14:53
  • @Sia, sorry, it's not all, it's code snippets. What a `config` is? Where's scene nodes' hierarchy? – Andy Jazz Oct 01 '19 at 21:29
  • @ARGeo cold you please let me know what do you need exactly, then I could find it in the platform. I just handover the path to the platform and the platform does what it does. – Sia Oct 02 '19 at 11:21
  • @Sia, show us all your code: content of renderer() methods, content of viewWillAppear(), etc... Is you code in written in Xcode or is it from Unity (wrapped ARKit SDK in C# script) ? – Andy Jazz Oct 02 '19 at 12:44
  • @ArgGeo thanks for the replay, I really need this to be done. your help means so much to me. Could I send the code to you? it is written in Xcode with swift4. it is a very simple application with 2 controllers. – Sia Oct 02 '19 at 13:03
  • 1
    @ArGeo I just updated the code – Sia Oct 02 '19 at 13:10
  • @Sia can you share your code please How you can load 3d models from remote url – Gangireddy Rami Reddy Jan 22 '20 at 12:40

1 Answers1

0

I have downloaded SamMiti-iOS Xcode project from GitHub and tested it. With a source code Utah Teapot SamMiti-iOS app works fine. I think the problem lies in your 3D model.

So you need to open your model in Xcode's Scene graph and rotate/scale it appropriately.

enter image description here

Select a model in Project Navigator (left panel), then go to Show the Node inspector (right panel) and rotate it about X axis. To show / hide a Scene Graph View use little rectangular button at a very bottom of Viewport.

Also you can do it programmatically:

private func initializeModel() {

    let virtualObject = SamMitiVirtualObject(refferenceNode: SCNReferenceNode(named: "art.scnassets/nameOfModel.scn")!,
                                          allowedAlignments: [.horizontal])

    // retrieving a model
    let yourModel = scene.rootNode.childNode(withName: "nameOfModelInSceneGraph",
                                          recursively: true)!
    yourModel.rotation.x = -90

    // ....
}
Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
  • yeah this works with the teapot but the model that the client has provided to us gets shown upside down. looking to the fact that the model is obj-mtl model. how to rotate it with Xcode? could you help me please? – Sia Oct 02 '19 at 15:09
  • Well I have done this how to save the model. The problem is the model should be saved and zipped and upload on the server. if I can do this manually by Xcode and save it , then I have a solution. – Sia Oct 02 '19 at 15:27
  • you have the code right. where should I get the scene there? is this self.sceneView in the initializeModel()? – Sia Oct 02 '19 at 15:31
  • I have done this virtualObject.rotation.x = -90 in ininitializeModel() no success! – Sia Oct 02 '19 at 15:45
  • If I want to go with manual change in Xcode, which camera is important? front or perspective? and how to save the changes? – Sia Oct 02 '19 at 15:51
  • I changed Scene graph as you showed in the picture but whenever I want to save it says "the documnets "xxxx.obj"" can not be saved! – Sia Oct 02 '19 at 16:12
  • What about programmatic approach? – Andy Jazz Oct 02 '19 at 16:18
  • I have done this virtualObject.rotation.x = -90 no success :( – Sia Oct 02 '19 at 16:20
  • Try another axis. – Andy Jazz Oct 02 '19 at 16:23
  • tried all of them, even something like self.sceneView.currentVirtualObject?.rotation.y = -90 but not even a bit of rotation – Sia Oct 02 '19 at 16:31
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/200313/discussion-between-sia-and-argeo). – Sia Oct 02 '19 at 17:58
  • @AndyFedo please guide how i can load 3d models from remote url – Gangireddy Rami Reddy Jan 22 '20 at 12:41
  • @GangiReddyRamiReddy, publish a new question, please, I'll try to respond during the day. And paste here a link. – Andy Jazz Jan 22 '20 at 12:56
  • 1
    @AndyFedo Thanks for your replay i published a new question in this below link please guide me how can i achieve that once.Thanks advance https://stackoverflow.com/q/59860657/7642568 – Gangireddy Rami Reddy Jan 22 '20 at 13:19
  • @GangiReddyRamiReddy, got it. – Andy Jazz Jan 22 '20 at 13:21