|
@@ -8611,6 +8611,26 @@ Object.assign( Color.prototype, {
|
|
|
|
|
|
},
|
|
|
|
|
|
+ fromBufferAttribute: function ( attribute, index ) {
|
|
|
+
|
|
|
+ this.r = attribute.getX( index );
|
|
|
+ this.g = attribute.getY( index );
|
|
|
+ this.b = attribute.getZ( index );
|
|
|
+
|
|
|
+ if ( attribute.normalized === true ) {
|
|
|
+
|
|
|
+ // assuming Uint8Array
|
|
|
+
|
|
|
+ this.r /= 255;
|
|
|
+ this.g /= 255;
|
|
|
+ this.b /= 255;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return this;
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
toJSON: function () {
|
|
|
|
|
|
return this.getHex();
|
|
@@ -11876,7 +11896,7 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
|
|
|
|
|
|
const scope = this;
|
|
|
|
|
|
- const indices = geometry.index !== null ? geometry.index.array : undefined;
|
|
|
+ const index = geometry.index !== null ? geometry.index : undefined;
|
|
|
const attributes = geometry.attributes;
|
|
|
|
|
|
if ( attributes.position === undefined ) {
|
|
@@ -11886,21 +11906,21 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
|
|
|
|
|
|
}
|
|
|
|
|
|
- const positions = attributes.position.array;
|
|
|
- const normals = attributes.normal !== undefined ? attributes.normal.array : undefined;
|
|
|
- const colors = attributes.color !== undefined ? attributes.color.array : undefined;
|
|
|
- const uvs = attributes.uv !== undefined ? attributes.uv.array : undefined;
|
|
|
- const uvs2 = attributes.uv2 !== undefined ? attributes.uv2.array : undefined;
|
|
|
+ const position = attributes.position;
|
|
|
+ const normal = attributes.normal;
|
|
|
+ const color = attributes.color;
|
|
|
+ const uv = attributes.uv;
|
|
|
+ const uv2 = attributes.uv2;
|
|
|
|
|
|
- if ( uvs2 !== undefined ) this.faceVertexUvs[ 1 ] = [];
|
|
|
+ if ( uv2 !== undefined ) this.faceVertexUvs[ 1 ] = [];
|
|
|
|
|
|
- for ( let i = 0; i < positions.length; i += 3 ) {
|
|
|
+ for ( let i = 0; i < position.count; i ++ ) {
|
|
|
|
|
|
- scope.vertices.push( new Vector3().fromArray( positions, i ) );
|
|
|
+ scope.vertices.push( new Vector3().fromBufferAttribute( position, i ) );
|
|
|
|
|
|
- if ( colors !== undefined ) {
|
|
|
+ if ( color !== undefined ) {
|
|
|
|
|
|
- scope.colors.push( new Color().fromArray( colors, i ) );
|
|
|
+ scope.colors.push( new Color().fromBufferAttribute( color, i ) );
|
|
|
|
|
|
}
|
|
|
|
|
@@ -11908,37 +11928,38 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
|
|
|
|
|
|
function addFace( a, b, c, materialIndex ) {
|
|
|
|
|
|
- const vertexColors = ( colors === undefined ) ? [] : [
|
|
|
+ const vertexColors = ( color === undefined ) ? [] : [
|
|
|
scope.colors[ a ].clone(),
|
|
|
scope.colors[ b ].clone(),
|
|
|
- scope.colors[ c ].clone() ];
|
|
|
+ scope.colors[ c ].clone()
|
|
|
+ ];
|
|
|
|
|
|
- const vertexNormals = ( normals === undefined ) ? [] : [
|
|
|
- new Vector3().fromArray( normals, a * 3 ),
|
|
|
- new Vector3().fromArray( normals, b * 3 ),
|
|
|
- new Vector3().fromArray( normals, c * 3 )
|
|
|
+ const vertexNormals = ( normal === undefined ) ? [] : [
|
|
|
+ new Vector3().fromBufferAttribute( normal, a ),
|
|
|
+ new Vector3().fromBufferAttribute( normal, b ),
|
|
|
+ new Vector3().fromBufferAttribute( normal, c )
|
|
|
];
|
|
|
|
|
|
const face = new Face3( a, b, c, vertexNormals, vertexColors, materialIndex );
|
|
|
|
|
|
scope.faces.push( face );
|
|
|
|
|
|
- if ( uvs !== undefined ) {
|
|
|
+ if ( uv !== undefined ) {
|
|
|
|
|
|
scope.faceVertexUvs[ 0 ].push( [
|
|
|
- new Vector2().fromArray( uvs, a * 2 ),
|
|
|
- new Vector2().fromArray( uvs, b * 2 ),
|
|
|
- new Vector2().fromArray( uvs, c * 2 )
|
|
|
+ new Vector2().fromBufferAttribute( uv, a ),
|
|
|
+ new Vector2().fromBufferAttribute( uv, b ),
|
|
|
+ new Vector2().fromBufferAttribute( uv, c )
|
|
|
] );
|
|
|
|
|
|
}
|
|
|
|
|
|
- if ( uvs2 !== undefined ) {
|
|
|
+ if ( uv2 !== undefined ) {
|
|
|
|
|
|
scope.faceVertexUvs[ 1 ].push( [
|
|
|
- new Vector2().fromArray( uvs2, a * 2 ),
|
|
|
- new Vector2().fromArray( uvs2, b * 2 ),
|
|
|
- new Vector2().fromArray( uvs2, c * 2 )
|
|
|
+ new Vector2().fromBufferAttribute( uv2, a ),
|
|
|
+ new Vector2().fromBufferAttribute( uv2, b ),
|
|
|
+ new Vector2().fromBufferAttribute( uv2, c )
|
|
|
] );
|
|
|
|
|
|
}
|
|
@@ -11958,9 +11979,9 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
|
|
|
|
|
|
for ( let j = start, jl = start + count; j < jl; j += 3 ) {
|
|
|
|
|
|
- if ( indices !== undefined ) {
|
|
|
+ if ( index !== undefined ) {
|
|
|
|
|
|
- addFace( indices[ j ], indices[ j + 1 ], indices[ j + 2 ], group.materialIndex );
|
|
|
+ addFace( index.getX( j ), index.getX( j + 1 ), index.getX( j + 2 ), group.materialIndex );
|
|
|
|
|
|
} else {
|
|
|
|
|
@@ -11974,17 +11995,17 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
|
|
|
|
|
|
} else {
|
|
|
|
|
|
- if ( indices !== undefined ) {
|
|
|
+ if ( index !== undefined ) {
|
|
|
|
|
|
- for ( let i = 0; i < indices.length; i += 3 ) {
|
|
|
+ for ( let i = 0; i < index.count; i += 3 ) {
|
|
|
|
|
|
- addFace( indices[ i ], indices[ i + 1 ], indices[ i + 2 ] );
|
|
|
+ addFace( index.getX( i ), index.getX( i + 1 ), index.getX( i + 2 ) );
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
- for ( let i = 0; i < positions.length / 3; i += 3 ) {
|
|
|
+ for ( let i = 0; i < position.count; i += 3 ) {
|
|
|
|
|
|
addFace( i, i + 1, i + 2 );
|
|
|
|
|
@@ -15528,7 +15549,7 @@ function WebGLBackground( renderer, state, objects, premultipliedAlpha ) {
|
|
|
|
|
|
function render( renderList, scene, camera, forceClear ) {
|
|
|
|
|
|
- let background = scene.background;
|
|
|
+ let background = scene.isScene === true ? scene.background : null;
|
|
|
|
|
|
// Ignore background in AR
|
|
|
// TODO: Reconsider this.
|
|
@@ -24257,63 +24278,65 @@ function WebGLRenderer( parameters ) {
|
|
|
|
|
|
// internal properties
|
|
|
|
|
|
- let _this = this,
|
|
|
+ const _this = this;
|
|
|
|
|
|
- _isContextLost = false,
|
|
|
+ let _isContextLost = false;
|
|
|
|
|
|
- // internal state cache
|
|
|
+ // internal state cache
|
|
|
|
|
|
- _framebuffer = null,
|
|
|
+ let _framebuffer = null;
|
|
|
|
|
|
- _currentActiveCubeFace = 0,
|
|
|
- _currentActiveMipmapLevel = 0,
|
|
|
- _currentRenderTarget = null,
|
|
|
- _currentFramebuffer = null,
|
|
|
- _currentMaterialId = - 1,
|
|
|
+ let _currentActiveCubeFace = 0;
|
|
|
+ let _currentActiveMipmapLevel = 0;
|
|
|
+ let _currentRenderTarget = null;
|
|
|
+ let _currentFramebuffer = null;
|
|
|
+ let _currentMaterialId = - 1;
|
|
|
|
|
|
- // geometry and program caching
|
|
|
+ // geometry and program caching
|
|
|
|
|
|
- _currentGeometryProgram = {
|
|
|
- geometry: null,
|
|
|
- program: null,
|
|
|
- wireframe: false
|
|
|
- },
|
|
|
+ const _currentGeometryProgram = {
|
|
|
+ geometry: null,
|
|
|
+ program: null,
|
|
|
+ wireframe: false
|
|
|
+ };
|
|
|
|
|
|
- _currentCamera = null,
|
|
|
- _currentArrayCamera = null,
|
|
|
+ let _currentCamera = null;
|
|
|
+ let _currentArrayCamera = null;
|
|
|
|
|
|
- _currentViewport = new Vector4(),
|
|
|
- _currentScissor = new Vector4(),
|
|
|
- _currentScissorTest = null,
|
|
|
+ const _currentViewport = new Vector4();
|
|
|
+ const _currentScissor = new Vector4();
|
|
|
+ let _currentScissorTest = null;
|
|
|
|
|
|
- //
|
|
|
+ //
|
|
|
+
|
|
|
+ let _width = _canvas.width;
|
|
|
+ let _height = _canvas.height;
|
|
|
|
|
|
- _width = _canvas.width,
|
|
|
- _height = _canvas.height,
|
|
|
+ let _pixelRatio = 1;
|
|
|
+ let _opaqueSort = null;
|
|
|
+ let _transparentSort = null;
|
|
|
|
|
|
- _pixelRatio = 1,
|
|
|
- _opaqueSort = null,
|
|
|
- _transparentSort = null,
|
|
|
+ const _viewport = new Vector4( 0, 0, _width, _height );
|
|
|
+ const _scissor = new Vector4( 0, 0, _width, _height );
|
|
|
+ let _scissorTest = false;
|
|
|
|
|
|
- _viewport = new Vector4( 0, 0, _width, _height ),
|
|
|
- _scissor = new Vector4( 0, 0, _width, _height ),
|
|
|
- _scissorTest = false,
|
|
|
+ // frustum
|
|
|
|
|
|
- // frustum
|
|
|
+ const _frustum = new Frustum();
|
|
|
|
|
|
- _frustum = new Frustum(),
|
|
|
+ // clipping
|
|
|
|
|
|
- // clipping
|
|
|
+ const _clipping = new WebGLClipping();
|
|
|
+ let _clippingEnabled = false;
|
|
|
+ let _localClippingEnabled = false;
|
|
|
|
|
|
- _clipping = new WebGLClipping(),
|
|
|
- _clippingEnabled = false,
|
|
|
- _localClippingEnabled = false,
|
|
|
+ // camera matrices cache
|
|
|
|
|
|
- // camera matrices cache
|
|
|
+ const _projScreenMatrix = new Matrix4();
|
|
|
|
|
|
- _projScreenMatrix = new Matrix4(),
|
|
|
+ const _vector3 = new Vector3();
|
|
|
|
|
|
- _vector3 = new Vector3();
|
|
|
+ const _emptyScene = { background: null, fog: null, environment: null, overrideMaterial: null, isScene: true };
|
|
|
|
|
|
function getTargetPixelRatio() {
|
|
|
|
|
@@ -24852,11 +24875,9 @@ function WebGLRenderer( parameters ) {
|
|
|
|
|
|
};
|
|
|
|
|
|
- const tempScene = new Scene();
|
|
|
-
|
|
|
this.renderBufferDirect = function ( camera, scene, geometry, material, object, group ) {
|
|
|
|
|
|
- if ( scene === null ) scene = tempScene; // renderBufferDirect second parameter used to be fog (could be null)
|
|
|
+ if ( scene === null ) scene = _emptyScene; // renderBufferDirect second parameter used to be fog (could be null)
|
|
|
|
|
|
const frontFaceCW = ( object.isMesh && object.matrixWorld.determinant() < 0 );
|
|
|
|
|
@@ -25278,14 +25299,14 @@ function WebGLRenderer( parameters ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
- if ( ! ( camera && camera.isCamera ) ) {
|
|
|
+ if ( camera !== undefined && camera.isCamera !== true ) {
|
|
|
|
|
|
console.error( 'THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.' );
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
- if ( _isContextLost ) return;
|
|
|
+ if ( _isContextLost === true ) return;
|
|
|
|
|
|
// reset caching for this frame
|
|
|
|
|
@@ -25303,14 +25324,14 @@ function WebGLRenderer( parameters ) {
|
|
|
|
|
|
if ( camera.parent === null ) camera.updateMatrixWorld();
|
|
|
|
|
|
- if ( xr.enabled && xr.isPresenting ) {
|
|
|
+ if ( xr.enabled === true && xr.isPresenting === true ) {
|
|
|
|
|
|
camera = xr.getCamera( camera );
|
|
|
|
|
|
}
|
|
|
|
|
|
//
|
|
|
- if ( scene.isScene ) scene.onBeforeRender( _this, scene, camera, renderTarget || _currentRenderTarget );
|
|
|
+ if ( scene.isScene === true ) scene.onBeforeRender( _this, scene, camera, renderTarget || _currentRenderTarget );
|
|
|
|
|
|
currentRenderState = renderStates.get( scene, camera );
|
|
|
currentRenderState.init();
|
|
@@ -25336,7 +25357,7 @@ function WebGLRenderer( parameters ) {
|
|
|
|
|
|
//
|
|
|
|
|
|
- if ( _clippingEnabled ) _clipping.beginShadows();
|
|
|
+ if ( _clippingEnabled === true ) _clipping.beginShadows();
|
|
|
|
|
|
const shadowsArray = currentRenderState.state.shadowsArray;
|
|
|
|
|
@@ -25344,11 +25365,11 @@ function WebGLRenderer( parameters ) {
|
|
|
|
|
|
currentRenderState.setupLights( camera );
|
|
|
|
|
|
- if ( _clippingEnabled ) _clipping.endShadows();
|
|
|
+ if ( _clippingEnabled === true ) _clipping.endShadows();
|
|
|
|
|
|
//
|
|
|
|
|
|
- if ( this.info.autoReset ) this.info.reset();
|
|
|
+ if ( this.info.autoReset === true ) this.info.reset();
|
|
|
|
|
|
if ( renderTarget !== undefined ) {
|
|
|
|
|
@@ -25365,28 +25386,12 @@ function WebGLRenderer( parameters ) {
|
|
|
const opaqueObjects = currentRenderList.opaque;
|
|
|
const transparentObjects = currentRenderList.transparent;
|
|
|
|
|
|
- if ( scene.overrideMaterial ) {
|
|
|
-
|
|
|
- const overrideMaterial = scene.overrideMaterial;
|
|
|
-
|
|
|
- if ( opaqueObjects.length ) renderObjects( opaqueObjects, scene, camera, overrideMaterial );
|
|
|
- if ( transparentObjects.length ) renderObjects( transparentObjects, scene, camera, overrideMaterial );
|
|
|
-
|
|
|
- } else {
|
|
|
-
|
|
|
- // opaque pass (front-to-back order)
|
|
|
-
|
|
|
- if ( opaqueObjects.length ) renderObjects( opaqueObjects, scene, camera );
|
|
|
-
|
|
|
- // transparent pass (back-to-front order)
|
|
|
-
|
|
|
- if ( transparentObjects.length ) renderObjects( transparentObjects, scene, camera );
|
|
|
-
|
|
|
- }
|
|
|
+ if ( opaqueObjects.length > 0 ) renderObjects( opaqueObjects, scene, camera );
|
|
|
+ if ( transparentObjects.length > 0 ) renderObjects( transparentObjects, scene, camera );
|
|
|
|
|
|
//
|
|
|
|
|
|
- if ( scene.isScene ) scene.onAfterRender( _this, scene, camera );
|
|
|
+ if ( scene.isScene === true ) scene.onAfterRender( _this, scene, camera );
|
|
|
|
|
|
//
|
|
|
|
|
@@ -25542,7 +25547,9 @@ function WebGLRenderer( parameters ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
- function renderObjects( renderList, scene, camera, overrideMaterial ) {
|
|
|
+ function renderObjects( renderList, scene, camera ) {
|
|
|
+
|
|
|
+ const overrideMaterial = scene.isScene === true ? scene.overrideMaterial : null;
|
|
|
|
|
|
for ( let i = 0, l = renderList.length; i < l; i ++ ) {
|
|
|
|
|
@@ -25550,7 +25557,7 @@ function WebGLRenderer( parameters ) {
|
|
|
|
|
|
const object = renderItem.object;
|
|
|
const geometry = renderItem.geometry;
|
|
|
- const material = overrideMaterial === undefined ? renderItem.material : overrideMaterial;
|
|
|
+ const material = overrideMaterial === null ? renderItem.material : overrideMaterial;
|
|
|
const group = renderItem.group;
|
|
|
|
|
|
if ( camera.isArrayCamera ) {
|
|
@@ -25620,6 +25627,8 @@ function WebGLRenderer( parameters ) {
|
|
|
|
|
|
function initMaterial( material, scene, object ) {
|
|
|
|
|
|
+ if ( scene.isScene !== true ) scene = _emptyScene; // scene could be a Mesh, Line, Points, ...
|
|
|
+
|
|
|
const materialProperties = properties.get( material );
|
|
|
|
|
|
const lights = currentRenderState.state.lights;
|
|
@@ -25761,6 +25770,8 @@ function WebGLRenderer( parameters ) {
|
|
|
|
|
|
function setProgram( camera, scene, material, object ) {
|
|
|
|
|
|
+ if ( scene.isScene !== true ) scene = _emptyScene; // scene could be a Mesh, Line, Points, ...
|
|
|
+
|
|
|
textures.resetTextureUnits();
|
|
|
|
|
|
const fog = scene.fog;
|
|
@@ -25770,9 +25781,9 @@ function WebGLRenderer( parameters ) {
|
|
|
const materialProperties = properties.get( material );
|
|
|
const lights = currentRenderState.state.lights;
|
|
|
|
|
|
- if ( _clippingEnabled ) {
|
|
|
+ if ( _clippingEnabled === true ) {
|
|
|
|
|
|
- if ( _localClippingEnabled || camera !== _currentCamera ) {
|
|
|
+ if ( _localClippingEnabled === true || camera !== _currentCamera ) {
|
|
|
|
|
|
const useCache =
|
|
|
camera === _currentCamera &&
|