Skip to content

Instantly share code, notes, and snippets.

@Mathias-Fuchs
Last active February 11, 2020 08:40
Show Gist options
  • Save Mathias-Fuchs/bdf6be61eaa11db268be4157b2b1fee5 to your computer and use it in GitHub Desktop.
Save Mathias-Fuchs/bdf6be61eaa11db268be4157b2b1fee5 to your computer and use it in GitHub Desktop.
Clean cobwesh meshes in three js and Rhino C#.
Mesh M = new Mesh();
int axis_divisions = 100;
int height_divisions = 200;
M.Vertices.Capacity = axis_divisions * height_divisions;
M.Faces.Capacity = 2 * (axis_divisions * (height_divisions - 1));
for (int th = 0; th < axis_divisions; th++)
{
double x = Math.Cos(2.0 * Math.PI * th / (double) axis_divisions);
double y = Math.Sin(2.0 * Math.PI * th / (double) axis_divisions);
for (int h = 0; h < height_divisions; h++)
{
double z = (0.1 + (double) h / (double) (height_divisions - 1)) / 1.1;
M.Vertices.Add(z * x, z * y, 0);
}
}
for (int th = 0; th < axis_divisions; th++)
{
for (int h = 1; h < height_divisions; h++)
{
M.Faces.AddFace(
((th + 0) % axis_divisions) * height_divisions + (h - 1),
((th + 1) % axis_divisions) * height_divisions + (h - 1),
((th + 0) % axis_divisions) * height_divisions + (h + 0)
);
M.Faces.AddFace(
((th + 1) % axis_divisions) * height_divisions + (h - 1),
((th + 1) % axis_divisions) * height_divisions + (h + 0),
((th + 0) % axis_divisions) * height_divisions + (h + 0)
);
}
}
var M = new THREE.Geometry();
var axis_divisions = 100;
var height_divisions = 200;
for (var th = 0; th < axis_divisions; th++)
{
var x = Math.cos(2.0 * Math.PI * th / axis_divisions);
var y = Math.sin(2.0 * Math.PI * th / axis_divisions);
for (var h = 0; h < height_divisions; h++)
{
var z = (0.1 + h / (height_divisions - 1)) / 1.1;
M.vertices.push(new THREE.Vector3(z * x, z * y, 0));
}
}
for (th = 0; th < axis_divisions; th++)
{
for (h = 1; h < height_divisions; h++)
{
M.faces.push(
new THREE.Face3(
((th + 0) % axis_divisions) * height_divisions + (h - 1),
((th + 1) % axis_divisions) * height_divisions + (h - 1),
((th + 0) % axis_divisions) * height_divisions + (h + 0)
));
M.faces.push(
new THREE.Face3(
((th + 1) % axis_divisions) * height_divisions + (h - 1),
((th + 1) % axis_divisions) * height_divisions + (h + 0),
((th + 0) % axis_divisions) * height_divisions + (h + 0)
));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment