xushiting hace 5 años
padre
commit
73b97ba09f
Se han modificado 5 ficheros con 508 adiciones y 10 borrados
  1. 154 1
      build/three.js
  2. 154 1
      build/three.module.js
  3. 47 8
      examples/Fdage1.html
  4. 144 0
      src/math/Matrix4.js
  5. 9 0
      src/renderers/WebGLRenderer.js

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 154 - 1
build/three.js


La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 154 - 1
build/three.module.js


+ 47 - 8
examples/Fdage1.html

@@ -46,13 +46,16 @@
 			var container, stats;
 
 			var camera, controls, scene, renderer;
-
+			var specularMapScene,specularMapTarget;
 
 			var mesh;
 
 			init();
+			renderer.setClearColor2(1, 0, 0, 1)
 			animate();
-
+			//setClearColor();
+			renderer.setClearColor2(0.0582, 0.06772, 0.07805, 1)
+			//renderer.setClearColor2(0.5, 0.5, 0.5, 1)
 			function init() {
 
 				container = document.getElementById( 'container' );
@@ -62,10 +65,10 @@
 				camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, .1, 2000000 );
 
 				scene = new THREE.Scene();
-
+				specularMapScene = new THREE.Scene();
 				//
 
-				scene.add( new THREE.AmbientLight( 0x999999 ) );
+				//scene.add( new THREE.AmbientLight( 0x999999 ) );
 
 				// var light1 = new THREE.DirectionalLight( 0xffffff, 0.5 );
 				// light1.position.set( 1, 1, 1 );
@@ -124,14 +127,15 @@
                         fragmentShader: shader.fragmentShader,
 						side:2
                     } );
-     
+					
+					//scene.json里backgroundBrightness对应的是0.488874
                     material.uniforms.b.value = 7 * Math.sqrt(0.488874);
                     material.uniforms.tex.value = texture;
 					mesh = new THREE.Mesh( geometry, material );
-					mesh.position.set(0,5,0);
-					scene.add( mesh );
+					specularMapScene.add( mesh );
 
                 }.bind(this)); 
+				
 
                 // this.material = new RawShaderMaterial( {
                 //     uniforms: shader.uniforms,
@@ -148,11 +152,12 @@
 				mesh1 = new THREE.Mesh( geometry1, material1 );
 				scene.add( mesh1 );
 
+				//View();
 				renderer = new THREE.WebGLRenderer({ antialias: true });
 				renderer.setPixelRatio( window.devicePixelRatio );
 				renderer.setSize( window.innerWidth, window.innerHeight );
 				container.appendChild( renderer.domElement );
-
+				
                 controls = new THREE.OrbitControls( camera, renderer.domElement );
 				controls.target.set( 0, 0, 0 );
 				controls.update();
@@ -160,6 +165,8 @@
 
 				initGUI();
 
+				
+
 				stats = new Stats();
 				container.appendChild( stats.dom );
 
@@ -180,6 +187,8 @@
 			function animate() {
 				requestAnimationFrame( animate );
 				renderer.render( scene, camera );
+				renderer.render( specularMapScene, camera, specularMapTarget);
+				
 				//controls.update();
 			}
 	
@@ -202,6 +211,36 @@
 				gui.add( effectController, "cameraPositionZ", -5, 1, 0.1 ).onChange( guiChanged );
 				guiChanged();
 			}
+
+			function View(){
+				var transform = new THREE.Matrix4();
+				//对应scene.json里的orbitRadius
+				transform.set(1,0,0,0,0,1,0,0,0,0,1,20.1192,0,0,0,1);
+				//对应scene.json里的angles
+				//transform = transform.rotation(3.33705);
+				//transform = transform.rotation(-19.8208);
+				var c = transform.rotation(new THREE.Matrix4(), 3.33705, 0);
+				var b = transform.rotation(new THREE.Matrix4(), -19.8208, 1);
+				c = transform.mul(c, b, c);
+				transform.elements = transform.mul(transform.elements, c, transform.elements);
+				//对应scene.json里的pivot
+				transform.elements[12] += 1.26448;
+				transform.elements[13] += 1.59621;
+				transform.elements[14] += -1.35686;
+				camera.Matrix4 = transform.invert(new THREE.Matrix4(), transform.elements);
+				camera.updateProjectionMatrix();
+				console.log('ok');
+			}
+
+			function setClearColor() {
+				renderer.setClearColor2(0.0582, 0.06772, 0.07805, 1)
+			}
+
+			function setSpecularTexture(){
+				var pars = { minFilter: THREE.LinearFilter, magFilter: THREE.LinearFilter, format: THREE.RGBFormat };
+				specularMapTarget = new THREE.WebGLRenderTarget( window.innerWidth, window.innerHeight, pars );
+			}
+
 		</script>
 
 	</body>

+ 144 - 0
src/math/Matrix4.js

@@ -930,6 +930,150 @@ Object.assign( Matrix4.prototype, {
 
 		return array;
 
+	},
+	//toolbag里的Matrix.rotation
+	rotation:function(a,c, b){
+		a[0] = 1;
+		a[4] = 0;
+		a[8] = 0;
+		a[12] = 0;
+		a[1] = 0;
+		a[5] = 1;
+		a[9] = 0;
+		a[13] = 0;
+		a[2] = 0;
+		a[6] = 0;
+		a[10] = 1;
+		a[14] = 0;
+		a[3] = 0;
+		a[7] = 0;
+		a[11] = 0;
+		a[15] = 1;
+		var d = 0.0174532925 * c;
+		c = Math.sin(d);
+		d = Math.cos(d);
+		switch (b) {
+		case 0:
+			a[5] = d;
+			a[9] = -c;
+			a[6] = c;
+			a[10] = d;
+			break;
+		case 1:
+			a[0] = d;
+			a[8] = c;
+			a[2] = -c;
+			a[10] = d;
+			break;
+		case 2:
+			a[0] = d,
+			a[4] = -c,
+			a[1] = c,
+			a[5] = d
+		}
+		return a
+	},
+	mul:function(a,c, b){
+		var d = c[0]
+		, e = c[1]
+		, f = c[2]
+		, g = c[3]
+		, h = c[4]
+		, k = c[5]
+		, n = c[6]
+		, m = c[7]
+		, l = c[8]
+		, p = c[9]
+		, r = c[10]
+		, s = c[11]
+		, u = c[12]
+		, q = c[13]
+		, x = c[14];
+	  c = c[15];
+	  var w = b[0]
+		, v = b[1]
+		, t = b[2]
+		, y = b[3];
+	  a[0] = w * d + v * h + t * l + y * u;
+	  a[1] = w * e + v * k + t * p + y * q;
+	  a[2] = w * f + v * n + t * r + y * x;
+	  a[3] = w * g + v * m + t * s + y * c;
+	  w = b[4];
+	  v = b[5];
+	  t = b[6];
+	  y = b[7];
+	  a[4] = w * d + v * h + t * l + y * u;
+	  a[5] = w * e + v * k + t * p + y * q;
+	  a[6] = w * f + v * n + t * r + y * x;
+	  a[7] = w * g + v * m + t * s + y * c;
+	  w = b[8];
+	  v = b[9];
+	  t = b[10];
+	  y = b[11];
+	  a[8] = w * d + v * h + t * l + y * u;
+	  a[9] = w * e + v * k + t * p + y * q;
+	  a[10] = w * f + v * n + t * r + y * x;
+	  a[11] = w * g + v * m + t * s + y * c;
+	  w = b[12];
+	  v = b[13];
+	  t = b[14];
+	  y = b[15];
+	  a[12] = w * d + v * h + t * l + y * u;
+	  a[13] = w * e + v * k + t * p + y * q;
+	  a[14] = w * f + v * n + t * r + y * x;
+	  a[15] = w * g + v * m + t * s + y * c;
+	  return a
+	},
+	invert: function(a, c) {
+		var b = c[0]
+		  , d = c[1]
+		  , e = c[2]
+		  , f = c[3]
+		  , g = c[4]
+		  , h = c[5]
+		  , k = c[6]
+		  , n = c[7]
+		  , m = c[8]
+		  , l = c[9]
+		  , p = c[10]
+		  , r = c[11]
+		  , s = c[12]
+		  , u = c[13]
+		  , q = c[14]
+		  , x = c[15]
+		  , w = b * h - d * g
+		  , v = b * k - e * g
+		  , t = b * n - f * g
+		  , y = d * k - e * h
+		  , E = d * n - f * h
+		  , F = e * n - f * k
+		  , A = m * u - l * s
+		  , B = m * q - p * s
+		  , z = m * x - r * s
+		  , C = l * q - p * u
+		  , G = l * x - r * u
+		  , H = p * x - r * q
+		  , D = w * H - v * G + t * C + y * z - E * B + F * A;
+		if (!D)
+			return null;
+		D = 1 / D;
+		a[0] = (h * H - k * G + n * C) * D;
+		a[1] = (e * G - d * H - f * C) * D;
+		a[2] = (u * F - q * E + x * y) * D;
+		a[3] = (p * E - l * F - r * y) * D;
+		a[4] = (k * z - g * H - n * B) * D;
+		a[5] = (b * H - e * z + f * B) * D;
+		a[6] = (q * t - s * F - x * v) * D;
+		a[7] = (m * F - p * t + r * v) * D;
+		a[8] = (g * G - h * z + n * A) * D;
+		a[9] = (d * z - b * G - f * A) * D;
+		a[10] = (s * E - u * t + x * w) * D;
+		a[11] = (l * t - m * E - r * w) * D;
+		a[12] = (h * B - g * C - k * A) * D;
+		a[13] = (b * C - d * B + e * A) * D;
+		a[14] = (u * v - s * y - q * w) * D;
+		a[15] = (m * y - l * v + p * w) * D;
+		return a
 	}
 
 } );

+ 9 - 0
src/renderers/WebGLRenderer.js

@@ -476,6 +476,15 @@ function WebGLRenderer( parameters ) {
 
 	};
 
+	this.setClearColor2 = function (r,g,b,alpha) {
+
+		_gl.clearColor( r,g,b,alpha );
+		_gl.clear(_gl.COLOR_BUFFER_BIT | _gl.DEPTH_BUFFER_BIT | _gl.STENCIL_BUFFER_BIT);
+		_gl.enable(_gl.DEPTH_TEST);
+		//_gl.clear(_gl.COLOR_BUFFER_BIT );
+
+	};
+
 	this.clearColor = function () {
 
 		this.clear( true, false, false );