@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.
Files changed (174) hide show
  1. package/Contexts/Render/DivineVoxelEngineRender.d.ts +1 -1
  2. package/Contexts/World/DivineVoxelEngineWorld.d.ts +1 -1
  3. package/Init/StartConstructor.js +6 -4
  4. package/Init/StartWorld.d.ts +1 -1
  5. package/Mesher/Functions/CompactVoxelMesh.d.ts +2 -2
  6. package/Mesher/Functions/CompactVoxelMesh.js +1 -1
  7. package/Mesher/Functions/MeshSection.js +20 -8
  8. package/Mesher/Functions/MeshTexture.d.ts +1 -1
  9. package/Mesher/Functions/MeshTexture.js +3 -4
  10. package/Mesher/Geomtry/Primitives/QuadVertexData.d.ts +12 -10
  11. package/Mesher/Geomtry/Primitives/QuadVertexData.js +49 -56
  12. package/Mesher/Geomtry/VoxelGeometryBuilder.d.ts +2 -2
  13. package/Mesher/Geomtry/VoxelGeometryBuilder.js +2 -2
  14. package/Mesher/Geomtry/VoxelMesh.d.ts +1 -1
  15. package/Mesher/Geomtry/VoxelMesh.js +2 -2
  16. package/Mesher/Geomtry/index.d.ts +0 -1
  17. package/Mesher/Geomtry/index.js +0 -1
  18. package/Mesher/InitMesher.js +1 -1
  19. package/Mesher/InitTask.js +4 -22
  20. package/Mesher/Models/Common/Calc/FaceDataCalc.d.ts +2 -2
  21. package/Mesher/Models/Common/Calc/FaceDataCalc.js +37 -30
  22. package/Mesher/Models/Nodes/Custom/Liquid/FlowGradient.d.ts +2 -2
  23. package/Mesher/Models/Nodes/Custom/Liquid/FlowGradient.js +1 -1
  24. package/Mesher/Models/Nodes/Custom/Liquid/LiquidGeomtryNode.js +11 -17
  25. package/Mesher/Models/Nodes/GeometryNode.d.ts +2 -2
  26. package/Mesher/Models/Nodes/Ruled/BoxVoxelGeometryNode.d.ts +1 -0
  27. package/Mesher/Models/Nodes/Ruled/BoxVoxelGeometryNode.js +24 -12
  28. package/Mesher/{Tools → Models/Protocols}/OutlinedVoxelTool.d.ts +1 -1
  29. package/Mesher/{Tools → Models/Protocols}/OutlinedVoxelTool.js +1 -1
  30. package/Mesher/Models/RenderedMaterials.d.ts +6 -0
  31. package/Mesher/{RenderedMaterials.js → Models/RenderedMaterials.js} +2 -2
  32. package/Mesher/Models/VoxelConstructor.d.ts +3 -3
  33. package/Mesher/Models/VoxelGeometryBuilderCacheSpace.d.ts +1 -3
  34. package/Mesher/Models/VoxelGeometryBuilderCacheSpace.js +0 -23
  35. package/Mesher/{Tools/VoxelMesherDataTool.d.ts → Models/VoxelModelBuilder.d.ts} +4 -5
  36. package/Mesher/{Tools/VoxelMesherDataTool.js → Models/VoxelModelBuilder.js} +11 -7
  37. package/Models/Defaults/CubeVoxelGeometry.js +4 -0
  38. package/Models/Defaults/CubeVoxelModels.js +344 -344
  39. package/Models/Defaults/LiquidVoxelModel.js +2 -2
  40. package/Models/Defaults/PanelVoxelModels.js +432 -432
  41. package/Models/Defaults/StairVoxelModel.js +576 -576
  42. package/Models/Examples.js +469 -456
  43. package/Models/Rules/Functions/BuildFinalInputs.js +9 -7
  44. package/Models/Rules/Functions/BuildGeomtryInputs.js +8 -5
  45. package/Models/Rules/Functions/BuildRules.js +2 -2
  46. package/Models/Rules/{VoxelModelManager.d.ts → VoxelModelRuleBuilderRegister.d.ts} +1 -1
  47. package/Models/Rules/VoxelModelRuleBuilderRegister.js +178 -0
  48. package/Models/VoxelModel.types.d.ts +14 -5
  49. package/Renderer/Classes/SectorMesh.d.ts +3 -4
  50. package/Renderer/Classes/SectorMesh.js +6 -11
  51. package/Renderer/InitTasks.js +6 -7
  52. package/Renderer/MeshManager.js +2 -2
  53. package/Renderer/MeshRegister.js +2 -1
  54. package/Settings/EngineSettings.d.ts +1 -1
  55. package/Settings/EngineSettings.js +3 -5
  56. package/Settings/EngineSettings.types.d.ts +17 -18
  57. package/Settings/EngineSettings.types.js +16 -15
  58. package/Tasks/IWG/IWG.d.ts +2 -1
  59. package/Tasks/IWG/IWG.js +9 -3
  60. package/Tasks/IWG/Internal/Classes/BuildQueue.d.ts +11 -0
  61. package/Tasks/IWG/Internal/Classes/BuildQueue.js +49 -0
  62. package/Tasks/IWG/Internal/Classes/Generator.d.ts +6 -1
  63. package/Tasks/IWG/Internal/Classes/Generator.js +13 -1
  64. package/Tasks/IWG/Internal/Classes/IWGTaskBase.js +2 -2
  65. package/Tasks/IWG/Internal/Functions/runBuildUpdate.js +21 -2
  66. package/Tasks/IWG/Internal/IWGTasks.d.ts +0 -4
  67. package/Tasks/IWG/Internal/IWGTasks.js +0 -10
  68. package/Tasks/IWG/Internal/IWGTools.d.ts +1 -1
  69. package/Tasks/IWG/Procedures/SaveAllSectors.js +2 -0
  70. package/Tasks/Update/UpdateTask.d.ts +3 -1
  71. package/Tasks/Update/UpdateTask.js +28 -2
  72. package/Tasks/Update/VoxelUpdate.js +6 -0
  73. package/Tasks/WorldGeneration/WorldGenBrush.js +1 -1
  74. package/Templates/Cursor/TemplateCursor.d.ts +2 -2
  75. package/Templates/Cursor/TemplateCursor.js +1 -2
  76. package/Templates/VoxelTemplates.types.d.ts +1 -1
  77. package/Textures/Classes/CompiledTexture.d.ts +18 -0
  78. package/Textures/Classes/CompiledTexture.js +50 -0
  79. package/Textures/Classes/CompiledTextureAnimation.d.ts +12 -0
  80. package/Textures/Classes/CompiledTextureAnimation.js +27 -0
  81. package/Textures/Classes/TextureAnimationTexture.d.ts +10 -0
  82. package/Textures/Classes/TextureAnimationTexture.js +32 -0
  83. package/Textures/Functions/BuildTextureData.d.ts +10 -0
  84. package/Textures/Functions/BuildTextureData.js +205 -0
  85. package/Textures/Texture.types.d.ts +50 -64
  86. package/Textures/TextureManager.d.ts +8 -19
  87. package/Textures/TextureManager.js +28 -166
  88. package/Tools/Brush/Brush.d.ts +1 -1
  89. package/Tools/Brush/Brush.js +39 -7
  90. package/Util/Binary/BinaryArrays.d.ts +6 -0
  91. package/Util/Binary/BinaryArrays.js +25 -0
  92. package/Util/Binary/BinaryBuffer.d.ts +29 -0
  93. package/Util/Binary/BinaryBuffer.js +130 -0
  94. package/Util/Binary/{BitArray.d.ts → BinaryFunctions.d.ts} +1 -2
  95. package/Util/Binary/BinaryFunctions.js +11 -0
  96. package/Voxels/Cursor/DataCursor.interface.d.ts +5 -0
  97. package/Voxels/Cursor/VoxelCursor.interface.d.ts +1 -1
  98. package/Voxels/Cursor/VoxelCursor.interface.js +8 -11
  99. package/Voxels/Data/VoxelPalettesRegister.d.ts +0 -5
  100. package/Voxels/Data/VoxelPalettesRegister.js +0 -9
  101. package/Voxels/Data/VoxelTagsRegister.js +7 -7
  102. package/Voxels/Functions/BuildStateData.js +9 -9
  103. package/Voxels/Functions/BuildTagAndPaletteData.js +2 -4
  104. package/Voxels/InitVoxelData.js +12 -13
  105. package/Voxels/State/Schema/StateSchema.d.ts +1 -1
  106. package/Voxels/Types/Voxel.types.d.ts +18 -0
  107. package/Voxels/Types/Voxel.types.js +6 -2
  108. package/World/Archive/Archive.types.d.ts +38 -34
  109. package/World/Archive/Functions/ArchiveArea.js +16 -24
  110. package/World/Archive/Functions/ArchiveSector.js +477 -192
  111. package/World/Archive/Functions/ImportSector.d.ts +3 -3
  112. package/World/Archive/Functions/ImportSector.js +202 -141
  113. package/World/Archive/Functions/Shared.d.ts +6 -0
  114. package/World/Archive/Functions/Shared.js +75 -0
  115. package/World/Archive/InitTasks.js +30 -13
  116. package/World/Cursor/SectionCursor.d.ts +2 -2
  117. package/World/Cursor/SectionCursor.js +2 -3
  118. package/World/Cursor/SectorCursor.d.ts +2 -2
  119. package/World/Cursor/SectorCursor.js +1 -2
  120. package/World/Cursor/WorldCursor.d.ts +2 -2
  121. package/World/Cursor/WorldCursor.js +1 -2
  122. package/World/Cursor/WorldVoxelCursor.js +1 -0
  123. package/World/InitTasks.d.ts +1 -1
  124. package/World/Lock/WorldLock.d.ts +1 -1
  125. package/World/Section/Section.d.ts +12 -16
  126. package/World/Section/Section.js +62 -20
  127. package/World/Section/SectionState.d.ts +10 -0
  128. package/World/Section/SectionState.js +11 -0
  129. package/World/Sector/Sector.d.ts +14 -6
  130. package/World/Sector/Sector.js +67 -17
  131. package/World/Sector/SectorHeightMap.js +2 -2
  132. package/World/Sector/SectorState.d.ts +14 -6
  133. package/World/Sector/SectorState.js +28 -15
  134. package/World/Types/WorldStorage.interface.js +1 -0
  135. package/World/WorldRegister.d.ts +4 -0
  136. package/World/WorldRegister.js +15 -3
  137. package/World/WorldSpaces.d.ts +4 -0
  138. package/World/WorldSpaces.js +19 -6
  139. package/package.json +1 -1
  140. package/Mesher/Functions/CompactMesh.d.ts +0 -2
  141. package/Mesher/Functions/CompactMesh.js +0 -42
  142. package/Mesher/Geomtry/GeometryNormals.d.ts +0 -10
  143. package/Mesher/Geomtry/GeometryNormals.js +0 -52
  144. package/Mesher/Geomtry/MeshData.types.d.ts +0 -13
  145. package/Mesher/Geomtry/MeshData.types.js +0 -6
  146. package/Mesher/Geomtry/Tools/MesherDataTools.d.ts +0 -7
  147. package/Mesher/Geomtry/Tools/MesherDataTools.js +0 -12
  148. package/Mesher/Geomtry/Tools/index.d.ts +0 -1
  149. package/Mesher/Geomtry/Tools/index.js +0 -1
  150. package/Mesher/RenderedMaterials.d.ts +0 -6
  151. package/Models/Rules/VoxelModelManager.js +0 -82
  152. package/Textures/TextureAnimations.d.ts +0 -4
  153. package/Textures/TextureAnimations.js +0 -35
  154. package/Textures/TextureArray.d.ts +0 -47
  155. package/Textures/TextureArray.js +0 -202
  156. package/Textures/TextureBuilder.d.ts +0 -13
  157. package/Textures/TextureBuilder.js +0 -120
  158. package/Textures/TextureRegister.d.ts +0 -9
  159. package/Textures/TextureRegister.js +0 -28
  160. package/Tools/DataCursor.interface.d.ts +0 -5
  161. package/Tools/DataCursor.interface.js +0 -2
  162. package/Util/Binary/BitArray.js +0 -16
  163. package/World/Structs/WorldDataStructProperties.d.ts +0 -8
  164. package/World/Structs/WorldDataStructProperties.js +0 -9
  165. /package/Mesher/{Tools → Geomtry}/VoxelMeshBVHBuilder.d.ts +0 -0
  166. /package/Mesher/{Tools → Geomtry}/VoxelMeshBVHBuilder.js +0 -0
  167. /package/Mesher/Geomtry/{Buffers.d.ts → VoxelMeshBuffers.d.ts} +0 -0
  168. /package/Mesher/Geomtry/{Buffers.js → VoxelMeshBuffers.js} +0 -0
  169. /package/Mesher/{Tools → Geomtry}/VoxelMeshVertexStructCursor.d.ts +0 -0
  170. /package/Mesher/{Tools → Geomtry}/VoxelMeshVertexStructCursor.js +0 -0
  171. /package/Mesher/{VoxelShaderData.d.ts → Geomtry/VoxelShaderData.d.ts} +0 -0
  172. /package/Mesher/{VoxelShaderData.js → Geomtry/VoxelShaderData.js} +0 -0
  173. /package/{World/Storage/WorldStorage.interface.js → Voxels/Cursor/DataCursor.interface.js} +0 -0
  174. /package/World/{Storage → Types}/WorldStorage.interface.d.ts +0 -0
@@ -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 = [type: string, id: string, varation?: string];
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
- /**# rawData
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
- /**# Path
9
+ /**
57
10
  * If the texture is not in the default path specify it here.
58
11
  */
59
12
  path?: string;
60
- /**# normalMap
61
- * If the texture is an overlay specify it here.
13
+ /**
14
+ * Provide a base64 encoded string to use instead of downloading
62
15
  */
63
- normalMap?: boolean;
64
- /**# Varations
65
- * The name of the texture must be default with the folder being its ID.
66
- * Variations allow you to add variations to the same texture.
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
- * If you add a variation of "grassy-up" you must you include in the
69
- * folder of the texture one with the name 'grassy-up'.
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
- * So the files in that folder would be for a texture with the ID **dreamstone**
72
- * - dreamstone/default.png
73
- * - dreamstone/grassy-up.png
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?: Record<string, TextureAnimationData & TextureDataBase>;
76
- } & TextureAnimationData & TextureDataBase;
61
+ variations?: (string | TextureDataBase)[];
62
+ } & TextureDataBase;
@@ -1,21 +1,10 @@
1
- import type { TextureData, TextureTypeUVMap, TextureId } from "./Texture.types";
2
- import { TextureArray } from "./TextureArray.js";
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 defaultTexturePath: string;
5
- static textureTypes: Map<string, TextureArray>;
6
- static getTextureIndex(data: TextureId): number;
7
- static _ready: boolean;
8
- static isReady(): boolean;
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 { EngineSettings } from "../Settings/EngineSettings.js";
2
- import { TextureBuilder } from "./TextureBuilder.js";
3
- import { TextureArray } from "./TextureArray.js";
4
- import { TextureRegister } from "./TextureRegister.js";
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 defaultTexturePath = "assets/textures";
7
- static textureTypes = new Map();
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
- if (Array.isArray(textureData)) {
66
- for (const texture of textureData) {
67
- const type = this.getOrAddTextureType(texture.type);
68
- if (!type)
69
- continue;
70
- type.addTexture(texture);
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 async createRawDataMap() {
128
- const map = new Map();
129
- for (const [typeKey, type] of this.textureTypes) {
130
- for (const data of type.textures) {
131
- if (!data.includeInRawDataMap)
132
- continue;
133
- if (!data.path && !data.rawData)
134
- continue;
135
- const key = `${type.id}|${data.id}|default`;
136
- if (data.frames) {
137
- for (let i = 1; i <= data.frames; i++) {
138
- const rawData = await TextureBuilder.getRawData(type._getPath(data, `${key}-${i}`, type.extension));
139
- data.rawData = rawData;
140
- map.set(`${key}-${i}`, rawData);
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");
@@ -7,7 +7,6 @@ export declare class BrushTool {
7
7
  x: number;
8
8
  y: number;
9
9
  z: number;
10
- name: string;
11
10
  voxelCursor: VoxelCursor;
12
11
  dataCursor: WorldCursor;
13
12
  setXYZ(x: number, y: number, z: number): this;
@@ -19,6 +18,7 @@ export declare class BrushTool {
19
18
  setId(id: string): this;
20
19
  setName(name: string): this;
21
20
  setSecondaryId(id: string): this;
21
+ setSecondaryName(name: string): this;
22
22
  setShapeState(state: number): this;
23
23
  setLevel(level: number): this;
24
24
  setLevelState(levelState: number): this;
@@ -7,8 +7,10 @@ const air = [0, 0, 0, 0, 0, 0];
7
7
  export class BrushTool {
8
8
  data = {
9
9
  id: airId,
10
+ name: "",
10
11
  state: 0,
11
12
  secondaryVoxelId: "",
13
+ secondaryVoxeName: "",
12
14
  level: 0,
13
15
  levelState: 0,
14
16
  mod: 0,
@@ -17,7 +19,6 @@ export class BrushTool {
17
19
  x = 0;
18
20
  y = 0;
19
21
  z = 0;
20
- name = airId;
21
22
  voxelCursor = new VoxelCursor();
22
23
  dataCursor = new WorldCursor();
23
24
  setXYZ(x, y, z) {
@@ -30,11 +31,22 @@ export class BrushTool {
30
31
  WorldRegister.sectors.new(this.dimension, this.x, this.y, this.z);
31
32
  }
32
33
  setData(data) {
33
- this.data.id = data.id ? data.id : airId;
34
+ this.clear();
35
+ if (data.name) {
36
+ this.setName(data.name);
37
+ }
38
+ else {
39
+ if (data.id)
40
+ this.setId(data.id);
41
+ }
42
+ if (data.secondaryVoxeName) {
43
+ this.setSecondaryName(data.secondaryVoxeName);
44
+ }
45
+ else {
46
+ if (data.secondaryVoxelId)
47
+ this.setSecondaryId(data.secondaryVoxelId);
48
+ }
34
49
  this.data.state = data.state ? data.state : 0;
35
- this.data.secondaryVoxelId = data.secondaryVoxelId
36
- ? data.secondaryVoxelId
37
- : airId;
38
50
  this.data.level = data.level ? data.level : 0;
39
51
  this.data.levelState = data.levelState ? data.levelState : 0;
40
52
  this.data.mod = data.mod ? data.mod : 0;
@@ -62,15 +74,34 @@ export class BrushTool {
62
74
  }
63
75
  setId(id) {
64
76
  this.data.id = id;
77
+ this.data.name = VoxelPalettesRegister.voxelIdToNameMap.get(id);
65
78
  return this;
66
79
  }
67
80
  setName(name) {
68
- this.data.id = VoxelPalettesRegister.voxelName.getId(name);
69
- this.name = name;
81
+ this.data.id = VoxelPalettesRegister.voxelNametoIdMap.get(name);
82
+ this.data.name = name;
70
83
  return this;
71
84
  }
72
85
  setSecondaryId(id) {
73
86
  this.data.secondaryVoxelId = id;
87
+ if (id) {
88
+ this.data.secondaryVoxeName =
89
+ VoxelPalettesRegister.voxelIdToNameMap.get(id);
90
+ }
91
+ else {
92
+ this.data.secondaryVoxeName = "";
93
+ }
94
+ return this;
95
+ }
96
+ setSecondaryName(name) {
97
+ if (name) {
98
+ this.data.secondaryVoxelId =
99
+ VoxelPalettesRegister.voxelNametoIdMap.get(name);
100
+ }
101
+ else {
102
+ this.data.secondaryVoxelId = "";
103
+ }
104
+ this.data.secondaryVoxeName = name;
74
105
  return this;
75
106
  }
76
107
  setShapeState(state) {
@@ -91,6 +122,7 @@ export class BrushTool {
91
122
  }
92
123
  clear() {
93
124
  this.data.id = "dve_air";
125
+ this.data.name = "";
94
126
  this.data.secondaryVoxelId = "";
95
127
  this.data.level = 0;
96
128
  this.data.levelState = 0;
@@ -0,0 +1,6 @@
1
+ export declare function getBitArrayIndex(data: Uint8Array, arrayIndex: number): number;
2
+ export declare function setBitArrayIndex(data: Uint8Array, arrayIndex: number, value: number): void;
3
+ export declare function getNibbleArrayIndex(data: Uint8Array, arrayIndex: number): number;
4
+ export declare function setNibbleArrayIndex(data: Uint8Array, arrayIndex: number, value: number): void;
5
+ export declare function getHalfNibbleArrayIndex(data: Uint8Array, arrayIndex: number): number;
6
+ export declare function setHalfNibbleArrayIndex(data: Uint8Array, arrayIndex: number, value: number): void;