Skip to content

Instantly share code, notes, and snippets.

@4DA
Created February 16, 2021 09:52
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 4DA/e4b272728f18b7faf158214af92c91ac to your computer and use it in GitHub Desktop.
Save 4DA/e4b272728f18b7faf158214af92c91ac to your computer and use it in GitHub Desktop.
Create triangualized Goursat surface using Mikola's isosurface lib
fs = require('fs');
var isosurface = require("isosurface")
var mesh = isosurface.surfaceNets([100,100,100], function(x,y,z) {
return Math.pow(x,4) + Math.pow(y,4) + Math.pow(z,4) - 1.5 * (x*x + y*y + z*z) + 1;
} , [[-2,-2,-2], [2,2,2]])
output = "";
for(i = 0; i < mesh.positions.length; i++) {
next = `v ${mesh.positions[i][0]} ${mesh.positions[i][1]} ${mesh.positions[i][2]}`
output = output.concat(next).concat("\n")
}
output = output.concat("\n")
for(i = 0; i < mesh.cells.length; i++) {
next = `f ${1 + mesh.cells[i][0]} ${1 + mesh.cells[i][1]} ${1 + mesh.cells[i][2]}`
output = output.concat(next).concat("\n")
}
console.log(output)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment