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
@@ -16,7 +16,6 @@
16
16
  super( manager );
17
17
  this.debug = false;
18
18
  this.group = null;
19
- this.position = 0;
20
19
  this.materials = [];
21
20
  this.meshes = [];
22
21
 
@@ -79,7 +78,6 @@
79
78
  parse( arraybuffer, path ) {
80
79
 
81
80
  this.group = new THREE.Group();
82
- this.position = 0;
83
81
  this.materials = [];
84
82
  this.meshes = [];
85
83
  this.readFile( arraybuffer, path );
@@ -105,31 +103,30 @@
105
103
  readFile( arraybuffer, path ) {
106
104
 
107
105
  const data = new DataView( arraybuffer );
108
- const chunk = this.readChunk( data );
106
+ const chunk = new Chunk( data, 0, this.debugMessage );
109
107
 
110
108
  if ( chunk.id === MLIBMAGIC || chunk.id === CMAGIC || chunk.id === M3DMAGIC ) {
111
109
 
112
- let next = this.nextChunk( data, chunk );
110
+ let next = chunk.readChunk();
113
111
 
114
- while ( next !== 0 ) {
112
+ while ( next ) {
115
113
 
116
- if ( next === M3D_VERSION ) {
114
+ if ( next.id === M3D_VERSION ) {
117
115
 
118
- const version = this.readDWord( data );
116
+ const version = next.readDWord();
119
117
  this.debugMessage( '3DS file version: ' + version );
120
118
 
121
- } else if ( next === MDATA ) {
119
+ } else if ( next.id === MDATA ) {
122
120
 
123
- this.resetPosition( data );
124
- this.readMeshData( data, path );
121
+ this.readMeshData( next, path );
125
122
 
126
123
  } else {
127
124
 
128
- this.debugMessage( 'Unknown main chunk: ' + next.toString( 16 ) );
125
+ this.debugMessage( 'Unknown main chunk: ' + next.hexId );
129
126
 
130
127
  }
131
128
 
132
- next = this.nextChunk( data, chunk );
129
+ next = chunk.readChunk();
133
130
 
134
131
  }
135
132
 
@@ -142,48 +139,45 @@
142
139
  * Read mesh data chunk.
143
140
  *
144
141
  * @method readMeshData
145
- * @param {Dataview} data Dataview in use.
142
+ * @param {Chunk} chunk to read mesh from
146
143
  * @param {String} path Path for external resources.
147
144
  */
148
145
 
149
146
 
150
- readMeshData( data, path ) {
147
+ readMeshData( chunk, path ) {
151
148
 
152
- const chunk = this.readChunk( data );
153
- let next = this.nextChunk( data, chunk );
149
+ let next = chunk.readChunk();
154
150
 
155
- while ( next !== 0 ) {
151
+ while ( next ) {
156
152
 
157
- if ( next === MESH_VERSION ) {
153
+ if ( next.id === MESH_VERSION ) {
158
154
 
159
- const version = + this.readDWord( data );
155
+ const version = + next.readDWord();
160
156
  this.debugMessage( 'Mesh Version: ' + version );
161
157
 
162
- } else if ( next === MASTER_SCALE ) {
158
+ } else if ( next.id === MASTER_SCALE ) {
163
159
 
164
- const scale = this.readFloat( data );
160
+ const scale = next.readFloat();
165
161
  this.debugMessage( 'Master scale: ' + scale );
166
162
  this.group.scale.set( scale, scale, scale );
167
163
 
168
- } else if ( next === NAMED_OBJECT ) {
164
+ } else if ( next.id === NAMED_OBJECT ) {
169
165
 
170
166
  this.debugMessage( 'Named Object' );
171
- this.resetPosition( data );
172
- this.readNamedObject( data );
167
+ this.readNamedObject( next );
173
168
 
174
- } else if ( next === MAT_ENTRY ) {
169
+ } else if ( next.id === MAT_ENTRY ) {
175
170
 
176
171
  this.debugMessage( 'Material' );
177
- this.resetPosition( data );
178
- this.readMaterialEntry( data, path );
172
+ this.readMaterialEntry( next, path );
179
173
 
180
174
  } else {
181
175
 
182
- this.debugMessage( 'Unknown MDATA chunk: ' + next.toString( 16 ) );
176
+ this.debugMessage( 'Unknown MDATA chunk: ' + next.hexId );
183
177
 
184
178
  }
185
179
 
186
- next = this.nextChunk( data, chunk );
180
+ next = chunk.readChunk();
187
181
 
188
182
  }
189
183
 
@@ -192,145 +186,134 @@
192
186
  * Read named object chunk.
193
187
  *
194
188
  * @method readNamedObject
195
- * @param {Dataview} data Dataview in use.
189
+ * @param {Chunk} chunk Chunk in use.
196
190
  */
197
191
 
198
192
 
199
- readNamedObject( data ) {
193
+ readNamedObject( chunk ) {
200
194
 
201
- const chunk = this.readChunk( data );
202
- const name = this.readString( data, 64 );
203
- chunk.cur = this.position;
204
- let next = this.nextChunk( data, chunk );
195
+ const name = chunk.readString();
196
+ let next = chunk.readChunk();
205
197
 
206
- while ( next !== 0 ) {
198
+ while ( next ) {
207
199
 
208
- if ( next === N_TRI_OBJECT ) {
200
+ if ( next.id === N_TRI_OBJECT ) {
209
201
 
210
- this.resetPosition( data );
211
- const mesh = this.readMesh( data );
202
+ const mesh = this.readMesh( next );
212
203
  mesh.name = name;
213
204
  this.meshes.push( mesh );
214
205
 
215
206
  } else {
216
207
 
217
- this.debugMessage( 'Unknown named object chunk: ' + next.toString( 16 ) );
208
+ this.debugMessage( 'Unknown named object chunk: ' + next.hexId );
218
209
 
219
210
  }
220
211
 
221
- next = this.nextChunk( data, chunk );
212
+ next = chunk.readChunk();
222
213
 
223
214
  }
224
215
 
225
- this.endChunk( chunk );
226
-
227
216
  }
228
217
  /**
229
218
  * Read material data chunk and add it to the material list.
230
219
  *
231
220
  * @method readMaterialEntry
232
- * @param {Dataview} data Dataview in use.
221
+ * @param {Chunk} chunk Chunk in use.
233
222
  * @param {String} path Path for external resources.
234
223
  */
235
224
 
236
225
 
237
- readMaterialEntry( data, path ) {
226
+ readMaterialEntry( chunk, path ) {
238
227
 
239
- const chunk = this.readChunk( data );
240
- let next = this.nextChunk( data, chunk );
228
+ let next = chunk.readChunk();
241
229
  const material = new THREE.MeshPhongMaterial();
242
230
 
243
- while ( next !== 0 ) {
231
+ while ( next ) {
244
232
 
245
- if ( next === MAT_NAME ) {
233
+ if ( next.id === MAT_NAME ) {
246
234
 
247
- material.name = this.readString( data, 64 );
235
+ material.name = next.readString();
248
236
  this.debugMessage( ' Name: ' + material.name );
249
237
 
250
- } else if ( next === MAT_WIRE ) {
238
+ } else if ( next.id === MAT_WIRE ) {
251
239
 
252
240
  this.debugMessage( ' Wireframe' );
253
241
  material.wireframe = true;
254
242
 
255
- } else if ( next === MAT_WIRE_SIZE ) {
243
+ } else if ( next.id === MAT_WIRE_SIZE ) {
256
244
 
257
- const value = this.readByte( data );
245
+ const value = next.readByte();
258
246
  material.wireframeLinewidth = value;
259
247
  this.debugMessage( ' Wireframe Thickness: ' + value );
260
248
 
261
- } else if ( next === MAT_TWO_SIDE ) {
249
+ } else if ( next.id === MAT_TWO_SIDE ) {
262
250
 
263
251
  material.side = THREE.DoubleSide;
264
252
  this.debugMessage( ' DoubleSided' );
265
253
 
266
- } else if ( next === MAT_ADDITIVE ) {
254
+ } else if ( next.id === MAT_ADDITIVE ) {
267
255
 
268
256
  this.debugMessage( ' Additive Blending' );
269
257
  material.blending = THREE.AdditiveBlending;
270
258
 
271
- } else if ( next === MAT_DIFFUSE ) {
259
+ } else if ( next.id === MAT_DIFFUSE ) {
272
260
 
273
261
  this.debugMessage( ' Diffuse THREE.Color' );
274
- material.color = this.readColor( data );
262
+ material.color = this.readColor( next );
275
263
 
276
- } else if ( next === MAT_SPECULAR ) {
264
+ } else if ( next.id === MAT_SPECULAR ) {
277
265
 
278
266
  this.debugMessage( ' Specular THREE.Color' );
279
- material.specular = this.readColor( data );
267
+ material.specular = this.readColor( next );
280
268
 
281
- } else if ( next === MAT_AMBIENT ) {
269
+ } else if ( next.id === MAT_AMBIENT ) {
282
270
 
283
271
  this.debugMessage( ' Ambient color' );
284
- material.color = this.readColor( data );
272
+ material.color = this.readColor( next );
285
273
 
286
- } else if ( next === MAT_SHININESS ) {
274
+ } else if ( next.id === MAT_SHININESS ) {
287
275
 
288
- const shininess = this.readPercentage( data );
276
+ const shininess = this.readPercentage( next );
289
277
  material.shininess = shininess * 100;
290
278
  this.debugMessage( ' Shininess : ' + shininess );
291
279
 
292
- } else if ( next === MAT_TRANSPARENCY ) {
280
+ } else if ( next.id === MAT_TRANSPARENCY ) {
293
281
 
294
- const transparency = this.readPercentage( data );
282
+ const transparency = this.readPercentage( next );
295
283
  material.opacity = 1 - transparency;
296
284
  this.debugMessage( ' Transparency : ' + transparency );
297
285
  material.transparent = material.opacity < 1 ? true : false;
298
286
 
299
- } else if ( next === MAT_TEXMAP ) {
287
+ } else if ( next.id === MAT_TEXMAP ) {
300
288
 
301
289
  this.debugMessage( ' ColorMap' );
302
- this.resetPosition( data );
303
- material.map = this.readMap( data, path );
290
+ material.map = this.readMap( next, path );
304
291
 
305
- } else if ( next === MAT_BUMPMAP ) {
292
+ } else if ( next.id === MAT_BUMPMAP ) {
306
293
 
307
294
  this.debugMessage( ' BumpMap' );
308
- this.resetPosition( data );
309
- material.bumpMap = this.readMap( data, path );
295
+ material.bumpMap = this.readMap( next, path );
310
296
 
311
- } else if ( next === MAT_OPACMAP ) {
297
+ } else if ( next.id === MAT_OPACMAP ) {
312
298
 
313
299
  this.debugMessage( ' OpacityMap' );
314
- this.resetPosition( data );
315
- material.alphaMap = this.readMap( data, path );
300
+ material.alphaMap = this.readMap( next, path );
316
301
 
317
- } else if ( next === MAT_SPECMAP ) {
302
+ } else if ( next.id === MAT_SPECMAP ) {
318
303
 
319
304
  this.debugMessage( ' SpecularMap' );
320
- this.resetPosition( data );
321
- material.specularMap = this.readMap( data, path );
305
+ material.specularMap = this.readMap( next, path );
322
306
 
323
307
  } else {
324
308
 
325
- this.debugMessage( ' Unknown material chunk: ' + next.toString( 16 ) );
309
+ this.debugMessage( ' Unknown material chunk: ' + next.hexId );
326
310
 
327
311
  }
328
312
 
329
- next = this.nextChunk( data, chunk );
313
+ next = chunk.readChunk();
330
314
 
331
315
  }
332
316
 
333
- this.endChunk( chunk );
334
317
  this.materials[ material.name ] = material;
335
318
 
336
319
  }
@@ -338,68 +321,66 @@
338
321
  * Read mesh data chunk.
339
322
  *
340
323
  * @method readMesh
341
- * @param {Dataview} data Dataview in use.
324
+ * @param {Chunk} chunk Chunk in use.
342
325
  * @return {Mesh} The parsed mesh.
343
326
  */
344
327
 
345
328
 
346
- readMesh( data ) {
329
+ readMesh( chunk ) {
347
330
 
348
- const chunk = this.readChunk( data );
349
- let next = this.nextChunk( data, chunk );
331
+ let next = chunk.readChunk();
350
332
  const geometry = new THREE.BufferGeometry();
351
333
  const material = new THREE.MeshPhongMaterial();
352
334
  const mesh = new THREE.Mesh( geometry, material );
353
335
  mesh.name = 'mesh';
354
336
 
355
- while ( next !== 0 ) {
337
+ while ( next ) {
356
338
 
357
- if ( next === POINT_ARRAY ) {
339
+ if ( next.id === POINT_ARRAY ) {
358
340
 
359
- const points = this.readWord( data );
341
+ const points = next.readWord();
360
342
  this.debugMessage( ' Vertex: ' + points ); //BufferGeometry
361
343
 
362
344
  const vertices = [];
363
345
 
364
346
  for ( let i = 0; i < points; i ++ ) {
365
347
 
366
- vertices.push( this.readFloat( data ) );
367
- vertices.push( this.readFloat( data ) );
368
- vertices.push( this.readFloat( data ) );
348
+ vertices.push( next.readFloat() );
349
+ vertices.push( next.readFloat() );
350
+ vertices.push( next.readFloat() );
369
351
 
370
352
  }
371
353
 
372
354
  geometry.setAttribute( 'position', new THREE.Float32BufferAttribute( vertices, 3 ) );
373
355
 
374
- } else if ( next === FACE_ARRAY ) {
356
+ } else if ( next.id === FACE_ARRAY ) {
375
357
 
376
- this.resetPosition( data );
377
- this.readFaceArray( data, mesh );
358
+ this.readFaceArray( next, mesh );
378
359
 
379
- } else if ( next === TEX_VERTS ) {
360
+ } else if ( next.id === TEX_VERTS ) {
380
361
 
381
- const texels = this.readWord( data );
362
+ const texels = next.readWord();
382
363
  this.debugMessage( ' UV: ' + texels ); //BufferGeometry
383
364
 
384
365
  const uvs = [];
385
366
 
386
367
  for ( let i = 0; i < texels; i ++ ) {
387
368
 
388
- uvs.push( this.readFloat( data ) );
389
- uvs.push( this.readFloat( data ) );
369
+ uvs.push( next.readFloat() );
370
+ uvs.push( next.readFloat() );
390
371
 
391
372
  }
392
373
 
393
374
  geometry.setAttribute( 'uv', new THREE.Float32BufferAttribute( uvs, 2 ) );
394
375
 
395
- } else if ( next === MESH_MATRIX ) {
376
+ } else if ( next.id === MESH_MATRIX ) {
396
377
 
397
378
  this.debugMessage( ' Tranformation Matrix (TODO)' );
398
379
  const values = [];
399
380
 
400
381
  for ( let i = 0; i < 12; i ++ ) {
401
382
 
402
- values[ i ] = this.readFloat( data );
383
+ values[ i ] = next.readFloat();
403
384
 
404
385
  }
405
386
 
@@ -432,15 +413,14 @@
432
413
 
433
414
  } else {
434
415
 
435
- this.debugMessage( ' Unknown mesh chunk: ' + next.toString( 16 ) );
416
+ this.debugMessage( ' Unknown mesh chunk: ' + next.hexId );
436
417
 
437
418
  }
438
419
 
439
- next = this.nextChunk( data, chunk );
420
+ next = chunk.readChunk();
440
421
 
441
422
  }
442
423
 
443
- this.endChunk( chunk );
444
424
  geometry.computeVertexNormals();
445
425
  return mesh;
446
426
 
@@ -449,22 +429,21 @@
449
429
  * Read face array data chunk.
450
430
  *
451
431
  * @method readFaceArray
452
- * @param {Dataview} data Dataview in use.
432
+ * @param {Chunk} chunk Chunk in use.
453
433
  * @param {Mesh} mesh THREE.Mesh to be filled with the data read.
454
434
  */
455
435
 
456
436
 
457
- readFaceArray( data, mesh ) {
437
+ readFaceArray( chunk, mesh ) {
458
438
 
459
- const chunk = this.readChunk( data );
460
- const faces = this.readWord( data );
439
+ const faces = chunk.readWord();
461
440
  this.debugMessage( ' Faces: ' + faces );
462
441
  const index = [];
463
442
 
464
443
  for ( let i = 0; i < faces; ++ i ) {
465
444
 
466
- index.push( this.readWord( data ), this.readWord( data ), this.readWord( data ) );
467
- this.readWord( data ); // visibility
445
+ index.push( chunk.readWord(), chunk.readWord(), chunk.readWord() );
446
+ chunk.readWord(); // visibility
468
447
 
469
448
  }
470
449
 
@@ -473,15 +452,14 @@
473
452
  let materialIndex = 0;
474
453
  let start = 0;
475
454
 
476
- while ( this.position < chunk.end ) {
455
+ while ( ! chunk.endOfChunk ) {
477
456
 
478
- const subchunk = this.readChunk( data );
457
+ const subchunk = chunk.readChunk();
479
458
 
480
459
  if ( subchunk.id === MSH_MAT_GROUP ) {
481
460
 
482
461
  this.debugMessage( ' Material THREE.Group' );
483
- this.resetPosition( data );
484
- const group = this.readMaterialGroup( data );
462
+ const group = this.readMaterialGroup( subchunk );
485
463
  const count = group.index.length * 3; // assuming successive indices
486
464
 
487
465
  mesh.geometry.addGroup( start, count, materialIndex );
@@ -498,76 +476,70 @@
498
476
 
499
477
  } else {
500
478
 
501
- this.debugMessage( ' Unknown face array chunk: ' + subchunk.toString( 16 ) );
479
+ this.debugMessage( ' Unknown face array chunk: ' + subchunk.hexId );
502
480
 
503
481
  }
504
482
 
505
- this.endChunk( subchunk );
506
-
507
483
  }
508
484
 
509
485
  if ( mesh.material.length === 1 ) mesh.material = mesh.material[ 0 ]; // for backwards compatibility
510
486
 
511
- this.endChunk( chunk );
512
-
513
487
  }
514
488
  /**
515
489
  * Read texture map data chunk.
516
490
  *
517
491
  * @method readMap
518
- * @param {Dataview} data Dataview in use.
492
+ * @param {Chunk} chunk Chunk in use.
519
493
  * @param {String} path Path for external resources.
520
494
  * @return {Texture} Texture read from this data chunk.
521
495
  */
522
496
 
523
497
 
524
- readMap( data, path ) {
498
+ readMap( chunk, path ) {
525
499
 
526
- const chunk = this.readChunk( data );
527
- let next = this.nextChunk( data, chunk );
500
+ let next = chunk.readChunk();
528
501
  let texture = {};
529
502
  const loader = new THREE.TextureLoader( this.manager );
530
503
  loader.setPath( this.resourcePath || path ).setCrossOrigin( this.crossOrigin );
531
504
 
532
- while ( next !== 0 ) {
505
+ while ( next ) {
533
506
 
534
- if ( next === MAT_MAPNAME ) {
507
+ if ( next.id === MAT_MAPNAME ) {
535
508
 
536
- const name = this.readString( data, 128 );
509
+ const name = next.readString();
537
510
  texture = loader.load( name );
538
511
  this.debugMessage( ' File: ' + path + name );
539
512
 
540
- } else if ( next === MAT_MAP_UOFFSET ) {
513
+ } else if ( next.id === MAT_MAP_UOFFSET ) {
541
514
 
542
- texture.offset.x = this.readFloat( data );
515
+ texture.offset.x = next.readFloat();
543
516
  this.debugMessage( ' OffsetX: ' + texture.offset.x );
544
517
 
545
- } else if ( next === MAT_MAP_VOFFSET ) {
518
+ } else if ( next.id === MAT_MAP_VOFFSET ) {
546
519
 
547
- texture.offset.y = this.readFloat( data );
520
+ texture.offset.y = next.readFloat();
548
521
  this.debugMessage( ' OffsetY: ' + texture.offset.y );
549
522
 
550
- } else if ( next === MAT_MAP_USCALE ) {
523
+ } else if ( next.id === MAT_MAP_USCALE ) {
551
524
 
552
- texture.repeat.x = this.readFloat( data );
525
+ texture.repeat.x = next.readFloat();
553
526
  this.debugMessage( ' RepeatX: ' + texture.repeat.x );
554
527
 
555
- } else if ( next === MAT_MAP_VSCALE ) {
528
+ } else if ( next.id === MAT_MAP_VSCALE ) {
556
529
 
557
- texture.repeat.y = this.readFloat( data );
530
+ texture.repeat.y = next.readFloat();
558
531
  this.debugMessage( ' RepeatY: ' + texture.repeat.y );
559
532
 
560
533
  } else {
561
534
 
562
- this.debugMessage( ' Unknown map chunk: ' + next.toString( 16 ) );
535
+ this.debugMessage( ' Unknown map chunk: ' + next.hexId );
563
536
 
564
537
  }
565
538
 
566
- next = this.nextChunk( data, chunk );
539
+ next = chunk.readChunk();
567
540
 
568
541
  }
569
542
 
570
- this.endChunk( chunk );
571
543
  return texture;
572
544
 
573
545
  }
@@ -575,23 +547,22 @@
575
547
  * Read material group data chunk.
576
548
  *
577
549
  * @method readMaterialGroup
578
- * @param {Dataview} data Dataview in use.
550
+ * @param {Chunk} chunk Chunk in use.
579
551
  * @return {Object} Object with name and index of the object.
580
552
  */
581
553
 
582
554
 
583
- readMaterialGroup( data ) {
555
+ readMaterialGroup( chunk ) {
584
556
 
585
- this.readChunk( data );
586
- const name = this.readString( data, 64 );
587
- const numFaces = this.readWord( data );
557
+ const name = chunk.readString();
558
+ const numFaces = chunk.readWord();
588
559
  this.debugMessage( ' Name: ' + name );
589
560
  this.debugMessage( ' Faces: ' + numFaces );
590
561
  const index = [];
591
562
 
592
563
  for ( let i = 0; i < numFaces; ++ i ) {
593
564
 
594
- index.push( this.readWord( data ) );
565
+ index.push( chunk.readWord() );
595
566
 
596
567
  }
597
568
 
@@ -605,132 +576,191 @@
605
576
  * Read a color value.
606
577
  *
607
578
  * @method readColor
608
- * @param {DataView} data Dataview.
579
+ * @param {Chunk} chunk Chunk.
609
580
  * @return {Color} THREE.Color value read..
610
581
  */
611
582
 
612
583
 
613
- readColor( data ) {
584
+ readColor( chunk ) {
614
585
 
615
- const chunk = this.readChunk( data );
586
+ const subChunk = chunk.readChunk();
616
587
  const color = new THREE.Color();
617
588
 
618
- if ( chunk.id === COLOR_24 || chunk.id === LIN_COLOR_24 ) {
589
+ if ( subChunk.id === COLOR_24 || subChunk.id === LIN_COLOR_24 ) {
619
590
 
620
- const r = this.readByte( data );
621
- const g = this.readByte( data );
622
- const b = this.readByte( data );
591
+ const r = subChunk.readByte();
592
+ const g = subChunk.readByte();
593
+ const b = subChunk.readByte();
623
594
  color.setRGB( r / 255, g / 255, b / 255 );
624
595
  this.debugMessage( ' THREE.Color: ' + color.r + ', ' + color.g + ', ' + color.b );
625
596
 
626
- } else if ( chunk.id === COLOR_F || chunk.id === LIN_COLOR_F ) {
597
+ } else if ( subChunk.id === COLOR_F || subChunk.id === LIN_COLOR_F ) {
627
598
 
628
- const r = this.readFloat( data );
629
- const g = this.readFloat( data );
630
- const b = this.readFloat( data );
599
+ const r = subChunk.readFloat();
600
+ const g = subChunk.readFloat();
601
+ const b = subChunk.readFloat();
631
602
  color.setRGB( r, g, b );
632
603
  this.debugMessage( ' THREE.Color: ' + color.r + ', ' + color.g + ', ' + color.b );
633
604
 
634
605
  } else {
635
606
 
636
- this.debugMessage( ' Unknown color chunk: ' + chunk.toString( 16 ) );
607
+ this.debugMessage( ' Unknown color chunk: ' + subChunk.hexId );
637
608
 
638
609
  }
639
610
 
640
- this.endChunk( chunk );
641
611
  return color;
642
612
 
643
613
  }
644
614
  /**
645
- * Read next chunk of data.
615
+ * Read percentage value.
646
616
  *
647
- * @method readChunk
648
- * @param {DataView} data Dataview.
649
- * @return {Object} Chunk of data read.
617
+ * @method readPercentage
618
+ * @param {Chunk} chunk Chunk to read data from.
619
+ * @return {Number} Data read from the dataview.
650
620
  */
651
621
 
652
622
 
653
- readChunk( data ) {
623
+ readPercentage( chunk ) {
654
624
 
655
- const chunk = {};
656
- chunk.cur = this.position;
657
- chunk.id = this.readWord( data );
658
- chunk.size = this.readDWord( data );
659
- chunk.end = chunk.cur + chunk.size;
660
- chunk.cur += 6;
661
- return chunk;
625
+ const subChunk = chunk.readChunk();
626
+
627
+ switch ( subChunk.id ) {
628
+
629
+ case INT_PERCENTAGE:
630
+ return subChunk.readShort() / 100;
631
+ break;
632
+
633
+ case FLOAT_PERCENTAGE:
634
+ return subChunk.readFloat();
635
+ break;
636
+
637
+ default:
638
+ this.debugMessage( ' Unknown percentage chunk: ' + subChunk.hexId );
639
+ return 0;
640
+
641
+ }
662
642
 
663
643
  }
664
644
  /**
665
- * Set position to the end of the current chunk of data.
645
+ * Print debug message to the console.
646
+ *
647
+ * Is controlled by a flag to show or hide debug messages.
666
648
  *
667
- * @method endChunk
668
- * @param {Object} chunk Data chunk.
649
+ * @method debugMessage
650
+ * @param {Object} message Debug message to print to the console.
669
651
  */
670
652
 
671
653
 
672
- endChunk( chunk ) {
654
+ debugMessage( message ) {
655
+
656
+ if ( this.debug ) {
673
657
 
674
- this.position = chunk.end;
658
+ console.log( message );
659
+
660
+ }
675
661
 
676
662
  }
663
+
664
+ }
665
+ /** Read data/sub-chunks from chunk */
666
+
667
+
668
+ class Chunk {
669
+
677
670
  /**
678
- * Move to the next data chunk.
671
+ * Create a new chunk
679
672
  *
680
- * @method nextChunk
681
- * @param {DataView} data Dataview.
682
- * @param {Object} chunk Data chunk.
673
+ * @class Chunk
674
+ * @param {DataView} data DataView to read from.
675
+ * @param {Number} position in data.
676
+ * @param {Function} debugMessage logging callback.
683
677
  */
678
+ constructor( data, position, debugMessage ) {
684
679
 
680
+ this.data = data; // the offset to the begin of this chunk
685
681
 
686
- nextChunk( data, chunk ) {
682
+ this.offset = position; // the current reading position
687
683
 
688
- if ( chunk.cur >= chunk.end ) {
684
+ this.position = position;
685
+ this.debugMessage = debugMessage;
689
686
 
690
- return 0;
687
+ if ( this.debugMessage instanceof Function ) {
688
+
689
+ this.debugMessage = function () {};
690
+
691
+ }
692
+
693
+ this.id = this.readWord();
694
+ this.size = this.readDWord();
695
+ this.end = this.offset + this.size;
696
+
697
+ if ( this.end > data.byteLength ) {
698
+
699
+ this.debugMessage( 'Bad chunk size for chunk at ' + position );
691
700
 
692
701
  }
693
702
 
694
- this.position = chunk.cur;
703
+ }
704
+ /**
705
+ * read a sub cchunk.
706
+ *
707
+ * @method readChunk
708
+ * @return {Chunk | null} next sub chunk
709
+ */
710
+
711
+
712
+ readChunk() {
713
+
714
+ if ( this.endOfChunk ) {
715
+
716
+ return null;
717
+
718
+ }
695
719
 
696
720
  try {
697
721
 
698
- const next = this.readChunk( data );
699
- chunk.cur += next.size;
700
- return next.id;
722
+ const next = new Chunk( this.data, this.position, this.debugMessage );
723
+ this.position += next.size;
724
+ return next;
701
725
 
702
726
  } catch ( e ) {
703
727
 
704
728
  this.debugMessage( 'Unable to read chunk at ' + this.position );
705
- return 0;
729
+ return null;
706
730
 
707
731
  }
708
732
 
709
733
  }
710
734
  /**
711
- * Reset dataview position.
735
+ * return the ID of this chunk as Hex
712
736
  *
713
- * @method resetPosition
737
+ * @method idToString
738
+ * @return {String} hex-string of id
714
739
  */
715
740
 
716
741
 
717
- resetPosition() {
742
+ get hexId() {
718
743
 
719
- this.position -= 6;
744
+ return this.id.toString( 16 );
745
+
746
+ }
747
+
748
+ get endOfChunk() {
749
+
750
+ return this.position >= this.end;
720
751
 
721
752
  }
722
753
  /**
723
754
  * Read byte value.
724
755
  *
725
756
  * @method readByte
726
- * @param {DataView} data Dataview to read data from.
727
757
  * @return {Number} Data read from the dataview.
728
758
  */
729
759
 
730
760
 
731
- readByte( data ) {
761
+ readByte() {
732
762
 
733
- const v = data.getUint8( this.position, true );
763
+ const v = this.data.getUint8( this.position, true );
734
764
  this.position += 1;
735
765
  return v;
736
766
 
@@ -739,22 +769,22 @@
739
769
  * Read 32 bit float value.
740
770
  *
741
771
  * @method readFloat
742
- * @param {DataView} data Dataview to read data from.
743
772
  * @return {Number} Data read from the dataview.
744
773
  */
745
774
 
746
775
 
747
- readFloat( data ) {
776
+ readFloat() {
748
777
 
749
778
  try {
750
779
 
751
- const v = data.getFloat32( this.position, true );
780
+ const v = this.data.getFloat32( this.position, true );
752
781
  this.position += 4;
753
782
  return v;
754
783
 
755
784
  } catch ( e ) {
756
785
 
757
- this.debugMessage( e + ' ' + this.position + ' ' + data.byteLength );
786
+ this.debugMessage( e + ' ' + this.position + ' ' + this.data.byteLength );
787
+ return 0;
758
788
 
759
789
  }
760
790
 
@@ -763,14 +793,13 @@
763
793
  * Read 32 bit signed integer value.
764
794
  *
765
795
  * @method readInt
766
- * @param {DataView} data Dataview to read data from.
767
796
  * @return {Number} Data read from the dataview.
768
797
  */
769
798
 
770
799
 
771
- readInt( data ) {
800
+ readInt() {
772
801
 
773
- const v = data.getInt32( this.position, true );
802
+ const v = this.data.getInt32( this.position, true );
774
803
  this.position += 4;
775
804
  return v;
776
805
 
@@ -779,14 +808,13 @@
779
808
  * Read 16 bit signed integer value.
780
809
  *
781
810
  * @method readShort
782
- * @param {DataView} data Dataview to read data from.
783
811
  * @return {Number} Data read from the dataview.
784
812
  */
785
813
 
786
814
 
787
- readShort( data ) {
815
+ readShort() {
788
816
 
789
- const v = data.getInt16( this.position, true );
817
+ const v = this.data.getInt16( this.position, true );
790
818
  this.position += 2;
791
819
  return v;
792
820
 
@@ -795,14 +823,13 @@
795
823
  * Read 64 bit unsigned integer value.
796
824
  *
797
825
  * @method readDWord
798
- * @param {DataView} data Dataview to read data from.
799
826
  * @return {Number} Data read from the dataview.
800
827
  */
801
828
 
802
829
 
803
- readDWord( data ) {
830
+ readDWord() {
804
831
 
805
- const v = data.getUint32( this.position, true );
832
+ const v = this.data.getUint32( this.position, true );
806
833
  this.position += 4;
807
834
  return v;
808
835
 
@@ -811,101 +838,40 @@
811
838
  * Read 32 bit unsigned integer value.
812
839
  *
813
840
  * @method readWord
814
- * @param {DataView} data Dataview to read data from.
815
841
  * @return {Number} Data read from the dataview.
816
842
  */
817
843
 
818
844
 
819
- readWord( data ) {
845
+ readWord() {
820
846
 
821
- const v = data.getUint16( this.position, true );
847
+ const v = this.data.getUint16( this.position, true );
822
848
  this.position += 2;
823
849
  return v;
824
850
 
825
851
  }
826
852
  /**
827
- * Read string value.
853
+ * Read NULL terminated ASCII string value from chunk-pos.
828
854
  *
829
855
  * @method readString
830
- * @param {DataView} data Dataview to read data from.
831
- * @param {Number} maxLength Max size of the string to be read.
832
856
  * @return {String} Data read from the dataview.
833
857
  */
834
858
 
835
859
 
836
- readString( data, maxLength ) {
860
+ readString() {
837
861
 
838
862
  let s = '';
863
+ let c = this.readByte();
839
864
 
840
- for ( let i = 0; i < maxLength; i ++ ) {
841
-
842
- const c = this.readByte( data );
843
-
844
- if ( ! c ) {
845
-
846
- break;
847
-
848
- }
865
+ while ( c ) {
849
866
 
850
867
  s += String.fromCharCode( c );
868
+ c = this.readByte();
851
869
 
852
870
  }
853
871
 
854
872
  return s;
855
873
 
856
874
  }
857
- /**
858
- * Read percentage value.
859
- *
860
- * @method readPercentage
861
- * @param {DataView} data Dataview to read data from.
862
- * @return {Number} Data read from the dataview.
863
- */
864
-
865
-
866
- readPercentage( data ) {
867
-
868
- const chunk = this.readChunk( data );
869
- let value;
870
-
871
- switch ( chunk.id ) {
872
-
873
- case INT_PERCENTAGE:
874
- value = this.readShort( data ) / 100;
875
- break;
876
-
877
- case FLOAT_PERCENTAGE:
878
- value = this.readFloat( data );
879
- break;
880
-
881
- default:
882
- this.debugMessage( ' Unknown percentage chunk: ' + chunk.toString( 16 ) );
883
-
884
- }
885
-
886
- this.endChunk( chunk );
887
- return value;
888
-
889
- }
890
- /**
891
- * Print debug message to the console.
892
- *
893
- * Is controlled by a flag to show or hide debug messages.
894
- *
895
- * @method debugMessage
896
- * @param {Object} message Debug message to print to the console.
897
- */
898
-
899
-
900
- debugMessage( message ) {
901
-
902
- if ( this.debug ) {
903
-
904
- console.log( message );
905
-
906
- }
907
-
908
- }
909
875
 
910
876
  } // const NULL_CHUNK = 0x0000;
911
877