@@ -30212,10 +30212,6 @@ THREE.WebGLShadowMap = function ( _renderer, _lights, _objects ) {
30212
30212
30213
30213
}
30214
30214
30215
- // We must call _renderer.resetGLState() at the end of each iteration of
30216
- // the light loop in order to force material updates for each light.
30217
- _renderer.resetGLState();
30218
-
30219
30215
}
30220
30216
30221
30217
// Restore GL state.
@@ -30231,8 +30227,6 @@ THREE.WebGLShadowMap = function ( _renderer, _lights, _objects ) {
30231
30227
30232
30228
}
30233
30229
30234
- _renderer.resetGLState();
30235
-
30236
30230
scope.needsUpdate = false;
30237
30231
30238
30232
};
@@ -37147,26 +37141,24 @@ THREE.ShapeGeometry.prototype.addShape = function ( shape, options ) {
37147
37141
37148
37142
};
37149
37143
37150
- // File:src/extras/geometries/LatheGeometry .js
37144
+ // File:src/extras/geometries/LatheBufferGeometry .js
37151
37145
37152
37146
/**
37153
- * @author astrodud / http://astrodud.isgreat.org/
37154
- * @author zz85 / https://github.com/zz85
37155
- * @author bhouston / http://clara.io
37147
+ * @author Mugen87 / https://github.com/Mugen87
37156
37148
*/
37157
37149
37158
- // points - to create a closed torus, one must use a set of points
37159
- // like so: [ a, b, c, d, a ], see first is the same as last.
37160
- // segments - the number of circumference segments to create
37161
- // phiStart - the starting radian
37162
- // phiLength - the radian (0 to 2*PI ) range of the lathed section
37163
- // 2*pi is a closed lathe, less than 2PI is a portion.
37150
+ // points - to create a closed torus, one must use a set of points
37151
+ // like so: [ a, b, c, d, a ], see first is the same as last.
37152
+ // segments - the number of circumference segments to create
37153
+ // phiStart - the starting radian
37154
+ // phiLength - the radian (0 to 2PI ) range of the lathed section
37155
+ // 2PI is a closed lathe, less than 2PI is a portion.
37164
37156
37165
- THREE.LatheGeometry = function ( points, segments, phiStart, phiLength ) {
37157
+ THREE.LatheBufferGeometry = function ( points, segments, phiStart, phiLength ) {
37166
37158
37167
- THREE.Geometry .call( this );
37159
+ THREE.BufferGeometry .call( this );
37168
37160
37169
- this.type = 'LatheGeometry ';
37161
+ this.type = 'LatheBufferGeometry ';
37170
37162
37171
37163
this.parameters = {
37172
37164
points: points,
@@ -37175,81 +37167,169 @@ THREE.LatheGeometry = function ( points, segments, phiStart, phiLength ) {
37175
37167
phiLength: phiLength
37176
37168
};
37177
37169
37178
- segments = segments || 12;
37170
+ segments = Math.floor( segments ) || 12;
37179
37171
phiStart = phiStart || 0;
37180
- phiLength = phiLength || 2 * Math.PI;
37172
+ phiLength = phiLength || Math.PI * 2;
37173
+
37174
+ // clamp phiLength so it's in range of [ 0, 2PI ]
37175
+ phiLength = THREE.Math.clamp( phiLength, 0, Math.PI * 2 );
37176
+
37177
+ // these are used to calculate buffer length
37178
+ var vertexCount = ( segments + 1 ) * points.length;
37179
+ var indexCount = segments * points.length * 2 * 3;
37181
37180
37181
+ // buffers
37182
+ var indices = new THREE.BufferAttribute( new ( indexCount > 65535 ? Uint32Array : Uint16Array )( indexCount ) , 1 );
37183
+ var vertices = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
37184
+ var uvs = new THREE.BufferAttribute( new Float32Array( vertexCount * 2 ), 2 );
37185
+
37186
+ // helper variables
37187
+ var index = 0, indexOffset = 0, base;
37182
37188
var inversePointLength = 1.0 / ( points.length - 1 );
37183
37189
var inverseSegments = 1.0 / segments;
37190
+ var vertex = new THREE.Vector3();
37191
+ var uv = new THREE.Vector2();
37192
+ var i, j;
37193
+
37194
+ // generate vertices and uvs
37184
37195
37185
- for ( var i = 0, il = segments ; i <= il ; i ++ ) {
37196
+ for ( i = 0; i <= segments ; i ++ ) {
37186
37197
37187
37198
var phi = phiStart + i * inverseSegments * phiLength;
37188
37199
37189
37200
var sin = Math.sin( phi );
37190
37201
var cos = Math.cos( phi );
37191
37202
37192
- for ( var j = 0, jl = points.length; j < jl ; j ++ ) {
37203
+ for ( j = 0; j <= ( points.length - 1 ) ; j ++ ) {
37193
37204
37194
- var point = points[ j ];
37195
-
37196
- var vertex = new THREE.Vector3();
37205
+ // vertex
37206
+ vertex.x = points[ j ].x * sin;
37207
+ vertex.y = points[ j ].y;
37208
+ vertex.z = points[ j ].x * cos;
37209
+ vertices.setXYZ( index, vertex.x, vertex.y, vertex.z );
37197
37210
37198
- vertex.x = point.x * sin;
37199
- vertex.y = point.y;
37200
- vertex.z = point.x * cos;
37211
+ // uv
37212
+ uv.x = i / segments;
37213
+ uv.y = j / ( points.length - 1 );
37214
+ uvs.setXY( index, uv.x, uv.y );
37201
37215
37202
- this.vertices.push( vertex );
37216
+ // increase index
37217
+ index ++;
37203
37218
37204
37219
}
37205
37220
37206
37221
}
37207
37222
37208
- var np = points.length;
37223
+ // generate indices
37224
+
37225
+ for ( i = 0; i < segments; i ++ ) {
37209
37226
37210
- for ( var i = 0, il = segments; i < il; i ++ ) {
37227
+ for ( j = 0; j < ( points.length - 1 ); j ++ ) {
37211
37228
37212
- for ( var j = 0, jl = points.length - 1; j < jl; j ++ ) {
37229
+ base = j + i * points.length;
37213
37230
37214
- var base = j + np * i;
37231
+ // indices
37215
37232
var a = base;
37216
- var b = base + np ;
37217
- var c = base + 1 + np ;
37233
+ var b = base + points.length ;
37234
+ var c = base + points.length + 1 ;
37218
37235
var d = base + 1;
37219
37236
37220
- var u0 = i * inverseSegments;
37221
- var v0 = j * inversePointLength ;
37222
- var u1 = u0 + inverseSegments ;
37223
- var v1 = v0 + inversePointLength ;
37237
+ // face one
37238
+ indices.setX( indexOffset, a ); indexOffset++ ;
37239
+ indices.setX( indexOffset, b ); indexOffset++ ;
37240
+ indices.setX( indexOffset, d ); indexOffset++ ;
37224
37241
37225
- this.faces.push( new THREE.Face3( a, b, d ) );
37242
+ // face two
37243
+ indices.setX( indexOffset, b ); indexOffset++;
37244
+ indices.setX( indexOffset, c ); indexOffset++;
37245
+ indices.setX( indexOffset, d ); indexOffset++;
37226
37246
37227
- this.faceVertexUvs[ 0 ].push( [
37247
+ }
37228
37248
37229
- new THREE.Vector2( u0, v0 ),
37230
- new THREE.Vector2( u1, v0 ),
37231
- new THREE.Vector2( u0, v1 )
37249
+ }
37232
37250
37233
- ] );
37251
+ // build geometry
37234
37252
37235
- this.faces.push( new THREE.Face3( b, c, d ) );
37253
+ this.setIndex( indices );
37254
+ this.addAttribute( 'position', vertices );
37255
+ this.addAttribute( 'uv', uvs );
37236
37256
37237
- this.faceVertexUvs[ 0 ].push( [
37257
+ // generate normals
37238
37258
37239
- new THREE.Vector2( u1, v0 ),
37240
- new THREE.Vector2( u1, v1 ),
37241
- new THREE.Vector2( u0, v1 )
37259
+ this.computeVertexNormals();
37242
37260
37243
- ] );
37261
+ // if the geometry is closed, we need to average the normals along the seam.
37262
+ // because the corresponding vertices are identical (but still have different UVs).
37244
37263
37264
+ if( phiLength === Math.PI * 2 ) {
37245
37265
37246
- }
37266
+ var normals = this.attributes.normal.array;
37267
+ var n1 = new THREE.Vector3();
37268
+ var n2 = new THREE.Vector3();
37269
+ var n = new THREE.Vector3();
37270
+
37271
+ // this is the buffer offset for the last line of vertices
37272
+ base = segments * points.length * 3;
37273
+
37274
+ for( i = 0, j = 0; i < points.length; i ++, j += 3 ) {
37275
+
37276
+ // select the normal of the vertex in the first line
37277
+ n1.x = normals[ j + 0 ];
37278
+ n1.y = normals[ j + 1 ];
37279
+ n1.z = normals[ j + 2 ];
37280
+
37281
+ // select the normal of the vertex in the last line
37282
+ n2.x = normals[ base + j + 0 ];
37283
+ n2.y = normals[ base + j + 1 ];
37284
+ n2.z = normals[ base + j + 2 ];
37285
+
37286
+ // average normals
37287
+ n.addVectors( n1, n2 ).normalize();
37288
+
37289
+ // assign the new values to both normals
37290
+ normals[ j + 0 ] = normals[ base + j + 0 ] = n.x;
37291
+ normals[ j + 1 ] = normals[ base + j + 1 ] = n.y;
37292
+ normals[ j + 2 ] = normals[ base + j + 2 ] = n.z;
37293
+
37294
+ } // next row
37247
37295
37248
37296
}
37249
37297
37298
+ };
37299
+
37300
+ THREE.LatheBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
37301
+ THREE.LatheBufferGeometry.prototype.constructor = THREE.LatheBufferGeometry;
37302
+
37303
+ // File:src/extras/geometries/LatheGeometry.js
37304
+
37305
+ /**
37306
+ * @author astrodud / http://astrodud.isgreat.org/
37307
+ * @author zz85 / https://github.com/zz85
37308
+ * @author bhouston / http://clara.io
37309
+ */
37310
+
37311
+ // points - to create a closed torus, one must use a set of points
37312
+ // like so: [ a, b, c, d, a ], see first is the same as last.
37313
+ // segments - the number of circumference segments to create
37314
+ // phiStart - the starting radian
37315
+ // phiLength - the radian (0 to 2PI) range of the lathed section
37316
+ // 2PI is a closed lathe, less than 2PI is a portion.
37317
+
37318
+ THREE.LatheGeometry = function ( points, segments, phiStart, phiLength ) {
37319
+
37320
+ THREE.Geometry.call( this );
37321
+
37322
+ this.type = 'LatheGeometry';
37323
+
37324
+ this.parameters = {
37325
+ points: points,
37326
+ segments: segments,
37327
+ phiStart: phiStart,
37328
+ phiLength: phiLength
37329
+ };
37330
+
37331
+ this.fromBufferGeometry( new THREE.LatheBufferGeometry( points, segments, phiStart, phiLength ) );
37250
37332
this.mergeVertices();
37251
- this.computeFaceNormals();
37252
- this.computeVertexNormals();
37253
37333
37254
37334
};
37255
37335
0 commit comments