I have a scene.scn file which contains a car.dae model. Here is the image:
I have the following code to load the scene.
override func viewDidLoad() {
super.viewDidLoad()
// Set the view's delegate
sceneView.delegate = self
// Show statistics such as fps and timing information
sceneView.showsStatistics = true
// Create a new scene
let scene = SCNScene(named: "art.scnassets/scene.scn")!
// Set the scene to the view
sceneView.scene = scene
}
I do not see the car being loading in the scene. Any ideas?
The following workflow produces repeatable results for me when exporting a 3D model from SketchUp Make 2017 (I use the Simple Template - Meters for drawing) to Xcode 9.0:
In Xcode, create a SceneKit asset catalog: Create an assets catalog and change the extension to .scnassets before saving.
In Xcode, in the asset catalog Settings, ensure that Always use the Y-up axis is not checked. This setting is buggy; while it works during runtime, it isn't taken into account by the Scene Editor.
In SketchUp, export the model using Export 3D Model... and select the file format COLLADA File (*.dae). Export it to the .scnassets folder of the asset catalog (or a subfolder thereof).
Hint: If you export somewhere else, use the Finder to copy or move the files. Don't drag-and-drop the exported model to Xcode, as it would only create a reference to the model and you would lose the textures on the way, as they are referenced in the .dae file by a relative path.
In Xcode, create a SceneKit Scene File: First, select the project and create a New file with the template SceneKit Scene File there; Save it in the .scnassets folder; Then delete the file (Remove reference) from your project, so that it is referenced only in the .scnassets folder.
Hint: You can't create a .scn file directly in the asset catalog, as the New file feature creates an empty file that the Scene Editor won't recognize, even if you rename it with the .scn extension.
Embed the .dae file in the scene and fix the axes:
a. Open the .scn file.
b. Drag-and-drop the .dae file to the scene. This creates a reference to the model. Ensure that the reference to the model is selected.
c. In the Node Inspector, under Transforms, select the Editing space: Local.
d. Set the local Position to x: 0, y: 0, z: 0 (or whatever position is needed).
e. Set the local Euler angles to x: -90, y: 0, z: 0. Now, the object is oriented as expected, e.g. its front is displayed when the point of view Front is selected in the toolbar at the bottom of the scene editor.
f. Set the local Scale to x: 0.0254, y: 0.0254, z: 0.0254. I assume that the .dae file import expects sizes in inches.
g. Still in the Node Inspector, under Transforms, select the Editing space: World. Check the size of the Bounding Box. I assume that meters are used as measurement unit here. Save the changes.
There's a flag in Xcode's scnassets inspector to set which axis is "up". In SceneKit, Y is up. IIRC SketchUp uses Z up by default.
Tip: I found for all the collada (dae) models created by SketchUp you need to adjust the Euler x-axis to -90 in the scene editor
In order to get the model the right way up when you load it.
Related
This would be working perfectly if it weren't for one aspect of what is going on. When I add the texture to the object (drag and drop it onto the object from the menu in the bottom right) it adds it exactly where I want, but it also adds it around the object large (too large for the object) and all blurred, and I want it to just stay white:
Before:
After:
I want it to stay in the middle where it is, and have the surrounding area be the original color of the shirt.
UPDATE
I created a static physics body, and that allowed me to get to the materials of the Plane object. But I can't remove the coloring around the image.
UPDATE
Also, I exported the texture from Blender with Save Image As from Blender UV/Image Editor, I'm not sure if that is the correct way to export a texture to be used correctly in xcode.
UPDATE
I used the .obj file instead and got this far, but when it renders in the app there is no image, only they gray tshirt.
To export a .dae including textures from Blender, make sure to select UV Textures and the Copy checkbox unter Texture Options, in the Export options, during export. Then, in xcode, your texture will be available as a material under the Materials tab, and you just have to drag the image that you were using with the texture, onto the material (make sure you have the correct material selected) in the Scene Editor in Xcode.
I am exporting 3D models from Cinema4D with .dae file format, and drag them into art.scnassets. Every time I compile the project the 3D object are too big or not in the right position. What is the best setting for models which we want to use in iOS ARKit ? I have search many topics and still not a final solution.
Edited :
I have found that if your object is for instance 50cm in cinema, you need to export it as .dae (1.4, important!) and then select 0.001 meters as scale.
Also, make sure that you position the object at 0, 0, 0 (even if you want it positioned somewhere else in the end, centering it will make editing & repositioning in Xcode easier).
After importing, inside Xcode, click on the .dae file. Select the object in the scene, open the right inspector menu and navigate to the identity inspector.
Then press is movable. This will convert the file to .scn which is better for editing. (is movable should still be unchecked after conversion, if not uncheck, or leave as is)
Then, open the new .scn file and click on your object. You'll see its scale on the right in the identity inspector. If it's still not right, you can change the scale of the bounding box there and also position the object in the scene.
I'm trying to understand SCNKit and ARKit a little better and have a barebones Xcode 9 Augmented Reality app deployed and working on my iPhone (which I'm using as a simple test device).
This app's source code is here.
Basically, the app starts, the camera is initialized, and it renders a 3D fighter jet inside the scene (world view) in a similar fashion to how Pokemon Go injects monsters into your camera viewport (wherever your pointing your camera at). Pretty cool!
This code was all auto-generated for me by Xcode. So I'm trying to understand where the logic lives that determines where to position/orient the fighter jet (the SCN file titled art.scnassets/ship.scn). From here we see the jet being loaded:
override func viewDidLoad() {
super.viewDidLoad()
// Set the view's delegate
sceneView.delegate = self
// Show statistics such as fps and timing information
sceneView.showsStatistics = true
// Create a new scene
print("Hello there Mr. Zac")
let scene = SCNScene(named: "art.scnassets/ship.scn")!
// Set the scene to the view
sceneView.scene = scene
}
But I don't understand how the app chooses where to place the jet/ship and to orient it in which direction. I ask because as a first step I'd like to try repositioning the jet and then also swapping it out for my own asset files.
The "logic" for that, such as there is any, lives in two places.
The ship.scn file defines not just a model, but the model's position in the scene. (That is, in a global "world" coordinate space.)
In the scn file that ships in that Xcode project template, the model is positioned at something like 0, 0, -0.5, so if a camera is placed at the origin of the coordinate system, the ship appears directly in front of the camera, half a meter away.
ARKit itself defines scene/world space relative to the initial real-world position/orientation of the device. By default, that coordinate system's z-axis matches the initial orientation of the device, so anything placed "in front of" the coordinate origin will appear in front of the camera when you start the AR session.
If I run Xcode's ARKit project template, I can move around the default ship as expected.
I have tried importing some dae models that I have exported from Blender, switching the ship to the new item but keeping the code the same. They always show in view but position in front the camera. If I try to move around the model it sticks infront of the camera and doesn't stay in the same virtual space.
I have also tried importing a dae from another tutorial and that works as expected.
Does anything need setting when exporting a 3d model as a Collada dae file to make sure it will anchor to a position in ARKit?
When importing 3D-models for ARKit make sure to check:
the scale of your file. One unit equals 1 meter
The model should be centered in the coordinate origin to make it easy to position the model
Try to import the file in the SceneKit editor in Xcode and check if it gets imported correctly.
I'm currently trying to combine the following sources:
Apples SceneKit Vehicle Demo, Resp. its Swift version,
ARKit by example, and resp. its Swift version.
Each project on its own works like a charm (although I changed the vehicle demo so that the car can be controlled by on-screen buttons).
Now, when I try to combine both projects to create an augmented reality racing game, I run into problems regarding the size of the .dae model of the car: it's too big.
I can scale the model using the (chassis) nodes .scale property, but as soon as I add the SCNPhysicsVehicle properties and behaviour, the car gets reset(?) to its original size. I tried to scale the model in Xcode (open dae file, change scale), but its bounding box remains the same - that tells me that the rescaling didn't work properly.
Any hints?
1)you can scale the dae models by art.scnassets directly.
art.scnassets -> car.dae -> node inspector -> transforms -> scale the object
2) can scale 3dmodel by SCNAction
let scene = SCNScene(named: "art.scnassets/cup.dae")!
let node = scene.rootNode.childNode(withName: "cup", recursively: true)!
let action = SCNAction.scale(by: sender.scale, duration: 1.0)
node.runAction(action)
What I like to do is use Blender or some other 3d modeling program to resize your dae model to work in meters. Everything in ARKit is based on meters, so by sticking to the same metric you can get all your models to play well together without having to guess what the scale factor needs to be.
I'm not sure how to fix the model directly in Xcode. However, you can fix it in blender. Start by importing the object into blender. Select the object and observe it's dimensions. Scale the object to the desired dimensions and apply them by hittin Ctrl + A, and selecting scale. Alternatively, from the object menu, you can select Apply -> Scale. Now you can export your model with the corrected size.