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.
Files changed (246) hide show
  1. package/build/three.js +619 -538
  2. package/build/three.min.js +1 -1
  3. package/build/three.module.js +763 -616
  4. package/examples/fonts/open-sans/open-sans-v15-cyrillic-ext_greek_greek-ext_cyrillic_latin_latin-ext_vietnamese-regular.woff +0 -0
  5. package/examples/fonts/open-sans/open-sans-v15-cyrillic-ext_greek_greek-ext_cyrillic_latin_latin-ext_vietnamese-regular.woff2 +0 -0
  6. package/examples/fonts/open-sans/open-sans.css +9 -0
  7. package/examples/fonts/tabler-icons/fonts/tabler-icons.eot +0 -0
  8. package/examples/fonts/tabler-icons/fonts/tabler-icons.ttf +0 -0
  9. package/examples/fonts/tabler-icons/fonts/tabler-icons.woff +0 -0
  10. package/examples/fonts/tabler-icons/fonts/tabler-icons.woff2 +0 -0
  11. package/examples/fonts/tabler-icons/tabler-icons.min.css +4 -0
  12. package/examples/js/controls/ArcballControls.js +68 -27
  13. package/examples/js/controls/DragControls.js +7 -0
  14. package/examples/js/controls/OrbitControls.js +5 -36
  15. package/examples/js/controls/TrackballControls.js +3 -2
  16. package/examples/js/csm/CSM.js +2 -2
  17. package/examples/js/csm/CSMFrustum.js +133 -0
  18. package/examples/js/exporters/GLTFExporter.js +147 -63
  19. package/examples/js/exporters/USDZExporter.js +45 -26
  20. package/examples/js/lines/LineMaterial.js +58 -20
  21. package/examples/js/lines/LineSegments2.js +29 -24
  22. package/examples/js/loaders/3DMLoader.js +24 -11
  23. package/examples/js/loaders/3MFLoader.js +2 -2
  24. package/examples/js/loaders/ColladaLoader.js +61 -3
  25. package/examples/js/loaders/FBXLoader.js +1 -1
  26. package/examples/js/loaders/GLTFLoader.js +94 -31
  27. package/examples/js/loaders/KTX2Loader.js +12 -0
  28. package/examples/js/loaders/LWOLoader.js +8 -6
  29. package/examples/js/loaders/LogLuvLoader.js +766 -0
  30. package/examples/js/loaders/PLYLoader.js +32 -7
  31. package/examples/js/loaders/RGBELoader.js +2 -1
  32. package/examples/js/loaders/SVGLoader.js +7 -3
  33. package/examples/js/loaders/TDSLoader.js +237 -271
  34. package/examples/js/loaders/lwo/LWO2Parser.js +1 -0
  35. package/examples/js/loaders/lwo/LWO3Parser.js +4 -2
  36. package/examples/js/objects/MarchingCubes.js +42 -128
  37. package/examples/js/renderers/CSS2DRenderer.js +4 -4
  38. package/examples/js/renderers/CSS3DRenderer.js +4 -4
  39. package/examples/js/utils/RoughnessMipmapper.js +1 -0
  40. package/examples/jsm/controls/ArcballControls.js +61 -29
  41. package/examples/jsm/controls/DragControls.js +7 -0
  42. package/examples/jsm/controls/OrbitControls.js +9 -51
  43. package/examples/jsm/controls/TrackballControls.js +1 -1
  44. package/examples/jsm/csm/CSM.js +3 -3
  45. package/examples/jsm/csm/{Frustum.js → CSMFrustum.js} +3 -3
  46. package/examples/jsm/exporters/GLTFExporter.js +160 -74
  47. package/examples/jsm/exporters/USDZExporter.js +47 -26
  48. package/examples/jsm/libs/flow.module.js +3218 -0
  49. package/examples/jsm/libs/lil-gui.module.min.js +8 -0
  50. package/examples/jsm/libs/rhino3dm/rhino3dm.wasm +0 -0
  51. package/examples/jsm/lines/LineMaterial.js +59 -23
  52. package/examples/jsm/lines/LineSegments2.js +22 -18
  53. package/examples/jsm/loaders/3DMLoader.js +18 -12
  54. package/examples/jsm/loaders/3MFLoader.js +2 -2
  55. package/examples/jsm/loaders/ColladaLoader.js +61 -3
  56. package/examples/jsm/loaders/FBXLoader.js +1 -1
  57. package/examples/jsm/loaders/GLTFLoader.js +99 -35
  58. package/examples/jsm/loaders/KTX2Loader.js +19 -0
  59. package/examples/jsm/loaders/LWOLoader.js +8 -6
  60. package/examples/jsm/loaders/LogLuvLoader.js +606 -0
  61. package/examples/jsm/loaders/PLYLoader.js +33 -7
  62. package/examples/jsm/loaders/SVGLoader.js +7 -4
  63. package/examples/jsm/loaders/TDSLoader.js +225 -285
  64. package/examples/jsm/loaders/lwo/LWO2Parser.js +1 -0
  65. package/examples/jsm/loaders/lwo/LWO3Parser.js +2 -2
  66. package/examples/jsm/node-editor/NodeEditor.js +455 -0
  67. package/examples/jsm/node-editor/accessors/NormalEditor.js +30 -0
  68. package/examples/jsm/node-editor/accessors/PositionEditor.js +30 -0
  69. package/examples/jsm/node-editor/accessors/UVEditor.js +26 -0
  70. package/examples/jsm/node-editor/display/BlendEditor.js +43 -0
  71. package/examples/jsm/node-editor/examples/animate-uv.json +1 -0
  72. package/examples/jsm/node-editor/examples/fake-top-light.json +1 -0
  73. package/examples/jsm/node-editor/examples/oscillator-color.json +1 -0
  74. package/examples/jsm/node-editor/examples/rim.json +1 -0
  75. package/examples/jsm/node-editor/inputs/ColorEditor.js +91 -0
  76. package/examples/jsm/node-editor/inputs/FloatEditor.js +24 -0
  77. package/examples/jsm/node-editor/inputs/SliderEditor.js +68 -0
  78. package/examples/jsm/node-editor/inputs/Vector2Editor.js +28 -0
  79. package/examples/jsm/node-editor/inputs/Vector3Editor.js +30 -0
  80. package/examples/jsm/node-editor/inputs/Vector4Editor.js +37 -0
  81. package/examples/jsm/node-editor/materials/StandardMaterialEditor.js +69 -0
  82. package/examples/jsm/node-editor/math/DotEditor.js +36 -0
  83. package/examples/jsm/node-editor/math/InvertEditor.js +38 -0
  84. package/examples/jsm/node-editor/math/LimiterEditor.js +48 -0
  85. package/examples/jsm/node-editor/math/NormalizeEditor.js +26 -0
  86. package/examples/jsm/node-editor/math/OperatorEditor.js +50 -0
  87. package/examples/jsm/node-editor/math/PowerEditor.js +34 -0
  88. package/examples/jsm/node-editor/math/TrigonometryEditor.js +39 -0
  89. package/examples/jsm/node-editor/procedural/CheckerEditor.js +26 -0
  90. package/examples/jsm/node-editor/utils/OscillatorEditor.js +42 -0
  91. package/examples/jsm/node-editor/utils/TimerEditor.js +57 -0
  92. package/examples/jsm/nodes/materials/StandardNodeMaterial.js +1 -1
  93. package/examples/jsm/nodes/materials/nodes/StandardNode.js +6 -6
  94. package/examples/jsm/nodes/utils/ColorSpaceNode.js +1 -49
  95. package/examples/jsm/objects/MarchingCubes.js +46 -152
  96. package/examples/jsm/postprocessing/AdaptiveToneMappingPass.js +1 -1
  97. package/examples/jsm/postprocessing/AfterimagePass.js +1 -1
  98. package/examples/jsm/postprocessing/BloomPass.js +1 -1
  99. package/examples/jsm/postprocessing/BokehPass.js +1 -1
  100. package/examples/jsm/postprocessing/ClearPass.js +1 -1
  101. package/examples/jsm/postprocessing/CubeTexturePass.js +1 -1
  102. package/examples/jsm/postprocessing/DotScreenPass.js +1 -1
  103. package/examples/jsm/postprocessing/EffectComposer.js +3 -3
  104. package/examples/jsm/postprocessing/FilmPass.js +1 -1
  105. package/examples/jsm/postprocessing/GlitchPass.js +1 -1
  106. package/examples/jsm/postprocessing/HalftonePass.js +1 -1
  107. package/examples/jsm/postprocessing/MaskPass.js +1 -1
  108. package/examples/jsm/postprocessing/OutlinePass.js +1 -1
  109. package/examples/jsm/postprocessing/RenderPass.js +1 -1
  110. package/examples/jsm/postprocessing/SAOPass.js +1 -1
  111. package/examples/jsm/postprocessing/SMAAPass.js +1 -1
  112. package/examples/jsm/postprocessing/SSAARenderPass.js +1 -1
  113. package/examples/jsm/postprocessing/SSAOPass.js +1 -1
  114. package/examples/jsm/postprocessing/SSRPass.js +1 -1
  115. package/examples/jsm/postprocessing/SSRrPass.js +1 -1
  116. package/examples/jsm/postprocessing/SavePass.js +1 -1
  117. package/examples/jsm/postprocessing/ShaderPass.js +1 -1
  118. package/examples/jsm/postprocessing/TAARenderPass.js +1 -1
  119. package/examples/jsm/postprocessing/TexturePass.js +1 -1
  120. package/examples/jsm/postprocessing/UnrealBloomPass.js +1 -1
  121. package/examples/jsm/renderers/CSS2DRenderer.js +5 -4
  122. package/examples/jsm/renderers/CSS3DRenderer.js +5 -4
  123. package/examples/jsm/renderers/nodes/Nodes.js +14 -13
  124. package/examples/jsm/renderers/nodes/ShaderNode.js +193 -41
  125. package/examples/jsm/renderers/nodes/accessors/MaterialNode.js +6 -6
  126. package/examples/jsm/renderers/nodes/accessors/ModelViewProjectionNode.js +5 -5
  127. package/examples/jsm/renderers/nodes/accessors/NormalNode.js +14 -3
  128. package/examples/jsm/renderers/nodes/accessors/PointUVNode.js +3 -3
  129. package/examples/jsm/renderers/nodes/accessors/PositionNode.js +15 -5
  130. package/examples/jsm/renderers/nodes/accessors/SkinningNode.js +107 -0
  131. package/examples/jsm/renderers/nodes/accessors/UVNode.js +7 -5
  132. package/examples/jsm/renderers/nodes/core/ArrayInputNode.js +3 -3
  133. package/examples/jsm/renderers/nodes/core/AttributeNode.js +6 -0
  134. package/examples/jsm/renderers/nodes/core/BypassNode.js +38 -0
  135. package/examples/jsm/renderers/nodes/core/CodeNode.js +3 -3
  136. package/examples/jsm/renderers/nodes/core/ContextNode.js +4 -19
  137. package/examples/jsm/renderers/nodes/core/ExpressionNode.js +13 -2
  138. package/examples/jsm/renderers/nodes/core/FunctionNode.js +19 -132
  139. package/examples/jsm/renderers/nodes/core/InputNode.js +13 -3
  140. package/examples/jsm/renderers/nodes/core/Node.js +32 -10
  141. package/examples/jsm/renderers/nodes/core/NodeBuilder.js +146 -128
  142. package/examples/jsm/renderers/nodes/core/NodeFunction.js +22 -0
  143. package/examples/jsm/renderers/nodes/core/NodeFunctionInput.js +4 -4
  144. package/examples/jsm/renderers/nodes/core/NodeKeywords.js +18 -179
  145. package/examples/jsm/renderers/nodes/core/NodeParser.js +11 -0
  146. package/examples/jsm/renderers/nodes/core/NodeVar.js +2 -2
  147. package/examples/jsm/renderers/nodes/core/PropertyNode.js +14 -2
  148. package/examples/jsm/renderers/nodes/core/TempNode.js +10 -13
  149. package/examples/jsm/renderers/nodes/core/VarNode.js +12 -7
  150. package/examples/jsm/renderers/nodes/core/VaryNode.js +23 -8
  151. package/examples/jsm/renderers/nodes/core/constants.js +2 -0
  152. package/examples/jsm/renderers/nodes/display/ColorSpaceNode.js +47 -25
  153. package/examples/jsm/renderers/nodes/display/NormalMapNode.js +21 -22
  154. package/examples/jsm/renderers/nodes/functions/BSDFs.js +64 -101
  155. package/examples/jsm/renderers/nodes/inputs/BufferNode.js +25 -0
  156. package/examples/jsm/renderers/nodes/inputs/IntNode.js +17 -0
  157. package/examples/jsm/renderers/nodes/inputs/TextureNode.js +10 -2
  158. package/examples/jsm/renderers/nodes/lights/LightContextNode.js +20 -14
  159. package/examples/jsm/renderers/nodes/lights/LightNode.js +32 -36
  160. package/examples/jsm/renderers/nodes/math/CondNode.js +60 -0
  161. package/examples/jsm/renderers/nodes/math/MathNode.js +87 -36
  162. package/examples/jsm/renderers/nodes/math/OperatorNode.js +124 -31
  163. package/examples/jsm/renderers/nodes/parsers/GLSLNodeFunction.js +137 -0
  164. package/examples/jsm/renderers/nodes/parsers/GLSLNodeParser.js +14 -0
  165. package/examples/jsm/renderers/nodes/parsers/WGSLNodeFunction.js +89 -0
  166. package/examples/jsm/renderers/nodes/parsers/WGSLNodeParser.js +14 -0
  167. package/examples/jsm/renderers/nodes/procedural/CheckerNode.js +7 -9
  168. package/examples/jsm/renderers/nodes/utils/ArrayElementNode.js +31 -0
  169. package/examples/jsm/renderers/nodes/utils/ConvertNode.js +33 -0
  170. package/examples/jsm/renderers/nodes/utils/JoinNode.js +7 -7
  171. package/examples/jsm/renderers/nodes/utils/OscNode.js +58 -0
  172. package/examples/jsm/renderers/nodes/utils/SplitNode.js +18 -8
  173. package/examples/jsm/renderers/nodes/utils/SpriteSheetUVNode.js +7 -7
  174. package/examples/jsm/renderers/webgl/nodes/SlotNode.js +22 -0
  175. package/examples/jsm/renderers/webgl/nodes/WebGLNodeBuilder.js +191 -94
  176. package/examples/jsm/renderers/webgl/nodes/WebGLNodes.js +2 -2
  177. package/examples/jsm/renderers/webgl/nodes/WebGLPhysicalContextNode.js +2 -2
  178. package/examples/jsm/renderers/webgpu/WebGPUBackground.js +1 -1
  179. package/examples/jsm/renderers/webgpu/WebGPUBindings.js +3 -3
  180. package/examples/jsm/renderers/webgpu/WebGPUComputePipelines.js +2 -4
  181. package/examples/jsm/renderers/webgpu/WebGPUProgrammableStage.js +2 -4
  182. package/examples/jsm/renderers/webgpu/WebGPURenderPipeline.js +15 -23
  183. package/examples/jsm/renderers/webgpu/WebGPURenderPipelines.js +3 -5
  184. package/examples/jsm/renderers/webgpu/WebGPURenderer.js +11 -27
  185. package/examples/jsm/renderers/webgpu/WebGPUTextureUtils.js +62 -28
  186. package/examples/jsm/renderers/webgpu/WebGPUTextures.js +34 -27
  187. package/examples/jsm/renderers/webgpu/constants.js +2 -2
  188. package/examples/jsm/renderers/webgpu/nodes/WebGPUNodeBuilder.js +430 -98
  189. package/examples/jsm/renderers/webgpu/nodes/WebGPUNodes.js +1 -1
  190. package/examples/jsm/utils/RoughnessMipmapper.js +1 -0
  191. package/examples/jsm/webxr/OculusHandPointerModel.js +6 -6
  192. package/package.json +10 -10
  193. package/src/Three.Legacy.js +6 -0
  194. package/src/Three.js +0 -1
  195. package/src/cameras/StereoCamera.js +8 -7
  196. package/src/constants.js +1 -2
  197. package/src/core/Layers.js +7 -1
  198. package/src/core/Object3D.js +2 -0
  199. package/src/extras/PMREMGenerator.js +11 -6
  200. package/src/loaders/FileLoader.js +89 -152
  201. package/src/loaders/ImageLoader.js +9 -4
  202. package/src/loaders/LoaderUtils.js +26 -0
  203. package/src/loaders/MaterialLoader.js +7 -4
  204. package/src/loaders/ObjectLoader.js +2 -0
  205. package/src/materials/Material.js +4 -4
  206. package/src/materials/MeshPhysicalMaterial.js +20 -14
  207. package/src/math/MathUtils.js +5 -16
  208. package/src/renderers/WebGLMultisampleRenderTarget.js +7 -1
  209. package/src/renderers/WebGLRenderer.js +83 -117
  210. package/src/renderers/shaders/ShaderChunk/bsdfs.glsl.js +2 -2
  211. package/src/renderers/shaders/ShaderChunk/encodings_pars_fragment.glsl.js +0 -27
  212. package/src/renderers/shaders/ShaderChunk/envmap_common_pars_fragment.glsl.js +0 -1
  213. package/src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl.js +19 -6
  214. package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +2 -2
  215. package/src/renderers/shaders/ShaderChunk/transmission_fragment.glsl.js +1 -1
  216. package/src/renderers/shaders/ShaderChunk/transmission_pars_fragment.glsl.js +1 -1
  217. package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +13 -5
  218. package/src/renderers/shaders/ShaderLib/vsm.glsl.js +2 -1
  219. package/src/renderers/shaders/ShaderLib.js +6 -4
  220. package/src/renderers/shaders/UniformsLib.js +1 -2
  221. package/src/renderers/webgl/WebGLExtensions.js +1 -0
  222. package/src/renderers/webgl/WebGLMaterials.js +27 -15
  223. package/src/renderers/webgl/WebGLProgram.js +10 -6
  224. package/src/renderers/webgl/WebGLPrograms.js +17 -12
  225. package/src/renderers/webgl/WebGLShadowMap.js +14 -5
  226. package/src/renderers/webgl/WebGLState.js +31 -17
  227. package/src/renderers/webgl/WebGLTextures.js +188 -51
  228. package/src/renderers/webgl/WebGLUniforms.js +45 -1
  229. package/src/renderers/webxr/WebXRManager.js +71 -110
  230. package/src/textures/Texture.js +6 -0
  231. package/src/utils.js +37 -1
  232. package/examples/js/controls/DeviceOrientationControls.js +0 -147
  233. package/examples/js/libs/dat.gui.min.js +0 -14
  234. package/examples/jsm/controls/DeviceOrientationControls.js +0 -153
  235. package/examples/jsm/libs/dat.gui.module.js +0 -3575
  236. package/examples/jsm/libs/glslang.js +0 -78
  237. package/examples/jsm/libs/glslang.wasm +0 -0
  238. package/examples/jsm/renderers/nodes/consts/MathConsts.js +0 -7
  239. package/examples/jsm/renderers/nodes/core/ConstNode.js +0 -39
  240. package/examples/jsm/renderers/nodes/core/NodeSlot.js +0 -13
  241. package/examples/jsm/renderers/nodes/core/StructNode.js +0 -80
  242. package/examples/jsm/renderers/nodes/core/StructVarNode.js +0 -75
  243. package/examples/jsm/renderers/nodes/functions/EncodingFunctions.js +0 -99
  244. package/examples/jsm/renderers/nodes/functions/MathFunctions.js +0 -47
  245. package/examples/jsm/renderers/webgpu/nodes/ShaderLib.js +0 -152
  246. 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 = this.readChunk( data );
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 = this.nextChunk( data, chunk );
128
+ let next = chunk.readChunk();
131
129
 
132
- while ( next !== 0 ) {
130
+ while ( next ) {
133
131
 
134
- if ( next === M3D_VERSION ) {
132
+ if ( next.id === M3D_VERSION ) {
135
133
 
136
- const version = this.readDWord( data );
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.resetPosition( data );
142
- this.readMeshData( data, path );
139
+ this.readMeshData( next, path );
143
140
 
144
141
  } else {
145
142
 
146
- this.debugMessage( 'Unknown main chunk: ' + next.toString( 16 ) );
143
+ this.debugMessage( 'Unknown main chunk: ' + next.hexId);
147
144
 
148
145
  }
149
146
 
150
- next = this.nextChunk( data, chunk );
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 {Dataview} data Dataview in use.
161
+ * @param {Chunk} chunk to read mesh from
165
162
  * @param {String} path Path for external resources.
166
163
  */
167
- readMeshData( data, path ) {
164
+ readMeshData( chunk, path ) {
168
165
 
169
- const chunk = this.readChunk( data );
170
- let next = this.nextChunk( data, chunk );
166
+ let next = chunk.readChunk();
171
167
 
172
- while ( next !== 0 ) {
168
+ while ( next ) {
173
169
 
174
- if ( next === MESH_VERSION ) {
170
+ if ( next.id === MESH_VERSION ) {
175
171
 
176
- const version = + this.readDWord( data );
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 = this.readFloat( data );
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.resetPosition( data );
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.resetPosition( data );
195
- this.readMaterialEntry( data, path );
189
+ this.readMaterialEntry( next, path );
196
190
 
197
191
  } else {
198
192
 
199
- this.debugMessage( 'Unknown MDATA chunk: ' + next.toString( 16 ) );
193
+ this.debugMessage( 'Unknown MDATA chunk: ' + next.hexId );
200
194
 
201
195
  }
202
196
 
203
- next = this.nextChunk( data, chunk );
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 {Dataview} data Dataview in use.
207
+ * @param {Chunk} chunk Chunk in use.
214
208
  */
215
- readNamedObject( data ) {
209
+ readNamedObject( chunk ) {
216
210
 
217
- const chunk = this.readChunk( data );
218
- const name = this.readString( data, 64 );
219
- chunk.cur = this.position;
211
+ const name = chunk.readString();
220
212
 
221
- let next = this.nextChunk( data, chunk );
222
- while ( next !== 0 ) {
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.resetPosition( data );
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 = this.nextChunk( data, chunk );
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 {Dataview} data Dataview in use.
236
+ * @param {Chunk} chunk Chunk in use.
250
237
  * @param {String} path Path for external resources.
251
238
  */
252
- readMaterialEntry( data, path ) {
239
+ readMaterialEntry( chunk, path ) {
253
240
 
254
- const chunk = this.readChunk( data );
255
- let next = this.nextChunk( data, chunk );
256
- const material = new MeshPhongMaterial();
241
+ let next = chunk.readChunk();
242
+ let material = new MeshPhongMaterial();
257
243
 
258
- while ( next !== 0 ) {
244
+ while ( next ) {
259
245
 
260
- if ( next === MAT_NAME ) {
246
+ if ( next.id === MAT_NAME ) {
261
247
 
262
- material.name = this.readString( data, 64 );
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 = this.readByte( data );
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( data );
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( data );
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( data );
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( data );
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( data );
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.resetPosition( data );
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.resetPosition( data );
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.resetPosition( data );
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.resetPosition( data );
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.toString( 16 ) );
322
+ this.debugMessage( ' Unknown material chunk: ' + next.hexId );
341
323
 
342
324
  }
343
325
 
344
- next = this.nextChunk( data, chunk );
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 {Dataview} data Dataview in use.
338
+ * @param {Chunk} chunk Chunk in use.
359
339
  * @return {Mesh} The parsed mesh.
360
340
  */
361
- readMesh( data ) {
341
+ readMesh( chunk ) {
362
342
 
363
- const chunk = this.readChunk( data );
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 !== 0 ) {
351
+ while ( next ) {
373
352
 
374
- if ( next === POINT_ARRAY ) {
353
+ if ( next.id === POINT_ARRAY ) {
375
354
 
376
- const points = this.readWord( data );
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( this.readFloat( data ) );
387
- vertices.push( this.readFloat( data ) );
388
- vertices.push( this.readFloat( data ) );
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.resetPosition( data );
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 = this.readWord( data );
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( this.readFloat( data ) );
412
- uvs.push( this.readFloat( data ) );
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 ] = this.readFloat( data );
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.toString( 16 ) );
444
+ this.debugMessage( ' Unknown mesh chunk: ' + next.hexId );
467
445
 
468
446
  }
469
447
 
470
- next = this.nextChunk( data, chunk );
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 {Dataview} data Dataview in use.
462
+ * @param {Chunk} chunk Chunk in use.
487
463
  * @param {Mesh} mesh Mesh to be filled with the data read.
488
464
  */
489
- readFaceArray( data, mesh ) {
465
+ readFaceArray( chunk, mesh ) {
490
466
 
491
- const chunk = this.readChunk( data );
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( this.readWord( data ), this.readWord( data ), this.readWord( data ) );
475
+ index.push( chunk.readWord( ), chunk.readWord( ), chunk.readWord( ) );
501
476
 
502
- this.readWord( data ); // visibility
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 ( this.position < chunk.end ) {
488
+ while ( !chunk.endOfChunk ) {
514
489
 
515
- const subchunk = this.readChunk( data );
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.resetPosition( data );
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.toString( 16 ) );
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 {Dataview} data Dataview in use.
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( data, path ) {
534
+ readMap( chunk, path ) {
566
535
 
567
- const chunk = this.readChunk( data );
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 !== 0 ) {
542
+ while ( next ) {
575
543
 
576
- if ( next === MAT_MAPNAME ) {
544
+ if ( next.id === MAT_MAPNAME ) {
577
545
 
578
- const name = this.readString( data, 128 );
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 = this.readFloat( data );
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 = this.readFloat( data );
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 = this.readFloat( data );
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 = this.readFloat( data );
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.toString( 16 ) );
573
+ this.debugMessage( ' Unknown map chunk: ' + next.hexId );
606
574
 
607
575
  }
608
576
 
609
- next = this.nextChunk( data, chunk );
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 {Dataview} data Dataview in use.
589
+ * @param {Chunk} chunk Chunk in use.
624
590
  * @return {Object} Object with name and index of the object.
625
591
  */
626
- readMaterialGroup( data ) {
592
+ readMaterialGroup( chunk ) {
627
593
 
628
- this.readChunk( data );
629
- const name = this.readString( data, 64 );
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( this.readWord( data ) );
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 {DataView} data Dataview.
615
+ * @param {Chunk} chunk Chunk.
651
616
  * @return {Color} Color value read..
652
617
  */
653
- readColor( data ) {
618
+ readColor( chunk ) {
654
619
 
655
- const chunk = this.readChunk( data );
620
+ const subChunk = chunk.readChunk( );
656
621
  const color = new Color();
657
622
 
658
- if ( chunk.id === COLOR_24 || chunk.id === LIN_COLOR_24 ) {
623
+ if ( subChunk.id === COLOR_24 || subChunk.id === LIN_COLOR_24 ) {
659
624
 
660
- const r = this.readByte( data );
661
- const g = this.readByte( data );
662
- const b = this.readByte( data );
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 ( chunk.id === COLOR_F || chunk.id === LIN_COLOR_F ) {
633
+ } else if ( subChunk.id === COLOR_F || subChunk.id === LIN_COLOR_F ) {
669
634
 
670
- const r = this.readFloat( data );
671
- const g = this.readFloat( data );
672
- const b = this.readFloat( data );
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: ' + chunk.toString( 16 ) );
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 next chunk of data.
654
+ * Read percentage value.
691
655
  *
692
- * @method readChunk
693
- * @param {DataView} data Dataview.
694
- * @return {Object} Chunk of data read.
656
+ * @method readPercentage
657
+ * @param {Chunk} chunk Chunk to read data from.
658
+ * @return {Number} Data read from the dataview.
695
659
  */
696
- readChunk( data ) {
660
+ readPercentage( chunk ) {
697
661
 
698
- const chunk = {};
662
+ const subChunk = chunk.readChunk( );
699
663
 
700
- chunk.cur = this.position;
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
- return chunk;
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
- * Set position to the end of the current chunk of data.
683
+ * Print debug message to the console.
684
+ *
685
+ * Is controlled by a flag to show or hide debug messages.
712
686
  *
713
- * @method endChunk
714
- * @param {Object} chunk Data chunk.
687
+ * @method debugMessage
688
+ * @param {Object} message Debug message to print to the console.
715
689
  */
716
- endChunk( chunk ) {
690
+ debugMessage( message ) {
717
691
 
718
- this.position = chunk.end;
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
- * Move to the next data chunk.
705
+ * Create a new chunk
724
706
  *
725
- * @method nextChunk
726
- * @param {DataView} data Dataview.
727
- * @param {Object} chunk Data chunk.
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
- nextChunk( data, chunk ) {
730
-
731
- if ( chunk.cur >= chunk.end ) {
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
- return 0;
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
- this.position = chunk.cur;
733
+ /**
734
+ * read a sub cchunk.
735
+ *
736
+ * @method readChunk
737
+ * @return {Chunk | null} next sub chunk
738
+ */
739
+ readChunk () {
738
740
 
739
- try {
741
+ if ( this.endOfChunk ) {
742
+ return null;
743
+ }
740
744
 
741
- const next = this.readChunk( data );
742
- chunk.cur += next.size;
743
- return next.id;
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 0;
752
+ return null;
749
753
 
750
754
  }
751
755
 
752
756
  }
753
757
 
754
758
  /**
755
- * Reset dataview position.
759
+ * return the ID of this chunk as Hex
756
760
  *
757
- * @method resetPosition
761
+ * @method idToString
762
+ * @return {String} hex-string of id
758
763
  */
759
- resetPosition() {
760
-
761
- this.position -= 6;
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( data ) {
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( data ) {
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( data ) {
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( data ) {
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( data ) {
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( data ) {
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( data, maxLength ) {
871
+ readString() {
872
872
 
873
873
  let s = '';
874
-
875
- for ( let i = 0; i < maxLength; i ++ ) {
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
  }