@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.
- 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.d.ts +5 -5
- package/Contexts/Render/DivineVoxelEngineRender.js +1 -1
- package/Contexts/World/DivineVoxelEngineWorld.d.ts +5 -5
- package/Init/StartRenderer.js +5 -5
- package/Math/Indexing.js +6 -6
- package/Mesher/Functions/CompactVoxelMesh.js +40 -7
- package/Mesher/Functions/MeshSection.js +16 -9
- package/Mesher/Functions/MeshTexture.d.ts +1 -1
- package/Mesher/Functions/MeshVoxel.js +5 -4
- 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 +12 -0
- package/Mesher/Geomtry/VoxelMesh.js +25 -0
- package/Mesher/InitTask.js +1 -2
- package/Mesher/Models/Common/BoxGeometryNode.js +2 -1
- package/Mesher/Models/Nodes/Ruled/BoxVoxelGeometryNode.js +10 -7
- package/Mesher/Models/Nodes/Ruled/QuadVoxelGeometryNode.js +7 -7
- package/Mesher/Models/Nodes/VoxelGeometryConstructor.js +1 -1
- package/Mesher/Models/VoxelConstructor.d.ts +0 -2
- package/Mesher/Models/VoxelConstructor.js +9 -15
- package/Mesher/Models/VoxelGeometryLookUp.d.ts +20 -11
- package/Mesher/Models/VoxelGeometryLookUp.js +84 -50
- package/Mesher/Tools/VoxelMeshBVHBuilder.js +20 -25
- package/Mesher/Tools/VoxelMeshVertexStructCursor.d.ts +3 -1
- package/Mesher/Tools/VoxelMesherDataTool.d.ts +3 -2
- package/Mesher/Tools/VoxelMesherDataTool.js +8 -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 +16 -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/Settings/EngineSettings.d.ts +5 -5
- package/Settings/EngineSettings.js +15 -15
- package/Settings/EngineSettings.types.d.ts +62 -44
- package/Settings/EngineSettings.types.js +44 -42
- package/Tasks/IWG/IWG.d.ts +3 -0
- package/Tasks/IWG/IWG.js +3 -0
- 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/Explosion/ExplosionManager.js +1 -1
- package/Tasks/Propagation/Flow/WorldFlow.js +6 -8
- package/Tasks/Propagation/Illumanation/RGBUpdate.js +2 -2
- package/Tasks/Propagation/Illumanation/WorldRGB.js +2 -3
- package/Tasks/Propagation/Illumanation/WorldSun.js +11 -5
- package/Tasks/Update/VoxelUpdate.js +21 -26
- package/Tasks/WorldGeneration/WorldGenRegister.js +5 -8
- package/Tasks/WorldGeneration/WorldGeneration.d.ts +0 -2
- package/Tasks/WorldGeneration/WorldGeneration.js +0 -2
- package/Templates/Cursor/TemplateVoxelCursor.d.ts +1 -0
- package/Templates/Cursor/TemplateVoxelCursor.js +1 -0
- package/Textures/TextureBuilder.d.ts +1 -1
- package/Textures/TextureBuilder.js +1 -1
- package/Textures/TextureManager.js +1 -1
- package/Tools/Brush/Brush.d.ts +1 -0
- package/Tools/Brush/Brush.js +8 -11
- package/Voxels/Cursor/VoxelCursor.d.ts +1 -0
- package/Voxels/Cursor/VoxelCursor.interface.d.ts +5 -0
- package/Voxels/Cursor/VoxelCursor.interface.js +5 -5
- package/Voxels/Cursor/VoxelCursor.js +5 -3
- package/Voxels/VoxelLevelReader.d.ts +10 -0
- package/Voxels/VoxelLevelReader.js +20 -0
- 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.d.ts +1 -0
- package/World/Cursor/SectorCursor.js +8 -3
- package/World/Cursor/WorldCursor.js +1 -2
- package/World/Cursor/WorldVoxelCursor.d.ts +1 -5
- package/World/Cursor/WorldVoxelCursor.js +1 -5
- 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/Voxels/VoxelStateReader.d.ts +0 -12
- package/Voxels/VoxelStateReader.js +0 -30
- 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
|
}
|
|
@@ -19,14 +19,14 @@ export declare class DivineVoxelEngineRender {
|
|
|
19
19
|
settings: {
|
|
20
20
|
enviorment: "node" | "browser";
|
|
21
21
|
settings: EngineSettingsData;
|
|
22
|
+
readonly doSunPropagation: boolean;
|
|
23
|
+
readonly doRGBPropagation: boolean;
|
|
24
|
+
readonly doLight: boolean;
|
|
25
|
+
readonly doFlow: boolean;
|
|
26
|
+
readonly isClient: boolean;
|
|
22
27
|
getSettings(): EngineSettingsData;
|
|
23
28
|
syncSettings(data: EngineSettingsData): void;
|
|
24
29
|
getSettingsCopy(): any;
|
|
25
|
-
doSunPropagation(): boolean;
|
|
26
|
-
doRGBPropagation(): boolean;
|
|
27
|
-
doLight(): boolean;
|
|
28
|
-
doFlow(): boolean;
|
|
29
|
-
isClient(): boolean;
|
|
30
30
|
addEventListener<K extends "synced">(type: K, listener: EventListenerObject | ((event: CustomEvent<{
|
|
31
31
|
synced: {
|
|
32
32
|
settings: any;
|
|
@@ -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
|
}
|
|
@@ -11,14 +11,14 @@ export declare class DivineVoxelEngineWorld {
|
|
|
11
11
|
settings: {
|
|
12
12
|
enviorment: "node" | "browser";
|
|
13
13
|
settings: import("../../Settings/EngineSettings.types.js").EngineSettingsData;
|
|
14
|
+
readonly doSunPropagation: boolean;
|
|
15
|
+
readonly doRGBPropagation: boolean;
|
|
16
|
+
readonly doLight: boolean;
|
|
17
|
+
readonly doFlow: boolean;
|
|
18
|
+
readonly isClient: boolean;
|
|
14
19
|
getSettings(): import("../../Settings/EngineSettings.types.js").EngineSettingsData;
|
|
15
20
|
syncSettings(data: import("../../Settings/EngineSettings.types.js").EngineSettingsData): void;
|
|
16
21
|
getSettingsCopy(): any;
|
|
17
|
-
doSunPropagation(): boolean;
|
|
18
|
-
doRGBPropagation(): boolean;
|
|
19
|
-
doLight(): boolean;
|
|
20
|
-
doFlow(): boolean;
|
|
21
|
-
isClient(): boolean;
|
|
22
22
|
addEventListener<K extends "synced">(type: K, listener: EventListenerObject | ((event: CustomEvent<{
|
|
23
23
|
synced: {
|
|
24
24
|
settings: any;
|
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,10 +68,14 @@ 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 - 1), cy - (padding.y - 1), cz - (padding.z - 1));
|
|
72
|
+
VoxelGeometryLookUp.start(space);
|
|
70
73
|
bvhTool.reset();
|
|
74
|
+
const effects = {};
|
|
71
75
|
for (let i = 0; i < RenderedMaterials.meshers.length; i++) {
|
|
72
|
-
RenderedMaterials.meshers[i]
|
|
76
|
+
const mesher = RenderedMaterials.meshers[i];
|
|
77
|
+
mesher.bvhTool = bvhTool;
|
|
78
|
+
mesher.effects = effects;
|
|
73
79
|
}
|
|
74
80
|
for (let y = minY; y <= maxY; y++) {
|
|
75
81
|
let foundVoxels = false;
|
|
@@ -86,7 +92,6 @@ export function MeshSection(location) {
|
|
|
86
92
|
SectionHeightMap.setDirty(y, false);
|
|
87
93
|
}
|
|
88
94
|
VoxelGeometryLookUp.stop();
|
|
89
|
-
const compactStart = performance.now();
|
|
90
95
|
const transfers = [];
|
|
91
96
|
const sectionEffects = [];
|
|
92
97
|
const sections = [location, [], sectionEffects, 0];
|
|
@@ -98,8 +103,9 @@ export function MeshSection(location) {
|
|
|
98
103
|
transfers.push(float.buffer);
|
|
99
104
|
sectionEffects.push([e, float]);
|
|
100
105
|
}
|
|
101
|
-
if (!mesher.mesh.
|
|
106
|
+
if (!mesher.mesh.vertexCount) {
|
|
102
107
|
mesher.resetAll();
|
|
108
|
+
mesher.bvhTool = null;
|
|
103
109
|
continue;
|
|
104
110
|
}
|
|
105
111
|
meshed.push(mesher);
|
|
@@ -108,6 +114,7 @@ export function MeshSection(location) {
|
|
|
108
114
|
sections[1] = compactMesh;
|
|
109
115
|
for (let i = 0; i < meshed.length; i++) {
|
|
110
116
|
meshed[i].resetAll();
|
|
117
|
+
meshed[i].bvhTool = null;
|
|
111
118
|
}
|
|
112
119
|
return [sections, [...transfers, ...buffers]];
|
|
113
120
|
}
|
|
@@ -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;
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { RenderedMaterials } from "../RenderedMaterials";
|
|
2
2
|
import { VoxelGeometryLookUp } from "../Models/VoxelGeometryLookUp.js";
|
|
3
3
|
import { TemplateCursor } from "../../Templates/Cursor/TemplateCursor.js";
|
|
4
|
-
import { VoxelCursor } from "../../Voxels/Cursor/VoxelCursor.js";
|
|
5
4
|
import { FullVoxelTemplate } from "../../Templates/FullVoxelTemplate.js";
|
|
6
5
|
import { CompactVoxelMesh } from "../Functions/CompactVoxelMesh.js";
|
|
7
6
|
import { VoxelModelConstructorRegister } from "../Models/VoxelModelConstructorRegister.js";
|
|
8
7
|
const templateCursor = new TemplateCursor();
|
|
9
|
-
const voxelCursor = new VoxelCursor();
|
|
10
8
|
templateCursor.setTemplate(new FullVoxelTemplate(FullVoxelTemplate.CreateNew([3, 3, 3], 0xf)));
|
|
9
|
+
const space = VoxelGeometryLookUp.createSpace(3, 3, 3);
|
|
11
10
|
export function MeshVoxel(rawVoxelData) {
|
|
12
11
|
const voxel = templateCursor.getVoxel(1, 1, 1);
|
|
13
12
|
voxel.copyRaw(rawVoxelData);
|
|
@@ -24,14 +23,16 @@ export function MeshVoxel(rawVoxelData) {
|
|
|
24
23
|
}
|
|
25
24
|
mesher.bvhTool = null;
|
|
26
25
|
mesher.resetAll();
|
|
27
|
-
|
|
26
|
+
space.start(0, 0, 0);
|
|
27
|
+
VoxelGeometryLookUp.start(space);
|
|
28
|
+
mesher.effects = {};
|
|
28
29
|
mesher.origin.x = -0.5;
|
|
29
30
|
mesher.origin.y = -0.5;
|
|
30
31
|
mesher.origin.z = -0.5;
|
|
31
32
|
mesher.position.x = 1;
|
|
32
33
|
mesher.position.y = 1;
|
|
33
34
|
mesher.position.z = 1;
|
|
34
|
-
mesher.voxel =
|
|
35
|
+
mesher.voxel = voxel;
|
|
35
36
|
mesher.nVoxel = templateCursor;
|
|
36
37
|
constructor.process(mesher);
|
|
37
38
|
mesher.reset();
|
|
@@ -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,12 @@
|
|
|
1
|
+
import { Vector3Like } from "@amodx/math";
|
|
2
|
+
import { VoxelVertexBuffer, VoxelIndiceBuffer } from "./Buffers";
|
|
3
|
+
export declare class VoxelMesh {
|
|
4
|
+
indicieCount: number;
|
|
5
|
+
vertexCount: number;
|
|
6
|
+
minBounds: Vector3Like;
|
|
7
|
+
maxBounds: Vector3Like;
|
|
8
|
+
readonly buffer: VoxelVertexBuffer;
|
|
9
|
+
readonly indices: VoxelIndiceBuffer;
|
|
10
|
+
addVerticies(vertexCount: number, indicesCount: number): void;
|
|
11
|
+
clear(): void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Vector3Like } from "@amodx/math";
|
|
2
|
+
import { VoxelVertexBuffer, VoxelIndiceBuffer } from "./Buffers";
|
|
3
|
+
import { VoxelMeshVertexStructCursor } from "../Tools/VoxelMeshVertexStructCursor";
|
|
4
|
+
export class VoxelMesh {
|
|
5
|
+
indicieCount = 0;
|
|
6
|
+
vertexCount = 0;
|
|
7
|
+
minBounds = Vector3Like.Create(Infinity, Infinity, Infinity);
|
|
8
|
+
maxBounds = Vector3Like.Create(-Infinity, -Infinity, -Infinity);
|
|
9
|
+
buffer = new VoxelVertexBuffer(VoxelMeshVertexStructCursor.VertexFloatSize, 1000);
|
|
10
|
+
indices = new VoxelIndiceBuffer(1000);
|
|
11
|
+
addVerticies(vertexCount, indicesCount) {
|
|
12
|
+
this.vertexCount += vertexCount;
|
|
13
|
+
this.indicieCount += indicesCount;
|
|
14
|
+
}
|
|
15
|
+
clear() {
|
|
16
|
+
this.indicieCount = 0;
|
|
17
|
+
this.vertexCount = 0;
|
|
18
|
+
this.minBounds.x = Infinity;
|
|
19
|
+
this.minBounds.y = Infinity;
|
|
20
|
+
this.minBounds.z = Infinity;
|
|
21
|
+
this.maxBounds.x = -Infinity;
|
|
22
|
+
this.maxBounds.y = -Infinity;
|
|
23
|
+
this.maxBounds.z = -Infinity;
|
|
24
|
+
}
|
|
25
|
+
}
|
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,
|
|
@@ -2,6 +2,7 @@ import { Vector3Like } from "@amodx/math";
|
|
|
2
2
|
import { VoxelFaces } from "../../../Math";
|
|
3
3
|
import { Quad } from "../../Geomtry/Primitives/Quad";
|
|
4
4
|
import { addQuadWeights } from "./Calc/CalcConstants";
|
|
5
|
+
import { TransformBox } from "../../../Models/Shared/Transform";
|
|
5
6
|
import { GetBounds } from "./BoundsFunctions";
|
|
6
7
|
export function GetBoxGeometryNodeData(points, transform) {
|
|
7
8
|
// const quads: Quad[] = [];
|
|
@@ -51,7 +52,7 @@ export function GetBoxGeometryNodeData(points, transform) {
|
|
|
51
52
|
[start.x, start.y, end.z],
|
|
52
53
|
[start.x, start.y, start.z],
|
|
53
54
|
]);
|
|
54
|
-
|
|
55
|
+
TransformBox(quads, transform);
|
|
55
56
|
const quadBounds = new Array(quads.length);
|
|
56
57
|
for (let i = 0; i < quads.length; i++) {
|
|
57
58
|
const positions = [];
|
|
@@ -33,8 +33,10 @@ 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
|
-
|
|
37
|
-
|
|
36
|
+
if (VoxelGeometryLookUp.space.foundHash[hashed] < 2)
|
|
37
|
+
continue;
|
|
38
|
+
const offsetBaseGometry = VoxelGeometryLookUp.space.getGeomtry(hashed);
|
|
39
|
+
const offsetConditonalGeometry = VoxelGeometryLookUp.space.getConditionalGeomtry(hashed);
|
|
38
40
|
if (offsetBaseGometry) {
|
|
39
41
|
for (let i = 0; i < offsetBaseGometry.length; i++) {
|
|
40
42
|
const geoId = offsetBaseGometry[i];
|
|
@@ -42,7 +44,7 @@ export class BoxVoxelGometryNode extends GeoemtryNode {
|
|
|
42
44
|
continue;
|
|
43
45
|
const faceIndex = this.geomtry.cullIndex.getValue(geoId, currentIndex, trueFaceIndex);
|
|
44
46
|
if (faceIndex > -1 &&
|
|
45
|
-
!VoxelGeometryLookUp.
|
|
47
|
+
!VoxelGeometryLookUp.space.getConstructor(hashed)?.isShapeStateFaceTransparent(VoxelGeometryLookUp.space.modCache[hashed], VoxelGeometryLookUp.space.stateCache[hashed], geoId, faceIndex)) {
|
|
46
48
|
return false;
|
|
47
49
|
}
|
|
48
50
|
}
|
|
@@ -57,7 +59,7 @@ export class BoxVoxelGometryNode extends GeoemtryNode {
|
|
|
57
59
|
continue;
|
|
58
60
|
const faceIndex = this.geomtry.cullIndex.getValue(geoId, currentIndex, trueFaceIndex);
|
|
59
61
|
if (faceIndex > -1 &&
|
|
60
|
-
!VoxelGeometryLookUp.
|
|
62
|
+
!VoxelGeometryLookUp.space.getConstructor(hashed)?.isCondtionalStateFaceTransparent(VoxelGeometryLookUp.space.modCache[hashed], VoxelGeometryLookUp.space.stateCache[hashed], geoId, faceIndex))
|
|
61
63
|
return false;
|
|
62
64
|
}
|
|
63
65
|
}
|
|
@@ -83,10 +85,11 @@ export class BoxVoxelGometryNode extends GeoemtryNode {
|
|
|
83
85
|
const currentIndex = aoIndexes[positionIndex];
|
|
84
86
|
const p = VoxelRelativeCubeIndexPositionMap[currentIndex];
|
|
85
87
|
const hashed = VoxelGeometryLookUp.getHash(tool.nVoxel, tool.position.x + p[0], tool.position.y + p[1], tool.position.z + p[2]);
|
|
86
|
-
if (VoxelGeometryLookUp.
|
|
88
|
+
if (VoxelGeometryLookUp.space.foundHash[hashed] < 2 ||
|
|
89
|
+
VoxelGeometryLookUp.space.noCastAO[hashed] === 1)
|
|
87
90
|
continue;
|
|
88
|
-
const baseGeo = VoxelGeometryLookUp.
|
|
89
|
-
const conditonalGeo = VoxelGeometryLookUp.
|
|
91
|
+
const baseGeo = VoxelGeometryLookUp.space.getGeomtry(hashed);
|
|
92
|
+
const conditonalGeo = VoxelGeometryLookUp.space.getConditionalGeomtry(hashed);
|
|
90
93
|
if (!baseGeo && !conditonalGeo)
|
|
91
94
|
continue;
|
|
92
95
|
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;
|