@divinevoxel/vlox 0.0.80 → 0.0.81

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 (162) hide show
  1. package/Builder/Tools/Brush/BrushTool.d.ts +12 -2
  2. package/Builder/Tools/Brush/BrushTool.js +53 -28
  3. package/Builder/Tools/Debug/DebugTool.d.ts +18 -0
  4. package/Builder/Tools/Debug/DebugTool.js +36 -0
  5. package/Builder/Tools/Path/PahtTool.d.ts +1 -1
  6. package/Builder/Tools/Path/PahtTool.js +1 -1
  7. package/Builder/Tools/Sculpt/SculptTool.js +8 -0
  8. package/Builder/Tools/Wrench/WrenchTool.js +10 -23
  9. package/Builder/Util/SurfaceBoxSelection.js +2 -0
  10. package/Builder/VoxelBuildSpace.js +3 -3
  11. package/Contexts/Base/Remote/InitDataSync.js +1 -1
  12. package/Math/UtilFunctions.js +7 -8
  13. package/Math/VoxelFaces.d.ts +2 -2
  14. package/Math/VoxelFaces.js +46 -55
  15. package/Math/WorldIndexing.d.ts +11 -0
  16. package/Math/WorldIndexing.js +34 -0
  17. package/Mesher/Geometry/Geometry.types.d.ts +2 -2
  18. package/Mesher/Geometry/Geometry.types.js +7 -20
  19. package/Mesher/Geometry/Primitives/QuadVertexData.js +118 -119
  20. package/Mesher/Geometry/Primitives/TriangleVertexData.js +89 -90
  21. package/Mesher/Geometry/Proto/ProtoMesh.d.ts +1 -1
  22. package/Mesher/Geometry/Proto/ProtoMesh.js +22 -29
  23. package/Mesher/Geometry/Proto/ProtoMeshBuffer.d.ts +4 -2
  24. package/Mesher/Geometry/Proto/ProtoMeshBuffer.js +14 -6
  25. package/Mesher/Geometry/Shapes/Box.js +6 -7
  26. package/Mesher/Geometry/Transform/TransformBox.js +8 -9
  27. package/Mesher/Geometry/Transform/TransformQuad.js +4 -5
  28. package/Mesher/Geometry/Transform/TransformTriangle.js +3 -4
  29. package/Mesher/InitMesher.js +4 -9
  30. package/Mesher/Items/Geometry/ItemGeometryBuilder.js +7 -8
  31. package/Mesher/Items/MeshTexture.js +125 -57
  32. package/Mesher/Voxels/Base/BuildVoxel.d.ts +6 -0
  33. package/Mesher/Voxels/Base/BuildVoxel.js +101 -0
  34. package/Mesher/Voxels/Base/CompactVoxelSectionMesh.js +1 -21
  35. package/Mesher/Voxels/Base/MeshSectionBase.js +3 -26
  36. package/Mesher/Voxels/Geometry/VoxelGeometryBuilder.js +33 -31
  37. package/Mesher/Voxels/Geometry/VoxelShaderData.js +3 -7
  38. package/Mesher/Voxels/MeshTemplate.js +6 -26
  39. package/Mesher/Voxels/MeshVoxel.js +5 -10
  40. package/Mesher/Voxels/Models/Common/Calc/CalcConstants.js +41 -42
  41. package/Mesher/Voxels/Models/Common/Calc/FaceDataCalc.js +6 -9
  42. package/Mesher/Voxels/Models/Common/Faces/CullRulledFace.js +64 -47
  43. package/Mesher/Voxels/Models/Common/Faces/ShadeRulledFace.js +57 -43
  44. package/Mesher/Voxels/Models/Nodes/Custom/Liquid/FlowGradient.js +4 -5
  45. package/Mesher/Voxels/Models/Nodes/Custom/Liquid/LiquidGeometryNode.d.ts +1 -1
  46. package/Mesher/Voxels/Models/Nodes/Custom/Liquid/LiquidGeometryNode.js +116 -118
  47. package/Mesher/Voxels/Models/Nodes/Default/QuadVoxelGeometryNode.js +4 -4
  48. package/Mesher/Voxels/Models/Nodes/VoxelGeometryConstructor.js +2 -2
  49. package/Mesher/Voxels/Models/Procedures/Default/OutlinedTextureProcedure.js +19 -21
  50. package/Mesher/Voxels/Models/Procedures/Default/PillarTextureProcedure.js +45 -38
  51. package/Mesher/Voxels/Models/RenderedMaterials.d.ts +1 -1
  52. package/Mesher/Voxels/Models/RenderedMaterials.js +8 -5
  53. package/Mesher/Voxels/Models/VoxelGeometryBuilderCacheSpace.d.ts +18 -4
  54. package/Mesher/Voxels/Models/VoxelGeometryBuilderCacheSpace.js +135 -22
  55. package/Mesher/Voxels/Models/VoxelGeometryBuilderCacheSpaceN.d.ts +33 -0
  56. package/Mesher/Voxels/Models/VoxelGeometryBuilderCacheSpaceN.js +204 -0
  57. package/Mesher/Voxels/Models/{VoxelModelConstructorRegister.d.ts → VoxelGeometryConstructorRegister.d.ts} +1 -6
  58. package/Mesher/Voxels/Models/VoxelGeometryConstructorRegister.js +20 -0
  59. package/Mesher/Voxels/Models/VoxelModelBuilder.js +15 -16
  60. package/Mesher/Voxels/Models/VoxelModelEffect.d.ts +1 -3
  61. package/Mesher/Voxels/Models/VoxelModelEffect.js +1 -3
  62. package/Renderer/DVERenderNode.types.d.ts +1 -0
  63. package/Renderer/InitTasks.js +2 -0
  64. package/Tasks/Paint/Erase/EraseVoxel.js +1 -1
  65. package/Tasks/Propagation/Illumanation/RGBUpdate.js +191 -48
  66. package/Tasks/Propagation/Illumanation/SunUpdate.d.ts +1 -1
  67. package/Tasks/Propagation/Illumanation/SunUpdate.js +167 -63
  68. package/Tasks/Propagation/Illumanation/WorldSun.js +96 -60
  69. package/Tasks/WorldGeneration/WorldGenBrush.d.ts +2 -0
  70. package/Tasks/WorldGeneration/WorldGenBrush.js +31 -0
  71. package/Templates/Archive/ArchivedVoxelTemplate.js +1 -1
  72. package/Templates/Archive/Functions/CreateArchivedTemplate.js +1 -1
  73. package/Templates/Archive/Functions/CreateArchivedTemplateFromFull.d.ts +6 -0
  74. package/Templates/Archive/Functions/CreateArchivedTemplateFromFull.js +174 -0
  75. package/Textures/Classes/CompactedTextureReader.d.ts +22 -0
  76. package/Textures/Classes/CompactedTextureReader.js +90 -0
  77. package/Textures/Classes/CompiledTexture.d.ts +4 -1
  78. package/Textures/Classes/CompiledTexture.js +36 -8
  79. package/Textures/Classes/TextureAtlasIndex.d.ts +7 -0
  80. package/Textures/Classes/TextureAtlasIndex.js +14 -0
  81. package/Textures/Classes/TextureLoader.d.ts +20 -0
  82. package/Textures/Classes/TextureLoader.js +95 -0
  83. package/Textures/Functions/BuildTextureData.d.ts +1 -1
  84. package/Textures/Functions/BuildTextureData.js +19 -122
  85. package/Textures/Functions/CreateCompactedTexture.d.ts +6 -0
  86. package/Textures/Functions/CreateCompactedTexture.js +105 -0
  87. package/Textures/Functions/ReadCompactedTexture.d.ts +2 -0
  88. package/Textures/Functions/ReadCompactedTexture.js +42 -0
  89. package/Textures/Texture.types.d.ts +14 -0
  90. package/Textures/TextureManager.d.ts +7 -1
  91. package/Textures/TextureManager.js +13 -0
  92. package/Tools/Brush/Brush.d.ts +4 -2
  93. package/Tools/Brush/Brush.js +28 -6
  94. package/Util/BinaryBuffer/Functions/BinaryBufferConvert.d.ts +1 -1
  95. package/Util/TickInterval.d.ts +3 -0
  96. package/Util/TickInterval.js +31 -3
  97. package/Voxels/Archive/VoxelPaletteArchiveReader.d.ts +1 -0
  98. package/Voxels/Archive/VoxelPaletteArchiveReader.js +9 -10
  99. package/Voxels/Archive/VoxelPaletteArechive.js +5 -4
  100. package/Voxels/Cursor/VoxelCursor.interface.d.ts +1 -1
  101. package/Voxels/Cursor/VoxelCursor.interface.js +22 -16
  102. package/Voxels/Data/VoxelLUT.d.ts +69 -42
  103. package/Voxels/Data/VoxelLUT.js +110 -53
  104. package/Voxels/Functions/BuildLUTs.js +100 -45
  105. package/Voxels/Functions/Geometry/CalcFunctions.js +6 -7
  106. package/Voxels/Functions/Geometry/Inputs/BuildTriangleInputs.js +3 -0
  107. package/Voxels/Indexes/VoxelIndex.js +3 -1
  108. package/Voxels/InitVoxelData.js +3 -1
  109. package/Voxels/Interaction/Functions/PickVoxel.js +3 -5
  110. package/Voxels/Interaction/Functions/PickVoxelWorld.js +4 -6
  111. package/Voxels/Models/Defaults/Examples.d.ts +2 -0
  112. package/Voxels/Models/Defaults/Examples.js +151 -2
  113. package/Voxels/State/Reltional/ReltionalStateBuilder.js +2 -0
  114. package/Voxels/State/Schema/BinarySchema.d.ts +1 -0
  115. package/Voxels/State/Schema/BinarySchema.js +14 -0
  116. package/Voxels/State/VoxelSchemas.d.ts +11 -4
  117. package/Voxels/State/VoxelSchemas.js +42 -9
  118. package/Voxels/Types/PaintVoxelData.js +6 -2
  119. package/World/Archive/Classes/ImportedSection.js +1 -1
  120. package/World/Archive/Classes/ImportedSector.js +0 -1
  121. package/World/Archive/Functions/Sector/ArchiveSector.js +2 -2
  122. package/World/Archive/Functions/Sector/ImportSector.d.ts +1 -0
  123. package/World/Archive/Functions/Sector/ImportSector.js +183 -7
  124. package/World/Cursor/SectorCursor.js +1 -4
  125. package/World/Cursor/WorldCursor.d.ts +12 -3
  126. package/World/Cursor/WorldCursor.js +60 -30
  127. package/World/InitTasks.js +1 -1
  128. package/World/Lock/Function/LockSectors.js +5 -1
  129. package/World/Lock/Function/UnLockSectors.js +5 -1
  130. package/World/SnapShot/SectionSnapShot.d.ts +7 -3
  131. package/World/SnapShot/SectionSnapShot.js +47 -21
  132. package/World/SnapShot/SectionSnapShotCursor.d.ts +4 -2
  133. package/World/SnapShot/SectionSnapShotCursor.js +23 -11
  134. package/World/SnapShot/SnapShots.d.ts +1 -2
  135. package/World/SnapShot/SnapShots.js +3 -3
  136. package/World/WorldSpaces.d.ts +7 -0
  137. package/World/WorldSpaces.js +35 -13
  138. package/WorldSimulation/Dimensions/DimensionSegment.d.ts +2 -0
  139. package/WorldSimulation/Dimensions/DimensionSegment.js +9 -1
  140. package/WorldSimulation/Dimensions/DimensionSimulation.js +6 -7
  141. package/WorldSimulation/Dimensions/Generator.d.ts +4 -0
  142. package/WorldSimulation/Dimensions/Generator.js +15 -1
  143. package/WorldSimulation/Dimensions/SimulationSector.d.ts +1 -0
  144. package/WorldSimulation/Dimensions/SimulationSector.js +18 -0
  145. package/WorldSimulation/Internal/WorldSimulationTasks.js +11 -7
  146. package/WorldSimulation/Procedures/InitalLoad.d.ts +1 -0
  147. package/WorldSimulation/Procedures/InitalLoad.js +18 -8
  148. package/WorldSimulation/Tasks/SimulationTaskBase.d.ts +4 -1
  149. package/WorldSimulation/Tasks/SimulationTaskBase.js +13 -2
  150. package/WorldSimulation/Tasks/TaskSegment.d.ts +4 -2
  151. package/WorldSimulation/Tasks/TaskSegment.js +36 -22
  152. package/WorldSimulation/Voxels/Ticks/Types/LiquidVoxelUpdate.js +1 -2
  153. package/WorldSimulation/WorldSimulation.d.ts +6 -3
  154. package/WorldSimulation/WorldSimulation.js +44 -20
  155. package/package.json +1 -1
  156. package/Mesher/Items/MeshTextureO.d.ts +0 -1
  157. package/Mesher/Items/MeshTextureO.js +0 -277
  158. package/Mesher/Voxels/Models/VoxelConstructor.d.ts +0 -8
  159. package/Mesher/Voxels/Models/VoxelConstructor.js +0 -78
  160. package/Mesher/Voxels/Models/VoxelModelConstructorRegister.js +0 -37
  161. package/WorldSimulation/Procedures/BuildOnly.d.ts +0 -10
  162. package/WorldSimulation/Procedures/BuildOnly.js +0 -55
@@ -1,94 +1,7 @@
1
1
  import { CompiledTexture } from "../Classes/CompiledTexture";
2
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("Canvas context is not available");
47
- canvas.width = finalSize[0];
48
- canvas.height = finalSize[1];
49
- return new Promise((resolve, reject) => {
50
- const image = typeof imgSrcData === "string" ? new Image() : imgSrcData;
51
- image.onerror = reject;
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 = () => resolve(returnImage);
66
- };
67
- });
68
- }
69
- async function loadImageForOriginal(imgSrcData) {
70
- return new Promise((resolve, reject) => {
71
- const image = typeof imgSrcData === "string" ? new Image() : imgSrcData;
72
- image.onerror = reject;
73
- if (typeof imgSrcData === "string")
74
- image.src = imgSrcData;
75
- image.onload = () => {
76
- resolve(image);
77
- };
78
- });
79
- }
80
- function getImagePath(data, parentId = null) {
81
- if (data.base64)
82
- return data.base64;
83
- if (data.path)
84
- return data.path;
85
- if (!parentId)
86
- return `${baseURL}/${data.id}.png`;
87
- return `${baseURL}/${parentId}/${data.id}.png`;
88
- }
89
- function getTextureId(data, parentId = null) {
90
- return `${parentId ? parentId : data.id}${!parentId ? "" : ":" + data.id}`;
91
- }
3
+ import { TextureLoader } from "../Classes/TextureLoader";
4
+ let loader;
92
5
  function createAnimationData(atlas, data, startIndex) {
93
6
  const compiled = new CompiledTextureAnimation(startIndex);
94
7
  if (!data?.frames) {
@@ -123,21 +36,19 @@ function createAnimationData(atlas, data, startIndex) {
123
36
  return compiled;
124
37
  }
125
38
  async function process(compiled, data, textureIndex, parent, cache = false) {
126
- const textureId = getTextureId(data, parent);
39
+ const textureId = loader.getTextureId(data, parent);
127
40
  compiled.textureMap[textureId] = textureIndex;
128
- const imagePath = getImagePath(data, parent);
41
+ const imagePath = loader.getImagePath(data, parent);
129
42
  if (cache) {
130
- data.base64 = await getImageBase64(imagePath);
43
+ data.base64 = await loader.getImageBase64(imagePath);
131
44
  }
132
45
  if (!data.atlas) {
133
- compiled.images[textureIndex] = await loadImageForShader(imagePath);
134
- compiled.originalImages[textureIndex] = await loadImageForOriginal(imagePath);
46
+ compiled.images[textureIndex] = await loader.loadImageForShader(imagePath);
135
47
  return textureIndex + 1;
136
48
  }
137
- const tiles = await sliceImageIntoTiles(imagePath, ...data.atlas.tiles);
49
+ const tiles = await loader.sliceImageIntoTiles(imagePath, ...data.atlas.tiles);
138
50
  for (let i = 0; i < tiles.length; i++) {
139
- compiled.images[textureIndex + i] = await loadImageForShader(tiles[i]);
140
- compiled.originalImages[textureIndex + i] = await loadImageForOriginal(tiles[i]);
51
+ compiled.images[textureIndex + i] = await loader.loadImageForShader(tiles[i].src);
141
52
  }
142
53
  compiled.atlasSizeMap[textureId] = data.atlas.tiles;
143
54
  if (data.animated) {
@@ -153,36 +64,22 @@ async function process(compiled, data, textureIndex, parent, cache = false) {
153
64
  }
154
65
  return textureIndex + tiles.length;
155
66
  }
156
- export async function BuildTextureData({ type, baseURL: currentBaseURL, textures, finalSize: currentFinalSize, createCache, }, progress) {
157
- const defaultBaseURL = currentBaseURL || "assets/textures";
158
- finalSize[0] = currentFinalSize ? currentFinalSize[0] : 256;
159
- finalSize[1] = currentFinalSize ? currentFinalSize[1] : 256;
160
- if (!canvas) {
161
- canvas = document.createElement("canvas");
162
- canvas.width = finalSize[0];
163
- canvas.height = finalSize[1];
164
- context = canvas.getContext("2d", {
165
- willReadFrequently: true,
166
- });
167
- context.imageSmoothingEnabled = false;
168
- atlasCanvas = document.createElement("canvas");
169
- atlasContext = atlasCanvas.getContext("2d", {
170
- willReadFrequently: true,
171
- });
172
- // atlasContext.imageSmoothingEnabled = false;
173
- if (!context)
174
- throw new Error(`Error could not create CanvasRenderingContext2D`);
67
+ export async function BuildTextureData({ type, baseURL, textures, finalSize, createCache }, progress) {
68
+ const defaultBaseURL = baseURL || "assets/textures";
69
+ if (!loader) {
70
+ loader = new TextureLoader();
175
71
  }
72
+ loader.setSize(finalSize || [16, 16]);
176
73
  const compiled = new CompiledTexture(type);
177
74
  let count = 0;
178
75
  for (const texture of textures) {
179
76
  progress.completeWorkItems(1);
180
77
  progress.setStatus(`Building Texture ${type} | ${texture.id}`);
181
78
  if (texture.basePath) {
182
- baseURL = texture.basePath;
79
+ loader.baseURL = texture.basePath;
183
80
  }
184
81
  else {
185
- baseURL = defaultBaseURL;
82
+ loader.baseURL = defaultBaseURL;
186
83
  }
187
84
  if (!texture.variations?.length) {
188
85
  try {
@@ -199,10 +96,10 @@ export async function BuildTextureData({ type, baseURL: currentBaseURL, textures
199
96
  for (let i = 0; i < texture.variations.length; i++) {
200
97
  const vara = texture.variations[i];
201
98
  if (texture.basePath) {
202
- baseURL = texture.basePath;
99
+ loader.baseURL = texture.basePath;
203
100
  }
204
101
  else {
205
- baseURL = defaultBaseURL;
102
+ loader.baseURL = defaultBaseURL;
206
103
  }
207
104
  if (typeof vara == "string") {
208
105
  const newData = { type: texture.type, id: vara };
@@ -220,10 +117,10 @@ export async function BuildTextureData({ type, baseURL: currentBaseURL, textures
220
117
  }
221
118
  try {
222
119
  if (vara.basePath) {
223
- baseURL = vara.basePath;
120
+ loader.baseURL = vara.basePath;
224
121
  }
225
122
  else {
226
- baseURL = defaultBaseURL;
123
+ loader.baseURL = defaultBaseURL;
227
124
  }
228
125
  count = await process(compiled, vara, count, texture.id, createCache);
229
126
  }
@@ -0,0 +1,6 @@
1
+ import { Vec2Array } from "@amodx/math";
2
+ import { CompactedTextureData, TextureData } from "../Texture.types";
3
+ export declare function CreateCompactedTexture(type: string, baseURL: string, size: Vec2Array, textures: TextureData[]): Promise<{
4
+ data: CompactedTextureData;
5
+ image: HTMLImageElement;
6
+ }>;
@@ -0,0 +1,105 @@
1
+ import { TextureLoader } from "../Classes/TextureLoader";
2
+ import { CompactedTextureReader } from "../Classes/CompactedTextureReader";
3
+ async function process(loader, reader, node, data, textureIndex, parent) {
4
+ const imagePath = loader.getImagePath(data, parent);
5
+ if (!data.atlas) {
6
+ const loadedImage = await loader.loadImage(imagePath);
7
+ reader.writeImage(textureIndex, loadedImage);
8
+ node.index = textureIndex;
9
+ return textureIndex + 1;
10
+ }
11
+ node.atlas = data.atlas.tiles;
12
+ const tiles = await loader.sliceImageIntoTiles(imagePath, ...data.atlas.tiles);
13
+ node.index = [];
14
+ for (let i = 0; i < tiles.length; i++) {
15
+ node.index.push(textureIndex + i);
16
+ reader.writeImage(textureIndex + i, tiles[i]);
17
+ }
18
+ return textureIndex + tiles.length;
19
+ }
20
+ export async function CreateCompactedTexture(type, baseURL, size, textures) {
21
+ const defaultBaseURL = baseURL || "assets/textures";
22
+ const compatexTextureData = {
23
+ type,
24
+ size: [0, 0],
25
+ textureSize: size,
26
+ nodes: [],
27
+ };
28
+ let totalImageCount = 0;
29
+ for (const textureData of textures) {
30
+ if (!textureData.variations?.length) {
31
+ if (textureData.atlas) {
32
+ totalImageCount +=
33
+ textureData.atlas.tiles[0] * textureData.atlas.tiles[1];
34
+ }
35
+ else {
36
+ totalImageCount++;
37
+ }
38
+ continue;
39
+ }
40
+ if (textureData.variations) {
41
+ for (const varation of textureData.variations) {
42
+ if (typeof varation == "string") {
43
+ totalImageCount++;
44
+ continue;
45
+ }
46
+ if (varation.atlas) {
47
+ totalImageCount += varation.atlas.tiles[0] * varation.atlas.tiles[1];
48
+ }
49
+ else {
50
+ totalImageCount++;
51
+ }
52
+ }
53
+ }
54
+ }
55
+ const width = Math.ceil(Math.sqrt(totalImageCount)) * size[0];
56
+ const height = Math.ceil(Math.sqrt(totalImageCount)) * size[1];
57
+ compatexTextureData.size = [width, height];
58
+ const loader = new TextureLoader();
59
+ loader.setSize(size);
60
+ const compactedTextureReader = new CompactedTextureReader();
61
+ compactedTextureReader.setSize([width, height], size);
62
+ let textureIndex = 0;
63
+ for (const textureData of textures) {
64
+ if (textureData.basePath) {
65
+ loader.baseURL = textureData.basePath;
66
+ }
67
+ else {
68
+ loader.baseURL = defaultBaseURL;
69
+ }
70
+ const baseNode = {
71
+ id: textureData.id,
72
+ index: 0,
73
+ };
74
+ compatexTextureData.nodes.push(baseNode);
75
+ if (!textureData?.variations?.length) {
76
+ textureIndex = await process(loader, compactedTextureReader, baseNode, textureData, textureIndex, null);
77
+ }
78
+ if (textureData.variations) {
79
+ baseNode.variations = [];
80
+ for (let varation of textureData.variations) {
81
+ if (typeof varation == "string") {
82
+ varation = { id: varation };
83
+ if (textureData.basePath)
84
+ varation.basePath = textureData.basePath;
85
+ }
86
+ if (varation.basePath) {
87
+ loader.baseURL = varation.basePath;
88
+ }
89
+ else {
90
+ loader.baseURL = defaultBaseURL;
91
+ }
92
+ const varationNode = {
93
+ id: varation.id,
94
+ index: 0,
95
+ };
96
+ baseNode.variations.push(varationNode);
97
+ textureIndex = await process(loader, compactedTextureReader, varationNode, varation, textureIndex, textureData.id);
98
+ }
99
+ }
100
+ }
101
+ return {
102
+ data: compatexTextureData,
103
+ image: compactedTextureReader.getFinalImage(),
104
+ };
105
+ }
@@ -0,0 +1,2 @@
1
+ import { CompactedTextureData, TextureData } from "../Texture.types";
2
+ export declare function ReadCompactedTexture(data: CompactedTextureData, textures: TextureData[], path: string): Promise<void>;
@@ -0,0 +1,42 @@
1
+ import { CompactedTextureReader } from "../Classes/CompactedTextureReader";
2
+ function findVarationTextureData(id, textureData) {
3
+ if (!textureData.variations)
4
+ return null;
5
+ for (let i = 0; i < textureData.variations.length; i++) {
6
+ if (typeof textureData.variations[i] == "string" &&
7
+ textureData.variations[i] == id) {
8
+ const data = {
9
+ id,
10
+ };
11
+ textureData.variations[i] = data;
12
+ return data;
13
+ }
14
+ else if (textureData.variations[i].id == id) {
15
+ return textureData.variations[i];
16
+ }
17
+ }
18
+ return null;
19
+ }
20
+ export async function ReadCompactedTexture(data, textures, path) {
21
+ const textureMap = new Map();
22
+ const compactedTextureMap = new Map();
23
+ for (const textureData of textures) {
24
+ textureMap.set(textureData.id, textureData);
25
+ }
26
+ for (const textureData of data.nodes) {
27
+ compactedTextureMap.set(textureData.id, textureData);
28
+ }
29
+ const compactedTextureReader = new CompactedTextureReader();
30
+ compactedTextureReader.setSize(data.size, data.textureSize);
31
+ await compactedTextureReader.loadImage(path);
32
+ for (const node of data.nodes) {
33
+ const textureData = textureMap.get(node.id);
34
+ textureData.base64 = (await compactedTextureReader.readImage(node)).src;
35
+ if (node.variations) {
36
+ for (const varation of node.variations) {
37
+ const data = findVarationTextureData(varation.id, textureData);
38
+ data.base64 = (await compactedTextureReader.readImage(varation)).src;
39
+ }
40
+ }
41
+ }
42
+ }
@@ -64,3 +64,17 @@ export type TextureData = {
64
64
  */
65
65
  variations?: (string | TextureDataBase)[];
66
66
  } & TextureDataBase;
67
+ export type CompactedTextureData = {
68
+ type: string;
69
+ size: [sizeX: number, sizeY: number];
70
+ textureSize: [sizeX: number, sizeY: number];
71
+ nodes: CompactedTextureNodeData[];
72
+ };
73
+ export type CompactedTextureNodeBaseData = {
74
+ id: string;
75
+ index: number | number[];
76
+ atlas?: [sizeX: number, sizeY: number];
77
+ };
78
+ export type CompactedTextureNodeData = {
79
+ variations?: CompactedTextureNodeBaseData[];
80
+ } & CompactedTextureNodeBaseData;
@@ -1,7 +1,8 @@
1
+ import { Vec2Array } from "@amodx/math";
1
2
  import { WorkItemProgress } from "../Util/WorkItemProgress.js";
2
3
  import { CompiledTexture } from "./Classes/CompiledTexture.js";
3
4
  import { BuildTextureDataProps } from "./Functions/BuildTextureData.js";
4
- import type { TextureData } from "./Texture.types";
5
+ import type { CompactedTextureData, TextureData } from "./Texture.types";
5
6
  export declare class TextureManager {
6
7
  static _textureTypes: Map<string, TextureData[]>;
7
8
  static _compiledTextures: Map<string, CompiledTexture>;
@@ -9,4 +10,9 @@ export declare class TextureManager {
9
10
  static registerTexture(textureData: TextureData[]): void;
10
11
  static getTexture(id: string): CompiledTexture;
11
12
  static compiledTextures(props?: Omit<BuildTextureDataProps, "textures" | "type">, progress?: WorkItemProgress): Promise<void>;
13
+ static createCompactedTextures(baseURL: string, textureSize: Vec2Array): Promise<{
14
+ data: CompactedTextureData;
15
+ image: HTMLImageElement;
16
+ }[]>;
17
+ static readCompactedTexture(data: CompactedTextureData, path: string): Promise<void>;
12
18
  }
@@ -1,5 +1,7 @@
1
1
  import { WorkItemProgress } from "../Util/WorkItemProgress.js";
2
2
  import { BuildTextureData, } from "./Functions/BuildTextureData.js";
3
+ import { CreateCompactedTexture } from "./Functions/CreateCompactedTexture.js";
4
+ import { ReadCompactedTexture } from "./Functions/ReadCompactedTexture.js";
3
5
  const missingTexture = {
4
6
  id: "dve_missing",
5
7
  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==",
@@ -40,6 +42,17 @@ export class TextureManager {
40
42
  this._compiledTextures.set(type, compiled);
41
43
  }
42
44
  }
45
+ static async createCompactedTextures(baseURL, textureSize) {
46
+ const returnData = [];
47
+ for (const [type, data] of this._textureTypes) {
48
+ returnData.push(await CreateCompactedTexture(type, baseURL, textureSize, data));
49
+ }
50
+ return returnData;
51
+ }
52
+ static async readCompactedTexture(data, path) {
53
+ const textures = this._textureTypes.get(data.type);
54
+ await ReadCompactedTexture(data, textures, path);
55
+ }
43
56
  }
44
57
  TextureManager.addTextureType("dve_item");
45
58
  TextureManager.addTextureType("dve_voxel");
@@ -6,6 +6,7 @@ import { PaintVoxelData } from "../../Voxels/Types/PaintVoxelData.js";
6
6
  import { VoxelPathData } from "../../Templates/Path/VoxelPath.types.js";
7
7
  import { IVoxelSelection } from "../../Templates/Selection/VoxelSelection.js";
8
8
  export declare class BrushTool {
9
+ private temp;
9
10
  data: PaintVoxelData;
10
11
  dimension: number;
11
12
  x: number;
@@ -28,8 +29,9 @@ export declare class BrushTool {
28
29
  setLevelState(levelState: number): this;
29
30
  setMod(mod: number): this;
30
31
  clear(): void;
31
- _paint(): false | undefined;
32
- _erase(): void;
32
+ protected _paint(): false | undefined;
33
+ protected _paintRaw(raw: RawVoxelData): false | undefined;
34
+ protected _erase(): void;
33
35
  paint(): this;
34
36
  paintTemplate(voxelTemplate: IVoxelTemplate): void;
35
37
  paintPath(data: VoxelPathData): void;
@@ -4,9 +4,9 @@ import { WorldRegister } from "../../World/WorldRegister.js";
4
4
  import { VoxelLUT } from "../../Voxels/Data/VoxelLUT.js";
5
5
  import { PaintVoxelData } from "../../Voxels/Types/PaintVoxelData.js";
6
6
  const air = [0, 0, 0, 0];
7
- const temp = [0, 0, 0, 0];
8
7
  PaintVoxelData.Set;
9
8
  export class BrushTool {
9
+ temp = [0, 0, 0, 0];
10
10
  data = PaintVoxelData.Create();
11
11
  dimension = 0;
12
12
  x = 0;
@@ -87,8 +87,7 @@ export class BrushTool {
87
87
  }
88
88
  setSecondaryName(name) {
89
89
  if (name) {
90
- this.data.secondaryVoxelId =
91
- VoxelLUT.voxelNametoIdMap.get(name);
90
+ this.data.secondaryVoxelId = VoxelLUT.voxelNametoIdMap.get(name);
92
91
  }
93
92
  else {
94
93
  this.data.secondaryVoxelId = "";
@@ -115,11 +114,14 @@ export class BrushTool {
115
114
  clear() {
116
115
  this.data.id = "dve_air";
117
116
  this.data.name = "";
117
+ this.data.state = 0;
118
+ this.data.mod = 0;
118
119
  this.data.secondaryVoxelId = "";
120
+ this.data.secondaryName = "";
121
+ this.data.secondaryState = 0;
122
+ this.data.secondaryMod = 0;
119
123
  this.data.level = 0;
120
124
  this.data.levelState = 0;
121
- this.data.state = 0;
122
- this.data.mod = 0;
123
125
  this.x = 0;
124
126
  this.y = 0;
125
127
  this.z = 0;
@@ -136,7 +138,26 @@ export class BrushTool {
136
138
  voxel.setLevel(this.data.level);
137
139
  if (this.data.secondaryVoxelId && this.data.secondaryVoxelId != "dve_air") {
138
140
  voxel.setSecondary(true);
139
- voxel.setStringId(this.data.secondaryVoxelId);
141
+ voxel.setStringId(this.data.secondaryVoxelId, this.data.secondaryState, this.data.secondaryMod);
142
+ voxel.setSecondary(false);
143
+ }
144
+ voxel.process();
145
+ if (voxel.isLightSource() && voxel.getLightSourceValue()) {
146
+ voxel.setLight(voxel.getLightSourceValue());
147
+ }
148
+ voxel.updateVoxel(0);
149
+ }
150
+ _paintRaw(raw) {
151
+ if (!this.dataCursor.inBounds(this.x, this.y, this.z))
152
+ return false;
153
+ const voxel = this.dataCursor.getVoxel(this.x, this.y, this.z);
154
+ if (!voxel)
155
+ return;
156
+ voxel.setId(raw[0]);
157
+ voxel.setLevel(raw[2]);
158
+ if (voxel.canHaveSecondaryVoxel() && raw[3] !== 0) {
159
+ voxel.setSecondary(true);
160
+ voxel.setId(raw[3]);
140
161
  voxel.setSecondary(false);
141
162
  }
142
163
  voxel.process();
@@ -158,6 +179,7 @@ export class BrushTool {
158
179
  paintTemplate(voxelTemplate) {
159
180
  const { x: ox, y: oy, z: oz } = this;
160
181
  const { x: sx, y: sy, z: sz } = voxelTemplate.bounds.size;
182
+ const temp = [0, 0, 0, 0];
161
183
  for (let x = 0; x < sx; x++) {
162
184
  for (let y = 0; y < sy; y++) {
163
185
  for (let z = 0; z < sz; z++) {
@@ -2,4 +2,4 @@ import { BinaryBufferFormat } from "../BinaryBuffer.types";
2
2
  export declare function DetermineSubByteArrayForBinaryBuffer(paletteSize: number): BinaryBufferFormat | null;
3
3
  export declare function GetConvertedBinaryBufferSize(source: Uint8Array | Uint16Array, format: BinaryBufferFormat): number;
4
4
  export declare function GetBinaryBufferIndexLength(source: Uint8Array | Uint16Array, format: BinaryBufferFormat): number;
5
- export declare function ConvertBinaryBuffer(source: Uint8Array | Uint16Array, sourceType: BinaryBufferFormat, destinationType: BinaryBufferFormat): Uint8Array<ArrayBuffer> | Uint16Array<ArrayBuffer>;
5
+ export declare function ConvertBinaryBuffer(source: Uint8Array | Uint16Array, sourceType: BinaryBufferFormat, destinationType: BinaryBufferFormat): Uint16Array<ArrayBuffer> | Uint8Array<ArrayBuffer>;
@@ -1,5 +1,6 @@
1
1
  /** # Tick Interval
2
2
  * Creates a predictable tick interval.
3
+ * Uses requestAnimationFrame when available, falling back to setTimeout.
3
4
  */
4
5
  export declare class TickInterval {
5
6
  stopOnError: boolean;
@@ -7,6 +8,8 @@ export declare class TickInterval {
7
8
  private interval;
8
9
  private currentTimeout;
9
10
  private __timeoutFunc;
11
+ private _useAnimationFrame;
12
+ private _lastTick;
10
13
  constructor(run?: () => void | Promise<void>, interval?: number, stopOnError?: boolean);
11
14
  setOnRun(run: () => void | Promise<void>): this;
12
15
  setInterval(interval: number): this;
@@ -1,5 +1,6 @@
1
1
  /** # Tick Interval
2
2
  * Creates a predictable tick interval.
3
+ * Uses requestAnimationFrame when available, falling back to setTimeout.
3
4
  */
4
5
  export class TickInterval {
5
6
  stopOnError;
@@ -7,8 +8,11 @@ export class TickInterval {
7
8
  interval = 1;
8
9
  currentTimeout;
9
10
  __timeoutFunc;
11
+ _useAnimationFrame;
12
+ _lastTick = 0;
10
13
  constructor(run, interval, stopOnError = true) {
11
14
  this.stopOnError = stopOnError;
15
+ this._useAnimationFrame = typeof requestAnimationFrame !== "undefined";
12
16
  if (run)
13
17
  this.setOnRun(run);
14
18
  if (interval !== undefined)
@@ -30,19 +34,43 @@ export class TickInterval {
30
34
  runInterval() {
31
35
  if (!this._active)
32
36
  return;
33
- this.currentTimeout = setTimeout(this.__timeoutFunc, this.interval);
37
+ if (this._useAnimationFrame) {
38
+ this.currentTimeout = requestAnimationFrame((timestamp) => {
39
+ if (!this._active)
40
+ return;
41
+ // Only fire once enough time has elapsed, matching the requested interval.
42
+ if (timestamp - this._lastTick >= this.interval) {
43
+ this._lastTick = timestamp;
44
+ this.__timeoutFunc();
45
+ }
46
+ else {
47
+ // Not time yet — re-queue without calling the callback.
48
+ this.runInterval();
49
+ }
50
+ });
51
+ }
52
+ else {
53
+ this.currentTimeout = setTimeout(this.__timeoutFunc, this.interval);
54
+ }
34
55
  }
35
56
  start() {
36
57
  if (!this._active) {
37
58
  this._active = true;
59
+ this._lastTick = 0;
38
60
  this.runInterval();
39
61
  }
40
62
  return this;
41
63
  }
42
64
  stop() {
43
65
  this._active = false;
44
- if (this.currentTimeout !== undefined)
45
- clearTimeout(this.currentTimeout);
66
+ if (this.currentTimeout !== undefined) {
67
+ if (this._useAnimationFrame) {
68
+ cancelAnimationFrame(this.currentTimeout);
69
+ }
70
+ else {
71
+ clearTimeout(this.currentTimeout);
72
+ }
73
+ }
46
74
  this.currentTimeout = undefined;
47
75
  return this;
48
76
  }
@@ -1,6 +1,7 @@
1
1
  import { BinarySchema } from "../State/Schema/BinarySchema";
2
2
  import { ArchivedVoxelDataForPalette, VoxelArchivePaletteData } from "./VoxelArchive.types";
3
3
  export declare class VoxelPaletteArchiveReader {
4
+ temp: [id: string, state: number, mod: number];
4
5
  voxelPalette: Uint16Array;
5
6
  _voxels: ArchivedVoxelDataForPalette[];
6
7
  _voxelStateSchema: Map<string, BinarySchema>;