diff --git a/examples/js/loaders/AssimpJSONLoader.js b/examples/js/loaders/AssimpJSONLoader.js index 32a0740687db5ff37a9464568f783d23145f217c..6bbae1f2833114c2d71d10ed600289503743cc24 100644 --- a/examples/js/loaders/AssimpJSONLoader.js +++ b/examples/js/loaders/AssimpJSONLoader.js @@ -125,7 +125,7 @@ THREE.AssimpJSONLoader.prototype = { } - geometry.setIndex( new ( Math.max.apply( Math, indices ) > 65535 ? THREE.Uint32BufferAttribute : THREE.Uint16BufferAttribute )( indices, 1 ) ); + geometry.setIndexArray( indices ); geometry.addAttribute( 'position', new THREE.Float32BufferAttribute( vertices, 3 ) ); if ( normals.length > 0 ) { diff --git a/examples/js/loaders/FBXLoader.js b/examples/js/loaders/FBXLoader.js index 5d838298cf214a009883402698904e269027abf6..6022cb0f5deb54ea23aa9a122734f07b534b67d1 100644 --- a/examples/js/loaders/FBXLoader.js +++ b/examples/js/loaders/FBXLoader.js @@ -263,15 +263,7 @@ if ( geoNode.indices !== undefined && geoNode.indices.length > 0 ) { - if ( Math.max.apply( Math, geoNode.indices ) > 65535 ) { - - tmpGeo.setIndex( new THREE.BufferAttribute( new Uint32Array( geoNode.indices ), 1 ) ); - - } else { - - tmpGeo.setIndex( new THREE.BufferAttribute( new Uint16Array( geoNode.indices ), 1 ) ); - - } + tmpGeo.setIndexArray( geoNode.indices ); } diff --git a/examples/js/loaders/MMDLoader.js b/examples/js/loaders/MMDLoader.js index 2a3e5889f79a7d63ce9c6ab3c9beca9d459475c1..8d8299e6bb79797f447403809d6e44c6b4460d26 100644 --- a/examples/js/loaders/MMDLoader.js +++ b/examples/js/loaders/MMDLoader.js @@ -1477,7 +1477,7 @@ THREE.MMDLoader.prototype.createMesh = function ( model, texturePath, onProgress var initGeometry = function () { - geometry.setIndex( new ( Math.max.apply( Math, buffer.indices ) > 65535 ? THREE.Uint32BufferAttribute : THREE.Uint16BufferAttribute )( buffer.indices, 1 ) ); + geometry.setIndexArray( buffer.indices ); geometry.addAttribute( 'position', new THREE.Float32BufferAttribute( buffer.vertices, 3 ) ); geometry.addAttribute( 'normal', new THREE.Float32BufferAttribute( buffer.normals, 3 ) ); geometry.addAttribute( 'uv', new THREE.Float32BufferAttribute( buffer.uvs, 2 ) ); diff --git a/examples/js/loaders/PLYLoader.js b/examples/js/loaders/PLYLoader.js index 8eb066a35d65642fbd6c47dd98f7e9f7af9555fb..cf7cf6e9827bda10d3acfcb9f761654b1181b8a8 100644 --- a/examples/js/loaders/PLYLoader.js +++ b/examples/js/loaders/PLYLoader.js @@ -313,8 +313,11 @@ THREE.PLYLoader.prototype = { // mandatory buffer data if ( buffer.indices.length > 0 ) { - geometry.setIndex( new ( Math.max.apply( Math, buffer.indices ) > 65535 ? THREE.Uint32BufferAttribute : THREE.Uint16BufferAttribute )( buffer.indices, 1 ) ); + + geometry.setIndexArray( buffer.indices ); + } + geometry.addAttribute( 'position', new THREE.Float32BufferAttribute( buffer.vertices, 3 ) ); // optional buffer data diff --git a/src/core/BufferGeometry.js b/src/core/BufferGeometry.js index 8886d38f2bee966637f8ed372a7b523e3254d5fa..e4e6b5f6695df22eab7c77b66fb16f80977a6397 100644 --- a/src/core/BufferGeometry.js +++ b/src/core/BufferGeometry.js @@ -514,7 +514,7 @@ BufferGeometry.prototype = { if ( geometry.indices.length > 0 ) { - var TypeArray = Math.max.apply( Math, geometry.indices ) > 65535 ? Uint32Array : Uint16Array; + var TypeArray = _Math.arrayMax( geometry.indices ) > 65535 ? Uint32Array : Uint16Array; var indices = new TypeArray( geometry.indices.length * 3 ); this.setIndex( new BufferAttribute( indices, 1 ).copyIndicesArray( geometry.indices ) ); diff --git a/src/geometries/BoxGeometry.js b/src/geometries/BoxGeometry.js index 64879f701b778533532481e6ce31dcc0cb7f385d..63b939532dd46d8c95b02cde80eafeabfc350cd9 100644 --- a/src/geometries/BoxGeometry.js +++ b/src/geometries/BoxGeometry.js @@ -32,7 +32,7 @@ BoxGeometry.prototype.constructor = BoxGeometry; * @author Mugen87 / https://github.com/Mugen87 */ -import { Float32BufferAttribute, Uint16BufferAttribute, Uint32BufferAttribute } from '../core/BufferAttribute'; +import { Float32BufferAttribute } from '../core/BufferAttribute'; import { BufferGeometry } from '../core/BufferGeometry'; import { Vector3 } from '../math/Vector3'; @@ -82,7 +82,7 @@ function BoxBufferGeometry( width, height, depth, widthSegments, heightSegments, // build geometry - this.setIndex( new ( Math.max.apply( Math, indices ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 ) ); + this.setIndexArray( indices ); this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) ); this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) ); this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) ); diff --git a/src/geometries/CircleGeometry.js b/src/geometries/CircleGeometry.js index 32abf1b055b6159e7465d907aace2b8aebf006c0..695d3cb0fc23c070cf1718f13d116476b5dfb709 100644 --- a/src/geometries/CircleGeometry.js +++ b/src/geometries/CircleGeometry.js @@ -29,7 +29,7 @@ CircleGeometry.prototype.constructor = CircleGeometry; * @author Mugen87 / https://github.com/Mugen87 */ -import { Float32BufferAttribute, Uint16BufferAttribute, Uint32BufferAttribute } from '../core/BufferAttribute'; +import { Float32BufferAttribute } from '../core/BufferAttribute'; import { BufferGeometry } from '../core/BufferGeometry'; import { Vector3 } from '../math/Vector3'; import { Vector2 } from '../math/Vector2'; @@ -106,7 +106,7 @@ function CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) { // build geometry - this.setIndex( new ( Math.max.apply( Math, indices ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 ) ); + this.setIndexArray( indices ); this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) ); this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) ); this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) ); diff --git a/src/geometries/CylinderGeometry.js b/src/geometries/CylinderGeometry.js index 5b43fe6f9c232054a057cc303ce938f7fe9ebb34..5ffdb292728c20c1bcda4019039fd66a6650c670 100644 --- a/src/geometries/CylinderGeometry.js +++ b/src/geometries/CylinderGeometry.js @@ -33,7 +33,7 @@ CylinderGeometry.prototype.constructor = CylinderGeometry; * @author Mugen87 / https://github.com/Mugen87 */ -import { Float32BufferAttribute, Uint16BufferAttribute, Uint32BufferAttribute } from '../core/BufferAttribute'; +import { Float32BufferAttribute } from '../core/BufferAttribute'; import { BufferGeometry } from '../core/BufferGeometry'; import { Vector3 } from '../math/Vector3'; import { Vector2 } from '../math/Vector2'; @@ -96,7 +96,7 @@ function CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments // build geometry - this.setIndex( new ( Math.max.apply( Math, indices ) ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 ) ); + this.setIndexArray( indices ); this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) ); this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) ); this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) ); diff --git a/src/geometries/LatheGeometry.js b/src/geometries/LatheGeometry.js index 9169c4fd92b2abc4c783a63bd0810e0f038cde1d..c0dc58c7f60b1038b5a215f6bbfd4c759d8a2e17 100644 --- a/src/geometries/LatheGeometry.js +++ b/src/geometries/LatheGeometry.js @@ -34,7 +34,7 @@ function LatheGeometry( points, segments, phiStart, phiLength ) { LatheGeometry.prototype = Object.create( Geometry.prototype ); LatheGeometry.prototype.constructor = LatheGeometry; -import { Float32BufferAttribute, Uint16BufferAttribute, Uint32BufferAttribute } from '../core/BufferAttribute'; +import { Float32BufferAttribute } from '../core/BufferAttribute'; import { BufferGeometry } from '../core/BufferGeometry'; import { Vector3 } from '../math/Vector3'; import { Vector2 } from '../math/Vector2'; @@ -62,7 +62,7 @@ function LatheBufferGeometry( points, segments, phiStart, phiLength ) { phiLength = phiLength || Math.PI * 2; // clamp phiLength so it's in range of [ 0, 2PI ] - + phiLength = _Math.clamp( phiLength, 0, Math.PI * 2 ); @@ -135,7 +135,7 @@ function LatheBufferGeometry( points, segments, phiStart, phiLength ) { // build geometry - this.setIndex( new ( Math.max.apply( Math, indices ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 ) ); + this.setIndexArray( indices ); this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) ); this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) ); diff --git a/src/geometries/ParametricGeometry.js b/src/geometries/ParametricGeometry.js index 1ed06b3ed757d8c3c1765146f4a397eea33063b0..6cd797cc349fb5106be306fef806af6581c88a99 100644 --- a/src/geometries/ParametricGeometry.js +++ b/src/geometries/ParametricGeometry.js @@ -35,7 +35,7 @@ ParametricGeometry.prototype.constructor = ParametricGeometry; */ import { BufferGeometry } from '../core/BufferGeometry'; -import { Float32BufferAttribute, Uint16BufferAttribute, Uint32BufferAttribute } from '../core/BufferAttribute'; +import { Float32BufferAttribute } from '../core/BufferAttribute'; function ParametricBufferGeometry( func, slices, stacks ) { @@ -100,7 +100,7 @@ function ParametricBufferGeometry( func, slices, stacks ) { // build geometry - this.setIndex( new ( Math.max.apply( Math, indices ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 ) ); + this.setIndexArray( indices ); this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) ); this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) ); diff --git a/src/geometries/PlaneGeometry.js b/src/geometries/PlaneGeometry.js index 72269736d13d67fbe63ef8a57893d5fd5834c0da..5a8ca01356eb5da7200dbd567b67086aac35eb89 100644 --- a/src/geometries/PlaneGeometry.js +++ b/src/geometries/PlaneGeometry.js @@ -32,7 +32,7 @@ PlaneGeometry.prototype.constructor = PlaneGeometry; * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Plane.as */ -import { Float32BufferAttribute, Uint16BufferAttribute, Uint32BufferAttribute } from '../core/BufferAttribute'; +import { Float32BufferAttribute } from '../core/BufferAttribute'; import { BufferGeometry } from '../core/BufferGeometry'; function PlaneBufferGeometry( width, height, widthSegments, heightSegments ) { @@ -112,7 +112,7 @@ function PlaneBufferGeometry( width, height, widthSegments, heightSegments ) { // build geometry - this.setIndex( new ( Math.max.apply( Math, indices ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 ) ); + this.setIndexArray( indices ); this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) ); this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) ); this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) ); diff --git a/src/geometries/RingGeometry.js b/src/geometries/RingGeometry.js index 94955ea833962aef31b5b25c32be0f44ea75391c..40ae88897a656cad07b68766ee39142e74984872 100644 --- a/src/geometries/RingGeometry.js +++ b/src/geometries/RingGeometry.js @@ -30,7 +30,7 @@ RingGeometry.prototype.constructor = RingGeometry; * @author Mugen87 / https://github.com/Mugen87 */ -import { Float32BufferAttribute, Uint16BufferAttribute, Uint32BufferAttribute } from '../core/BufferAttribute'; +import { Float32BufferAttribute } from '../core/BufferAttribute'; import { BufferGeometry } from '../core/BufferGeometry'; import { Vector2 } from '../math/Vector2'; import { Vector3 } from '../math/Vector3'; @@ -97,7 +97,7 @@ function RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegment normals.push( 0, 0, 1 ); // uv - + uv.x = ( vertex.x / outerRadius + 1 ) / 2; uv.y = ( vertex.y / outerRadius + 1 ) / 2; @@ -137,7 +137,7 @@ function RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegment // build geometry - this.setIndex( new ( Math.max.apply( Math, indices ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 ) ); + this.setIndexArray( indices ); this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) ); this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) ); this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) ); diff --git a/src/geometries/ShapeGeometry.js b/src/geometries/ShapeGeometry.js index a211125e3ab51eec93bcfeb14c78a6521035bdba..c1da3c0baef93bf08bae2f0b377c9bd6107f9368 100644 --- a/src/geometries/ShapeGeometry.js +++ b/src/geometries/ShapeGeometry.js @@ -35,7 +35,7 @@ ShapeGeometry.prototype.constructor = ShapeGeometry; * @author Mugen87 / https://github.com/Mugen87 */ -import { Float32BufferAttribute, Uint16BufferAttribute, Uint32BufferAttribute } from '../core/BufferAttribute'; +import { Float32BufferAttribute } from '../core/BufferAttribute'; import { BufferGeometry } from '../core/BufferGeometry'; import { ShapeUtils } from '../extras/ShapeUtils'; @@ -87,7 +87,7 @@ function ShapeBufferGeometry( shapes, curveSegments ) { // build geometry - this.setIndex( new ( Math.max.apply( Math, indices ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 ) ); + this.setIndexArray( indices ); this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) ); this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) ); this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) ); diff --git a/src/geometries/SphereGeometry.js b/src/geometries/SphereGeometry.js index d8dc037a2b2094a4fbb2dc174b62a4d1b139dd70..ee28576cb5144086c42fad188477e8a3cbb5b14a 100644 --- a/src/geometries/SphereGeometry.js +++ b/src/geometries/SphereGeometry.js @@ -32,7 +32,7 @@ SphereGeometry.prototype.constructor = SphereGeometry; * @author Mugen87 / https://github.com/Mugen87 */ -import { Float32BufferAttribute, Uint16BufferAttribute, Uint32BufferAttribute } from '../core/BufferAttribute'; +import { Float32BufferAttribute } from '../core/BufferAttribute'; import { BufferGeometry } from '../core/BufferGeometry'; import { Vector3 } from '../math/Vector3'; @@ -137,7 +137,7 @@ function SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, // build geometry - this.setIndex( new ( Math.max.apply( Math, indices ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 ) ); + this.setIndexArray( indices ); this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) ); this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) ); this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) ); diff --git a/src/geometries/TorusGeometry.js b/src/geometries/TorusGeometry.js index 15a93a9c13800af41f48cf001b9afa94687bfd3a..7500788d3e4b4ca41018860c4f40b05a881ff46e 100644 --- a/src/geometries/TorusGeometry.js +++ b/src/geometries/TorusGeometry.js @@ -31,7 +31,7 @@ TorusGeometry.prototype.constructor = TorusGeometry; * @author Mugen87 / https://github.com/Mugen87 */ -import { Float32BufferAttribute, Uint16BufferAttribute, Uint32BufferAttribute } from '../core/BufferAttribute'; +import { Float32BufferAttribute } from '../core/BufferAttribute'; import { BufferGeometry } from '../core/BufferGeometry'; import { Vector3 } from '../math/Vector3'; @@ -128,7 +128,7 @@ function TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc // build geometry - this.setIndex( new ( Math.max.apply( Math, indices ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 ) ); + this.setIndexArray( indices ); this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) ); this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) ); this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) ); diff --git a/src/geometries/TorusKnotGeometry.js b/src/geometries/TorusKnotGeometry.js index a2eef6069056dca2a72e5e7cea33fe9a2dcba5a4..e5b210c1cc1935f475fdb21df70492d1086db665 100644 --- a/src/geometries/TorusKnotGeometry.js +++ b/src/geometries/TorusKnotGeometry.js @@ -34,7 +34,7 @@ TorusKnotGeometry.prototype.constructor = TorusKnotGeometry; * see: http://www.blackpawn.com/texts/pqtorus/ */ -import { Float32BufferAttribute, Uint16BufferAttribute, Uint32BufferAttribute } from '../core/BufferAttribute'; +import { Float32BufferAttribute } from '../core/BufferAttribute'; import { BufferGeometry } from '../core/BufferGeometry'; import { Vector3 } from '../math/Vector3'; import { Vector2 } from '../math/Vector2'; @@ -166,7 +166,7 @@ function TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, // build geometry - this.setIndex( new ( Math.max.apply( Math, indices ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 ) ); + this.setIndexArray( indices ); this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) ); this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) ); this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) ); diff --git a/src/geometries/TubeGeometry.js b/src/geometries/TubeGeometry.js index 80af7515e62a72ea5311d80a52da34dcc1dc9c2b..650113394988a2b7389d2af83e16bed43a62115f 100644 --- a/src/geometries/TubeGeometry.js +++ b/src/geometries/TubeGeometry.js @@ -48,7 +48,7 @@ TubeGeometry.prototype.constructor = TubeGeometry; * @author Mugen87 / https://github.com/Mugen87 */ -import { Float32BufferAttribute, Uint16BufferAttribute, Uint32BufferAttribute } from '../core/BufferAttribute'; +import { Float32BufferAttribute } from '../core/BufferAttribute'; import { BufferGeometry } from '../core/BufferGeometry'; import { Vector2 } from '../math/Vector2'; import { Vector3 } from '../math/Vector3'; @@ -101,7 +101,7 @@ function TubeBufferGeometry( path, tubularSegments, radius, radialSegments, clos // build geometry - this.setIndex( new ( Math.max.apply( Math, indices ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 ) ); + this.setIndexArray( indices ); this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) ); this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) ); this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) ); diff --git a/src/renderers/webgl/WebGLObjects.js b/src/renderers/webgl/WebGLObjects.js index 568d756451bb07dfdb991ecb33740f6e2823f537..2e2a5d8fe835de799330fa42709faf89bece074c 100644 --- a/src/renderers/webgl/WebGLObjects.js +++ b/src/renderers/webgl/WebGLObjects.js @@ -3,6 +3,7 @@ */ import { Uint16BufferAttribute, Uint32BufferAttribute } from '../../core/BufferAttribute'; +import { _Math } from '../../math/Math'; import { WebGLGeometries } from './WebGLGeometries'; function WebGLObjects( gl, properties, info ) { @@ -234,7 +235,7 @@ function WebGLObjects( gl, properties, info ) { // console.timeEnd( 'wireframe' ); - var attribute = new ( Math.max.apply( Math, indices ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 ); + var attribute = new ( _Math.arrayMax( indices ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 ); updateAttribute( attribute, gl.ELEMENT_ARRAY_BUFFER );