super-three 0.155.0 → 0.156.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/three.cjs +107 -125
- package/build/three.js +107 -125
- package/build/three.min.js +1 -1
- package/build/three.module.js +104 -126
- package/build/three.module.min.js +1 -1
- package/examples/jsm/controls/OrbitControls.js +13 -5
- package/examples/jsm/csm/CSMShader.js +35 -1
- package/examples/jsm/libs/tween.module.js +790 -735
- package/examples/jsm/libs/utif.module.js +1644 -1558
- package/examples/jsm/loaders/DDSLoader.js +46 -3
- package/examples/jsm/loaders/EXRLoader.js +4 -4
- package/examples/jsm/loaders/FBXLoader.js +2 -0
- package/examples/jsm/loaders/GLTFLoader.js +17 -7
- package/examples/jsm/loaders/KTX2Loader.js +126 -77
- package/examples/jsm/loaders/LogLuvLoader.js +2 -2
- package/examples/jsm/loaders/MMDLoader.js +10 -7
- package/examples/jsm/loaders/RGBELoader.js +48 -66
- package/examples/jsm/loaders/STLLoader.js +7 -0
- package/examples/jsm/nodes/Nodes.js +3 -0
- package/examples/jsm/nodes/accessors/BufferAttributeNode.js +28 -2
- package/examples/jsm/nodes/accessors/CubeTextureNode.js +18 -3
- package/examples/jsm/nodes/accessors/ExtendedMaterialNode.js +2 -4
- package/examples/jsm/nodes/accessors/LineMaterialNode.js +31 -0
- package/examples/jsm/nodes/accessors/MaterialNode.js +55 -33
- package/examples/jsm/nodes/accessors/MaterialReferenceNode.js +3 -0
- package/examples/jsm/nodes/accessors/Object3DNode.js +2 -2
- package/examples/jsm/nodes/accessors/TextureNode.js +6 -2
- package/examples/jsm/nodes/accessors/TextureStoreNode.js +29 -0
- package/examples/jsm/nodes/core/AttributeNode.js +2 -2
- package/examples/jsm/nodes/core/Node.js +17 -1
- package/examples/jsm/nodes/core/NodeBuilder.js +94 -12
- package/examples/jsm/nodes/core/NodeUniform.js +1 -1
- package/examples/jsm/nodes/core/OutputStructNode.js +58 -0
- package/examples/jsm/nodes/core/PropertyNode.js +2 -0
- package/examples/jsm/nodes/core/StackNode.js +4 -4
- package/examples/jsm/nodes/core/StructTypeNode.js +24 -0
- package/examples/jsm/nodes/display/ViewportNode.js +19 -5
- package/examples/jsm/nodes/materials/LineDashedNodeMaterial.js +54 -0
- package/examples/jsm/nodes/materials/Materials.js +1 -0
- package/examples/jsm/nodes/materials/NodeMaterial.js +12 -3
- package/examples/jsm/nodes/math/HashNode.js +35 -0
- package/examples/jsm/nodes/shadernode/ShaderNode.js +4 -0
- package/examples/jsm/nodes/utils/SplitNode.js +1 -1
- package/examples/jsm/postprocessing/FilmPass.js +3 -5
- package/examples/jsm/postprocessing/RenderPass.js +30 -12
- package/examples/jsm/postprocessing/SAOPass.js +23 -98
- package/examples/jsm/postprocessing/SSAOPass.js +10 -30
- package/examples/jsm/renderers/common/Backend.js +11 -8
- package/examples/jsm/renderers/common/Binding.js +6 -0
- package/examples/jsm/renderers/common/Bindings.js +5 -4
- package/examples/jsm/renderers/common/Pipelines.js +2 -2
- package/examples/jsm/renderers/common/RenderContexts.js +26 -1
- package/examples/jsm/renderers/common/RenderList.js +12 -4
- package/examples/jsm/renderers/common/RenderObject.js +6 -2
- package/examples/jsm/renderers/common/Renderer.js +12 -3
- package/examples/jsm/renderers/common/SampledTexture.js +2 -1
- package/examples/jsm/renderers/common/Sampler.js +1 -1
- package/examples/jsm/renderers/common/StorageBuffer.js +1 -1
- package/examples/jsm/renderers/common/Textures.js +155 -15
- package/examples/jsm/renderers/common/nodes/NodeSampledTexture.js +2 -2
- package/examples/jsm/renderers/common/nodes/NodeSampler.js +1 -1
- package/examples/jsm/renderers/common/nodes/Nodes.js +43 -9
- package/examples/jsm/renderers/webgl/WebGLBackend.js +607 -0
- package/examples/jsm/renderers/webgl/nodes/GLSLNodeBuilder.js +118 -17
- package/examples/jsm/renderers/webgl/utils/WebGLAttributeUtils.js +84 -0
- package/examples/jsm/renderers/webgl/utils/WebGLExtensions.js +26 -0
- package/examples/jsm/renderers/webgl/utils/WebGLState.js +529 -0
- package/examples/jsm/renderers/webgl/utils/WebGLTextureUtils.js +199 -0
- package/examples/jsm/renderers/webgl/utils/WebGLUtils.js +242 -0
- package/examples/jsm/renderers/webgl-legacy/nodes/GLSL1NodeBuilder.js +340 -0
- package/examples/jsm/renderers/{webgl → webgl-legacy}/nodes/WebGLNodeBuilder.js +1 -1
- package/examples/jsm/renderers/webgpu/WebGPUBackend.js +279 -40
- package/examples/jsm/renderers/webgpu/WebGPURenderer.js +18 -2
- package/examples/jsm/renderers/webgpu/nodes/WGSLNodeBuilder.js +89 -59
- package/examples/jsm/renderers/webgpu/nodes/WGSLNodeFunction.js +2 -2
- package/examples/jsm/renderers/webgpu/utils/WebGPUBindingUtils.js +15 -2
- package/examples/jsm/renderers/webgpu/utils/WebGPUPipelineUtils.js +34 -9
- package/examples/jsm/renderers/webgpu/utils/WebGPUTextureUtils.js +26 -135
- package/examples/jsm/renderers/webgpu/utils/WebGPUUtils.js +6 -5
- package/examples/jsm/shaders/FilmShader.js +11 -54
- package/examples/jsm/shaders/SAOShader.js +0 -13
- package/examples/jsm/shaders/SSAOShader.js +33 -26
- package/package.json +1 -1
- package/src/Three.js +1 -0
- package/src/audio/Audio.js +6 -0
- package/src/constants.js +4 -1
- package/src/core/Object3D.js +1 -14
- package/src/core/UniformsGroup.js +2 -2
- package/src/loaders/DataTextureLoader.js +0 -2
- package/src/materials/Material.js +2 -2
- package/src/math/Vector2.js +2 -2
- package/src/math/Vector3.js +3 -3
- package/src/math/Vector4.js +4 -4
- package/src/objects/Line.js +1 -1
- package/src/objects/Mesh.js +1 -1
- package/src/objects/Points.js +1 -1
- package/src/renderers/WebGLRenderer.js +21 -49
- package/src/renderers/shaders/ShaderChunk/map_fragment.glsl.js +11 -1
- package/src/renderers/shaders/ShaderLib/background.glsl.js +8 -0
- package/src/renderers/webgl/WebGLBackground.js +5 -14
- package/src/renderers/webgl/WebGLProgram.js +2 -0
- package/src/renderers/webgl/WebGLPrograms.js +5 -1
- package/src/renderers/webgl/WebGLTextures.js +4 -4
- package/src/renderers/webgl/WebGLUtils.js +27 -20
- package/src/textures/Texture.js +2 -2
- package/src/utils.js +9 -1
- /package/examples/jsm/renderers/{webgl → webgl-legacy}/nodes/SlotNode.js +0 -0
- /package/examples/jsm/renderers/{webgl → webgl-legacy}/nodes/WebGLNodes.js +0 -0
|
@@ -4,7 +4,9 @@ import {
|
|
|
4
4
|
RGBA_S3TC_DXT3_Format,
|
|
5
5
|
RGBA_S3TC_DXT5_Format,
|
|
6
6
|
RGB_ETC1_Format,
|
|
7
|
-
RGB_S3TC_DXT1_Format
|
|
7
|
+
RGB_S3TC_DXT1_Format,
|
|
8
|
+
RGB_BPTC_SIGNED_Format,
|
|
9
|
+
RGB_BPTC_UNSIGNED_Format
|
|
8
10
|
} from 'three';
|
|
9
11
|
|
|
10
12
|
class DDSLoader extends CompressedTextureLoader {
|
|
@@ -56,6 +58,9 @@ class DDSLoader extends CompressedTextureLoader {
|
|
|
56
58
|
// const DDPF_YUV = 0x200;
|
|
57
59
|
// const DDPF_LUMINANCE = 0x20000;
|
|
58
60
|
|
|
61
|
+
const DXGI_FORMAT_BC6H_UF16 = 95;
|
|
62
|
+
const DXGI_FORMAT_BC6H_SF16 = 96;
|
|
63
|
+
|
|
59
64
|
function fourCCToInt32( value ) {
|
|
60
65
|
|
|
61
66
|
return value.charCodeAt( 0 ) +
|
|
@@ -108,8 +113,10 @@ class DDSLoader extends CompressedTextureLoader {
|
|
|
108
113
|
const FOURCC_DXT3 = fourCCToInt32( 'DXT3' );
|
|
109
114
|
const FOURCC_DXT5 = fourCCToInt32( 'DXT5' );
|
|
110
115
|
const FOURCC_ETC1 = fourCCToInt32( 'ETC1' );
|
|
116
|
+
const FOURCC_DX10 = fourCCToInt32( 'DX10' );
|
|
111
117
|
|
|
112
118
|
const headerLengthInt = 31; // The header length in 32 bit ints
|
|
119
|
+
const extendedHeaderLengthInt = 5; // The extended header length in 32 bit ints
|
|
113
120
|
|
|
114
121
|
// Offsets into the header array
|
|
115
122
|
|
|
@@ -135,6 +142,9 @@ class DDSLoader extends CompressedTextureLoader {
|
|
|
135
142
|
// const off_caps3 = 29;
|
|
136
143
|
// const off_caps4 = 30;
|
|
137
144
|
|
|
145
|
+
// If fourCC = DX10, the extended header starts after 32
|
|
146
|
+
const off_dxgiFormat = 0;
|
|
147
|
+
|
|
138
148
|
// Parse header
|
|
139
149
|
|
|
140
150
|
const header = new Int32Array( buffer, 0, headerLengthInt );
|
|
@@ -152,6 +162,8 @@ class DDSLoader extends CompressedTextureLoader {
|
|
|
152
162
|
|
|
153
163
|
let isRGBAUncompressed = false;
|
|
154
164
|
|
|
165
|
+
let dataOffset = header[ off_size ] + 4;
|
|
166
|
+
|
|
155
167
|
switch ( fourCC ) {
|
|
156
168
|
|
|
157
169
|
case FOURCC_DXT1:
|
|
@@ -178,6 +190,39 @@ class DDSLoader extends CompressedTextureLoader {
|
|
|
178
190
|
dds.format = RGB_ETC1_Format;
|
|
179
191
|
break;
|
|
180
192
|
|
|
193
|
+
case FOURCC_DX10:
|
|
194
|
+
|
|
195
|
+
dataOffset += extendedHeaderLengthInt * 4;
|
|
196
|
+
const extendedHeader = new Int32Array( buffer, ( headerLengthInt + 1 ) * 4, extendedHeaderLengthInt );
|
|
197
|
+
const dxgiFormat = extendedHeader[ off_dxgiFormat ];
|
|
198
|
+
switch ( dxgiFormat ) {
|
|
199
|
+
|
|
200
|
+
case DXGI_FORMAT_BC6H_SF16: {
|
|
201
|
+
|
|
202
|
+
blockBytes = 16;
|
|
203
|
+
dds.format = RGB_BPTC_SIGNED_Format;
|
|
204
|
+
break;
|
|
205
|
+
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
case DXGI_FORMAT_BC6H_UF16: {
|
|
209
|
+
|
|
210
|
+
blockBytes = 16;
|
|
211
|
+
dds.format = RGB_BPTC_UNSIGNED_Format;
|
|
212
|
+
break;
|
|
213
|
+
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
default: {
|
|
217
|
+
|
|
218
|
+
console.error( 'THREE.DDSLoader.parse: Unsupported DXGI_FORMAT code ', dxgiFormat );
|
|
219
|
+
return dds;
|
|
220
|
+
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
}
|
|
224
|
+
break;
|
|
225
|
+
|
|
181
226
|
default:
|
|
182
227
|
|
|
183
228
|
if ( header[ off_RGBBitCount ] === 32
|
|
@@ -226,8 +271,6 @@ class DDSLoader extends CompressedTextureLoader {
|
|
|
226
271
|
dds.width = header[ off_width ];
|
|
227
272
|
dds.height = header[ off_height ];
|
|
228
273
|
|
|
229
|
-
let dataOffset = header[ off_size ] + 4;
|
|
230
|
-
|
|
231
274
|
// Extract mipmaps buffers
|
|
232
275
|
|
|
233
276
|
const faces = dds.isCubemap ? 6 : 1;
|
|
@@ -1996,7 +1996,7 @@ class EXRLoader extends DataTextureLoader {
|
|
|
1996
1996
|
|
|
1997
1997
|
if ( dataView.getUint32( 0, true ) != 20000630 ) { // magic
|
|
1998
1998
|
|
|
1999
|
-
throw new Error( 'THREE.EXRLoader:
|
|
1999
|
+
throw new Error( 'THREE.EXRLoader: Provided file doesn\'t appear to be in OpenEXR format.' );
|
|
2000
2000
|
|
|
2001
2001
|
}
|
|
2002
2002
|
|
|
@@ -2033,7 +2033,7 @@ class EXRLoader extends DataTextureLoader {
|
|
|
2033
2033
|
|
|
2034
2034
|
if ( attributeValue === undefined ) {
|
|
2035
2035
|
|
|
2036
|
-
console.warn( `EXRLoader
|
|
2036
|
+
console.warn( `THREE.EXRLoader: Skipped unknown header attribute type \'${attributeType}\'.` );
|
|
2037
2037
|
|
|
2038
2038
|
} else {
|
|
2039
2039
|
|
|
@@ -2047,8 +2047,8 @@ class EXRLoader extends DataTextureLoader {
|
|
|
2047
2047
|
|
|
2048
2048
|
if ( ( spec & ~ 0x04 ) != 0 ) { // unsupported tiled, deep-image, multi-part
|
|
2049
2049
|
|
|
2050
|
-
console.error( 'EXRHeader:', EXRHeader );
|
|
2051
|
-
throw new Error( 'THREE.EXRLoader:
|
|
2050
|
+
console.error( 'THREE.EXRHeader:', EXRHeader );
|
|
2051
|
+
throw new Error( 'THREE.EXRLoader: Provided file is currently unsupported.' );
|
|
2052
2052
|
|
|
2053
2053
|
}
|
|
2054
2054
|
|
|
@@ -961,6 +961,7 @@ class FBXTreeParser {
|
|
|
961
961
|
}
|
|
962
962
|
|
|
963
963
|
model.name = node.attrName ? PropertyBinding.sanitizeNodeName( node.attrName ) : '';
|
|
964
|
+
model.userData.originalName = node.attrName;
|
|
964
965
|
|
|
965
966
|
model.ID = id;
|
|
966
967
|
|
|
@@ -997,6 +998,7 @@ class FBXTreeParser {
|
|
|
997
998
|
// set name and id here - otherwise in cases where "subBone" is created it will not have a name / id
|
|
998
999
|
|
|
999
1000
|
bone.name = name ? PropertyBinding.sanitizeNodeName( name ) : '';
|
|
1001
|
+
bone.userData.originalName = name;
|
|
1000
1002
|
bone.ID = id;
|
|
1001
1003
|
|
|
1002
1004
|
skeleton.bones[ i ] = bone;
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
BufferGeometry,
|
|
7
7
|
ClampToEdgeWrapping,
|
|
8
8
|
Color,
|
|
9
|
+
ColorManagement,
|
|
9
10
|
DirectionalLight,
|
|
10
11
|
DoubleSide,
|
|
11
12
|
FileLoader,
|
|
@@ -25,6 +26,7 @@ import {
|
|
|
25
26
|
LinearFilter,
|
|
26
27
|
LinearMipmapLinearFilter,
|
|
27
28
|
LinearMipmapNearestFilter,
|
|
29
|
+
LinearSRGBColorSpace,
|
|
28
30
|
Loader,
|
|
29
31
|
LoaderUtils,
|
|
30
32
|
Material,
|
|
@@ -545,7 +547,7 @@ class GLTFLightsExtension {
|
|
|
545
547
|
|
|
546
548
|
const color = new Color( 0xffffff );
|
|
547
549
|
|
|
548
|
-
if ( lightDef.color !== undefined ) color.
|
|
550
|
+
if ( lightDef.color !== undefined ) color.setRGB( lightDef.color[ 0 ], lightDef.color[ 1 ], lightDef.color[ 2 ], LinearSRGBColorSpace );
|
|
549
551
|
|
|
550
552
|
const range = lightDef.range !== undefined ? lightDef.range : 0;
|
|
551
553
|
|
|
@@ -663,7 +665,7 @@ class GLTFMaterialsUnlitExtension {
|
|
|
663
665
|
|
|
664
666
|
const array = metallicRoughness.baseColorFactor;
|
|
665
667
|
|
|
666
|
-
materialParams.color.
|
|
668
|
+
materialParams.color.setRGB( array[ 0 ], array[ 1 ], array[ 2 ], LinearSRGBColorSpace );
|
|
667
669
|
materialParams.opacity = array[ 3 ];
|
|
668
670
|
|
|
669
671
|
}
|
|
@@ -939,7 +941,8 @@ class GLTFMaterialsSheenExtension {
|
|
|
939
941
|
|
|
940
942
|
if ( extension.sheenColorFactor !== undefined ) {
|
|
941
943
|
|
|
942
|
-
|
|
944
|
+
const colorFactor = extension.sheenColorFactor;
|
|
945
|
+
materialParams.sheenColor.setRGB( colorFactor[ 0 ], colorFactor[ 1 ], colorFactor [ 2 ], LinearSRGBColorSpace );
|
|
943
946
|
|
|
944
947
|
}
|
|
945
948
|
|
|
@@ -1077,7 +1080,7 @@ class GLTFMaterialsVolumeExtension {
|
|
|
1077
1080
|
materialParams.attenuationDistance = extension.attenuationDistance || Infinity;
|
|
1078
1081
|
|
|
1079
1082
|
const colorArray = extension.attenuationColor || [ 1, 1, 1 ];
|
|
1080
|
-
materialParams.attenuationColor = new Color( colorArray[ 0 ], colorArray[ 1 ], colorArray[ 2 ] );
|
|
1083
|
+
materialParams.attenuationColor = new Color().setRGB( colorArray[ 0 ], colorArray[ 1 ], colorArray[ 2 ], LinearSRGBColorSpace );
|
|
1081
1084
|
|
|
1082
1085
|
return Promise.all( pending );
|
|
1083
1086
|
|
|
@@ -1180,7 +1183,7 @@ class GLTFMaterialsSpecularExtension {
|
|
|
1180
1183
|
}
|
|
1181
1184
|
|
|
1182
1185
|
const colorArray = extension.specularColorFactor || [ 1, 1, 1 ];
|
|
1183
|
-
materialParams.specularColor = new Color( colorArray[ 0 ], colorArray[ 1 ], colorArray[ 2 ] );
|
|
1186
|
+
materialParams.specularColor = new Color().setRGB( colorArray[ 0 ], colorArray[ 1 ], colorArray[ 2 ], LinearSRGBColorSpace );
|
|
1184
1187
|
|
|
1185
1188
|
if ( extension.specularColorTexture !== undefined ) {
|
|
1186
1189
|
|
|
@@ -3386,7 +3389,7 @@ class GLTFParser {
|
|
|
3386
3389
|
|
|
3387
3390
|
const array = metallicRoughness.baseColorFactor;
|
|
3388
3391
|
|
|
3389
|
-
materialParams.color.
|
|
3392
|
+
materialParams.color.setRGB( array[ 0 ], array[ 1 ], array[ 2 ], LinearSRGBColorSpace );
|
|
3390
3393
|
materialParams.opacity = array[ 3 ];
|
|
3391
3394
|
|
|
3392
3395
|
}
|
|
@@ -3478,7 +3481,8 @@ class GLTFParser {
|
|
|
3478
3481
|
|
|
3479
3482
|
if ( materialDef.emissiveFactor !== undefined && materialType !== MeshBasicMaterial ) {
|
|
3480
3483
|
|
|
3481
|
-
|
|
3484
|
+
const emissiveFactor = materialDef.emissiveFactor;
|
|
3485
|
+
materialParams.emissive = new Color().setRGB( emissiveFactor[ 0 ], emissiveFactor[ 1 ], emissiveFactor[ 2 ], LinearSRGBColorSpace );
|
|
3482
3486
|
|
|
3483
3487
|
}
|
|
3484
3488
|
|
|
@@ -4559,6 +4563,12 @@ function addPrimitiveAttributes( geometry, primitiveDef, parser ) {
|
|
|
4559
4563
|
|
|
4560
4564
|
}
|
|
4561
4565
|
|
|
4566
|
+
if ( ColorManagement.workingColorSpace !== LinearSRGBColorSpace && 'COLOR_0' in attributes ) {
|
|
4567
|
+
|
|
4568
|
+
console.warn( `THREE.GLTFLoader: Converting vertex colors from "srgb-linear" to "${ColorManagement.workingColorSpace}" not supported.` );
|
|
4569
|
+
|
|
4570
|
+
}
|
|
4571
|
+
|
|
4562
4572
|
assignExtrasToUserData( geometry, primitiveDef );
|
|
4563
4573
|
|
|
4564
4574
|
computeBounds( geometry, primitiveDef, parser );
|
|
@@ -17,12 +17,15 @@ import {
|
|
|
17
17
|
CompressedCubeTexture,
|
|
18
18
|
Data3DTexture,
|
|
19
19
|
DataTexture,
|
|
20
|
+
DisplayP3ColorSpace,
|
|
20
21
|
FileLoader,
|
|
21
22
|
FloatType,
|
|
22
23
|
HalfFloatType,
|
|
23
24
|
NoColorSpace,
|
|
24
25
|
LinearFilter,
|
|
25
26
|
LinearMipmapLinearFilter,
|
|
27
|
+
LinearDisplayP3ColorSpace,
|
|
28
|
+
LinearSRGBColorSpace,
|
|
26
29
|
Loader,
|
|
27
30
|
RedFormat,
|
|
28
31
|
RGB_ETC1_Format,
|
|
@@ -30,6 +33,7 @@ import {
|
|
|
30
33
|
RGB_PVRTC_4BPPV1_Format,
|
|
31
34
|
RGB_S3TC_DXT1_Format,
|
|
32
35
|
RGBA_ASTC_4x4_Format,
|
|
36
|
+
RGBA_ASTC_6x6_Format,
|
|
33
37
|
RGBA_BPTC_Format,
|
|
34
38
|
RGBA_ETC2_EAC_Format,
|
|
35
39
|
RGBA_PVRTC_4BPPV1_Format,
|
|
@@ -59,6 +63,11 @@ import {
|
|
|
59
63
|
VK_FORMAT_R8G8_UNORM,
|
|
60
64
|
VK_FORMAT_R8G8B8A8_SRGB,
|
|
61
65
|
VK_FORMAT_R8G8B8A8_UNORM,
|
|
66
|
+
VK_FORMAT_ASTC_6x6_SRGB_BLOCK,
|
|
67
|
+
VK_FORMAT_ASTC_6x6_UNORM_BLOCK,
|
|
68
|
+
KHR_DF_PRIMARIES_UNSPECIFIED,
|
|
69
|
+
KHR_DF_PRIMARIES_BT709,
|
|
70
|
+
KHR_DF_PRIMARIES_DISPLAYP3
|
|
62
71
|
} from '../libs/ktx-parse.module.js';
|
|
63
72
|
import { ZSTDDecoder } from '../libs/zstddec.module.js';
|
|
64
73
|
|
|
@@ -254,7 +263,7 @@ class KTX2Loader extends Loader {
|
|
|
254
263
|
|
|
255
264
|
_createTextureFrom( transcodeResult, container ) {
|
|
256
265
|
|
|
257
|
-
const { faces, width, height, format, type, error,
|
|
266
|
+
const { faces, width, height, format, type, error, dfdFlags } = transcodeResult;
|
|
258
267
|
|
|
259
268
|
if ( type === 'error' ) return Promise.reject( error );
|
|
260
269
|
|
|
@@ -279,8 +288,7 @@ class KTX2Loader extends Loader {
|
|
|
279
288
|
texture.generateMipmaps = false;
|
|
280
289
|
|
|
281
290
|
texture.needsUpdate = true;
|
|
282
|
-
|
|
283
|
-
texture.colorSpace = dfdTransferFn === KHR_DF_TRANSFER_SRGB ? SRGBColorSpace : NoColorSpace;
|
|
291
|
+
texture.colorSpace = parseColorSpace( container );
|
|
284
292
|
texture.premultiplyAlpha = !! ( dfdFlags & KHR_DF_FLAG_ALPHA_PREMULTIPLIED );
|
|
285
293
|
|
|
286
294
|
return texture;
|
|
@@ -298,33 +306,7 @@ class KTX2Loader extends Loader {
|
|
|
298
306
|
|
|
299
307
|
if ( container.vkFormat !== VK_FORMAT_UNDEFINED ) {
|
|
300
308
|
|
|
301
|
-
|
|
302
|
-
const pendings = [];
|
|
303
|
-
|
|
304
|
-
for ( let levelIndex = 0; levelIndex < container.levels.length; levelIndex ++ ) {
|
|
305
|
-
|
|
306
|
-
pendings.push( createDataTexture( container, levelIndex ).then( function ( dataTexture ) {
|
|
307
|
-
|
|
308
|
-
mipmaps[ levelIndex ] = dataTexture;
|
|
309
|
-
|
|
310
|
-
} ) );
|
|
311
|
-
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
await Promise.all( pendings );
|
|
315
|
-
|
|
316
|
-
const texture = mipmaps[ 0 ];
|
|
317
|
-
texture.mipmaps = mipmaps.map( dt => {
|
|
318
|
-
|
|
319
|
-
return {
|
|
320
|
-
data: dt.source.data,
|
|
321
|
-
width: dt.source.data.width,
|
|
322
|
-
height: dt.source.data.height,
|
|
323
|
-
depth: dt.source.data.depth
|
|
324
|
-
};
|
|
325
|
-
|
|
326
|
-
} );
|
|
327
|
-
return texture;
|
|
309
|
+
return createRawTexture( container );
|
|
328
310
|
|
|
329
311
|
}
|
|
330
312
|
|
|
@@ -426,9 +408,9 @@ KTX2Loader.BasisWorker = function () {
|
|
|
426
408
|
|
|
427
409
|
try {
|
|
428
410
|
|
|
429
|
-
const { faces, buffers, width, height, hasAlpha, format,
|
|
411
|
+
const { faces, buffers, width, height, hasAlpha, format, dfdFlags } = transcode( message.buffer );
|
|
430
412
|
|
|
431
|
-
self.postMessage( { type: 'transcode', id: message.id, faces, width, height, hasAlpha, format,
|
|
413
|
+
self.postMessage( { type: 'transcode', id: message.id, faces, width, height, hasAlpha, format, dfdFlags }, buffers );
|
|
432
414
|
|
|
433
415
|
} catch ( error ) {
|
|
434
416
|
|
|
@@ -491,7 +473,6 @@ KTX2Loader.BasisWorker = function () {
|
|
|
491
473
|
const levelCount = ktx2File.getLevels();
|
|
492
474
|
const faceCount = ktx2File.getFaces();
|
|
493
475
|
const hasAlpha = ktx2File.getHasAlpha();
|
|
494
|
-
const dfdTransferFn = ktx2File.getDFDTransferFunc();
|
|
495
476
|
const dfdFlags = ktx2File.getDFDFlags();
|
|
496
477
|
|
|
497
478
|
const { transcoderFormat, engineFormat } = getTranscoderFormat( basisFormat, width, height, hasAlpha );
|
|
@@ -575,7 +556,7 @@ KTX2Loader.BasisWorker = function () {
|
|
|
575
556
|
|
|
576
557
|
cleanup();
|
|
577
558
|
|
|
578
|
-
return { faces, buffers, width, height, hasAlpha, format: engineFormat,
|
|
559
|
+
return { faces, buffers, width, height, hasAlpha, format: engineFormat, dfdFlags };
|
|
579
560
|
|
|
580
561
|
}
|
|
581
562
|
|
|
@@ -730,7 +711,10 @@ KTX2Loader.BasisWorker = function () {
|
|
|
730
711
|
};
|
|
731
712
|
|
|
732
713
|
//
|
|
733
|
-
//
|
|
714
|
+
// Parsing for non-Basis textures. These textures are may have supercompression
|
|
715
|
+
// like Zstd, but they do not require transcoding.
|
|
716
|
+
|
|
717
|
+
const UNCOMPRESSED_FORMATS = new Set( [ RGBAFormat, RGFormat, RedFormat ] );
|
|
734
718
|
|
|
735
719
|
const FORMAT_MAP = {
|
|
736
720
|
|
|
@@ -749,6 +733,9 @@ const FORMAT_MAP = {
|
|
|
749
733
|
[ VK_FORMAT_R8_SRGB ]: RedFormat,
|
|
750
734
|
[ VK_FORMAT_R8_UNORM ]: RedFormat,
|
|
751
735
|
|
|
736
|
+
[ VK_FORMAT_ASTC_6x6_SRGB_BLOCK ]: RGBA_ASTC_6x6_Format,
|
|
737
|
+
[ VK_FORMAT_ASTC_6x6_UNORM_BLOCK ]: RGBA_ASTC_6x6_Format,
|
|
738
|
+
|
|
752
739
|
};
|
|
753
740
|
|
|
754
741
|
const TYPE_MAP = {
|
|
@@ -768,22 +755,14 @@ const TYPE_MAP = {
|
|
|
768
755
|
[ VK_FORMAT_R8_SRGB ]: UnsignedByteType,
|
|
769
756
|
[ VK_FORMAT_R8_UNORM ]: UnsignedByteType,
|
|
770
757
|
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
const COLOR_SPACE_MAP = {
|
|
774
|
-
|
|
775
|
-
[ VK_FORMAT_R8G8B8A8_SRGB ]: SRGBColorSpace,
|
|
776
|
-
[ VK_FORMAT_R8G8_SRGB ]: SRGBColorSpace,
|
|
777
|
-
[ VK_FORMAT_R8_SRGB ]: SRGBColorSpace,
|
|
758
|
+
[ VK_FORMAT_ASTC_6x6_SRGB_BLOCK ]: UnsignedByteType,
|
|
759
|
+
[ VK_FORMAT_ASTC_6x6_UNORM_BLOCK ]: UnsignedByteType,
|
|
778
760
|
|
|
779
761
|
};
|
|
780
762
|
|
|
781
|
-
async function
|
|
763
|
+
async function createRawTexture( container ) {
|
|
782
764
|
|
|
783
765
|
const { vkFormat } = container;
|
|
784
|
-
const pixelWidth = Math.max( 1, container.pixelWidth >> levelIndex );
|
|
785
|
-
const pixelHeight = Math.max( 1, container.pixelHeight >> levelIndex );
|
|
786
|
-
const pixelDepth = Math.max( 1, container.pixelDepth >> levelIndex );
|
|
787
766
|
|
|
788
767
|
if ( FORMAT_MAP[ vkFormat ] === undefined ) {
|
|
789
768
|
|
|
@@ -791,16 +770,11 @@ async function createDataTexture( container, levelIndex = 0 ) {
|
|
|
791
770
|
|
|
792
771
|
}
|
|
793
772
|
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
let levelData;
|
|
797
|
-
let view;
|
|
798
|
-
|
|
799
|
-
if ( container.supercompressionScheme === KHR_SUPERCOMPRESSION_NONE ) {
|
|
773
|
+
//
|
|
800
774
|
|
|
801
|
-
|
|
775
|
+
let zstd;
|
|
802
776
|
|
|
803
|
-
|
|
777
|
+
if ( container.supercompressionScheme === KHR_SUPERCOMPRESSION_ZSTD ) {
|
|
804
778
|
|
|
805
779
|
if ( ! _zstd ) {
|
|
806
780
|
|
|
@@ -814,49 +788,99 @@ async function createDataTexture( container, levelIndex = 0 ) {
|
|
|
814
788
|
|
|
815
789
|
}
|
|
816
790
|
|
|
817
|
-
|
|
791
|
+
zstd = await _zstd;
|
|
818
792
|
|
|
819
|
-
}
|
|
793
|
+
}
|
|
820
794
|
|
|
821
|
-
|
|
795
|
+
//
|
|
822
796
|
|
|
823
|
-
|
|
797
|
+
const mipmaps = [];
|
|
798
|
+
|
|
799
|
+
|
|
800
|
+
for ( let levelIndex = 0; levelIndex < container.levels.length; levelIndex ++ ) {
|
|
801
|
+
|
|
802
|
+
const levelWidth = Math.max( 1, container.pixelWidth >> levelIndex );
|
|
803
|
+
const levelHeight = Math.max( 1, container.pixelHeight >> levelIndex );
|
|
804
|
+
const levelDepth = container.pixelDepth ? Math.max( 1, container.pixelDepth >> levelIndex ) : 0;
|
|
805
|
+
|
|
806
|
+
const level = container.levels[ levelIndex ];
|
|
824
807
|
|
|
825
|
-
|
|
808
|
+
let levelData;
|
|
826
809
|
|
|
827
|
-
|
|
810
|
+
if ( container.supercompressionScheme === KHR_SUPERCOMPRESSION_NONE ) {
|
|
828
811
|
|
|
829
|
-
levelData.
|
|
830
|
-
levelData.byteOffset,
|
|
831
|
-
levelData.byteLength / Float32Array.BYTES_PER_ELEMENT
|
|
812
|
+
levelData = level.levelData;
|
|
832
813
|
|
|
833
|
-
)
|
|
814
|
+
} else if ( container.supercompressionScheme === KHR_SUPERCOMPRESSION_ZSTD ) {
|
|
834
815
|
|
|
835
|
-
|
|
816
|
+
levelData = zstd.decode( level.levelData, level.uncompressedByteLength );
|
|
836
817
|
|
|
837
|
-
|
|
818
|
+
} else {
|
|
819
|
+
|
|
820
|
+
throw new Error( 'THREE.KTX2Loader: Unsupported supercompressionScheme.' );
|
|
821
|
+
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
let data;
|
|
838
825
|
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
826
|
+
if ( TYPE_MAP[ vkFormat ] === FloatType ) {
|
|
827
|
+
|
|
828
|
+
data = new Float32Array(
|
|
829
|
+
|
|
830
|
+
levelData.buffer,
|
|
831
|
+
levelData.byteOffset,
|
|
832
|
+
levelData.byteLength / Float32Array.BYTES_PER_ELEMENT
|
|
833
|
+
|
|
834
|
+
);
|
|
842
835
|
|
|
843
|
-
)
|
|
836
|
+
} else if ( TYPE_MAP[ vkFormat ] === HalfFloatType ) {
|
|
837
|
+
|
|
838
|
+
data = new Uint16Array(
|
|
839
|
+
|
|
840
|
+
levelData.buffer,
|
|
841
|
+
levelData.byteOffset,
|
|
842
|
+
levelData.byteLength / Uint16Array.BYTES_PER_ELEMENT
|
|
843
|
+
|
|
844
|
+
);
|
|
845
|
+
|
|
846
|
+
} else {
|
|
847
|
+
|
|
848
|
+
data = levelData;
|
|
849
|
+
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
mipmaps.push( {
|
|
853
|
+
|
|
854
|
+
data: data,
|
|
855
|
+
width: levelWidth,
|
|
856
|
+
height: levelHeight,
|
|
857
|
+
depth: levelDepth,
|
|
858
|
+
|
|
859
|
+
} );
|
|
860
|
+
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
let texture;
|
|
864
|
+
|
|
865
|
+
if ( UNCOMPRESSED_FORMATS.has( FORMAT_MAP[ vkFormat ] ) ) {
|
|
866
|
+
|
|
867
|
+
texture = container.pixelDepth === 0
|
|
868
|
+
? new DataTexture( mipmaps[ 0 ].data, container.pixelWidth, container.pixelHeight )
|
|
869
|
+
: new Data3DTexture( mipmaps[ 0 ].data, container.pixelWidth, container.pixelHeight, container.pixelDepth );
|
|
844
870
|
|
|
845
871
|
} else {
|
|
846
872
|
|
|
847
|
-
|
|
873
|
+
if ( container.pixelDepth > 0 ) throw new Error( 'THREE.KTX2Loader: Unsupported pixelDepth.' );
|
|
874
|
+
|
|
875
|
+
texture = new CompressedTexture( mipmaps, container.pixelWidth, container.pixelHeight );
|
|
848
876
|
|
|
849
877
|
}
|
|
850
|
-
//
|
|
851
878
|
|
|
852
|
-
|
|
853
|
-
? new DataTexture( view, pixelWidth, pixelHeight )
|
|
854
|
-
: new Data3DTexture( view, pixelWidth, pixelHeight, pixelDepth );
|
|
879
|
+
texture.mipmaps = mipmaps;
|
|
855
880
|
|
|
856
881
|
texture.type = TYPE_MAP[ vkFormat ];
|
|
857
882
|
texture.format = FORMAT_MAP[ vkFormat ];
|
|
858
|
-
texture.colorSpace =
|
|
859
|
-
|
|
883
|
+
texture.colorSpace = parseColorSpace( container );
|
|
860
884
|
texture.needsUpdate = true;
|
|
861
885
|
|
|
862
886
|
//
|
|
@@ -865,4 +889,29 @@ async function createDataTexture( container, levelIndex = 0 ) {
|
|
|
865
889
|
|
|
866
890
|
}
|
|
867
891
|
|
|
892
|
+
function parseColorSpace( container ) {
|
|
893
|
+
|
|
894
|
+
const dfd = container.dataFormatDescriptor[ 0 ];
|
|
895
|
+
|
|
896
|
+
if ( dfd.colorPrimaries === KHR_DF_PRIMARIES_BT709 ) {
|
|
897
|
+
|
|
898
|
+
return dfd.transferFunction === KHR_DF_TRANSFER_SRGB ? SRGBColorSpace : LinearSRGBColorSpace;
|
|
899
|
+
|
|
900
|
+
} else if ( dfd.colorPrimaries === KHR_DF_PRIMARIES_DISPLAYP3 ) {
|
|
901
|
+
|
|
902
|
+
return dfd.transferFunction === KHR_DF_TRANSFER_SRGB ? DisplayP3ColorSpace : LinearDisplayP3ColorSpace;
|
|
903
|
+
|
|
904
|
+
} else if ( dfd.colorPrimaries === KHR_DF_PRIMARIES_UNSPECIFIED ) {
|
|
905
|
+
|
|
906
|
+
return NoColorSpace;
|
|
907
|
+
|
|
908
|
+
} else {
|
|
909
|
+
|
|
910
|
+
console.warn( `THREE.KTX2Loader: Unsupported color primaries, "${ dfd.colorPrimaries }"` );
|
|
911
|
+
return NoColorSpace;
|
|
912
|
+
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
}
|
|
916
|
+
|
|
868
917
|
export { KTX2Loader };
|
|
@@ -393,7 +393,7 @@ UTIF.toRGBA = function ( out, type ) {
|
|
|
393
393
|
break;
|
|
394
394
|
|
|
395
395
|
default:
|
|
396
|
-
|
|
396
|
+
throw new Error( 'THREE.LogLuvLoader: Unsupported texture data type: ' + type );
|
|
397
397
|
|
|
398
398
|
}
|
|
399
399
|
|
|
@@ -451,7 +451,7 @@ UTIF.toRGBA = function ( out, type ) {
|
|
|
451
451
|
|
|
452
452
|
} else {
|
|
453
453
|
|
|
454
|
-
|
|
454
|
+
throw new Error( 'THREE.LogLuvLoader: Unsupported Photometric interpretation: ' + intp );
|
|
455
455
|
|
|
456
456
|
}
|
|
457
457
|
|
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
Skeleton,
|
|
28
28
|
SkinnedMesh,
|
|
29
29
|
SrcAlphaFactor,
|
|
30
|
+
SRGBColorSpace,
|
|
30
31
|
TextureLoader,
|
|
31
32
|
Uint16BufferAttribute,
|
|
32
33
|
Vector3,
|
|
@@ -1133,17 +1134,18 @@ class MaterialBuilder {
|
|
|
1133
1134
|
* MMDToonMaterial doesn't have ambient. Set it to emissive instead.
|
|
1134
1135
|
* It'll be too bright if material has map texture so using coef 0.2.
|
|
1135
1136
|
*/
|
|
1136
|
-
params.diffuse = new Color().
|
|
1137
|
+
params.diffuse = new Color().setRGB(
|
|
1138
|
+
material.diffuse[ 0 ],
|
|
1139
|
+
material.diffuse[ 1 ],
|
|
1140
|
+
material.diffuse[ 2 ],
|
|
1141
|
+
SRGBColorSpace
|
|
1142
|
+
);
|
|
1137
1143
|
params.opacity = material.diffuse[ 3 ];
|
|
1138
|
-
params.specular = new Color().
|
|
1144
|
+
params.specular = new Color().setRGB( ...material.specular, SRGBColorSpace );
|
|
1139
1145
|
params.shininess = material.shininess;
|
|
1140
|
-
params.emissive = new Color().
|
|
1146
|
+
params.emissive = new Color().setRGB( ...material.ambient, SRGBColorSpace );
|
|
1141
1147
|
params.transparent = params.opacity !== 1.0;
|
|
1142
1148
|
|
|
1143
|
-
params.diffuse.convertSRGBToLinear();
|
|
1144
|
-
params.specular.convertSRGBToLinear();
|
|
1145
|
-
params.emissive.convertSRGBToLinear();
|
|
1146
|
-
|
|
1147
1149
|
//
|
|
1148
1150
|
|
|
1149
1151
|
params.fog = true;
|
|
@@ -1452,6 +1454,7 @@ class MaterialBuilder {
|
|
|
1452
1454
|
t.flipY = false;
|
|
1453
1455
|
t.wrapS = RepeatWrapping;
|
|
1454
1456
|
t.wrapT = RepeatWrapping;
|
|
1457
|
+
t.colorSpace = SRGBColorSpace;
|
|
1455
1458
|
|
|
1456
1459
|
for ( let i = 0; i < texture.readyCallbacks.length; i ++ ) {
|
|
1457
1460
|
|