super-three 0.133.2 → 0.135.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.js +619 -538
- package/build/three.min.js +1 -1
- package/build/three.module.js +763 -616
- package/examples/fonts/open-sans/open-sans-v15-cyrillic-ext_greek_greek-ext_cyrillic_latin_latin-ext_vietnamese-regular.woff +0 -0
- package/examples/fonts/open-sans/open-sans-v15-cyrillic-ext_greek_greek-ext_cyrillic_latin_latin-ext_vietnamese-regular.woff2 +0 -0
- package/examples/fonts/open-sans/open-sans.css +9 -0
- package/examples/fonts/tabler-icons/fonts/tabler-icons.eot +0 -0
- package/examples/fonts/tabler-icons/fonts/tabler-icons.ttf +0 -0
- package/examples/fonts/tabler-icons/fonts/tabler-icons.woff +0 -0
- package/examples/fonts/tabler-icons/fonts/tabler-icons.woff2 +0 -0
- package/examples/fonts/tabler-icons/tabler-icons.min.css +4 -0
- package/examples/js/controls/ArcballControls.js +68 -27
- package/examples/js/controls/DragControls.js +7 -0
- package/examples/js/controls/OrbitControls.js +5 -36
- package/examples/js/controls/TrackballControls.js +3 -2
- package/examples/js/csm/CSM.js +2 -2
- package/examples/js/csm/CSMFrustum.js +133 -0
- package/examples/js/exporters/GLTFExporter.js +147 -63
- package/examples/js/exporters/USDZExporter.js +45 -26
- package/examples/js/lines/LineMaterial.js +58 -20
- package/examples/js/lines/LineSegments2.js +29 -24
- package/examples/js/loaders/3DMLoader.js +24 -11
- package/examples/js/loaders/3MFLoader.js +2 -2
- package/examples/js/loaders/ColladaLoader.js +61 -3
- package/examples/js/loaders/FBXLoader.js +1 -1
- package/examples/js/loaders/GLTFLoader.js +94 -31
- package/examples/js/loaders/KTX2Loader.js +12 -0
- package/examples/js/loaders/LWOLoader.js +8 -6
- package/examples/js/loaders/LogLuvLoader.js +766 -0
- package/examples/js/loaders/PLYLoader.js +32 -7
- package/examples/js/loaders/RGBELoader.js +2 -1
- package/examples/js/loaders/SVGLoader.js +7 -3
- package/examples/js/loaders/TDSLoader.js +237 -271
- package/examples/js/loaders/lwo/LWO2Parser.js +1 -0
- package/examples/js/loaders/lwo/LWO3Parser.js +4 -2
- package/examples/js/objects/MarchingCubes.js +42 -128
- package/examples/js/renderers/CSS2DRenderer.js +4 -4
- package/examples/js/renderers/CSS3DRenderer.js +4 -4
- package/examples/js/utils/RoughnessMipmapper.js +1 -0
- package/examples/jsm/controls/ArcballControls.js +61 -29
- package/examples/jsm/controls/DragControls.js +7 -0
- package/examples/jsm/controls/OrbitControls.js +9 -51
- package/examples/jsm/controls/TrackballControls.js +1 -1
- package/examples/jsm/csm/CSM.js +3 -3
- package/examples/jsm/csm/{Frustum.js → CSMFrustum.js} +3 -3
- package/examples/jsm/exporters/GLTFExporter.js +160 -74
- package/examples/jsm/exporters/USDZExporter.js +47 -26
- package/examples/jsm/libs/flow.module.js +3218 -0
- package/examples/jsm/libs/lil-gui.module.min.js +8 -0
- package/examples/jsm/libs/rhino3dm/rhino3dm.wasm +0 -0
- package/examples/jsm/lines/LineMaterial.js +59 -23
- package/examples/jsm/lines/LineSegments2.js +22 -18
- package/examples/jsm/loaders/3DMLoader.js +18 -12
- package/examples/jsm/loaders/3MFLoader.js +2 -2
- package/examples/jsm/loaders/ColladaLoader.js +61 -3
- package/examples/jsm/loaders/FBXLoader.js +1 -1
- package/examples/jsm/loaders/GLTFLoader.js +99 -35
- package/examples/jsm/loaders/KTX2Loader.js +19 -0
- package/examples/jsm/loaders/LWOLoader.js +8 -6
- package/examples/jsm/loaders/LogLuvLoader.js +606 -0
- package/examples/jsm/loaders/PLYLoader.js +33 -7
- package/examples/jsm/loaders/SVGLoader.js +7 -4
- package/examples/jsm/loaders/TDSLoader.js +225 -285
- package/examples/jsm/loaders/lwo/LWO2Parser.js +1 -0
- package/examples/jsm/loaders/lwo/LWO3Parser.js +2 -2
- package/examples/jsm/node-editor/NodeEditor.js +455 -0
- package/examples/jsm/node-editor/accessors/NormalEditor.js +30 -0
- package/examples/jsm/node-editor/accessors/PositionEditor.js +30 -0
- package/examples/jsm/node-editor/accessors/UVEditor.js +26 -0
- package/examples/jsm/node-editor/display/BlendEditor.js +43 -0
- package/examples/jsm/node-editor/examples/animate-uv.json +1 -0
- package/examples/jsm/node-editor/examples/fake-top-light.json +1 -0
- package/examples/jsm/node-editor/examples/oscillator-color.json +1 -0
- package/examples/jsm/node-editor/examples/rim.json +1 -0
- package/examples/jsm/node-editor/inputs/ColorEditor.js +91 -0
- package/examples/jsm/node-editor/inputs/FloatEditor.js +24 -0
- package/examples/jsm/node-editor/inputs/SliderEditor.js +68 -0
- package/examples/jsm/node-editor/inputs/Vector2Editor.js +28 -0
- package/examples/jsm/node-editor/inputs/Vector3Editor.js +30 -0
- package/examples/jsm/node-editor/inputs/Vector4Editor.js +37 -0
- package/examples/jsm/node-editor/materials/StandardMaterialEditor.js +69 -0
- package/examples/jsm/node-editor/math/DotEditor.js +36 -0
- package/examples/jsm/node-editor/math/InvertEditor.js +38 -0
- package/examples/jsm/node-editor/math/LimiterEditor.js +48 -0
- package/examples/jsm/node-editor/math/NormalizeEditor.js +26 -0
- package/examples/jsm/node-editor/math/OperatorEditor.js +50 -0
- package/examples/jsm/node-editor/math/PowerEditor.js +34 -0
- package/examples/jsm/node-editor/math/TrigonometryEditor.js +39 -0
- package/examples/jsm/node-editor/procedural/CheckerEditor.js +26 -0
- package/examples/jsm/node-editor/utils/OscillatorEditor.js +42 -0
- package/examples/jsm/node-editor/utils/TimerEditor.js +57 -0
- package/examples/jsm/nodes/materials/StandardNodeMaterial.js +1 -1
- package/examples/jsm/nodes/materials/nodes/StandardNode.js +6 -6
- package/examples/jsm/nodes/utils/ColorSpaceNode.js +1 -49
- package/examples/jsm/objects/MarchingCubes.js +46 -152
- package/examples/jsm/postprocessing/AdaptiveToneMappingPass.js +1 -1
- package/examples/jsm/postprocessing/AfterimagePass.js +1 -1
- package/examples/jsm/postprocessing/BloomPass.js +1 -1
- package/examples/jsm/postprocessing/BokehPass.js +1 -1
- package/examples/jsm/postprocessing/ClearPass.js +1 -1
- package/examples/jsm/postprocessing/CubeTexturePass.js +1 -1
- package/examples/jsm/postprocessing/DotScreenPass.js +1 -1
- package/examples/jsm/postprocessing/EffectComposer.js +3 -3
- package/examples/jsm/postprocessing/FilmPass.js +1 -1
- package/examples/jsm/postprocessing/GlitchPass.js +1 -1
- package/examples/jsm/postprocessing/HalftonePass.js +1 -1
- package/examples/jsm/postprocessing/MaskPass.js +1 -1
- package/examples/jsm/postprocessing/OutlinePass.js +1 -1
- package/examples/jsm/postprocessing/RenderPass.js +1 -1
- package/examples/jsm/postprocessing/SAOPass.js +1 -1
- package/examples/jsm/postprocessing/SMAAPass.js +1 -1
- package/examples/jsm/postprocessing/SSAARenderPass.js +1 -1
- package/examples/jsm/postprocessing/SSAOPass.js +1 -1
- package/examples/jsm/postprocessing/SSRPass.js +1 -1
- package/examples/jsm/postprocessing/SSRrPass.js +1 -1
- package/examples/jsm/postprocessing/SavePass.js +1 -1
- package/examples/jsm/postprocessing/ShaderPass.js +1 -1
- package/examples/jsm/postprocessing/TAARenderPass.js +1 -1
- package/examples/jsm/postprocessing/TexturePass.js +1 -1
- package/examples/jsm/postprocessing/UnrealBloomPass.js +1 -1
- package/examples/jsm/renderers/CSS2DRenderer.js +5 -4
- package/examples/jsm/renderers/CSS3DRenderer.js +5 -4
- package/examples/jsm/renderers/nodes/Nodes.js +14 -13
- package/examples/jsm/renderers/nodes/ShaderNode.js +193 -41
- package/examples/jsm/renderers/nodes/accessors/MaterialNode.js +6 -6
- package/examples/jsm/renderers/nodes/accessors/ModelViewProjectionNode.js +5 -5
- package/examples/jsm/renderers/nodes/accessors/NormalNode.js +14 -3
- package/examples/jsm/renderers/nodes/accessors/PointUVNode.js +3 -3
- package/examples/jsm/renderers/nodes/accessors/PositionNode.js +15 -5
- package/examples/jsm/renderers/nodes/accessors/SkinningNode.js +107 -0
- package/examples/jsm/renderers/nodes/accessors/UVNode.js +7 -5
- package/examples/jsm/renderers/nodes/core/ArrayInputNode.js +3 -3
- package/examples/jsm/renderers/nodes/core/AttributeNode.js +6 -0
- package/examples/jsm/renderers/nodes/core/BypassNode.js +38 -0
- package/examples/jsm/renderers/nodes/core/CodeNode.js +3 -3
- package/examples/jsm/renderers/nodes/core/ContextNode.js +4 -19
- package/examples/jsm/renderers/nodes/core/ExpressionNode.js +13 -2
- package/examples/jsm/renderers/nodes/core/FunctionNode.js +19 -132
- package/examples/jsm/renderers/nodes/core/InputNode.js +13 -3
- package/examples/jsm/renderers/nodes/core/Node.js +32 -10
- package/examples/jsm/renderers/nodes/core/NodeBuilder.js +146 -128
- package/examples/jsm/renderers/nodes/core/NodeFunction.js +22 -0
- package/examples/jsm/renderers/nodes/core/NodeFunctionInput.js +4 -4
- package/examples/jsm/renderers/nodes/core/NodeKeywords.js +18 -179
- package/examples/jsm/renderers/nodes/core/NodeParser.js +11 -0
- package/examples/jsm/renderers/nodes/core/NodeVar.js +2 -2
- package/examples/jsm/renderers/nodes/core/PropertyNode.js +14 -2
- package/examples/jsm/renderers/nodes/core/TempNode.js +10 -13
- package/examples/jsm/renderers/nodes/core/VarNode.js +12 -7
- package/examples/jsm/renderers/nodes/core/VaryNode.js +23 -8
- package/examples/jsm/renderers/nodes/core/constants.js +2 -0
- package/examples/jsm/renderers/nodes/display/ColorSpaceNode.js +47 -25
- package/examples/jsm/renderers/nodes/display/NormalMapNode.js +21 -22
- package/examples/jsm/renderers/nodes/functions/BSDFs.js +64 -101
- package/examples/jsm/renderers/nodes/inputs/BufferNode.js +25 -0
- package/examples/jsm/renderers/nodes/inputs/IntNode.js +17 -0
- package/examples/jsm/renderers/nodes/inputs/TextureNode.js +10 -2
- package/examples/jsm/renderers/nodes/lights/LightContextNode.js +20 -14
- package/examples/jsm/renderers/nodes/lights/LightNode.js +32 -36
- package/examples/jsm/renderers/nodes/math/CondNode.js +60 -0
- package/examples/jsm/renderers/nodes/math/MathNode.js +87 -36
- package/examples/jsm/renderers/nodes/math/OperatorNode.js +124 -31
- package/examples/jsm/renderers/nodes/parsers/GLSLNodeFunction.js +137 -0
- package/examples/jsm/renderers/nodes/parsers/GLSLNodeParser.js +14 -0
- package/examples/jsm/renderers/nodes/parsers/WGSLNodeFunction.js +89 -0
- package/examples/jsm/renderers/nodes/parsers/WGSLNodeParser.js +14 -0
- package/examples/jsm/renderers/nodes/procedural/CheckerNode.js +7 -9
- package/examples/jsm/renderers/nodes/utils/ArrayElementNode.js +31 -0
- package/examples/jsm/renderers/nodes/utils/ConvertNode.js +33 -0
- package/examples/jsm/renderers/nodes/utils/JoinNode.js +7 -7
- package/examples/jsm/renderers/nodes/utils/OscNode.js +58 -0
- package/examples/jsm/renderers/nodes/utils/SplitNode.js +18 -8
- package/examples/jsm/renderers/nodes/utils/SpriteSheetUVNode.js +7 -7
- package/examples/jsm/renderers/webgl/nodes/SlotNode.js +22 -0
- package/examples/jsm/renderers/webgl/nodes/WebGLNodeBuilder.js +191 -94
- package/examples/jsm/renderers/webgl/nodes/WebGLNodes.js +2 -2
- package/examples/jsm/renderers/webgl/nodes/WebGLPhysicalContextNode.js +2 -2
- package/examples/jsm/renderers/webgpu/WebGPUBackground.js +1 -1
- package/examples/jsm/renderers/webgpu/WebGPUBindings.js +3 -3
- package/examples/jsm/renderers/webgpu/WebGPUComputePipelines.js +2 -4
- package/examples/jsm/renderers/webgpu/WebGPUProgrammableStage.js +2 -4
- package/examples/jsm/renderers/webgpu/WebGPURenderPipeline.js +15 -23
- package/examples/jsm/renderers/webgpu/WebGPURenderPipelines.js +3 -5
- package/examples/jsm/renderers/webgpu/WebGPURenderer.js +11 -27
- package/examples/jsm/renderers/webgpu/WebGPUTextureUtils.js +62 -28
- package/examples/jsm/renderers/webgpu/WebGPUTextures.js +34 -27
- package/examples/jsm/renderers/webgpu/constants.js +2 -2
- package/examples/jsm/renderers/webgpu/nodes/WebGPUNodeBuilder.js +430 -98
- package/examples/jsm/renderers/webgpu/nodes/WebGPUNodes.js +1 -1
- package/examples/jsm/utils/RoughnessMipmapper.js +1 -0
- package/examples/jsm/webxr/OculusHandPointerModel.js +6 -6
- package/package.json +10 -10
- package/src/Three.Legacy.js +6 -0
- package/src/Three.js +0 -1
- package/src/cameras/StereoCamera.js +8 -7
- package/src/constants.js +1 -2
- package/src/core/Layers.js +7 -1
- package/src/core/Object3D.js +2 -0
- package/src/extras/PMREMGenerator.js +11 -6
- package/src/loaders/FileLoader.js +89 -152
- package/src/loaders/ImageLoader.js +9 -4
- package/src/loaders/LoaderUtils.js +26 -0
- package/src/loaders/MaterialLoader.js +7 -4
- package/src/loaders/ObjectLoader.js +2 -0
- package/src/materials/Material.js +4 -4
- package/src/materials/MeshPhysicalMaterial.js +20 -14
- package/src/math/MathUtils.js +5 -16
- package/src/renderers/WebGLMultisampleRenderTarget.js +7 -1
- package/src/renderers/WebGLRenderer.js +83 -117
- package/src/renderers/shaders/ShaderChunk/bsdfs.glsl.js +2 -2
- package/src/renderers/shaders/ShaderChunk/encodings_pars_fragment.glsl.js +0 -27
- package/src/renderers/shaders/ShaderChunk/envmap_common_pars_fragment.glsl.js +0 -1
- package/src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl.js +19 -6
- package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +2 -2
- package/src/renderers/shaders/ShaderChunk/transmission_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/transmission_pars_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +13 -5
- package/src/renderers/shaders/ShaderLib/vsm.glsl.js +2 -1
- package/src/renderers/shaders/ShaderLib.js +6 -4
- package/src/renderers/shaders/UniformsLib.js +1 -2
- package/src/renderers/webgl/WebGLExtensions.js +1 -0
- package/src/renderers/webgl/WebGLMaterials.js +27 -15
- package/src/renderers/webgl/WebGLProgram.js +10 -6
- package/src/renderers/webgl/WebGLPrograms.js +17 -12
- package/src/renderers/webgl/WebGLShadowMap.js +14 -5
- package/src/renderers/webgl/WebGLState.js +31 -17
- package/src/renderers/webgl/WebGLTextures.js +188 -51
- package/src/renderers/webgl/WebGLUniforms.js +45 -1
- package/src/renderers/webxr/WebXRManager.js +71 -110
- package/src/textures/Texture.js +6 -0
- package/src/utils.js +37 -1
- package/examples/js/controls/DeviceOrientationControls.js +0 -147
- package/examples/js/libs/dat.gui.min.js +0 -14
- package/examples/jsm/controls/DeviceOrientationControls.js +0 -153
- package/examples/jsm/libs/dat.gui.module.js +0 -3575
- package/examples/jsm/libs/glslang.js +0 -78
- package/examples/jsm/libs/glslang.wasm +0 -0
- package/examples/jsm/renderers/nodes/consts/MathConsts.js +0 -7
- package/examples/jsm/renderers/nodes/core/ConstNode.js +0 -39
- package/examples/jsm/renderers/nodes/core/NodeSlot.js +0 -13
- package/examples/jsm/renderers/nodes/core/StructNode.js +0 -80
- package/examples/jsm/renderers/nodes/core/StructVarNode.js +0 -75
- package/examples/jsm/renderers/nodes/functions/EncodingFunctions.js +0 -99
- package/examples/jsm/renderers/nodes/functions/MathFunctions.js +0 -47
- package/examples/jsm/renderers/webgpu/nodes/ShaderLib.js +0 -152
- package/src/extras/objects/ImmediateRenderObject.js +0 -31
|
@@ -32,7 +32,6 @@ class TDSLoader extends Loader {
|
|
|
32
32
|
this.debug = false;
|
|
33
33
|
|
|
34
34
|
this.group = null;
|
|
35
|
-
this.position = 0;
|
|
36
35
|
|
|
37
36
|
this.materials = [];
|
|
38
37
|
this.meshes = [];
|
|
@@ -97,7 +96,6 @@ class TDSLoader extends Loader {
|
|
|
97
96
|
parse( arraybuffer, path ) {
|
|
98
97
|
|
|
99
98
|
this.group = new Group();
|
|
100
|
-
this.position = 0;
|
|
101
99
|
this.materials = [];
|
|
102
100
|
this.meshes = [];
|
|
103
101
|
|
|
@@ -123,31 +121,30 @@ class TDSLoader extends Loader {
|
|
|
123
121
|
readFile( arraybuffer, path ) {
|
|
124
122
|
|
|
125
123
|
const data = new DataView( arraybuffer );
|
|
126
|
-
const chunk =
|
|
124
|
+
const chunk = new Chunk( data, 0, this.debugMessage );
|
|
127
125
|
|
|
128
126
|
if ( chunk.id === MLIBMAGIC || chunk.id === CMAGIC || chunk.id === M3DMAGIC ) {
|
|
129
127
|
|
|
130
|
-
let next =
|
|
128
|
+
let next = chunk.readChunk();
|
|
131
129
|
|
|
132
|
-
while ( next
|
|
130
|
+
while ( next ) {
|
|
133
131
|
|
|
134
|
-
if ( next === M3D_VERSION ) {
|
|
132
|
+
if ( next.id === M3D_VERSION ) {
|
|
135
133
|
|
|
136
|
-
const version =
|
|
134
|
+
const version = next.readDWord();
|
|
137
135
|
this.debugMessage( '3DS file version: ' + version );
|
|
138
136
|
|
|
139
|
-
} else if ( next === MDATA ) {
|
|
137
|
+
} else if ( next.id === MDATA ) {
|
|
140
138
|
|
|
141
|
-
this.
|
|
142
|
-
this.readMeshData( data, path );
|
|
139
|
+
this.readMeshData( next, path );
|
|
143
140
|
|
|
144
141
|
} else {
|
|
145
142
|
|
|
146
|
-
this.debugMessage( 'Unknown main chunk: ' + next.
|
|
143
|
+
this.debugMessage( 'Unknown main chunk: ' + next.hexId);
|
|
147
144
|
|
|
148
145
|
}
|
|
149
146
|
|
|
150
|
-
next =
|
|
147
|
+
next = chunk.readChunk();
|
|
151
148
|
|
|
152
149
|
}
|
|
153
150
|
|
|
@@ -161,46 +158,43 @@ class TDSLoader extends Loader {
|
|
|
161
158
|
* Read mesh data chunk.
|
|
162
159
|
*
|
|
163
160
|
* @method readMeshData
|
|
164
|
-
* @param {
|
|
161
|
+
* @param {Chunk} chunk to read mesh from
|
|
165
162
|
* @param {String} path Path for external resources.
|
|
166
163
|
*/
|
|
167
|
-
readMeshData(
|
|
164
|
+
readMeshData( chunk, path ) {
|
|
168
165
|
|
|
169
|
-
|
|
170
|
-
let next = this.nextChunk( data, chunk );
|
|
166
|
+
let next = chunk.readChunk();
|
|
171
167
|
|
|
172
|
-
while ( next
|
|
168
|
+
while ( next ) {
|
|
173
169
|
|
|
174
|
-
if ( next === MESH_VERSION ) {
|
|
170
|
+
if ( next.id === MESH_VERSION ) {
|
|
175
171
|
|
|
176
|
-
const version = +
|
|
172
|
+
const version = + next.readDWord();
|
|
177
173
|
this.debugMessage( 'Mesh Version: ' + version );
|
|
178
174
|
|
|
179
|
-
} else if ( next === MASTER_SCALE ) {
|
|
175
|
+
} else if ( next.id === MASTER_SCALE ) {
|
|
180
176
|
|
|
181
|
-
const scale =
|
|
177
|
+
const scale = next.readFloat();
|
|
182
178
|
this.debugMessage( 'Master scale: ' + scale );
|
|
183
179
|
this.group.scale.set( scale, scale, scale );
|
|
184
180
|
|
|
185
|
-
} else if ( next === NAMED_OBJECT ) {
|
|
181
|
+
} else if ( next.id === NAMED_OBJECT ) {
|
|
186
182
|
|
|
187
183
|
this.debugMessage( 'Named Object' );
|
|
188
|
-
this.
|
|
189
|
-
this.readNamedObject( data );
|
|
184
|
+
this.readNamedObject( next );
|
|
190
185
|
|
|
191
|
-
} else if ( next === MAT_ENTRY ) {
|
|
186
|
+
} else if ( next.id === MAT_ENTRY ) {
|
|
192
187
|
|
|
193
188
|
this.debugMessage( 'Material' );
|
|
194
|
-
this.
|
|
195
|
-
this.readMaterialEntry( data, path );
|
|
189
|
+
this.readMaterialEntry( next, path );
|
|
196
190
|
|
|
197
191
|
} else {
|
|
198
192
|
|
|
199
|
-
this.debugMessage( 'Unknown MDATA chunk: ' + next.
|
|
193
|
+
this.debugMessage( 'Unknown MDATA chunk: ' + next.hexId );
|
|
200
194
|
|
|
201
195
|
}
|
|
202
196
|
|
|
203
|
-
next =
|
|
197
|
+
next = chunk.readChunk();
|
|
204
198
|
|
|
205
199
|
}
|
|
206
200
|
|
|
@@ -210,143 +204,129 @@ class TDSLoader extends Loader {
|
|
|
210
204
|
* Read named object chunk.
|
|
211
205
|
*
|
|
212
206
|
* @method readNamedObject
|
|
213
|
-
* @param {
|
|
207
|
+
* @param {Chunk} chunk Chunk in use.
|
|
214
208
|
*/
|
|
215
|
-
readNamedObject(
|
|
209
|
+
readNamedObject( chunk ) {
|
|
216
210
|
|
|
217
|
-
const
|
|
218
|
-
const name = this.readString( data, 64 );
|
|
219
|
-
chunk.cur = this.position;
|
|
211
|
+
const name = chunk.readString();
|
|
220
212
|
|
|
221
|
-
let next =
|
|
222
|
-
while ( next
|
|
213
|
+
let next = chunk.readChunk();
|
|
214
|
+
while ( next ) {
|
|
223
215
|
|
|
224
|
-
if ( next === N_TRI_OBJECT ) {
|
|
216
|
+
if ( next.id === N_TRI_OBJECT ) {
|
|
225
217
|
|
|
226
|
-
this.
|
|
227
|
-
const mesh = this.readMesh( data );
|
|
218
|
+
const mesh = this.readMesh( next );
|
|
228
219
|
mesh.name = name;
|
|
229
220
|
this.meshes.push( mesh );
|
|
230
|
-
|
|
231
221
|
} else {
|
|
232
|
-
|
|
233
|
-
this.debugMessage( 'Unknown named object chunk: ' + next.toString( 16 ) );
|
|
222
|
+
this.debugMessage( 'Unknown named object chunk: ' + next.hexId );
|
|
234
223
|
|
|
235
224
|
}
|
|
236
225
|
|
|
237
|
-
next =
|
|
226
|
+
next = chunk.readChunk( );
|
|
238
227
|
|
|
239
228
|
}
|
|
240
229
|
|
|
241
|
-
this.endChunk( chunk );
|
|
242
|
-
|
|
243
230
|
}
|
|
244
231
|
|
|
245
232
|
/**
|
|
246
233
|
* Read material data chunk and add it to the material list.
|
|
247
234
|
*
|
|
248
235
|
* @method readMaterialEntry
|
|
249
|
-
* @param {
|
|
236
|
+
* @param {Chunk} chunk Chunk in use.
|
|
250
237
|
* @param {String} path Path for external resources.
|
|
251
238
|
*/
|
|
252
|
-
readMaterialEntry(
|
|
239
|
+
readMaterialEntry( chunk, path ) {
|
|
253
240
|
|
|
254
|
-
|
|
255
|
-
let
|
|
256
|
-
const material = new MeshPhongMaterial();
|
|
241
|
+
let next = chunk.readChunk();
|
|
242
|
+
let material = new MeshPhongMaterial();
|
|
257
243
|
|
|
258
|
-
while ( next
|
|
244
|
+
while ( next ) {
|
|
259
245
|
|
|
260
|
-
if ( next === MAT_NAME ) {
|
|
246
|
+
if ( next.id === MAT_NAME ) {
|
|
261
247
|
|
|
262
|
-
material.name =
|
|
248
|
+
material.name = next.readString();
|
|
263
249
|
this.debugMessage( ' Name: ' + material.name );
|
|
264
250
|
|
|
265
|
-
} else if ( next === MAT_WIRE ) {
|
|
251
|
+
} else if ( next.id === MAT_WIRE ) {
|
|
266
252
|
|
|
267
253
|
this.debugMessage( ' Wireframe' );
|
|
268
254
|
material.wireframe = true;
|
|
269
255
|
|
|
270
|
-
} else if ( next === MAT_WIRE_SIZE ) {
|
|
256
|
+
} else if ( next.id === MAT_WIRE_SIZE ) {
|
|
271
257
|
|
|
272
|
-
const value =
|
|
258
|
+
const value = next.readByte();
|
|
273
259
|
material.wireframeLinewidth = value;
|
|
274
260
|
this.debugMessage( ' Wireframe Thickness: ' + value );
|
|
275
261
|
|
|
276
|
-
} else if ( next === MAT_TWO_SIDE ) {
|
|
262
|
+
} else if ( next.id === MAT_TWO_SIDE ) {
|
|
277
263
|
|
|
278
264
|
material.side = DoubleSide;
|
|
279
265
|
this.debugMessage( ' DoubleSided' );
|
|
280
266
|
|
|
281
|
-
} else if ( next === MAT_ADDITIVE ) {
|
|
267
|
+
} else if ( next.id === MAT_ADDITIVE ) {
|
|
282
268
|
|
|
283
269
|
this.debugMessage( ' Additive Blending' );
|
|
284
270
|
material.blending = AdditiveBlending;
|
|
285
271
|
|
|
286
|
-
} else if ( next === MAT_DIFFUSE ) {
|
|
272
|
+
} else if ( next.id === MAT_DIFFUSE ) {
|
|
287
273
|
|
|
288
274
|
this.debugMessage( ' Diffuse Color' );
|
|
289
|
-
material.color = this.readColor(
|
|
275
|
+
material.color = this.readColor( next );
|
|
290
276
|
|
|
291
|
-
} else if ( next === MAT_SPECULAR ) {
|
|
277
|
+
} else if ( next.id === MAT_SPECULAR ) {
|
|
292
278
|
|
|
293
279
|
this.debugMessage( ' Specular Color' );
|
|
294
|
-
material.specular = this.readColor(
|
|
280
|
+
material.specular = this.readColor( next );
|
|
295
281
|
|
|
296
|
-
} else if ( next === MAT_AMBIENT ) {
|
|
282
|
+
} else if ( next.id === MAT_AMBIENT ) {
|
|
297
283
|
|
|
298
284
|
this.debugMessage( ' Ambient color' );
|
|
299
|
-
material.color = this.readColor(
|
|
285
|
+
material.color = this.readColor( next );
|
|
300
286
|
|
|
301
|
-
} else if ( next === MAT_SHININESS ) {
|
|
287
|
+
} else if ( next.id === MAT_SHININESS ) {
|
|
302
288
|
|
|
303
|
-
const shininess = this.readPercentage(
|
|
289
|
+
const shininess = this.readPercentage( next );
|
|
304
290
|
material.shininess = shininess * 100;
|
|
305
291
|
this.debugMessage( ' Shininess : ' + shininess );
|
|
306
292
|
|
|
307
|
-
} else if ( next === MAT_TRANSPARENCY ) {
|
|
293
|
+
} else if ( next.id === MAT_TRANSPARENCY ) {
|
|
308
294
|
|
|
309
|
-
const transparency = this.readPercentage(
|
|
295
|
+
const transparency = this.readPercentage( next );
|
|
310
296
|
material.opacity = 1 - transparency;
|
|
311
297
|
this.debugMessage( ' Transparency : ' + transparency );
|
|
312
298
|
material.transparent = material.opacity < 1 ? true : false;
|
|
313
299
|
|
|
314
|
-
} else if ( next === MAT_TEXMAP ) {
|
|
300
|
+
} else if ( next.id === MAT_TEXMAP ) {
|
|
315
301
|
|
|
316
302
|
this.debugMessage( ' ColorMap' );
|
|
317
|
-
this.
|
|
318
|
-
material.map = this.readMap( data, path );
|
|
303
|
+
material.map = this.readMap( next, path );
|
|
319
304
|
|
|
320
|
-
} else if ( next === MAT_BUMPMAP ) {
|
|
305
|
+
} else if ( next.id === MAT_BUMPMAP ) {
|
|
321
306
|
|
|
322
307
|
this.debugMessage( ' BumpMap' );
|
|
323
|
-
this.
|
|
324
|
-
material.bumpMap = this.readMap( data, path );
|
|
308
|
+
material.bumpMap = this.readMap( next, path );
|
|
325
309
|
|
|
326
|
-
} else if ( next === MAT_OPACMAP ) {
|
|
310
|
+
} else if ( next.id === MAT_OPACMAP ) {
|
|
327
311
|
|
|
328
312
|
this.debugMessage( ' OpacityMap' );
|
|
329
|
-
this.
|
|
330
|
-
material.alphaMap = this.readMap( data, path );
|
|
313
|
+
material.alphaMap = this.readMap( next, path );
|
|
331
314
|
|
|
332
|
-
} else if ( next === MAT_SPECMAP ) {
|
|
315
|
+
} else if ( next.id === MAT_SPECMAP ) {
|
|
333
316
|
|
|
334
317
|
this.debugMessage( ' SpecularMap' );
|
|
335
|
-
this.
|
|
336
|
-
material.specularMap = this.readMap( data, path );
|
|
318
|
+
material.specularMap = this.readMap( next, path );
|
|
337
319
|
|
|
338
320
|
} else {
|
|
339
321
|
|
|
340
|
-
this.debugMessage( ' Unknown material chunk: ' + next.
|
|
322
|
+
this.debugMessage( ' Unknown material chunk: ' + next.hexId );
|
|
341
323
|
|
|
342
324
|
}
|
|
343
325
|
|
|
344
|
-
next =
|
|
326
|
+
next = chunk.readChunk();
|
|
345
327
|
|
|
346
328
|
}
|
|
347
329
|
|
|
348
|
-
this.endChunk( chunk );
|
|
349
|
-
|
|
350
330
|
this.materials[ material.name ] = material;
|
|
351
331
|
|
|
352
332
|
}
|
|
@@ -355,13 +335,12 @@ class TDSLoader extends Loader {
|
|
|
355
335
|
* Read mesh data chunk.
|
|
356
336
|
*
|
|
357
337
|
* @method readMesh
|
|
358
|
-
* @param {
|
|
338
|
+
* @param {Chunk} chunk Chunk in use.
|
|
359
339
|
* @return {Mesh} The parsed mesh.
|
|
360
340
|
*/
|
|
361
|
-
readMesh(
|
|
341
|
+
readMesh( chunk ) {
|
|
362
342
|
|
|
363
|
-
|
|
364
|
-
let next = this.nextChunk( data, chunk );
|
|
343
|
+
let next = chunk.readChunk( );
|
|
365
344
|
|
|
366
345
|
const geometry = new BufferGeometry();
|
|
367
346
|
|
|
@@ -369,11 +348,11 @@ class TDSLoader extends Loader {
|
|
|
369
348
|
const mesh = new Mesh( geometry, material );
|
|
370
349
|
mesh.name = 'mesh';
|
|
371
350
|
|
|
372
|
-
while ( next
|
|
351
|
+
while ( next ) {
|
|
373
352
|
|
|
374
|
-
if ( next === POINT_ARRAY ) {
|
|
353
|
+
if ( next.id === POINT_ARRAY ) {
|
|
375
354
|
|
|
376
|
-
const points =
|
|
355
|
+
const points = next.readWord( );
|
|
377
356
|
|
|
378
357
|
this.debugMessage( ' Vertex: ' + points );
|
|
379
358
|
|
|
@@ -383,22 +362,21 @@ class TDSLoader extends Loader {
|
|
|
383
362
|
|
|
384
363
|
for ( let i = 0; i < points; i ++ ) {
|
|
385
364
|
|
|
386
|
-
vertices.push(
|
|
387
|
-
vertices.push(
|
|
388
|
-
vertices.push(
|
|
365
|
+
vertices.push( next.readFloat( ) );
|
|
366
|
+
vertices.push( next.readFloat( ) );
|
|
367
|
+
vertices.push( next.readFloat( ) );
|
|
389
368
|
|
|
390
369
|
}
|
|
391
370
|
|
|
392
371
|
geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
|
|
393
372
|
|
|
394
|
-
} else if ( next === FACE_ARRAY ) {
|
|
373
|
+
} else if ( next.id === FACE_ARRAY ) {
|
|
395
374
|
|
|
396
|
-
this.
|
|
397
|
-
this.readFaceArray( data, mesh );
|
|
375
|
+
this.readFaceArray( next, mesh );
|
|
398
376
|
|
|
399
|
-
} else if ( next === TEX_VERTS ) {
|
|
377
|
+
} else if ( next.id === TEX_VERTS ) {
|
|
400
378
|
|
|
401
|
-
const texels =
|
|
379
|
+
const texels = next.readWord( );
|
|
402
380
|
|
|
403
381
|
this.debugMessage( ' UV: ' + texels );
|
|
404
382
|
|
|
@@ -406,24 +384,24 @@ class TDSLoader extends Loader {
|
|
|
406
384
|
|
|
407
385
|
const uvs = [];
|
|
408
386
|
|
|
409
|
-
for ( let i = 0; i < texels; i ++ )
|
|
387
|
+
for ( let i = 0; i < texels; i ++ ) {
|
|
410
388
|
|
|
411
|
-
uvs.push(
|
|
412
|
-
uvs.push(
|
|
389
|
+
uvs.push( next.readFloat( ) );
|
|
390
|
+
uvs.push( next.readFloat( ) );
|
|
413
391
|
|
|
414
392
|
}
|
|
415
393
|
|
|
416
394
|
geometry.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
|
|
417
395
|
|
|
418
396
|
|
|
419
|
-
} else if ( next === MESH_MATRIX ) {
|
|
397
|
+
} else if ( next.id === MESH_MATRIX ) {
|
|
420
398
|
|
|
421
399
|
this.debugMessage( ' Tranformation Matrix (TODO)' );
|
|
422
400
|
|
|
423
401
|
const values = [];
|
|
424
402
|
for ( let i = 0; i < 12; i ++ ) {
|
|
425
403
|
|
|
426
|
-
values[ i ] =
|
|
404
|
+
values[ i ] = next.readFloat( );
|
|
427
405
|
|
|
428
406
|
}
|
|
429
407
|
|
|
@@ -463,16 +441,14 @@ class TDSLoader extends Loader {
|
|
|
463
441
|
|
|
464
442
|
} else {
|
|
465
443
|
|
|
466
|
-
this.debugMessage( ' Unknown mesh chunk: ' + next.
|
|
444
|
+
this.debugMessage( ' Unknown mesh chunk: ' + next.hexId );
|
|
467
445
|
|
|
468
446
|
}
|
|
469
447
|
|
|
470
|
-
next =
|
|
448
|
+
next = chunk.readChunk( );
|
|
471
449
|
|
|
472
450
|
}
|
|
473
451
|
|
|
474
|
-
this.endChunk( chunk );
|
|
475
|
-
|
|
476
452
|
geometry.computeVertexNormals();
|
|
477
453
|
|
|
478
454
|
return mesh;
|
|
@@ -483,13 +459,12 @@ class TDSLoader extends Loader {
|
|
|
483
459
|
* Read face array data chunk.
|
|
484
460
|
*
|
|
485
461
|
* @method readFaceArray
|
|
486
|
-
* @param {
|
|
462
|
+
* @param {Chunk} chunk Chunk in use.
|
|
487
463
|
* @param {Mesh} mesh Mesh to be filled with the data read.
|
|
488
464
|
*/
|
|
489
|
-
readFaceArray(
|
|
465
|
+
readFaceArray( chunk, mesh ) {
|
|
490
466
|
|
|
491
|
-
const
|
|
492
|
-
const faces = this.readWord( data );
|
|
467
|
+
const faces = chunk.readWord( );
|
|
493
468
|
|
|
494
469
|
this.debugMessage( ' Faces: ' + faces );
|
|
495
470
|
|
|
@@ -497,9 +472,9 @@ class TDSLoader extends Loader {
|
|
|
497
472
|
|
|
498
473
|
for ( let i = 0; i < faces; ++ i ) {
|
|
499
474
|
|
|
500
|
-
index.push(
|
|
475
|
+
index.push( chunk.readWord( ), chunk.readWord( ), chunk.readWord( ) );
|
|
501
476
|
|
|
502
|
-
|
|
477
|
+
chunk.readWord( ); // visibility
|
|
503
478
|
|
|
504
479
|
}
|
|
505
480
|
|
|
@@ -510,17 +485,15 @@ class TDSLoader extends Loader {
|
|
|
510
485
|
let materialIndex = 0;
|
|
511
486
|
let start = 0;
|
|
512
487
|
|
|
513
|
-
while (
|
|
488
|
+
while ( !chunk.endOfChunk ) {
|
|
514
489
|
|
|
515
|
-
const subchunk =
|
|
490
|
+
const subchunk = chunk.readChunk( );
|
|
516
491
|
|
|
517
492
|
if ( subchunk.id === MSH_MAT_GROUP ) {
|
|
518
493
|
|
|
519
494
|
this.debugMessage( ' Material Group' );
|
|
520
495
|
|
|
521
|
-
this.
|
|
522
|
-
|
|
523
|
-
const group = this.readMaterialGroup( data );
|
|
496
|
+
const group = this.readMaterialGroup( subchunk );
|
|
524
497
|
const count = group.index.length * 3; // assuming successive indices
|
|
525
498
|
|
|
526
499
|
mesh.geometry.addGroup( start, count, materialIndex );
|
|
@@ -540,78 +513,71 @@ class TDSLoader extends Loader {
|
|
|
540
513
|
|
|
541
514
|
} else {
|
|
542
515
|
|
|
543
|
-
this.debugMessage( ' Unknown face array chunk: ' + subchunk.
|
|
516
|
+
this.debugMessage( ' Unknown face array chunk: ' + subchunk.hexId );
|
|
544
517
|
|
|
545
518
|
}
|
|
546
519
|
|
|
547
|
-
this.endChunk( subchunk );
|
|
548
|
-
|
|
549
520
|
}
|
|
550
521
|
|
|
551
522
|
if ( mesh.material.length === 1 ) mesh.material = mesh.material[ 0 ]; // for backwards compatibility
|
|
552
523
|
|
|
553
|
-
this.endChunk( chunk );
|
|
554
|
-
|
|
555
524
|
}
|
|
556
525
|
|
|
557
526
|
/**
|
|
558
527
|
* Read texture map data chunk.
|
|
559
528
|
*
|
|
560
529
|
* @method readMap
|
|
561
|
-
* @param {
|
|
530
|
+
* @param {Chunk} chunk Chunk in use.
|
|
562
531
|
* @param {String} path Path for external resources.
|
|
563
532
|
* @return {Texture} Texture read from this data chunk.
|
|
564
533
|
*/
|
|
565
|
-
readMap(
|
|
534
|
+
readMap( chunk, path ) {
|
|
566
535
|
|
|
567
|
-
|
|
568
|
-
let next = this.nextChunk( data, chunk );
|
|
536
|
+
let next = chunk.readChunk( );
|
|
569
537
|
let texture = {};
|
|
570
538
|
|
|
571
539
|
const loader = new TextureLoader( this.manager );
|
|
572
540
|
loader.setPath( this.resourcePath || path ).setCrossOrigin( this.crossOrigin );
|
|
573
541
|
|
|
574
|
-
while ( next
|
|
542
|
+
while ( next ) {
|
|
575
543
|
|
|
576
|
-
if ( next === MAT_MAPNAME ) {
|
|
544
|
+
if ( next.id === MAT_MAPNAME ) {
|
|
577
545
|
|
|
578
|
-
const name =
|
|
546
|
+
const name = next.readString();
|
|
579
547
|
texture = loader.load( name );
|
|
580
548
|
|
|
581
549
|
this.debugMessage( ' File: ' + path + name );
|
|
582
550
|
|
|
583
|
-
} else if ( next === MAT_MAP_UOFFSET ) {
|
|
551
|
+
} else if ( next.id === MAT_MAP_UOFFSET ) {
|
|
584
552
|
|
|
585
|
-
texture.offset.x =
|
|
553
|
+
texture.offset.x = next.readFloat( );
|
|
586
554
|
this.debugMessage( ' OffsetX: ' + texture.offset.x );
|
|
587
555
|
|
|
588
|
-
} else if ( next === MAT_MAP_VOFFSET ) {
|
|
556
|
+
} else if ( next.id === MAT_MAP_VOFFSET ) {
|
|
589
557
|
|
|
590
|
-
texture.offset.y =
|
|
558
|
+
texture.offset.y = next.readFloat( );
|
|
591
559
|
this.debugMessage( ' OffsetY: ' + texture.offset.y );
|
|
592
560
|
|
|
593
|
-
} else if ( next === MAT_MAP_USCALE ) {
|
|
561
|
+
} else if ( next.id === MAT_MAP_USCALE ) {
|
|
594
562
|
|
|
595
|
-
texture.repeat.x =
|
|
563
|
+
texture.repeat.x = next.readFloat( );
|
|
596
564
|
this.debugMessage( ' RepeatX: ' + texture.repeat.x );
|
|
597
565
|
|
|
598
|
-
} else if ( next === MAT_MAP_VSCALE ) {
|
|
566
|
+
} else if ( next.id === MAT_MAP_VSCALE ) {
|
|
599
567
|
|
|
600
|
-
texture.repeat.y =
|
|
568
|
+
texture.repeat.y = next.readFloat( );
|
|
601
569
|
this.debugMessage( ' RepeatY: ' + texture.repeat.y );
|
|
602
570
|
|
|
603
571
|
} else {
|
|
604
572
|
|
|
605
|
-
this.debugMessage( ' Unknown map chunk: ' + next.
|
|
573
|
+
this.debugMessage( ' Unknown map chunk: ' + next.hexId );
|
|
606
574
|
|
|
607
575
|
}
|
|
608
576
|
|
|
609
|
-
next =
|
|
577
|
+
next = chunk.readChunk( );
|
|
610
578
|
|
|
611
579
|
}
|
|
612
580
|
|
|
613
|
-
this.endChunk( chunk );
|
|
614
|
-
|
|
615
581
|
return texture;
|
|
616
582
|
|
|
617
583
|
}
|
|
@@ -620,14 +586,13 @@ class TDSLoader extends Loader {
|
|
|
620
586
|
* Read material group data chunk.
|
|
621
587
|
*
|
|
622
588
|
* @method readMaterialGroup
|
|
623
|
-
* @param {
|
|
589
|
+
* @param {Chunk} chunk Chunk in use.
|
|
624
590
|
* @return {Object} Object with name and index of the object.
|
|
625
591
|
*/
|
|
626
|
-
readMaterialGroup(
|
|
592
|
+
readMaterialGroup( chunk ) {
|
|
627
593
|
|
|
628
|
-
|
|
629
|
-
const
|
|
630
|
-
const numFaces = this.readWord( data );
|
|
594
|
+
const name = chunk.readString();
|
|
595
|
+
const numFaces = chunk.readWord();
|
|
631
596
|
|
|
632
597
|
this.debugMessage( ' Name: ' + name );
|
|
633
598
|
this.debugMessage( ' Faces: ' + numFaces );
|
|
@@ -635,7 +600,7 @@ class TDSLoader extends Loader {
|
|
|
635
600
|
const index = [];
|
|
636
601
|
for ( let i = 0; i < numFaces; ++ i ) {
|
|
637
602
|
|
|
638
|
-
index.push(
|
|
603
|
+
index.push( chunk.readWord( ) );
|
|
639
604
|
|
|
640
605
|
}
|
|
641
606
|
|
|
@@ -647,29 +612,29 @@ class TDSLoader extends Loader {
|
|
|
647
612
|
* Read a color value.
|
|
648
613
|
*
|
|
649
614
|
* @method readColor
|
|
650
|
-
* @param {
|
|
615
|
+
* @param {Chunk} chunk Chunk.
|
|
651
616
|
* @return {Color} Color value read..
|
|
652
617
|
*/
|
|
653
|
-
readColor(
|
|
618
|
+
readColor( chunk ) {
|
|
654
619
|
|
|
655
|
-
const
|
|
620
|
+
const subChunk = chunk.readChunk( );
|
|
656
621
|
const color = new Color();
|
|
657
622
|
|
|
658
|
-
if (
|
|
623
|
+
if ( subChunk.id === COLOR_24 || subChunk.id === LIN_COLOR_24 ) {
|
|
659
624
|
|
|
660
|
-
const r =
|
|
661
|
-
const g =
|
|
662
|
-
const b =
|
|
625
|
+
const r = subChunk.readByte( );
|
|
626
|
+
const g = subChunk.readByte( );
|
|
627
|
+
const b = subChunk.readByte( );
|
|
663
628
|
|
|
664
629
|
color.setRGB( r / 255, g / 255, b / 255 );
|
|
665
630
|
|
|
666
631
|
this.debugMessage( ' Color: ' + color.r + ', ' + color.g + ', ' + color.b );
|
|
667
632
|
|
|
668
|
-
} else if (
|
|
633
|
+
} else if ( subChunk.id === COLOR_F || subChunk.id === LIN_COLOR_F ) {
|
|
669
634
|
|
|
670
|
-
const r =
|
|
671
|
-
const g =
|
|
672
|
-
const b =
|
|
635
|
+
const r = subChunk.readFloat( );
|
|
636
|
+
const g = subChunk.readFloat( );
|
|
637
|
+
const b = subChunk.readFloat( );
|
|
673
638
|
|
|
674
639
|
color.setRGB( r, g, b );
|
|
675
640
|
|
|
@@ -677,101 +642,142 @@ class TDSLoader extends Loader {
|
|
|
677
642
|
|
|
678
643
|
} else {
|
|
679
644
|
|
|
680
|
-
this.debugMessage( ' Unknown color chunk: ' +
|
|
645
|
+
this.debugMessage( ' Unknown color chunk: ' + subChunk.hexId );
|
|
681
646
|
|
|
682
647
|
}
|
|
683
648
|
|
|
684
|
-
this.endChunk( chunk );
|
|
685
649
|
return color;
|
|
686
650
|
|
|
687
651
|
}
|
|
688
652
|
|
|
689
653
|
/**
|
|
690
|
-
* Read
|
|
654
|
+
* Read percentage value.
|
|
691
655
|
*
|
|
692
|
-
* @method
|
|
693
|
-
* @param {
|
|
694
|
-
* @return {
|
|
656
|
+
* @method readPercentage
|
|
657
|
+
* @param {Chunk} chunk Chunk to read data from.
|
|
658
|
+
* @return {Number} Data read from the dataview.
|
|
695
659
|
*/
|
|
696
|
-
|
|
660
|
+
readPercentage( chunk ) {
|
|
697
661
|
|
|
698
|
-
const
|
|
662
|
+
const subChunk = chunk.readChunk( );
|
|
699
663
|
|
|
700
|
-
|
|
701
|
-
chunk.id = this.readWord( data );
|
|
702
|
-
chunk.size = this.readDWord( data );
|
|
703
|
-
chunk.end = chunk.cur + chunk.size;
|
|
704
|
-
chunk.cur += 6;
|
|
664
|
+
switch ( subChunk.id ) {
|
|
705
665
|
|
|
706
|
-
|
|
666
|
+
case INT_PERCENTAGE:
|
|
667
|
+
return ( subChunk.readShort( ) / 100 );
|
|
668
|
+
break;
|
|
669
|
+
|
|
670
|
+
case FLOAT_PERCENTAGE:
|
|
671
|
+
return subChunk.readFloat( );
|
|
672
|
+
break;
|
|
673
|
+
|
|
674
|
+
default:
|
|
675
|
+
this.debugMessage( ' Unknown percentage chunk: ' + subChunk.hexId );
|
|
676
|
+
return 0;
|
|
677
|
+
|
|
678
|
+
}
|
|
707
679
|
|
|
708
680
|
}
|
|
709
681
|
|
|
710
682
|
/**
|
|
711
|
-
*
|
|
683
|
+
* Print debug message to the console.
|
|
684
|
+
*
|
|
685
|
+
* Is controlled by a flag to show or hide debug messages.
|
|
712
686
|
*
|
|
713
|
-
* @method
|
|
714
|
-
* @param {Object}
|
|
687
|
+
* @method debugMessage
|
|
688
|
+
* @param {Object} message Debug message to print to the console.
|
|
715
689
|
*/
|
|
716
|
-
|
|
690
|
+
debugMessage( message ) {
|
|
717
691
|
|
|
718
|
-
this.
|
|
692
|
+
if ( this.debug ) {
|
|
693
|
+
|
|
694
|
+
console.log( message );
|
|
695
|
+
|
|
696
|
+
}
|
|
719
697
|
|
|
720
698
|
}
|
|
699
|
+
}
|
|
700
|
+
|
|
721
701
|
|
|
702
|
+
/** Read data/sub-chunks from chunk */
|
|
703
|
+
class Chunk {
|
|
722
704
|
/**
|
|
723
|
-
*
|
|
705
|
+
* Create a new chunk
|
|
724
706
|
*
|
|
725
|
-
* @
|
|
726
|
-
* @param {DataView} data
|
|
727
|
-
* @param {
|
|
707
|
+
* @class Chunk
|
|
708
|
+
* @param {DataView} data DataView to read from.
|
|
709
|
+
* @param {Number} position in data.
|
|
710
|
+
* @param {Function} debugMessage logging callback.
|
|
728
711
|
*/
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
712
|
+
constructor(data, position, debugMessage) {
|
|
713
|
+
this.data = data;
|
|
714
|
+
// the offset to the begin of this chunk
|
|
715
|
+
this.offset = position;
|
|
716
|
+
// the current reading position
|
|
717
|
+
this.position = position;
|
|
718
|
+
this.debugMessage = debugMessage;
|
|
719
|
+
|
|
720
|
+
if (this.debugMessage instanceof Function) {
|
|
721
|
+
this.debugMessage = function() {};
|
|
722
|
+
}
|
|
732
723
|
|
|
733
|
-
|
|
724
|
+
this.id = this.readWord();
|
|
725
|
+
this.size = this.readDWord();
|
|
726
|
+
this.end = this.offset + this.size;
|
|
734
727
|
|
|
728
|
+
if (this.end > data.byteLength) {
|
|
729
|
+
this.debugMessage( 'Bad chunk size for chunk at ' + position );
|
|
735
730
|
}
|
|
731
|
+
}
|
|
736
732
|
|
|
737
|
-
|
|
733
|
+
/**
|
|
734
|
+
* read a sub cchunk.
|
|
735
|
+
*
|
|
736
|
+
* @method readChunk
|
|
737
|
+
* @return {Chunk | null} next sub chunk
|
|
738
|
+
*/
|
|
739
|
+
readChunk () {
|
|
738
740
|
|
|
739
|
-
|
|
741
|
+
if ( this.endOfChunk ) {
|
|
742
|
+
return null;
|
|
743
|
+
}
|
|
740
744
|
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
745
|
+
try {
|
|
746
|
+
let next = new Chunk( this.data, this.position, this.debugMessage );
|
|
747
|
+
this.position += next.size;
|
|
748
|
+
return next;
|
|
744
749
|
|
|
745
750
|
} catch ( e ) {
|
|
746
|
-
|
|
747
751
|
this.debugMessage( 'Unable to read chunk at ' + this.position );
|
|
748
|
-
return
|
|
752
|
+
return null;
|
|
749
753
|
|
|
750
754
|
}
|
|
751
755
|
|
|
752
756
|
}
|
|
753
757
|
|
|
754
758
|
/**
|
|
755
|
-
*
|
|
759
|
+
* return the ID of this chunk as Hex
|
|
756
760
|
*
|
|
757
|
-
* @method
|
|
761
|
+
* @method idToString
|
|
762
|
+
* @return {String} hex-string of id
|
|
758
763
|
*/
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
764
|
+
get hexId() {
|
|
765
|
+
return this.id.toString( 16 );
|
|
766
|
+
}
|
|
762
767
|
|
|
768
|
+
get endOfChunk() {
|
|
769
|
+
return this.position >= this.end;
|
|
763
770
|
}
|
|
764
771
|
|
|
765
772
|
/**
|
|
766
773
|
* Read byte value.
|
|
767
774
|
*
|
|
768
775
|
* @method readByte
|
|
769
|
-
* @param {DataView} data Dataview to read data from.
|
|
770
776
|
* @return {Number} Data read from the dataview.
|
|
771
777
|
*/
|
|
772
|
-
readByte(
|
|
778
|
+
readByte() {
|
|
773
779
|
|
|
774
|
-
const v = data.getUint8( this.position, true );
|
|
780
|
+
const v = this.data.getUint8( this.position, true );
|
|
775
781
|
this.position += 1;
|
|
776
782
|
return v;
|
|
777
783
|
|
|
@@ -781,20 +787,20 @@ class TDSLoader extends Loader {
|
|
|
781
787
|
* Read 32 bit float value.
|
|
782
788
|
*
|
|
783
789
|
* @method readFloat
|
|
784
|
-
* @param {DataView} data Dataview to read data from.
|
|
785
790
|
* @return {Number} Data read from the dataview.
|
|
786
791
|
*/
|
|
787
|
-
readFloat(
|
|
792
|
+
readFloat() {
|
|
788
793
|
|
|
789
794
|
try {
|
|
790
795
|
|
|
791
|
-
const v = data.getFloat32( this.position, true );
|
|
796
|
+
const v = this.data.getFloat32( this.position, true );
|
|
792
797
|
this.position += 4;
|
|
793
798
|
return v;
|
|
794
799
|
|
|
795
800
|
} catch ( e ) {
|
|
796
801
|
|
|
797
|
-
this.debugMessage( e + ' ' + this.position + ' ' + data.byteLength );
|
|
802
|
+
this.debugMessage( e + ' ' + this.position + ' ' + this.data.byteLength );
|
|
803
|
+
return 0;
|
|
798
804
|
|
|
799
805
|
}
|
|
800
806
|
|
|
@@ -804,12 +810,11 @@ class TDSLoader extends Loader {
|
|
|
804
810
|
* Read 32 bit signed integer value.
|
|
805
811
|
*
|
|
806
812
|
* @method readInt
|
|
807
|
-
* @param {DataView} data Dataview to read data from.
|
|
808
813
|
* @return {Number} Data read from the dataview.
|
|
809
814
|
*/
|
|
810
|
-
readInt(
|
|
815
|
+
readInt() {
|
|
811
816
|
|
|
812
|
-
const v = data.getInt32( this.position, true );
|
|
817
|
+
const v = this.data.getInt32( this.position, true );
|
|
813
818
|
this.position += 4;
|
|
814
819
|
return v;
|
|
815
820
|
|
|
@@ -819,12 +824,11 @@ class TDSLoader extends Loader {
|
|
|
819
824
|
* Read 16 bit signed integer value.
|
|
820
825
|
*
|
|
821
826
|
* @method readShort
|
|
822
|
-
* @param {DataView} data Dataview to read data from.
|
|
823
827
|
* @return {Number} Data read from the dataview.
|
|
824
828
|
*/
|
|
825
|
-
readShort(
|
|
829
|
+
readShort() {
|
|
826
830
|
|
|
827
|
-
const v = data.getInt16( this.position, true );
|
|
831
|
+
const v = this.data.getInt16( this.position, true );
|
|
828
832
|
this.position += 2;
|
|
829
833
|
return v;
|
|
830
834
|
|
|
@@ -834,12 +838,11 @@ class TDSLoader extends Loader {
|
|
|
834
838
|
* Read 64 bit unsigned integer value.
|
|
835
839
|
*
|
|
836
840
|
* @method readDWord
|
|
837
|
-
* @param {DataView} data Dataview to read data from.
|
|
838
841
|
* @return {Number} Data read from the dataview.
|
|
839
842
|
*/
|
|
840
|
-
readDWord(
|
|
843
|
+
readDWord() {
|
|
841
844
|
|
|
842
|
-
const v = data.getUint32( this.position, true );
|
|
845
|
+
const v = this.data.getUint32( this.position, true );
|
|
843
846
|
this.position += 4;
|
|
844
847
|
return v;
|
|
845
848
|
|
|
@@ -849,95 +852,32 @@ class TDSLoader extends Loader {
|
|
|
849
852
|
* Read 32 bit unsigned integer value.
|
|
850
853
|
*
|
|
851
854
|
* @method readWord
|
|
852
|
-
* @param {DataView} data Dataview to read data from.
|
|
853
855
|
* @return {Number} Data read from the dataview.
|
|
854
856
|
*/
|
|
855
|
-
readWord(
|
|
857
|
+
readWord() {
|
|
856
858
|
|
|
857
|
-
const v = data.getUint16( this.position, true );
|
|
859
|
+
const v = this.data.getUint16( this.position, true );
|
|
858
860
|
this.position += 2;
|
|
859
861
|
return v;
|
|
860
862
|
|
|
861
863
|
}
|
|
862
864
|
|
|
863
865
|
/**
|
|
864
|
-
* Read string value.
|
|
866
|
+
* Read NULL terminated ASCII string value from chunk-pos.
|
|
865
867
|
*
|
|
866
868
|
* @method readString
|
|
867
|
-
* @param {DataView} data Dataview to read data from.
|
|
868
|
-
* @param {Number} maxLength Max size of the string to be read.
|
|
869
869
|
* @return {String} Data read from the dataview.
|
|
870
870
|
*/
|
|
871
|
-
readString(
|
|
871
|
+
readString() {
|
|
872
872
|
|
|
873
873
|
let s = '';
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
const c = this.readByte( data );
|
|
878
|
-
if ( ! c ) {
|
|
879
|
-
|
|
880
|
-
break;
|
|
881
|
-
|
|
882
|
-
}
|
|
883
|
-
|
|
874
|
+
let c = this.readByte();
|
|
875
|
+
while ( c ) {
|
|
884
876
|
s += String.fromCharCode( c );
|
|
885
|
-
|
|
877
|
+
c = this.readByte();
|
|
886
878
|
}
|
|
887
879
|
|
|
888
880
|
return s;
|
|
889
|
-
|
|
890
|
-
}
|
|
891
|
-
|
|
892
|
-
/**
|
|
893
|
-
* Read percentage value.
|
|
894
|
-
*
|
|
895
|
-
* @method readPercentage
|
|
896
|
-
* @param {DataView} data Dataview to read data from.
|
|
897
|
-
* @return {Number} Data read from the dataview.
|
|
898
|
-
*/
|
|
899
|
-
readPercentage( data ) {
|
|
900
|
-
|
|
901
|
-
const chunk = this.readChunk( data );
|
|
902
|
-
let value;
|
|
903
|
-
|
|
904
|
-
switch ( chunk.id ) {
|
|
905
|
-
|
|
906
|
-
case INT_PERCENTAGE:
|
|
907
|
-
value = ( this.readShort( data ) / 100 );
|
|
908
|
-
break;
|
|
909
|
-
|
|
910
|
-
case FLOAT_PERCENTAGE:
|
|
911
|
-
value = this.readFloat( data );
|
|
912
|
-
break;
|
|
913
|
-
|
|
914
|
-
default:
|
|
915
|
-
this.debugMessage( ' Unknown percentage chunk: ' + chunk.toString( 16 ) );
|
|
916
|
-
|
|
917
|
-
}
|
|
918
|
-
|
|
919
|
-
this.endChunk( chunk );
|
|
920
|
-
|
|
921
|
-
return value;
|
|
922
|
-
|
|
923
|
-
}
|
|
924
|
-
|
|
925
|
-
/**
|
|
926
|
-
* Print debug message to the console.
|
|
927
|
-
*
|
|
928
|
-
* Is controlled by a flag to show or hide debug messages.
|
|
929
|
-
*
|
|
930
|
-
* @method debugMessage
|
|
931
|
-
* @param {Object} message Debug message to print to the console.
|
|
932
|
-
*/
|
|
933
|
-
debugMessage( message ) {
|
|
934
|
-
|
|
935
|
-
if ( this.debug ) {
|
|
936
|
-
|
|
937
|
-
console.log( message );
|
|
938
|
-
|
|
939
|
-
}
|
|
940
|
-
|
|
941
881
|
}
|
|
942
882
|
|
|
943
883
|
}
|