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

CSG optimizations for animation #39

Open
fabiencomte opened this issue Aug 18, 2017 · 0 comments
Open

CSG optimizations for animation #39

fabiencomte opened this issue Aug 18, 2017 · 0 comments

Comments

@fabiencomte
Copy link

Hello,
I want to create an animation where an object is subtracted with a box but csg is a bit slow to do what i want.

The object is not moving but the box does. i wanted to add the possibility to move box csg without recreate it each time but it doesn t work. Could you look at this code please ?

`ThreeBSP.prototype.transform = function(transformation_matrix) {
var i, j,
polygons = this.tree.polygons/.allPolygons()/,
polygon_count = polygons.length,
polygon, polygon_vertice_count;

		var transformation_matrix_elements = transformation_matrix.elements;


	for ( i = 0; i < polygon_count; i++ ) {
		polygon = polygons[i];
		polygon_vertice_count = polygon.vertices.length;
		for ( j = 0; j < polygon_vertice_count; j++ ) {
			polygon.vertices[j].applyMatrix4_2(transformation_matrix_elements);
			
			polygon.calculateProperties();
		}
	}

	console.log(polygons[0].vertices[0].x + " " + polygons[0].vertices[0].y + " " + polygons[0].vertices[0].z);
	
	this.matrix = this.matrix.multiply(transformation_matrix);
	this.tree = new ThreeBSP.Node( polygons );
};

ThreeBSP.Vertex.prototype.applyMatrix4_2 = function ( e ) {

	// input: THREE.Matrix4 affine matrix
	var x = this.x, y = this.y, z = this.z;

	this.x = e[0] * x + e[4] * y + e[8]  * z + e[12];
	this.y = e[1] * x + e[5] * y + e[9]  * z + e[13];
	this.z = e[2] * x + e[6] * y + e[10] * z + e[14];

	return this;
}

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant