I have been attempting to create an applet that displays various types of space quadrics using the Marching Cubes library from three.js to render implicit surfaces. However, the shapes that are being generated do not appear as expected, leading me to believe that I may not be utilizing the properties of THREE.MarchingCubes
correctly. The main part of the applet includes the following code snippet:
quadricData = {
a11: 1,
a22: 1,
a33: 1,
a12: 0,
a13: 0,
a23: 0,
a1: 0,
a2: 0,
a3: 0,
a: -1
};
quadValue = function (data, x, y, z) {
return data.a11*x*x+
data.a22*y*y+
data.a33*z*z+
data.a12*2*x*y+
data.a13*2*x*z+
data.a23*2*y*z+
data.a1*x+
data.a2*y+
data.a3*z+
data.a;
}
var res = 50;
var material = new THREE.MeshPhongMaterial( {
color: '#1565C0', // blue 800
transparent: true,
opacity: 0.8,
side: THREE.DoubleSide,
flatShading: true
} );
quadric = new THREE.MarchingCubes( res, material );
quadric.isolation = 0;
for ( var k = 0 ; k < res ; k++ ) {
for ( var j = 0 ; j < res ; j++ ) {
for ( var i = 0 ; i < res ; i++ ) {
var x = 8*(i-res/2)/res;
var y = 8*(j-res/2)/res;
var z = 8*(k-res/2)/res;
quadric.field[ i + j*res + k*res*res ] = quadValue(quadricData,x,y,z);
}
}
}
For the complete code, you can visit here. It seems that the 'field' attribute needs to be populated with values from a function, but this may not be the correct approach. Odd effects occur, like an ellipsoid expanding when a11
is increased instead of shrinking. The 'marching cubes grid' also appears to expand, which is quite amusing.
https://i.sstatic.net/y1pja.gif
Several other configurations do not produce the expected results. What is the proper way to utilize THREE.MarchingCubes
?