scenekit, how to bend an object

2019-06-09 09:59发布

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?

标签: 3d scenekit
2条回答
Lonely孤独者°
2楼-- · 2019-06-09 10:50

SCNBox has a heightSegmentCount 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:

float offset = _geometry.color.x * (sin(1.2 * u_time + (_geometry.position.x + _geometry.position.z) * 4.0) + 0.5) * 0.02;
_geometry.position.x += offset;
_geometry.color.xyz = vec3(1.0);

Bending weights are baked in the vertex color (SCNGeometrySourceSemanticColor, but you could also use texture coordinates) which is later reset to 1.0 so that they doesn't affect the final color of the geometry.

查看更多
戒情不戒烟
3楼-- · 2019-06-09 11:01

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.

查看更多
登录 后发表回答