@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.
- package/Contexts/Base/Remote/InitDataSync.js +4 -0
- package/Contexts/Base/Remote/InitWorldDataSync.js +1 -1
- package/Contexts/Render/DivineVoxelEngineRender.d.ts +1 -0
- package/Contexts/World/DivineVoxelEngineWorld.d.ts +1 -0
- package/Init/StartConstructor.js +2 -0
- package/Math/index.d.ts +5 -1
- package/Mesher/Functions/CompactVoxelSectionMesh.d.ts +4 -0
- package/Mesher/Functions/CompactVoxelSectionMesh.js +112 -0
- package/Mesher/Functions/MeshSection.d.ts +1 -1
- package/Mesher/Functions/MeshSection.js +15 -22
- package/Mesher/Geomtry/CompactedSectionVoxelMesh.d.ts +23 -0
- package/Mesher/Geomtry/CompactedSectionVoxelMesh.js +144 -0
- package/Mesher/Geomtry/VoxelGeometryBuilder.d.ts +1 -1
- package/Mesher/Geomtry/VoxelGeometryBuilder.js +118 -197
- package/Mesher/Geomtry/VoxelMesh.js +2 -2
- package/Mesher/Geomtry/VoxelMeshBVHBuilder.d.ts +8 -70
- package/Mesher/Geomtry/VoxelMeshBVHBuilder.js +18 -183
- package/Mesher/Geomtry/VoxelMeshBVHStructCursor.d.ts +22 -0
- package/Mesher/Geomtry/VoxelMeshBVHStructCursor.js +78 -0
- package/Mesher/Geomtry/VoxelMeshBuffers.js +2 -2
- package/Mesher/InitTask.js +5 -1
- package/Mesher/Models/Common/BoxGeometryNode.js +7 -7
- package/Mesher/Models/Common/Calc/CalcConstants.d.ts +1 -1
- package/Mesher/Models/Common/Calc/CalcConstants.js +1 -1
- package/Mesher/Models/Common/QuadGeometryNode.js +2 -2
- package/Mesher/Models/Nodes/Custom/Liquid/LiquidGeomtryNode.js +7 -7
- package/Mesher/Models/Nodes/Ruled/BoxVoxelGeometryNode.js +22 -25
- package/Mesher/Models/Nodes/Ruled/QuadVoxelGeometryNode.js +2 -2
- package/Mesher/Models/Nodes/Ruleless/RulelessBoxVoxelGeometryNode.js +2 -2
- package/Mesher/Models/Nodes/Ruleless/RulelessQuadVoxelGeometryNode.js +2 -2
- package/Mesher/Models/VoxelConstructor.d.ts +3 -3
- package/Mesher/Models/VoxelConstructor.js +8 -8
- package/Mesher/Models/VoxelGeometryBuilderCacheSpace.d.ts +2 -2
- package/Mesher/Models/VoxelGeometryBuilderCacheSpace.js +8 -9
- package/Mesher/Models/VoxelModelBuilder.js +1 -8
- package/Mesher/Types/Mesher.types.d.ts +1 -0
- package/Models/Defaults/CubeVoxelModels.js +16 -39
- package/Models/Defaults/LiquidVoxelModel.js +3 -3
- package/Models/Defaults/PanelVoxelModels.js +10 -36
- package/Models/Defaults/StairVoxelModel.js +6 -21
- package/Models/Examples.js +23 -44
- package/Models/Rules/Classes/VoxelRulesModel.d.ts +1 -1
- package/Models/Rules/Classes/VoxelRulesModel.js +3 -3
- package/Models/Rules/Functions/BuildFinalInputs.d.ts +1 -1
- package/Models/Rules/Functions/BuildFinalInputs.js +13 -13
- package/Models/Rules/VoxelModelRuleBuilderRegister.js +8 -8
- package/Models/VoxelModel.types.d.ts +3 -3
- package/Renderer/Classes/DVESectionMeshes.d.ts +2 -3
- package/Renderer/InitTasks.js +1 -9
- package/Renderer/MeshManager.d.ts +1 -1
- package/Renderer/MeshManager.js +24 -23
- package/Renderer/MeshRegister.d.ts +5 -5
- package/Renderer/MeshRegister.js +2 -2
- package/Settings/EngineSettings.d.ts +1 -0
- package/Settings/EngineSettings.js +6 -3
- package/Settings/EngineSettings.types.d.ts +7 -21
- package/Settings/EngineSettings.types.js +6 -14
- package/Tasks/Logic/InitTasks.d.ts +1 -0
- package/Tasks/Logic/InitTasks.js +10 -0
- package/Tasks/Logic/VoxelLogicUpdate.d.ts +3 -0
- package/Tasks/Logic/VoxelLogicUpdate.js +71 -0
- package/Tasks/Propagation/Explosion/ExplosionManager.d.ts +2 -2
- package/Tasks/Propagation/Explosion/ExplosionManager.js +1 -2
- package/Tasks/Propagation/Flow/FlowManager.d.ts +4 -4
- package/Tasks/Propagation/Flow/FlowRemove.d.ts +2 -2
- package/Tasks/Propagation/Flow/FlowUpdate.d.ts +2 -2
- package/Tasks/Propagation/Flow/WorldFlow.d.ts +2 -2
- package/Tasks/Propagation/Illumanation/RGBUpdate.d.ts +3 -3
- package/Tasks/Propagation/Illumanation/SunUpdate.d.ts +3 -3
- package/Tasks/Propagation/Illumanation/WorldRGB.d.ts +2 -2
- package/Tasks/Propagation/Illumanation/WorldSun.d.ts +2 -2
- package/Tasks/Propagation/Illumanation/WorldSun.js +8 -15
- package/Tasks/Propagation/InitTasks.js +4 -4
- package/Tasks/Propagation/Power/PowerUpdate.d.ts +3 -0
- package/Tasks/Propagation/Power/PowerUpdate.js +80 -0
- package/Tasks/Tasks.types.d.ts +2 -2
- package/Tasks/TasksIds.d.ts +2 -1
- package/Tasks/TasksIds.js +1 -0
- package/Tasks/Update/Common.d.ts +3 -0
- package/Tasks/Update/Common.js +41 -0
- package/Tasks/Update/EreaseUpdate.d.ts +3 -0
- package/Tasks/Update/EreaseUpdate.js +66 -0
- package/Tasks/Update/InitTasks.d.ts +2 -2
- package/Tasks/Update/InitTasks.js +3 -1
- package/Tasks/Update/PaintUpdate.d.ts +3 -0
- package/Tasks/Update/PaintUpdate.js +89 -0
- package/Tasks/Update/VoxelUpdate.d.ts +2 -5
- package/Tasks/Update/VoxelUpdate.js +5 -147
- package/Tasks/{Update/UpdateTask.d.ts → VoxelUpdateTask.d.ts} +15 -7
- package/Tasks/{Update/UpdateTask.js → VoxelUpdateTask.js} +20 -7
- package/Tasks/WorldGeneration/WorldGenBrush.d.ts +3 -3
- package/Tasks/WorldGeneration/WorldGenBrush.js +2 -2
- package/Tasks/WorldGeneration/WorldGenRegister.d.ts +1 -1
- package/Templates/Functions/CreateTemplate.d.ts +1 -1
- package/Tools/Brush/AdvancedBrushTool.js +1 -1
- package/Tools/Brush/Brush.d.ts +2 -2
- package/Tools/Brush/Brush.js +1 -1
- package/Tools/Tasks/TasksTool.d.ts +1 -0
- package/Tools/Tasks/TasksTool.js +2 -0
- package/Util/Binary/BinaryBuffer.d.ts +17 -11
- package/Util/Binary/BinaryBuffer.js +65 -59
- package/Util/Binary/BinaryTree.d.ts +46 -0
- package/Util/Binary/BinaryTree.js +104 -0
- package/Voxels/Cursor/VoxelCursor.interface.d.ts +7 -2
- package/Voxels/Cursor/VoxelCursor.interface.js +46 -2
- package/Voxels/Cursor/VoxelLightData.js +1 -1
- package/Voxels/Data/VoxelTag.types.d.ts +17 -2
- package/Voxels/Data/VoxelTag.types.js +6 -1
- package/Voxels/Data/VoxelTagsRegister.js +5 -0
- package/Voxels/Functions/BuildStateData.d.ts +6 -6
- package/Voxels/Functions/BuildStateData.js +31 -31
- package/Voxels/Functions/BuildTagAndPaletteData.js +5 -0
- package/Voxels/Indexes/VoxelIndex.d.ts +2 -2
- package/Voxels/Indexes/VoxelIndex.js +16 -18
- package/Voxels/InitVoxelData.js +12 -8
- package/Voxels/Logic/Classes/Default/Types/VoxelPoweredLogicType.d.ts +5 -0
- package/Voxels/Logic/Classes/Default/Types/VoxelPoweredLogicType.js +6 -0
- package/Voxels/Logic/Classes/VoxelLogic.d.ts +11 -0
- package/Voxels/Logic/Classes/VoxelLogic.js +49 -0
- package/Voxels/Logic/Classes/VoxelLogicType.d.ts +4 -0
- package/Voxels/Logic/Classes/VoxelLogicType.js +2 -0
- package/Voxels/Logic/VoxelLogic.types.d.ts +23 -0
- package/Voxels/Logic/VoxelLogic.types.js +1 -0
- package/Voxels/Logic/VoxelLogicRegister.d.ts +9 -0
- package/Voxels/Logic/VoxelLogicRegister.js +15 -0
- package/Voxels/State/SchemaRegister.js +10 -5
- package/Voxels/State/State.types.d.ts +1 -1
- package/Voxels/State/StateTreeReader.d.ts +1 -1
- package/Voxels/State/StateTreeReader.js +2 -3
- package/Voxels/Types/Voxel.types.d.ts +3 -0
- package/Voxels/Types/VoxelModelCompiledData.types.d.ts +6 -4
- package/World/Archive/Archive.types.d.ts +31 -12
- package/World/Archive/Classes/ArchiveClasses.d.ts +66 -0
- package/World/Archive/Classes/ArchiveClasses.js +78 -0
- package/World/Archive/Classes/ImportedSection.d.ts +40 -0
- package/World/Archive/Classes/ImportedSection.js +307 -0
- package/World/Archive/Classes/ImportedSector.d.ts +23 -0
- package/World/Archive/Classes/ImportedSector.js +97 -0
- package/World/Archive/Functions/ArchiveArea.d.ts +1 -1
- package/World/Archive/Functions/ArchiveArea.js +39 -36
- package/World/Archive/Functions/ArchiveSector.js +210 -404
- package/World/Archive/Functions/CreateArchivedSection.d.ts +3 -0
- package/World/Archive/Functions/CreateArchivedSection.js +207 -0
- package/World/Archive/Functions/ImportSector.d.ts +1 -3
- package/World/Archive/Functions/ImportSector.js +13 -244
- package/World/Archive/Functions/RemoveDuplicates.d.ts +3 -0
- package/World/Archive/Functions/RemoveDuplicates.js +92 -0
- package/World/Archive/Functions/Shared.d.ts +2 -2
- package/World/Archive/Functions/Shared.js +15 -40
- package/World/Archive/InitTasks.js +7 -10
- package/World/Cursor/SectionCursor.d.ts +1 -1
- package/World/Cursor/SectorCursor.d.ts +1 -1
- package/World/Cursor/WorldCursor.d.ts +4 -3
- package/World/Cursor/WorldCursor.js +16 -13
- package/World/Cursor/WorldVoxelCursor.d.ts +0 -4
- package/World/Cursor/WorldVoxelCursor.js +23 -14
- package/World/Dimension/Dimension.d.ts +4 -1
- package/World/Dimension/Dimension.js +8 -1
- package/World/Section/Section.d.ts +17 -4
- package/World/Section/Section.js +68 -6
- package/World/Section/SectionState.d.ts +4 -2
- package/World/Section/SectionState.js +4 -2
- package/World/Sector/Sector.d.ts +7 -1
- package/World/Sector/Sector.js +37 -4
- package/World/Sector/SectorState.d.ts +3 -2
- package/World/Sector/SectorState.js +3 -2
- package/World/Types/WorldData.types.d.ts +2 -7
- package/World/WorldRegister.d.ts +9 -9
- package/World/WorldRegister.js +9 -6
- package/World/WorldSpaces.js +6 -6
- package/{Tasks/IWG → WorldSimulation}/Internal/Classes/DimensionSegment.d.ts +2 -2
- package/{Tasks/IWG → WorldSimulation}/Internal/Classes/Generator.d.ts +6 -4
- package/{Tasks/IWG → WorldSimulation}/Internal/Classes/Generator.js +9 -5
- package/WorldSimulation/Internal/Classes/Queues/BuildQueue.d.ts +5 -0
- package/WorldSimulation/Internal/Classes/Queues/BuildQueue.js +6 -0
- package/WorldSimulation/Internal/Classes/Queues/LogiccQueue.d.ts +5 -0
- package/WorldSimulation/Internal/Classes/Queues/LogiccQueue.js +6 -0
- package/{Tasks/IWG → WorldSimulation}/Internal/Classes/SectorVisistedMap.js +1 -1
- package/WorldSimulation/Internal/Classes/TickQueue.d.ts +12 -0
- package/{Tasks/IWG/Internal/Classes/BuildQueue.js → WorldSimulation/Internal/Classes/TickQueue.js} +16 -7
- package/WorldSimulation/Internal/Classes/WorldSimulationTaskBase.d.ts +15 -0
- package/{Tasks/IWG/Internal/Classes/IWGTaskBase.js → WorldSimulation/Internal/Classes/WorldSimulationTaskBase.js} +6 -6
- package/{Tasks/IWG → WorldSimulation}/Internal/Functions/cullSectors.js +9 -9
- package/{Tasks/IWG → WorldSimulation}/Internal/Functions/getSectorState.d.ts +1 -1
- package/{Tasks/IWG → WorldSimulation}/Internal/Functions/getSectorState.js +4 -4
- package/WorldSimulation/Internal/Functions/runTickUpdate.d.ts +2 -0
- package/{Tasks/IWG/Internal/Functions/runBuildUpdate.js → WorldSimulation/Internal/Functions/runTickUpdate.js} +29 -19
- package/{Tasks/IWG → WorldSimulation}/Internal/Functions/runWorldUpdate.js +13 -13
- package/{Tasks/IWG → WorldSimulation}/Internal/TaskRegister.d.ts +2 -2
- package/{Tasks/IWG → WorldSimulation}/Internal/TaskRegister.js +1 -1
- package/WorldSimulation/Internal/WorldSimulationDimensions.d.ts +6 -0
- package/{Tasks/IWG/Internal/IWGDimensions.js → WorldSimulation/Internal/WorldSimulationDimensions.js} +1 -1
- package/WorldSimulation/Internal/WorldSimulationTasks.d.ts +30 -0
- package/{Tasks/IWG/Internal/IWGTasks.js → WorldSimulation/Internal/WorldSimulationTasks.js} +14 -14
- package/WorldSimulation/Internal/WorldSimulationTools.d.ts +8 -0
- package/{Tasks/IWG/Internal/IWGTools.js → WorldSimulation/Internal/WorldSimulationTools.js} +1 -1
- package/{Tasks/IWG → WorldSimulation}/Procedures/InitalLoad.d.ts +1 -1
- package/{Tasks/IWG → WorldSimulation}/Procedures/InitalLoad.js +11 -11
- package/{Tasks/IWG → WorldSimulation}/Procedures/SaveAllSectors.js +5 -5
- package/{Tasks/IWG/IWG.d.ts → WorldSimulation/WorldSimulation.d.ts} +5 -5
- package/{Tasks/IWG/IWG.js → WorldSimulation/WorldSimulation.js} +21 -21
- package/{Tasks/IWG → WorldSimulation}/index.d.ts +1 -1
- package/{Tasks/IWG → WorldSimulation}/index.js +1 -1
- package/package.json +1 -1
- package/Tasks/IWG/Internal/Classes/BuildQueue.d.ts +0 -11
- package/Tasks/IWG/Internal/Classes/IWGTaskBase.d.ts +0 -15
- package/Tasks/IWG/Internal/Functions/runBuildUpdate.d.ts +0 -2
- package/Tasks/IWG/Internal/IWGDimensions.d.ts +0 -6
- package/Tasks/IWG/Internal/IWGTasks.d.ts +0 -30
- package/Tasks/IWG/Internal/IWGTools.d.ts +0 -8
- /package/{Tasks/IWG → WorldSimulation}/Internal/Classes/DimensionSegment.js +0 -0
- /package/{Tasks/IWG → WorldSimulation}/Internal/Classes/SectorState.d.ts +0 -0
- /package/{Tasks/IWG → WorldSimulation}/Internal/Classes/SectorState.js +0 -0
- /package/{Tasks/IWG → WorldSimulation}/Internal/Classes/SectorVisistedMap.d.ts +0 -0
- /package/{Tasks/IWG → WorldSimulation}/Internal/Functions/cullSectors.d.ts +0 -0
- /package/{Tasks/IWG → WorldSimulation}/Internal/Functions/runWorldUpdate.d.ts +0 -0
- /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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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
|
-
|
|
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,
|
|
10
|
-
indices = new VoxelIndiceBuffer(
|
|
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
|
-
|
|
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:
|
|
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
|
|
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
|
+
}
|