Skip to content

Instantly share code, notes, and snippets.

@rngtm
Last active February 1, 2021 12:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rngtm/12de01b42e5fa67ffe79109eb33585a5 to your computer and use it in GitHub Desktop.
Save rngtm/12de01b42e5fa67ffe79109eb33585a5 to your computer and use it in GitHub Desktop.
Houdini VEX でメビウスの輪
// tの分割数
int tDiv = 200;
// r
float rMin = -1; // rの最小値
float rMax = 1; // rの最大値
int rDiv = 2; // rの分割数
// t
float tMin = 0; // tの最小値
float tMax = 3 * $PI; // tの最大値
// メビウスの輪の座標計算
vector mobiusPoint(float r; float t){
float x = (r * cos(t) + 2) * cos(2 * t);
float y = (r * cos(t) + 2) * sin(2 * t);
float z = r * sin(t);
return set(x, y, z);
}
// メビウスの輪の頂点を計算
int mobiusPoints[] = {};
vector vertexColors[] = {};
for (int ti = 0; ti < tDiv; ti++) {
float tLerp = float(ti % tDiv) / (tDiv);
float t = lerp(tMin, tMax, tLerp);
for (int ri = 0; ri < rDiv; ri++) {
float rLerp = float(ri) / (rDiv);
float r = lerp(rMin, rMax, rLerp);
vector p = mobiusPoint(r, t);
int pt = addpoint(geoself(), p);
append(mobiusPoints, pt);
}
}
// 計算した頂点からメッシュを作成する
int ptNum = len(mobiusPoints);
int pt = 0;
for (int ti = 0; ti < tDiv - 1; ti++) {
int points[] = {};
// triangle 1
append(points, mobiusPoints[(pt + 0) % ptNum]);
append(points, mobiusPoints[(pt + 1) % ptNum]);
append(points, mobiusPoints[(pt + 2) % ptNum]);
// triangle 2
append(points, mobiusPoints[(pt + 1) % ptNum]);
append(points, mobiusPoints[(pt + 3) % ptNum]);
append(points, mobiusPoints[(pt + 2) % ptNum]);
addprim(geoself(), "poly", points);
pt += 2;
}
@rngtm
Copy link
Author

rngtm commented Feb 1, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment