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

Packaged library so that it can be distributed with Bower, NPM #19

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions .bowerrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"directory": "examples/vendor"
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*~
node_modules/
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ThreeCSG
========

CSG plugin for Three.js


31 changes: 31 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "ThreeCSG",
"main": "dist/ThreeCSG.js",
"version": "0.1.4",
"homepage": "https://github.com/chandlerprall/ThreeCSG",
"authors": [
"Chandler Prall"
],
"description": "CSG plugin for Three.js",
"keywords": [
"threejs",
"3d",
"csg",
"webgl"
],
"license": "MIT",
"ignore": [
"**/.*",
".bowerrc",
"bower_components",
"examples",
"gruntfile.js",
"node_modules",
"src",
"test",
"tests"
],
"devDependencies": {
"threejs": "*"
}
}
30 changes: 17 additions & 13 deletions ThreeCSG.js → dist/ThreeCSG.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
'use strict';
/* jshint -W097 */
/* globals THREE, window */
"use strict";

window.ThreeBSP = (function() {

var ThreeBSP,
Expand All @@ -17,15 +20,15 @@ window.ThreeBSP = (function() {
tree;

if ( geometry instanceof THREE.Geometry ) {
this.matrix = new THREE.Matrix4;
this.matrix = new THREE.Matrix4();
} else if ( geometry instanceof THREE.Mesh ) {
// #todo: add hierarchy support
geometry.updateMatrix();
this.matrix = geometry.matrix.clone();
geometry = geometry.geometry;
} else if ( geometry instanceof ThreeBSP.Node ) {
this.tree = geometry;
this.matrix = new THREE.Matrix4;
this.matrix = new THREE.Matrix4();
return this;
} else {
throw 'ThreeBSP: Given geometry is unsupported';
Expand All @@ -34,7 +37,7 @@ window.ThreeBSP = (function() {
for ( i = 0, _length_i = geometry.faces.length; i < _length_i; i++ ) {
face = geometry.faces[i];
faceVertexUvs = geometry.faceVertexUvs[0][i];
polygon = new ThreeBSP.Polygon;
polygon = new ThreeBSP.Polygon();

if ( face instanceof THREE.Face3 ) {
vertex = geometry.vertices[ face.a ];
Expand Down Expand Up @@ -84,7 +87,7 @@ window.ThreeBSP = (function() {

polygon.calculateProperties();
polygons.push( polygon );
};
}

this.tree = new ThreeBSP.Node( polygons );
};
Expand Down Expand Up @@ -238,11 +241,11 @@ window.ThreeBSP = (function() {
};
ThreeBSP.Polygon.prototype.clone = function() {
var i, vertice_count,
polygon = new ThreeBSP.Polygon;
polygon = new ThreeBSP.Polygon();

for ( i = 0, vertice_count = this.vertices.length; i < vertice_count; i++ ) {
polygon.vertices.push( this.vertices[i].clone() );
};
}
polygon.calculateProperties();

return polygon;
Expand All @@ -256,7 +259,7 @@ window.ThreeBSP = (function() {

for ( i = this.vertices.length - 1; i >= 0; i-- ) {
vertices.push( this.vertices[i] );
};
}
this.vertices = vertices;

return this;
Expand Down Expand Up @@ -349,8 +352,8 @@ window.ThreeBSP = (function() {
this.x = x;
this.y = y;
this.z = z;
this.normal = normal || new THREE.Vector3;
this.uv = uv || new THREE.Vector2;
this.normal = normal || new THREE.Vector3();
this.uv = uv || new THREE.Vector2();
};
ThreeBSP.Vertex.prototype.clone = function() {
return new ThreeBSP.Vertex( this.x, this.y, this.z, this.normal.clone(), this.uv.clone() );
Expand Down Expand Up @@ -428,7 +431,7 @@ window.ThreeBSP = (function() {

return this;

}
};


ThreeBSP.Node = function( polygons ) {
Expand Down Expand Up @@ -528,7 +531,8 @@ window.ThreeBSP = (function() {

if ( !this.divider ) return polygons.slice();

front = [], back = [];
front = [];
back = [];

for ( i = 0, polygon_count = polygons.length; i < polygon_count; i++ ) {
this.divider.splitPolygon( polygons[i], front, back, front, back );
Expand All @@ -549,4 +553,4 @@ window.ThreeBSP = (function() {


return ThreeBSP;
})();
})();
1 change: 1 addition & 0 deletions dist/ThreeCSG.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions examples.html → examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

<head>

<script type="text/javascript" src="https://raw.github.com/mrdoob/three.js/master/build/three.min.js"></script>
<script type="text/javascript" src="ThreeCSG.js"></script>
<script type="text/javascript" src="vendor/threejs/build/three.min.js"></script>
<script type="text/javascript" src="lib/ThreeCSG.js"></script>

<script type="text/javascript">
var renderer, scene, camera, light;
Expand Down
Loading