I created a particle system that should act as a spaceship's vehicle fire.
I've added it in a node loaded from a COLLADA file (made with Blender):
let engine = _spaceship.childNode(withName: "Engine", recursively: false)!
let engine_pSystem = SCNParticleSystem(named: "Engine", inDirectory: "art.scnassets")!
engine.addParticleSystem(engine_pSystem)
But the particle system looks black (literally like smoke) from certain angles, while from certain angles it looks normal (like in the scnp file of the image above). This video shows the problem: https://youtu.be/JvNe140C068
Try these settings, or similar to them...
Related
I am working on the game with spaceship flying around earth and destroying objects. I wanted to add some reaction when object hit the spaceship but the contact is detected before it "hit" visual model of the spaceship. I found out that the physicsbody of the node is bigger than visual model. What should I do to set it on the same size?
Here's some more info:
I created model built of many basic shapes/nodes in SceneKit editor in Xcode
I set physics body in the editor with options: dynamic type, default shape, bounding box, scale: 1.
There's part of my code that do something with the ship node:
shipNode = scene.rootNode.childNode(withName: "ship", recursively: true)!
shipNode.physicsBody!.physicsShape = SCNPhysicsShape(node: shipNode, options: nil)
shipNode.physicsBody!.categoryBitMask = 4
screen of UI of my game, with physicsshapes visible
Just to close this out, we should probably mark it as solved;
Before, the spaceship was too big so I changed scale of "ship reference" in main scene. In this situation textures got smaller but physicsbody didn't. After your tip, I changed the size of the ship in original .scn file and it solved all problems
So I purchased a 3D model of a car to display in my ARKIT app.The folder consisted of different model formats and a single image.
I dragged and dropped the .dae file to my project. This is the file structure.
However when adding to the scene the axis would be completely off and not load correctly. It did not load the complete model with textures, and would load above me.
See example:
Then I decided to load the .Blender file in Blender and export again as a colada .dae file.
This was the result when adding to my project.
When loading it in the real world a half car would appear where I stood at a ridiculously large scale.
I have tried the project with a separate model and it worked fine. Does anyone have any ideas how I can work with the 3D Model to load correctly in my app ?
I had some problems scaling models I have purchased. You aren't supposed to post links, but it's too big to paste in - I followed this guide to scale down the models and rotate them into the proper position in blender before exporting.
https://jibransyed.wordpress.com/2014/06/05/how-to-correct-scale-and-rotation-of-static-blender-models-for-unity/
On most models I use this to load:
func loadCollada(sceneName: String, objName: String) -> SCNNode
{
let vScene = SCNScene(named: sceneName)!
let gObject = vScene.rootNode.childNode(withName: objName,
recursively: true)!
return gObject
}
On some larger models, I had to do it this way:
func collada2SCNNode(filepath: String) -> SCNNode
{
let returnNode = SCNNode()
let scene = SCNScene(named: filepath)
for vNode in (scene?.rootNode.childNodes)!
{
returnNode.addChildNode(vNode)
}
return returnNode
}
Then set Y UP:
scntool --convert fighter0.dae --format c3d --output out.dae --force-y-up --force-interleaved --look-for-pvrtc-image
I am trying to work with a dae model, but somehow can't modify the position or scale it at all. Other models work fine though. Can these dae models be locked somehow?
let objScene = SCNScene(named: "art.scnassets/test.dae")!
self.objNode = objScene.rootNode.childNode(withName: "test", recursively: true)
let action = SCNAction.scale(by: 0.25, duration: 1.0)
self.objNode.runAction(action)
self.objNode?.position = SCNVector3(0.0,0.0,-2.0)
self.arSceneView.scene.rootNode.addChildNode(self.objNode!)
This can happen if your Collada file contains animations that target the "test" node.
If you programmatically set the node's position or scale, and then an animation targeting the node's transform is evaluated it will override everything giving the impression that the node can't be modified.
You can always nest a node targeted by an animation under a dummy parent node, that you can freely translate, rotate or scale.
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.
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.