@divinevoxel/vlox 0.0.5 → 0.0.7

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 (98) hide show
  1. package/Contexts/Base/Remote/InitWorldDataSync.js +2 -4
  2. package/Contexts/Render/DVERenderThreads.d.ts +1 -1
  3. package/Contexts/Render/DVERenderThreads.js +2 -2
  4. package/Contexts/Render/DivineVoxelEngineRender.d.ts +5 -5
  5. package/Contexts/Render/DivineVoxelEngineRender.js +1 -1
  6. package/Contexts/World/DivineVoxelEngineWorld.d.ts +5 -5
  7. package/Init/StartRenderer.js +5 -5
  8. package/Math/Indexing.js +6 -6
  9. package/Mesher/Functions/CompactVoxelMesh.js +40 -7
  10. package/Mesher/Functions/MeshSection.js +16 -9
  11. package/Mesher/Functions/MeshTexture.d.ts +1 -1
  12. package/Mesher/Functions/MeshVoxel.js +5 -4
  13. package/Mesher/Geomtry/Buffers.d.ts +19 -0
  14. package/Mesher/Geomtry/Buffers.js +81 -0
  15. package/Mesher/Geomtry/Tools/MesherDataTools.d.ts +3 -3
  16. package/Mesher/Geomtry/Tools/MesherDataTools.js +2 -2
  17. package/Mesher/Geomtry/VoxelGeometryBuilder.js +3 -3
  18. package/Mesher/Geomtry/VoxelMesh.d.ts +12 -0
  19. package/Mesher/Geomtry/VoxelMesh.js +25 -0
  20. package/Mesher/InitTask.js +1 -2
  21. package/Mesher/Models/Common/BoxGeometryNode.js +2 -1
  22. package/Mesher/Models/Nodes/Ruled/BoxVoxelGeometryNode.js +10 -7
  23. package/Mesher/Models/Nodes/Ruled/QuadVoxelGeometryNode.js +7 -7
  24. package/Mesher/Models/Nodes/VoxelGeometryConstructor.js +1 -1
  25. package/Mesher/Models/VoxelConstructor.d.ts +0 -2
  26. package/Mesher/Models/VoxelConstructor.js +9 -15
  27. package/Mesher/Models/VoxelGeometryLookUp.d.ts +20 -11
  28. package/Mesher/Models/VoxelGeometryLookUp.js +84 -50
  29. package/Mesher/Tools/VoxelMeshBVHBuilder.js +20 -25
  30. package/Mesher/Tools/VoxelMeshVertexStructCursor.d.ts +3 -1
  31. package/Mesher/Tools/VoxelMesherDataTool.d.ts +3 -2
  32. package/Mesher/Tools/VoxelMesherDataTool.js +8 -3
  33. package/Renderer/Classes/DVESectionMeshes.d.ts +1 -0
  34. package/Renderer/Classes/SectionMesh.d.ts +1 -2
  35. package/Renderer/Classes/SectionMesh.js +0 -3
  36. package/Renderer/InitTasks.js +16 -1
  37. package/Renderer/MeshManager.js +4 -0
  38. package/Renderer/MeshRegister.d.ts +1 -6
  39. package/Renderer/index.d.ts +0 -1
  40. package/Renderer/index.js +0 -1
  41. package/Settings/EngineSettings.d.ts +5 -5
  42. package/Settings/EngineSettings.js +15 -15
  43. package/Settings/EngineSettings.types.d.ts +62 -44
  44. package/Settings/EngineSettings.types.js +44 -42
  45. package/Tasks/IWG/IWG.d.ts +3 -0
  46. package/Tasks/IWG/IWG.js +3 -0
  47. package/Tasks/IWG/Internal/Functions/cullSectors.js +1 -2
  48. package/Tasks/IWG/Internal/Functions/getSectorState.js +1 -1
  49. package/Tasks/IWG/Internal/Functions/runBuildUpdate.js +1 -2
  50. package/Tasks/IWG/Internal/Functions/runWorldUpdate.js +1 -2
  51. package/Tasks/IWG/Internal/IWGTasks.js +7 -13
  52. package/Tasks/Propagation/Explosion/ExplosionManager.js +1 -1
  53. package/Tasks/Propagation/Flow/WorldFlow.js +6 -8
  54. package/Tasks/Propagation/Illumanation/RGBUpdate.js +2 -2
  55. package/Tasks/Propagation/Illumanation/WorldRGB.js +2 -3
  56. package/Tasks/Propagation/Illumanation/WorldSun.js +11 -5
  57. package/Tasks/Update/VoxelUpdate.js +21 -26
  58. package/Tasks/WorldGeneration/WorldGenRegister.js +5 -8
  59. package/Tasks/WorldGeneration/WorldGeneration.d.ts +0 -2
  60. package/Tasks/WorldGeneration/WorldGeneration.js +0 -2
  61. package/Templates/Cursor/TemplateVoxelCursor.d.ts +1 -0
  62. package/Templates/Cursor/TemplateVoxelCursor.js +1 -0
  63. package/Textures/TextureBuilder.d.ts +1 -1
  64. package/Textures/TextureBuilder.js +1 -1
  65. package/Textures/TextureManager.js +1 -1
  66. package/Tools/Brush/Brush.d.ts +1 -0
  67. package/Tools/Brush/Brush.js +8 -11
  68. package/Voxels/Cursor/VoxelCursor.d.ts +1 -0
  69. package/Voxels/Cursor/VoxelCursor.interface.d.ts +5 -0
  70. package/Voxels/Cursor/VoxelCursor.interface.js +5 -5
  71. package/Voxels/Cursor/VoxelCursor.js +5 -3
  72. package/Voxels/VoxelLevelReader.d.ts +10 -0
  73. package/Voxels/VoxelLevelReader.js +20 -0
  74. package/World/Archive/Functions/ArchiveSector.d.ts +1 -1
  75. package/World/Archive/Functions/ArchiveSector.js +2 -3
  76. package/World/Archive/InitTasks.js +2 -3
  77. package/World/Cursor/SectionCursor.js +1 -2
  78. package/World/Cursor/SectorCursor.d.ts +1 -0
  79. package/World/Cursor/SectorCursor.js +8 -3
  80. package/World/Cursor/WorldCursor.js +1 -2
  81. package/World/Cursor/WorldVoxelCursor.d.ts +1 -5
  82. package/World/Cursor/WorldVoxelCursor.js +1 -5
  83. package/World/InitTasks.js +5 -10
  84. package/World/Lock/WorldLock.js +4 -5
  85. package/World/Sector/SectorHeightMap.js +4 -6
  86. package/World/WorldRegister.d.ts +4 -6
  87. package/World/WorldRegister.js +24 -20
  88. package/World/WorldSpaces.d.ts +21 -0
  89. package/World/WorldSpaces.js +58 -7
  90. package/package.json +1 -1
  91. package/Mesher/Geomtry/Mesh.d.ts +0 -11
  92. package/Mesher/Geomtry/Mesh.js +0 -23
  93. package/Renderer/Classes/DVESectionMeshInterface.d.ts +0 -3
  94. package/Renderer/Classes/DVESectionMeshInterface.js +0 -1
  95. package/Voxels/VoxelStateReader.d.ts +0 -12
  96. package/Voxels/VoxelStateReader.js +0 -30
  97. package/World/WorldBounds.d.ts +0 -20
  98. package/World/WorldBounds.js +0 -53
@@ -61,7 +61,7 @@ export class VoxelGeometryConstructor {
61
61
  for (const node of this.nodes) {
62
62
  node.faceIndex = faceCount;
63
63
  node.vertexIndex = vertexCount;
64
- faceCount += node.faceCount - 1;
64
+ faceCount += node.faceCount;
65
65
  vertexCount += node.vertexCount;
66
66
  }
67
67
  }
@@ -21,8 +21,6 @@ export declare class VoxelConstructor {
21
21
  shapeStateTree: StateTreeReader;
22
22
  condtioanlShapeStateTree: CondtionalTreeReader;
23
23
  constructor(id: string, data: CompiledVoxelModelData, voxleData: CompiledVoxelModelInputData);
24
- getShapeStateTransaprentByteIndex(shapeState: number, geomtryId: number): number;
25
- getCondtionalStateTransaprentByteIndex(shapeState: number, geomtryId: number): number;
26
24
  isShapeStateFaceTransparent(modState: number, shapeState: number, geoId: number, faceIndex: number): boolean;
27
25
  isCondtionalStateFaceTransparent(modState: number, shapeState: number, geoId: number, faceIndex: number): boolean;
28
26
  process(tool: VoxelMesherDataTool): void;
@@ -25,30 +25,24 @@ export class VoxelConstructor {
25
25
  this.baseInputMap = voxleData.baseGeometryInputMap;
26
26
  this.conditonalInputMap = voxleData.condiotnalGeometryInputMap;
27
27
  this.transparentIndex = new VoxelFaceTransparentResultsIndex(voxleData.transparentFaceIndex);
28
- this.modSchema = new StateSchema(voxleData.modSchema);
29
- this.modTree = new StateTreeReader(this.modSchema, 0, voxleData.modStateTree);
30
28
  this.schema = new StateSchema(data.schema);
31
29
  this.shapeStateTree = new StateTreeReader(this.schema, 0, data.shapeStateTree);
32
30
  this.condtioanlShapeStateTree = new CondtionalTreeReader(this.schema, data.condiotnalStatements, data.condiotnalStateTree);
31
+ this.modSchema = new StateSchema(voxleData.modSchema);
32
+ this.modTree = new StateTreeReader(this.modSchema, 0, voxleData.modStateTree);
33
33
  this.effects = new VoxelModelEffect(this);
34
34
  }
35
- getShapeStateTransaprentByteIndex(shapeState, geomtryId) {
36
- return this.data.relativeGeometryByteIndexMap[this.data.shapeStateRelativeGeometryMap[shapeState][geomtryId]];
37
- }
38
- getCondtionalStateTransaprentByteIndex(shapeState, geomtryId) {
39
- return this.data.relativeGeometryByteIndexMap[this.data.condiotnalShapeStateRelativeGeometryMap[shapeState][geomtryId]];
40
- }
41
35
  isShapeStateFaceTransparent(modState, shapeState, geoId, faceIndex) {
42
- return (this.transparentIndex.getValue(modState, this.getShapeStateTransaprentByteIndex(shapeState, geoId), faceIndex) == 1);
36
+ return (this.transparentIndex.getValue(modState, this.data.relativeGeometryByteIndexMap[this.data.shapeStateRelativeGeometryMap[shapeState][geoId]], faceIndex) == 1);
43
37
  }
44
38
  isCondtionalStateFaceTransparent(modState, shapeState, geoId, faceIndex) {
45
- return (this.transparentIndex.getValue(modState, this.getCondtionalStateTransaprentByteIndex(shapeState, geoId), faceIndex) == 1);
39
+ return (this.transparentIndex.getValue(modState, this.data.relativeGeometryByteIndexMap[this.data.condiotnalShapeStateRelativeGeometryMap[shapeState][geoId]], faceIndex) == 1);
46
40
  }
47
41
  process(tool) {
48
42
  const hashed = VoxelGeometryLookUp.getHash(tool.nVoxel, tool.position.x, tool.position.y, tool.position.z);
49
- const treeState = VoxelGeometryLookUp.stateCache[hashed];
50
- const modState = VoxelGeometryLookUp.modCache[hashed];
51
- if (treeState !== undefined && treeState > -1) {
43
+ const treeState = VoxelGeometryLookUp.space.stateCache[hashed];
44
+ const modState = VoxelGeometryLookUp.space.modCache[hashed];
45
+ if (treeState > -1) {
52
46
  const geoLinks = this.data.shapeStateMap[treeState];
53
47
  const geometries = this.data.shapeStateGeometryMap[treeState];
54
48
  const geometriesLength = geoLinks.length;
@@ -63,8 +57,8 @@ export class VoxelConstructor {
63
57
  }
64
58
  }
65
59
  }
66
- const conditonalTreeState = VoxelGeometryLookUp.conditonalStateCache[hashed];
67
- if (conditonalTreeState !== undefined && conditonalTreeState > -1) {
60
+ const conditonalTreeState = VoxelGeometryLookUp.space.conditonalStateCache[hashed];
61
+ if (conditonalTreeState > -1) {
68
62
  const condiotnalNodes = this.data.condiotnalShapeStateMap[conditonalTreeState];
69
63
  const condiotnalNodesLength = condiotnalNodes.length;
70
64
  for (let c = 0; c < condiotnalNodesLength; c++) {
@@ -1,19 +1,28 @@
1
1
  import { DataCursorInterface } from "../../Data/Cursor/DataCursor.interface";
2
- import { VoxelConstructor } from "./VoxelConstructor";
3
- import { Vec3Array } from "@amodx/math";
2
+ import { Vec3Array, Vector3Like } from "@amodx/math";
4
3
  import { VoxelCursor } from "../../Voxels/Cursor/VoxelCursor";
4
+ export declare class VoxelGeometryLookUpSpace {
5
+ bounds: Vector3Like;
6
+ foundHash: Uint8Array;
7
+ voxelHash: Uint16Array;
8
+ modCache: Int32Array;
9
+ stateCache: Int32Array;
10
+ conditonalStateCache: Int32Array;
11
+ noCastAO: Uint8Array;
12
+ offset: Vec3Array;
13
+ constructor(bounds: Vector3Like);
14
+ start(x: number, y: number, z: number): void;
15
+ getIndex(x: number, y: number, z: number): number;
16
+ getConstructor(index: number): import("./VoxelConstructor").VoxelConstructor | null;
17
+ getGeomtry(index: number): false | number[];
18
+ getConditionalGeomtry(index: number): false | number[][];
19
+ }
5
20
  export declare class VoxelGeometryLookUp {
6
- static voxelHash: VoxelConstructor[];
7
- static modCache: number[];
8
- static stateCache: number[];
9
- static conditonalStateCache: number[];
10
- static geometryCache: number[][];
11
- static conditionalGeometryCache: number[][][];
12
- static noCastAO: boolean[];
13
- static offset: Vec3Array;
21
+ static space: VoxelGeometryLookUpSpace | null;
14
22
  static voxelCursor: VoxelCursor;
23
+ static createSpace(x: number, y: number, z: number): VoxelGeometryLookUpSpace;
15
24
  static init(): void;
16
- static start(dimension: string, x: number, y: number, z: number): void;
25
+ static start(space: VoxelGeometryLookUpSpace): void;
17
26
  static isRulesless(geoId: number): boolean;
18
27
  static stop(): void;
19
28
  static getHash(dataCursor: DataCursorInterface, x: number, y: number, z: number): number;
@@ -1,67 +1,106 @@
1
1
  import { VoxelModelConstructorRegister } from "./VoxelModelConstructorRegister";
2
- import { Vector3Like } from "@amodx/math";
3
2
  import { VoxelCursor } from "../../Voxels/Cursor/VoxelCursor";
4
- export class VoxelGeometryLookUp {
5
- static voxelHash = [];
6
- static modCache = [];
7
- static stateCache = [];
8
- static conditonalStateCache = [];
9
- static geometryCache = [];
10
- static conditionalGeometryCache = [];
11
- static noCastAO = [];
12
- static offset = [0, 0, 0];
13
- static voxelCursor = new VoxelCursor();
14
- static init() { }
15
- static start(dimension, x, y, z) {
3
+ import { GetYXZOrderArrayIndex } from "../../Math/Indexing";
4
+ export class VoxelGeometryLookUpSpace {
5
+ bounds;
6
+ foundHash;
7
+ voxelHash;
8
+ modCache;
9
+ stateCache;
10
+ conditonalStateCache;
11
+ noCastAO;
12
+ offset = [0, 0, 0];
13
+ constructor(bounds) {
14
+ this.bounds = bounds;
15
+ const volume = bounds.x * bounds.y * bounds.z;
16
+ this.foundHash = new Uint8Array(volume);
17
+ this.voxelHash = new Uint16Array(volume);
18
+ this.modCache = new Int32Array(volume);
19
+ this.stateCache = new Int32Array(volume);
20
+ this.conditonalStateCache = new Int32Array(volume);
21
+ this.noCastAO = new Uint8Array(volume);
22
+ }
23
+ start(x, y, z) {
16
24
  this.offset[0] = x;
17
25
  this.offset[1] = y;
18
26
  this.offset[2] = z;
27
+ this.foundHash.fill(0);
28
+ this.voxelHash.fill(0);
29
+ this.modCache.fill(-1);
30
+ this.stateCache.fill(-1);
31
+ this.conditonalStateCache.fill(-1);
32
+ this.noCastAO.fill(0);
33
+ }
34
+ getIndex(x, y, z) {
35
+ return GetYXZOrderArrayIndex(x - this.offset[0], y - this.offset[1], z - this.offset[2], this.bounds.x, this.bounds.y, this.bounds.z);
36
+ }
37
+ getConstructor(index) {
38
+ if (this.foundHash[index] !== 2)
39
+ return null;
40
+ return VoxelModelConstructorRegister.constructorsPaltte[this.voxelHash[index]];
41
+ }
42
+ getGeomtry(index) {
43
+ if (this.foundHash[index] !== 2)
44
+ return false;
45
+ return VoxelModelConstructorRegister.constructorsPaltte[this.voxelHash[index]].data.shapeStateGeometryMap[this.stateCache[index]];
46
+ }
47
+ getConditionalGeomtry(index) {
48
+ if (this.foundHash[index] !== 2)
49
+ return false;
50
+ return VoxelModelConstructorRegister.constructorsPaltte[this.voxelHash[index]].data.condiotnalShapeStateGeometryMap[this.conditonalStateCache[index]];
51
+ }
52
+ }
53
+ export class VoxelGeometryLookUp {
54
+ static space = null;
55
+ static voxelCursor = new VoxelCursor();
56
+ static createSpace(x, y, z) {
57
+ return new VoxelGeometryLookUpSpace({ x, y, z });
58
+ }
59
+ static init() { }
60
+ static start(space) {
61
+ this.space = space;
19
62
  }
20
63
  static isRulesless(geoId) {
21
64
  return VoxelModelConstructorRegister.rulesless[geoId] == true;
22
65
  }
23
- static stop() {
24
- this.stateCache.length = 0;
25
- this.voxelHash.length = 0;
26
- this.modCache.length = 0;
27
- this.geometryCache.length = 0;
28
- this.conditionalGeometryCache.length = 0;
29
- this.conditonalStateCache.length = 0;
30
- this.noCastAO.length = 0;
31
- }
66
+ static stop() { }
32
67
  static getHash(dataCursor, x, y, z) {
33
- const hashed = Vector3Like.HashXYZ(x - this.offset[0], y - this.offset[1], z - this.offset[2]);
34
- if (!this.stateCache[hashed])
68
+ if (!this.space)
69
+ throw new Error(`Voxel geomtry look up must have space set`);
70
+ const hashed = this.space.getIndex(x, y, z);
71
+ if (this.space.foundHash[hashed] == 0) {
35
72
  this.hashState(dataCursor, hashed, x, y, z);
73
+ }
36
74
  return hashed;
37
75
  }
38
- static hashState(dataCursor, hashed, x, y, z) {
39
- if (this.stateCache[hashed] !== undefined)
40
- return this.stateCache[hashed];
41
- const voxel = dataCursor.getVoxel(x, y, z);
42
- if (!voxel) {
43
- this.stateCache[hashed] = -1;
76
+ static hashState(dataCursor, index, x, y, z) {
77
+ if (!this.space)
78
+ throw new Error(`Voxel geomtry look up must have space set`);
79
+ if (this.space.foundHash[index] == 1)
44
80
  return -1;
45
- }
46
- if (!voxel.isRenderable()) {
47
- this.stateCache[hashed] = -1;
81
+ if (this.space.foundHash[index] == 2)
82
+ return this.space.stateCache[index];
83
+ const voxel = dataCursor.getVoxel(x, y, z);
84
+ if (!voxel || !voxel.isRenderable()) {
85
+ this.space.foundHash[index] = 1;
48
86
  return -1;
49
87
  }
50
- const voxelConstructor = VoxelModelConstructorRegister.constructorsPaltte[voxel.getId()];
51
- if (!voxelConstructor || !voxelConstructor.isModel) {
52
- this.stateCache[hashed] = -1;
88
+ const voxelId = voxel.getId();
89
+ const voxelConstructor = VoxelModelConstructorRegister.constructorsPaltte[voxelId];
90
+ if (!voxelConstructor) {
91
+ this.space.foundHash[index] = 1;
53
92
  return -1;
54
93
  }
94
+ this.space.voxelHash[index] = voxelId;
95
+ this.space.foundHash[index] = 2;
55
96
  //no ao
56
- this.noCastAO[hashed] = voxel.isLightSource() || voxel.noAO();
97
+ this.space.noCastAO[index] = voxel.isLightSource() || voxel.noAO() ? 1 : 0;
57
98
  //state
58
- const shapeState = voxel.getState();
59
- const state = voxelConstructor.shapeStateTree.getState(shapeState);
60
- this.stateCache[hashed] = state;
99
+ const state = voxelConstructor.shapeStateTree.getState(voxel.getState());
100
+ this.space.stateCache[index] = state;
61
101
  //mod
62
- const mod = voxel.getMod();
63
- const modState = voxelConstructor.modTree.getState(mod);
64
- this.modCache[hashed] = modState;
102
+ const mod = voxelConstructor.modTree.getState(voxel.getMod());
103
+ this.space.modCache[index] = mod;
65
104
  this.voxelCursor.copy(voxel).process();
66
105
  voxelConstructor.schema.position.x = x;
67
106
  voxelConstructor.schema.position.y = y;
@@ -69,12 +108,7 @@ export class VoxelGeometryLookUp {
69
108
  voxelConstructor.schema.voxel = this.voxelCursor;
70
109
  voxelConstructor.schema.dataCursor = dataCursor;
71
110
  const conditonalState = voxelConstructor.condtioanlShapeStateTree.getState();
72
- this.voxelHash[hashed] = voxelConstructor;
73
- this.conditonalStateCache[hashed] = conditonalState;
74
- this.geometryCache[hashed] =
75
- voxelConstructor.data.shapeStateGeometryMap[state];
76
- this.conditionalGeometryCache[hashed] =
77
- voxelConstructor.data.condiotnalShapeStateGeometryMap[conditonalState];
78
- return state;
111
+ this.space.conditonalStateCache[index] = conditonalState;
112
+ return 1;
79
113
  }
80
114
  }
@@ -1,4 +1,5 @@
1
1
  import { WorldSpaces } from "../../World/WorldSpaces";
2
+ const MAX_FLOAT32 = new Float32Array([Infinity])[0];
2
3
  /**
3
4
  * A class to help with indexing a full flat binary tree defined by the number of levels it has.
4
5
  */
@@ -160,23 +161,29 @@ export class StructCursor {
160
161
  const ix = this.trueIndex;
161
162
  const iy = this.trueIndex + 1;
162
163
  const iz = this.trueIndex + 2;
163
- this.data[ix] =
164
- this.data[ix] == -Infinity || x < this.data[ix] ? x : this.data[ix];
165
- this.data[iy] =
166
- this.data[iy] == -Infinity || y < this.data[iy] ? y : this.data[iy];
167
- this.data[iz] =
168
- this.data[iz] == -Infinity || z < this.data[iz] ? z : this.data[iz];
164
+ if (x < this.data[ix] || this.data[ix] == -MAX_FLOAT32) {
165
+ this.data[ix] = x;
166
+ }
167
+ if (y < this.data[iy] || this.data[iy] == -MAX_FLOAT32) {
168
+ this.data[iy] = y;
169
+ }
170
+ if (z < this.data[iz] || this.data[iz] == -MAX_FLOAT32) {
171
+ this.data[iz] = z;
172
+ }
169
173
  }
170
174
  updateMax(x, y, z) {
171
175
  const ix = this.trueIndex + 4;
172
176
  const iy = this.trueIndex + 5;
173
177
  const iz = this.trueIndex + 6;
174
- this.data[ix] =
175
- this.data[ix] == -Infinity || x > this.data[ix] ? x : this.data[ix];
176
- this.data[iy] =
177
- this.data[iy] == -Infinity || y > this.data[iy] ? y : this.data[iy];
178
- this.data[iz] =
179
- this.data[iz] == -Infinity || z > this.data[iz] ? z : this.data[iz];
178
+ if (x > this.data[ix] || this.data[ix] == -MAX_FLOAT32) {
179
+ this.data[ix] = x;
180
+ }
181
+ if (y > this.data[iy] || this.data[iy] == -MAX_FLOAT32) {
182
+ this.data[iy] = y;
183
+ }
184
+ if (z > this.data[iz] || this.data[iz] == -MAX_FLOAT32) {
185
+ this.data[iz] = z;
186
+ }
180
187
  }
181
188
  toJSON() {
182
189
  return {
@@ -194,7 +201,7 @@ export class VoxelMeshBVHBuilder {
194
201
  structCursor = new StructCursor(this.tree);
195
202
  indices = new Uint32Array(this.treeIndex.getLevelSize(12) * 2);
196
203
  reset() {
197
- this.tree.fill(-Infinity);
204
+ this.tree.fill(-MAX_FLOAT32);
198
205
  this.indices.fill(0);
199
206
  }
200
207
  updateVoxel(voxelX, voxelY, voxelZ, meshIndex, indicesStart, indicesEnd, minX, minY, minZ, maxX, maxY, maxZ) {
@@ -219,15 +226,3 @@ export class VoxelMeshBVHBuilder {
219
226
  }
220
227
  }
221
228
  }
222
- /*
223
- console.warn(
224
- [voxelX, voxelY, voxelZ],
225
- "add gometry",
226
- [minX, minY, minZ],
227
- [maxX, maxY, maxZ],
228
- [voxelX, voxelY, voxelZ],
229
- [indicesStart, indicesEnd],
230
- indicesEnd - indicesStart,
231
- (indicesEnd - indicesStart) / 3
232
- );
233
- */
@@ -39,7 +39,9 @@ export declare class VoxelMeshVertexStructCursor {
39
39
  set colorB(value: number);
40
40
  trueIndex: number;
41
41
  _index: number;
42
- data: Float32Array | number[];
42
+ data: {
43
+ [index: number]: number;
44
+ };
43
45
  get index(): number;
44
46
  set index(index: number);
45
47
  constructor(data?: Float32Array);
@@ -2,7 +2,7 @@ import { MesherDataTool } from "../Geomtry/Tools/MesherDataTools";
2
2
  import { QuadScalarVertexData } from "../Geomtry/Primitives/QuadVertexData";
3
3
  import { VoxelFaces } from "../../Math";
4
4
  import { QuadVerticies } from "../Geomtry/Geometry.types";
5
- import { Mesh } from "../Geomtry/Mesh";
5
+ import { VoxelMesh } from "../Geomtry/VoxelMesh";
6
6
  import { VoxelMeshBVHBuilder } from "./VoxelMeshBVHBuilder";
7
7
  import { Vec3Array, Vector3Like } from "@amodx/math";
8
8
  import { VoxelCursorInterface } from "../../Voxels/Cursor/VoxelCursor.interface.js";
@@ -26,7 +26,7 @@ export declare class VoxelMesherDataTool extends MesherDataTool {
26
26
  position: Vector3Like;
27
27
  /**The current local origin */
28
28
  origin: Vector3Like;
29
- mesh: Mesh;
29
+ mesh: VoxelMesh;
30
30
  bvhTool: VoxelMeshBVHBuilder | null;
31
31
  vars: VoxelVars;
32
32
  dataCalculated: Record<VoxelFaces, boolean>;
@@ -44,5 +44,6 @@ export declare class VoxelMesherDataTool extends MesherDataTool {
44
44
  calculateFaceData(direction: VoxelFaces): true | undefined;
45
45
  clearCalculatedData(): void;
46
46
  reset(): void;
47
+ resetAll(): this;
47
48
  }
48
49
  export {};
@@ -5,7 +5,7 @@ import { QuadScalarVertexData } from "../Geomtry/Primitives/QuadVertexData";
5
5
  import { VoxelFaces, VoxelFacesArray } from "../../Math";
6
6
  import { QuadVerticies } from "../Geomtry/Geometry.types";
7
7
  import { FaceDataCalc } from "../Models/Common/Calc/FaceDataCalc.js";
8
- import { Mesh } from "../Geomtry/Mesh";
8
+ import { VoxelMesh } from "../Geomtry/VoxelMesh";
9
9
  import { Vector3Like } from "@amodx/math";
10
10
  class VoxelVars {
11
11
  faceFlipped = false;
@@ -29,7 +29,7 @@ export class VoxelMesherDataTool extends MesherDataTool {
29
29
  position = Vector3Like.Create();
30
30
  /**The current local origin */
31
31
  origin = Vector3Like.Create();
32
- mesh = new Mesh();
32
+ mesh = new VoxelMesh();
33
33
  bvhTool = null;
34
34
  vars = new VoxelVars();
35
35
  dataCalculated;
@@ -70,7 +70,7 @@ export class VoxelMesherDataTool extends MesherDataTool {
70
70
  this.lightData[face][QuadVerticies.BottomLeft] = 0;
71
71
  this.lightData[face][QuadVerticies.BottomRight] = 0;
72
72
  }
73
- this.startNewMesh(new Mesh(true));
73
+ this.startNewMesh(new VoxelMesh());
74
74
  }
75
75
  bounds = {
76
76
  min: [0, 0, 0],
@@ -112,4 +112,9 @@ export class VoxelMesherDataTool extends MesherDataTool {
112
112
  reset() {
113
113
  this.vars.reset();
114
114
  }
115
+ resetAll() {
116
+ this.vars.reset();
117
+ this.mesh.clear();
118
+ return this;
119
+ }
115
120
  }
@@ -3,4 +3,5 @@ import { CompactMeshData } from "../../Mesher/Types/Mesher.types";
3
3
  import { SectionMesh } from "./SectionMesh";
4
4
  export declare abstract class DVESectionMeshes {
5
5
  abstract updateVertexData(section: SectionMesh, position: Vec3Array, data: CompactMeshData): SectionMesh;
6
+ abstract returnMesh(mesh: any): void;
6
7
  }
@@ -1,11 +1,10 @@
1
- import { DVESectionMeshInterface } from "./DVESectionMeshInterface";
2
1
  import { VoxelEffect } from "../../Voxels/Effects/VoxelEffect";
3
2
  import { SectorMesh } from "./SectorMesh";
4
3
  import { Vec3Array } from "@amodx/math";
5
4
  export declare class SectionMesh {
6
5
  sector: SectorMesh;
7
6
  index: number;
8
- meshes: Map<string, DVESectionMeshInterface>;
7
+ meshes: Map<string, any>;
9
8
  effects: Map<string, VoxelEffect>;
10
9
  constructor(sector: SectorMesh, index: number);
11
10
  getPosition(): Vec3Array;
@@ -19,8 +19,5 @@ export class SectionMesh {
19
19
  for (const [key, effect] of this.effects) {
20
20
  effect.dispose();
21
21
  }
22
- for (const [key, mesh] of this.meshes) {
23
- mesh.dispose();
24
- }
25
22
  }
26
23
  }
@@ -2,9 +2,24 @@ import { Threads } from "@amodx/threads/";
2
2
  import { MeshManager } from "./MeshManager";
3
3
  import { MeshRegister } from "./MeshRegister";
4
4
  import { TaskTool } from "../Tools/Tasks/TasksTool";
5
+ import { EngineSettings } from "../Settings/EngineSettings";
5
6
  export default function RendererTasks(threads) {
6
7
  const tasks = new TaskTool(threads);
7
- Threads.registerTask("set-section", (data) => MeshManager.updateSection(data));
8
+ Threads.registerTask("set-section", (data, origin) => {
9
+ MeshManager.updateSection(data);
10
+ const tranfers = [];
11
+ for (const comp of data[1]) {
12
+ if (comp[0] !== 0)
13
+ continue;
14
+ for (const mesh of comp[1]) {
15
+ tranfers.push(mesh[1]);
16
+ tranfers.push(mesh[2]);
17
+ }
18
+ }
19
+ if (!EngineSettings.settings.rendererSettings.cpuBound) {
20
+ origin.sendMessage(data, tranfers);
21
+ }
22
+ });
8
23
  Threads.registerTask("remove-sector", (data) => {
9
24
  MeshManager.removeSector(data);
10
25
  });
@@ -49,6 +49,10 @@ export class MeshManager {
49
49
  if (!section)
50
50
  continue;
51
51
  section.dispose();
52
+ for (const [, mesh] of section.meshes) {
53
+ this.sectorMeshes.returnMesh(mesh);
54
+ }
55
+ section.meshes.clear();
52
56
  }
53
57
  }
54
58
  }
@@ -1,6 +1,5 @@
1
1
  import { type LocationData } from "../Math/index.js";
2
2
  import { SectorMesh } from "./Classes/SectorMesh.js";
3
- import { DVESectionMeshInterface } from "./Classes/DVESectionMeshInterface.js";
4
3
  export type MeshRegisterDimensions = Map<string, Map<string, SectorMesh>>;
5
4
  declare class Sectors {
6
5
  static add(location: LocationData): SectorMesh;
@@ -10,11 +9,7 @@ declare class Sectors {
10
9
  declare class Dimensions {
11
10
  static add(id: string): Map<any, any>;
12
11
  static get(id: string): Map<string, SectorMesh> | undefined;
13
- static getAllMeshes(id: string): Generator<[
14
- location: LocationData,
15
- substance: string,
16
- mesh: DVESectionMeshInterface
17
- ]>;
12
+ static getAllMeshes(id: string): Generator<[location: LocationData, substance: string, mesh: any]>;
18
13
  static remove(id: string): boolean;
19
14
  }
20
15
  export declare class MeshRegister {
@@ -1,4 +1,3 @@
1
1
  export * from "./Classes/DVESectionMeshes";
2
- export * from "./Classes/DVESectionMeshInterface";
3
2
  export * from "./Classes/SectionMesh";
4
3
  export * from "./Classes/SectorMesh";
package/Renderer/index.js CHANGED
@@ -1,4 +1,3 @@
1
1
  export * from "./Classes/DVESectionMeshes";
2
- export * from "./Classes/DVESectionMeshInterface";
3
2
  export * from "./Classes/SectionMesh";
4
3
  export * from "./Classes/SectorMesh";
@@ -12,14 +12,14 @@ type EngineSettingsEvents = {
12
12
  declare class EngineSettingsClass extends TypedEventTarget<EngineSettingsEvents> {
13
13
  enviorment: "node" | "browser";
14
14
  settings: EngineSettingsData;
15
+ get doSunPropagation(): boolean;
16
+ get doRGBPropagation(): boolean;
17
+ get doLight(): boolean;
18
+ get doFlow(): boolean;
19
+ get isClient(): boolean;
15
20
  getSettings(): EngineSettingsData;
16
21
  syncSettings(data: EngineSettingsData): void;
17
22
  getSettingsCopy(): any;
18
- doSunPropagation(): boolean;
19
- doRGBPropagation(): boolean;
20
- doLight(): boolean;
21
- doFlow(): boolean;
22
- isClient(): boolean;
23
23
  }
24
24
  export declare const EngineSettings: EngineSettingsClass;
25
25
  export {};
@@ -8,6 +8,21 @@ import { TypedEventTarget } from "../Util/TypedEventTarget.js";
8
8
  class EngineSettingsClass extends TypedEventTarget {
9
9
  enviorment = Environment.isNode() ? "node" : "browser";
10
10
  settings = new EngineSettingsData();
11
+ get doSunPropagation() {
12
+ return this.settings.lighting.autoSunLight == true;
13
+ }
14
+ get doRGBPropagation() {
15
+ return this.settings.lighting.autoRGBLight == true;
16
+ }
17
+ get doLight() {
18
+ return this.doRGBPropagation || this.doSunPropagation;
19
+ }
20
+ get doFlow() {
21
+ return this.settings.flow.enable;
22
+ }
23
+ get isClient() {
24
+ return this.enviorment != "browser";
25
+ }
11
26
  getSettings() {
12
27
  return this.settings;
13
28
  }
@@ -34,20 +49,5 @@ class EngineSettingsClass extends TypedEventTarget {
34
49
  getSettingsCopy() {
35
50
  return JSON.parse(JSON.stringify(this.settings));
36
51
  }
37
- doSunPropagation() {
38
- return this.settings.lighting.autoSunLight == true;
39
- }
40
- doRGBPropagation() {
41
- return this.settings.lighting.autoRGBLight == true;
42
- }
43
- doLight() {
44
- return this.doRGBPropagation() || this.doSunPropagation();
45
- }
46
- doFlow() {
47
- return this.settings.flow.enable;
48
- }
49
- isClient() {
50
- return this.enviorment != "browser";
51
- }
52
52
  }
53
53
  export const EngineSettings = new EngineSettingsClass();