language
stringclasses
1 value
owner
stringlengths
2
15
repo
stringlengths
2
21
sha
stringlengths
45
45
message
stringlengths
7
36.3k
path
stringlengths
1
199
patch
stringlengths
15
102k
is_multipart
bool
2 classes
Other
mrdoob
three.js
d64380e8aa074c323d58735d135fad199791f059.json
update xmove function Moved and modded as westLangley proposed
examples/webgl_geometry_text_shapes.html
@@ -65,6 +65,12 @@ side: THREE.DoubleSide } ); + var xMove = function( shape, shapeMid ) { + + return shape.translate( shapeMid, 0, 0 ); + + } + var message = " Three.js\nSimple text."; var shapes = font.generateShapes( message, 100, 2 ); @@ -126,12 +132,6 @@ } // end init - function xMove( shape, shapeMid ) { - - return shape.applyMatrix( new THREE.Matrix4().makeTranslation( shapeMid, 0, 0 ) ); - - } - function onWindowResize() { camera.aspect = window.innerWidth / window.innerHeight;
false
Other
mrdoob
three.js
ae249e1bf75acb093a87d2ef32335968ad76e6cd.json
move texture.image order
src/loaders/TextureLoader.js
@@ -23,13 +23,12 @@ Object.assign( TextureLoader.prototype, { var loader = new ImageLoader( this.manager ); loader.setCrossOrigin( this.crossOrigin ); loader.setPath( this.path ); - loader.load( url, function ( image ) { + var image = loader.load( url, function ( image ) { // JPEGs can't have an alpha channel, so memory can be saved by storing them as RGB. var isJPEG = url.search( /\.(jpg|jpeg)$/ ) > 0 || url.search( /^data\:image\/jpeg/ ) === 0; texture.format = isJPEG ? RGBFormat : RGBAFormat; - texture.image = image; texture.needsUpdate = true; if ( onLoad !== undefined ) { @@ -40,6 +39,7 @@ Object.assign( TextureLoader.prototype, { }, onProgress, onError ); + texture.image = image; return texture; },
false
Other
mrdoob
three.js
7ed394f1b33db49bcea386b11a3cbf566f2f328d.json
Remove MultiMaterial from MMDLoader
examples/js/loaders/MMDLoader.js
@@ -495,7 +495,7 @@ THREE.MMDLoader.prototype.createMesh = function ( model, texturePath, onProgress var scope = this; var geometry = new THREE.BufferGeometry(); - var material = new THREE.MultiMaterial(); + var materials = []; var helper = new THREE.MMDLoader.DataCreationHelper(); var buffer = {}; @@ -1329,7 +1329,7 @@ THREE.MMDLoader.prototype.createMesh = function ( model, texturePath, onProgress } - material.materials.push( m ); + materials.push( m ); } @@ -1353,7 +1353,7 @@ THREE.MMDLoader.prototype.createMesh = function ( model, texturePath, onProgress } - var m = material.materials[ e.index ]; + var m = materials[ e.index ]; if ( m.opacity !== e.diffuse[ 3 ] ) { @@ -1498,7 +1498,7 @@ THREE.MMDLoader.prototype.createMesh = function ( model, texturePath, onProgress initPhysics(); initGeometry(); - var mesh = new THREE.SkinnedMesh( geometry, material ); + var mesh = new THREE.SkinnedMesh( geometry, materials ); // console.log( mesh ); // for console debug
true
Other
mrdoob
three.js
7ed394f1b33db49bcea386b11a3cbf566f2f328d.json
Remove MultiMaterial from MMDLoader
examples/webgl_loader_mmd.html
@@ -177,7 +177,7 @@ } - phongMaterials = new THREE.MultiMaterial( array ); + phongMaterials = array; } @@ -202,7 +202,7 @@ gui.add( api, 'gradient mapping' ).onChange( function () { if ( originalMaterials === undefined ) originalMaterials = mesh.material; - if ( phongMaterials === undefined ) makePhongMaterials( mesh.material.materials ); + if ( phongMaterials === undefined ) makePhongMaterials( mesh.material ); if ( api[ 'gradient mapping' ] ) {
true
Other
mrdoob
three.js
8f319e4a2c7af16435d0bbe6ae90f2a7e34af631.json
Remove MultiMaterial from OutlineEffect
examples/js/effects/OutlineEffect.js
@@ -13,11 +13,11 @@ * * // How to set outline parameters for each material * material.outlineParameters = { - * thickNess: 0.01, // this paremeter won't work for MultiMaterial - * color: new THREE.Color( 0x888888 ), // this paremeter won't work for MultiMaterial - * alpha: 0.8, // this paremeter won't work for MultiMaterial + * thickNess: 0.01, + * color: new THREE.Color( 0x888888 ), + * alpha: 0.8, * visible: true, - * keepAlive: true // this paremeter won't work for Material in materials of MultiMaterial + * keepAlive: true * }; * * TODO @@ -35,17 +35,17 @@ THREE.OutlineEffect = function ( renderer, parameters ) { var defaultAlpha = parameters.defaultAlpha !== undefined ? parameters.defaultAlpha : 1.0; var defaultKeepAlive = parameters.defaultKeepAlive !== undefined ? parameters.defaultKeepAlive : false; - // object.material.uuid -> outlineMaterial - // (no mapping from children of MultiMaterial) + // object.material.uuid -> outlineMaterial or + // object.material[ n ].uuid -> outlineMaterial // save at the outline material creation and release // if it's unused removeThresholdCount frames // unless keepAlive is true. var cache = {}; var removeThresholdCount = 60; - // outlineMaterial.uuid (or object.uuid for invisibleMaterial) -> originalMaterial - // including children of MultiMaterial. + // outlineMaterial.uuid -> object.material or + // outlineMaterial.uuid -> object.material[ n ] // save before render and release after render. var originalMaterials = {}; @@ -55,8 +55,6 @@ THREE.OutlineEffect = function ( renderer, parameters ) { //this.cache = cache; // for debug - var invisibleMaterial = new THREE.ShaderMaterial( { visible: false } ); - // copied from WebGLPrograms and removed some materials var shaderIDs = { MeshBasicMaterial: 'basic', @@ -139,6 +137,12 @@ THREE.OutlineEffect = function ( renderer, parameters ) { ].join( "\n" ); + function createInvisibleMaterial() { + + return new THREE.ShaderMaterial( { name: 'invisible', visible: false } ); + + } + function createMaterial( originalMaterial ) { var shaderID = shaderIDs[ originalMaterial.type ]; @@ -162,7 +166,7 @@ THREE.OutlineEffect = function ( renderer, parameters ) { console.warn( 'THREE.OutlineEffect requires both vec3 position and normal attributes in vertex shader, ' + 'does not draw outline for ' + originalMaterial.name + '(uuid:' + originalMaterial.uuid + ') material.' ); - return invisibleMaterial; + return createInvisibleMaterial(); } @@ -173,7 +177,7 @@ THREE.OutlineEffect = function ( renderer, parameters ) { } else { - return invisibleMaterial; + return createInvisibleMaterial(); } @@ -195,7 +199,7 @@ THREE.OutlineEffect = function ( renderer, parameters ) { if ( ! /vec3\s+transformed\s*=/.test( originalVertexShader ) && ! /#include\s+<begin_vertex>/.test( originalVertexShader ) ) defines.DECLARE_TRANSFORMED = true; - var material = new THREE.ShaderMaterial( { + return new THREE.ShaderMaterial( { defines: defines, uniforms: uniforms, vertexShader: vertexShader, @@ -207,73 +211,61 @@ THREE.OutlineEffect = function ( renderer, parameters ) { fog: false } ); - return material; - - } - - function createMultiMaterial( originalMaterial ) { - - var materials = []; - - for ( var i = 0, il = originalMaterial.materials.length; i < il; i ++ ) { - - materials.push( createMaterial( originalMaterial.materials[ i ] ) ); - - } - - return new THREE.MultiMaterial( materials ); - } - function setOutlineMaterial( object ) { - - if ( object.material === undefined ) return; + function getOutlineMaterialFromCache( originalMaterial ) { - var data = cache[ object.material.uuid ]; + var data = cache[ originalMaterial.uuid ]; if ( data === undefined ) { data = { - material: object.material.isMultiMaterial === true ? createMultiMaterial( object.material ) : createMaterial( object.material ), + material: createMaterial( originalMaterial ), used: true, keepAlive: defaultKeepAlive, count: 0 }; - cache[ object.material.uuid ] = data; + cache[ originalMaterial.uuid ] = data; } - var outlineMaterial = data.material; data.used = true; - var uuid = outlineMaterial !== invisibleMaterial ? outlineMaterial.uuid : object.uuid; - originalMaterials[ uuid ] = object.material; + return data.material; - if ( object.material.isMultiMaterial === true ) { + } - for ( var i = 0, il = object.material.materials.length; i < il; i ++ ) { + function getOutlineMaterial( originalMaterial ) { - // originalMaterial of leaf material of MultiMaterial is used only for - // updating outlineMaterial. so need not to save for invisibleMaterial. - if ( outlineMaterial.materials[ i ] !== invisibleMaterial ) { + var outlineMaterial = getOutlineMaterialFromCache( originalMaterial ); - originalMaterials[ outlineMaterial.materials[ i ].uuid ] = object.material.materials[ i ]; + originalMaterials[ outlineMaterial.uuid ] = originalMaterial; - } + updateOutlineMaterial( outlineMaterial, originalMaterial ); - } + return outlineMaterial; + + } + + function setOutlineMaterial( object ) { + + if ( object.material === undefined ) return; - updateOutlineMultiMaterial( outlineMaterial, object.material ); + if ( Array.isArray( object.material ) ) { + + for ( var i = 0, il = object.material.length; i < il; i ++ ) { + + object.material[ i ] = getOutlineMaterial( object.material[ i ] ); + + } } else { - updateOutlineMaterial( outlineMaterial, object.material ); + object.material = getOutlineMaterial( object.material ); } - object.material = outlineMaterial; - originalOnBeforeRenders[ object.uuid ] = object.onBeforeRender; object.onBeforeRender = onBeforeRender; @@ -283,31 +275,29 @@ THREE.OutlineEffect = function ( renderer, parameters ) { if ( object.material === undefined ) return; - var originalMaterial = originalMaterials[ object.material.uuid ]; + if ( Array.isArray( object.material ) ) { + + for ( var i = 0, il = object.material.length; i < il; i ++ ) { - if ( originalMaterial === undefined ) { + object.material[ i ] = originalMaterials[ object.material[ i ].uuid ]; + + } - originalMaterial = originalMaterials[ object.uuid ]; + } else { - if ( originalMaterial === undefined ) return; + object.material = originalMaterials[ object.material.uuid ]; } - object.material = originalMaterial; object.onBeforeRender = originalOnBeforeRenders[ object.uuid ]; } function onBeforeRender( renderer, scene, camera, geometry, material, group ) { - // check some things before updating just in case - - if ( material === invisibleMaterial ) return; - - if ( material.isMultiMaterial === true ) return; - var originalMaterial = originalMaterials[ material.uuid ]; + // just in case if ( originalMaterial === undefined ) return; updateUniforms( material, originalMaterial ); @@ -332,7 +322,7 @@ THREE.OutlineEffect = function ( renderer, parameters ) { function updateOutlineMaterial( material, originalMaterial ) { - if ( material === invisibleMaterial ) return; + if ( material.name === 'invisible' ) return; var outlineParameters = originalMaterial.outlineParameters; @@ -354,8 +344,7 @@ THREE.OutlineEffect = function ( renderer, parameters ) { material.transparent = ( outlineParameters.alpha !== undefined && outlineParameters.alpha < 1.0 ) ? true : originalMaterial.transparent; - // cache[ originalMaterial.uuid ] is undefined if originalMaterial is in materials of MultiMaterial - if ( outlineParameters.keepAlive !== undefined && cache[ originalMaterial.uuid ] !== undefined ) cache[ originalMaterial.uuid ].keepAlive = outlineParameters.keepAlive; + if ( outlineParameters.keepAlive !== undefined ) cache[ originalMaterial.uuid ].keepAlive = outlineParameters.keepAlive; } else { @@ -368,40 +357,6 @@ THREE.OutlineEffect = function ( renderer, parameters ) { } - function updateOutlineMultiMaterial( material, originalMaterial ) { - - if ( material === invisibleMaterial ) return; - - var outlineParameters = originalMaterial.outlineParameters; - - if ( outlineParameters !== undefined ) { - - if ( originalMaterial.visible === false ) { - - material.visible = false; - - } else { - - material.visible = ( outlineParameters.visible !== undefined ) ? outlineParameters.visible : true; - - } - - if ( outlineParameters.keepAlive !== undefined ) cache[ originalMaterial.uuid ].keepAlive = outlineParameters.keepAlive; - - } else { - - material.visible = originalMaterial.visible; - - } - - for ( var i = 0, il = material.materials.length; i < il; i ++ ) { - - updateOutlineMaterial( material.materials[ i ], originalMaterial.materials[ i ] ); - - } - - } - function cleanupCache() { var keys;
false
Other
mrdoob
three.js
6a3cdc83dc0f6c22666af749ecf3758a4b9b727d.json
Add files via upload
docs/api/loaders/FontLoader.html
@@ -21,6 +21,7 @@ <h1>[name]</h1> <h2>Examples</h2> <div> + [example:webgl_geometry_text_shapes geometry / text / shapes ]<br/> [example:webgl_geometry_text geometry / text ]<br /> [example:webgl_geometry_text_earcut geometry / text / earcut]<br /> [example:webgl_geometry_text_pnltri geometry / text / pnltri]<br />
false
Other
mrdoob
three.js
3f055db652621f7679fa940d556f70ab4d06a9ee.json
Add files via upload
docs/api/extras/core/Font.html
@@ -16,6 +16,13 @@ <h1>[name]</h1> This is used internally by the [page:FontLoader]. </div> + <h2>Examples</h2> + + <div> + [example:webgl_geometry_text_shapes geometry / text / shapes ]<br/> + [example:webgl_shaders_vector vector / text ]<br/> + </div> + <h2>Constructor</h2> <h3>[name]( data )</h3>
false
Other
mrdoob
three.js
edb5771db148cb6f701bae3f8f84b81c4cfb1425.json
Create GLTF2Loader fork.
docs/examples/loaders/GLTFLoader.html
@@ -23,10 +23,6 @@ <h2>Notes</h2> When using custom shaders provided within a glTF file [page:THREE.GLTFLoader.Shaders] should be updated on each render loop. See [example:webgl_loader_gltf] demo source code for example usage. </div> - <div> - This class is often used with [page:THREE.GLTFLoader.Animations THREE.GLTFLoader.Animations] to animate parsed animations. See [example:webgl_loader_gltf] demo source code for example usage. - </div> - <h2>Example</h2> <code> @@ -45,7 +41,7 @@ <h2>Example</h2> </code> [example:webgl_loader_gltf] - + <h2>Constructor</h2> <h3>[name]( [page:LoadingManager manager] )</h3>
true
Other
mrdoob
three.js
edb5771db148cb6f701bae3f8f84b81c4cfb1425.json
Create GLTF2Loader fork.
examples/js/loaders/GLTF2Loader.js
@@ -0,0 +1,2183 @@ +/** + * @author Rich Tibbett / https://github.com/richtr + * @author mrdoob / http://mrdoob.com/ + * @author Tony Parisi / http://www.tonyparisi.com/ + * @author Takahiro / https://github.com/takahirox + * @author Don McCurdy / https://www.donmccurdy.com + */ + +THREE.GLTF2Loader = ( function () { + + function GLTF2Loader( manager ) { + + this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager; + + } + + GLTF2Loader.prototype = { + + constructor: GLTF2Loader, + + load: function ( url, onLoad, onProgress, onError ) { + + var scope = this; + + var path = this.path && ( typeof this.path === "string" ) ? this.path : THREE.Loader.prototype.extractUrlBase( url ); + + var loader = new THREE.FileLoader( scope.manager ); + + loader.setResponseType( 'arraybuffer' ); + + loader.load( url, function ( data ) { + + scope.parse( data, onLoad, path ); + + }, onProgress, onError ); + + }, + + setCrossOrigin: function ( value ) { + + this.crossOrigin = value; + + }, + + setPath: function ( value ) { + + this.path = value; + + }, + + parse: function ( data, callback, path ) { + + var content; + var extensions = {}; + + var magic = convertUint8ArrayToString( new Uint8Array( data, 0, 4 ) ); + + if ( magic === BINARY_EXTENSION_HEADER_DEFAULTS.magic ) { + + extensions[ EXTENSIONS.KHR_BINARY_GLTF ] = new GLTFBinaryExtension( data ); + content = extensions[ EXTENSIONS.KHR_BINARY_GLTF ].content; + + } else { + + content = convertUint8ArrayToString( new Uint8Array( data ) ); + + } + + var json = JSON.parse( content ); + + if ( json.extensionsUsed && json.extensionsUsed.indexOf( EXTENSIONS.KHR_MATERIALS_COMMON ) >= 0 ) { + + extensions[ EXTENSIONS.KHR_MATERIALS_COMMON ] = new GLTFMaterialsCommonExtension( json ); + + } + + console.time( 'GLTF2Loader' ); + + var parser = new GLTFParser( json, extensions, { + + path: path || this.path, + crossOrigin: this.crossOrigin + + } ); + + parser.parse( function ( scene, scenes, cameras, animations ) { + + console.timeEnd( 'GLTF2Loader' ); + + var glTF = { + "scene": scene, + "scenes": scenes, + "cameras": cameras, + "animations": animations + }; + + callback( glTF ); + + } ); + + } + + }; + + /* GLTFREGISTRY */ + + function GLTFRegistry() { + + var objects = {}; + + return { + + get: function ( key ) { + + return objects[ key ]; + + }, + + add: function ( key, object ) { + + objects[ key ] = object; + + }, + + remove: function ( key ) { + + delete objects[ key ]; + + }, + + removeAll: function () { + + objects = {}; + + }, + + update: function ( scene, camera ) { + + // update scene graph + + scene.updateMatrixWorld(); + + // update camera matrices and frustum + + camera.updateMatrixWorld(); + camera.matrixWorldInverse.getInverse( camera.matrixWorld ); + + for ( var name in objects ) { + + var object = objects[ name ]; + + if ( object.update ) { + + object.update( scene, camera ); + + } + + } + + } + + }; + + } + + /* GLTFSHADERS */ + + GLTF2Loader.Shaders = new GLTFRegistry(); + + /* GLTFSHADER */ + + function GLTFShader( targetNode, allNodes ) { + + var boundUniforms = {}; + + // bind each uniform to its source node + + var uniforms = targetNode.material.uniforms; + + for ( var uniformId in uniforms ) { + + var uniform = uniforms[ uniformId ]; + + if ( uniform.semantic ) { + + var sourceNodeRef = uniform.node; + + var sourceNode = targetNode; + + if ( sourceNodeRef ) { + + sourceNode = allNodes[ sourceNodeRef ]; + + } + + boundUniforms[ uniformId ] = { + semantic: uniform.semantic, + sourceNode: sourceNode, + targetNode: targetNode, + uniform: uniform + }; + + } + + } + + this.boundUniforms = boundUniforms; + this._m4 = new THREE.Matrix4(); + + } + + // Update - update all the uniform values + GLTFShader.prototype.update = function ( scene, camera ) { + + var boundUniforms = this.boundUniforms; + + for ( var name in boundUniforms ) { + + var boundUniform = boundUniforms[ name ]; + + switch ( boundUniform.semantic ) { + + case "MODELVIEW": + + var m4 = boundUniform.uniform.value; + m4.multiplyMatrices( camera.matrixWorldInverse, boundUniform.sourceNode.matrixWorld ); + break; + + case "MODELVIEWINVERSETRANSPOSE": + + var m3 = boundUniform.uniform.value; + this._m4.multiplyMatrices( camera.matrixWorldInverse, boundUniform.sourceNode.matrixWorld ); + m3.getNormalMatrix( this._m4 ); + break; + + case "PROJECTION": + + var m4 = boundUniform.uniform.value; + m4.copy( camera.projectionMatrix ); + break; + + case "JOINTMATRIX": + + var m4v = boundUniform.uniform.value; + + for ( var mi = 0; mi < m4v.length; mi ++ ) { + + // So it goes like this: + // SkinnedMesh world matrix is already baked into MODELVIEW; + // transform joints to local space, + // then transform using joint's inverse + m4v[ mi ] + .getInverse( boundUniform.sourceNode.matrixWorld ) + .multiply( boundUniform.targetNode.skeleton.bones[ mi ].matrixWorld ) + .multiply( boundUniform.targetNode.skeleton.boneInverses[ mi ] ) + .multiply( boundUniform.targetNode.bindMatrix ); + + } + + break; + + default : + + console.warn( "Unhandled shader semantic: " + boundUniform.semantic ); + break; + + } + + } + + }; + + /*********************************/ + /********** EXTENSIONS ***********/ + /*********************************/ + + var EXTENSIONS = { + KHR_BINARY_GLTF: 'KHR_binary_glTF', + KHR_MATERIALS_COMMON: 'KHR_materials_common' + }; + + /* MATERIALS COMMON EXTENSION */ + + function GLTFMaterialsCommonExtension( json ) { + + this.name = EXTENSIONS.KHR_MATERIALS_COMMON; + + this.lights = {}; + + var extension = ( json.extensions && json.extensions[ EXTENSIONS.KHR_MATERIALS_COMMON ] ) || {}; + var lights = extension.lights || {}; + + for ( var lightId in lights ) { + + var light = lights[ lightId ]; + var lightNode; + + var lightParams = light[ light.type ]; + var color = new THREE.Color().fromArray( lightParams.color ); + + switch ( light.type ) { + + case "directional": + lightNode = new THREE.DirectionalLight( color ); + lightNode.position.set( 0, 0, 1 ); + break; + + case "point": + lightNode = new THREE.PointLight( color ); + break; + + case "spot": + lightNode = new THREE.SpotLight( color ); + lightNode.position.set( 0, 0, 1 ); + break; + + case "ambient": + lightNode = new THREE.AmbientLight( color ); + break; + + } + + if ( lightNode ) { + + this.lights[ lightId ] = lightNode; + + } + + } + + } + + /* BINARY EXTENSION */ + + var BINARY_EXTENSION_BUFFER_NAME = 'binary_glTF'; + + var BINARY_EXTENSION_HEADER_DEFAULTS = { magic: 'glTF', version: 1, contentFormat: 0 }; + + var BINARY_EXTENSION_HEADER_LENGTH = 20; + + function GLTFBinaryExtension( data ) { + + this.name = EXTENSIONS.KHR_BINARY_GLTF; + + var headerView = new DataView( data, 0, BINARY_EXTENSION_HEADER_LENGTH ); + + var header = { + magic: convertUint8ArrayToString( new Uint8Array( data.slice( 0, 4 ) ) ), + version: headerView.getUint32( 4, true ), + length: headerView.getUint32( 8, true ), + contentLength: headerView.getUint32( 12, true ), + contentFormat: headerView.getUint32( 16, true ) + }; + + for ( var key in BINARY_EXTENSION_HEADER_DEFAULTS ) { + + var value = BINARY_EXTENSION_HEADER_DEFAULTS[ key ]; + + if ( header[ key ] !== value ) { + + throw new Error( 'Unsupported glTF-Binary header: Expected "%s" to be "%s".', key, value ); + + } + + } + + var contentArray = new Uint8Array( data, BINARY_EXTENSION_HEADER_LENGTH, header.contentLength ); + + this.header = header; + this.content = convertUint8ArrayToString( contentArray ); + this.body = data.slice( BINARY_EXTENSION_HEADER_LENGTH + header.contentLength, header.length ); + + } + + GLTFBinaryExtension.prototype.loadShader = function ( shader, bufferViews ) { + + var bufferView = bufferViews[ shader.extensions[ EXTENSIONS.KHR_BINARY_GLTF ].bufferView ]; + var array = new Uint8Array( bufferView ); + + return convertUint8ArrayToString( array ); + + }; + + GLTFBinaryExtension.prototype.loadTextureSourceUri = function ( source, bufferViews ) { + + var metadata = source.extensions[ EXTENSIONS.KHR_BINARY_GLTF ]; + var bufferView = bufferViews[ metadata.bufferView ]; + var stringData = convertUint8ArrayToString( new Uint8Array( bufferView ) ); + + return 'data:' + metadata.mimeType + ';base64,' + btoa( stringData ); + + }; + + /*********************************/ + /********** INTERNALS ************/ + /*********************************/ + + /* CONSTANTS */ + + var WEBGL_CONSTANTS = { + FLOAT: 5126, + //FLOAT_MAT2: 35674, + FLOAT_MAT3: 35675, + FLOAT_MAT4: 35676, + FLOAT_VEC2: 35664, + FLOAT_VEC3: 35665, + FLOAT_VEC4: 35666, + LINEAR: 9729, + REPEAT: 10497, + SAMPLER_2D: 35678, + TRIANGLES: 4, + LINES: 1, + UNSIGNED_BYTE: 5121, + UNSIGNED_SHORT: 5123, + + VERTEX_SHADER: 35633, + FRAGMENT_SHADER: 35632 + }; + + var WEBGL_TYPE = { + 5126: Number, + //35674: THREE.Matrix2, + 35675: THREE.Matrix3, + 35676: THREE.Matrix4, + 35664: THREE.Vector2, + 35665: THREE.Vector3, + 35666: THREE.Vector4, + 35678: THREE.Texture + }; + + var WEBGL_COMPONENT_TYPES = { + 5120: Int8Array, + 5121: Uint8Array, + 5122: Int16Array, + 5123: Uint16Array, + 5125: Uint32Array, + 5126: Float32Array + }; + + var WEBGL_FILTERS = { + 9728: THREE.NearestFilter, + 9729: THREE.LinearFilter, + 9984: THREE.NearestMipMapNearestFilter, + 9985: THREE.LinearMipMapNearestFilter, + 9986: THREE.NearestMipMapLinearFilter, + 9987: THREE.LinearMipMapLinearFilter + }; + + var WEBGL_WRAPPINGS = { + 33071: THREE.ClampToEdgeWrapping, + 33648: THREE.MirroredRepeatWrapping, + 10497: THREE.RepeatWrapping + }; + + var WEBGL_TEXTURE_FORMATS = { + 6406: THREE.AlphaFormat, + 6407: THREE.RGBFormat, + 6408: THREE.RGBAFormat, + 6409: THREE.LuminanceFormat, + 6410: THREE.LuminanceAlphaFormat + }; + + var WEBGL_TEXTURE_DATATYPES = { + 5121: THREE.UnsignedByteType, + 32819: THREE.UnsignedShort4444Type, + 32820: THREE.UnsignedShort5551Type, + 33635: THREE.UnsignedShort565Type + }; + + var WEBGL_SIDES = { + 1028: THREE.BackSide, // Culling front + 1029: THREE.FrontSide // Culling back + //1032: THREE.NoSide // Culling front and back, what to do? + }; + + var WEBGL_DEPTH_FUNCS = { + 512: THREE.NeverDepth, + 513: THREE.LessDepth, + 514: THREE.EqualDepth, + 515: THREE.LessEqualDepth, + 516: THREE.GreaterEqualDepth, + 517: THREE.NotEqualDepth, + 518: THREE.GreaterEqualDepth, + 519: THREE.AlwaysDepth + }; + + var WEBGL_BLEND_EQUATIONS = { + 32774: THREE.AddEquation, + 32778: THREE.SubtractEquation, + 32779: THREE.ReverseSubtractEquation + }; + + var WEBGL_BLEND_FUNCS = { + 0: THREE.ZeroFactor, + 1: THREE.OneFactor, + 768: THREE.SrcColorFactor, + 769: THREE.OneMinusSrcColorFactor, + 770: THREE.SrcAlphaFactor, + 771: THREE.OneMinusSrcAlphaFactor, + 772: THREE.DstAlphaFactor, + 773: THREE.OneMinusDstAlphaFactor, + 774: THREE.DstColorFactor, + 775: THREE.OneMinusDstColorFactor, + 776: THREE.SrcAlphaSaturateFactor + // The followings are not supported by Three.js yet + //32769: CONSTANT_COLOR, + //32770: ONE_MINUS_CONSTANT_COLOR, + //32771: CONSTANT_ALPHA, + //32772: ONE_MINUS_CONSTANT_COLOR + }; + + var WEBGL_TYPE_SIZES = { + 'SCALAR': 1, + 'VEC2': 2, + 'VEC3': 3, + 'VEC4': 4, + 'MAT2': 4, + 'MAT3': 9, + 'MAT4': 16 + }; + + var PATH_PROPERTIES = { + scale: 'scale', + translation: 'position', + rotation: 'quaternion' + }; + + var INTERPOLATION = { + LINEAR: THREE.InterpolateLinear, + STEP: THREE.InterpolateDiscrete + }; + + var STATES_ENABLES = { + 2884: 'CULL_FACE', + 2929: 'DEPTH_TEST', + 3042: 'BLEND', + 3089: 'SCISSOR_TEST', + 32823: 'POLYGON_OFFSET_FILL', + 32926: 'SAMPLE_ALPHA_TO_COVERAGE' + }; + + /* UTILITY FUNCTIONS */ + + function _each( object, callback, thisObj ) { + + if ( !object ) { + return Promise.resolve(); + } + + var results; + var fns = []; + + if ( Object.prototype.toString.call( object ) === '[object Array]' ) { + + results = []; + + var length = object.length; + + for ( var idx = 0; idx < length; idx ++ ) { + + var value = callback.call( thisObj || this, object[ idx ], idx ); + + if ( value ) { + + fns.push( value ); + + if ( value instanceof Promise ) { + + value.then( function( key, value ) { + + results[ idx ] = value; + + }.bind( this, key )); + + } else { + + results[ idx ] = value; + + } + + } + + } + + } else { + + results = {}; + + for ( var key in object ) { + + if ( object.hasOwnProperty( key ) ) { + + var value = callback.call( thisObj || this, object[ key ], key ); + + if ( value ) { + + fns.push( value ); + + if ( value instanceof Promise ) { + + value.then( function( key, value ) { + + results[ key ] = value; + + }.bind( this, key )); + + } else { + + results[ key ] = value; + + } + + } + + } + + } + + } + + return Promise.all( fns ).then( function() { + + return results; + + }); + + } + + function resolveURL( url, path ) { + + // Invalid URL + if ( typeof url !== 'string' || url === '' ) + return ''; + + // Absolute URL + if ( /^https?:\/\//i.test( url ) ) { + + return url; + + } + + // Data URI + if ( /^data:.*,.*$/i.test( url ) ) { + + return url; + + } + + // Relative URL + return ( path || '' ) + url; + + } + + // Avoid the String.fromCharCode.apply(null, array) shortcut, which + // throws a "maximum call stack size exceeded" error for large arrays. + function convertUint8ArrayToString( array ) { + + var s = ''; + + for ( var i = 0; i < array.length; i ++ ) { + + s += String.fromCharCode( array[ i ] ); + + } + + return s; + + } + + // Three.js seems too dependent on attribute names so globally + // replace those in the shader code + function replaceTHREEShaderAttributes( shaderText, technique ) { + + // Expected technique attributes + var attributes = {}; + + for ( var attributeId in technique.attributes ) { + + var pname = technique.attributes[ attributeId ]; + + var param = technique.parameters[ pname ]; + var atype = param.type; + var semantic = param.semantic; + + attributes[ attributeId ] = { + type: atype, + semantic: semantic + }; + + } + + // Figure out which attributes to change in technique + + var shaderParams = technique.parameters; + var shaderAttributes = technique.attributes; + var params = {}; + + for ( var attributeId in attributes ) { + + var pname = shaderAttributes[ attributeId ]; + var shaderParam = shaderParams[ pname ]; + var semantic = shaderParam.semantic; + if ( semantic ) { + + params[ attributeId ] = shaderParam; + + } + + } + + for ( var pname in params ) { + + var param = params[ pname ]; + var semantic = param.semantic; + + var regEx = new RegExp( "\\b" + pname + "\\b", "g" ); + + switch ( semantic ) { + + case "POSITION": + + shaderText = shaderText.replace( regEx, 'position' ); + break; + + case "NORMAL": + + shaderText = shaderText.replace( regEx, 'normal' ); + break; + + case 'TEXCOORD_0': + case 'TEXCOORD0': + case 'TEXCOORD': + + shaderText = shaderText.replace( regEx, 'uv' ); + break; + + case 'COLOR_0': + case 'COLOR0': + case 'COLOR': + + shaderText = shaderText.replace( regEx, 'color' ); + break; + + case "WEIGHT": + + shaderText = shaderText.replace( regEx, 'skinWeight' ); + break; + + case "JOINT": + + shaderText = shaderText.replace( regEx, 'skinIndex' ); + break; + + } + + } + + return shaderText; + + } + + function createDefaultMaterial() { + + return new THREE.MeshPhongMaterial( { + color: 0x00000, + emissive: 0x888888, + specular: 0x000000, + shininess: 0, + transparent: false, + depthTest: true, + side: THREE.FrontSide + } ); + + } + + // Deferred constructor for RawShaderMaterial types + function DeferredShaderMaterial( params ) { + + this.isDeferredShaderMaterial = true; + + this.params = params; + + } + + DeferredShaderMaterial.prototype.create = function () { + + var uniforms = THREE.UniformsUtils.clone( this.params.uniforms ); + + for ( var uniformId in this.params.uniforms ) { + + var originalUniform = this.params.uniforms[ uniformId ]; + + if ( originalUniform.value instanceof THREE.Texture ) { + + uniforms[ uniformId ].value = originalUniform.value; + uniforms[ uniformId ].value.needsUpdate = true; + + } + + uniforms[ uniformId ].semantic = originalUniform.semantic; + uniforms[ uniformId ].node = originalUniform.node; + + } + + this.params.uniforms = uniforms; + + return new THREE.RawShaderMaterial( this.params ); + + }; + + /* GLTF PARSER */ + + function GLTFParser( json, extensions, options ) { + + this.json = json || {}; + this.extensions = extensions || {}; + this.options = options || {}; + + // loader object cache + this.cache = new GLTFRegistry(); + + } + + GLTFParser.prototype._withDependencies = function ( dependencies ) { + + var _dependencies = {}; + + for ( var i = 0; i < dependencies.length; i ++ ) { + + var dependency = dependencies[ i ]; + var fnName = "load" + dependency.charAt( 0 ).toUpperCase() + dependency.slice( 1 ); + + var cached = this.cache.get( dependency ); + + if ( cached !== undefined ) { + + _dependencies[ dependency ] = cached; + + } else if ( this[ fnName ] ) { + + var fn = this[ fnName ](); + this.cache.add( dependency, fn ); + + _dependencies[ dependency ] = fn; + + } + + } + + return _each( _dependencies, function ( dependency ) { + + return dependency; + + } ); + + }; + + GLTFParser.prototype.parse = function ( callback ) { + + var json = this.json; + + // Clear the loader cache + this.cache.removeAll(); + + // Fire the callback on complete + this._withDependencies( [ + + "scenes", + "cameras", + "animations" + + ] ).then( function ( dependencies ) { + + var scene = dependencies.scenes[ json.scene ]; + + var scenes = []; + + for ( var name in dependencies.scenes ) { + + scenes.push( dependencies.scenes[ name ] ); + + } + + var cameras = []; + + for ( var name in dependencies.cameras ) { + + var camera = dependencies.cameras[ name ]; + cameras.push( camera ); + + } + + var animations = []; + + for ( var name in dependencies.animations ) { + + animations.push( dependencies.animations[ name ] ); + + } + + callback( scene, scenes, cameras, animations ); + + } ); + + }; + + GLTFParser.prototype.loadShaders = function () { + + var json = this.json; + var extensions = this.extensions; + var options = this.options; + + return this._withDependencies( [ + + "bufferViews" + + ] ).then( function ( dependencies ) { + + return _each( json.shaders, function ( shader ) { + + if ( shader.extensions && shader.extensions[ EXTENSIONS.KHR_BINARY_GLTF ] ) { + + return extensions[ EXTENSIONS.KHR_BINARY_GLTF ].loadShader( shader, dependencies.bufferViews ); + + } + + return new Promise( function ( resolve ) { + + var loader = new THREE.FileLoader(); + loader.setResponseType( 'text' ); + loader.load( resolveURL( shader.uri, options.path ), function ( shaderText ) { + + resolve( shaderText ); + + } ); + + } ); + + } ); + + } ); + + }; + + GLTFParser.prototype.loadBuffers = function () { + + var json = this.json; + var extensions = this.extensions; + var options = this.options; + + return _each( json.buffers, function ( buffer, name ) { + + if ( name === BINARY_EXTENSION_BUFFER_NAME ) { + + return extensions[ EXTENSIONS.KHR_BINARY_GLTF ].body; + + } + + if ( buffer.type === 'arraybuffer' || buffer.type === undefined ) { + + return new Promise( function ( resolve ) { + + var loader = new THREE.FileLoader(); + loader.setResponseType( 'arraybuffer' ); + loader.load( resolveURL( buffer.uri, options.path ), function ( buffer ) { + + resolve( buffer ); + + } ); + + } ); + + } else { + + console.warn( 'THREE.GLTF2Loader: ' + buffer.type + ' buffer type is not supported' ); + + } + + } ); + + }; + + GLTFParser.prototype.loadBufferViews = function () { + + var json = this.json; + + return this._withDependencies( [ + + "buffers" + + ] ).then( function ( dependencies ) { + + return _each( json.bufferViews, function ( bufferView ) { + + var arraybuffer = dependencies.buffers[ bufferView.buffer ]; + + var byteLength = bufferView.byteLength !== undefined ? bufferView.byteLength : 0; + + return arraybuffer.slice( bufferView.byteOffset, bufferView.byteOffset + byteLength ); + + } ); + + } ); + + }; + + GLTFParser.prototype.loadAccessors = function () { + + var json = this.json; + + return this._withDependencies( [ + + "bufferViews" + + ] ).then( function ( dependencies ) { + + return _each( json.accessors, function ( accessor ) { + + var arraybuffer = dependencies.bufferViews[ accessor.bufferView ]; + var itemSize = WEBGL_TYPE_SIZES[ accessor.type ]; + var TypedArray = WEBGL_COMPONENT_TYPES[ accessor.componentType ]; + + // For VEC3: itemSize is 3, elementBytes is 4, itemBytes is 12. + var elementBytes = TypedArray.BYTES_PER_ELEMENT; + var itemBytes = elementBytes * itemSize; + + // The buffer is not interleaved if the stride is the item size in bytes. + if ( accessor.byteStride && accessor.byteStride !== itemBytes ) { + + // Use the full buffer if it's interleaved. + var array = new TypedArray( arraybuffer ); + + // Integer parameters to IB/IBA are in array elements, not bytes. + var ib = new THREE.InterleavedBuffer( array, accessor.byteStride / elementBytes ); + + return new THREE.InterleavedBufferAttribute( ib, itemSize, accessor.byteOffset / elementBytes ); + + } else { + + array = new TypedArray( arraybuffer, accessor.byteOffset, accessor.count * itemSize ); + + return new THREE.BufferAttribute( array, itemSize ); + + } + + } ); + + } ); + + }; + + GLTFParser.prototype.loadTextures = function () { + + var json = this.json; + var extensions = this.extensions; + var options = this.options; + + return this._withDependencies( [ + + "bufferViews" + + ] ).then( function ( dependencies ) { + + return _each( json.textures, function ( texture ) { + + if ( texture.source ) { + + return new Promise( function ( resolve ) { + + var source = json.images[ texture.source ]; + var sourceUri = source.uri; + + if ( source.extensions && source.extensions[ EXTENSIONS.KHR_BINARY_GLTF ] ) { + + sourceUri = extensions[ EXTENSIONS.KHR_BINARY_GLTF ].loadTextureSourceUri( source, dependencies.bufferViews ); + + } + + var textureLoader = THREE.Loader.Handlers.get( sourceUri ); + + if ( textureLoader === null ) { + + textureLoader = new THREE.TextureLoader(); + + } + + textureLoader.setCrossOrigin( options.crossOrigin ); + + textureLoader.load( resolveURL( sourceUri, options.path ), function ( _texture ) { + + _texture.flipY = false; + + if ( texture.name !== undefined ) _texture.name = texture.name; + + _texture.format = texture.format !== undefined ? WEBGL_TEXTURE_FORMATS[ texture.format ] : THREE.RGBAFormat; + + if ( texture.internalFormat !== undefined && _texture.format !== WEBGL_TEXTURE_FORMATS[ texture.internalFormat ] ) { + + console.warn( 'THREE.GLTF2Loader: Three.js doesn\'t support texture internalFormat which is different from texture format. ' + + 'internalFormat will be forced to be the same value as format.' ); + + } + + _texture.type = texture.type !== undefined ? WEBGL_TEXTURE_DATATYPES[ texture.type ] : THREE.UnsignedByteType; + + if ( texture.sampler ) { + + var sampler = json.samplers[ texture.sampler ]; + + _texture.magFilter = WEBGL_FILTERS[ sampler.magFilter ] || THREE.LinearFilter; + _texture.minFilter = WEBGL_FILTERS[ sampler.minFilter ] || THREE.NearestMipMapLinearFilter; + _texture.wrapS = WEBGL_WRAPPINGS[ sampler.wrapS ] || THREE.RepeatWrapping; + _texture.wrapT = WEBGL_WRAPPINGS[ sampler.wrapT ] || THREE.RepeatWrapping; + + } + + resolve( _texture ); + + }, undefined, function () { + + resolve(); + + } ); + + } ); + + } + + } ); + + } ); + + }; + + GLTFParser.prototype.loadMaterials = function () { + + var json = this.json; + + return this._withDependencies( [ + + "shaders", + "textures" + + ] ).then( function ( dependencies ) { + + return _each( json.materials, function ( material ) { + + var materialType; + var materialValues = {}; + var materialParams = {}; + + var khr_material; + + if ( material.extensions && material.extensions[ EXTENSIONS.KHR_MATERIALS_COMMON ] ) { + + khr_material = material.extensions[ EXTENSIONS.KHR_MATERIALS_COMMON ]; + + } + + if ( khr_material ) { + + // don't copy over unused values to avoid material warning spam + var keys = [ 'ambient', 'emission', 'transparent', 'transparency', 'doubleSided' ]; + + switch ( khr_material.technique ) { + + case 'BLINN' : + case 'PHONG' : + materialType = THREE.MeshPhongMaterial; + keys.push( 'diffuse', 'specular', 'shininess' ); + break; + + case 'LAMBERT' : + materialType = THREE.MeshLambertMaterial; + keys.push( 'diffuse' ); + break; + + case 'CONSTANT' : + default : + materialType = THREE.MeshBasicMaterial; + break; + + } + + keys.forEach( function( v ) { + + if ( khr_material.values[ v ] !== undefined ) materialValues[ v ] = khr_material.values[ v ]; + + } ); + + if ( khr_material.doubleSided || materialValues.doubleSided ) { + + materialParams.side = THREE.DoubleSide; + + } + + if ( khr_material.transparent || materialValues.transparent ) { + + materialParams.transparent = true; + materialParams.opacity = ( materialValues.transparency !== undefined ) ? materialValues.transparency : 1; + + } + + } else if ( material.technique === undefined ) { + + materialType = THREE.MeshPhongMaterial; + + Object.assign( materialValues, material.values ); + + } else { + + materialType = DeferredShaderMaterial; + + var technique = json.techniques[ material.technique ]; + + materialParams.uniforms = {}; + + var program = json.programs[ technique.program ]; + + if ( program ) { + + materialParams.fragmentShader = dependencies.shaders[ program.fragmentShader ]; + + if ( ! materialParams.fragmentShader ) { + + console.warn( "ERROR: Missing fragment shader definition:", program.fragmentShader ); + materialType = THREE.MeshPhongMaterial; + + } + + var vertexShader = dependencies.shaders[ program.vertexShader ]; + + if ( ! vertexShader ) { + + console.warn( "ERROR: Missing vertex shader definition:", program.vertexShader ); + materialType = THREE.MeshPhongMaterial; + + } + + // IMPORTANT: FIX VERTEX SHADER ATTRIBUTE DEFINITIONS + materialParams.vertexShader = replaceTHREEShaderAttributes( vertexShader, technique ); + + var uniforms = technique.uniforms; + + for ( var uniformId in uniforms ) { + + var pname = uniforms[ uniformId ]; + var shaderParam = technique.parameters[ pname ]; + + var ptype = shaderParam.type; + + if ( WEBGL_TYPE[ ptype ] ) { + + var pcount = shaderParam.count; + var value; + + if ( material.values !== undefined ) value = material.values[ pname ]; + + var uvalue = new WEBGL_TYPE[ ptype ](); + var usemantic = shaderParam.semantic; + var unode = shaderParam.node; + + switch ( ptype ) { + + case WEBGL_CONSTANTS.FLOAT: + + uvalue = shaderParam.value; + + if ( pname == "transparency" ) { + + materialParams.transparent = true; + + } + + if ( value !== undefined ) { + + uvalue = value; + + } + + break; + + case WEBGL_CONSTANTS.FLOAT_VEC2: + case WEBGL_CONSTANTS.FLOAT_VEC3: + case WEBGL_CONSTANTS.FLOAT_VEC4: + case WEBGL_CONSTANTS.FLOAT_MAT3: + + if ( shaderParam && shaderParam.value ) { + + uvalue.fromArray( shaderParam.value ); + + } + + if ( value ) { + + uvalue.fromArray( value ); + + } + + break; + + case WEBGL_CONSTANTS.FLOAT_MAT2: + + // what to do? + console.warn( "FLOAT_MAT2 is not a supported uniform type" ); + break; + + case WEBGL_CONSTANTS.FLOAT_MAT4: + + if ( pcount ) { + + uvalue = new Array( pcount ); + + for ( var mi = 0; mi < pcount; mi ++ ) { + + uvalue[ mi ] = new WEBGL_TYPE[ ptype ](); + + } + + if ( shaderParam && shaderParam.value ) { + + var m4v = shaderParam.value; + uvalue.fromArray( m4v ); + + } + + if ( value ) { + + uvalue.fromArray( value ); + + } + + } else { + + if ( shaderParam && shaderParam.value ) { + + var m4 = shaderParam.value; + uvalue.fromArray( m4 ); + + } + + if ( value ) { + + uvalue.fromArray( value ); + + } + + } + + break; + + case WEBGL_CONSTANTS.SAMPLER_2D: + + if ( value !== undefined ) { + + uvalue = dependencies.textures[ value ]; + + } else if ( shaderParam.value !== undefined ) { + + uvalue = dependencies.textures[ shaderParam.value ]; + + } else { + + uvalue = null; + + } + + break; + + } + + materialParams.uniforms[ uniformId ] = { + value: uvalue, + semantic: usemantic, + node: unode + }; + + } else { + + throw new Error( "Unknown shader uniform param type: " + ptype ); + + } + + } + + var states = technique.states || {}; + var enables = states.enable || []; + var functions = states.functions || {}; + + var enableCullFace = false; + var enableDepthTest = false; + var enableBlend = false; + + for ( var i = 0, il = enables.length; i < il; i ++ ) { + + var enable = enables[ i ]; + + switch ( STATES_ENABLES[ enable ] ) { + + case 'CULL_FACE': + + enableCullFace = true; + + break; + + case 'DEPTH_TEST': + + enableDepthTest = true; + + break; + + case 'BLEND': + + enableBlend = true; + + break; + + // TODO: implement + case 'SCISSOR_TEST': + case 'POLYGON_OFFSET_FILL': + case 'SAMPLE_ALPHA_TO_COVERAGE': + + break; + + default: + + throw new Error( "Unknown technique.states.enable: " + enable ); + + } + + } + + if ( enableCullFace ) { + + materialParams.side = functions.cullFace !== undefined ? WEBGL_SIDES[ functions.cullFace ] : THREE.FrontSide; + + } else { + + materialParams.side = THREE.DoubleSide; + + } + + materialParams.depthTest = enableDepthTest; + materialParams.depthFunc = functions.depthFunc !== undefined ? WEBGL_DEPTH_FUNCS[ functions.depthFunc ] : THREE.LessDepth; + materialParams.depthWrite = functions.depthMask !== undefined ? functions.depthMask[ 0 ] : true; + + materialParams.blending = enableBlend ? THREE.CustomBlending : THREE.NoBlending; + materialParams.transparent = enableBlend; + + var blendEquationSeparate = functions.blendEquationSeparate; + + if ( blendEquationSeparate !== undefined ) { + + materialParams.blendEquation = WEBGL_BLEND_EQUATIONS[ blendEquationSeparate[ 0 ] ]; + materialParams.blendEquationAlpha = WEBGL_BLEND_EQUATIONS[ blendEquationSeparate[ 1 ] ]; + + } else { + + materialParams.blendEquation = THREE.AddEquation; + materialParams.blendEquationAlpha = THREE.AddEquation; + + } + + var blendFuncSeparate = functions.blendFuncSeparate; + + if ( blendFuncSeparate !== undefined ) { + + materialParams.blendSrc = WEBGL_BLEND_FUNCS[ blendFuncSeparate[ 0 ] ]; + materialParams.blendDst = WEBGL_BLEND_FUNCS[ blendFuncSeparate[ 1 ] ]; + materialParams.blendSrcAlpha = WEBGL_BLEND_FUNCS[ blendFuncSeparate[ 2 ] ]; + materialParams.blendDstAlpha = WEBGL_BLEND_FUNCS[ blendFuncSeparate[ 3 ] ]; + + } else { + + materialParams.blendSrc = THREE.OneFactor; + materialParams.blendDst = THREE.ZeroFactor; + materialParams.blendSrcAlpha = THREE.OneFactor; + materialParams.blendDstAlpha = THREE.ZeroFactor; + + } + + } + + } + + if ( Array.isArray( materialValues.diffuse ) ) { + + materialParams.color = new THREE.Color().fromArray( materialValues.diffuse ); + + } else if ( typeof( materialValues.diffuse ) === 'string' ) { + + materialParams.map = dependencies.textures[ materialValues.diffuse ]; + + } + + delete materialParams.diffuse; + + if ( typeof( materialValues.reflective ) === 'string' ) { + + materialParams.envMap = dependencies.textures[ materialValues.reflective ]; + + } + + if ( typeof( materialValues.bump ) === 'string' ) { + + materialParams.bumpMap = dependencies.textures[ materialValues.bump ]; + + } + + if ( Array.isArray( materialValues.emission ) ) { + + if ( materialType === THREE.MeshBasicMaterial ) { + + materialParams.color = new THREE.Color().fromArray( materialValues.emission ); + + } else { + + materialParams.emissive = new THREE.Color().fromArray( materialValues.emission ); + + } + + } else if ( typeof( materialValues.emission ) === 'string' ) { + + if ( materialType === THREE.MeshBasicMaterial ) { + + materialParams.map = dependencies.textures[ materialValues.emission ]; + + } else { + + materialParams.emissiveMap = dependencies.textures[ materialValues.emission ]; + + } + + } + + if ( Array.isArray( materialValues.specular ) ) { + + materialParams.specular = new THREE.Color().fromArray( materialValues.specular ); + + } else if ( typeof( materialValues.specular ) === 'string' ) { + + materialParams.specularMap = dependencies.textures[ materialValues.specular ]; + + } + + if ( materialValues.shininess !== undefined ) { + + materialParams.shininess = materialValues.shininess; + + } + + var _material = new materialType( materialParams ); + if ( material.name !== undefined ) _material.name = material.name; + + return _material; + + } ); + + } ); + + }; + + GLTFParser.prototype.loadMeshes = function () { + + var json = this.json; + + return this._withDependencies( [ + + "accessors", + "materials" + + ] ).then( function ( dependencies ) { + + return _each( json.meshes, function ( mesh ) { + + var group = new THREE.Object3D(); + if ( mesh.name !== undefined ) group.name = mesh.name; + + if ( mesh.extras ) group.userData = mesh.extras; + + var primitives = mesh.primitives || []; + + for ( var name in primitives ) { + + var primitive = primitives[ name ]; + + if ( primitive.mode === WEBGL_CONSTANTS.TRIANGLES || primitive.mode === undefined ) { + + var geometry = new THREE.BufferGeometry(); + + var attributes = primitive.attributes; + + for ( var attributeId in attributes ) { + + var attributeEntry = attributes[ attributeId ]; + + if ( ! attributeEntry ) return; + + var bufferAttribute = dependencies.accessors[ attributeEntry ]; + + switch ( attributeId ) { + + case 'POSITION': + geometry.addAttribute( 'position', bufferAttribute ); + break; + + case 'NORMAL': + geometry.addAttribute( 'normal', bufferAttribute ); + break; + + case 'TEXCOORD_0': + case 'TEXCOORD0': + case 'TEXCOORD': + geometry.addAttribute( 'uv', bufferAttribute ); + break; + + case 'COLOR_0': + case 'COLOR0': + case 'COLOR': + geometry.addAttribute( 'color', bufferAttribute ); + break; + + case 'WEIGHT': + geometry.addAttribute( 'skinWeight', bufferAttribute ); + break; + + case 'JOINT': + geometry.addAttribute( 'skinIndex', bufferAttribute ); + break; + + } + + } + + if ( primitive.indices ) { + + geometry.setIndex( dependencies.accessors[ primitive.indices ] ); + + } + + var material = dependencies.materials !== undefined ? dependencies.materials[ primitive.material ] : createDefaultMaterial(); + + var meshNode = new THREE.Mesh( geometry, material ); + meshNode.castShadow = true; + meshNode.name = ( name === "0" ? group.name : group.name + name ); + + if ( primitive.extras ) meshNode.userData = primitive.extras; + + group.add( meshNode ); + + } else if ( primitive.mode === WEBGL_CONSTANTS.LINES ) { + + var geometry = new THREE.BufferGeometry(); + + var attributes = primitive.attributes; + + for ( var attributeId in attributes ) { + + var attributeEntry = attributes[ attributeId ]; + + if ( ! attributeEntry ) return; + + var bufferAttribute = dependencies.accessors[ attributeEntry ]; + + switch ( attributeId ) { + + case 'POSITION': + geometry.addAttribute( 'position', bufferAttribute ); + break; + + case 'COLOR_0': + case 'COLOR0': + case 'COLOR': + geometry.addAttribute( 'color', bufferAttribute ); + break; + + } + + } + + var material = dependencies.materials[ primitive.material ]; + + var meshNode; + + if ( primitive.indices ) { + + geometry.setIndex( dependencies.accessors[ primitive.indices ] ); + + meshNode = new THREE.LineSegments( geometry, material ); + + } else { + + meshNode = new THREE.Line( geometry, material ); + + } + + meshNode.name = ( name === "0" ? group.name : group.name + name ); + + if ( primitive.extras ) meshNode.userData = primitive.extras; + + group.add( meshNode ); + + } else { + + console.warn( "Only triangular and line primitives are supported" ); + + } + + } + + return group; + + } ); + + } ); + + }; + + GLTFParser.prototype.loadCameras = function () { + + var json = this.json; + + return _each( json.cameras, function ( camera ) { + + if ( camera.type == "perspective" && camera.perspective ) { + + var yfov = camera.perspective.yfov; + var aspectRatio = camera.perspective.aspectRatio !== undefined ? camera.perspective.aspectRatio : 1; + + // According to COLLADA spec... + // aspectRatio = xfov / yfov + var xfov = yfov * aspectRatio; + + var _camera = new THREE.PerspectiveCamera( THREE.Math.radToDeg( xfov ), aspectRatio, camera.perspective.znear || 1, camera.perspective.zfar || 2e6 ); + if ( camera.name !== undefined ) _camera.name = camera.name; + + if ( camera.extras ) _camera.userData = camera.extras; + + return _camera; + + } else if ( camera.type == "orthographic" && camera.orthographic ) { + + var _camera = new THREE.OrthographicCamera( window.innerWidth / - 2, window.innerWidth / 2, window.innerHeight / 2, window.innerHeight / - 2, camera.orthographic.znear, camera.orthographic.zfar ); + if ( camera.name !== undefined ) _camera.name = camera.name; + + if ( camera.extras ) _camera.userData = camera.extras; + + return _camera; + + } + + } ); + + }; + + GLTFParser.prototype.loadSkins = function () { + + var json = this.json; + + return this._withDependencies( [ + + "accessors" + + ] ).then( function ( dependencies ) { + + return _each( json.skins, function ( skin ) { + + var bindShapeMatrix = new THREE.Matrix4(); + + if ( skin.bindShapeMatrix !== undefined ) bindShapeMatrix.fromArray( skin.bindShapeMatrix ); + + var _skin = { + bindShapeMatrix: bindShapeMatrix, + jointNames: skin.jointNames, + inverseBindMatrices: dependencies.accessors[ skin.inverseBindMatrices ] + }; + + return _skin; + + } ); + + } ); + + }; + + GLTFParser.prototype.loadAnimations = function () { + + var json = this.json; + + return this._withDependencies( [ + + "accessors", + "nodes" + + ] ).then( function ( dependencies ) { + + return _each( json.animations, function ( animation, animationId ) { + + var tracks = []; + + for ( var channelId in animation.channels ) { + + var channel = animation.channels[ channelId ]; + var sampler = animation.samplers[ channel.sampler ]; + + if ( sampler ) { + + var target = channel.target; + var name = target.id; + var input = animation.parameters !== undefined ? animation.parameters[ sampler.input ] : sampler.input; + var output = animation.parameters !== undefined ? animation.parameters[ sampler.output ] : sampler.output; + + var inputAccessor = dependencies.accessors[ input ]; + var outputAccessor = dependencies.accessors[ output ]; + + var node = dependencies.nodes[ name ]; + + if ( node ) { + + node.updateMatrix(); + node.matrixAutoUpdate = true; + + var TypedKeyframeTrack = PATH_PROPERTIES[ target.path ] === PATH_PROPERTIES.rotation + ? THREE.QuaternionKeyframeTrack + : THREE.VectorKeyframeTrack; + + var targetName = node.name ? node.name : node.uuid; + var interpolation = sampler.interpolation !== undefined ? INTERPOLATION[ sampler.interpolation ] : THREE.InterpolateLinear; + + // KeyframeTrack.optimize() will modify given 'times' and 'values' + // buffers before creating a truncated copy to keep. Because buffers may + // be reused by other tracks, make copies here. + tracks.push( new TypedKeyframeTrack( + targetName + '.' + PATH_PROPERTIES[ target.path ], + THREE.AnimationUtils.arraySlice( inputAccessor.array, 0 ), + THREE.AnimationUtils.arraySlice( outputAccessor.array, 0 ), + interpolation + ) ); + + } + + } + + } + + var name = animation.name !== undefined ? animation.name : "animation_" + animationId; + + return new THREE.AnimationClip( name, undefined, tracks ); + + } ); + + } ); + + }; + + GLTFParser.prototype.loadNodes = function () { + + var json = this.json; + var extensions = this.extensions; + var scope = this; + + return _each( json.nodes, function ( node ) { + + var matrix = new THREE.Matrix4(); + + var _node; + + if ( node.jointName ) { + + _node = new THREE.Bone(); + _node.name = node.name !== undefined ? node.name : node.jointName; + _node.jointName = node.jointName; + + } else { + + _node = new THREE.Object3D(); + if ( node.name !== undefined ) _node.name = node.name; + + } + + if ( node.extras ) _node.userData = node.extras; + + if ( node.matrix !== undefined ) { + + matrix.fromArray( node.matrix ); + _node.applyMatrix( matrix ); + + } else { + + if ( node.translation !== undefined ) { + + _node.position.fromArray( node.translation ); + + } + + if ( node.rotation !== undefined ) { + + _node.quaternion.fromArray( node.rotation ); + + } + + if ( node.scale !== undefined ) { + + _node.scale.fromArray( node.scale ); + + } + + } + + return _node; + + } ).then( function ( __nodes ) { + + return scope._withDependencies( [ + + "meshes", + "skins", + "cameras" + + ] ).then( function ( dependencies ) { + + return _each( __nodes, function ( _node, nodeId ) { + + var node = json.nodes[ nodeId ]; + + if ( node.meshes !== undefined ) { + + for ( var meshId in node.meshes ) { + + var mesh = node.meshes[ meshId ]; + var group = dependencies.meshes[ mesh ]; + + if ( group === undefined ) { + + console.warn( 'GLTF2Loader: Couldn\'t find node "' + mesh + '".' ); + continue; + + } + + for ( var childrenId in group.children ) { + + var child = group.children[ childrenId ]; + + // clone Mesh to add to _node + + var originalMaterial = child.material; + var originalGeometry = child.geometry; + var originalUserData = child.userData; + var originalName = child.name; + + var material; + + if ( originalMaterial.isDeferredShaderMaterial ) { + + originalMaterial = material = originalMaterial.create(); + + } else { + + material = originalMaterial; + + } + + switch ( child.type ) { + + case 'LineSegments': + child = new THREE.LineSegments( originalGeometry, material ); + break; + + case 'LineLoop': + child = new THREE.LineLoop( originalGeometry, material ); + break; + + case 'Line': + child = new THREE.Line( originalGeometry, material ); + break; + + default: + child = new THREE.Mesh( originalGeometry, material ); + + } + + child.castShadow = true; + child.userData = originalUserData; + child.name = originalName; + + var skinEntry; + + if ( node.skin ) { + + skinEntry = dependencies.skins[ node.skin ]; + + } + + // Replace Mesh with SkinnedMesh in library + if ( skinEntry ) { + + var getJointNode = function ( jointId ) { + + var keys = Object.keys( __nodes ); + + for ( var i = 0, il = keys.length; i < il; i ++ ) { + + var n = __nodes[ keys[ i ] ]; + + if ( n.jointName === jointId ) return n; + + } + + return null; + + }; + + var geometry = originalGeometry; + var material = originalMaterial; + + child = new THREE.SkinnedMesh( geometry, material, false ); + child.castShadow = true; + child.userData = originalUserData; + child.name = originalName; + + var bones = []; + var boneInverses = []; + + for ( var i = 0, l = skinEntry.jointNames.length; i < l; i ++ ) { + + var jointId = skinEntry.jointNames[ i ]; + var jointNode = getJointNode( jointId ); + + if ( jointNode ) { + + bones.push( jointNode ); + + var m = skinEntry.inverseBindMatrices.array; + var mat = new THREE.Matrix4().fromArray( m, i * 16 ); + boneInverses.push( mat ); + + } else { + + console.warn( "WARNING: joint: '" + jointId + "' could not be found" ); + + } + + } + + child.bind( new THREE.Skeleton( bones, boneInverses, false ), skinEntry.bindShapeMatrix ); + + var buildBoneGraph = function ( parentJson, parentObject, property ) { + + var children = parentJson[ property ]; + + if ( children === undefined ) return; + + for ( var i = 0, il = children.length; i < il; i ++ ) { + + var nodeId = children[ i ]; + var bone = __nodes[ nodeId ]; + var boneJson = json.nodes[ nodeId ]; + + if ( bone !== undefined && bone.isBone === true && boneJson !== undefined ) { + + parentObject.add( bone ); + buildBoneGraph( boneJson, bone, 'children' ); + + } + + } + + }; + + buildBoneGraph( node, child, 'skeletons' ); + + } + + _node.add( child ); + + } + + } + + } + + if ( node.camera !== undefined ) { + + var camera = dependencies.cameras[ node.camera ]; + + _node.add( camera ); + + } + + if ( node.extensions + && node.extensions[ EXTENSIONS.KHR_MATERIALS_COMMON ] + && node.extensions[ EXTENSIONS.KHR_MATERIALS_COMMON ].light ) { + + var extensionLights = extensions[ EXTENSIONS.KHR_MATERIALS_COMMON ].lights; + var light = extensionLights[ node.extensions[ EXTENSIONS.KHR_MATERIALS_COMMON ].light ]; + + _node.add( light ); + + } + + return _node; + + } ); + + } ); + + } ); + + }; + + GLTFParser.prototype.loadScenes = function () { + + var json = this.json; + + // scene node hierachy builder + + function buildNodeHierachy( nodeId, parentObject, allNodes ) { + + var _node = allNodes[ nodeId ]; + parentObject.add( _node ); + + var node = json.nodes[ nodeId ]; + + if ( node.children ) { + + var children = node.children; + + for ( var i = 0, l = children.length; i < l; i ++ ) { + + var child = children[ i ]; + buildNodeHierachy( child, _node, allNodes ); + + } + + } + + } + + return this._withDependencies( [ + + "nodes" + + ] ).then( function ( dependencies ) { + + return _each( json.scenes, function ( scene ) { + + var _scene = new THREE.Scene(); + if ( scene.name !== undefined ) _scene.name = scene.name; + + if ( scene.extras ) _scene.userData = scene.extras; + + var nodes = scene.nodes || []; + + for ( var i = 0, l = nodes.length; i < l; i ++ ) { + + var nodeId = nodes[ i ]; + buildNodeHierachy( nodeId, _scene, dependencies.nodes ); + + } + + _scene.traverse( function ( child ) { + + // Register raw material meshes with GLTF2Loader.Shaders + if ( child.material && child.material.isRawShaderMaterial ) { + + var xshader = new GLTFShader( child, dependencies.nodes ); + GLTF2Loader.Shaders.add( child.uuid, xshader ); + + } + + } ); + + return _scene; + + } ); + + } ); + + }; + + return GLTF2Loader; + +} )();
true
Other
mrdoob
three.js
edb5771db148cb6f701bae3f8f84b81c4cfb1425.json
Create GLTF2Loader fork.
examples/webgl_loader_gltf.html
@@ -95,7 +95,7 @@ </div> <script src="../build/three.js"></script> <script src="js/controls/OrbitControls.js"></script> - <script src="js/loaders/GLTFLoader.js"></script> + <script src="js/loaders/GLTF2Loader.js"></script> <script> var orbitControls = null; @@ -202,8 +202,8 @@ scene.add(ground); } - THREE.GLTFLoader.Shaders.removeAll(); // remove all previous shaders - loader = new THREE.GLTFLoader; + THREE.GLTF2Loader.Shaders.removeAll(); // remove all previous shaders + loader = new THREE.GLTF2Loader; for (var i = 0; i < extensionSelect.children.length; i++) { var child = extensionSelect.children[i]; @@ -338,7 +338,7 @@ function animate() { requestAnimationFrame( animate ); if (mixer) mixer.update(clock.getDelta()); - THREE.GLTFLoader.Shaders.update(scene, camera); + THREE.GLTF2Loader.Shaders.update(scene, camera); if (cameraIndex == 0) orbitControls.update(); render();
true
Other
mrdoob
three.js
9d72e97f9d5e1bcffd14cb9ed0763be1260731e4.json
Fix Sprite raycast intersection distance The existing code used the distance between the sprite and the closest point on the ray. However, this is inconsistent with both the documentation and other objects, which return the distance between the intersection and the ray origin. The new code is similar to the Point raycast implementation. The closest point on the ray is saved to `intersectionPoint`. An intersection object is created if the following conditions are met: 1. The (squared) distance between `intersectionPoint` and the sprite position is less than the (squared) sprite size. 2. The distance between `intersectionPoint` and the ray origin is within the `near` and `far` bounds.
src/objects/Sprite.js
@@ -25,25 +25,25 @@ Sprite.prototype = Object.assign( Object.create( Object3D.prototype ), { raycast: ( function () { + var intersectPoint = new Vector3(); var matrixPosition = new Vector3(); return function raycast( raycaster, intersects ) { matrixPosition.setFromMatrixPosition( this.matrixWorld ); - - var distanceSq = raycaster.ray.distanceSqToPoint( matrixPosition ); + raycaster.ray.closestPointToPoint( matrixPosition, intersectPoint ); var guessSizeSq = this.scale.x * this.scale.y / 4; - if ( distanceSq > guessSizeSq ) { + if ( matrixPosition.distanceToSquared( intersectPoint ) > guessSizeSq ) return; - return; + var distance = raycaster.ray.origin.distanceTo( intersectPoint ); - } + if ( distance < raycaster.near || distance > raycaster.far ) return; intersects.push( { - distance: Math.sqrt( distanceSq ), - point: this.position, + distance: distance, + point: intersectPoint.clone(), face: null, object: this
false
Other
mrdoob
three.js
f9ea222f1daf8460bff0722b6ad4b6554a85dc2f.json
Fix syntax error on older builds of IE11 #11440
src/loaders/BufferGeometryLoader.js
@@ -93,7 +93,7 @@ Object.assign( BufferGeometryLoader.prototype, { var TYPED_ARRAYS = { Int8Array: Int8Array, Uint8Array: Uint8Array, - Uint8ClampedArray: Uint8ClampedArray, + Uint8ClampedArray: typeof Uint8ClampedArray !== 'undefined' ? Uint8ClampedArray : Uint8Array, Int16Array: Int16Array, Uint16Array: Uint16Array, Int32Array: Int32Array,
false
Other
mrdoob
three.js
8743685a9556f13dbfdb7028f885ab844ce3b891.json
Optimize Ray.applyMatrix4 performance
src/math/Ray.js
@@ -515,10 +515,8 @@ Object.assign( Ray.prototype, { applyMatrix4: function ( matrix4 ) { - this.direction.add( this.origin ).applyMatrix4( matrix4 ); this.origin.applyMatrix4( matrix4 ); - this.direction.sub( this.origin ); - this.direction.normalize(); + this.direction.transformDirection( matrix4 ); return this;
false
Other
mrdoob
three.js
8f1a4323de3b53700e6cd01d1e9aa25011ff8726.json
Fix renderer.render check camera bug
src/renderers/WebGLRenderer.js
@@ -1082,8 +1082,7 @@ function WebGLRenderer( parameters ) { // Rendering this.render = function ( scene, camera, renderTarget, forceClear ) { - - if ( camera !== undefined && camera.isCamera !== true ) { + if ( ! ( camera && camera.isCamera ) ) { console.error( 'THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.' ); return;
false
Other
mrdoob
three.js
e0f84b07ac779bfb70227270532306d4296e9625.json
Fix geometry.mergeMesh determine mesh bug
src/core/Geometry.js
@@ -820,7 +820,7 @@ Object.assign( Geometry.prototype, EventDispatcher.prototype, { mergeMesh: function ( mesh ) { - if ( ( mesh && mesh.isMesh ) === false ) { + if ( !mesh || !mesh.isMesh ) { console.error( 'THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh ); return;
false
Other
mrdoob
three.js
9de93ad036e544591c2747285c953d502dd33c36.json
remove debug code
src/renderers/WebGLRenderer.js
@@ -2677,7 +2677,7 @@ function WebGLRenderer( parameters ) { state.scissor( _currentScissor ); state.setScissorTest( _currentScissorTest ); - !window.xx && state.viewport( _currentViewport ); + state.viewport( _currentViewport ); if ( isCube ) {
false
Other
mrdoob
three.js
ee87cc5c239c4286f558d5be1c0b30871bec78a2.json
Update morph of GLTF2Loader
examples/js/loaders/GLTF2Loader.js
@@ -2161,16 +2161,19 @@ THREE.GLTF2Loader = ( function () { var targets = primitive.targets; var morphAttributes = geometry.morphAttributes; + morphAttributes.position = []; + morphAttributes.normal = []; + + material.morphTargets = true; + for ( var i = 0, il = targets.length; i < il; i ++ ) { var target = targets[ i ]; var attributeName = 'morphTarget' + i; - if ( target.POSITION !== undefined ) { - - material.morphTargets = true; + var positionAttribute, normalAttribute; - if ( morphAttributes.position === undefined ) morphAttributes.position = []; + if ( target.POSITION !== undefined ) { // Three.js morph formula is // position @@ -2186,39 +2189,41 @@ THREE.GLTF2Loader = ( function () { // So morphTarget value will depend on mesh's position, then cloning attribute // for the case if attribute is shared among two or more meshes. - var attribute = dependencies.accessors[ target.POSITION ].clone(); - attribute.name = attributeName; + positionAttribute = dependencies.accessors[ target.POSITION ].clone(); var position = geometry.attributes.position; - for ( var j = 0, jl = attribute.array.length; j < jl; j ++ ) { + for ( var j = 0, jl = positionAttribute.array.length; j < jl; j ++ ) { - attribute.array[ j ] += position.array[ j ]; + positionAttribute.array[ j ] += position.array[ j ]; } - morphAttributes.position.push( attribute ); + } else { + + // Copying the original position not to affect the final position. + // See the formula above. + positionAttribute = geometry.attributes.position.clone(); } if ( target.NORMAL !== undefined ) { material.morphNormals = true; - if ( morphAttributes.normal === undefined ) morphAttributes.normal = []; - // see target.POSITION's comment - var attribute = dependencies.accessors[ target.NORMAL ].clone(); - attribute.name = attributeName; + normalAttribute = dependencies.accessors[ target.NORMAL ].clone(); var normal = geometry.attributes.normal; - for ( var j = 0, jl = attribute.array.length; j < jl; j ++ ) { + for ( var j = 0, jl = normalAttribute.array.length; j < jl; j ++ ) { - attribute.array[ j ] += normal.array[ j ]; + normalAttribute.array[ j ] += normal.array[ j ]; } - morphAttributes.normal.push( attribute ); + } else { + + normalAttribute = geometry.attributes.normal.clone(); } @@ -2227,6 +2232,12 @@ THREE.GLTF2Loader = ( function () { } + positionAttribute.name = attributeName; + normalAttribute.name = attributeName; + + morphAttributes.position.push( positionAttribute ); + morphAttributes.normal.push( normalAttribute ); + } meshNode.updateMorphTargets();
false
Other
mrdoob
three.js
ebc6324710adc5657855b27a39beb9bbd89237fb.json
Remove unnecessary lines
examples/js/loaders/FBXLoader2.js
@@ -1516,31 +1516,13 @@ var PoseNode = BindPoseNode.subNodes.PoseNode; var worldMatrices = new Map(); - if ( Array.isArray( PoseNode ) ) { + for ( var PoseNodeIndex = 0, PoseNodeLength = PoseNode.length; PoseNodeIndex < PoseNodeLength; ++ PoseNodeIndex ) { - for ( var PoseNodeIndex = 0, PoseNodeLength = PoseNode.length; PoseNodeIndex < PoseNodeLength; ++ PoseNodeIndex ) { + var node = PoseNode[ PoseNodeIndex ]; - var node = PoseNode[ PoseNodeIndex ]; + var rawMatWrd = parseMatrixArray( node.subNodes.Matrix.properties.a ); - var rawMatWrd = parseMatrixArray( node.subNodes.Matrix.properties.a ); - - worldMatrices.set( parseInt( node.id ), rawMatWrd ); - - } - - } else { - - var keys = Object.keys( PoseNode ); - - for ( var i = 0, il = keys.length; i < il; i++ ) { - - var node = PoseNode[ keys[ i ] ]; - - var rawMatWrd = parseMatrixArray( node.subNodes.Matrix.properties.a ); - - worldMatrices.set( parseInt( node.id ), rawMatWrd ); - - } + worldMatrices.set( parseInt( node.id ), rawMatWrd ); } @@ -4047,10 +4029,6 @@ properties[ node.name ] = value; - // If child node's name is Node, this node's id is set to child node's Node value. - // This follows TextParser manner. - if ( node.name === 'Node' ) id = value; - } continue;
false
Other
mrdoob
three.js
322ff6444e7332bbdc35f7d506ebfa3688ff2f36.json
Support FBX Binary format
examples/js/loaders/FBXLoader2.js
@@ -1,8 +1,9 @@ /** * @author Kyle-Larson https://github.com/Kyle-Larson + * @author Takahiro https://github.com/takahirox * * Loader loads FBX file and generates Group representing FBX scene. - * Requires FBX file to be >= 7.0 and in ASCII format. + * Requires FBX file to be >= 7.0 and in ASCII or to be any version in Binary format. * * Supports: * Mesh Generation (Positional Data) @@ -35,7 +36,7 @@ Object.assign( THREE.FBXLoader.prototype, { /** - * Loads an ASCII FBX file from URL and parses into a THREE.Group. + * Loads an ASCII/Binary FBX file from URL and parses into a THREE.Group. * THREE.Group will have an animations property of AnimationClips * of the different animations exported with the FBX. * @param {string} url - URL of the FBX file. @@ -52,11 +53,12 @@ resourceDirectory = resourceDirectory.join( '/' ) + '/'; var loader = new THREE.FileLoader( this.manager ); - loader.load( url, function ( text ) { + loader.setResponseType( 'arraybuffer' ); + loader.load( url, function ( buffer ) { try { - var scene = self.parse( text, resourceDirectory ); + var scene = self.parse( buffer, resourceDirectory ); onLoad( scene ); @@ -77,38 +79,50 @@ }, /** - * Parses an ASCII FBX file and returns a THREE.Group. + * Parses an ASCII/Binary FBX file and returns a THREE.Group. * THREE.Group will have an animations property of AnimationClips * of the different animations within the FBX file. - * @param {string} FBXText - Contents of FBX file to parse. + * @param {ArrayBuffer} FBXBuffer - Contents of FBX file to parse. * @param {string} resourceDirectory - Directory to load external assets (e.g. textures ) from. * @returns {THREE.Group} */ - parse: function ( FBXText, resourceDirectory ) { + parse: function ( FBXBuffer, resourceDirectory ) { - if ( ! isFbxFormatASCII( FBXText ) ) { + var FBXTree; - throw new Error( 'FBXLoader: FBX Binary format not supported.' ); - self.manager.itemError( url ); - return; + if ( isFbxFormatBinary( FBXBuffer ) ) { - //TODO: Support Binary parsing. Hopefully in the future, - //we call var FBXTree = new BinaryParser().parse( FBXText ); + FBXTree = new BinaryParser().parse( FBXBuffer ); - } + } else { - if ( getFbxVersion( FBXText ) < 7000 ) { + var FBXText = convertArrayBufferToString( FBXBuffer ); - throw new Error( 'FBXLoader: FBX version not supported for file at ' + url + ', FileVersion: ' + getFbxVersion( text ) ); - self.manager.itemError( url ); - return; + if ( ! isFbxFormatASCII( FBXText ) ) { + + throw new Error( 'FBXLoader: Unknown format.' ); + self.manager.itemError( url ); + return; + + } + + if ( getFbxVersion( FBXText ) < 7000 ) { + + throw new Error( 'FBXLoader: FBX version not supported for file at ' + url + ', FileVersion: ' + getFbxVersion( FBXText ) ); + self.manager.itemError( url ); + return; + + } + + FBXTree = new TextParser().parse( FBXText ); } - var FBXTree = new TextParser().parse( FBXText ); + console.log( FBXTree ); var connections = parseConnections( FBXTree ); - var textures = parseTextures( FBXTree, new THREE.TextureLoader( this.manager ).setPath( resourceDirectory ) ); + var images = parseImages( FBXTree ); + var textures = parseTextures( FBXTree, new THREE.TextureLoader( this.manager ).setPath( resourceDirectory ), images, connections ); var materials = parseMaterials( FBXTree, textures, connections ); var deformers = parseDeformers( FBXTree, connections ); var geometryMap = parseGeometries( FBXTree, connections, deformers ); @@ -174,12 +188,97 @@ } + /** + * Parses map of images referenced in FBXTree. + * @param {{Objects: {subNodes: {Texture: Object.<string, FBXTextureNode>}}}} FBXTree + * @returns {Map<number, string(image blob URL)>} + */ + function parseImages( FBXTree ) { + + /** + * @type {Map<number, string(image blob URL)>} + */ + var imageMap = new Map(); + + if ( 'Video' in FBXTree.Objects.subNodes ) { + + var videoNodes = FBXTree.Objects.subNodes.Video; + + for ( var nodeID in videoNodes ) { + + var videoNode = videoNodes[ nodeID ]; + + // raw image data is in videoNode.properties.Content + if ( 'Content' in videoNode.properties ) { + + var image = parseImage( videoNodes[ nodeID ] ); + imageMap.set( parseInt( nodeID ), image ); + + } + + } + + } + + return imageMap; + + } + + /** + * @param {videoNode} videoNode - Node to get texture image information from. + * @returns {string} - image blob URL + */ + function parseImage( videoNode ) { + + var buffer = videoNode.properties.Content; + var array = new Uint8Array( buffer ); + var fileName = videoNode.properties.RelativeFilename || videoNode.properties.Filename; + var extension = fileName.slice( fileName.lastIndexOf( '.' ) + 1 ).toLowerCase(); + + var type; + + switch ( extension ) { + + case 'bmp': + + type = 'image/bmp'; + break; + + case 'jpg': + + type = 'image/jpeg'; + break; + + case 'png': + + type = 'image/png'; + break; + + case 'tif': + + type = 'image/tiff'; + break; + + default: + + console.warn( 'FBXLoader: No support image type ' + extension ); + return; + + } + + return window.URL.createObjectURL( new Blob( [ array ], { type: type } ) ); + + } + /** * Parses map of textures referenced in FBXTree. * @param {{Objects: {subNodes: {Texture: Object.<string, FBXTextureNode>}}}} FBXTree + * @param {THREE.TextureLoader} loader + * @param {Map<number, string(image blob URL)>} imageMap + * @param {Map<number, {parents: {ID: number, relationship: string}[], children: {ID: number, relationship: string}[]}>} connections * @returns {Map<number, THREE.Texture>} */ - function parseTextures( FBXTree, loader ) { + function parseTextures( FBXTree, loader, imageMap, connections ) { /** * @type {Map<number, THREE.Texture>} @@ -191,7 +290,7 @@ var textureNodes = FBXTree.Objects.subNodes.Texture; for ( var nodeID in textureNodes ) { - var texture = parseTexture( textureNodes[ nodeID ], loader ); + var texture = parseTexture( textureNodes[ nodeID ], loader, imageMap, connections ); textureMap.set( parseInt( nodeID ), texture ); } @@ -204,30 +303,69 @@ /** * @param {textureNode} textureNode - Node to get texture information from. + * @param {THREE.TextureLoader} loader + * @param {Map<number, string(image blob URL)>} imageMap + * @param {Map<number, {parents: {ID: number, relationship: string}[], children: {ID: number, relationship: string}[]}>} connections * @returns {THREE.Texture} */ - function parseTexture( textureNode, loader ) { + function parseTexture( textureNode, loader, imageMap, connections ) { var FBX_ID = textureNode.id; + var name = textureNode.name; + + var fileName; + var filePath = textureNode.properties.FileName; - var split = filePath.split( /[\\\/]/ ); - if ( split.length > 0 ) { + var relativeFilePath = textureNode.properties.RelativeFilename; + + var children = connections.get( FBX_ID ).children; + + if ( children !== undefined && children.length > 0 && imageMap.has( children[ 0 ].ID ) ) { + + fileName = imageMap.get( children[ 0 ].ID ); - var fileName = split[ split.length - 1 ]; + } else if ( relativeFilePath !== undefined && relativeFilePath[ 0 ] !== '/' && + relativeFilePath.match( /^[a-zA-Z]:/ ) === null ) { + + // use textureNode.properties.RelativeFilename + // if it exists and it doesn't seem an absolute path + + fileName = relativeFilePath; } else { - var fileName = filePath; + var split = filePath.split( /[\\\/]/ ); + + if ( split.length > 0 ) { + + fileName = split[ split.length - 1 ]; + + } else { + + fileName = filePath; + + } + + } + + var currentPath = loader.path; + + if ( fileName.indexOf( 'blob:' ) === 0 ) { + + loader.setPath( undefined ); } + /** * @type {THREE.Texture} */ var texture = loader.load( fileName ); texture.name = name; texture.FBX_ID = FBX_ID; + loader.setPath( currentPath ); + return texture; } @@ -284,6 +422,7 @@ var parameters = parseParameters( materialNode.properties, textureMap, children ); var material; + switch ( type ) { case 'phong': @@ -363,15 +502,20 @@ var relationship = childrenRelationships[ childrenRelationshipsIndex ]; var type = relationship.relationship; + switch ( type ) { + case "DiffuseColor": case " \"DiffuseColor": parameters.map = textureMap.get( relationship.ID ); break; case " \"AmbientColor": case " \"Bump": case " \"EmissiveColor": + case "AmbientColor": + case "Bump": + case "EmissiveColor": default: console.warn( 'Unknown texture application of type ' + type + ', skipping texture' ); break; @@ -694,9 +838,21 @@ if ( endOfFace ) { var face = new Face(); - var materials = getData( polygonVertexIndex, polygonIndex, vertexIndex, materialInfo ); face.genTrianglesFromVertices( faceVertexBuffer ); - face.materialIndex = materials[ 0 ]; + + if ( materialInfo !== undefined ) { + + var materials = getData( polygonVertexIndex, polygonIndex, vertexIndex, materialInfo ); + face.materialIndex = materials[ 0 ]; + + } else { + + // Seems like some models don't have materialInfo(subNodes.LayerElementMaterial). + // Set 0 in such a case. + face.materialIndex = 0; + + } + geometry.faces.push( face ); faceVertexBuffer = []; polygonIndex ++; @@ -1153,9 +1309,14 @@ if ( subDeformer ) { + var model2 = model; model = new THREE.Bone(); deformer.bones[ subDeformer.index ] = model; + // seems like we need this not to make non-connected bone, maybe? + // TODO: confirm + if ( model2 !== null ) model.add( model2 ); + } } @@ -1355,13 +1516,31 @@ var PoseNode = BindPoseNode.subNodes.PoseNode; var worldMatrices = new Map(); - for ( var PoseNodeIndex = 0, PoseNodeLength = PoseNode.length; PoseNodeIndex < PoseNodeLength; ++ PoseNodeIndex ) { + if ( Array.isArray( PoseNode ) ) { + + for ( var PoseNodeIndex = 0, PoseNodeLength = PoseNode.length; PoseNodeIndex < PoseNodeLength; ++ PoseNodeIndex ) { + + var node = PoseNode[ PoseNodeIndex ]; + + var rawMatWrd = parseMatrixArray( node.subNodes.Matrix.properties.a ); + + worldMatrices.set( parseInt( node.id ), rawMatWrd ); + + } + + } else { + + var keys = Object.keys( PoseNode ); - var node = PoseNode[ PoseNodeIndex ]; + for ( var i = 0, il = keys.length; i < il; i++ ) { - var rawMatWrd = parseMatrixArray( node.subNodes.Matrix.properties.a ); + var node = PoseNode[ keys[ i ] ]; - worldMatrices.set( parseInt( node.id ), rawMatWrd ); + var rawMatWrd = parseMatrixArray( node.subNodes.Matrix.properties.a ); + + worldMatrices.set( parseInt( node.id ), rawMatWrd ); + + } } @@ -1928,6 +2107,10 @@ if ( nodeID.match( /\d+/ ) ) { var animationCurve = parseAnimationCurve( rawCurves[ nodeID ] ); + + // seems like this check would be necessary? + if ( ! connections.has( animationCurve.id ) ) continue; + animationCurves.push( animationCurve ); var firstParentConn = connections.get( animationCurve.id ).parents[ 0 ]; @@ -3724,203 +3907,980 @@ } ); - function FBXTree() {} + // Binary format specification: + // https://code.blender.org/2013/08/fbx-binary-file-format-specification/ + // https://wiki.rogiken.org/specifications/file-format/fbx/ (more detail but Japanese) + function BinaryParser() {} - Object.assign( FBXTree.prototype, { + Object.assign( BinaryParser.prototype, { - add: function ( key, val ) { + /** + * Parses binary data and builds FBXTree as much compatible as possible with the one built by TextParser. + * @param {ArrayBuffer} buffer + * @returns {THREE.FBXTree} + */ + parse: function ( buffer ) { - this[ key ] = val; + var reader = new BinaryReader( buffer ); + reader.skip( 23 ); // skip magic 23 bytes - }, + var version = reader.getUint32(); - searchConnectionParent: function ( id ) { + console.log( 'FBX binary version: ' + version ); - if ( this.__cache_search_connection_parent === undefined ) { + var allNodes = new FBXTree(); - this.__cache_search_connection_parent = []; + while ( ! this.endOfContent( reader ) ) { + + var node = this.parseNode( reader, version ); + if ( node !== null ) allNodes.add( node.name, node ); } - if ( this.__cache_search_connection_parent[ id ] !== undefined ) { + return allNodes; - return this.__cache_search_connection_parent[ id ]; + }, + + /** + * Checks if reader has reached the end of content. + * @param {BinaryReader} reader + * @returns {boolean} + */ + endOfContent: function( reader ) { + + // footer size: 160bytes + 16-byte alignment padding + // - 16bytes: magic + // - padding til 16-byte alignment + // (seems like some exporters embed fixed 15bytes?) + // - 4bytes: magic + // - 4bytes: version + // - 120bytes: zero + // - 16bytes: magic + if ( reader.size() % 16 === 0 ) { + + return ( ( reader.getOffset() + 160 + 15 ) & ~0xf ) >= reader.size(); } else { - this.__cache_search_connection_parent[ id ] = []; + return reader.getOffset() + 160 + 15 >= reader.size(); } - var conns = this.Connections.properties.connections; + }, - var results = []; - for ( var i = 0; i < conns.length; ++ i ) { + /** + * Parses Node as much compatible as possible with the one parsed by TextParser + * TODO: could be optimized more? + * @param {BinaryReader} reader + * @param {number} version + * @returns {Object} - Returns an Object as node, or null if NULL-record. + */ + parseNode: function ( reader, version ) { - if ( conns[ i ][ 0 ] == id ) { + // The first three data sizes depends on version. + var endOffset = ( version >= 7500 ) ? reader.getUint64() : reader.getUint32(); + var numProperties = ( version >= 7500 ) ? reader.getUint64() : reader.getUint32(); + var propertyListLen = ( version >= 7500 ) ? reader.getUint64() : reader.getUint32(); + var nameLen = reader.getUint8(); + var name = reader.getString( nameLen ); - // 0 means scene root - var res = conns[ i ][ 1 ] === 0 ? - 1 : conns[ i ][ 1 ]; - results.push( res ); + // Regards this node as NULL-record if endOffset is zero + if ( endOffset === 0 ) return null; - } + var propertyList = []; + + for ( var i = 0; i < numProperties; i ++ ) { + + propertyList.push( this.parseProperty( reader ) ); } - if ( results.length > 0 ) { + // Regards the first three elements in propertyList as id, attrName, and attrType + var id = propertyList.length > 0 ? propertyList[ 0 ] : ''; + var attrName = propertyList.length > 1 ? propertyList[ 1 ] : ''; + var attrType = propertyList.length > 2 ? propertyList[ 2 ] : ''; - append( this.__cache_search_connection_parent[ id ], results ); - return results; + var subNodes = {}; + var properties = {}; - } else { + var isSingleProperty = false; - this.__cache_search_connection_parent[ id ] = [ - 1 ]; - return [ - 1 ]; + // if this node represents just a single property + // like (name, 0) set or (name2, [0, 1, 2]) set of {name: 0, name2: [0, 1, 2]} + if ( numProperties === 1 && reader.getOffset() === endOffset ) { + + isSingleProperty = true; } - }, + while ( endOffset > reader.getOffset() ) { - searchConnectionChildren: function ( id ) { + var node = this.parseNode( reader, version ); - if ( this.__cache_search_connection_children === undefined ) { + if ( node === null ) continue; - this.__cache_search_connection_children = []; + // special case: child node is single property + if ( node.singleProperty === true ) { - } + var value = node.propertyList[ 0 ]; - if ( this.__cache_search_connection_children[ id ] !== undefined ) { + if ( Array.isArray( value ) ) { - return this.__cache_search_connection_children[ id ]; + // node represents + // Vertices: *3 { + // a: 0.01, 0.02, 0.03 + // } + // of text format here. - } else { + node.properties[ node.name ] = node.propertyList[ 0 ]; + subNodes[ node.name ] = node; - this.__cache_search_connection_children[ id ] = []; + // Later phase expects single property array is in node.properties.a as String. + // TODO: optimize + node.properties.a = value.toString(); - } + } else { - var conns = this.Connections.properties.connections; + // node represents + // Version: 100 + // of text format here. - var res = []; - for ( var i = 0; i < conns.length; ++ i ) { + properties[ node.name ] = value; - if ( conns[ i ][ 1 ] == id ) { + // If child node's name is Node, this node's id is set to child node's Node value. + // This follows TextParser manner. + if ( node.name === 'Node' ) id = value; - // 0 means scene root - res.push( conns[ i ][ 0 ] === 0 ? - 1 : conns[ i ][ 0 ] ); - // there may more than one kid, then search to the end + } + + continue; } - } + // special case: connections + if ( name === 'Connections' && node.name === 'C' ) { - if ( res.length > 0 ) { + var array = []; - append( this.__cache_search_connection_children[ id ], res ); - return res; + // node.propertyList would be like + // ["OO", 111264976, 144038752, "d|x"] (?, from, to, additional values) + for ( var i = 1, il = node.propertyList.length; i < il; i ++ ) { - } else { + array[ i - 1 ] = node.propertyList[ i ]; - this.__cache_search_connection_children[ id ] = [ ]; - return [ ]; + } - } + if ( properties.connections === undefined ) { - }, + properties.connections = []; - searchConnectionType: function ( id, to ) { + } - var key = id + ',' + to; // TODO: to hash - if ( this.__cache_search_connection_type === undefined ) { + properties.connections.push( array ); - this.__cache_search_connection_type = {}; + continue; - } + } - if ( this.__cache_search_connection_type[ key ] !== undefined ) { + // special case: child node is Properties\d+ + if ( node.name.match( /^Properties\d+$/ ) ) { - return this.__cache_search_connection_type[ key ]; + // move child node's properties to this node. - } else { + var keys = Object.keys( node.properties ); - this.__cache_search_connection_type[ key ] = ''; + for ( var i = 0, il = keys.length; i < il; i ++ ) { - } + var key = keys[ i ]; + properties[ key ] = node.properties[ key ]; - var conns = this.Connections.properties.connections; + } - for ( var i = 0; i < conns.length; ++ i ) { + continue; - if ( conns[ i ][ 0 ] == id && conns[ i ][ 1 ] == to ) { + } - // 0 means scene root - this.__cache_search_connection_type[ key ] = conns[ i ][ 2 ]; - return conns[ i ][ 2 ]; + // special case: properties + if ( name.match( /^Properties\d+$/ ) && node.name === 'P' ) { - } + var innerPropName = node.propertyList[ 0 ]; + var innerPropType1 = node.propertyList[ 1 ]; + var innerPropType2 = node.propertyList[ 2 ]; + var innerPropFlag = node.propertyList[ 3 ]; + var innerPropValue; - } + if ( innerPropName.indexOf( 'Lcl ' ) === 0 ) innerPropName = innerPropName.replace( 'Lcl ', 'Lcl_' ); + if ( innerPropType1.indexOf( 'Lcl ' ) === 0 ) innerPropType1 = innerPropType1.replace( 'Lcl ', 'Lcl_' ); - this.__cache_search_connection_type[ id ] = null; - return null; + if ( innerPropType1 === 'ColorRGB' || innerPropType1 === 'Vector' || + innerPropType1 === 'Vector3D' || innerPropType1.indexOf( 'Lcl_' ) === 0 ) { - } + innerPropValue = [ + node.propertyList[ 4 ], + node.propertyList[ 5 ], + node.propertyList[ 6 ] + ]; - } ); + } else { - /** - * @returns {boolean} - */ - function isFbxFormatASCII( text ) { + innerPropValue = node.propertyList[ 4 ]; - var CORRECT = [ 'K', 'a', 'y', 'd', 'a', 'r', 'a', '\\', 'F', 'B', 'X', '\\', 'B', 'i', 'n', 'a', 'r', 'y', '\\', '\\' ]; + } - var cursor = 0; + if ( innerPropType1.indexOf( 'Lcl_' ) === 0 ) { - function read( offset ) { + innerPropValue = innerPropValue.toString(); - var result = text[ offset - 1 ]; - text = text.slice( cursor + offset ); - cursor ++; - return result; + } - } + // this will be copied to parent. see above. + properties[ innerPropName ] = { - for ( var i = 0; i < CORRECT.length; ++ i ) { + 'type': innerPropType1, + 'type2': innerPropType2, + 'flag': innerPropFlag, + 'value': innerPropValue - var num = read( 1 ); - if ( num == CORRECT[ i ] ) { + }; - return false; + continue; - } + } - } + // standard case + // follows TextParser's manner. + if ( subNodes[ node.name ] === undefined ) { - return true; + if ( typeof node.id === 'number' ) { - } + subNodes[ node.name ] = {}; + subNodes[ node.name ][ node.id ] = node; - /** - * @returns {number} - */ - function getFbxVersion( text ) { + } else { - var versionRegExp = /FBXVersion: (\d+)/; - var match = text.match( versionRegExp ); - if ( match ) { + subNodes[ node.name ] = node; - var version = parseInt( match[ 1 ] ); - return version; + } - } - throw new Error( 'FBXLoader: Cannot find the version number for the file given.' ); + } else { - } + if ( node.id === '' ) { - /** - * Converts FBX ticks into real time seconds. - * @param {number} time - FBX tick timestamp to convert. + if ( ! Array.isArray( subNodes[ node.name ] ) ) { + + subNodes[ node.name ] = [ subNodes[ node.name ] ]; + + } + + subNodes[ node.name ].push( node ); + + } else { + + if ( subNodes[ node.name ][ node.id ] === undefined ) { + + subNodes[ node.name ][ node.id ] = node; + + } else { + + // conflict id. irregular? + + if ( ! Array.isArray( subNodes[ node.name ][ node.id ] ) ) { + + subNodes[ node.name ][ node.id ] = [ subNodes[ node.name ][ node.id ] ]; + + } + + subNodes[ node.name ][ node.id ].push( node ); + + } + + } + + } + + } + + return { + + singleProperty: isSingleProperty, + id: id, + attrName: attrName, + attrType: attrType, + name: name, + properties: properties, + propertyList: propertyList, // raw property list, would be used by parent + subNodes: subNodes + + }; + + }, + + parseProperty: function ( reader ) { + + var type = reader.getChar(); + + switch ( type ) { + + case 'F': + return reader.getFloat32(); + + case 'D': + return reader.getFloat64(); + + case 'L': + return reader.getInt64(); + + case 'I': + return reader.getInt32(); + + case 'Y': + return reader.getInt16(); + + case 'C': + return reader.getBoolean(); + + case 'f': + case 'd': + case 'l': + case 'i': + case 'b': + + var arrayLength = reader.getUint32(); + var encoding = reader.getUint32(); // 0: non-compressed, 1: compressed + var compressedLength = reader.getUint32(); + + if ( encoding === 0 ) { + + switch ( type ) { + + case 'f': + return reader.getFloat32Array( arrayLength ); + + case 'd': + return reader.getFloat64Array( arrayLength ); + + case 'l': + return reader.getInt64Array( arrayLength ); + + case 'i': + return reader.getInt32Array( arrayLength ); + + case 'b': + return reader.getBooleanArray( arrayLength ); + + } + + } + + if ( window.Zlib === undefined ) { + + throw new Error( 'FBXLoader: Import https://github.com/imaya/zlib.js' ); + + } + + var inflate = new Zlib.Inflate( new Uint8Array( reader.getArrayBuffer( compressedLength ) ) ); + var reader2 = new BinaryReader( inflate.decompress().buffer ); + + switch ( type ) { + + case 'f': + return reader2.getFloat32Array( arrayLength ); + + case 'd': + return reader2.getFloat64Array( arrayLength ); + + case 'l': + return reader2.getInt64Array( arrayLength ); + + case 'i': + return reader2.getInt32Array( arrayLength ); + + case 'b': + return reader2.getBooleanArray( arrayLength ); + + } + + case 'S': + var length = reader.getUint32(); + return reader.getString( length ); + + case 'R': + var length = reader.getUint32(); + return reader.getArrayBuffer( length ); + + default: + throw new Error( 'FBXLoader: Unknown property type ' + type ); + + } + + } + + } ); + + + function BinaryReader( buffer, littleEndian ) { + + this.dv = new DataView( buffer ); + this.offset = 0; + this.littleEndian = ( littleEndian !== undefined ) ? littleEndian : true; + + } + + Object.assign( BinaryReader.prototype, { + + getOffset: function () { + + return this.offset; + + }, + + size: function () { + + return this.dv.buffer.byteLength; + + }, + + skip: function ( length ) { + + this.offset += length; + + }, + + // seems like true/false representation depends on exporter. + // true: 1 or 'Y'(=0x59), false: 0 or 'T'(=0x54) + // then sees LSB. + getBoolean: function () { + + return ( this.getUint8() & 1 ) === 1; + + }, + + getBooleanArray: function ( size ) { + + var a = []; + + for ( var i = 0; i < size; i ++ ) { + + a.push( this.getBoolean() ); + + } + + return a; + + }, + + getInt8: function () { + + var value = this.dv.getInt8( this.offset ); + this.offset += 1; + return value; + + }, + + getInt8Array: function ( size ) { + + var a = []; + + for ( var i = 0; i < size; i ++ ) { + + a.push( this.getInt8() ); + + } + + return a; + + }, + + getUint8: function () { + + var value = this.dv.getUint8( this.offset ); + this.offset += 1; + return value; + + }, + + getUint8Array: function ( size ) { + + var a = []; + + for ( var i = 0; i < size; i ++ ) { + + a.push( this.getUint8() ); + + } + + return a; + + }, + + getInt16: function () { + + var value = this.dv.getInt16( this.offset, this.littleEndian ); + this.offset += 2; + return value; + + }, + + getInt16Array: function ( size ) { + + var a = []; + + for ( var i = 0; i < size; i ++ ) { + + a.push( this.getInt16() ); + + } + + return a; + + }, + + getUint16: function () { + + var value = this.dv.getUint16( this.offset, this.littleEndian ); + this.offset += 2; + return value; + + }, + + getUint16Array: function ( size ) { + + var a = []; + + for ( var i = 0; i < size; i ++ ) { + + a.push( this.getUint16() ); + + } + + return a; + + }, + + getInt32: function () { + + var value = this.dv.getInt32( this.offset, this.littleEndian ); + this.offset += 4; + return value; + + }, + + getInt32Array: function ( size ) { + + var a = []; + + for ( var i = 0; i < size; i ++ ) { + + a.push( this.getInt32() ); + + } + + return a; + + }, + + getUint32: function () { + + var value = this.dv.getUint32( this.offset, this.littleEndian ); + this.offset += 4; + return value; + + }, + + getUint32Array: function ( size ) { + + var a = []; + + for ( var i = 0; i < size; i ++ ) { + + a.push( this.getUint32() ); + + } + + return a; + + }, + + // JavaScript doesn't support 64-bit integer so attempting to calculate by ourselves. + // 1 << 32 will return 1 so using multiply operation instead here. + // There'd be a possibility that this method returns wrong value if the value + // is out of the range between Number.MAX_SAFE_INTEGER and Number.MIN_SAFE_INTEGER. + // TODO: safely handle 64-bit integer + getInt64: function () { + + var low, high; + + if ( this.littleEndian ) { + + low = this.getUint32(); + high = this.getUint32(); + + } else { + + high = this.getUint32(); + low = this.getUint32(); + + } + + // calculate negative value + if ( high & 0x80000000 ) { + + high = ~high & 0xFFFFFFFF; + low = ~low & 0xFFFFFFFF; + + if ( low === 0xFFFFFFFF ) high = ( high + 1 ) & 0xFFFFFFFF; + + low = ( low + 1 ) & 0xFFFFFFFF; + + return - ( high * 0x100000000 + low ); + + } + + return high * 0x100000000 + low; + + }, + + getInt64Array: function ( size ) { + + var a = []; + + for ( var i = 0; i < size; i ++ ) { + + a.push( this.getInt64() ); + + } + + return a; + + }, + + // Note: see getInt64() comment + getUint64: function () { + + var low, high; + + if ( this.littleEndian ) { + + low = this.getUint32(); + high = this.getUint32(); + + } else { + + high = this.getUint32(); + low = this.getUint32(); + + } + + return high * 0x100000000 + low; + + }, + + getUint64Array: function ( size ) { + + var a = []; + + for ( var i = 0; i < size; i ++ ) { + + a.push( this.getUint64() ); + + } + + return a; + + }, + + getFloat32: function () { + + var value = this.dv.getFloat32( this.offset, this.littleEndian ); + this.offset += 4; + return value; + + }, + + getFloat32Array: function ( size ) { + + var a = []; + + for ( var i = 0; i < size; i ++ ) { + + a.push( this.getFloat32() ); + + } + + return a; + + }, + + getFloat64: function () { + + var value = this.dv.getFloat64( this.offset, this.littleEndian ); + this.offset += 8; + return value; + + }, + + getFloat64Array: function ( size ) { + + var a = []; + + for ( var i = 0; i < size; i ++ ) { + + a.push( this.getFloat64() ); + + } + + return a; + + }, + + getArrayBuffer: function ( size ) { + + var value = this.dv.buffer.slice( this.offset, this.offset + size ); + this.offset += size; + return value; + + }, + + getChar: function () { + + return String.fromCharCode( this.getUint8() ); + + }, + + getString: function ( size ) { + + var s = ''; + + while ( size > 0 ) { + + var value = this.getUint8(); + size--; + + if ( value === 0 ) break; + + s += String.fromCharCode( value ); + + } + + this.skip( size ); + + return s; + + } + + } ); + + + function FBXTree() {} + + Object.assign( FBXTree.prototype, { + + add: function ( key, val ) { + + this[ key ] = val; + + }, + + searchConnectionParent: function ( id ) { + + if ( this.__cache_search_connection_parent === undefined ) { + + this.__cache_search_connection_parent = []; + + } + + if ( this.__cache_search_connection_parent[ id ] !== undefined ) { + + return this.__cache_search_connection_parent[ id ]; + + } else { + + this.__cache_search_connection_parent[ id ] = []; + + } + + var conns = this.Connections.properties.connections; + + var results = []; + for ( var i = 0; i < conns.length; ++ i ) { + + if ( conns[ i ][ 0 ] == id ) { + + // 0 means scene root + var res = conns[ i ][ 1 ] === 0 ? - 1 : conns[ i ][ 1 ]; + results.push( res ); + + } + + } + + if ( results.length > 0 ) { + + append( this.__cache_search_connection_parent[ id ], results ); + return results; + + } else { + + this.__cache_search_connection_parent[ id ] = [ - 1 ]; + return [ - 1 ]; + + } + + }, + + searchConnectionChildren: function ( id ) { + + if ( this.__cache_search_connection_children === undefined ) { + + this.__cache_search_connection_children = []; + + } + + if ( this.__cache_search_connection_children[ id ] !== undefined ) { + + return this.__cache_search_connection_children[ id ]; + + } else { + + this.__cache_search_connection_children[ id ] = []; + + } + + var conns = this.Connections.properties.connections; + + var res = []; + for ( var i = 0; i < conns.length; ++ i ) { + + if ( conns[ i ][ 1 ] == id ) { + + // 0 means scene root + res.push( conns[ i ][ 0 ] === 0 ? - 1 : conns[ i ][ 0 ] ); + // there may more than one kid, then search to the end + + } + + } + + if ( res.length > 0 ) { + + append( this.__cache_search_connection_children[ id ], res ); + return res; + + } else { + + this.__cache_search_connection_children[ id ] = [ ]; + return [ ]; + + } + + }, + + searchConnectionType: function ( id, to ) { + + var key = id + ',' + to; // TODO: to hash + if ( this.__cache_search_connection_type === undefined ) { + + this.__cache_search_connection_type = {}; + + } + + if ( this.__cache_search_connection_type[ key ] !== undefined ) { + + return this.__cache_search_connection_type[ key ]; + + } else { + + this.__cache_search_connection_type[ key ] = ''; + + } + + var conns = this.Connections.properties.connections; + + for ( var i = 0; i < conns.length; ++ i ) { + + if ( conns[ i ][ 0 ] == id && conns[ i ][ 1 ] == to ) { + + // 0 means scene root + this.__cache_search_connection_type[ key ] = conns[ i ][ 2 ]; + return conns[ i ][ 2 ]; + + } + + } + + this.__cache_search_connection_type[ id ] = null; + return null; + + } + + } ); + + + /** + * @param {ArrayBuffer} buffer + * @returns {boolean} + */ + function isFbxFormatBinary( buffer ) { + + var CORRECT = 'Kaydara FBX Binary \0'; + + return buffer.byteLength >= CORRECT.length && CORRECT === convertArrayBufferToString( buffer, 0, CORRECT.length ); + + } + + /** + * @returns {boolean} + */ + function isFbxFormatASCII( text ) { + + var CORRECT = [ 'K', 'a', 'y', 'd', 'a', 'r', 'a', '\\', 'F', 'B', 'X', '\\', 'B', 'i', 'n', 'a', 'r', 'y', '\\', '\\' ]; + + var cursor = 0; + + function read( offset ) { + + var result = text[ offset - 1 ]; + text = text.slice( cursor + offset ); + cursor ++; + return result; + + } + + for ( var i = 0; i < CORRECT.length; ++ i ) { + + var num = read( 1 ); + if ( num == CORRECT[ i ] ) { + + return false; + + } + + } + + return true; + + } + + /** + * @returns {number} + */ + function getFbxVersion( text ) { + + var versionRegExp = /FBXVersion: (\d+)/; + var match = text.match( versionRegExp ); + if ( match ) { + + var version = parseInt( match[ 1 ] ); + return version; + + } + throw new Error( 'FBXLoader: Cannot find the version number for the file given.' ); + + } + + /** + * Converts FBX ticks into real time seconds. + * @param {number} time - FBX tick timestamp to convert. * @returns {number} - FBX tick in real world time. */ function convertFBXTimeToSeconds( time ) { @@ -4000,6 +4960,32 @@ } + /** + * Converts ArrayBuffer to String. + * @param {ArrayBuffer} buffer + * @param {number} from + * @param {number} to + * @returns {String} + */ + function convertArrayBufferToString( buffer, from, to ) { + + if ( from === undefined ) from = 0; + if ( to === undefined ) to = buffer.byteLength; + + var array = new Uint8Array( buffer, from, to ); + + var s = ''; + + for ( var i = 0, il = array.length; i < il; i ++ ) { + + s += String.fromCharCode( array[ i ] ); + + } + + return s; + + } + /** * Converts number from degrees into radians. * @param {number} value
false
Other
mrdoob
three.js
f5f68fcaf89e32c35844b28a5e1cace9a7060e40.json
Update docs on aoMap channel and UVs.
docs/api/materials/MeshBasicMaterial.html
@@ -63,7 +63,7 @@ <h3>[property:Texture alphaMap]</h3> </div> <h3>[property:Texture aoMap]</h3> - <div>The ambient occlusion map. Default is null.</div> + <div>The red channel of this texture is used as the ambient occlusion map. Default is null. The aoMap requires a second set of UVs.</div> <h3>[property:Float aoMapIntensity]</h3> <div>Intensity of the ambient occlusion effect. Default is 1. Zero is no occlusion effect.</div>
true
Other
mrdoob
three.js
f5f68fcaf89e32c35844b28a5e1cace9a7060e40.json
Update docs on aoMap channel and UVs.
docs/api/materials/MeshLambertMaterial.html
@@ -74,7 +74,7 @@ <h3>[property:Texture alphaMap]</h3> </div> <h3>[property:Texture aoMap]</h3> - <div>The ambient occlusion map. Default is null.</div> + <div>The red channel of this texture is used as the ambient occlusion map. Default is null. The aoMap requires a second set of UVs.</div> <h3>[property:Float aoMapIntensity]</h3> <div>Intensity of the ambient occlusion effect. Default is 1. Zero is no occlusion effect.</div>
true
Other
mrdoob
three.js
f5f68fcaf89e32c35844b28a5e1cace9a7060e40.json
Update docs on aoMap channel and UVs.
docs/api/materials/MeshPhongMaterial.html
@@ -73,7 +73,7 @@ <h3>[property:Texture alphaMap]</h3> </div> <h3>[property:Texture aoMap]</h3> - <div>The ambient occlusion map. Default is null.</div> + <div>The red channel of this texture is used as the ambient occlusion map. Default is null. The aoMap requires a second set of UVs.</div> <h3>[property:Float aoMapIntensity]</h3> <div>Intensity of the ambient occlusion effect. Default is 1. Zero is no occlusion effect.</div>
true
Other
mrdoob
three.js
f5f68fcaf89e32c35844b28a5e1cace9a7060e40.json
Update docs on aoMap channel and UVs.
docs/api/materials/MeshStandardMaterial.html
@@ -97,7 +97,7 @@ <h3>[property:Texture alphaMap]</h3> </div> <h3>[property:Texture aoMap]</h3> - <div>The red channel of this texture is used as the ambient occlusion map. Default is null.</div> + <div>The red channel of this texture is used as the ambient occlusion map. Default is null. The aoMap requires a second set of UVs.</div> <h3>[property:Float aoMapIntensity]</h3> <div>Intensity of the ambient occlusion effect. Default is 1. Zero is no occlusion effect.</div>
true
Other
mrdoob
three.js
78b236bbef3c631800b9bfc209341360307b4c28.json
add missing newline
src/renderers/shaders/ShaderChunk/project_vertex.glsl
@@ -1,3 +1,3 @@ vec4 mvPosition = modelViewMatrix * vec4( transformed, 1.0 ); -gl_Position = projectionMatrix * mvPosition; \ No newline at end of file +gl_Position = projectionMatrix * mvPosition;
false
Other
mrdoob
three.js
fb46e685fad9f3fd6b31ddfecfc0c09d753773c8.json
Use boombox as first example.
examples/webgl_loader_gltf2.html
@@ -415,15 +415,6 @@ } var sceneList = [ - { - name : 'Duck', url : './models/gltf/Duck/%s/duck.gltf', - cameraPos: new THREE.Vector3(0, 3, 5), - addLights:true, - addGround:true, - shadows:true, - // TODO: 'glTF-MaterialsCommon', 'glTF-techniqueWebGL' - extensions: ['glTF', 'glTF-Embedded', 'glTF-pbrSpecularGlossiness', 'glTF-Binary'] - }, { name : 'BoomBox (PBR)', url : './models/gltf/BoomBox/%s/BoomBox.gltf', cameraPos: new THREE.Vector3(2, 1, 3), @@ -440,6 +431,15 @@ extensions: ['glTF'], addEnvMap: true }, + { + name : 'Duck', url : './models/gltf/Duck/%s/duck.gltf', + cameraPos: new THREE.Vector3(0, 3, 5), + addLights:true, + addGround:true, + shadows:true, + // TODO: 'glTF-MaterialsCommon', 'glTF-techniqueWebGL' + extensions: ['glTF', 'glTF-Embedded', 'glTF-pbrSpecularGlossiness', 'glTF-Binary'] + }, { name : "Monster", url : "./models/gltf/Monster/%s/Monster.gltf", cameraPos: new THREE.Vector3(30, 10, 70),
false
Other
mrdoob
three.js
bbd838eed5bc0a3f027ee933924c27365bc7ff2a.json
Fix skinned animation for glTF2.0.
examples/js/loaders/GLTF2Loader.js
@@ -2380,7 +2380,7 @@ THREE.GLTF2Loader = ( function () { var _skin = { bindShapeMatrix: bindShapeMatrix, - jointNames: skin.jointNames, + joints: skin.joints, inverseBindMatrices: dependencies.accessors[ skin.inverseBindMatrices ] }; @@ -2665,24 +2665,8 @@ THREE.GLTF2Loader = ( function () { // Replace Mesh with SkinnedMesh in library if ( skinEntry ) { - var getJointNode = function ( jointId ) { - - var keys = Object.keys( __nodes ); - - for ( var i = 0, il = keys.length; i < il; i ++ ) { - - var n = __nodes[ keys[ i ] ]; - - if ( n.jointName === jointId ) return n; - - } - - return null; - - }; - var geometry = originalGeometry; - var material = originalMaterial; + material = originalMaterial; material.skinning = true; child = new THREE.SkinnedMesh( geometry, material, false ); @@ -2693,10 +2677,10 @@ THREE.GLTF2Loader = ( function () { var bones = []; var boneInverses = []; - for ( var i = 0, l = skinEntry.jointNames.length; i < l; i ++ ) { + for ( var i = 0, l = skinEntry.joints.length; i < l; i ++ ) { - var jointId = skinEntry.jointNames[ i ]; - var jointNode = getJointNode( jointId ); + var jointId = skinEntry.joints[ i ]; + var jointNode = __nodes[ jointId ]; if ( jointNode ) {
false
Other
mrdoob
three.js
b21159859dc06e170d0590b919e08d2047755aae.json
Update demos for duck.
examples/webgl_loader_gltf.html
@@ -381,14 +381,6 @@ addGround:true, extensions: ["glTF", "glTF-MaterialsCommon", "glTF-Binary"] }, - { - name : "Duck", url : "./models/gltf/duck/%s/duck.gltf", - cameraPos: new THREE.Vector3(0, 3, 5), - addLights:true, - addGround:true, - shadows:true, - extensions: ["glTF", "glTF-MaterialsCommon", "glTF-Binary"] - }, { name : "Cesium Man", url : "./models/gltf/CesiumMan/%s/Cesium_Man.gltf", cameraPos: new THREE.Vector3(0, 3, 10),
true
Other
mrdoob
three.js
b21159859dc06e170d0590b919e08d2047755aae.json
Update demos for duck.
examples/webgl_loader_gltf2.html
@@ -86,10 +86,12 @@ <div> Extension <select id="extensions_list" onchange="selectExtension();"> - <option value="glTF">None</option> - <option value="glTF-MaterialsCommon">Built-in shaders</option> - <option value="glTF-pbrSpecularGlossiness">Specular-Glossiness</option> - <option value="glTF-Binary">Binary</option> + <option value="glTF">None (Default)</option> + <option value="glTF-Embedded">None (Embedded)</option> + <option value="glTF-Binary">None (Binary)</option> + <option value="glTF-MaterialsCommon">Common Materials</option> + <option value="glTF-pbrSpecularGlossiness">Specular-Glossiness (PBR)</option> + <option value="glTF-techniqueWebGL">GLSL</option> </select> </div> </div> @@ -285,7 +287,7 @@ for (i = 0; i < len; i++) { var addCamera = true; - var cameraName = gltf.cameras[i].parent.name; + var cameraName = gltf.cameras[i].parent.name || ('camera_' + i); if (sceneInfo.cameras && !(cameraName in sceneInfo.cameras)) { addCamera = false; @@ -413,6 +415,14 @@ } var sceneList = [ + { + name : 'Duck', url : './models/gltf/Duck/%s/duck.gltf', + cameraPos: new THREE.Vector3(0, 3, 5), + addLights:true, + addGround:true, + shadows:true, + extensions: ['glTF', 'glTF-Embedded', 'glTF-MaterialsCommon', 'glTF-pbrSpecularGlossiness', 'glTF-Binary', 'glTF-techniqueWebGL'] + }, { name : 'BoomBox (PBR)', url : './models/gltf/BoomBox/%s/BoomBox.gltf', cameraPos: new THREE.Vector3(2, 1, 3), @@ -428,7 +438,7 @@ addLights:true, extensions: ['glTF'], addEnvMap: true - } + }, ]; function buildSceneList() {
true
Other
mrdoob
three.js
0fccdc2267e0b0c3793ef6c32eb9ca98e1e9e1bd.json
fix broken link
docs/api/lights/DirectionalLight.html
@@ -43,7 +43,7 @@ <h2>Example</h2> [example:canvas_morphtargets_horse morphtargets / horse ]<br /> [example:misc_controls_fly controls / fly ]<br /> [example:misc_lights_test lights / test ]<br /> - [example:vr_cubes cubes ]<br /> + [example:webvr_cubes cubes ]<br /> [example:webgl_effects_parallaxbarrier effects / parallaxbarrier ]<br /> [example:webgl_effects_stereo effects / stereo ]<br /> [example:webgl_geometry_extrude_splines geometry / extrude / splines ]<br />
false
Other
mrdoob
three.js
315e63685970967d7e1f5d5ddd226183b27a31a4.json
remove unused variables
examples/webgl_nearestneighbour.html
@@ -72,11 +72,8 @@ <script> var camera, scene, renderer; - var geometry, mesh; var controls; - var objects = []; - var amountOfParticles = 500000, maxDistance = Math.pow( 120, 2 ); var positions, alphas, particles, _particleGeom;
false
Other
mrdoob
three.js
7fbd12b5f4fc8b6d4228589ba671b87616d90ff7.json
Add color keyframe and clean up
examples/misc_animation_keys.html
@@ -70,36 +70,36 @@ // var geometry = new THREE.BoxBufferGeometry( 5, 5, 5 ); - var material = new THREE.MeshBasicMaterial( { color: 0xffff00 } ); + var material = new THREE.MeshBasicMaterial( { color: 0xffffff } ); var mesh = new THREE.Mesh( geometry, material ); scene.add( mesh ); // create a keyframe track (i.e. a timed sequence of keyframes) for each animated property - // Note: the keyframe track type should correspond to the type of the property being animated + // Note: the keyframe track type should correspond to the type of the property being animated // POSITION - var positionKF = new THREE.VectorKeyframeTrack('.position', [ 0, 1, 2 ], [ 0, 0, 0, 30, 0, 0, 0, 0, 0 ] ); + var positionKF = new THREE.VectorKeyframeTrack( '.position', [ 0, 1, 2 ], [ 0, 0, 0, 30, 0, 0, 0, 0, 0 ] ); - // SCALE - var scaleKF = new THREE.VectorKeyframeTrack('.scale', [ 0, 1, 2 ], [ 1, 1, 1, 2, 2, 2, 1, 1, 1 ] ); + // SCALE + var scaleKF = new THREE.VectorKeyframeTrack( '.scale', [ 0, 1, 2 ], [ 1, 1, 1, 2, 2, 2, 1, 1, 1 ] ); // ROTATION // Rotation should be performed using quaternions, using a QuaternionKeyframeTrack // Interpolating Euler angles (.rotation property) can be problematic and is currently not supported - - // set up rotation about x axis - var xAxis = new THREE.Vector3( 1, 0, 0 ); + + // set up rotation about x axis + var xAxis = new THREE.Vector3( 1, 0, 0 ); var qInitial = new THREE.Quaternion().setFromAxisAngle( xAxis, 0 ); var qFinal = new THREE.Quaternion().setFromAxisAngle( xAxis, Math.PI ); - var quaternionKF = new THREE.QuaternionKeyframeTrack('.quaternion', [ 0, 1, 2 ], [ qInitial.x, qInitial.y, qInitial.z, qInitial.w, qFinal.x, qFinal.y, qFinal.z, qFinal.w, qInitial.x, qInitial.y, qInitial.z, qInitial.w ] ); + var quaternionKF = new THREE.QuaternionKeyframeTrack( '.quaternion', [ 0, 1, 2 ], [ qInitial.x, qInitial.y, qInitial.z, qInitial.w, qFinal.x, qFinal.y, qFinal.z, qFinal.w, qInitial.x, qInitial.y, qInitial.z, qInitial.w ] ); - // COLOR - Not yet implemented! - // var colorKF = new THREE.ColorKeyframeTrack('.material.color', [0, 1, 2], [0xffff00, 0xffffff, 0xffff00]) + // COLOR + var colorKF = new THREE.ColorKeyframeTrack( '.material.color', [ 0, 1, 2 ], [ 1, 0, 0, 0, 1, 0, 0, 0, 1 ], THREE.InterpolateDiscrete ); // create an animation sequence with the tracks - // If a negative time value is passed, the duration will be calculated from the times of the passed tracks array - var clip = new THREE.AnimationClip( 'Action', -1, [ scaleKF, positionKF, quaternionKF ] ); + // If a negative time value is passed, the duration will be calculated from the times of the passed tracks array + var clip = new THREE.AnimationClip( 'Action', 3, [ scaleKF, positionKF, quaternionKF, colorKF ] ); // setup the AnimationMixer mixer = new THREE.AnimationMixer( mesh ); @@ -108,10 +108,10 @@ var clipAction = mixer.clipAction( clip ); clipAction.play(); - // + // renderer = new THREE.WebGLRenderer(); - renderer.setClearColor( 0x555555 ); + renderer.setClearColor( 0x000000, 0 ); renderer.setPixelRatio( window.devicePixelRatio ); renderer.setSize( window.innerWidth, window.innerHeight ); container.appendChild( renderer.domElement ); @@ -123,13 +123,13 @@ // - clock = new THREE.Clock() + clock = new THREE.Clock(); // window.addEventListener( 'resize', onWindowResize, false ); - }; + } function onWindowResize() { @@ -138,15 +138,15 @@ renderer.setSize( window.innerWidth, window.innerHeight ); - }; + } function animate() { requestAnimationFrame( animate ); render(); - }; + } function render() { @@ -162,7 +162,7 @@ stats.update(); - }; + } </script>
false
Other
mrdoob
three.js
951e67cd17f3b2591329ae500173da5425706253.json
remove excess colon
src/math/Matrix3.js
@@ -203,7 +203,7 @@ Object.assign( Matrix3.prototype, { if ( det === 0 ) { - var msg = "THREE.Matrix3: .getInverse(): can't invert matrix, determinant is 0"; + var msg = "THREE.Matrix3: .getInverse() can't invert matrix, determinant is 0"; if ( throwOnDegenerate === true ) {
true
Other
mrdoob
three.js
951e67cd17f3b2591329ae500173da5425706253.json
remove excess colon
src/math/Matrix4.js
@@ -555,7 +555,7 @@ Object.assign( Matrix4.prototype, { if ( det === 0 ) { - var msg = "THREE.Matrix4: .getInverse(): can't invert matrix, determinant is 0"; + var msg = "THREE.Matrix4: .getInverse() can't invert matrix, determinant is 0"; if ( throwOnDegenerate === true ) {
true
Other
mrdoob
three.js
58198fc113c9dc30c88b56dd8fc44a30a4c58fee.json
remove -o- prefix css
examples/js/renderers/CSS3DRenderer.js
@@ -59,7 +59,6 @@ THREE.CSS3DRenderer = function () { cameraElement.style.WebkitTransformStyle = 'preserve-3d'; cameraElement.style.MozTransformStyle = 'preserve-3d'; - cameraElement.style.oTransformStyle = 'preserve-3d'; cameraElement.style.transformStyle = 'preserve-3d'; domElement.appendChild( cameraElement ); @@ -197,7 +196,6 @@ THREE.CSS3DRenderer = function () { element.style.WebkitTransform = style; element.style.MozTransform = style; - element.style.oTransform = style; element.style.transform = style; cache.objects[ object.id ] = { style: style }; @@ -278,7 +276,6 @@ THREE.CSS3DRenderer = function () { domElement.style.WebkitPerspective = fov + 'px'; domElement.style.MozPerspective = fov + 'px'; - domElement.style.oPerspective = fov + 'px'; domElement.style.perspective = fov + 'px'; cache.camera.fov = fov; @@ -298,11 +295,10 @@ THREE.CSS3DRenderer = function () { var style = cameraCSSMatrix + 'translate(' + _widthHalf + 'px,' + _heightHalf + 'px)'; - if ( !isFlatTransform && cache.camera.style !== style ) { + if ( ! isFlatTransform && cache.camera.style !== style ) { cameraElement.style.WebkitTransform = style; cameraElement.style.MozTransform = style; - cameraElement.style.oTransform = style; cameraElement.style.transform = style; cache.camera.style = style;
false
Other
mrdoob
three.js
56cc2c5116cc53f597f3708eb5bbc438e1dfb445.json
remove unnecessary lines
examples/webgl_postprocessing_outline.html
@@ -41,13 +41,11 @@ <script src="js/Detector.js"></script> <script src="js/shaders/CopyShader.js"></script> - <script src="js/postprocessing/EffectComposer.js"></script> - <script src="js/postprocessing/MaskPass.js"></script> - <script src="js/shaders/CopyShader.js"></script> + <script src="js/shaders/FXAAShader.js"></script> + <script src="js/postprocessing/EffectComposer.js"></script> <script src="js/postprocessing/RenderPass.js"></script> <script src="js/postprocessing/ShaderPass.js"></script> <script src="js/postprocessing/OutlinePass.js"></script> - <script src="js/shaders/FXAAShader.js"></script> <script src="js/libs/stats.min.js"></script> <script src='js/libs/dat.gui.min.js'></script>
false
Other
mrdoob
three.js
ce190ebd7d6c16fcab98f305c4b811ae00a0d885.json
Convert primitive warning to error.
examples/js/loaders/GLTF2Loader.js
@@ -1809,7 +1809,7 @@ THREE.GLTF2Loader = ( function () { } else { - console.warn( "Only triangular and line primitives are supported" ); + throw new Error( "Only triangular and line primitives are supported" ); }
false
Other
mrdoob
three.js
d1e2a494d8d7426eec4805bd0eb4eeeb8de91543.json
Parse second UV channel
examples/js/loaders/GLTF2Loader.js
@@ -1719,6 +1719,10 @@ THREE.GLTF2Loader = ( function () { geometry.addAttribute( 'uv', bufferAttribute ); break; + case 'TEXCOORD_1': + geometry.addAttribute( 'uv2', bufferAttribute ); + break; + case 'COLOR_0': case 'COLOR0': case 'COLOR':
true
Other
mrdoob
three.js
d1e2a494d8d7426eec4805bd0eb4eeeb8de91543.json
Parse second UV channel
examples/js/loaders/GLTFLoader.js
@@ -1625,6 +1625,10 @@ THREE.GLTFLoader = ( function () { geometry.addAttribute( 'uv', bufferAttribute ); break; + case 'TEXCOORD_1': + geometry.addAttribute( 'uv2', bufferAttribute ); + break; + case 'COLOR_0': case 'COLOR0': case 'COLOR':
true
Other
mrdoob
three.js
beb9bf0e505c79852dcf080a9b26d926fc898dfd.json
Use TextDecoder for PCDLoader
examples/js/loaders/PCDLoader.js
@@ -35,9 +35,16 @@ THREE.PCDLoader.prototype = { binarryToStr: function ( data ) { - var text = ""; var charArray = new Uint8Array( data ); - for ( var i = 0; i < data.byteLength; i ++ ) { + + if ( window.TextDecoder !== undefined ) { + + return new TextDecoder().decode( charArray ); + + } + + var text = ""; + for ( var i = 0, il = data.byteLength; i < il; i ++ ) { text += String.fromCharCode( charArray[ i ] );
false
Other
mrdoob
three.js
754b94720b29e7589ae5432dc8f6512fd1580c4f.json
Fix an offset bug in BinaryLoader
examples/js/loaders/BinaryLoader.js
@@ -250,7 +250,7 @@ THREE.BinaryLoader.prototype = { for ( var i = 0; i < length; i ++ ) { - text += String.fromCharCode( charArray[ offset + i ] ); + text += String.fromCharCode( charArray[ i ] ); }
false
Other
mrdoob
three.js
c2e03ce8162036e5856448264e9687912e98ee3e.json
Accept animation.target.node=0 in GLTF2Loader
examples/js/loaders/GLTF2Loader.js
@@ -2309,7 +2309,7 @@ THREE.GLTF2Loader = ( function () { if ( sampler ) { var target = channel.target; - var name = target.node || target.id; // NOTE: target.id is deprecated. + var name = target.node !== undefined ? target.node : target.id; // NOTE: target.id is deprecated. var input = animation.parameters !== undefined ? animation.parameters[ sampler.input ] : sampler.input; var output = animation.parameters !== undefined ? animation.parameters[ sampler.output ] : sampler.output;
false
Other
mrdoob
three.js
5622169499f72768399f7430f6cd3ce0f0b50f72.json
Remove unnecessary lines in GLTF2Loader
examples/js/loaders/GLTF2Loader.js
@@ -2180,8 +2180,6 @@ THREE.GLTF2Loader = ( function () { // TODO: implement if ( target.TANGENT !== undefined ) { - console.log( dependencies.accessors[ target.NORMAL ] ); - } } @@ -2362,7 +2360,6 @@ THREE.GLTF2Loader = ( function () { var target = channel.target; var name = target.node || target.id; // NOTE: target.id is deprecated. - var input = animation.parameters !== undefined ? animation.parameters[ sampler.input ] : sampler.input; var output = animation.parameters !== undefined ? animation.parameters[ sampler.output ] : sampler.output;
false
Other
mrdoob
three.js
0d40bfdac25e852acbae35306e8bda347dfb489b.json
Add comment about techniques to GLTF2Loader
examples/js/loaders/GLTF2Loader.js
@@ -1668,6 +1668,12 @@ THREE.GLTF2Loader = ( function () { materialType = DeferredShaderMaterial; + // I've left the existing json.techniques code as is so far though + // techniques is moved to extension in glTF 2.0 because + // it seems there still be many models which have techniques under json. + // I'm gonna move the techniques code into GLTFTechniqueWebglExtension + // when glTF 2.0 release is officially announced. + var extension = extensions[ EXTENSIONS.KHR_TECHNIQUE_WEBGL ]; var techniques = extension !== undefined ? extension.techniques : json.techniques;
false
Other
mrdoob
three.js
7ffac6f5df245129f6841a5dfee01c015176c253.json
Add renderer.gammaOutput to program code
src/renderers/webgl/WebGLPrograms.js
@@ -239,6 +239,8 @@ function WebGLPrograms( renderer, capabilities ) { } + array.push( renderer.gammaOutput ); + return array.join(); };
false
Other
mrdoob
three.js
5c521f8da5e7972f7cc22729ffaa80efae2b70a3.json
Compute flat normals when detail is zero
src/geometries/PolyhedronGeometry.js
@@ -77,7 +77,7 @@ function PolyhedronBufferGeometry( vertices, indices, radius, detail ) { if ( detail === 0 ) { - BufferGeometry.prototype.computeVertexNormals.call( this ); // flat normals + this.computeVertexNormals(); // flat normals } else {
false
Other
mrdoob
three.js
cd71783f755a3c2f79e496a0a874a0c2cc522d0b.json
Compute flat normals when detail is zero
src/geometries/PolyhedronGeometry.js
@@ -74,7 +74,16 @@ function PolyhedronBufferGeometry( vertices, indices, radius, detail ) { this.addAttribute( 'position', new Float32BufferAttribute( vertexBuffer, 3 ) ); this.addAttribute( 'normal', new Float32BufferAttribute( vertexBuffer.slice(), 3 ) ); this.addAttribute( 'uv', new Float32BufferAttribute( uvBuffer, 2 ) ); - this.normalizeNormals(); + + if ( detail === 0 ) { + + BufferGeometry.prototype.computeVertexNormals.call( this ); // flat normals + + } else { + + this.normalizeNormals(); // smooth normals + + } // helper functions
false
Other
mrdoob
three.js
488437c791f0f64e518ca7e796e9197c78598b94.json
Fix Markdown syntax typo in Testing-with-NPM.html
docs/manual/buildTools/Testing-with-NPM.html
@@ -187,7 +187,7 @@ <h2>Add your own code</h2> <ol> <li> Write a test for the expected behaviour of your code, and place it under test/. - [linkk:https://github.com/air/encounter/blob/master/test/Physics-test.js Here] is an example from a real project. + [link:https://github.com/air/encounter/blob/master/test/Physics-test.js Here] is an example from a real project. </li> <li>
false
Other
mrdoob
three.js
d96f03d9470321996cad163b61bac37e41c89d9a.json
add reference to Module
examples/js/loaders/DRACOLoader.js
@@ -18,6 +18,7 @@ THREE.DRACOLoader = function(manager) { this.materials = null; }; +const DracoModule = Module; THREE.DRACOLoader.prototype = { @@ -51,12 +52,12 @@ THREE.DRACOLoader.prototype = { */ const geometryType = wrapper.GetEncodedGeometryType(buffer); if (geometryType == DracoModule.TRIANGULAR_MESH) { - fileDisplayArea.innerText = "Loaded a mesh.\n"; + //fileDisplayArea.innerText = "Loaded a mesh.\n"; } else if (geometryType == DracoModule.POINT_CLOUD) { - fileDisplayArea.innerText = "Loaded a point cloud.\n"; + //fileDisplayArea.innerText = "Loaded a point cloud.\n"; } else { const errorMsg = "Error: Unknown geometry type."; - fileDisplayArea.innerText = errorMsg; + //fileDisplayArea.innerText = errorMsg; throw new Error(errorMsg); } return scope.convertDracoGeometryTo3JS(wrapper, geometryType, buffer); @@ -96,7 +97,7 @@ THREE.DRACOLoader.prototype = { Module.POSITION); if (posAttId == -1) { const errorMsg = "No position attribute found in the mesh."; - fileDisplayArea.innerText = errorMsg; + //fileDisplayArea.innerText = errorMsg; DracoModule.destroy(wrapper); DracoModule.destroy(dracoGeometry); throw new Error(errorMsg); @@ -179,7 +180,7 @@ THREE.DRACOLoader.prototype = { DracoModule.destroy(wrapper); DracoModule.destroy(dracoGeometry); - fileDisplayArea.innerText += geometryInfoStr; + //fileDisplayArea.innerText += geometryInfoStr; // Import data to Three JS geometry. const geometry = new THREE.BufferGeometry();
false
Other
mrdoob
three.js
5d32ac4d8a1795f2d81f77afc00ebe675d842fa3.json
add .vscode directory to .gitignore
.gitignore
@@ -3,4 +3,6 @@ .project node_modules .idea/ +.vscode/ npm-debug.log +
false
Other
mrdoob
three.js
08c40e22c7cec08cb4df7b3552392eff50a125c1.json
Remove unecessary constructor assignments
src/animation/AnimationAction.js
@@ -78,8 +78,6 @@ function AnimationAction( mixer, clip, localRoot ) { Object.assign( AnimationAction.prototype, { - constructor: AnimationAction, - // State & Scheduling play: function() {
true
Other
mrdoob
three.js
08c40e22c7cec08cb4df7b3552392eff50a125c1.json
Remove unecessary constructor assignments
src/animation/AnimationClip.js
@@ -310,8 +310,6 @@ Object.assign( AnimationClip, { Object.assign( AnimationClip.prototype, { - constructor: AnimationClip, - resetDuration: function() { var tracks = this.tracks,
true
Other
mrdoob
three.js
08c40e22c7cec08cb4df7b3552392eff50a125c1.json
Remove unecessary constructor assignments
src/animation/AnimationMixer.js
@@ -29,8 +29,6 @@ function AnimationMixer( root ) { Object.assign( AnimationMixer.prototype, EventDispatcher.prototype, { - constructor: AnimationMixer, - _bindAction: function ( action, prototypeAction ) { var root = action._localRoot || this._root,
true
Other
mrdoob
three.js
08c40e22c7cec08cb4df7b3552392eff50a125c1.json
Remove unecessary constructor assignments
src/animation/AnimationObjectGroup.js
@@ -73,8 +73,6 @@ function AnimationObjectGroup( var_args ) { Object.assign( AnimationObjectGroup.prototype, { - constructor: AnimationObjectGroup, - isAnimationObjectGroup: true, add: function( var_args ) {
true
Other
mrdoob
three.js
08c40e22c7cec08cb4df7b3552392eff50a125c1.json
Remove unecessary constructor assignments
src/animation/PropertyBinding.js
@@ -19,8 +19,6 @@ function Composite ( targetGroup, path, optionalParsedPath ) { Object.assign( Composite.prototype, { - constructor: Composite, - getValue: function( array, offset ) { this.bind(); // bind all binding @@ -226,8 +224,6 @@ Object.assign( PropertyBinding, { Object.assign( PropertyBinding.prototype, { // prototype, continued - constructor: PropertyBinding, - // these are used to "bind" a nonexistent property _getValue_unavailable: function() {}, _setValue_unavailable: function() {},
true
Other
mrdoob
three.js
08c40e22c7cec08cb4df7b3552392eff50a125c1.json
Remove unecessary constructor assignments
src/animation/PropertyMixer.js
@@ -58,8 +58,6 @@ function PropertyMixer( binding, typeName, valueSize ) { Object.assign( PropertyMixer.prototype, { - constructor: PropertyMixer, - // accumulate data in the 'incoming' region into 'accu<i>' accumulate: function( accuIndex, weight ) {
true
Other
mrdoob
three.js
08c40e22c7cec08cb4df7b3552392eff50a125c1.json
Remove unecessary constructor assignments
src/core/BufferAttribute.js
@@ -44,8 +44,6 @@ Object.defineProperty( BufferAttribute.prototype, "needsUpdate", { Object.assign( BufferAttribute.prototype, { - constructor: BufferAttribute, - isBufferAttribute: true, setArray: function ( array ) {
true
Other
mrdoob
three.js
08c40e22c7cec08cb4df7b3552392eff50a125c1.json
Remove unecessary constructor assignments
src/core/BufferGeometry.js
@@ -43,8 +43,6 @@ BufferGeometry.MaxIndex = 65535; Object.assign( BufferGeometry.prototype, EventDispatcher.prototype, { - constructor: BufferGeometry, - isBufferGeometry: true, getIndex: function () {
true
Other
mrdoob
three.js
08c40e22c7cec08cb4df7b3552392eff50a125c1.json
Remove unecessary constructor assignments
src/core/Clock.js
@@ -16,8 +16,6 @@ function Clock( autoStart ) { Object.assign( Clock.prototype, { - constructor: Clock, - start: function () { this.startTime = ( performance || Date ).now();
true
Other
mrdoob
three.js
08c40e22c7cec08cb4df7b3552392eff50a125c1.json
Remove unecessary constructor assignments
src/core/Face3.js
@@ -24,8 +24,6 @@ function Face3( a, b, c, normal, color, materialIndex ) { Object.assign( Face3.prototype, { - constructor: Face3, - clone: function () { return new this.constructor().copy( this );
true
Other
mrdoob
three.js
08c40e22c7cec08cb4df7b3552392eff50a125c1.json
Remove unecessary constructor assignments
src/core/Geometry.js
@@ -61,8 +61,6 @@ function Geometry() { Object.assign( Geometry.prototype, EventDispatcher.prototype, { - constructor: Geometry, - isGeometry: true, applyMatrix: function ( matrix ) {
true
Other
mrdoob
three.js
08c40e22c7cec08cb4df7b3552392eff50a125c1.json
Remove unecessary constructor assignments
src/core/InterleavedBuffer.js
@@ -33,8 +33,6 @@ Object.defineProperty( InterleavedBuffer.prototype, "needsUpdate", { Object.assign( InterleavedBuffer.prototype, { - constructor: InterleavedBuffer, - isInterleavedBuffer: true, setArray: function ( array ) {
true
Other
mrdoob
three.js
08c40e22c7cec08cb4df7b3552392eff50a125c1.json
Remove unecessary constructor assignments
src/core/InterleavedBufferAttribute.js
@@ -42,8 +42,6 @@ Object.defineProperties( InterleavedBufferAttribute.prototype, { Object.assign( InterleavedBufferAttribute.prototype, { - constructor: InterleavedBufferAttribute, - isInterleavedBufferAttribute: true, setX: function ( index, x ) {
true
Other
mrdoob
three.js
08c40e22c7cec08cb4df7b3552392eff50a125c1.json
Remove unecessary constructor assignments
src/core/Layers.js
@@ -10,8 +10,6 @@ function Layers() { Object.assign( Layers.prototype, { - constructor: Layers, - set: function ( channel ) { this.mask = 1 << channel;
true
Other
mrdoob
three.js
08c40e22c7cec08cb4df7b3552392eff50a125c1.json
Remove unecessary constructor assignments
src/core/Object3D.js
@@ -103,8 +103,6 @@ Object3D.DefaultMatrixAutoUpdate = true; Object.assign( Object3D.prototype, EventDispatcher.prototype, { - constructor: Object3D, - isObject3D: true, applyMatrix: function ( matrix ) {
true
Other
mrdoob
three.js
08c40e22c7cec08cb4df7b3552392eff50a125c1.json
Remove unecessary constructor assignments
src/core/Raycaster.js
@@ -61,8 +61,6 @@ function intersectObject( object, raycaster, intersects, recursive ) { Object.assign( Raycaster.prototype, { - constructor: Raycaster, - linePrecision: 1, set: function ( origin, direction ) {
true
Other
mrdoob
three.js
08c40e22c7cec08cb4df7b3552392eff50a125c1.json
Remove unecessary constructor assignments
src/extras/core/Curve.js
@@ -41,8 +41,6 @@ function Curve() {} Object.assign( Curve.prototype, { - constructor: Curve, - // Virtual base class method to overwrite and implement in subclasses // - t [0 .. 1]
true
Other
mrdoob
three.js
08c40e22c7cec08cb4df7b3552392eff50a125c1.json
Remove unecessary constructor assignments
src/loaders/Loader.js
@@ -67,8 +67,6 @@ Loader.Handlers = { Object.assign( Loader.prototype, { - constructor: Loader, - crossOrigin: undefined, extractUrlBase: function ( url ) {
true
Other
mrdoob
three.js
08c40e22c7cec08cb4df7b3552392eff50a125c1.json
Remove unecessary constructor assignments
src/materials/Material.js
@@ -82,8 +82,6 @@ Object.defineProperty( Material.prototype, "needsUpdate", { Object.assign( Material.prototype, EventDispatcher.prototype, { - constructor: Material, - isMaterial: true, setValues: function ( values ) {
true
Other
mrdoob
three.js
08c40e22c7cec08cb4df7b3552392eff50a125c1.json
Remove unecessary constructor assignments
src/materials/MultiMaterial.js
@@ -18,8 +18,6 @@ function MultiMaterial( materials ) { Object.assign( MultiMaterial.prototype, { - constructor: MultiMaterial, - isMultiMaterial: true, toJSON: function ( meta ) {
true
Other
mrdoob
three.js
08c40e22c7cec08cb4df7b3552392eff50a125c1.json
Remove unecessary constructor assignments
src/math/Box2.js
@@ -13,8 +13,6 @@ function Box2( min, max ) { Object.assign( Box2.prototype, { - constructor: Box2, - set: function ( min, max ) { this.min.copy( min );
true
Other
mrdoob
three.js
08c40e22c7cec08cb4df7b3552392eff50a125c1.json
Remove unecessary constructor assignments
src/math/Box3.js
@@ -15,8 +15,6 @@ function Box3( min, max ) { Object.assign( Box3.prototype, { - constructor: Box3, - isBox3: true, set: function ( min, max ) {
true
Other
mrdoob
three.js
08c40e22c7cec08cb4df7b3552392eff50a125c1.json
Remove unecessary constructor assignments
src/math/Color.js
@@ -44,8 +44,6 @@ function Color( r, g, b ) { Object.assign( Color.prototype, { - constructor: Color, - isColor: true, r: 1, g: 1, b: 1,
true
Other
mrdoob
three.js
08c40e22c7cec08cb4df7b3552392eff50a125c1.json
Remove unecessary constructor assignments
src/math/Cylindrical.js
@@ -17,8 +17,6 @@ function Cylindrical( radius, theta, y ) { Object.assign( Cylindrical.prototype, { - constructor: Cylindrical, - set: function ( radius, theta, y ) { this.radius = radius;
true
Other
mrdoob
three.js
08c40e22c7cec08cb4df7b3552392eff50a125c1.json
Remove unecessary constructor assignments
src/math/Euler.js
@@ -96,8 +96,6 @@ Object.defineProperties( Euler.prototype, { Object.assign( Euler.prototype, { - constructor: Euler, - isEuler: true, set: function ( x, y, z, order ) {
true
Other
mrdoob
three.js
08c40e22c7cec08cb4df7b3552392eff50a125c1.json
Remove unecessary constructor assignments
src/math/Frustum.js
@@ -25,8 +25,6 @@ function Frustum( p0, p1, p2, p3, p4, p5 ) { Object.assign( Frustum.prototype, { - constructor: Frustum, - set: function ( p0, p1, p2, p3, p4, p5 ) { var planes = this.planes;
true
Other
mrdoob
three.js
08c40e22c7cec08cb4df7b3552392eff50a125c1.json
Remove unecessary constructor assignments
src/math/Interpolant.js
@@ -34,8 +34,6 @@ function Interpolant( parameterPositions, sampleValues, sampleSize, resultBuffer Object.assign( Interpolant.prototype, { - constructor: Interpolant, - evaluate: function( t ) { var pp = this.parameterPositions,
true
Other
mrdoob
three.js
08c40e22c7cec08cb4df7b3552392eff50a125c1.json
Remove unecessary constructor assignments
src/math/Line3.js
@@ -14,8 +14,6 @@ function Line3( start, end ) { Object.assign( Line3.prototype, { - constructor: Line3, - set: function ( start, end ) { this.start.copy( start );
true
Other
mrdoob
three.js
08c40e22c7cec08cb4df7b3552392eff50a125c1.json
Remove unecessary constructor assignments
src/math/Matrix3.js
@@ -27,8 +27,6 @@ function Matrix3() { Object.assign( Matrix3.prototype, { - constructor: Matrix3, - isMatrix3: true, set: function ( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
true
Other
mrdoob
three.js
08c40e22c7cec08cb4df7b3552392eff50a125c1.json
Remove unecessary constructor assignments
src/math/Matrix4.js
@@ -35,8 +35,6 @@ function Matrix4() { Object.assign( Matrix4.prototype, { - constructor: Matrix4, - isMatrix4: true, set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
true
Other
mrdoob
three.js
08c40e22c7cec08cb4df7b3552392eff50a125c1.json
Remove unecessary constructor assignments
src/math/Plane.js
@@ -14,8 +14,6 @@ function Plane( normal, constant ) { Object.assign( Plane.prototype, { - constructor: Plane, - set: function ( normal, constant ) { this.normal.copy( normal );
true
Other
mrdoob
three.js
08c40e22c7cec08cb4df7b3552392eff50a125c1.json
Remove unecessary constructor assignments
src/math/Quaternion.js
@@ -163,8 +163,6 @@ Object.defineProperties( Quaternion.prototype, { Object.assign( Quaternion.prototype, { - constructor: Quaternion, - set: function ( x, y, z, w ) { this._x = x;
true
Other
mrdoob
three.js
08c40e22c7cec08cb4df7b3552392eff50a125c1.json
Remove unecessary constructor assignments
src/math/Ray.js
@@ -13,8 +13,6 @@ function Ray( origin, direction ) { Object.assign( Ray.prototype, { - constructor: Ray, - set: function ( origin, direction ) { this.origin.copy( origin );
true
Other
mrdoob
three.js
08c40e22c7cec08cb4df7b3552392eff50a125c1.json
Remove unecessary constructor assignments
src/math/Sphere.js
@@ -15,8 +15,6 @@ function Sphere( center, radius ) { Object.assign( Sphere.prototype, { - constructor: Sphere, - set: function ( center, radius ) { this.center.copy( center );
true
Other
mrdoob
three.js
08c40e22c7cec08cb4df7b3552392eff50a125c1.json
Remove unecessary constructor assignments
src/math/Spherical.js
@@ -22,8 +22,6 @@ function Spherical( radius, phi, theta ) { Object.assign( Spherical.prototype, { - constructor: Spherical, - set: function ( radius, phi, theta ) { this.radius = radius;
true
Other
mrdoob
three.js
08c40e22c7cec08cb4df7b3552392eff50a125c1.json
Remove unecessary constructor assignments
src/math/Triangle.js
@@ -104,8 +104,6 @@ Object.assign( Triangle, { Object.assign( Triangle.prototype, { - constructor: Triangle, - set: function ( a, b, c ) { this.a.copy( a );
true
Other
mrdoob
three.js
08c40e22c7cec08cb4df7b3552392eff50a125c1.json
Remove unecessary constructor assignments
src/math/Vector2.js
@@ -50,8 +50,6 @@ Object.defineProperties( Vector2.prototype, { Object.assign( Vector2.prototype, { - constructor: Vector2, - isVector2: true, set: function ( x, y ) {
true
Other
mrdoob
three.js
08c40e22c7cec08cb4df7b3552392eff50a125c1.json
Remove unecessary constructor assignments
src/math/Vector3.js
@@ -21,8 +21,6 @@ function Vector3( x, y, z ) { Object.assign( Vector3.prototype, { - constructor: Vector3, - isVector3: true, set: function ( x, y, z ) {
true
Other
mrdoob
three.js
08c40e22c7cec08cb4df7b3552392eff50a125c1.json
Remove unecessary constructor assignments
src/math/Vector4.js
@@ -17,8 +17,6 @@ function Vector4( x, y, z, w ) { Object.assign( Vector4.prototype, { - constructor: Vector4, - isVector4: true, set: function ( x, y, z, w ) {
true
Other
mrdoob
three.js
08c40e22c7cec08cb4df7b3552392eff50a125c1.json
Remove unecessary constructor assignments
src/renderers/WebGLRenderTarget.js
@@ -41,8 +41,6 @@ function WebGLRenderTarget( width, height, options ) { Object.assign( WebGLRenderTarget.prototype, EventDispatcher.prototype, { - constructor: WebGLRenderTarget, - isWebGLRenderTarget: true, setSize: function ( width, height ) {
true
Other
mrdoob
three.js
246393ebf1af7a285886fd906287cc9a60423df8.json
Implement LineLoop using `LINE_LOOP` rendering
docs/api/objects/LineLoop.html
@@ -0,0 +1,55 @@ +<!DOCTYPE html> +<html lang="en"> + <head> + <meta charset="utf-8" /> + <base href="../../" /> + <script src="list.js"></script> + <script src="page.js"></script> + <link type="text/css" rel="stylesheet" href="page.css" /> + </head> + <body> + [page:Object3D] &rarr; [page:Line] &rarr; + + <h1>[name]</h1> + + <div class="desc"> + A continuous line that connects back to the start.<br /><br /> + + This is nearly the same as [page:Line]; the only difference is that it is rendered using + [link:https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/drawElements gl.LINE_LOOP] + instead of [link:https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/drawElements gl.LINE_STRIP], + which draws a straight line to the next vertex, and connects the last vertex back to the first. + </div> + + + <h2>Constructor</h2> + + <h3>[name]( [page:Geometry geometry], [page:Material material] )</h3> + + <div> + [page:Geometry geometry] — List of vertices representing points on the line loop.<br /> + [page:Material material] — Material for the line. Default is [page:LineBasicMaterial LineBasicMaterial]. + </div> + + <div>If no material is supplied, a randomized line material will be created and assigned to the object.</div> + + + <h2>Properties</h2> + <div>See the base [page:Line] class for common properties.</div> + + <h3>[property:Boolean isLineLoop]</h3> + <div> + Used to check whether this or derived classes are line loops. Default is *true*.<br /><br /> + + You should not change this, as it used internally for optimisation. + </div> + + + <h2>Methods</h2> + <div>See the base [page:Line] class for common methods.</div> + + <h2>Source</h2> + + [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js] + </body> +</html>
true
Other
mrdoob
three.js
246393ebf1af7a285886fd906287cc9a60423df8.json
Implement LineLoop using `LINE_LOOP` rendering
docs/list.js
@@ -286,6 +286,7 @@ var list = { [ "Group", "api/objects/Group" ], [ "LensFlare", "api/objects/LensFlare" ], [ "Line", "api/objects/Line" ], + [ "LineLoop", "api/objects/LineLoop" ], [ "LineSegments", "api/objects/LineSegments" ], [ "LOD", "api/objects/LOD" ], [ "Mesh", "api/objects/Mesh" ],
true
Other
mrdoob
three.js
246393ebf1af7a285886fd906287cc9a60423df8.json
Implement LineLoop using `LINE_LOOP` rendering
examples/js/loaders/GLTFLoader.js
@@ -1940,6 +1940,10 @@ THREE.GLTFLoader = ( function () { child = new THREE.LineSegments( originalGeometry, material ); break; + case 'LineLoop': + child = new THREE.LineLoop( originalGeometry, material ); + break; + case 'Line': child = new THREE.Line( originalGeometry, material ); break;
true
Other
mrdoob
three.js
246393ebf1af7a285886fd906287cc9a60423df8.json
Implement LineLoop using `LINE_LOOP` rendering
src/Three.js
@@ -19,6 +19,7 @@ export { Skeleton } from './objects/Skeleton.js'; export { Bone } from './objects/Bone.js'; export { Mesh } from './objects/Mesh.js'; export { LineSegments } from './objects/LineSegments.js'; +export { LineLoop } from './objects/LineLoop.js'; export { Line } from './objects/Line.js'; export { Points } from './objects/Points.js'; export { Group } from './objects/Group.js';
true
Other
mrdoob
three.js
246393ebf1af7a285886fd906287cc9a60423df8.json
Implement LineLoop using `LINE_LOOP` rendering
src/loaders/ObjectLoader.js
@@ -666,6 +666,12 @@ Object.assign( ObjectLoader.prototype, { break; + case 'LineLoop': + + object = new LineLoop( getGeometry( data.geometry ), getMaterial( data.material ) ); + + break; + case 'LineSegments': object = new LineSegments( getGeometry( data.geometry ), getMaterial( data.material ) );
true
Other
mrdoob
three.js
246393ebf1af7a285886fd906287cc9a60423df8.json
Implement LineLoop using `LINE_LOOP` rendering
src/objects/LineLoop.js
@@ -0,0 +1,24 @@ +import { Line } from './Line'; + +/** + * @author mgreter / http://github.com/mgreter + */ + +function LineLoop( geometry, material ) { + + Line.call( this, geometry, material ); + + this.type = 'LineLoop'; + +} + +LineLoop.prototype = Object.assign( Object.create( Line.prototype ), { + + constructor: LineLoop, + + isLineLoop: true, + +} ); + + +export { LineLoop };
true
Other
mrdoob
three.js
246393ebf1af7a285886fd906287cc9a60423df8.json
Implement LineLoop using `LINE_LOOP` rendering
src/renderers/WebGLRenderer.js
@@ -855,6 +855,10 @@ function WebGLRenderer( parameters ) { renderer.setMode( _gl.LINES ); + } else if ( object.isLineLoop ) { + + renderer.setMode( _gl.LINE_LOOP ); + } else { renderer.setMode( _gl.LINE_STRIP );
true
Other
mrdoob
three.js
945c76723e98de898d90eebf3bbed8a841238395.json
add UI for size selection
examples/js/vr/PaintViveController.js
@@ -47,19 +47,53 @@ THREE.PaintViveController = function ( id ) { } + // COLOR UI + var geometry = new THREE.CircleGeometry( 1, 32 ); var material = new THREE.MeshBasicMaterial( { map: generateHueTexture() } ); - var mesh = new THREE.Mesh( geometry, material ); - mesh.position.set( 0, 0.005, 0.0495 ); - mesh.rotation.x = - 1.45; - mesh.scale.setScalar( 0.02 ); - this.add( mesh ); + var colorUI = new THREE.Mesh( geometry, material ); + colorUI.position.set( 0, 0.005, 0.0495 ); + colorUI.rotation.x = - 1.45; + colorUI.scale.setScalar( 0.02 ); + this.add( colorUI ); var geometry = new THREE.IcosahedronGeometry( 0.1, 2 ); var material = new THREE.MeshBasicMaterial(); material.color = color; var ball = new THREE.Mesh( geometry, material ); - mesh.add( ball ); + colorUI.add( ball ); + + + // SIZE UI + var sizeUI = new THREE.Group(); + sizeUI.position.set( 0, 0.005, 0.0495 ); + sizeUI.rotation.x = - 1.45; + sizeUI.scale.setScalar( 0.02 ); + this.add( sizeUI ); + + var triangleShape = new THREE.Shape(); + triangleShape.moveTo( 0, -1 ); + triangleShape.lineTo( 1, 1 ); + triangleShape.lineTo( -1, 1 ); + + var geometry = new THREE.ShapeGeometry( triangleShape ); + var material = new THREE.MeshBasicMaterial( { color: 0x222222, wireframe:true } ); + var sizeUIOutline = new THREE.Mesh( geometry, material ) ; + sizeUIOutline.position.z = 0.001; + resizeTriangleGeometry(sizeUIOutline.geometry, 1.0); + sizeUI.add( sizeUIOutline ); + + var geometry = new THREE.ShapeGeometry( triangleShape ); + var material = new THREE.MeshBasicMaterial( {side: THREE.DoubleSide } ); + material.color = color; + var sizeUIFill = new THREE.Mesh( geometry, material ) ; + sizeUIFill.position.z = 0.0011; + resizeTriangleGeometry(sizeUIFill.geometry, 0.5); + sizeUI.add( sizeUIFill ); + + sizeUI.visible = false; + + function onAxisChanged( event ) { @@ -70,27 +104,52 @@ THREE.PaintViveController = function ( id ) { if ( mode === MODES.COLOR ) { color.setHSL( Math.atan2( y, x ) / PI2, 1, ( 0.5 - Math.sqrt( x * x + y * y ) ) * 2.0 ); - ball.position.x = event.axes[ 0 ]; - ball.position.y = event.axes[ 1 ]; + + ball.position.set(event.axes[ 0 ], event.axes[ 1 ], 0); } if ( mode === MODES.SIZE ) { - size = (0.5 - y) * 2; + var ratio = (0.5 - y); + size = ratio * 2; + + resizeTriangleGeometry(sizeUIFill.geometry, ratio); } } + function resizeTriangleGeometry(geometry, ratio) { + + + + var x = 0, y =0; + var fullWidth = 0.75; fullHeight = 1.5; + var angle = Math.atan((fullWidth/2)/fullHeight); + + var bottomY = y - fullHeight/2; + var height = fullHeight * ratio; + var width = (Math.tan(angle) * height) * 2; + + geometry.vertices[0].set( x, bottomY, 0); + geometry.vertices[1].set( x + width/2, bottomY + height, 0 ); + geometry.vertices[2].set( x - width/2, bottomY + height, 0 ); + + geometry.verticesNeedUpdate = true; + + } + function onGripsDown( event ) { if ( mode === MODES.COLOR ) { mode = MODES.SIZE; - mesh.visible = false; + colorUI.visible = false; + sizeUI.visible = true; return; } if ( mode === MODES.SIZE ) { mode = MODES.COLOR; - mesh.visible = true; + colorUI.visible = true; + sizeUI.visible = false; return; }
false
Other
mrdoob
three.js
2254a241d084615ad5fe5fa35e515c6c2f556041.json
Fix Interpolant alias
src/math/Interpolant.js
@@ -36,12 +36,6 @@ Object.assign( Interpolant.prototype, { constructor: Interpolant, - beforeStart_: //( 0, t, t0 ), returns this.resultBuffer - Interpolant.prototype.copySampleValue_, - - afterEnd_: //( N-1, tN-1, t ), returns this.resultBuffer - Interpolant.prototype.copySampleValue_, - evaluate: function( t ) { var pp = this.parameterPositions, @@ -251,5 +245,15 @@ Object.assign( Interpolant.prototype, { } ); +//!\ DECLARE ALIAS AFTER assign prototype ! +Object.assign( Interpolant.prototype, { + + //( 0, t, t0 ), returns this.resultBuffer + beforeStart_: Interpolant.prototype.copySampleValue_, + + //( N-1, tN-1, t ), returns this.resultBuffer + afterEnd_: Interpolant.prototype.copySampleValue_, + +} ); export { Interpolant };
false
Other
mrdoob
three.js
9ee0f7dddb7b38f2706acb450d2539cd5dc615ee.json
Fix Texture accessors
src/textures/Texture.js
@@ -59,17 +59,17 @@ function Texture( image, mapping, wrapS, wrapT, magFilter, minFilter, format, ty Texture.DEFAULT_IMAGE = undefined; Texture.DEFAULT_MAPPING = UVMapping; -Object.assign( Texture.prototype, EventDispatcher.prototype, { +Object.defineProperty( Texture.prototype, "needsUpdate", { - constructor: Texture, + set: function(value) { if ( value === true ) this.version ++; } - isTexture: true, +}); - set needsUpdate( value ) { +Object.assign( Texture.prototype, EventDispatcher.prototype, { - if ( value === true ) this.version ++; + constructor: Texture, - }, + isTexture: true, clone: function () {
false
Other
mrdoob
three.js
13f13397e9b59afb9e9c920f329e52309a2d7088.json
Fix Vector2 accessors
src/math/Vector2.js
@@ -12,37 +12,26 @@ function Vector2( x, y ) { } -Object.assign( Vector2.prototype, { - - constructor: Vector2, - - isVector2: true, - - get width() { - - return this.x; +Object.defineProperties( Vector2.prototype, { + "width" : { + get: function () { return this.x; }, + set: function ( value ) { this.x = value; } }, - set width( value ) { - - this.x = value; - - }, - - get height() { - - return this.y; + "height" : { + get: function () { return this.y; }, + set: function ( value ) { this.y = value; } + } - }, +} ); - set height( value ) { - this.y = value; +Object.assign( Vector2.prototype, { - }, + constructor: Vector2, - // + isVector2: true, set: function ( x, y ) {
false