Created
February 16, 2021 09:52
-
-
Save 4DA/e4b272728f18b7faf158214af92c91ac to your computer and use it in GitHub Desktop.
Create triangualized Goursat surface using Mikola's isosurface lib
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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