Houdini VEX : 立方体を作る
code:c
vector positions[] = {
{-halfSideLength, -halfSideLength, -halfSideLength},
{ halfSideLength, -halfSideLength, -halfSideLength},
{ halfSideLength, -halfSideLength, halfSideLength},
{-halfSideLength, -halfSideLength, halfSideLength},
{-halfSideLength, halfSideLength, -halfSideLength},
{ halfSideLength, halfSideLength, -halfSideLength},
{ halfSideLength, halfSideLength, halfSideLength},
{-halfSideLength, halfSideLength, halfSideLength}
};
int vertexIndices[] = {
0, 1, 2, 3,
4, 5, 6, 7,
0, 1, 5, 4,
1, 2, 6, 5,
2, 3, 7, 6,
3, 0, 4, 7
};
int arrayCount = len(vertexIndices);
int pointIndices[] = {};
foreach (vector position; positions)
{
int pointIndex = addpoint(0, position);
append(pointIndices, pointIndex);
}
int primIndices[] = {};
for (int i = 0; i < arrayCount; i+= 4)
{
int vertexIndexList[] = vertexIndicesi:i+4:1; int primIndex = addprim(0, "poly", vertexIndexList);
append(primIndices, primIndex);
}
code:c
int points1[];
int points2[];
int points3[];
int points4[];
int points5[];
int points6[];
vector vertices[] = {
{1, -1, 0}, // 0
{-1, -1, 0}, // 1
{-1, 1, 0}, // 2
{1, 1, 0}, // 3
};
foreach(vector v; vertices)
{
append(points1, addpoint(geoself(), set(v.x, v.y, 1)));
append(points2, addpoint(geoself(), set(1, v.x, v.y)));
append(points3, addpoint(geoself(), set(v.y, 1, v.x)));
append(points4, addpoint(geoself(), set(v.y, v.x, -1)));
append(points5, addpoint(geoself(), set(-1, v.y, v.x)));
append(points6, addpoint(geoself(), set(v.x, -1, v.y)));
}
addprim(geoself(), "poly", points1);
addprim(geoself(), "poly", points2);
addprim(geoself(), "poly", points3);
addprim(geoself(), "poly", points4);
addprim(geoself(), "poly", points5);
addprim(geoself(), "poly", points6);
code:c
int points1[]; // z
int points2[]; // z
int points3[]; // y
int points4[]; // y
int points5[]; // x
int points6[]; // x
int p0 = addpoint(geoself(), { 1, 1, -1});
int p1 = addpoint(geoself(), {-1, 1, -1});
int p2 = addpoint(geoself(), {-1, -1, -1});
int p3 = addpoint(geoself(), { 1, -1, -1});
int p4 = addpoint(geoself(), { 1, 1, 1});
int p5 = addpoint(geoself(), {-1, 1, 1});
int p6 = addpoint(geoself(), {-1, -1, 1});
int p7 = addpoint(geoself(), { 1, -1, 1});
function void addPoints(int points[]; int p1; int p2; int p3)
{
append(points, p1);
append(points, p2);
append(points, p3);
}
addPoints(points1, p0, p1, p2);
addPoints(points1, p1, p2, p3);
addprim(geoself(), "poly", points1);
addPoints(points2, p6, p5, p4);
addPoints(points2, p7, p6, p5);
addprim(geoself(), "poly", points2);
addPoints(points3, p4, p1, p0);
addPoints(points3, p4, p5, p1);
addprim(geoself(), "poly", points3);
addPoints(points4, p2, p6, p3);
addPoints(points4, p6, p7, p3);
addprim(geoself(), "poly", points4);
addPoints(points5, p0, p3, p4);
addPoints(points5, p3, p7, p4);
addprim(geoself(), "poly", points5);
addPoints(points6, p2, p1, p5);
addPoints(points6, p2, p5, p6);
addprim(geoself(), "poly", points6);
1辺の長さが2の立方体ができる
https://gyazo.com/1a121ba054a90014adbe75df18288d0e