@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
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export class CompiledTextureAnimation {
|
|
2
|
+
textureIndex;
|
|
3
|
+
_frames = [];
|
|
4
|
+
_times = [];
|
|
5
|
+
_currentTime = 0;
|
|
6
|
+
_frameIndex = 0;
|
|
7
|
+
_current = Infinity;
|
|
8
|
+
_animatedTextureIndex = -1;
|
|
9
|
+
constructor(textureIndex) {
|
|
10
|
+
this.textureIndex = textureIndex;
|
|
11
|
+
}
|
|
12
|
+
tick(delta) {
|
|
13
|
+
if (this._current == Infinity)
|
|
14
|
+
this._current = this._times[0];
|
|
15
|
+
this._current -= delta;
|
|
16
|
+
if (this._current <= 0) {
|
|
17
|
+
this._frameIndex++;
|
|
18
|
+
this._frameIndex %= this._frames.length;
|
|
19
|
+
this._current = this._times[this._frameIndex];
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
getIndex() {
|
|
25
|
+
return this._frames[this._frameIndex] + this.textureIndex;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CompiledTexture } from "./CompiledTexture";
|
|
2
|
+
export declare class TextureAnimationTexture {
|
|
3
|
+
_texture: CompiledTexture;
|
|
4
|
+
_buffer: Uint16Array;
|
|
5
|
+
_size: number;
|
|
6
|
+
shaderTexture: any;
|
|
7
|
+
constructor(_texture: CompiledTexture);
|
|
8
|
+
build(): Uint16Array;
|
|
9
|
+
tick(delta: number): boolean;
|
|
10
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { CompiledTexture } from "./CompiledTexture";
|
|
2
|
+
export class TextureAnimationTexture {
|
|
3
|
+
_texture;
|
|
4
|
+
_buffer;
|
|
5
|
+
_size = 0;
|
|
6
|
+
shaderTexture;
|
|
7
|
+
constructor(_texture) {
|
|
8
|
+
this._texture = _texture;
|
|
9
|
+
}
|
|
10
|
+
build() {
|
|
11
|
+
const totalTexture = this._texture.images.length;
|
|
12
|
+
const size = Math.pow(2, Math.ceil(Math.log2(Math.ceil(Math.sqrt(totalTexture)))));
|
|
13
|
+
this._size = size;
|
|
14
|
+
this._buffer = new Uint16Array(size * size);
|
|
15
|
+
for (let i = 0; i < this._texture.animations.length; i++) {
|
|
16
|
+
const anim = this._texture.animations[i];
|
|
17
|
+
anim._animatedTextureIndex = CompiledTexture.GetAtlasIndex(...CompiledTexture.GetAtlasPosition(anim.textureIndex, this._size), this._size);
|
|
18
|
+
}
|
|
19
|
+
return this._buffer;
|
|
20
|
+
}
|
|
21
|
+
tick(delta) {
|
|
22
|
+
let update = false;
|
|
23
|
+
for (let i = 0; i < this._texture.animations.length; i++) {
|
|
24
|
+
const anim = this._texture.animations[i];
|
|
25
|
+
if (anim.tick(delta)) {
|
|
26
|
+
update = true;
|
|
27
|
+
this._buffer[anim._animatedTextureIndex] = anim.getIndex();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return update;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CompiledTexture } from "../Classes/CompiledTexture";
|
|
2
|
+
import { TextureData } from "../../Textures/Texture.types";
|
|
3
|
+
export type BuildTextureDataProps = {
|
|
4
|
+
type: string;
|
|
5
|
+
baseURL?: string;
|
|
6
|
+
createCache?: boolean;
|
|
7
|
+
textures: TextureData[];
|
|
8
|
+
finalSize?: [width: number, height: number];
|
|
9
|
+
};
|
|
10
|
+
export declare function BuildTextureData({ type, baseURL: currentBaseURL, textures, finalSize: currentFinalSize, createCache, }: BuildTextureDataProps): Promise<CompiledTexture>;
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { CompiledTexture } from "../Classes/CompiledTexture";
|
|
2
|
+
import { CompiledTextureAnimation } from "../../Textures/Classes/CompiledTextureAnimation";
|
|
3
|
+
let baseURL = "assets/textures";
|
|
4
|
+
let canvas;
|
|
5
|
+
let context;
|
|
6
|
+
let atlasCanvas;
|
|
7
|
+
let atlasContext;
|
|
8
|
+
const finalSize = [256, 256];
|
|
9
|
+
async function getImageBase64(url) {
|
|
10
|
+
const response = await fetch(url);
|
|
11
|
+
const blob = await response.blob();
|
|
12
|
+
return new Promise((resolve, reject) => {
|
|
13
|
+
const reader = new FileReader();
|
|
14
|
+
reader.readAsDataURL(blob);
|
|
15
|
+
reader.onloadend = () => resolve(reader.result);
|
|
16
|
+
reader.onerror = reject;
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
function loadImage(src) {
|
|
20
|
+
return new Promise((resolve, reject) => {
|
|
21
|
+
const img = new Image();
|
|
22
|
+
img.src = src;
|
|
23
|
+
img.onload = () => resolve(img);
|
|
24
|
+
img.onerror = reject;
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
async function sliceImageIntoTiles(src, tilesX, tilesY) {
|
|
28
|
+
const image = await loadImage(src);
|
|
29
|
+
const tileWidth = image.width / tilesX;
|
|
30
|
+
const tileHeight = image.height / tilesY;
|
|
31
|
+
atlasCanvas.width = tileWidth;
|
|
32
|
+
atlasCanvas.height = tileHeight;
|
|
33
|
+
const tiles = [];
|
|
34
|
+
for (let x = 0; x < tilesX; x++) {
|
|
35
|
+
for (let y = 0; y < tilesY; y++) {
|
|
36
|
+
atlasContext.clearRect(0, 0, tileWidth, tileHeight);
|
|
37
|
+
atlasContext.drawImage(image, x * tileWidth, y * tileHeight, tileWidth, tileHeight, 0, 0, tileWidth, tileHeight);
|
|
38
|
+
tiles[CompiledTexture.GetAtlasIndex(x, y, tilesX)] =
|
|
39
|
+
atlasCanvas.toDataURL("image/png");
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return tiles;
|
|
43
|
+
}
|
|
44
|
+
async function loadImageForShader(imgSrcData) {
|
|
45
|
+
if (!context)
|
|
46
|
+
throw new Error("");
|
|
47
|
+
canvas.width = finalSize[0];
|
|
48
|
+
canvas.height = finalSize[1];
|
|
49
|
+
const prom = new Promise((resolve, reject) => {
|
|
50
|
+
const image = typeof imgSrcData == "string" ? new Image() : imgSrcData;
|
|
51
|
+
image.onerror = (error) => reject(error);
|
|
52
|
+
if (typeof imgSrcData == "string")
|
|
53
|
+
image.src = imgSrcData;
|
|
54
|
+
image.onload = () => {
|
|
55
|
+
context.clearRect(0, 0, canvas.width, canvas.height);
|
|
56
|
+
context.imageSmoothingEnabled = false;
|
|
57
|
+
context.save();
|
|
58
|
+
context.translate(0, canvas.height);
|
|
59
|
+
context.scale(1, -1);
|
|
60
|
+
context.drawImage(image, 0, 0, canvas.width, canvas.height);
|
|
61
|
+
context.restore();
|
|
62
|
+
const dataUrl = canvas.toDataURL("image/png");
|
|
63
|
+
const returnImage = new Image(canvas.width, canvas.height);
|
|
64
|
+
returnImage.src = dataUrl;
|
|
65
|
+
returnImage.onload = () => {
|
|
66
|
+
resolve(returnImage);
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
});
|
|
70
|
+
return prom;
|
|
71
|
+
}
|
|
72
|
+
function getImagePath(data, parentId = null) {
|
|
73
|
+
if (data.base64)
|
|
74
|
+
return data.base64;
|
|
75
|
+
if (data.path)
|
|
76
|
+
return data.path;
|
|
77
|
+
if (!parentId)
|
|
78
|
+
return `${baseURL}/${data.id}.png`;
|
|
79
|
+
return `${baseURL}/${parentId}/${data.id}.png`;
|
|
80
|
+
}
|
|
81
|
+
function getTextureId(data, parentId = null) {
|
|
82
|
+
return `${parentId ? parentId : data.id}${!parentId ? "" : ":" + data.id}`;
|
|
83
|
+
}
|
|
84
|
+
function createAnimationData(atlas, data, startIndex) {
|
|
85
|
+
const compiled = new CompiledTextureAnimation(startIndex);
|
|
86
|
+
if (!data?.frames) {
|
|
87
|
+
const maxFrames = atlas.tiles[0] * atlas.tiles[1];
|
|
88
|
+
for (let i = 0; i < maxFrames; i++) {
|
|
89
|
+
compiled._frames[i] = i;
|
|
90
|
+
compiled._times[i] = data.frameTime;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
for (let i = 0; i < data.frames.length; i++) {
|
|
95
|
+
const frameData = data.frames[i];
|
|
96
|
+
if (typeof frameData == "number") {
|
|
97
|
+
compiled._frames[i] = frameData;
|
|
98
|
+
compiled._times[i] = data.frameTime;
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
compiled._frames[i] = frameData.index;
|
|
102
|
+
compiled._times[i] = frameData.time;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (data?.pingPong) {
|
|
106
|
+
compiled._frames = [
|
|
107
|
+
...compiled._frames,
|
|
108
|
+
...compiled._frames.toReversed().slice(1, compiled._frames.length - 1),
|
|
109
|
+
];
|
|
110
|
+
compiled._times = [
|
|
111
|
+
...compiled._times,
|
|
112
|
+
...compiled._times.toReversed().slice(1, compiled._times.length - 1),
|
|
113
|
+
];
|
|
114
|
+
}
|
|
115
|
+
return compiled;
|
|
116
|
+
}
|
|
117
|
+
async function process(compiled, data, textureIndex, parent, cache = false) {
|
|
118
|
+
const textureId = getTextureId(data, parent);
|
|
119
|
+
compiled.textureMap[textureId] = textureIndex;
|
|
120
|
+
const imagePath = getImagePath(data, parent);
|
|
121
|
+
if (cache) {
|
|
122
|
+
data.base64 = await getImageBase64(imagePath);
|
|
123
|
+
}
|
|
124
|
+
if (!data.atlas) {
|
|
125
|
+
compiled.images[textureIndex] = await loadImageForShader(imagePath);
|
|
126
|
+
return textureIndex + 1;
|
|
127
|
+
}
|
|
128
|
+
const tiles = await sliceImageIntoTiles(imagePath, ...data.atlas.tiles);
|
|
129
|
+
for (let i = 0; i < tiles.length; i++) {
|
|
130
|
+
compiled.images[textureIndex + i] = await loadImageForShader(tiles[i]);
|
|
131
|
+
}
|
|
132
|
+
compiled.atlasSizeMap[textureId] = data.atlas.tiles;
|
|
133
|
+
if (data.animated) {
|
|
134
|
+
compiled.animations.push(createAnimationData(data.atlas, data.animated, textureIndex));
|
|
135
|
+
}
|
|
136
|
+
if (data.atlas.namedTiles) {
|
|
137
|
+
for (const named of data.atlas.namedTiles) {
|
|
138
|
+
let tIndex = Array.isArray(named.index)
|
|
139
|
+
? CompiledTexture.GetAtlasIndex(...named.index, data.atlas.tiles[0])
|
|
140
|
+
: named.index;
|
|
141
|
+
compiled.textureMap[`${textureId}:${named.id}`] = textureIndex + tIndex;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return textureIndex + tiles.length;
|
|
145
|
+
}
|
|
146
|
+
export async function BuildTextureData({ type, baseURL: currentBaseURL, textures, finalSize: currentFinalSize, createCache, }) {
|
|
147
|
+
baseURL = currentBaseURL || "assets/textures";
|
|
148
|
+
finalSize[0] = currentFinalSize ? currentFinalSize[0] : 256;
|
|
149
|
+
finalSize[1] = currentFinalSize ? currentFinalSize[1] : 256;
|
|
150
|
+
if (!canvas) {
|
|
151
|
+
canvas = document.createElement("canvas");
|
|
152
|
+
canvas.width = finalSize[0];
|
|
153
|
+
canvas.height = finalSize[1];
|
|
154
|
+
context = canvas.getContext("2d", { willReadFrequently: true });
|
|
155
|
+
context.imageSmoothingEnabled = false;
|
|
156
|
+
atlasCanvas = document.createElement("canvas");
|
|
157
|
+
atlasContext = atlasCanvas.getContext("2d", { willReadFrequently: true });
|
|
158
|
+
// atlasContext.imageSmoothingEnabled = false;
|
|
159
|
+
if (!context)
|
|
160
|
+
throw new Error(`Error could not create CanvasRenderingContext2D`);
|
|
161
|
+
}
|
|
162
|
+
const compiled = new CompiledTexture(type);
|
|
163
|
+
let count = 0;
|
|
164
|
+
for (const texture of textures) {
|
|
165
|
+
if (!texture.variations?.length) {
|
|
166
|
+
try {
|
|
167
|
+
count = await process(compiled, texture, count, null, createCache);
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
catch (error) {
|
|
171
|
+
console.warn(`Could not load texture ${texture.id}`);
|
|
172
|
+
console.error(error);
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
if (texture.variations) {
|
|
177
|
+
for (let i = 0; i < texture.variations.length; i++) {
|
|
178
|
+
const vara = texture.variations[i];
|
|
179
|
+
if (typeof vara == "string") {
|
|
180
|
+
const newData = { type: texture.type, id: vara };
|
|
181
|
+
try {
|
|
182
|
+
count = await process(compiled, newData, count, texture.id, createCache);
|
|
183
|
+
if (createCache)
|
|
184
|
+
texture.variations[i] = newData;
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
catch (error) {
|
|
188
|
+
console.warn(`Could not load texture ${texture.id}`);
|
|
189
|
+
console.error(error);
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
try {
|
|
194
|
+
count = await process(compiled, vara, count, texture.id, createCache);
|
|
195
|
+
}
|
|
196
|
+
catch (error) {
|
|
197
|
+
console.warn(`Could not load texture ${texture.id}`);
|
|
198
|
+
console.error(error);
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return compiled;
|
|
205
|
+
}
|
|
@@ -1,76 +1,62 @@
|
|
|
1
|
-
export type TextureId = [
|
|
2
|
-
export type TextureTypes = string;
|
|
1
|
+
export type TextureId = [id: string, frame: [x: number, y: number]] | [id: string, index: number] | [id: string, varation: string] | [id: string, varation: string, frame: [x: number, y: number]] | [id: string, varation: string, index: number] | string;
|
|
3
2
|
export type TextureTypeUVMap = Record<string, Record<string, number>>;
|
|
4
|
-
export type TextureAnimationData = {
|
|
5
|
-
/**# Frames
|
|
6
|
-
* If the texture has animation frames the number of frames must be set to the number
|
|
7
|
-
* texture animatoin images. This number must be greater than 1.
|
|
8
|
-
*
|
|
9
|
-
* The number will be used to locate all the associated frames.
|
|
10
|
-
*
|
|
11
|
-
* Example: If you specify 3 frames for a texture with the ID **dreamstone** the folder would look like this:
|
|
12
|
-
* - dreamstone/default-1.png
|
|
13
|
-
* - dreamstone/default-2.png
|
|
14
|
-
* - dreamstone/default-3.png
|
|
15
|
-
*/
|
|
16
|
-
frames: number;
|
|
17
|
-
/**# Anim Keys
|
|
18
|
-
* If the texture is animated you must supply the anim key frames which
|
|
19
|
-
* is just the order of the frames.
|
|
20
|
-
*/
|
|
21
|
-
animKeys?: number[];
|
|
22
|
-
/**# Global Frame Time
|
|
23
|
-
* ---
|
|
24
|
-
* Specifies how many frames every anim key should be display.
|
|
25
|
-
*/
|
|
26
|
-
globalFrameTime?: number;
|
|
27
|
-
/**# Anim Key Frame Time
|
|
28
|
-
* ---
|
|
29
|
-
* If set globalFrameTime will be ignored.
|
|
30
|
-
* Specifies how many frames every anim should be displayed.
|
|
31
|
-
* You must supply a number for every animKey.
|
|
32
|
-
*/
|
|
33
|
-
animKeyFrameTimes?: number[];
|
|
34
|
-
};
|
|
35
3
|
export type TextureDataBase = {
|
|
36
|
-
|
|
37
|
-
* Provide a Uint8ClampedArray or an array of Uint8ClampedArray's instead of downloading
|
|
38
|
-
*/
|
|
39
|
-
rawData?: Uint8ClampedArray | Uint8ClampedArray[];
|
|
40
|
-
/**# base64
|
|
41
|
-
* Provide a base64 encoded string to use instead of downloading
|
|
42
|
-
*/
|
|
43
|
-
base64?: string | string[];
|
|
44
|
-
/**# includeInRawDataMap
|
|
45
|
-
* Will keep a Uint8ClampedArray of the loaded texture if set to true.
|
|
46
|
-
*/
|
|
47
|
-
includeInRawDataMap?: boolean;
|
|
48
|
-
};
|
|
49
|
-
export type TextureData = {
|
|
50
|
-
type: TextureTypes;
|
|
51
|
-
/**# ID
|
|
4
|
+
/**
|
|
52
5
|
* The id of the texture.
|
|
53
|
-
* This will be used to locate the file.
|
|
6
|
+
* This will be used to locate the file if no direct path is given.
|
|
54
7
|
*/
|
|
55
8
|
id: string;
|
|
56
|
-
|
|
9
|
+
/**
|
|
57
10
|
* If the texture is not in the default path specify it here.
|
|
58
11
|
*/
|
|
59
12
|
path?: string;
|
|
60
|
-
|
|
61
|
-
*
|
|
13
|
+
/**
|
|
14
|
+
* Provide a base64 encoded string to use instead of downloading
|
|
62
15
|
*/
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
*
|
|
66
|
-
|
|
16
|
+
base64?: string;
|
|
17
|
+
/**
|
|
18
|
+
* If the texture is an atlas specify it here.
|
|
19
|
+
*/
|
|
20
|
+
atlas?: {
|
|
21
|
+
tiles: [tilesX: number, tilesY: number];
|
|
22
|
+
/**To make it eaiser to use specifc tiles from an atlas you can name tiles.
|
|
23
|
+
*
|
|
24
|
+
* To use the name just at it to the end of the id with a colon ":".
|
|
25
|
+
*
|
|
26
|
+
* dve_dream_stone:grassy-top
|
|
27
|
+
*/
|
|
28
|
+
namedTiles?: {
|
|
29
|
+
id: string;
|
|
30
|
+
index: [tileX: number, tileY: number] | number;
|
|
31
|
+
}[];
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* If the texture is an animated speicfy it here.
|
|
35
|
+
* Only atlas texture can be animated.
|
|
36
|
+
*/
|
|
37
|
+
animated?: {
|
|
38
|
+
frameTime: number;
|
|
39
|
+
pingPong?: boolean;
|
|
40
|
+
interpolate?: boolean;
|
|
41
|
+
frames?: (number | {
|
|
42
|
+
index: number;
|
|
43
|
+
time: number;
|
|
44
|
+
})[];
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
export type TextureData = {
|
|
48
|
+
/**
|
|
49
|
+
* The type of texture. Used to combined all textures into one final one.
|
|
67
50
|
*
|
|
68
|
-
*
|
|
69
|
-
|
|
51
|
+
* Defaults to dve_voxel
|
|
52
|
+
*/
|
|
53
|
+
type?: string;
|
|
54
|
+
/**
|
|
55
|
+
* Add textures to the same texture that can be refernced with a TextureId.
|
|
70
56
|
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
57
|
+
* If not directly giving paths the main texture must be named default
|
|
58
|
+
* and all varations must be in the same folder and be the name of the key they
|
|
59
|
+
* are stored in the variations object.
|
|
74
60
|
*/
|
|
75
|
-
variations?:
|
|
76
|
-
} &
|
|
61
|
+
variations?: (string | TextureDataBase)[];
|
|
62
|
+
} & TextureDataBase;
|
|
@@ -1,21 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import { CompiledTexture } from "./Classes/CompiledTexture.js";
|
|
2
|
+
import { BuildTextureDataProps } from "./Functions/BuildTextureData.js";
|
|
3
|
+
import type { TextureData } from "./Texture.types";
|
|
3
4
|
export declare class TextureManager {
|
|
4
|
-
static
|
|
5
|
-
static
|
|
6
|
-
static
|
|
7
|
-
static
|
|
8
|
-
static
|
|
9
|
-
static init(): Promise<void>;
|
|
10
|
-
static generateTextureUVMap(): TextureTypeUVMap;
|
|
11
|
-
static defineDefaultTexturePath(path: string): void;
|
|
12
|
-
static getTextureData([type, id, segment]: TextureId): TextureData | undefined;
|
|
13
|
-
static getTextureType(id: string): false | TextureArray;
|
|
14
|
-
static getOrAddTextureType(id: string): TextureArray;
|
|
15
|
-
static addTextureType(id: string): TextureArray;
|
|
16
|
-
static clearTextureData(): void;
|
|
17
|
-
static registerTexture(textureData: TextureData | TextureData[]): void;
|
|
18
|
-
static getTexturePath(textureType: string, id: string, varation: string, segment?: string, frames?: number): string;
|
|
19
|
-
static createCached(): Promise<TextureData[]>;
|
|
20
|
-
static createRawDataMap(): Promise<Map<string, Uint8ClampedArray>>;
|
|
5
|
+
static _textureTypes: Map<string, TextureData[]>;
|
|
6
|
+
static _compiledTextures: Map<string, CompiledTexture>;
|
|
7
|
+
static registerTexture(textureData: TextureData[]): void;
|
|
8
|
+
static getTexture(id: string): CompiledTexture;
|
|
9
|
+
static compiledTextures(props?: Omit<BuildTextureDataProps, "textures" | "type">): Promise<void>;
|
|
21
10
|
}
|
|
@@ -1,174 +1,36 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { BuildTextureData, } from "./Functions/BuildTextureData.js";
|
|
2
|
+
const missingTexture = {
|
|
3
|
+
id: "dve_missing",
|
|
4
|
+
base64: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAEsGlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQiPz4KPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iWE1QIENvcmUgNS41LjAiPgogPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4KICA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIgogICAgeG1sbnM6ZXhpZj0iaHR0cDovL25zLmFkb2JlLmNvbS9leGlmLzEuMC8iCiAgICB4bWxuczp0aWZmPSJodHRwOi8vbnMuYWRvYmUuY29tL3RpZmYvMS4wLyIKICAgIHhtbG5zOnBob3Rvc2hvcD0iaHR0cDovL25zLmFkb2JlLmNvbS9waG90b3Nob3AvMS4wLyIKICAgIHhtbG5zOnhtcD0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wLyIKICAgIHhtbG5zOnhtcE1NPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvbW0vIgogICAgeG1sbnM6c3RFdnQ9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZUV2ZW50IyIKICAgZXhpZjpQaXhlbFhEaW1lbnNpb249IjE2IgogICBleGlmOlBpeGVsWURpbWVuc2lvbj0iMTYiCiAgIGV4aWY6Q29sb3JTcGFjZT0iMSIKICAgdGlmZjpJbWFnZVdpZHRoPSIxNiIKICAgdGlmZjpJbWFnZUxlbmd0aD0iMTYiCiAgIHRpZmY6UmVzb2x1dGlvblVuaXQ9IjIiCiAgIHRpZmY6WFJlc29sdXRpb249IjcyLzEiCiAgIHRpZmY6WVJlc29sdXRpb249IjcyLzEiCiAgIHBob3Rvc2hvcDpDb2xvck1vZGU9IjMiCiAgIHBob3Rvc2hvcDpJQ0NQcm9maWxlPSJzUkdCIElFQzYxOTY2LTIuMSIKICAgeG1wOk1vZGlmeURhdGU9IjIwMjUtMDItMDRUMTM6MjY6MzYtMDU6MDAiCiAgIHhtcDpNZXRhZGF0YURhdGU9IjIwMjUtMDItMDRUMTM6MjY6MzYtMDU6MDAiPgogICA8eG1wTU06SGlzdG9yeT4KICAgIDxyZGY6U2VxPgogICAgIDxyZGY6bGkKICAgICAgc3RFdnQ6YWN0aW9uPSJwcm9kdWNlZCIKICAgICAgc3RFdnQ6c29mdHdhcmVBZ2VudD0iQWZmaW5pdHkgUGhvdG8gMS4xMC42IgogICAgICBzdEV2dDp3aGVuPSIyMDI1LTAyLTA0VDEzOjI2OjM2LTA1OjAwIi8+CiAgICA8L3JkZjpTZXE+CiAgIDwveG1wTU06SGlzdG9yeT4KICA8L3JkZjpEZXNjcmlwdGlvbj4KIDwvcmRmOlJERj4KPC94OnhtcG1ldGE+Cjw/eHBhY2tldCBlbmQ9InIiPz6QxtZwAAABgWlDQ1BzUkdCIElFQzYxOTY2LTIuMQAAKJF1kb9LQlEUxz9qYfQDAyMaGiSsKcMMpJYGoyyoBjPIatHnr0Dt8Z4R0Rq0CgVRS7+G+gtqDZqDoCiCaK61qKXkdZ4KSuS5nHs+93vvOdx7LljDGSWrN3ghm8troWDAtRBZdNnfsGLDSSe9UUVXZ+YmwtS1rwcsZrzzmLXqn/vXWuIJXQFLk/Coomp54Unh6fW8avKucIeSjsaFz4X7Nbmg8L2px8r8anKqzD8ma+HQGFjbhV2pGo7VsJLWssLyctzZzJpSuY/5ktZEbn5OYo94NzohggRwMcU4Y/gZZERmPx58DMiKOvneUv4sq5KryKyygcYKKdLk6Rd1TaonJCZFT8jIsGH2/29f9eSQr1y9NQCNL4bx0Qv2HSgWDOP72DCKJ2B7hqtcNX/1CIY/RS9UNfchOLbg4rqqxfbgchu6ntSoFi1JNnFrMgnvZ9AWAectNC+Ve1bZ5/QRwpvyVTewfwB9ct6x/AtRCWfcDyqUNQAAAAlwSFlzAAALEwAACxMBAJqcGAAAACRJREFUKJFjPMWAHZjhEGfCIY4TjGogBjDiksAVP4PQD8NBAwBeSgHpmKHwOgAAAABJRU5ErkJggg==",
|
|
5
|
+
};
|
|
5
6
|
export class TextureManager {
|
|
6
|
-
static
|
|
7
|
-
static
|
|
8
|
-
static getTextureIndex(data) {
|
|
9
|
-
const [textureType, textureId, varation] = data;
|
|
10
|
-
const type = this.getTextureType(textureType);
|
|
11
|
-
if (!type)
|
|
12
|
-
return NaN;
|
|
13
|
-
return type.getTextureIndex(textureId, varation);
|
|
14
|
-
}
|
|
15
|
-
static _ready = false;
|
|
16
|
-
static isReady() {
|
|
17
|
-
return this._ready;
|
|
18
|
-
}
|
|
19
|
-
static async init() {
|
|
20
|
-
TextureBuilder.defineTextureDimensions(EngineSettings.settings.textures.textureSize);
|
|
21
|
-
for (const [key, type] of this.textureTypes) {
|
|
22
|
-
await type.build();
|
|
23
|
-
}
|
|
24
|
-
TextureRegister.setTextureIndex(this.generateTextureUVMap());
|
|
25
|
-
this._ready = true;
|
|
26
|
-
}
|
|
27
|
-
static generateTextureUVMap() {
|
|
28
|
-
const uvMap = {};
|
|
29
|
-
for (const [key, type] of this.textureTypes) {
|
|
30
|
-
uvMap[key] = type.getTextureIndexMap();
|
|
31
|
-
}
|
|
32
|
-
return uvMap;
|
|
33
|
-
}
|
|
34
|
-
static defineDefaultTexturePath(path) {
|
|
35
|
-
this.defaultTexturePath = path;
|
|
36
|
-
}
|
|
37
|
-
static getTextureData([type, id, segment]) {
|
|
38
|
-
const t = this.getTextureType(type);
|
|
39
|
-
if (!t)
|
|
40
|
-
return undefined;
|
|
41
|
-
return t.textureMap.get(id);
|
|
42
|
-
}
|
|
43
|
-
static getTextureType(id) {
|
|
44
|
-
const texture = this.textureTypes.get(id);
|
|
45
|
-
if (!texture)
|
|
46
|
-
return false;
|
|
47
|
-
return texture;
|
|
48
|
-
}
|
|
49
|
-
static getOrAddTextureType(id) {
|
|
50
|
-
const texture = this.textureTypes.get(id);
|
|
51
|
-
if (!texture)
|
|
52
|
-
return this.addTextureType(id);
|
|
53
|
-
return texture;
|
|
54
|
-
}
|
|
55
|
-
static addTextureType(id) {
|
|
56
|
-
const newType = new TextureArray(id);
|
|
57
|
-
this.textureTypes.set(id, newType);
|
|
58
|
-
return newType;
|
|
59
|
-
}
|
|
60
|
-
static clearTextureData() {
|
|
61
|
-
//
|
|
62
|
-
// this.textureTypes.forEach((_) => _.clearSegmentData());
|
|
63
|
-
}
|
|
7
|
+
static _textureTypes = new Map();
|
|
8
|
+
static _compiledTextures = new Map();
|
|
64
9
|
static registerTexture(textureData) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
continue;
|
|
72
|
-
}
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
const type = this.getOrAddTextureType(textureData.type);
|
|
76
|
-
if (!type)
|
|
77
|
-
return;
|
|
78
|
-
type.addTexture(textureData);
|
|
79
|
-
}
|
|
80
|
-
static getTexturePath(textureType, id, varation, segment = "main", frames) {
|
|
81
|
-
const data = this.getTextureData([textureType, id, segment]);
|
|
82
|
-
if (!data)
|
|
83
|
-
throw new Error(`Could not find data for ${textureType} ${id} ${varation}`);
|
|
84
|
-
let path = data.base64 &&
|
|
85
|
-
(Array.isArray(data.base64) ? data.base64[0] : data.base64);
|
|
86
|
-
if (path)
|
|
87
|
-
return path;
|
|
88
|
-
const type = this.textureTypes.get(textureType);
|
|
89
|
-
return type._getPath(data, varation, type.extension);
|
|
90
|
-
}
|
|
91
|
-
static async createCached() {
|
|
92
|
-
const cachedTextureData = [];
|
|
93
|
-
for (const [typeKey, type] of this.textureTypes) {
|
|
94
|
-
for (const baseData of type.textures) {
|
|
95
|
-
const data = structuredClone(baseData);
|
|
96
|
-
const id = baseData.id;
|
|
97
|
-
if (data.frames) {
|
|
98
|
-
const images = [];
|
|
99
|
-
for (let i = 1; i <= data.frames; i++) {
|
|
100
|
-
images.push(await TextureBuilder.getBase64(type._getPath(data, `${id}-${i}`, type.extension)));
|
|
101
|
-
}
|
|
102
|
-
data.base64 = images;
|
|
103
|
-
}
|
|
104
|
-
else {
|
|
105
|
-
data.base64 = await TextureBuilder.getBase64(type._getPath(data, "default", type.extension));
|
|
106
|
-
}
|
|
107
|
-
if (data.variations) {
|
|
108
|
-
for (const varId in data.variations) {
|
|
109
|
-
const varation = data.variations[varId];
|
|
110
|
-
if (varation.frames) {
|
|
111
|
-
const images = [];
|
|
112
|
-
for (let i = 1; i <= varation.frames; i++) {
|
|
113
|
-
images.push(await TextureBuilder.getBase64(type._getPath(data, `${varId}-${i}`, type.extension)));
|
|
114
|
-
}
|
|
115
|
-
varation.base64 = images;
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
varation.base64 = await TextureBuilder.getBase64(type._getPath(data, varId, type.extension));
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
cachedTextureData.push(data);
|
|
10
|
+
for (const texture of textureData) {
|
|
11
|
+
const typeId = texture.type || "dve_voxel";
|
|
12
|
+
let type = this._textureTypes.get(typeId);
|
|
13
|
+
if (!type) {
|
|
14
|
+
type = [missingTexture];
|
|
15
|
+
this._textureTypes.set(typeId, type);
|
|
123
16
|
}
|
|
17
|
+
type.push(texture);
|
|
124
18
|
}
|
|
125
|
-
return cachedTextureData;
|
|
126
19
|
}
|
|
127
|
-
static
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
else {
|
|
144
|
-
const rawData = await TextureBuilder.getRawData(type._getPath(data, "default", type.extension));
|
|
145
|
-
data.rawData = rawData;
|
|
146
|
-
map.set(key, rawData);
|
|
147
|
-
}
|
|
148
|
-
if (data.variations) {
|
|
149
|
-
for (const varId in data.variations) {
|
|
150
|
-
const varation = data.variations[varId];
|
|
151
|
-
if (!varation.includeInRawDataMap)
|
|
152
|
-
continue;
|
|
153
|
-
const key = `${type.id}|${data.id}|${varId}`;
|
|
154
|
-
if (data.frames) {
|
|
155
|
-
for (let i = 1; i <= data.frames; i++) {
|
|
156
|
-
const rawData = await TextureBuilder.getRawData(type._getPath(data, `${key}-${i}`, type.extension));
|
|
157
|
-
data.rawData = rawData;
|
|
158
|
-
map.set(`${key}-${i}`, rawData);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
else {
|
|
162
|
-
const rawData = await TextureBuilder.getRawData(type._getPath(data, varId, type.extension));
|
|
163
|
-
data.rawData = rawData;
|
|
164
|
-
map.set(key, rawData);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}
|
|
20
|
+
static getTexture(id) {
|
|
21
|
+
const type = this._compiledTextures.get(id);
|
|
22
|
+
if (!type)
|
|
23
|
+
throw new Error(`Compiled texture with id ${id} does not exist`);
|
|
24
|
+
return type;
|
|
25
|
+
}
|
|
26
|
+
static async compiledTextures(props = {}) {
|
|
27
|
+
for (const [type, data] of this._textureTypes) {
|
|
28
|
+
const compiled = await BuildTextureData({
|
|
29
|
+
type,
|
|
30
|
+
textures: data,
|
|
31
|
+
...props,
|
|
32
|
+
});
|
|
33
|
+
this._compiledTextures.set(type, compiled);
|
|
169
34
|
}
|
|
170
|
-
return map;
|
|
171
35
|
}
|
|
172
36
|
}
|
|
173
|
-
TextureManager.getOrAddTextureType("dve_voxel");
|
|
174
|
-
TextureManager.getOrAddTextureType("dve_node");
|