瀏覽代碼

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

Mr.doob 9 年之前
父節點
當前提交
cd8ddd19f1

+ 5 - 0
docs/api/math/Vector2.html

@@ -120,6 +120,11 @@
 		Normalizes this vector.
 		</div>
 
+		<h3>[method:Float angle]()</h3>
+		<div>
+		Computes the angle in radians of this vector with respect to the positive x-axis.
+		</div>
+
 		<h3>[method:Float distanceTo]( [page:Vector2 v] )</h3>
 		<div>
 		Computes distance of this vector to *v*.

+ 1 - 0
editor/index.html

@@ -119,6 +119,7 @@
 		<script src="js/Sidebar.Geometry.TorusKnotGeometry.js"></script>
 		<script src="../examples/js/geometries/TeapotBufferGeometry.js"></script>
 		<script src="js/Sidebar.Geometry.TeapotBufferGeometry.js"></script>
+		<script src="js/Sidebar.Geometry.LatheGeometry.js"></script>
 		<script src="js/Sidebar.Material.js"></script>
 		<script src="js/Sidebar.Animation.js"></script>
 		<script src="js/Sidebar.Script.js"></script>

+ 33 - 0
editor/js/Menubar.Add.js

@@ -242,6 +242,39 @@ Menubar.Add = function ( editor ) {
 	options.add( option );
 	*/
 
+	// Lathe
+
+	var option = new UI.Row();
+	option.setClass( 'option' );
+	option.setTextContent( 'Lathe geometry' );
+	option.onClick( function() {
+
+		var points = [];
+		var segments = 20;
+		var phiStart = 0;
+		var phiLength = 2 * Math.PI;
+
+		points.push( new THREE.Vector3( 0, 0, 0 ) );
+		points.push( new THREE.Vector3( 4, 0, 0 ) );
+		points.push( new THREE.Vector3( 3.5, 0, 0.5 ) );
+		points.push( new THREE.Vector3( 1, 0, 0.75 ) );
+		points.push( new THREE.Vector3( 0.8, 0, 1 ) );
+		points.push( new THREE.Vector3( 0.8, 0, 4 ) );
+		points.push( new THREE.Vector3( 1, 0, 4.2 ) );
+		points.push( new THREE.Vector3( 1.4, 0, 4.8 ) );
+		points.push( new THREE.Vector3( 2, 0, 5 ) );
+		points.push( new THREE.Vector3( 2.5, 0, 5.4 ) );
+		points.push( new THREE.Vector3( 2.5, 0, 12 ) );
+
+		var geometry = new THREE.LatheGeometry( points, segments, phiStart, phiLength );
+		var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial( { side: THREE.DoubleSide } ) );
+		mesh.name = 'Lathe ' + ( ++meshCount );
+
+		editor.execute( new AddObjectCommand( mesh ) );
+
+	} );
+	options.add( option );
+
 	// Sprite
 
 	var option = new UI.Row();

+ 134 - 0
editor/js/Sidebar.Geometry.LatheGeometry.js

@@ -0,0 +1,134 @@
+/**
+ * @author rfm1201
+ */
+
+Sidebar.Geometry.LatheGeometry = function( editor, object ) {
+
+	var signals = editor.signals;
+
+	var container = new UI.Row();
+
+	var parameters = object.geometry.parameters;
+
+	// segments
+
+	var segmentsRow = new UI.Row();
+	var segments = new UI.Integer( parameters.segments ).onChange( update );
+
+	segmentsRow.add( new UI.Text( 'Segments' ).setWidth( '90px' ) );
+	segmentsRow.add( segments );
+
+	container.add( segmentsRow );
+
+	// phiStart
+
+	var phiStartRow = new UI.Row();
+	var phiStart = new UI.Number( parameters.phiStart * 180 / Math.PI ).onChange( update );
+
+	phiStartRow.add( new UI.Text( 'Phi start (°)' ).setWidth( '90px' ) );
+	phiStartRow.add( phiStart );
+
+	container.add( phiStartRow );
+
+	// phiLength
+
+	var phiLengthRow = new UI.Row();
+	var phiLength = new UI.Number( parameters.phiLength * 180 / Math.PI ).onChange( update );
+
+	phiLengthRow.add( new UI.Text( 'Phi length (°)' ).setWidth( '90px' ) );
+	phiLengthRow.add( phiLength );
+
+	container.add( phiLengthRow );
+
+	// points
+
+	var lastPointIdx = 0;
+	var pointsUI = [];
+
+	var pointsDiv = new UI.Div();
+	var point;
+	for ( var i = 0; i < parameters.points.length; i ++ ) {
+
+		point = parameters.points[ i ];
+		pointsDiv.add( createPointRow( point.x, point.z ) );
+
+	}
+
+	var pointsRow = new UI.Row().setDisplay( 'flex' );
+
+	var btnAdd = new UI.Button( '+' ).setMarginRight( '15px' ).onClick( function() {
+
+		pointsDiv.add( createPointRow( 0, 0 ) );
+		update();
+
+	} );
+
+	pointsRow.add( new UI.Text( 'Points' ).setWidth( '50px' ), btnAdd, pointsDiv );
+	container.add( pointsRow );
+
+	//
+
+	function createPointRow( x, y ) {
+
+		var pointRow = new UI.Row();
+		var lbl = new UI.Text( lastPointIdx + 1 ).setWidth( '20px' );
+		var txtX = new UI.Number( x ).setRange( 0, Infinity ).setWidth( '40px' ).onChange( update );
+		var txtY = new UI.Number( y ).setWidth( '40px' ).onChange( update );
+		var idx = lastPointIdx;
+		var btn = new UI.Button( '-' ).onClick( function() {
+
+			deletePointRow( idx );
+
+		} );
+
+		pointsUI.push( { row: pointRow, lbl: lbl, x: txtX, y: txtY } );
+		lastPointIdx ++;
+		pointRow.add( lbl, txtX, txtY, btn );
+
+		return pointRow;
+
+	}
+
+	function deletePointRow( idx ) {
+
+		if ( ! pointsUI[ idx ] ) return;
+
+		pointsDiv.remove( pointsUI[ idx ].row );
+		pointsUI[ idx ] = null;
+
+		update();
+
+	}
+
+	function update() {
+
+		var points = [];
+		var count = 0;
+		var pointUI;
+		for ( var i = 0; i < pointsUI.length; i ++ ) {
+
+			pointUI = pointsUI[ i ];
+			if ( ! pointUI ) {
+
+				continue;
+
+			}
+
+			points.push( new THREE.Vector3( pointUI.x.getValue(), 0, pointUI.y.getValue() ) );
+			count ++;
+			pointUI.lbl.setValue( count );
+
+		}
+
+		editor.execute( new SetGeometryCommand( object, new THREE.LatheGeometry(
+					points,
+					segments.getValue(),
+					phiStart.getValue() / 180 * Math.PI,
+					phiLength.getValue() / 180 * Math.PI
+				) ) );
+
+	}
+
+	return container;
+
+}

+ 56 - 64
examples/webgl_shading_physical.html

@@ -64,11 +64,11 @@
 
 			var mixer;
 
-			var parameters, tweenDirection, tweenDay, tweenNight;
+			var parameters, tweenDay, tweenNight;
 
 			var clock = new THREE.Clock();
 
-			var gui, shadowConfig = {
+			var gui, shadowCameraHelper, shadowConfig = {
 
 				shadowCameraVisible: false,
 				shadowCameraNear: 750,
@@ -78,6 +78,10 @@
 
 			};
 
+			var lightingConfig = {
+				daylight: false
+			}
+
 			init();
 			animate();
 
@@ -102,18 +106,18 @@
 
 				// TEXTURES
 
-				var textureSquares = THREE.ImageUtils.loadTexture( "textures/patterns/bright_squares256.png" );
+				var textureSquares = new THREE.TextureLoader().load( "textures/patterns/bright_squares256.png" );
 				textureSquares.repeat.set( 50, 50 );
 				textureSquares.wrapS = textureSquares.wrapT = THREE.RepeatWrapping;
 				textureSquares.magFilter = THREE.NearestFilter;
 				textureSquares.format = THREE.RGBFormat;
 
-				var textureNoiseColor = THREE.ImageUtils.loadTexture( "textures/disturb.jpg" );
+				var textureNoiseColor = new THREE.TextureLoader().load( "textures/disturb.jpg" );
 				textureNoiseColor.repeat.set( 1, 1 );
 				textureNoiseColor.wrapS = textureNoiseColor.wrapT = THREE.RepeatWrapping;
 				textureNoiseColor.format = THREE.RGBFormat;
 
-				var textureLava = THREE.ImageUtils.loadTexture( "textures/lava/lavatile.jpg" );
+				var textureLava = new THREE.TextureLoader().load( "textures/lava/lavatile.jpg" );
 				textureLava.repeat.set( 6, 2 );
 				textureLava.wrapS = textureLava.wrapT = THREE.RepeatWrapping;
 				textureLava.format = THREE.RGBFormat;
@@ -128,7 +132,7 @@
 						path + 'pz' + format, path + 'nz' + format
 					];
 
-				var reflectionCube = THREE.ImageUtils.loadTextureCube( urls );
+				var reflectionCube = new THREE.CubeTextureLoader().load( urls );
 
 				// GROUND
 
@@ -150,18 +154,6 @@
 
 				// MATERIALS
 
-				var shader = THREE.ShaderLib[ "cube" ];
-				shader.uniforms[ "tCube" ].texture = cubeCamera.renderTarget;
-				shader.uniforms[ "tFlip" ].value = 1;
-
-				var materialCube = new THREE.ShaderMaterial( {
-
-					fragmentShader: shader.fragmentShader,
-					vertexShader: shader.vertexShader,
-					uniforms: shader.uniforms
-
-				} );
-
 				var materialLambert = new THREE.MeshPhongMaterial( { shininess: 50, color: 0xffffff, map: textureNoiseColor } );
 				var materialPhong = new THREE.MeshPhongMaterial( { shininess: 50, color: 0xffffff, specular: 0x999999, map: textureLava } );
 				var materialPhongCube = new THREE.MeshPhongMaterial( { shininess: 50, color: 0xffffff, specular: 0x999999, envMap: cubeCamera.renderTarget } );
@@ -279,16 +271,20 @@
 
 				sunLight.castShadow = true;
 
-				sunLight.shadowBias = -0.0002;
+				sunLight.shadow.bias = shadowConfig.shadowBias;
 
-				sunLight.shadowCameraNear = 750;
-				sunLight.shadowCameraFar = 4000;
-				sunLight.shadowCameraFov = 30;
-
-				sunLight.shadowCameraVisible = false;
+				sunLight.shadow.camera.far = shadowConfig.shadowCameraFar;
+				sunLight.shadow.camera.near = shadowConfig.shadowCameraNear;
+				sunLight.shadow.camera.fov = shadowConfig.shadowCameraFov;
 
 				scene.add( sunLight );
 
+				// SHADOW CAMERA HELPER
+
+				shadowCameraHelper = new THREE.CameraHelper( sunLight.shadow.camera );
+				shadowCameraHelper.visible = shadowConfig.shadowCameraVisible;
+				scene.add( shadowCameraHelper );
+
 				// RENDERER
 
 				renderer = new THREE.WebGLRenderer( { antialias: true } );
@@ -333,100 +329,96 @@
 				// EVENTS
 
 				window.addEventListener( 'resize', onWindowResize, false );
-				document.addEventListener( 'keydown', onKeyDown, false );
 
 				// TWEEN
 
 				parameters = { control: 0 };
 
-				tweenDirection = -1;
-
 				tweenDay = new TWEEN.Tween( parameters ).to( { control: 1 }, 1000 ).easing( TWEEN.Easing.Exponential.Out );
 				tweenNight = new TWEEN.Tween( parameters ).to( { control: 0 }, 1000 ).easing( TWEEN.Easing.Exponential.Out );
 
 				// GUI
 
-				gui = new dat.GUI();
+				gui = new dat.GUI( { width: 400 } );
 
-				shadowGUI = gui.addFolder( "Shadow" );
+				// SHADOW
 
-    			shadowGUI.add( shadowConfig, 'shadowCameraVisible' ).onChange( function() {
+				var shadowGUI = gui.addFolder( "Shadow" );
 
-					sunLight.shadowCameraVisible = shadowConfig.shadowCameraVisible;
+    		shadowGUI.add( shadowConfig, 'shadowCameraVisible' ).onChange( function() {
+
+					shadowCameraHelper.visible = shadowConfig.shadowCameraVisible;
 
 				});
 
 				shadowGUI.add( shadowConfig, 'shadowCameraNear', 1, 1500 ).onChange( function() {
 
-					sunLight.shadowCamera.near = shadowConfig.shadowCameraNear;
-					sunLight.shadowCamera.updateProjectionMatrix();
+					sunLight.shadow.camera.near = shadowConfig.shadowCameraNear;
+					sunLight.shadow.camera.updateProjectionMatrix();
+					shadowCameraHelper.update();
 
 				});
 
 				shadowGUI.add( shadowConfig, 'shadowCameraFar', 1501, 5000 ).onChange( function() {
 
-					sunLight.shadowCamera.far = shadowConfig.shadowCameraFar;
-					sunLight.shadowCamera.updateProjectionMatrix();
+					sunLight.shadow.camera.far = shadowConfig.shadowCameraFar;
+					sunLight.shadow.camera.updateProjectionMatrix();
+					shadowCameraHelper.update();
 
 				});
 
 				shadowGUI.add( shadowConfig, 'shadowCameraFov', 1, 120 ).onChange( function() {
 
-					sunLight.shadowCamera.fov = shadowConfig.shadowCameraFov;
-					sunLight.shadowCamera.updateProjectionMatrix();
+					sunLight.shadow.camera.fov = shadowConfig.shadowCameraFov;
+					sunLight.shadow.camera.updateProjectionMatrix();
+					shadowCameraHelper.update();
 
 				});
 
 				shadowGUI.add( shadowConfig, 'shadowBias', -0.01, 0.01 ).onChange( function() {
 
-					sunLight.shadowBias = shadowConfig.shadowBias;
+					sunLight.shadow.bias = shadowConfig.shadowBias;
 
 				});
 
 				shadowGUI.open();
 
-			}
+				// LIGHTING
 
-			//
+				var lightingGUI = gui.addFolder( "Lighting" );
 
-			function onWindowResize( event ) {
+				lightingGUI.add( lightingConfig, 'daylight' ).onChange( function() {
 
-				camera.aspect = window.innerWidth / window.innerHeight;
-				camera.updateProjectionMatrix();
+					// change between day and night
 
-				renderer.setSize( window.innerWidth, window.innerHeight );
-
-				controls.handleResize();
-
-			}
-
-			//
+					if( lightingConfig.daylight === true ) {
 
-			function onKeyDown ( event ) {
+						tweenNight.stop();
+						tweenDay.start();
 
-				switch ( event.keyCode ) {
+					} else {
 
-					case 78: /*N*/
+						tweenDay.stop();
+						tweenNight.start();
 
-						if ( tweenDirection == 1 ) {
+					};
 
-							tweenDay.stop();
-							tweenNight.start();
+				});
 
-							tweenDirection = -1;
+				lightingGUI.open();
 
-						} else {
+			}
 
-							tweenNight.stop();
-							tweenDay.start();
+			//
 
-							tweenDirection = 1;
+			function onWindowResize( event ) {
 
-						}
+				camera.aspect = window.innerWidth / window.innerHeight;
+				camera.updateProjectionMatrix();
 
-					break;
+				renderer.setSize( window.innerWidth, window.innerHeight );
 
-				}
+				controls.handleResize();
 
 			}
 

+ 12 - 0
src/math/Vector2.js

@@ -370,6 +370,18 @@ THREE.Vector2.prototype = {
 
 	},
 
+	angle: function () {
+
+		// computes the angle in radians with respect to the positive x-axis
+
+		var angle = Math.atan2( this.y, this.x );
+
+		if ( angle < 0 ) angle += 2 * Math.PI;
+
+		return angle;
+
+	},
+
 	distanceTo: function ( v ) {
 
 		return Math.sqrt( this.distanceToSquared( v ) );

+ 10 - 0
utils/npm/node_modules/three.js/README.md

@@ -0,0 +1,10 @@
+three.js
+========
+
+**IMPORTANT NOTE**
+
+This ```three.js``` NPM package has been deprecated in favor of the three package available here:
+
+[Three NPM Package](http://npmjs.org/packages/three/)
+
+This NPM package currently acts as a shim for the three NPM package.

+ 16 - 0
utils/npm/node_modules/three.js/package.json

@@ -0,0 +1,16 @@
+{
+  "name": "three.js",
+  "version": "0.73.2",
+  "description": "Note: 'three.js' npm package has been deprecated in favor of the 'three' npm package.",
+  "main": "shim.js",
+  "repository": {
+    "type": "git",
+    "url": "git+https://github.com/mrdoob/three.js.git"
+  },
+  "author": {
+    "name": "mrdoob"
+  },
+  "dependencies": {
+    "three": "0.73.0"
+  }
+}

+ 12 - 0
utils/npm/node_modules/three.js/shim.js

@@ -0,0 +1,12 @@
+var THREE = require('three');
+
+console.warn( "WARNING: The 'three.js' npm package is deprecated in favor of the 'three' npm package, please upgrade.");
+
+if (typeof exports !== 'undefined') {
+  if (typeof module !== 'undefined' && module.exports) {
+    exports = module.exports = THREE;
+  }
+  exports.THREE = THREE;
+} else {
+  this['THREE'] = THREE;
+}