@divinevoxel/vlox 0.0.72 → 0.0.73
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/Render/DivineVoxelEngineRender.d.ts +1 -1
- package/Contexts/World/DivineVoxelEngineWorld.d.ts +1 -1
- package/Init/StartConstructor.js +6 -4
- package/Init/StartWorld.d.ts +1 -1
- package/Mesher/Functions/CompactVoxelMesh.d.ts +2 -2
- package/Mesher/Functions/CompactVoxelMesh.js +1 -1
- package/Mesher/Functions/MeshSection.js +20 -8
- package/Mesher/Functions/MeshTexture.d.ts +1 -1
- package/Mesher/Functions/MeshTexture.js +3 -4
- package/Mesher/Geomtry/Primitives/QuadVertexData.d.ts +12 -10
- package/Mesher/Geomtry/Primitives/QuadVertexData.js +49 -56
- package/Mesher/Geomtry/VoxelGeometryBuilder.d.ts +2 -2
- package/Mesher/Geomtry/VoxelGeometryBuilder.js +2 -2
- package/Mesher/Geomtry/VoxelMesh.d.ts +1 -1
- package/Mesher/Geomtry/VoxelMesh.js +2 -2
- package/Mesher/Geomtry/index.d.ts +0 -1
- package/Mesher/Geomtry/index.js +0 -1
- package/Mesher/InitMesher.js +1 -1
- package/Mesher/InitTask.js +4 -22
- package/Mesher/Models/Common/Calc/FaceDataCalc.d.ts +2 -2
- package/Mesher/Models/Common/Calc/FaceDataCalc.js +37 -30
- package/Mesher/Models/Nodes/Custom/Liquid/FlowGradient.d.ts +2 -2
- package/Mesher/Models/Nodes/Custom/Liquid/FlowGradient.js +1 -1
- package/Mesher/Models/Nodes/Custom/Liquid/LiquidGeomtryNode.js +11 -17
- package/Mesher/Models/Nodes/GeometryNode.d.ts +2 -2
- package/Mesher/Models/Nodes/Ruled/BoxVoxelGeometryNode.d.ts +1 -0
- package/Mesher/Models/Nodes/Ruled/BoxVoxelGeometryNode.js +24 -12
- package/Mesher/{Tools → Models/Protocols}/OutlinedVoxelTool.d.ts +1 -1
- package/Mesher/{Tools → Models/Protocols}/OutlinedVoxelTool.js +1 -1
- package/Mesher/Models/RenderedMaterials.d.ts +6 -0
- package/Mesher/{RenderedMaterials.js → Models/RenderedMaterials.js} +2 -2
- package/Mesher/Models/VoxelConstructor.d.ts +3 -3
- package/Mesher/Models/VoxelGeometryBuilderCacheSpace.d.ts +1 -3
- package/Mesher/Models/VoxelGeometryBuilderCacheSpace.js +0 -23
- package/Mesher/{Tools/VoxelMesherDataTool.d.ts → Models/VoxelModelBuilder.d.ts} +4 -5
- package/Mesher/{Tools/VoxelMesherDataTool.js → Models/VoxelModelBuilder.js} +11 -7
- package/Models/Defaults/CubeVoxelGeometry.js +4 -0
- package/Models/Defaults/CubeVoxelModels.js +344 -344
- package/Models/Defaults/LiquidVoxelModel.js +2 -2
- package/Models/Defaults/PanelVoxelModels.js +432 -432
- package/Models/Defaults/StairVoxelModel.js +576 -576
- package/Models/Examples.js +469 -456
- package/Models/Rules/Functions/BuildFinalInputs.js +9 -7
- package/Models/Rules/Functions/BuildGeomtryInputs.js +8 -5
- package/Models/Rules/Functions/BuildRules.js +2 -2
- package/Models/Rules/{VoxelModelManager.d.ts → VoxelModelRuleBuilderRegister.d.ts} +1 -1
- package/Models/Rules/VoxelModelRuleBuilderRegister.js +178 -0
- package/Models/VoxelModel.types.d.ts +14 -5
- package/Renderer/Classes/SectorMesh.d.ts +3 -4
- package/Renderer/Classes/SectorMesh.js +6 -11
- package/Renderer/InitTasks.js +6 -7
- package/Renderer/MeshManager.js +2 -2
- package/Renderer/MeshRegister.js +2 -1
- package/Settings/EngineSettings.d.ts +1 -1
- package/Settings/EngineSettings.js +3 -5
- package/Settings/EngineSettings.types.d.ts +17 -18
- package/Settings/EngineSettings.types.js +16 -15
- package/Tasks/IWG/IWG.d.ts +2 -1
- package/Tasks/IWG/IWG.js +9 -3
- package/Tasks/IWG/Internal/Classes/BuildQueue.d.ts +11 -0
- package/Tasks/IWG/Internal/Classes/BuildQueue.js +49 -0
- package/Tasks/IWG/Internal/Classes/Generator.d.ts +6 -1
- package/Tasks/IWG/Internal/Classes/Generator.js +13 -1
- package/Tasks/IWG/Internal/Classes/IWGTaskBase.js +2 -2
- package/Tasks/IWG/Internal/Functions/runBuildUpdate.js +21 -2
- package/Tasks/IWG/Internal/IWGTasks.d.ts +0 -4
- package/Tasks/IWG/Internal/IWGTasks.js +0 -10
- package/Tasks/IWG/Internal/IWGTools.d.ts +1 -1
- package/Tasks/IWG/Procedures/SaveAllSectors.js +2 -0
- package/Tasks/Update/UpdateTask.d.ts +3 -1
- package/Tasks/Update/UpdateTask.js +28 -2
- package/Tasks/Update/VoxelUpdate.js +6 -0
- package/Tasks/WorldGeneration/WorldGenBrush.js +1 -1
- package/Templates/Cursor/TemplateCursor.d.ts +2 -2
- package/Templates/Cursor/TemplateCursor.js +1 -2
- package/Templates/VoxelTemplates.types.d.ts +1 -1
- package/Textures/Classes/CompiledTexture.d.ts +18 -0
- package/Textures/Classes/CompiledTexture.js +50 -0
- package/Textures/Classes/CompiledTextureAnimation.d.ts +12 -0
- package/Textures/Classes/CompiledTextureAnimation.js +27 -0
- package/Textures/Classes/TextureAnimationTexture.d.ts +10 -0
- package/Textures/Classes/TextureAnimationTexture.js +32 -0
- package/Textures/Functions/BuildTextureData.d.ts +10 -0
- package/Textures/Functions/BuildTextureData.js +205 -0
- package/Textures/Texture.types.d.ts +50 -64
- package/Textures/TextureManager.d.ts +8 -19
- package/Textures/TextureManager.js +28 -166
- package/Tools/Brush/Brush.d.ts +1 -1
- package/Tools/Brush/Brush.js +39 -7
- package/Util/Binary/BinaryArrays.d.ts +6 -0
- package/Util/Binary/BinaryArrays.js +25 -0
- package/Util/Binary/BinaryBuffer.d.ts +29 -0
- package/Util/Binary/BinaryBuffer.js +130 -0
- package/Util/Binary/{BitArray.d.ts → BinaryFunctions.d.ts} +1 -2
- package/Util/Binary/BinaryFunctions.js +11 -0
- package/Voxels/Cursor/DataCursor.interface.d.ts +5 -0
- package/Voxels/Cursor/VoxelCursor.interface.d.ts +1 -1
- package/Voxels/Cursor/VoxelCursor.interface.js +8 -11
- package/Voxels/Data/VoxelPalettesRegister.d.ts +0 -5
- package/Voxels/Data/VoxelPalettesRegister.js +0 -9
- package/Voxels/Data/VoxelTagsRegister.js +7 -7
- package/Voxels/Functions/BuildStateData.js +9 -9
- package/Voxels/Functions/BuildTagAndPaletteData.js +2 -4
- package/Voxels/InitVoxelData.js +12 -13
- package/Voxels/State/Schema/StateSchema.d.ts +1 -1
- package/Voxels/Types/Voxel.types.d.ts +18 -0
- package/Voxels/Types/Voxel.types.js +6 -2
- package/World/Archive/Archive.types.d.ts +38 -34
- package/World/Archive/Functions/ArchiveArea.js +16 -24
- package/World/Archive/Functions/ArchiveSector.js +477 -192
- package/World/Archive/Functions/ImportSector.d.ts +3 -3
- package/World/Archive/Functions/ImportSector.js +202 -141
- package/World/Archive/Functions/Shared.d.ts +6 -0
- package/World/Archive/Functions/Shared.js +75 -0
- package/World/Archive/InitTasks.js +30 -13
- package/World/Cursor/SectionCursor.d.ts +2 -2
- package/World/Cursor/SectionCursor.js +2 -3
- package/World/Cursor/SectorCursor.d.ts +2 -2
- package/World/Cursor/SectorCursor.js +1 -2
- package/World/Cursor/WorldCursor.d.ts +2 -2
- package/World/Cursor/WorldCursor.js +1 -2
- package/World/Cursor/WorldVoxelCursor.js +1 -0
- package/World/InitTasks.d.ts +1 -1
- package/World/Lock/WorldLock.d.ts +1 -1
- package/World/Section/Section.d.ts +12 -16
- package/World/Section/Section.js +62 -20
- package/World/Section/SectionState.d.ts +10 -0
- package/World/Section/SectionState.js +11 -0
- package/World/Sector/Sector.d.ts +14 -6
- package/World/Sector/Sector.js +67 -17
- package/World/Sector/SectorHeightMap.js +2 -2
- package/World/Sector/SectorState.d.ts +14 -6
- package/World/Sector/SectorState.js +28 -15
- package/World/Types/WorldStorage.interface.js +1 -0
- package/World/WorldRegister.d.ts +4 -0
- package/World/WorldRegister.js +15 -3
- package/World/WorldSpaces.d.ts +4 -0
- package/World/WorldSpaces.js +19 -6
- package/package.json +1 -1
- package/Mesher/Functions/CompactMesh.d.ts +0 -2
- package/Mesher/Functions/CompactMesh.js +0 -42
- package/Mesher/Geomtry/GeometryNormals.d.ts +0 -10
- package/Mesher/Geomtry/GeometryNormals.js +0 -52
- package/Mesher/Geomtry/MeshData.types.d.ts +0 -13
- package/Mesher/Geomtry/MeshData.types.js +0 -6
- package/Mesher/Geomtry/Tools/MesherDataTools.d.ts +0 -7
- package/Mesher/Geomtry/Tools/MesherDataTools.js +0 -12
- package/Mesher/Geomtry/Tools/index.d.ts +0 -1
- package/Mesher/Geomtry/Tools/index.js +0 -1
- package/Mesher/RenderedMaterials.d.ts +0 -6
- package/Models/Rules/VoxelModelManager.js +0 -82
- package/Textures/TextureAnimations.d.ts +0 -4
- package/Textures/TextureAnimations.js +0 -35
- package/Textures/TextureArray.d.ts +0 -47
- package/Textures/TextureArray.js +0 -202
- package/Textures/TextureBuilder.d.ts +0 -13
- package/Textures/TextureBuilder.js +0 -120
- package/Textures/TextureRegister.d.ts +0 -9
- package/Textures/TextureRegister.js +0 -28
- package/Tools/DataCursor.interface.d.ts +0 -5
- package/Tools/DataCursor.interface.js +0 -2
- package/Util/Binary/BitArray.js +0 -16
- package/World/Structs/WorldDataStructProperties.d.ts +0 -8
- package/World/Structs/WorldDataStructProperties.js +0 -9
- /package/Mesher/{Tools → Geomtry}/VoxelMeshBVHBuilder.d.ts +0 -0
- /package/Mesher/{Tools → Geomtry}/VoxelMeshBVHBuilder.js +0 -0
- /package/Mesher/Geomtry/{Buffers.d.ts → VoxelMeshBuffers.d.ts} +0 -0
- /package/Mesher/Geomtry/{Buffers.js → VoxelMeshBuffers.js} +0 -0
- /package/Mesher/{Tools → Geomtry}/VoxelMeshVertexStructCursor.d.ts +0 -0
- /package/Mesher/{Tools → Geomtry}/VoxelMeshVertexStructCursor.js +0 -0
- /package/Mesher/{VoxelShaderData.d.ts → Geomtry/VoxelShaderData.d.ts} +0 -0
- /package/Mesher/{VoxelShaderData.js → Geomtry/VoxelShaderData.js} +0 -0
- /package/{World/Storage/WorldStorage.interface.js → Voxels/Cursor/DataCursor.interface.js} +0 -0
- /package/World/{Storage → Types}/WorldStorage.interface.d.ts +0 -0
package/World/WorldSpaces.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
//types
|
|
2
2
|
import { EngineSettings } from "../Settings/EngineSettings.js";
|
|
3
3
|
import { Vector3Like } from "@amodx/math";
|
|
4
|
-
import { CubeHashVec3, CubeHashVec3Array, GetYXZOrderArrayIndex, GetYXZOrderArrayPositionVec3, } from "../Math/Indexing.js";
|
|
4
|
+
import { CubeHashVec3, CubeHashVec3Array, GetYXZOrderArrayIndex, GetYXZOrderArrayPositionVec3, GetYXZOrderArrayPositionVec3Array, } from "../Math/Indexing.js";
|
|
5
5
|
const tempPosition = Vector3Like.Create();
|
|
6
6
|
const tempPosition2 = Vector3Like.Create();
|
|
7
7
|
class WorldBounds {
|
|
@@ -57,6 +57,8 @@ class SectorSpace {
|
|
|
57
57
|
static power2Axes = Vector3Like.Create();
|
|
58
58
|
static bounds = Vector3Like.Create();
|
|
59
59
|
static volumne = 0;
|
|
60
|
+
static sectionBounds = Vector3Like.Create();
|
|
61
|
+
static sectionVolumne = 0;
|
|
60
62
|
static getPosition(x, y, z, refPosition = Vector3Like.Create()) {
|
|
61
63
|
CubeHashVec3(x, y, z, SectorSpace.power2Axes.x, SectorSpace.power2Axes.y, SectorSpace.power2Axes.z, refPosition);
|
|
62
64
|
return refPosition;
|
|
@@ -81,7 +83,13 @@ class SectionSpace {
|
|
|
81
83
|
static getIndex(x, y, z) {
|
|
82
84
|
SectionSpace.getPosition(x, y, z, tempPosition);
|
|
83
85
|
SectorSpace.getPosition(x, y, z, tempPosition2);
|
|
84
|
-
return (tempPosition.y - tempPosition2.y) / SectionSpace.bounds.y;
|
|
86
|
+
return GetYXZOrderArrayIndex((tempPosition.x - tempPosition2.x) / SectionSpace.bounds.x, (tempPosition.y - tempPosition2.y) / SectionSpace.bounds.y, (tempPosition.z - tempPosition2.z) / SectionSpace.bounds.z, SectorSpace.sectionBounds.x, SectorSpace.sectionBounds.y, SectorSpace.sectionBounds.z);
|
|
87
|
+
}
|
|
88
|
+
static getPositionFromIndex(index, refPosition = Vector3Like.Create()) {
|
|
89
|
+
return GetYXZOrderArrayPositionVec3(index, SectorSpace.sectionBounds.x, SectorSpace.sectionBounds.y, SectorSpace.sectionBounds.z, refPosition);
|
|
90
|
+
}
|
|
91
|
+
static getPositionFromIndexVec3Array(index, refPosition = [0, 0, 0]) {
|
|
92
|
+
return GetYXZOrderArrayPositionVec3Array(index, SectorSpace.sectionBounds.x, SectorSpace.sectionBounds.y, SectorSpace.sectionBounds.z, refPosition);
|
|
85
93
|
}
|
|
86
94
|
}
|
|
87
95
|
class VoxelSpace {
|
|
@@ -138,6 +146,8 @@ EngineSettings.addEventListener("synced", (event) => {
|
|
|
138
146
|
SectorSpace.bounds.x = 1 << SectorSpace.power2Axes.x;
|
|
139
147
|
SectorSpace.bounds.y = 1 << SectorSpace.power2Axes.y;
|
|
140
148
|
SectorSpace.bounds.z = 1 << SectorSpace.power2Axes.z;
|
|
149
|
+
SectorSpace.volumne =
|
|
150
|
+
SectorSpace.bounds.x * SectorSpace.bounds.y * SectorSpace.bounds.z;
|
|
141
151
|
SectionSpace.power2Axes.x = settings.sections.power2Size.x;
|
|
142
152
|
SectionSpace.power2Axes.y = settings.sections.power2Size.y;
|
|
143
153
|
SectionSpace.power2Axes.z = settings.sections.power2Size.z;
|
|
@@ -146,8 +156,11 @@ EngineSettings.addEventListener("synced", (event) => {
|
|
|
146
156
|
SectionSpace.bounds.z = 1 << SectionSpace.power2Axes.z;
|
|
147
157
|
SectionSpace.volumne =
|
|
148
158
|
SectionSpace.bounds.x * SectionSpace.bounds.y * SectionSpace.bounds.z;
|
|
149
|
-
SectorSpace.
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
159
|
+
SectorSpace.sectionBounds.x = SectorSpace.bounds.x / SectionSpace.bounds.x;
|
|
160
|
+
SectorSpace.sectionBounds.y = SectorSpace.bounds.y / SectionSpace.bounds.y;
|
|
161
|
+
SectorSpace.sectionBounds.z = SectorSpace.bounds.z / SectionSpace.bounds.z;
|
|
162
|
+
SectorSpace.sectionVolumne =
|
|
163
|
+
SectorSpace.sectionBounds.x *
|
|
164
|
+
SectorSpace.sectionBounds.y *
|
|
165
|
+
SectorSpace.sectionBounds.z;
|
|
153
166
|
});
|
package/package.json
CHANGED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
export function CompactMesh(materialId, tool) {
|
|
2
|
-
/* let webGPU = EngineSettings.settings.rendererSettings.mode == "webgpu";
|
|
3
|
-
|
|
4
|
-
const mesh = tool.mesh!;
|
|
5
|
-
const byteRanges: [
|
|
6
|
-
byteStart: number,
|
|
7
|
-
length: number,
|
|
8
|
-
type: BinaryNumberTypes,
|
|
9
|
-
][] = [];
|
|
10
|
-
const dataMap: CompactSubMesh = [materialId, []];
|
|
11
|
-
let totalSize = 0;
|
|
12
|
-
for (let [key, [array, stride, type]] of mesh.attributes) {
|
|
13
|
-
if (key == MeshDefaultAttributes.Indices) {
|
|
14
|
-
if (array.length > 60_000) {
|
|
15
|
-
type = BinaryNumberTypes.Uint32;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
let current = totalSize;
|
|
19
|
-
|
|
20
|
-
totalSize += MappedByteCounts[type] * array.length;
|
|
21
|
-
byteRanges.push([current, array.length, type]);
|
|
22
|
-
dataMap[1].push([key, array as any, stride]);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const finalBuffer = new ArrayBuffer(totalSize);
|
|
26
|
-
|
|
27
|
-
for (let i = 0; i < dataMap[1].length; i++) {
|
|
28
|
-
const startByte = byteRanges[i][0];
|
|
29
|
-
const length = byteRanges[i][1];
|
|
30
|
-
const type = byteRanges[i][2];
|
|
31
|
-
const newArray = new TypedArrayClassMap[type](
|
|
32
|
-
finalBuffer,
|
|
33
|
-
//@ts-ignore
|
|
34
|
-
startByte,
|
|
35
|
-
length
|
|
36
|
-
) as Float32Array;
|
|
37
|
-
newArray.set(dataMap[1][i][0] as any as number[]);
|
|
38
|
-
dataMap[1][i][1] = newArray;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return [0, finalBuffer, [dataMap]]; */
|
|
42
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { Vec3Array } from "@amodx/math";
|
|
2
|
-
export declare class GeometryNormals {
|
|
3
|
-
static subtract(v1: Vec3Array, v2: Vec3Array): Vec3Array;
|
|
4
|
-
static cross(v1: Vec3Array, v2: Vec3Array): Vec3Array;
|
|
5
|
-
static scale(v: Vec3Array, scaleFactor: number): Vec3Array;
|
|
6
|
-
static add(v1: Vec3Array, v2: Vec3Array): Vec3Array;
|
|
7
|
-
static normalize(v: Vec3Array): Vec3Array;
|
|
8
|
-
static getTriangleNormals(p1: Vec3Array, p2: Vec3Array, p3: Vec3Array): Vec3Array;
|
|
9
|
-
static getQuadNormal(p1: Vec3Array, p2: Vec3Array, p3: Vec3Array, p4: Vec3Array): [n1: Vec3Array, n2: Vec3Array, n3: Vec3Array, n4: Vec3Array];
|
|
10
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
export class GeometryNormals {
|
|
2
|
-
static subtract(v1, v2) {
|
|
3
|
-
return [v1[0] - v2[0], v1[1] - v2[1], v1[2] - v2[2]];
|
|
4
|
-
}
|
|
5
|
-
static cross(v1, v2) {
|
|
6
|
-
return [
|
|
7
|
-
v1[1] * v2[2] - v1[2] * v2[1],
|
|
8
|
-
v1[2] * v2[0] - v1[0] * v2[2],
|
|
9
|
-
v1[0] * v2[1] - v1[1] * v2[0],
|
|
10
|
-
];
|
|
11
|
-
}
|
|
12
|
-
static scale(v, scaleFactor) {
|
|
13
|
-
return [v[0] * scaleFactor, v[1] * scaleFactor, v[2] * scaleFactor];
|
|
14
|
-
}
|
|
15
|
-
static add(v1, v2) {
|
|
16
|
-
return [v1[0] + v2[0], v1[1] + v2[1], v1[2] + v2[2]];
|
|
17
|
-
}
|
|
18
|
-
static normalize(v) {
|
|
19
|
-
const length = Math.sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
|
|
20
|
-
return length > 0
|
|
21
|
-
? [v[0] / length, v[1] / length, v[2] / length]
|
|
22
|
-
: [0, 0, 0];
|
|
23
|
-
}
|
|
24
|
-
static getTriangleNormals(p1, p2, p3) {
|
|
25
|
-
const a = this.subtract(p2, p1);
|
|
26
|
-
const b = this.subtract(p3, p1);
|
|
27
|
-
const substract = this.cross(a, b);
|
|
28
|
-
const normal = this.scale(substract, -1);
|
|
29
|
-
return this.normalize(normal);
|
|
30
|
-
}
|
|
31
|
-
static getQuadNormal(p1, p2, p3, p4) {
|
|
32
|
-
const vectorA1 = [p2[0] - p1[0], p2[1] - p1[1], p2[2] - p1[2]];
|
|
33
|
-
const vectorA2 = [p3[0] - p1[0], p3[1] - p1[1], p3[2] - p1[2]];
|
|
34
|
-
const normalA = this.normalize(this.cross(vectorA1, vectorA2));
|
|
35
|
-
const vectorB1 = [p3[0] - p1[0], p3[1] - p1[1], p3[2] - p1[2]];
|
|
36
|
-
const vectorB2 = [p4[0] - p1[0], p4[1] - p1[1], p4[2] - p1[2]];
|
|
37
|
-
const normalB = this.normalize(this.cross(vectorB1, vectorB2));
|
|
38
|
-
const n1 = this.normalize([
|
|
39
|
-
(normalA[0] + normalB[0]) / 2,
|
|
40
|
-
(normalA[1] + normalB[1]) / 2,
|
|
41
|
-
(normalA[2] + normalB[2]) / 2,
|
|
42
|
-
]);
|
|
43
|
-
const n2 = normalA;
|
|
44
|
-
const n3 = this.normalize([
|
|
45
|
-
(normalA[0] + normalB[0]) / 2,
|
|
46
|
-
(normalA[1] + normalB[1]) / 2,
|
|
47
|
-
(normalA[2] + normalB[2]) / 2,
|
|
48
|
-
]);
|
|
49
|
-
const n4 = normalB;
|
|
50
|
-
return [n1, n2, n3, n4];
|
|
51
|
-
}
|
|
52
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { TypedArrays } from "@amodx/binary";
|
|
2
|
-
export declare enum MeshDefaultAttributes {
|
|
3
|
-
Position = "position",
|
|
4
|
-
Normal = "normal",
|
|
5
|
-
Indices = "indices"
|
|
6
|
-
}
|
|
7
|
-
export type MeshAttributes = [
|
|
8
|
-
id: string,
|
|
9
|
-
data: TypedArrays,
|
|
10
|
-
stride: number,
|
|
11
|
-
componentTypes?: number,
|
|
12
|
-
noramlizer?: number
|
|
13
|
-
][];
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export var MeshDefaultAttributes;
|
|
2
|
-
(function (MeshDefaultAttributes) {
|
|
3
|
-
MeshDefaultAttributes["Position"] = "position";
|
|
4
|
-
MeshDefaultAttributes["Normal"] = "normal";
|
|
5
|
-
MeshDefaultAttributes["Indices"] = "indices";
|
|
6
|
-
})(MeshDefaultAttributes || (MeshDefaultAttributes = {}));
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./MesherDataTools.js";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./MesherDataTools.js";
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { StringPalette } from "../../Util/StringPalette";
|
|
2
|
-
import { VoxelRuleGeometry } from "./Classes/VoxelRulesGeometry";
|
|
3
|
-
import { VoxelRulesModoel } from "./Classes/VoxelRulesModel";
|
|
4
|
-
const addGeo = (modelId, stateId, nodes) => {
|
|
5
|
-
const registred = [];
|
|
6
|
-
for (const geoLinkNode of nodes) {
|
|
7
|
-
const geo = VoxelModelManager.geometry.get(geoLinkNode.geometryId);
|
|
8
|
-
if (!geo)
|
|
9
|
-
throw new Error(`Geometry ${geoLinkNode.geometryId} is not registered.`);
|
|
10
|
-
const newId = getGeometryLinkId(geoLinkNode);
|
|
11
|
-
if (VoxelModelManager.geometry.has(newId))
|
|
12
|
-
continue;
|
|
13
|
-
registred.push([stateId, newId]);
|
|
14
|
-
if (!VoxelModelManager.geometryPalette.isRegistered(newId))
|
|
15
|
-
VoxelModelManager.geometryPalette.register(newId);
|
|
16
|
-
const newData = structuredClone(geo.data);
|
|
17
|
-
newData.nodes = newData.nodes.map((_) => ({
|
|
18
|
-
..._,
|
|
19
|
-
tranform: {
|
|
20
|
-
...(geoLinkNode.position ? { position: geoLinkNode.position } : {}),
|
|
21
|
-
...(geoLinkNode.scale ? { scale: geoLinkNode.scale } : {}),
|
|
22
|
-
...(geoLinkNode.rotation ? { rotation: geoLinkNode.rotation } : {}),
|
|
23
|
-
...(geoLinkNode.rotationPivot
|
|
24
|
-
? { rotationPivot: geoLinkNode.rotationPivot }
|
|
25
|
-
: {}),
|
|
26
|
-
...(geoLinkNode.flip ? { flip: geoLinkNode.flip } : {}),
|
|
27
|
-
},
|
|
28
|
-
}));
|
|
29
|
-
VoxelModelManager.geometry.set(newId, new VoxelRuleGeometry(newId, newData));
|
|
30
|
-
continue;
|
|
31
|
-
}
|
|
32
|
-
return registred;
|
|
33
|
-
};
|
|
34
|
-
const getGeometryLinkId = (node) => {
|
|
35
|
-
return `${node.geometryId}${node.position ? `-p${node.position.toString()}` : ""}${node.rotation ? `-r${node.rotation.toString()}` : ""}${node.scale ? `-s${node.scale.toString()}` : ""}`.trim();
|
|
36
|
-
};
|
|
37
|
-
export class VoxelModelManager {
|
|
38
|
-
static geometryPalette = new StringPalette();
|
|
39
|
-
static getGeometryLinkId = getGeometryLinkId;
|
|
40
|
-
static voxels = new Map();
|
|
41
|
-
static geometry = new Map();
|
|
42
|
-
static models = new Map();
|
|
43
|
-
static registerGeometry(...geometry) {
|
|
44
|
-
for (const geo of geometry) {
|
|
45
|
-
if (!this.geometryPalette.isRegistered(geo.id))
|
|
46
|
-
this.geometryPalette.register(geo.id);
|
|
47
|
-
this.geometry.set(geo.id, new VoxelRuleGeometry(geo.id, {
|
|
48
|
-
ogData: geo,
|
|
49
|
-
id: geo.id,
|
|
50
|
-
nodes: geo.nodes.map((node) => ({
|
|
51
|
-
node,
|
|
52
|
-
tranform: {},
|
|
53
|
-
})),
|
|
54
|
-
}));
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
static getGeomtryFromLink(link) {
|
|
58
|
-
return this.geometry.get(getGeometryLinkId(link));
|
|
59
|
-
}
|
|
60
|
-
static registerModels(...models) {
|
|
61
|
-
for (const model of models) {
|
|
62
|
-
const rulesModel = new VoxelRulesModoel(model);
|
|
63
|
-
this.models.set(model.id, rulesModel);
|
|
64
|
-
for (const stateId in model.shapeStatesNodes) {
|
|
65
|
-
const nodes = model.shapeStatesNodes[stateId];
|
|
66
|
-
addGeo(model.id, stateId, nodes).forEach((_) => rulesModel.registerShapeState(..._));
|
|
67
|
-
}
|
|
68
|
-
for (const stateId in model.shapeStatesConditonalNodes) {
|
|
69
|
-
const nodes = model.shapeStatesConditonalNodes[stateId];
|
|
70
|
-
addGeo(model.id, stateId, nodes).forEach((_) => rulesModel.registerCondiotnalNode(..._));
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
static registerVoxel(id, data) {
|
|
75
|
-
let voxelModels = this.voxels.get(data.id);
|
|
76
|
-
if (!voxelModels) {
|
|
77
|
-
voxelModels = [];
|
|
78
|
-
this.voxels.set(data.id, voxelModels);
|
|
79
|
-
}
|
|
80
|
-
voxelModels.push({ id, data });
|
|
81
|
-
}
|
|
82
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
export const TextureAnimationCreator = {
|
|
2
|
-
createAnimations(texture) {
|
|
3
|
-
if (!texture.paths.size)
|
|
4
|
-
return;
|
|
5
|
-
const animaitonUniform = [];
|
|
6
|
-
let i = 0;
|
|
7
|
-
for (const anim of texture.animationsMap) {
|
|
8
|
-
animaitonUniform[anim[0]] = anim[0];
|
|
9
|
-
let keyCounts = [];
|
|
10
|
-
const animTime = texture.animationTimes[i];
|
|
11
|
-
if (animTime.length == 1) {
|
|
12
|
-
for (let k = 0; k < anim.length; k++) {
|
|
13
|
-
keyCounts.push(animTime[0]);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
else {
|
|
17
|
-
keyCounts = texture.animationTimes[i];
|
|
18
|
-
}
|
|
19
|
-
texture.animations.push({
|
|
20
|
-
uniformIndex: anim[0],
|
|
21
|
-
keys: anim,
|
|
22
|
-
currentFrame: 0,
|
|
23
|
-
currentCount: 0,
|
|
24
|
-
keyCounts: keyCounts,
|
|
25
|
-
});
|
|
26
|
-
i++;
|
|
27
|
-
}
|
|
28
|
-
for (let i = 0; i < texture.totalTextures; i++) {
|
|
29
|
-
if (!animaitonUniform[i]) {
|
|
30
|
-
animaitonUniform[i] = 0;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
texture.animationUniform = new Float32Array(animaitonUniform);
|
|
34
|
-
},
|
|
35
|
-
};
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import type { TextureData } from "./Texture.types";
|
|
2
|
-
export declare class TextureArray {
|
|
3
|
-
id: string;
|
|
4
|
-
extension: string;
|
|
5
|
-
totalTextures: number;
|
|
6
|
-
textureMap: Map<string, TextureData>;
|
|
7
|
-
textures: TextureData[];
|
|
8
|
-
textureIndex: Record<string, number>;
|
|
9
|
-
animationsMap: number[][];
|
|
10
|
-
animationTimes: number[][];
|
|
11
|
-
animations: {
|
|
12
|
-
uniformIndex: number;
|
|
13
|
-
overlay?: boolean;
|
|
14
|
-
keys: number[];
|
|
15
|
-
currentFrame: number;
|
|
16
|
-
currentCount: number;
|
|
17
|
-
keyCounts: number[];
|
|
18
|
-
}[];
|
|
19
|
-
varyingID: string;
|
|
20
|
-
animationUniforID: string;
|
|
21
|
-
animationUniform: Float32Array;
|
|
22
|
-
paths: Map<string, HTMLImageElement | string | false>;
|
|
23
|
-
images: HTMLImageElement[];
|
|
24
|
-
shaderTexture: any | null;
|
|
25
|
-
textureID: string;
|
|
26
|
-
attributeID: string;
|
|
27
|
-
constructor(id: string);
|
|
28
|
-
/**# clearData
|
|
29
|
-
* ---
|
|
30
|
-
* Clear all un-needed data.
|
|
31
|
-
*/
|
|
32
|
-
clearData(): void;
|
|
33
|
-
/**# flush
|
|
34
|
-
* ---
|
|
35
|
-
* Clear all data.
|
|
36
|
-
*/
|
|
37
|
-
flush(): void;
|
|
38
|
-
flushAll(): void;
|
|
39
|
-
build(): Promise<void>;
|
|
40
|
-
getTextureIndex(textureId: string, varation?: string): number;
|
|
41
|
-
addTexture(data: TextureData): void;
|
|
42
|
-
runAnimations(): void;
|
|
43
|
-
getTextureIndexMap(): Record<string, number>;
|
|
44
|
-
_processVariations(textureData: TextureData, paths: Map<string, HTMLImageElement | string | false>, map: Record<string, number>, animations: number[][], textureAnimatioTimes: number[][], extension: string, count: number): number;
|
|
45
|
-
_getPath(textureData: TextureData, varation: string | undefined, extension: string): string;
|
|
46
|
-
buildTextureIndex(): false | undefined;
|
|
47
|
-
}
|
package/Textures/TextureArray.js
DELETED
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
import { TextureManager } from "./TextureManager.js";
|
|
2
|
-
import { TextureAnimationCreator } from "./TextureAnimations.js";
|
|
3
|
-
import { TextureBuilder } from "./TextureBuilder.js";
|
|
4
|
-
export class TextureArray {
|
|
5
|
-
id;
|
|
6
|
-
extension = "png";
|
|
7
|
-
totalTextures = 0;
|
|
8
|
-
textureMap = new Map();
|
|
9
|
-
textures = [];
|
|
10
|
-
textureIndex = {};
|
|
11
|
-
animationsMap = [];
|
|
12
|
-
animationTimes = [];
|
|
13
|
-
animations = [];
|
|
14
|
-
varyingID = "";
|
|
15
|
-
animationUniforID = "";
|
|
16
|
-
animationUniform = new Float32Array();
|
|
17
|
-
paths = new Map();
|
|
18
|
-
images = [];
|
|
19
|
-
/* actual renderer resource */
|
|
20
|
-
shaderTexture = null;
|
|
21
|
-
textureID = "";
|
|
22
|
-
attributeID = "textureIndex";
|
|
23
|
-
constructor(id) {
|
|
24
|
-
this.id = id;
|
|
25
|
-
this.textureID = id.replace("#", "");
|
|
26
|
-
}
|
|
27
|
-
/**# clearData
|
|
28
|
-
* ---
|
|
29
|
-
* Clear all un-needed data.
|
|
30
|
-
*/
|
|
31
|
-
clearData() {
|
|
32
|
-
this.paths.clear();
|
|
33
|
-
this.textures = [];
|
|
34
|
-
this.textureMap.clear();
|
|
35
|
-
this.textureIndex = {};
|
|
36
|
-
this.images = [];
|
|
37
|
-
this.animationsMap = [];
|
|
38
|
-
this.animationTimes = [];
|
|
39
|
-
}
|
|
40
|
-
/**# flush
|
|
41
|
-
* ---
|
|
42
|
-
* Clear all data.
|
|
43
|
-
*/
|
|
44
|
-
flush() {
|
|
45
|
-
this.clearData();
|
|
46
|
-
this.images = [];
|
|
47
|
-
this.animations = [];
|
|
48
|
-
this.animationTimes = [];
|
|
49
|
-
this.animationsMap = [];
|
|
50
|
-
this.textureIndex = {};
|
|
51
|
-
this.totalTextures = 0;
|
|
52
|
-
}
|
|
53
|
-
flushAll() {
|
|
54
|
-
// this.materials.clear();
|
|
55
|
-
}
|
|
56
|
-
async build() {
|
|
57
|
-
this.buildTextureIndex();
|
|
58
|
-
if (this.paths.size) {
|
|
59
|
-
this.images = await TextureBuilder.createMaterialTexture(this.id, this.paths);
|
|
60
|
-
}
|
|
61
|
-
TextureAnimationCreator.createAnimations(this);
|
|
62
|
-
}
|
|
63
|
-
getTextureIndex(textureId, varation = "") {
|
|
64
|
-
let id = textureId;
|
|
65
|
-
if (varation) {
|
|
66
|
-
id = `${textureId}:${varation}`;
|
|
67
|
-
}
|
|
68
|
-
let uv = -1;
|
|
69
|
-
uv = this.textureIndex[id];
|
|
70
|
-
if (uv == -1) {
|
|
71
|
-
throw new Error(`Texture with id: ${id} does not exists.typeId : ${this.id} `);
|
|
72
|
-
}
|
|
73
|
-
return uv;
|
|
74
|
-
}
|
|
75
|
-
addTexture(data) {
|
|
76
|
-
this.textures.push(data);
|
|
77
|
-
this.textureMap.set(data.id, data);
|
|
78
|
-
}
|
|
79
|
-
runAnimations() {
|
|
80
|
-
for (let i = 0; i < this.animations.length; i++) {
|
|
81
|
-
const anim = this.animations[i];
|
|
82
|
-
if (anim.currentCount <= anim.keyCounts[anim.currentFrame]) {
|
|
83
|
-
anim.currentCount++;
|
|
84
|
-
continue;
|
|
85
|
-
}
|
|
86
|
-
anim.currentCount = 0;
|
|
87
|
-
if (anim.currentFrame < anim.keys.length - 1) {
|
|
88
|
-
anim.currentFrame++;
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
anim.currentFrame = 0;
|
|
92
|
-
}
|
|
93
|
-
this.animationUniform[anim.uniformIndex] = anim.keys[anim.currentFrame];
|
|
94
|
-
/* for (const [key, material] of this.materials) {
|
|
95
|
-
material!.setNumberArray(
|
|
96
|
-
this.animationUniforID,
|
|
97
|
-
this.animationUniform as any
|
|
98
|
-
);
|
|
99
|
-
} */
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
getTextureIndexMap() {
|
|
103
|
-
return this.textureIndex;
|
|
104
|
-
}
|
|
105
|
-
_processVariations(textureData, paths, map, animations, textureAnimatioTimes, extension, count) {
|
|
106
|
-
if (!textureData.variations)
|
|
107
|
-
return count;
|
|
108
|
-
for (const varation of Object.keys(textureData.variations)) {
|
|
109
|
-
const data = textureData.variations[varation];
|
|
110
|
-
if (data.frames == 0) {
|
|
111
|
-
map[`${textureData.id}:${varation}`] = count;
|
|
112
|
-
const assetPath = this._getPath(textureData, varation, extension);
|
|
113
|
-
let raw = false;
|
|
114
|
-
if (data.base64 && !Array.isArray(data.base64)) {
|
|
115
|
-
raw = data.base64;
|
|
116
|
-
}
|
|
117
|
-
paths.set(assetPath, raw);
|
|
118
|
-
count++;
|
|
119
|
-
}
|
|
120
|
-
else {
|
|
121
|
-
if (!data.animKeys)
|
|
122
|
-
throw new Error("Texture Varation must have supplied animKeys if frames are greater than 0.");
|
|
123
|
-
for (let i = 1; i <= data.frames; i++) {
|
|
124
|
-
map[`${textureData.id}:${varation}-${i}`] = count;
|
|
125
|
-
const assetPath = this._getPath(textureData, `${varation}-${i}`, extension);
|
|
126
|
-
let raw = false;
|
|
127
|
-
if (data.base64) {
|
|
128
|
-
raw = data.base64[i - 1];
|
|
129
|
-
}
|
|
130
|
-
paths.set(assetPath, raw);
|
|
131
|
-
count++;
|
|
132
|
-
}
|
|
133
|
-
const trueKeys = [];
|
|
134
|
-
for (let i = 0; i < data.animKeys.length; i++) {
|
|
135
|
-
trueKeys.push(map[`${textureData.id}:${varation}-${data.animKeys[i]}`]);
|
|
136
|
-
}
|
|
137
|
-
if (data.animKeyFrameTimes) {
|
|
138
|
-
textureAnimatioTimes.push(data.animKeyFrameTimes);
|
|
139
|
-
}
|
|
140
|
-
if (data.globalFrameTime) {
|
|
141
|
-
textureAnimatioTimes.push([data.globalFrameTime]);
|
|
142
|
-
}
|
|
143
|
-
animations.push(trueKeys);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
return count;
|
|
147
|
-
}
|
|
148
|
-
_getPath(textureData, varation = "default", extension) {
|
|
149
|
-
return `${textureData.path ? textureData.path : TextureManager.defaultTexturePath}/${textureData.id}/${varation}.${extension}`;
|
|
150
|
-
}
|
|
151
|
-
buildTextureIndex() {
|
|
152
|
-
const texture = this;
|
|
153
|
-
if (!texture)
|
|
154
|
-
return false;
|
|
155
|
-
const extension = texture.extension;
|
|
156
|
-
let count = 0;
|
|
157
|
-
const map = this.textureIndex;
|
|
158
|
-
const paths = this.paths;
|
|
159
|
-
const animationTimes = this.animationTimes;
|
|
160
|
-
const animations = this.animationsMap;
|
|
161
|
-
for (const textureData of this.textures) {
|
|
162
|
-
if (textureData.frames == 0) {
|
|
163
|
-
this.textureIndex[`${textureData.id}`] = count;
|
|
164
|
-
const assetPath = this._getPath(textureData, "default", extension);
|
|
165
|
-
let raw = false;
|
|
166
|
-
if (textureData.base64 && !Array.isArray(textureData.base64)) {
|
|
167
|
-
raw = textureData.base64;
|
|
168
|
-
}
|
|
169
|
-
paths.set(assetPath, raw);
|
|
170
|
-
count++;
|
|
171
|
-
count = this._processVariations(textureData, paths, map, animations, animationTimes, extension, count);
|
|
172
|
-
}
|
|
173
|
-
else {
|
|
174
|
-
if (!textureData.animKeys)
|
|
175
|
-
throw new Error("Texture must have supplied animKeys if frames are greater than 0.");
|
|
176
|
-
const rawData = textureData.rawData;
|
|
177
|
-
for (let i = 1; i <= textureData.frames; i++) {
|
|
178
|
-
const assetPath = this._getPath(textureData, `default-${i}`, extension);
|
|
179
|
-
let raw = false;
|
|
180
|
-
if (textureData.base64) {
|
|
181
|
-
raw = textureData.base64[i - 1];
|
|
182
|
-
}
|
|
183
|
-
paths.set(assetPath, raw);
|
|
184
|
-
count++;
|
|
185
|
-
}
|
|
186
|
-
const trueKeys = [];
|
|
187
|
-
for (let i = 0; i < textureData.animKeys.length; i++) {
|
|
188
|
-
trueKeys.push(map[`${textureData.id}:default-${textureData.animKeys[i]}`]);
|
|
189
|
-
}
|
|
190
|
-
if (textureData.animKeyFrameTimes) {
|
|
191
|
-
animationTimes.push(textureData.animKeyFrameTimes);
|
|
192
|
-
}
|
|
193
|
-
if (textureData.globalFrameTime) {
|
|
194
|
-
animationTimes.push([textureData.globalFrameTime]);
|
|
195
|
-
}
|
|
196
|
-
animations.push(trueKeys);
|
|
197
|
-
count = this._processVariations(textureData, paths, map, animations, animationTimes, extension, count);
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
this.totalTextures = count;
|
|
201
|
-
}
|
|
202
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export declare class TextureBuilder {
|
|
2
|
-
static context: CanvasRenderingContext2D | null;
|
|
3
|
-
static _textureSize: number;
|
|
4
|
-
static finalImagWidth: number;
|
|
5
|
-
static finalImageHeight: number;
|
|
6
|
-
static _canvas: HTMLCanvasElement;
|
|
7
|
-
static defineTextureDimensions(textureSize: number): void;
|
|
8
|
-
static setUpImageCreation(): void;
|
|
9
|
-
static createMaterialTexture(name: string, images: Map<string, HTMLImageElement | string | false>, width?: number, height?: number): Promise<HTMLImageElement[]>;
|
|
10
|
-
static getRawData(imageSrc: string): Promise<Uint8ClampedArray>;
|
|
11
|
-
static getBase64(imageSrc: string): Promise<string>;
|
|
12
|
-
static loadImage(imgSrcData: string | HTMLImageElement, width?: number, height?: number): Promise<HTMLImageElement>;
|
|
13
|
-
}
|