|
|
@@ -9,17 +9,34 @@ import {
|
|
|
} from 'three';
|
|
|
|
|
|
/**
|
|
|
- * Port of http://webglsamples.org/blob/blob.html
|
|
|
+ * A marching cubes implementation.
|
|
|
+ *
|
|
|
+ * Port of: {@link http://webglsamples.org/blob/blob.html}
|
|
|
*/
|
|
|
-
|
|
|
class MarchingCubes extends Mesh {
|
|
|
|
|
|
+ /**
|
|
|
+ * Constructs a new marching cubes instance.
|
|
|
+ *
|
|
|
+ * @param {number} resolution - The effect's resolution.
|
|
|
+ * @param {Material} material - The cube's material.
|
|
|
+ * @param {boolean} [enableUvs=false] - Whether texture coordinates should be animated or not.
|
|
|
+ * @param {boolean} [enableColors=false] - Whether colors should be animated or not.
|
|
|
+ * @param {boolean} [maxPolyCount=10000] - The maximum size of the geometry buffers.
|
|
|
+ */
|
|
|
constructor( resolution, material, enableUvs = false, enableColors = false, maxPolyCount = 10000 ) {
|
|
|
|
|
|
const geometry = new BufferGeometry();
|
|
|
|
|
|
super( geometry, material );
|
|
|
|
|
|
+ /**
|
|
|
+ * This flag can be used for type testing.
|
|
|
+ *
|
|
|
+ * @type {boolean}
|
|
|
+ * @readonly
|
|
|
+ * @default true
|
|
|
+ */
|
|
|
this.isMarchingCubes = true;
|
|
|
|
|
|
const scope = this;
|
|
|
@@ -30,7 +47,20 @@ class MarchingCubes extends Mesh {
|
|
|
const nlist = new Float32Array( 12 * 3 );
|
|
|
const clist = new Float32Array( 12 * 3 );
|
|
|
|
|
|
+ /**
|
|
|
+ * Whether texture coordinates should be animated or not.
|
|
|
+ *
|
|
|
+ * @type {boolean}
|
|
|
+ * @default false
|
|
|
+ */
|
|
|
this.enableUvs = enableUvs;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Whether colors should be animated or not.
|
|
|
+ *
|
|
|
+ * @type {boolean}
|
|
|
+ * @default false
|
|
|
+ */
|
|
|
this.enableColors = enableColors;
|
|
|
|
|
|
// functions have to be object properties
|
|
|
@@ -495,9 +525,17 @@ class MarchingCubes extends Mesh {
|
|
|
// Metaballs
|
|
|
/////////////////////////////////////
|
|
|
|
|
|
- // Adds a reciprocal ball (nice and blobby) that, to be fast, fades to zero after
|
|
|
- // a fixed distance, determined by strength and subtract.
|
|
|
-
|
|
|
+ /**
|
|
|
+ * Adds a reciprocal ball (nice and blobby) that, to be fast, fades to zero after
|
|
|
+ * a fixed distance, determined by strength and subtract.
|
|
|
+ *
|
|
|
+ * @param {number} ballx - The x-coordinate of the ball.
|
|
|
+ * @param {number} bally - The y-coordinate of the ball.
|
|
|
+ * @param {number} ballz - The z-coordinate of the ball.
|
|
|
+ * @param {number} strength - The strength factor.
|
|
|
+ * @param {number} subtract - The subtract factor.
|
|
|
+ * @param {Color} colors - The color.
|
|
|
+ */
|
|
|
this.addBall = function ( ballx, bally, ballz, strength, subtract, colors ) {
|
|
|
|
|
|
const sign = Math.sign( strength );
|
|
|
@@ -598,6 +636,12 @@ class MarchingCubes extends Mesh {
|
|
|
|
|
|
};
|
|
|
|
|
|
+ /**
|
|
|
+ * Adds a plane along the x-axis.
|
|
|
+ *
|
|
|
+ * @param {number} strength - The strength factor.
|
|
|
+ * @param {number} subtract - The subtract factor.
|
|
|
+ */
|
|
|
this.addPlaneX = function ( strength, subtract ) {
|
|
|
|
|
|
// cache attribute lookups
|
|
|
@@ -643,6 +687,12 @@ class MarchingCubes extends Mesh {
|
|
|
|
|
|
};
|
|
|
|
|
|
+ /**
|
|
|
+ * Adds a plane along the y-axis.
|
|
|
+ *
|
|
|
+ * @param {number} strength - The strength factor.
|
|
|
+ * @param {number} subtract - The subtract factor.
|
|
|
+ */
|
|
|
this.addPlaneY = function ( strength, subtract ) {
|
|
|
|
|
|
// cache attribute lookups
|
|
|
@@ -687,6 +737,12 @@ class MarchingCubes extends Mesh {
|
|
|
|
|
|
};
|
|
|
|
|
|
+ /**
|
|
|
+ * Adds a plane along the z-axis.
|
|
|
+ *
|
|
|
+ * @param {number} strength - The strength factor.
|
|
|
+ * @param {number} subtract - The subtract factor.
|
|
|
+ */
|
|
|
this.addPlaneZ = function ( strength, subtract ) {
|
|
|
|
|
|
// cache attribute lookups
|
|
|
@@ -735,6 +791,14 @@ class MarchingCubes extends Mesh {
|
|
|
// Updates
|
|
|
/////////////////////////////////////
|
|
|
|
|
|
+ /**
|
|
|
+ * Sets the cell value for the given coordinates.
|
|
|
+ *
|
|
|
+ * @param {number} x - The x value.
|
|
|
+ * @param {number} y - The y value.
|
|
|
+ * @param {number} z - The z value.
|
|
|
+ * @param {number} value - The value to set.
|
|
|
+ */
|
|
|
this.setCell = function ( x, y, z, value ) {
|
|
|
|
|
|
const index = this.size2 * z + this.size * y + x;
|
|
|
@@ -742,6 +806,14 @@ class MarchingCubes extends Mesh {
|
|
|
|
|
|
};
|
|
|
|
|
|
+ /**
|
|
|
+ * Returns the cell value for the given coordinates.
|
|
|
+ *
|
|
|
+ * @param {number} x - The x value.
|
|
|
+ * @param {number} y - The y value.
|
|
|
+ * @param {number} z - The z value.
|
|
|
+ * @return {number} The value.
|
|
|
+ */
|
|
|
this.getCell = function ( x, y, z ) {
|
|
|
|
|
|
const index = this.size2 * z + this.size * y + x;
|
|
|
@@ -749,6 +821,11 @@ class MarchingCubes extends Mesh {
|
|
|
|
|
|
};
|
|
|
|
|
|
+ /**
|
|
|
+ * Applies a blur with the given intensity.
|
|
|
+ *
|
|
|
+ * @param {number} [intensity=1] - The intensity of the blur.
|
|
|
+ */
|
|
|
this.blur = function ( intensity = 1 ) {
|
|
|
|
|
|
const field = this.field;
|
|
|
@@ -802,6 +879,9 @@ class MarchingCubes extends Mesh {
|
|
|
|
|
|
};
|
|
|
|
|
|
+ /**
|
|
|
+ * Resets the effect.
|
|
|
+ */
|
|
|
this.reset = function () {
|
|
|
|
|
|
// wipe the normal cache
|
|
|
@@ -818,6 +898,9 @@ class MarchingCubes extends Mesh {
|
|
|
|
|
|
};
|
|
|
|
|
|
+ /**
|
|
|
+ * Updates the effect.
|
|
|
+ */
|
|
|
this.update = function () {
|
|
|
|
|
|
this.count = 0;
|