Browse Source

Merge remote-tracking branch 'remotes/upstream/dev' into dev

webglzhang 5 years ago
parent
commit
6fd3a259c6

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


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


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


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

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

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

@@ -21,11 +21,11 @@ Menubar.Examples = function ( editor ) {
 	// Examples
 	// Examples
 
 
 	var items = [
 	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();
 	var loader = new THREE.FileLoader();
@@ -38,7 +38,7 @@ Menubar.Examples = function ( editor ) {
 
 
 			var option = new UI.Row();
 			var option = new UI.Row();
 			option.setClass( 'option' );
 			option.setClass( 'option' );
-			option.setTextContent( item.title );
+			option.setTextContent( strings.getKey( item.title ) );
 			option.onClick( function () {
 			option.onClick( function () {
 
 
 				if ( confirm( 'Any unsaved data will be lost. Are you sure?' ) ) {
 				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/play/play': 'Play',
 
 
 			'menubar/examples': 'Examples',
 			'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': 'Help',
 			'menubar/help/source_code': 'Source Code',
 			'menubar/help/source_code': 'Source Code',
@@ -364,6 +369,11 @@ var Strings = function ( config ) {
 			'menubar/play/play': '启动',
 			'menubar/play/play': '启动',
 
 
 			'menubar/examples': '示例',
 			'menubar/examples': '示例',
+			'menubar/examples/Arkanoid': '打砖块',
+			'menubar/examples/Camera': ' 摄像机',
+			'menubar/examples/Particles': '粒子',
+			'menubar/examples/Pong': '乒乓球',
+			'menubar/examples/Shaders': '着色器',
 
 
 			'menubar/help': '帮助',
 			'menubar/help': '帮助',
 			'menubar/help/source_code': '源码',
 			'menubar/help/source_code': '源码',

+ 6 - 5
examples/js/loaders/GLTFLoader.js

@@ -2285,12 +2285,13 @@ THREE.GLTFLoader = ( function () {
 			var max = accessor.max;
 			var max = accessor.max;
 
 
 			box.set(
 			box.set(
-				new THREE.Vector3( min[0], min[1], min[2] ),
-				new THREE.Vector3( max[0], max[1], max[2] ) );
+				new THREE.Vector3( min[ 0 ], min[ 1 ], min[ 2 ] ),
+				new THREE.Vector3( max[ 0 ], max[ 1 ], max[ 2 ] ) );
 
 
 		} else {
 		} else {
 
 
 			return;
 			return;
+
 		}
 		}
 
 
 		var targets = primitiveDef.targets;
 		var targets = primitiveDef.targets;
@@ -2310,9 +2311,9 @@ THREE.GLTFLoader = ( function () {
 					var max = accessor.max;
 					var max = accessor.max;
 
 
 					// we need to get max of absolute components because target weight is [-1,1]
 					// 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] ) ) );
+					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 );
 					box.expandByVector( vector );
 
 

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

@@ -9,6 +9,7 @@
 import {
 import {
 	AnimationClip,
 	AnimationClip,
 	Bone,
 	Bone,
+	Box3,
 	BufferAttribute,
 	BufferAttribute,
 	BufferGeometry,
 	BufferGeometry,
 	ClampToEdgeWrapping,
 	ClampToEdgeWrapping,
@@ -59,12 +60,14 @@ import {
 	ShaderMaterial,
 	ShaderMaterial,
 	Skeleton,
 	Skeleton,
 	SkinnedMesh,
 	SkinnedMesh,
+	Sphere,
 	SpotLight,
 	SpotLight,
 	TextureLoader,
 	TextureLoader,
 	TriangleFanDrawMode,
 	TriangleFanDrawMode,
 	TriangleStripDrawMode,
 	TriangleStripDrawMode,
 	UniformsUtils,
 	UniformsUtils,
 	Vector2,
 	Vector2,
+	Vector3,
 	VectorKeyframeTrack,
 	VectorKeyframeTrack,
 	VertexColors,
 	VertexColors,
 	sRGBEncoding
 	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 {BufferGeometry} geometry
 	 * @param {GLTF.Primitive} primitiveDef
 	 * @param {GLTF.Primitive} primitiveDef
@@ -2379,6 +2449,8 @@ var GLTFLoader = ( function () {
 
 
 		assignExtrasToUserData( geometry, primitiveDef );
 		assignExtrasToUserData( geometry, primitiveDef );
 
 
+		computeBounds( geometry, primitiveDef, parser );
+
 		return Promise.all( pending ).then( function () {
 		return Promise.all( pending ).then( function () {
 
 
 			return primitiveDef.targets !== undefined
 			return primitiveDef.targets !== undefined

+ 6 - 14
src/renderers/shaders/ShaderChunk/packing.glsl.js

@@ -22,23 +22,15 @@ vec4 packDepthToRGBA( const in float v ) {
 }
 }
 
 
 float unpackRGBAToDepth( const in vec4 v ) {
 float unpackRGBAToDepth( const in vec4 v ) {
-	return dot( v, UnpackFactors );
+	return dot( floor( v * 255.0 + 0.5 ) / 255.0, 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 packHalfToRGBA( 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 unpackHalfToRGBA( vec4 v ) {
+	v = floor( v * 255.0 + 0.5 ) / 255.0;
 	return vec2( v.x + ( v.y / 255.0 ), v.z + ( v.w / 255.0 ) );
 	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 ) {
 	vec2 texture2DDistribution( sampler2D shadow, vec2 uv ) {
 
 
-		return decodeHalfRGBA( texture2D( shadow, uv ) );
+		return unpackHalfToRGBA( texture2D( shadow, uv ) );
 
 
 	}
 	}
 
 

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

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

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