Michael Herzog пре 3 година
родитељ
комит
a5d6b17d69

+ 26 - 18
examples/js/controls/ArcballControls.js

@@ -40,7 +40,7 @@
 	const _endEvent = {
 		type: 'end'
 	};
-	
+
 	const _raycaster = new THREE.Raycaster();
 	/**
  *
@@ -49,6 +49,7 @@
  * @param {Scene} scene The scene to be rendered
  */
 
+
 	class ArcballControls extends THREE.Object3D {
 
 		constructor( _camera, domElement, scene = null ) {
@@ -463,11 +464,11 @@
 
 									}
 
-									this.applyTransformMatrix( this.scale( size, scalePoint ) );
+									this.applyTransformMatrix( this.applyScale( size, scalePoint ) );
 
 								} else {
 
-									this.applyTransformMatrix( this.scale( size, this._gizmos.position ) );
+									this.applyTransformMatrix( this.applyScale( size, this._gizmos.position ) );
 
 								}
 
@@ -540,7 +541,7 @@
 									const newDistance = y / Math.tan( THREE.MathUtils.DEG2RAD * ( newFov / 2 ) );
 									size = x / newDistance;
 									this.setFov( newFov );
-									this.applyTransformMatrix( this.scale( size, this._gizmos.position, false ) );
+									this.applyTransformMatrix( this.applyScale( size, this._gizmos.position, false ) );
 
 								}
 
@@ -858,7 +859,7 @@
 
 									}
 
-									this.applyTransformMatrix( this.scale( size, this._gizmos.position ) );
+									this.applyTransformMatrix( this.applyScale( size, this._gizmos.position ) );
 
 								}
 
@@ -927,7 +928,7 @@
 									this._v3_2.setFromMatrixPosition( this._gizmoMatrixState );
 
 									this.setFov( newFov );
-									this.applyTransformMatrix( this.scale( size, this._v3_2, false ) ); //adjusting distance
+									this.applyTransformMatrix( this.applyScale( size, this._v3_2, false ) ); //adjusting distance
 
 									const direction = this._gizmos.position.clone().sub( this.camera.position ).normalize().multiplyScalar( newDistance / x );
 
@@ -1215,7 +1216,7 @@
 
 					}
 
-					this.applyTransformMatrix( this.scale( amount, scalePoint ) );
+					this.applyTransformMatrix( this.applyScale( amount, scalePoint ) );
 					this.dispatchEvent( _changeEvent );
 
 				}
@@ -1319,7 +1320,7 @@
 					this._v3_2.setFromMatrixPosition( this._gizmoMatrixState );
 
 					this.setFov( newFov );
-					this.applyTransformMatrix( this.scale( size, this._v3_2, false ) ); //adjusting distance
+					this.applyTransformMatrix( this.applyScale( size, this._v3_2, false ) ); //adjusting distance
 
 					const direction = this._gizmos.position.clone().sub( this.camera.position ).normalize().multiplyScalar( newDistance / x );
 
@@ -1635,7 +1636,7 @@
 
 				if ( this.enableZoom ) {
 
-					this.applyTransformMatrix( this.scale( size, this._gizmos.position ) );
+					this.applyTransformMatrix( this.applyScale( size, this._gizmos.position ) );
 
 				}
 
@@ -2160,7 +2161,7 @@
 
 			};
 
-			this.scale = ( size, point, scaleGizmos = true ) => {
+			this.applyScale = ( size, point, scaleGizmos = true ) => {
 
 				const scalePoint = point.clone();
 				let sizeInverse = 1 / size;
@@ -2323,12 +2324,6 @@
 
 			};
 
-			this.getRaycaster = () => {
-
-				return _raycaster;
-	
-			};
-
 			this.unprojectOnObj = ( cursor, camera ) => {
 
 				const raycaster = this.getRaycaster();
@@ -2591,7 +2586,7 @@
 					if ( this.camera.zoom > this.maxZoom || this.camera.zoom < this.minZoom ) {
 
 						const newZoom = THREE.MathUtils.clamp( this.camera.zoom, this.minZoom, this.maxZoom );
-						this.applyTransformMatrix( this.scale( newZoom / this.camera.zoom, this._gizmos.position, true ) );
+						this.applyTransformMatrix( this.applyScale( newZoom / this.camera.zoom, this._gizmos.position, true ) );
 
 					}
 
@@ -2603,7 +2598,7 @@
 					if ( distance > this.maxDistance + EPS || distance < this.minDistance - EPS ) {
 
 						const newDistance = THREE.MathUtils.clamp( distance, this.minDistance, this.maxDistance );
-						this.applyTransformMatrix( this.scale( newDistance / distance, this._gizmos.position ) );
+						this.applyTransformMatrix( this.applyScale( newDistance / distance, this._gizmos.position ) );
 						this.updateMatrixState();
 
 					} //check fov
@@ -2996,6 +2991,19 @@
    */
 
 
+		getRaycaster() {
+
+			return _raycaster;
+
+		}
+		/**
+   * Unproject the cursor on the 3D object surface
+   * @param {Vector2} cursor Cursor coordinates in NDC
+   * @param {Camera} camera Virtual camera
+   * @returns {Vector3} The point of intersection with the model, if exist, null otherwise
+   */
+
+
 	}
 
 	THREE.ArcballControls = ArcballControls;

+ 1 - 1
examples/js/controls/TrackballControls.js

@@ -194,7 +194,7 @@
 
 					} else if ( scope.object.isOrthographicCamera ) {
 
-						scope.object.zoom *= factor;
+						scope.object.zoom /= factor;
 						scope.object.updateProjectionMatrix();
 
 					} else {

+ 52 - 19
examples/js/lines/LineMaterial.js

@@ -52,10 +52,23 @@
 		attribute vec3 instanceColorStart;
 		attribute vec3 instanceColorEnd;
 
-		varying vec2 vUv;
-		varying vec4 worldPos;
-		varying vec3 worldStart;
-		varying vec3 worldEnd;
+		#ifdef WORLD_UNITS
+
+			varying vec4 worldPos;
+			varying vec3 worldStart;
+			varying vec3 worldEnd;
+
+			#ifdef USE_DASH
+
+				varying vec2 vUv;
+
+			#endif
+
+		#else
+
+			varying vec2 vUv;
+
+		#endif
 
 		#ifdef USE_DASH
 
@@ -92,19 +105,26 @@
 			#ifdef USE_DASH
 
 				vLineDistance = ( position.y < 0.5 ) ? dashScale * instanceDistanceStart : dashScale * instanceDistanceEnd;
+				vUv = uv;
 
 			#endif
 
 			float aspect = resolution.x / resolution.y;
 
-			vUv = uv;
-
 			// camera space
 			vec4 start = modelViewMatrix * vec4( instanceStart, 1.0 );
 			vec4 end = modelViewMatrix * vec4( instanceEnd, 1.0 );
 
-			worldStart = start.xyz;
-			worldEnd = end.xyz;
+			#ifdef WORLD_UNITS
+
+				worldStart = start.xyz;
+				worldEnd = end.xyz;
+
+			#else
+
+				vUv = uv;
+
+			#endif
 
 			// special case for perspective projection, and segments that terminate either in, or behind, the camera plane
 			// clearly the gpu firmware has a way of addressing this issue when projecting into ndc space
@@ -260,9 +280,24 @@
 		#endif
 
 		varying float vLineDistance;
-		varying vec4 worldPos;
-		varying vec3 worldStart;
-		varying vec3 worldEnd;
+
+		#ifdef WORLD_UNITS
+
+			varying vec4 worldPos;
+			varying vec3 worldStart;
+			varying vec3 worldEnd;
+
+			#ifdef USE_DASH
+
+				varying vec2 vUv;
+
+			#endif
+
+		#else
+
+			varying vec2 vUv;
+
+		#endif
 
 		#include <common>
 		#include <color_pars_fragment>
@@ -270,8 +305,6 @@
 		#include <logdepthbuf_pars_fragment>
 		#include <clipping_planes_pars_fragment>
 
-		varying vec2 vUv;
-
 		vec2 closestLineToLine(vec3 p1, vec3 p2, vec3 p3, vec3 p4) {
 
 			float mua;
@@ -330,7 +363,7 @@
 
 				#ifndef USE_DASH
 
-					#ifdef ALPHA_TO_COVERAGE
+					#ifdef USE_ALPHA_TO_COVERAGE
 
 						float dnorm = fwidth( norm );
 						alpha = 1.0 - smoothstep( 0.5 - dnorm, 0.5 + dnorm, norm );
@@ -349,7 +382,7 @@
 
 			#else
 
-				#ifdef ALPHA_TO_COVERAGE
+				#ifdef USE_ALPHA_TO_COVERAGE
 
 					// artifacts appear on some hardware if a derivative is taken within a conditional
 					float a = vUv.x;
@@ -566,12 +599,12 @@
 					enumerable: true,
 					get: function () {
 
-						return Boolean( 'ALPHA_TO_COVERAGE' in this.defines );
+						return Boolean( 'USE_ALPHA_TO_COVERAGE' in this.defines );
 
 					},
 					set: function ( value ) {
 
-						if ( Boolean( value ) !== Boolean( 'ALPHA_TO_COVERAGE' in this.defines ) ) {
+						if ( Boolean( value ) !== Boolean( 'USE_ALPHA_TO_COVERAGE' in this.defines ) ) {
 
 							this.needsUpdate = true;
 
@@ -579,12 +612,12 @@
 
 						if ( value === true ) {
 
-							this.defines.ALPHA_TO_COVERAGE = '';
+							this.defines.USE_ALPHA_TO_COVERAGE = '';
 							this.extensions.derivatives = true;
 
 						} else {
 
-							delete this.defines.ALPHA_TO_COVERAGE;
+							delete this.defines.USE_ALPHA_TO_COVERAGE;
 							this.extensions.derivatives = false;
 
 						}

+ 1 - 1
examples/js/loaders/3MFLoader.js

@@ -1299,7 +1299,7 @@
 				for ( let i = 0; i < buildData.length; i ++ ) {
 
 					const buildItem = buildData[ i ];
-					const object3D = objects[ buildItem[ 'objectId' ] ]; // apply transform
+					const object3D = objects[ buildItem[ 'objectId' ] ].clone(); // apply transform
 
 					const transform = buildItem[ 'transform' ];
 

+ 2 - 26
examples/js/loaders/GLTFLoader.js

@@ -1724,34 +1724,10 @@
 		MASK: 'MASK',
 		BLEND: 'BLEND'
 	};
-	/* UTILITY FUNCTIONS */
-
-	function resolveURL( url, path ) {
-
-		// Invalid URL
-		if ( typeof url !== 'string' || url === '' ) return ''; // Host Relative URL
-
-		if ( /^https?:\/\//i.test( path ) && /^\//.test( url ) ) {
-
-			path = path.replace( /(^https?:\/\/[^\/]+).*/i, '$1' );
-
-		} // Absolute URL http://,https://,//
-
-
-		if ( /^(https?:)?\/\//i.test( url ) ) return url; // Data URI
-
-		if ( /^data:.*,.*$/i.test( url ) ) return url; // Blob URL
-
-		if ( /^blob:.*$/i.test( url ) ) return url; // Relative URL
-
-		return path + url;
-
-	}
 	/**
  * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#default-material
  */
 
-
 	function createDefaultMaterial( cache ) {
 
 		if ( cache[ 'DefaultMaterial' ] === undefined ) {
@@ -2378,7 +2354,7 @@
 			const options = this.options;
 			return new Promise( function ( resolve, reject ) {
 
-				loader.load( resolveURL( bufferDef.uri, options.path ), resolve, undefined, function () {
+				loader.load( THREE.LoaderUtils.resolveURL( bufferDef.uri, options.path ), resolve, undefined, function () {
 
 					reject( new Error( 'THREE.GLTFLoader: Failed to load buffer "' + bufferDef.uri + '".' ) );
 
@@ -2613,7 +2589,7 @@
 
 					}
 
-					loader.load( resolveURL( sourceURI, options.path ), onLoad, undefined, reject );
+					loader.load( THREE.LoaderUtils.resolveURL( sourceURI, options.path ), onLoad, undefined, reject );
 
 				} );