@divinevoxel/vlox 0.0.80 → 0.0.81

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 (162) hide show
  1. package/Builder/Tools/Brush/BrushTool.d.ts +12 -2
  2. package/Builder/Tools/Brush/BrushTool.js +53 -28
  3. package/Builder/Tools/Debug/DebugTool.d.ts +18 -0
  4. package/Builder/Tools/Debug/DebugTool.js +36 -0
  5. package/Builder/Tools/Path/PahtTool.d.ts +1 -1
  6. package/Builder/Tools/Path/PahtTool.js +1 -1
  7. package/Builder/Tools/Sculpt/SculptTool.js +8 -0
  8. package/Builder/Tools/Wrench/WrenchTool.js +10 -23
  9. package/Builder/Util/SurfaceBoxSelection.js +2 -0
  10. package/Builder/VoxelBuildSpace.js +3 -3
  11. package/Contexts/Base/Remote/InitDataSync.js +1 -1
  12. package/Math/UtilFunctions.js +7 -8
  13. package/Math/VoxelFaces.d.ts +2 -2
  14. package/Math/VoxelFaces.js +46 -55
  15. package/Math/WorldIndexing.d.ts +11 -0
  16. package/Math/WorldIndexing.js +34 -0
  17. package/Mesher/Geometry/Geometry.types.d.ts +2 -2
  18. package/Mesher/Geometry/Geometry.types.js +7 -20
  19. package/Mesher/Geometry/Primitives/QuadVertexData.js +118 -119
  20. package/Mesher/Geometry/Primitives/TriangleVertexData.js +89 -90
  21. package/Mesher/Geometry/Proto/ProtoMesh.d.ts +1 -1
  22. package/Mesher/Geometry/Proto/ProtoMesh.js +22 -29
  23. package/Mesher/Geometry/Proto/ProtoMeshBuffer.d.ts +4 -2
  24. package/Mesher/Geometry/Proto/ProtoMeshBuffer.js +14 -6
  25. package/Mesher/Geometry/Shapes/Box.js +6 -7
  26. package/Mesher/Geometry/Transform/TransformBox.js +8 -9
  27. package/Mesher/Geometry/Transform/TransformQuad.js +4 -5
  28. package/Mesher/Geometry/Transform/TransformTriangle.js +3 -4
  29. package/Mesher/InitMesher.js +4 -9
  30. package/Mesher/Items/Geometry/ItemGeometryBuilder.js +7 -8
  31. package/Mesher/Items/MeshTexture.js +125 -57
  32. package/Mesher/Voxels/Base/BuildVoxel.d.ts +6 -0
  33. package/Mesher/Voxels/Base/BuildVoxel.js +101 -0
  34. package/Mesher/Voxels/Base/CompactVoxelSectionMesh.js +1 -21
  35. package/Mesher/Voxels/Base/MeshSectionBase.js +3 -26
  36. package/Mesher/Voxels/Geometry/VoxelGeometryBuilder.js +33 -31
  37. package/Mesher/Voxels/Geometry/VoxelShaderData.js +3 -7
  38. package/Mesher/Voxels/MeshTemplate.js +6 -26
  39. package/Mesher/Voxels/MeshVoxel.js +5 -10
  40. package/Mesher/Voxels/Models/Common/Calc/CalcConstants.js +41 -42
  41. package/Mesher/Voxels/Models/Common/Calc/FaceDataCalc.js +6 -9
  42. package/Mesher/Voxels/Models/Common/Faces/CullRulledFace.js +64 -47
  43. package/Mesher/Voxels/Models/Common/Faces/ShadeRulledFace.js +57 -43
  44. package/Mesher/Voxels/Models/Nodes/Custom/Liquid/FlowGradient.js +4 -5
  45. package/Mesher/Voxels/Models/Nodes/Custom/Liquid/LiquidGeometryNode.d.ts +1 -1
  46. package/Mesher/Voxels/Models/Nodes/Custom/Liquid/LiquidGeometryNode.js +116 -118
  47. package/Mesher/Voxels/Models/Nodes/Default/QuadVoxelGeometryNode.js +4 -4
  48. package/Mesher/Voxels/Models/Nodes/VoxelGeometryConstructor.js +2 -2
  49. package/Mesher/Voxels/Models/Procedures/Default/OutlinedTextureProcedure.js +19 -21
  50. package/Mesher/Voxels/Models/Procedures/Default/PillarTextureProcedure.js +45 -38
  51. package/Mesher/Voxels/Models/RenderedMaterials.d.ts +1 -1
  52. package/Mesher/Voxels/Models/RenderedMaterials.js +8 -5
  53. package/Mesher/Voxels/Models/VoxelGeometryBuilderCacheSpace.d.ts +18 -4
  54. package/Mesher/Voxels/Models/VoxelGeometryBuilderCacheSpace.js +135 -22
  55. package/Mesher/Voxels/Models/VoxelGeometryBuilderCacheSpaceN.d.ts +33 -0
  56. package/Mesher/Voxels/Models/VoxelGeometryBuilderCacheSpaceN.js +204 -0
  57. package/Mesher/Voxels/Models/{VoxelModelConstructorRegister.d.ts → VoxelGeometryConstructorRegister.d.ts} +1 -6
  58. package/Mesher/Voxels/Models/VoxelGeometryConstructorRegister.js +20 -0
  59. package/Mesher/Voxels/Models/VoxelModelBuilder.js +15 -16
  60. package/Mesher/Voxels/Models/VoxelModelEffect.d.ts +1 -3
  61. package/Mesher/Voxels/Models/VoxelModelEffect.js +1 -3
  62. package/Renderer/DVERenderNode.types.d.ts +1 -0
  63. package/Renderer/InitTasks.js +2 -0
  64. package/Tasks/Paint/Erase/EraseVoxel.js +1 -1
  65. package/Tasks/Propagation/Illumanation/RGBUpdate.js +191 -48
  66. package/Tasks/Propagation/Illumanation/SunUpdate.d.ts +1 -1
  67. package/Tasks/Propagation/Illumanation/SunUpdate.js +167 -63
  68. package/Tasks/Propagation/Illumanation/WorldSun.js +96 -60
  69. package/Tasks/WorldGeneration/WorldGenBrush.d.ts +2 -0
  70. package/Tasks/WorldGeneration/WorldGenBrush.js +31 -0
  71. package/Templates/Archive/ArchivedVoxelTemplate.js +1 -1
  72. package/Templates/Archive/Functions/CreateArchivedTemplate.js +1 -1
  73. package/Templates/Archive/Functions/CreateArchivedTemplateFromFull.d.ts +6 -0
  74. package/Templates/Archive/Functions/CreateArchivedTemplateFromFull.js +174 -0
  75. package/Textures/Classes/CompactedTextureReader.d.ts +22 -0
  76. package/Textures/Classes/CompactedTextureReader.js +90 -0
  77. package/Textures/Classes/CompiledTexture.d.ts +4 -1
  78. package/Textures/Classes/CompiledTexture.js +36 -8
  79. package/Textures/Classes/TextureAtlasIndex.d.ts +7 -0
  80. package/Textures/Classes/TextureAtlasIndex.js +14 -0
  81. package/Textures/Classes/TextureLoader.d.ts +20 -0
  82. package/Textures/Classes/TextureLoader.js +95 -0
  83. package/Textures/Functions/BuildTextureData.d.ts +1 -1
  84. package/Textures/Functions/BuildTextureData.js +19 -122
  85. package/Textures/Functions/CreateCompactedTexture.d.ts +6 -0
  86. package/Textures/Functions/CreateCompactedTexture.js +105 -0
  87. package/Textures/Functions/ReadCompactedTexture.d.ts +2 -0
  88. package/Textures/Functions/ReadCompactedTexture.js +42 -0
  89. package/Textures/Texture.types.d.ts +14 -0
  90. package/Textures/TextureManager.d.ts +7 -1
  91. package/Textures/TextureManager.js +13 -0
  92. package/Tools/Brush/Brush.d.ts +4 -2
  93. package/Tools/Brush/Brush.js +28 -6
  94. package/Util/BinaryBuffer/Functions/BinaryBufferConvert.d.ts +1 -1
  95. package/Util/TickInterval.d.ts +3 -0
  96. package/Util/TickInterval.js +31 -3
  97. package/Voxels/Archive/VoxelPaletteArchiveReader.d.ts +1 -0
  98. package/Voxels/Archive/VoxelPaletteArchiveReader.js +9 -10
  99. package/Voxels/Archive/VoxelPaletteArechive.js +5 -4
  100. package/Voxels/Cursor/VoxelCursor.interface.d.ts +1 -1
  101. package/Voxels/Cursor/VoxelCursor.interface.js +22 -16
  102. package/Voxels/Data/VoxelLUT.d.ts +69 -42
  103. package/Voxels/Data/VoxelLUT.js +110 -53
  104. package/Voxels/Functions/BuildLUTs.js +100 -45
  105. package/Voxels/Functions/Geometry/CalcFunctions.js +6 -7
  106. package/Voxels/Functions/Geometry/Inputs/BuildTriangleInputs.js +3 -0
  107. package/Voxels/Indexes/VoxelIndex.js +3 -1
  108. package/Voxels/InitVoxelData.js +3 -1
  109. package/Voxels/Interaction/Functions/PickVoxel.js +3 -5
  110. package/Voxels/Interaction/Functions/PickVoxelWorld.js +4 -6
  111. package/Voxels/Models/Defaults/Examples.d.ts +2 -0
  112. package/Voxels/Models/Defaults/Examples.js +151 -2
  113. package/Voxels/State/Reltional/ReltionalStateBuilder.js +2 -0
  114. package/Voxels/State/Schema/BinarySchema.d.ts +1 -0
  115. package/Voxels/State/Schema/BinarySchema.js +14 -0
  116. package/Voxels/State/VoxelSchemas.d.ts +11 -4
  117. package/Voxels/State/VoxelSchemas.js +42 -9
  118. package/Voxels/Types/PaintVoxelData.js +6 -2
  119. package/World/Archive/Classes/ImportedSection.js +1 -1
  120. package/World/Archive/Classes/ImportedSector.js +0 -1
  121. package/World/Archive/Functions/Sector/ArchiveSector.js +2 -2
  122. package/World/Archive/Functions/Sector/ImportSector.d.ts +1 -0
  123. package/World/Archive/Functions/Sector/ImportSector.js +183 -7
  124. package/World/Cursor/SectorCursor.js +1 -4
  125. package/World/Cursor/WorldCursor.d.ts +12 -3
  126. package/World/Cursor/WorldCursor.js +60 -30
  127. package/World/InitTasks.js +1 -1
  128. package/World/Lock/Function/LockSectors.js +5 -1
  129. package/World/Lock/Function/UnLockSectors.js +5 -1
  130. package/World/SnapShot/SectionSnapShot.d.ts +7 -3
  131. package/World/SnapShot/SectionSnapShot.js +47 -21
  132. package/World/SnapShot/SectionSnapShotCursor.d.ts +4 -2
  133. package/World/SnapShot/SectionSnapShotCursor.js +23 -11
  134. package/World/SnapShot/SnapShots.d.ts +1 -2
  135. package/World/SnapShot/SnapShots.js +3 -3
  136. package/World/WorldSpaces.d.ts +7 -0
  137. package/World/WorldSpaces.js +35 -13
  138. package/WorldSimulation/Dimensions/DimensionSegment.d.ts +2 -0
  139. package/WorldSimulation/Dimensions/DimensionSegment.js +9 -1
  140. package/WorldSimulation/Dimensions/DimensionSimulation.js +6 -7
  141. package/WorldSimulation/Dimensions/Generator.d.ts +4 -0
  142. package/WorldSimulation/Dimensions/Generator.js +15 -1
  143. package/WorldSimulation/Dimensions/SimulationSector.d.ts +1 -0
  144. package/WorldSimulation/Dimensions/SimulationSector.js +18 -0
  145. package/WorldSimulation/Internal/WorldSimulationTasks.js +11 -7
  146. package/WorldSimulation/Procedures/InitalLoad.d.ts +1 -0
  147. package/WorldSimulation/Procedures/InitalLoad.js +18 -8
  148. package/WorldSimulation/Tasks/SimulationTaskBase.d.ts +4 -1
  149. package/WorldSimulation/Tasks/SimulationTaskBase.js +13 -2
  150. package/WorldSimulation/Tasks/TaskSegment.d.ts +4 -2
  151. package/WorldSimulation/Tasks/TaskSegment.js +36 -22
  152. package/WorldSimulation/Voxels/Ticks/Types/LiquidVoxelUpdate.js +1 -2
  153. package/WorldSimulation/WorldSimulation.d.ts +6 -3
  154. package/WorldSimulation/WorldSimulation.js +44 -20
  155. package/package.json +1 -1
  156. package/Mesher/Items/MeshTextureO.d.ts +0 -1
  157. package/Mesher/Items/MeshTextureO.js +0 -277
  158. package/Mesher/Voxels/Models/VoxelConstructor.d.ts +0 -8
  159. package/Mesher/Voxels/Models/VoxelConstructor.js +0 -78
  160. package/Mesher/Voxels/Models/VoxelModelConstructorRegister.js +0 -37
  161. package/WorldSimulation/Procedures/BuildOnly.d.ts +0 -10
  162. package/WorldSimulation/Procedures/BuildOnly.js +0 -55
@@ -1,117 +1,221 @@
1
1
  import { VoxelLightData } from "../../../Voxels/Cursor/VoxelLightData";
2
2
  import { isLessThanForSunAdd, getMinusOneForSun, isLessThanForSunAddDown, getSunLightForUnderVoxel, removeSunLight, isLessThanForSunRemove, isGreaterOrEqualThanForSunRemove, sunLightCompareForDownSunRemove, } from "./CommonFunctions";
3
- const FloodOutPositions = [
4
- [1, 0, 0],
5
- [-1, 0, 0],
6
- [0, 0, 1],
7
- [0, 0, -1],
8
- [0, 1, 0],
9
- ];
10
3
  export function SunUpdate(tasks) {
11
4
  const queue = tasks.sun.update;
12
- while (queue.length) {
13
- const x = queue.shift();
14
- const y = queue.shift();
15
- const z = queue.shift();
16
- const voxel = tasks.sDataCursor.getVoxel(x, y, z);
5
+ const sDataCursor = tasks.sDataCursor;
6
+ const nDataCursor = tasks.nDataCursor;
7
+ const bounds = tasks.bounds;
8
+ const sunFallOff = VoxelLightData.SunFallOffValue;
9
+ let queueIndex = 0;
10
+ while (queueIndex < queue.length) {
11
+ const x = queue[queueIndex++];
12
+ const y = queue[queueIndex++];
13
+ const z = queue[queueIndex++];
14
+ const voxel = sDataCursor.getVoxel(x, y, z);
17
15
  if (!voxel)
18
16
  continue;
19
17
  const sl = voxel.getLight();
20
18
  if (sl <= 0)
21
19
  continue;
22
- for (let i = 0; i < 5; i++) {
23
- const nx = FloodOutPositions[i][0] + x;
24
- const ny = FloodOutPositions[i][1] + y;
25
- const nz = FloodOutPositions[i][2] + z;
26
- if (!tasks.nDataCursor.inBounds(nx, ny, nz))
27
- continue;
28
- const nVoxel = tasks.nDataCursor.getVoxel(nx, ny, nz);
20
+ let nx, ny, nz, nVoxel, nl;
21
+ nx = x + 1;
22
+ if (nDataCursor.inBounds(nx, y, z)) {
23
+ nVoxel = nDataCursor.getVoxel(nx, y, z);
29
24
  if (nVoxel) {
30
- const nl = nVoxel.getLight();
31
- if (nl > -1 && isLessThanForSunAdd(nl, sl, VoxelLightData.SunFallOffValue)) {
32
- queue.push(nx, ny, nz);
33
- nVoxel.setLight(getMinusOneForSun(sl, nl, VoxelLightData.SunFallOffValue));
25
+ nl = nVoxel.getLight();
26
+ if (nl > -1 && isLessThanForSunAdd(nl, sl, sunFallOff)) {
27
+ queue.push(nx, y, z);
28
+ nVoxel.setLight(getMinusOneForSun(sl, nl, sunFallOff));
34
29
  }
35
30
  }
36
31
  }
37
- if (tasks.nDataCursor.inBounds(x, y - 1, z)) {
38
- const nVoxel = tasks.nDataCursor.getVoxel(x, y - 1, z);
32
+ nx = x - 1;
33
+ if (nDataCursor.inBounds(nx, y, z)) {
34
+ nVoxel = nDataCursor.getVoxel(nx, y, z);
39
35
  if (nVoxel) {
40
- const nl = nVoxel.getLight();
41
- if (nl > -1 && isLessThanForSunAddDown(nl, sl, VoxelLightData.SunFallOffValue)) {
36
+ nl = nVoxel.getLight();
37
+ if (nl > -1 && isLessThanForSunAdd(nl, sl, sunFallOff)) {
38
+ queue.push(nx, y, z);
39
+ nVoxel.setLight(getMinusOneForSun(sl, nl, sunFallOff));
40
+ }
41
+ }
42
+ }
43
+ nz = z + 1;
44
+ if (nDataCursor.inBounds(x, y, nz)) {
45
+ nVoxel = nDataCursor.getVoxel(x, y, nz);
46
+ if (nVoxel) {
47
+ nl = nVoxel.getLight();
48
+ if (nl > -1 && isLessThanForSunAdd(nl, sl, sunFallOff)) {
49
+ queue.push(x, y, nz);
50
+ nVoxel.setLight(getMinusOneForSun(sl, nl, sunFallOff));
51
+ }
52
+ }
53
+ }
54
+ nz = z - 1;
55
+ if (nDataCursor.inBounds(x, y, nz)) {
56
+ nVoxel = nDataCursor.getVoxel(x, y, nz);
57
+ if (nVoxel) {
58
+ nl = nVoxel.getLight();
59
+ if (nl > -1 && isLessThanForSunAdd(nl, sl, sunFallOff)) {
60
+ queue.push(x, y, nz);
61
+ nVoxel.setLight(getMinusOneForSun(sl, nl, sunFallOff));
62
+ }
63
+ }
64
+ }
65
+ ny = y + 1;
66
+ if (nDataCursor.inBounds(x, ny, z)) {
67
+ nVoxel = nDataCursor.getVoxel(x, ny, z);
68
+ if (nVoxel) {
69
+ nl = nVoxel.getLight();
70
+ if (nl > -1 && isLessThanForSunAdd(nl, sl, sunFallOff)) {
71
+ queue.push(x, ny, z);
72
+ nVoxel.setLight(getMinusOneForSun(sl, nl, sunFallOff));
73
+ }
74
+ }
75
+ }
76
+ ny = y - 1;
77
+ if (nDataCursor.inBounds(x, ny, z)) {
78
+ nVoxel = nDataCursor.getVoxel(x, ny, z);
79
+ if (nVoxel) {
80
+ nl = nVoxel.getLight();
81
+ if (nl > -1 && isLessThanForSunAddDown(nl, sl, sunFallOff)) {
42
82
  if (nVoxel.isAir()) {
43
- queue.push(x, y - 1, z);
44
- nVoxel.setLight(getSunLightForUnderVoxel(sl, nl, VoxelLightData.SunFallOffValue));
83
+ queue.push(x, ny, z);
84
+ nVoxel.setLight(getSunLightForUnderVoxel(sl, nl, sunFallOff));
45
85
  }
46
- else {
47
- if (!nVoxel.isOpaque()) {
48
- queue.push(x, y - 1, z);
49
- nVoxel.setLight(getMinusOneForSun(sl, nl, VoxelLightData.SunFallOffValue));
50
- }
86
+ else if (!nVoxel.isOpaque()) {
87
+ queue.push(x, ny, z);
88
+ nVoxel.setLight(getMinusOneForSun(sl, nl, sunFallOff));
51
89
  }
52
90
  }
53
91
  }
54
92
  }
55
- tasks.bounds.updateDisplay(x, y, z);
93
+ bounds.updateDisplay(x, y, z);
56
94
  }
95
+ queue.length = 0;
57
96
  }
58
- export function SunRemove(tasks, clearUpdateMap = true) {
97
+ export function SunRemove(tasks) {
59
98
  const remove = tasks.sun.remove;
60
99
  const update = tasks.sun.update;
61
100
  const removeMap = tasks.sun.removeMap;
62
101
  const updateMap = tasks.sun.updateMap;
63
- while (remove.length) {
64
- const x = remove.shift();
65
- const y = remove.shift();
66
- const z = remove.shift();
102
+ const sDataCursor = tasks.sDataCursor;
103
+ const nDataCursor = tasks.nDataCursor;
104
+ const bounds = tasks.bounds;
105
+ let removeIndex = 0;
106
+ while (removeIndex < remove.length) {
107
+ const x = remove[removeIndex++];
108
+ const y = remove[removeIndex++];
109
+ const z = remove[removeIndex++];
67
110
  if (removeMap.has(x, y, z))
68
111
  continue;
69
112
  removeMap.add(x, y, z);
70
- const voxel = tasks.sDataCursor.getVoxel(x, y, z);
113
+ const voxel = sDataCursor.getVoxel(x, y, z);
71
114
  if (!voxel)
72
115
  continue;
73
116
  const sl = voxel.getLight();
74
117
  if (sl <= 0)
75
118
  continue;
76
- for (let i = 0; i < 5; i++) {
77
- const nx = FloodOutPositions[i][0] + x;
78
- const ny = FloodOutPositions[i][1] + y;
79
- const nz = FloodOutPositions[i][2] + z;
80
- if (!tasks.nDataCursor.inBounds(nx, ny, nz))
81
- continue;
82
- const nVoxel = tasks.nDataCursor.getVoxel(nx, ny, nz);
119
+ let nx, ny, nz, nVoxel, nl;
120
+ nx = x + 1;
121
+ if (nDataCursor.inBounds(nx, y, z)) {
122
+ nVoxel = nDataCursor.getVoxel(nx, y, z);
123
+ if (nVoxel) {
124
+ nl = nVoxel.getLight();
125
+ if (nl > 0) {
126
+ if (isLessThanForSunRemove(nl, sl)) {
127
+ remove.push(nx, y, z);
128
+ }
129
+ else if (isGreaterOrEqualThanForSunRemove(nl, sl) && !updateMap.has(nx, y, z)) {
130
+ updateMap.add(nx, y, z);
131
+ update.push(nx, y, z);
132
+ }
133
+ }
134
+ }
135
+ }
136
+ nx = x - 1;
137
+ if (nDataCursor.inBounds(nx, y, z)) {
138
+ nVoxel = nDataCursor.getVoxel(nx, y, z);
139
+ if (nVoxel) {
140
+ nl = nVoxel.getLight();
141
+ if (nl > 0) {
142
+ if (isLessThanForSunRemove(nl, sl)) {
143
+ remove.push(nx, y, z);
144
+ }
145
+ else if (isGreaterOrEqualThanForSunRemove(nl, sl) && !updateMap.has(nx, y, z)) {
146
+ updateMap.add(nx, y, z);
147
+ update.push(nx, y, z);
148
+ }
149
+ }
150
+ }
151
+ }
152
+ nz = z + 1;
153
+ if (nDataCursor.inBounds(x, y, nz)) {
154
+ nVoxel = nDataCursor.getVoxel(x, y, nz);
155
+ if (nVoxel) {
156
+ nl = nVoxel.getLight();
157
+ if (nl > 0) {
158
+ if (isLessThanForSunRemove(nl, sl)) {
159
+ remove.push(x, y, nz);
160
+ }
161
+ else if (isGreaterOrEqualThanForSunRemove(nl, sl) && !updateMap.has(x, y, nz)) {
162
+ updateMap.add(x, y, nz);
163
+ update.push(x, y, nz);
164
+ }
165
+ }
166
+ }
167
+ }
168
+ nz = z - 1;
169
+ if (nDataCursor.inBounds(x, y, nz)) {
170
+ nVoxel = nDataCursor.getVoxel(x, y, nz);
171
+ if (nVoxel) {
172
+ nl = nVoxel.getLight();
173
+ if (nl > 0) {
174
+ if (isLessThanForSunRemove(nl, sl)) {
175
+ remove.push(x, y, nz);
176
+ }
177
+ else if (isGreaterOrEqualThanForSunRemove(nl, sl) && !updateMap.has(x, y, nz)) {
178
+ updateMap.add(x, y, nz);
179
+ update.push(x, y, nz);
180
+ }
181
+ }
182
+ }
183
+ }
184
+ ny = y + 1;
185
+ if (nDataCursor.inBounds(x, ny, z)) {
186
+ nVoxel = nDataCursor.getVoxel(x, ny, z);
83
187
  if (nVoxel) {
84
- const nl = nVoxel.getLight();
188
+ nl = nVoxel.getLight();
85
189
  if (nl > 0) {
86
190
  if (isLessThanForSunRemove(nl, sl)) {
87
- remove.push(nx, ny, nz);
191
+ remove.push(x, ny, z);
88
192
  }
89
- else if (isGreaterOrEqualThanForSunRemove(nl, sl) &&
90
- !updateMap.has(nx, ny, nz)) {
91
- updateMap.add(nx, ny, nz);
92
- update.push(nx, ny, nz);
193
+ else if (isGreaterOrEqualThanForSunRemove(nl, sl) && !updateMap.has(x, ny, z)) {
194
+ updateMap.add(x, ny, z);
195
+ update.push(x, ny, z);
93
196
  }
94
197
  }
95
198
  }
96
199
  }
97
- if (tasks.nDataCursor.inBounds(x, y - 1, z)) {
98
- const nVoxel = tasks.nDataCursor.getVoxel(x, y - 1, z);
200
+ ny = y - 1;
201
+ if (nDataCursor.inBounds(x, ny, z)) {
202
+ nVoxel = nDataCursor.getVoxel(x, ny, z);
99
203
  if (nVoxel) {
100
- const nl = nVoxel.getLight();
204
+ nl = nVoxel.getLight();
101
205
  if (nl > 0) {
102
206
  if (sunLightCompareForDownSunRemove(nl, sl)) {
103
- remove.push(x, y - 1, z);
207
+ remove.push(x, ny, z);
104
208
  }
105
- else if (isGreaterOrEqualThanForSunRemove(nl, sl) &&
106
- !updateMap.has(x, y - 1, z)) {
107
- updateMap.add(x, y - 1, z);
108
- update.push(x, y - 1, z);
209
+ else if (isGreaterOrEqualThanForSunRemove(nl, sl) && !updateMap.has(x, ny, z)) {
210
+ updateMap.add(x, ny, z);
211
+ update.push(x, ny, z);
109
212
  }
110
213
  }
111
214
  }
112
215
  }
113
- tasks.bounds.updateDisplay(x, y, z);
216
+ bounds.updateDisplay(x, y, z);
114
217
  voxel.setLight(removeSunLight(sl));
115
218
  }
219
+ remove.length = 0;
116
220
  removeMap.clear();
117
221
  }
@@ -3,31 +3,33 @@ import { WorldSpaces } from "../../../World/WorldSpaces.js";
3
3
  import { SectorHeightMap } from "../../../World/Sector/SectorHeightMap.js";
4
4
  import { VoxelLightData } from "../../../Voxels/Cursor/VoxelLightData.js";
5
5
  import { getMinusOneForSun, getSunLightForUnderVoxel, isLessThanForSunAddDown, isLessThanForSunAdd, } from "./CommonFunctions.js";
6
- const FloodOutPositions = [
7
- [1, 0, 0],
8
- [-1, 0, 0],
9
- [0, 0, 1],
10
- [0, 0, -1],
11
- [0, 1, 0],
12
- ];
13
6
  const queue = [];
14
7
  const lightData = new VoxelLightData();
15
8
  export function RunWorldSun(tasks) {
16
- const [, cx, cy, cz] = tasks.origin;
17
- const RmaxY = SectorHeightMap.getRelative(tasks.origin);
18
- const AmaxY = SectorHeightMap.getAbsolute(...tasks.origin);
19
- const maxX = cx + WorldSpaces.sector.bounds.x;
20
- const maxY = cy + WorldSpaces.sector.bounds.y;
21
- const maxZ = cz + WorldSpaces.sector.bounds.z;
22
- const sectorCursor = tasks.nDataCursor.getSector(tasks.origin[1], tasks.origin[2], tasks.origin[3]);
9
+ const origin = tasks.origin;
10
+ const cx = origin[1];
11
+ const cy = origin[2];
12
+ const cz = origin[3];
13
+ const sectorBoundsX = WorldSpaces.sector.bounds.x;
14
+ const sectorBoundsY = WorldSpaces.sector.bounds.y;
15
+ const sectorBoundsZ = WorldSpaces.sector.bounds.z;
16
+ const sectionBoundsY = WorldSpaces.section.bounds.y;
17
+ const RmaxY = SectorHeightMap.getRelative(origin);
18
+ const AmaxY = SectorHeightMap.getAbsolute(origin[0], origin[1], origin[2], origin[3]);
19
+ const maxX = cx + sectorBoundsX;
20
+ const maxY = cy + sectorBoundsY;
21
+ const maxZ = cz + sectorBoundsZ;
22
+ const sectorCursor = tasks.nDataCursor.getSector(origin[1], origin[2], origin[3]);
23
23
  if (!sectorCursor) {
24
- console.warn("Could not load sector when running world sun at ", tasks.origin.toString());
24
+ console.warn("Could not load sector when running world sun at ", origin.toString());
25
25
  return;
26
26
  }
27
27
  const minY = AmaxY - 1 < 0 ? 0 : AmaxY;
28
28
  const section = sectorCursor.getSection(cx, minY, cz);
29
- const sectionY = section.getPosition()[1] + WorldSpaces.section.bounds.y;
30
- //fill to relative max y
29
+ const sectionY = section.getPosition()[1] + sectionBoundsY;
30
+ const sunFallOff = VoxelLightData.SunFallOffValue;
31
+ const nDataCursor = tasks.nDataCursor;
32
+ const sDataCursor = tasks.sDataCursor;
31
33
  for (let iy = minY; iy < sectionY; iy++) {
32
34
  for (let ix = cx; ix < maxX; ix++) {
33
35
  for (let iz = cz; iz < maxZ; iz++) {
@@ -41,80 +43,114 @@ export function RunWorldSun(tasks) {
41
43
  }
42
44
  }
43
45
  }
44
- //fill rest
45
- for (let iy = sectionY; iy < maxY; iy += WorldSpaces.section.bounds.y) {
46
- const section = sectorCursor.getSection(cx, iy, cz);
47
- const length = section.light.length;
46
+ for (let iy = sectionY; iy < maxY; iy += sectionBoundsY) {
47
+ const sec = sectorCursor.getSection(cx, iy, cz);
48
+ const light = sec.light;
49
+ const length = light.length;
48
50
  for (let i = 0; i < length; i++) {
49
- section.light[i] = lightData.setS(0xf, section.light[i]);
51
+ light[i] = lightData.setS(0xf, light[i]);
50
52
  }
51
53
  }
52
- //accumulate
53
54
  const maxAcculamteY = AmaxY == RmaxY ? RmaxY + 1 : RmaxY;
54
- let index = queue.length;
55
+ let queueIndex = 0;
56
+ queue.length = 0;
55
57
  for (let iy = minY; iy <= maxAcculamteY; iy++) {
56
58
  for (let ix = cx; ix < maxX; ix++) {
57
59
  for (let iz = cz; iz < maxZ; iz++) {
58
- const l = sectorCursor.getVoxel(ix, iy, iz)?.getLight();
59
- if (l && l < 0 && lightData.getS(l) != 0xf)
60
+ const voxel = sectorCursor.getVoxel(ix, iy, iz);
61
+ if (!voxel)
62
+ continue;
63
+ const l = voxel.getLight();
64
+ if (l < 0 || lightData.getS(l) != 0xf)
60
65
  continue;
61
66
  for (let i = 0; i < CardinalNeighbors3D.length; i++) {
62
67
  const n = CardinalNeighbors3D[i];
63
68
  const nx = ix + n[0];
64
69
  const ny = iy + n[1];
65
70
  const nz = iz + n[2];
66
- const nVoxel = tasks.nDataCursor.getVoxel(nx, ny, nz);
71
+ const nVoxel = nDataCursor.getVoxel(nx, ny, nz);
67
72
  if (!nVoxel)
68
73
  continue;
69
74
  const nl = nVoxel.getLight();
70
75
  if (nl > -1 && lightData.getS(nl) < 0xf) {
71
- queue[index++] = ix;
72
- queue[index++] = iy;
73
- queue[index++] = iz;
76
+ queue.push(ix, iy, iz);
74
77
  break;
75
78
  }
76
79
  }
77
80
  }
78
81
  }
79
82
  }
80
- //flood
81
- while (queue.length) {
82
- const x = queue.shift();
83
- const y = queue.shift();
84
- const z = queue.shift();
85
- const sl = tasks.sDataCursor.getVoxel(x, y, z)?.getLight();
86
- if (!sl || sl < 0)
83
+ while (queueIndex < queue.length) {
84
+ const x = queue[queueIndex++];
85
+ const y = queue[queueIndex++];
86
+ const z = queue[queueIndex++];
87
+ const voxel = sDataCursor.getVoxel(x, y, z);
88
+ if (!voxel)
87
89
  continue;
88
- for (let i = 0; i < 5; i++) {
89
- const nx = x + FloodOutPositions[i][0];
90
- const ny = y + FloodOutPositions[i][1];
91
- const nz = z + FloodOutPositions[i][2];
92
- const nVoxel = tasks.nDataCursor.getVoxel(nx, ny, nz);
93
- if (nVoxel) {
94
- const nl = nVoxel.getLight();
95
- if (nl > -1 &&
96
- isLessThanForSunAdd(nl, sl, VoxelLightData.SunFallOffValue)) {
97
- queue.push(nx, ny, nz);
98
- nVoxel.setLight(getMinusOneForSun(sl, nl, VoxelLightData.SunFallOffValue));
99
- }
90
+ const sl = voxel.getLight();
91
+ if (sl < 0)
92
+ continue;
93
+ let nx, ny, nz, nVoxel, nl;
94
+ nx = x + 1;
95
+ nVoxel = nDataCursor.getVoxel(nx, y, z);
96
+ if (nVoxel) {
97
+ nl = nVoxel.getLight();
98
+ if (nl > -1 && isLessThanForSunAdd(nl, sl, sunFallOff)) {
99
+ queue.push(nx, y, z);
100
+ nVoxel.setLight(getMinusOneForSun(sl, nl, sunFallOff));
101
+ }
102
+ }
103
+ nx = x - 1;
104
+ nVoxel = nDataCursor.getVoxel(nx, y, z);
105
+ if (nVoxel) {
106
+ nl = nVoxel.getLight();
107
+ if (nl > -1 && isLessThanForSunAdd(nl, sl, sunFallOff)) {
108
+ queue.push(nx, y, z);
109
+ nVoxel.setLight(getMinusOneForSun(sl, nl, sunFallOff));
100
110
  }
101
111
  }
102
- const nVoxel = tasks.nDataCursor.getVoxel(x, y - 1, z);
112
+ nz = z + 1;
113
+ nVoxel = nDataCursor.getVoxel(x, y, nz);
103
114
  if (nVoxel) {
104
- const nl = nVoxel.getLight();
105
- if (nl > -1 &&
106
- isLessThanForSunAddDown(nl, sl, VoxelLightData.SunFallOffValue)) {
115
+ nl = nVoxel.getLight();
116
+ if (nl > -1 && isLessThanForSunAdd(nl, sl, sunFallOff)) {
117
+ queue.push(x, y, nz);
118
+ nVoxel.setLight(getMinusOneForSun(sl, nl, sunFallOff));
119
+ }
120
+ }
121
+ nz = z - 1;
122
+ nVoxel = nDataCursor.getVoxel(x, y, nz);
123
+ if (nVoxel) {
124
+ nl = nVoxel.getLight();
125
+ if (nl > -1 && isLessThanForSunAdd(nl, sl, sunFallOff)) {
126
+ queue.push(x, y, nz);
127
+ nVoxel.setLight(getMinusOneForSun(sl, nl, sunFallOff));
128
+ }
129
+ }
130
+ ny = y + 1;
131
+ nVoxel = nDataCursor.getVoxel(x, ny, z);
132
+ if (nVoxel) {
133
+ nl = nVoxel.getLight();
134
+ if (nl > -1 && isLessThanForSunAdd(nl, sl, sunFallOff)) {
135
+ queue.push(x, ny, z);
136
+ nVoxel.setLight(getMinusOneForSun(sl, nl, sunFallOff));
137
+ }
138
+ }
139
+ ny = y - 1;
140
+ nVoxel = nDataCursor.getVoxel(x, ny, z);
141
+ if (nVoxel) {
142
+ nl = nVoxel.getLight();
143
+ if (nl > -1 && isLessThanForSunAddDown(nl, sl, sunFallOff)) {
107
144
  if (nVoxel.isAir()) {
108
- queue.push(x, y - 1, z);
109
- nVoxel.setLight(getSunLightForUnderVoxel(sl, nl, VoxelLightData.SunFallOffValue));
145
+ queue.push(x, ny, z);
146
+ nVoxel.setLight(getSunLightForUnderVoxel(sl, nl, sunFallOff));
110
147
  }
111
- else {
112
- if (!nVoxel.isOpaque()) {
113
- queue.push(x, y - 1, z);
114
- nVoxel.setLight(getMinusOneForSun(sl, nl, VoxelLightData.SunFallOffValue));
115
- }
148
+ else if (!nVoxel.isOpaque()) {
149
+ queue.push(x, ny, z);
150
+ nVoxel.setLight(getMinusOneForSun(sl, nl, sunFallOff));
116
151
  }
117
152
  }
118
153
  }
119
154
  }
155
+ queue.length = 0;
120
156
  }
@@ -1,11 +1,13 @@
1
1
  import type { Vec3Array } from "@amodx/math";
2
2
  import { BrushTool } from "../../Tools/Brush/Brush.js";
3
3
  import { VoxelUpdateTask } from "../VoxelUpdateTask.js";
4
+ import { RawVoxelData } from "Voxels/index.js";
4
5
  export declare class WorldGenBrush extends BrushTool {
5
6
  constructor();
6
7
  requestsId: "";
7
8
  tasks: VoxelUpdateTask;
8
9
  start(dimension: number, x: number, y: number, z: number): this;
10
+ paintRaw(raw: RawVoxelData): this;
9
11
  paint(): this;
10
12
  getUpdatedSections(): Vec3Array[];
11
13
  update(): false | undefined;
@@ -22,6 +22,37 @@ export class WorldGenBrush extends BrushTool {
22
22
  this.z = z;
23
23
  return this;
24
24
  }
25
+ paintRaw(raw) {
26
+ let voxel = this.dataCursor.getVoxel(this.x, this.y, this.z);
27
+ if (!voxel) {
28
+ if (this.requestsId != "") {
29
+ WorldGenRegister.addToRequest(this.requestsId, [this.dimension, this.x, this.y, this.z], this.voxelCursor.getRaw());
30
+ return this;
31
+ }
32
+ throw new Error(`Tried painting in an unloaded location ${[
33
+ this.dimension,
34
+ this.x,
35
+ this.y,
36
+ this.z,
37
+ ].toString()}`);
38
+ }
39
+ const sl = voxel.getLight();
40
+ if (sl > 0 || !voxel.isAir()) {
41
+ this._erase();
42
+ voxel.setLight(sl < 0 ? 0 : sl);
43
+ if (lightData.hasRGBLight(sl)) {
44
+ this.tasks.rgb.remove.push(this.x, this.y, this.z);
45
+ RGBRemove(this.tasks);
46
+ }
47
+ if (lightData.hasSunLight(sl)) {
48
+ this.tasks.sun.remove.push(this.x, this.y, this.z);
49
+ SunRemove(this.tasks);
50
+ }
51
+ }
52
+ this._paintRaw(raw);
53
+ this.tasks.bounds.updateDisplay(this.x, this.y, this.z);
54
+ return this;
55
+ }
25
56
  paint() {
26
57
  let voxel = this.dataCursor.getVoxel(this.x, this.y, this.z);
27
58
  if (!voxel) {
@@ -45,7 +45,7 @@ export class ArchivedVoxelTemplate {
45
45
  }
46
46
  getSecondary(index) {
47
47
  const id = this.getId(index);
48
- const trueId = VoxelLUT.voxels[id][0];
48
+ const trueId = VoxelLUT.voxelIdToTrueId[id];
49
49
  if (VoxelTagsRegister.VoxelTags[trueId]["dve_can_have_secondary"]) {
50
50
  return VoxelLUT.getVoxelIdFromString(...this.voxelPalette.getVoxelData(this.secondaryPalette.getValue(this.secondary.getValue(index))));
51
51
  }
@@ -44,7 +44,7 @@ export default function CreateArchivedTemplate(dataCursor, bounds) {
44
44
  ? levelPalette.register(level)
45
45
  : levelPalette.getId(level);
46
46
  let voxelSecondary = 0;
47
- if (VoxelTagsRegister.VoxelTags[VoxelLUT.voxels[rawData[0]][0]]["dve_can_have_secondary"]) {
47
+ if (VoxelTagsRegister.VoxelTags[VoxelLUT.voxelIdToTrueId[rawData[0]]]["dve_can_have_secondary"]) {
48
48
  voxelSecondary = voxelPalette.register(rawData[3]);
49
49
  if (!secondaryPalette.isRegistered(voxelSecondary))
50
50
  secondaryPalette.register(voxelSecondary);
@@ -0,0 +1,6 @@
1
+ import { ArchivedVoxelTemplate } from "../ArchivedVoxelTemplate";
2
+ import { FullVoxelTemplateData } from "../../Full/FullVoxelTemplate.types";
3
+ /**
4
+ * Converts a FullVoxelTemplateData into an ArchivedVoxelTemplate.
5
+ */
6
+ export default function CreateArchivedTemplateFromFull(fullData: FullVoxelTemplateData): ArchivedVoxelTemplate;