Skip to content

CSG optimizations for animation #39

Open

Description

@fabiencomte

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;
}

`

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions