@divinevoxel/vlox 0.0.73 → 0.0.74

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 (217) hide show
  1. package/Contexts/Base/Remote/InitDataSync.js +4 -0
  2. package/Contexts/Base/Remote/InitWorldDataSync.js +1 -1
  3. package/Contexts/Render/DivineVoxelEngineRender.d.ts +1 -0
  4. package/Contexts/World/DivineVoxelEngineWorld.d.ts +1 -0
  5. package/Init/StartConstructor.js +2 -0
  6. package/Math/index.d.ts +5 -1
  7. package/Mesher/Functions/CompactVoxelSectionMesh.d.ts +4 -0
  8. package/Mesher/Functions/CompactVoxelSectionMesh.js +112 -0
  9. package/Mesher/Functions/MeshSection.d.ts +1 -1
  10. package/Mesher/Functions/MeshSection.js +15 -22
  11. package/Mesher/Geomtry/CompactedSectionVoxelMesh.d.ts +23 -0
  12. package/Mesher/Geomtry/CompactedSectionVoxelMesh.js +144 -0
  13. package/Mesher/Geomtry/VoxelGeometryBuilder.d.ts +1 -1
  14. package/Mesher/Geomtry/VoxelGeometryBuilder.js +118 -197
  15. package/Mesher/Geomtry/VoxelMesh.js +2 -2
  16. package/Mesher/Geomtry/VoxelMeshBVHBuilder.d.ts +8 -70
  17. package/Mesher/Geomtry/VoxelMeshBVHBuilder.js +18 -183
  18. package/Mesher/Geomtry/VoxelMeshBVHStructCursor.d.ts +22 -0
  19. package/Mesher/Geomtry/VoxelMeshBVHStructCursor.js +78 -0
  20. package/Mesher/Geomtry/VoxelMeshBuffers.js +2 -2
  21. package/Mesher/InitTask.js +5 -1
  22. package/Mesher/Models/Common/BoxGeometryNode.js +7 -7
  23. package/Mesher/Models/Common/Calc/CalcConstants.d.ts +1 -1
  24. package/Mesher/Models/Common/Calc/CalcConstants.js +1 -1
  25. package/Mesher/Models/Common/QuadGeometryNode.js +2 -2
  26. package/Mesher/Models/Nodes/Custom/Liquid/LiquidGeomtryNode.js +7 -7
  27. package/Mesher/Models/Nodes/Ruled/BoxVoxelGeometryNode.js +22 -25
  28. package/Mesher/Models/Nodes/Ruled/QuadVoxelGeometryNode.js +2 -2
  29. package/Mesher/Models/Nodes/Ruleless/RulelessBoxVoxelGeometryNode.js +2 -2
  30. package/Mesher/Models/Nodes/Ruleless/RulelessQuadVoxelGeometryNode.js +2 -2
  31. package/Mesher/Models/VoxelConstructor.d.ts +3 -3
  32. package/Mesher/Models/VoxelConstructor.js +8 -8
  33. package/Mesher/Models/VoxelGeometryBuilderCacheSpace.d.ts +2 -2
  34. package/Mesher/Models/VoxelGeometryBuilderCacheSpace.js +8 -9
  35. package/Mesher/Models/VoxelModelBuilder.js +1 -8
  36. package/Mesher/Types/Mesher.types.d.ts +1 -0
  37. package/Models/Defaults/CubeVoxelModels.js +16 -39
  38. package/Models/Defaults/LiquidVoxelModel.js +3 -3
  39. package/Models/Defaults/PanelVoxelModels.js +10 -36
  40. package/Models/Defaults/StairVoxelModel.js +6 -21
  41. package/Models/Examples.js +23 -44
  42. package/Models/Rules/Classes/VoxelRulesModel.d.ts +1 -1
  43. package/Models/Rules/Classes/VoxelRulesModel.js +3 -3
  44. package/Models/Rules/Functions/BuildFinalInputs.d.ts +1 -1
  45. package/Models/Rules/Functions/BuildFinalInputs.js +13 -13
  46. package/Models/Rules/VoxelModelRuleBuilderRegister.js +8 -8
  47. package/Models/VoxelModel.types.d.ts +3 -3
  48. package/Renderer/Classes/DVESectionMeshes.d.ts +2 -3
  49. package/Renderer/InitTasks.js +1 -9
  50. package/Renderer/MeshManager.d.ts +1 -1
  51. package/Renderer/MeshManager.js +24 -23
  52. package/Renderer/MeshRegister.d.ts +5 -5
  53. package/Renderer/MeshRegister.js +2 -2
  54. package/Settings/EngineSettings.d.ts +1 -0
  55. package/Settings/EngineSettings.js +6 -3
  56. package/Settings/EngineSettings.types.d.ts +7 -21
  57. package/Settings/EngineSettings.types.js +6 -14
  58. package/Tasks/Logic/InitTasks.d.ts +1 -0
  59. package/Tasks/Logic/InitTasks.js +10 -0
  60. package/Tasks/Logic/VoxelLogicUpdate.d.ts +3 -0
  61. package/Tasks/Logic/VoxelLogicUpdate.js +71 -0
  62. package/Tasks/Propagation/Explosion/ExplosionManager.d.ts +2 -2
  63. package/Tasks/Propagation/Explosion/ExplosionManager.js +1 -2
  64. package/Tasks/Propagation/Flow/FlowManager.d.ts +4 -4
  65. package/Tasks/Propagation/Flow/FlowRemove.d.ts +2 -2
  66. package/Tasks/Propagation/Flow/FlowUpdate.d.ts +2 -2
  67. package/Tasks/Propagation/Flow/WorldFlow.d.ts +2 -2
  68. package/Tasks/Propagation/Illumanation/RGBUpdate.d.ts +3 -3
  69. package/Tasks/Propagation/Illumanation/SunUpdate.d.ts +3 -3
  70. package/Tasks/Propagation/Illumanation/WorldRGB.d.ts +2 -2
  71. package/Tasks/Propagation/Illumanation/WorldSun.d.ts +2 -2
  72. package/Tasks/Propagation/Illumanation/WorldSun.js +8 -15
  73. package/Tasks/Propagation/InitTasks.js +4 -4
  74. package/Tasks/Propagation/Power/PowerUpdate.d.ts +3 -0
  75. package/Tasks/Propagation/Power/PowerUpdate.js +80 -0
  76. package/Tasks/Tasks.types.d.ts +2 -2
  77. package/Tasks/TasksIds.d.ts +2 -1
  78. package/Tasks/TasksIds.js +1 -0
  79. package/Tasks/Update/Common.d.ts +3 -0
  80. package/Tasks/Update/Common.js +41 -0
  81. package/Tasks/Update/EreaseUpdate.d.ts +3 -0
  82. package/Tasks/Update/EreaseUpdate.js +66 -0
  83. package/Tasks/Update/InitTasks.d.ts +2 -2
  84. package/Tasks/Update/InitTasks.js +3 -1
  85. package/Tasks/Update/PaintUpdate.d.ts +3 -0
  86. package/Tasks/Update/PaintUpdate.js +89 -0
  87. package/Tasks/Update/VoxelUpdate.d.ts +2 -5
  88. package/Tasks/Update/VoxelUpdate.js +5 -147
  89. package/Tasks/{Update/UpdateTask.d.ts → VoxelUpdateTask.d.ts} +15 -7
  90. package/Tasks/{Update/UpdateTask.js → VoxelUpdateTask.js} +20 -7
  91. package/Tasks/WorldGeneration/WorldGenBrush.d.ts +3 -3
  92. package/Tasks/WorldGeneration/WorldGenBrush.js +2 -2
  93. package/Tasks/WorldGeneration/WorldGenRegister.d.ts +1 -1
  94. package/Templates/Functions/CreateTemplate.d.ts +1 -1
  95. package/Tools/Brush/AdvancedBrushTool.js +1 -1
  96. package/Tools/Brush/Brush.d.ts +2 -2
  97. package/Tools/Brush/Brush.js +1 -1
  98. package/Tools/Tasks/TasksTool.d.ts +1 -0
  99. package/Tools/Tasks/TasksTool.js +2 -0
  100. package/Util/Binary/BinaryBuffer.d.ts +17 -11
  101. package/Util/Binary/BinaryBuffer.js +65 -59
  102. package/Util/Binary/BinaryTree.d.ts +46 -0
  103. package/Util/Binary/BinaryTree.js +104 -0
  104. package/Voxels/Cursor/VoxelCursor.interface.d.ts +7 -2
  105. package/Voxels/Cursor/VoxelCursor.interface.js +46 -2
  106. package/Voxels/Cursor/VoxelLightData.js +1 -1
  107. package/Voxels/Data/VoxelTag.types.d.ts +17 -2
  108. package/Voxels/Data/VoxelTag.types.js +6 -1
  109. package/Voxels/Data/VoxelTagsRegister.js +5 -0
  110. package/Voxels/Functions/BuildStateData.d.ts +6 -6
  111. package/Voxels/Functions/BuildStateData.js +31 -31
  112. package/Voxels/Functions/BuildTagAndPaletteData.js +5 -0
  113. package/Voxels/Indexes/VoxelIndex.d.ts +2 -2
  114. package/Voxels/Indexes/VoxelIndex.js +16 -18
  115. package/Voxels/InitVoxelData.js +12 -8
  116. package/Voxels/Logic/Classes/Default/Types/VoxelPoweredLogicType.d.ts +5 -0
  117. package/Voxels/Logic/Classes/Default/Types/VoxelPoweredLogicType.js +6 -0
  118. package/Voxels/Logic/Classes/VoxelLogic.d.ts +11 -0
  119. package/Voxels/Logic/Classes/VoxelLogic.js +49 -0
  120. package/Voxels/Logic/Classes/VoxelLogicType.d.ts +4 -0
  121. package/Voxels/Logic/Classes/VoxelLogicType.js +2 -0
  122. package/Voxels/Logic/VoxelLogic.types.d.ts +23 -0
  123. package/Voxels/Logic/VoxelLogic.types.js +1 -0
  124. package/Voxels/Logic/VoxelLogicRegister.d.ts +9 -0
  125. package/Voxels/Logic/VoxelLogicRegister.js +15 -0
  126. package/Voxels/State/SchemaRegister.js +10 -5
  127. package/Voxels/State/State.types.d.ts +1 -1
  128. package/Voxels/State/StateTreeReader.d.ts +1 -1
  129. package/Voxels/State/StateTreeReader.js +2 -3
  130. package/Voxels/Types/Voxel.types.d.ts +3 -0
  131. package/Voxels/Types/VoxelModelCompiledData.types.d.ts +6 -4
  132. package/World/Archive/Archive.types.d.ts +31 -12
  133. package/World/Archive/Classes/ArchiveClasses.d.ts +66 -0
  134. package/World/Archive/Classes/ArchiveClasses.js +78 -0
  135. package/World/Archive/Classes/ImportedSection.d.ts +40 -0
  136. package/World/Archive/Classes/ImportedSection.js +307 -0
  137. package/World/Archive/Classes/ImportedSector.d.ts +23 -0
  138. package/World/Archive/Classes/ImportedSector.js +97 -0
  139. package/World/Archive/Functions/ArchiveArea.d.ts +1 -1
  140. package/World/Archive/Functions/ArchiveArea.js +39 -36
  141. package/World/Archive/Functions/ArchiveSector.js +210 -404
  142. package/World/Archive/Functions/CreateArchivedSection.d.ts +3 -0
  143. package/World/Archive/Functions/CreateArchivedSection.js +207 -0
  144. package/World/Archive/Functions/ImportSector.d.ts +1 -3
  145. package/World/Archive/Functions/ImportSector.js +13 -244
  146. package/World/Archive/Functions/RemoveDuplicates.d.ts +3 -0
  147. package/World/Archive/Functions/RemoveDuplicates.js +92 -0
  148. package/World/Archive/Functions/Shared.d.ts +2 -2
  149. package/World/Archive/Functions/Shared.js +15 -40
  150. package/World/Archive/InitTasks.js +7 -10
  151. package/World/Cursor/SectionCursor.d.ts +1 -1
  152. package/World/Cursor/SectorCursor.d.ts +1 -1
  153. package/World/Cursor/WorldCursor.d.ts +4 -3
  154. package/World/Cursor/WorldCursor.js +16 -13
  155. package/World/Cursor/WorldVoxelCursor.d.ts +0 -4
  156. package/World/Cursor/WorldVoxelCursor.js +23 -14
  157. package/World/Dimension/Dimension.d.ts +4 -1
  158. package/World/Dimension/Dimension.js +8 -1
  159. package/World/Section/Section.d.ts +17 -4
  160. package/World/Section/Section.js +68 -6
  161. package/World/Section/SectionState.d.ts +4 -2
  162. package/World/Section/SectionState.js +4 -2
  163. package/World/Sector/Sector.d.ts +7 -1
  164. package/World/Sector/Sector.js +37 -4
  165. package/World/Sector/SectorState.d.ts +3 -2
  166. package/World/Sector/SectorState.js +3 -2
  167. package/World/Types/WorldData.types.d.ts +2 -7
  168. package/World/WorldRegister.d.ts +9 -9
  169. package/World/WorldRegister.js +9 -6
  170. package/World/WorldSpaces.js +6 -6
  171. package/{Tasks/IWG → WorldSimulation}/Internal/Classes/DimensionSegment.d.ts +2 -2
  172. package/{Tasks/IWG → WorldSimulation}/Internal/Classes/Generator.d.ts +6 -4
  173. package/{Tasks/IWG → WorldSimulation}/Internal/Classes/Generator.js +9 -5
  174. package/WorldSimulation/Internal/Classes/Queues/BuildQueue.d.ts +5 -0
  175. package/WorldSimulation/Internal/Classes/Queues/BuildQueue.js +6 -0
  176. package/WorldSimulation/Internal/Classes/Queues/LogiccQueue.d.ts +5 -0
  177. package/WorldSimulation/Internal/Classes/Queues/LogiccQueue.js +6 -0
  178. package/{Tasks/IWG → WorldSimulation}/Internal/Classes/SectorVisistedMap.js +1 -1
  179. package/WorldSimulation/Internal/Classes/TickQueue.d.ts +12 -0
  180. package/{Tasks/IWG/Internal/Classes/BuildQueue.js → WorldSimulation/Internal/Classes/TickQueue.js} +16 -7
  181. package/WorldSimulation/Internal/Classes/WorldSimulationTaskBase.d.ts +15 -0
  182. package/{Tasks/IWG/Internal/Classes/IWGTaskBase.js → WorldSimulation/Internal/Classes/WorldSimulationTaskBase.js} +6 -6
  183. package/{Tasks/IWG → WorldSimulation}/Internal/Functions/cullSectors.js +9 -9
  184. package/{Tasks/IWG → WorldSimulation}/Internal/Functions/getSectorState.d.ts +1 -1
  185. package/{Tasks/IWG → WorldSimulation}/Internal/Functions/getSectorState.js +4 -4
  186. package/WorldSimulation/Internal/Functions/runTickUpdate.d.ts +2 -0
  187. package/{Tasks/IWG/Internal/Functions/runBuildUpdate.js → WorldSimulation/Internal/Functions/runTickUpdate.js} +29 -19
  188. package/{Tasks/IWG → WorldSimulation}/Internal/Functions/runWorldUpdate.js +13 -13
  189. package/{Tasks/IWG → WorldSimulation}/Internal/TaskRegister.d.ts +2 -2
  190. package/{Tasks/IWG → WorldSimulation}/Internal/TaskRegister.js +1 -1
  191. package/WorldSimulation/Internal/WorldSimulationDimensions.d.ts +6 -0
  192. package/{Tasks/IWG/Internal/IWGDimensions.js → WorldSimulation/Internal/WorldSimulationDimensions.js} +1 -1
  193. package/WorldSimulation/Internal/WorldSimulationTasks.d.ts +30 -0
  194. package/{Tasks/IWG/Internal/IWGTasks.js → WorldSimulation/Internal/WorldSimulationTasks.js} +14 -14
  195. package/WorldSimulation/Internal/WorldSimulationTools.d.ts +8 -0
  196. package/{Tasks/IWG/Internal/IWGTools.js → WorldSimulation/Internal/WorldSimulationTools.js} +1 -1
  197. package/{Tasks/IWG → WorldSimulation}/Procedures/InitalLoad.d.ts +1 -1
  198. package/{Tasks/IWG → WorldSimulation}/Procedures/InitalLoad.js +11 -11
  199. package/{Tasks/IWG → WorldSimulation}/Procedures/SaveAllSectors.js +5 -5
  200. package/{Tasks/IWG/IWG.d.ts → WorldSimulation/WorldSimulation.d.ts} +5 -5
  201. package/{Tasks/IWG/IWG.js → WorldSimulation/WorldSimulation.js} +21 -21
  202. package/{Tasks/IWG → WorldSimulation}/index.d.ts +1 -1
  203. package/{Tasks/IWG → WorldSimulation}/index.js +1 -1
  204. package/package.json +1 -1
  205. package/Tasks/IWG/Internal/Classes/BuildQueue.d.ts +0 -11
  206. package/Tasks/IWG/Internal/Classes/IWGTaskBase.d.ts +0 -15
  207. package/Tasks/IWG/Internal/Functions/runBuildUpdate.d.ts +0 -2
  208. package/Tasks/IWG/Internal/IWGDimensions.d.ts +0 -6
  209. package/Tasks/IWG/Internal/IWGTasks.d.ts +0 -30
  210. package/Tasks/IWG/Internal/IWGTools.d.ts +0 -8
  211. /package/{Tasks/IWG → WorldSimulation}/Internal/Classes/DimensionSegment.js +0 -0
  212. /package/{Tasks/IWG → WorldSimulation}/Internal/Classes/SectorState.d.ts +0 -0
  213. /package/{Tasks/IWG → WorldSimulation}/Internal/Classes/SectorState.js +0 -0
  214. /package/{Tasks/IWG → WorldSimulation}/Internal/Classes/SectorVisistedMap.d.ts +0 -0
  215. /package/{Tasks/IWG → WorldSimulation}/Internal/Functions/cullSectors.d.ts +0 -0
  216. /package/{Tasks/IWG → WorldSimulation}/Internal/Functions/runWorldUpdate.d.ts +0 -0
  217. /package/{Tasks/IWG → WorldSimulation}/Procedures/SaveAllSectors.d.ts +0 -0
@@ -5,6 +5,7 @@ import { SchemaRegister } from "../../../Voxels/State/SchemaRegister";
5
5
  import { VoxelTagStates } from "../../../Voxels/Data/VoxelTagStates";
6
6
  import { VoxelPalettesRegister } from "../../../Voxels/Data/VoxelPalettesRegister";
7
7
  import { VoxelTagsRegister } from "../../../Voxels/Data/VoxelTagsRegister";
8
+ import { VoxelLogicRegister } from "../../../Voxels/Logic/VoxelLogicRegister";
8
9
  export default function InitDataSync(props) {
9
10
  Threads.registerTask("sync-data", (data) => {
10
11
  EngineSettings.syncSettings(data.settings);
@@ -23,6 +24,9 @@ export default function InitDataSync(props) {
23
24
  SchemaRegister.registerVoxel(voxel.id, voxel.modelId, voxel.modSchema);
24
25
  }
25
26
  VoxelTagStates.load(modelData.tagState);
27
+ for (const id in data.voxels.data.logic) {
28
+ VoxelLogicRegister.register(id, data.voxels.data.logic[id]);
29
+ }
26
30
  props.onSync(data);
27
31
  });
28
32
  }
@@ -3,7 +3,7 @@ import { WorldDataSyncIds } from "../../../World/Types/WorldDataSyncIds.js";
3
3
  import { WorldRegister } from "../../../World/WorldRegister.js";
4
4
  export default function () {
5
5
  Threads.registerTask(WorldDataSyncIds.SyncDimension, (data) => {
6
- WorldRegister.dimensions.add(data.id);
6
+ WorldRegister.dimensions.add(data.index, data.id);
7
7
  });
8
8
  Threads.registerTask(WorldDataSyncIds.UnSyncDimension, (data) => {
9
9
  // register.dimensions.re(data.id);
@@ -24,6 +24,7 @@ export declare class DivineVoxelEngineRender {
24
24
  readonly doRGBPropagation: boolean;
25
25
  readonly doLight: boolean;
26
26
  readonly doFlow: boolean;
27
+ readonly doPower: boolean;
27
28
  getSettings(): EngineSettingsData;
28
29
  syncSettings(data: EngineSettingsData): void;
29
30
  getSettingsCopy(): any;
@@ -16,6 +16,7 @@ export declare class DivineVoxelEngineWorld {
16
16
  readonly doRGBPropagation: boolean;
17
17
  readonly doLight: boolean;
18
18
  readonly doFlow: boolean;
19
+ readonly doPower: boolean;
19
20
  getSettings(): import("../../Settings/EngineSettings.types.js").EngineSettingsData;
20
21
  syncSettings(data: import("../../Settings/EngineSettings.types.js").EngineSettingsData): void;
21
22
  getSettingsCopy(): any;
@@ -3,6 +3,7 @@ import { DivineVoxelEngineConstructor } from "../Contexts/Constructor/DivineVoxe
3
3
  import { Threads } from "@amodx/threads";
4
4
  import { Environment } from "../Util/Environment";
5
5
  import { WorldRegister } from "../World/WorldRegister";
6
+ import InitLogicTasks from "../Tasks/Logic/InitTasks";
6
7
  import InitUpdateTasks from "../Tasks/Update/InitTasks";
7
8
  import InitPropagationTasks from "../Tasks/Propagation/InitTasks";
8
9
  import InitMesherTasks from "../Mesher/InitTask";
@@ -42,6 +43,7 @@ export async function StartContrusctor(data = {}) {
42
43
  InitWorldDataSync();
43
44
  InitPropagationTasks();
44
45
  InitMesherTasks(DVEC.threads.parent);
46
+ InitLogicTasks();
45
47
  InitUpdateTasks({
46
48
  onDone(tasks, origin) {
47
49
  tasks.bounds.markSectionsAsDirty();
package/Math/index.d.ts CHANGED
@@ -1,8 +1,12 @@
1
1
  export * from "./VoxelFaces.js";
2
2
  export * from "./VoxelFaces.js";
3
3
  export type LocationData = [
4
- dimensionId: string,
4
+ /**Index for the dimension */
5
+ dimensionIndex: number,
6
+ /**x position */
5
7
  x: number,
8
+ /**y position */
6
9
  y: number,
10
+ /**z position */
7
11
  z: number
8
12
  ];
@@ -0,0 +1,4 @@
1
+ import { SetSectionMeshTask } from "../Types/Mesher.types";
2
+ import { VoxelModelBuilder } from "../Models/VoxelModelBuilder";
3
+ import { LocationData } from "../../Math";
4
+ export declare function CompactVoxelSectionMesh(location: LocationData, tools: VoxelModelBuilder[], transfers?: any[]): SetSectionMeshTask;
@@ -0,0 +1,112 @@
1
+ import { VoxelMeshVertexStructCursor } from "../Geomtry/VoxelMeshVertexStructCursor";
2
+ import { CompactedSectionVoxelMesh, CompactedMeshData, } from "../Geomtry/CompactedSectionVoxelMesh";
3
+ const meshData = new CompactedMeshData();
4
+ const compactedMesh = new CompactedSectionVoxelMesh();
5
+ /** Utility to ensure a value is aligned to 4 bytes. */
6
+ function align4(value) {
7
+ return (value + 3) & ~3;
8
+ }
9
+ export function CompactVoxelSectionMesh(location, tools, transfers = []) {
10
+ // 1) First compute how large the final buffer needs to be (with 4-byte alignment).
11
+ let headerSize = CompactedSectionVoxelMesh.GetHeaderByteSize(tools.length);
12
+ // Make the header itself 4-byte aligned
13
+ headerSize = align4(headerSize);
14
+ let totalByteCount = headerSize;
15
+ for (let i = 0; i < tools.length; i++) {
16
+ const tool = tools[i];
17
+ // Add the vertex data
18
+ const vertexByteSize = tool.mesh.vertexCount * VoxelMeshVertexStructCursor.VertexByteSize;
19
+ totalByteCount += vertexByteSize;
20
+ // Align after writing vertex data
21
+ totalByteCount = align4(totalByteCount);
22
+ // Add the index data
23
+ const indexByteSize = tool.mesh.indicieCount > 65535
24
+ ? tool.mesh.indicieCount * 4
25
+ : tool.mesh.indicieCount * 2;
26
+ totalByteCount += indexByteSize;
27
+ // Align after writing index data
28
+ totalByteCount = align4(totalByteCount);
29
+ }
30
+ // 2) Allocate the final buffer
31
+ const buffer = new ArrayBuffer(totalByteCount);
32
+ compactedMesh.setData(buffer);
33
+ compactedMesh.setLocation(...location);
34
+ compactedMesh.setTotalMeshes(tools.length);
35
+ // We'll track our position in the buffer here
36
+ let byteCount = headerSize;
37
+ for (let i = 0; i < tools.length; i++) {
38
+ const tool = tools[i];
39
+ // Fill out the meshData structure
40
+ meshData.material = tool.id;
41
+ const minBounds = tool.mesh.minBounds;
42
+ const maxBounds = tool.mesh.maxBounds;
43
+ meshData.minBounds[0] = minBounds.x;
44
+ meshData.minBounds[1] = minBounds.y;
45
+ meshData.minBounds[2] = minBounds.z;
46
+ meshData.maxBounds[0] = maxBounds.x;
47
+ meshData.maxBounds[1] = maxBounds.y;
48
+ meshData.maxBounds[2] = maxBounds.z;
49
+ // Vertex info
50
+ const totalVertFloats = tool.mesh.vertexCount * VoxelMeshVertexStructCursor.VertexFloatSize;
51
+ const vertexByteCount = totalVertFloats * 4;
52
+ meshData.vertexIndex[0] = byteCount;
53
+ meshData.vertexIndex[1] = totalVertFloats;
54
+ // Now move the pointer
55
+ byteCount += vertexByteCount;
56
+ // Align to 4 bytes again before writing indices
57
+ byteCount = align4(byteCount);
58
+ // Index info
59
+ meshData.indiceIndex[0] = byteCount;
60
+ meshData.indiceIndex[1] = tool.mesh.indicieCount;
61
+ const indexByteCount = tool.mesh.indicieCount > 65535
62
+ ? tool.mesh.indicieCount * 4
63
+ : tool.mesh.indicieCount * 2;
64
+ byteCount += indexByteCount;
65
+ // Align to 4 bytes for the next iteration (or final)
66
+ byteCount = align4(byteCount);
67
+ // Store the meta info
68
+ compactedMesh.setMeshData(i, meshData);
69
+ // Write vertex data
70
+ const vertexArray = new Float32Array(buffer, meshData.vertexIndex[0], totalVertFloats);
71
+ const vertexBuffers = tool.mesh.buffer._buffers;
72
+ let start = 0;
73
+ let done = false;
74
+ for (let b = 0; b < vertexBuffers.length; b++) {
75
+ const buf = vertexBuffers[b];
76
+ for (let j = 0; j < buf.length; j++) {
77
+ vertexArray[start] = buf[j];
78
+ start++;
79
+ if (start >= totalVertFloats) {
80
+ done = true;
81
+ break;
82
+ }
83
+ }
84
+ if (done)
85
+ break;
86
+ }
87
+ // Write index data
88
+ const indicesArray = tool.mesh.indicieCount > 65535
89
+ ? new Uint32Array(buffer, meshData.indiceIndex[0], tool.mesh.indicieCount)
90
+ : new Uint16Array(buffer, meshData.indiceIndex[0], tool.mesh.indicieCount);
91
+ const indiceBuffers = tool.mesh.indices._buffers;
92
+ start = 0;
93
+ done = false;
94
+ for (let b = 0; b < indiceBuffers.length; b++) {
95
+ const buf = indiceBuffers[b];
96
+ for (let j = 0; j < buf.length; j++) {
97
+ indicesArray[start] = buf[j];
98
+ start++;
99
+ if (start >= tool.mesh.indicieCount) {
100
+ done = true;
101
+ break;
102
+ }
103
+ }
104
+ if (done)
105
+ break;
106
+ }
107
+ }
108
+ // Transfer the ArrayBuffer to your worker if needed
109
+ transfers.push(buffer);
110
+ // Return the buffer or the task object as needed
111
+ return buffer;
112
+ }
@@ -1,3 +1,3 @@
1
1
  import { LocationData } from "../../Math";
2
- import type { SetSectionMeshTask } from "../../Renderer/Renderer.types.js";
2
+ import type { SetSectionMeshTask } from "../Types/Mesher.types";
3
3
  export declare function MeshSection(location: LocationData, transfers?: any[]): SetSectionMeshTask | null;
@@ -2,7 +2,6 @@
2
2
  import { WorldSpaces } from "../../World/WorldSpaces.js";
3
3
  //tools
4
4
  import { VoxelGeometryBuilderCacheSpace } from "../Models/VoxelGeometryBuilderCacheSpace.js";
5
- import { CompactVoxelMesh } from "./CompactVoxelMesh.js";
6
5
  import { WorldCursor } from "../../World/Cursor/WorldCursor.js";
7
6
  import { SectionCursor } from "../../World/Cursor/SectionCursor.js";
8
7
  import { VoxelModelConstructorRegister } from "../Models/VoxelModelConstructorRegister.js";
@@ -10,6 +9,7 @@ import { WorldRegister } from "../../World/WorldRegister.js";
10
9
  import { VoxelMeshBVHBuilder } from "../Geomtry/VoxelMeshBVHBuilder";
11
10
  import { Vector3Like } from "@amodx/math";
12
11
  import { RenderedMaterials } from "../Models/RenderedMaterials";
12
+ import { CompactVoxelSectionMesh } from "./CompactVoxelSectionMesh";
13
13
  const sectionCursor = new SectionCursor();
14
14
  const worldCursor = new WorldCursor();
15
15
  let space;
@@ -48,7 +48,7 @@ export function MeshSection(location, transfers = []) {
48
48
  sectionCursor.setSection(...location);
49
49
  let [minY, maxY] = section.getMinMax();
50
50
  if (minY == Infinity && maxY == -Infinity) {
51
- section.setDirty(false);
51
+ section.setDisplayDirty(false);
52
52
  section.setInProgress(false);
53
53
  return null;
54
54
  }
@@ -61,10 +61,10 @@ export function MeshSection(location, transfers = []) {
61
61
  mesher.bvhTool = bvhTool;
62
62
  mesher.effects = effects;
63
63
  }
64
- const volume = WorldSpaces.section.volumne;
65
64
  const slice = WorldSpaces.section.bounds.x * WorldSpaces.section.bounds.z;
66
- //const t = performance.now();
67
- for (let i = 0; i < volume; i++) {
65
+ const startY = minY * slice;
66
+ const endY = (maxY + 1) * slice;
67
+ for (let i = startY; i < endY; i++) {
68
68
  if (!(i % slice)) {
69
69
  const y = i / slice;
70
70
  if (!section.getHasVoxel(y) && !section.getHasVoxelDirty(y)) {
@@ -91,36 +91,29 @@ export function MeshSection(location, transfers = []) {
91
91
  }
92
92
  section.setBuried(i, !addedVoxel);
93
93
  }
94
- // console.log(performance.now() - t);
95
- const sectionEffects = [];
96
- const sections = [
97
- [location[0], ...section.getPosition()],
98
- [],
99
- sectionEffects,
100
- 0,
101
- ];
102
94
  const meshed = [];
103
95
  for (let i = 0; i < RenderedMaterials.meshers.length; i++) {
104
96
  const mesher = RenderedMaterials.meshers[i];
105
- for (const e in mesher.effects) {
106
- const float = Float32Array.from(mesher.effects[e]);
107
- transfers.push(float.buffer);
108
- sectionEffects.push([e, float]);
109
- }
110
97
  if (!mesher.mesh.vertexCount) {
111
98
  mesher.clear();
112
99
  mesher.bvhTool = null;
113
100
  continue;
114
101
  }
102
+ const { min, max } = mesher.bvhTool.getMeshBounds();
103
+ mesher.mesh.minBounds.x = min[0];
104
+ mesher.mesh.minBounds.y = min[1];
105
+ mesher.mesh.minBounds.z = min[2];
106
+ mesher.mesh.maxBounds.x = max[0];
107
+ mesher.mesh.maxBounds.y = max[1];
108
+ mesher.mesh.maxBounds.z = max[2];
115
109
  meshed.push(mesher);
116
110
  }
117
- const compactMesh = CompactVoxelMesh(meshed, transfers);
118
- sections[1] = compactMesh;
111
+ const compactMesh = CompactVoxelSectionMesh(location, meshed, transfers);
119
112
  for (let i = 0; i < meshed.length; i++) {
120
113
  meshed[i].clear();
121
114
  meshed[i].bvhTool = null;
122
115
  }
123
- section.setDirty(false);
116
+ section.setDisplayDirty(false);
124
117
  section.setInProgress(false);
125
- return sections;
118
+ return compactMesh;
126
119
  }
@@ -0,0 +1,23 @@
1
+ import { Vec3Array } from "@amodx/math";
2
+ import { LocationData } from "../../Math";
3
+ export declare class CompactedMeshData {
4
+ material: string;
5
+ minBounds: Vec3Array;
6
+ maxBounds: Vec3Array;
7
+ vertexIndex: [start: number, length: number];
8
+ indiceIndex: [start: number, length: number];
9
+ verticies: Float32Array;
10
+ indices: Uint16Array | Uint32Array;
11
+ }
12
+ export declare class CompactedSectionVoxelMesh {
13
+ static GetHeaderByteSize(totalMeshes?: number): number;
14
+ static GetMeshHeaderByteSize(): number;
15
+ data: DataView;
16
+ setData(data: ArrayBuffer): void;
17
+ setTotalMeshes(amount: number): void;
18
+ getTotalMeshes(): number;
19
+ setLocation(dimesion: number, x: number, y: number, z: number): void;
20
+ getLocation(location?: LocationData): LocationData;
21
+ setMeshData(index: number, mesh: CompactedMeshData): void;
22
+ getMeshData(index: number, mesh: CompactedMeshData): CompactedMeshData;
23
+ }
@@ -0,0 +1,144 @@
1
+ import { VoxelPalettesRegister } from "../../Voxels/Data/VoxelPalettesRegister";
2
+ export class CompactedMeshData {
3
+ material = "dve_solid";
4
+ minBounds = [0, 0, 0];
5
+ maxBounds = [0, 0, 0];
6
+ vertexIndex = [0, 0];
7
+ indiceIndex = [0, 0];
8
+ verticies;
9
+ indices;
10
+ }
11
+ export class CompactedSectionVoxelMesh {
12
+ static GetHeaderByteSize(totalMeshes = 0) {
13
+ return (
14
+ //dimension index 2 bytes uint16
15
+ 2 +
16
+ //position x 4 bytes int32
17
+ 4 +
18
+ //position y 4 bytes int32
19
+ 4 +
20
+ //position z 4 bytes int32
21
+ 4 +
22
+ //total meshes
23
+ 1 +
24
+ //other mehes
25
+ totalMeshes * this.GetMeshHeaderByteSize());
26
+ }
27
+ static GetMeshHeaderByteSize() {
28
+ return (
29
+ //material index 1 byte
30
+ 1 +
31
+ //min x 4 bytes Float32
32
+ 4 +
33
+ //min y 4 bytes Float32
34
+ 4 +
35
+ //min z 4 bytes Float32
36
+ 4 +
37
+ //max x 4 bytes Float32
38
+ 4 +
39
+ //max y 4 bytes Float32
40
+ 4 +
41
+ //max z 4 bytes Float32
42
+ 4 +
43
+ //Vertex Start Byte uint32
44
+ 4 +
45
+ //Vertex Length
46
+ 4 +
47
+ //Indice Start Byte uint32
48
+ 4 +
49
+ //Indice Length
50
+ 4);
51
+ }
52
+ data;
53
+ setData(data) {
54
+ this.data = new DataView(data);
55
+ }
56
+ setTotalMeshes(amount) {
57
+ this.data.setUint8(14, amount);
58
+ }
59
+ getTotalMeshes() {
60
+ return this.data.getUint8(14);
61
+ }
62
+ setLocation(dimesion, x, y, z) {
63
+ this.data.setInt16(0, dimesion);
64
+ this.data.setInt32(2, x);
65
+ this.data.setInt32(6, y);
66
+ this.data.setInt32(10, z);
67
+ }
68
+ getLocation(location = [0, 0, 0, 0]) {
69
+ location[0] = this.data.getInt16(0);
70
+ location[1] = this.data.getInt32(2);
71
+ location[2] = this.data.getInt32(6);
72
+ location[3] = this.data.getInt32(10);
73
+ return location;
74
+ }
75
+ setMeshData(index, mesh) {
76
+ const { material, minBounds, maxBounds, vertexIndex, indiceIndex } = mesh;
77
+ let startByte = CompactedSectionVoxelMesh.GetHeaderByteSize(0) +
78
+ CompactedSectionVoxelMesh.GetMeshHeaderByteSize() * index;
79
+ //material index
80
+ this.data.setUint8(startByte, VoxelPalettesRegister.material.getNumberId(material));
81
+ startByte++;
82
+ //min bounds
83
+ this.data.setFloat32(startByte, minBounds[0]);
84
+ startByte += 4;
85
+ this.data.setFloat32(startByte, minBounds[1]);
86
+ startByte += 4;
87
+ this.data.setFloat32(startByte, minBounds[2]);
88
+ startByte += 4;
89
+ //max bounds
90
+ this.data.setFloat32(startByte, maxBounds[0]);
91
+ startByte += 4;
92
+ this.data.setFloat32(startByte, maxBounds[1]);
93
+ startByte += 4;
94
+ this.data.setFloat32(startByte, maxBounds[2]);
95
+ startByte += 4;
96
+ //vertex index
97
+ this.data.setUint32(startByte, vertexIndex[0]);
98
+ startByte += 4;
99
+ this.data.setUint32(startByte, vertexIndex[1]);
100
+ startByte += 4;
101
+ //indice index
102
+ this.data.setUint32(startByte, indiceIndex[0]);
103
+ startByte += 4;
104
+ this.data.setUint32(startByte, indiceIndex[1]);
105
+ startByte += 4;
106
+ }
107
+ getMeshData(index, mesh) {
108
+ let startByte = CompactedSectionVoxelMesh.GetHeaderByteSize(0) +
109
+ CompactedSectionVoxelMesh.GetMeshHeaderByteSize() * index;
110
+ // material index
111
+ mesh.material = VoxelPalettesRegister.material.getStringId(this.data.getUint8(startByte));
112
+ startByte++;
113
+ // min bounds
114
+ mesh.minBounds[0] = this.data.getFloat32(startByte);
115
+ startByte += 4;
116
+ mesh.minBounds[1] = this.data.getFloat32(startByte);
117
+ startByte += 4;
118
+ mesh.minBounds[2] = this.data.getFloat32(startByte);
119
+ startByte += 4;
120
+ // max bounds
121
+ mesh.maxBounds[0] = this.data.getFloat32(startByte);
122
+ startByte += 4;
123
+ mesh.maxBounds[1] = this.data.getFloat32(startByte);
124
+ startByte += 4;
125
+ mesh.maxBounds[2] = this.data.getFloat32(startByte);
126
+ startByte += 4;
127
+ // vertex index
128
+ mesh.vertexIndex[0] = this.data.getUint32(startByte);
129
+ startByte += 4;
130
+ mesh.vertexIndex[1] = this.data.getUint32(startByte);
131
+ startByte += 4;
132
+ // indice index
133
+ mesh.indiceIndex[0] = this.data.getUint32(startByte);
134
+ startByte += 4;
135
+ mesh.indiceIndex[1] = this.data.getUint32(startByte);
136
+ startByte += 4;
137
+ mesh.verticies = new Float32Array(this.data.buffer, ...mesh.vertexIndex);
138
+ mesh.indices =
139
+ mesh.indiceIndex[1] > 65535
140
+ ? new Uint32Array(this.data.buffer, ...mesh.indiceIndex)
141
+ : new Uint16Array(this.data.buffer, ...mesh.indiceIndex);
142
+ return mesh;
143
+ }
144
+ }
@@ -2,5 +2,5 @@ import { Vector3Like } from "@amodx/math";
2
2
  import { VoxelModelBuilder } from "../Models/VoxelModelBuilder";
3
3
  import { Quad } from "./Primitives/Quad";
4
4
  export declare class VoxelGeometryBuilder {
5
- static addQuad(tool: VoxelModelBuilder, origin: Vector3Like, quad: Quad): void;
6
5
  }
6
+ export declare function addVoxelQuad(tool: VoxelModelBuilder, origin: Vector3Like, quad: Quad): void;