@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
@@ -4,205 +4,126 @@ import { VoxelMeshVertexConstants, VoxelMeshVertexStructCursor, } from "./VoxelM
4
4
  const empty = [];
5
5
  const structCursor = new VoxelMeshVertexStructCursor();
6
6
  export class VoxelGeometryBuilder {
7
- /* static addTriangle(
8
- tool: VoxelMesherDataTool,
9
- origin: Vector3Like,
10
- points: [Vec3Array, Vec3Array, Vec3Array],
11
- [[u1, v1], [u2, v2], [u3, v3]]: [Vec2Array, Vec2Array, Vec2Array]
12
- ) {
13
- if (!tool.mesh) return;
14
- const worldLight = tool.vars.light;
15
- const worldAO = tool.vars.ao;
16
- const texture = tool.vars.textureIndex;
17
- GeometryBuilder.addTriangle(tool, origin, points);
18
- {
19
- const attribute = tool.mesh.getAttribute("voxelData");
20
-
21
- attribute.push(
22
- VoxelShaderData.createAttribute(
23
- worldLight.vertices[1],
24
- worldAO.vertices[1],
25
- 0
26
- ),
27
- VoxelShaderData.createAttribute(
28
- worldLight.vertices[2],
29
- worldAO.vertices[2],
30
- 0
31
- ),
32
- VoxelShaderData.createAttribute(
33
- worldLight.vertices[3],
34
- worldAO.vertices[3],
35
- 9
36
- )
37
- );
38
- }
39
- {
40
- const uvs = tool.mesh.getAttribute("uv");
41
- uvs.push(u1, v1, texture, u2, v2, texture, u3, v3, texture);
42
- }
43
- {
44
- const uvs = tool.mesh.getAttribute("textureIndex");
45
-
46
- uvs.push(
47
- //v1
48
- 0,
49
- 0,
50
- 0,
51
- 0,
52
- //v2
53
- 0,
54
- 0,
55
- 0,
56
- 0,
57
- //v3
58
- 0,
59
- 0,
60
- 0,
61
- 0
62
- );
63
- }
64
- {
65
- const colors = tool.mesh.getAttribute("colors");
66
- colors.push(
67
- //v1
68
- 0,
69
- 0,
70
- 0,
71
- //v2
72
- 0,
73
- 0,
74
- 0,
75
- //v3
76
- 0,
77
- 0,
78
- 0
79
- );
80
- }
81
- } */
82
- static addQuad(tool, origin, quad) {
83
- if (!tool.mesh)
84
- return;
85
- const worldLight = tool.vars.light;
86
- const worldAO = tool.vars.ao;
87
- const animData = tool.vars.animation;
88
- const texture = tool.vars.textureIndex;
89
- const overlayTextures = tool.vars.overlayTextures;
90
- const topRightPos = quad.positions.vertices[0];
91
- const topLeftPos = quad.positions.vertices[1];
92
- const bottomLeftPos = quad.positions.vertices[2];
93
- const bottomRightPos = quad.positions.vertices[3];
94
- const topRightNor = quad.normals.vertices[0];
95
- const topLeftNor = quad.normals.vertices[1];
96
- const bottomLeftNor = quad.normals.vertices[2];
97
- const bottomRightNor = quad.normals.vertices[3];
98
- const topRightVoxelData = VoxelShaderData.createAttribute(worldLight.vertices[QuadVerticies.TopRight], worldAO.vertices[QuadVerticies.TopRight], animData.vertices[QuadVerticies.TopRight]);
99
- const topLeftVoxelData = VoxelShaderData.createAttribute(worldLight.vertices[QuadVerticies.TopLeft], worldAO.vertices[QuadVerticies.TopLeft], animData.vertices[QuadVerticies.TopLeft]);
100
- const bottomLeftVoxelData = VoxelShaderData.createAttribute(worldLight.vertices[QuadVerticies.BottomLeft], worldAO.vertices[QuadVerticies.BottomLeft], animData.vertices[QuadVerticies.BottomLeft]);
101
- const bottomRightVoxelData = VoxelShaderData.createAttribute(worldLight.vertices[QuadVerticies.BottomRight], worldAO.vertices[QuadVerticies.BottomRight], animData.vertices[QuadVerticies.BottomRight]);
102
- const indices = tool.mesh.indices;
103
- let indIndex = tool.mesh.indicieCount;
104
- let sides = quad.doubleSided ? 2 : 1;
105
- const flip = quad.flip;
106
- let orientation = quad.orientation;
107
- while (sides--) {
108
- const baseIndex = tool.mesh.vertexCount;
109
- if (!flip) {
110
- tool.mesh.buffer.setIndex(baseIndex);
111
- structCursor.data = tool.mesh.buffer.currentArray;
112
- structCursor.index = tool.mesh.buffer.curentIndex;
113
- addVertex(tool.mesh.buffer.curentIndex, tool.mesh.buffer.currentArray, origin, topRightPos, topRightNor, quad.uvs.vertices[QuadVerticies.TopRight], topRightVoxelData, texture, overlayTextures);
114
- tool.mesh.buffer.setIndex(baseIndex + 1);
115
- structCursor.data = tool.mesh.buffer.currentArray;
116
- structCursor.index = tool.mesh.buffer.curentIndex;
117
- addVertex(tool.mesh.buffer.curentIndex, tool.mesh.buffer.currentArray, origin, topLeftPos, topLeftNor, quad.uvs.vertices[QuadVerticies.TopLeft], topLeftVoxelData, texture, overlayTextures);
118
- tool.mesh.buffer.setIndex(baseIndex + 2);
119
- structCursor.data = tool.mesh.buffer.currentArray;
120
- structCursor.index = tool.mesh.buffer.curentIndex;
121
- addVertex(tool.mesh.buffer.curentIndex, tool.mesh.buffer.currentArray, origin, bottomLeftPos, bottomLeftNor, quad.uvs.vertices[QuadVerticies.BottomLeft], bottomLeftVoxelData, texture, overlayTextures);
122
- tool.mesh.buffer.setIndex(baseIndex + 3);
123
- structCursor.data = tool.mesh.buffer.currentArray;
124
- structCursor.index = tool.mesh.buffer.curentIndex;
125
- addVertex(tool.mesh.buffer.curentIndex, tool.mesh.buffer.currentArray, origin, bottomRightPos, bottomRightNor, quad.uvs.vertices[QuadVerticies.BottomRight], bottomRightVoxelData, texture, overlayTextures);
126
- }
127
- if (flip) {
128
- tool.mesh.buffer.setIndex(baseIndex);
129
- structCursor.data = tool.mesh.buffer.currentArray;
130
- structCursor.index = tool.mesh.buffer.curentIndex;
131
- addVertex(tool.mesh.buffer.curentIndex, tool.mesh.buffer.currentArray, origin, topLeftPos, topLeftNor, quad.uvs.vertices[QuadVerticies.TopLeft], topLeftVoxelData, texture, overlayTextures);
132
- tool.mesh.buffer.setIndex(baseIndex + 1);
133
- structCursor.data = tool.mesh.buffer.currentArray;
134
- structCursor.index = tool.mesh.buffer.curentIndex;
135
- addVertex(tool.mesh.buffer.curentIndex, tool.mesh.buffer.currentArray, origin, topRightPos, topRightNor, quad.uvs.vertices[QuadVerticies.TopRight], topRightVoxelData, texture, overlayTextures);
136
- tool.mesh.buffer.setIndex(baseIndex + 2);
137
- structCursor.data = tool.mesh.buffer.currentArray;
138
- structCursor.index = tool.mesh.buffer.curentIndex;
139
- addVertex(tool.mesh.buffer.curentIndex, tool.mesh.buffer.currentArray, origin, bottomRightPos, bottomRightNor, quad.uvs.vertices[QuadVerticies.BottomRight], bottomRightVoxelData, texture, overlayTextures);
140
- tool.mesh.buffer.setIndex(baseIndex + 3);
141
- structCursor.data = tool.mesh.buffer.currentArray;
142
- structCursor.index = tool.mesh.buffer.curentIndex;
143
- addVertex(tool.mesh.buffer.curentIndex, tool.mesh.buffer.currentArray, origin, bottomLeftPos, bottomLeftNor, quad.uvs.vertices[QuadVerticies.BottomLeft], bottomLeftVoxelData, texture, overlayTextures);
144
- }
145
- if (!orientation && !flip) {
146
- indices.setIndex(indIndex).currentArray[indices.curentIndex] =
147
- baseIndex;
148
- indices.setIndex(indIndex + 1).currentArray[indices.curentIndex] =
149
- baseIndex + 1;
150
- indices.setIndex(indIndex + 2).currentArray[indices.curentIndex] =
151
- baseIndex + 2;
152
- indices.setIndex(indIndex + 3).currentArray[indices.curentIndex] =
153
- baseIndex + 2;
154
- indices.setIndex(indIndex + 4).currentArray[indices.curentIndex] =
155
- baseIndex + 3;
156
- indices.setIndex(indIndex + 5).currentArray[indices.curentIndex] =
157
- baseIndex;
158
- }
159
- else if (!orientation && flip) {
160
- indices.setIndex(indIndex).currentArray[indices.curentIndex] =
161
- baseIndex;
162
- indices.setIndex(indIndex + 1).currentArray[indices.curentIndex] =
163
- baseIndex + 3;
164
- indices.setIndex(indIndex + 2).currentArray[indices.curentIndex] =
165
- baseIndex + 2;
166
- indices.setIndex(indIndex + 3).currentArray[indices.curentIndex] =
167
- baseIndex + 2;
168
- indices.setIndex(indIndex + 4).currentArray[indices.curentIndex] =
169
- baseIndex + 1;
170
- indices.setIndex(indIndex + 5).currentArray[indices.curentIndex] =
171
- baseIndex;
172
- }
173
- if (orientation && !flip) {
174
- indices.setIndex(indIndex).currentArray[indices.curentIndex] =
175
- baseIndex;
176
- indices.setIndex(indIndex + 1).currentArray[indices.curentIndex] =
177
- baseIndex + 3;
178
- indices.setIndex(indIndex + 2).currentArray[indices.curentIndex] =
179
- baseIndex + 2;
180
- indices.setIndex(indIndex + 3).currentArray[indices.curentIndex] =
181
- baseIndex + 2;
182
- indices.setIndex(indIndex + 4).currentArray[indices.curentIndex] =
183
- baseIndex + 1;
184
- indices.setIndex(indIndex + 5).currentArray[indices.curentIndex] =
185
- baseIndex;
186
- }
187
- else if (orientation && flip) {
188
- indices.setIndex(indIndex).currentArray[indices.curentIndex] =
189
- baseIndex;
190
- indices.setIndex(indIndex + 1).currentArray[indices.curentIndex] =
191
- baseIndex + 1;
192
- indices.setIndex(indIndex + 2).currentArray[indices.curentIndex] =
193
- baseIndex + 2;
194
- indices.setIndex(indIndex + 3).currentArray[indices.curentIndex] =
195
- baseIndex + 2;
196
- indices.setIndex(indIndex + 4).currentArray[indices.curentIndex] =
197
- baseIndex + 3;
198
- indices.setIndex(indIndex + 5).currentArray[indices.curentIndex] =
199
- baseIndex;
200
- }
201
- tool.mesh.addVerticies(4, 6);
7
+ }
8
+ export function addVoxelQuad(tool, origin, quad) {
9
+ if (!tool.mesh)
10
+ return;
11
+ const worldLight = tool.vars.light;
12
+ const worldAO = tool.vars.ao;
13
+ const animData = tool.vars.animation;
14
+ const texture = tool.vars.textureIndex;
15
+ const overlayTextures = tool.vars.overlayTextures;
16
+ const topRightPos = quad.positions.vertices[0];
17
+ const topLeftPos = quad.positions.vertices[1];
18
+ const bottomLeftPos = quad.positions.vertices[2];
19
+ const bottomRightPos = quad.positions.vertices[3];
20
+ const topRightNor = quad.normals.vertices[0];
21
+ const topLeftNor = quad.normals.vertices[1];
22
+ const bottomLeftNor = quad.normals.vertices[2];
23
+ const bottomRightNor = quad.normals.vertices[3];
24
+ const topRightVoxelData = VoxelShaderData.createAttribute(worldLight.vertices[QuadVerticies.TopRight], worldAO.vertices[QuadVerticies.TopRight], animData.vertices[QuadVerticies.TopRight]);
25
+ const topLeftVoxelData = VoxelShaderData.createAttribute(worldLight.vertices[QuadVerticies.TopLeft], worldAO.vertices[QuadVerticies.TopLeft], animData.vertices[QuadVerticies.TopLeft]);
26
+ const bottomLeftVoxelData = VoxelShaderData.createAttribute(worldLight.vertices[QuadVerticies.BottomLeft], worldAO.vertices[QuadVerticies.BottomLeft], animData.vertices[QuadVerticies.BottomLeft]);
27
+ const bottomRightVoxelData = VoxelShaderData.createAttribute(worldLight.vertices[QuadVerticies.BottomRight], worldAO.vertices[QuadVerticies.BottomRight], animData.vertices[QuadVerticies.BottomRight]);
28
+ const indices = tool.mesh.indices;
29
+ let indIndex = tool.mesh.indicieCount;
30
+ let sides = quad.doubleSided ? 2 : 1;
31
+ const flip = quad.flip;
32
+ let orientation = quad.orientation;
33
+ while (sides--) {
34
+ const baseIndex = tool.mesh.vertexCount;
35
+ if (!flip) {
36
+ tool.mesh.buffer.setIndex(baseIndex);
37
+ structCursor.data = tool.mesh.buffer.currentArray;
38
+ structCursor.index = tool.mesh.buffer.curentIndex;
39
+ addVertex(tool.mesh.buffer.curentIndex, tool.mesh.buffer.currentArray, origin, topRightPos, topRightNor, quad.uvs.vertices[QuadVerticies.TopRight], topRightVoxelData, texture, overlayTextures);
40
+ tool.mesh.buffer.setIndex(baseIndex + 1);
41
+ structCursor.data = tool.mesh.buffer.currentArray;
42
+ structCursor.index = tool.mesh.buffer.curentIndex;
43
+ addVertex(tool.mesh.buffer.curentIndex, tool.mesh.buffer.currentArray, origin, topLeftPos, topLeftNor, quad.uvs.vertices[QuadVerticies.TopLeft], topLeftVoxelData, texture, overlayTextures);
44
+ tool.mesh.buffer.setIndex(baseIndex + 2);
45
+ structCursor.data = tool.mesh.buffer.currentArray;
46
+ structCursor.index = tool.mesh.buffer.curentIndex;
47
+ addVertex(tool.mesh.buffer.curentIndex, tool.mesh.buffer.currentArray, origin, bottomLeftPos, bottomLeftNor, quad.uvs.vertices[QuadVerticies.BottomLeft], bottomLeftVoxelData, texture, overlayTextures);
48
+ tool.mesh.buffer.setIndex(baseIndex + 3);
49
+ structCursor.data = tool.mesh.buffer.currentArray;
50
+ structCursor.index = tool.mesh.buffer.curentIndex;
51
+ addVertex(tool.mesh.buffer.curentIndex, tool.mesh.buffer.currentArray, origin, bottomRightPos, bottomRightNor, quad.uvs.vertices[QuadVerticies.BottomRight], bottomRightVoxelData, texture, overlayTextures);
52
+ }
53
+ if (flip) {
54
+ tool.mesh.buffer.setIndex(baseIndex);
55
+ structCursor.data = tool.mesh.buffer.currentArray;
56
+ structCursor.index = tool.mesh.buffer.curentIndex;
57
+ addVertex(tool.mesh.buffer.curentIndex, tool.mesh.buffer.currentArray, origin, topLeftPos, topLeftNor, quad.uvs.vertices[QuadVerticies.TopLeft], topLeftVoxelData, texture, overlayTextures);
58
+ tool.mesh.buffer.setIndex(baseIndex + 1);
59
+ structCursor.data = tool.mesh.buffer.currentArray;
60
+ structCursor.index = tool.mesh.buffer.curentIndex;
61
+ addVertex(tool.mesh.buffer.curentIndex, tool.mesh.buffer.currentArray, origin, topRightPos, topRightNor, quad.uvs.vertices[QuadVerticies.TopRight], topRightVoxelData, texture, overlayTextures);
62
+ tool.mesh.buffer.setIndex(baseIndex + 2);
63
+ structCursor.data = tool.mesh.buffer.currentArray;
64
+ structCursor.index = tool.mesh.buffer.curentIndex;
65
+ addVertex(tool.mesh.buffer.curentIndex, tool.mesh.buffer.currentArray, origin, bottomRightPos, bottomRightNor, quad.uvs.vertices[QuadVerticies.BottomRight], bottomRightVoxelData, texture, overlayTextures);
66
+ tool.mesh.buffer.setIndex(baseIndex + 3);
67
+ structCursor.data = tool.mesh.buffer.currentArray;
68
+ structCursor.index = tool.mesh.buffer.curentIndex;
69
+ addVertex(tool.mesh.buffer.curentIndex, tool.mesh.buffer.currentArray, origin, bottomLeftPos, bottomLeftNor, quad.uvs.vertices[QuadVerticies.BottomLeft], bottomLeftVoxelData, texture, overlayTextures);
70
+ }
71
+ if (!orientation && !flip) {
72
+ indices.setIndex(indIndex).currentArray[indices.curentIndex] = baseIndex;
73
+ indices.setIndex(indIndex + 1).currentArray[indices.curentIndex] =
74
+ baseIndex + 1;
75
+ indices.setIndex(indIndex + 2).currentArray[indices.curentIndex] =
76
+ baseIndex + 2;
77
+ indices.setIndex(indIndex + 3).currentArray[indices.curentIndex] =
78
+ baseIndex + 2;
79
+ indices.setIndex(indIndex + 4).currentArray[indices.curentIndex] =
80
+ baseIndex + 3;
81
+ indices.setIndex(indIndex + 5).currentArray[indices.curentIndex] =
82
+ baseIndex;
83
+ }
84
+ else if (!orientation && flip) {
85
+ indices.setIndex(indIndex).currentArray[indices.curentIndex] = baseIndex;
86
+ indices.setIndex(indIndex + 1).currentArray[indices.curentIndex] =
87
+ baseIndex + 3;
88
+ indices.setIndex(indIndex + 2).currentArray[indices.curentIndex] =
89
+ baseIndex + 2;
90
+ indices.setIndex(indIndex + 3).currentArray[indices.curentIndex] =
91
+ baseIndex + 2;
92
+ indices.setIndex(indIndex + 4).currentArray[indices.curentIndex] =
93
+ baseIndex + 1;
94
+ indices.setIndex(indIndex + 5).currentArray[indices.curentIndex] =
95
+ baseIndex;
202
96
  }
97
+ if (orientation && !flip) {
98
+ indices.setIndex(indIndex).currentArray[indices.curentIndex] = baseIndex;
99
+ indices.setIndex(indIndex + 1).currentArray[indices.curentIndex] =
100
+ baseIndex + 3;
101
+ indices.setIndex(indIndex + 2).currentArray[indices.curentIndex] =
102
+ baseIndex + 2;
103
+ indices.setIndex(indIndex + 3).currentArray[indices.curentIndex] =
104
+ baseIndex + 2;
105
+ indices.setIndex(indIndex + 4).currentArray[indices.curentIndex] =
106
+ baseIndex + 1;
107
+ indices.setIndex(indIndex + 5).currentArray[indices.curentIndex] =
108
+ baseIndex;
109
+ }
110
+ else if (orientation && flip) {
111
+ indices.setIndex(indIndex).currentArray[indices.curentIndex] = baseIndex;
112
+ indices.setIndex(indIndex + 1).currentArray[indices.curentIndex] =
113
+ baseIndex + 1;
114
+ indices.setIndex(indIndex + 2).currentArray[indices.curentIndex] =
115
+ baseIndex + 2;
116
+ indices.setIndex(indIndex + 3).currentArray[indices.curentIndex] =
117
+ baseIndex + 2;
118
+ indices.setIndex(indIndex + 4).currentArray[indices.curentIndex] =
119
+ baseIndex + 3;
120
+ indices.setIndex(indIndex + 5).currentArray[indices.curentIndex] =
121
+ baseIndex;
122
+ }
123
+ tool.mesh.addVerticies(4, 6);
203
124
  }
204
125
  }
205
- const addVertex = (index, array, origin, position, normal, uvs, voxelData, texture, overlayTextures) => {
126
+ function addVertex(index, array, origin, position, normal, uvs, voxelData, texture, overlayTextures) {
206
127
  index *= VoxelMeshVertexConstants.VertexFloatSize;
207
128
  array[VoxelMeshVertexConstants.PositionOffset + index] =
208
129
  position.x + origin.x;
@@ -222,4 +143,4 @@ const addVertex = (index, array, origin, position, normal, uvs, voxelData, textu
222
143
  array[VoxelMeshVertexConstants.TextureIndexOffset + index + 2] =
223
144
  VoxelShaderData.createTextureIndex(overlayTextures.w, 0);
224
145
  array[VoxelMeshVertexConstants.VoxelDataOFfset + index] = voxelData;
225
- };
146
+ }
@@ -6,8 +6,8 @@ export class VoxelMesh {
6
6
  vertexCount = 0;
7
7
  minBounds = Vector3Like.Create(Infinity, Infinity, Infinity);
8
8
  maxBounds = Vector3Like.Create(-Infinity, -Infinity, -Infinity);
9
- buffer = new VoxelVertexBuffer(VoxelMeshVertexStructCursor.VertexFloatSize, 1000);
10
- indices = new VoxelIndiceBuffer(1000);
9
+ buffer = new VoxelVertexBuffer(VoxelMeshVertexStructCursor.VertexFloatSize, 1024);
10
+ indices = new VoxelIndiceBuffer(1024);
11
11
  addVerticies(vertexCount, indicesCount) {
12
12
  this.vertexCount += vertexCount;
13
13
  this.indicieCount += indicesCount;
@@ -1,78 +1,16 @@
1
- /**
2
- * A class to help with indexing a full flat binary tree defined by the number of levels it has.
3
- */
4
- declare class FlatBinaryTreeIndex {
5
- levels: number;
6
- constructor(levels: number);
7
- /** Gets the number of nodes at a level of the tree */
8
- getLevelSize(level: number): number;
9
- /**
10
- * Gets the flat index of a node indexed by the level it's on and its relative index in that level.
11
- */
12
- getIndexAtLevel(level: number, node: number): number;
13
- /**
14
- * Gets the level and relative index of a node's flat index.
15
- */
16
- getLevelAndIndex(index: number): [level: number, relativeIndex: number];
17
- /**
18
- * Gets the flat left child of a node, where the node is indexed by its level and its relative index at that level.
19
- * @returns -1 if no child exist
20
- */
21
- getLeftChildAtLevel(level: number, node: number): number;
22
- /**
23
- * Gets the flat right child of a node, where the node is indexed by its level and its relative index at that level.
24
- * @returns -1 if no child exist
25
- */
26
- getRightChildAtLevel(level: number, node: number): number;
27
- /**
28
- * Gets the flat index of the parent of a node, where the node is indexed by its level and its relative index at that level.
29
- * @returns -1 if level has no parent
30
- */
31
- getParentAtLevel(level: number, node: number): number;
32
- /** Gets the flat index of the left child of the node.
33
- * @returns -1 if no child exist
34
- */
35
- getLeftChild(node: number): number;
36
- /** Gets the flat index of the right child of the node.
37
- * @returns -1 if no child exist
38
- */
39
- getRightChild(node: number): number;
40
- /** Gets the flat index of the parent of the node.
41
- * @returns -1 if no parent exist
42
- */
43
- getParent(node: number): number;
44
- /** Gets the total number of nodes in the tree */
45
- getTotalSize(): number;
46
- }
47
- export declare class StructCursor {
48
- data: Float32Array;
49
- get minX(): number;
50
- get minY(): number;
51
- get minZ(): number;
52
- get maxX(): number;
53
- get maxY(): number;
54
- get maxZ(): number;
55
- get voxelIndex(): number;
56
- get active(): number;
57
- get nodeType(): number;
58
- trueIndex: number;
59
- private index;
60
- setIndex(index: number): void;
61
- constructor(data: Float32Array);
62
- setActive(): void;
63
- setVoxelIndex(value: number): void;
64
- setInnerNode(): void;
65
- setGeomtryNode(): void;
66
- updateMin(x: number, y: number, z: number): void;
67
- updateMax(x: number, y: number, z: number): void;
68
- }
1
+ import { Vec3Array } from "@amodx/math";
2
+ import { VoxelMeshBVHStructCursor } from "./VoxelMeshBVHStructCursor";
3
+ import { FlatBinaryTreeIndex } from "../../Util/Binary/BinaryTree";
69
4
  export declare class VoxelMeshBVHBuilder {
70
5
  static AABBStructByteSize: number;
71
6
  treeIndex: FlatBinaryTreeIndex;
72
7
  tree: Float32Array;
73
- structCursor: StructCursor;
8
+ structCursor: VoxelMeshBVHStructCursor;
74
9
  indices: Uint32Array;
75
10
  reset(): void;
11
+ getMeshBounds(): {
12
+ min: Vec3Array;
13
+ max: Vec3Array;
14
+ };
76
15
  updateVoxel(voxelX: number, voxelY: number, voxelZ: number, meshIndex: number, indicesStart: number, indicesEnd: number, minX: number, minY: number, minZ: number, maxX: number, maxY: number, maxZ: number): void;
77
16
  }
78
- export {};
@@ -1,197 +1,32 @@
1
1
  import { WorldSpaces } from "../../World/WorldSpaces";
2
+ import { VoxelMeshBVHStructCursor } from "./VoxelMeshBVHStructCursor";
3
+ import { FlatBinaryTreeIndex } from "../../Util/Binary/BinaryTree";
2
4
  const MAX_FLOAT32 = new Float32Array([Infinity])[0];
3
- /**
4
- * A class to help with indexing a full flat binary tree defined by the number of levels it has.
5
- */
6
- class FlatBinaryTreeIndex {
7
- levels;
8
- constructor(levels) {
9
- this.levels = levels;
10
- }
11
- /** Gets the number of nodes at a level of the tree */
12
- getLevelSize(level) {
13
- if (level < 0 || level >= this.levels) {
14
- throw new Error("Invalid level");
15
- }
16
- return 1 << level; // Equivalent to 2^level
17
- }
18
- /**
19
- * Gets the flat index of a node indexed by the level it's on and its relative index in that level.
20
- */
21
- getIndexAtLevel(level, node) {
22
- if (level < 0 || level >= this.levels) {
23
- throw new Error("Invalid level");
24
- }
25
- const levelSize = this.getLevelSize(level);
26
- if (node < 0 || node >= levelSize) {
27
- throw new Error("Invalid node index at the given level");
28
- }
29
- return (1 << level) - 1 + node;
30
- }
31
- /**
32
- * Gets the level and relative index of a node's flat index.
33
- */
34
- getLevelAndIndex(index) {
35
- const totalNodes = (1 << this.levels) - 1;
36
- if (index < 0 || index >= totalNodes) {
37
- throw new Error("Invalid node index");
38
- }
39
- const level = Math.floor(Math.log2(index + 1));
40
- const firstIndexAtLevel = (1 << level) - 1;
41
- const relativeIndex = index - firstIndexAtLevel;
42
- return [level, relativeIndex];
43
- }
44
- /**
45
- * Gets the flat left child of a node, where the node is indexed by its level and its relative index at that level.
46
- * @returns -1 if no child exist
47
- */
48
- getLeftChildAtLevel(level, node) {
49
- if (level + 1 >= this.levels) {
50
- return -1;
51
- }
52
- const nodeIndex = this.getIndexAtLevel(level, node);
53
- return this.getLeftChild(nodeIndex);
54
- }
55
- /**
56
- * Gets the flat right child of a node, where the node is indexed by its level and its relative index at that level.
57
- * @returns -1 if no child exist
58
- */
59
- getRightChildAtLevel(level, node) {
60
- if (level + 1 >= this.levels) {
61
- return -1;
62
- }
63
- const nodeIndex = this.getIndexAtLevel(level, node);
64
- return this.getRightChild(nodeIndex);
65
- }
66
- /**
67
- * Gets the flat index of the parent of a node, where the node is indexed by its level and its relative index at that level.
68
- * @returns -1 if level has no parent
69
- */
70
- getParentAtLevel(level, node) {
71
- if (level === 0) {
72
- return -1;
73
- }
74
- const nodeIndex = this.getIndexAtLevel(level, node);
75
- return this.getParent(nodeIndex);
76
- }
77
- /** Gets the flat index of the left child of the node.
78
- * @returns -1 if no child exist
79
- */
80
- getLeftChild(node) {
81
- const leftChildIndex = 2 * node + 1;
82
- const totalNodes = (1 << this.levels) - 1;
83
- return leftChildIndex < totalNodes ? leftChildIndex : -1;
84
- }
85
- /** Gets the flat index of the right child of the node.
86
- * @returns -1 if no child exist
87
- */
88
- getRightChild(node) {
89
- const rightChildIndex = 2 * node + 2;
90
- const totalNodes = (1 << this.levels) - 1;
91
- return rightChildIndex < totalNodes ? rightChildIndex : -1;
92
- }
93
- /** Gets the flat index of the parent of the node.
94
- * @returns -1 if no parent exist
95
- */
96
- getParent(node) {
97
- if (node === 0) {
98
- return -1; // Root node has no parent
99
- }
100
- return Math.floor((node - 1) / 2);
101
- }
102
- /** Gets the total number of nodes in the tree */
103
- getTotalSize() {
104
- return (1 << this.levels) - 1; // Equivalent to 2^levels - 1
105
- }
106
- }
107
- export class StructCursor {
108
- data;
109
- get minX() {
110
- return this.data[this.trueIndex];
111
- }
112
- get minY() {
113
- return this.data[this.trueIndex + 1];
114
- }
115
- get minZ() {
116
- return this.data[this.trueIndex + 2];
117
- }
118
- get maxX() {
119
- return this.data[this.trueIndex + 4];
120
- }
121
- get maxY() {
122
- return this.data[this.trueIndex + 5];
123
- }
124
- get maxZ() {
125
- return this.data[this.trueIndex + 6];
126
- }
127
- get voxelIndex() {
128
- return this.data[this.trueIndex + 3];
129
- }
130
- get active() {
131
- return this.data[this.trueIndex + 3];
132
- }
133
- get nodeType() {
134
- return this.data[this.trueIndex + 7];
135
- }
136
- trueIndex = 0;
137
- index = 0;
138
- setIndex(index) {
139
- this.trueIndex = index * 8;
140
- }
141
- constructor(data) {
142
- this.data = data;
143
- }
144
- setActive() {
145
- this.data[this.trueIndex + 3] = 1;
146
- }
147
- setVoxelIndex(value) {
148
- this.data[this.trueIndex + 3] = value;
149
- }
150
- setInnerNode() {
151
- this.data[this.trueIndex + 7] = 1;
152
- }
153
- setGeomtryNode() {
154
- this.data[this.trueIndex + 7] = 2;
155
- }
156
- updateMin(x, y, z) {
157
- const ix = this.trueIndex;
158
- const iy = this.trueIndex + 1;
159
- const iz = this.trueIndex + 2;
160
- if (x < this.data[ix] || this.data[ix] == -MAX_FLOAT32) {
161
- this.data[ix] = x;
162
- }
163
- if (y < this.data[iy] || this.data[iy] == -MAX_FLOAT32) {
164
- this.data[iy] = y;
165
- }
166
- if (z < this.data[iz] || this.data[iz] == -MAX_FLOAT32) {
167
- this.data[iz] = z;
168
- }
169
- }
170
- updateMax(x, y, z) {
171
- const ix = this.trueIndex + 4;
172
- const iy = this.trueIndex + 5;
173
- const iz = this.trueIndex + 6;
174
- if (x > this.data[ix] || this.data[ix] == -MAX_FLOAT32) {
175
- this.data[ix] = x;
176
- }
177
- if (y > this.data[iy] || this.data[iy] == -MAX_FLOAT32) {
178
- this.data[iy] = y;
179
- }
180
- if (z > this.data[iz] || this.data[iz] == -MAX_FLOAT32) {
181
- this.data[iz] = z;
182
- }
183
- }
184
- }
185
5
  export class VoxelMeshBVHBuilder {
186
6
  static AABBStructByteSize = (4 + 4) * 4;
187
7
  treeIndex = new FlatBinaryTreeIndex(13);
188
8
  tree = new Float32Array(new ArrayBuffer(this.treeIndex.getTotalSize() * VoxelMeshBVHBuilder.AABBStructByteSize));
189
- structCursor = new StructCursor(this.tree);
9
+ structCursor = new VoxelMeshBVHStructCursor(this.tree);
190
10
  indices = new Uint32Array(this.treeIndex.getLevelSize(12) * 2);
191
11
  reset() {
192
12
  this.tree.fill(-MAX_FLOAT32);
193
13
  this.indices.fill(0);
194
14
  }
15
+ getMeshBounds() {
16
+ const leafIndex = this.treeIndex.getIndexAtLevel(0, 0);
17
+ return {
18
+ min: [
19
+ this.tree[leafIndex],
20
+ this.tree[leafIndex + 1],
21
+ this.tree[leafIndex + 2],
22
+ ],
23
+ max: [
24
+ this.tree[leafIndex + 4],
25
+ this.tree[leafIndex + 5],
26
+ this.tree[leafIndex + 6],
27
+ ],
28
+ };
29
+ }
195
30
  updateVoxel(voxelX, voxelY, voxelZ, meshIndex, indicesStart, indicesEnd, minX, minY, minZ, maxX, maxY, maxZ) {
196
31
  const voxelIndex = WorldSpaces.voxel.getIndex(voxelX, voxelY, voxelZ);
197
32
  const leafIndex = this.treeIndex.getIndexAtLevel(12, voxelIndex);
@@ -0,0 +1,22 @@
1
+ export declare class VoxelMeshBVHStructCursor {
2
+ data: Float32Array;
3
+ get minX(): number;
4
+ get minY(): number;
5
+ get minZ(): number;
6
+ get maxX(): number;
7
+ get maxY(): number;
8
+ get maxZ(): number;
9
+ get voxelIndex(): number;
10
+ get active(): number;
11
+ get nodeType(): number;
12
+ trueIndex: number;
13
+ private index;
14
+ setIndex(index: number): void;
15
+ constructor(data: Float32Array);
16
+ setActive(): void;
17
+ setVoxelIndex(value: number): void;
18
+ setInnerNode(): void;
19
+ setGeomtryNode(): void;
20
+ updateMin(x: number, y: number, z: number): void;
21
+ updateMax(x: number, y: number, z: number): void;
22
+ }