From 1f3207f15754e5af8df480b8cd5a5fe6b54f1ee9 Mon Sep 17 00:00:00 2001 From: Takahiro Date: Sun, 22 Apr 2018 05:38:44 +0900 Subject: [PATCH 01/85] Add missing properties to Texture.toJSON() --- src/textures/Texture.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/textures/Texture.js b/src/textures/Texture.js index e88e52a826d4be..5566717a329885 100644 --- a/src/textures/Texture.js +++ b/src/textures/Texture.js @@ -191,11 +191,18 @@ Texture.prototype = Object.assign( Object.create( EventDispatcher.prototype ), { wrap: [ this.wrapS, this.wrapT ], format: this.format, + type: this.type, + encoding: this.encoding, + minFilter: this.minFilter, magFilter: this.magFilter, anisotropy: this.anisotropy, + mipmaps: this.mipmaps.slice(), + + flipY: this.flipY, - flipY: this.flipY + premultiplyAlpha: this.premultiplyAlpha, + unpackAlignment: this.unpackAlignment }; From 1cfd6de5b21e86ab9e30cefc2f1d8190a5988356 Mon Sep 17 00:00:00 2001 From: Takahiro Date: Sun, 22 Apr 2018 05:39:17 +0900 Subject: [PATCH 02/85] Add missing properties for Texture to ObjectLoader.parseTextures() --- src/loaders/ObjectLoader.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/loaders/ObjectLoader.js b/src/loaders/ObjectLoader.js index 9001f468ef8e2b..76aea676a92029 100644 --- a/src/loaders/ObjectLoader.js +++ b/src/loaders/ObjectLoader.js @@ -564,13 +564,19 @@ Object.assign( ObjectLoader.prototype, { } if ( data.format !== undefined ) texture.format = data.format; + if ( data.type !== undefined ) texture.type = data.type; + if ( data.encoding ) texture.encoding = data.encoding; if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter, TEXTURE_FILTER ); if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter, TEXTURE_FILTER ); if ( data.anisotropy !== undefined ) texture.anisotropy = data.anisotropy; + if ( data.mipmaps !== undefined ) texture.mipmaps = data.mipmaps; if ( data.flipY !== undefined ) texture.flipY = data.flipY; + if ( data.premultiplyAlpha ) texture.premultiplyAlpha = data.premultiplyAlpha; + if ( data.unpackAlignment ) texture.unpackAlignment = data.unpackAlignment; + textures[ data.uuid ] = texture; } From 27dabc262eeeae33675028485f831571e1fdf066 Mon Sep 17 00:00:00 2001 From: Takahiro Date: Mon, 23 Apr 2018 01:15:01 +0900 Subject: [PATCH 03/85] Compare with undefined in parseTextures of ObjectLoader --- src/loaders/ObjectLoader.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/loaders/ObjectLoader.js b/src/loaders/ObjectLoader.js index 76aea676a92029..09e39549dc9248 100644 --- a/src/loaders/ObjectLoader.js +++ b/src/loaders/ObjectLoader.js @@ -565,7 +565,7 @@ Object.assign( ObjectLoader.prototype, { if ( data.format !== undefined ) texture.format = data.format; if ( data.type !== undefined ) texture.type = data.type; - if ( data.encoding ) texture.encoding = data.encoding; + if ( data.encoding !== undefined ) texture.encoding = data.encoding; if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter, TEXTURE_FILTER ); if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter, TEXTURE_FILTER ); @@ -574,8 +574,8 @@ Object.assign( ObjectLoader.prototype, { if ( data.flipY !== undefined ) texture.flipY = data.flipY; - if ( data.premultiplyAlpha ) texture.premultiplyAlpha = data.premultiplyAlpha; - if ( data.unpackAlignment ) texture.unpackAlignment = data.unpackAlignment; + if ( data.premultiplyAlpha !== undefined ) texture.premultiplyAlpha = data.premultiplyAlpha; + if ( data.unpackAlignment !== undefined ) texture.unpackAlignment = data.unpackAlignment; textures[ data.uuid ] = texture; From 2730e41b505466e26699141570865b6a956ec194 Mon Sep 17 00:00:00 2001 From: Takahiro Date: Mon, 23 Apr 2018 04:24:41 +0900 Subject: [PATCH 04/85] Update Geometry and BufferGeomery docs for .userData --- docs/api/core/BufferGeometry.html | 6 ++++++ docs/api/core/Geometry.html | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/docs/api/core/BufferGeometry.html b/docs/api/core/BufferGeometry.html index 8dd53b02b006b8..8eafbad529d613 100644 --- a/docs/api/core/BufferGeometry.html +++ b/docs/api/core/BufferGeometry.html @@ -185,6 +185,12 @@

[property:String name]

Optional name for this bufferGeometry instance. Default is an empty string.

+

[property:Object userData]

+

+ An object that can be used to store custom data about the BufferGeometry. It should not hold + references to functions as these will not be cloned. +

+

[property:String uuid]

[link:http://en.wikipedia.org/wiki/Universally_unique_identifier UUID] of this object instance. diff --git a/docs/api/core/Geometry.html b/docs/api/core/Geometry.html index 8abddb54bda309..47949f7f20c210 100644 --- a/docs/api/core/Geometry.html +++ b/docs/api/core/Geometry.html @@ -174,6 +174,12 @@

[property:Array skinIndices]

+

[property:Object userData]

+

+ An object that can be used to store custom data about the Geometry. It should not hold + references to functions as these will not be cloned. +

+

[property:String uuid]

[link:http://en.wikipedia.org/wiki/Universally_unique_identifier UUID] of this object instance. From 38f4b7935780999979d7bef0a418a9b5dff596d8 Mon Sep 17 00:00:00 2001 From: Takahiro Date: Wed, 25 Apr 2018 03:55:04 +0900 Subject: [PATCH 05/85] Revert "Update Geometry and BufferGeomery docs for .userData" This reverts commit 2730e41b505466e26699141570865b6a956ec194. --- docs/api/core/BufferGeometry.html | 6 ------ docs/api/core/Geometry.html | 6 ------ 2 files changed, 12 deletions(-) diff --git a/docs/api/core/BufferGeometry.html b/docs/api/core/BufferGeometry.html index 8eafbad529d613..8dd53b02b006b8 100644 --- a/docs/api/core/BufferGeometry.html +++ b/docs/api/core/BufferGeometry.html @@ -185,12 +185,6 @@

[property:String name]

Optional name for this bufferGeometry instance. Default is an empty string.

-

[property:Object userData]

-

- An object that can be used to store custom data about the BufferGeometry. It should not hold - references to functions as these will not be cloned. -

-

[property:String uuid]

[link:http://en.wikipedia.org/wiki/Universally_unique_identifier UUID] of this object instance. diff --git a/docs/api/core/Geometry.html b/docs/api/core/Geometry.html index 47949f7f20c210..8abddb54bda309 100644 --- a/docs/api/core/Geometry.html +++ b/docs/api/core/Geometry.html @@ -174,12 +174,6 @@

[property:Array skinIndices]

-

[property:Object userData]

-

- An object that can be used to store custom data about the Geometry. It should not hold - references to functions as these will not be cloned. -

-

[property:String uuid]

[link:http://en.wikipedia.org/wiki/Universally_unique_identifier UUID] of this object instance. From f5ab28e6d3aea4506198f16391dcc2f7a64c1ae6 Mon Sep 17 00:00:00 2001 From: Takahiro Date: Wed, 25 Apr 2018 06:49:08 +0900 Subject: [PATCH 06/85] Texture.mipmaps serialization --- src/loaders/ObjectLoader.js | 38 +++++++++++++++++++++++++- src/textures/Texture.js | 54 ++++++++++++++++++++++++++----------- 2 files changed, 76 insertions(+), 16 deletions(-) diff --git a/src/loaders/ObjectLoader.js b/src/loaders/ObjectLoader.js index 09e39549dc9248..ec9b6eb3b112b5 100644 --- a/src/loaders/ObjectLoader.js +++ b/src/loaders/ObjectLoader.js @@ -570,7 +570,43 @@ Object.assign( ObjectLoader.prototype, { if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter, TEXTURE_FILTER ); if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter, TEXTURE_FILTER ); if ( data.anisotropy !== undefined ) texture.anisotropy = data.anisotropy; - if ( data.mipmaps !== undefined ) texture.mipmaps = data.mipmaps; + + if ( data.mipmaps !== undefined ) { + + var TYPED_ARRAYS = { + Int8Array: Int8Array, + Uint8Array: Uint8Array, + // Workaround for IE11 pre KB2929437. See #11440 + Uint8ClampedArray: typeof Uint8ClampedArray !== 'undefined' ? Uint8ClampedArray : Uint8Array, + Int16Array: Int16Array, + Uint16Array: Uint16Array, + Int32Array: Int32Array, + Uint32Array: Uint32Array, + Float32Array: Float32Array, + Float64Array: Float64Array + }; + + for ( var j = 0, jl = data.mipmaps.length; j < jl; j ++ ) { + + var mipmap = data.mipmaps[ j ]; + + if ( mipmap.array !== undefined ) { + + texture.mipmaps.push( { + width: mipmap.width, + height: mipmap.height, + data: new TYPED_ARRAYS[ mipmap.type ]( mipmap.array ) + } ); + + } else { + + texture.mipmaps.push( images[ mipmap ] ); + + } + + } + + } if ( data.flipY !== undefined ) texture.flipY = data.flipY; diff --git a/src/textures/Texture.js b/src/textures/Texture.js index 5566717a329885..4292ae35d98b6c 100644 --- a/src/textures/Texture.js +++ b/src/textures/Texture.js @@ -170,6 +170,29 @@ Texture.prototype = Object.assign( Object.create( EventDispatcher.prototype ), { } + function addImage( image ) { + + // TODO: Move to THREE.Image + + if ( image.uuid === undefined ) { + + image.uuid = _Math.generateUUID(); // UGH + + } + + if ( ! isRootObject && meta.images[ image.uuid ] === undefined ) { + + meta.images[ image.uuid ] = { + uuid: image.uuid, + url: getDataURL( image ) + }; + + } + + return image.uuid; + + } + var output = { metadata: { @@ -197,7 +220,6 @@ Texture.prototype = Object.assign( Object.create( EventDispatcher.prototype ), { minFilter: this.minFilter, magFilter: this.magFilter, anisotropy: this.anisotropy, - mipmaps: this.mipmaps.slice(), flipY: this.flipY, @@ -206,31 +228,33 @@ Texture.prototype = Object.assign( Object.create( EventDispatcher.prototype ), { }; - if ( this.image !== undefined ) { + var mipmaps = []; - // TODO: Move to THREE.Image + for ( var i = 0, il = this.mipmaps.length; i < il; i ++ ) { - var image = this.image; + var mipmap = this.mipmaps[ i ]; - if ( image.uuid === undefined ) { + if ( mipmap.data !== undefined ) { - image.uuid = _Math.generateUUID(); // UGH - - } + mipmaps.push( { + width: mipmap.width, + height: mipmap.height, + type: mipmap.data.constructor.name, + array: Array.prototype.slice.call( mipmap.data ) + } ); - if ( ! isRootObject && meta.images[ image.uuid ] === undefined ) { + } else { - meta.images[ image.uuid ] = { - uuid: image.uuid, - url: getDataURL( image ) - }; + mipmaps.push( addImage( mipmap ) ); } - output.image = image.uuid; - } + if ( mipmaps.length > 0 ) output.mipmaps = mipmaps; + + if ( this.image !== undefined ) output.image = addImage( this.image ); + if ( ! isRootObject ) { meta.textures[ this.uuid ] = output; From 99a7cb9fdff3c4968ccd4c78d00bc7f5cac5f333 Mon Sep 17 00:00:00 2001 From: Takahiro Date: Wed, 25 Apr 2018 06:55:05 +0900 Subject: [PATCH 07/85] Remove an unnecessary space --- src/textures/Texture.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/textures/Texture.js b/src/textures/Texture.js index 4292ae35d98b6c..ff7cea9aaa03b2 100644 --- a/src/textures/Texture.js +++ b/src/textures/Texture.js @@ -240,7 +240,7 @@ Texture.prototype = Object.assign( Object.create( EventDispatcher.prototype ), { width: mipmap.width, height: mipmap.height, type: mipmap.data.constructor.name, - array: Array.prototype.slice.call( mipmap.data ) + array: Array.prototype.slice.call( mipmap.data ) } ); } else { From a071924e87f027d2206d68208f8f9e389568b8c2 Mon Sep 17 00:00:00 2001 From: Takahiro Date: Thu, 26 Apr 2018 04:11:45 +0900 Subject: [PATCH 08/85] Revert "Remove an unnecessary space" This reverts commit 99a7cb9fdff3c4968ccd4c78d00bc7f5cac5f333. --- src/textures/Texture.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/textures/Texture.js b/src/textures/Texture.js index ff7cea9aaa03b2..4292ae35d98b6c 100644 --- a/src/textures/Texture.js +++ b/src/textures/Texture.js @@ -240,7 +240,7 @@ Texture.prototype = Object.assign( Object.create( EventDispatcher.prototype ), { width: mipmap.width, height: mipmap.height, type: mipmap.data.constructor.name, - array: Array.prototype.slice.call( mipmap.data ) + array: Array.prototype.slice.call( mipmap.data ) } ); } else { From 51dbe2afe6fb9817f078ee5221de9ddf6d73aeb8 Mon Sep 17 00:00:00 2001 From: Takahiro Date: Thu, 26 Apr 2018 04:12:02 +0900 Subject: [PATCH 09/85] Revert "Texture.mipmaps serialization" This reverts commit f5ab28e6d3aea4506198f16391dcc2f7a64c1ae6. --- src/loaders/ObjectLoader.js | 38 +------------------------- src/textures/Texture.js | 54 +++++++++++-------------------------- 2 files changed, 16 insertions(+), 76 deletions(-) diff --git a/src/loaders/ObjectLoader.js b/src/loaders/ObjectLoader.js index ec9b6eb3b112b5..09e39549dc9248 100644 --- a/src/loaders/ObjectLoader.js +++ b/src/loaders/ObjectLoader.js @@ -570,43 +570,7 @@ Object.assign( ObjectLoader.prototype, { if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter, TEXTURE_FILTER ); if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter, TEXTURE_FILTER ); if ( data.anisotropy !== undefined ) texture.anisotropy = data.anisotropy; - - if ( data.mipmaps !== undefined ) { - - var TYPED_ARRAYS = { - Int8Array: Int8Array, - Uint8Array: Uint8Array, - // Workaround for IE11 pre KB2929437. See #11440 - Uint8ClampedArray: typeof Uint8ClampedArray !== 'undefined' ? Uint8ClampedArray : Uint8Array, - Int16Array: Int16Array, - Uint16Array: Uint16Array, - Int32Array: Int32Array, - Uint32Array: Uint32Array, - Float32Array: Float32Array, - Float64Array: Float64Array - }; - - for ( var j = 0, jl = data.mipmaps.length; j < jl; j ++ ) { - - var mipmap = data.mipmaps[ j ]; - - if ( mipmap.array !== undefined ) { - - texture.mipmaps.push( { - width: mipmap.width, - height: mipmap.height, - data: new TYPED_ARRAYS[ mipmap.type ]( mipmap.array ) - } ); - - } else { - - texture.mipmaps.push( images[ mipmap ] ); - - } - - } - - } + if ( data.mipmaps !== undefined ) texture.mipmaps = data.mipmaps; if ( data.flipY !== undefined ) texture.flipY = data.flipY; diff --git a/src/textures/Texture.js b/src/textures/Texture.js index 4292ae35d98b6c..5566717a329885 100644 --- a/src/textures/Texture.js +++ b/src/textures/Texture.js @@ -170,29 +170,6 @@ Texture.prototype = Object.assign( Object.create( EventDispatcher.prototype ), { } - function addImage( image ) { - - // TODO: Move to THREE.Image - - if ( image.uuid === undefined ) { - - image.uuid = _Math.generateUUID(); // UGH - - } - - if ( ! isRootObject && meta.images[ image.uuid ] === undefined ) { - - meta.images[ image.uuid ] = { - uuid: image.uuid, - url: getDataURL( image ) - }; - - } - - return image.uuid; - - } - var output = { metadata: { @@ -220,6 +197,7 @@ Texture.prototype = Object.assign( Object.create( EventDispatcher.prototype ), { minFilter: this.minFilter, magFilter: this.magFilter, anisotropy: this.anisotropy, + mipmaps: this.mipmaps.slice(), flipY: this.flipY, @@ -228,32 +206,30 @@ Texture.prototype = Object.assign( Object.create( EventDispatcher.prototype ), { }; - var mipmaps = []; + if ( this.image !== undefined ) { - for ( var i = 0, il = this.mipmaps.length; i < il; i ++ ) { + // TODO: Move to THREE.Image - var mipmap = this.mipmaps[ i ]; + var image = this.image; - if ( mipmap.data !== undefined ) { + if ( image.uuid === undefined ) { - mipmaps.push( { - width: mipmap.width, - height: mipmap.height, - type: mipmap.data.constructor.name, - array: Array.prototype.slice.call( mipmap.data ) - } ); + image.uuid = _Math.generateUUID(); // UGH - } else { + } - mipmaps.push( addImage( mipmap ) ); + if ( ! isRootObject && meta.images[ image.uuid ] === undefined ) { - } + meta.images[ image.uuid ] = { + uuid: image.uuid, + url: getDataURL( image ) + }; - } + } - if ( mipmaps.length > 0 ) output.mipmaps = mipmaps; + output.image = image.uuid; - if ( this.image !== undefined ) output.image = addImage( this.image ); + } if ( ! isRootObject ) { From a89ed40a1e72a9179844fad9db3ad93bc1ba9374 Mon Sep 17 00:00:00 2001 From: Takahiro Date: Thu, 26 Apr 2018 04:13:21 +0900 Subject: [PATCH 10/85] Remove mipmaps serialization --- src/loaders/ObjectLoader.js | 1 - src/textures/Texture.js | 1 - 2 files changed, 2 deletions(-) diff --git a/src/loaders/ObjectLoader.js b/src/loaders/ObjectLoader.js index 09e39549dc9248..d2399498cde802 100644 --- a/src/loaders/ObjectLoader.js +++ b/src/loaders/ObjectLoader.js @@ -570,7 +570,6 @@ Object.assign( ObjectLoader.prototype, { if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter, TEXTURE_FILTER ); if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter, TEXTURE_FILTER ); if ( data.anisotropy !== undefined ) texture.anisotropy = data.anisotropy; - if ( data.mipmaps !== undefined ) texture.mipmaps = data.mipmaps; if ( data.flipY !== undefined ) texture.flipY = data.flipY; diff --git a/src/textures/Texture.js b/src/textures/Texture.js index 5566717a329885..f17202c80a3ff9 100644 --- a/src/textures/Texture.js +++ b/src/textures/Texture.js @@ -197,7 +197,6 @@ Texture.prototype = Object.assign( Object.create( EventDispatcher.prototype ), { minFilter: this.minFilter, magFilter: this.magFilter, anisotropy: this.anisotropy, - mipmaps: this.mipmaps.slice(), flipY: this.flipY, From 6f186bb317c599aea4b818dd614360438070e93e Mon Sep 17 00:00:00 2001 From: WestLangley Date: Tue, 18 Sep 2018 22:50:16 -0400 Subject: [PATCH 11/85] Adopt glTF convention: lights face local neg-z direction --- docs/api/en/helpers/RectAreaLightHelper.html | 2 +- docs/api/en/lights/RectAreaLight.html | 2 +- examples/webgl_lights_rectarealight.html | 3 +- src/core/Object3D.js | 2 +- src/helpers/RectAreaLightHelper.js | 75 ++++++++++--------- .../lights_physical_pars_fragment.glsl | 8 +- 6 files changed, 47 insertions(+), 45 deletions(-) diff --git a/docs/api/en/helpers/RectAreaLightHelper.html b/docs/api/en/helpers/RectAreaLightHelper.html index 87aad7ab9542c5..39e77e8bad3949 100644 --- a/docs/api/en/helpers/RectAreaLightHelper.html +++ b/docs/api/en/helpers/RectAreaLightHelper.html @@ -23,7 +23,7 @@

Example

var helper = new THREE.RectAreaLightHelper( light ); -scene.add( helper ); +light.add( helper ); // helper must be added as a child of the light diff --git a/docs/api/en/lights/RectAreaLight.html b/docs/api/en/lights/RectAreaLight.html index 4f188f540cc04c..b423250d024bcd 100644 --- a/docs/api/en/lights/RectAreaLight.html +++ b/docs/api/en/lights/RectAreaLight.html @@ -41,7 +41,7 @@

Examples

scene.add( rectLight ) rectLightHelper = new THREE.RectAreaLightHelper( rectLight ); -scene.add( rectLightHelper ); +rectLight.add( rectLightHelper );

diff --git a/examples/webgl_lights_rectarealight.html b/examples/webgl_lights_rectarealight.html index 4da1e2685f24c2..98104ec12f474c 100644 --- a/examples/webgl_lights_rectarealight.html +++ b/examples/webgl_lights_rectarealight.html @@ -107,13 +107,12 @@ rectLight.position.set( 5, 5, 0 ); scene.add( rectLight ); - var rectLightMesh = new THREE.Mesh( new THREE.PlaneBufferGeometry(), new THREE.MeshBasicMaterial() ); + var rectLightMesh = new THREE.Mesh( new THREE.PlaneBufferGeometry(), new THREE.MeshBasicMaterial( { side: THREE.BackSide } ) ); rectLightMesh.scale.x = rectLight.width; rectLightMesh.scale.y = rectLight.height; rectLight.add( rectLightMesh ); var rectLightMeshBack = new THREE.Mesh( new THREE.PlaneBufferGeometry(), new THREE.MeshBasicMaterial( { color: 0x080808 } ) ); - rectLightMeshBack.rotation.y = Math.PI; rectLightMesh.add( rectLightMeshBack ); var geoFloor = new THREE.BoxBufferGeometry( 2000, 0.1, 2000 ); diff --git a/src/core/Object3D.js b/src/core/Object3D.js index 2689103bb02b78..728a71a784bd93 100644 --- a/src/core/Object3D.js +++ b/src/core/Object3D.js @@ -328,7 +328,7 @@ Object3D.prototype = Object.assign( Object.create( EventDispatcher.prototype ), position.setFromMatrixPosition( this.matrixWorld ); - if ( this.isCamera ) { + if ( this.isCamera || this.isLight ) { m1.lookAt( position, target, this.up ); diff --git a/src/helpers/RectAreaLightHelper.js b/src/helpers/RectAreaLightHelper.js index dfeca0eb0c749a..7d260777c833c8 100644 --- a/src/helpers/RectAreaLightHelper.js +++ b/src/helpers/RectAreaLightHelper.js @@ -2,79 +2,82 @@ * @author abelnation / http://github.com/abelnation * @author Mugen87 / http://github.com/Mugen87 * @author WestLangley / http://github.com/WestLangley + * + * This helper must be added as a child of the light */ -import { Object3D } from '../core/Object3D.js'; import { Line } from '../objects/Line.js'; +import { Mesh } from '../objects/Mesh.js'; import { LineBasicMaterial } from '../materials/LineBasicMaterial.js'; +import { MeshBasicMaterial } from '../materials/MeshBasicMaterial.js'; +import { Float32BufferAttribute } from '../core/BufferAttribute.js'; import { BufferGeometry } from '../core/BufferGeometry.js'; -import { BufferAttribute } from '../core/BufferAttribute.js'; function RectAreaLightHelper( light, color ) { - Object3D.call( this ); + this.type = 'RectAreaLightHelper'; this.light = light; - this.light.updateMatrixWorld(); - this.matrix = light.matrixWorld; - this.matrixAutoUpdate = false; + this.color = color; // optional hardwired color for the helper - this.color = color; + var positions = [ 1, 1, 0, - 1, 1, 0, - 1, - 1, 0, 1, - 1, 0, 1, 1, 0 ]; + + var geometry = new BufferGeometry(); + geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) ); + geometry.computeBoundingSphere(); var material = new LineBasicMaterial( { fog: false } ); - var geometry = new BufferGeometry(); + Line.call( this, geometry, material ); - geometry.addAttribute( 'position', new BufferAttribute( new Float32Array( 5 * 3 ), 3 ) ); + // - this.line = new Line( geometry, material ); - this.add( this.line ); + var positions2 = [ 1, 1, 0, - 1, 1, 0, - 1, - 1, 0, 1, 1, 0, - 1, - 1, 0, 1, - 1, 0 ]; + var geometry2 = new BufferGeometry(); + geometry2.addAttribute( 'position', new Float32BufferAttribute( positions2, 3 ) ); + geometry2.computeBoundingSphere(); + + this.add( new Mesh( geometry2, new MeshBasicMaterial( { side: THREE.BackSide, fog: false } ) ) ); this.update(); } -RectAreaLightHelper.prototype = Object.create( Object3D.prototype ); +RectAreaLightHelper.prototype = Object.create( Line.prototype ); RectAreaLightHelper.prototype.constructor = RectAreaLightHelper; -RectAreaLightHelper.prototype.dispose = function () { - - this.children[ 0 ].geometry.dispose(); - this.children[ 0 ].material.dispose(); - -}; - RectAreaLightHelper.prototype.update = function () { - // calculate new dimensions of the helper + this.scale.set( 0.5 * this.light.width, 0.5 * this.light.height, 1 ); - var hx = this.light.width * 0.5; - var hy = this.light.height * 0.5; + if ( this.color !== undefined ) { - var position = this.line.geometry.attributes.position; - var array = position.array; + this.material.color.set( this.color ); + this.children[ 0 ].material.color.set( this.color ); - // update vertices + } else { - array[ 0 ] = hx; array[ 1 ] = - hy; array[ 2 ] = 0; - array[ 3 ] = hx; array[ 4 ] = hy; array[ 5 ] = 0; - array[ 6 ] = - hx; array[ 7 ] = hy; array[ 8 ] = 0; - array[ 9 ] = - hx; array[ 10 ] = - hy; array[ 11 ] = 0; - array[ 12 ] = hx; array[ 13 ] = - hy; array[ 14 ] = 0; + this.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity ); - position.needsUpdate = true; + // prevent hue shift + var c = this.material.color; + var max = Math.max( c.r, c.g, c.b ); + if ( max > 1 ) c.multiplyScalar( 1 / max ); - if ( this.color !== undefined ) { + this.children[ 0 ].material.color.copy( this.material.color ); - this.line.material.color.set( this.color ); + } - } else { +}; - this.line.material.color.copy( this.light.color ); +RectAreaLightHelper.prototype.dispose = function () { - } + this.geometry.dispose(); + this.material.dispose(); + this.children[ 0 ].geometry.dispose(); + this.children[ 0 ].material.dispose(); }; diff --git a/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl b/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl index 32ed0f22f81798..3678a30f4df4d3 100644 --- a/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl +++ b/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl @@ -35,10 +35,10 @@ float clearCoatDHRApprox( const in float roughness, const in float dotNL ) { float roughness = material.specularRoughness; vec3 rectCoords[ 4 ]; - rectCoords[ 0 ] = lightPos - halfWidth - halfHeight; // counterclockwise - rectCoords[ 1 ] = lightPos + halfWidth - halfHeight; - rectCoords[ 2 ] = lightPos + halfWidth + halfHeight; - rectCoords[ 3 ] = lightPos - halfWidth + halfHeight; + rectCoords[ 0 ] = lightPos + halfWidth - halfHeight; // counterclockwise; light shines in local neg z direction + rectCoords[ 1 ] = lightPos - halfWidth - halfHeight; + rectCoords[ 2 ] = lightPos - halfWidth + halfHeight; + rectCoords[ 3 ] = lightPos + halfWidth + halfHeight; vec2 uv = LTC_Uv( normal, viewDir, roughness ); From 575dca778539733ae56fedf6d041d86f4d15fa6a Mon Sep 17 00:00:00 2001 From: rexdk <44414261+rexdk@users.noreply.github.com> Date: Wed, 24 Oct 2018 07:09:46 +0100 Subject: [PATCH 12/85] Update BoxGeometry.html To clarify and correct BoxGeometry documentation --- docs/api/en/geometries/BoxGeometry.html | 32 +++++++++++++------------ 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/docs/api/en/geometries/BoxGeometry.html b/docs/api/en/geometries/BoxGeometry.html index 80cb7efa431a86..2817aafc4b7ae5 100644 --- a/docs/api/en/geometries/BoxGeometry.html +++ b/docs/api/en/geometries/BoxGeometry.html @@ -12,8 +12,8 @@

[name]

-

BoxGeometry is the quadrilateral primitive geometry class. It is typically used for creating a cube or irregular quadrilateral of the dimensions provided with the 'width', 'height', and 'depth' constructor arguments.

- +

BoxGeometry is a geometry class for a [link:https://en.wikipedia.org/wiki/Cuboid rectangular cuboid] with a given 'width', 'height', and 'depth'. The cuboid is centred on the origin, with each edge parallel to one of the axes.

+ -

Example

+

示例

var geometry = new THREE.ParametricBufferGeometry( THREE.ParametricGeometries.klein, 25, 25 ); @@ -42,7 +42,7 @@

Example

-

Constructor

+

构造函数

[name]([param:Function func], [param:Integer slices], [param:Integer stacks])

@@ -52,15 +52,15 @@

[name]([param:Function func], [param:Integer slices], [param:Integer stacks] stacks — The count of stacks to use for the parametric function

-

Properties

+

属性

[property:Object parameters]

- An object with a property for each of the constructor parameters. Any modification after instantiation does not change the geometry. + 一个包含着构造函数中每个参数的对象。在对象实例化之后,对该属性的任何修改都不会改变这个几何体。

-

Source

+

方法

[link:https://github.com/mrdoob/three.js/blob/master/src/geometries/ParametricGeometry.js src/geometries/ParametricGeometry.js] diff --git a/docs/api/zh/geometries/ParametricGeometry.html b/docs/api/zh/geometries/ParametricGeometry.html index d54758331a8c85..8940826f0297a8 100644 --- a/docs/api/zh/geometries/ParametricGeometry.html +++ b/docs/api/zh/geometries/ParametricGeometry.html @@ -10,9 +10,9 @@ [page:Geometry] → -

[name]

+

参数化几何体([name])

-

Generate geometry representing a parametric surface.

+

生成由参数表示其表面的几何体。

@@ -32,7 +32,7 @@

[name]

-

Example

+

示例

var geometry = new THREE.ParametricGeometry( THREE.ParametricGeometries.klein, 25, 25 ); @@ -42,7 +42,7 @@

Example

-

Constructor

+

构造函数

[name]([param:Function func], [param:Integer slices], [param:Integer stacks])

@@ -53,15 +53,15 @@

[name]([param:Function func], [param:Integer slices], [param:Integer stacks]

-

Properties

+

属性

[property:Object parameters]

- An object with a property for each of the constructor parameters. Any modification after instantiation does not change the geometry. + 一个包含着构造函数中每个参数的对象。在对象实例化之后,对该属性的任何修改都不会改变这个几何体。

-

Source

+

源代码

[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js] diff --git a/docs/api/zh/math/Ray.html b/docs/api/zh/math/Ray.html index fde60556945ffe..a2d67905fd2579 100644 --- a/docs/api/zh/math/Ray.html +++ b/docs/api/zh/math/Ray.html @@ -23,7 +23,7 @@

构造函数

[name]( [param:Vector3 origin], [param:Vector3 direction] )

[page:Vector3 origin] - (可选)[page:Ray](射线)的原点,默认值是一个位于(0, 0, 0)的[page:Vector3]。
- [page:Vector3 direction] - [page:Vector3] [page:Ray](射线)的方向。该向量必须被标准化(使用[page:Vector3.normalize]函数),这样才能使方法正常运行。 + [page:Vector3 direction] - [page:Vector3] [page:Ray](射线)的方向。该向量必须经过标准化(使用[page:Vector3.normalize]),这样才能使方法正常运行。 默认值是一个位于(0, 0, 0)的[page:Vector3]。

创建一个新的[name]。 @@ -36,7 +36,7 @@

[property:Vector3 origin]

[property:Vector3 direction]

- [page:Ray](射线)的方向。该向量必须被标准化(使用[page:Vector3.normalize]函数),这样才能使方法正常运行。 + [page:Ray](射线)的方向。该向量必须经过标准化(使用[page:Vector3.normalize]),这样才能使方法正常运行。 默认值是一个位于(0, 0, 0)的[page:Vector3]。

@@ -87,27 +87,27 @@

[method:Float distanceSqToPoint]( [param:Vector3 point] )

[method:Float distanceSqToSegment]( [param:Vector3 v0], [param:Vector3 v1], [param:Vector3 optionalPointOnRay], [param:Vector3 optionalPointOnSegment] )

- [page:Vector3 v0] - the start of the line segment.
- [page:Vector3 v1] - the end of the line segment.
- optionalPointOnRay - (optional) if this is provided, it receives the point on this - [page:Ray] that is closest to the segment.
- optionalPointOnSegment - (optional) if this is provided, it receives the point - on the line segment that is closest to this [page:Ray].

+ [page:Vector3 v0] - 线段的起点。
+ [page:Vector3 v1] - 线段的终点。
+ optionalPointOnRay - (可选)若这个值被给定,它将接收在[page:Ray](射线)上距离线段最近的点。 +
+ optionalPointOnSegment - (可选)若这个值被给定,它将接收在线段上距离[page:Ray](射线)最近的点。

- Get the squared distance between this [page:Ray] and a line segment. + 获取[page:Ray](射线)与线段之间的平方距离。

[method:Float distanceToPlane]( [param:Plane plane] )

- [page:Plane plane] - the [page:Plane] to get the distance to.

+ [page:Plane plane] - 将要获取射线原点到该平面的距离的平面。

- Get the distance from [page:.origin origin] to the [page:Plane], or *null* if the [page:Ray] doesn't intersect the [page:Plane]. + 获取射线原点([page:.origin origin])到平面([page:Plane])之间的距离。若射线([page:Ray])不与平面([page:Plane])相交,则将返回*null*。

[method:Float distanceToPoint]( [param:Vector3 point] )

- [page:Vector3 point] - [page:Vector3] The [page:Vector3] to compute a distance to.

+ [page:Vector3 point] - [page:Vector3] 将被用于计算到其距离的[page:Vector3]。

+ 获得射线到所传入[page:Vector3 point]之间最接近的距离。 Get the distance of the closest approach between the [page:Ray] and the [page:Vector3 point].

@@ -121,61 +121,56 @@

[method:Boolean equals]( [param:Ray ray] )

[method:Vector3 intersectBox]( [param:Box3 box], [param:Vector3 target] )

- [page:Box3 box] - the [page:Box3] to intersect with.
- [page:Vector3 target] — the result will be copied into this Vector3.

+ [page:Box3 box] - 将会与之相交的[page:Box3]。
+ [page:Vector3 target] — 结果将会被复制到这一Vector3中。

- 相交 - Intersect this [page:Ray] with a [page:Box3], returning the intersection point or - *null* if there is no intersection. + 将[page:Ray](射线)与一个[page:Box3]相交,并返回交点,倘若没有交点将返回*null*。

[method:Vector3 intersectPlane]( [param:Plane plane], [param:Vector3 target] )

- [page:Plane plane] - the [page:Plane] to intersect with.
- [page:Vector3 target] — the result will be copied into this Vector3.

+ [page:Plane plane] - 将会与之相交的[page:Plane]。
+ [page:Vector3 target] — 结果将会被复制到这一Vector3中。

- Intersect this [page:Ray] with a [page:Plane], returning the intersection point or - *null* if there is no intersection. + 将[page:Ray](射线)与一个[page:Plane]相交,并返回交点,倘若没有交点将返回*null*。

[method:Vector3 intersectSphere]( [param:Sphere sphere], [param:Vector3 target] )

- [page:Sphere sphere] - the [page:Sphere] to intersect with.
- [page:Vector3 target] — the result will be copied into this Vector3.

+ [page:Sphere sphere] - 将会与之相交的[page:Sphere]。
+ [page:Vector3 target] — 结果将会被复制到这一Vector3中。

- Intersect this [page:Ray] with a [page:Sphere], returning the intersection point or - *null* if there is no intersection. + 将[page:Ray](射线)与一个[page:Sphere](球)相交,并返回交点,倘若没有交点将返回*null*。

[method:Vector3 intersectTriangle]( [param:Vector3 a], [param:Vector3 b], [param:Vector3 c], [param:Boolean backfaceCulling], [param:Vector3 target] )

- [page:Vector3 a], [page:Vector3 b], [page:Vector3 c] - The [page:Vector3] points making up the triangle.
- [page:Boolean backfaceCulling] - whether to use backface culling.
- [page:Vector3 target] — the result will be copied into this Vector3.

+ [page:Vector3 a], [page:Vector3 b], [page:Vector3 c] - 组成三角形的三个[page:Vector3]。
+ [page:Boolean backfaceCulling] - 是否使用背面剔除。
+ [page:Vector3 target] — 结果将会被复制到这一Vector3中。

- Intersect this [page:Ray] with a triangle, returning the intersection point or *null* - if there is no intersection. + 将[page:Ray](射线)与一个三角形相交,并返回交点,倘若没有交点将返回*null*。

[method:Boolean intersectsBox]( [param:Box3 box] )

- [page:Box3 box] - the [page:Box3] to intersect with.

+ [page:Box3 box] - 将被检查是否与之相交的[page:Box3]。

- Return true if this [page:Ray] intersects with the [page:Box3]. + 若这一射线与[page:Box3]相交,则将返回true。

[method:Boolean intersectsPlane]( [param:Plane plane] )

- [page:Plane plane] - the [page:Plane] to intersect with.

+ [page:Plane plane] - 将被检查是否与之相交的[page:Plane]。

- Return true if this [page:Ray] intersects with the [page:Plane]. + 若这一射线与[page:Plane]相交,则将返回true。

[method:Boolean intersectsSphere]( [param:Sphere sphere] )

- [page:Sphere sphere] - the [page:Sphere] to intersect with.

+ [page:Sphere sphere] - 将被检查是否与之相交的[page:Sphere]。

- Return true if this [page:Ray] intersects with the [page:Sphere]. + 若这一射线与[page:Sphere]相交,则将返回true。

[method:Ray lookAt]( [param:Vector3 v] )

@@ -194,13 +189,13 @@

[method:Ray recast]( [param:Float t] )

[method:Ray set]( [param:Vector3 origin], [param:Vector3 direction] )

- [page:Vector3 origin] - the [page:.origin origin] of the [page:Ray].
- [page:Vector3 origin] - the [page:.direction direction] of the [page:Ray]. - This must be normalized (with [page:Vector3.normalize]) for the methods to operate - properly.

+ [page:Vector3 origin] - [page:Ray](射线)的[page:.origin origin](原点)。
+ [page:Vector3 origin] - [page:Ray](射线)的[page:.direction direction](方向)。 + + 该向量必须经过标准化(使用[page:Vector3.normalize]),这样才能使方法正常运行。 +

- Copy the parameters to the [page:.origin origin] and [page:.direction direction] properties - of this ray. + 将传入的参数赋值给射线的[page:.origin origin]和[page:.direction direction]。

diff --git a/docs/api/zh/math/Vector2.html b/docs/api/zh/math/Vector2.html index 83ca5a87e6e3dd..10656d32f2f1da 100644 --- a/docs/api/zh/math/Vector2.html +++ b/docs/api/zh/math/Vector2.html @@ -8,36 +8,33 @@ -

[name]

+

二维向量([name])

- Class representing a 2D [link:https://en.wikipedia.org/wiki/Vector_space vector]. + 表示2D [link:https://en.wikipedia.org/wiki/Vector_space vector](二维向量)的类。 - A 2D vector is an ordered pair of numbers (labeled x and y), which can be used to - represent a number of things, such as: + 一个二维向量是一对有顺序的数字(标记为x和y),可被用于表示很多事物,例如:

  • - A point in 2D space (i.e. a position on a plane). + 一个位于二维空间中的点(例如一个在平面上的点)。
  • - A direction and length across a plane. In three.js the length will always be the - [link:https://en.wikipedia.org/wiki/Euclidean_distance Euclidean distance] - (straight-line distance) from (0, 0) to (x, y) and the direction is also - measured from (0, 0) towards (x, y). + 横过平面的方向与长度。在three.js中,长度总是从(0, 0)到(x, y)的 + [link:https://en.wikipedia.org/wiki/Euclidean_distance Euclidean distance](欧几里德距离,即直线距离), + 方向也是从(0, 0)到(x, y)的方向。
  • - Any arbitrary ordered pair of numbers. + 任意的、有顺序的一对数字。

- There are other things a 2D vector can be used to represent, such as momentum - vectors, complex numbers and so on, however these are the most common uses in three.js. + 其他的一些事物也可以使用二维向量进行表示,比如说动量矢量、复数等等;但以上这些是three.js中的常用用途。

-

Example

+

示例

var a = new THREE.Vector2( 0, 1 ); @@ -49,38 +46,39 @@

Example

-

Constructor

+

构造函数

[name]( [param:Float x], [param:Float y] )

- [page:Float x] - the x value of the vector. Default is *0*.
- [page:Float y] - the y value of the vector. Default is *0*.

+ [page:Float x] - 向量的x值,默认值为*0*。
+ [page:Float y] - 向量的y值,默认值为*0*。

- Creates a new [name]. + 创建一个新的[name]。

-

Properties

+

属性

[property:Boolean isVector2]

- Used to check whether this or derived classes are Vector2s. Default is *true*.

+ 用于检查该类或者其派生类是否为Vector2,默认值为true。 +

- You should not change this, as it is used internally for optimisation. + 你不应当对这个属性进行改变,因为它在内部使用,以用于优化。

[property:Float height]

-

Alias for [page:.y y].

+

[page:.y y]的别名。

[property:Float width]

-

Alias for [page:.x x].

+

[page:.x x]的别名。

[property:Float x]

[property:Float y]

-

Methods

+

方法

[method:this add]( [param:Vector2 v] )

Adds [page:Vector2 v] to this vector.

From c4d849b0603c6c7047ed3f9af38b3db49cb2661c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E7=82=B3=E6=9D=83?= <695601626@qq.com> Date: Fri, 14 Dec 2018 16:46:08 +0800 Subject: [PATCH 50/85] fixes bug --- editor/js/Sidebar.Object.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/editor/js/Sidebar.Object.js b/editor/js/Sidebar.Object.js index 78086dd213a02d..b6510fb90020ea 100644 --- a/editor/js/Sidebar.Object.js +++ b/editor/js/Sidebar.Object.js @@ -480,8 +480,8 @@ Sidebar.Object = function ( editor ) { if ( object.receiveShadow !== undefined && object.receiveShadow !== objectReceiveShadow.getValue() ) { - editor.execute( new SetValueCommand( object, 'receiveShadow', objectReceiveShadow.getValue() ) ); object.material.needsUpdate = true; + editor.execute( new SetValueCommand( object, 'receiveShadow', objectReceiveShadow.getValue() ) ); } From c7213e28045bf21abf1c9f3829dc08d8117c8eea Mon Sep 17 00:00:00 2001 From: Conrad Pinnow Date: Fri, 14 Dec 2018 12:59:02 -0700 Subject: [PATCH 51/85] modification to parsing so ke values are correctly converted from string to array --- examples/js/loaders/MTLLoader.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/js/loaders/MTLLoader.js b/examples/js/loaders/MTLLoader.js index a98159b68c8ecc..bc4e5c25ff18d2 100644 --- a/examples/js/loaders/MTLLoader.js +++ b/examples/js/loaders/MTLLoader.js @@ -149,7 +149,7 @@ THREE.MTLLoader.prototype = { } else { - if ( key === 'ka' || key === 'kd' || key === 'ks' ) { + if ( key === 'ka' || key === 'kd' || key === 'ks'|| key ==='ke') { var ss = value.split( delimiter_pattern, 3 ); info[ key ] = [ parseFloat( ss[ 0 ] ), parseFloat( ss[ 1 ] ), parseFloat( ss[ 2 ] ) ]; From 4581003cef7b5c9e86916f90a901d9d855b1d422 Mon Sep 17 00:00:00 2001 From: Don McCurdy Date: Sat, 15 Dec 2018 17:57:21 -0800 Subject: [PATCH 52/85] GLTFLoader: Fix bug with certain interleaved attributes. --- examples/js/loaders/GLTFLoader.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/js/loaders/GLTFLoader.js b/examples/js/loaders/GLTFLoader.js index b54b097668513f..d329a50d0c2f7f 100644 --- a/examples/js/loaders/GLTFLoader.js +++ b/examples/js/loaders/GLTFLoader.js @@ -1611,12 +1611,12 @@ THREE.GLTFLoader = ( function () { var itemSize = attribute.itemSize; var array = attribute.array.slice( 0, count * itemSize ); - for ( var i = 0; i < count; ++ i ) { + for ( var i = 0, j = 0; i < count; ++ i ) { - array[ i ] = attribute.getX( i ); - if ( itemSize >= 2 ) array[ i + 1 ] = attribute.getY( i ); - if ( itemSize >= 3 ) array[ i + 2 ] = attribute.getZ( i ); - if ( itemSize >= 4 ) array[ i + 3 ] = attribute.getW( i ); + array[ j++ ] = attribute.getX( i ); + if ( itemSize >= 2 ) array[ j++ ] = attribute.getY( i ); + if ( itemSize >= 3 ) array[ j++ ] = attribute.getZ( i ); + if ( itemSize >= 4 ) array[ j++ ] = attribute.getW( i ); } From 809ece3089fef0f740356fc5dd5cd369e8a737e9 Mon Sep 17 00:00:00 2001 From: gogoend Date: Sun, 16 Dec 2018 16:18:29 +0800 Subject: [PATCH 53/85] Translate some files in extras and math floder,and some fix --- docs/api/zh/extras/core/Curve.html | 2 +- docs/api/zh/extras/core/CurvePath.html | 30 ++--- docs/api/zh/extras/core/Interpolations.html | 24 ++-- docs/api/zh/extras/core/Path.html | 106 +++++++++--------- docs/api/zh/extras/core/ShapePath.html | 2 +- .../zh/extras/curves/CubicBezierCurve3.html | 2 +- docs/api/zh/extras/curves/LineCurve.html | 2 +- .../extras/curves/QuadraticBezierCurve.html | 38 +++---- .../extras/curves/QuadraticBezierCurve3.html | 2 +- .../extras/objects/ImmediateRenderObject.html | 4 +- docs/api/zh/math/Quaternion.html | 33 +++--- docs/api/zh/math/Vector2.html | 46 ++++---- docs/manual/zh/introduction/FAQ.html | 8 +- 13 files changed, 151 insertions(+), 148 deletions(-) diff --git a/docs/api/zh/extras/core/Curve.html b/docs/api/zh/extras/core/Curve.html index 5115f27d85fcbe..ee3a07713aa2ab 100644 --- a/docs/api/zh/extras/core/Curve.html +++ b/docs/api/zh/extras/core/Curve.html @@ -8,7 +8,7 @@ -

曲线([name])

+

[name]

An abstract base class for creating a [name] object that contains methods for interpolation. diff --git a/docs/api/zh/extras/core/CurvePath.html b/docs/api/zh/extras/core/CurvePath.html index 54c6c8ef6e48c9..9b32955a386469 100644 --- a/docs/api/zh/extras/core/CurvePath.html +++ b/docs/api/zh/extras/core/CurvePath.html @@ -10,50 +10,50 @@ [page:Curve] → -

[name]

+

曲线路径([name])

- An abstract base class extending [page:Curve]. A CurvePath is simply an array of connected curves, - but retains the api of a curve. + + 一个扩展了[page:Curve]的抽象基类。CurvePath仅仅是一个已连接的曲线的数组,但保留了曲线的API。

-

Constructor

+

构造函数

[name]()

- The constructor take no parameters. + 构造函数中不传入参数。

-

Properties

-

See the base [page:Curve] class for common properties.

+

属性

+

请参阅其基类[page:Curve]来了解供共有属性。

[property:array curves]

-

The array of [page:Curve Curves].

+

[page:Curve Curves]数组。

[property:boolean autoClose]

-

Whether or not to automatically close the path.

+

是否自动闭合路径。

-

Methods

-

See the base [page:Curve] class for common methods.

+

方法

+

请参阅其基类[page:Curve]来了解共有方法。

[method:null add]( [param:Curve curve] )

-

Add a curve to the [page:.curves] array.

+

添加一条曲线到[page:.curves]数组中。

[method:null closePath]()

-

Adds a [page:LineCurve lineCurve] to close the path.

+

添加一条[page:LineCurve lineCurve]用于闭合路径。

[method:Float getCurveLengths]()

-

Adds together the lengths of the curves in the [page:.curves] array.

+

将[page:.curves]数组中曲线的长度相加。

-

Source

+

源代码

[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js] diff --git a/docs/api/zh/extras/core/Interpolations.html b/docs/api/zh/extras/core/Interpolations.html index c31ba66b943d87..57a47242693de0 100644 --- a/docs/api/zh/extras/core/Interpolations.html +++ b/docs/api/zh/extras/core/Interpolations.html @@ -8,39 +8,39 @@ -

[name]

+

插值([name])

TODO

-

Methods

+

方法

[method:Float CatmullRom]( [param:Float t], [param:Float p0], [param:Float p1], [param:Float p2], [param:Float p3] )

- t -- interpolation weight.
- p0, p1, p2, p3 -- the points defining the spline curve.

+ t -- 插值权重
+ p0, p1, p2, p3 -- 定义了样条曲线的点。

- Used internally by [page:SplineCurve SplineCurve]. + 在内部由[page:SplineCurve SplineCurve]所使用。

[method:Float QuadraticBezier]( [param:Float t], [param:Float p0], [param:Float p1], [param:Float p2] )

- t -- interpolation weight.
- p0, p1, p2 -- the starting, control and end points defining the curve.

+ t -- 插值权重
+ p0, p1, p2 -- 定义了该曲线的起始点、控制点和终止点。

- Used internally by [page:QuadraticBezierCurve3 QuadraticBezierCurve3], [page:QuadraticBezierCurve QuadraticBezierCurve] and [page:Font Font]. + 在内部由[page:QuadraticBezierCurve3 QuadraticBezierCurve3]、[page:QuadraticBezierCurve QuadraticBezierCurve]和[page:Font Font]所使用。

[method:Float CubicBezier]( [param:Float t], [param:Float p0], [param:Float p1], [param:Float p2], [param:Float p3] )

- t -- interpolation weight.
- p0, p1, p2, p3 -- the starting, control(twice) and end points defining the curve.

+ t -- 插值权重
+ p0, p1, p2, p3 -- 定义了该曲线的起始点、两个控制点和终止点。

- Used internally by [page:CubicBezierCurve3 CubicBezierCurve3], [page:CubicBezierCurve CubicBezierCurve] and [page:Font Font]. + 在内部由[page:CubicBezierCurve3 CubicBezierCurve3]、[page:CubicBezierCurve CubicBezierCurve]和[page:Font Font]所使用。

-

Source

+

源代码

[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js] diff --git a/docs/api/zh/extras/core/Path.html b/docs/api/zh/extras/core/Path.html index 5adbe97c226225..bfe61943b96ff4 100644 --- a/docs/api/zh/extras/core/Path.html +++ b/docs/api/zh/extras/core/Path.html @@ -10,13 +10,13 @@ [page:CurvePath] → -

[name]

+

路径([name])

- A 2D path representation. The class provides methods for creating paths and contours of 2D shapes similar to the 2D Canvas API. + 该类定义了二维路径,提供了一些类似2D Canvas API的方法来创建或者构造二维路径。

-

Example

+

示例

var path = new THREE.Path(); @@ -35,110 +35,108 @@

Example

-

Constructor

+

构造函数

[name]( [param:Array points] )

- points -- (optional) array of [page:Vector2 Vector2s].

+ points -- (可选)[page:Vector2 Vector2s]数组。

- Creates a Path from the points. The first point defines the offset, then successive points - are added to the [page:CurvePath.curves curves] array as [page:LineCurve LineCurves].

+ 从传入的点中创建一条Path。第一个点定义了偏移量, + 接下来的点作为[page:LineCurve LineCurves]被添加到[page:CurvePath.curves curves]数组中。

- If no points are specified, an empty path is created and the [page:.currentPoint] is set to - the origin. + 倘若没有点被指定,一条空路径将会被创建,[page:.currentPoint]将被设置为原点。

-

Properties

-

See the base [page:CurvePath] class for common properties.

+

属性

+

请参阅其基类[page:CurvePath]来了解共有属性。

[property:array currentPoint]

-

The current offset of the path. Any new [page:Curve] added will start here.

+

路径当前的偏移量,任何新被加入的[page:Curve]将会从这里开始。

-

Methods

-

See the base [page:CurvePath] class for common methods.

+

方法

+

请参阅其基类[page:CurvePath]来了解共有方法。

[method:null absarc]( [param:Float x], [param:Float y], [param:Float radius], [param:Float startAngle], [param:Float endAngle], [param:Float clockwise] )

- x, y -- The absolute center of the arc.
- radius -- The radius of the arc.
- startAngle -- The start angle in radians.
- endAngle -- The end angle in radians.
- clockwise -- Sweep the arc clockwise. Defaults to *false*.

+ x, y -- 弧线的绝对中心。
+ radius -- 弧线的半径。
+ startAngle -- 起始角,以弧度来表示。
+ endAngle -- 终止角,以弧度来表示。
+ clockwise -- 以顺时针方向创建(扫过)弧线。默认值为*false*。

- Adds an absolutely positioned [page:EllipseCurve EllipseCurve] to the path. + 添加一条绝对定位的[page:EllipseCurve EllipseCurve]到路径中。

[method:null absellipse]( [param:Float x], [param:Float y], [param:Float xRadius], [param:Float yRadius], [param:Float startAngle], [param:Float endAngle], [param:Float clockwise], [param:Float rotation] )

- x, y -- The absolute center of the ellipse.
- xRadius -- The radius of the ellipse in the x axis.
- yRadius -- The radius of the ellipse in the y axis.
- startAngle -- The start angle in radians.
- endAngle -- The end angle in radians.
- clockwise -- Sweep the ellipse clockwise. Defaults to false.
- rotation -- The rotation angle of the ellipse in radians, counterclockwise from the positive X axis. Optional, defaults to 0.

- - Adds an absolutely positioned [page:EllipseCurve EllipseCurve] to the path. + x, y -- 椭圆的绝对中心。
+ xRadius -- 椭圆x轴方向的半径。
+ yRadius -- 椭圆y轴方向的半径。
+ startAngle -- 起始角,以弧度来表示。
+ endAngle -- 终止角,以弧度来表示。
+ clockwise -- 以顺时针方向创建(扫过)椭圆。默认值为*false*。
+ rotation -- 椭圆从X轴正方向逆时针的旋转角度(可选),以弧度表示,默认值为*0*。

+ + 添加一条绝对定位的[page:EllipseCurve EllipseCurve]到路径中。

[method:null arc]( [param:Float x], [param:Float y], [param:Float radius], [param:Float startAngle], [param:Float endAngle], [param:Float clockwise] )

- x, y -- The center of the arc offset from the last call.
- radius -- The radius of the arc.
- startAngle -- The start angle in radians.
- endAngle -- The end angle in radians.
- clockwise -- Sweep the arc clockwise. Defaults to *false*.

+ x, y -- 弧线的中心来自上次调用后的偏移量。
+ radius -- 弧线的半径。
+ startAngle -- 起始角,以弧度来表示。
+ endAngle -- 终止角,以弧度来表示。
+ clockwise -- 以顺时针方向创建(扫过)弧线。默认值为*false*。

- Adds an [page:EllipseCurve EllipseCurve] to the path, positioned relative to [page:.currentPoint]. + 添加一条[page:EllipseCurve EllipseCurve]到路径中,位置相对于[page:.currentPoint]。

[method:null bezierCurveTo]( [param:Float cp1X], [param:Float cp1Y], [param:Float cp2X], [param:Float cp2Y], [param:Float x], [param:Float y] )

-

This creates a bezier curve from [page:.currentPoint] with (cp1X, cp1Y) and (cp2X, cp2Y) as control points and updates [page:.currentPoint] to x and y.

+

从[page:.currentPoint]创建一条贝塞尔曲线,以(cp1X, cp1Y)和(cp2X, cp2Y)作为控制点,并将[page:.currentPoint]更新到x,y。

[method:null ellipse]( [param:Float x], [param:Float y], [param:Float xRadius], [param:Float yRadius], [param:Float startAngle], [param:Float endAngle], [param:Float clockwise], [param:Float rotation] )

- x, y -- The center of the ellipse offset from the last call.
- xRadius -- The radius of the ellipse in the x axis.
- yRadius -- The radius of the ellipse in the y axis.
- startAngle -- The start angle in radians.
- endAngle -- The end angle in radians.
- clockwise -- Sweep the ellipse clockwise. Defaults to *false*.
- rotation -- The rotation angle of the ellipse in radians, counterclockwise from the positive X axis. Optional, defaults to *0*.

- - Adds an [page:EllipseCurve EllipseCurve] to the path, positioned relative to [page:.currentPoint]. + x, y -- 椭圆的中心来自上次调用后的偏移量。The center of the ellipse offset from the last call.
+ xRadius -- 椭圆x轴方向的半径。
+ yRadius -- 椭圆y轴方向的半径。
+ startAngle -- 起始角,以弧度来表示。
+ endAngle -- 终止角,以弧度来表示。
+ clockwise -- 以顺时针方向创建(扫过)椭圆。默认值为*false*。
+ rotation -- 椭圆从X轴正方向逆时针的旋转角度(可选),以弧度表示,默认值为*0*。

+ + 添加一条[page:EllipseCurve EllipseCurve]到路径中,位置相对于[page:.currentPoint]。

[method:null lineTo]( [param:Float x], [param:Float y] )

-

Connects a [page:LineCurve] from [page:.currentPoint] to x, y onto the path.

+

在当前路径上,从[page:.currentPoint]连接一条直线到x,y。

[method:null moveTo]( [param:Float x], [param:Float y] )

-

Move the [page:.currentPoint] to x, y.

+

将[page:.currentPoint]移动到x, y。

[method:null quadraticCurveTo]( [param:Float cpX], [param:Float cpY], [param:Float x], [param:Float y] )

-

Creates a quadratic curve from [page:.currentPoint] with cpX and cpY as control point and updates [page:.currentPoint] to x and y.

+

从[page:.currentPoint]创建一条二次曲线,以(cpX,cpY)作为控制点,并将[page:.currentPoint]更新到x,y。

[method:null setFromPoints]( [param:Array vector2s] )

- points -- array of [page:Vector2 Vector2s].

+ points -- [page:Vector2 Vector2]数组。

- Points are added to the [page:CurvePath.curves curves] - array as [page:LineCurve LineCurves]. + 点将被作为[page:LineCurve LineCurves]加入到[page:CurvePath.curves curves]数组中。

[method:null splineThru] ( [param:Array points] )

- points - An array of [page:Vector2 Vector2s]

+ points -[page:Vector2 Vector2]数组。

- Connects a new [page:SplineCurve] onto the path. + 连接一条新的[page:SplineCurve]到路径上。

-

Source

+

源代码

[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js] diff --git a/docs/api/zh/extras/core/ShapePath.html b/docs/api/zh/extras/core/ShapePath.html index f985026bc4248a..5b99de06f9ee83 100644 --- a/docs/api/zh/extras/core/ShapePath.html +++ b/docs/api/zh/extras/core/ShapePath.html @@ -30,7 +30,7 @@

[name]( )

-

P属性

+

属性

[property:array subPaths]

diff --git a/docs/api/zh/extras/curves/CubicBezierCurve3.html b/docs/api/zh/extras/curves/CubicBezierCurve3.html index b60dd4601d92d0..f6c9c5a4acefe6 100644 --- a/docs/api/zh/extras/curves/CubicBezierCurve3.html +++ b/docs/api/zh/extras/curves/CubicBezierCurve3.html @@ -10,7 +10,7 @@ [page:Curve] → -

三维三次贝塞尔曲线[name]

+

三维三次贝塞尔曲线([name])

创建一条光滑的三维 diff --git a/docs/api/zh/extras/curves/LineCurve.html b/docs/api/zh/extras/curves/LineCurve.html index 02d5efe610042e..fd8d674ab296a2 100644 --- a/docs/api/zh/extras/curves/LineCurve.html +++ b/docs/api/zh/extras/curves/LineCurve.html @@ -10,7 +10,7 @@ [page:Curve] → -

二维线段曲线[name]

+

二维线段曲线([name])

一个表示二维线段的曲线。

diff --git a/docs/api/zh/extras/curves/QuadraticBezierCurve.html b/docs/api/zh/extras/curves/QuadraticBezierCurve.html index f20c947bd81d7d..0356382cfd1bd6 100644 --- a/docs/api/zh/extras/curves/QuadraticBezierCurve.html +++ b/docs/api/zh/extras/curves/QuadraticBezierCurve.html @@ -10,15 +10,15 @@ [page:Curve] → -

[name]

+

二维二次贝塞尔曲线([name])

- Create a smooth 2d - quadratic bezier curve, - defined by a startpoint, endpoint and a single control point. + 创建一条光滑的二维 + 二次贝塞尔曲线, + 由起点、终点和一个控制点所定义。

-

Example

+

示例

var curve = new THREE.QuadraticBezierCurve( @@ -36,41 +36,41 @@

Example

var curveObject = new THREE.Line( geometry, material );
-

Constructor

+

构造函数

[name]( [param:Vector2 v0], [param:Vector2 v1], [param:Vector2 v2] )

- [page:Vector2 v0] – The startpoint.
- [page:Vector2 v1] – The control point.
- [page:Vector2 v2] – The endpoint. + [page:Vector2 v0] – 起点
+ [page:Vector2 v1] – 中间的控制点
+ [page:Vector2 v2] – 终点

-

Properties

-

See the base [page:Curve] class for common properties.

+

属性

+

请参阅其基类[page:Curve]来了解共有属性。

[property:Boolean isQuadraticBezierCurve]

- Used to check whether this or derived classes are QuadraticBezierCurves. Default is *true*.

+ 用于检查该类或者其派生类是否为QuadraticBezierCurve。默认值为*true*。

- You should not change this, as it used internally for optimisation. + 你不应当对这一属性进行改变,它在内部使用,以用于优化。

[property:Vector2 v0]

-

The startpoint.

+

起点

[property:Vector2 v1]

-

The control point.

+

控制点

[property:Vector2 v2]

-

The endpoint.

+

终点

-

Methods

-

See the base [page:Curve] class for common methods.

+

方法

+

请参阅其基类[page:Curve]来了解共有方法。

-

Source

+

源代码

[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js] diff --git a/docs/api/zh/extras/curves/QuadraticBezierCurve3.html b/docs/api/zh/extras/curves/QuadraticBezierCurve3.html index 9e1a18bf6df871..353ab33ba55e1e 100644 --- a/docs/api/zh/extras/curves/QuadraticBezierCurve3.html +++ b/docs/api/zh/extras/curves/QuadraticBezierCurve3.html @@ -10,7 +10,7 @@ [page:Curve] → -

三维二次贝塞尔曲线[name]

+

三维二次贝塞尔曲线([name])

创建一条光滑的三维 diff --git a/docs/api/zh/extras/objects/ImmediateRenderObject.html b/docs/api/zh/extras/objects/ImmediateRenderObject.html index c2f8f8d5034f46..3a9d4694a43a97 100644 --- a/docs/api/zh/extras/objects/ImmediateRenderObject.html +++ b/docs/api/zh/extras/objects/ImmediateRenderObject.html @@ -10,9 +10,9 @@ [page:Object3D] → -

及时渲染对象([name])

+

即时渲染对象([name])

-

及时渲染对象的基类。

+

即时渲染对象的基类。

构造函数(Constructor)

diff --git a/docs/api/zh/math/Quaternion.html b/docs/api/zh/math/Quaternion.html index 9cdeb405a73e9f..f2465c6f81b237 100644 --- a/docs/api/zh/math/Quaternion.html +++ b/docs/api/zh/math/Quaternion.html @@ -8,16 +8,18 @@ -

四元数([name])

+

[name]

- 这个类是对[link:http://en.wikipedia.org/wiki/Quaternion quaternion](四元数)的实现。 - 它用于排除万向锁([link:http://en.wikipedia.org/wiki/Gimbal_lock gimbal lock])问题,以对物体进行旋转([link:https://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation rotating things]), - 此外它还具有其它优点。 + Implementation of a [link:http://en.wikipedia.org/wiki/Quaternion quaternion]. + This is used for [link:https://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation rotating things] + without encountering the dreaded + [link:http://en.wikipedia.org/wiki/Gimbal_lock gimbal lock] issue, amongst other + advantages.

-

示例

+

Example

var quaternion = new THREE.Quaternion(); @@ -28,7 +30,7 @@

示例

-

构造函数

+

Constructor

[name]( [param:Float x], [param:Float y], [param:Float z], [param:Float w] )

@@ -40,31 +42,32 @@

[name]( [param:Float x], [param:Float y], [param:Float z], [param:Float w] )

-

属性

+

Properties

[property:Float x]

-

改变这一属性将会导致[page:.onChangeCallback onChangeCallback]被调用。

+

Changing this property will result in [page:.onChangeCallback onChangeCallback] being called.

[property:Float y]

-

改变这一属性将会导致[page:.onChangeCallback onChangeCallback]被调用。

+

Changing this property will result in [page:.onChangeCallback onChangeCallback] being called.

[property:Float z]

-

改变这一属性将会导致[page:.onChangeCallback onChangeCallback]被调用。

+

Changing this property will result in [page:.onChangeCallback onChangeCallback] being called.

[property:Float w]

-

改变这一属性将会导致[page:.onChangeCallback onChangeCallback]被调用。

+

Changing this property will result in [page:.onChangeCallback onChangeCallback] being called.

-

方法

+

Methods

[method:Float angleTo]( [param:Quaternion q] )

- 以弧度的形式返回这一四元数与四元数[page:Quaternion q]之间的夹角。 + Returns the angle between this quaternion and quaternion [page:Quaternion q] in radians.

[method:Quaternion clone]()

- 以和这一四元数相同的[page:.x x]、[page:.y y]、[page:.z z]和[page:.w w]属性来创建一个新的四元数。 + Creates a new Quaternion with identical [page:.x x], [page:.y y], + [page:.z z] and [page:.w w] properties to this one.

[method:Quaternion conjugate]()

@@ -287,4 +290,4 @@

Source

[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js] - + \ No newline at end of file diff --git a/docs/api/zh/math/Vector2.html b/docs/api/zh/math/Vector2.html index 10656d32f2f1da..2eeb1146f2545e 100644 --- a/docs/api/zh/math/Vector2.html +++ b/docs/api/zh/math/Vector2.html @@ -8,33 +8,36 @@ -

二维向量([name])

+

[name]

- 表示2D [link:https://en.wikipedia.org/wiki/Vector_space vector](二维向量)的类。 + Class representing a 2D [link:https://en.wikipedia.org/wiki/Vector_space vector]. - 一个二维向量是一对有顺序的数字(标记为x和y),可被用于表示很多事物,例如: + A 2D vector is an ordered pair of numbers (labeled x and y), which can be used to + represent a number of things, such as:

  • - 一个位于二维空间中的点(例如一个在平面上的点)。 + A point in 2D space (i.e. a position on a plane).
  • - 横过平面的方向与长度。在three.js中,长度总是从(0, 0)到(x, y)的 - [link:https://en.wikipedia.org/wiki/Euclidean_distance Euclidean distance](欧几里德距离,即直线距离), - 方向也是从(0, 0)到(x, y)的方向。 + A direction and length across a plane. In three.js the length will always be the + [link:https://en.wikipedia.org/wiki/Euclidean_distance Euclidean distance] + (straight-line distance) from (0, 0) to (x, y) and the direction is also + measured from (0, 0) towards (x, y).
  • - 任意的、有顺序的一对数字。 + Any arbitrary ordered pair of numbers.

- 其他的一些事物也可以使用二维向量进行表示,比如说动量矢量、复数等等;但以上这些是three.js中的常用用途。 + There are other things a 2D vector can be used to represent, such as momentum + vectors, complex numbers and so on, however these are the most common uses in three.js.

-

示例

+

Example

var a = new THREE.Vector2( 0, 1 ); @@ -46,39 +49,38 @@

示例

-

构造函数

+

Constructor

[name]( [param:Float x], [param:Float y] )

- [page:Float x] - 向量的x值,默认值为*0*。
- [page:Float y] - 向量的y值,默认值为*0*。

+ [page:Float x] - the x value of the vector. Default is *0*.
+ [page:Float y] - the y value of the vector. Default is *0*.

- 创建一个新的[name]。 + Creates a new [name].

-

属性

+

Properties

[property:Boolean isVector2]

- 用于检查该类或者其派生类是否为Vector2,默认值为true。 -

+ Used to check whether this or derived classes are Vector2s. Default is *true*.

- 你不应当对这个属性进行改变,因为它在内部使用,以用于优化。 + You should not change this, as it is used internally for optimisation.

[property:Float height]

-

[page:.y y]的别名。

+

Alias for [page:.y y].

[property:Float width]

-

[page:.x x]的别名。

+

Alias for [page:.x x].

[property:Float x]

[property:Float y]

-

方法

+

Methods

[method:this add]( [param:Vector2 v] )

Adds [page:Vector2 v] to this vector.

@@ -341,4 +343,4 @@

Source

[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js] - + \ No newline at end of file diff --git a/docs/manual/zh/introduction/FAQ.html b/docs/manual/zh/introduction/FAQ.html index 353d10bbfaa96d..b2c0ce9335f2ca 100644 --- a/docs/manual/zh/introduction/FAQ.html +++ b/docs/manual/zh/introduction/FAQ.html @@ -10,7 +10,7 @@

常见问题([name])

-

哪一种三维物体格式能够得到最好地支持呢?

+

哪一种三维物体格式能够得到最好地支持?

推荐使用glTF(gl传输格式)来对三维物体进行导入和导出,由于glTF这种格式是专注于在程序运行时呈现三维物体的,所以它的传输效率非常高,且加载速度非常快。 @@ -41,13 +41,13 @@

如何在窗口调整大小时保持场景比例不变?

visible_height = 2 * Math.tan( ( Math.PI / 180 ) * camera.fov / 2 ) * distance_from_camera;
如果我们以一定的百分比增加了窗口的高度,那我们所想要的结果便是所有距离的可见高度都增加相同的百分比。 - 这并不能通过改变摄像机的位置来实现,相反,你得改变摄像机的视野角度(FOV)。这是个示例:[link:http://jsfiddle.net/Q4Jpu/ Example]. + 这并不能通过改变摄像机的位置来实现,相反,你需要改变摄像机的视野角度(FOV)。这是个示例:[link:http://jsfiddle.net/Q4Jpu/ Example].

为什么我的物体的一部分是不可见的?

- 这可能是由于面消隐而导致的。面是具有朝向的,这个朝向决定了哪边是正面或者哪边是背面。 - 在正常情况下,渲染时会将背面进行消隐。要查看这是不是你所遇到的问题,请将material的slide更改为THREE.DoubleSide。 + 这可能是由于面剔除而导致的。面是具有朝向的,这个朝向决定了哪边是正面或者哪边是背面。 + 在正常情况下,渲染时会将背面进行剔除。要查看这是否为你所遇到的问题,请将material的slide更改为THREE.DoubleSide。 material.side = THREE.DoubleSide

From c905c0ffd594e4205f41b6e03d13ee4c497dd002 Mon Sep 17 00:00:00 2001 From: gogoend Date: Sun, 16 Dec 2018 16:45:28 +0800 Subject: [PATCH 54/85] Update FAQ.html --- docs/manual/zh/introduction/FAQ.html | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/docs/manual/zh/introduction/FAQ.html b/docs/manual/zh/introduction/FAQ.html index b2c0ce9335f2ca..4f4704f3b67b94 100644 --- a/docs/manual/zh/introduction/FAQ.html +++ b/docs/manual/zh/introduction/FAQ.html @@ -10,7 +10,7 @@

常见问题([name])

-

哪一种三维物体格式能够得到最好地支持?

+

哪一种三维物体格式能够得到最好地支持呢?

推荐使用glTF(gl传输格式)来对三维物体进行导入和导出,由于glTF这种格式是专注于在程序运行时呈现三维物体的,所以它的传输效率非常高,且加载速度非常快。 @@ -41,15 +41,14 @@

如何在窗口调整大小时保持场景比例不变?

visible_height = 2 * Math.tan( ( Math.PI / 180 ) * camera.fov / 2 ) * distance_from_camera;
如果我们以一定的百分比增加了窗口的高度,那我们所想要的结果便是所有距离的可见高度都增加相同的百分比。 - 这并不能通过改变摄像机的位置来实现,相反,你需要改变摄像机的视野角度(FOV)。这是个示例:[link:http://jsfiddle.net/Q4Jpu/ Example]. + 这并不能通过改变摄像机的位置来实现,相反,你得改变摄像机的视野角度(FOV)。这是个示例:[link:http://jsfiddle.net/Q4Jpu/ Example].

为什么我的物体的一部分是不可见的?

- 这可能是由于面剔除而导致的。面是具有朝向的,这个朝向决定了哪边是正面或者哪边是背面。 - 在正常情况下,渲染时会将背面进行剔除。要查看这是否为你所遇到的问题,请将material的slide更改为THREE.DoubleSide。 + 这可能是由于面消隐而导致的。面是具有朝向的,这个朝向决定了哪边是正面或者哪边是背面。 + 在正常情况下,渲染时会将背面进行消隐。要查看这是不是你所遇到的问题,请将material的side更改为THREE.DoubleSide。 material.side = THREE.DoubleSide

- From eb44f5a9cf6530b0ca80459803d43ddfecc75c69 Mon Sep 17 00:00:00 2001 From: gogoend Date: Sun, 16 Dec 2018 16:54:49 +0800 Subject: [PATCH 55/85] Fix some characters. --- docs/manual/zh/introduction/FAQ.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/manual/zh/introduction/FAQ.html b/docs/manual/zh/introduction/FAQ.html index 4f4704f3b67b94..381bd5c4fa1fd2 100644 --- a/docs/manual/zh/introduction/FAQ.html +++ b/docs/manual/zh/introduction/FAQ.html @@ -10,7 +10,7 @@

常见问题([name])

-

哪一种三维物体格式能够得到最好地支持呢?

+

哪一种三维物体格式能够得到最好地支持?

推荐使用glTF(gl传输格式)来对三维物体进行导入和导出,由于glTF这种格式是专注于在程序运行时呈现三维物体的,所以它的传输效率非常高,且加载速度非常快。 @@ -46,8 +46,8 @@

如何在窗口调整大小时保持场景比例不变?

为什么我的物体的一部分是不可见的?

- 这可能是由于面消隐而导致的。面是具有朝向的,这个朝向决定了哪边是正面或者哪边是背面。 - 在正常情况下,渲染时会将背面进行消隐。要查看这是不是你所遇到的问题,请将material的side更改为THREE.DoubleSide。 + 这可能是由于面剔除而导致的。面是具有朝向的,这个朝向决定了哪边是正面或者哪边是背面。 + 在正常情况下,渲染时会将背面进行剔除。要查看这是不是你所遇到的问题,请将material的side更改为THREE.DoubleSide。 material.side = THREE.DoubleSide

From 75d26d61e60ea3ac6ddd8a820f2753a524fc7224 Mon Sep 17 00:00:00 2001 From: gogoend Date: Sun, 16 Dec 2018 19:15:08 +0800 Subject: [PATCH 56/85] Some fixes. --- docs/api/zh/extras/curves/CatmullRomCurve3.html | 2 +- docs/api/zh/extras/curves/CubicBezierCurve.html | 2 +- docs/api/zh/extras/curves/CubicBezierCurve3.html | 2 +- docs/api/zh/extras/curves/QuadraticBezierCurve.html | 2 +- docs/api/zh/extras/curves/QuadraticBezierCurve3.html | 2 +- docs/api/zh/geometries/CircleBufferGeometry.html | 2 +- docs/api/zh/geometries/LatheBufferGeometry.html | 2 +- docs/api/zh/geometries/PlaneBufferGeometry.html | 2 +- docs/api/zh/geometries/SphereGeometry.html | 2 +- docs/api/zh/geometries/TorusGeometry.html | 2 +- docs/api/zh/geometries/TorusKnotBufferGeometry.html | 2 +- docs/api/zh/math/Matrix4.html | 2 +- docs/api/zh/math/Ray.html | 11 +++++------ docs/api/zh/math/Sphere.html | 7 +++---- 14 files changed, 20 insertions(+), 22 deletions(-) diff --git a/docs/api/zh/extras/curves/CatmullRomCurve3.html b/docs/api/zh/extras/curves/CatmullRomCurve3.html index cbfa0c5f708057..e88c715c325c06 100644 --- a/docs/api/zh/extras/curves/CatmullRomCurve3.html +++ b/docs/api/zh/extras/curves/CatmullRomCurve3.html @@ -14,7 +14,7 @@

[name]

使用[link:https://en.wikipedia.org/wiki/Centripetal_Catmull-Rom_spline Catmull-Rom]算法, - 从一系列的点创建一条光滑的三维样条曲线。

+ 从一系列的点创建一条平滑的三维样条曲线。

示例

diff --git a/docs/api/zh/extras/curves/CubicBezierCurve.html b/docs/api/zh/extras/curves/CubicBezierCurve.html index 29680762e37c0c..b3f22b959679f7 100644 --- a/docs/api/zh/extras/curves/CubicBezierCurve.html +++ b/docs/api/zh/extras/curves/CubicBezierCurve.html @@ -13,7 +13,7 @@

二维三次贝塞尔曲线([name])

- 创建一条光滑的二维 + 创建一条平滑的二维 三次贝塞尔曲线, 由起点、终点和两个控制点所定义。

diff --git a/docs/api/zh/extras/curves/CubicBezierCurve3.html b/docs/api/zh/extras/curves/CubicBezierCurve3.html index f6c9c5a4acefe6..293ab9e99fe566 100644 --- a/docs/api/zh/extras/curves/CubicBezierCurve3.html +++ b/docs/api/zh/extras/curves/CubicBezierCurve3.html @@ -13,7 +13,7 @@

三维三次贝塞尔曲线([name])

- 创建一条光滑的三维 + 创建一条平滑的三维 三次贝塞尔曲线, 由起点、终点和两个控制点所定义。

diff --git a/docs/api/zh/extras/curves/QuadraticBezierCurve.html b/docs/api/zh/extras/curves/QuadraticBezierCurve.html index 0356382cfd1bd6..5b940e9276ccc2 100644 --- a/docs/api/zh/extras/curves/QuadraticBezierCurve.html +++ b/docs/api/zh/extras/curves/QuadraticBezierCurve.html @@ -13,7 +13,7 @@

二维二次贝塞尔曲线([name])

- 创建一条光滑的二维 + 创建一条平滑的二维 二次贝塞尔曲线, 由起点、终点和一个控制点所定义。

diff --git a/docs/api/zh/extras/curves/QuadraticBezierCurve3.html b/docs/api/zh/extras/curves/QuadraticBezierCurve3.html index 353ab33ba55e1e..f7424f28e4c4a1 100644 --- a/docs/api/zh/extras/curves/QuadraticBezierCurve3.html +++ b/docs/api/zh/extras/curves/QuadraticBezierCurve3.html @@ -13,7 +13,7 @@

三维二次贝塞尔曲线([name])

- 创建一条光滑的三维 + 创建一条平滑的三维 二次贝塞尔曲线, 由起点、终点和一个控制点所定义。

diff --git a/docs/api/zh/geometries/CircleBufferGeometry.html b/docs/api/zh/geometries/CircleBufferGeometry.html index e225b8c7f1785e..72d3ffca4529b0 100644 --- a/docs/api/zh/geometries/CircleBufferGeometry.html +++ b/docs/api/zh/geometries/CircleBufferGeometry.html @@ -10,7 +10,7 @@ [page:BufferGeometry] → -

圆形缓冲几何体[name]

+

圆形缓冲几何体([name])

这是[page:CircleGeometry]中的[page:BufferGeometry]接口。

diff --git a/docs/api/zh/geometries/LatheBufferGeometry.html b/docs/api/zh/geometries/LatheBufferGeometry.html index 5a461563b3a92e..eeb85d70648056 100644 --- a/docs/api/zh/geometries/LatheBufferGeometry.html +++ b/docs/api/zh/geometries/LatheBufferGeometry.html @@ -10,7 +10,7 @@ [page:BufferGeometry] → -

[name]

+

车削缓冲几何体([name])

这是[page:LatheGeometry]中的[page:BufferGeometry]接口。

diff --git a/docs/api/zh/geometries/PlaneBufferGeometry.html b/docs/api/zh/geometries/PlaneBufferGeometry.html index 22e5799a22b685..02e35c9bb6171a 100644 --- a/docs/api/zh/geometries/PlaneBufferGeometry.html +++ b/docs/api/zh/geometries/PlaneBufferGeometry.html @@ -10,7 +10,7 @@ [page:BufferGeometry] → -

[name]

+

平面缓冲几何体([name])

这是[page:PlaneGeometry]中的[page:BufferGeometry]接口。

diff --git a/docs/api/zh/geometries/SphereGeometry.html b/docs/api/zh/geometries/SphereGeometry.html index 6e4fafef1310c0..a0979aa702799e 100644 --- a/docs/api/zh/geometries/SphereGeometry.html +++ b/docs/api/zh/geometries/SphereGeometry.html @@ -10,7 +10,7 @@ [page:Geometry] → -

球几何体[name]

+

球几何体([name])

一个用于生成球体的类。

diff --git a/docs/api/zh/geometries/TorusGeometry.html b/docs/api/zh/geometries/TorusGeometry.html index 80d84be55df2c3..dfb701922dee51 100644 --- a/docs/api/zh/geometries/TorusGeometry.html +++ b/docs/api/zh/geometries/TorusGeometry.html @@ -10,7 +10,7 @@ [page:Geometry] → -

圆环几何体[name]

+

圆环几何体([name])

一个用于生成圆环几何体的类。

diff --git a/docs/api/zh/geometries/TorusKnotBufferGeometry.html b/docs/api/zh/geometries/TorusKnotBufferGeometry.html index 12e2c596c4ed7e..46b47294f7cac4 100644 --- a/docs/api/zh/geometries/TorusKnotBufferGeometry.html +++ b/docs/api/zh/geometries/TorusKnotBufferGeometry.html @@ -10,7 +10,7 @@ [page:BufferGeometry] → -

[name]

+

圆环缓冲几何体([name])

This is the [page:BufferGeometry] port of [page:TorusKnotGeometry].

diff --git a/docs/api/zh/math/Matrix4.html b/docs/api/zh/math/Matrix4.html index cebdeff10ab4d7..df311392b23219 100644 --- a/docs/api/zh/math/Matrix4.html +++ b/docs/api/zh/math/Matrix4.html @@ -8,7 +8,7 @@ -

四维矩阵([name]

+

四维矩阵([name])

表示为一个 4x4 [link:https://en.wikipedia.org/wiki/Matrix_(mathematics) matrix].

diff --git a/docs/api/zh/math/Ray.html b/docs/api/zh/math/Ray.html index a2d67905fd2579..4808264c5161a8 100644 --- a/docs/api/zh/math/Ray.html +++ b/docs/api/zh/math/Ray.html @@ -67,8 +67,8 @@

[method:Ray clone]()

[method:Vector3 closestPointToPoint]( [param:Vector3 point], [param:Vector3 target] )

- [page:Vector3 point] - the point to get the closest approach to.
- [page:Vector3 target] — the result will be copied into this Vector3.

+ [page:Vector3 point] - 获得距离射线上的点最接近的点。
+ [page:Vector3 target] — 结果将复制到这一Vector3中。

沿着[page:Ray],获得与所传入[page:Vector3]最接近的点。

@@ -107,8 +107,7 @@

[method:Float distanceToPoint]( [param:Vector3 point] )

[page:Vector3 point] - [page:Vector3] 将被用于计算到其距离的[page:Vector3]。

- 获得射线到所传入[page:Vector3 point]之间最接近的距离。 - Get the distance of the closest approach between the [page:Ray] and the [page:Vector3 point]. + 获得[page:Ray](射线)到所传入[page:Vector3 point]之间最接近的距离。

@@ -182,9 +181,9 @@

[method:Ray lookAt]( [param:Vector3 v] )

[method:Ray recast]( [param:Float t] )

- [page:Float t] - The distance along the [page:Ray] to interpolate.

+ [page:Float t] - 沿着[page:Ray]进行插值的距离。

- Shift the origin of this [page:Ray] along its direction by the distance given. + 将[page:Ray](射线)的原点沿着其方向移动给定的距离。

[method:Ray set]( [param:Vector3 origin], [param:Vector3 direction] )

diff --git a/docs/api/zh/math/Sphere.html b/docs/api/zh/math/Sphere.html index 0288e8a0e56a59..fe37fa23638cae 100644 --- a/docs/api/zh/math/Sphere.html +++ b/docs/api/zh/math/Sphere.html @@ -117,11 +117,10 @@

[method:Sphere set]( [param:Vector3 center], [param:Float radius] )

[method:Sphere setFromPoints]( [param:Array points], [param:Vector3 optionalCenter] )

[page:Array points] - 一个包含有[page:Vector3]位置的[page:Array]。
- [page:Vector3 optionalCenter] - 可选, [page:Vector3] position for the sphere's center.

+ [page:Vector3 optionalCenter] - 可选, [page:Vector3] 球心位置。

- Computes the minimum bounding sphere for an array of [page:Array points]. If [page:Vector3 optionalCenter]is given, - it is used as the sphere's center. Otherwise, the center of the axis-aligned bounding box encompassing - [page:Array points] is calculated. + 计算一个[page:Array points]数组(中的点)的最小边界球。如果给定了[page:Vector3 optionalCenter],则它将被用作该球的球心; + 否则,环绕[page:Array points]的包围盒的轴心将通过计算来得到。

[method:Sphere translate]( [param:Vector3 offset] )

From 9e55b92fa1abf75a23558eef253f0373c7bcc7f3 Mon Sep 17 00:00:00 2001 From: gogoend Date: Sun, 16 Dec 2018 23:58:06 +0800 Subject: [PATCH 57/85] Sync with en doc:#15334 Stop telling users how to disable security. https://github.com/mrdoob/three.js/pull/15334 --- .../How-to-run-things-locally.html | 56 ------------------- 1 file changed, 56 deletions(-) diff --git a/docs/manual/zh/introduction/How-to-run-things-locally.html b/docs/manual/zh/introduction/How-to-run-things-locally.html index 3e1168c86fa6d1..585059ae63ab49 100644 --- a/docs/manual/zh/introduction/How-to-run-things-locally.html +++ b/docs/manual/zh/introduction/How-to-run-things-locally.html @@ -117,62 +117,6 @@

Lighttpd

-

更改本地文件的安全策略

-
-

Safari

-
-

- 在“偏好”面板中启用开发菜单,位于“高级”->“在菜单栏中显示开发菜单” -

- -

- 之后从Safari中的“开发”菜单中,选择“停用本地文件限制”,同样需要注意的是,Safari对于缓存有一些奇怪的行为, - 因此建议,在同一菜单中打开“停用缓存”的选项;如果你正在编辑,请使用Safari进行调试。 -

-
- - -

Chrome

-
-

请关闭Chrome浏览器正在运行的*所有*实例,注意这里非常重要的关键字是“*所有*”。

- -

- 在Windows中,你可以在任务管理器中查看所有正在运行的Chorme浏览器的实例。 - 此外,如果你在系统任务栏中看到了Chrome图标,请鼠标右键打开它的上下文菜单,点击关闭。这样就应当已经关闭所有正在运行的Chrome浏览器实例了。 - -

- -

- 然后使用命令行执行Chrome浏览器,并在命令行中添加允许访问本地文件的参数:

- - chrome --allow-file-access-from-files - -

- 在Windows中,最简单的做法或许就是创建一个特别的快捷方式图标,快捷方式的目标指向上面的命令行 - (右键点击快捷方式图标->属性->目标)。 -

- -

在Mac OS X中,你可以用这种方法来添加允许访问本地文件的参数并运行Chrome:

- - open /Applications/Google\ Chrome.app --args --allow-file-access-from-files -
-

Firefox

-
-
    -
  1. - 在地址栏中,键入about:config -
  2. -
  3. - 找到这个参数security.fileuri.strict_origin_policy -
  4. -
  5. - 将其设置为false -
  6. -
-
- -
-

其它简单的替代方案你可以在Stack Overflow上找到:[link:http://stackoverflow.com/q/12905426/24874 click here]。

From 941ca1b473079223315d0bdf30f74c1738e1c45e Mon Sep 17 00:00:00 2001 From: gogoend Date: Mon, 17 Dec 2018 09:31:47 +0800 Subject: [PATCH 58/85] Translate 'TODO' placeholder in Loading-3D-models.html --- .../zh/introduction/Loading-3D-models.html | 45 ++++++++++++++++++- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/docs/manual/zh/introduction/Loading-3D-models.html b/docs/manual/zh/introduction/Loading-3D-models.html index 0f1fbe149c3d28..cd71f094525217 100644 --- a/docs/manual/zh/introduction/Loading-3D-models.html +++ b/docs/manual/zh/introduction/Loading-3D-models.html @@ -67,9 +67,50 @@

推荐的工作流程

当glTF不可用的时候,诸如FBX、OBJ或者COLLADA等等其它广受欢迎的格式在Three.js中也是可以使用、并且定期维护的。

-

Loading

+

加载

-

TODO.

+

+ three.js中默认仅包含了几个加载器(例如:[page:ObjectLoader])——其它加载器需要你分别地添加到页面中。 + 取决于你对构建工具的偏好,选择以下任意一种方式: +

+ + + // global script + <script src="GLTFLoader.js"></script> + + // commonjs + var THREE = window.THREE = require('three'); + require('three/examples/js/loaders/GLTFLoader'); + + +

+ 目前three.js示例不能作为ES modules (import … from '…')来使用。 + 这里讨论了一些解决方法: + #9562. +

+ +

+ 一旦你引入了一个加载器,你就已经准备好为场景添加模型了。不同加载器之间可能具有不同的语法 —— + 当使用其它格式的时候请参阅该格式加载器的示例以及文档。对于glTF,基本用法类似: +

+ + + var loader = new THREE.GLTFLoader(); + + loader.load( 'path/to/model.glb', function ( gltf ) { + + scene.add( gltf.scene ); + + }, undefined, function ( error ) { + + console.error( error ); + + } ); + + +

+ 请参阅[page:GLTFLoader GLTFLoader documentation]来深入了解详细信息。 +

故障排除

From 353697752001a96e14d36c4d0f36d0b99decd03e Mon Sep 17 00:00:00 2001 From: gogoend Date: Mon, 17 Dec 2018 20:51:47 +0800 Subject: [PATCH 59/85] Fix the wrong link. --- docs/manual/en/introduction/Loading-3D-models.html | 2 +- docs/manual/zh/introduction/Loading-3D-models.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/manual/en/introduction/Loading-3D-models.html b/docs/manual/en/introduction/Loading-3D-models.html index aa011a6a1a9f6c..777da207e322ae 100644 --- a/docs/manual/en/introduction/Loading-3D-models.html +++ b/docs/manual/en/introduction/Loading-3D-models.html @@ -97,7 +97,7 @@

Loading

Currently three.js examples are not available as ES modules (import … from '…'). Several workarounds are discussed in - #9562. + #9562.

diff --git a/docs/manual/zh/introduction/Loading-3D-models.html b/docs/manual/zh/introduction/Loading-3D-models.html index cd71f094525217..e09713c9d88342 100644 --- a/docs/manual/zh/introduction/Loading-3D-models.html +++ b/docs/manual/zh/introduction/Loading-3D-models.html @@ -86,7 +86,7 @@

加载

目前three.js示例不能作为ES modules (import … from '…')来使用。 这里讨论了一些解决方法: - #9562. + #9562.

From bda55a3bf0bc3f181b295a1c34997935f8ed7f1e Mon Sep 17 00:00:00 2001 From: Don McCurdy Date: Mon, 17 Dec 2018 07:35:36 -0800 Subject: [PATCH 60/85] Clean up. --- examples/js/loaders/GLTFLoader.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/js/loaders/GLTFLoader.js b/examples/js/loaders/GLTFLoader.js index d329a50d0c2f7f..d011eb7cd52524 100644 --- a/examples/js/loaders/GLTFLoader.js +++ b/examples/js/loaders/GLTFLoader.js @@ -1613,10 +1613,10 @@ THREE.GLTFLoader = ( function () { for ( var i = 0, j = 0; i < count; ++ i ) { - array[ j++ ] = attribute.getX( i ); - if ( itemSize >= 2 ) array[ j++ ] = attribute.getY( i ); - if ( itemSize >= 3 ) array[ j++ ] = attribute.getZ( i ); - if ( itemSize >= 4 ) array[ j++ ] = attribute.getW( i ); + array[ j ++ ] = attribute.getX( i ); + if ( itemSize >= 2 ) array[ j ++ ] = attribute.getY( i ); + if ( itemSize >= 3 ) array[ j ++ ] = attribute.getZ( i ); + if ( itemSize >= 4 ) array[ j ++ ] = attribute.getW( i ); } From 04b78fbd8eeed657cde1c6a4b7d7b525324ea453 Mon Sep 17 00:00:00 2001 From: "Mr.doob" Date: Mon, 17 Dec 2018 14:37:41 -0500 Subject: [PATCH 61/85] PositionalAudio: Clean up. --- src/audio/PositionalAudio.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/audio/PositionalAudio.js b/src/audio/PositionalAudio.js index d933bd4e3a0183..e4926a172f8f30 100644 --- a/src/audio/PositionalAudio.js +++ b/src/audio/PositionalAudio.js @@ -106,11 +106,12 @@ PositionalAudio.prototype = Object.assign( Object.create( Audio.prototype ), { if ( this.isPlaying === false ) return; - var panner = this.panner; this.matrixWorld.decompose( position, quaternion, scale ); orientation.set( 0, 0, 1 ).applyQuaternion( quaternion ); + var panner = this.panner; + if ( panner.positionX ) { // code path for Chrome and Firefox (see #14393) From b44437a5fae191b1dba87e3a9fd58ceebc7be068 Mon Sep 17 00:00:00 2001 From: "Mr.doob" Date: Mon, 17 Dec 2018 14:39:16 -0500 Subject: [PATCH 62/85] SVGLoader: Clean up. --- examples/js/loaders/SVGLoader.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/examples/js/loaders/SVGLoader.js b/examples/js/loaders/SVGLoader.js index 809c4d94d0a8ae..31fc4353269ce3 100644 --- a/examples/js/loaders/SVGLoader.js +++ b/examples/js/loaders/SVGLoader.js @@ -143,10 +143,10 @@ THREE.SVGLoader.prototype = { var type = command.charAt( 0 ); var data = command.substr( 1 ).trim(); - if ( isFirstPoint ) { + if ( isFirstPoint === true ) { doSetFirstPoint = true; + isFirstPoint = false; } - isFirstPoint = false; switch ( type ) { @@ -432,13 +432,11 @@ THREE.SVGLoader.prototype = { // console.log( type, parseFloats( data ), parseFloats( data ).length ) - if ( doSetFirstPoint ) { - + if ( doSetFirstPoint === true ) { firstPoint.copy( point ); - doSetFirstPoint = false; - } + } return path; @@ -759,7 +757,7 @@ THREE.SVGLoader.prototype = { var transform = new THREE.Matrix3(); var currentTransform = tempTransform0; var transformsTexts = node.getAttribute( 'transform' ).split( ' ' ); - + for ( var tIndex = transformsTexts.length - 1; tIndex >= 0; tIndex-- ) { var transformText = transformsTexts[ tIndex ]; @@ -771,7 +769,7 @@ THREE.SVGLoader.prototype = { var transformType = transformText.substr( 0, openParPos ); var array = parseFloats( transformText.substr( openParPos + 1, closeParPos - openParPos - 1 ) ); - + currentTransform.identity(); switch ( transformType ) { From 67a793ac1666746bde643cfb1934a0fb588e1014 Mon Sep 17 00:00:00 2001 From: Takahiro Date: Tue, 18 Dec 2018 10:19:11 +0900 Subject: [PATCH 63/85] Null uniform value serialization. --- src/materials/ShaderMaterial.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/materials/ShaderMaterial.js b/src/materials/ShaderMaterial.js index 456c0ef5f4c58a..4c1609fe7e1750 100644 --- a/src/materials/ShaderMaterial.js +++ b/src/materials/ShaderMaterial.js @@ -123,42 +123,42 @@ ShaderMaterial.prototype.toJSON = function ( meta ) { var uniform = this.uniforms[ name ]; var value = uniform.value; - if ( value.isTexture ) { + if ( value && value.isTexture ) { data.uniforms[ name ] = { type: 't', value: value.toJSON( meta ).uuid }; - } else if ( value.isColor ) { + } else if ( value && value.isColor ) { data.uniforms[ name ] = { type: 'c', value: value.getHex() }; - } else if ( value.isVector2 ) { + } else if ( value && value.isVector2 ) { data.uniforms[ name ] = { type: 'v2', value: value.toArray() }; - } else if ( value.isVector3 ) { + } else if ( value && value.isVector3 ) { data.uniforms[ name ] = { type: 'v3', value: value.toArray() }; - } else if ( value.isVector4 ) { + } else if ( value && value.isVector4 ) { data.uniforms[ name ] = { type: 'v4', value: value.toArray() }; - } else if ( value.isMatrix4 ) { + } else if ( value && value.isMatrix4 ) { data.uniforms[ name ] = { type: 'm4', From 1bb18eb508323b80fe1c5b64265e7d6594167fff Mon Sep 17 00:00:00 2001 From: "Mr.doob" Date: Tue, 18 Dec 2018 11:48:08 -0500 Subject: [PATCH 64/85] MTLLoader: Clean up. --- examples/js/loaders/MTLLoader.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/js/loaders/MTLLoader.js b/examples/js/loaders/MTLLoader.js index bc4e5c25ff18d2..50de5b93665ef5 100644 --- a/examples/js/loaders/MTLLoader.js +++ b/examples/js/loaders/MTLLoader.js @@ -149,7 +149,7 @@ THREE.MTLLoader.prototype = { } else { - if ( key === 'ka' || key === 'kd' || key === 'ks'|| key ==='ke') { + if ( key === 'ka' || key === 'kd' || key === 'ks' || key ==='ke' ) { var ss = value.split( delimiter_pattern, 3 ); info[ key ] = [ parseFloat( ss[ 0 ] ), parseFloat( ss[ 1 ] ), parseFloat( ss[ 2 ] ) ]; From 7aa204e349d997f957b5f3cf1d7a8c62f3bd6068 Mon Sep 17 00:00:00 2001 From: Mugen87 Date: Wed, 19 Dec 2018 11:42:48 +0100 Subject: [PATCH 65/85] Examples: Removed THREE.Octree --- docs/api/en/core/Raycaster.html | 1 - docs/api/zh/core/Raycaster.html | 3 +- examples/files.js | 2 - examples/js/Octree.js | 2143 ------------------------- examples/webgl_octree.html | 250 --- examples/webgl_octree_raycasting.html | 360 ----- 6 files changed, 1 insertion(+), 2758 deletions(-) delete mode 100644 examples/js/Octree.js delete mode 100644 examples/webgl_octree.html delete mode 100644 examples/webgl_octree_raycasting.html diff --git a/docs/api/en/core/Raycaster.html b/docs/api/en/core/Raycaster.html index da504c11ada75c..5ece3207a79160 100644 --- a/docs/api/en/core/Raycaster.html +++ b/docs/api/en/core/Raycaster.html @@ -61,7 +61,6 @@

Example

[example:webgl_interactive_lines Raycasting to a Line]
[example:webgl_interactive_raycasting_points Raycasting to Points]
[example:webgl_geometry_terrain_raycast Terrain raycasting]
- [example:webgl_octree_raycasting Raycasting using an octree]
[example:webgl_interactive_voxelpainter Raycasting to paint voxels]
[example:webgl_raycast_texture Raycast to a Texture]
diff --git a/docs/api/zh/core/Raycaster.html b/docs/api/zh/core/Raycaster.html index 05814dc7cba353..3b15861eba7bf3 100644 --- a/docs/api/zh/core/Raycaster.html +++ b/docs/api/zh/core/Raycaster.html @@ -59,7 +59,6 @@

示例

[example:webgl_interactive_lines Raycasting to a Line]
[example:webgl_interactive_raycasting_points Raycasting to Points]
[example:webgl_geometry_terrain_raycast Terrain raycasting]
- [example:webgl_octree_raycasting Raycasting using an octree]
[example:webgl_interactive_voxelpainter Raycasting to paint voxels]
[example:webgl_raycast_texture Raycast to a Texture]
@@ -136,7 +135,7 @@

[method:null set]( [param:Vector3 origin], [param:Vector3 direction] )

[method:null setFromCamera]( [param:Vector2 coords], [param:Camera camera] )

[page:Vector2 coords] —— 在标准化设备坐标中鼠标的二维坐标 —— X分量与Y分量应当在-1到1之间。
- + [page:Camera camera] —— 射线所来源的摄像机。

diff --git a/examples/files.js b/examples/files.js index d3f8f88e15f11b..12619856517d81 100644 --- a/examples/files.js +++ b/examples/files.js @@ -198,8 +198,6 @@ var files = { "webgl_multiple_scenes_comparison", "webgl_multiple_views", "webgl_nearestneighbour", - "webgl_octree", - "webgl_octree_raycasting", "webgl_panorama_cube", "webgl_panorama_dualfisheye", "webgl_panorama_equirectangular", diff --git a/examples/js/Octree.js b/examples/js/Octree.js deleted file mode 100644 index fdcaae72669e0e..00000000000000 --- a/examples/js/Octree.js +++ /dev/null @@ -1,2143 +0,0 @@ -/*! - * - * threeoctree.js (r60) / https://github.com/collinhover/threeoctree - * (sparse) dynamic 3D spatial representation structure for fast searches. - * - * @author Collin Hover / http://collinhover.com/ - * based on Dynamic Octree by Piko3D @ http://www.piko3d.com/ and Octree by Marek Pawlowski @ pawlowski.it - * - */ -( function ( THREE ) { - - "use strict"; - - /*=================================================== - - utility - - =====================================================*/ - - function isNumber( n ) { - - return ! isNaN( n ) && isFinite( n ); - - } - - function isArray( target ) { - - return Object.prototype.toString.call( target ) === '[object Array]'; - - } - - function toArray( target ) { - - return target ? ( isArray( target ) !== true ? [ target ] : target ) : []; - - } - - function indexOfValue( array, value ) { - - for ( var i = 0, il = array.length; i < il; i ++ ) { - - if ( array[ i ] === value ) { - - return i; - - } - - } - - return - 1; - - } - - function indexOfPropertyWithValue( array, property, value ) { - - for ( var i = 0, il = array.length; i < il; i ++ ) { - - if ( array[ i ][ property ] === value ) { - - return i; - - } - - } - - return - 1; - - } - - /*=================================================== - - octree - - =====================================================*/ - - THREE.Octree = function ( parameters ) { - - // handle parameters - - parameters = parameters || {}; - - parameters.tree = this; - - // static properties ( modification is not recommended ) - - this.nodeCount = 0; - - this.INDEX_INSIDE_CROSS = - 1; - this.INDEX_OUTSIDE_OFFSET = 2; - - this.INDEX_OUTSIDE_POS_X = isNumber( parameters.INDEX_OUTSIDE_POS_X ) ? parameters.INDEX_OUTSIDE_POS_X : 0; - this.INDEX_OUTSIDE_NEG_X = isNumber( parameters.INDEX_OUTSIDE_NEG_X ) ? parameters.INDEX_OUTSIDE_NEG_X : 1; - this.INDEX_OUTSIDE_POS_Y = isNumber( parameters.INDEX_OUTSIDE_POS_Y ) ? parameters.INDEX_OUTSIDE_POS_Y : 2; - this.INDEX_OUTSIDE_NEG_Y = isNumber( parameters.INDEX_OUTSIDE_NEG_Y ) ? parameters.INDEX_OUTSIDE_NEG_Y : 3; - this.INDEX_OUTSIDE_POS_Z = isNumber( parameters.INDEX_OUTSIDE_POS_Z ) ? parameters.INDEX_OUTSIDE_POS_Z : 4; - this.INDEX_OUTSIDE_NEG_Z = isNumber( parameters.INDEX_OUTSIDE_NEG_Z ) ? parameters.INDEX_OUTSIDE_NEG_Z : 5; - - this.INDEX_OUTSIDE_MAP = []; - this.INDEX_OUTSIDE_MAP[ this.INDEX_OUTSIDE_POS_X ] = { index: this.INDEX_OUTSIDE_POS_X, count: 0, x: 1, y: 0, z: 0 }; - this.INDEX_OUTSIDE_MAP[ this.INDEX_OUTSIDE_NEG_X ] = { index: this.INDEX_OUTSIDE_NEG_X, count: 0, x: - 1, y: 0, z: 0 }; - this.INDEX_OUTSIDE_MAP[ this.INDEX_OUTSIDE_POS_Y ] = { index: this.INDEX_OUTSIDE_POS_Y, count: 0, x: 0, y: 1, z: 0 }; - this.INDEX_OUTSIDE_MAP[ this.INDEX_OUTSIDE_NEG_Y ] = { index: this.INDEX_OUTSIDE_NEG_Y, count: 0, x: 0, y: - 1, z: 0 }; - this.INDEX_OUTSIDE_MAP[ this.INDEX_OUTSIDE_POS_Z ] = { index: this.INDEX_OUTSIDE_POS_Z, count: 0, x: 0, y: 0, z: 1 }; - this.INDEX_OUTSIDE_MAP[ this.INDEX_OUTSIDE_NEG_Z ] = { index: this.INDEX_OUTSIDE_NEG_Z, count: 0, x: 0, y: 0, z: - 1 }; - - this.FLAG_POS_X = 1 << ( this.INDEX_OUTSIDE_POS_X + 1 ); - this.FLAG_NEG_X = 1 << ( this.INDEX_OUTSIDE_NEG_X + 1 ); - this.FLAG_POS_Y = 1 << ( this.INDEX_OUTSIDE_POS_Y + 1 ); - this.FLAG_NEG_Y = 1 << ( this.INDEX_OUTSIDE_NEG_Y + 1 ); - this.FLAG_POS_Z = 1 << ( this.INDEX_OUTSIDE_POS_Z + 1 ); - this.FLAG_NEG_Z = 1 << ( this.INDEX_OUTSIDE_NEG_Z + 1 ); - - this.utilVec31Search = new THREE.Vector3(); - this.utilVec32Search = new THREE.Vector3(); - - // pass scene to see octree structure - - this.scene = parameters.scene; - - if ( this.scene ) { - - var helper = new THREE.BoxHelper( new THREE.Mesh( new THREE.BoxBufferGeometry( 1, 1, 1 ) ), 0xff0066 ); - this.visualGeometry = helper.geometry; - this.visualMaterial = helper.material; - - } - - // properties - - this.objects = []; - this.objectsMap = {}; - this.objectsData = []; - this.objectsDeferred = []; - - this.depthMax = isNumber( parameters.depthMax ) ? parameters.depthMax : Infinity; - this.objectsThreshold = isNumber( parameters.objectsThreshold ) ? parameters.objectsThreshold : 8; - this.overlapPct = isNumber( parameters.overlapPct ) ? parameters.overlapPct : 0.15; - this.undeferred = parameters.undeferred || false; - - this.root = parameters.root instanceof THREE.OctreeNode ? parameters.root : new THREE.OctreeNode( parameters ); - - }; - - THREE.Octree.prototype = { - - update: function () { - - // add any deferred objects that were waiting for render cycle - - if ( this.objectsDeferred.length > 0 ) { - - for ( var i = 0, il = this.objectsDeferred.length; i < il; i ++ ) { - - var deferred = this.objectsDeferred[ i ]; - - this.addDeferred( deferred.object, deferred.options ); - - } - - this.objectsDeferred.length = 0; - - } - - }, - - add: function ( object, options ) { - - // add immediately - - if ( this.undeferred ) { - - this.updateObject( object ); - - this.addDeferred( object, options ); - - } else { - - // defer add until update called - - this.objectsDeferred.push( { object: object, options: options } ); - - } - - }, - - addDeferred: function ( object, options ) { - - var i, l, - geometry, - faces, - useFaces, - vertices, - useVertices, - objectData; - - // ensure object is not object data - - if ( object instanceof THREE.OctreeObjectData ) { - - object = object.object; - - } - - // check uuid to avoid duplicates - - if ( ! object.uuid ) { - - object.uuid = THREE.Math.generateUUID(); - - } - - if ( ! this.objectsMap[ object.uuid ] ) { - - // store - - this.objects.push( object ); - this.objectsMap[ object.uuid ] = object; - - // check options - - if ( options ) { - - useFaces = options.useFaces; - useVertices = options.useVertices; - - } - - if ( useVertices === true ) { - - geometry = object.geometry; - vertices = geometry.vertices; - - for ( i = 0, l = vertices.length; i < l; i ++ ) { - - this.addObjectData( object, vertices[ i ] ); - - } - - } else if ( useFaces === true ) { - - geometry = object.geometry; - faces = geometry.faces; - - for ( i = 0, l = faces.length; i < l; i ++ ) { - - this.addObjectData( object, faces[ i ] ); - - } - - } else { - - this.addObjectData( object ); - - } - - } - - }, - - addObjectData: function ( object, part ) { - - var objectData = new THREE.OctreeObjectData( object, part ); - - // add to tree objects data list - - this.objectsData.push( objectData ); - - // add to nodes - - this.root.addObject( objectData ); - - }, - - remove: function ( object ) { - - var i, l, - objectData = object, - index, - objectsDataRemoved; - - // ensure object is not object data for index search - - if ( object instanceof THREE.OctreeObjectData ) { - - object = object.object; - - } - - // check uuid - - if ( this.objectsMap[ object.uuid ] ) { - - this.objectsMap[ object.uuid ] = undefined; - - // check and remove from objects, nodes, and data lists - - index = indexOfValue( this.objects, object ); - - if ( index !== - 1 ) { - - this.objects.splice( index, 1 ); - - // remove from nodes - - objectsDataRemoved = this.root.removeObject( objectData ); - - // remove from objects data list - - for ( i = 0, l = objectsDataRemoved.length; i < l; i ++ ) { - - objectData = objectsDataRemoved[ i ]; - - index = indexOfValue( this.objectsData, objectData ); - - if ( index !== - 1 ) { - - this.objectsData.splice( index, 1 ); - - } - - } - - } - - } else if ( this.objectsDeferred.length > 0 ) { - - // check and remove from deferred - - index = indexOfPropertyWithValue( this.objectsDeferred, 'object', object ); - - if ( index !== - 1 ) { - - this.objectsDeferred.splice( index, 1 ); - - } - - } - - }, - - extend: function ( octree ) { - - var i, l, - objectsData, - objectData; - - if ( octree instanceof THREE.Octree ) { - - // for each object data - - objectsData = octree.objectsData; - - for ( i = 0, l = objectsData.length; i < l; i ++ ) { - - objectData = objectsData[ i ]; - - this.add( objectData, { useFaces: objectData.faces, useVertices: objectData.vertices } ); - - } - - } - - }, - - rebuild: function () { - - var i, l, - node, - object, - objectData, - indexOctant, - indexOctantLast, - objectsUpdate = []; - - // check all object data for changes in position - // assumes all object matrices are up to date - - for ( i = 0, l = this.objectsData.length; i < l; i ++ ) { - - objectData = this.objectsData[ i ]; - - node = objectData.node; - - // update object - - objectData.update(); - - // if position has changed since last organization of object in tree - - if ( node instanceof THREE.OctreeNode && ! objectData.positionLast.equals( objectData.position ) ) { - - // get octant index of object within current node - - indexOctantLast = objectData.indexOctant; - - indexOctant = node.getOctantIndex( objectData ); - - // if object octant index has changed - - if ( indexOctant !== indexOctantLast ) { - - // add to update list - - objectsUpdate.push( objectData ); - - } - - } - - } - - // update changed objects - - for ( i = 0, l = objectsUpdate.length; i < l; i ++ ) { - - objectData = objectsUpdate[ i ]; - - // remove object from current node - - objectData.node.removeObject( objectData ); - - // add object to tree root - - this.root.addObject( objectData ); - - } - - }, - - updateObject: function ( object ) { - - var i, l, - parentCascade = [ object ], - parent, - parentUpdate; - - // search all parents between object and root for world matrix update - - parent = object.parent; - - while ( parent ) { - - parentCascade.push( parent ); - parent = parent.parent; - - } - - for ( i = 0, l = parentCascade.length; i < l; i ++ ) { - - parent = parentCascade[ i ]; - - if ( parent.matrixWorldNeedsUpdate === true ) { - - parentUpdate = parent; - - } - - } - - // update world matrix starting at uppermost parent that needs update - - if ( typeof parentUpdate !== 'undefined' ) { - - parentUpdate.updateMatrixWorld(); - - } - - }, - - search: function ( position, radius, organizeByObject, direction ) { - - var i, l, - node, - objects, - objectData, - object, - results, - resultData, - resultsObjectsIndices, - resultObjectIndex, - directionPct; - - // add root objects - - objects = [].concat( this.root.objects ); - - // ensure radius (i.e. distance of ray) is a number - - if ( ! ( radius > 0 ) ) { - - radius = Number.MAX_VALUE; - - } - - // if direction passed, normalize and find pct - - if ( direction instanceof THREE.Vector3 ) { - - direction = this.utilVec31Search.copy( direction ).normalize(); - directionPct = this.utilVec32Search.set( 1, 1, 1 ).divide( direction ); - - } - - // search each node of root - - for ( i = 0, l = this.root.nodesIndices.length; i < l; i ++ ) { - - node = this.root.nodesByIndex[ this.root.nodesIndices[ i ] ]; - - objects = node.search( position, radius, objects, direction, directionPct ); - - } - - // if should organize results by object - - if ( organizeByObject === true ) { - - results = []; - resultsObjectsIndices = []; - - // for each object data found - - for ( i = 0, l = objects.length; i < l; i ++ ) { - - objectData = objects[ i ]; - object = objectData.object; - - resultObjectIndex = indexOfValue( resultsObjectsIndices, object ); - - // if needed, create new result data - - if ( resultObjectIndex === - 1 ) { - - resultData = { - object: object, - faces: [], - vertices: [] - }; - - results.push( resultData ); - - resultsObjectsIndices.push( object ); - - } else { - - resultData = results[ resultObjectIndex ]; - - } - - // object data has faces or vertices, add to list - - if ( objectData.faces ) { - - resultData.faces.push( objectData.faces ); - - } else if ( objectData.vertices ) { - - resultData.vertices.push( objectData.vertices ); - - } - - } - - } else { - - results = objects; - - } - - return results; - - }, - - setRoot: function ( root ) { - - if ( root instanceof THREE.OctreeNode ) { - - // store new root - - this.root = root; - - // update properties - - this.root.updateProperties(); - - } - - }, - - getDepthEnd: function () { - - return this.root.getDepthEnd(); - - }, - - getNodeCountEnd: function () { - - return this.root.getNodeCountEnd(); - - }, - - getObjectCountEnd: function () { - - return this.root.getObjectCountEnd(); - - }, - - toConsole: function () { - - this.root.toConsole(); - - } - - }; - - /*=================================================== - - object data - - =====================================================*/ - - THREE.OctreeObjectData = function ( object, part ) { - - // properties - - this.object = object; - - // handle part by type - - if ( part instanceof THREE.Face3 ) { - - this.faces = part; - this.face3 = true; - this.utilVec31FaceBounds = new THREE.Vector3(); - - } else if ( part instanceof THREE.Vector3 ) { - - this.vertices = part; - - } - - this.radius = 0; - this.position = new THREE.Vector3(); - - // initial update - - if ( this.object instanceof THREE.Object3D ) { - - this.update(); - - } - - this.positionLast = this.position.clone(); - - }; - - THREE.OctreeObjectData.prototype = { - - update: function () { - - if ( this.face3 ) { - - this.radius = this.getFace3BoundingRadius( this.object, this.faces ); - this.position.copy( this.faces.centroid ).applyMatrix4( this.object.matrixWorld ); - - } else if ( this.vertices ) { - - this.radius = this.object.material.size || 1; - this.position.copy( this.vertices ).applyMatrix4( this.object.matrixWorld ); - - } else { - - if ( this.object.geometry ) { - - if ( this.object.geometry.boundingSphere === null ) { - - this.object.geometry.computeBoundingSphere(); - - } - - this.radius = this.object.geometry.boundingSphere.radius; - this.position.copy( this.object.geometry.boundingSphere.center ).applyMatrix4( this.object.matrixWorld ); - - } else { - - this.radius = this.object.boundRadius; - this.position.setFromMatrixPosition( this.object.matrixWorld ); - - } - - } - - this.radius = this.radius * Math.max( this.object.scale.x, this.object.scale.y, this.object.scale.z ); - - }, - - getFace3BoundingRadius: function ( object, face ) { - - if ( face.centroid === undefined ) face.centroid = new THREE.Vector3(); - - var geometry = object.geometry || object, - vertices = geometry.vertices, - centroid = face.centroid, - va = vertices[ face.a ], vb = vertices[ face.b ], vc = vertices[ face.c ], - centroidToVert = this.utilVec31FaceBounds, - radius; - - centroid.addVectors( va, vb ).add( vc ).divideScalar( 3 ); - radius = Math.max( centroidToVert.subVectors( centroid, va ).length(), centroidToVert.subVectors( centroid, vb ).length(), centroidToVert.subVectors( centroid, vc ).length() ); - - return radius; - - } - - }; - - /*=================================================== - - node - - =====================================================*/ - - THREE.OctreeNode = function ( parameters ) { - - // utility - - this.utilVec31Branch = new THREE.Vector3(); - this.utilVec31Expand = new THREE.Vector3(); - this.utilVec31Ray = new THREE.Vector3(); - - // handle parameters - - parameters = parameters || {}; - - // store or create tree - - if ( parameters.tree instanceof THREE.Octree ) { - - this.tree = parameters.tree; - - } else if ( parameters.parent instanceof THREE.OctreeNode !== true ) { - - parameters.root = this; - - this.tree = new THREE.Octree( parameters ); - - } - - // basic properties - - this.id = this.tree.nodeCount ++; - this.position = parameters.position instanceof THREE.Vector3 ? parameters.position : new THREE.Vector3(); - this.radius = parameters.radius > 0 ? parameters.radius : 1; - this.indexOctant = parameters.indexOctant; - this.depth = 0; - - // reset and assign parent - - this.reset(); - this.setParent( parameters.parent ); - - // additional properties - - this.overlap = this.radius * this.tree.overlapPct; - this.radiusOverlap = this.radius + this.overlap; - this.left = this.position.x - this.radiusOverlap; - this.right = this.position.x + this.radiusOverlap; - this.bottom = this.position.y - this.radiusOverlap; - this.top = this.position.y + this.radiusOverlap; - this.back = this.position.z - this.radiusOverlap; - this.front = this.position.z + this.radiusOverlap; - - // visual - - if ( this.tree.scene ) { - - this.visual = new THREE.LineSegments( this.tree.visualGeometry, this.tree.visualMaterial ); - this.visual.scale.set( this.radiusOverlap * 2, this.radiusOverlap * 2, this.radiusOverlap * 2 ); - this.visual.position.copy( this.position ); - this.tree.scene.add( this.visual ); - - } - - }; - - THREE.OctreeNode.prototype = { - - setParent: function ( parent ) { - - // store new parent - - if ( parent !== this && this.parent !== parent ) { - - this.parent = parent; - - // update properties - - this.updateProperties(); - - } - - }, - - updateProperties: function () { - - var i, l; - - // properties - - if ( this.parent instanceof THREE.OctreeNode ) { - - this.tree = this.parent.tree; - this.depth = this.parent.depth + 1; - - } else { - - this.depth = 0; - - } - - // cascade - - for ( i = 0, l = this.nodesIndices.length; i < l; i ++ ) { - - this.nodesByIndex[ this.nodesIndices[ i ] ].updateProperties(); - - } - - }, - - reset: function ( cascade, removeVisual ) { - - var i, l, - node, - nodesIndices = this.nodesIndices || [], - nodesByIndex = this.nodesByIndex; - - this.objects = []; - this.nodesIndices = []; - this.nodesByIndex = {}; - - // unset parent in nodes - - for ( i = 0, l = nodesIndices.length; i < l; i ++ ) { - - node = nodesByIndex[ nodesIndices[ i ] ]; - - node.setParent( undefined ); - - if ( cascade === true ) { - - node.reset( cascade, removeVisual ); - - } - - } - - // visual - - if ( removeVisual === true && this.visual && this.visual.parent ) { - - this.visual.parent.remove( this.visual ); - - } - - }, - - addNode: function ( node, indexOctant ) { - - node.indexOctant = indexOctant; - - if ( indexOfValue( this.nodesIndices, indexOctant ) === - 1 ) { - - this.nodesIndices.push( indexOctant ); - - } - - this.nodesByIndex[ indexOctant ] = node; - - if ( node.parent !== this ) { - - node.setParent( this ); - - } - - }, - - removeNode: function ( indexOctant ) { - - var index, - node; - - index = indexOfValue( this.nodesIndices, indexOctant ); - - this.nodesIndices.splice( index, 1 ); - - node = node || this.nodesByIndex[ indexOctant ]; - - delete this.nodesByIndex[ indexOctant ]; - - if ( node.parent === this ) { - - node.setParent( undefined ); - - } - - }, - - addObject: function ( object ) { - - var index, - indexOctant, - node; - - // get object octant index - - indexOctant = this.getOctantIndex( object ); - - // if object fully contained by an octant, add to subtree - if ( indexOctant > - 1 && this.nodesIndices.length > 0 ) { - - node = this.branch( indexOctant ); - - node.addObject( object ); - - } else if ( indexOctant < - 1 && this.parent instanceof THREE.OctreeNode ) { - - // if object lies outside bounds, add to parent node - - this.parent.addObject( object ); - - } else { - - // add to this objects list - - index = indexOfValue( this.objects, object ); - - if ( index === - 1 ) { - - this.objects.push( object ); - - } - - // node reference - - object.node = this; - - // check if need to expand, split, or both - - this.checkGrow(); - - } - - }, - - addObjectWithoutCheck: function ( objects ) { - - var i, l, - object; - - for ( i = 0, l = objects.length; i < l; i ++ ) { - - object = objects[ i ]; - - this.objects.push( object ); - - object.node = this; - - } - - }, - - removeObject: function ( object ) { - - var i, l, - nodesRemovedFrom, - removeData; - - // cascade through tree to find and remove object - - removeData = this.removeObjectRecursive( object, { searchComplete: false, nodesRemovedFrom: [], objectsDataRemoved: [] } ); - - // if object removed, try to shrink the nodes it was removed from - - nodesRemovedFrom = removeData.nodesRemovedFrom; - - if ( nodesRemovedFrom.length > 0 ) { - - for ( i = 0, l = nodesRemovedFrom.length; i < l; i ++ ) { - - nodesRemovedFrom[ i ].shrink(); - - } - - } - - return removeData.objectsDataRemoved; - - }, - - removeObjectRecursive: function ( object, removeData ) { - - var i, l, - index = - 1, - objectData, - node, - objectRemoved; - - // find index of object in objects list - - // search and remove object data (fast) - if ( object instanceof THREE.OctreeObjectData ) { - - // remove from this objects list - - index = indexOfValue( this.objects, object ); - - if ( index !== - 1 ) { - - this.objects.splice( index, 1 ); - object.node = undefined; - - removeData.objectsDataRemoved.push( object ); - - removeData.searchComplete = objectRemoved = true; - - } - - } else { - - // search each object data for object and remove (slow) - - for ( i = this.objects.length - 1; i >= 0; i -- ) { - - objectData = this.objects[ i ]; - - if ( objectData.object === object ) { - - this.objects.splice( i, 1 ); - objectData.node = undefined; - - removeData.objectsDataRemoved.push( objectData ); - - objectRemoved = true; - - if ( ! objectData.faces && ! objectData.vertices ) { - - removeData.searchComplete = true; - break; - - } - - } - - } - - } - - // if object data removed and this is not on nodes removed from - - if ( objectRemoved === true ) { - - removeData.nodesRemovedFrom.push( this ); - - } - - // if search not complete, search nodes - - if ( removeData.searchComplete !== true ) { - - for ( i = 0, l = this.nodesIndices.length; i < l; i ++ ) { - - node = this.nodesByIndex[ this.nodesIndices[ i ] ]; - - // try removing object from node - - removeData = node.removeObjectRecursive( object, removeData ); - - if ( removeData.searchComplete === true ) { - - break; - - } - - } - - } - - return removeData; - - }, - - checkGrow: function () { - - // if object count above max - - if ( this.objects.length > this.tree.objectsThreshold && this.tree.objectsThreshold > 0 ) { - - this.grow(); - - } - - }, - - grow: function () { - - var indexOctant, - object, - objectsExpand = [], - objectsExpandOctants = [], - objectsSplit = [], - objectsSplitOctants = [], - objectsRemaining = [], - i, l; - - // for each object - - for ( i = 0, l = this.objects.length; i < l; i ++ ) { - - object = this.objects[ i ]; - - // get object octant index - - indexOctant = this.getOctantIndex( object ); - - // if lies within octant - if ( indexOctant > - 1 ) { - - objectsSplit.push( object ); - objectsSplitOctants.push( indexOctant ); - - } else if ( indexOctant < - 1 ) { - - // lies outside radius - - objectsExpand.push( object ); - objectsExpandOctants.push( indexOctant ); - - } else { - - // lies across bounds between octants - - objectsRemaining.push( object ); - - } - - } - - // if has objects to split - - if ( objectsSplit.length > 0 ) { - - objectsRemaining = objectsRemaining.concat( this.split( objectsSplit, objectsSplitOctants ) ); - - } - - // if has objects to expand - - if ( objectsExpand.length > 0 ) { - - objectsRemaining = objectsRemaining.concat( this.expand( objectsExpand, objectsExpandOctants ) ); - - } - - // store remaining - - this.objects = objectsRemaining; - - // merge check - - this.checkMerge(); - - }, - - split: function ( objects, octants ) { - - var i, l, - indexOctant, - object, - node, - objectsRemaining; - - // if not at max depth - - if ( this.depth < this.tree.depthMax ) { - - objects = objects || this.objects; - - octants = octants || []; - - objectsRemaining = []; - - // for each object - - for ( i = 0, l = objects.length; i < l; i ++ ) { - - object = objects[ i ]; - - // get object octant index - - indexOctant = octants[ i ]; - - // if object contained by octant, branch this tree - - if ( indexOctant > - 1 ) { - - node = this.branch( indexOctant ); - - node.addObject( object ); - - } else { - - objectsRemaining.push( object ); - - } - - } - - // if all objects, set remaining as new objects - - if ( objects === this.objects ) { - - this.objects = objectsRemaining; - - } - - } else { - - objectsRemaining = this.objects; - - } - - return objectsRemaining; - - }, - - branch: function ( indexOctant ) { - - var node, - overlap, - radius, - radiusOffset, - offset, - position; - - // node exists - - if ( this.nodesByIndex[ indexOctant ] instanceof THREE.OctreeNode ) { - - node = this.nodesByIndex[ indexOctant ]; - - } else { - - // properties - - radius = ( this.radiusOverlap ) * 0.5; - overlap = radius * this.tree.overlapPct; - radiusOffset = radius - overlap; - offset = this.utilVec31Branch.set( indexOctant & 1 ? radiusOffset : - radiusOffset, indexOctant & 2 ? radiusOffset : - radiusOffset, indexOctant & 4 ? radiusOffset : - radiusOffset ); - position = new THREE.Vector3().addVectors( this.position, offset ); - - // node - - node = new THREE.OctreeNode( { - tree: this.tree, - parent: this, - position: position, - radius: radius, - indexOctant: indexOctant - } ); - - // store - - this.addNode( node, indexOctant ); - - } - - return node; - - }, - - expand: function ( objects, octants ) { - - var i, l, - object, - objectsRemaining, - objectsExpand, - indexOctant, - flagsOutside, - indexOutside, - indexOctantInverse, - iom = this.tree.INDEX_OUTSIDE_MAP, - indexOutsideCounts, - infoIndexOutside1, - infoIndexOutside2, - infoIndexOutside3, - indexOutsideBitwise1, - indexOutsideBitwise2, - infoPotential1, - infoPotential2, - infoPotential3, - indexPotentialBitwise1, - indexPotentialBitwise2, - octantX, octantY, octantZ, - overlap, - radius, - radiusOffset, - radiusParent, - overlapParent, - offset = this.utilVec31Expand, - position, - parent; - - // handle max depth down tree - - if ( this.tree.root.getDepthEnd() < this.tree.depthMax ) { - - objects = objects || this.objects; - octants = octants || []; - - objectsRemaining = []; - objectsExpand = []; - - // reset counts - - for ( i = 0, l = iom.length; i < l; i ++ ) { - - iom[ i ].count = 0; - - } - - // for all outside objects, find outside octants containing most objects - - for ( i = 0, l = objects.length; i < l; i ++ ) { - - object = objects[ i ]; - - // get object octant index - - indexOctant = octants[ i ]; - - // if object outside this, include in calculations - - if ( indexOctant < - 1 ) { - - // convert octant index to outside flags - - flagsOutside = - indexOctant - this.tree.INDEX_OUTSIDE_OFFSET; - - // check against bitwise flags - - // x - - if ( flagsOutside & this.tree.FLAG_POS_X ) { - - iom[ this.tree.INDEX_OUTSIDE_POS_X ].count ++; - - } else if ( flagsOutside & this.tree.FLAG_NEG_X ) { - - iom[ this.tree.INDEX_OUTSIDE_NEG_X ].count ++; - - } - - // y - - if ( flagsOutside & this.tree.FLAG_POS_Y ) { - - iom[ this.tree.INDEX_OUTSIDE_POS_Y ].count ++; - - } else if ( flagsOutside & this.tree.FLAG_NEG_Y ) { - - iom[ this.tree.INDEX_OUTSIDE_NEG_Y ].count ++; - - } - - // z - - if ( flagsOutside & this.tree.FLAG_POS_Z ) { - - iom[ this.tree.INDEX_OUTSIDE_POS_Z ].count ++; - - } else if ( flagsOutside & this.tree.FLAG_NEG_Z ) { - - iom[ this.tree.INDEX_OUTSIDE_NEG_Z ].count ++; - - } - - // store in expand list - - objectsExpand.push( object ); - - } else { - - objectsRemaining.push( object ); - - } - - } - - // if objects to expand - - if ( objectsExpand.length > 0 ) { - - // shallow copy index outside map - - indexOutsideCounts = iom.slice( 0 ); - - // sort outside index count so highest is first - - indexOutsideCounts.sort( function ( a, b ) { - - return b.count - a.count; - - } ); - - // get highest outside indices - - // first is first - infoIndexOutside1 = indexOutsideCounts[ 0 ]; - indexOutsideBitwise1 = infoIndexOutside1.index | 1; - - // second is ( one of next two bitwise OR 1 ) that is not opposite of ( first bitwise OR 1 ) - - infoPotential1 = indexOutsideCounts[ 1 ]; - infoPotential2 = indexOutsideCounts[ 2 ]; - - infoIndexOutside2 = ( infoPotential1.index | 1 ) !== indexOutsideBitwise1 ? infoPotential1 : infoPotential2; - indexOutsideBitwise2 = infoIndexOutside2.index | 1; - - // third is ( one of next three bitwise OR 1 ) that is not opposite of ( first or second bitwise OR 1 ) - - infoPotential1 = indexOutsideCounts[ 2 ]; - infoPotential2 = indexOutsideCounts[ 3 ]; - infoPotential3 = indexOutsideCounts[ 4 ]; - - indexPotentialBitwise1 = infoPotential1.index | 1; - indexPotentialBitwise2 = infoPotential2.index | 1; - - infoIndexOutside3 = indexPotentialBitwise1 !== indexOutsideBitwise1 && indexPotentialBitwise1 !== indexOutsideBitwise2 ? infoPotential1 : indexPotentialBitwise2 !== indexOutsideBitwise1 && indexPotentialBitwise2 !== indexOutsideBitwise2 ? infoPotential2 : infoPotential3; - - // get this octant normal based on outside octant indices - - octantX = infoIndexOutside1.x + infoIndexOutside2.x + infoIndexOutside3.x; - octantY = infoIndexOutside1.y + infoIndexOutside2.y + infoIndexOutside3.y; - octantZ = infoIndexOutside1.z + infoIndexOutside2.z + infoIndexOutside3.z; - - // get this octant indices based on octant normal - - indexOctant = this.getOctantIndexFromPosition( octantX, octantY, octantZ ); - indexOctantInverse = this.getOctantIndexFromPosition( - octantX, - octantY, - octantZ ); - - // properties - - overlap = this.overlap; - radius = this.radius; - - // radius of parent comes from reversing overlap of this, unless overlap percent is 0 - - radiusParent = this.tree.overlapPct > 0 ? overlap / ( ( 0.5 * this.tree.overlapPct ) * ( 1 + this.tree.overlapPct ) ) : radius * 2; - overlapParent = radiusParent * this.tree.overlapPct; - - // parent offset is difference between radius + overlap of parent and child - - radiusOffset = ( radiusParent + overlapParent ) - ( radius + overlap ); - offset.set( indexOctant & 1 ? radiusOffset : - radiusOffset, indexOctant & 2 ? radiusOffset : - radiusOffset, indexOctant & 4 ? radiusOffset : - radiusOffset ); - position = new THREE.Vector3().addVectors( this.position, offset ); - - // parent - - parent = new THREE.OctreeNode( { - tree: this.tree, - position: position, - radius: radiusParent - } ); - - // set self as node of parent - - parent.addNode( this, indexOctantInverse ); - - // set parent as root - - this.tree.setRoot( parent ); - - // add all expand objects to parent - - for ( i = 0, l = objectsExpand.length; i < l; i ++ ) { - - this.tree.root.addObject( objectsExpand[ i ] ); - - } - - } - - // if all objects, set remaining as new objects - - if ( objects === this.objects ) { - - this.objects = objectsRemaining; - - } - - } else { - - objectsRemaining = objects; - - } - - return objectsRemaining; - - }, - - shrink: function () { - - // merge check - - this.checkMerge(); - - // contract check - - this.tree.root.checkContract(); - - }, - - checkMerge: function () { - - var nodeParent = this, - nodeMerge; - - // traverse up tree as long as node + entire subtree's object count is under minimum - - while ( nodeParent.parent instanceof THREE.OctreeNode && nodeParent.getObjectCountEnd() < this.tree.objectsThreshold ) { - - nodeMerge = nodeParent; - nodeParent = nodeParent.parent; - - } - - // if parent node is not this, merge entire subtree into merge node - - if ( nodeParent !== this ) { - - nodeParent.merge( nodeMerge ); - - } - - }, - - merge: function ( nodes ) { - - var i, l, - j, k, - node; - - // handle nodes - - nodes = toArray( nodes ); - - for ( i = 0, l = nodes.length; i < l; i ++ ) { - - node = nodes[ i ]; - - // gather node + all subtree objects - - this.addObjectWithoutCheck( node.getObjectsEnd() ); - - // reset node + entire subtree - - node.reset( true, true ); - - // remove node - - this.removeNode( node.indexOctant, node ); - - } - - // merge check - - this.checkMerge(); - - }, - - checkContract: function () { - - var i, l, - node, - nodeObjectsCount, - nodeHeaviest, - nodeHeaviestObjectsCount, - outsideHeaviestObjectsCount; - - // find node with highest object count - - if ( this.nodesIndices.length > 0 ) { - - nodeHeaviestObjectsCount = 0; - outsideHeaviestObjectsCount = this.objects.length; - - for ( i = 0, l = this.nodesIndices.length; i < l; i ++ ) { - - node = this.nodesByIndex[ this.nodesIndices[ i ] ]; - - nodeObjectsCount = node.getObjectCountEnd(); - outsideHeaviestObjectsCount += nodeObjectsCount; - - if ( nodeHeaviest instanceof THREE.OctreeNode === false || nodeObjectsCount > nodeHeaviestObjectsCount ) { - - nodeHeaviest = node; - nodeHeaviestObjectsCount = nodeObjectsCount; - - } - - } - - // subtract heaviest count from outside count - - outsideHeaviestObjectsCount -= nodeHeaviestObjectsCount; - - // if should contract - - if ( outsideHeaviestObjectsCount < this.tree.objectsThreshold && nodeHeaviest instanceof THREE.OctreeNode ) { - - this.contract( nodeHeaviest ); - - } - - } - - }, - - contract: function ( nodeRoot ) { - - var i, l, - node; - - // handle all nodes - - for ( i = 0, l = this.nodesIndices.length; i < l; i ++ ) { - - node = this.nodesByIndex[ this.nodesIndices[ i ] ]; - - // if node is not new root - - if ( node !== nodeRoot ) { - - // add node + all subtree objects to root - - nodeRoot.addObjectWithoutCheck( node.getObjectsEnd() ); - - // reset node + entire subtree - - node.reset( true, true ); - - } - - } - - // add own objects to root - - nodeRoot.addObjectWithoutCheck( this.objects ); - - // reset self - - this.reset( false, true ); - - // set new root - - this.tree.setRoot( nodeRoot ); - - // contract check on new root - - nodeRoot.checkContract(); - - }, - - getOctantIndex: function ( objectData ) { - - var i, l, - positionObj, - radiusObj, - position = this.position, - radiusOverlap = this.radiusOverlap, - overlap = this.overlap, - deltaX, deltaY, deltaZ, - distX, distY, distZ, - distance, - indexOctant = 0; - - // handle type - - if ( objectData instanceof THREE.OctreeObjectData ) { - - radiusObj = objectData.radius; - - positionObj = objectData.position; - - // update object data position last - - objectData.positionLast.copy( positionObj ); - - } else if ( objectData instanceof THREE.OctreeNode ) { - - positionObj = objectData.position; - - radiusObj = 0; - - } - - // find delta and distance - - deltaX = positionObj.x - position.x; - deltaY = positionObj.y - position.y; - deltaZ = positionObj.z - position.z; - - distX = Math.abs( deltaX ); - distY = Math.abs( deltaY ); - distZ = Math.abs( deltaZ ); - distance = Math.max( distX, distY, distZ ); - - // if outside, use bitwise flags to indicate on which sides object is outside of - - if ( distance + radiusObj > radiusOverlap ) { - - // x - - if ( distX + radiusObj > radiusOverlap ) { - - indexOctant = indexOctant ^ ( deltaX > 0 ? this.tree.FLAG_POS_X : this.tree.FLAG_NEG_X ); - - } - - // y - - if ( distY + radiusObj > radiusOverlap ) { - - indexOctant = indexOctant ^ ( deltaY > 0 ? this.tree.FLAG_POS_Y : this.tree.FLAG_NEG_Y ); - - } - - // z - - if ( distZ + radiusObj > radiusOverlap ) { - - indexOctant = indexOctant ^ ( deltaZ > 0 ? this.tree.FLAG_POS_Z : this.tree.FLAG_NEG_Z ); - - } - - objectData.indexOctant = - indexOctant - this.tree.INDEX_OUTSIDE_OFFSET; - - return objectData.indexOctant; - - } - - // return octant index from delta xyz - - if ( deltaX - radiusObj > - overlap ) { - - // x right - - indexOctant = indexOctant | 1; - - } else if ( ! ( deltaX + radiusObj < overlap ) ) { - - // x left - - objectData.indexOctant = this.tree.INDEX_INSIDE_CROSS; - return objectData.indexOctant; - - } - - if ( deltaY - radiusObj > - overlap ) { - - // y right - - indexOctant = indexOctant | 2; - - } else if ( ! ( deltaY + radiusObj < overlap ) ) { - - // y left - - objectData.indexOctant = this.tree.INDEX_INSIDE_CROSS; - return objectData.indexOctant; - - } - - - if ( deltaZ - radiusObj > - overlap ) { - - // z right - - indexOctant = indexOctant | 4; - - } else if ( ! ( deltaZ + radiusObj < overlap ) ) { - - // z left - - objectData.indexOctant = this.tree.INDEX_INSIDE_CROSS; - return objectData.indexOctant; - - } - - objectData.indexOctant = indexOctant; - return objectData.indexOctant; - - }, - - getOctantIndexFromPosition: function ( x, y, z ) { - - var indexOctant = 0; - - if ( x > 0 ) { - - indexOctant = indexOctant | 1; - - } - - if ( y > 0 ) { - - indexOctant = indexOctant | 2; - - } - - if ( z > 0 ) { - - indexOctant = indexOctant | 4; - - } - - return indexOctant; - - }, - - search: function ( position, radius, objects, direction, directionPct ) { - - var i, l, - node, - intersects; - - // test intersects by parameters - - if ( direction ) { - - intersects = this.intersectRay( position, direction, radius, directionPct ); - - } else { - - intersects = this.intersectSphere( position, radius ); - - } - - // if intersects - - if ( intersects === true ) { - - // gather objects - - objects = objects.concat( this.objects ); - - // search subtree - - for ( i = 0, l = this.nodesIndices.length; i < l; i ++ ) { - - node = this.nodesByIndex[ this.nodesIndices[ i ] ]; - - objects = node.search( position, radius, objects, direction ); - - } - - } - - return objects; - - }, - - intersectSphere: function ( position, radius ) { - - var distance = radius * radius, - px = position.x, - py = position.y, - pz = position.z; - - if ( px < this.left ) { - - distance -= Math.pow( px - this.left, 2 ); - - } else if ( px > this.right ) { - - distance -= Math.pow( px - this.right, 2 ); - - } - - if ( py < this.bottom ) { - - distance -= Math.pow( py - this.bottom, 2 ); - - } else if ( py > this.top ) { - - distance -= Math.pow( py - this.top, 2 ); - - } - - if ( pz < this.back ) { - - distance -= Math.pow( pz - this.back, 2 ); - - } else if ( pz > this.front ) { - - distance -= Math.pow( pz - this.front, 2 ); - - } - - return distance >= 0; - - }, - - intersectRay: function ( origin, direction, distance, directionPct ) { - - if ( typeof directionPct === 'undefined' ) { - - directionPct = this.utilVec31Ray.set( 1, 1, 1 ).divide( direction ); - - } - - var t1 = ( this.left - origin.x ) * directionPct.x, - t2 = ( this.right - origin.x ) * directionPct.x, - t3 = ( this.bottom - origin.y ) * directionPct.y, - t4 = ( this.top - origin.y ) * directionPct.y, - t5 = ( this.back - origin.z ) * directionPct.z, - t6 = ( this.front - origin.z ) * directionPct.z, - tmax = Math.min( Math.min( Math.max( t1, t2 ), Math.max( t3, t4 ) ), Math.max( t5, t6 ) ), - tmin; - - // ray would intersect in reverse direction, i.e. this is behind ray - if ( tmax < 0 ) { - - return false; - - } - - tmin = Math.max( Math.max( Math.min( t1, t2 ), Math.min( t3, t4 ) ), Math.min( t5, t6 ) ); - - // if tmin > tmax or tmin > ray distance, ray doesn't intersect AABB - if ( tmin > tmax || tmin > distance ) { - - return false; - - } - - return true; - - }, - - getDepthEnd: function ( depth ) { - - var i, l, - node; - - if ( this.nodesIndices.length > 0 ) { - - for ( i = 0, l = this.nodesIndices.length; i < l; i ++ ) { - - node = this.nodesByIndex[ this.nodesIndices[ i ] ]; - - depth = node.getDepthEnd( depth ); - - } - - } else { - - depth = ! depth || this.depth > depth ? this.depth : depth; - - } - - return depth; - - }, - - getNodeCountEnd: function () { - - return this.tree.root.getNodeCountRecursive() + 1; - - }, - - getNodeCountRecursive: function () { - - var i, l, - count = this.nodesIndices.length; - - for ( i = 0, l = this.nodesIndices.length; i < l; i ++ ) { - - count += this.nodesByIndex[ this.nodesIndices[ i ] ].getNodeCountRecursive(); - - } - - return count; - - }, - - getObjectsEnd: function ( objects ) { - - var i, l, - node; - - objects = ( objects || [] ).concat( this.objects ); - - for ( i = 0, l = this.nodesIndices.length; i < l; i ++ ) { - - node = this.nodesByIndex[ this.nodesIndices[ i ] ]; - - objects = node.getObjectsEnd( objects ); - - } - - return objects; - - }, - - getObjectCountEnd: function () { - - var i, l, - count = this.objects.length; - - for ( i = 0, l = this.nodesIndices.length; i < l; i ++ ) { - - count += this.nodesByIndex[ this.nodesIndices[ i ] ].getObjectCountEnd(); - - } - - return count; - - }, - - getObjectCountStart: function () { - - var count = this.objects.length, - parent = this.parent; - - while ( parent instanceof THREE.OctreeNode ) { - - count += parent.objects.length; - parent = parent.parent; - - } - - return count; - - }, - - toConsole: function ( space ) { - - var i, l, - node, - spaceAddition = ' '; - - space = typeof space === 'string' ? space : spaceAddition; - - console.log( ( this.parent ? space + ' octree NODE > ' : ' octree ROOT > ' ), this, ' // id: ', this.id, ' // indexOctant: ', this.indexOctant, ' // position: ', this.position.x, this.position.y, this.position.z, ' // radius: ', this.radius, ' // depth: ', this.depth ); - console.log( ( this.parent ? space + ' ' : ' ' ), '+ objects ( ', this.objects.length, ' ) ', this.objects ); - console.log( ( this.parent ? space + ' ' : ' ' ), '+ children ( ', this.nodesIndices.length, ' )', this.nodesIndices, this.nodesByIndex ); - - for ( i = 0, l = this.nodesIndices.length; i < l; i ++ ) { - - node = this.nodesByIndex[ this.nodesIndices[ i ] ]; - - node.toConsole( space + spaceAddition ); - - } - - } - - }; - - /*=================================================== - - raycaster additional functionality - - =====================================================*/ - - THREE.Raycaster.prototype.intersectOctreeObject = function ( object, recursive ) { - - var intersects, - octreeObject, - facesAll, - facesSearch; - - if ( object.object instanceof THREE.Object3D ) { - - octreeObject = object; - object = octreeObject.object; - - // temporarily replace object geometry's faces with octree object faces - - facesSearch = octreeObject.faces; - facesAll = object.geometry.faces; - - if ( facesSearch.length > 0 ) { - - object.geometry.faces = facesSearch; - - } - - // intersect - - intersects = this.intersectObject( object, recursive ); - - // revert object geometry's faces - - if ( facesSearch.length > 0 ) { - - object.geometry.faces = facesAll; - - } - - } else { - - intersects = this.intersectObject( object, recursive ); - - } - - return intersects; - - }; - - THREE.Raycaster.prototype.intersectOctreeObjects = function ( objects, recursive ) { - - var i, il, - intersects = []; - - for ( i = 0, il = objects.length; i < il; i ++ ) { - - intersects = intersects.concat( this.intersectOctreeObject( objects[ i ], recursive ) ); - - } - - // we should sort it, the elements in it aren't arranged by distance. - intersects.sort( function( a, b ) { - return a.distance - b.distance; - } ); - - return intersects; - - }; - -}( THREE ) ); diff --git a/examples/webgl_octree.html b/examples/webgl_octree.html deleted file mode 100644 index 2da44731a4c000..00000000000000 --- a/examples/webgl_octree.html +++ /dev/null @@ -1,250 +0,0 @@ - - - - three.js webgl - octree - - - - - - - - - - - diff --git a/examples/webgl_octree_raycasting.html b/examples/webgl_octree_raycasting.html deleted file mode 100644 index a5985af4a67f9e..00000000000000 --- a/examples/webgl_octree_raycasting.html +++ /dev/null @@ -1,360 +0,0 @@ - - - - three.js webgl - octree raycasting - - - - - - - - - - - - - - - - - From b214d0093d4a240ccfff39f2c6b25c9aaa2ab84d Mon Sep 17 00:00:00 2001 From: Mugen87 Date: Wed, 19 Dec 2018 16:03:34 +0100 Subject: [PATCH 66/85] Examples: Clean up --- examples/webgl_modifier_subdivision.html | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/examples/webgl_modifier_subdivision.html b/examples/webgl_modifier_subdivision.html index aa2815b61d999a..dc83d3aae84127 100644 --- a/examples/webgl_modifier_subdivision.html +++ b/examples/webgl_modifier_subdivision.html @@ -31,7 +31,7 @@ var container, stats; - var camera, controls, scene, renderer; + var camera, scene, renderer; var cube, mesh, material, geometry, smooth, group; @@ -109,7 +109,7 @@ return geometry.clone(); - }; + }; updateInfo(); @@ -126,7 +126,7 @@ return geometry.clone(); - }; + }; updateInfo(); @@ -252,11 +252,13 @@ group = new THREE.Group(); scene.add( group ); - mesh = new THREE.Mesh( geometry, material ); + mesh = new THREE.Mesh( new THREE.BufferGeometry().fromGeometry( geometry ), material ); group.add( mesh ); - cube = new THREE.Mesh( smooth, smoothMaterial ); - var wireframe = new THREE.Mesh( smooth, wireframeMaterial ); + var smoothBufferGeometry = new THREE.BufferGeometry().fromGeometry( smooth ); + + cube = new THREE.Mesh( smoothBufferGeometry, smoothMaterial ); + var wireframe = new THREE.Mesh( smoothBufferGeometry, wireframeMaterial ); cube.add( wireframe ); cube.scale.setScalar( params.meshScale ? params.meshScale : 1 ); @@ -301,7 +303,7 @@ // - controls = new THREE.OrbitControls( camera, renderer.domElement ); + var controls = new THREE.OrbitControls( camera, renderer.domElement ); window.addEventListener( 'resize', onWindowResize, false ); From 0946d88d1b720b6835e70dfb1f5d2d4c88c06a5b Mon Sep 17 00:00:00 2001 From: Mugen87 Date: Thu, 20 Dec 2018 14:39:59 +0100 Subject: [PATCH 67/85] Docs: Fix links in "Useful Links" page --- docs/manual/en/introduction/Useful-links.html | 8 ++++---- docs/manual/zh/introduction/Useful-links.html | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/docs/manual/en/introduction/Useful-links.html b/docs/manual/en/introduction/Useful-links.html index f75df2858ffcce..00473b8dcac8a0 100644 --- a/docs/manual/en/introduction/Useful-links.html +++ b/docs/manual/en/introduction/Useful-links.html @@ -103,7 +103,7 @@

Examples

maintained as part of the three.js repository, and always use the latest version of three.js.
  • - [link:https://rawgit.com/mrdoob/three.js/dev/examples/ Official three.js dev branch examples] - + [link:https://raw.githack.com/mrdoob/three.js/dev/examples/ Official three.js dev branch examples] - Same as the above, except these use the dev branch of three.js, and are used to check that everything is working as three.js being is developed.
  • @@ -126,7 +126,7 @@

    Tools

    [link:http://idflood.github.io/ThreeNodes.js/ ThreeNodes.js]. - +

    WebGL References

    • @@ -142,7 +142,7 @@

      Old Links

      • - AlterQualia at WebGL Camp 3 + AlterQualia at WebGL Camp 3
      • [link:http://yomotsu.github.io/threejs-examples/ Yomotsus Examples] - a collection of examples using three.js r45. @@ -157,7 +157,7 @@

        Old Links

        [link:http://bkcore.com/blog/general/adobe-user-group-nl-talk-video-hexgl.html Fast HTML5 game development using three.js] by [link:https://github.com/BKcore BKcore] (video).
      • - Trigger Rally by [link:https://github.com/jareiko jareiko] (video). + Trigger Rally by [link:https://github.com/jareiko jareiko] (video).
      • [link:http://blackjk3.github.io/threefab/ ThreeFab] - scene editor, maintained up until around three.js r50. diff --git a/docs/manual/zh/introduction/Useful-links.html b/docs/manual/zh/introduction/Useful-links.html index ac4bbbac61d282..0f2d4a40c95d30 100644 --- a/docs/manual/zh/introduction/Useful-links.html +++ b/docs/manual/zh/introduction/Useful-links.html @@ -24,7 +24,7 @@

        帮助论坛

        Three.js官方使用[link:http://stackoverflow.com/tags/three.js/info Stack Overflow]来处理帮助请求。 如果你需要一些帮助,这才是你所要去的地方。请一定不要在GitHub上提issue来寻求帮助。 - +

        教程以及课程

        @@ -100,7 +100,7 @@

        示例

        maintained as part of the three.js repository, and always use the latest version of three.js.
      • - [link:https://rawgit.com/mrdoob/three.js/dev/examples/ Official three.js dev branch examples] - + [link:https://raw.githack.com/mrdoob/three.js/dev/examples/ Official three.js dev branch examples] - Same as the above, except these use the dev branch of three.js, and are used to check that everything is working as three.js being is developed.
      • @@ -123,7 +123,7 @@

        工具

        [link:http://idflood.github.io/ThreeNodes.js/ ThreeNodes.js].
      - +

      WebGL参考

      • @@ -138,7 +138,7 @@

        较旧的链接

        • - AlterQualia at WebGL Camp 3 + AlterQualia at WebGL Camp 3
        • [link:http://yomotsu.github.io/threejs-examples/ Yomotsus Examples] - a collection of examples using three.js r45. @@ -153,7 +153,7 @@

          较旧的链接

          [link:http://bkcore.com/blog/general/adobe-user-group-nl-talk-video-hexgl.html Fast HTML5 game development using three.js] by [link:https://github.com/BKcore BKcore] (video).
        • - Trigger Rally by [link:https://github.com/jareiko jareiko] (video). + Trigger Rally by [link:https://github.com/jareiko jareiko] (video).
        • [link:http://blackjk3.github.io/threefab/ ThreeFab] - scene editor, maintained up until around three.js r50. From 77dec217368a069a3c3e54e4a10419a98f7b9c83 Mon Sep 17 00:00:00 2001 From: Mugen87 Date: Thu, 20 Dec 2018 17:17:38 +0100 Subject: [PATCH 68/85] Lensflare: Perform early out if the lensflare is behind the camera --- examples/js/objects/Lensflare.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/examples/js/objects/Lensflare.js b/examples/js/objects/Lensflare.js index c43f4fdfef0b90..c50fc49df5e9a8 100644 --- a/examples/js/objects/Lensflare.js +++ b/examples/js/objects/Lensflare.js @@ -14,6 +14,7 @@ THREE.Lensflare = function () { // var positionScreen = new THREE.Vector3(); + var positionView = new THREE.Vector3(); // textures @@ -175,10 +176,12 @@ THREE.Lensflare = function () { // calculate position in screen space - positionScreen.setFromMatrixPosition( this.matrixWorld ); + positionView.setFromMatrixPosition( this.matrixWorld ); + positionView.applyMatrix4( camera.matrixWorldInverse ); - positionScreen.applyMatrix4( camera.matrixWorldInverse ); - positionScreen.applyMatrix4( camera.projectionMatrix ); + if ( positionView.z > 0 ) return; // lensflare is behind the camera + + positionScreen.copy( positionView ).applyMatrix4( camera.projectionMatrix ); // horizontal and vertical coordinate of the lower left corner of the pixels to copy From b6375eedd6f246ec90e5a9ee716a2c3e1e6d71c9 Mon Sep 17 00:00:00 2001 From: Mugen87 Date: Thu, 20 Dec 2018 18:23:38 +0100 Subject: [PATCH 69/85] Exampels: Clean up --- .../webgl_interactive_raycasting_points.html | 54 ++----------------- 1 file changed, 5 insertions(+), 49 deletions(-) diff --git a/examples/webgl_interactive_raycasting_points.html b/examples/webgl_interactive_raycasting_points.html index a462fec0867616..36d5ca2b03d65a 100644 --- a/examples/webgl_interactive_raycasting_points.html +++ b/examples/webgl_interactive_raycasting_points.html @@ -173,45 +173,6 @@ } - function generateRegularPointcloud( color, width, length ) { - - var geometry = new THREE.Geometry(); - - var colors = []; - - var k = 0; - - for ( var i = 0; i < width; i ++ ) { - - for ( var j = 0; j < length; j ++ ) { - - var u = i / width; - var v = j / length; - var x = u - 0.5; - var y = ( Math.cos( u * Math.PI * 8 ) + Math.sin( v * Math.PI * 8 ) ) / 20; - var z = v - 0.5; - var v = new THREE.Vector3( x, y, z ); - geometry.vertices.push( v ); - - var intensity = ( y + 0.1 ) * 7; - colors[ k ] = ( color.clone().multiplyScalar( intensity ) ); - - k ++; - - } - - } - - geometry.colors = colors; - geometry.computeBoundingBox(); - - var material = new THREE.PointsMaterial( { size: pointSize, vertexColors: THREE.VertexColors } ); - var pointcloud = new THREE.Points( geometry, material ); - - return pointcloud; - - } - function init() { var container = document.getElementById( 'container' ); @@ -221,7 +182,7 @@ clock = new THREE.Clock(); camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 10000 ); - camera.position.set( 10, 10, 10 ); + camera.position.set( 15, 15, 15 ); camera.lookAt( scene.position ); camera.updateMatrix(); @@ -229,25 +190,20 @@ var pcBuffer = generatePointcloud( new THREE.Color( 1, 0, 0 ), width, length ); pcBuffer.scale.set( 10, 10, 10 ); - pcBuffer.position.set( - 5, 0, 5 ); + pcBuffer.position.set( - 10, 0, 0 ); scene.add( pcBuffer ); var pcIndexed = generateIndexedPointcloud( new THREE.Color( 0, 1, 0 ), width, length ); pcIndexed.scale.set( 10, 10, 10 ); - pcIndexed.position.set( 5, 0, 5 ); + pcIndexed.position.set( 0, 0, 0 ); scene.add( pcIndexed ); var pcIndexedOffset = generateIndexedWithOffsetPointcloud( new THREE.Color( 0, 1, 1 ), width, length ); pcIndexedOffset.scale.set( 10, 10, 10 ); - pcIndexedOffset.position.set( 5, 0, - 5 ); + pcIndexedOffset.position.set( 10, 0, 0 ); scene.add( pcIndexedOffset ); - var pcRegular = generateRegularPointcloud( new THREE.Color( 1, 0, 1 ), width, length ); - pcRegular.scale.set( 10, 10, 10 ); - pcRegular.position.set( - 5, 0, - 5 ); - scene.add( pcRegular ); - - pointclouds = [ pcBuffer, pcIndexed, pcIndexedOffset, pcRegular ]; + pointclouds = [ pcBuffer, pcIndexed, pcIndexedOffset ]; // From 1b8c23d274f921362c03a04fc1b36a7429b9e102 Mon Sep 17 00:00:00 2001 From: Mugen87 Date: Thu, 20 Dec 2018 19:05:34 +0100 Subject: [PATCH 70/85] Xloader: Fixed SkinnedMesh creation --- examples/js/loaders/XLoader.js | 48 ++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/examples/js/loaders/XLoader.js b/examples/js/loaders/XLoader.js index 8c613e747bc20a..ecf450e17162b9 100644 --- a/examples/js/loaders/XLoader.js +++ b/examples/js/loaders/XLoader.js @@ -1415,9 +1415,9 @@ } var bufferGeometry = this._buildGeometry(); - bufferGeometry.bones = putBones; mesh = new THREE.SkinnedMesh( bufferGeometry, this._currentGeo.Materials.length === 1 ? this._currentGeo.Materials[ 0 ] : this._currentGeo.Materials ); - mesh.skeleton.boneInverses = offsetList; + + this._initSkeleton( mesh, putBones, offsetList ); } else { @@ -1450,6 +1450,50 @@ this.Meshes.push( mesh ); } + }, { + key: '_initSkeleton', + value: function _initSkeleton( mesh, boneList, boneInverses ) { + + var bones = [], bone, gbone; + var i, il; + + for ( i = 0, il = boneList.length; i < il; i ++ ) { + + gbone = boneList[ i ]; + + bone = new THREE.Bone(); + bones.push( bone ); + + bone.name = gbone.name; + bone.position.fromArray( gbone.pos ); + bone.quaternion.fromArray( gbone.rotq ); + if ( gbone.scl !== undefined ) bone.scale.fromArray( gbone.scl ); + + } + + for ( i = 0, il = boneList.length; i < il; i ++ ) { + + gbone = boneList[ i ]; + + if ( ( gbone.parent !== - 1 ) && ( gbone.parent !== null ) && ( bones[ gbone.parent ] !== undefined ) ) { + + bones[ gbone.parent ].add( bones[ i ] ); + + } else { + + mesh.add( bones[ i ] ); + + } + + } + + mesh.updateMatrixWorld( true ); + + var skeleton = new THREE.Skeleton( bones, boneInverses ); + mesh.bind( skeleton, mesh.matrixWorld ); + + } + }, { key: '_readAnimationKey', value: function _readAnimationKey() { From fc2ba0fd3f610f4e0322943e7821c81fc64011d2 Mon Sep 17 00:00:00 2001 From: Mugen87 Date: Fri, 21 Dec 2018 10:48:36 +0100 Subject: [PATCH 71/85] FBXLoader: Normalize skin weights --- examples/js/loaders/FBXLoader.js | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/js/loaders/FBXLoader.js b/examples/js/loaders/FBXLoader.js index aad891744d77cd..01b863c154a89e 100644 --- a/examples/js/loaders/FBXLoader.js +++ b/examples/js/loaders/FBXLoader.js @@ -1231,6 +1231,7 @@ THREE.FBXLoader = ( function () { } ); model = new THREE.SkinnedMesh( geometry, material ); + model.normalizeSkinWeights(); } else { From 57f4b5cd88d918ddd3aec3c12a2e0dc0b516f811 Mon Sep 17 00:00:00 2001 From: Mugen87 Date: Fri, 21 Dec 2018 10:56:14 +0100 Subject: [PATCH 72/85] Examples: More clean up --- examples/misc_exporter_gltf.html | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/misc_exporter_gltf.html b/examples/misc_exporter_gltf.html index 63eae3072f59ea..d18b6a1ee84296 100644 --- a/examples/misc_exporter_gltf.html +++ b/examples/misc_exporter_gltf.html @@ -212,7 +212,7 @@ map: mapGrid } ); - object = new THREE.Mesh( new THREE.IcosahedronGeometry( 75, 0 ), material ); + object = new THREE.Mesh( new THREE.IcosahedronBufferGeometry( 75, 0 ), material ); object.position.set( - 200, 0, 200 ); object.name = 'Icosahedron'; scene1.add( object ); @@ -222,7 +222,7 @@ color: 0x0000ff, wireframe: true } ); - object = new THREE.Mesh( new THREE.OctahedronGeometry( 75, 1 ), material ); + object = new THREE.Mesh( new THREE.OctahedronBufferGeometry( 75, 1 ), material ); object.position.set( 0, 0, 200 ); object.name = 'Octahedron'; scene1.add( object ); @@ -234,7 +234,7 @@ opacity: 0.5 } ); - object = new THREE.Mesh( new THREE.TetrahedronGeometry( 75, 0 ), material ); + object = new THREE.Mesh( new THREE.TetrahedronBufferGeometry( 75, 0 ), material ); object.position.set( 200, 0, 200 ); object.name = 'Tetrahedron'; scene1.add( object ); @@ -269,7 +269,7 @@ color: 0xff0000, roughness: 1 } ); - object = new THREE.Mesh( new THREE.TorusKnotGeometry( 50, 15, 40, 10 ), material ); + object = new THREE.Mesh( new THREE.TorusKnotBufferGeometry( 50, 15, 40, 10 ), material ); object.position.set( - 200, 0, 0 ); object.name = "Cylinder"; scene1.add( object ); @@ -459,15 +459,15 @@ side: THREE.DoubleSide } ); - object = new THREE.Mesh( new THREE.CircleGeometry( 50, 20, 0, Math.PI * 2 ), material ); + object = new THREE.Mesh( new THREE.CircleBufferGeometry( 50, 20, 0, Math.PI * 2 ), material ); object.position.set( 200, 0, - 400 ); scene1.add( object ); - object = new THREE.Mesh( new THREE.RingGeometry( 10, 50, 20, 5, 0, Math.PI * 2 ), material ); + object = new THREE.Mesh( new THREE.RingBufferGeometry( 10, 50, 20, 5, 0, Math.PI * 2 ), material ); object.position.set( 0, 0, - 400 ); scene1.add( object ); - object = new THREE.Mesh( new THREE.CylinderGeometry( 25, 75, 100, 40, 5 ), material ); + object = new THREE.Mesh( new THREE.CylinderBufferGeometry( 25, 75, 100, 40, 5 ), material ); object.position.set( - 200, 0, - 400 ); scene1.add( object ); @@ -480,7 +480,7 @@ } - object = new THREE.Mesh( new THREE.LatheGeometry( points, 20 ), material ); + object = new THREE.Mesh( new THREE.LatheBufferGeometry( points, 20 ), material ); object.position.set( 200, 0, 400 ); scene1.add( object ); From 36a0d3b148666f4030d328196f7110fb05834f57 Mon Sep 17 00:00:00 2001 From: Mugen87 Date: Fri, 21 Dec 2018 12:02:58 +0100 Subject: [PATCH 73/85] Mesh: Remove Geometry support from .updateMorphTargets() --- src/objects/Mesh.js | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/src/objects/Mesh.js b/src/objects/Mesh.js index f796876dfdcdc1..a304c2c28bf75b 100644 --- a/src/objects/Mesh.js +++ b/src/objects/Mesh.js @@ -104,17 +104,7 @@ Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), { if ( morphTargets !== undefined && morphTargets.length > 0 ) { - this.morphTargetInfluences = []; - this.morphTargetDictionary = {}; - - for ( m = 0, ml = morphTargets.length; m < ml; m ++ ) { - - name = morphTargets[ m ].name || String( m ); - - this.morphTargetInfluences.push( 0 ); - this.morphTargetDictionary[ name ] = m; - - } + console.error( 'THREE.Mesh.updateMorphTargets() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' ); } From 05d7b55c98196c5748424d66d82756a2fdf7b96a Mon Sep 17 00:00:00 2001 From: Takahiro Date: Sat, 22 Dec 2018 00:34:36 +0900 Subject: [PATCH 74/85] ShaderMaterial.extensions serialization --- src/loaders/MaterialLoader.js | 10 ++++++++++ src/materials/ShaderMaterial.js | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/loaders/MaterialLoader.js b/src/loaders/MaterialLoader.js index fbd754060a8612..6a94b8058cac94 100644 --- a/src/loaders/MaterialLoader.js +++ b/src/loaders/MaterialLoader.js @@ -146,6 +146,16 @@ Object.assign( MaterialLoader.prototype, { if ( json.vertexShader !== undefined ) material.vertexShader = json.vertexShader; if ( json.fragmentShader !== undefined ) material.fragmentShader = json.fragmentShader; + if ( json.extensions !== undefined ) { + + for ( var key in json.extensions ) { + + material.extensions[ key ] = json.extensions[ key ]; + + } + + } + // Deprecated if ( json.shading !== undefined ) material.flatShading = json.shading === 1; // THREE.FlatShading diff --git a/src/materials/ShaderMaterial.js b/src/materials/ShaderMaterial.js index 4c1609fe7e1750..ca2455f6c2ff17 100644 --- a/src/materials/ShaderMaterial.js +++ b/src/materials/ShaderMaterial.js @@ -182,6 +182,16 @@ ShaderMaterial.prototype.toJSON = function ( meta ) { data.vertexShader = this.vertexShader; data.fragmentShader = this.fragmentShader; + var extensions = {}; + + for ( var key in this.extensions ) { + + if ( this.extensions[ key ] === true ) extensions[ key ] = true; + + } + + if ( Object.keys( extensions ).length > 0 ) data.extensions = extensions; + return data; }; From 95c8a1af59221ca4c065bc57fae5cf2a47e454ef Mon Sep 17 00:00:00 2001 From: clintonman Date: Sat, 22 Dec 2018 21:55:14 -0800 Subject: [PATCH 75/85] adjusted collada export shader elements to follow the collada standard, changed material to get number of materials from the material array instead of the empty geometry.groups array and added an example for the changes --- examples/js/exporters/ColladaExporter.js | 38 +- examples/webgl_geometry_teapot_collada.html | 428 ++++++++++++++++++++ 2 files changed, 451 insertions(+), 15 deletions(-) create mode 100644 examples/webgl_geometry_teapot_collada.html diff --git a/examples/js/exporters/ColladaExporter.js b/examples/js/exporters/ColladaExporter.js index fa83fe28730b78..3cebc36d8735e7 100644 --- a/examples/js/exporters/ColladaExporter.js +++ b/examples/js/exporters/ColladaExporter.js @@ -402,28 +402,35 @@ THREE.ColladaExporter.prototype = { '' + - '' + - ( - m.map ? - '' : - `${ diffuse.r } ${ diffuse.g } ${ diffuse.b } 1` + type !== 'constant' ? + '' + + + ( + m.map ? + '' : + `${ diffuse.r } ${ diffuse.g } ${ diffuse.b } 1` + ) + + '' + : '' ) + - '' + + ( + type === 'phong' ? + `${ specular.r } ${ specular.g } ${ specular.b } 1` + - `${ specular.r } ${ specular.g } ${ specular.b } 1` + + '' + - '' + + ( + m.specularMap ? + '' : + `${ shininess }` + ) + - ( - m.specularMap ? - '' : - `${ shininess }` + '' + : '' ) + - '' + - `${ diffuse.r } ${ diffuse.g } ${ diffuse.b } 1` + `${ reflectivity }` + @@ -508,7 +515,8 @@ THREE.ColladaExporter.prototype = { // the materials. var mat = o.material || new THREE.MeshBasicMaterial(); var materials = Array.isArray( mat ) ? mat : [ mat ]; - matids = new Array( geometry.groups.length ) + // matids = new Array( geometry.groups.length ) + matids = new Array( materials.length ) .fill() .map( ( v, i ) => processMaterial( materials[ i % materials.length ] ) ); diff --git a/examples/webgl_geometry_teapot_collada.html b/examples/webgl_geometry_teapot_collada.html new file mode 100644 index 00000000000000..eb8da19cbe8539 --- /dev/null +++ b/examples/webgl_geometry_teapot_collada.html @@ -0,0 +1,428 @@ + + + + three.js webgl - teapot buffer geometry + + + + + +
          + three.js - the Utah Teapot
          + from Udacity Interactive 3D Graphics + +
          + + + + + + + + + + + + + + + + + From 3d93da45d5777ddf85fa1059da0ba02f5d3d4c82 Mon Sep 17 00:00:00 2001 From: clinton Date: Sun, 23 Dec 2018 09:40:18 -0800 Subject: [PATCH 76/85] fixed my matid error, changed output file names to be unique, removed console logs --- examples/js/exporters/ColladaExporter.js | 11 ++++--- examples/webgl_geometry_teapot_collada.html | 32 ++++++++------------- 2 files changed, 19 insertions(+), 24 deletions(-) diff --git a/examples/js/exporters/ColladaExporter.js b/examples/js/exporters/ColladaExporter.js index 3cebc36d8735e7..9733f4bc76ede1 100644 --- a/examples/js/exporters/ColladaExporter.js +++ b/examples/js/exporters/ColladaExporter.js @@ -509,18 +509,21 @@ THREE.ColladaExporter.prototype = { // ids of the materials to bind to the geometry var matids = null; + var matidsArray = []; // get a list of materials to bind to the sub groups of the geometry. // If the amount of subgroups is greater than the materials, than reuse // the materials. var mat = o.material || new THREE.MeshBasicMaterial(); var materials = Array.isArray( mat ) ? mat : [ mat ]; - // matids = new Array( geometry.groups.length ) - matids = new Array( materials.length ) - .fill() + if ( geometry.groups.length > materials.length ) { + matidsArray = new Array( geometry.groups.length ); + } else { + matidsArray = new Array( materials.length ) + } + matids = matidsArray.fill() .map( ( v, i ) => processMaterial( materials[ i % materials.length ] ) ); - node += `` + diff --git a/examples/webgl_geometry_teapot_collada.html b/examples/webgl_geometry_teapot_collada.html index eb8da19cbe8539..8c18fbf0fbcb99 100644 --- a/examples/webgl_geometry_teapot_collada.html +++ b/examples/webgl_geometry_teapot_collada.html @@ -366,7 +366,8 @@ } var exporter = new THREE.ColladaExporter(); - function exportASCII() { + + function saveColladaFile() { var result = exporter.parse( teapot ); var material_type = "Phong"; @@ -376,24 +377,14 @@ if ( shading === "smooth" ) { material_type = "Lambert" } - console.log(result.textures) - saveString( result.data, 'teapot_' + material_type + '.dae' ); + + saveString( result.data, 'teapot_' + shading + "_" + material_type + '.dae' ); result.textures.forEach( tex => { saveArrayBuffer( tex.data, `${ tex.name }.${ tex.ext }` ); }); } - var link = document.createElement( 'a' ); - link.style.display = 'none'; - document.body.appendChild( link ); - - var savecolladabutton = document.getElementById("savecolladabutton"); - savecolladabutton.addEventListener('click', function(){ - exportASCII(); - }); - - function save( blob, filename ) { link.href = URL.createObjectURL( blob ); @@ -408,19 +399,20 @@ } - function exportBinary() { - - var result = exporter.parse( mesh, { binary: true } ); - saveArrayBuffer( result, 'box.stl' ); - - } - function saveArrayBuffer( buffer, filename ) { save( new Blob( [ buffer ], { type: 'application/octet-stream' } ), filename ); } + var link = document.createElement( 'a' ); + link.style.display = 'none'; + document.body.appendChild( link ); + + var savecolladabutton = document.getElementById("savecolladabutton"); + savecolladabutton.addEventListener('click', function(){ + saveColladaFile(); + }); From b2c7509a1ea5f3cc07a6916dd16b45ee807dd604 Mon Sep 17 00:00:00 2001 From: Joe Pea Date: Sun, 23 Dec 2018 16:54:10 -0800 Subject: [PATCH 77/85] fix typo that was forcing CSS3D to update when not necessary --- examples/js/renderers/CSS3DRenderer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/js/renderers/CSS3DRenderer.js b/examples/js/renderers/CSS3DRenderer.js index c22196a3d074bd..20b6dedc2caa8e 100644 --- a/examples/js/renderers/CSS3DRenderer.js +++ b/examples/js/renderers/CSS3DRenderer.js @@ -186,7 +186,7 @@ THREE.CSS3DRenderer = function () { var element = object.element; var cachedStyle = cache.objects.get( object ); - if ( cachedStyle === undefined || cachedStyle !== style ) { + if ( cachedStyle === undefined || cachedStyle.style !== style ) { element.style.WebkitTransform = style; element.style.transform = style; From 10076261910409282ab2be3f3235f67a6722fb6d Mon Sep 17 00:00:00 2001 From: clinton Date: Sun, 23 Dec 2018 23:11:45 -0800 Subject: [PATCH 78/85] changed html title to three.js webgl - collada exporter and renamed the file from webgl_geometry_teapot_collada.html to misc_exporter_collada.html --- ..._geometry_teapot_collada.html => misc_exporter_collada.html} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename examples/{webgl_geometry_teapot_collada.html => misc_exporter_collada.html} (99%) diff --git a/examples/webgl_geometry_teapot_collada.html b/examples/misc_exporter_collada.html similarity index 99% rename from examples/webgl_geometry_teapot_collada.html rename to examples/misc_exporter_collada.html index 8c18fbf0fbcb99..88cc0825c4d75d 100644 --- a/examples/webgl_geometry_teapot_collada.html +++ b/examples/misc_exporter_collada.html @@ -1,7 +1,7 @@ - three.js webgl - teapot buffer geometry + three.js webgl - collada exporter