@anov/3d 0.0.1 → 0.0.2

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 (570) hide show
  1. package/README.md +142 -1
  2. package/dist/core/camera.d.ts +31 -4
  3. package/dist/core/camera.js +62 -52
  4. package/dist/core/control/transformControls.d.ts +12 -0
  5. package/dist/core/control/transformControls.js +72 -0
  6. package/dist/core/cssRenderer.d.ts +17 -0
  7. package/dist/core/cssRenderer.js +36 -0
  8. package/dist/core/global/global.d.ts +27 -0
  9. package/dist/core/global/global.js +72 -0
  10. package/dist/core/global/globalControl.d.ts +17 -0
  11. package/dist/core/global/globalControl.js +62 -0
  12. package/dist/core/group.d.ts +51 -6
  13. package/dist/core/group.js +124 -16
  14. package/dist/core/line.d.ts +13 -0
  15. package/dist/core/line.js +83 -0
  16. package/dist/core/mesh.d.ts +12 -7
  17. package/dist/core/mesh.js +57 -56
  18. package/dist/core/model.d.ts +11 -3
  19. package/dist/core/model.js +34 -7
  20. package/dist/core/scene.d.ts +84 -25
  21. package/dist/core/scene.js +207 -53
  22. package/dist/core/use/useScene.d.ts +10 -0
  23. package/dist/core/use/useScene.js +14 -0
  24. package/dist/core/use/useframe.d.ts +6 -0
  25. package/dist/core/use/useframe.js +11 -0
  26. package/dist/export.d.ts +41 -0
  27. package/dist/export.js +37 -0
  28. package/dist/index.d.ts +3 -6
  29. package/dist/index.js +5 -6
  30. package/dist/threeCell.d.ts +8 -0
  31. package/dist/threeCell.js +16 -0
  32. package/dist/type.d.ts +4 -3
  33. package/dist/utils/createElement.d.ts +103 -0
  34. package/dist/utils/createElement.js +145 -0
  35. package/dist/utils/createLabel.d.ts +2 -0
  36. package/dist/utils/createLabel.js +4 -0
  37. package/dist/utils/index.d.ts +36 -0
  38. package/dist/utils/index.js +76 -0
  39. package/dist/utils/line.d.ts +0 -0
  40. package/dist/utils/line.js +0 -0
  41. package/dist/utils/move.d.ts +48 -0
  42. package/dist/utils/move.js +149 -0
  43. package/examples/fonts/LICENSE +13 -0
  44. package/examples/fonts/README.md +11 -0
  45. package/examples/fonts/droid/NOTICE +190 -0
  46. package/examples/fonts/droid/README.txt +18 -0
  47. package/examples/fonts/droid/droid_sans_bold.typeface.json +1 -0
  48. package/examples/fonts/droid/droid_sans_mono_regular.typeface.json +1 -0
  49. package/examples/fonts/droid/droid_sans_regular.typeface.json +1 -0
  50. package/examples/fonts/droid/droid_serif_bold.typeface.json +1 -0
  51. package/examples/fonts/droid/droid_serif_regular.typeface.json +1 -0
  52. package/examples/fonts/gentilis_bold.typeface.json +1 -0
  53. package/examples/fonts/gentilis_regular.typeface.json +1 -0
  54. package/examples/fonts/helvetiker_bold.typeface.json +1 -0
  55. package/examples/fonts/helvetiker_regular.typeface.json +1 -0
  56. package/examples/fonts/optimer_bold.typeface.json +1 -0
  57. package/examples/fonts/optimer_regular.typeface.json +1 -0
  58. package/examples/fonts/ttf/README.md +9 -0
  59. package/examples/fonts/ttf/kenpixel.ttf +0 -0
  60. package/examples/jsm/animation/AnimationClipCreator.js +116 -0
  61. package/examples/jsm/animation/CCDIKSolver.js +482 -0
  62. package/examples/jsm/animation/MMDAnimationHelper.js +1207 -0
  63. package/examples/jsm/animation/MMDPhysics.js +1406 -0
  64. package/examples/jsm/cameras/CinematicCamera.js +208 -0
  65. package/examples/jsm/capabilities/WebGL.js +91 -0
  66. package/examples/jsm/capabilities/WebGPU.js +53 -0
  67. package/examples/jsm/controls/ArcballControls.js +3224 -0
  68. package/examples/jsm/controls/DragControls.js +220 -0
  69. package/examples/jsm/controls/FirstPersonControls.js +325 -0
  70. package/examples/jsm/controls/FlyControls.js +300 -0
  71. package/examples/jsm/controls/MapControls.js +28 -0
  72. package/examples/jsm/controls/OrbitControls.js +1388 -0
  73. package/examples/jsm/controls/PointerLockControls.js +162 -0
  74. package/examples/jsm/controls/TrackballControls.js +828 -0
  75. package/examples/jsm/controls/TransformControls.js +1557 -0
  76. package/examples/jsm/csm/CSM.js +384 -0
  77. package/examples/jsm/csm/CSMFrustum.js +152 -0
  78. package/examples/jsm/csm/CSMHelper.js +193 -0
  79. package/examples/jsm/csm/CSMShader.js +252 -0
  80. package/examples/jsm/curves/CurveExtras.js +422 -0
  81. package/examples/jsm/curves/NURBSCurve.js +80 -0
  82. package/examples/jsm/curves/NURBSSurface.js +52 -0
  83. package/examples/jsm/curves/NURBSUtils.js +487 -0
  84. package/examples/jsm/effects/AnaglyphEffect.js +154 -0
  85. package/examples/jsm/effects/AsciiEffect.js +263 -0
  86. package/examples/jsm/effects/OutlineEffect.js +539 -0
  87. package/examples/jsm/effects/ParallaxBarrierEffect.js +119 -0
  88. package/examples/jsm/effects/PeppersGhostEffect.js +153 -0
  89. package/examples/jsm/effects/StereoEffect.js +55 -0
  90. package/examples/jsm/environments/DebugEnvironment.js +52 -0
  91. package/examples/jsm/environments/RoomEnvironment.js +148 -0
  92. package/examples/jsm/exporters/DRACOExporter.js +267 -0
  93. package/examples/jsm/exporters/EXRExporter.js +501 -0
  94. package/examples/jsm/exporters/GLTFExporter.js +3161 -0
  95. package/examples/jsm/exporters/KTX2Exporter.js +292 -0
  96. package/examples/jsm/exporters/MMDExporter.js +217 -0
  97. package/examples/jsm/exporters/OBJExporter.js +284 -0
  98. package/examples/jsm/exporters/PLYExporter.js +528 -0
  99. package/examples/jsm/exporters/STLExporter.js +199 -0
  100. package/examples/jsm/exporters/USDZExporter.js +711 -0
  101. package/examples/jsm/geometries/BoxLineGeometry.js +69 -0
  102. package/examples/jsm/geometries/ConvexGeometry.js +53 -0
  103. package/examples/jsm/geometries/DecalGeometry.js +356 -0
  104. package/examples/jsm/geometries/ParametricGeometries.js +254 -0
  105. package/examples/jsm/geometries/ParametricGeometry.js +139 -0
  106. package/examples/jsm/geometries/RoundedBoxGeometry.js +155 -0
  107. package/examples/jsm/geometries/TeapotGeometry.js +704 -0
  108. package/examples/jsm/geometries/TextGeometry.js +57 -0
  109. package/examples/jsm/helpers/LightProbeHelper.js +130 -0
  110. package/examples/jsm/helpers/OctreeHelper.js +73 -0
  111. package/examples/jsm/helpers/PositionalAudioHelper.js +109 -0
  112. package/examples/jsm/helpers/RectAreaLightHelper.js +85 -0
  113. package/examples/jsm/helpers/VertexNormalsHelper.js +96 -0
  114. package/examples/jsm/helpers/VertexTangentsHelper.js +88 -0
  115. package/examples/jsm/helpers/ViewHelper.js +333 -0
  116. package/examples/jsm/interactive/HTMLMesh.js +565 -0
  117. package/examples/jsm/interactive/InteractiveGroup.js +116 -0
  118. package/examples/jsm/interactive/SelectionBox.js +227 -0
  119. package/examples/jsm/interactive/SelectionHelper.js +104 -0
  120. package/examples/jsm/libs/ammo.wasm.js +822 -0
  121. package/examples/jsm/libs/ammo.wasm.wasm +0 -0
  122. package/examples/jsm/libs/basis/README.md +46 -0
  123. package/examples/jsm/libs/basis/basis_transcoder.js +21 -0
  124. package/examples/jsm/libs/basis/basis_transcoder.wasm +0 -0
  125. package/examples/jsm/libs/chevrotain.module.min.js +141 -0
  126. package/examples/jsm/libs/draco/README.md +32 -0
  127. package/examples/jsm/libs/draco/draco_decoder.js +34 -0
  128. package/examples/jsm/libs/draco/draco_decoder.wasm +0 -0
  129. package/examples/jsm/libs/draco/draco_encoder.js +33 -0
  130. package/examples/jsm/libs/draco/draco_wasm_wrapper.js +117 -0
  131. package/examples/jsm/libs/draco/gltf/draco_decoder.js +33 -0
  132. package/examples/jsm/libs/draco/gltf/draco_decoder.wasm +0 -0
  133. package/examples/jsm/libs/draco/gltf/draco_encoder.js +33 -0
  134. package/examples/jsm/libs/draco/gltf/draco_wasm_wrapper.js +116 -0
  135. package/examples/jsm/libs/ecsy.module.js +1792 -0
  136. package/examples/jsm/libs/fflate.module.js +2474 -0
  137. package/examples/jsm/libs/ktx-parse.module.js +1 -0
  138. package/examples/jsm/libs/lil-gui.module.min.js +8 -0
  139. package/examples/jsm/libs/lottie_canvas.module.js +14844 -0
  140. package/examples/jsm/libs/meshopt_decoder.module.js +178 -0
  141. package/examples/jsm/libs/mikktspace.module.js +128 -0
  142. package/examples/jsm/libs/mmdparser.module.js +11530 -0
  143. package/examples/jsm/libs/motion-controllers.module.js +397 -0
  144. package/examples/jsm/libs/opentype.module.js +14568 -0
  145. package/examples/jsm/libs/potpack.module.js +125 -0
  146. package/examples/jsm/libs/rhino3dm/rhino3dm.js +21 -0
  147. package/examples/jsm/libs/rhino3dm/rhino3dm.module.js +16 -0
  148. package/examples/jsm/libs/rhino3dm/rhino3dm.wasm +0 -0
  149. package/examples/jsm/libs/stats.module.js +167 -0
  150. package/examples/jsm/libs/tween.module.js +803 -0
  151. package/examples/jsm/libs/utif.module.js +1579 -0
  152. package/examples/jsm/libs/zstddec.module.js +1 -0
  153. package/examples/jsm/lights/IESSpotLight.js +25 -0
  154. package/examples/jsm/lights/LightProbeGenerator.js +252 -0
  155. package/examples/jsm/lights/RectAreaLightUniformsLib.js +79 -0
  156. package/examples/jsm/lines/Line2.js +19 -0
  157. package/examples/jsm/lines/LineGeometry.js +79 -0
  158. package/examples/jsm/lines/LineMaterial.js +702 -0
  159. package/examples/jsm/lines/LineSegments2.js +361 -0
  160. package/examples/jsm/lines/LineSegmentsGeometry.js +241 -0
  161. package/examples/jsm/lines/Wireframe.js +56 -0
  162. package/examples/jsm/lines/WireframeGeometry2.js +24 -0
  163. package/examples/jsm/loaders/3DMLoader.js +1497 -0
  164. package/examples/jsm/loaders/3MFLoader.js +1478 -0
  165. package/examples/jsm/loaders/AMFLoader.js +521 -0
  166. package/examples/jsm/loaders/BVHLoader.js +437 -0
  167. package/examples/jsm/loaders/ColladaLoader.js +4122 -0
  168. package/examples/jsm/loaders/DDSLoader.js +274 -0
  169. package/examples/jsm/loaders/DRACOLoader.js +612 -0
  170. package/examples/jsm/loaders/EXRLoader.js +2309 -0
  171. package/examples/jsm/loaders/FBXLoader.js +4142 -0
  172. package/examples/jsm/loaders/FontLoader.js +183 -0
  173. package/examples/jsm/loaders/GCodeLoader.js +261 -0
  174. package/examples/jsm/loaders/GLTFLoader.js +4576 -0
  175. package/examples/jsm/loaders/HDRCubeTextureLoader.js +115 -0
  176. package/examples/jsm/loaders/IESLoader.js +337 -0
  177. package/examples/jsm/loaders/KMZLoader.js +130 -0
  178. package/examples/jsm/loaders/KTX2Loader.js +868 -0
  179. package/examples/jsm/loaders/KTXLoader.js +176 -0
  180. package/examples/jsm/loaders/LDrawLoader.js +2464 -0
  181. package/examples/jsm/loaders/LUT3dlLoader.js +151 -0
  182. package/examples/jsm/loaders/LUTCubeLoader.js +153 -0
  183. package/examples/jsm/loaders/LWOLoader.js +1052 -0
  184. package/examples/jsm/loaders/LogLuvLoader.js +606 -0
  185. package/examples/jsm/loaders/LottieLoader.js +77 -0
  186. package/examples/jsm/loaders/MD2Loader.js +399 -0
  187. package/examples/jsm/loaders/MDDLoader.js +102 -0
  188. package/examples/jsm/loaders/MMDLoader.js +2273 -0
  189. package/examples/jsm/loaders/MTLLoader.js +567 -0
  190. package/examples/jsm/loaders/MaterialXLoader.js +734 -0
  191. package/examples/jsm/loaders/NRRDLoader.js +699 -0
  192. package/examples/jsm/loaders/OBJLoader.js +905 -0
  193. package/examples/jsm/loaders/PCDLoader.js +467 -0
  194. package/examples/jsm/loaders/PDBLoader.js +232 -0
  195. package/examples/jsm/loaders/PLYLoader.js +771 -0
  196. package/examples/jsm/loaders/PVRLoader.js +251 -0
  197. package/examples/jsm/loaders/RGBELoader.js +468 -0
  198. package/examples/jsm/loaders/RGBMLoader.js +1065 -0
  199. package/examples/jsm/loaders/STLLoader.js +403 -0
  200. package/examples/jsm/loaders/SVGLoader.js +3172 -0
  201. package/examples/jsm/loaders/TDSLoader.js +1124 -0
  202. package/examples/jsm/loaders/TGALoader.js +517 -0
  203. package/examples/jsm/loaders/TIFFLoader.js +36 -0
  204. package/examples/jsm/loaders/TTFLoader.js +214 -0
  205. package/examples/jsm/loaders/TiltLoader.js +520 -0
  206. package/examples/jsm/loaders/USDZLoader.js +633 -0
  207. package/examples/jsm/loaders/VOXLoader.js +311 -0
  208. package/examples/jsm/loaders/VRMLLoader.js +3533 -0
  209. package/examples/jsm/loaders/VTKLoader.js +1163 -0
  210. package/examples/jsm/loaders/XYZLoader.js +106 -0
  211. package/examples/jsm/loaders/lwo/IFFParser.js +1218 -0
  212. package/examples/jsm/loaders/lwo/LWO2Parser.js +414 -0
  213. package/examples/jsm/loaders/lwo/LWO3Parser.js +373 -0
  214. package/examples/jsm/materials/MeshGouraudMaterial.js +420 -0
  215. package/examples/jsm/math/Capsule.js +137 -0
  216. package/examples/jsm/math/ColorConverter.js +36 -0
  217. package/examples/jsm/math/ConvexHull.js +1271 -0
  218. package/examples/jsm/math/ImprovedNoise.js +71 -0
  219. package/examples/jsm/math/Lut.js +204 -0
  220. package/examples/jsm/math/MeshSurfaceSampler.js +250 -0
  221. package/examples/jsm/math/OBB.js +423 -0
  222. package/examples/jsm/math/Octree.js +462 -0
  223. package/examples/jsm/math/SimplexNoise.js +444 -0
  224. package/examples/jsm/misc/ConvexObjectBreaker.js +519 -0
  225. package/examples/jsm/misc/GPUComputationRenderer.js +446 -0
  226. package/examples/jsm/misc/Gyroscope.js +66 -0
  227. package/examples/jsm/misc/MD2Character.js +276 -0
  228. package/examples/jsm/misc/MD2CharacterComplex.js +576 -0
  229. package/examples/jsm/misc/MorphAnimMesh.js +75 -0
  230. package/examples/jsm/misc/MorphBlendMesh.js +322 -0
  231. package/examples/jsm/misc/ProgressiveLightMap.js +323 -0
  232. package/examples/jsm/misc/RollerCoaster.js +566 -0
  233. package/examples/jsm/misc/TubePainter.js +205 -0
  234. package/examples/jsm/misc/Volume.js +473 -0
  235. package/examples/jsm/misc/VolumeSlice.js +229 -0
  236. package/examples/jsm/modifiers/CurveModifier.js +326 -0
  237. package/examples/jsm/modifiers/EdgeSplitModifier.js +279 -0
  238. package/examples/jsm/modifiers/SimplifyModifier.js +525 -0
  239. package/examples/jsm/modifiers/TessellateModifier.js +307 -0
  240. package/examples/jsm/nodes/Nodes.js +171 -0
  241. package/examples/jsm/nodes/accessors/BitangentNode.js +89 -0
  242. package/examples/jsm/nodes/accessors/BufferAttributeNode.js +99 -0
  243. package/examples/jsm/nodes/accessors/BufferNode.js +30 -0
  244. package/examples/jsm/nodes/accessors/CameraNode.js +98 -0
  245. package/examples/jsm/nodes/accessors/CubeTextureNode.js +103 -0
  246. package/examples/jsm/nodes/accessors/ExtendedMaterialNode.js +77 -0
  247. package/examples/jsm/nodes/accessors/InstanceNode.js +71 -0
  248. package/examples/jsm/nodes/accessors/MaterialNode.js +267 -0
  249. package/examples/jsm/nodes/accessors/MaterialReferenceNode.js +39 -0
  250. package/examples/jsm/nodes/accessors/ModelNode.js +34 -0
  251. package/examples/jsm/nodes/accessors/ModelViewProjectionNode.js +29 -0
  252. package/examples/jsm/nodes/accessors/MorphNode.js +70 -0
  253. package/examples/jsm/nodes/accessors/NormalNode.js +96 -0
  254. package/examples/jsm/nodes/accessors/Object3DNode.js +150 -0
  255. package/examples/jsm/nodes/accessors/PointUVNode.js +26 -0
  256. package/examples/jsm/nodes/accessors/PositionNode.js +104 -0
  257. package/examples/jsm/nodes/accessors/ReferenceNode.js +72 -0
  258. package/examples/jsm/nodes/accessors/ReflectVectorNode.js +35 -0
  259. package/examples/jsm/nodes/accessors/SceneNode.js +52 -0
  260. package/examples/jsm/nodes/accessors/SkinningNode.js +93 -0
  261. package/examples/jsm/nodes/accessors/StorageBufferNode.js +27 -0
  262. package/examples/jsm/nodes/accessors/TangentNode.js +103 -0
  263. package/examples/jsm/nodes/accessors/TextureBicubicNode.js +94 -0
  264. package/examples/jsm/nodes/accessors/TextureNode.js +271 -0
  265. package/examples/jsm/nodes/accessors/TextureSizeNode.js +35 -0
  266. package/examples/jsm/nodes/accessors/UVNode.js +47 -0
  267. package/examples/jsm/nodes/accessors/UserDataNode.js +29 -0
  268. package/examples/jsm/nodes/code/CodeNode.js +78 -0
  269. package/examples/jsm/nodes/code/ExpressionNode.js +37 -0
  270. package/examples/jsm/nodes/code/FunctionCallNode.js +96 -0
  271. package/examples/jsm/nodes/code/FunctionNode.js +127 -0
  272. package/examples/jsm/nodes/code/ScriptableNode.js +488 -0
  273. package/examples/jsm/nodes/code/ScriptableValueNode.js +167 -0
  274. package/examples/jsm/nodes/core/ArrayUniformNode.js +26 -0
  275. package/examples/jsm/nodes/core/AttributeNode.js +102 -0
  276. package/examples/jsm/nodes/core/BypassNode.js +45 -0
  277. package/examples/jsm/nodes/core/CacheNode.js +46 -0
  278. package/examples/jsm/nodes/core/ConstNode.js +32 -0
  279. package/examples/jsm/nodes/core/ContextNode.js +61 -0
  280. package/examples/jsm/nodes/core/IndexNode.js +66 -0
  281. package/examples/jsm/nodes/core/InputNode.js +83 -0
  282. package/examples/jsm/nodes/core/LightingModel.js +15 -0
  283. package/examples/jsm/nodes/core/Node.js +454 -0
  284. package/examples/jsm/nodes/core/NodeAttribute.js +15 -0
  285. package/examples/jsm/nodes/core/NodeBuilder.js +1016 -0
  286. package/examples/jsm/nodes/core/NodeCache.js +26 -0
  287. package/examples/jsm/nodes/core/NodeCode.js +15 -0
  288. package/examples/jsm/nodes/core/NodeFrame.js +110 -0
  289. package/examples/jsm/nodes/core/NodeFunction.js +22 -0
  290. package/examples/jsm/nodes/core/NodeFunctionInput.js +17 -0
  291. package/examples/jsm/nodes/core/NodeKeywords.js +80 -0
  292. package/examples/jsm/nodes/core/NodeParser.js +11 -0
  293. package/examples/jsm/nodes/core/NodeUniform.js +28 -0
  294. package/examples/jsm/nodes/core/NodeUtils.js +212 -0
  295. package/examples/jsm/nodes/core/NodeVar.js +14 -0
  296. package/examples/jsm/nodes/core/NodeVarying.js +17 -0
  297. package/examples/jsm/nodes/core/PropertyNode.js +61 -0
  298. package/examples/jsm/nodes/core/StackNode.js +99 -0
  299. package/examples/jsm/nodes/core/TempNode.js +58 -0
  300. package/examples/jsm/nodes/core/UniformNode.js +61 -0
  301. package/examples/jsm/nodes/core/VarNode.js +87 -0
  302. package/examples/jsm/nodes/core/VaryingNode.js +69 -0
  303. package/examples/jsm/nodes/core/constants.js +27 -0
  304. package/examples/jsm/nodes/display/BlendModeNode.js +99 -0
  305. package/examples/jsm/nodes/display/BumpMapNode.js +77 -0
  306. package/examples/jsm/nodes/display/ColorAdjustmentNode.js +100 -0
  307. package/examples/jsm/nodes/display/ColorSpaceNode.js +108 -0
  308. package/examples/jsm/nodes/display/FrontFacingNode.js +27 -0
  309. package/examples/jsm/nodes/display/NormalMapNode.js +106 -0
  310. package/examples/jsm/nodes/display/PosterizeNode.js +32 -0
  311. package/examples/jsm/nodes/display/ToneMappingNode.js +141 -0
  312. package/examples/jsm/nodes/display/ViewportDepthNode.js +69 -0
  313. package/examples/jsm/nodes/display/ViewportDepthTextureNode.js +34 -0
  314. package/examples/jsm/nodes/display/ViewportNode.js +115 -0
  315. package/examples/jsm/nodes/display/ViewportSharedTextureNode.js +31 -0
  316. package/examples/jsm/nodes/display/ViewportTextureNode.js +75 -0
  317. package/examples/jsm/nodes/fog/FogExp2Node.js +35 -0
  318. package/examples/jsm/nodes/fog/FogNode.js +37 -0
  319. package/examples/jsm/nodes/fog/FogRangeNode.js +34 -0
  320. package/examples/jsm/nodes/functions/BSDF/BRDF_GGX.js +40 -0
  321. package/examples/jsm/nodes/functions/BSDF/BRDF_Lambert.js +9 -0
  322. package/examples/jsm/nodes/functions/BSDF/BRDF_Sheen.js +43 -0
  323. package/examples/jsm/nodes/functions/BSDF/DFGApprox.js +29 -0
  324. package/examples/jsm/nodes/functions/BSDF/D_GGX.js +18 -0
  325. package/examples/jsm/nodes/functions/BSDF/EnvironmentBRDF.js +13 -0
  326. package/examples/jsm/nodes/functions/BSDF/F_Schlick.js +16 -0
  327. package/examples/jsm/nodes/functions/BSDF/Schlick_to_F0.js +13 -0
  328. package/examples/jsm/nodes/functions/BSDF/V_GGX_SmithCorrelated.js +20 -0
  329. package/examples/jsm/nodes/functions/PhongLightingModel.js +67 -0
  330. package/examples/jsm/nodes/functions/PhysicalLightingModel.js +343 -0
  331. package/examples/jsm/nodes/functions/material/getGeometryRoughness.js +13 -0
  332. package/examples/jsm/nodes/functions/material/getRoughness.js +18 -0
  333. package/examples/jsm/nodes/geometry/RangeNode.js +104 -0
  334. package/examples/jsm/nodes/gpgpu/ComputeNode.js +85 -0
  335. package/examples/jsm/nodes/lighting/AONode.js +27 -0
  336. package/examples/jsm/nodes/lighting/AmbientLightNode.js +27 -0
  337. package/examples/jsm/nodes/lighting/AnalyticLightNode.js +184 -0
  338. package/examples/jsm/nodes/lighting/DirectionalLightNode.js +40 -0
  339. package/examples/jsm/nodes/lighting/EnvironmentNode.js +191 -0
  340. package/examples/jsm/nodes/lighting/HemisphereLightNode.js +55 -0
  341. package/examples/jsm/nodes/lighting/IESSpotLightNode.js +39 -0
  342. package/examples/jsm/nodes/lighting/LightNode.js +57 -0
  343. package/examples/jsm/nodes/lighting/LightUtils.js +17 -0
  344. package/examples/jsm/nodes/lighting/LightingContextNode.js +102 -0
  345. package/examples/jsm/nodes/lighting/LightingNode.js +21 -0
  346. package/examples/jsm/nodes/lighting/LightsNode.js +128 -0
  347. package/examples/jsm/nodes/lighting/PointLightNode.js +68 -0
  348. package/examples/jsm/nodes/lighting/SpotLightNode.js +89 -0
  349. package/examples/jsm/nodes/loaders/NodeLoader.js +108 -0
  350. package/examples/jsm/nodes/loaders/NodeMaterialLoader.js +59 -0
  351. package/examples/jsm/nodes/loaders/NodeObjectLoader.js +70 -0
  352. package/examples/jsm/nodes/materials/LineBasicNodeMaterial.js +28 -0
  353. package/examples/jsm/nodes/materials/Materials.js +12 -0
  354. package/examples/jsm/nodes/materials/MeshBasicNodeMaterial.js +27 -0
  355. package/examples/jsm/nodes/materials/MeshLambertNodeMaterial.js +34 -0
  356. package/examples/jsm/nodes/materials/MeshNormalNodeMaterial.js +40 -0
  357. package/examples/jsm/nodes/materials/MeshPhongNodeMaterial.js +65 -0
  358. package/examples/jsm/nodes/materials/MeshPhysicalNodeMaterial.js +128 -0
  359. package/examples/jsm/nodes/materials/MeshStandardNodeMaterial.js +80 -0
  360. package/examples/jsm/nodes/materials/NodeMaterial.js +536 -0
  361. package/examples/jsm/nodes/materials/PointsNodeMaterial.js +49 -0
  362. package/examples/jsm/nodes/materials/SpriteNodeMaterial.js +103 -0
  363. package/examples/jsm/nodes/materialx/DISCLAIMER.md +199 -0
  364. package/examples/jsm/nodes/materialx/MaterialXNodes.js +68 -0
  365. package/examples/jsm/nodes/materialx/lib/mx_hsv.js +56 -0
  366. package/examples/jsm/nodes/materialx/lib/mx_noise.js +618 -0
  367. package/examples/jsm/nodes/materialx/lib/mx_transform_color.js +19 -0
  368. package/examples/jsm/nodes/math/CondNode.js +86 -0
  369. package/examples/jsm/nodes/math/MathNode.js +359 -0
  370. package/examples/jsm/nodes/math/OperatorNode.js +269 -0
  371. package/examples/jsm/nodes/parsers/GLSLNodeFunction.js +152 -0
  372. package/examples/jsm/nodes/parsers/GLSLNodeParser.js +14 -0
  373. package/examples/jsm/nodes/procedural/CheckerNode.js +42 -0
  374. package/examples/jsm/nodes/shadernode/ShaderNode.js +420 -0
  375. package/examples/jsm/nodes/utils/ArrayElementNode.js +33 -0
  376. package/examples/jsm/nodes/utils/ConvertNode.js +65 -0
  377. package/examples/jsm/nodes/utils/DiscardNode.js +26 -0
  378. package/examples/jsm/nodes/utils/EquirectUVNode.js +33 -0
  379. package/examples/jsm/nodes/utils/JoinNode.js +51 -0
  380. package/examples/jsm/nodes/utils/LoopNode.js +186 -0
  381. package/examples/jsm/nodes/utils/MatcapUVNode.js +30 -0
  382. package/examples/jsm/nodes/utils/MaxMipLevelNode.js +46 -0
  383. package/examples/jsm/nodes/utils/OscNode.js +81 -0
  384. package/examples/jsm/nodes/utils/PackingNode.js +55 -0
  385. package/examples/jsm/nodes/utils/RemapNode.js +42 -0
  386. package/examples/jsm/nodes/utils/RotateUVNode.js +43 -0
  387. package/examples/jsm/nodes/utils/SpecularMIPLevelNode.js +37 -0
  388. package/examples/jsm/nodes/utils/SplitNode.js +104 -0
  389. package/examples/jsm/nodes/utils/SpriteSheetUVNode.js +41 -0
  390. package/examples/jsm/nodes/utils/TimerNode.js +94 -0
  391. package/examples/jsm/nodes/utils/TriplanarTexturesNode.js +62 -0
  392. package/examples/jsm/objects/GroundProjectedSkybox.js +172 -0
  393. package/examples/jsm/objects/Lensflare.js +377 -0
  394. package/examples/jsm/objects/MarchingCubes.js +1176 -0
  395. package/examples/jsm/objects/Reflector.js +264 -0
  396. package/examples/jsm/objects/ReflectorForSSRPass.js +349 -0
  397. package/examples/jsm/objects/Refractor.js +324 -0
  398. package/examples/jsm/objects/ShadowMesh.js +80 -0
  399. package/examples/jsm/objects/Sky.js +219 -0
  400. package/examples/jsm/objects/Water.js +330 -0
  401. package/examples/jsm/objects/Water2.js +358 -0
  402. package/examples/jsm/offscreen/jank.js +45 -0
  403. package/examples/jsm/offscreen/offscreen.js +8 -0
  404. package/examples/jsm/offscreen/scene.js +86 -0
  405. package/examples/jsm/physics/AmmoPhysics.js +285 -0
  406. package/examples/jsm/physics/RapierPhysics.js +199 -0
  407. package/examples/jsm/postprocessing/AfterimagePass.js +104 -0
  408. package/examples/jsm/postprocessing/BloomPass.js +172 -0
  409. package/examples/jsm/postprocessing/BokehPass.js +140 -0
  410. package/examples/jsm/postprocessing/ClearPass.js +46 -0
  411. package/examples/jsm/postprocessing/CubeTexturePass.js +85 -0
  412. package/examples/jsm/postprocessing/DotScreenPass.js +65 -0
  413. package/examples/jsm/postprocessing/EffectComposer.js +231 -0
  414. package/examples/jsm/postprocessing/FilmPass.js +66 -0
  415. package/examples/jsm/postprocessing/GlitchPass.js +128 -0
  416. package/examples/jsm/postprocessing/HalftonePass.js +79 -0
  417. package/examples/jsm/postprocessing/LUTPass.js +173 -0
  418. package/examples/jsm/postprocessing/MaskPass.js +104 -0
  419. package/examples/jsm/postprocessing/OutlinePass.js +654 -0
  420. package/examples/jsm/postprocessing/OutputPass.js +91 -0
  421. package/examples/jsm/postprocessing/Pass.js +84 -0
  422. package/examples/jsm/postprocessing/RenderPass.js +81 -0
  423. package/examples/jsm/postprocessing/RenderPixelatedPass.js +235 -0
  424. package/examples/jsm/postprocessing/SAOPass.js +411 -0
  425. package/examples/jsm/postprocessing/SMAAPass.js +201 -0
  426. package/examples/jsm/postprocessing/SSAARenderPass.js +228 -0
  427. package/examples/jsm/postprocessing/SSAOPass.js +440 -0
  428. package/examples/jsm/postprocessing/SSRPass.js +641 -0
  429. package/examples/jsm/postprocessing/SavePass.js +79 -0
  430. package/examples/jsm/postprocessing/ShaderPass.js +77 -0
  431. package/examples/jsm/postprocessing/TAARenderPass.js +189 -0
  432. package/examples/jsm/postprocessing/TexturePass.js +67 -0
  433. package/examples/jsm/postprocessing/UnrealBloomPass.js +415 -0
  434. package/examples/jsm/renderers/CSS2DRenderer.js +215 -0
  435. package/examples/jsm/renderers/CSS3DRenderer.js +335 -0
  436. package/examples/jsm/renderers/Projector.js +918 -0
  437. package/examples/jsm/renderers/SVGRenderer.js +553 -0
  438. package/examples/jsm/renderers/common/Animation.js +58 -0
  439. package/examples/jsm/renderers/common/Attributes.js +75 -0
  440. package/examples/jsm/renderers/common/Backend.js +162 -0
  441. package/examples/jsm/renderers/common/Background.js +136 -0
  442. package/examples/jsm/renderers/common/Binding.js +19 -0
  443. package/examples/jsm/renderers/common/Bindings.js +165 -0
  444. package/examples/jsm/renderers/common/Buffer.js +38 -0
  445. package/examples/jsm/renderers/common/BufferUtils.js +33 -0
  446. package/examples/jsm/renderers/common/ChainMap.js +89 -0
  447. package/examples/jsm/renderers/common/ComputePipeline.js +17 -0
  448. package/examples/jsm/renderers/common/Constants.js +14 -0
  449. package/examples/jsm/renderers/common/CubeRenderTarget.js +65 -0
  450. package/examples/jsm/renderers/common/DataMap.js +54 -0
  451. package/examples/jsm/renderers/common/Geometries.js +215 -0
  452. package/examples/jsm/renderers/common/Info.js +73 -0
  453. package/examples/jsm/renderers/common/Pipeline.js +13 -0
  454. package/examples/jsm/renderers/common/Pipelines.js +370 -0
  455. package/examples/jsm/renderers/common/ProgrammableStage.js +18 -0
  456. package/examples/jsm/renderers/common/RenderContext.js +38 -0
  457. package/examples/jsm/renderers/common/RenderContexts.js +49 -0
  458. package/examples/jsm/renderers/common/RenderList.js +178 -0
  459. package/examples/jsm/renderers/common/RenderLists.js +38 -0
  460. package/examples/jsm/renderers/common/RenderObject.js +129 -0
  461. package/examples/jsm/renderers/common/RenderObjects.js +95 -0
  462. package/examples/jsm/renderers/common/RenderPipeline.js +16 -0
  463. package/examples/jsm/renderers/common/Renderer.js +895 -0
  464. package/examples/jsm/renderers/common/SampledTexture.js +80 -0
  465. package/examples/jsm/renderers/common/Sampler.js +18 -0
  466. package/examples/jsm/renderers/common/StorageBuffer.js +17 -0
  467. package/examples/jsm/renderers/common/Textures.js +218 -0
  468. package/examples/jsm/renderers/common/Uniform.js +140 -0
  469. package/examples/jsm/renderers/common/UniformBuffer.js +15 -0
  470. package/examples/jsm/renderers/common/UniformsGroup.js +299 -0
  471. package/examples/jsm/renderers/common/nodes/NodeSampledTexture.js +39 -0
  472. package/examples/jsm/renderers/common/nodes/NodeSampler.js +21 -0
  473. package/examples/jsm/renderers/common/nodes/NodeUniform.js +135 -0
  474. package/examples/jsm/renderers/common/nodes/Nodes.js +330 -0
  475. package/examples/jsm/renderers/webgl/nodes/GLSLNodeBuilder.js +340 -0
  476. package/examples/jsm/renderers/webgl/nodes/SlotNode.js +26 -0
  477. package/examples/jsm/renderers/webgl/nodes/WebGLNodeBuilder.js +764 -0
  478. package/examples/jsm/renderers/webgl/nodes/WebGLNodes.js +49 -0
  479. package/examples/jsm/renderers/webgpu/WebGPUBackend.js +844 -0
  480. package/examples/jsm/renderers/webgpu/WebGPURenderer.js +32 -0
  481. package/examples/jsm/renderers/webgpu/nodes/WGSLNodeBuilder.js +902 -0
  482. package/examples/jsm/renderers/webgpu/nodes/WGSLNodeFunction.js +104 -0
  483. package/examples/jsm/renderers/webgpu/nodes/WGSLNodeParser.js +14 -0
  484. package/examples/jsm/renderers/webgpu/utils/WebGPUAttributeUtils.js +274 -0
  485. package/examples/jsm/renderers/webgpu/utils/WebGPUBindingUtils.js +223 -0
  486. package/examples/jsm/renderers/webgpu/utils/WebGPUConstants.js +324 -0
  487. package/examples/jsm/renderers/webgpu/utils/WebGPUPipelineUtils.js +533 -0
  488. package/examples/jsm/renderers/webgpu/utils/WebGPUTextureMipmapUtils.js +163 -0
  489. package/examples/jsm/renderers/webgpu/utils/WebGPUTextureUtils.js +964 -0
  490. package/examples/jsm/renderers/webgpu/utils/WebGPUUtils.js +92 -0
  491. package/examples/jsm/shaders/ACESFilmicToneMappingShader.js +87 -0
  492. package/examples/jsm/shaders/AfterimageShader.js +56 -0
  493. package/examples/jsm/shaders/BasicShader.js +27 -0
  494. package/examples/jsm/shaders/BleachBypassShader.js +62 -0
  495. package/examples/jsm/shaders/BlendShader.js +47 -0
  496. package/examples/jsm/shaders/BokehShader.js +143 -0
  497. package/examples/jsm/shaders/BokehShader2.js +393 -0
  498. package/examples/jsm/shaders/BrightnessContrastShader.js +54 -0
  499. package/examples/jsm/shaders/ColorCorrectionShader.js +50 -0
  500. package/examples/jsm/shaders/ColorifyShader.js +51 -0
  501. package/examples/jsm/shaders/ConvolutionShader.js +103 -0
  502. package/examples/jsm/shaders/CopyShader.js +45 -0
  503. package/examples/jsm/shaders/DOFMipMapShader.js +54 -0
  504. package/examples/jsm/shaders/DepthLimitedBlurShader.js +166 -0
  505. package/examples/jsm/shaders/DigitalGlitch.js +101 -0
  506. package/examples/jsm/shaders/DotScreenShader.js +70 -0
  507. package/examples/jsm/shaders/ExposureShader.js +44 -0
  508. package/examples/jsm/shaders/FXAAShader.js +286 -0
  509. package/examples/jsm/shaders/FilmShader.js +102 -0
  510. package/examples/jsm/shaders/FocusShader.js +87 -0
  511. package/examples/jsm/shaders/FreiChenShader.js +94 -0
  512. package/examples/jsm/shaders/GammaCorrectionShader.js +43 -0
  513. package/examples/jsm/shaders/GodRaysShader.js +313 -0
  514. package/examples/jsm/shaders/HalftoneShader.js +310 -0
  515. package/examples/jsm/shaders/HorizontalBlurShader.js +59 -0
  516. package/examples/jsm/shaders/HorizontalTiltShiftShader.js +61 -0
  517. package/examples/jsm/shaders/HueSaturationShader.js +65 -0
  518. package/examples/jsm/shaders/KaleidoShader.js +56 -0
  519. package/examples/jsm/shaders/LuminosityHighPassShader.js +64 -0
  520. package/examples/jsm/shaders/LuminosityShader.js +46 -0
  521. package/examples/jsm/shaders/MMDToonShader.js +132 -0
  522. package/examples/jsm/shaders/MirrorShader.js +54 -0
  523. package/examples/jsm/shaders/NormalMapShader.js +53 -0
  524. package/examples/jsm/shaders/OutputShader.js +78 -0
  525. package/examples/jsm/shaders/RGBShiftShader.js +54 -0
  526. package/examples/jsm/shaders/SAOShader.js +188 -0
  527. package/examples/jsm/shaders/SMAAShader.js +460 -0
  528. package/examples/jsm/shaders/SSAOShader.js +288 -0
  529. package/examples/jsm/shaders/SSRShader.js +364 -0
  530. package/examples/jsm/shaders/SepiaShader.js +52 -0
  531. package/examples/jsm/shaders/SobelOperatorShader.js +90 -0
  532. package/examples/jsm/shaders/SubsurfaceScatteringShader.js +88 -0
  533. package/examples/jsm/shaders/TechnicolorShader.js +43 -0
  534. package/examples/jsm/shaders/ToonShader.js +326 -0
  535. package/examples/jsm/shaders/TriangleBlurShader.js +72 -0
  536. package/examples/jsm/shaders/UnpackDepthRGBAShader.js +45 -0
  537. package/examples/jsm/shaders/VelocityShader.js +128 -0
  538. package/examples/jsm/shaders/VerticalBlurShader.js +59 -0
  539. package/examples/jsm/shaders/VerticalTiltShiftShader.js +61 -0
  540. package/examples/jsm/shaders/VignetteShader.js +51 -0
  541. package/examples/jsm/shaders/VolumeShader.js +289 -0
  542. package/examples/jsm/shaders/WaterRefractionShader.js +93 -0
  543. package/examples/jsm/textures/FlakesTexture.js +40 -0
  544. package/examples/jsm/utils/BufferGeometryUtils.js +1373 -0
  545. package/examples/jsm/utils/CameraUtils.js +73 -0
  546. package/examples/jsm/utils/GPUStatsPanel.js +128 -0
  547. package/examples/jsm/utils/GeometryCompressionUtils.js +639 -0
  548. package/examples/jsm/utils/GeometryUtils.js +221 -0
  549. package/examples/jsm/utils/LDrawUtils.js +202 -0
  550. package/examples/jsm/utils/PackedPhongMaterial.js +178 -0
  551. package/examples/jsm/utils/SceneUtils.js +254 -0
  552. package/examples/jsm/utils/ShadowMapViewer.js +210 -0
  553. package/examples/jsm/utils/SkeletonUtils.js +413 -0
  554. package/examples/jsm/utils/TextureUtils.js +86 -0
  555. package/examples/jsm/utils/UVsDebug.js +165 -0
  556. package/examples/jsm/utils/WorkerPool.js +102 -0
  557. package/examples/jsm/webxr/ARButton.js +208 -0
  558. package/examples/jsm/webxr/OculusHandModel.js +109 -0
  559. package/examples/jsm/webxr/OculusHandPointerModel.js +413 -0
  560. package/examples/jsm/webxr/Text2D.js +38 -0
  561. package/examples/jsm/webxr/VRButton.js +200 -0
  562. package/examples/jsm/webxr/XRButton.js +198 -0
  563. package/examples/jsm/webxr/XRControllerModelFactory.js +299 -0
  564. package/examples/jsm/webxr/XREstimatedLight.js +223 -0
  565. package/examples/jsm/webxr/XRHandMeshModel.js +112 -0
  566. package/examples/jsm/webxr/XRHandModelFactory.js +105 -0
  567. package/examples/jsm/webxr/XRHandPrimitiveModel.js +103 -0
  568. package/examples/jsm/webxr/XRPlanes.js +100 -0
  569. package/lib/3d.min.js +1 -0
  570. package/package.json +25 -12
@@ -0,0 +1,1218 @@
1
+ /**
2
+ * === IFFParser ===
3
+ * - Parses data from the IFF buffer.
4
+ * - LWO3 files are in IFF format and can contain the following data types, referred to by shorthand codes
5
+ *
6
+ * ATOMIC DATA TYPES
7
+ * ID Tag - 4x 7 bit uppercase ASCII chars: ID4
8
+ * signed integer, 1, 2, or 4 byte length: I1, I2, I4
9
+ * unsigned integer, 1, 2, or 4 byte length: U1, U2, U4
10
+ * float, 4 byte length: F4
11
+ * string, series of ASCII chars followed by null byte (If the length of the string including the null terminating byte is odd, an extra null is added so that the data that follows will begin on an even byte boundary): S0
12
+ *
13
+ * COMPOUND DATA TYPES
14
+ * Variable-length Index (index into an array or collection): U2 or U4 : VX
15
+ * Color (RGB): F4 + F4 + F4: COL12
16
+ * Coordinate (x, y, z): F4 + F4 + F4: VEC12
17
+ * Percentage F4 data type from 0->1 with 1 = 100%: FP4
18
+ * Angle in radian F4: ANG4
19
+ * Filename (string) S0: FNAM0
20
+ * XValue F4 + index (VX) + optional envelope( ENVL ): XVAL
21
+ * XValue vector VEC12 + index (VX) + optional envelope( ENVL ): XVAL3
22
+ *
23
+ * The IFF file is arranged in chunks:
24
+ * CHUNK = ID4 + length (U4) + length X bytes of data + optional 0 pad byte
25
+ * optional 0 pad byte is there to ensure chunk ends on even boundary, not counted in size
26
+ *
27
+ * COMPOUND DATA TYPES
28
+ * - Chunks are combined in Forms (collections of chunks)
29
+ * - FORM = string 'FORM' (ID4) + length (U4) + type (ID4) + optional ( CHUNK | FORM )
30
+ * - CHUNKS and FORMS are collectively referred to as blocks
31
+ * - The entire file is contained in one top level FORM
32
+ *
33
+ **/
34
+
35
+ import { LWO2Parser } from './LWO2Parser.js';
36
+ import { LWO3Parser } from './LWO3Parser.js';
37
+
38
+ function IFFParser( ) {
39
+
40
+ this.debugger = new Debugger();
41
+ // this.debugger.enable(); // un-comment to log IFF hierarchy.
42
+
43
+ }
44
+
45
+ IFFParser.prototype = {
46
+
47
+ constructor: IFFParser,
48
+
49
+ parse: function ( buffer ) {
50
+
51
+ this.reader = new DataViewReader( buffer );
52
+
53
+ this.tree = {
54
+ materials: {},
55
+ layers: [],
56
+ tags: [],
57
+ textures: [],
58
+ };
59
+
60
+ // start out at the top level to add any data before first layer is encountered
61
+ this.currentLayer = this.tree;
62
+ this.currentForm = this.tree;
63
+
64
+ this.parseTopForm();
65
+
66
+ if ( this.tree.format === undefined ) return;
67
+
68
+ if ( this.tree.format === 'LWO2' ) {
69
+
70
+ this.parser = new LWO2Parser( this );
71
+ while ( ! this.reader.endOfFile() ) this.parser.parseBlock();
72
+
73
+ } else if ( this.tree.format === 'LWO3' ) {
74
+
75
+ this.parser = new LWO3Parser( this );
76
+ while ( ! this.reader.endOfFile() ) this.parser.parseBlock();
77
+
78
+ }
79
+
80
+ this.debugger.offset = this.reader.offset;
81
+ this.debugger.closeForms();
82
+
83
+ return this.tree;
84
+
85
+ },
86
+
87
+ parseTopForm() {
88
+
89
+ this.debugger.offset = this.reader.offset;
90
+
91
+ var topForm = this.reader.getIDTag();
92
+
93
+ if ( topForm !== 'FORM' ) {
94
+
95
+ console.warn( 'LWOLoader: Top-level FORM missing.' );
96
+ return;
97
+
98
+ }
99
+
100
+ var length = this.reader.getUint32();
101
+
102
+ this.debugger.dataOffset = this.reader.offset;
103
+ this.debugger.length = length;
104
+
105
+ var type = this.reader.getIDTag();
106
+
107
+ if ( type === 'LWO2' ) {
108
+
109
+ this.tree.format = type;
110
+
111
+ } else if ( type === 'LWO3' ) {
112
+
113
+ this.tree.format = type;
114
+
115
+ }
116
+
117
+ this.debugger.node = 0;
118
+ this.debugger.nodeID = type;
119
+ this.debugger.log();
120
+
121
+ return;
122
+
123
+ },
124
+
125
+
126
+ ///
127
+ // FORM PARSING METHODS
128
+ ///
129
+
130
+ // Forms are organisational and can contain any number of sub chunks and sub forms
131
+ // FORM ::= 'FORM'[ID4], length[U4], type[ID4], ( chunk[CHUNK] | form[FORM] ) * }
132
+ parseForm( length ) {
133
+
134
+ var type = this.reader.getIDTag();
135
+
136
+ switch ( type ) {
137
+
138
+ // SKIPPED FORMS
139
+ // if skipForm( length ) is called, the entire form and any sub forms and chunks are skipped
140
+
141
+ case 'ISEQ': // Image sequence
142
+ case 'ANIM': // plug in animation
143
+ case 'STCC': // Color-cycling Still
144
+ case 'VPVL':
145
+ case 'VPRM':
146
+ case 'NROT':
147
+ case 'WRPW': // image wrap w ( for cylindrical and spherical projections)
148
+ case 'WRPH': // image wrap h
149
+ case 'FUNC':
150
+ case 'FALL':
151
+ case 'OPAC':
152
+ case 'GRAD': // gradient texture
153
+ case 'ENVS':
154
+ case 'VMOP':
155
+ case 'VMBG':
156
+
157
+ // Car Material FORMS
158
+ case 'OMAX':
159
+ case 'STEX':
160
+ case 'CKBG':
161
+ case 'CKEY':
162
+ case 'VMLA':
163
+ case 'VMLB':
164
+ this.debugger.skipped = true;
165
+ this.skipForm( length ); // not currently supported
166
+ break;
167
+
168
+ // if break; is called directly, the position in the lwoTree is not created
169
+ // any sub chunks and forms are added to the parent form instead
170
+ case 'META':
171
+ case 'NNDS':
172
+ case 'NODS':
173
+ case 'NDTA':
174
+ case 'ADAT':
175
+ case 'AOVS':
176
+ case 'BLOK':
177
+
178
+ // used by texture nodes
179
+ case 'IBGC': // imageBackgroundColor
180
+ case 'IOPC': // imageOpacity
181
+ case 'IIMG': // hold reference to image path
182
+ case 'TXTR':
183
+ // this.setupForm( type, length );
184
+ this.debugger.length = 4;
185
+ this.debugger.skipped = true;
186
+ break;
187
+
188
+ case 'IFAL': // imageFallof
189
+ case 'ISCL': // imageScale
190
+ case 'IPOS': // imagePosition
191
+ case 'IROT': // imageRotation
192
+ case 'IBMP':
193
+ case 'IUTD':
194
+ case 'IVTD':
195
+ this.parseTextureNodeAttribute( type );
196
+ break;
197
+
198
+ case 'ENVL':
199
+ this.parseEnvelope( length );
200
+ break;
201
+
202
+ // CLIP FORM AND SUB FORMS
203
+
204
+ case 'CLIP':
205
+ if ( this.tree.format === 'LWO2' ) {
206
+
207
+ this.parseForm( length );
208
+
209
+ } else {
210
+
211
+ this.parseClip( length );
212
+
213
+ }
214
+
215
+ break;
216
+
217
+ case 'STIL':
218
+ this.parseImage();
219
+ break;
220
+
221
+ case 'XREF': // clone of another STIL
222
+ this.reader.skip( 8 ); // unknown
223
+ this.currentForm.referenceTexture = {
224
+ index: this.reader.getUint32(),
225
+ refName: this.reader.getString() // internal unique ref
226
+ };
227
+ break;
228
+
229
+ // Not in spec, used by texture nodes
230
+
231
+ case 'IMST':
232
+ this.parseImageStateForm( length );
233
+ break;
234
+
235
+ // SURF FORM AND SUB FORMS
236
+
237
+ case 'SURF':
238
+ this.parseSurfaceForm( length );
239
+ break;
240
+
241
+ case 'VALU': // Not in spec
242
+ this.parseValueForm( length );
243
+ break;
244
+
245
+ case 'NTAG':
246
+ this.parseSubNode( length );
247
+ break;
248
+
249
+ case 'ATTR': // BSDF Node Attributes
250
+ case 'SATR': // Standard Node Attributes
251
+ this.setupForm( 'attributes', length );
252
+ break;
253
+
254
+ case 'NCON':
255
+ this.parseConnections( length );
256
+ break;
257
+
258
+ case 'SSHA':
259
+ this.parentForm = this.currentForm;
260
+ this.currentForm = this.currentSurface;
261
+ this.setupForm( 'surfaceShader', length );
262
+ break;
263
+
264
+ case 'SSHD':
265
+ this.setupForm( 'surfaceShaderData', length );
266
+ break;
267
+
268
+ case 'ENTR': // Not in spec
269
+ this.parseEntryForm( length );
270
+ break;
271
+
272
+ // Image Map Layer
273
+
274
+ case 'IMAP':
275
+ this.parseImageMap( length );
276
+ break;
277
+
278
+ case 'TAMP':
279
+ this.parseXVAL( 'amplitude', length );
280
+ break;
281
+
282
+ //Texture Mapping Form
283
+
284
+ case 'TMAP':
285
+ this.setupForm( 'textureMap', length );
286
+ break;
287
+
288
+ case 'CNTR':
289
+ this.parseXVAL3( 'center', length );
290
+ break;
291
+
292
+ case 'SIZE':
293
+ this.parseXVAL3( 'scale', length );
294
+ break;
295
+
296
+ case 'ROTA':
297
+ this.parseXVAL3( 'rotation', length );
298
+ break;
299
+
300
+ default:
301
+ this.parseUnknownForm( type, length );
302
+
303
+ }
304
+
305
+ this.debugger.node = 0;
306
+ this.debugger.nodeID = type;
307
+ this.debugger.log();
308
+
309
+ },
310
+
311
+ setupForm( type, length ) {
312
+
313
+ if ( ! this.currentForm ) this.currentForm = this.currentNode;
314
+
315
+ this.currentFormEnd = this.reader.offset + length;
316
+ this.parentForm = this.currentForm;
317
+
318
+ if ( ! this.currentForm[ type ] ) {
319
+
320
+ this.currentForm[ type ] = {};
321
+ this.currentForm = this.currentForm[ type ];
322
+
323
+
324
+ } else {
325
+
326
+ // should never see this unless there's a bug in the reader
327
+ console.warn( 'LWOLoader: form already exists on parent: ', type, this.currentForm );
328
+
329
+ this.currentForm = this.currentForm[ type ];
330
+
331
+ }
332
+
333
+
334
+ },
335
+
336
+ skipForm( length ) {
337
+
338
+ this.reader.skip( length - 4 );
339
+
340
+ },
341
+
342
+ parseUnknownForm( type, length ) {
343
+
344
+ console.warn( 'LWOLoader: unknown FORM encountered: ' + type, length );
345
+
346
+ printBuffer( this.reader.dv.buffer, this.reader.offset, length - 4 );
347
+ this.reader.skip( length - 4 );
348
+
349
+ },
350
+
351
+ parseSurfaceForm( length ) {
352
+
353
+ this.reader.skip( 8 ); // unknown Uint32 x2
354
+
355
+ var name = this.reader.getString();
356
+
357
+ var surface = {
358
+ attributes: {}, // LWO2 style non-node attributes will go here
359
+ connections: {},
360
+ name: name,
361
+ inputName: name,
362
+ nodes: {},
363
+ source: this.reader.getString(),
364
+ };
365
+
366
+ this.tree.materials[ name ] = surface;
367
+ this.currentSurface = surface;
368
+
369
+ this.parentForm = this.tree.materials;
370
+ this.currentForm = surface;
371
+ this.currentFormEnd = this.reader.offset + length;
372
+
373
+ },
374
+
375
+ parseSurfaceLwo2( length ) {
376
+
377
+ var name = this.reader.getString();
378
+
379
+ var surface = {
380
+ attributes: {}, // LWO2 style non-node attributes will go here
381
+ connections: {},
382
+ name: name,
383
+ nodes: {},
384
+ source: this.reader.getString(),
385
+ };
386
+
387
+ this.tree.materials[ name ] = surface;
388
+ this.currentSurface = surface;
389
+
390
+ this.parentForm = this.tree.materials;
391
+ this.currentForm = surface;
392
+ this.currentFormEnd = this.reader.offset + length;
393
+
394
+ },
395
+
396
+ parseSubNode( length ) {
397
+
398
+ // parse the NRNM CHUNK of the subnode FORM to get
399
+ // a meaningful name for the subNode
400
+ // some subnodes can be renamed, but Input and Surface cannot
401
+
402
+ this.reader.skip( 8 ); // NRNM + length
403
+ var name = this.reader.getString();
404
+
405
+ var node = {
406
+ name: name
407
+ };
408
+ this.currentForm = node;
409
+ this.currentNode = node;
410
+
411
+ this.currentFormEnd = this.reader.offset + length;
412
+
413
+
414
+ },
415
+
416
+ // collect attributes from all nodes at the top level of a surface
417
+ parseConnections( length ) {
418
+
419
+ this.currentFormEnd = this.reader.offset + length;
420
+ this.parentForm = this.currentForm;
421
+
422
+ this.currentForm = this.currentSurface.connections;
423
+
424
+ },
425
+
426
+ // surface node attribute data, e.g. specular, roughness etc
427
+ parseEntryForm( length ) {
428
+
429
+ this.reader.skip( 8 ); // NAME + length
430
+ var name = this.reader.getString();
431
+ this.currentForm = this.currentNode.attributes;
432
+
433
+ this.setupForm( name, length );
434
+
435
+ },
436
+
437
+ // parse values from material - doesn't match up to other LWO3 data types
438
+ // sub form of entry form
439
+ parseValueForm() {
440
+
441
+ this.reader.skip( 8 ); // unknown + length
442
+
443
+ var valueType = this.reader.getString();
444
+
445
+ if ( valueType === 'double' ) {
446
+
447
+ this.currentForm.value = this.reader.getUint64();
448
+
449
+ } else if ( valueType === 'int' ) {
450
+
451
+ this.currentForm.value = this.reader.getUint32();
452
+
453
+ } else if ( valueType === 'vparam' ) {
454
+
455
+ this.reader.skip( 24 );
456
+ this.currentForm.value = this.reader.getFloat64();
457
+
458
+ } else if ( valueType === 'vparam3' ) {
459
+
460
+ this.reader.skip( 24 );
461
+ this.currentForm.value = this.reader.getFloat64Array( 3 );
462
+
463
+ }
464
+
465
+ },
466
+
467
+ // holds various data about texture node image state
468
+ // Data other thanmipMapLevel unknown
469
+ parseImageStateForm() {
470
+
471
+ this.reader.skip( 8 ); // unknown
472
+
473
+ this.currentForm.mipMapLevel = this.reader.getFloat32();
474
+
475
+ },
476
+
477
+ // LWO2 style image data node OR LWO3 textures defined at top level in editor (not as SURF node)
478
+ parseImageMap( length ) {
479
+
480
+ this.currentFormEnd = this.reader.offset + length;
481
+ this.parentForm = this.currentForm;
482
+
483
+ if ( ! this.currentForm.maps ) this.currentForm.maps = [];
484
+
485
+ var map = {};
486
+ this.currentForm.maps.push( map );
487
+ this.currentForm = map;
488
+
489
+ this.reader.skip( 10 ); // unknown, could be an issue if it contains a VX
490
+
491
+ },
492
+
493
+ parseTextureNodeAttribute( type ) {
494
+
495
+ this.reader.skip( 28 ); // FORM + length + VPRM + unknown + Uint32 x2 + float32
496
+
497
+ this.reader.skip( 20 ); // FORM + length + VPVL + float32 + Uint32
498
+
499
+ switch ( type ) {
500
+
501
+ case 'ISCL':
502
+ this.currentNode.scale = this.reader.getFloat32Array( 3 );
503
+ break;
504
+ case 'IPOS':
505
+ this.currentNode.position = this.reader.getFloat32Array( 3 );
506
+ break;
507
+ case 'IROT':
508
+ this.currentNode.rotation = this.reader.getFloat32Array( 3 );
509
+ break;
510
+ case 'IFAL':
511
+ this.currentNode.falloff = this.reader.getFloat32Array( 3 );
512
+ break;
513
+
514
+ case 'IBMP':
515
+ this.currentNode.amplitude = this.reader.getFloat32();
516
+ break;
517
+ case 'IUTD':
518
+ this.currentNode.uTiles = this.reader.getFloat32();
519
+ break;
520
+ case 'IVTD':
521
+ this.currentNode.vTiles = this.reader.getFloat32();
522
+ break;
523
+
524
+ }
525
+
526
+ this.reader.skip( 2 ); // unknown
527
+
528
+
529
+ },
530
+
531
+ // ENVL forms are currently ignored
532
+ parseEnvelope( length ) {
533
+
534
+ this.reader.skip( length - 4 ); // skipping entirely for now
535
+
536
+ },
537
+
538
+ ///
539
+ // CHUNK PARSING METHODS
540
+ ///
541
+
542
+ // clips can either be defined inside a surface node, or at the top
543
+ // level and they have a different format in each case
544
+ parseClip( length ) {
545
+
546
+ var tag = this.reader.getIDTag();
547
+
548
+ // inside surface node
549
+ if ( tag === 'FORM' ) {
550
+
551
+ this.reader.skip( 16 );
552
+
553
+ this.currentNode.fileName = this.reader.getString();
554
+
555
+ return;
556
+
557
+ }
558
+
559
+ // otherwise top level
560
+ this.reader.setOffset( this.reader.offset - 4 );
561
+
562
+ this.currentFormEnd = this.reader.offset + length;
563
+ this.parentForm = this.currentForm;
564
+
565
+ this.reader.skip( 8 ); // unknown
566
+
567
+ var texture = {
568
+ index: this.reader.getUint32()
569
+ };
570
+ this.tree.textures.push( texture );
571
+ this.currentForm = texture;
572
+
573
+ },
574
+
575
+ parseClipLwo2( length ) {
576
+
577
+ var texture = {
578
+ index: this.reader.getUint32(),
579
+ fileName: ''
580
+ };
581
+
582
+ // seach STIL block
583
+ while ( true ) {
584
+
585
+ var tag = this.reader.getIDTag();
586
+ var n_length = this.reader.getUint16();
587
+ if ( tag === 'STIL' ) {
588
+
589
+ texture.fileName = this.reader.getString();
590
+ break;
591
+
592
+ }
593
+
594
+ if ( n_length >= length ) {
595
+
596
+ break;
597
+
598
+ }
599
+
600
+ }
601
+
602
+ this.tree.textures.push( texture );
603
+ this.currentForm = texture;
604
+
605
+ },
606
+
607
+ parseImage() {
608
+
609
+ this.reader.skip( 8 ); // unknown
610
+ this.currentForm.fileName = this.reader.getString();
611
+
612
+ },
613
+
614
+ parseXVAL( type, length ) {
615
+
616
+ var endOffset = this.reader.offset + length - 4;
617
+ this.reader.skip( 8 );
618
+
619
+ this.currentForm[ type ] = this.reader.getFloat32();
620
+
621
+ this.reader.setOffset( endOffset ); // set end offset directly to skip optional envelope
622
+
623
+ },
624
+
625
+ parseXVAL3( type, length ) {
626
+
627
+ var endOffset = this.reader.offset + length - 4;
628
+ this.reader.skip( 8 );
629
+
630
+ this.currentForm[ type ] = {
631
+ x: this.reader.getFloat32(),
632
+ y: this.reader.getFloat32(),
633
+ z: this.reader.getFloat32(),
634
+ };
635
+
636
+ this.reader.setOffset( endOffset );
637
+
638
+ },
639
+
640
+ // Tags associated with an object
641
+ // OTAG { type[ID4], tag-string[S0] }
642
+ parseObjectTag() {
643
+
644
+ if ( ! this.tree.objectTags ) this.tree.objectTags = {};
645
+
646
+ this.tree.objectTags[ this.reader.getIDTag() ] = {
647
+ tagString: this.reader.getString()
648
+ };
649
+
650
+ },
651
+
652
+ // Signals the start of a new layer. All the data chunks which follow will be included in this layer until another layer chunk is encountered.
653
+ // LAYR: number[U2], flags[U2], pivot[VEC12], name[S0], parent[U2]
654
+ parseLayer( length ) {
655
+
656
+ var layer = {
657
+ number: this.reader.getUint16(),
658
+ flags: this.reader.getUint16(), // If the least significant bit of flags is set, the layer is hidden.
659
+ pivot: this.reader.getFloat32Array( 3 ), // Note: this seems to be superflous, as the geometry is translated when pivot is present
660
+ name: this.reader.getString(),
661
+ };
662
+
663
+ this.tree.layers.push( layer );
664
+ this.currentLayer = layer;
665
+
666
+ var parsedLength = 16 + stringOffset( this.currentLayer.name ); // index ( 2 ) + flags( 2 ) + pivot( 12 ) + stringlength
667
+
668
+ // if we have not reached then end of the layer block, there must be a parent defined
669
+ this.currentLayer.parent = ( parsedLength < length ) ? this.reader.getUint16() : - 1; // omitted or -1 for no parent
670
+
671
+ },
672
+
673
+ // VEC12 * ( F4 + F4 + F4 ) array of x,y,z vectors
674
+ // Converting from left to right handed coordinate system:
675
+ // x -> -x and switch material FrontSide -> BackSide
676
+ parsePoints( length ) {
677
+
678
+ this.currentPoints = [];
679
+ for ( var i = 0; i < length / 4; i += 3 ) {
680
+
681
+ // z -> -z to match three.js right handed coords
682
+ this.currentPoints.push( this.reader.getFloat32(), this.reader.getFloat32(), - this.reader.getFloat32() );
683
+
684
+ }
685
+
686
+ },
687
+
688
+ // parse VMAP or VMAD
689
+ // Associates a set of floating-point vectors with a set of points.
690
+ // VMAP: { type[ID4], dimension[U2], name[S0], ( vert[VX], value[F4] # dimension ) * }
691
+
692
+ // VMAD Associates a set of floating-point vectors with the vertices of specific polygons.
693
+ // Similar to VMAP UVs, but associates with polygon vertices rather than points
694
+ // to solve to problem of UV seams: VMAD chunks are paired with VMAPs of the same name,
695
+ // if they exist. The vector values in the VMAD will then replace those in the
696
+ // corresponding VMAP, but only for calculations involving the specified polygons.
697
+ // VMAD { type[ID4], dimension[U2], name[S0], ( vert[VX], poly[VX], value[F4] # dimension ) * }
698
+ parseVertexMapping( length, discontinuous ) {
699
+
700
+ var finalOffset = this.reader.offset + length;
701
+
702
+ var channelName = this.reader.getString();
703
+
704
+ if ( this.reader.offset === finalOffset ) {
705
+
706
+ // then we are in a texture node and the VMAP chunk is just a reference to a UV channel name
707
+ this.currentForm.UVChannel = channelName;
708
+ return;
709
+
710
+ }
711
+
712
+ // otherwise reset to initial length and parse normal VMAP CHUNK
713
+ this.reader.setOffset( this.reader.offset - stringOffset( channelName ) );
714
+
715
+ var type = this.reader.getIDTag();
716
+
717
+ this.reader.getUint16(); // dimension
718
+ var name = this.reader.getString();
719
+
720
+ var remainingLength = length - 6 - stringOffset( name );
721
+
722
+ switch ( type ) {
723
+
724
+ case 'TXUV':
725
+ this.parseUVMapping( name, finalOffset, discontinuous );
726
+ break;
727
+ case 'MORF':
728
+ case 'SPOT':
729
+ this.parseMorphTargets( name, finalOffset, type ); // can't be discontinuous
730
+ break;
731
+ // unsupported VMAPs
732
+ case 'APSL':
733
+ case 'NORM':
734
+ case 'WGHT':
735
+ case 'MNVW':
736
+ case 'PICK':
737
+ case 'RGB ':
738
+ case 'RGBA':
739
+ this.reader.skip( remainingLength );
740
+ break;
741
+ default:
742
+ console.warn( 'LWOLoader: unknown vertex map type: ' + type );
743
+ this.reader.skip( remainingLength );
744
+
745
+ }
746
+
747
+ },
748
+
749
+ parseUVMapping( name, finalOffset, discontinuous ) {
750
+
751
+ var uvIndices = [];
752
+ var polyIndices = [];
753
+ var uvs = [];
754
+
755
+ while ( this.reader.offset < finalOffset ) {
756
+
757
+ uvIndices.push( this.reader.getVariableLengthIndex() );
758
+
759
+ if ( discontinuous ) polyIndices.push( this.reader.getVariableLengthIndex() );
760
+
761
+ uvs.push( this.reader.getFloat32(), this.reader.getFloat32() );
762
+
763
+ }
764
+
765
+ if ( discontinuous ) {
766
+
767
+ if ( ! this.currentLayer.discontinuousUVs ) this.currentLayer.discontinuousUVs = {};
768
+
769
+ this.currentLayer.discontinuousUVs[ name ] = {
770
+ uvIndices: uvIndices,
771
+ polyIndices: polyIndices,
772
+ uvs: uvs,
773
+ };
774
+
775
+ } else {
776
+
777
+ if ( ! this.currentLayer.uvs ) this.currentLayer.uvs = {};
778
+
779
+ this.currentLayer.uvs[ name ] = {
780
+ uvIndices: uvIndices,
781
+ uvs: uvs,
782
+ };
783
+
784
+ }
785
+
786
+ },
787
+
788
+ parseMorphTargets( name, finalOffset, type ) {
789
+
790
+ var indices = [];
791
+ var points = [];
792
+
793
+ type = ( type === 'MORF' ) ? 'relative' : 'absolute';
794
+
795
+ while ( this.reader.offset < finalOffset ) {
796
+
797
+ indices.push( this.reader.getVariableLengthIndex() );
798
+ // z -> -z to match three.js right handed coords
799
+ points.push( this.reader.getFloat32(), this.reader.getFloat32(), - this.reader.getFloat32() );
800
+
801
+ }
802
+
803
+ if ( ! this.currentLayer.morphTargets ) this.currentLayer.morphTargets = {};
804
+
805
+ this.currentLayer.morphTargets[ name ] = {
806
+ indices: indices,
807
+ points: points,
808
+ type: type,
809
+ };
810
+
811
+ },
812
+
813
+ // A list of polygons for the current layer.
814
+ // POLS { type[ID4], ( numvert+flags[U2], vert[VX] # numvert ) * }
815
+ parsePolygonList( length ) {
816
+
817
+ var finalOffset = this.reader.offset + length;
818
+ var type = this.reader.getIDTag();
819
+
820
+ var indices = [];
821
+
822
+ // hold a list of polygon sizes, to be split up later
823
+ var polygonDimensions = [];
824
+
825
+ while ( this.reader.offset < finalOffset ) {
826
+
827
+ var numverts = this.reader.getUint16();
828
+
829
+ //var flags = numverts & 64512; // 6 high order bits are flags - ignoring for now
830
+ numverts = numverts & 1023; // remaining ten low order bits are vertex num
831
+ polygonDimensions.push( numverts );
832
+
833
+ for ( var j = 0; j < numverts; j ++ ) indices.push( this.reader.getVariableLengthIndex() );
834
+
835
+ }
836
+
837
+ var geometryData = {
838
+ type: type,
839
+ vertexIndices: indices,
840
+ polygonDimensions: polygonDimensions,
841
+ points: this.currentPoints
842
+ };
843
+
844
+ // Note: assuming that all polys will be lines or points if the first is
845
+ if ( polygonDimensions[ 0 ] === 1 ) geometryData.type = 'points';
846
+ else if ( polygonDimensions[ 0 ] === 2 ) geometryData.type = 'lines';
847
+
848
+ this.currentLayer.geometry = geometryData;
849
+
850
+ },
851
+
852
+ // Lists the tag strings that can be associated with polygons by the PTAG chunk.
853
+ // TAGS { tag-string[S0] * }
854
+ parseTagStrings( length ) {
855
+
856
+ this.tree.tags = this.reader.getStringArray( length );
857
+
858
+ },
859
+
860
+ // Associates tags of a given type with polygons in the most recent POLS chunk.
861
+ // PTAG { type[ID4], ( poly[VX], tag[U2] ) * }
862
+ parsePolygonTagMapping( length ) {
863
+
864
+ var finalOffset = this.reader.offset + length;
865
+ var type = this.reader.getIDTag();
866
+ if ( type === 'SURF' ) this.parseMaterialIndices( finalOffset );
867
+ else { //PART, SMGP, COLR not supported
868
+
869
+ this.reader.skip( length - 4 );
870
+
871
+ }
872
+
873
+ },
874
+
875
+ parseMaterialIndices( finalOffset ) {
876
+
877
+ // array holds polygon index followed by material index
878
+ this.currentLayer.geometry.materialIndices = [];
879
+
880
+ while ( this.reader.offset < finalOffset ) {
881
+
882
+ var polygonIndex = this.reader.getVariableLengthIndex();
883
+ var materialIndex = this.reader.getUint16();
884
+
885
+ this.currentLayer.geometry.materialIndices.push( polygonIndex, materialIndex );
886
+
887
+ }
888
+
889
+ },
890
+
891
+ parseUnknownCHUNK( blockID, length ) {
892
+
893
+ console.warn( 'LWOLoader: unknown chunk type: ' + blockID + ' length: ' + length );
894
+
895
+ // print the chunk plus some bytes padding either side
896
+ // printBuffer( this.reader.dv.buffer, this.reader.offset - 20, length + 40 );
897
+
898
+ var data = this.reader.getString( length );
899
+
900
+ this.currentForm[ blockID ] = data;
901
+
902
+ }
903
+
904
+ };
905
+
906
+ function DataViewReader( buffer ) {
907
+
908
+ this.dv = new DataView( buffer );
909
+ this.offset = 0;
910
+ this._textDecoder = new TextDecoder();
911
+ this._bytes = new Uint8Array( buffer );
912
+
913
+ }
914
+
915
+ DataViewReader.prototype = {
916
+
917
+ constructor: DataViewReader,
918
+
919
+ size: function () {
920
+
921
+ return this.dv.buffer.byteLength;
922
+
923
+ },
924
+
925
+ setOffset( offset ) {
926
+
927
+ if ( offset > 0 && offset < this.dv.buffer.byteLength ) {
928
+
929
+ this.offset = offset;
930
+
931
+ } else {
932
+
933
+ console.error( 'LWOLoader: invalid buffer offset' );
934
+
935
+ }
936
+
937
+ },
938
+
939
+ endOfFile: function () {
940
+
941
+ if ( this.offset >= this.size() ) return true;
942
+ return false;
943
+
944
+ },
945
+
946
+ skip: function ( length ) {
947
+
948
+ this.offset += length;
949
+
950
+ },
951
+
952
+ getUint8: function () {
953
+
954
+ var value = this.dv.getUint8( this.offset );
955
+ this.offset += 1;
956
+ return value;
957
+
958
+ },
959
+
960
+ getUint16: function () {
961
+
962
+ var value = this.dv.getUint16( this.offset );
963
+ this.offset += 2;
964
+ return value;
965
+
966
+ },
967
+
968
+ getInt32: function () {
969
+
970
+ var value = this.dv.getInt32( this.offset, false );
971
+ this.offset += 4;
972
+ return value;
973
+
974
+ },
975
+
976
+ getUint32: function () {
977
+
978
+ var value = this.dv.getUint32( this.offset, false );
979
+ this.offset += 4;
980
+ return value;
981
+
982
+ },
983
+
984
+ getUint64: function () {
985
+
986
+ var low, high;
987
+
988
+ high = this.getUint32();
989
+ low = this.getUint32();
990
+ return high * 0x100000000 + low;
991
+
992
+ },
993
+
994
+ getFloat32: function () {
995
+
996
+ var value = this.dv.getFloat32( this.offset, false );
997
+ this.offset += 4;
998
+ return value;
999
+
1000
+ },
1001
+
1002
+ getFloat32Array: function ( size ) {
1003
+
1004
+ var a = [];
1005
+
1006
+ for ( var i = 0; i < size; i ++ ) {
1007
+
1008
+ a.push( this.getFloat32() );
1009
+
1010
+ }
1011
+
1012
+ return a;
1013
+
1014
+ },
1015
+
1016
+ getFloat64: function () {
1017
+
1018
+ var value = this.dv.getFloat64( this.offset, this.littleEndian );
1019
+ this.offset += 8;
1020
+ return value;
1021
+
1022
+ },
1023
+
1024
+ getFloat64Array: function ( size ) {
1025
+
1026
+ var a = [];
1027
+
1028
+ for ( var i = 0; i < size; i ++ ) {
1029
+
1030
+ a.push( this.getFloat64() );
1031
+
1032
+ }
1033
+
1034
+ return a;
1035
+
1036
+ },
1037
+
1038
+ // get variable-length index data type
1039
+ // VX ::= index[U2] | (index + 0xFF000000)[U4]
1040
+ // If the index value is less than 65,280 (0xFF00),then VX === U2
1041
+ // otherwise VX === U4 with bits 24-31 set
1042
+ // When reading an index, if the first byte encountered is 255 (0xFF), then
1043
+ // the four-byte form is being used and the first byte should be discarded or masked out.
1044
+ getVariableLengthIndex() {
1045
+
1046
+ var firstByte = this.getUint8();
1047
+
1048
+ if ( firstByte === 255 ) {
1049
+
1050
+ return this.getUint8() * 65536 + this.getUint8() * 256 + this.getUint8();
1051
+
1052
+ }
1053
+
1054
+ return firstByte * 256 + this.getUint8();
1055
+
1056
+ },
1057
+
1058
+ // An ID tag is a sequence of 4 bytes containing 7-bit ASCII values
1059
+ getIDTag() {
1060
+
1061
+ return this.getString( 4 );
1062
+
1063
+ },
1064
+
1065
+ getString: function ( size ) {
1066
+
1067
+ if ( size === 0 ) return;
1068
+
1069
+ const start = this.offset;
1070
+
1071
+ let result;
1072
+ let length;
1073
+
1074
+ if ( size ) {
1075
+
1076
+ length = size;
1077
+ result = this._textDecoder.decode( new Uint8Array( this.dv.buffer, start, size ) );
1078
+
1079
+ } else {
1080
+
1081
+ // use 1:1 mapping of buffer to avoid redundant new array creation.
1082
+ length = this._bytes.indexOf( 0, start ) - start;
1083
+
1084
+ result = this._textDecoder.decode( new Uint8Array( this.dv.buffer, start, length ) );
1085
+
1086
+ // account for null byte in length
1087
+ length ++;
1088
+
1089
+ // if string with terminating nullbyte is uneven, extra nullbyte is added, skip that too
1090
+ length += length % 2;
1091
+
1092
+ }
1093
+
1094
+ this.skip( length );
1095
+
1096
+ return result;
1097
+
1098
+ },
1099
+
1100
+ getStringArray: function ( size ) {
1101
+
1102
+ var a = this.getString( size );
1103
+ a = a.split( '\0' );
1104
+
1105
+ return a.filter( Boolean ); // return array with any empty strings removed
1106
+
1107
+ }
1108
+
1109
+ };
1110
+
1111
+ // ************** DEBUGGER **************
1112
+
1113
+ function Debugger( ) {
1114
+
1115
+ this.active = false;
1116
+ this.depth = 0;
1117
+ this.formList = [];
1118
+
1119
+ }
1120
+
1121
+ Debugger.prototype = {
1122
+
1123
+ constructor: Debugger,
1124
+
1125
+ enable: function () {
1126
+
1127
+ this.active = true;
1128
+
1129
+ },
1130
+
1131
+ log: function () {
1132
+
1133
+ if ( ! this.active ) return;
1134
+
1135
+ var nodeType;
1136
+
1137
+ switch ( this.node ) {
1138
+
1139
+ case 0:
1140
+ nodeType = 'FORM';
1141
+ break;
1142
+
1143
+ case 1:
1144
+ nodeType = 'CHK';
1145
+ break;
1146
+
1147
+ case 2:
1148
+ nodeType = 'S-CHK';
1149
+ break;
1150
+
1151
+ }
1152
+
1153
+ console.log(
1154
+ '| '.repeat( this.depth ) +
1155
+ nodeType,
1156
+ this.nodeID,
1157
+ `( ${this.offset} ) -> ( ${this.dataOffset + this.length} )`,
1158
+ ( ( this.node == 0 ) ? ' {' : '' ),
1159
+ ( ( this.skipped ) ? 'SKIPPED' : '' ),
1160
+ ( ( this.node == 0 && this.skipped ) ? '}' : '' )
1161
+ );
1162
+
1163
+ if ( this.node == 0 && ! this.skipped ) {
1164
+
1165
+ this.depth += 1;
1166
+ this.formList.push( this.dataOffset + this.length );
1167
+
1168
+ }
1169
+
1170
+ this.skipped = false;
1171
+
1172
+ },
1173
+
1174
+ closeForms: function () {
1175
+
1176
+ if ( ! this.active ) return;
1177
+
1178
+ for ( var i = this.formList.length - 1; i >= 0; i -- ) {
1179
+
1180
+ if ( this.offset >= this.formList[ i ] ) {
1181
+
1182
+ this.depth -= 1;
1183
+ console.log( '| '.repeat( this.depth ) + '}' );
1184
+ this.formList.splice( - 1, 1 );
1185
+
1186
+ }
1187
+
1188
+ }
1189
+
1190
+ }
1191
+
1192
+ };
1193
+
1194
+ // ************** UTILITY FUNCTIONS **************
1195
+
1196
+ function isEven( num ) {
1197
+
1198
+ return num % 2;
1199
+
1200
+ }
1201
+
1202
+ // calculate the length of the string in the buffer
1203
+ // this will be string.length + nullbyte + optional padbyte to make the length even
1204
+ function stringOffset( string ) {
1205
+
1206
+ return string.length + 1 + ( isEven( string.length + 1 ) ? 1 : 0 );
1207
+
1208
+ }
1209
+
1210
+ // for testing purposes, dump buffer to console
1211
+ // printBuffer( this.reader.dv.buffer, this.reader.offset, length );
1212
+ function printBuffer( buffer, from, to ) {
1213
+
1214
+ console.log( new TextDecoder().decode( new Uint8Array( buffer, from, to ) ) );
1215
+
1216
+ }
1217
+
1218
+ export { IFFParser };