Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xiaomao Ding : project 6 #4

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
first couple parts done, working on polygonizing
xnieamo committed Feb 28, 2017
commit 6cdb49504b6af2a0ff29a6076b4f129b3b3be359
32 changes: 30 additions & 2 deletions src/marching_cubes.js
Original file line number Diff line number Diff line change
@@ -144,8 +144,12 @@ export default class MarchingCubes {
// Implement a function that returns the value of the all metaballs influence to a given point.
// Please follow the resources given in the write-up for details.
sample(point) {
// @TODO
var isovalue = 1.1;
this.balls.forEach(function(ball) {
var dist = point.distanceTo(ball.pos);
var influence = (ball.radius * ball.radius) / (dist * dist);
isovalue += influence;
});
return isovalue;
}

@@ -165,6 +169,11 @@ export default class MarchingCubes {
// Sampling the center point
this.voxels[c].center.isovalue = this.sample(this.voxels[c].center.pos);

// Sample corners
for (var i = 0; i < 8; i++) {
this.voxels[c].corners[i].isovalue = this.sample(this.voxels[c].corners[i].pos);
}

// Visualizing grid
if (VISUAL_DEBUG && this.showGrid) {

@@ -174,9 +183,17 @@ export default class MarchingCubes {
} else {
this.voxels[c].hide();
}

this.voxels[c].center.updateLabel(this.camera);
this.voxels[c].corners.forEach((function(corner) {
corner.updateLabel(this.camera);
}).bind(this));

} else {
this.voxels[c].center.clearLabel();
this.voxels[c].corners.forEach(function(corner) {
corner.clearLabel();
});
}
}

@@ -206,7 +223,7 @@ export default class MarchingCubes {
};

makeMesh() {
// @TODO

}

updateMesh() {
@@ -283,6 +300,17 @@ class Voxel {

// Center dot
this.center = new InspectPoint(new THREE.Vector3(x, y, z), 0, VISUAL_DEBUG);

// Corners
this.corners = [];
for (var i = 0; i < 8; i++) {
var x = this.pos.x + Math.pow(-1, (i>>0)&1) * halfGridCellWidth;
var y = this.pos.y + Math.pow(-1, (i>>1)&1) * halfGridCellWidth;
var z = this.pos.z + Math.pow(-1, (i>>2)&1) * halfGridCellWidth;

this.corners[i] = new InspectPoint(new THREE.Vector3(x, y, z), 0, VISUAL_DEBUG);
console.log(this.corners[i]);
}
}

show() {
18 changes: 17 additions & 1 deletion src/metaball.js
Original file line number Diff line number Diff line change
@@ -41,6 +41,22 @@ export default class Metaball {
};

update() {
// @TODO
// Check if out of bounds. If so, reverse velocity
var margin = 1.0;
if ((this.pos.x - this.radius) < 0 + margin || (this.pos.x + this.radius) > this.gridWidth - margin) {
this.vel = new THREE.Vector3(-this.vel.x, this.vel.y, this.vel.z);
}
if ((this.pos.y - this.radius) < 0 + margin || (this.pos.y + this.radius) > this.gridWidth - margin) {
this.vel = new THREE.Vector3(this.vel.x, -this.vel.y, this.vel.z);
}
if ((this.pos.z - this.radius) < 0 + margin || (this.pos.z + this.radius) > this.gridWidth - margin) {
this.vel = new THREE.Vector3(this.vel.x, this.vel.y, -this.vel.z);
}

// Update velocity
this.pos = new THREE.Vector3(this.vel.x + this.pos.x, this.vel.y + this.pos.y, this.vel.z + this.pos.z);
if (this.mesh) {
this.mesh.position.set(this.pos.x, this.pos.y, this.pos.z);
}
}
}