提交 038c576b 编写于 作者: M Mr.doob

Merge branch 'dev' into instancing

......@@ -2144,11 +2144,13 @@
},
projectOnVector: function ( vector ) {
projectOnVector: function ( v ) {
var scalar = vector.dot( this ) / vector.lengthSq();
// v cannot be the zero v
return this.copy( vector ).multiplyScalar( scalar );
var scalar = v.dot( this ) / v.lengthSq();
return this.copy( v ).multiplyScalar( scalar );
},
......@@ -2171,6 +2173,8 @@
angleTo: function ( v ) {
// assumes this and v are not the zero vector
var theta = this.dot( v ) / ( Math.sqrt( this.lengthSq() * v.lengthSq() ) );
// clamp, to handle numerical problems
......@@ -11374,6 +11378,13 @@
var indices = geometry.index !== null ? geometry.index.array : undefined;
var attributes = geometry.attributes;
if ( attributes.position === undefined ) {
console.error( 'THREE.Geometry.fromBufferGeometry(): Position attribute required for conversion.' );
return this;
}
var positions = attributes.position.array;
var normals = attributes.normal !== undefined ? attributes.normal.array : undefined;
var colors = attributes.color !== undefined ? attributes.color.array : undefined;
......@@ -14039,7 +14050,7 @@
var color_vertex = "#ifdef USE_COLOR\n\tvColor.xyz = color.xyz;\n#endif";
var common = "#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI_HALF 1.5707963267949\n#define RECIPROCAL_PI 0.31830988618\n#define RECIPROCAL_PI2 0.15915494\n#define LOG2 1.442695\n#define EPSILON 1e-6\n#define saturate(a) clamp( a, 0.0, 1.0 )\n#define whiteComplement(a) ( 1.0 - saturate( a ) )\nfloat pow2( const in float x ) { return x*x; }\nfloat pow3( const in float x ) { return x*x*x; }\nfloat pow4( const in float x ) { float x2 = x*x; return x2*x2; }\nfloat average( const in vec3 color ) { return dot( color, vec3( 0.3333 ) ); }\nhighp float rand( const in vec2 uv ) {\n\tconst highp float a = 12.9898, b = 78.233, c = 43758.5453;\n\thighp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );\n\treturn fract(sin(sn) * c);\n}\n#ifdef HIGH_PRECISION\n\tfloat precisionSafeLength( vec3 v ) { return length( v ); }\n#else\n\tfloat max3( vec3 v ) { return max( max( v.x, v.y ), v.z ); }\n\tfloat precisionSafeLength( vec3 v ) {\n\t\tfloat maxComponent = max3( abs( v ) );\n\t\treturn length( v / maxComponent ) * maxComponent;\n\t}\n#endif\nstruct IncidentLight {\n\tvec3 color;\n\tvec3 direction;\n\tbool visible;\n};\nstruct ReflectedLight {\n\tvec3 directDiffuse;\n\tvec3 directSpecular;\n\tvec3 indirectDiffuse;\n\tvec3 indirectSpecular;\n};\nstruct GeometricContext {\n\tvec3 position;\n\tvec3 normal;\n\tvec3 viewDir;\n#ifdef CLEARCOAT\n\tvec3 clearcoatNormal;\n#endif\n};\nvec3 transformDirection( in vec3 dir, in mat4 matrix ) {\n\treturn normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );\n}\nvec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) {\n\treturn normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );\n}\nvec3 projectOnPlane(in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\tfloat distance = dot( planeNormal, point - pointOnPlane );\n\treturn - distance * planeNormal + point;\n}\nfloat sideOfPlane( in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\treturn sign( dot( point - pointOnPlane, planeNormal ) );\n}\nvec3 linePlaneIntersect( in vec3 pointOnLine, in vec3 lineDirection, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\treturn lineDirection * ( dot( planeNormal, pointOnPlane - pointOnLine ) / dot( planeNormal, lineDirection ) ) + pointOnLine;\n}\nmat3 transposeMat3( const in mat3 m ) {\n\tmat3 tmp;\n\ttmp[ 0 ] = vec3( m[ 0 ].x, m[ 1 ].x, m[ 2 ].x );\n\ttmp[ 1 ] = vec3( m[ 0 ].y, m[ 1 ].y, m[ 2 ].y );\n\ttmp[ 2 ] = vec3( m[ 0 ].z, m[ 1 ].z, m[ 2 ].z );\n\treturn tmp;\n}\nfloat linearToRelativeLuminance( const in vec3 color ) {\n\tvec3 weights = vec3( 0.2126, 0.7152, 0.0722 );\n\treturn dot( weights, color.rgb );\n}\nbool isPerspectiveMatrix( mat4 projectionMatrix ) {\n return projectionMatrix[ 2 ][ 3 ] == - 1.0;\n}";
var common = "#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI_HALF 1.5707963267949\n#define RECIPROCAL_PI 0.31830988618\n#define RECIPROCAL_PI2 0.15915494\n#define LOG2 1.442695\n#define EPSILON 1e-6\n#ifndef saturate\n#define saturate(a) clamp( a, 0.0, 1.0 )\n#endif\n#define whiteComplement(a) ( 1.0 - saturate( a ) )\nfloat pow2( const in float x ) { return x*x; }\nfloat pow3( const in float x ) { return x*x*x; }\nfloat pow4( const in float x ) { float x2 = x*x; return x2*x2; }\nfloat average( const in vec3 color ) { return dot( color, vec3( 0.3333 ) ); }\nhighp float rand( const in vec2 uv ) {\n\tconst highp float a = 12.9898, b = 78.233, c = 43758.5453;\n\thighp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );\n\treturn fract(sin(sn) * c);\n}\n#ifdef HIGH_PRECISION\n\tfloat precisionSafeLength( vec3 v ) { return length( v ); }\n#else\n\tfloat max3( vec3 v ) { return max( max( v.x, v.y ), v.z ); }\n\tfloat precisionSafeLength( vec3 v ) {\n\t\tfloat maxComponent = max3( abs( v ) );\n\t\treturn length( v / maxComponent ) * maxComponent;\n\t}\n#endif\nstruct IncidentLight {\n\tvec3 color;\n\tvec3 direction;\n\tbool visible;\n};\nstruct ReflectedLight {\n\tvec3 directDiffuse;\n\tvec3 directSpecular;\n\tvec3 indirectDiffuse;\n\tvec3 indirectSpecular;\n};\nstruct GeometricContext {\n\tvec3 position;\n\tvec3 normal;\n\tvec3 viewDir;\n#ifdef CLEARCOAT\n\tvec3 clearcoatNormal;\n#endif\n};\nvec3 transformDirection( in vec3 dir, in mat4 matrix ) {\n\treturn normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );\n}\nvec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) {\n\treturn normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );\n}\nvec3 projectOnPlane(in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\tfloat distance = dot( planeNormal, point - pointOnPlane );\n\treturn - distance * planeNormal + point;\n}\nfloat sideOfPlane( in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\treturn sign( dot( point - pointOnPlane, planeNormal ) );\n}\nvec3 linePlaneIntersect( in vec3 pointOnLine, in vec3 lineDirection, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\treturn lineDirection * ( dot( planeNormal, pointOnPlane - pointOnLine ) / dot( planeNormal, lineDirection ) ) + pointOnLine;\n}\nmat3 transposeMat3( const in mat3 m ) {\n\tmat3 tmp;\n\ttmp[ 0 ] = vec3( m[ 0 ].x, m[ 1 ].x, m[ 2 ].x );\n\ttmp[ 1 ] = vec3( m[ 0 ].y, m[ 1 ].y, m[ 2 ].y );\n\ttmp[ 2 ] = vec3( m[ 0 ].z, m[ 1 ].z, m[ 2 ].z );\n\treturn tmp;\n}\nfloat linearToRelativeLuminance( const in vec3 color ) {\n\tvec3 weights = vec3( 0.2126, 0.7152, 0.0722 );\n\treturn dot( weights, color.rgb );\n}\nbool isPerspectiveMatrix( mat4 projectionMatrix ) {\n return projectionMatrix[ 2 ][ 3 ] == - 1.0;\n}";
var cube_uv_reflection_fragment = "#ifdef ENVMAP_TYPE_CUBE_UV\n#define cubeUV_textureSize (1024.0)\nint getFaceFromDirection(vec3 direction) {\n\tvec3 absDirection = abs(direction);\n\tint face = -1;\n\tif( absDirection.x > absDirection.z ) {\n\t\tif(absDirection.x > absDirection.y )\n\t\t\tface = direction.x > 0.0 ? 0 : 3;\n\t\telse\n\t\t\tface = direction.y > 0.0 ? 1 : 4;\n\t}\n\telse {\n\t\tif(absDirection.z > absDirection.y )\n\t\t\tface = direction.z > 0.0 ? 2 : 5;\n\t\telse\n\t\t\tface = direction.y > 0.0 ? 1 : 4;\n\t}\n\treturn face;\n}\n#define cubeUV_maxLods1 (log2(cubeUV_textureSize*0.25) - 1.0)\n#define cubeUV_rangeClamp (exp2((6.0 - 1.0) * 2.0))\nvec2 MipLevelInfo( vec3 vec, float roughnessLevel, float roughness ) {\n\tfloat scale = exp2(cubeUV_maxLods1 - roughnessLevel);\n\tfloat dxRoughness = dFdx(roughness);\n\tfloat dyRoughness = dFdy(roughness);\n\tvec3 dx = dFdx( vec * scale * dxRoughness );\n\tvec3 dy = dFdy( vec * scale * dyRoughness );\n\tfloat d = max( dot( dx, dx ), dot( dy, dy ) );\n\td = clamp(d, 1.0, cubeUV_rangeClamp);\n\tfloat mipLevel = 0.5 * log2(d);\n\treturn vec2(floor(mipLevel), fract(mipLevel));\n}\n#define cubeUV_maxLods2 (log2(cubeUV_textureSize*0.25) - 2.0)\n#define cubeUV_rcpTextureSize (1.0 / cubeUV_textureSize)\nvec2 getCubeUV(vec3 direction, float roughnessLevel, float mipLevel) {\n\tmipLevel = roughnessLevel > cubeUV_maxLods2 - 3.0 ? 0.0 : mipLevel;\n\tfloat a = 16.0 * cubeUV_rcpTextureSize;\n\tvec2 exp2_packed = exp2( vec2( roughnessLevel, mipLevel ) );\n\tvec2 rcp_exp2_packed = vec2( 1.0 ) / exp2_packed;\n\tfloat powScale = exp2_packed.x * exp2_packed.y;\n\tfloat scale = rcp_exp2_packed.x * rcp_exp2_packed.y * 0.25;\n\tfloat mipOffset = 0.75*(1.0 - rcp_exp2_packed.y) * rcp_exp2_packed.x;\n\tbool bRes = mipLevel == 0.0;\n\tscale = bRes && (scale < a) ? a : scale;\n\tvec3 r;\n\tvec2 offset;\n\tint face = getFaceFromDirection(direction);\n\tfloat rcpPowScale = 1.0 / powScale;\n\tif( face == 0) {\n\t\tr = vec3(direction.x, -direction.z, direction.y);\n\t\toffset = vec2(0.0+mipOffset,0.75 * rcpPowScale);\n\t\toffset.y = bRes && (offset.y < 2.0*a) ? a : offset.y;\n\t}\n\telse if( face == 1) {\n\t\tr = vec3(direction.y, direction.x, direction.z);\n\t\toffset = vec2(scale+mipOffset, 0.75 * rcpPowScale);\n\t\toffset.y = bRes && (offset.y < 2.0*a) ? a : offset.y;\n\t}\n\telse if( face == 2) {\n\t\tr = vec3(direction.z, direction.x, direction.y);\n\t\toffset = vec2(2.0*scale+mipOffset, 0.75 * rcpPowScale);\n\t\toffset.y = bRes && (offset.y < 2.0*a) ? a : offset.y;\n\t}\n\telse if( face == 3) {\n\t\tr = vec3(direction.x, direction.z, direction.y);\n\t\toffset = vec2(0.0+mipOffset,0.5 * rcpPowScale);\n\t\toffset.y = bRes && (offset.y < 2.0*a) ? 0.0 : offset.y;\n\t}\n\telse if( face == 4) {\n\t\tr = vec3(direction.y, direction.x, -direction.z);\n\t\toffset = vec2(scale+mipOffset, 0.5 * rcpPowScale);\n\t\toffset.y = bRes && (offset.y < 2.0*a) ? 0.0 : offset.y;\n\t}\n\telse {\n\t\tr = vec3(direction.z, -direction.x, direction.y);\n\t\toffset = vec2(2.0*scale+mipOffset, 0.5 * rcpPowScale);\n\t\toffset.y = bRes && (offset.y < 2.0*a) ? 0.0 : offset.y;\n\t}\n\tr = normalize(r);\n\tfloat texelOffset = 0.5 * cubeUV_rcpTextureSize;\n\tvec2 s = ( r.yz / abs( r.x ) + vec2( 1.0 ) ) * 0.5;\n\tvec2 base = offset + vec2( texelOffset );\n\treturn base + s * ( scale - 2.0 * texelOffset );\n}\n#define cubeUV_maxLods3 (log2(cubeUV_textureSize*0.25) - 3.0)\nvec4 textureCubeUV( sampler2D envMap, vec3 reflectedDirection, float roughness ) {\n\tfloat roughnessVal = roughness* cubeUV_maxLods3;\n\tfloat r1 = floor(roughnessVal);\n\tfloat r2 = r1 + 1.0;\n\tfloat t = fract(roughnessVal);\n\tvec2 mipInfo = MipLevelInfo(reflectedDirection, r1, roughness);\n\tfloat s = mipInfo.y;\n\tfloat level0 = mipInfo.x;\n\tfloat level1 = level0 + 1.0;\n\tlevel1 = level1 > 5.0 ? 5.0 : level1;\n\tlevel0 += min( floor( s + 0.5 ), 5.0 );\n\tvec2 uv_10 = getCubeUV(reflectedDirection, r1, level0);\n\tvec4 color10 = envMapTexelToLinear(texture2D(envMap, uv_10));\n\tvec2 uv_20 = getCubeUV(reflectedDirection, r2, level0);\n\tvec4 color20 = envMapTexelToLinear(texture2D(envMap, uv_20));\n\tvec4 result = mix(color10, color20, t);\n\treturn vec4(result.rgb, 1.0);\n}\n#endif";
......@@ -14175,7 +14186,7 @@
var tonemapping_fragment = "#if defined( TONE_MAPPING )\n\tgl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif";
var tonemapping_pars_fragment = "#ifndef saturate\n\t#define saturate(a) clamp( a, 0.0, 1.0 )\n#endif\nuniform float toneMappingExposure;\nuniform float toneMappingWhitePoint;\nvec3 LinearToneMapping( vec3 color ) {\n\treturn toneMappingExposure * color;\n}\nvec3 ReinhardToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\treturn saturate( color / ( vec3( 1.0 ) + color ) );\n}\n#define Uncharted2Helper( x ) max( ( ( x * ( 0.15 * x + 0.10 * 0.50 ) + 0.20 * 0.02 ) / ( x * ( 0.15 * x + 0.50 ) + 0.20 * 0.30 ) ) - 0.02 / 0.30, vec3( 0.0 ) )\nvec3 Uncharted2ToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\treturn saturate( Uncharted2Helper( color ) / Uncharted2Helper( vec3( toneMappingWhitePoint ) ) );\n}\nvec3 OptimizedCineonToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\tcolor = max( vec3( 0.0 ), color - 0.004 );\n\treturn pow( ( color * ( 6.2 * color + 0.5 ) ) / ( color * ( 6.2 * color + 1.7 ) + 0.06 ), vec3( 2.2 ) );\n}\nvec3 ACESFilmicToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\treturn saturate( ( color * ( 2.51 * color + 0.03 ) ) / ( color * ( 2.43 * color + 0.59 ) + 0.14 ) );\n}";
var tonemapping_pars_fragment = "#ifndef saturate\n#define saturate(a) clamp( a, 0.0, 1.0 )\n#endif\nuniform float toneMappingExposure;\nuniform float toneMappingWhitePoint;\nvec3 LinearToneMapping( vec3 color ) {\n\treturn toneMappingExposure * color;\n}\nvec3 ReinhardToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\treturn saturate( color / ( vec3( 1.0 ) + color ) );\n}\n#define Uncharted2Helper( x ) max( ( ( x * ( 0.15 * x + 0.10 * 0.50 ) + 0.20 * 0.02 ) / ( x * ( 0.15 * x + 0.50 ) + 0.20 * 0.30 ) ) - 0.02 / 0.30, vec3( 0.0 ) )\nvec3 Uncharted2ToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\treturn saturate( Uncharted2Helper( color ) / Uncharted2Helper( vec3( toneMappingWhitePoint ) ) );\n}\nvec3 OptimizedCineonToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\tcolor = max( vec3( 0.0 ), color - 0.004 );\n\treturn pow( ( color * ( 6.2 * color + 0.5 ) ) / ( color * ( 6.2 * color + 1.7 ) + 0.06 ), vec3( 2.2 ) );\n}\nvec3 ACESFilmicToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\treturn saturate( ( color * ( 2.51 * color + 0.03 ) ) / ( color * ( 2.43 * color + 0.59 ) + 0.14 ) );\n}";
var uv_pars_fragment = "#ifdef USE_UV\n\tvarying vec2 vUv;\n#endif";
......@@ -16371,6 +16382,8 @@
this.generateMipmaps = false;
this.flipY = false;
this.needsUpdate = true;
}
DataTexture2DArray.prototype = Object.create( Texture.prototype );
......@@ -16403,6 +16416,9 @@
this.generateMipmaps = false;
this.flipY = false;
this.needsUpdate = true;
}
DataTexture3D.prototype = Object.create( Texture.prototype );
......@@ -17460,52 +17476,58 @@
}
function parseIncludes( string ) {
// Resolve Includes
var pattern = /^[ \t]*#include +<([\w\d./]+)>/gm;
var includePattern = /^[ \t]*#include +<([\w\d./]+)>/gm;
function replace( match, include ) {
function resolveIncludes( string ) {
var replace = ShaderChunk[ include ];
return string.replace( includePattern, includeReplacer );
if ( replace === undefined ) {
}
throw new Error( 'Can not resolve #include <' + include + '>' );
function includeReplacer( match, include ) {
}
var string = ShaderChunk[ include ];
return parseIncludes( replace );
if ( string === undefined ) {
throw new Error( 'Can not resolve #include <' + include + '>' );
}
return string.replace( pattern, replace );
return resolveIncludes( string );
}
function unrollLoops( string ) {
// Unroll Loops
var pattern = /#pragma unroll_loop[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
var loopPattern = /#pragma unroll_loop[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
function replace( match, start, end, snippet ) {
function unrollLoops( string ) {
var unroll = '';
return string.replace( loopPattern, loopReplacer );
for ( var i = parseInt( start ); i < parseInt( end ); i ++ ) {
}
unroll += snippet
.replace( /\[ i \]/g, '[ ' + i + ' ]' )
.replace( /UNROLLED_LOOP_INDEX/g, i );
function loopReplacer( match, start, end, snippet ) {
}
var string = '';
for ( var i = parseInt( start ); i < parseInt( end ); i ++ ) {
return unroll;
string += snippet
.replace( /\[ i \]/g, '[ ' + i + ' ]' )
.replace( /UNROLLED_LOOP_INDEX/g, i );
}
return string.replace( pattern, replace );
return string;
}
//
function generatePrecision( parameters ) {
var precisionstring = "precision " + parameters.precision + " float;\nprecision " + parameters.precision + " int;";
......@@ -17910,11 +17932,11 @@
}
vertexShader = parseIncludes( vertexShader );
vertexShader = resolveIncludes( vertexShader );
vertexShader = replaceLightNums( vertexShader, parameters );
vertexShader = replaceClippingPlaneNums( vertexShader, parameters );
fragmentShader = parseIncludes( fragmentShader );
fragmentShader = resolveIncludes( fragmentShader );
fragmentShader = replaceLightNums( fragmentShader, parameters );
fragmentShader = replaceClippingPlaneNums( fragmentShader, parameters );
此差异已折叠。
......@@ -2138,11 +2138,13 @@ Object.assign( Vector3.prototype, {
},
projectOnVector: function ( vector ) {
projectOnVector: function ( v ) {
var scalar = vector.dot( this ) / vector.lengthSq();
// v cannot be the zero v
return this.copy( vector ).multiplyScalar( scalar );
var scalar = v.dot( this ) / v.lengthSq();
return this.copy( v ).multiplyScalar( scalar );
},
......@@ -2165,6 +2167,8 @@ Object.assign( Vector3.prototype, {
angleTo: function ( v ) {
// assumes this and v are not the zero vector
var theta = this.dot( v ) / ( Math.sqrt( this.lengthSq() * v.lengthSq() ) );
// clamp, to handle numerical problems
......@@ -11368,6 +11372,13 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
var indices = geometry.index !== null ? geometry.index.array : undefined;
var attributes = geometry.attributes;
if ( attributes.position === undefined ) {
console.error( 'THREE.Geometry.fromBufferGeometry(): Position attribute required for conversion.' );
return this;
}
var positions = attributes.position.array;
var normals = attributes.normal !== undefined ? attributes.normal.array : undefined;
var colors = attributes.color !== undefined ? attributes.color.array : undefined;
......@@ -14025,7 +14036,7 @@ var color_pars_vertex = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";
var color_vertex = "#ifdef USE_COLOR\n\tvColor.xyz = color.xyz;\n#endif";
var common = "#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI_HALF 1.5707963267949\n#define RECIPROCAL_PI 0.31830988618\n#define RECIPROCAL_PI2 0.15915494\n#define LOG2 1.442695\n#define EPSILON 1e-6\n#define saturate(a) clamp( a, 0.0, 1.0 )\n#define whiteComplement(a) ( 1.0 - saturate( a ) )\nfloat pow2( const in float x ) { return x*x; }\nfloat pow3( const in float x ) { return x*x*x; }\nfloat pow4( const in float x ) { float x2 = x*x; return x2*x2; }\nfloat average( const in vec3 color ) { return dot( color, vec3( 0.3333 ) ); }\nhighp float rand( const in vec2 uv ) {\n\tconst highp float a = 12.9898, b = 78.233, c = 43758.5453;\n\thighp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );\n\treturn fract(sin(sn) * c);\n}\n#ifdef HIGH_PRECISION\n\tfloat precisionSafeLength( vec3 v ) { return length( v ); }\n#else\n\tfloat max3( vec3 v ) { return max( max( v.x, v.y ), v.z ); }\n\tfloat precisionSafeLength( vec3 v ) {\n\t\tfloat maxComponent = max3( abs( v ) );\n\t\treturn length( v / maxComponent ) * maxComponent;\n\t}\n#endif\nstruct IncidentLight {\n\tvec3 color;\n\tvec3 direction;\n\tbool visible;\n};\nstruct ReflectedLight {\n\tvec3 directDiffuse;\n\tvec3 directSpecular;\n\tvec3 indirectDiffuse;\n\tvec3 indirectSpecular;\n};\nstruct GeometricContext {\n\tvec3 position;\n\tvec3 normal;\n\tvec3 viewDir;\n#ifdef CLEARCOAT\n\tvec3 clearcoatNormal;\n#endif\n};\nvec3 transformDirection( in vec3 dir, in mat4 matrix ) {\n\treturn normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );\n}\nvec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) {\n\treturn normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );\n}\nvec3 projectOnPlane(in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\tfloat distance = dot( planeNormal, point - pointOnPlane );\n\treturn - distance * planeNormal + point;\n}\nfloat sideOfPlane( in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\treturn sign( dot( point - pointOnPlane, planeNormal ) );\n}\nvec3 linePlaneIntersect( in vec3 pointOnLine, in vec3 lineDirection, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\treturn lineDirection * ( dot( planeNormal, pointOnPlane - pointOnLine ) / dot( planeNormal, lineDirection ) ) + pointOnLine;\n}\nmat3 transposeMat3( const in mat3 m ) {\n\tmat3 tmp;\n\ttmp[ 0 ] = vec3( m[ 0 ].x, m[ 1 ].x, m[ 2 ].x );\n\ttmp[ 1 ] = vec3( m[ 0 ].y, m[ 1 ].y, m[ 2 ].y );\n\ttmp[ 2 ] = vec3( m[ 0 ].z, m[ 1 ].z, m[ 2 ].z );\n\treturn tmp;\n}\nfloat linearToRelativeLuminance( const in vec3 color ) {\n\tvec3 weights = vec3( 0.2126, 0.7152, 0.0722 );\n\treturn dot( weights, color.rgb );\n}\nbool isPerspectiveMatrix( mat4 projectionMatrix ) {\n return projectionMatrix[ 2 ][ 3 ] == - 1.0;\n}";
var common = "#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI_HALF 1.5707963267949\n#define RECIPROCAL_PI 0.31830988618\n#define RECIPROCAL_PI2 0.15915494\n#define LOG2 1.442695\n#define EPSILON 1e-6\n#ifndef saturate\n#define saturate(a) clamp( a, 0.0, 1.0 )\n#endif\n#define whiteComplement(a) ( 1.0 - saturate( a ) )\nfloat pow2( const in float x ) { return x*x; }\nfloat pow3( const in float x ) { return x*x*x; }\nfloat pow4( const in float x ) { float x2 = x*x; return x2*x2; }\nfloat average( const in vec3 color ) { return dot( color, vec3( 0.3333 ) ); }\nhighp float rand( const in vec2 uv ) {\n\tconst highp float a = 12.9898, b = 78.233, c = 43758.5453;\n\thighp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );\n\treturn fract(sin(sn) * c);\n}\n#ifdef HIGH_PRECISION\n\tfloat precisionSafeLength( vec3 v ) { return length( v ); }\n#else\n\tfloat max3( vec3 v ) { return max( max( v.x, v.y ), v.z ); }\n\tfloat precisionSafeLength( vec3 v ) {\n\t\tfloat maxComponent = max3( abs( v ) );\n\t\treturn length( v / maxComponent ) * maxComponent;\n\t}\n#endif\nstruct IncidentLight {\n\tvec3 color;\n\tvec3 direction;\n\tbool visible;\n};\nstruct ReflectedLight {\n\tvec3 directDiffuse;\n\tvec3 directSpecular;\n\tvec3 indirectDiffuse;\n\tvec3 indirectSpecular;\n};\nstruct GeometricContext {\n\tvec3 position;\n\tvec3 normal;\n\tvec3 viewDir;\n#ifdef CLEARCOAT\n\tvec3 clearcoatNormal;\n#endif\n};\nvec3 transformDirection( in vec3 dir, in mat4 matrix ) {\n\treturn normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );\n}\nvec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) {\n\treturn normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );\n}\nvec3 projectOnPlane(in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\tfloat distance = dot( planeNormal, point - pointOnPlane );\n\treturn - distance * planeNormal + point;\n}\nfloat sideOfPlane( in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\treturn sign( dot( point - pointOnPlane, planeNormal ) );\n}\nvec3 linePlaneIntersect( in vec3 pointOnLine, in vec3 lineDirection, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\treturn lineDirection * ( dot( planeNormal, pointOnPlane - pointOnLine ) / dot( planeNormal, lineDirection ) ) + pointOnLine;\n}\nmat3 transposeMat3( const in mat3 m ) {\n\tmat3 tmp;\n\ttmp[ 0 ] = vec3( m[ 0 ].x, m[ 1 ].x, m[ 2 ].x );\n\ttmp[ 1 ] = vec3( m[ 0 ].y, m[ 1 ].y, m[ 2 ].y );\n\ttmp[ 2 ] = vec3( m[ 0 ].z, m[ 1 ].z, m[ 2 ].z );\n\treturn tmp;\n}\nfloat linearToRelativeLuminance( const in vec3 color ) {\n\tvec3 weights = vec3( 0.2126, 0.7152, 0.0722 );\n\treturn dot( weights, color.rgb );\n}\nbool isPerspectiveMatrix( mat4 projectionMatrix ) {\n return projectionMatrix[ 2 ][ 3 ] == - 1.0;\n}";
var cube_uv_reflection_fragment = "#ifdef ENVMAP_TYPE_CUBE_UV\n#define cubeUV_textureSize (1024.0)\nint getFaceFromDirection(vec3 direction) {\n\tvec3 absDirection = abs(direction);\n\tint face = -1;\n\tif( absDirection.x > absDirection.z ) {\n\t\tif(absDirection.x > absDirection.y )\n\t\t\tface = direction.x > 0.0 ? 0 : 3;\n\t\telse\n\t\t\tface = direction.y > 0.0 ? 1 : 4;\n\t}\n\telse {\n\t\tif(absDirection.z > absDirection.y )\n\t\t\tface = direction.z > 0.0 ? 2 : 5;\n\t\telse\n\t\t\tface = direction.y > 0.0 ? 1 : 4;\n\t}\n\treturn face;\n}\n#define cubeUV_maxLods1 (log2(cubeUV_textureSize*0.25) - 1.0)\n#define cubeUV_rangeClamp (exp2((6.0 - 1.0) * 2.0))\nvec2 MipLevelInfo( vec3 vec, float roughnessLevel, float roughness ) {\n\tfloat scale = exp2(cubeUV_maxLods1 - roughnessLevel);\n\tfloat dxRoughness = dFdx(roughness);\n\tfloat dyRoughness = dFdy(roughness);\n\tvec3 dx = dFdx( vec * scale * dxRoughness );\n\tvec3 dy = dFdy( vec * scale * dyRoughness );\n\tfloat d = max( dot( dx, dx ), dot( dy, dy ) );\n\td = clamp(d, 1.0, cubeUV_rangeClamp);\n\tfloat mipLevel = 0.5 * log2(d);\n\treturn vec2(floor(mipLevel), fract(mipLevel));\n}\n#define cubeUV_maxLods2 (log2(cubeUV_textureSize*0.25) - 2.0)\n#define cubeUV_rcpTextureSize (1.0 / cubeUV_textureSize)\nvec2 getCubeUV(vec3 direction, float roughnessLevel, float mipLevel) {\n\tmipLevel = roughnessLevel > cubeUV_maxLods2 - 3.0 ? 0.0 : mipLevel;\n\tfloat a = 16.0 * cubeUV_rcpTextureSize;\n\tvec2 exp2_packed = exp2( vec2( roughnessLevel, mipLevel ) );\n\tvec2 rcp_exp2_packed = vec2( 1.0 ) / exp2_packed;\n\tfloat powScale = exp2_packed.x * exp2_packed.y;\n\tfloat scale = rcp_exp2_packed.x * rcp_exp2_packed.y * 0.25;\n\tfloat mipOffset = 0.75*(1.0 - rcp_exp2_packed.y) * rcp_exp2_packed.x;\n\tbool bRes = mipLevel == 0.0;\n\tscale = bRes && (scale < a) ? a : scale;\n\tvec3 r;\n\tvec2 offset;\n\tint face = getFaceFromDirection(direction);\n\tfloat rcpPowScale = 1.0 / powScale;\n\tif( face == 0) {\n\t\tr = vec3(direction.x, -direction.z, direction.y);\n\t\toffset = vec2(0.0+mipOffset,0.75 * rcpPowScale);\n\t\toffset.y = bRes && (offset.y < 2.0*a) ? a : offset.y;\n\t}\n\telse if( face == 1) {\n\t\tr = vec3(direction.y, direction.x, direction.z);\n\t\toffset = vec2(scale+mipOffset, 0.75 * rcpPowScale);\n\t\toffset.y = bRes && (offset.y < 2.0*a) ? a : offset.y;\n\t}\n\telse if( face == 2) {\n\t\tr = vec3(direction.z, direction.x, direction.y);\n\t\toffset = vec2(2.0*scale+mipOffset, 0.75 * rcpPowScale);\n\t\toffset.y = bRes && (offset.y < 2.0*a) ? a : offset.y;\n\t}\n\telse if( face == 3) {\n\t\tr = vec3(direction.x, direction.z, direction.y);\n\t\toffset = vec2(0.0+mipOffset,0.5 * rcpPowScale);\n\t\toffset.y = bRes && (offset.y < 2.0*a) ? 0.0 : offset.y;\n\t}\n\telse if( face == 4) {\n\t\tr = vec3(direction.y, direction.x, -direction.z);\n\t\toffset = vec2(scale+mipOffset, 0.5 * rcpPowScale);\n\t\toffset.y = bRes && (offset.y < 2.0*a) ? 0.0 : offset.y;\n\t}\n\telse {\n\t\tr = vec3(direction.z, -direction.x, direction.y);\n\t\toffset = vec2(2.0*scale+mipOffset, 0.5 * rcpPowScale);\n\t\toffset.y = bRes && (offset.y < 2.0*a) ? 0.0 : offset.y;\n\t}\n\tr = normalize(r);\n\tfloat texelOffset = 0.5 * cubeUV_rcpTextureSize;\n\tvec2 s = ( r.yz / abs( r.x ) + vec2( 1.0 ) ) * 0.5;\n\tvec2 base = offset + vec2( texelOffset );\n\treturn base + s * ( scale - 2.0 * texelOffset );\n}\n#define cubeUV_maxLods3 (log2(cubeUV_textureSize*0.25) - 3.0)\nvec4 textureCubeUV( sampler2D envMap, vec3 reflectedDirection, float roughness ) {\n\tfloat roughnessVal = roughness* cubeUV_maxLods3;\n\tfloat r1 = floor(roughnessVal);\n\tfloat r2 = r1 + 1.0;\n\tfloat t = fract(roughnessVal);\n\tvec2 mipInfo = MipLevelInfo(reflectedDirection, r1, roughness);\n\tfloat s = mipInfo.y;\n\tfloat level0 = mipInfo.x;\n\tfloat level1 = level0 + 1.0;\n\tlevel1 = level1 > 5.0 ? 5.0 : level1;\n\tlevel0 += min( floor( s + 0.5 ), 5.0 );\n\tvec2 uv_10 = getCubeUV(reflectedDirection, r1, level0);\n\tvec4 color10 = envMapTexelToLinear(texture2D(envMap, uv_10));\n\tvec2 uv_20 = getCubeUV(reflectedDirection, r2, level0);\n\tvec4 color20 = envMapTexelToLinear(texture2D(envMap, uv_20));\n\tvec4 result = mix(color10, color20, t);\n\treturn vec4(result.rgb, 1.0);\n}\n#endif";
......@@ -14161,7 +14172,7 @@ var specularmap_pars_fragment = "#ifdef USE_SPECULARMAP\n\tuniform sampler2D spe
var tonemapping_fragment = "#if defined( TONE_MAPPING )\n\tgl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif";
var tonemapping_pars_fragment = "#ifndef saturate\n\t#define saturate(a) clamp( a, 0.0, 1.0 )\n#endif\nuniform float toneMappingExposure;\nuniform float toneMappingWhitePoint;\nvec3 LinearToneMapping( vec3 color ) {\n\treturn toneMappingExposure * color;\n}\nvec3 ReinhardToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\treturn saturate( color / ( vec3( 1.0 ) + color ) );\n}\n#define Uncharted2Helper( x ) max( ( ( x * ( 0.15 * x + 0.10 * 0.50 ) + 0.20 * 0.02 ) / ( x * ( 0.15 * x + 0.50 ) + 0.20 * 0.30 ) ) - 0.02 / 0.30, vec3( 0.0 ) )\nvec3 Uncharted2ToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\treturn saturate( Uncharted2Helper( color ) / Uncharted2Helper( vec3( toneMappingWhitePoint ) ) );\n}\nvec3 OptimizedCineonToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\tcolor = max( vec3( 0.0 ), color - 0.004 );\n\treturn pow( ( color * ( 6.2 * color + 0.5 ) ) / ( color * ( 6.2 * color + 1.7 ) + 0.06 ), vec3( 2.2 ) );\n}\nvec3 ACESFilmicToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\treturn saturate( ( color * ( 2.51 * color + 0.03 ) ) / ( color * ( 2.43 * color + 0.59 ) + 0.14 ) );\n}";
var tonemapping_pars_fragment = "#ifndef saturate\n#define saturate(a) clamp( a, 0.0, 1.0 )\n#endif\nuniform float toneMappingExposure;\nuniform float toneMappingWhitePoint;\nvec3 LinearToneMapping( vec3 color ) {\n\treturn toneMappingExposure * color;\n}\nvec3 ReinhardToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\treturn saturate( color / ( vec3( 1.0 ) + color ) );\n}\n#define Uncharted2Helper( x ) max( ( ( x * ( 0.15 * x + 0.10 * 0.50 ) + 0.20 * 0.02 ) / ( x * ( 0.15 * x + 0.50 ) + 0.20 * 0.30 ) ) - 0.02 / 0.30, vec3( 0.0 ) )\nvec3 Uncharted2ToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\treturn saturate( Uncharted2Helper( color ) / Uncharted2Helper( vec3( toneMappingWhitePoint ) ) );\n}\nvec3 OptimizedCineonToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\tcolor = max( vec3( 0.0 ), color - 0.004 );\n\treturn pow( ( color * ( 6.2 * color + 0.5 ) ) / ( color * ( 6.2 * color + 1.7 ) + 0.06 ), vec3( 2.2 ) );\n}\nvec3 ACESFilmicToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\treturn saturate( ( color * ( 2.51 * color + 0.03 ) ) / ( color * ( 2.43 * color + 0.59 ) + 0.14 ) );\n}";
var uv_pars_fragment = "#ifdef USE_UV\n\tvarying vec2 vUv;\n#endif";
......@@ -16358,6 +16369,8 @@ function DataTexture2DArray( data, width, height, depth ) {
this.generateMipmaps = false;
this.flipY = false;
this.needsUpdate = true;
}
DataTexture2DArray.prototype = Object.create( Texture.prototype );
......@@ -16390,6 +16403,9 @@ function DataTexture3D( data, width, height, depth ) {
this.generateMipmaps = false;
this.flipY = false;
this.needsUpdate = true;
}
DataTexture3D.prototype = Object.create( Texture.prototype );
......@@ -17447,52 +17463,58 @@ function replaceClippingPlaneNums( string, parameters ) {
}
function parseIncludes( string ) {
// Resolve Includes
var pattern = /^[ \t]*#include +<([\w\d./]+)>/gm;
var includePattern = /^[ \t]*#include +<([\w\d./]+)>/gm;
function replace( match, include ) {
function resolveIncludes( string ) {
var replace = ShaderChunk[ include ];
return string.replace( includePattern, includeReplacer );
if ( replace === undefined ) {
}
throw new Error( 'Can not resolve #include <' + include + '>' );
function includeReplacer( match, include ) {
}
var string = ShaderChunk[ include ];
return parseIncludes( replace );
if ( string === undefined ) {
throw new Error( 'Can not resolve #include <' + include + '>' );
}
return string.replace( pattern, replace );
return resolveIncludes( string );
}
function unrollLoops( string ) {
// Unroll Loops
var pattern = /#pragma unroll_loop[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
var loopPattern = /#pragma unroll_loop[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
function replace( match, start, end, snippet ) {
function unrollLoops( string ) {
var unroll = '';
return string.replace( loopPattern, loopReplacer );
for ( var i = parseInt( start ); i < parseInt( end ); i ++ ) {
}
unroll += snippet
.replace( /\[ i \]/g, '[ ' + i + ' ]' )
.replace( /UNROLLED_LOOP_INDEX/g, i );
function loopReplacer( match, start, end, snippet ) {
}
var string = '';
for ( var i = parseInt( start ); i < parseInt( end ); i ++ ) {
return unroll;
string += snippet
.replace( /\[ i \]/g, '[ ' + i + ' ]' )
.replace( /UNROLLED_LOOP_INDEX/g, i );
}
return string.replace( pattern, replace );
return string;
}
//
function generatePrecision( parameters ) {
var precisionstring = "precision " + parameters.precision + " float;\nprecision " + parameters.precision + " int;";
......@@ -17899,11 +17921,11 @@ function WebGLProgram( renderer, extensions, code, material, shader, parameters
}
vertexShader = parseIncludes( vertexShader );
vertexShader = resolveIncludes( vertexShader );
vertexShader = replaceLightNums( vertexShader, parameters );
vertexShader = replaceClippingPlaneNums( vertexShader, parameters );
fragmentShader = parseIncludes( fragmentShader );
fragmentShader = resolveIncludes( fragmentShader );
fragmentShader = replaceLightNums( fragmentShader, parameters );
fragmentShader = replaceClippingPlaneNums( fragmentShader, parameters );
......@@ -121,7 +121,7 @@ var d = a.distanceTo( b );
<h3>[method:Float angleTo]( [param:Vector3 v] )</h3>
<p>
Returns the angle between this vector and vector [page:Vector3 v] in radians.
Returns the angle between this vector and vector [page:Vector3 v] in radians. Neither this vector nor [page:Vector3 v] can be the zero vector.
</p>
<h3>[method:this ceil]()</h3>
......@@ -320,8 +320,8 @@ var d = a.distanceTo( b );
normal from this vector.
</p>
<h3>[method:this projectOnVector]( [param:Vector3] )</h3>
<p>[link:https://en.wikipedia.org/wiki/Vector_projection Projects] this vector onto another vector.</p>
<h3>[method:this projectOnVector]( [param:Vector3 v] )</h3>
<p>[link:https://en.wikipedia.org/wiki/Vector_projection Projects] this vector onto [page:Vector3 v]. [page:Vector3 v] cannot be the zero vector.</p>
<h3>[method:this reflect]( [param:Vector3 normal] )</h3>
<p>
......
......@@ -188,6 +188,7 @@
<li>triangles</li>
<li>points</li>
<li>lines</li>
<li>frame</li>
</ul>
</li>
<li>programs
......
......@@ -167,6 +167,7 @@
<li>triangles</li>
<li>points</li>
<li>lines</li>
<li>frame</li>
</ul>
</li>
<li>programs
......
......@@ -94,6 +94,7 @@
<li>truncateDrawRange - bool. Export just the attributes within the drawRange, if defined, instead of exporting the whole array. Default is true.</li>
<li>binary - bool. Export in binary (.glb) format, returning an ArrayBuffer. Default is false.</li>
<li>embedImages - bool. Export with images embedded into the glTF asset. Default is true.</li>
<li>maxTextureSize - int. Restricts the image maximum size (both width and height) to the given value. This option works only if embedImages is true. Default is Infinity.</li>
<li>animations - Array<[page:AnimationClip AnimationClip]>. List of animations to be included in the export.</li>
<li>forceIndices - bool. Generate indices for non-index geometry and export with them. Default is false.</li>
<li>forcePowerOfTwoTextures - bool. Export with images resized to POT size. This option works only if embedImages is true. Default is false.</li>
......
......@@ -94,6 +94,7 @@
<li>truncateDrawRange - bool. Export just the attributes within the drawRange, if defined, instead of exporting the whole array. Default is true.</li>
<li>binary - bool. Export in binary (.glb) format, returning an ArrayBuffer. Default is false.</li>
<li>embedImages - bool. Export with images embedded into the glTF asset. Default is true.</li>
<li>maxTextureSize - int. Restricts the image maximum size (both width and height) to the given value. This option works only if embedImages is true. Default is Infinity.</li>
<li>animations - Array<[page:AnimationClip AnimationClip]>. List of animations to be included in the export.</li>
<li>forceIndices - bool. Generate indices for non-index geometry and export with them. Default is false.</li>
<li>forcePowerOfTwoTextures - bool. Export with images resized to POT size. This option works only if embedImages is true. Default is false.</li>
......
......@@ -273,7 +273,6 @@ select {
.Panel {
color: #888;
border-top: 1px solid #222;
}
/* */
......
......@@ -267,7 +267,6 @@ select {
.Panel {
color: #888;
border-top: 1px solid #ccc;
}
/* */
......
......@@ -63,6 +63,7 @@ textarea, input { outline: none; } /* osx */
.TabbedPanel .Tabs .Tab {
padding: 10px;
vertical-align: middle;
text-transform: uppercase;
}
.TabbedPanel .Tabs .Panels {
......
......@@ -57,7 +57,9 @@ var Editor = function () {
helperAdded: new Signal(),
helperRemoved: new Signal(),
materialAdded: new Signal(),
materialChanged: new Signal(),
materialRemoved: new Signal(),
scriptAdded: new Signal(),
scriptChanged: new Signal(),
......@@ -234,6 +236,34 @@ Editor.prototype = {
addMaterial: function ( material ) {
this.materials[ material.uuid ] = material;
this.signals.materialAdded.dispatch();
},
removeMaterial: function ( material ) {
delete this.materials[ material.uuid ];
this.signals.materialRemoved.dispatch();
},
getMaterialById: function ( id ) {
var material;
var materials = Object.values( this.materials );
for ( var i = 0; i < materials.length; i ++ ) {
if ( materials[ i ].id === id ) {
material = materials[ i ];
break;
}
}
return material;
},
......
......@@ -17,12 +17,6 @@ Sidebar.Material = function ( editor ) {
container.setDisplay( 'none' );
container.setPaddingTop( '20px' );
// New / Copy / Paste
var copiedMaterial;
var managerRow = new UI.Row();
// Current material slot
var materialSlotRow = new UI.Row();
......@@ -35,43 +29,6 @@ Sidebar.Material = function ( editor ) {
container.add( materialSlotRow );
managerRow.add( new UI.Text( '' ).setWidth( '90px' ) );
managerRow.add( new UI.Button( strings.getKey( 'sidebar/material/new' ) ).onClick( function () {
var material = new THREE[ materialClass.getValue() ]();
editor.execute( new SetMaterialCommand( editor, currentObject, material, currentMaterialSlot ), 'New Material: ' + materialClass.getValue() );
update();
} ) );
managerRow.add( new UI.Button( strings.getKey( 'sidebar/material/copy' ) ).setMarginLeft( '4px' ).onClick( function () {
copiedMaterial = currentObject.material;
if ( Array.isArray( copiedMaterial ) ) {
if ( copiedMaterial.length === 0 ) return;
copiedMaterial = copiedMaterial[ currentMaterialSlot ];
}
} ) );
managerRow.add( new UI.Button( strings.getKey( 'sidebar/material/paste' ) ).setMarginLeft( '4px' ).onClick( function () {
if ( copiedMaterial === undefined ) return;
editor.execute( new SetMaterialCommand( editor, currentObject, copiedMaterial, currentMaterialSlot ), 'Pasted Material: ' + materialClass.getValue() );
refreshUI();
update();
} ) );
container.add( managerRow );
// type
var materialClassRow = new UI.Row();
......@@ -655,9 +612,9 @@ Sidebar.Material = function ( editor ) {
var sheen = sheenEnabled ? new THREE.Color(materialSheen.getHexValue()) : null;
editor.execute( new SetMaterialValueCommand( editor, currentObject, 'sheen', sheen, currentMaterialSlot ) );
}
if ( material.sheen !== undefined && material.sheen !== null && material.sheen.getHex() !== materialSheen.getHexValue() ) {
editor.execute( new SetMaterialColorCommand( editor, currentObject, 'sheen', materialSheen.getHexValue(), currentMaterialSlot ) );
......@@ -1297,9 +1254,9 @@ Sidebar.Material = function ( editor ) {
materialMetalness.setValue( material.metalness );
}
if ( material.sheen !== undefined && material.sheen !== null ) {
materialSheenEnabled.setValue( true );
materialSheen.setHexValue( material.sheen.getHexString() );
......
......@@ -19,8 +19,14 @@ Sidebar.Project = function ( editor ) {
var container = new UI.Panel();
container.setBorderTop( '0' );
container.setPadding( '0' );
container.setPaddingTop( '20px' );
var projectsettings = new UI.Panel();
projectsettings.setBorderTop( '0' );
container.add( projectsettings );
// Title
var titleRow = new UI.Row();
......@@ -33,7 +39,7 @@ Sidebar.Project = function ( editor ) {
titleRow.add( new UI.Text( strings.getKey( 'sidebar/project/title' ) ).setWidth( '90px' ) );
titleRow.add( title );
container.add( titleRow );
projectsettings.add( titleRow );
// Editable
......@@ -47,7 +53,7 @@ Sidebar.Project = function ( editor ) {
editableRow.add( new UI.Text( strings.getKey( 'sidebar/project/editable' ) ).setWidth( '90px' ) );
editableRow.add( editable );
container.add( editableRow );
projectsettings.add( editableRow );
// VR
......@@ -61,7 +67,7 @@ Sidebar.Project = function ( editor ) {
vrRow.add( new UI.Text( strings.getKey( 'sidebar/project/vr' ) ).setWidth( '90px' ) );
vrRow.add( vr );
container.add( vrRow );
projectsettings.add( vrRow );
// Renderer
......@@ -89,7 +95,7 @@ Sidebar.Project = function ( editor ) {
rendererTypeRow.add( new UI.Text( strings.getKey( 'sidebar/project/renderer' ) ).setWidth( '90px' ) );
rendererTypeRow.add( rendererType );
container.add( rendererTypeRow );
projectsettings.add( rendererTypeRow );
if ( config.getKey( 'project/renderer' ) !== undefined ) {
......@@ -119,7 +125,7 @@ Sidebar.Project = function ( editor ) {
} );
rendererPropertiesRow.add( rendererShadows );
container.add( rendererPropertiesRow );
projectsettings.add( rendererPropertiesRow );
//
......@@ -165,6 +171,70 @@ Sidebar.Project = function ( editor ) {
createRenderer( config.getKey( 'project/renderer' ), config.getKey( 'project/renderer/antialias' ), config.getKey( 'project/renderer/shadows' ) );
// Materials
var materials = new UI.Panel();
var headerRow = new UI.Row();
headerRow.add( new UI.Text( strings.getKey( 'sidebar/project/materials' ) ) );
materials.add( headerRow );
var listbox = new UI.Listbox();
signals.materialAdded.add( function () {
listbox.setItems( Object.values( editor.materials ) );
} );
materials.add( listbox );
var buttonsRow = new UI.Row();
buttonsRow.setPadding( '10px 0px' );
materials.add( buttonsRow );
/*
var addButton = new UI.Button().setLabel( 'Add' ).setMarginRight( '5px' );
addButton.onClick( function () {
editor.addMaterial( new THREE.MeshStandardMaterial() );
} );
buttonsRow.add( addButton );
*/
var assignMaterial = new UI.Button().setLabel( 'Assign' ).setMargin( '0px 5px' );
assignMaterial.onClick( function () {
if ( editor.selected !== null ) {
var material = editor.getMaterialById( parseInt( listbox.getValue() ) );
if ( material !== undefined ) {
editor.execute( new SetMaterialCommand( editor, editor.selected, material ) );
}
}
} );
buttonsRow.add( assignMaterial );
container.add( materials );
// events
signals.objectSelected.add( function ( object ) {
if ( object !== null ) {
var index = Object.values( editor.materials ).indexOf( object.material );
listbox.selectIndex( index );
}
} );
return container;
};
......@@ -12,6 +12,7 @@ Sidebar.Properties = function ( editor ) {
container.addTab( 'object', strings.getKey( 'sidebar/properties/object' ), new Sidebar.Object( editor ) );
container.addTab( 'geometry', strings.getKey( 'sidebar/properties/geometry' ), new Sidebar.Geometry( editor ) );
container.addTab( 'material', strings.getKey( 'sidebar/properties/material' ), new Sidebar.Material( editor ) );
container.select( 'object' );
return container;
......
......@@ -24,6 +24,7 @@ var Sidebar = function ( editor ) {
container.addTab( 'scene', strings.getKey( 'sidebar/scene' ), scene );
container.addTab( 'project', strings.getKey( 'sidebar/project' ), new Sidebar.Project( editor ) );
container.addTab( 'settings', strings.getKey( 'sidebar/settings' ), settings );
container.select( 'scene' );
return container;
......
......@@ -280,6 +280,7 @@ var Strings = function ( config ) {
'sidebar/project/renderer': 'Renderer',
'sidebar/project/antialias': 'antialias',
'sidebar/project/shadows': 'shadows',
'sidebar/project/materials': 'Materials',
'sidebar/settings': 'Settings',
'sidebar/settings/language': 'Language',
......@@ -555,6 +556,7 @@ var Strings = function ( config ) {
'sidebar/project/renderer': '渲染器',
'sidebar/project/antialias': '抗锯齿',
'sidebar/project/shadows': '阴影',
'sidebar/project/materials': 'Materials',
'sidebar/settings': '设置',
'sidebar/settings/language': '语言',
......
......@@ -1025,8 +1025,8 @@ UI.TabbedPanel = function ( ) {
UI.Element.call( this );
var dom = document.createElement('div');
var dom = document.createElement( 'div' );
this.dom = dom;
this.setClass( 'TabbedPanel' );
......@@ -1047,7 +1047,7 @@ UI.TabbedPanel = function ( ) {
return this;
}
};
UI.TabbedPanel.prototype = Object.create( UI.Element.prototype );
UI.TabbedPanel.prototype.constructor = UI.TabbedPanel;
......@@ -1057,9 +1057,10 @@ UI.TabbedPanel.prototype.select = function ( id ) {
var tab;
var panel;
var scope = this;
// Deselect current selection
if ( this.selected && this.selected.length ) {
tab = this.tabs.find( function ( item ) { return item.dom.id === scope.selected } );
panel = this.panels.find( function ( item ) { return item.dom.id === scope.selected } );
......@@ -1069,7 +1070,7 @@ UI.TabbedPanel.prototype.select = function ( id ) {
}
if( panel ) {
if ( panel ) {
panel.setDisplay( 'none' );
......@@ -1079,14 +1080,14 @@ UI.TabbedPanel.prototype.select = function ( id ) {
tab = this.tabs.find( function ( item ) { return item.dom.id === id } );
panel = this.panels.find( function ( item ) { return item.dom.id === id } );
if ( tab ) {
tab.addClass( 'selected' );
}
if( panel ) {
if ( panel ) {
panel.setDisplay( '' );
......@@ -1096,7 +1097,7 @@ UI.TabbedPanel.prototype.select = function ( id ) {
return this;
}
};
UI.TabbedPanel.prototype.addTab = function ( id, label, items ) {
......@@ -1114,7 +1115,7 @@ UI.TabbedPanel.prototype.addTab = function ( id, label, items ) {
this.select( id );
}
};
UI.TabbedPanel.Tab = function ( text, parent ) {
......@@ -1124,15 +1125,16 @@ UI.TabbedPanel.Tab = function ( text, parent ) {
this.setClass( 'Tab' );
var scope = this;
this.dom.addEventListener( 'click', function ( event ) {
scope.parent.select( scope.dom.id );
} )
} );
return this;
}
};
UI.TabbedPanel.Tab.prototype = Object.create( UI.Text.prototype );
UI.TabbedPanel.Tab.prototype.constructor = UI.TabbedPanel.Tab;
......@@ -1154,10 +1156,10 @@ UI.Listbox = function ( ) {
return this;
}
};
UI.Listbox.prototype = Object.create( UI.Element.prototype );
UI.Listbox.prototype.constructor = UI.ListboxItem;
UI.Listbox.prototype.constructor = UI.Listbox;
UI.Listbox.prototype.setItems = function ( items ) {
......@@ -1167,25 +1169,25 @@ UI.Listbox.prototype.setItems = function ( items ) {
}
this.render( );
this.render();
}
};
UI.Listbox.prototype.render = function ( ) {
while( this.listitems.length ) {
while ( this.listitems.length ) {
var item = this.listitems[0];
var item = this.listitems[ 0 ];
item.dom.remove();
this.listitems.splice(0, 1);
this.listitems.splice( 0, 1 );
}
for ( var i = 0; i < this.items.length; i ++ ) {
var item = this.items[i];
var item = this.items[ i ];
var listitem = new UI.Listbox.ListboxItem( this );
listitem.setId( item.id || `Listbox-${i}` );
......@@ -1194,10 +1196,10 @@ UI.Listbox.prototype.render = function ( ) {
}
}
};
// Assuming user passes valid list items
UI.Listbox.prototype.add = function ( ) {
UI.Listbox.prototype.add = function () {
var items = Array.from( arguments );
......@@ -1205,25 +1207,25 @@ UI.Listbox.prototype.add = function ( ) {
UI.Element.prototype.add.apply( this, items );
}
};
UI.Listbox.prototype.selectIndex = function ( index ) {
if ( index >= 0 && index < this.items.length ) {
this.setValue( this.listitems[ index ].getId( ) );
this.setValue( this.listitems[ index ].getId() );
}
this.selectIndex = index;
this.selectedIndex = index;
}
};
UI.Listbox.prototype.getValue = function ( index ) {
UI.Listbox.prototype.getValue = function () {
return this.selectedValue;
}
};
UI.Listbox.prototype.setValue = function ( value ) {
......@@ -1231,12 +1233,12 @@ UI.Listbox.prototype.setValue = function ( value ) {
var element = this.listitems[ i ];
if ( element.getId( ) === value ) {
if ( element.getId() === value ) {
element.addClass( 'active' );
} else {
element.removeClass( 'active' );
}
......@@ -1249,7 +1251,7 @@ UI.Listbox.prototype.setValue = function ( value ) {
changeEvent.initEvent( 'change', true, true );
this.dom.dispatchEvent( changeEvent );
}
};
// Listbox Item
UI.Listbox.ListboxItem = function ( parent ) {
......@@ -1264,10 +1266,12 @@ UI.Listbox.ListboxItem = function ( parent ) {
var scope = this;
function onClick ( ) {
if( scope.parent ) {
function onClick() {
if ( scope.parent ) {
scope.parent.setValue( scope.getId( ) );
}
}
......@@ -1276,7 +1280,7 @@ UI.Listbox.ListboxItem = function ( parent ) {
return this;
}
};
UI.Listbox.ListboxItem.prototype = Object.create( UI.Element.prototype );
UI.Listbox.ListboxItem.prototype.constructor = UI.Listbox.ListboxItem;
// r108
const staticAssets = [
const assets = [
'./',
'../files/favicon.ico',
'../build/three.js',
'../examples/js/controls/EditorControls.js',
'../examples/js/controls/TransformControls.js',
'../examples/js/libs/chevrotain.min.js',
......@@ -42,6 +41,9 @@ const staticAssets = [
'../examples/js/renderers/SoftwareRenderer.js',
'../examples/js/renderers/SVGRenderer.js',
'./manifest.json',
'./images/icon.png',
'./js/libs/codemirror/codemirror.css',
'./js/libs/codemirror/theme/monokai.css',
......@@ -92,6 +94,7 @@ const staticAssets = [
'./css/dark.css',
'./css/light.css',
'./js/EditorControls.js',
'./js/Storage.js',
'./js/Editor.js',
......@@ -122,6 +125,7 @@ const staticAssets = [
'./js/Sidebar.Geometry.BoxGeometry.js',
'./js/Sidebar.Geometry.CircleGeometry.js',
'./js/Sidebar.Geometry.CylinderGeometry.js',
'./js/Sidebar.Geometry.DodecahedronGeometry.js',
'./js/Sidebar.Geometry.ExtrudeGeometry.js',
'./js/Sidebar.Geometry.IcosahedronGeometry.js',
'./js/Sidebar.Geometry.OctahedronGeometry.js',
......@@ -179,10 +183,19 @@ const staticAssets = [
];
self.addEventListener( 'install', async function ( event ) {
self.addEventListener( 'install', async function () {
const cache = await caches.open( 'threejs-editor' );
cache.addAll( staticAssets );
assets.forEach( function ( asset ) {
cache.add( asset ).catch( function () {
console.error( '[SW] Cound\'t cache:', asset );
} );
} );
} );
......@@ -196,6 +209,14 @@ self.addEventListener( 'fetch', async function ( event ) {
async function cacheFirst( request ) {
const cachedResponse = await caches.match( request );
return cachedResponse || fetch( request );
if ( cachedResponse === undefined ) {
console.error( '[SW] Not cached:', request.url );
return fetch( request );
}
return cachedResponse;
}
......@@ -78,6 +78,7 @@ THREE.GLTFExporter.prototype = {
onlyVisible: true,
truncateDrawRange: true,
embedImages: true,
maxTextureSize: Infinity,
animations: [],
forceIndices: false,
forcePowerOfTwoTextures: false,
......@@ -751,10 +752,10 @@ THREE.GLTFExporter.prototype = {
var canvas = cachedCanvas = cachedCanvas || document.createElement( 'canvas' );
canvas.width = image.width;
canvas.height = image.height;
canvas.width = Math.min( image.width, options.maxTextureSize );
canvas.height = Math.min( image.height, options.maxTextureSize );
if ( options.forcePowerOfTwoTextures && ! isPowerOfTwo( image ) ) {
if ( options.forcePowerOfTwoTextures && ! isPowerOfTwo( canvas ) ) {
console.warn( 'GLTFExporter: Resized non-power-of-two image.', image );
......
......@@ -36,7 +36,7 @@ basisLoader.load( 'diffuse.basis', function ( texture ) {
```
For further documentation about the Basis compressor and transcoder, refer to
the [Basis GitHub repository](https://github.com/BinomialLLC/basis_universal). The JavaScript wrapper requires one modification from the version provided in the Basis repository – the declaration on the first line is changed from `var Module` to `Module`, to accomodate lazy initialization in a Web Worker ([details](https://github.com/mrdoob/three.js/issues/16524)).
the [Basis GitHub repository](https://github.com/BinomialLLC/basis_universal).
## License
......
......@@ -4,8 +4,6 @@
* @author Shrek Shao / https://github.com/shrekshao
*/
/* global Module, createBasisModule */
/**
* Loader for Basis Universal GPU Texture Codec.
*
......@@ -32,6 +30,7 @@ THREE.BasisTextureLoader = function ( manager ) {
this.workerSourceURL = '';
this.workerConfig = {
format: null,
astcSupported: false,
etcSupported: false,
dxtSupported: false,
pvrtcSupported: false,
......@@ -63,22 +62,27 @@ THREE.BasisTextureLoader.prototype = Object.assign( Object.create( THREE.Loader.
var config = this.workerConfig;
config.astcSupported = !! renderer.extensions.get( 'WEBGL_compressed_texture_astc' );
config.etcSupported = !! renderer.extensions.get( 'WEBGL_compressed_texture_etc1' );
config.dxtSupported = !! renderer.extensions.get( 'WEBGL_compressed_texture_s3tc' );
config.pvrtcSupported = !! renderer.extensions.get( 'WEBGL_compressed_texture_pvrtc' )
|| !! renderer.extensions.get( 'WEBKIT_WEBGL_compressed_texture_pvrtc' );
if ( config.etcSupported ) {
if ( config.astcSupported ) {
config.format = THREE.BasisTextureLoader.BASIS_FORMAT.cTFETC1;
config.format = THREE.BasisTextureLoader.BASIS_FORMAT.cTFASTC_4x4;
} else if ( config.dxtSupported ) {
config.format = THREE.BasisTextureLoader.BASIS_FORMAT.cTFBC1;
config.format = THREE.BasisTextureLoader.BASIS_FORMAT.cTFBC3;
} else if ( config.pvrtcSupported ) {
config.format = THREE.BasisTextureLoader.BASIS_FORMAT.cTFPVRTC1_4_OPAQUE_ONLY;
config.format = THREE.BasisTextureLoader.BASIS_FORMAT.cTFPVRTC1_4_RGBA;
} else if ( config.etcSupported ) {
config.format = THREE.BasisTextureLoader.BASIS_FORMAT.cTFETC1;
} else {
......@@ -136,25 +140,30 @@ THREE.BasisTextureLoader.prototype = Object.assign( Object.create( THREE.Loader.
var config = this.workerConfig;
var { width, height, mipmaps } = message;
var { width, height, hasAlpha, mipmaps, format } = message;
var texture;
if ( config.etcSupported ) {
texture = new THREE.CompressedTexture( mipmaps, width, height, THREE.RGB_ETC1_Format );
} else if ( config.dxtSupported ) {
texture = new THREE.CompressedTexture( mipmaps, width, height, THREE.BasisTextureLoader.DXT_FORMAT_MAP[ config.format ], THREE.UnsignedByteType );
} else if ( config.pvrtcSupported ) {
texture = new THREE.CompressedTexture( mipmaps, width, height, THREE.RGB_PVRTC_4BPPV1_Format );
} else {
throw new Error( 'THREE.BasisTextureLoader: No supported format available.' );
switch ( format ) {
case THREE.BasisTextureLoader.BASIS_FORMAT.cTFASTC_4x4:
texture = new THREE.CompressedTexture( mipmaps, width, height, THREE.RGBA_ASTC_4x4_Format );
break;
case THREE.BasisTextureLoader.BASIS_FORMAT.cTFBC1:
case THREE.BasisTextureLoader.BASIS_FORMAT.cTFBC3:
texture = new THREE.CompressedTexture( mipmaps, width, height, THREE.BasisTextureLoader.DXT_FORMAT_MAP[ config.format ], THREE.UnsignedByteType );
break;
case THREE.BasisTextureLoader.BASIS_FORMAT.cTFETC1:
texture = new THREE.CompressedTexture( mipmaps, width, height, THREE.RGB_ETC1_Format );
break;
case THREE.BasisTextureLoader.BASIS_FORMAT.cTFPVRTC1_4_RGB:
texture = new THREE.CompressedTexture( mipmaps, width, height, THREE.RGB_PVRTC_4BPPV1_Format );
break;
case THREE.BasisTextureLoader.BASIS_FORMAT.cTFPVRTC1_4_RGBA:
texture = new THREE.CompressedTexture( mipmaps, width, height, THREE.RGBA_PVRTC_4BPPV1_Format );
break;
default:
throw new Error( 'THREE.BasisTextureLoader: No supported format available.' );
}
......@@ -214,12 +223,7 @@ THREE.BasisTextureLoader.prototype = Object.assign( Object.create( THREE.Loader.
var body = [
'/* basis_transcoder.js */',
'var Module;',
'function createBasisModule () {',
' ' + jsContent,
' return Module;',
'}',
'',
jsContent,
'/* worker */',
fn.substring( fn.indexOf( '{' ) + 1, fn.lastIndexOf( '}' ) )
].join( '\n' );
......@@ -312,13 +316,22 @@ THREE.BasisTextureLoader.prototype = Object.assign( Object.create( THREE.Loader.
THREE.BasisTextureLoader.BASIS_FORMAT = {
cTFETC1: 0,
cTFBC1: 1,
cTFBC4: 2,
cTFPVRTC1_4_OPAQUE_ONLY: 3,
cTFBC7_M6_OPAQUE_ONLY: 4,
cTFETC2: 5,
cTFBC3: 6,
cTFBC5: 7,
cTFETC2: 1,
cTFBC1: 2,
cTFBC3: 3,
cTFBC4: 4,
cTFBC5: 5,
cTFBC7_M6_OPAQUE_ONLY: 6,
cTFBC7_M5: 7,
cTFPVRTC1_4_RGB: 8,
cTFPVRTC1_4_RGBA: 9,
cTFASTC_4x4: 10,
cTFATC_RGB: 11,
cTFATC_RGBA_INTERPOLATED_ALPHA: 12,
cTFRGBA32: 13,
cTFRGB565: 14,
cTFBGR565: 15,
cTFRGBA4444: 16,
};
// DXT formats, from:
......@@ -359,7 +372,7 @@ THREE.BasisTextureLoader.BasisWorker = function () {
try {
var { width, height, mipmaps } = transcode( message.buffer );
var { width, height, hasAlpha, mipmaps, format } = transcode( message.buffer );
var buffers = [];
......@@ -369,7 +382,7 @@ THREE.BasisTextureLoader.BasisWorker = function () {
}
self.postMessage( { type: 'transcode', id: message.id, width, height, mipmaps }, buffers );
self.postMessage( { type: 'transcode', id: message.id, width, height, hasAlpha, mipmaps, format }, buffers );
} catch ( error ) {
......@@ -388,19 +401,15 @@ THREE.BasisTextureLoader.BasisWorker = function () {
function init( wasmBinary ) {
var BasisModule;
transcoderPending = new Promise( ( resolve ) => {
// The 'Module' global is used by the Basis wrapper, which will check for
// the 'wasmBinary' property before trying to load the file itself.
// TODO(donmccurdy): This only works with a modified version of the
// emscripten-generated wrapper. The default seems to have a bug making it
// impossible to override the WASM binary.
Module = { wasmBinary, onRuntimeInitialized: resolve };
BasisModule = { wasmBinary, onRuntimeInitialized: resolve };
BASIS( BasisModule );
} ).then( () => {
var { BasisFile, initializeBasis } = Module;
var { BasisFile, initializeBasis } = BasisModule;
_BasisFile = BasisFile;
......@@ -408,8 +417,6 @@ THREE.BasisTextureLoader.BasisWorker = function () {
} );
createBasisModule();
}
function transcode( buffer ) {
......@@ -419,6 +426,7 @@ THREE.BasisTextureLoader.BasisWorker = function () {
var width = basisFile.getImageWidth( 0, 0 );
var height = basisFile.getImageHeight( 0, 0 );
var levels = basisFile.getNumLevels( 0 );
var hasAlpha = basisFile.getHasAlpha();
function cleanup() {
......@@ -427,6 +435,20 @@ THREE.BasisTextureLoader.BasisWorker = function () {
}
if ( ! hasAlpha ) {
switch ( config.format ) {
case 9: // Hardcoded: THREE.BasisTextureLoader.BASIS_FORMAT.cTFPVRTC1_4_RGBA
config.format = 8; // Hardcoded: THREE.BasisTextureLoader.BASIS_FORMAT.cTFPVRTC1_4_RGB;
break;
default:
break;
}
}
if ( ! width || ! height || ! levels ) {
cleanup();
......@@ -441,12 +463,6 @@ THREE.BasisTextureLoader.BasisWorker = function () {
}
if ( basisFile.getHasAlpha() ) {
console.warn( 'THREE.BasisTextureLoader: Alpha not yet implemented.' );
}
var mipmaps = [];
for ( var mip = 0; mip < levels; mip ++ ) {
......@@ -460,7 +476,7 @@ THREE.BasisTextureLoader.BasisWorker = function () {
0,
mip,
config.format,
config.etcSupported ? 0 : ( config.dxtSupported ? 1 : 0 ),
hasAlpha,
0
);
......@@ -477,7 +493,7 @@ THREE.BasisTextureLoader.BasisWorker = function () {
cleanup();
return { width, height, mipmaps };
return { width, height, hasAlpha, mipmaps, format: config.format };
}
......
......@@ -269,8 +269,7 @@ THREE.GLTFLoader = ( function () {
/**
* DDS Texture Extension
*
* Specification:
* https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/MSFT_texture_dds
* Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/MSFT_texture_dds
*
*/
function GLTFTextureDDSExtension( ddsLoader ) {
......@@ -287,9 +286,9 @@ THREE.GLTFLoader = ( function () {
}
/**
* Lights Extension
* Punctual Lights Extension
*
* Specification: PENDING
* Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_lights_punctual
*/
function GLTFLightsExtension( json ) {
......@@ -356,9 +355,9 @@ THREE.GLTFLoader = ( function () {
};
/**
* Unlit Materials Extension (pending)
* Unlit Materials Extension
*
* PR: https://github.com/KhronosGroup/glTF/pull/1163
* Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit
*/
function GLTFMaterialsUnlitExtension() {
......@@ -473,7 +472,7 @@ THREE.GLTFLoader = ( function () {
/**
* DRACO Mesh Compression Extension
*
* Specification: https://github.com/KhronosGroup/glTF/pull/874
* Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression
*/
function GLTFDracoMeshCompressionExtension( json, dracoLoader ) {
......@@ -551,7 +550,7 @@ THREE.GLTFLoader = ( function () {
/**
* Texture Transform Extension
*
* Specification:
* Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_texture_transform
*/
function GLTFTextureTransformExtension() {
......
......@@ -286,6 +286,12 @@ THREE.OBJLoader = ( function () {
this.addVertex( ia, ib, ic );
if ( this.colors.length > 0 ) {
this.addColor( ia, ib, ic );
}
if ( ua !== undefined && ua !== '' ) {
var uvLen = this.uvs.length;
......@@ -309,12 +315,6 @@ THREE.OBJLoader = ( function () {
}
if ( this.colors.length > 0 ) {
this.addColor( ia, ib, ic );
}
},
addPointGeometry: function ( vertices ) {
......
......@@ -9,7 +9,7 @@ THREE.CopyShader = {
uniforms: {
"tDiffuse": { value: null },
"opacity": { value: 1.0 }
"opacity": { value: 1.0 }
},
......
......@@ -4,19 +4,19 @@
THREE.DepthLimitedBlurShader = {
defines: {
'KERNEL_RADIUS': 4,
'DEPTH_PACKING': 1,
'PERSPECTIVE_CAMERA': 1
"KERNEL_RADIUS": 4,
"DEPTH_PACKING": 1,
"PERSPECTIVE_CAMERA": 1
},
uniforms: {
'tDiffuse': { value: null },
'size': { value: new THREE.Vector2( 512, 512 ) },
'sampleUvOffsets': { value: [ new THREE.Vector2( 0, 0 ) ] },
'sampleWeights': { value: [ 1.0 ] },
'tDepth': { value: null },
'cameraNear': { value: 10 },
'cameraFar': { value: 1000 },
'depthCutoff': { value: 10 },
"tDiffuse": { value: null },
"size": { value: new THREE.Vector2( 512, 512 ) },
"sampleUvOffsets": { value: [ new THREE.Vector2( 0, 0 ) ] },
"sampleWeights": { value: [ 1.0 ] },
"tDepth": { value: null },
"cameraNear": { value: 10 },
"cameraFar": { value: 1000 },
"depthCutoff": { value: 10 },
},
vertexShader: [
"#include <common>",
......@@ -149,9 +149,9 @@ THREE.BlurShaderUtils = {
configure: function ( material, kernelRadius, stdDev, uvIncrement ) {
material.defines[ 'KERNEL_RADIUS' ] = kernelRadius;
material.uniforms[ 'sampleUvOffsets' ].value = THREE.BlurShaderUtils.createSampleOffsets( kernelRadius, uvIncrement );
material.uniforms[ 'sampleWeights' ].value = THREE.BlurShaderUtils.createSampleWeights( kernelRadius, stdDev );
material.defines[ "KERNEL_RADIUS" ] = kernelRadius;
material.uniforms[ "sampleUvOffsets" ].value = THREE.BlurShaderUtils.createSampleOffsets( kernelRadius, uvIncrement );
material.uniforms[ "sampleWeights" ].value = THREE.BlurShaderUtils.createSampleWeights( kernelRadius, stdDev );
material.needsUpdate = true;
}
......
......@@ -37,7 +37,7 @@ THREE.DigitalGlitch = {
].join( "\n" ),
fragmentShader: [
"uniform int byp;",//should we apply the glitch ?
"uniform int byp;", //should we apply the glitch ?
"uniform sampler2D tDiffuse;",
"uniform sampler2D tDisp;",
......
......@@ -11,10 +11,10 @@ THREE.DotScreenShader = {
uniforms: {
"tDiffuse": { value: null },
"tSize": { value: new THREE.Vector2( 256, 256 ) },
"center": { value: new THREE.Vector2( 0.5, 0.5 ) },
"angle": { value: 1.57 },
"scale": { value: 1.0 }
"tSize": { value: new THREE.Vector2( 256, 256 ) },
"center": { value: new THREE.Vector2( 0.5, 0.5 ) },
"angle": { value: 1.57 },
"scale": { value: 1.0 }
},
......
此差异已折叠。
......@@ -70,25 +70,25 @@ THREE.FilmShader = {
"void main() {",
// sample the source
// sample the source
" vec4 cTextureScreen = texture2D( tDiffuse, vUv );",
// make some noise
// make some noise
" float dx = rand( vUv + time );",
// add noise
// add noise
" vec3 cResult = cTextureScreen.rgb + cTextureScreen.rgb * clamp( 0.1 + dx, 0.0, 1.0 );",
// get us a sine and cosine
// get us a sine and cosine
" vec2 sc = vec2( sin( vUv.y * sCount ), cos( vUv.y * sCount ) );",
// add scanlines
// add scanlines
" cResult += cTextureScreen.rgb * vec3( sc.x, sc.y, sc.x ) * sIntensity;",
// interpolate between source and result by intensity
// interpolate between source and result by intensity
" cResult = cTextureScreen.rgb + clamp( nIntensity, 0.0,1.0 ) * ( cResult - cTextureScreen.rgb );",
// convert to grayscale if desired
// convert to grayscale if desired
" if( grayscale ) {",
" cResult = vec3( cResult.r * 0.3 + cResult.g * 0.59 + cResult.b * 0.11 );",
......
......@@ -27,14 +27,14 @@ THREE.HalftoneShader = {
vertexShader: [
"varying vec2 vUV;",
"varying vec2 vUV;",
"void main() {",
"void main() {",
"vUV = uv;",
"gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);",
" vUV = uv;",
" gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);",
"}"
"}"
].join( "\n" ),
......
......@@ -43,7 +43,7 @@ THREE.HueSaturationShader = {
" gl_FragColor = texture2D( tDiffuse, vUv );",
// hue
// hue
" float angle = hue * 3.14159265;",
" float s = sin(angle), c = cos(angle);",
" vec3 weights = (vec3(2.0 * c, -sqrt(3.0) * s - c, sqrt(3.0) * s - c) + 1.0) / 3.0;",
......@@ -54,7 +54,7 @@ THREE.HueSaturationShader = {
" dot(gl_FragColor.rgb, weights.yzx)",
" );",
// saturation
// saturation
" float average = (gl_FragColor.r + gl_FragColor.g + gl_FragColor.b) / 3.0;",
" if (saturation > 0.0) {",
" gl_FragColor.rgb += (average - gl_FragColor.rgb) * (1.0 - 1.0 / (1.001 - saturation));",
......
......@@ -31,7 +31,7 @@ THREE.LuminosityHighPassShader = {
"}"
].join("\n"),
].join( "\n" ),
fragmentShader: [
......@@ -59,6 +59,6 @@ THREE.LuminosityHighPassShader = {
"}"
].join("\n")
].join( "\n" )
};
此差异已折叠。
......@@ -6,11 +6,11 @@
THREE.ParallaxShader = {
// Ordered from fastest to best quality.
modes: {
none: 'NO_PARALLAX',
basic: 'USE_BASIC_PARALLAX',
steep: 'USE_STEEP_PARALLAX',
occlusion: 'USE_OCLUSION_PARALLAX', // a.k.a. POM
relief: 'USE_RELIEF_PARALLAX'
none: "NO_PARALLAX",
basic: "USE_BASIC_PARALLAX",
steep: "USE_STEEP_PARALLAX",
occlusion: "USE_OCLUSION_PARALLAX", // a.k.a. POM
relief: "USE_RELIEF_PARALLAX"
},
uniforms: {
......@@ -36,7 +36,7 @@ THREE.ParallaxShader = {
"}"
].join( "\n" ),
].join( "\n" ),
fragmentShader: [
"uniform sampler2D bumpMap;",
......@@ -56,10 +56,10 @@ THREE.ParallaxShader = {
" float initialHeight = texture2D( bumpMap, vUv ).r;",
// No Offset Limitting: messy, floating output at grazing angles.
//"vec2 texCoordOffset = parallaxScale * V.xy / V.z * initialHeight;",
// No Offset Limitting: messy, floating output at grazing angles.
//"vec2 texCoordOffset = parallaxScale * V.xy / V.z * initialHeight;",
// Offset Limiting
// Offset Limiting
" vec2 texCoordOffset = parallaxScale * V.xy * initialHeight;",
" return vUv - texCoordOffset;",
......@@ -69,27 +69,27 @@ THREE.ParallaxShader = {
" vec2 parallaxMap( in vec3 V ) {",
// Determine number of layers from angle between V and N
// Determine number of layers from angle between V and N
" float numLayers = mix( parallaxMaxLayers, parallaxMinLayers, abs( dot( vec3( 0.0, 0.0, 1.0 ), V ) ) );",
" float layerHeight = 1.0 / numLayers;",
" float currentLayerHeight = 0.0;",
// Shift of texture coordinates for each iteration
// Shift of texture coordinates for each iteration
" vec2 dtex = parallaxScale * V.xy / V.z / numLayers;",
" vec2 currentTextureCoords = vUv;",
" float heightFromTexture = texture2D( bumpMap, currentTextureCoords ).r;",
// while ( heightFromTexture > currentLayerHeight )
// Infinite loops are not well supported. Do a "large" finite
// loop, but not too large, as it slows down some compilers.
// while ( heightFromTexture > currentLayerHeight )
// Infinite loops are not well supported. Do a "large" finite
// loop, but not too large, as it slows down some compilers.
" for ( int i = 0; i < 30; i += 1 ) {",
" if ( heightFromTexture <= currentLayerHeight ) {",
" break;",
" }",
" currentLayerHeight += layerHeight;",
// Shift texture coordinates along vector V
// Shift texture coordinates along vector V
" currentTextureCoords -= dtex;",
" heightFromTexture = texture2D( bumpMap, currentTextureCoords ).r;",
" }",
......@@ -103,18 +103,18 @@ THREE.ParallaxShader = {
" vec2 deltaTexCoord = dtex / 2.0;",
" float deltaHeight = layerHeight / 2.0;",
// Return to the mid point of previous layer
// Return to the mid point of previous layer
" currentTextureCoords += deltaTexCoord;",
" currentLayerHeight -= deltaHeight;",
// Binary search to increase precision of Steep Parallax Mapping
// Binary search to increase precision of Steep Parallax Mapping
" const int numSearches = 5;",
" for ( int i = 0; i < numSearches; i += 1 ) {",
" deltaTexCoord /= 2.0;",
" deltaHeight /= 2.0;",
" heightFromTexture = texture2D( bumpMap, currentTextureCoords ).r;",
// Shift along or against vector V
// Shift along or against vector V
" if( heightFromTexture > currentLayerHeight ) {", // Below the surface
" currentTextureCoords -= deltaTexCoord;",
......@@ -134,14 +134,14 @@ THREE.ParallaxShader = {
" vec2 prevTCoords = currentTextureCoords + dtex;",
// Heights for linear interpolation
// Heights for linear interpolation
" float nextH = heightFromTexture - currentLayerHeight;",
" float prevH = texture2D( bumpMap, prevTCoords ).r - currentLayerHeight + layerHeight;",
// Proportions for linear interpolation
// Proportions for linear interpolation
" float weight = nextH / ( nextH - prevH );",
// Interpolation of texture coordinates
// Interpolation of texture coordinates
" return prevTCoords * weight + currentTextureCoords * ( 1.0 - weight );",
" #else", // NO_PARALLAX
......@@ -179,6 +179,6 @@ THREE.ParallaxShader = {
"}"
].join( "\n" )
].join( "\n" )
};
......@@ -4,32 +4,32 @@
THREE.SAOShader = {
defines: {
'NUM_SAMPLES': 7,
'NUM_RINGS': 4,
'NORMAL_TEXTURE': 0,
'DIFFUSE_TEXTURE': 0,
'DEPTH_PACKING': 1,
'PERSPECTIVE_CAMERA': 1
"NUM_SAMPLES": 7,
"NUM_RINGS": 4,
"NORMAL_TEXTURE": 0,
"DIFFUSE_TEXTURE": 0,
"DEPTH_PACKING": 1,
"PERSPECTIVE_CAMERA": 1
},
uniforms: {
'tDepth': { value: null },
'tDiffuse': { value: null },
'tNormal': { value: null },
'size': { value: new THREE.Vector2( 512, 512 ) },
"tDepth": { value: null },
"tDiffuse": { value: null },
"tNormal": { value: null },
"size": { value: new THREE.Vector2( 512, 512 ) },
'cameraNear': { value: 1 },
'cameraFar': { value: 100 },
'cameraProjectionMatrix': { value: new THREE.Matrix4() },
'cameraInverseProjectionMatrix': { value: new THREE.Matrix4() },
"cameraNear": { value: 1 },
"cameraFar": { value: 100 },
"cameraProjectionMatrix": { value: new THREE.Matrix4() },
"cameraInverseProjectionMatrix": { value: new THREE.Matrix4() },
'scale': { value: 1.0 },
'intensity': { value: 0.1 },
'bias': { value: 0.5 },
"scale": { value: 1.0 },
"intensity": { value: 0.1 },
"bias": { value: 0.5 },
'minResolution': { value: 0.0 },
'kernelRadius': { value: 100.0 },
'randomSeed': { value: 0.0 }
"minResolution": { value: 0.0 },
"kernelRadius": { value: 100.0 },
"randomSeed": { value: 0.0 }
},
vertexShader: [
"varying vec2 vUv;",
......
此差异已折叠。
......@@ -40,44 +40,44 @@ THREE.SobelOperatorShader = {
" vec2 texel = vec2( 1.0 / resolution.x, 1.0 / resolution.y );",
// kernel definition (in glsl matrices are filled in column-major order)
// kernel definition (in glsl matrices are filled in column-major order)
" const mat3 Gx = mat3( -1, -2, -1, 0, 0, 0, 1, 2, 1 );", // x direction kernel
" const mat3 Gy = mat3( -1, 0, 1, -2, 0, 2, -1, 0, 1 );", // y direction kernel
// fetch the 3x3 neighbourhood of a fragment
// fetch the 3x3 neighbourhood of a fragment
// first column
// first column
" float tx0y0 = texture2D( tDiffuse, vUv + texel * vec2( -1, -1 ) ).r;",
" float tx0y1 = texture2D( tDiffuse, vUv + texel * vec2( -1, 0 ) ).r;",
" float tx0y2 = texture2D( tDiffuse, vUv + texel * vec2( -1, 1 ) ).r;",
// second column
// second column
" float tx1y0 = texture2D( tDiffuse, vUv + texel * vec2( 0, -1 ) ).r;",
" float tx1y1 = texture2D( tDiffuse, vUv + texel * vec2( 0, 0 ) ).r;",
" float tx1y2 = texture2D( tDiffuse, vUv + texel * vec2( 0, 1 ) ).r;",
// third column
// third column
" float tx2y0 = texture2D( tDiffuse, vUv + texel * vec2( 1, -1 ) ).r;",
" float tx2y1 = texture2D( tDiffuse, vUv + texel * vec2( 1, 0 ) ).r;",
" float tx2y2 = texture2D( tDiffuse, vUv + texel * vec2( 1, 1 ) ).r;",
// gradient value in x direction
// gradient value in x direction
" float valueGx = Gx[0][0] * tx0y0 + Gx[1][0] * tx1y0 + Gx[2][0] * tx2y0 + ",
" Gx[0][1] * tx0y1 + Gx[1][1] * tx1y1 + Gx[2][1] * tx2y1 + ",
" Gx[0][2] * tx0y2 + Gx[1][2] * tx1y2 + Gx[2][2] * tx2y2; ",
// gradient value in y direction
// gradient value in y direction
" float valueGy = Gy[0][0] * tx0y0 + Gy[1][0] * tx1y0 + Gy[2][0] * tx2y0 + ",
" Gy[0][1] * tx0y1 + Gy[1][1] * tx1y1 + Gy[2][1] * tx2y1 + ",
" Gy[0][2] * tx0y2 + Gy[1][2] * tx1y2 + Gy[2][2] * tx2y2; ",
// magnitute of the total gradient
// magnitute of the total gradient
" float G = sqrt( ( valueGx * valueGx ) + ( valueGy * valueGy ) );",
......
......@@ -49,7 +49,7 @@ THREE.TriangleBlurShader = {
" float total = 0.0;",
// randomize the lookup values to hide the fixed number of samples
// randomize the lookup values to hide the fixed number of samples
" float offset = rand( vUv );",
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册