Instantly share code, notes, and snippets.
View chaht01's full-sized avatar
π―
Focusing
Tak Cha chaht01
π―
Focusing
Present Visual Insight by layering trivial things around us
- Seoul, Korea
- http://www.hyuntak.com
chaht01
/ Gradient.js
Last active
May 1, 2019 00:35
This file contains hidden or 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
module.exports = NUM_METABALLS => {
return `
uniform sampler2D texture;
uniform vec4 metaballs[${NUM_METABALLS}];
uniform float metaball_opacity[${NUM_METABALLS}];
uniform float u_image_ratio;
uniform vec2 u_resolution;
uniform float u_ratio;
uniform float u_scale;
uniform float zoom;
chaht01
/ alpha_vertex.js
Created
April 30, 2019 06:12
This file contains hidden or 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
let subGeo = subMarchingCube.geo; // Assume this is THREE.Geometry instance
let submesh = new THREE.Mesh(
subGeo,
new THREE.ShaderMaterial({
subGeo,
new THREE.ShaderMaterial({
vertexShader: `
varying vec3 vColor;
attribute float opacity;
varying float vOpacity;
chaht01
/ getPosOfUniv.js
Last active
April 30, 2019 08:16
This file contains hidden or 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
function getPosOfLocal(start, dest, local_scale, dest_center) {
const abs_dist = start - dest;
const half_subWorld = local_scale * 0.5 * 2;
const jump_cnt = abs_dist / half_subWorld;
return new THREE.Vector3(
0.5 * (1 - jump_cnt),
dest_center.y,
dest_center.z
);
}
chaht01
/ getPosOf.js
Last active
April 30, 2019 08:16
This file contains hidden or 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
function getPosOfMainInSubWorld() {
const abs_dist = cube_pos.sub - cube_pos.main;
const half_subWorld = cube_scale.sub * 0.5 * 2; // ASSUME marching cube width is 2.
const jump_cnt = abs_dist / half_subWorld;
return new THREE.Vector3(
0.5 * (1 - jump_cnt),
cube_center.main.y,
cube_center.main.z
);
}
chaht01
/ multi-marching-cubes.js
Created
April 30, 2019 04:08
This file contains hidden or 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
[...Array(effectController.numBlobs).keys()].map(i => {
const { x, y, z } = cube_center.main;
mainMarchingCube
.getObject()
.addBall(
x,
y,
z,
ball_options.main.strengths[i] /
This file contains hidden or 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
var copyblobs = []; // To render outside of Marching Cubes
var scale = 200; // Allocate 200*200*200 in the center of screen
...
for (let i = 0; i < effectController.numBlobs; i++) {
let blobx, bloby, blobz;
let subtract, strength;
// blob classifier
chaht01
/ setup.diff
Last active
April 29, 2019 09:50
This file contains hidden or 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
@@ -14,6 +15,7 @@ THREE.MarchingCubes = function ( resolution, material, enableUvs, enableColors )
var vlist = new Float32Array( 12 * 3 );
var nlist = new Float32Array( 12 * 3 );
+ var clist = new Float32Array( 12 * 3 );
@@ -45,6 +47,7 @@ THREE.MarchingCubes = function ( resolution, material, enableUvs, enableColors )
this.field = new Float32Array( this.size3 );
this.normal_cache = new Float32Array( this.size3 * 3 );
+ this.palette = new Float32Array( this.size3 * 3 );
chaht01
/ posnormtriv.diff
Created
April 29, 2019 09:13
This file contains hidden or 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
@@ -398,17 +479,17 @@ THREE.MarchingCubes = function ( resolution, material, enableUvs, enableColors )
if ( scope.enableColors ) {
- scope.colorArray[ c + 0 ] = pos[ o1 + 0 ];
- scope.colorArray[ c + 1 ] = pos[ o1 + 1 ];
- scope.colorArray[ c + 2 ] = pos[ o1 + 2 ];
+ scope.colorArray[ c + 0 ] = colors[ o1 + 0 ];
+ scope.colorArray[ c + 1 ] = colors[ o1 + 1 ];
+ scope.colorArray[ c + 2 ] = colors[ o1 + 2 ];
chaht01
/ palette.diff
Last active
April 29, 2019 09:51
This file contains hidden or 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
@@ -484,10 +565,36 @@ THREE.MarchingCubes = function ( resolution, material, enableUvs, enableColors )
- this.addBall = function ( ballx, bally, ballz, strength, subtract ) {
+ this.addBall = function ( ballx, bally, ballz, strength, subtract, colors ) {
@@ -530,7 +641,22 @@ THREE.MarchingCubes = function ( resolution, material, enableUvs, enableColors )
- if ( val > 0.0 ) this.field[ y_offset + x ] += val * sign;
+ if ( val > 0.0 ) {
+
chaht01
/ marchingcube.diff
Created
April 29, 2019 09:12
This file contains hidden or 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
@@ -14,6 +15,7 @@ THREE.MarchingCubes = function ( resolution, material, enableUvs, enableColors )
var vlist = new Float32Array( 12 * 3 );
var nlist = new Float32Array( 12 * 3 );
+ var clist = new Float32Array( 12 * 3 );
@@ -45,6 +47,7 @@ THREE.MarchingCubes = function ( resolution, material, enableUvs, enableColors )
this.field = new Float32Array( this.size3 );
this.normal_cache = new Float32Array( this.size3 * 3 );
+ this.palette = new Float32Array( this.size3 * 4 );
NewerOlder