@divinevoxel/vlox 0.0.71 → 0.0.73

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 (271) hide show
  1. package/Contexts/Base/Main/InitDataGenerator.js +0 -9
  2. package/Contexts/Base/Remote/DataSync.types.d.ts +0 -5
  3. package/Contexts/Base/Remote/InitDataSync.js +17 -31
  4. package/Contexts/Render/DivineVoxelEngineRender.d.ts +1 -1
  5. package/Contexts/World/DivineVoxelEngineWorld.d.ts +1 -1
  6. package/Init/StartConstructor.js +7 -7
  7. package/Init/StartWorld.d.ts +1 -1
  8. package/Init/StartWorld.js +0 -12
  9. package/Math/Indexing.d.ts +12 -3
  10. package/Math/Indexing.js +24 -15
  11. package/Mesher/Functions/CompactVoxelMesh.d.ts +2 -2
  12. package/Mesher/Functions/CompactVoxelMesh.js +4 -5
  13. package/Mesher/Functions/MeshSection.d.ts +1 -1
  14. package/Mesher/Functions/MeshSection.js +72 -66
  15. package/Mesher/Functions/MeshTexture.d.ts +1 -1
  16. package/Mesher/Functions/MeshTexture.js +3 -4
  17. package/Mesher/Functions/MeshVoxel.js +20 -26
  18. package/Mesher/Geomtry/Primitives/QuadVertexData.d.ts +12 -10
  19. package/Mesher/Geomtry/Primitives/QuadVertexData.js +49 -56
  20. package/Mesher/Geomtry/VoxelGeometryBuilder.d.ts +2 -2
  21. package/Mesher/Geomtry/VoxelGeometryBuilder.js +108 -125
  22. package/Mesher/Geomtry/VoxelMesh.d.ts +1 -1
  23. package/Mesher/Geomtry/VoxelMesh.js +2 -2
  24. package/Mesher/{Tools → Geomtry}/VoxelMeshBVHBuilder.d.ts +2 -9
  25. package/Mesher/{Tools → Geomtry}/VoxelMeshBVHBuilder.js +4 -16
  26. package/Mesher/Geomtry/{Buffers.d.ts → VoxelMeshBuffers.d.ts} +9 -8
  27. package/Mesher/Geomtry/VoxelMeshBuffers.js +49 -0
  28. package/Mesher/{Tools → Geomtry}/VoxelMeshVertexStructCursor.d.ts +10 -0
  29. package/Mesher/{Tools → Geomtry}/VoxelMeshVertexStructCursor.js +10 -0
  30. package/Mesher/Geomtry/index.d.ts +0 -1
  31. package/Mesher/Geomtry/index.js +0 -1
  32. package/Mesher/InitMesher.js +2 -11
  33. package/Mesher/InitTask.js +10 -22
  34. package/Mesher/Models/Common/BoundsFunctions.d.ts +1 -3
  35. package/Mesher/Models/Common/BoundsFunctions.js +0 -16
  36. package/Mesher/Models/Common/Calc/CalcConstants.js +14 -31
  37. package/Mesher/Models/Common/Calc/FaceDataCalc.d.ts +2 -8
  38. package/Mesher/Models/Common/Calc/FaceDataCalc.js +50 -52
  39. package/Mesher/Models/Nodes/Custom/Liquid/FlowGradient.d.ts +2 -2
  40. package/Mesher/Models/Nodes/Custom/Liquid/FlowGradient.js +1 -1
  41. package/Mesher/Models/Nodes/Custom/Liquid/LiquidGeomtryNode.d.ts +1 -5
  42. package/Mesher/Models/Nodes/Custom/Liquid/LiquidGeomtryNode.js +40 -42
  43. package/Mesher/Models/Nodes/GeometryNode.d.ts +3 -5
  44. package/Mesher/Models/Nodes/GeometryNode.js +1 -2
  45. package/Mesher/Models/Nodes/Ruled/BoxVoxelGeometryNode.d.ts +3 -6
  46. package/Mesher/Models/Nodes/Ruled/BoxVoxelGeometryNode.js +55 -40
  47. package/Mesher/Models/Nodes/Ruled/QuadVoxelGeometryNode.d.ts +2 -6
  48. package/Mesher/Models/Nodes/Ruled/QuadVoxelGeometryNode.js +52 -51
  49. package/Mesher/Models/Nodes/Ruleless/RulelessBoxVoxelGeometryNode.d.ts +2 -6
  50. package/Mesher/Models/Nodes/Ruleless/RulelessBoxVoxelGeometryNode.js +18 -19
  51. package/Mesher/Models/Nodes/Ruleless/RulelessQuadVoxelGeometryNode.d.ts +2 -6
  52. package/Mesher/Models/Nodes/Ruleless/RulelessQuadVoxelGeometryNode.js +37 -40
  53. package/Mesher/{Tools → Models/Protocols}/OutlinedVoxelTool.d.ts +1 -1
  54. package/Mesher/{Tools → Models/Protocols}/OutlinedVoxelTool.js +1 -1
  55. package/Mesher/Models/RenderedMaterials.d.ts +6 -0
  56. package/Mesher/{RenderedMaterials.js → Models/RenderedMaterials.js} +2 -2
  57. package/Mesher/Models/VoxelConstructor.d.ts +4 -5
  58. package/Mesher/Models/VoxelConstructor.js +23 -12
  59. package/Mesher/Models/{VoxelGeometryLookUp.d.ts → VoxelGeometryBuilderCacheSpace.d.ts} +6 -14
  60. package/Mesher/Models/{VoxelGeometryLookUp.js → VoxelGeometryBuilderCacheSpace.js} +26 -44
  61. package/Mesher/{Tools/VoxelMesherDataTool.d.ts → Models/VoxelModelBuilder.d.ts} +10 -8
  62. package/Mesher/{Tools/VoxelMesherDataTool.js → Models/VoxelModelBuilder.js} +44 -19
  63. package/Mesher/Models/VoxelModelConstructorRegister.js +3 -3
  64. package/Models/Defaults/CubeVoxelGeometry.js +4 -0
  65. package/Models/Defaults/CubeVoxelModels.js +344 -344
  66. package/Models/Defaults/LiquidVoxelModel.js +2 -2
  67. package/Models/Defaults/PanelVoxelModels.js +432 -432
  68. package/Models/Defaults/StairVoxelModel.js +576 -576
  69. package/Models/Examples.js +469 -456
  70. package/Models/Indexing/VoxelAOResultsIndex.d.ts +4 -4
  71. package/Models/Indexing/VoxelAOResultsIndex.js +15 -9
  72. package/Models/Indexing/VoxelFaceCullResultsIndex.d.ts +3 -3
  73. package/Models/Indexing/VoxelFaceCullResultsIndex.js +14 -9
  74. package/Models/Indexing/VoxelFaceTransparentResultsIndex.d.ts +1 -1
  75. package/Models/Indexing/VoxelFaceTransparentResultsIndex.js +1 -1
  76. package/Models/Rules/Functions/BuildFinalInputs.js +9 -7
  77. package/Models/Rules/Functions/BuildGeomtryInputs.js +8 -5
  78. package/Models/Rules/Functions/BuildRules.js +4 -4
  79. package/Models/Rules/{VoxelModelManager.d.ts → VoxelModelRuleBuilderRegister.d.ts} +1 -1
  80. package/Models/Rules/VoxelModelRuleBuilderRegister.js +178 -0
  81. package/Models/VoxelModel.types.d.ts +14 -5
  82. package/Renderer/Classes/SectorMesh.d.ts +3 -4
  83. package/Renderer/Classes/SectorMesh.js +6 -11
  84. package/Renderer/InitTasks.js +6 -7
  85. package/Renderer/MeshManager.js +2 -2
  86. package/Renderer/MeshRegister.js +2 -1
  87. package/Settings/EngineSettings.d.ts +1 -1
  88. package/Settings/EngineSettings.js +3 -5
  89. package/Settings/EngineSettings.types.d.ts +17 -18
  90. package/Settings/EngineSettings.types.js +16 -15
  91. package/Tasks/IWG/IWG.d.ts +2 -1
  92. package/Tasks/IWG/IWG.js +9 -3
  93. package/Tasks/IWG/Internal/Classes/BuildQueue.d.ts +11 -0
  94. package/Tasks/IWG/Internal/Classes/BuildQueue.js +49 -0
  95. package/Tasks/IWG/Internal/Classes/Generator.d.ts +6 -1
  96. package/Tasks/IWG/Internal/Classes/Generator.js +14 -2
  97. package/Tasks/IWG/Internal/Classes/IWGTaskBase.js +2 -2
  98. package/Tasks/IWG/Internal/Functions/getSectorState.js +4 -7
  99. package/Tasks/IWG/Internal/Functions/runBuildUpdate.js +21 -2
  100. package/Tasks/IWG/Internal/Functions/runWorldUpdate.js +5 -6
  101. package/Tasks/IWG/Internal/IWGTasks.d.ts +0 -4
  102. package/Tasks/IWG/Internal/IWGTasks.js +12 -31
  103. package/Tasks/IWG/Internal/IWGTools.d.ts +1 -1
  104. package/Tasks/IWG/Procedures/SaveAllSectors.js +2 -0
  105. package/Tasks/Propagation/Flow/FlowManager.d.ts +0 -2
  106. package/Tasks/Propagation/Flow/FlowManager.js +86 -87
  107. package/Tasks/Propagation/Flow/WorldFlow.js +2 -3
  108. package/Tasks/Propagation/Illumanation/WorldRGB.js +1 -2
  109. package/Tasks/Update/InitTasks.d.ts +2 -1
  110. package/Tasks/Update/InitTasks.js +6 -6
  111. package/Tasks/Update/UpdateTask.d.ts +3 -1
  112. package/Tasks/Update/UpdateTask.js +28 -2
  113. package/Tasks/Update/VoxelUpdate.js +21 -7
  114. package/Tasks/WorldGeneration/WorldGenBrush.js +2 -1
  115. package/Templates/Cursor/TemplateCursor.d.ts +2 -2
  116. package/Templates/Cursor/TemplateCursor.js +1 -2
  117. package/Templates/Functions/CreateTemplate.js +1 -1
  118. package/Templates/VoxelTemplate.js +6 -8
  119. package/Templates/VoxelTemplates.types.d.ts +1 -1
  120. package/Textures/Classes/CompiledTexture.d.ts +18 -0
  121. package/Textures/Classes/CompiledTexture.js +50 -0
  122. package/Textures/Classes/CompiledTextureAnimation.d.ts +12 -0
  123. package/Textures/Classes/CompiledTextureAnimation.js +27 -0
  124. package/Textures/Classes/TextureAnimationTexture.d.ts +10 -0
  125. package/Textures/Classes/TextureAnimationTexture.js +32 -0
  126. package/Textures/Functions/BuildTextureData.d.ts +10 -0
  127. package/Textures/Functions/BuildTextureData.js +205 -0
  128. package/Textures/Texture.types.d.ts +50 -64
  129. package/Textures/TextureManager.d.ts +8 -19
  130. package/Textures/TextureManager.js +28 -166
  131. package/Tools/Brush/Brush.d.ts +1 -3
  132. package/Tools/Brush/Brush.js +43 -12
  133. package/Util/Binary/BinaryArrays.d.ts +6 -0
  134. package/Util/Binary/BinaryArrays.js +25 -0
  135. package/Util/Binary/BinaryBuffer.d.ts +29 -0
  136. package/Util/Binary/BinaryBuffer.js +130 -0
  137. package/Util/Binary/BinaryFunctions.d.ts +3 -0
  138. package/Util/Binary/BinaryFunctions.js +11 -0
  139. package/Util/StringPalette.d.ts +1 -0
  140. package/Util/StringPalette.js +8 -0
  141. package/Voxels/Cursor/DataCursor.interface.d.ts +5 -0
  142. package/Voxels/Cursor/VoxelCursor.d.ts +6 -6
  143. package/Voxels/Cursor/VoxelCursor.interface.d.ts +11 -16
  144. package/Voxels/Cursor/VoxelCursor.interface.js +35 -58
  145. package/Voxels/Cursor/VoxelCursor.js +13 -12
  146. package/Voxels/Cursor/VoxelLightData.d.ts +3 -4
  147. package/Voxels/Cursor/VoxelLightData.js +8 -7
  148. package/Voxels/Data/VoxelPalettesRegister.d.ts +8 -0
  149. package/Voxels/Data/VoxelPalettesRegister.js +8 -0
  150. package/Voxels/Data/VoxelTag.types.d.ts +56 -0
  151. package/Voxels/Data/VoxelTag.types.js +23 -0
  152. package/Voxels/{State → Data}/VoxelTagStates.d.ts +2 -2
  153. package/Voxels/{State → Data}/VoxelTagStates.js +5 -5
  154. package/Voxels/Data/VoxelTagsRegister.d.ts +9 -0
  155. package/Voxels/Data/VoxelTagsRegister.js +32 -0
  156. package/Voxels/Functions/BuildStateData.js +12 -12
  157. package/Voxels/Functions/BuildTagAndPaletteData.d.ts +13 -0
  158. package/Voxels/Functions/BuildTagAndPaletteData.js +55 -0
  159. package/Voxels/Indexes/VoxelIndex.js +3 -3
  160. package/Voxels/InitVoxelData.js +31 -73
  161. package/Voxels/State/Schema/StateSchema.d.ts +1 -1
  162. package/Voxels/Types/Voxel.types.d.ts +20 -42
  163. package/Voxels/Types/Voxel.types.js +6 -17
  164. package/Voxels/Types/VoxelModelCompiledData.types.d.ts +11 -13
  165. package/Voxels/Types/VoxelSubstances.types.d.ts +2 -15
  166. package/Voxels/Types/VoxelSubstances.types.js +1 -9
  167. package/World/Archive/Archive.types.d.ts +38 -34
  168. package/World/Archive/Functions/ArchiveArea.js +18 -30
  169. package/World/Archive/Functions/ArchiveSector.js +484 -213
  170. package/World/Archive/Functions/ImportSector.d.ts +3 -3
  171. package/World/Archive/Functions/ImportSector.js +205 -151
  172. package/World/Archive/Functions/Shared.d.ts +6 -0
  173. package/World/Archive/Functions/Shared.js +75 -0
  174. package/World/Archive/InitTasks.js +30 -13
  175. package/World/Cursor/SectionCursor.d.ts +3 -2
  176. package/World/Cursor/SectionCursor.js +9 -4
  177. package/World/Cursor/SectorCursor.d.ts +3 -2
  178. package/World/Cursor/SectorCursor.js +5 -3
  179. package/World/Cursor/WorldCursor.d.ts +2 -2
  180. package/World/Cursor/WorldCursor.js +6 -3
  181. package/World/Cursor/WorldVoxelCursor.d.ts +7 -7
  182. package/World/Cursor/WorldVoxelCursor.js +21 -24
  183. package/World/InitTasks.d.ts +1 -1
  184. package/World/Lock/WorldLock.d.ts +1 -1
  185. package/World/Section/Section.d.ts +31 -23
  186. package/World/Section/Section.js +116 -18
  187. package/World/Section/SectionState.d.ts +10 -0
  188. package/World/Section/SectionState.js +11 -0
  189. package/World/Sector/Sector.d.ts +24 -9
  190. package/World/Sector/Sector.js +92 -21
  191. package/World/Sector/SectorHeightMap.js +3 -5
  192. package/World/Sector/SectorState.d.ts +21 -0
  193. package/World/Sector/SectorState.js +28 -0
  194. package/World/WorldRegister.d.ts +4 -0
  195. package/World/WorldRegister.js +15 -3
  196. package/World/WorldSpaces.d.ts +6 -0
  197. package/World/WorldSpaces.js +25 -6
  198. package/package.json +1 -1
  199. package/Data/Cursor/DataCursor.interface.d.ts +0 -5
  200. package/Data/Cursor/DataCursor.interface.js +0 -2
  201. package/Data/Register/MappedDataRegister.d.ts +0 -5
  202. package/Data/Register/MappedDataRegister.js +0 -9
  203. package/Data/Register/MappedRegisterBase.d.ts +0 -14
  204. package/Data/Register/MappedRegisterBase.js +0 -50
  205. package/Data/Structs/StructBuilder.d.ts +0 -34
  206. package/Data/Structs/StructBuilder.js +0 -157
  207. package/Data/Structs/StructBuilder.types.d.ts +0 -30
  208. package/Mesher/Functions/CompactMesh.d.ts +0 -2
  209. package/Mesher/Functions/CompactMesh.js +0 -42
  210. package/Mesher/Geomtry/Buffers.js +0 -81
  211. package/Mesher/Geomtry/GeometryNormals.d.ts +0 -10
  212. package/Mesher/Geomtry/GeometryNormals.js +0 -52
  213. package/Mesher/Geomtry/MeshData.types.d.ts +0 -13
  214. package/Mesher/Geomtry/MeshData.types.js +0 -6
  215. package/Mesher/Geomtry/Tools/MesherDataTools.d.ts +0 -7
  216. package/Mesher/Geomtry/Tools/MesherDataTools.js +0 -12
  217. package/Mesher/Geomtry/Tools/index.d.ts +0 -1
  218. package/Mesher/Geomtry/Tools/index.js +0 -1
  219. package/Mesher/RenderedMaterials.d.ts +0 -6
  220. package/Models/Rules/VoxelModelManager.js +0 -82
  221. package/Textures/TextureAnimations.d.ts +0 -4
  222. package/Textures/TextureAnimations.js +0 -35
  223. package/Textures/TextureArray.d.ts +0 -47
  224. package/Textures/TextureArray.js +0 -202
  225. package/Textures/TextureBuilder.d.ts +0 -13
  226. package/Textures/TextureBuilder.js +0 -120
  227. package/Textures/TextureRegister.d.ts +0 -9
  228. package/Textures/TextureRegister.js +0 -28
  229. package/Tools/Data/SubstanceDataTool.d.ts +0 -13
  230. package/Tools/Data/SubstanceDataTool.js +0 -51
  231. package/Voxels/Palettes/MaterialPalette.d.ts +0 -9
  232. package/Voxels/Palettes/MaterialPalette.js +0 -11
  233. package/Voxels/Palettes/SubstancePalette.d.ts +0 -9
  234. package/Voxels/Palettes/SubstancePalette.js +0 -11
  235. package/Voxels/Palettes/VoxelPalette.d.ts +0 -11
  236. package/Voxels/Palettes/VoxelPalette.js +0 -15
  237. package/Voxels/Segments/MaterialDataGenerator.d.ts +0 -6
  238. package/Voxels/Segments/MaterialDataGenerator.js +0 -12
  239. package/Voxels/Segments/SubstanceDataGenerator.d.ts +0 -6
  240. package/Voxels/Segments/SubstanceDataGenerator.js +0 -35
  241. package/Voxels/Segments/VoxelDataGenerator.d.ts +0 -10
  242. package/Voxels/Segments/VoxelDataGenerator.js +0 -56
  243. package/Voxels/Structs/Builder/SubstanceStructBuilder.d.ts +0 -2
  244. package/Voxels/Structs/Builder/SubstanceStructBuilder.js +0 -42
  245. package/Voxels/Structs/Builder/VoxelStructBuilder.d.ts +0 -2
  246. package/Voxels/Structs/Builder/VoxelStructBuilder.js +0 -68
  247. package/Voxels/Structs/SubstanceStruct.d.ts +0 -17
  248. package/Voxels/Structs/SubstanceStruct.js +0 -17
  249. package/Voxels/Structs/VoxelStruct.d.ts +0 -27
  250. package/Voxels/Structs/VoxelStruct.js +0 -29
  251. package/World/Section/SectionHeightMap.d.ts +0 -10
  252. package/World/Section/SectionHeightMap.js +0 -39
  253. package/World/Section/SectionStruct.d.ts +0 -8
  254. package/World/Section/SectionStruct.js +0 -29
  255. package/World/Section/SectionStructProperties.d.ts +0 -10
  256. package/World/Section/SectionStructProperties.js +0 -11
  257. package/World/Sector/SectorStruct.d.ts +0 -1
  258. package/World/Sector/SectorStruct.js +0 -46
  259. package/World/Sector/SectorStructIds.d.ts +0 -13
  260. package/World/Sector/SectorStructIds.js +0 -14
  261. package/World/Structs/WorldDataStructProperties.d.ts +0 -8
  262. package/World/Structs/WorldDataStructProperties.js +0 -9
  263. /package/Mesher/{VoxelShaderData.d.ts → Geomtry/VoxelShaderData.d.ts} +0 -0
  264. /package/Mesher/{VoxelShaderData.js → Geomtry/VoxelShaderData.js} +0 -0
  265. /package/{Data/Functions → Util/Binary}/Palettes.d.ts +0 -0
  266. /package/{Data/Functions → Util/Binary}/Palettes.js +0 -0
  267. /package/{Data/Structs/StructBuilder.types.js → Voxels/Cursor/DataCursor.interface.js} +0 -0
  268. /package/Voxels/{VoxelLevelReader.d.ts → Cursor/VoxelLevelReader.d.ts} +0 -0
  269. /package/Voxels/{VoxelLevelReader.js → Cursor/VoxelLevelReader.js} +0 -0
  270. /package/World/{Storage → Types}/WorldStorage.interface.d.ts +0 -0
  271. /package/World/{Storage → Types}/WorldStorage.interface.js +0 -0
@@ -1,202 +0,0 @@
1
- import { TextureManager } from "./TextureManager.js";
2
- import { TextureAnimationCreator } from "./TextureAnimations.js";
3
- import { TextureBuilder } from "./TextureBuilder.js";
4
- export class TextureArray {
5
- id;
6
- extension = "png";
7
- totalTextures = 0;
8
- textureMap = new Map();
9
- textures = [];
10
- textureIndex = {};
11
- animationsMap = [];
12
- animationTimes = [];
13
- animations = [];
14
- varyingID = "";
15
- animationUniforID = "";
16
- animationUniform = new Float32Array();
17
- paths = new Map();
18
- images = [];
19
- /* actual renderer resource */
20
- shaderTexture = null;
21
- textureID = "";
22
- attributeID = "textureIndex";
23
- constructor(id) {
24
- this.id = id;
25
- this.textureID = id.replace("#", "");
26
- }
27
- /**# clearData
28
- * ---
29
- * Clear all un-needed data.
30
- */
31
- clearData() {
32
- this.paths.clear();
33
- this.textures = [];
34
- this.textureMap.clear();
35
- this.textureIndex = {};
36
- this.images = [];
37
- this.animationsMap = [];
38
- this.animationTimes = [];
39
- }
40
- /**# flush
41
- * ---
42
- * Clear all data.
43
- */
44
- flush() {
45
- this.clearData();
46
- this.images = [];
47
- this.animations = [];
48
- this.animationTimes = [];
49
- this.animationsMap = [];
50
- this.textureIndex = {};
51
- this.totalTextures = 0;
52
- }
53
- flushAll() {
54
- // this.materials.clear();
55
- }
56
- async build() {
57
- this.buildTextureIndex();
58
- if (this.paths.size) {
59
- this.images = await TextureBuilder.createMaterialTexture(this.id, this.paths);
60
- }
61
- TextureAnimationCreator.createAnimations(this);
62
- }
63
- getTextureIndex(textureId, varation = "") {
64
- let id = textureId;
65
- if (varation) {
66
- id = `${textureId}:${varation}`;
67
- }
68
- let uv = -1;
69
- uv = this.textureIndex[id];
70
- if (uv == -1) {
71
- throw new Error(`Texture with id: ${id} does not exists.typeId : ${this.id} `);
72
- }
73
- return uv;
74
- }
75
- addTexture(data) {
76
- this.textures.push(data);
77
- this.textureMap.set(data.id, data);
78
- }
79
- runAnimations() {
80
- for (let i = 0; i < this.animations.length; i++) {
81
- const anim = this.animations[i];
82
- if (anim.currentCount <= anim.keyCounts[anim.currentFrame]) {
83
- anim.currentCount++;
84
- continue;
85
- }
86
- anim.currentCount = 0;
87
- if (anim.currentFrame < anim.keys.length - 1) {
88
- anim.currentFrame++;
89
- }
90
- else {
91
- anim.currentFrame = 0;
92
- }
93
- this.animationUniform[anim.uniformIndex] = anim.keys[anim.currentFrame];
94
- /* for (const [key, material] of this.materials) {
95
- material!.setNumberArray(
96
- this.animationUniforID,
97
- this.animationUniform as any
98
- );
99
- } */
100
- }
101
- }
102
- getTextureIndexMap() {
103
- return this.textureIndex;
104
- }
105
- _processVariations(textureData, paths, map, animations, textureAnimatioTimes, extension, count) {
106
- if (!textureData.variations)
107
- return count;
108
- for (const varation of Object.keys(textureData.variations)) {
109
- const data = textureData.variations[varation];
110
- if (data.frames == 0) {
111
- map[`${textureData.id}:${varation}`] = count;
112
- const assetPath = this._getPath(textureData, varation, extension);
113
- let raw = false;
114
- if (data.base64 && !Array.isArray(data.base64)) {
115
- raw = data.base64;
116
- }
117
- paths.set(assetPath, raw);
118
- count++;
119
- }
120
- else {
121
- if (!data.animKeys)
122
- throw new Error("Texture Varation must have supplied animKeys if frames are greater than 0.");
123
- for (let i = 1; i <= data.frames; i++) {
124
- map[`${textureData.id}:${varation}-${i}`] = count;
125
- const assetPath = this._getPath(textureData, `${varation}-${i}`, extension);
126
- let raw = false;
127
- if (data.base64) {
128
- raw = data.base64[i - 1];
129
- }
130
- paths.set(assetPath, raw);
131
- count++;
132
- }
133
- const trueKeys = [];
134
- for (let i = 0; i < data.animKeys.length; i++) {
135
- trueKeys.push(map[`${textureData.id}:${varation}-${data.animKeys[i]}`]);
136
- }
137
- if (data.animKeyFrameTimes) {
138
- textureAnimatioTimes.push(data.animKeyFrameTimes);
139
- }
140
- if (data.globalFrameTime) {
141
- textureAnimatioTimes.push([data.globalFrameTime]);
142
- }
143
- animations.push(trueKeys);
144
- }
145
- }
146
- return count;
147
- }
148
- _getPath(textureData, varation = "default", extension) {
149
- return `${textureData.path ? textureData.path : TextureManager.defaultTexturePath}/${textureData.id}/${varation}.${extension}`;
150
- }
151
- buildTextureIndex() {
152
- const texture = this;
153
- if (!texture)
154
- return false;
155
- const extension = texture.extension;
156
- let count = 0;
157
- const map = this.textureIndex;
158
- const paths = this.paths;
159
- const animationTimes = this.animationTimes;
160
- const animations = this.animationsMap;
161
- for (const textureData of this.textures) {
162
- if (textureData.frames == 0) {
163
- this.textureIndex[`${textureData.id}`] = count;
164
- const assetPath = this._getPath(textureData, "default", extension);
165
- let raw = false;
166
- if (textureData.base64 && !Array.isArray(textureData.base64)) {
167
- raw = textureData.base64;
168
- }
169
- paths.set(assetPath, raw);
170
- count++;
171
- count = this._processVariations(textureData, paths, map, animations, animationTimes, extension, count);
172
- }
173
- else {
174
- if (!textureData.animKeys)
175
- throw new Error("Texture must have supplied animKeys if frames are greater than 0.");
176
- const rawData = textureData.rawData;
177
- for (let i = 1; i <= textureData.frames; i++) {
178
- const assetPath = this._getPath(textureData, `default-${i}`, extension);
179
- let raw = false;
180
- if (textureData.base64) {
181
- raw = textureData.base64[i - 1];
182
- }
183
- paths.set(assetPath, raw);
184
- count++;
185
- }
186
- const trueKeys = [];
187
- for (let i = 0; i < textureData.animKeys.length; i++) {
188
- trueKeys.push(map[`${textureData.id}:default-${textureData.animKeys[i]}`]);
189
- }
190
- if (textureData.animKeyFrameTimes) {
191
- animationTimes.push(textureData.animKeyFrameTimes);
192
- }
193
- if (textureData.globalFrameTime) {
194
- animationTimes.push([textureData.globalFrameTime]);
195
- }
196
- animations.push(trueKeys);
197
- count = this._processVariations(textureData, paths, map, animations, animationTimes, extension, count);
198
- }
199
- }
200
- this.totalTextures = count;
201
- }
202
- }
@@ -1,13 +0,0 @@
1
- export declare class TextureBuilder {
2
- static context: CanvasRenderingContext2D | null;
3
- static _textureSize: number;
4
- static finalImagWidth: number;
5
- static finalImageHeight: number;
6
- static _canvas: HTMLCanvasElement;
7
- static defineTextureDimensions(textureSize: number): void;
8
- static setUpImageCreation(): void;
9
- static createMaterialTexture(name: string, images: Map<string, HTMLImageElement | string | false>, width?: number, height?: number): Promise<HTMLImageElement[]>;
10
- static getRawData(imageSrc: string): Promise<Uint8ClampedArray>;
11
- static getBase64(imageSrc: string): Promise<string>;
12
- static loadImage(imgSrcData: string | HTMLImageElement, width?: number, height?: number): Promise<HTMLImageElement>;
13
- }
@@ -1,120 +0,0 @@
1
- export class TextureBuilder {
2
- static context = null;
3
- static _textureSize = 16;
4
- static finalImagWidth = 16;
5
- static finalImageHeight = 16;
6
- static _canvas = document.createElement("canvas");
7
- static defineTextureDimensions(textureSize) {
8
- this.finalImagWidth = textureSize < 256 ? 256 : textureSize;
9
- this.finalImageHeight = textureSize < 256 ? 256 : textureSize;
10
- this._textureSize = textureSize;
11
- }
12
- static setUpImageCreation() {
13
- this._canvas.width = this.finalImagWidth;
14
- this._canvas.height = this.finalImageHeight;
15
- const context = this._canvas.getContext("2d", { willReadFrequently: true });
16
- if (!context) {
17
- throw new Error("Context did not load for texture creation.");
18
- }
19
- document.body.append(this._canvas);
20
- /* this._canvas.setAttribute(
21
- "style",
22
- `
23
- image-rendering: pixelated;
24
- position: absolute;
25
- border: 1px solid red;
26
- z-index: 1000;
27
- top: 0;
28
- `
29
- );
30
-
31
- */
32
- this.context = context;
33
- }
34
- static async createMaterialTexture(name, images, width = -1, height = -1) {
35
- if (width == -1)
36
- width = this.finalImagWidth;
37
- if (height == -1)
38
- height = this.finalImageHeight;
39
- this._canvas.width = this.finalImagWidth;
40
- this._canvas.height = this.finalImageHeight;
41
- const resolvedImages = [];
42
- for (const [path, rawData] of images) {
43
- const data = await this.loadImage(rawData ? rawData : path, width, height);
44
- resolvedImages.push(data);
45
- }
46
- return resolvedImages;
47
- }
48
- static async getRawData(imageSrc) {
49
- return new Promise((resolve, reject) => {
50
- const image = new Image();
51
- image.crossOrigin = "Anonymous";
52
- image.src = imageSrc;
53
- image.onload = () => {
54
- if (!this.context) {
55
- return reject(new Error("Context is not set for texture creation."));
56
- }
57
- this._canvas.width = image.width;
58
- this._canvas.height = image.height;
59
- this.context.clearRect(0, 0, image.width, image.height);
60
- this.context.drawImage(image, 0, 0, image.width, image.height);
61
- const imgData = this.context.getImageData(0, 0, image.width, image.height);
62
- resolve(imgData.data);
63
- this._canvas.width = this.finalImagWidth;
64
- this._canvas.height = this.finalImageHeight;
65
- };
66
- image.onerror = (err) => reject(err);
67
- });
68
- }
69
- static async getBase64(imageSrc) {
70
- return new Promise((resolve, reject) => {
71
- const image = new Image();
72
- image.crossOrigin = "Anonymous";
73
- image.src = imageSrc;
74
- image.onload = () => {
75
- if (!this.context) {
76
- return reject(new Error("Context is not set for texture creation."));
77
- }
78
- this._canvas.width = image.width;
79
- this._canvas.height = image.height;
80
- this.context.clearRect(0, 0, image.width, image.height);
81
- this.context.drawImage(image, 0, 0, image.width, image.height);
82
- resolve(this._canvas.toDataURL("image/png"));
83
- this._canvas.width = this.finalImagWidth;
84
- this._canvas.height = this.finalImageHeight;
85
- };
86
- image.onerror = (err) => reject(err);
87
- });
88
- }
89
- static async loadImage(imgSrcData, width = 0, height = 0) {
90
- if (!width)
91
- width = this.finalImagWidth;
92
- if (!height)
93
- height = this.finalImageHeight;
94
- const ctx = TextureBuilder.context;
95
- if (!ctx) {
96
- throw new Error("Context is not set for texture creation.");
97
- }
98
- const prom = new Promise((resolve) => {
99
- const image = typeof imgSrcData == "string" ? new Image() : imgSrcData;
100
- if (typeof imgSrcData == "string")
101
- image.src = imgSrcData;
102
- image.onload = () => {
103
- ctx.clearRect(0, 0, this._canvas.width, this._canvas.height);
104
- ctx.imageSmoothingEnabled = false;
105
- ctx.save();
106
- ctx.translate(0, this._canvas.height);
107
- ctx.scale(1, -1);
108
- ctx.drawImage(image, 0, 0, this._canvas.width, this._canvas.height);
109
- ctx.restore();
110
- const dataUrl = this._canvas.toDataURL("image/png");
111
- const returnImage = new Image(this._canvas.width, this._canvas.height);
112
- returnImage.src = dataUrl;
113
- returnImage.onload = () => {
114
- resolve(returnImage);
115
- };
116
- };
117
- });
118
- return prom;
119
- }
120
- }
@@ -1,9 +0,0 @@
1
- import type { TextureTypeUVMap, TextureId } from "./Texture.types";
2
- export declare class TextureRegister {
3
- static textureDataHasBeenSet: boolean;
4
- static data: TextureTypeUVMap;
5
- static getTextureUV(data: TextureId): number;
6
- static setTextureIndex(data: TextureTypeUVMap): void;
7
- static releaseTextureData(): void;
8
- static isReady(): boolean;
9
- }
@@ -1,28 +0,0 @@
1
- export class TextureRegister {
2
- static textureDataHasBeenSet = false;
3
- static data;
4
- static getTextureUV(data) {
5
- const [textureType, textureId, varation] = data;
6
- let id = textureId;
7
- if (varation) {
8
- id = `${textureId}:${varation}`;
9
- }
10
- let uv = -1;
11
- uv = this.data[textureType][id];
12
- if (uv == -1) {
13
- throw new Error(`Texture with id: ${id} does not exists.`);
14
- }
15
- return uv;
16
- }
17
- static setTextureIndex(data) {
18
- this.textureDataHasBeenSet = true;
19
- this.data = data;
20
- }
21
- static releaseTextureData() {
22
- this.data = null;
23
- delete this["data"];
24
- }
25
- static isReady() {
26
- return this.textureDataHasBeenSet;
27
- }
28
- }
@@ -1,13 +0,0 @@
1
- import { SubstanceStruct } from "../../Voxels/Structs/SubstanceStruct.js";
2
- export declare class SubstanceDataTool {
3
- static tags: typeof SubstanceStruct;
4
- substanceTagIndex: number;
5
- setSubstanceFromString(substance: string): this;
6
- setSubstance(substance: number): this;
7
- getSubstanceStringId(): string;
8
- isSolid(): boolean;
9
- isLiquid(): boolean;
10
- isWindAffected(): boolean;
11
- getParent(): string;
12
- getFlowRate(): number;
13
- }
@@ -1,51 +0,0 @@
1
- import { SubstancePalette } from "../../Voxels/Palettes/SubstancePalette.js";
2
- import { MappedDataRegister } from "../../Data/Register/MappedDataRegister.js";
3
- import { SubstanceStructIds } from "../../Voxels/Types/VoxelSubstances.types.js";
4
- import { SubstanceStruct } from "../../Voxels/Structs/SubstanceStruct.js";
5
- export class SubstanceDataTool {
6
- static tags = SubstanceStruct;
7
- //substance = "";
8
- substanceTagIndex = 0;
9
- setSubstanceFromString(substance) {
10
- // this.substance = substance;
11
- this.substanceTagIndex = SubstancePalette.id.numberFromString(substance);
12
- SubstanceStruct.setSubstance(this.substanceTagIndex);
13
- return this;
14
- }
15
- setSubstance(substance) {
16
- // this.substance = substance;
17
- this.substanceTagIndex = substance;
18
- SubstanceStruct.setSubstance(this.substanceTagIndex);
19
- return this;
20
- }
21
- getSubstanceStringId() {
22
- return SubstancePalette.id.stringFromNumber(this.substanceTagIndex);
23
- }
24
- /* isTransparent() {
25
- return SubstanceStruct.instance[SubstanceStructIds.isTransparent] == 1;
26
- }
27
-
28
- */
29
- isSolid() {
30
- return SubstanceStruct.instance[SubstanceStructIds.isSolid] == 1;
31
- }
32
- isLiquid() {
33
- return SubstanceStruct.instance[SubstanceStructIds.isLiquid] == 1;
34
- }
35
- isWindAffected() {
36
- return SubstanceStruct.instance[SubstanceStructIds.isWindAffected] == 1;
37
- }
38
- /* isOpaque() {
39
- return this.isSolid() && !this.isTransparent();
40
- }
41
- */
42
- /* allowLight() {
43
- return this.isTransparent();
44
- } */
45
- getParent() {
46
- return MappedDataRegister.stringMaps.get("substance", SubstanceStructIds.parent, SubstanceStruct.instance[SubstanceStructIds.parent]);
47
- }
48
- getFlowRate() {
49
- return SubstanceStruct.instance[SubstanceStructIds.flowRate];
50
- }
51
- }
@@ -1,9 +0,0 @@
1
- import { StringPalette } from "../../Util/StringPalette";
2
- export declare class MaterialPalette {
3
- static palette: StringPalette;
4
- static setPalette(palette: string[]): void;
5
- static id: {
6
- stringFromNumber: (id: number) => string;
7
- numberFromString: (id: string) => number;
8
- };
9
- }
@@ -1,11 +0,0 @@
1
- import { StringPalette } from "../../Util/StringPalette";
2
- export class MaterialPalette {
3
- static palette;
4
- static setPalette(palette) {
5
- this.palette = new StringPalette(palette);
6
- }
7
- static id = {
8
- stringFromNumber: (id) => this.palette.getStringId(id),
9
- numberFromString: (id) => this.palette.getNumberId(id),
10
- };
11
- }
@@ -1,9 +0,0 @@
1
- import { StringPalette } from "../../Util/StringPalette";
2
- export declare class SubstancePalette {
3
- static palette: StringPalette;
4
- static setPalette(palette: string[]): void;
5
- static id: {
6
- stringFromNumber: (id: number) => string;
7
- numberFromString: (id: string) => number;
8
- };
9
- }
@@ -1,11 +0,0 @@
1
- import { StringPalette } from "../../Util/StringPalette";
2
- export class SubstancePalette {
3
- static palette;
4
- static setPalette(palette) {
5
- this.palette = new StringPalette(palette);
6
- }
7
- static id = {
8
- stringFromNumber: (id) => this.palette.getStringId(id),
9
- numberFromString: (id) => this.palette.getNumberId(id),
10
- };
11
- }
@@ -1,11 +0,0 @@
1
- import { StringPalette } from "../../Util/StringPalette";
2
- export declare class VoxelPalette {
3
- static _nameToIdMap: Map<string, string>;
4
- static _idToNameMap: Map<string, string>;
5
- static ids: StringPalette;
6
- static loadIn(voxelPalette: string[], nameToIdMap: Record<string, string>, idToNameMap: Record<string, string>): void;
7
- static name: {
8
- getId: (name: string) => string;
9
- getName: (id: string) => string;
10
- };
11
- }
@@ -1,15 +0,0 @@
1
- import { StringPalette } from "../../Util/StringPalette";
2
- export class VoxelPalette {
3
- static _nameToIdMap = new Map();
4
- static _idToNameMap = new Map();
5
- static ids;
6
- static loadIn(voxelPalette, nameToIdMap, idToNameMap) {
7
- this.ids = new StringPalette(voxelPalette);
8
- this._nameToIdMap = new Map(Object.entries(nameToIdMap));
9
- this._idToNameMap = new Map(Object.entries(idToNameMap));
10
- }
11
- static name = {
12
- getId: (name) => this._nameToIdMap.get(name),
13
- getName: (id) => this._idToNameMap.get(id),
14
- };
15
- }
@@ -1,6 +0,0 @@
1
- import { StringPalette } from "../../Util/StringPalette";
2
- import { VoxelMaterialData } from "..";
3
- export declare const MaterialDataGenerator: {
4
- generate(data: VoxelMaterialData[]): void;
5
- palette: StringPalette;
6
- };
@@ -1,12 +0,0 @@
1
- import { MaterialPalette } from "../Palettes/MaterialPalette";
2
- import { StringPalette } from "../../Util/StringPalette";
3
- export const MaterialDataGenerator = {
4
- generate(data) {
5
- //build palette
6
- for (const substance of data) {
7
- this.palette.register(substance.id);
8
- }
9
- MaterialPalette.setPalette(this.palette._palette);
10
- },
11
- palette: new StringPalette(),
12
- };
@@ -1,6 +0,0 @@
1
- import { StringPalette } from "../../Util/StringPalette";
2
- import { VoxelSubstanceData } from "../Types/VoxelSubstances.types";
3
- export declare const SubstanceDataGenerator: {
4
- generate(data: VoxelSubstanceData[]): void;
5
- palette: StringPalette;
6
- };
@@ -1,35 +0,0 @@
1
- import { SubstancePalette } from "../Palettes/SubstancePalette";
2
- import { StringPalette } from "../../Util/StringPalette";
3
- import { SubstanceStructBuilder } from "../Structs/Builder/SubstanceStructBuilder";
4
- import { SubstanceStruct } from "..//Structs/SubstanceStruct";
5
- export const SubstanceDataGenerator = {
6
- generate(data) {
7
- //build palette
8
- for (const substance of data) {
9
- this.palette.register(substance.id);
10
- }
11
- SubstancePalette.setPalette(this.palette._palette);
12
- //create data buffer
13
- const tags = SubstanceStructBuilder.build(this.palette.size);
14
- const buffer = new SharedArrayBuffer(tags.structData.bufferSize);
15
- tags.structData.buffer = buffer;
16
- tags.setBuffer(buffer);
17
- //build data
18
- for (const substance of data) {
19
- const substanceID = SubstancePalette.id.numberFromString(substance.id);
20
- if (typeof substanceID == undefined)
21
- continue;
22
- tags.setStructArrayIndex(substanceID);
23
- SubstanceStructBuilder.setDefaults(tags);
24
- for (const id in substance.properties) {
25
- const value = substance.properties[id];
26
- if (!SubstanceStructBuilder.hasNode(id))
27
- continue;
28
- SubstanceStructBuilder.setNode(id, value, tags);
29
- }
30
- }
31
- SubstanceStruct.init(tags.structData);
32
- SubstanceStruct.instance.setBuffer(buffer);
33
- },
34
- palette: new StringPalette(),
35
- };
@@ -1,10 +0,0 @@
1
- import { BinaryStruct } from "@amodx/binary";
2
- import { StringPalette } from "../../Util/StringPalette";
3
- import { VoxelData } from "../Types/Voxel.types";
4
- export declare class VoxelDataGenerator {
5
- static overrides: Map<string, (tags: BinaryStruct, value: unknown, id: string) => void>;
6
- static nameToIdMap: Record<string, string>;
7
- static idToNameMap: Record<string, string>;
8
- static generate(data: VoxelData[]): void;
9
- static palette: StringPalette;
10
- }
@@ -1,56 +0,0 @@
1
- //objects
2
- import { VoxelStructBuilder } from "../Structs/Builder/VoxelStructBuilder";
3
- import { VoxelPalette } from "../Palettes/VoxelPalette";
4
- import { VoxelStruct } from "../Structs/VoxelStruct";
5
- import { StringPalette } from "../../Util/StringPalette";
6
- export class VoxelDataGenerator {
7
- static overrides = new Map();
8
- static nameToIdMap = {};
9
- static idToNameMap = {};
10
- static generate(data) {
11
- //build palette
12
- for (const voxel of data) {
13
- if (this.palette.isRegistered(voxel.id))
14
- throw new Error(`Duplicate voxel id ${voxel.id}`);
15
- this.palette.register(voxel.id);
16
- this.nameToIdMap[voxel.name ? voxel.name : voxel.id] = voxel.id;
17
- this.idToNameMap[voxel.id] = voxel.name ? voxel.name : voxel.id;
18
- }
19
- VoxelPalette.loadIn(this.palette._palette, this.nameToIdMap, this.idToNameMap);
20
- //build index
21
- const indexBuffer = new SharedArrayBuffer(this.palette.size * 2);
22
- const voxelIndex = new Uint16Array(indexBuffer);
23
- for (let i = 0; i < this.palette.size; i++) {
24
- voxelIndex[i] = i;
25
- }
26
- //create data bufferv
27
- const tags = VoxelStructBuilder.build(this.palette.size);
28
- const buffer = new SharedArrayBuffer(tags.structData.bufferSize);
29
- tags.structData.buffer = buffer;
30
- tags.setBuffer(buffer);
31
- // VoxelStruct.init(initData);
32
- // VoxelStruct.setBuffer(buffer);
33
- //build data
34
- for (const voxel of data) {
35
- const baseID = VoxelPalette.ids.getNumberId(voxel.id);
36
- if (!baseID)
37
- continue;
38
- tags.setStructArrayIndex(voxelIndex[baseID]);
39
- VoxelStructBuilder.setDefaults(tags);
40
- for (const id in voxel.properties) {
41
- const value = voxel.properties[id];
42
- if (!VoxelStructBuilder.hasNode(id))
43
- continue;
44
- if (this.overrides.has(id)) {
45
- this.overrides.get(id)(tags, value, id);
46
- continue;
47
- }
48
- VoxelStructBuilder.setNode(id, value, tags);
49
- }
50
- }
51
- VoxelStruct.sync(voxelIndex);
52
- VoxelStruct.init(tags.structData);
53
- VoxelStruct.instance.setBuffer(buffer);
54
- }
55
- static palette = new StringPalette();
56
- }
@@ -1,2 +0,0 @@
1
- import { StructBuilder } from "../../../Data/Structs/StructBuilder.js";
2
- export declare const SubstanceStructBuilder: StructBuilder;