|
@@ -2,7 +2,7 @@
|
|
|
* @author Mugen87 / https://github.com/Mugen87
|
|
|
*/
|
|
|
|
|
|
-THREE.CylinderBufferGeometry = function ( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
|
|
|
+THREE.CylinderBufferGeometry = function( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
|
|
|
|
|
|
THREE.BufferGeometry.call( this );
|
|
|
|
|
@@ -19,11 +19,13 @@ THREE.CylinderBufferGeometry = function ( radiusTop, radiusBottom, height, radia
|
|
|
thetaLength: thetaLength
|
|
|
};
|
|
|
|
|
|
+ var scope = this;
|
|
|
+
|
|
|
radiusTop = radiusTop !== undefined ? radiusTop : 20;
|
|
|
radiusBottom = radiusBottom !== undefined ? radiusBottom : 20;
|
|
|
height = height !== undefined ? height : 100;
|
|
|
|
|
|
- radialSegments = Math.floor( radialSegments ) || 8;
|
|
|
+ radialSegments = Math.floor( radialSegments ) || 8;
|
|
|
heightSegments = Math.floor( heightSegments ) || 1;
|
|
|
|
|
|
openEnded = openEnded !== undefined ? openEnded : false;
|
|
@@ -46,6 +48,9 @@ THREE.CylinderBufferGeometry = function ( radiusTop, radiusBottom, height, radia
|
|
|
|
|
|
var index = 0, indexOffset = 0, indexArray = [], halfHeight = height / 2;
|
|
|
|
|
|
+ // group variables
|
|
|
+ var groupStart = 0;
|
|
|
+
|
|
|
// generate geometry
|
|
|
|
|
|
generateTorso();
|
|
@@ -66,7 +71,7 @@ THREE.CylinderBufferGeometry = function ( radiusTop, radiusBottom, height, radia
|
|
|
|
|
|
// helper functions
|
|
|
|
|
|
- function calculateVertexCount () {
|
|
|
+ function calculateVertexCount() {
|
|
|
|
|
|
var count = ( radialSegments + 1 ) * ( heightSegments + 1 );
|
|
|
|
|
@@ -80,7 +85,7 @@ THREE.CylinderBufferGeometry = function ( radiusTop, radiusBottom, height, radia
|
|
|
|
|
|
}
|
|
|
|
|
|
- function calculateIndexCount () {
|
|
|
+ function calculateIndexCount() {
|
|
|
|
|
|
var count = radialSegments * heightSegments * 2 * 3;
|
|
|
|
|
@@ -94,12 +99,14 @@ THREE.CylinderBufferGeometry = function ( radiusTop, radiusBottom, height, radia
|
|
|
|
|
|
}
|
|
|
|
|
|
- function generateTorso () {
|
|
|
+ function generateTorso() {
|
|
|
|
|
|
var x, y;
|
|
|
var normal = new THREE.Vector3();
|
|
|
var vertex = new THREE.Vector3();
|
|
|
|
|
|
+ var groupCount = 0;
|
|
|
+
|
|
|
// this will be used to calculate the normal
|
|
|
var tanTheta = ( radiusBottom - radiusTop ) / height;
|
|
|
|
|
@@ -128,7 +135,7 @@ THREE.CylinderBufferGeometry = function ( radiusTop, radiusBottom, height, radia
|
|
|
normal.copy( vertex );
|
|
|
|
|
|
// handle special case if radiusTop/radiusBottom is zero
|
|
|
- if ( ( radiusTop === 0 && y === 0 ) || ( radiusBottom === 0 && y === heightSegments ) ) {
|
|
|
+ if ( ( radiusTop === 0 && y === 0 ) || ( radiusBottom === 0 && y === heightSegments ) ) {
|
|
|
|
|
|
normal.x = Math.sin( u * thetaLength + thetaStart );
|
|
|
normal.z = Math.cos( u * thetaLength + thetaStart );
|
|
@@ -176,18 +183,29 @@ THREE.CylinderBufferGeometry = function ( radiusTop, radiusBottom, height, radia
|
|
|
indices.setX( indexOffset, i3 ); indexOffset ++;
|
|
|
indices.setX( indexOffset, i4 ); indexOffset ++;
|
|
|
|
|
|
+ // update counters
|
|
|
+ groupCount += 6;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
+ // add a group to the geometry. this will ensure multi material support
|
|
|
+ scope.addGroup( groupStart, groupCount, 0 );
|
|
|
+
|
|
|
+ // calculate new start value for groups
|
|
|
+ groupStart += groupCount;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- function generateCap ( top ) {
|
|
|
+ function generateCap( top ) {
|
|
|
|
|
|
var x, centerIndexStart, centerIndexEnd;
|
|
|
var uv = new THREE.Vector2();
|
|
|
var vertex = new THREE.Vector3();
|
|
|
|
|
|
+ var groupCount = 0;
|
|
|
+
|
|
|
var radius = ( top === true ) ? radiusTop : radiusBottom;
|
|
|
var sign = ( top === true ) ? 1 : - 1;
|
|
|
|
|
@@ -275,8 +293,17 @@ THREE.CylinderBufferGeometry = function ( radiusTop, radiusBottom, height, radia
|
|
|
|
|
|
}
|
|
|
|
|
|
+ // update counters
|
|
|
+ groupCount += 3;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
+ // add a group to the geometry. this will ensure multi material support
|
|
|
+ scope.addGroup( groupStart, groupCount, top === true ? 1 : 2 );
|
|
|
+
|
|
|
+ // calculate new start value for groups
|
|
|
+ groupStart += groupCount;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
};
|