I'm new to 3D.
I have a straight stick object which is a SCNBox, and at some stage I want to bend it (with animation). Is there any way to achieve this? Or do I have to use multiple objects to simulate a SCNBox in the first place, and then move and rotate those objects to simulate bending?
SCNBox
has aheightSegmentCount
property that you can use to produce more vertices.Using a shader modifier you'll be able to bend the cube. That's how the grass blades are animated in Fox: Building a SceneKit Game with the Xcode Scene Editor. This can be done right in the SceneKit editor see (Enhancements to SceneKit from WWDC 2015) or programmatically.
edit:
Here is the modifier for the
SCNShaderModifierEntryPointGeometry
entry point:Bending weights are baked in the vertex color (
SCNGeometrySourceSemanticColor
, but you could also use texture coordinates) which is later reset to1.0
so that they doesn't affect the final color of the geometry.You have multiple options, depending on what effect you're after. I don't think you'll be able to do it with just a single
SCNBox
, though.You can design your object in a 3D tool like Blender, Maya, or Cheetah3D. Create an animation within that tool, export the model to Collada/DAE format, and display it in SceneKit. You can then play the animation by name.
You might also be able to use the morphing API. That's slide 34 of the WWDC 2014 SceneKit sample code. The live session is Session 610.
Inverse Kinematics could work for you if you want the end of your stick to touch a particular point. That would involve building IK into your Collada file, or constructing the object programmatically using physics joints.
None of these approaches are beginner-level techniques.