@divinevoxel/vlox 0.0.71 → 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/Base/Main/InitDataGenerator.js +0 -9
- package/Contexts/Base/Remote/DataSync.types.d.ts +0 -5
- package/Contexts/Base/Remote/InitDataSync.js +17 -31
- package/Contexts/Render/DivineVoxelEngineRender.d.ts +1 -1
- package/Contexts/World/DivineVoxelEngineWorld.d.ts +1 -1
- package/Init/StartConstructor.js +7 -7
- package/Init/StartWorld.d.ts +1 -1
- package/Init/StartWorld.js +0 -12
- package/Math/Indexing.d.ts +12 -3
- package/Math/Indexing.js +24 -15
- package/Mesher/Functions/CompactVoxelMesh.d.ts +2 -2
- package/Mesher/Functions/CompactVoxelMesh.js +4 -5
- package/Mesher/Functions/MeshSection.d.ts +1 -1
- package/Mesher/Functions/MeshSection.js +72 -66
- package/Mesher/Functions/MeshTexture.d.ts +1 -1
- package/Mesher/Functions/MeshTexture.js +3 -4
- package/Mesher/Functions/MeshVoxel.js +20 -26
- 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 +108 -125
- package/Mesher/Geomtry/VoxelMesh.d.ts +1 -1
- package/Mesher/Geomtry/VoxelMesh.js +2 -2
- package/Mesher/{Tools → Geomtry}/VoxelMeshBVHBuilder.d.ts +2 -9
- package/Mesher/{Tools → Geomtry}/VoxelMeshBVHBuilder.js +4 -16
- package/Mesher/Geomtry/{Buffers.d.ts → VoxelMeshBuffers.d.ts} +9 -8
- package/Mesher/Geomtry/VoxelMeshBuffers.js +49 -0
- package/Mesher/{Tools → Geomtry}/VoxelMeshVertexStructCursor.d.ts +10 -0
- package/Mesher/{Tools → Geomtry}/VoxelMeshVertexStructCursor.js +10 -0
- package/Mesher/Geomtry/index.d.ts +0 -1
- package/Mesher/Geomtry/index.js +0 -1
- package/Mesher/InitMesher.js +2 -11
- package/Mesher/InitTask.js +10 -22
- package/Mesher/Models/Common/BoundsFunctions.d.ts +1 -3
- package/Mesher/Models/Common/BoundsFunctions.js +0 -16
- package/Mesher/Models/Common/Calc/CalcConstants.js +14 -31
- package/Mesher/Models/Common/Calc/FaceDataCalc.d.ts +2 -8
- package/Mesher/Models/Common/Calc/FaceDataCalc.js +50 -52
- 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.d.ts +1 -5
- package/Mesher/Models/Nodes/Custom/Liquid/LiquidGeomtryNode.js +40 -42
- package/Mesher/Models/Nodes/GeometryNode.d.ts +3 -5
- package/Mesher/Models/Nodes/GeometryNode.js +1 -2
- package/Mesher/Models/Nodes/Ruled/BoxVoxelGeometryNode.d.ts +3 -6
- package/Mesher/Models/Nodes/Ruled/BoxVoxelGeometryNode.js +55 -40
- package/Mesher/Models/Nodes/Ruled/QuadVoxelGeometryNode.d.ts +2 -6
- package/Mesher/Models/Nodes/Ruled/QuadVoxelGeometryNode.js +52 -51
- package/Mesher/Models/Nodes/Ruleless/RulelessBoxVoxelGeometryNode.d.ts +2 -6
- package/Mesher/Models/Nodes/Ruleless/RulelessBoxVoxelGeometryNode.js +18 -19
- package/Mesher/Models/Nodes/Ruleless/RulelessQuadVoxelGeometryNode.d.ts +2 -6
- package/Mesher/Models/Nodes/Ruleless/RulelessQuadVoxelGeometryNode.js +37 -40
- 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 +4 -5
- package/Mesher/Models/VoxelConstructor.js +23 -12
- package/Mesher/Models/{VoxelGeometryLookUp.d.ts → VoxelGeometryBuilderCacheSpace.d.ts} +6 -14
- package/Mesher/Models/{VoxelGeometryLookUp.js → VoxelGeometryBuilderCacheSpace.js} +26 -44
- package/Mesher/{Tools/VoxelMesherDataTool.d.ts → Models/VoxelModelBuilder.d.ts} +10 -8
- package/Mesher/{Tools/VoxelMesherDataTool.js → Models/VoxelModelBuilder.js} +44 -19
- package/Mesher/Models/VoxelModelConstructorRegister.js +3 -3
- 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/Indexing/VoxelAOResultsIndex.d.ts +4 -4
- package/Models/Indexing/VoxelAOResultsIndex.js +15 -9
- package/Models/Indexing/VoxelFaceCullResultsIndex.d.ts +3 -3
- package/Models/Indexing/VoxelFaceCullResultsIndex.js +14 -9
- package/Models/Indexing/VoxelFaceTransparentResultsIndex.d.ts +1 -1
- package/Models/Indexing/VoxelFaceTransparentResultsIndex.js +1 -1
- package/Models/Rules/Functions/BuildFinalInputs.js +9 -7
- package/Models/Rules/Functions/BuildGeomtryInputs.js +8 -5
- package/Models/Rules/Functions/BuildRules.js +4 -4
- 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 +14 -2
- package/Tasks/IWG/Internal/Classes/IWGTaskBase.js +2 -2
- package/Tasks/IWG/Internal/Functions/getSectorState.js +4 -7
- package/Tasks/IWG/Internal/Functions/runBuildUpdate.js +21 -2
- package/Tasks/IWG/Internal/Functions/runWorldUpdate.js +5 -6
- package/Tasks/IWG/Internal/IWGTasks.d.ts +0 -4
- package/Tasks/IWG/Internal/IWGTasks.js +12 -31
- package/Tasks/IWG/Internal/IWGTools.d.ts +1 -1
- package/Tasks/IWG/Procedures/SaveAllSectors.js +2 -0
- package/Tasks/Propagation/Flow/FlowManager.d.ts +0 -2
- package/Tasks/Propagation/Flow/FlowManager.js +86 -87
- package/Tasks/Propagation/Flow/WorldFlow.js +2 -3
- package/Tasks/Propagation/Illumanation/WorldRGB.js +1 -2
- package/Tasks/Update/InitTasks.d.ts +2 -1
- package/Tasks/Update/InitTasks.js +6 -6
- package/Tasks/Update/UpdateTask.d.ts +3 -1
- package/Tasks/Update/UpdateTask.js +28 -2
- package/Tasks/Update/VoxelUpdate.js +21 -7
- package/Tasks/WorldGeneration/WorldGenBrush.js +2 -1
- package/Templates/Cursor/TemplateCursor.d.ts +2 -2
- package/Templates/Cursor/TemplateCursor.js +1 -2
- package/Templates/Functions/CreateTemplate.js +1 -1
- package/Templates/VoxelTemplate.js +6 -8
- 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 -3
- package/Tools/Brush/Brush.js +43 -12
- 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/BinaryFunctions.d.ts +3 -0
- package/Util/Binary/BinaryFunctions.js +11 -0
- package/Util/StringPalette.d.ts +1 -0
- package/Util/StringPalette.js +8 -0
- package/Voxels/Cursor/DataCursor.interface.d.ts +5 -0
- package/Voxels/Cursor/VoxelCursor.d.ts +6 -6
- package/Voxels/Cursor/VoxelCursor.interface.d.ts +11 -16
- package/Voxels/Cursor/VoxelCursor.interface.js +35 -58
- package/Voxels/Cursor/VoxelCursor.js +13 -12
- package/Voxels/Cursor/VoxelLightData.d.ts +3 -4
- package/Voxels/Cursor/VoxelLightData.js +8 -7
- package/Voxels/Data/VoxelPalettesRegister.d.ts +8 -0
- package/Voxels/Data/VoxelPalettesRegister.js +8 -0
- package/Voxels/Data/VoxelTag.types.d.ts +56 -0
- package/Voxels/Data/VoxelTag.types.js +23 -0
- package/Voxels/{State → Data}/VoxelTagStates.d.ts +2 -2
- package/Voxels/{State → Data}/VoxelTagStates.js +5 -5
- package/Voxels/Data/VoxelTagsRegister.d.ts +9 -0
- package/Voxels/Data/VoxelTagsRegister.js +32 -0
- package/Voxels/Functions/BuildStateData.js +12 -12
- package/Voxels/Functions/BuildTagAndPaletteData.d.ts +13 -0
- package/Voxels/Functions/BuildTagAndPaletteData.js +55 -0
- package/Voxels/Indexes/VoxelIndex.js +3 -3
- package/Voxels/InitVoxelData.js +31 -73
- package/Voxels/State/Schema/StateSchema.d.ts +1 -1
- package/Voxels/Types/Voxel.types.d.ts +20 -42
- package/Voxels/Types/Voxel.types.js +6 -17
- package/Voxels/Types/VoxelModelCompiledData.types.d.ts +11 -13
- package/Voxels/Types/VoxelSubstances.types.d.ts +2 -15
- package/Voxels/Types/VoxelSubstances.types.js +1 -9
- package/World/Archive/Archive.types.d.ts +38 -34
- package/World/Archive/Functions/ArchiveArea.js +18 -30
- package/World/Archive/Functions/ArchiveSector.js +484 -213
- package/World/Archive/Functions/ImportSector.d.ts +3 -3
- package/World/Archive/Functions/ImportSector.js +205 -151
- 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 +3 -2
- package/World/Cursor/SectionCursor.js +9 -4
- package/World/Cursor/SectorCursor.d.ts +3 -2
- package/World/Cursor/SectorCursor.js +5 -3
- package/World/Cursor/WorldCursor.d.ts +2 -2
- package/World/Cursor/WorldCursor.js +6 -3
- package/World/Cursor/WorldVoxelCursor.d.ts +7 -7
- package/World/Cursor/WorldVoxelCursor.js +21 -24
- package/World/InitTasks.d.ts +1 -1
- package/World/Lock/WorldLock.d.ts +1 -1
- package/World/Section/Section.d.ts +31 -23
- package/World/Section/Section.js +116 -18
- package/World/Section/SectionState.d.ts +10 -0
- package/World/Section/SectionState.js +11 -0
- package/World/Sector/Sector.d.ts +24 -9
- package/World/Sector/Sector.js +92 -21
- package/World/Sector/SectorHeightMap.js +3 -5
- package/World/Sector/SectorState.d.ts +21 -0
- package/World/Sector/SectorState.js +28 -0
- package/World/WorldRegister.d.ts +4 -0
- package/World/WorldRegister.js +15 -3
- package/World/WorldSpaces.d.ts +6 -0
- package/World/WorldSpaces.js +25 -6
- package/package.json +1 -1
- package/Data/Cursor/DataCursor.interface.d.ts +0 -5
- package/Data/Cursor/DataCursor.interface.js +0 -2
- package/Data/Register/MappedDataRegister.d.ts +0 -5
- package/Data/Register/MappedDataRegister.js +0 -9
- package/Data/Register/MappedRegisterBase.d.ts +0 -14
- package/Data/Register/MappedRegisterBase.js +0 -50
- package/Data/Structs/StructBuilder.d.ts +0 -34
- package/Data/Structs/StructBuilder.js +0 -157
- package/Data/Structs/StructBuilder.types.d.ts +0 -30
- package/Mesher/Functions/CompactMesh.d.ts +0 -2
- package/Mesher/Functions/CompactMesh.js +0 -42
- package/Mesher/Geomtry/Buffers.js +0 -81
- 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/Data/SubstanceDataTool.d.ts +0 -13
- package/Tools/Data/SubstanceDataTool.js +0 -51
- package/Voxels/Palettes/MaterialPalette.d.ts +0 -9
- package/Voxels/Palettes/MaterialPalette.js +0 -11
- package/Voxels/Palettes/SubstancePalette.d.ts +0 -9
- package/Voxels/Palettes/SubstancePalette.js +0 -11
- package/Voxels/Palettes/VoxelPalette.d.ts +0 -11
- package/Voxels/Palettes/VoxelPalette.js +0 -15
- package/Voxels/Segments/MaterialDataGenerator.d.ts +0 -6
- package/Voxels/Segments/MaterialDataGenerator.js +0 -12
- package/Voxels/Segments/SubstanceDataGenerator.d.ts +0 -6
- package/Voxels/Segments/SubstanceDataGenerator.js +0 -35
- package/Voxels/Segments/VoxelDataGenerator.d.ts +0 -10
- package/Voxels/Segments/VoxelDataGenerator.js +0 -56
- package/Voxels/Structs/Builder/SubstanceStructBuilder.d.ts +0 -2
- package/Voxels/Structs/Builder/SubstanceStructBuilder.js +0 -42
- package/Voxels/Structs/Builder/VoxelStructBuilder.d.ts +0 -2
- package/Voxels/Structs/Builder/VoxelStructBuilder.js +0 -68
- package/Voxels/Structs/SubstanceStruct.d.ts +0 -17
- package/Voxels/Structs/SubstanceStruct.js +0 -17
- package/Voxels/Structs/VoxelStruct.d.ts +0 -27
- package/Voxels/Structs/VoxelStruct.js +0 -29
- package/World/Section/SectionHeightMap.d.ts +0 -10
- package/World/Section/SectionHeightMap.js +0 -39
- package/World/Section/SectionStruct.d.ts +0 -8
- package/World/Section/SectionStruct.js +0 -29
- package/World/Section/SectionStructProperties.d.ts +0 -10
- package/World/Section/SectionStructProperties.js +0 -11
- package/World/Sector/SectorStruct.d.ts +0 -1
- package/World/Sector/SectorStruct.js +0 -46
- package/World/Sector/SectorStructIds.d.ts +0 -13
- package/World/Sector/SectorStructIds.js +0 -14
- package/World/Structs/WorldDataStructProperties.d.ts +0 -8
- package/World/Structs/WorldDataStructProperties.js +0 -9
- /package/Mesher/{VoxelShaderData.d.ts → Geomtry/VoxelShaderData.d.ts} +0 -0
- /package/Mesher/{VoxelShaderData.js → Geomtry/VoxelShaderData.js} +0 -0
- /package/{Data/Functions → Util/Binary}/Palettes.d.ts +0 -0
- /package/{Data/Functions → Util/Binary}/Palettes.js +0 -0
- /package/{Data/Structs/StructBuilder.types.js → Voxels/Cursor/DataCursor.interface.js} +0 -0
- /package/Voxels/{VoxelLevelReader.d.ts → Cursor/VoxelLevelReader.d.ts} +0 -0
- /package/Voxels/{VoxelLevelReader.js → Cursor/VoxelLevelReader.js} +0 -0
- /package/World/{Storage → Types}/WorldStorage.interface.d.ts +0 -0
- /package/World/{Storage → Types}/WorldStorage.interface.js +0 -0
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
|
-
}
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
export class TextureBuilder {
|
|
2
|
-
static context = null;
|
|
3
|
-
static _textureSize = 16;
|
|
4
|
-
static finalImagWidth = 16;
|
|
5
|
-
static finalImageHeight = 16;
|
|
6
|
-
static _canvas = document.createElement("canvas");
|
|
7
|
-
static defineTextureDimensions(textureSize) {
|
|
8
|
-
this.finalImagWidth = textureSize < 256 ? 256 : textureSize;
|
|
9
|
-
this.finalImageHeight = textureSize < 256 ? 256 : textureSize;
|
|
10
|
-
this._textureSize = textureSize;
|
|
11
|
-
}
|
|
12
|
-
static setUpImageCreation() {
|
|
13
|
-
this._canvas.width = this.finalImagWidth;
|
|
14
|
-
this._canvas.height = this.finalImageHeight;
|
|
15
|
-
const context = this._canvas.getContext("2d", { willReadFrequently: true });
|
|
16
|
-
if (!context) {
|
|
17
|
-
throw new Error("Context did not load for texture creation.");
|
|
18
|
-
}
|
|
19
|
-
document.body.append(this._canvas);
|
|
20
|
-
/* this._canvas.setAttribute(
|
|
21
|
-
"style",
|
|
22
|
-
`
|
|
23
|
-
image-rendering: pixelated;
|
|
24
|
-
position: absolute;
|
|
25
|
-
border: 1px solid red;
|
|
26
|
-
z-index: 1000;
|
|
27
|
-
top: 0;
|
|
28
|
-
`
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
*/
|
|
32
|
-
this.context = context;
|
|
33
|
-
}
|
|
34
|
-
static async createMaterialTexture(name, images, width = -1, height = -1) {
|
|
35
|
-
if (width == -1)
|
|
36
|
-
width = this.finalImagWidth;
|
|
37
|
-
if (height == -1)
|
|
38
|
-
height = this.finalImageHeight;
|
|
39
|
-
this._canvas.width = this.finalImagWidth;
|
|
40
|
-
this._canvas.height = this.finalImageHeight;
|
|
41
|
-
const resolvedImages = [];
|
|
42
|
-
for (const [path, rawData] of images) {
|
|
43
|
-
const data = await this.loadImage(rawData ? rawData : path, width, height);
|
|
44
|
-
resolvedImages.push(data);
|
|
45
|
-
}
|
|
46
|
-
return resolvedImages;
|
|
47
|
-
}
|
|
48
|
-
static async getRawData(imageSrc) {
|
|
49
|
-
return new Promise((resolve, reject) => {
|
|
50
|
-
const image = new Image();
|
|
51
|
-
image.crossOrigin = "Anonymous";
|
|
52
|
-
image.src = imageSrc;
|
|
53
|
-
image.onload = () => {
|
|
54
|
-
if (!this.context) {
|
|
55
|
-
return reject(new Error("Context is not set for texture creation."));
|
|
56
|
-
}
|
|
57
|
-
this._canvas.width = image.width;
|
|
58
|
-
this._canvas.height = image.height;
|
|
59
|
-
this.context.clearRect(0, 0, image.width, image.height);
|
|
60
|
-
this.context.drawImage(image, 0, 0, image.width, image.height);
|
|
61
|
-
const imgData = this.context.getImageData(0, 0, image.width, image.height);
|
|
62
|
-
resolve(imgData.data);
|
|
63
|
-
this._canvas.width = this.finalImagWidth;
|
|
64
|
-
this._canvas.height = this.finalImageHeight;
|
|
65
|
-
};
|
|
66
|
-
image.onerror = (err) => reject(err);
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
static async getBase64(imageSrc) {
|
|
70
|
-
return new Promise((resolve, reject) => {
|
|
71
|
-
const image = new Image();
|
|
72
|
-
image.crossOrigin = "Anonymous";
|
|
73
|
-
image.src = imageSrc;
|
|
74
|
-
image.onload = () => {
|
|
75
|
-
if (!this.context) {
|
|
76
|
-
return reject(new Error("Context is not set for texture creation."));
|
|
77
|
-
}
|
|
78
|
-
this._canvas.width = image.width;
|
|
79
|
-
this._canvas.height = image.height;
|
|
80
|
-
this.context.clearRect(0, 0, image.width, image.height);
|
|
81
|
-
this.context.drawImage(image, 0, 0, image.width, image.height);
|
|
82
|
-
resolve(this._canvas.toDataURL("image/png"));
|
|
83
|
-
this._canvas.width = this.finalImagWidth;
|
|
84
|
-
this._canvas.height = this.finalImageHeight;
|
|
85
|
-
};
|
|
86
|
-
image.onerror = (err) => reject(err);
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
static async loadImage(imgSrcData, width = 0, height = 0) {
|
|
90
|
-
if (!width)
|
|
91
|
-
width = this.finalImagWidth;
|
|
92
|
-
if (!height)
|
|
93
|
-
height = this.finalImageHeight;
|
|
94
|
-
const ctx = TextureBuilder.context;
|
|
95
|
-
if (!ctx) {
|
|
96
|
-
throw new Error("Context is not set for texture creation.");
|
|
97
|
-
}
|
|
98
|
-
const prom = new Promise((resolve) => {
|
|
99
|
-
const image = typeof imgSrcData == "string" ? new Image() : imgSrcData;
|
|
100
|
-
if (typeof imgSrcData == "string")
|
|
101
|
-
image.src = imgSrcData;
|
|
102
|
-
image.onload = () => {
|
|
103
|
-
ctx.clearRect(0, 0, this._canvas.width, this._canvas.height);
|
|
104
|
-
ctx.imageSmoothingEnabled = false;
|
|
105
|
-
ctx.save();
|
|
106
|
-
ctx.translate(0, this._canvas.height);
|
|
107
|
-
ctx.scale(1, -1);
|
|
108
|
-
ctx.drawImage(image, 0, 0, this._canvas.width, this._canvas.height);
|
|
109
|
-
ctx.restore();
|
|
110
|
-
const dataUrl = this._canvas.toDataURL("image/png");
|
|
111
|
-
const returnImage = new Image(this._canvas.width, this._canvas.height);
|
|
112
|
-
returnImage.src = dataUrl;
|
|
113
|
-
returnImage.onload = () => {
|
|
114
|
-
resolve(returnImage);
|
|
115
|
-
};
|
|
116
|
-
};
|
|
117
|
-
});
|
|
118
|
-
return prom;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { TextureTypeUVMap, TextureId } from "./Texture.types";
|
|
2
|
-
export declare class TextureRegister {
|
|
3
|
-
static textureDataHasBeenSet: boolean;
|
|
4
|
-
static data: TextureTypeUVMap;
|
|
5
|
-
static getTextureUV(data: TextureId): number;
|
|
6
|
-
static setTextureIndex(data: TextureTypeUVMap): void;
|
|
7
|
-
static releaseTextureData(): void;
|
|
8
|
-
static isReady(): boolean;
|
|
9
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
export class TextureRegister {
|
|
2
|
-
static textureDataHasBeenSet = false;
|
|
3
|
-
static data;
|
|
4
|
-
static getTextureUV(data) {
|
|
5
|
-
const [textureType, textureId, varation] = data;
|
|
6
|
-
let id = textureId;
|
|
7
|
-
if (varation) {
|
|
8
|
-
id = `${textureId}:${varation}`;
|
|
9
|
-
}
|
|
10
|
-
let uv = -1;
|
|
11
|
-
uv = this.data[textureType][id];
|
|
12
|
-
if (uv == -1) {
|
|
13
|
-
throw new Error(`Texture with id: ${id} does not exists.`);
|
|
14
|
-
}
|
|
15
|
-
return uv;
|
|
16
|
-
}
|
|
17
|
-
static setTextureIndex(data) {
|
|
18
|
-
this.textureDataHasBeenSet = true;
|
|
19
|
-
this.data = data;
|
|
20
|
-
}
|
|
21
|
-
static releaseTextureData() {
|
|
22
|
-
this.data = null;
|
|
23
|
-
delete this["data"];
|
|
24
|
-
}
|
|
25
|
-
static isReady() {
|
|
26
|
-
return this.textureDataHasBeenSet;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { SubstanceStruct } from "../../Voxels/Structs/SubstanceStruct.js";
|
|
2
|
-
export declare class SubstanceDataTool {
|
|
3
|
-
static tags: typeof SubstanceStruct;
|
|
4
|
-
substanceTagIndex: number;
|
|
5
|
-
setSubstanceFromString(substance: string): this;
|
|
6
|
-
setSubstance(substance: number): this;
|
|
7
|
-
getSubstanceStringId(): string;
|
|
8
|
-
isSolid(): boolean;
|
|
9
|
-
isLiquid(): boolean;
|
|
10
|
-
isWindAffected(): boolean;
|
|
11
|
-
getParent(): string;
|
|
12
|
-
getFlowRate(): number;
|
|
13
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { SubstancePalette } from "../../Voxels/Palettes/SubstancePalette.js";
|
|
2
|
-
import { MappedDataRegister } from "../../Data/Register/MappedDataRegister.js";
|
|
3
|
-
import { SubstanceStructIds } from "../../Voxels/Types/VoxelSubstances.types.js";
|
|
4
|
-
import { SubstanceStruct } from "../../Voxels/Structs/SubstanceStruct.js";
|
|
5
|
-
export class SubstanceDataTool {
|
|
6
|
-
static tags = SubstanceStruct;
|
|
7
|
-
//substance = "";
|
|
8
|
-
substanceTagIndex = 0;
|
|
9
|
-
setSubstanceFromString(substance) {
|
|
10
|
-
// this.substance = substance;
|
|
11
|
-
this.substanceTagIndex = SubstancePalette.id.numberFromString(substance);
|
|
12
|
-
SubstanceStruct.setSubstance(this.substanceTagIndex);
|
|
13
|
-
return this;
|
|
14
|
-
}
|
|
15
|
-
setSubstance(substance) {
|
|
16
|
-
// this.substance = substance;
|
|
17
|
-
this.substanceTagIndex = substance;
|
|
18
|
-
SubstanceStruct.setSubstance(this.substanceTagIndex);
|
|
19
|
-
return this;
|
|
20
|
-
}
|
|
21
|
-
getSubstanceStringId() {
|
|
22
|
-
return SubstancePalette.id.stringFromNumber(this.substanceTagIndex);
|
|
23
|
-
}
|
|
24
|
-
/* isTransparent() {
|
|
25
|
-
return SubstanceStruct.instance[SubstanceStructIds.isTransparent] == 1;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
*/
|
|
29
|
-
isSolid() {
|
|
30
|
-
return SubstanceStruct.instance[SubstanceStructIds.isSolid] == 1;
|
|
31
|
-
}
|
|
32
|
-
isLiquid() {
|
|
33
|
-
return SubstanceStruct.instance[SubstanceStructIds.isLiquid] == 1;
|
|
34
|
-
}
|
|
35
|
-
isWindAffected() {
|
|
36
|
-
return SubstanceStruct.instance[SubstanceStructIds.isWindAffected] == 1;
|
|
37
|
-
}
|
|
38
|
-
/* isOpaque() {
|
|
39
|
-
return this.isSolid() && !this.isTransparent();
|
|
40
|
-
}
|
|
41
|
-
*/
|
|
42
|
-
/* allowLight() {
|
|
43
|
-
return this.isTransparent();
|
|
44
|
-
} */
|
|
45
|
-
getParent() {
|
|
46
|
-
return MappedDataRegister.stringMaps.get("substance", SubstanceStructIds.parent, SubstanceStruct.instance[SubstanceStructIds.parent]);
|
|
47
|
-
}
|
|
48
|
-
getFlowRate() {
|
|
49
|
-
return SubstanceStruct.instance[SubstanceStructIds.flowRate];
|
|
50
|
-
}
|
|
51
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { StringPalette } from "../../Util/StringPalette";
|
|
2
|
-
export declare class MaterialPalette {
|
|
3
|
-
static palette: StringPalette;
|
|
4
|
-
static setPalette(palette: string[]): void;
|
|
5
|
-
static id: {
|
|
6
|
-
stringFromNumber: (id: number) => string;
|
|
7
|
-
numberFromString: (id: string) => number;
|
|
8
|
-
};
|
|
9
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { StringPalette } from "../../Util/StringPalette";
|
|
2
|
-
export class MaterialPalette {
|
|
3
|
-
static palette;
|
|
4
|
-
static setPalette(palette) {
|
|
5
|
-
this.palette = new StringPalette(palette);
|
|
6
|
-
}
|
|
7
|
-
static id = {
|
|
8
|
-
stringFromNumber: (id) => this.palette.getStringId(id),
|
|
9
|
-
numberFromString: (id) => this.palette.getNumberId(id),
|
|
10
|
-
};
|
|
11
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { StringPalette } from "../../Util/StringPalette";
|
|
2
|
-
export declare class SubstancePalette {
|
|
3
|
-
static palette: StringPalette;
|
|
4
|
-
static setPalette(palette: string[]): void;
|
|
5
|
-
static id: {
|
|
6
|
-
stringFromNumber: (id: number) => string;
|
|
7
|
-
numberFromString: (id: string) => number;
|
|
8
|
-
};
|
|
9
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { StringPalette } from "../../Util/StringPalette";
|
|
2
|
-
export class SubstancePalette {
|
|
3
|
-
static palette;
|
|
4
|
-
static setPalette(palette) {
|
|
5
|
-
this.palette = new StringPalette(palette);
|
|
6
|
-
}
|
|
7
|
-
static id = {
|
|
8
|
-
stringFromNumber: (id) => this.palette.getStringId(id),
|
|
9
|
-
numberFromString: (id) => this.palette.getNumberId(id),
|
|
10
|
-
};
|
|
11
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { StringPalette } from "../../Util/StringPalette";
|
|
2
|
-
export declare class VoxelPalette {
|
|
3
|
-
static _nameToIdMap: Map<string, string>;
|
|
4
|
-
static _idToNameMap: Map<string, string>;
|
|
5
|
-
static ids: StringPalette;
|
|
6
|
-
static loadIn(voxelPalette: string[], nameToIdMap: Record<string, string>, idToNameMap: Record<string, string>): void;
|
|
7
|
-
static name: {
|
|
8
|
-
getId: (name: string) => string;
|
|
9
|
-
getName: (id: string) => string;
|
|
10
|
-
};
|
|
11
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { StringPalette } from "../../Util/StringPalette";
|
|
2
|
-
export class VoxelPalette {
|
|
3
|
-
static _nameToIdMap = new Map();
|
|
4
|
-
static _idToNameMap = new Map();
|
|
5
|
-
static ids;
|
|
6
|
-
static loadIn(voxelPalette, nameToIdMap, idToNameMap) {
|
|
7
|
-
this.ids = new StringPalette(voxelPalette);
|
|
8
|
-
this._nameToIdMap = new Map(Object.entries(nameToIdMap));
|
|
9
|
-
this._idToNameMap = new Map(Object.entries(idToNameMap));
|
|
10
|
-
}
|
|
11
|
-
static name = {
|
|
12
|
-
getId: (name) => this._nameToIdMap.get(name),
|
|
13
|
-
getName: (id) => this._idToNameMap.get(id),
|
|
14
|
-
};
|
|
15
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { MaterialPalette } from "../Palettes/MaterialPalette";
|
|
2
|
-
import { StringPalette } from "../../Util/StringPalette";
|
|
3
|
-
export const MaterialDataGenerator = {
|
|
4
|
-
generate(data) {
|
|
5
|
-
//build palette
|
|
6
|
-
for (const substance of data) {
|
|
7
|
-
this.palette.register(substance.id);
|
|
8
|
-
}
|
|
9
|
-
MaterialPalette.setPalette(this.palette._palette);
|
|
10
|
-
},
|
|
11
|
-
palette: new StringPalette(),
|
|
12
|
-
};
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { SubstancePalette } from "../Palettes/SubstancePalette";
|
|
2
|
-
import { StringPalette } from "../../Util/StringPalette";
|
|
3
|
-
import { SubstanceStructBuilder } from "../Structs/Builder/SubstanceStructBuilder";
|
|
4
|
-
import { SubstanceStruct } from "..//Structs/SubstanceStruct";
|
|
5
|
-
export const SubstanceDataGenerator = {
|
|
6
|
-
generate(data) {
|
|
7
|
-
//build palette
|
|
8
|
-
for (const substance of data) {
|
|
9
|
-
this.palette.register(substance.id);
|
|
10
|
-
}
|
|
11
|
-
SubstancePalette.setPalette(this.palette._palette);
|
|
12
|
-
//create data buffer
|
|
13
|
-
const tags = SubstanceStructBuilder.build(this.palette.size);
|
|
14
|
-
const buffer = new SharedArrayBuffer(tags.structData.bufferSize);
|
|
15
|
-
tags.structData.buffer = buffer;
|
|
16
|
-
tags.setBuffer(buffer);
|
|
17
|
-
//build data
|
|
18
|
-
for (const substance of data) {
|
|
19
|
-
const substanceID = SubstancePalette.id.numberFromString(substance.id);
|
|
20
|
-
if (typeof substanceID == undefined)
|
|
21
|
-
continue;
|
|
22
|
-
tags.setStructArrayIndex(substanceID);
|
|
23
|
-
SubstanceStructBuilder.setDefaults(tags);
|
|
24
|
-
for (const id in substance.properties) {
|
|
25
|
-
const value = substance.properties[id];
|
|
26
|
-
if (!SubstanceStructBuilder.hasNode(id))
|
|
27
|
-
continue;
|
|
28
|
-
SubstanceStructBuilder.setNode(id, value, tags);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
SubstanceStruct.init(tags.structData);
|
|
32
|
-
SubstanceStruct.instance.setBuffer(buffer);
|
|
33
|
-
},
|
|
34
|
-
palette: new StringPalette(),
|
|
35
|
-
};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { BinaryStruct } from "@amodx/binary";
|
|
2
|
-
import { StringPalette } from "../../Util/StringPalette";
|
|
3
|
-
import { VoxelData } from "../Types/Voxel.types";
|
|
4
|
-
export declare class VoxelDataGenerator {
|
|
5
|
-
static overrides: Map<string, (tags: BinaryStruct, value: unknown, id: string) => void>;
|
|
6
|
-
static nameToIdMap: Record<string, string>;
|
|
7
|
-
static idToNameMap: Record<string, string>;
|
|
8
|
-
static generate(data: VoxelData[]): void;
|
|
9
|
-
static palette: StringPalette;
|
|
10
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
//objects
|
|
2
|
-
import { VoxelStructBuilder } from "../Structs/Builder/VoxelStructBuilder";
|
|
3
|
-
import { VoxelPalette } from "../Palettes/VoxelPalette";
|
|
4
|
-
import { VoxelStruct } from "../Structs/VoxelStruct";
|
|
5
|
-
import { StringPalette } from "../../Util/StringPalette";
|
|
6
|
-
export class VoxelDataGenerator {
|
|
7
|
-
static overrides = new Map();
|
|
8
|
-
static nameToIdMap = {};
|
|
9
|
-
static idToNameMap = {};
|
|
10
|
-
static generate(data) {
|
|
11
|
-
//build palette
|
|
12
|
-
for (const voxel of data) {
|
|
13
|
-
if (this.palette.isRegistered(voxel.id))
|
|
14
|
-
throw new Error(`Duplicate voxel id ${voxel.id}`);
|
|
15
|
-
this.palette.register(voxel.id);
|
|
16
|
-
this.nameToIdMap[voxel.name ? voxel.name : voxel.id] = voxel.id;
|
|
17
|
-
this.idToNameMap[voxel.id] = voxel.name ? voxel.name : voxel.id;
|
|
18
|
-
}
|
|
19
|
-
VoxelPalette.loadIn(this.palette._palette, this.nameToIdMap, this.idToNameMap);
|
|
20
|
-
//build index
|
|
21
|
-
const indexBuffer = new SharedArrayBuffer(this.palette.size * 2);
|
|
22
|
-
const voxelIndex = new Uint16Array(indexBuffer);
|
|
23
|
-
for (let i = 0; i < this.palette.size; i++) {
|
|
24
|
-
voxelIndex[i] = i;
|
|
25
|
-
}
|
|
26
|
-
//create data bufferv
|
|
27
|
-
const tags = VoxelStructBuilder.build(this.palette.size);
|
|
28
|
-
const buffer = new SharedArrayBuffer(tags.structData.bufferSize);
|
|
29
|
-
tags.structData.buffer = buffer;
|
|
30
|
-
tags.setBuffer(buffer);
|
|
31
|
-
// VoxelStruct.init(initData);
|
|
32
|
-
// VoxelStruct.setBuffer(buffer);
|
|
33
|
-
//build data
|
|
34
|
-
for (const voxel of data) {
|
|
35
|
-
const baseID = VoxelPalette.ids.getNumberId(voxel.id);
|
|
36
|
-
if (!baseID)
|
|
37
|
-
continue;
|
|
38
|
-
tags.setStructArrayIndex(voxelIndex[baseID]);
|
|
39
|
-
VoxelStructBuilder.setDefaults(tags);
|
|
40
|
-
for (const id in voxel.properties) {
|
|
41
|
-
const value = voxel.properties[id];
|
|
42
|
-
if (!VoxelStructBuilder.hasNode(id))
|
|
43
|
-
continue;
|
|
44
|
-
if (this.overrides.has(id)) {
|
|
45
|
-
this.overrides.get(id)(tags, value, id);
|
|
46
|
-
continue;
|
|
47
|
-
}
|
|
48
|
-
VoxelStructBuilder.setNode(id, value, tags);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
VoxelStruct.sync(voxelIndex);
|
|
52
|
-
VoxelStruct.init(tags.structData);
|
|
53
|
-
VoxelStruct.instance.setBuffer(buffer);
|
|
54
|
-
}
|
|
55
|
-
static palette = new StringPalette();
|
|
56
|
-
}
|