【发布时间】:2014-06-19 10:19:12
【问题描述】:
通常,贝塞尔曲面用作具有 16 个控制点的双三次面片。但是,在 3dsMax 中,可以隐藏内部边缘以防止编辑和计算 automatically(这是它们的默认状态)。这样就只剩下 12 个控制点,这使得编辑更简单。
来自Primitives3D sample project 的 XNA 代码(简化版):
void CreatePatchVertices(Vector3[] patch, int tessellation)
{
Debug.Assert(patch.Length == 16);
for (int i = 0; i <= tessellation; i++)
{
float ti = (float)i / tessellation;
for (int j = 0; j <= tessellation; j++)
{
float tj = (float)j / tessellation;
// Perform four horizontal bezier interpolations
// between the control points of this patch.
Vector3 p1 = Bezier(patch[0], patch[1], patch[2], patch[3], ti);
Vector3 p2 = Bezier(patch[4], patch[5], patch[6], patch[7], ti);
Vector3 p3 = Bezier(patch[8], patch[9], patch[10], patch[11], ti);
Vector3 p4 = Bezier(patch[12], patch[13], patch[14], patch[15], ti);
// Perform a vertical interpolation between the results of the
// previous horizontal interpolations, to compute the position.
Vector3 position = Bezier(p1, p2, p3, p4, tj);
// Perform another four bezier interpolations between the control
// points, but this time vertically rather than horizontally.
Vector3 q1 = Bezier(patch[0], patch[4], patch[8], patch[12], tj);
Vector3 q2 = Bezier(patch[1], patch[5], patch[9], patch[13], tj);
Vector3 q3 = Bezier(patch[2], patch[6], patch[10], patch[14], tj);
Vector3 q4 = Bezier(patch[3], patch[7], patch[11], patch[15], tj);
// Compute vertical and horizontal tangent vectors.
Vector3 tangentA = BezierTangent(p1, p2, p3, p4, tj);
Vector3 tangentB = BezierTangent(q1, q2, q3, q4, ti);
// Cross the two tangent vectors to compute the normal.
Vector3 normal = Vector3.Cross(tangentA, tangentB);
normal.Normalize();
// Create the vertex.
AddVertex(position, normal);
}
}
}
在这个示例中,如何像在 3dsMax 中一样自动计算向量 5、6、9 和 10(patch[5] 等)?
【问题讨论】:
-
我不知道3dsMax是做什么的,但是你试过简单的线性插值吗?
patch[5] = 0.66 * patch[1] + 0.33 * patch[13]等
标签: c# algorithm xna geometry bezier