Scenekit,如何弯曲物体 [英] scenekit, how to bend an object

查看:15
本文介绍了Scenekit,如何弯曲物体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 3D 新手.

我有一个直棒对象,它是一个 SCNBox,在某个阶段我想弯曲它(带动画).有没有办法实现这一目标?或者我必须首先使用多个对象来模拟 SCNBox,然后移动和旋转这些对象来模拟弯曲?

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 有一个 heightSegmentCount 属性,您可以使用它来生成更多顶点.

SCNBox has a heightSegmentCount property that you can use to produce more vertices.

使用着色器修改器,您将能够弯曲立方体.这就是 Fox:使用 Xcode 场景编辑器构建 SceneKit 游戏.这可以直接在 SceneKit 编辑器中完成,请参阅(Enhancements to SceneKit from WWDC2015) 或以编程方式.

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.

这是 SCNShaderModifierEntryPointGeometry 入口点的修饰符:

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);

弯曲权重在顶点颜色中烘焙(SCNGeometrySourceSemanticColor,但您也可以使用纹理坐标),稍后将其重置为 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.

这篇关于Scenekit,如何弯曲物体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆