Browse Source

Merge branch 'dev' of https://github.com/mrdoob/three.js into dev

Luis Blanco 5 years ago
parent
commit
1d73a66333
49 changed files with 897 additions and 784 deletions
  1. 41 50
      build/three.js
  2. 136 294
      build/three.min.js
  3. 41 50
      build/three.module.js
  4. 3 1
      docs/api/en/core/Raycaster.html
  5. 6 2
      docs/api/en/materials/Material.html
  6. 2 1
      docs/api/en/math/Box2.html
  7. 4 1
      docs/api/en/math/Box3.html
  8. 2 1
      docs/api/en/math/Frustum.html
  9. 1 1
      docs/api/en/math/Plane.html
  10. 1 2
      docs/api/en/math/Ray.html
  11. 2 1
      docs/api/en/math/Sphere.html
  12. 2 1
      docs/api/en/math/Triangle.html
  13. 11 0
      docs/api/en/objects/InstancedMesh.html
  14. 1 1
      docs/api/zh/core/Geometry.html
  15. 3 1
      docs/api/zh/core/Raycaster.html
  16. 6 2
      docs/api/zh/materials/Material.html
  17. 11 0
      docs/api/zh/objects/InstancedMesh.html
  18. 6 6
      editor/js/Menubar.Examples.js
  19. 10 0
      editor/js/Strings.js
  20. 1 0
      examples/files.js
  21. 69 0
      examples/js/loaders/GLTFLoader.js
  22. 13 155
      examples/js/vr/HelioWebXRPolyfill.js
  23. 72 0
      examples/jsm/loaders/GLTFLoader.js
  24. 4 3
      examples/jsm/nodes/materials/NodeMaterial.js
  25. 146 0
      examples/webgl_instancing_raycast.html
  26. 71 95
      examples/webvr_6dof_panorama.html
  27. 28 22
      src/core/BufferAttribute.d.ts
  28. 5 7
      src/core/InterleavedBufferAttribute.d.ts
  29. 2 2
      src/loaders/AnimationLoader.d.ts
  30. 3 3
      src/loaders/AudioLoader.d.ts
  31. 5 4
      src/loaders/BufferGeometryLoader.d.ts
  32. 1 1
      src/loaders/ImageBitmapLoader.d.ts
  33. 2 0
      src/loaders/LoadingManager.js
  34. 5 0
      src/materials/Material.d.ts
  35. 10 1
      src/materials/Material.js
  36. 12 31
      src/math/Box3.js
  37. 3 0
      src/objects/InstancedMesh.d.ts
  38. 57 3
      src/objects/InstancedMesh.js
  39. 11 3
      src/renderers/WebGLRenderer.js
  40. 2 13
      src/renderers/shaders/ShaderChunk/normalmap_pars_fragment.glsl.js
  41. 4 13
      src/renderers/shaders/ShaderChunk/packing.glsl.js
  42. 1 1
      src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js
  43. 4 4
      src/renderers/shaders/ShaderLib/vsm_frag.glsl.js
  44. 11 3
      src/renderers/webgl/WebGLAttributes.d.ts
  45. 11 4
      src/renderers/webgl/WebGLGeometries.d.ts
  46. 1 1
      src/renderers/webgl/WebGLInfo.d.ts
  47. 28 0
      src/renderers/webvr/WebVRManager.js
  48. 3 0
      src/renderers/webvr/WebXRManager.js
  49. 23 0
      test/unit/src/loaders/LoadingManager.tests.js

File diff suppressed because it is too large
+ 41 - 50
build/three.js


File diff suppressed because it is too large
+ 136 - 294
build/three.min.js


File diff suppressed because it is too large
+ 41 - 50
build/three.module.js


+ 3 - 1
docs/api/en/core/Raycaster.html

@@ -58,6 +58,7 @@
 			Examples: [example:webgl_interactive_cubes Raycasting to a Mesh]<br />
 			[example:webgl_interactive_cubes_ortho Raycasting to a Mesh in using an OrthographicCamera]<br />
 			[example:webgl_interactive_buffergeometry Raycasting to a Mesh with BufferGeometry]<br />
+			[example:webgl_instancing_raycast Raycasting to a InstancedMesh]<br />
 			[example:webgl_interactive_lines Raycasting to a Line]<br />
 			[example:webgl_interactive_raycasting_points Raycasting to Points]<br />
 			[example:webgl_geometry_terrain_raycast Terrain raycasting]<br />
@@ -170,7 +171,8 @@
 			[page:Integer faceIndex] – index of the intersected face<br />
 			[page:Object3D object] – the intersected object<br />
 			[page:Vector2 uv] - U,V coordinates at point of intersection<br />
-			[page:Vector2 uv2] - Second set of U,V coordinates at point of intersection
+			[page:Vector2 uv2] - Second set of U,V coordinates at point of intersection<br />
+			[page:Integer instanceId] – The index number of the instance where the ray intersects the InstancedMesh
 		</p>
 		<p>
 		*Raycaster* delegates to the [page:Object3D.raycast raycast] method of the passed object, when evaluating whether the ray intersects the object or not. This allows [page:Mesh meshes] to respond differently to ray casting than [page:Line lines] and [page:Points pointclouds].

+ 6 - 2
docs/api/en/materials/Material.html

@@ -186,8 +186,7 @@
 
 		<h3>[property:Boolean needsUpdate]</h3>
 		<p>
-		Specifies that the material needs to be recompiled.<br />
-		This property is automatically set to *true* when instancing a new material.
+		Specifies that the material needs to be recompiled.
 		</p>
 
 		<h3>[property:Float opacity]</h3>
@@ -296,6 +295,11 @@
 		This gets automatically assigned, so this shouldn't be edited.
 		</p>
 
+		<h3>[property:Integer version]</h3>
+		<p>
+		This starts at *0* and counts how many times [property:Boolean needsUpdate] is set to *true*.
+		</p>
+
 		<h3>[property:Integer vertexColors]</h3>
 		<p>
 		Defines whether vertex coloring is used.

+ 2 - 1
docs/api/en/math/Box2.html

@@ -174,7 +174,8 @@
 			[page:Vector2 min] - (required ) [page:Vector2] representing the lower (x, y) boundary of the box. <br>
 			[page:Vector2 max]  - (required) [page:Vector2] representing the upper (x, y) boundary of the box. <br /><br />
 
-			Sets the lower and upper (x, y) boundaries of this box.
+			Sets the lower and upper (x, y) boundaries of this box.<br>
+			Please note that this method only copies the values from the given objects.
 		</p>
 
 		<h3>[method:Box2 setFromCenterAndSize]( [param:Vector2 center], [param:Vector2 size] )</h3>

+ 4 - 1
docs/api/en/math/Box3.html

@@ -138,6 +138,7 @@
 
 		Expands the boundaries of this box to include [page:Object3D object] and its children,
 		accounting for the object's, and children's, world transforms.
+		The function may result in a larger box than strictly necessary.
 
 		</p>
 
@@ -247,7 +248,8 @@
 		[page:Vector3 min] - [page:Vector3] representing the lower (x, y, z) boundary of the box.<br />
 		[page:Vector3 max] - [page:Vector3] representing the lower upper (x, y, z) boundary of the box.<br /><br />
 
-		Sets the lower and upper (x, y, z) boundaries of this box.
+		Sets the lower and upper (x, y, z) boundaries of this box.<br>
+		Please note that this method only copies the values from the given objects.
 		</p>
 
 		<h3>[method:Box3 setFromArray]( [param:Array array] ) [param:Box3 this]</h3>
@@ -279,6 +281,7 @@
 
 		Computes the world-axis-aligned bounding box of an [page:Object3D] (including its children),
 		accounting for the object's, and children's, world transforms.
+		The function may result in a larger box than strictly necessary.
 
 		</p>
 

+ 2 - 1
docs/api/en/math/Frustum.html

@@ -91,7 +91,8 @@
 
 		<h3>[method:Frustum set]( [param:Plane p0], [param:Plane p1], [param:Plane p2], [param:Plane p3], [param:Plane p4], [param:Plane p5] )</h3>
 		<p>
-		Sets the current frustum from the passed planes. No plane order is implicitely implied.
+		Sets the current frustum from the passed planes. No plane order is implicitely implied.<br>
+		Please note that this method only copies the values from the given objects.
 		</p>
 
 		<h3>[method:Frustum setFromMatrix]( [param:Matrix4 matrix] )</h3>

+ 1 - 1
docs/api/en/math/Plane.html

@@ -130,7 +130,7 @@
 			[page:Vector3 normal] - a unit length [page:Vector3] defining the normal of the plane.<br />
 			[page:Float constant] - the signed distance from the origin to the plane. Default is *0*.<br /><br />
 
-			 Sets the plane's [page:.normal normal] and [page:.constant constant] properties.
+			Sets this plane's [page:.normal normal] and [page:.constant constant] properties by copying the values from the given normal.
 		</p>
 
 		<h3>[method:Plane setComponents]( [param:Float x], [param:Float y], [param:Float z], [param:Float w] )</h3>

+ 1 - 2
docs/api/en/math/Ray.html

@@ -201,8 +201,7 @@
 		This must be normalized (with [page:Vector3.normalize]) for the methods to operate
 		properly.<br /><br />
 
-		Copy the parameters to the [page:.origin origin] and [page:.direction direction] properties
-		of this ray.
+		Sets this ray's [page:.origin origin] and [page:.direction direction] properties by copying the values from the given objects.
 		</p>
 
 

+ 2 - 1
docs/api/en/math/Sphere.html

@@ -114,7 +114,8 @@
 			[page:Vector3 center] - center of the sphere.<br />
 			[page:Float radius] - radius of the sphere.<br /><br />
 
-		Sets the [page:.center center] and [page:.radius radius] properties of this sphere.
+		Sets the [page:.center center] and [page:.radius radius] properties of this sphere.<br>
+		Please note that this method only copies the values from the given center.
 		</p>
 
 		<h3>[method:Sphere setFromPoints]( [param:Array points], [param:Vector3 optionalCenter] )</h3>

+ 2 - 1
docs/api/en/math/Triangle.html

@@ -123,7 +123,8 @@
 
 		<h3>[method:Triangle set]( [param:Vector3 a], [param:Vector3 b], [param:Vector3 c] ) [param:Triangle this]</h3>
 		<p>
-		Sets the triangle's [page:.a a], [page:.b b] and [page:.c c] properties to the passed [page:vector3 vector3s].
+		Sets the triangle's [page:.a a], [page:.b b] and [page:.c c] properties to the passed [page:vector3 vector3s].<br>
+		Please note that this method only copies the values from the given objects.
 		</p>
 
 		<h3>[method:Triangle setFromPointsAndIndices]( [param:Array points], [param:Integer i0], [param:Integer i1], [param:Integer i2] ) [param:Triangle this]</h3>

+ 11 - 0
docs/api/en/objects/InstancedMesh.html

@@ -53,6 +53,17 @@
 		<h2>Methods</h2>
 		<p>See the base [page:Mesh] class for common methods.</p>
 
+		<h3>[method:null getMatrixAt]( [param:Integer index], [param:Matrix4 matrix] )</h3>
+		<p>
+			[page:Integer index]: The index of an instance. Values have to be in the range [0, count].
+		</p>
+		<p>
+			[page:Matrix4 matrix]: This 4x4 matrix will be set to the local transformation matrix of the defined instance.
+		</p>
+		<p>
+			Get the local transformation matrix of the defined instance.
+		</p>
+
 		<h3>[method:null setMatrixAt]( [param:Integer index], [param:Matrix4 matrix] )</h3>
 		<p>
 			[page:Integer index]: The index of an instance. Values have to be in the range [0, count].

+ 1 - 1
docs/api/zh/core/Geometry.html

@@ -12,7 +12,7 @@
 
 		<div class="desc">
 		<p>
-			Geometry 是对 [page:BufferGeometry] 的用户有好替代。Geometry 利用 [page:Vector3]
+			Geometry 是一个便于用户使用的 [page:BufferGeometry] 的替代品。Geometry 利用 [page:Vector3]
 			或 [page:Color] 存储了几何体的相关 attributes(如顶点位置,面信息,颜色等)比起 BufferGeometry
 			更容易读写,但是运行效率不如有类型的队列。
 		</p>

+ 3 - 1
docs/api/zh/core/Raycaster.html

@@ -56,6 +56,7 @@
 			其它示例:<br>[example:webgl_interactive_cubes Raycasting to a Mesh]<br />
 			[example:webgl_interactive_cubes_ortho Raycasting to a Mesh in using an OrthographicCamera]<br />
 			[example:webgl_interactive_buffergeometry Raycasting to a Mesh with BufferGeometry]<br />
+			[example:webgl_instancing_raycast Raycasting to a InstancedMesh]<br />
 			[example:webgl_interactive_lines Raycasting to a Line]<br />
 			[example:webgl_interactive_raycasting_points Raycasting to Points]<br />
 			[example:webgl_geometry_terrain_raycast Terrain raycasting]<br />
@@ -170,7 +171,8 @@
 			[page:Integer faceIndex] —— 相交的面的索引<br />
 			[page:Object3D object] —— 相交的物体<br />
 			[page:Vector2 uv] —— 相交部分的点的UV坐标。<br />
-			[page:Vector2 uv2] —— Second set of U,V coordinates at point of intersection
+			[page:Vector2 uv2] —— Second set of U,V coordinates at point of intersection<br />
+			[page:Integer instanceId] – The index number of the instance where the ray intersects the InstancedMesh
 		</p>
 		<p>
 			当计算这条射线是否和物体相交的时候,*Raycaster*将传入的对象委托给[page:Object3D.raycast raycast]方法。

+ 6 - 2
docs/api/zh/materials/Material.html

@@ -163,8 +163,7 @@ Which stencil operation to perform when the comparison function returns true and
 <p>对象的可选名称(不必是唯一的)。默认值为空字符串。</p>
 
 <h3>[property:Boolean needsUpdate]</h3>
-<p>指定需要重新编译材质。<br/>
-	实例化新材质时,此属性自动设置为true。
+<p>指定需要重新编译材质。
 </p>
 
 <h3>[property:Float opacity]</h3>
@@ -255,6 +254,11 @@ Defines whether this material is tone mapped according to the renderer's [page:W
 <p> 此材质实例的[link:http://en.wikipedia.org/wiki/Universally_unique_identifier UUID],会自动分配,不应该被更改。
 </p>
 
+<h3>[property:Integer version]</h3>
+<p>
+This starts at *0* and counts how many times [property:Boolean needsUpdate] is set to *true*.
+</p>
+
 <h3>[property:Integer vertexColors]</h3>
 <p> 是否使用顶点着色。默认值为[page:Materials THREE.NoColors]。
 	其他选项有[page:Materials THREE.VertexColors] 和 [page:Materials THREE.FaceColors]。

+ 11 - 0
docs/api/zh/objects/InstancedMesh.html

@@ -53,6 +53,17 @@
 		<h2>Methods</h2>
 		<p>See the base [page:Mesh] class for common methods.</p>
 
+		<h3>[method:null getMatrixAt]( [param:Integer index], [param:Matrix4 matrix] )</h3>
+		<p>
+			[page:Integer index]: The index of an instance. Values have to be in the range [0, count].
+		</p>
+		<p>
+			[page:Matrix4 matrix]: This 4x4 matrix will be set to the local transformation matrix of the defined instance.
+		</p>
+		<p>
+			Get the local transformation matrix of the defined instance.
+		</p>
+
 		<h3>[method:null setMatrixAt]( [param:Integer index], [param:Matrix4 matrix] )</h3>
 		<p>
 			[page:Integer index]: The index of an instance. Values have to be in the range [0, count].

+ 6 - 6
editor/js/Menubar.Examples.js

@@ -21,11 +21,11 @@ Menubar.Examples = function ( editor ) {
 	// Examples
 
 	var items = [
-		{ title: 'Arkanoid', file: 'arkanoid.app.json' },
-		{ title: 'Camera', file: 'camera.app.json' },
-		{ title: 'Particles', file: 'particles.app.json' },
-		{ title: 'Pong', file: 'pong.app.json' },
-		{ title: 'Shaders', file: 'shaders.app.json' }
+		{ title: 'menubar/examples/Arkanoid', file: 'arkanoid.app.json' },
+		{ title: 'menubar/examples/Camera', file: 'camera.app.json' },
+		{ title: 'menubar/examples/Particles', file: 'particles.app.json' },
+		{ title: 'menubar/examples/Pong', file: 'pong.app.json' },
+		{ title: 'menubar/examples/Shaders', file: 'shaders.app.json' }
 	];
 
 	var loader = new THREE.FileLoader();
@@ -38,7 +38,7 @@ Menubar.Examples = function ( editor ) {
 
 			var option = new UI.Row();
 			option.setClass( 'option' );
-			option.setTextContent( item.title );
+			option.setTextContent( strings.getKey( item.title ) );
 			option.onClick( function () {
 
 				if ( confirm( 'Any unsaved data will be lost. Are you sure?' ) ) {

+ 10 - 0
editor/js/Strings.js

@@ -65,6 +65,11 @@ var Strings = function ( config ) {
 			'menubar/play/play': 'Play',
 
 			'menubar/examples': 'Examples',
+			'menubar/examples/Arkanoid': 'Arkanoid',
+			'menubar/examples/Camera': 'Camera',
+			'menubar/examples/Particles': 'Particles',
+			'menubar/examples/Pong': 'Pong',
+			'menubar/examples/Shaders': 'Shaders',
 
 			'menubar/help': 'Help',
 			'menubar/help/source_code': 'Source Code',
@@ -364,6 +369,11 @@ var Strings = function ( config ) {
 			'menubar/play/play': '启动',
 
 			'menubar/examples': '示例',
+			'menubar/examples/Arkanoid': '打砖块',
+			'menubar/examples/Camera': ' 摄像机',
+			'menubar/examples/Particles': '粒子',
+			'menubar/examples/Pong': '乒乓球',
+			'menubar/examples/Shaders': '着色器',
 
 			'menubar/help': '帮助',
 			'menubar/help/source_code': '源码',

+ 1 - 0
examples/files.js

@@ -48,6 +48,7 @@ var files = {
 		"webgl_geometry_text_stroke",
 		"webgl_helpers",
 		"webgl_instancing_suzanne",
+		"webgl_instancing_raycast",
 		"webgl_interactive_buffergeometry",
 		"webgl_interactive_cubes",
 		"webgl_interactive_cubes_gpu",

+ 69 - 0
examples/js/loaders/GLTFLoader.js

@@ -2267,6 +2267,73 @@ THREE.GLTFLoader = ( function () {
 
 	};
 
+	/**
+	 * @param {THREE.BufferGeometry} geometry
+	 * @param {GLTF.Primitive} primitiveDef
+	 * @param {GLTFParser} parser
+	 */
+	function computeBounds( geometry, primitiveDef, parser ) {
+
+		var attributes = primitiveDef.attributes;
+
+		var box = new THREE.Box3();
+
+		if ( attributes.POSITION !== undefined ) {
+
+			var accessor = parser.json.accessors[ attributes.POSITION ];
+			var min = accessor.min;
+			var max = accessor.max;
+
+			box.set(
+				new THREE.Vector3( min[ 0 ], min[ 1 ], min[ 2 ] ),
+				new THREE.Vector3( max[ 0 ], max[ 1 ], max[ 2 ] ) );
+
+		} else {
+
+			return;
+
+		}
+
+		var targets = primitiveDef.targets;
+
+		if ( targets !== undefined ) {
+
+			var vector = new THREE.Vector3();
+
+			for ( var i = 0, il = targets.length; i < il; i ++ ) {
+
+				var target = targets[ i ];
+
+				if ( target.POSITION !== undefined ) {
+
+					var accessor = parser.json.accessors[ target.POSITION ];
+					var min = accessor.min;
+					var max = accessor.max;
+
+					// we need to get max of absolute components because target weight is [-1,1]
+					vector.setX( Math.max( Math.abs( min[ 0 ] ), Math.abs( max[ 0 ] ) ) );
+					vector.setY( Math.max( Math.abs( min[ 1 ] ), Math.abs( max[ 1 ] ) ) );
+					vector.setZ( Math.max( Math.abs( min[ 2 ] ), Math.abs( max[ 2 ] ) ) );
+
+					box.expandByVector( vector );
+
+				}
+
+			}
+
+		}
+
+		geometry.boundingBox = box;
+
+		var sphere = new THREE.Sphere();
+
+		box.getCenter( sphere.center );
+		sphere.radius = box.min.distanceTo( box.max ) / 2;
+
+		geometry.boundingSphere = sphere;
+
+	}
+
 	/**
 	 * @param {THREE.BufferGeometry} geometry
 	 * @param {GLTF.Primitive} primitiveDef
@@ -2315,6 +2382,8 @@ THREE.GLTFLoader = ( function () {
 
 		assignExtrasToUserData( geometry, primitiveDef );
 
+		computeBounds( geometry, primitiveDef, parser );
+
 		return Promise.all( pending ).then( function () {
 
 			return primitiveDef.targets !== undefined

+ 13 - 155
examples/js/vr/HelioWebXRPolyfill.js

@@ -2,29 +2,24 @@
  * @author mvilledieu / http://github.com/mvilledieu
  */
 
-if ( /(Helio)/g.test( navigator.userAgent ) && "xr" in navigator && 'isSessionSupported' in navigator.xr === false) {
+if ( /(Helio)/g.test( navigator.userAgent ) && 'xr' in navigator ) {
 
-	console.log( "Helio WebXR Polyfill (Lumin 0.97.0)" );
+	console.log( "Helio WebXR Polyfill (Lumin 0.98.0)" );
 
-	const isHelio96 = navigator.userAgent.includes( "Chrome/73" );
+	if ( 'isSessionSupported' in navigator.xr ) {
 
-	// WebXRManager - XR.supportSession() Polyfill - WebVR.js line 147
+		const tempIsSessionSupported = navigator.xr.isSessionSupported.bind( navigator.xr );
 
-	if (
-		"supportsSession" in navigator.xr === false &&
-	"supportsSessionMode" in navigator.xr
-	) {
-
-		navigator.xr.supportsSession = function ( /*sessionType*/ ) {
+		navigator.xr.isSessionSupported = function ( /*sessionType*/ ) {
 
 			// Force using immersive-ar
-			return navigator.xr.supportsSessionMode( 'immersive-ar' );
+			return tempIsSessionSupported( 'immersive-ar' );
 
 		};
 
 	}
 
-	if ( "requestSession" in navigator.xr ) {
+	if ( 'isSessionSupported' in navigator.xr && 'requestSession' in navigator.xr ) {
 
 		const tempRequestSession = navigator.xr.requestSession.bind( navigator.xr );
 
@@ -32,154 +27,17 @@ if ( /(Helio)/g.test( navigator.userAgent ) && "xr" in navigator && 'isSessionSu
 
 			return new Promise( function ( resolve, reject ) {
 
-				const sessionType = ( isHelio96 ? {
-					mode: 'immersive-ar' // Force using immersive-ar
-				} : 'immersive-ar' );
-
-				tempRequestSession( sessionType )
-					.then( function ( session ) {
-
-						// WebXRManager - xrFrame.getPose() Polyfill - line 279
-
-						const tempRequestAnimationFrame = session.requestAnimationFrame.bind(
-							session
-						);
-
-						session.requestAnimationFrame = function ( callback ) {
-
-							return tempRequestAnimationFrame( function ( time, frame ) {
-
-								// WebXRManager - xrFrame.getViewerPose() Polyfill - line 279
-								// Transforms view.viewMatrix to view.transform.inverse.matrix
-
-								const tempGetViewerPose = frame.getViewerPose.bind( frame );
-
-								frame.getViewerPose = function ( referenceSpace ) {
-
-									const pose = tempGetViewerPose( referenceSpace );
-
-									pose.views.forEach( function ( view ) {
-
-										view.transform = {
-											inverse: {
-												matrix: view.viewMatrix
-											}
-										};
-
-									} );
-
-									return pose;
-
-								};
-
-								// WebXRManager - xrFrame.getPose() Polyfill - line 259
-
-								const tempGetPose = ( isHelio96 ? null : frame.getPose.bind( frame ) );
-
-								frame.getPose = function ( targetRaySpace, referenceSpace ) {
-
-									if ( isHelio96 ) {
-
-										const inputPose = frame.getInputPose(
-											targetRaySpace,
-											referenceSpace
-										);
-
-										inputPose.transform = {
-											matrix: inputPose.targetRay.transformMatrix
-										};
-
-										return inputPose;
-
-									} else {
-
-										return tempGetPose( targetRaySpace.gripSpace, referenceSpace );
-
-									}
-
-								};
-
-								callback( time, frame );
-
-							} );
-
-						};
-
-						// WebXRManager - xrFrame.getPose( inputSource.targetRaySpace, referenceSpace) Polyfill - line 279
-
-						const tempGetInputSources = session.getInputSources.bind( session );
-
-						session.getInputSources = function () {
-
-							const res = tempGetInputSources();
-
-							res.forEach( function ( xrInputSource ) {
-
-								Object.defineProperty( xrInputSource, "targetRaySpace", {
-									get: function () {
-
-										return xrInputSource;
-
-									}
-								} );
-
-							} );
-
-							return res;
-
-						};
-
-						// WebXRManager - xrSession.getInputSources() Polyfill Line 132 - 136
-
-						session.inputSources = Object.defineProperty(
-							session,
-							"inputSources",
-							{
-								get: session.getInputSources
-							}
-						);
-
-						// WebXRManager - xrSession.updateRenderState() Polyfill Line 129
-
-						if ( isHelio96 ) {
-
-							session.updateRenderState = function ( { baseLayer } ) {
-
-								session.baseLayer = baseLayer;
-
-								// WebXRManager - xrSession.renderState.baseLayer Polyfill Line 219
-
-								session.renderState = {
-									baseLayer: baseLayer
-								};
-
-							};
-
-						}
-
-						// WebXRManager - xrSession.requestReferenceSpace() Polyfill Line 130
-
-						const tempRequestReferenceSpace = session.requestReferenceSpace.bind(
-							session
-						);
-
-						session.requestReferenceSpace = function () {
-
-							return tempRequestReferenceSpace( {
-								type: "stationary",
-								subtype: "floor-level"
-							} );
+				var sessionInit = { optionalFeatures: [ 'local-floor', 'bounded-floor' ] };
 
-						};
+				tempRequestSession( 'immersive-ar', sessionInit ).then( function ( session ) {
 
-						resolve( session );
+					resolve( session );
 
-					} )
-					.catch( function ( error ) {
+				} ).catch( function ( error ) {
 
-						return reject( error );
+					return reject( error );
 
-					} );
+				} );
 
 			} );
 

+ 72 - 0
examples/jsm/loaders/GLTFLoader.js

@@ -9,6 +9,7 @@
 import {
 	AnimationClip,
 	Bone,
+	Box3,
 	BufferAttribute,
 	BufferGeometry,
 	ClampToEdgeWrapping,
@@ -59,12 +60,14 @@ import {
 	ShaderMaterial,
 	Skeleton,
 	SkinnedMesh,
+	Sphere,
 	SpotLight,
 	TextureLoader,
 	TriangleFanDrawMode,
 	TriangleStripDrawMode,
 	UniformsUtils,
 	Vector2,
+	Vector3,
 	VectorKeyframeTrack,
 	VertexColors,
 	sRGBEncoding
@@ -2331,6 +2334,73 @@ var GLTFLoader = ( function () {
 
 	};
 
+	/**
+	 * @param {BufferGeometry} geometry
+	 * @param {GLTF.Primitive} primitiveDef
+	 * @param {GLTFParser} parser
+	 */
+	function computeBounds( geometry, primitiveDef, parser ) {
+
+		var attributes = primitiveDef.attributes;
+
+		var box = new Box3();
+
+		if ( attributes.POSITION !== undefined ) {
+
+			var accessor = parser.json.accessors[ attributes.POSITION ];
+			var min = accessor.min;
+			var max = accessor.max;
+
+			box.set(
+				new Vector3( min[ 0 ], min[ 1 ], min[ 2 ] ),
+				new Vector3( max[ 0 ], max[ 1 ], max[ 2 ] ) );
+
+		} else {
+
+			return;
+
+		}
+
+		var targets = primitiveDef.targets;
+
+		if ( targets !== undefined ) {
+
+			var vector = new Vector3();
+
+			for ( var i = 0, il = targets.length; i < il; i ++ ) {
+
+				var target = targets[ i ];
+
+				if ( target.POSITION !== undefined ) {
+
+					var accessor = parser.json.accessors[ target.POSITION ];
+					var min = accessor.min;
+					var max = accessor.max;
+
+					// we need to get max of absolute components because target weight is [-1,1]
+					vector.setX( Math.max( Math.abs( min[ 0 ] ), Math.abs( max[ 0 ] ) ) );
+					vector.setY( Math.max( Math.abs( min[ 1 ] ), Math.abs( max[ 1 ] ) ) );
+					vector.setZ( Math.max( Math.abs( min[ 2 ] ), Math.abs( max[ 2 ] ) ) );
+
+					box.expandByVector( vector );
+
+				}
+
+			}
+
+		}
+
+		geometry.boundingBox = box;
+
+		var sphere = new Sphere();
+
+		box.getCenter( sphere.center );
+		sphere.radius = box.min.distanceTo( box.max ) / 2;
+
+		geometry.boundingSphere = sphere;
+
+	}
+
 	/**
 	 * @param {BufferGeometry} geometry
 	 * @param {GLTF.Primitive} primitiveDef
@@ -2379,6 +2449,8 @@ var GLTFLoader = ( function () {
 
 		assignExtrasToUserData( geometry, primitiveDef );
 
+		computeBounds( geometry, primitiveDef, parser );
+
 		return Promise.all( pending ).then( function () {
 
 			return primitiveDef.targets !== undefined

+ 4 - 3
examples/jsm/nodes/materials/NodeMaterial.js

@@ -30,7 +30,9 @@ function NodeMaterial( vertex, fragment ) {
 
 	this.onBeforeCompile = function ( shader, renderer ) {
 
-		if ( this.needsUpdate ) {
+		var materialProperties = renderer.properties.get( this );
+
+		if ( this.version !== materialProperties.__version ) {
 
 			this.build( { renderer: renderer } );
 
@@ -74,6 +76,7 @@ Object.defineProperties( NodeMaterial.prototype, {
 
 		set: function ( value ) {
 
+			if ( value === true ) this.version ++;
 			this.needsCompile = value;
 
 		},
@@ -120,8 +123,6 @@ NodeMaterial.prototype.build = function ( params ) {
 
 	this.transparent = builder.requires.transparent || this.blending > NormalBlending;
 
-	this.needsUpdate = false;
-
 	return this;
 
 };

+ 146 - 0
examples/webgl_instancing_raycast.html

@@ -0,0 +1,146 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+	<title>three.js webgl - instancing - raycast</title>
+	<meta charset="utf-8">
+	<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
+	<link type="text/css" rel="stylesheet" href="main.css">
+</head>
+<body>
+<script type="module">
+
+	import * as THREE from '../build/three.module.js';
+
+	import Stats from './jsm/libs/stats.module.js';
+	import { GUI } from './jsm/libs/dat.gui.module.js';
+	import { OrbitControls } from "./jsm/controls/OrbitControls.js";
+
+	var camera, scene, renderer, stats;
+
+	var mesh, geometry;
+	var amount = parseInt( window.location.search.substr( 1 ) ) || 3;
+	var count = Math.pow( amount, 3 );
+	var object = new THREE.Object3D();
+
+	var intersection;
+	var raycaster = new THREE.Raycaster();
+	var mouse = new THREE.Vector2( 1, 1 );
+
+	var rotationTheta = 0.1;
+	var rotationMatrix = new THREE.Matrix4().makeRotationY( rotationTheta );
+	var instanceMatrix = new THREE.Matrix4();
+	var matrix = new THREE.Matrix4();
+
+	init();
+	animate();
+
+	function init() {
+
+		camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 0.1, 1000 );
+		camera.position.set( amount, amount, amount );
+		camera.lookAt( 0, 0, 0 );
+
+		scene = new THREE.Scene();
+
+		geometry = new THREE.TorusKnotBufferGeometry( 0.5, 0.2, 16, 4, 2, 3 );
+		geometry.scale( 0.5, 0.5, 0.5 );
+
+		var material = new THREE.MeshNormalMaterial( { flatShading: true } );
+
+		mesh = new THREE.InstancedMesh( geometry, material, count );
+
+		var i = 0;
+		var offset = amount / 2;
+
+		for ( var x = 0; x < amount; x ++ ) {
+
+			for ( var y = 0; y < amount; y ++ ) {
+
+				for ( var z = 0; z < amount; z ++ ) {
+
+					object.position.set( offset - x, offset - y, offset - z );
+
+					object.updateMatrix();
+
+					mesh.setMatrixAt( i ++, object.matrix );
+
+				}
+
+			}
+
+		}
+
+		scene.add( mesh );
+
+		//
+
+		var gui = new GUI();
+		gui.add( mesh, 'count', 0, count );
+
+		renderer = new THREE.WebGLRenderer( { antialias: true } );
+		renderer.setPixelRatio( window.devicePixelRatio );
+		renderer.setSize( window.innerWidth, window.innerHeight );
+		document.body.appendChild( renderer.domElement );
+
+		var orbitControls = new OrbitControls( camera, renderer.domElement );
+
+		stats = new Stats();
+		document.body.appendChild( stats.dom );
+
+		window.addEventListener( 'resize', onWindowResize, false );
+		document.addEventListener( 'mousemove', onMouseMove, false );
+
+	}
+
+	function onWindowResize() {
+
+		camera.aspect = window.innerWidth / window.innerHeight;
+		camera.updateProjectionMatrix();
+
+		renderer.setSize( window.innerWidth, window.innerHeight );
+
+	}
+
+	function onMouseMove( event ) {
+
+		event.preventDefault();
+
+		mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
+		mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
+
+	}
+
+	function animate() {
+
+		requestAnimationFrame( animate );
+
+		render();
+
+	}
+
+	function render() {
+
+		raycaster.setFromCamera( mouse, camera );
+
+		intersection = raycaster.intersectObjects( scene.children );
+
+		if ( intersection.length > 0 ) {
+
+			mesh.getMatrixAt( intersection[ 0 ].instanceId, instanceMatrix );
+			matrix.multiplyMatrices( instanceMatrix, rotationMatrix );
+
+			mesh.setMatrixAt( intersection[ 0 ].instanceId, matrix );
+			mesh.instanceMatrix.needsUpdate = true;
+
+		}
+
+		renderer.render( scene, camera );
+
+		stats.update();
+
+	}
+
+</script>
+
+</body>
+</html>

+ 71 - 95
examples/webvr_6dof_panorama.html

@@ -13,149 +13,125 @@
 
 		<div id="info">
 			<a href="http://threejs.org" target="_blank" rel="noopener">three.js</a> webvr - 360 6DOF panorama<br />
-			Written by <a href="https://orfleisher.com" target="_blank" rel="noopener">@juniorxsound</a>. Panorama from <a href="https://krpano.com/examples/?depthmap" target="_blank" rel="noopener">krpano</a>.
+			Created by <a href="https://orfleisher.com" target="_blank" rel="noopener">@juniorxsound</a>. Panorama from <a href="https://krpano.com/examples/?depthmap" target="_blank" rel="noopener">krpano</a>.
         </div>
-        
-        <script type="x-shader/x-vertex" id="vertexshader">
-            varying vec2 vUv;
-
-            uniform sampler2D depth_map;
-            uniform float displacement;
-
-            void main() {
-
-                vUv = uv;
-                
-                float depth = texture2D(depth_map, uv).r;
-                float disp = displacement * depth;
-                vec3 offset = position + (-normal) * disp;
-            
-                gl_Position = projectionMatrix *
-                                modelViewMatrix *
-                                vec4(offset, 1.0);
-            }
-
-        </script>
-
-        <script type="x-shader/x-fragment" id="fragmentshader">
-
-            varying vec2 vUv;
-
-            uniform sampler2D texture;
-
-            void main() {
-
-                gl_FragColor = texture2D(texture, vUv);
-
-            }
-
-        </script>
 
 		<script src="js/vr/HelioWebXRPolyfill.js"></script>
 
 		<script type="module">
 
-			import * as THREE from '../build/three.module.js';
-			import { WEBVR } from './jsm/vr/WebVR.js';
+            import * as THREE from '../build/three.module.js';
+            import { WEBVR } from './jsm/vr/WebVR.js';
 
-			var camera, scene, renderer, sphere, clock;
+            var camera, scene, renderer, sphere, clock;
 
-			init();
-			animate();
+            init();
+            animate();
 
-			function init() {
+            function init() {
 
                 var container = document.getElementById( 'container' );
-                
+
                 clock = new THREE.Clock();
 
                 scene = new THREE.Scene();
-				scene.background = new THREE.Color( 0x101010 );
+                scene.background = new THREE.Color( 0x101010 );
+
+                var light = new THREE.AmbientLight( 0x404040, 10 );
+                scene.add( light );
 
                 camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 1, 2000 );
                 var cameraRig = new THREE.Object3D();
-                cameraRig.position.y = -1.6;
+                cameraRig.position.y = - 1.6;
                 cameraRig.add( camera );
                 scene.add( cameraRig );
 
-                // Create the panoramic sphere with the custom shader material
+                // Create the panoramic sphere geometery
                 var panoSphereGeo = new THREE.SphereBufferGeometry( 6, 256, 256 );
-                var panoSphereMat = new THREE.ShaderMaterial({
-                    uniforms: {
-                        texture: { value : null },
-                        depth_map: { value: null },
-                        displacement: { value: 4 }
-                    },
-                    vertexShader: document.getElementById( 'vertexshader' ).textContent,
-                    fragmentShader: document.getElementById( 'fragmentshader' ).textContent,
-                    side: THREE.BackSide
-                });
+
+                // Create the panoramic sphere material
+                var panoSphereMat = new THREE.MeshStandardMaterial( {
+                    side: THREE.BackSide,
+                    displacementScale: - 4.0
+                } );
+
+                // Create the panoramic sphere mesh
                 sphere = new THREE.Mesh( panoSphereGeo, panoSphereMat );
-                scene.add( sphere );
 
                 // Load and assign the texture and depth map
-                var loader = new THREE.TextureLoader();
-                loader.load('./textures/kandao3.jpg', function ( texture ) {
-                    texture.minFilter = THREE.NearestFilter
-                    texture.magFilter = THREE.LinearFilter
-                    texture.format = THREE.RGBFormat
-                    texture.generateMipmaps = false
-                    sphere.material.uniforms.texture.value = texture;
-                });
+                var manager = new THREE.LoadingManager();
+                var loader = new THREE.TextureLoader( manager );
+
+                loader.load( './textures/kandao3.jpg', function ( texture ) {
 
-                loader.load('./textures/kandao3_depthmap.jpg', function ( depth ) {
-                    depth.minFilter = THREE.NearestFilter
-                    depth.magFilter = THREE.LinearFilter
-                    depth.format = THREE.RGBFormat
-                    depth.generateMipmaps = false
-                    sphere.material.uniforms.depth_map.value = depth;
-                });
+                    texture.minFilter = THREE.NearestFilter;
+                    texture.format = THREE.RGBFormat;
+                    texture.generateMipmaps = false;
+                    sphere.material.map = texture;
 
-				renderer = new THREE.WebGLRenderer();
-				renderer.setPixelRatio( window.devicePixelRatio );
-				renderer.setSize( window.innerWidth, window.innerHeight );
-				renderer.vr.enabled = true;
-				container.appendChild( renderer.domElement );
+                } );
 
-				document.body.appendChild( WEBVR.createButton( renderer ) );
+                loader.load( './textures/kandao3_depthmap.jpg', function ( depth ) {
 
-				//
+                    depth.minFilter = THREE.NearestFilter;
+                    depth.format = THREE.RGBFormat;
+                    depth.generateMipmaps = false;
+                    sphere.material.displacementMap = depth;
 
-				window.addEventListener( 'resize', onWindowResize, false );
+                } );
 
-			}
+                // On load complete add the panoramic sphere to the scene
+                manager.onLoad = function () {
 
-			function onWindowResize() {
+                    scene.add( sphere );
 
-				camera.aspect = window.innerWidth / window.innerHeight;
-				camera.updateProjectionMatrix();
+                };
 
-				renderer.setSize( window.innerWidth, window.innerHeight );
+                renderer = new THREE.WebGLRenderer();
+                renderer.setPixelRatio( window.devicePixelRatio );
+                renderer.setSize( window.innerWidth, window.innerHeight );
+                renderer.vr.enabled = true;
+                container.appendChild( renderer.domElement );
 
-			}
+                document.body.appendChild( WEBVR.createButton( renderer ) );
 
-			function animate() {
+                //
 
-				renderer.setAnimationLoop( render );
+                window.addEventListener( 'resize', onWindowResize, false );
+
+            }
 
-			}
+            function onWindowResize() {
 
-			function render() {
+                camera.aspect = window.innerWidth / window.innerHeight;
+                camera.updateProjectionMatrix();
+
+                renderer.setSize( window.innerWidth, window.innerHeight );
+
+            }
+
+            function animate() {
+
+                renderer.setAnimationLoop( render );
+
+            }
+
+            function render() {
 
                 // If we are not presenting move the camera a little so the effect is visible
-                if (!renderer.vr.isPresenting()) {
+                if ( ! renderer.vr.isPresenting() ) {
 
                     var time = clock.getElapsedTime();
 
                     sphere.rotation.y += 0.001;
-                    sphere.position.x = Math.sin(time) * 0.2;
-                    sphere.position.z = Math.cos(time) * 0.2;
+                    sphere.position.x = Math.sin( time ) * 0.2;
+                    sphere.position.z = Math.cos( time ) * 0.2;
 
                 }
 
-				renderer.render( scene, camera );
+                renderer.render( scene, camera );
 
-			}
+            }
 
 		</script>
 	</body>

+ 28 - 22
src/core/BufferAttribute.d.ts

@@ -16,54 +16,60 @@ export class BufferAttribute {
 	updateRange: { offset: number; count: number };
 	version: number;
 	normalized: boolean;
-	needsUpdate: boolean;
 	count: number;
-	onUpload: Function;
 
-	setUsage( usage: Usage ): BufferAttribute;
-	clone(): this;
+	set needsUpdate( value: boolean );
+
+	isBufferAttribute: true;
+
+	onUploadCallback: () => void;
+	onUpload( callback: () => void ): this;
+	setUsage( usage: Usage ): this;
+	clone(): BufferAttribute;
 	copy( source: BufferAttribute ): this;
 	copyAt(
 		index1: number,
 		attribute: BufferAttribute,
 		index2: number
-	): BufferAttribute;
-	copyArray( array: ArrayLike<number> ): BufferAttribute;
+	): this;
+	copyArray( array: ArrayLike<number> ): this;
 	copyColorsArray(
 		colors: { r: number; g: number; b: number }[]
-	): BufferAttribute;
-	copyVector2sArray( vectors: { x: number; y: number }[] ): BufferAttribute;
+	): this;
+	copyVector2sArray( vectors: { x: number; y: number }[] ): this;
 	copyVector3sArray(
 		vectors: { x: number; y: number; z: number }[]
-	): BufferAttribute;
+	): this;
 	copyVector4sArray(
 		vectors: { x: number; y: number; z: number; w: number }[]
-	): BufferAttribute;
+	): this;
 	set(
 		value: ArrayLike<number> | ArrayBufferView,
 		offset?: number
-	): BufferAttribute;
+	): this;
 	getX( index: number ): number;
-	setX( index: number, x: number ): BufferAttribute;
+	setX( index: number, x: number ): this;
 	getY( index: number ): number;
-	setY( index: number, y: number ): BufferAttribute;
+	setY( index: number, y: number ): this;
 	getZ( index: number ): number;
-	setZ( index: number, z: number ): BufferAttribute;
+	setZ( index: number, z: number ): this;
 	getW( index: number ): number;
-	setW( index: number, z: number ): BufferAttribute;
-	setXY( index: number, x: number, y: number ): BufferAttribute;
-	setXYZ( index: number, x: number, y: number, z: number ): BufferAttribute;
+	setW( index: number, z: number ): this;
+	setXY( index: number, x: number, y: number ): this;
+	setXYZ( index: number, x: number, y: number, z: number ): this;
 	setXYZW(
 		index: number,
 		x: number,
 		y: number,
 		z: number,
 		w: number
-	): BufferAttribute;
-	/**
-	 * @deprecated Use {@link BufferAttribute#count .count} instead.
-	 */
-	length: number;
+	): this;
+	toJSON(): {
+		itemSize: number,
+		type: string,
+		array: number[],
+		normalized: boolean
+	};
 
 }
 

+ 5 - 7
src/core/InterleavedBufferAttribute.d.ts

@@ -11,13 +11,15 @@ export class InterleavedBufferAttribute {
 		normalized?: boolean
 	);
 
-	uuid: string;
 	data: InterleavedBuffer;
 	itemSize: number;
 	offset: number;
-	count: number;
 	normalized: boolean;
-	array: any[];
+
+	get count(): number;
+	get array(): ArrayLike<number>;
+
+	isInterleavedBufferAttribute: true;
 
 	getX( index: number ): number;
 	setX( index: number, x: number ): InterleavedBufferAttribute;
@@ -41,9 +43,5 @@ export class InterleavedBufferAttribute {
 		z: number,
 		w: number
 	): InterleavedBufferAttribute;
-	/**
-	 * @deprecated Use {@link InterleavedBufferAttribute#count .count} instead.
-	 */
-	length: number;
 
 }

+ 2 - 2
src/loaders/AnimationLoader.d.ts

@@ -8,10 +8,10 @@ export class AnimationLoader extends Loader {
 
 	load(
 		url: string,
-		onLoad?: ( response: string | ArrayBuffer ) => void,
+		onLoad: ( response: AnimationClip[] ) => void,
 		onProgress?: ( request: ProgressEvent ) => void,
 		onError?: ( event: ErrorEvent ) => void
-	): any;
+	): void;
 	parse( json: any ): AnimationClip[];
 
 }

+ 3 - 3
src/loaders/AudioLoader.d.ts

@@ -7,9 +7,9 @@ export class AudioLoader extends Loader {
 
 	load(
 		url: string,
-		onLoad: Function,
-		onPrgress: Function,
-		onError: Function
+		onLoad: ( audioBuffer: AudioBuffer ) => void,
+		onProgress?: ( request: ProgressEvent ) => void,
+		onError?: ( event: ErrorEvent ) => void
 	): void;
 
 }

+ 5 - 4
src/loaders/BufferGeometryLoader.d.ts

@@ -1,6 +1,7 @@
 import { Loader } from './Loader';
 import { LoadingManager } from './LoadingManager';
 import { BufferGeometry } from './../core/BufferGeometry';
+import { InstancedBufferGeometry } from '../core/InstancedBufferGeometry';
 
 export class BufferGeometryLoader extends Loader {
 
@@ -8,10 +9,10 @@ export class BufferGeometryLoader extends Loader {
 
 	load(
 		url: string,
-		onLoad: ( bufferGeometry: BufferGeometry ) => void,
-		onProgress?: ( event: any ) => void,
-		onError?: ( event: any ) => void
+		onLoad: ( bufferGeometry: InstancedBufferGeometry | BufferGeometry ) => void,
+		onProgress?: ( request: ProgressEvent ) => void,
+		onError?: ( event: ErrorEvent ) => void
 	): void;
-	parse( json: any ): BufferGeometry;
+	parse( json: any ): InstancedBufferGeometry | BufferGeometry;
 
 }

+ 1 - 1
src/loaders/ImageBitmapLoader.d.ts

@@ -10,7 +10,7 @@ export class ImageBitmapLoader extends Loader {
 	setOptions( options: object ): ImageBitmapLoader;
 	load(
 		url: string,
-		onLoad?: ( response: string | ArrayBuffer ) => void,
+		onLoad?: ( response: ImageBitmap ) => void,
 		onProgress?: ( request: ProgressEvent ) => void,
 		onError?: ( event: ErrorEvent ) => void
 	): any;

+ 2 - 0
src/loaders/LoadingManager.js

@@ -121,6 +121,8 @@ function LoadingManager( onLoad, onProgress, onError ) {
 			var regex = handlers[ i ];
 			var loader = handlers[ i + 1 ];
 
+			if ( regex.global ) regex.lastIndex = 0; // see #17920
+
 			if ( regex.test( file ) ) {
 
 				return loader;

+ 5 - 0
src/materials/Material.d.ts

@@ -293,6 +293,11 @@ export class Material extends EventDispatcher {
 	 */
 	userData: any;
 
+	/**
+	 * This starts at 0 and counts how many times .needsUpdate is set to true.
+	 */
+	version: number;
+
 	/**
 	 * Return a new material with the same parameters as this material.
 	 */

+ 10 - 1
src/materials/Material.js

@@ -74,7 +74,7 @@ function Material() {
 
 	this.userData = {};
 
-	this.needsUpdate = true;
+	this.version = 0;
 
 }
 
@@ -422,5 +422,14 @@ Material.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
 
 } );
 
+Object.defineProperty( Material.prototype, 'needsUpdate', {
+
+	set: function ( value ) {
+
+		if ( value === true ) this.version ++;
+
+	}
+
+} );
 
 export { Material };

+ 12 - 31
src/math/Box3.js

@@ -10,8 +10,11 @@ var _points = [
 	new Vector3(),
 	new Vector3()
 ];
+
 var _vector = new Vector3();
 
+var _box = new Box3();
+
 // triangle centered vertices
 
 var _v0 = new Vector3();
@@ -41,6 +44,7 @@ function Box3( min, max ) {
 
 }
 
+
 Object.assign( Box3.prototype, {
 
 	isBox3: true,
@@ -240,8 +244,6 @@ Object.assign( Box3.prototype, {
 
 	expandByObject: function ( object ) {
 
-		var i, l;
-
 		// Computes the world-axis-aligned bounding box of an object (including its children),
 		// accounting for both the object's, and children's, world transforms
 
@@ -251,44 +253,23 @@ Object.assign( Box3.prototype, {
 
 		if ( geometry !== undefined ) {
 
-			if ( geometry.isGeometry ) {
-
-				var vertices = geometry.vertices;
-
-				for ( i = 0, l = vertices.length; i < l; i ++ ) {
-
-					_vector.copy( vertices[ i ] );
-					_vector.applyMatrix4( object.matrixWorld );
-
-					this.expandByPoint( _vector );
-
-				}
+			if ( geometry.boundingBox === null ) {
 
-			} else if ( geometry.isBufferGeometry ) {
+				geometry.computeBoundingBox();
 
-				var attribute = geometry.attributes.position;
-
-				if ( attribute !== undefined ) {
-
-					for ( i = 0, l = attribute.count; i < l; i ++ ) {
-
-						_vector.fromBufferAttribute( attribute, i ).applyMatrix4( object.matrixWorld );
-
-						this.expandByPoint( _vector );
-
-					}
+			}
 
-				}
+			_box.copy( geometry.boundingBox );
+			_box.applyMatrix4( object.matrixWorld );
 
-			}
+			this.expandByPoint( _box.min );
+			this.expandByPoint( _box.max );
 
 		}
 
-		//
-
 		var children = object.children;
 
-		for ( i = 0, l = children.length; i < l; i ++ ) {
+		for ( var i = 0, l = children.length; i < l; i ++ ) {
 
 			this.expandByObject( children[ i ] );
 

+ 3 - 0
src/objects/InstancedMesh.d.ts

@@ -17,6 +17,9 @@ export class InstancedMesh extends Mesh {
 	instanceMatrix: BufferAttribute;
 	isInstancedMesh: true;
 
+	getMatrixAt( index: number, matrix: Matrix4 ): void;
 	setMatrixAt( index: number, matrix: Matrix4 ): void;
 
+
+
 }

+ 57 - 3
src/objects/InstancedMesh.js

@@ -1,9 +1,16 @@
 /**
  * @author mrdoob / http://mrdoob.com/
  */
-
 import { BufferAttribute } from '../core/BufferAttribute.js';
 import { Mesh } from './Mesh.js';
+import { Matrix4 } from '../math/Matrix4.js';
+
+var _instanceLocalMatrix = new Matrix4();
+var _instanceWorldMatrix = new Matrix4();
+
+var _instanceIntersects = [];
+
+var _mesh = new Mesh();
 
 function InstancedMesh( geometry, material, count ) {
 
@@ -21,7 +28,52 @@ InstancedMesh.prototype = Object.assign( Object.create( Mesh.prototype ), {
 
 	isInstancedMesh: true,
 
-	raycast: function () {},
+	getMatrixAt: function ( index, matrix ) {
+
+		matrix.fromArray( this.instanceMatrix.array, index * 16 );
+
+	},
+
+	raycast: function ( raycaster, intersects ) {
+
+		var matrixWorld = this.matrixWorld;
+		var raycastTimes = this.count;
+
+		_mesh.geometry = this.geometry;
+		_mesh.material = this.material;
+
+		if ( _mesh.material === undefined ) return;
+
+		for ( var instanceId = 0; instanceId < raycastTimes; instanceId ++ ) {
+
+			// calculate the world matrix for each instance
+
+			this.getMatrixAt( instanceId, _instanceLocalMatrix );
+
+			_instanceWorldMatrix.multiplyMatrices( matrixWorld, _instanceLocalMatrix );
+
+			// the mesh represents this single instance
+
+			_mesh.matrixWorld = _instanceWorldMatrix;
+
+			_mesh.raycast( raycaster, _instanceIntersects );
+
+			// process the result of raycast
+
+			if ( _instanceIntersects.length > 0 ) {
+
+				_instanceIntersects[ 0 ].instanceId = instanceId;
+				_instanceIntersects[ 0 ].object = this;
+
+				intersects.push( _instanceIntersects[ 0 ] );
+
+				_instanceIntersects.length = 0;
+
+			}
+
+		}
+
+	},
 
 	setMatrixAt: function ( index, matrix ) {
 
@@ -29,7 +81,9 @@ InstancedMesh.prototype = Object.assign( Object.create( Mesh.prototype ), {
 
 	},
 
-	updateMorphTargets: function () {}
+	updateMorphTargets: function () {
+
+	}
 
 } );
 

+ 11 - 3
src/renderers/WebGLRenderer.js

@@ -742,6 +742,14 @@ function WebGLRenderer( parameters ) {
 
 		var index = geometry.index;
 		var position = geometry.attributes.position;
+
+		//
+
+		if ( index !== null && index.count === 0 ) return;
+		if ( position === undefined || position.count === 0 ) return;
+
+		//
+
 		var rangeFactor = 1;
 
 		if ( material.wireframe === true ) {
@@ -1675,7 +1683,7 @@ function WebGLRenderer( parameters ) {
 
 		}
 
-		if ( material.needsUpdate === false ) {
+		if ( material.version === materialProperties.__version ) {
 
 			if ( materialProperties.program === undefined ) {
 
@@ -1699,10 +1707,10 @@ function WebGLRenderer( parameters ) {
 
 		}
 
-		if ( material.needsUpdate ) {
+		if ( material.version !== materialProperties.__version ) {
 
 			initMaterial( material, fog, object );
-			material.needsUpdate = false;
+			materialProperties.__version = material.version;
 
 		}
 

+ 2 - 13
src/renderers/shaders/ShaderChunk/normalmap_pars_fragment.glsl.js

@@ -32,21 +32,10 @@ export default /* glsl */`
 		vec3 T = normalize( ( - q0 * st1.s + q1 * st0.s ) * scale );
 		vec3 N = normalize( surf_norm );
 
-		#ifdef DOUBLE_SIDED
-
-			// Workaround for Adreno GPUs gl_FrontFacing bug. See #15850 and #10331
-
-			bool frontFacing = dot( cross( S, T ), N ) > 0.0;
-
-			mapN.xy *= ( float( frontFacing ) * 2.0 - 1.0 );
-
-		#else
-
-			mapN.xy *= ( float( gl_FrontFacing ) * 2.0 - 1.0 );
+		mat3 tsn = mat3( S, T, N );
 
-		#endif
+		mapN.xy *= ( float( gl_FrontFacing ) * 2.0 - 1.0 );
 
-		mat3 tsn = mat3( S, T, N );
 		return normalize( tsn * mapN );
 
 	}

+ 4 - 13
src/renderers/shaders/ShaderChunk/packing.glsl.js

@@ -25,20 +25,11 @@ float unpackRGBAToDepth( const in vec4 v ) {
 	return dot( v, UnpackFactors );
 }
 
-vec4 encodeHalfRGBA ( vec2 v ) {
-	vec4 encoded = vec4( 0.0 );
-	const vec2 offset = vec2( 1.0 / 255.0, 0.0 );
-
-	encoded.xy = vec2( v.x, fract( v.x * 255.0 ) );
-	encoded.xy = encoded.xy - ( encoded.yy * offset );
-
-	encoded.zw = vec2( v.y, fract( v.y * 255.0 ) );
-	encoded.zw = encoded.zw - ( encoded.ww * offset );
-
-	return encoded;
+vec4 pack2HalfToRGBA( vec2 v ) {
+	vec4 r = vec4( v.x, fract( v.x * 255.0 ), v.y, fract( v.y * 255.0 ));
+	return vec4( r.x - r.y / 255.0, r.y, r.z - r.w / 255.0, r.w);
 }
-
-vec2 decodeHalfRGBA( vec4 v ) {
+vec2 unpack2HalfToRGBA( vec4 v ) {
 	return vec2( v.x + ( v.y / 255.0 ), v.z + ( v.w / 255.0 ) );
 }
 

+ 1 - 1
src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js

@@ -38,7 +38,7 @@ export default /* glsl */`
 
 	vec2 texture2DDistribution( sampler2D shadow, vec2 uv ) {
 
-		return decodeHalfRGBA( texture2D( shadow, uv ) );
+		return unpack2HalfToRGBA( texture2D( shadow, uv ) );
 
 	}
 

+ 4 - 4
src/renderers/shaders/ShaderLib/vsm_frag.glsl.js

@@ -9,7 +9,7 @@ void main() {
 
   float mean = 0.0;
   float squared_mean = 0.0;
-  
+
 	// This seems totally useless but it's a crazy work around for a Adreno compiler bug
 	float depth = unpackRGBAToDepth( texture2D( shadow_pass, ( gl_FragCoord.xy  ) / resolution ) );
 
@@ -17,7 +17,7 @@ void main() {
 
     #ifdef HORIZONAL_PASS
 
-      vec2 distribution = decodeHalfRGBA ( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( i, 0.0 ) * radius ) / resolution ) );
+      vec2 distribution = unpack2HalfToRGBA ( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( i, 0.0 ) * radius ) / resolution ) );
       mean += distribution.x;
       squared_mean += distribution.y * distribution.y + distribution.x * distribution.x;
 
@@ -34,9 +34,9 @@ void main() {
   mean = mean * HALF_SAMPLE_RATE;
   squared_mean = squared_mean * HALF_SAMPLE_RATE;
 
-  float std_dev = pow( squared_mean - mean * mean, 0.5 );
+  float std_dev = sqrt( squared_mean - mean * mean );
 
-  gl_FragColor = encodeHalfRGBA( vec2( mean, std_dev ) );
+  gl_FragColor = pack2HalfToRGBA( vec2( mean, std_dev ) );
 
 }
 `;

+ 11 - 3
src/renderers/webgl/WebGLAttributes.d.ts

@@ -1,11 +1,19 @@
+import { BufferAttribute } from "../../core/BufferAttribute";
+import { InterleavedBufferAttribute } from "../../core/InterleavedBufferAttribute";
+
 export class WebGLAttributes {
 
 	constructor( gl: WebGLRenderingContext | WebGL2RenderingContext );
 
-	get( attribute: any ): any;
+	get( attribute: BufferAttribute | InterleavedBufferAttribute ): {
+		buffer: WebGLBuffer,
+		type: GLenum,
+		bytesPerElement: number,
+		version: number
+	};
 
-	remove( attribute: any ): void;
+	remove( attribute: BufferAttribute | InterleavedBufferAttribute ): void;
 
-	update( attribute: any, bufferType: Array<any> ): void;
+	update( attribute: BufferAttribute | InterleavedBufferAttribute, bufferType: GLenum ): void;
 
 }

+ 11 - 4
src/renderers/webgl/WebGLGeometries.d.ts

@@ -1,9 +1,16 @@
+import { WebGLAttributes } from './WebGLAttributes';
+import { WebGLInfo } from './WebGLInfo';
+import { BufferAttribute } from '../../core/BufferAttribute';
+import { BufferGeometry } from '../../core/BufferGeometry';
+import { Geometry } from '../../core/Geometry';
+import { Object3D } from '../../core/Object3D';
+
 export class WebGLGeometries {
 
-	constructor( gl: WebGLRenderingContext, attributes: any, info: any );
+	constructor( gl: WebGLRenderingContext, attributes: WebGLAttributes, info: WebGLInfo );
 
-	get( object: any, geometry: any ): any;
-	update( geometry: any ): any;
-	getWireframeAttribute( geometry: any ): any;
+	get( object: Object3D, geometry: Geometry | BufferGeometry ): BufferGeometry;
+	update( geometry: Geometry | BufferGeometry ): void;
+	getWireframeAttribute( geometry: Geometry | BufferGeometry ): BufferAttribute;
 
 }

+ 1 - 1
src/renderers/webgl/WebGLInfo.d.ts

@@ -20,7 +20,7 @@ export class WebGLInfo {
 		points: number;
 		triangles: number;
 	};
-	update( count: any, mode: any, instanceCount: any ): void;
+	update( count: number, mode: GLenum, instanceCount: number ): void;
 	reset(): void;
 
 }

+ 28 - 0
src/renderers/webvr/WebVRManager.js

@@ -104,6 +104,7 @@ function WebVRManager( renderer ) {
 	//
 
 	var triggers = [];
+	var grips = [];
 
 	function findGamepad( id ) {
 
@@ -179,6 +180,33 @@ function WebVRManager( renderer ) {
 
 				}
 
+				// Grip
+				buttonId = 2;
+
+				if ( grips[ i ] === undefined ) grips[ i ] = false;
+
+				// Skip if the grip button doesn't exist on this controller
+				if ( gamepad.buttons[ buttonId ] !== undefined ) {
+
+					if ( grips[ i ] !== gamepad.buttons[ buttonId ].pressed ) {
+
+						grips[ i ] = gamepad.buttons[ buttonId ].pressed;
+
+						if ( grips[ i ] === true ) {
+
+							controller.dispatchEvent( { type: 'squeezestart' } );
+
+						} else {
+
+							controller.dispatchEvent( { type: 'squeezeend' } );
+							controller.dispatchEvent( { type: 'squeeze' } );
+
+						}
+
+					}
+
+				}
+
 			} else {
 
 				controller.visible = false;

+ 3 - 0
src/renderers/webvr/WebXRManager.js

@@ -133,6 +133,9 @@ function WebXRManager( renderer, gl ) {
 			session.addEventListener( 'select', onSessionEvent );
 			session.addEventListener( 'selectstart', onSessionEvent );
 			session.addEventListener( 'selectend', onSessionEvent );
+			session.addEventListener( 'squeeze', onSessionEvent );
+			session.addEventListener( 'squeezestart', onSessionEvent );
+			session.addEventListener( 'squeezeend', onSessionEvent );
 			session.addEventListener( 'end', onSessionEnd );
 
 			// eslint-disable-next-line no-undef

+ 23 - 0
test/unit/src/loaders/LoadingManager.tests.js

@@ -4,6 +4,7 @@
 /* global QUnit */
 
 import { LoadingManager } from '../../../../src/loaders/LoadingManager';
+import { Loader } from '../../../../src/loaders/Loader';
 
 export default QUnit.module( 'Loaders', () => {
 
@@ -59,6 +60,28 @@ export default QUnit.module( 'Loaders', () => {
 
 		} );
 
+		QUnit.test( "getHandler", ( assert ) => {
+
+			const loadingManager = new LoadingManager();
+			const loader = new Loader();
+
+			const regex1 = /\.jpg$/i;
+			const regex2 = /\.jpg$/gi;
+
+			loadingManager.addHandler( regex1, loader );
+
+			assert.equal( loadingManager.getHandler( 'foo.jpg' ), loader, 'Returns the expected loader.' );
+			assert.equal( loadingManager.getHandler( 'foo.jpg.png' ), null, 'Returns null since the correct file extension is not at the end of the file name.' );
+			assert.equal( loadingManager.getHandler( 'foo.jpeg' ), null, 'Returns null since file extension is wrong.' );
+
+			loadingManager.removeHandler( regex1 );
+			loadingManager.addHandler( regex2, loader );
+
+			assert.equal( loadingManager.getHandler( 'foo.jpg' ), loader, 'Returns the expected loader when using a regex with "g" flag.' );
+			assert.equal( loadingManager.getHandler( 'foo.jpg' ), loader, 'Returns the expected loader when using a regex with "g" flag. Test twice, see #17920.' );
+
+		} );
+
 	} );
 
 } );

Some files were not shown because too many files changed in this diff