@divinevoxel/vlox 0.0.5 → 0.0.6
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/InitWorldDataSync.js +2 -4
- package/Contexts/Render/DVERenderThreads.d.ts +1 -1
- package/Contexts/Render/DVERenderThreads.js +2 -2
- package/Contexts/Render/DivineVoxelEngineRender.js +1 -1
- package/Init/StartRenderer.js +5 -5
- package/Math/Indexing.js +6 -6
- package/Mesher/Functions/CompactVoxelMesh.js +40 -7
- package/Mesher/Functions/MeshSection.js +12 -8
- package/Mesher/Functions/MeshTexture.d.ts +1 -1
- package/Mesher/Functions/MeshVoxel.js +2 -1
- package/Mesher/Geomtry/Buffers.d.ts +19 -0
- package/Mesher/Geomtry/Buffers.js +81 -0
- package/Mesher/Geomtry/Tools/MesherDataTools.d.ts +3 -3
- package/Mesher/Geomtry/Tools/MesherDataTools.js +2 -2
- package/Mesher/Geomtry/VoxelGeometryBuilder.js +3 -3
- package/Mesher/Geomtry/VoxelMesh.d.ts +13 -0
- package/Mesher/Geomtry/VoxelMesh.js +28 -0
- package/Mesher/InitTask.js +1 -2
- package/Mesher/Models/Nodes/Ruled/BoxVoxelGeometryNode.js +7 -7
- package/Mesher/Models/Nodes/Ruled/QuadVoxelGeometryNode.js +7 -7
- package/Mesher/Models/VoxelConstructor.js +3 -3
- package/Mesher/Models/VoxelGeometryLookUp.d.ts +20 -11
- package/Mesher/Models/VoxelGeometryLookUp.js +73 -39
- package/Mesher/Tools/VoxelMeshBVHBuilder.js +20 -25
- package/Mesher/Tools/VoxelMeshVertexStructCursor.d.ts +3 -1
- package/Mesher/Tools/VoxelMesherDataTool.d.ts +2 -2
- package/Mesher/Tools/VoxelMesherDataTool.js +3 -3
- package/Renderer/Classes/DVESectionMeshes.d.ts +1 -0
- package/Renderer/Classes/SectionMesh.d.ts +1 -2
- package/Renderer/Classes/SectionMesh.js +0 -3
- package/Renderer/InitTasks.js +13 -1
- package/Renderer/MeshManager.js +4 -0
- package/Renderer/MeshRegister.d.ts +1 -6
- package/Renderer/index.d.ts +0 -1
- package/Renderer/index.js +0 -1
- package/Tasks/IWG/Internal/Functions/cullSectors.js +1 -2
- package/Tasks/IWG/Internal/Functions/getSectorState.js +1 -1
- package/Tasks/IWG/Internal/Functions/runBuildUpdate.js +1 -2
- package/Tasks/IWG/Internal/Functions/runWorldUpdate.js +1 -2
- package/Tasks/IWG/Internal/IWGTasks.js +7 -13
- package/Tasks/Propagation/Flow/WorldFlow.js +2 -4
- package/Tasks/Propagation/Illumanation/WorldRGB.js +1 -2
- package/Tasks/Propagation/Illumanation/WorldSun.js +1 -4
- package/Tasks/WorldGeneration/WorldGenRegister.js +5 -8
- package/Tasks/WorldGeneration/WorldGeneration.d.ts +0 -2
- package/Tasks/WorldGeneration/WorldGeneration.js +0 -2
- package/Tools/Brush/Brush.js +1 -2
- package/World/Archive/Functions/ArchiveSector.d.ts +1 -1
- package/World/Archive/Functions/ArchiveSector.js +2 -3
- package/World/Archive/InitTasks.js +2 -3
- package/World/Cursor/SectionCursor.js +1 -2
- package/World/Cursor/SectorCursor.js +1 -2
- package/World/Cursor/WorldCursor.js +1 -2
- package/World/InitTasks.js +5 -10
- package/World/Lock/WorldLock.js +4 -5
- package/World/Sector/SectorHeightMap.js +4 -6
- package/World/WorldRegister.d.ts +4 -6
- package/World/WorldRegister.js +24 -20
- package/World/WorldSpaces.d.ts +21 -0
- package/World/WorldSpaces.js +58 -7
- package/package.json +1 -1
- package/Mesher/Geomtry/Mesh.d.ts +0 -11
- package/Mesher/Geomtry/Mesh.js +0 -23
- package/Renderer/Classes/DVESectionMeshInterface.d.ts +0 -3
- package/Renderer/Classes/DVESectionMeshInterface.js +0 -1
- package/World/WorldBounds.d.ts +0 -20
- package/World/WorldBounds.js +0 -53
|
@@ -9,11 +9,9 @@ export default function () {
|
|
|
9
9
|
// register.dimensions.re(data.id);
|
|
10
10
|
});
|
|
11
11
|
Threads.registerTask(WorldDataSyncIds.SyncSector, (data) => {
|
|
12
|
-
WorldRegister.
|
|
13
|
-
WorldRegister.sectors.add(data[0][1], data[0][2], data[0][3], data[1]);
|
|
12
|
+
WorldRegister.sectors.add(data[0][0], data[0][1], data[0][2], data[0][3], data[1]);
|
|
14
13
|
});
|
|
15
14
|
Threads.registerTask(WorldDataSyncIds.UnSyncSector, (data) => {
|
|
16
|
-
WorldRegister.
|
|
17
|
-
WorldRegister.sectors.remove(data[1], data[2], data[3]);
|
|
15
|
+
WorldRegister.sectors.remove(data[0], data[1], data[2], data[3]);
|
|
18
16
|
});
|
|
19
17
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ThreadManager } from "../Base/ThreadManager";
|
|
2
2
|
export declare class DVERenderThreads extends ThreadManager {
|
|
3
3
|
nexus: import("@amodx/threads").Thread;
|
|
4
|
-
|
|
4
|
+
constructors: import("@amodx/threads").ThreadPool;
|
|
5
5
|
parent: import("@amodx/threads").Thread;
|
|
6
6
|
world: import("@amodx/threads").Thread;
|
|
7
7
|
constructor();
|
|
@@ -2,12 +2,12 @@ import { Threads } from "@amodx/threads";
|
|
|
2
2
|
import { ThreadManager } from "../Base/ThreadManager";
|
|
3
3
|
export class DVERenderThreads extends ThreadManager {
|
|
4
4
|
nexus = Threads.createThread("nexus");
|
|
5
|
-
|
|
5
|
+
constructors = Threads.createThreadPool("constructor");
|
|
6
6
|
parent = Threads.parent;
|
|
7
7
|
world = Threads.createThread("world");
|
|
8
8
|
constructor() {
|
|
9
9
|
super();
|
|
10
|
-
this.addThread(this.
|
|
10
|
+
this.addThread(this.constructors);
|
|
11
11
|
this.addThread(this.parent);
|
|
12
12
|
this.addThread(this.world);
|
|
13
13
|
}
|
|
@@ -25,7 +25,7 @@ export class DivineVoxelEngineRender {
|
|
|
25
25
|
async clearAll() {
|
|
26
26
|
this.meshRegister.clearAll();
|
|
27
27
|
await this.threads.world.runTaskAsync("clear-all", "");
|
|
28
|
-
await Promise.all(this.threads.
|
|
28
|
+
await Promise.all(this.threads.constructors
|
|
29
29
|
.getThreads()
|
|
30
30
|
.map((_) => _.runTaskAsync("clear-all", "")));
|
|
31
31
|
}
|
package/Init/StartRenderer.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { DivineVoxelEngineRender } from "../Contexts/Render";
|
|
2
2
|
import InitDataGenerator from "../Contexts/Base/Main/InitDataGenerator";
|
|
3
|
-
import { Thread, ThreadPool } from "@amodx/threads";
|
|
3
|
+
import { Threads, Thread, ThreadPool } from "@amodx/threads";
|
|
4
4
|
import InitWorldDataSync from "../Contexts/Base/Remote/InitWorldDataSync";
|
|
5
5
|
import InitRendererTasks from "../Renderer/InitTasks";
|
|
6
6
|
import InitMesher from "../Mesher/InitMesher";
|
|
7
7
|
import { MeshManager } from "../Renderer/MeshManager";
|
|
8
8
|
export async function StartRenderer(initData) {
|
|
9
9
|
const DVER = new DivineVoxelEngineRender();
|
|
10
|
-
await
|
|
10
|
+
await Threads.init("render", window, "window");
|
|
11
11
|
DivineVoxelEngineRender.initialized = true;
|
|
12
12
|
DVER.renderer = initData.renderer;
|
|
13
13
|
MeshManager.sectorMeshes = initData.renderer.sectorMeshes;
|
|
@@ -22,7 +22,7 @@ export async function StartRenderer(initData) {
|
|
|
22
22
|
DVER.threads.setThreadPort(DVER.threads.world.name, initData.worldWorker);
|
|
23
23
|
if (Array.isArray(initData.constructorWorkers) &&
|
|
24
24
|
initData.constructorWorkers[0] instanceof Worker) {
|
|
25
|
-
DVER.threads.setThreadPort(DVER.threads.
|
|
25
|
+
DVER.threads.setThreadPort(DVER.threads.constructors.name, initData.constructorWorkers);
|
|
26
26
|
}
|
|
27
27
|
else {
|
|
28
28
|
throw Error("Supplied data for the Constructor Workers is not correct. Must be path to worker or an array workers.");
|
|
@@ -35,7 +35,7 @@ export async function StartRenderer(initData) {
|
|
|
35
35
|
substances: initData.substances || [],
|
|
36
36
|
materials: initData.materials || [],
|
|
37
37
|
});
|
|
38
|
-
InitRendererTasks(DVER.threads.
|
|
38
|
+
InitRendererTasks(DVER.threads.constructors);
|
|
39
39
|
InitWorldDataSync();
|
|
40
40
|
InitMesher(syncData.voxels.materials.palette, syncData.voxels.models);
|
|
41
41
|
for (const thread of DVER.threads._threads) {
|
|
@@ -54,7 +54,7 @@ export async function StartRenderer(initData) {
|
|
|
54
54
|
await thread.runTaskAsync("sync-data", syncData);
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
|
-
DVER.threads.world.waitTillTaskExist("sync-data");
|
|
57
|
+
await DVER.threads.world.waitTillTaskExist("sync-data");
|
|
58
58
|
await DVER.threads.world.runTaskAsync("sync-data", syncData);
|
|
59
59
|
await DVER.renderer.init(DVER);
|
|
60
60
|
return DVER;
|
package/Math/Indexing.js
CHANGED
|
@@ -42,15 +42,15 @@ export function GetXZYOrderArrayIndex(positionX, positionY, positionZ, boundsX,
|
|
|
42
42
|
return positionX + positionY * boundsX + positionZ * boundsX * boundsZ;
|
|
43
43
|
}
|
|
44
44
|
export function GetYXZOrderArrayPositionVec3Array(index, boundsX, boundsY, boundsZ, positionRef = [0, 0, 0]) {
|
|
45
|
-
positionRef[1] =
|
|
46
|
-
positionRef[0] =
|
|
47
|
-
positionRef[2] = index % boundsZ;
|
|
45
|
+
positionRef[1] = index / (boundsX * boundsZ);
|
|
46
|
+
positionRef[0] = (index % (boundsX * boundsZ)) / boundsZ;
|
|
47
|
+
positionRef[2] = index % boundsZ;
|
|
48
48
|
return positionRef;
|
|
49
49
|
}
|
|
50
50
|
export function GetYXZOrderArrayPositionVec3(index, boundsX, boundsY, boundsZ, positionRef = Vector3Like.Create()) {
|
|
51
|
-
positionRef.y =
|
|
52
|
-
positionRef.x =
|
|
53
|
-
positionRef.z = index % boundsZ;
|
|
51
|
+
positionRef.y = index / (boundsX * boundsZ);
|
|
52
|
+
positionRef.x = (index % (boundsX * boundsZ)) / boundsZ;
|
|
53
|
+
positionRef.z = index % boundsZ;
|
|
54
54
|
return positionRef;
|
|
55
55
|
}
|
|
56
56
|
export function GetYXZOrderArrayIndex(positionX, positionY, positionZ, boundsX, boundsY, boundsZ) {
|
|
@@ -67,20 +67,53 @@ export function CompactVoxelMesh(tools) {
|
|
|
67
67
|
const tool = tools[i];
|
|
68
68
|
if (!tool.mesh.buffer.length)
|
|
69
69
|
continue;
|
|
70
|
-
const
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
70
|
+
const totalVerticies = tool.mesh.vertexCount * VoxelMeshVertexStructCursor.VertexFloatSize;
|
|
71
|
+
const vertexArray = new Float32Array(totalVerticies);
|
|
72
|
+
const vertexBuffers = tool.mesh.buffer._buffers;
|
|
73
|
+
let start = 0;
|
|
74
|
+
let done = false;
|
|
75
|
+
for (let i = 0; i < vertexBuffers.length; i++) {
|
|
76
|
+
const buffer = vertexBuffers[i];
|
|
77
|
+
for (let j = 0; j < buffer.length; j++) {
|
|
78
|
+
vertexArray[start] = buffer[j];
|
|
79
|
+
start++;
|
|
80
|
+
if (start > totalVerticies) {
|
|
81
|
+
done = true;
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (done)
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
const indiciesArray = tool.mesh.indicieCount > 65535
|
|
89
|
+
? new Uint32Array(tool.mesh.indicieCount)
|
|
90
|
+
: new Uint16Array(tool.mesh.indicieCount);
|
|
91
|
+
const indiceBuffers = tool.mesh.indices._buffers;
|
|
92
|
+
start = 0;
|
|
93
|
+
done = false;
|
|
94
|
+
for (let i = 0; i < indiceBuffers.length; i++) {
|
|
95
|
+
const buffer = indiceBuffers[i];
|
|
96
|
+
for (let j = 0; j < buffer.length; j++) {
|
|
97
|
+
indiciesArray[start] = buffer[j];
|
|
98
|
+
start++;
|
|
99
|
+
if (start > tool.mesh.indicieCount) {
|
|
100
|
+
done = true;
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (done)
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
74
107
|
const minBounds = tool.mesh.minBounds;
|
|
75
108
|
const maxBounds = tool.mesh.maxBounds;
|
|
76
109
|
data[1].push([
|
|
77
110
|
tool.id,
|
|
78
|
-
|
|
79
|
-
|
|
111
|
+
vertexArray,
|
|
112
|
+
indiciesArray,
|
|
80
113
|
[minBounds.x, minBounds.y, minBounds.z],
|
|
81
114
|
[maxBounds.x, maxBounds.y, maxBounds.z],
|
|
82
115
|
]);
|
|
83
|
-
transfers.push(
|
|
116
|
+
transfers.push(vertexArray.buffer, indiciesArray.buffer);
|
|
84
117
|
}
|
|
85
118
|
return [data, transfers];
|
|
86
119
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
//data
|
|
2
2
|
import { WorldSpaces } from "../../World/WorldSpaces.js";
|
|
3
3
|
//tools
|
|
4
|
-
import { VoxelGeometryLookUp } from "../Models/VoxelGeometryLookUp.js";
|
|
4
|
+
import { VoxelGeometryLookUp, } from "../Models/VoxelGeometryLookUp.js";
|
|
5
5
|
import { CompactVoxelMesh } from "./CompactVoxelMesh.js";
|
|
6
6
|
import { WorldCursor } from "../../World/Cursor/WorldCursor.js";
|
|
7
7
|
import { SectionCursor } from "../../World/Cursor/SectionCursor.js";
|
|
@@ -10,8 +10,10 @@ import { VoxelModelConstructorRegister } from "../Models/VoxelModelConstructorRe
|
|
|
10
10
|
import { SectionHeightMap } from "../../World/Section/SectionHeightMap.js";
|
|
11
11
|
import { WorldRegister } from "../../World/WorldRegister.js";
|
|
12
12
|
import { VoxelMeshBVHBuilder } from "../Tools/VoxelMeshBVHBuilder";
|
|
13
|
+
import { Vector3Like } from "@amodx/math";
|
|
13
14
|
const sectionCursor = new SectionCursor();
|
|
14
15
|
const worldCursor = new WorldCursor();
|
|
16
|
+
let space;
|
|
15
17
|
const bvhTool = new VoxelMeshBVHBuilder();
|
|
16
18
|
function process(x, y, z) {
|
|
17
19
|
const voxel = sectionCursor.getVoxel(x, y, z);
|
|
@@ -49,14 +51,14 @@ function meshVoxel(x, y, z, voxel) {
|
|
|
49
51
|
mesher.endConstruction();
|
|
50
52
|
mesher.reset();
|
|
51
53
|
}
|
|
54
|
+
const padding = Vector3Like.Create(5, 5, 5);
|
|
52
55
|
export function MeshSection(location) {
|
|
56
|
+
if (!space)
|
|
57
|
+
space = VoxelGeometryLookUp.createSpace(WorldSpaces.section.bounds.x + padding.x, WorldSpaces.section.bounds.y + padding.y, WorldSpaces.section.bounds.z + padding.z);
|
|
53
58
|
const [dimension, cx, cy, cz] = location;
|
|
54
|
-
WorldRegister.
|
|
55
|
-
const sector = WorldRegister.sectors.get(cx, cy, cz);
|
|
59
|
+
const sector = WorldRegister.sectors.get(dimension, cx, cy, cz);
|
|
56
60
|
if (!sector)
|
|
57
61
|
return null;
|
|
58
|
-
// console.log("mesh section", dimension, cx, cy, cz);
|
|
59
|
-
const meshStart = performance.now();
|
|
60
62
|
const section = sector.getSection(cy);
|
|
61
63
|
SectionHeightMap.setSection(section);
|
|
62
64
|
worldCursor.setFocalPoint(...location);
|
|
@@ -66,7 +68,8 @@ export function MeshSection(location) {
|
|
|
66
68
|
const maxZ = WorldSpaces.section.bounds.z;
|
|
67
69
|
if (Math.abs(minY) == Infinity && Math.abs(maxY) == Infinity)
|
|
68
70
|
return null;
|
|
69
|
-
|
|
71
|
+
space.start(cx - padding.x, cy - padding.y, cz - padding.z);
|
|
72
|
+
VoxelGeometryLookUp.start(space);
|
|
70
73
|
bvhTool.reset();
|
|
71
74
|
for (let i = 0; i < RenderedMaterials.meshers.length; i++) {
|
|
72
75
|
RenderedMaterials.meshers[i].bvhTool = bvhTool;
|
|
@@ -86,7 +89,6 @@ export function MeshSection(location) {
|
|
|
86
89
|
SectionHeightMap.setDirty(y, false);
|
|
87
90
|
}
|
|
88
91
|
VoxelGeometryLookUp.stop();
|
|
89
|
-
const compactStart = performance.now();
|
|
90
92
|
const transfers = [];
|
|
91
93
|
const sectionEffects = [];
|
|
92
94
|
const sections = [location, [], sectionEffects, 0];
|
|
@@ -98,8 +100,9 @@ export function MeshSection(location) {
|
|
|
98
100
|
transfers.push(float.buffer);
|
|
99
101
|
sectionEffects.push([e, float]);
|
|
100
102
|
}
|
|
101
|
-
if (!mesher.mesh.
|
|
103
|
+
if (!mesher.mesh.vertexCount) {
|
|
102
104
|
mesher.resetAll();
|
|
105
|
+
mesher.bvhTool = null;
|
|
103
106
|
continue;
|
|
104
107
|
}
|
|
105
108
|
meshed.push(mesher);
|
|
@@ -108,6 +111,7 @@ export function MeshSection(location) {
|
|
|
108
111
|
sections[1] = compactMesh;
|
|
109
112
|
for (let i = 0; i < meshed.length; i++) {
|
|
110
113
|
meshed[i].resetAll();
|
|
114
|
+
meshed[i].bvhTool = null;
|
|
111
115
|
}
|
|
112
116
|
return [sections, [...transfers, ...buffers]];
|
|
113
117
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function MeshTexture(textureId: number, textureData: number[]): import("../Geomtry/
|
|
1
|
+
export declare function MeshTexture(textureId: number, textureData: number[]): import("../Geomtry/VoxelMesh").VoxelMesh | null;
|
|
@@ -8,6 +8,7 @@ import { VoxelModelConstructorRegister } from "../Models/VoxelModelConstructorRe
|
|
|
8
8
|
const templateCursor = new TemplateCursor();
|
|
9
9
|
const voxelCursor = new VoxelCursor();
|
|
10
10
|
templateCursor.setTemplate(new FullVoxelTemplate(FullVoxelTemplate.CreateNew([3, 3, 3], 0xf)));
|
|
11
|
+
const space = VoxelGeometryLookUp.createSpace(3, 3, 3);
|
|
11
12
|
export function MeshVoxel(rawVoxelData) {
|
|
12
13
|
const voxel = templateCursor.getVoxel(1, 1, 1);
|
|
13
14
|
voxel.copyRaw(rawVoxelData);
|
|
@@ -24,7 +25,7 @@ export function MeshVoxel(rawVoxelData) {
|
|
|
24
25
|
}
|
|
25
26
|
mesher.bvhTool = null;
|
|
26
27
|
mesher.resetAll();
|
|
27
|
-
VoxelGeometryLookUp.start(
|
|
28
|
+
VoxelGeometryLookUp.start(space);
|
|
28
29
|
mesher.origin.x = -0.5;
|
|
29
30
|
mesher.origin.y = -0.5;
|
|
30
31
|
mesher.origin.z = -0.5;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface VoxelVertexBuffer {
|
|
2
|
+
[index: number]: number;
|
|
3
|
+
}
|
|
4
|
+
export declare class VoxelVertexBuffer {
|
|
5
|
+
vertexFloatSize: number;
|
|
6
|
+
sectorVertexSize: number;
|
|
7
|
+
_buffers: Float32Array[];
|
|
8
|
+
constructor(vertexFloatSize: number, sectorVertexSize: number, startingSectorSize?: number);
|
|
9
|
+
get length(): number;
|
|
10
|
+
}
|
|
11
|
+
export interface VoxelIndiceBuffer {
|
|
12
|
+
[index: number]: number;
|
|
13
|
+
}
|
|
14
|
+
export declare class VoxelIndiceBuffer {
|
|
15
|
+
sectorSize: number;
|
|
16
|
+
_buffers: Uint32Array[];
|
|
17
|
+
constructor(sectorSize: number, startingSectorSize?: number);
|
|
18
|
+
get length(): number;
|
|
19
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
export class VoxelVertexBuffer {
|
|
2
|
+
vertexFloatSize;
|
|
3
|
+
sectorVertexSize;
|
|
4
|
+
_buffers = [];
|
|
5
|
+
constructor(vertexFloatSize, sectorVertexSize, startingSectorSize = 4) {
|
|
6
|
+
this.vertexFloatSize = vertexFloatSize;
|
|
7
|
+
this.sectorVertexSize = sectorVertexSize;
|
|
8
|
+
const sectorSize = vertexFloatSize * sectorVertexSize;
|
|
9
|
+
for (let i = 0; i < startingSectorSize; i++) {
|
|
10
|
+
this._buffers.push(new Float32Array(sectorSize));
|
|
11
|
+
}
|
|
12
|
+
const array = this;
|
|
13
|
+
return new Proxy([], {
|
|
14
|
+
get: (target, property) => {
|
|
15
|
+
if (property == "length")
|
|
16
|
+
return array.length;
|
|
17
|
+
if (property == "_buffers")
|
|
18
|
+
return array._buffers;
|
|
19
|
+
const index = +property;
|
|
20
|
+
const bufferIndex = Math.floor(index / sectorSize);
|
|
21
|
+
if (!array._buffers[bufferIndex])
|
|
22
|
+
this._buffers[bufferIndex] = new Float32Array(sectorSize);
|
|
23
|
+
const arrayIndex = index - bufferIndex * sectorSize;
|
|
24
|
+
return array._buffers[bufferIndex][arrayIndex];
|
|
25
|
+
},
|
|
26
|
+
set: (target, property, value) => {
|
|
27
|
+
if (property == "length")
|
|
28
|
+
return false;
|
|
29
|
+
const index = +property;
|
|
30
|
+
const bufferIndex = Math.floor(index / sectorSize);
|
|
31
|
+
if (!array._buffers[bufferIndex])
|
|
32
|
+
array._buffers[bufferIndex] = new Float32Array(sectorSize);
|
|
33
|
+
const arrayIndex = index - bufferIndex * sectorSize;
|
|
34
|
+
array._buffers[bufferIndex][arrayIndex] = value;
|
|
35
|
+
return true;
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
get length() {
|
|
40
|
+
return this._buffers.length * this.vertexFloatSize;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
export class VoxelIndiceBuffer {
|
|
44
|
+
sectorSize;
|
|
45
|
+
_buffers = [];
|
|
46
|
+
constructor(sectorSize, startingSectorSize = 4) {
|
|
47
|
+
this.sectorSize = sectorSize;
|
|
48
|
+
for (let i = 0; i < startingSectorSize; i++) {
|
|
49
|
+
this._buffers.push(new Uint32Array(sectorSize));
|
|
50
|
+
}
|
|
51
|
+
const array = this;
|
|
52
|
+
return new Proxy([], {
|
|
53
|
+
get: (target, property) => {
|
|
54
|
+
if (property == "length")
|
|
55
|
+
return array.length;
|
|
56
|
+
if (property == "_buffers")
|
|
57
|
+
return array._buffers;
|
|
58
|
+
const index = +property;
|
|
59
|
+
const bufferIndex = Math.floor(index / sectorSize);
|
|
60
|
+
if (!array._buffers[bufferIndex])
|
|
61
|
+
this._buffers[bufferIndex] = new Uint32Array(sectorSize);
|
|
62
|
+
const arrayIndex = index - bufferIndex * sectorSize;
|
|
63
|
+
return array._buffers[bufferIndex][arrayIndex];
|
|
64
|
+
},
|
|
65
|
+
set: (target, property, value) => {
|
|
66
|
+
if (property == "length")
|
|
67
|
+
return false;
|
|
68
|
+
const index = +property;
|
|
69
|
+
const bufferIndex = Math.floor(index / sectorSize);
|
|
70
|
+
if (!array._buffers[bufferIndex])
|
|
71
|
+
array._buffers[bufferIndex] = new Uint32Array(sectorSize);
|
|
72
|
+
const arrayIndex = index - bufferIndex * sectorSize;
|
|
73
|
+
array._buffers[bufferIndex][arrayIndex] = value;
|
|
74
|
+
return true;
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
get length() {
|
|
79
|
+
return this._buffers.length * this.sectorSize;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { VoxelMesh } from "../VoxelMesh.js";
|
|
2
2
|
export declare class MesherDataTool {
|
|
3
3
|
segments: Map<string, number[]>;
|
|
4
|
-
mesh:
|
|
5
|
-
startNewMesh(mesh?:
|
|
4
|
+
mesh: VoxelMesh | null;
|
|
5
|
+
startNewMesh(mesh?: VoxelMesh): void;
|
|
6
6
|
resetAll(): this;
|
|
7
7
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { VoxelMesh } from "../VoxelMesh.js";
|
|
2
2
|
export class MesherDataTool {
|
|
3
3
|
segments = new Map();
|
|
4
4
|
mesh = null;
|
|
5
5
|
startNewMesh(mesh) {
|
|
6
|
-
this.mesh = mesh ? mesh : new
|
|
6
|
+
this.mesh = mesh ? mesh : new VoxelMesh();
|
|
7
7
|
}
|
|
8
8
|
resetAll() {
|
|
9
9
|
this.mesh?.clear();
|
|
@@ -97,12 +97,12 @@ export class VoxelGeometryBuilder {
|
|
|
97
97
|
const bottomLeftNor = quad.normals.vertices[2];
|
|
98
98
|
const bottomRightNor = quad.normals.vertices[3];
|
|
99
99
|
const indices = tool.mesh.indices;
|
|
100
|
-
let indIndex =
|
|
100
|
+
let indIndex = tool.mesh.indicieCount;
|
|
101
101
|
let sides = quad.doubleSided ? 2 : 1;
|
|
102
102
|
const flip = quad.flip;
|
|
103
103
|
let orientation = quad.orientation;
|
|
104
104
|
while (sides--) {
|
|
105
|
-
const baseIndex = tool.mesh.
|
|
105
|
+
const baseIndex = tool.mesh.vertexCount;
|
|
106
106
|
if (!flip) {
|
|
107
107
|
//1
|
|
108
108
|
structCursor.index = baseIndex;
|
|
@@ -235,7 +235,7 @@ export class VoxelGeometryBuilder {
|
|
|
235
235
|
indices[indIndex++] = baseIndex + 3;
|
|
236
236
|
indices[indIndex++] = baseIndex;
|
|
237
237
|
}
|
|
238
|
-
tool.mesh.
|
|
238
|
+
tool.mesh.addVerticies(4, 6);
|
|
239
239
|
}
|
|
240
240
|
structCursor.data = empty;
|
|
241
241
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Vector3Like } from "@amodx/math";
|
|
2
|
+
import { VoxelVertexBuffer, VoxelIndiceBuffer } from "./Buffers";
|
|
3
|
+
export declare class VoxelMesh {
|
|
4
|
+
indicieIndex: number;
|
|
5
|
+
indicieCount: number;
|
|
6
|
+
vertexCount: number;
|
|
7
|
+
minBounds: Vector3Like;
|
|
8
|
+
maxBounds: Vector3Like;
|
|
9
|
+
readonly buffer: VoxelVertexBuffer;
|
|
10
|
+
readonly indices: VoxelIndiceBuffer;
|
|
11
|
+
addVerticies(count: number, indicesCount: number): void;
|
|
12
|
+
clear(): void;
|
|
13
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Vector3Like } from "@amodx/math";
|
|
2
|
+
import { VoxelVertexBuffer, VoxelIndiceBuffer } from "./Buffers";
|
|
3
|
+
import { VoxelMeshVertexStructCursor } from "../Tools/VoxelMeshVertexStructCursor";
|
|
4
|
+
export class VoxelMesh {
|
|
5
|
+
indicieIndex = 0;
|
|
6
|
+
indicieCount = 0;
|
|
7
|
+
vertexCount = 0;
|
|
8
|
+
minBounds = Vector3Like.Create(Infinity, Infinity, Infinity);
|
|
9
|
+
maxBounds = Vector3Like.Create(-Infinity, -Infinity, -Infinity);
|
|
10
|
+
buffer = new VoxelVertexBuffer(VoxelMeshVertexStructCursor.VertexFloatSize, 1000);
|
|
11
|
+
indices = new VoxelIndiceBuffer(1000);
|
|
12
|
+
addVerticies(count, indicesCount) {
|
|
13
|
+
this.vertexCount += count;
|
|
14
|
+
this.indicieCount += indicesCount;
|
|
15
|
+
}
|
|
16
|
+
clear() {
|
|
17
|
+
// this.buffer.length = 0;
|
|
18
|
+
//this.indices.length = 0;
|
|
19
|
+
this.indicieCount = 0;
|
|
20
|
+
this.vertexCount = 0;
|
|
21
|
+
this.minBounds.x = Infinity;
|
|
22
|
+
this.minBounds.y = Infinity;
|
|
23
|
+
this.minBounds.z = Infinity;
|
|
24
|
+
this.maxBounds.x = -Infinity;
|
|
25
|
+
this.maxBounds.y = -Infinity;
|
|
26
|
+
this.maxBounds.z = -Infinity;
|
|
27
|
+
}
|
|
28
|
+
}
|
package/Mesher/InitTask.js
CHANGED
|
@@ -11,9 +11,8 @@ export default function (rendererThread) {
|
|
|
11
11
|
rendererThread.runTask("set-section", section[0], section[1]);
|
|
12
12
|
});
|
|
13
13
|
Threads.registerTask(TasksIds.BuildSector, (location) => {
|
|
14
|
-
WorldRegister.setDimension(location[0]);
|
|
15
14
|
const sectorPosition = WorldSpaces.sector.getPosition(location[1], location[2], location[3]);
|
|
16
|
-
const sector = WorldRegister.sectors.get(sectorPosition.x, sectorPosition.y, sectorPosition.z);
|
|
15
|
+
const sector = WorldRegister.sectors.get(location[0], sectorPosition.x, sectorPosition.y, sectorPosition.z);
|
|
17
16
|
if (!sector) {
|
|
18
17
|
console.warn("Tried building a sector that does not exists.", [
|
|
19
18
|
sectorPosition.x,
|
|
@@ -33,8 +33,8 @@ export class BoxVoxelGometryNode extends GeoemtryNode {
|
|
|
33
33
|
const currentIndex = faceIndexes[positionIndex];
|
|
34
34
|
const p = VoxelRelativeCubeIndexPositionMap[currentIndex];
|
|
35
35
|
const hashed = VoxelGeometryLookUp.getHash(tool.nVoxel, tool.position.x + p[0], tool.position.y + p[1], tool.position.z + p[2]);
|
|
36
|
-
const offsetBaseGometry = VoxelGeometryLookUp.
|
|
37
|
-
const offsetConditonalGeometry = VoxelGeometryLookUp.
|
|
36
|
+
const offsetBaseGometry = VoxelGeometryLookUp.space.getGeomtry(hashed);
|
|
37
|
+
const offsetConditonalGeometry = VoxelGeometryLookUp.space.getConditionalGeomtry(hashed);
|
|
38
38
|
if (offsetBaseGometry) {
|
|
39
39
|
for (let i = 0; i < offsetBaseGometry.length; i++) {
|
|
40
40
|
const geoId = offsetBaseGometry[i];
|
|
@@ -42,7 +42,7 @@ export class BoxVoxelGometryNode extends GeoemtryNode {
|
|
|
42
42
|
continue;
|
|
43
43
|
const faceIndex = this.geomtry.cullIndex.getValue(geoId, currentIndex, trueFaceIndex);
|
|
44
44
|
if (faceIndex > -1 &&
|
|
45
|
-
!VoxelGeometryLookUp.
|
|
45
|
+
!VoxelGeometryLookUp.space.getConstructor(hashed)?.isShapeStateFaceTransparent(VoxelGeometryLookUp.space.modCache[hashed], VoxelGeometryLookUp.space.stateCache[hashed], geoId, faceIndex)) {
|
|
46
46
|
return false;
|
|
47
47
|
}
|
|
48
48
|
}
|
|
@@ -57,7 +57,7 @@ export class BoxVoxelGometryNode extends GeoemtryNode {
|
|
|
57
57
|
continue;
|
|
58
58
|
const faceIndex = this.geomtry.cullIndex.getValue(geoId, currentIndex, trueFaceIndex);
|
|
59
59
|
if (faceIndex > -1 &&
|
|
60
|
-
!VoxelGeometryLookUp.
|
|
60
|
+
!VoxelGeometryLookUp.space.getConstructor(hashed)?.isCondtionalStateFaceTransparent(VoxelGeometryLookUp.space.modCache[hashed], VoxelGeometryLookUp.space.stateCache[hashed], geoId, faceIndex))
|
|
61
61
|
return false;
|
|
62
62
|
}
|
|
63
63
|
}
|
|
@@ -83,10 +83,10 @@ export class BoxVoxelGometryNode extends GeoemtryNode {
|
|
|
83
83
|
const currentIndex = aoIndexes[positionIndex];
|
|
84
84
|
const p = VoxelRelativeCubeIndexPositionMap[currentIndex];
|
|
85
85
|
const hashed = VoxelGeometryLookUp.getHash(tool.nVoxel, tool.position.x + p[0], tool.position.y + p[1], tool.position.z + p[2]);
|
|
86
|
-
if (VoxelGeometryLookUp.noCastAO[hashed] ===
|
|
86
|
+
if (VoxelGeometryLookUp.space.noCastAO[hashed] === 1)
|
|
87
87
|
continue;
|
|
88
|
-
const baseGeo = VoxelGeometryLookUp.
|
|
89
|
-
const conditonalGeo = VoxelGeometryLookUp.
|
|
88
|
+
const baseGeo = VoxelGeometryLookUp.space.getGeomtry(hashed);
|
|
89
|
+
const conditonalGeo = VoxelGeometryLookUp.space.getConditionalGeomtry(hashed);
|
|
90
90
|
if (!baseGeo && !conditonalGeo)
|
|
91
91
|
continue;
|
|
92
92
|
let length = 0;
|
|
@@ -39,13 +39,13 @@ export class QuadVoxelGometryNode extends GeoemtryNode {
|
|
|
39
39
|
const currentIndex = faceIndexes[positionIndex];
|
|
40
40
|
const p = VoxelRelativeCubeIndexPositionMap[currentIndex];
|
|
41
41
|
const hashed = VoxelGeometryLookUp.getHash(tool.nVoxel, tool.position.x + p[0], tool.position.y + p[1], tool.position.z + p[2]);
|
|
42
|
-
const offsetBaseGometry = VoxelGeometryLookUp.
|
|
43
|
-
const offsetConditonalGeometry = VoxelGeometryLookUp.
|
|
42
|
+
const offsetBaseGometry = VoxelGeometryLookUp.space.getGeomtry(hashed);
|
|
43
|
+
const offsetConditonalGeometry = VoxelGeometryLookUp.space.getConditionalGeomtry(hashed);
|
|
44
44
|
if (offsetBaseGometry) {
|
|
45
45
|
for (let i = 0; i < offsetBaseGometry.length; i++) {
|
|
46
46
|
const faceIndex = this.geomtry.cullIndex.getValue(offsetBaseGometry[i], currentIndex, trueFaceIndex);
|
|
47
47
|
if (faceIndex > -1 &&
|
|
48
|
-
!VoxelGeometryLookUp.
|
|
48
|
+
!VoxelGeometryLookUp.space.getConstructor(hashed)?.isShapeStateFaceTransparent(VoxelGeometryLookUp.space.modCache[hashed], VoxelGeometryLookUp.space.stateCache[hashed], offsetBaseGometry[i], faceIndex)) {
|
|
49
49
|
return false;
|
|
50
50
|
}
|
|
51
51
|
}
|
|
@@ -57,7 +57,7 @@ export class QuadVoxelGometryNode extends GeoemtryNode {
|
|
|
57
57
|
for (let k = 0; k < cond.length; k++) {
|
|
58
58
|
const faceIndex = this.geomtry.cullIndex.getValue(cond[k], currentIndex, trueFaceIndex);
|
|
59
59
|
if (faceIndex > -1 &&
|
|
60
|
-
!VoxelGeometryLookUp.
|
|
60
|
+
!VoxelGeometryLookUp.space.getConstructor(hashed)?.isCondtionalStateFaceTransparent(VoxelGeometryLookUp.space.modCache[hashed], VoxelGeometryLookUp.space.stateCache[hashed], cond[i], faceIndex))
|
|
61
61
|
return false;
|
|
62
62
|
}
|
|
63
63
|
}
|
|
@@ -83,10 +83,10 @@ export class QuadVoxelGometryNode extends GeoemtryNode {
|
|
|
83
83
|
const currentIndex = aoIndexes[positionIndex];
|
|
84
84
|
const p = VoxelRelativeCubeIndexPositionMap[currentIndex];
|
|
85
85
|
const hashed = VoxelGeometryLookUp.getHash(tool.nVoxel, tool.position.x + p[0], tool.position.y + p[1], tool.position.z + p[2]);
|
|
86
|
-
if (VoxelGeometryLookUp.noCastAO[hashed] ===
|
|
86
|
+
if (VoxelGeometryLookUp.space.noCastAO[hashed] === 1)
|
|
87
87
|
continue;
|
|
88
|
-
const baseGeo = VoxelGeometryLookUp.
|
|
89
|
-
const conditonalGeo = VoxelGeometryLookUp.
|
|
88
|
+
const baseGeo = VoxelGeometryLookUp.space.getGeomtry(hashed);
|
|
89
|
+
const conditonalGeo = VoxelGeometryLookUp.space.getConditionalGeomtry(hashed);
|
|
90
90
|
if (!baseGeo && !conditonalGeo)
|
|
91
91
|
continue;
|
|
92
92
|
let length = 0;
|
|
@@ -46,8 +46,8 @@ export class VoxelConstructor {
|
|
|
46
46
|
}
|
|
47
47
|
process(tool) {
|
|
48
48
|
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];
|
|
49
|
+
const treeState = VoxelGeometryLookUp.space.stateCache[hashed];
|
|
50
|
+
const modState = VoxelGeometryLookUp.space.modCache[hashed];
|
|
51
51
|
if (treeState !== undefined && treeState > -1) {
|
|
52
52
|
const geoLinks = this.data.shapeStateMap[treeState];
|
|
53
53
|
const geometries = this.data.shapeStateGeometryMap[treeState];
|
|
@@ -63,7 +63,7 @@ export class VoxelConstructor {
|
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
|
-
const conditonalTreeState = VoxelGeometryLookUp.conditonalStateCache[hashed];
|
|
66
|
+
const conditonalTreeState = VoxelGeometryLookUp.space.conditonalStateCache[hashed];
|
|
67
67
|
if (conditonalTreeState !== undefined && conditonalTreeState > -1) {
|
|
68
68
|
const condiotnalNodes = this.data.condiotnalShapeStateMap[conditonalTreeState];
|
|
69
69
|
const condiotnalNodesLength = condiotnalNodes.length;
|
|
@@ -1,19 +1,28 @@
|
|
|
1
1
|
import { DataCursorInterface } from "../../Data/Cursor/DataCursor.interface";
|
|
2
|
-
import {
|
|
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
|
|
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(
|
|
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;
|