minerender 2.1.0-alpha.132 → 2.1.0-alpha.133
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/dist/browser/esm/assets/Fonts.mjs +31 -4
- package/dist/browser/esm/assets/Fonts.mjs.map +1 -1
- package/dist/browser/esm/assets/_fonts/Unihex.mjs +166 -0
- package/dist/browser/esm/assets/_fonts/Unihex.mjs.map +1 -0
- package/dist/browser/esm/assets/source/HostedAssetSource.mjs +12 -1
- package/dist/browser/esm/assets/source/HostedAssetSource.mjs.map +1 -1
- package/dist/browser/esm/assets/source/parser/AssetParsers.mjs +1 -0
- package/dist/browser/esm/assets/source/parser/AssetParsers.mjs.map +1 -1
- package/dist/browser/esm/cache/Caching.mjs +2 -0
- package/dist/browser/esm/cache/Caching.mjs.map +1 -1
- package/dist/browser/esm/gui/GuiText.mjs +4 -3
- package/dist/browser/esm/gui/GuiText.mjs.map +1 -1
- package/dist/browser/esm/index.browser.d.mts +23 -4
- package/dist/browser/index.d.ts +23 -4
- package/dist/browser/index.js +245 -31
- package/dist/browser/index.js.map +1 -1
- package/dist/bundle.js +288 -31
- package/dist/bundle.js.map +1 -1
- package/dist/node/index.d.mts +23 -4
- package/dist/node/index.d.ts +23 -4
- package/dist/node/index.js +249 -31
- package/dist/node/index.js.map +1 -1
- package/dist/node/index.mjs +249 -31
- package/dist/node/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/bundle.js
CHANGED
|
@@ -35632,6 +35632,7 @@ void main() {
|
|
|
35632
35632
|
this.entityAnimationCache,
|
|
35633
35633
|
this.blockEntityIndexCache,
|
|
35634
35634
|
this.fontCache,
|
|
35635
|
+
this.unihexCache,
|
|
35635
35636
|
this.bannerPatternCache,
|
|
35636
35637
|
this.mineRenderDataCache,
|
|
35637
35638
|
this.usernameUuidCache,
|
|
@@ -35685,6 +35686,7 @@ void main() {
|
|
|
35685
35686
|
_Caching.entityTextureCache = _Caching.createAssetCache();
|
|
35686
35687
|
_Caching.entityAnimationCache = _Caching.createAssetCache();
|
|
35687
35688
|
_Caching.blockEntityIndexCache = _Caching.createAssetCache();
|
|
35689
|
+
_Caching.unihexCache = _Caching.createAssetCache();
|
|
35688
35690
|
_Caching.fontCache = _Caching.createAssetCache();
|
|
35689
35691
|
_Caching.bannerPatternCache = _Caching.createAssetCache();
|
|
35690
35692
|
_Caching.mineRenderDataCache = _Caching.createAssetCache();
|
|
@@ -37098,6 +37100,7 @@ void main() {
|
|
|
37098
37100
|
AssetParser2["IMAGE"] = "image";
|
|
37099
37101
|
AssetParser2["LIST"] = "list";
|
|
37100
37102
|
AssetParser2["JSON"] = "json";
|
|
37103
|
+
AssetParser2["BINARY"] = "binary";
|
|
37101
37104
|
return AssetParser2;
|
|
37102
37105
|
})(AssetParser || {});
|
|
37103
37106
|
}
|
|
@@ -73063,7 +73066,7 @@ return ${compiler2.callType("value", tagType)}
|
|
|
73063
73066
|
});
|
|
73064
73067
|
|
|
73065
73068
|
// src/assets/source/HostedAssetSource.ts
|
|
73066
|
-
var p7, DEFAULT_OPTIONS2, _HostedAssetSource, HostedAssetSource;
|
|
73069
|
+
var BINARY_TIMEOUT, p7, DEFAULT_OPTIONS2, _HostedAssetSource, HostedAssetSource;
|
|
73067
73070
|
var init_HostedAssetSource = __esm({
|
|
73068
73071
|
"src/assets/source/HostedAssetSource.ts"() {
|
|
73069
73072
|
init_dirname();
|
|
@@ -73079,6 +73082,7 @@ return ${compiler2.callType("value", tagType)}
|
|
|
73079
73082
|
init_AssetLoader();
|
|
73080
73083
|
init_parser();
|
|
73081
73084
|
init_merge();
|
|
73085
|
+
BINARY_TIMEOUT = 6e4;
|
|
73082
73086
|
p7 = prefix("HostedAssetSource");
|
|
73083
73087
|
DEFAULT_OPTIONS2 = {
|
|
73084
73088
|
retryDefaults: true
|
|
@@ -73219,6 +73223,15 @@ return ${compiler2.callType("value", tagType)}
|
|
|
73219
73223
|
return response.data;
|
|
73220
73224
|
}
|
|
73221
73225
|
};
|
|
73226
|
+
_HostedAssetSource.BINARY = {
|
|
73227
|
+
config(request) {
|
|
73228
|
+
request.timeout = BINARY_TIMEOUT;
|
|
73229
|
+
request.responseType = "arraybuffer";
|
|
73230
|
+
},
|
|
73231
|
+
parse(response) {
|
|
73232
|
+
return { data: new Uint8Array(response.data) };
|
|
73233
|
+
}
|
|
73234
|
+
};
|
|
73222
73235
|
_HostedAssetSource.PARSER_MAP = /* @__PURE__ */ new Map([
|
|
73223
73236
|
["model" /* MODEL */, _HostedAssetSource.MODEL],
|
|
73224
73237
|
["blockstate" /* BLOCKSTATE */, _HostedAssetSource.BLOCKSTATE],
|
|
@@ -73226,7 +73239,8 @@ return ${compiler2.callType("value", tagType)}
|
|
|
73226
73239
|
["nbt" /* NBT */, _HostedAssetSource.NBT],
|
|
73227
73240
|
["image" /* IMAGE */, _HostedAssetSource.IMAGE],
|
|
73228
73241
|
["list" /* LIST */, _HostedAssetSource.LIST],
|
|
73229
|
-
["json" /* JSON */, _HostedAssetSource.JSON]
|
|
73242
|
+
["json" /* JSON */, _HostedAssetSource.JSON],
|
|
73243
|
+
["binary" /* BINARY */, _HostedAssetSource.BINARY]
|
|
73230
73244
|
]);
|
|
73231
73245
|
HostedAssetSource = _HostedAssetSource;
|
|
73232
73246
|
}
|
|
@@ -81841,7 +81855,7 @@ return ${compiler2.callType("value", tagType)}
|
|
|
81841
81855
|
function readUint8Array(reader, offset, size, diskNumber) {
|
|
81842
81856
|
return reader.readUint8Array(offset, size, diskNumber);
|
|
81843
81857
|
}
|
|
81844
|
-
var ERR_ITERATOR_COMPLETED_TOO_SOON, HTTP_HEADER_CONTENT_TYPE, DEFAULT_CHUNK_SIZE, PROPERTY_NAME_WRITABLE, Stream, Reader, BlobReader, BlobWriter, SplitDataReader, SplitDataWriter;
|
|
81858
|
+
var ERR_ITERATOR_COMPLETED_TOO_SOON, HTTP_HEADER_CONTENT_TYPE, DEFAULT_CHUNK_SIZE, PROPERTY_NAME_WRITABLE, Stream, Reader, BlobReader, BlobWriter, TextWriter, Uint8ArrayReader, SplitDataReader, SplitDataWriter;
|
|
81845
81859
|
var init_io = __esm({
|
|
81846
81860
|
"../../node_modules/@zip.js/zip.js/lib/core/io.js"() {
|
|
81847
81861
|
init_dirname();
|
|
@@ -81924,6 +81938,46 @@ return ${compiler2.callType("value", tagType)}
|
|
|
81924
81938
|
return this.blob;
|
|
81925
81939
|
}
|
|
81926
81940
|
};
|
|
81941
|
+
TextWriter = class extends BlobWriter {
|
|
81942
|
+
constructor(encoding) {
|
|
81943
|
+
super(encoding);
|
|
81944
|
+
Object.assign(this, {
|
|
81945
|
+
encoding,
|
|
81946
|
+
utf8: !encoding || encoding.toLowerCase() == "utf-8"
|
|
81947
|
+
});
|
|
81948
|
+
}
|
|
81949
|
+
async getData() {
|
|
81950
|
+
const {
|
|
81951
|
+
encoding,
|
|
81952
|
+
utf8
|
|
81953
|
+
} = this;
|
|
81954
|
+
const blob = await super.getData();
|
|
81955
|
+
if (blob.text && utf8) {
|
|
81956
|
+
return blob.text();
|
|
81957
|
+
} else {
|
|
81958
|
+
const reader = new FileReader();
|
|
81959
|
+
return new Promise((resolve, reject) => {
|
|
81960
|
+
Object.assign(reader, {
|
|
81961
|
+
onload: ({ target }) => resolve(target.result),
|
|
81962
|
+
onerror: () => reject(reader.error)
|
|
81963
|
+
});
|
|
81964
|
+
reader.readAsText(blob, encoding);
|
|
81965
|
+
});
|
|
81966
|
+
}
|
|
81967
|
+
}
|
|
81968
|
+
};
|
|
81969
|
+
Uint8ArrayReader = class extends Reader {
|
|
81970
|
+
constructor(array) {
|
|
81971
|
+
super();
|
|
81972
|
+
Object.assign(this, {
|
|
81973
|
+
array,
|
|
81974
|
+
size: array.length
|
|
81975
|
+
});
|
|
81976
|
+
}
|
|
81977
|
+
readUint8Array(index, length) {
|
|
81978
|
+
return this.array.slice(index, index + length);
|
|
81979
|
+
}
|
|
81980
|
+
};
|
|
81927
81981
|
SplitDataReader = class extends Reader {
|
|
81928
81982
|
constructor(readers) {
|
|
81929
81983
|
super();
|
|
@@ -84682,6 +84736,181 @@ ${key}` : key;
|
|
|
84682
84736
|
}
|
|
84683
84737
|
});
|
|
84684
84738
|
|
|
84739
|
+
// src/assets/_fonts/Unihex.ts
|
|
84740
|
+
var Unihex_exports = {};
|
|
84741
|
+
__export(Unihex_exports, {
|
|
84742
|
+
loadUnihex: () => loadUnihex
|
|
84743
|
+
});
|
|
84744
|
+
function readHex(text2, filename, glyphs) {
|
|
84745
|
+
const lines = text2.split("\n");
|
|
84746
|
+
if (lines[lines.length - 1] === "") lines.pop();
|
|
84747
|
+
lines.forEach((line, index) => {
|
|
84748
|
+
const match = /^([0-9A-F]{4,6}):([0-9A-F]+)$/.exec(line);
|
|
84749
|
+
if (!match || ![32, 64, 96, 128].includes(match[2].length)) {
|
|
84750
|
+
throw new Error(`Invalid Unihex record in ${filename} at line ${index + 1}`);
|
|
84751
|
+
}
|
|
84752
|
+
const codepoint = parseInt(match[1], 16);
|
|
84753
|
+
if (codepoint > 1114111) throw new Error(`Invalid Unihex codepoint in ${filename} at line ${index + 1}`);
|
|
84754
|
+
const bitWidth = match[2].length / 4;
|
|
84755
|
+
const rowLength = bitWidth / 4;
|
|
84756
|
+
const rows = new Uint32Array(GLYPH_HEIGHT);
|
|
84757
|
+
let mask = 0;
|
|
84758
|
+
for (let y5 = 0; y5 < GLYPH_HEIGHT; y5++) {
|
|
84759
|
+
rows[y5] = parseInt(match[2].slice(y5 * rowLength, (y5 + 1) * rowLength), 16);
|
|
84760
|
+
mask |= rows[y5];
|
|
84761
|
+
}
|
|
84762
|
+
let left = 0, right = bitWidth;
|
|
84763
|
+
if (mask) {
|
|
84764
|
+
while (!(mask >>> bitWidth - left - 1 & 1)) left++;
|
|
84765
|
+
right = bitWidth - 1;
|
|
84766
|
+
while (!(mask >>> bitWidth - right - 1 & 1)) right--;
|
|
84767
|
+
}
|
|
84768
|
+
glyphs.set(codepoint, { rows, bitWidth, left, right });
|
|
84769
|
+
});
|
|
84770
|
+
}
|
|
84771
|
+
async function parseUnihex(key) {
|
|
84772
|
+
try {
|
|
84773
|
+
const asset2 = await AssetLoader.get(key, "binary" /* BINARY */);
|
|
84774
|
+
if (!asset2) throw new Error(`Could not load Unihex archive ${key.toNamespacedString()}`);
|
|
84775
|
+
const records = /* @__PURE__ */ new Map();
|
|
84776
|
+
const reader = new ZipReader(new Uint8ArrayReader(asset2.data), { useWebWorkers: false, useCompressionStream: false });
|
|
84777
|
+
try {
|
|
84778
|
+
for (const entry of await reader.getEntries()) {
|
|
84779
|
+
if (!entry.directory && entry.filename.endsWith(".hex")) {
|
|
84780
|
+
readHex(await entry.getData(new TextWriter(), { checkSignature: true }), entry.filename, records);
|
|
84781
|
+
}
|
|
84782
|
+
}
|
|
84783
|
+
} finally {
|
|
84784
|
+
await reader.close();
|
|
84785
|
+
}
|
|
84786
|
+
const indices = new Int32Array(1114112).fill(-1);
|
|
84787
|
+
const rows = new Uint32Array(records.size * GLYPH_HEIGHT), metrics = new Uint8Array(records.size * 3);
|
|
84788
|
+
let index = 0;
|
|
84789
|
+
for (const [codepoint, record] of records) {
|
|
84790
|
+
indices[codepoint] = index;
|
|
84791
|
+
rows.set(record.rows, index * GLYPH_HEIGHT);
|
|
84792
|
+
metrics.set([record.bitWidth, record.left, record.right], index * 3);
|
|
84793
|
+
index++;
|
|
84794
|
+
}
|
|
84795
|
+
return { indices, rows, metrics };
|
|
84796
|
+
} catch (error2) {
|
|
84797
|
+
console.warn(`Could not load Unihex file ${key.toNamespacedString()}`, error2);
|
|
84798
|
+
return void 0;
|
|
84799
|
+
}
|
|
84800
|
+
}
|
|
84801
|
+
async function loadUnihex(provider, fontKey, characters) {
|
|
84802
|
+
const origin = new AssetKey(DEFAULT_NAMESPACE, "", void 0, void 0, "assets", "", fontKey.root);
|
|
84803
|
+
const key = AssetKey.parse("font", provider.hex_file, origin);
|
|
84804
|
+
key.assetType = void 0;
|
|
84805
|
+
const glyphs = /* @__PURE__ */ new Map();
|
|
84806
|
+
let overrides;
|
|
84807
|
+
try {
|
|
84808
|
+
overrides = (provider.size_overrides ?? []).map((override) => {
|
|
84809
|
+
const from = override.from.codePointAt(0), to = override.to.codePointAt(0);
|
|
84810
|
+
if ([...override.from].length !== 1 || [...override.to].length !== 1 || from >= to || !Number.isInteger(override.left) || !Number.isInteger(override.right) || override.right < override.left) {
|
|
84811
|
+
throw new Error(`Invalid Unihex size override in font ${fontKey.toNamespacedString()}`);
|
|
84812
|
+
}
|
|
84813
|
+
return { ...override, from, to };
|
|
84814
|
+
});
|
|
84815
|
+
} catch (error2) {
|
|
84816
|
+
console.warn(`Could not load Unihex file ${key.toNamespacedString()}`, error2);
|
|
84817
|
+
return glyphs;
|
|
84818
|
+
}
|
|
84819
|
+
const file = await Caching.unihexCache.get(key.serialize(), () => parseUnihex(key));
|
|
84820
|
+
if (!file) return glyphs;
|
|
84821
|
+
let atlas = atlases.get(provider);
|
|
84822
|
+
if (!atlas) {
|
|
84823
|
+
atlas = new UnihexAtlas();
|
|
84824
|
+
atlases.set(provider, atlas);
|
|
84825
|
+
}
|
|
84826
|
+
for (const character of characters) {
|
|
84827
|
+
const codepoint = character.codePointAt(0), index = file.indices[codepoint];
|
|
84828
|
+
if (index < 0) continue;
|
|
84829
|
+
const record = {
|
|
84830
|
+
rows: file.rows.subarray(index * GLYPH_HEIGHT, (index + 1) * GLYPH_HEIGHT),
|
|
84831
|
+
bitWidth: file.metrics[index * 3],
|
|
84832
|
+
left: file.metrics[index * 3 + 1],
|
|
84833
|
+
right: file.metrics[index * 3 + 2]
|
|
84834
|
+
};
|
|
84835
|
+
const override = overrides.find((range) => codepoint >= range.from && codepoint <= range.to);
|
|
84836
|
+
if (override) {
|
|
84837
|
+
record.left = override.left;
|
|
84838
|
+
record.right = override.right;
|
|
84839
|
+
}
|
|
84840
|
+
const width = record.right - record.left + 1;
|
|
84841
|
+
let rendered;
|
|
84842
|
+
const render = () => rendered ?? (rendered = atlas.draw(record));
|
|
84843
|
+
glyphs.set(character, {
|
|
84844
|
+
get image() {
|
|
84845
|
+
return render().image;
|
|
84846
|
+
},
|
|
84847
|
+
get x() {
|
|
84848
|
+
return render().x;
|
|
84849
|
+
},
|
|
84850
|
+
get y() {
|
|
84851
|
+
return render().y;
|
|
84852
|
+
},
|
|
84853
|
+
width,
|
|
84854
|
+
height: GLYPH_HEIGHT,
|
|
84855
|
+
scale: 0.5,
|
|
84856
|
+
ascent: 7,
|
|
84857
|
+
advance: Math.floor(width / 2) + 1,
|
|
84858
|
+
boldOffset: 0.5,
|
|
84859
|
+
shadowOffset: 0.5
|
|
84860
|
+
});
|
|
84861
|
+
}
|
|
84862
|
+
return glyphs;
|
|
84863
|
+
}
|
|
84864
|
+
var ATLAS_SIZE, GLYPH_HEIGHT, UnihexAtlas, atlases;
|
|
84865
|
+
var init_Unihex = __esm({
|
|
84866
|
+
"src/assets/_fonts/Unihex.ts"() {
|
|
84867
|
+
init_dirname();
|
|
84868
|
+
init_buffer2();
|
|
84869
|
+
init_process2();
|
|
84870
|
+
init_zip();
|
|
84871
|
+
init_AssetKey();
|
|
84872
|
+
init_AssetLoader();
|
|
84873
|
+
init_Assets();
|
|
84874
|
+
init_Caching();
|
|
84875
|
+
init_AssetParsers();
|
|
84876
|
+
init_CanvasCompat();
|
|
84877
|
+
ATLAS_SIZE = 512;
|
|
84878
|
+
GLYPH_HEIGHT = 16;
|
|
84879
|
+
UnihexAtlas = class {
|
|
84880
|
+
constructor() {
|
|
84881
|
+
this.x = 0;
|
|
84882
|
+
this.y = 0;
|
|
84883
|
+
}
|
|
84884
|
+
draw(glyph) {
|
|
84885
|
+
const width = glyph.right - glyph.left + 1;
|
|
84886
|
+
if (this.image && this.x + width > this.image.width) {
|
|
84887
|
+
this.x = 0;
|
|
84888
|
+
this.y += GLYPH_HEIGHT;
|
|
84889
|
+
}
|
|
84890
|
+
if (!this.image || this.y + GLYPH_HEIGHT > this.image.height || width > this.image.width) {
|
|
84891
|
+
this.image = createCanvas(Math.max(ATLAS_SIZE, width), ATLAS_SIZE);
|
|
84892
|
+
this.x = 0;
|
|
84893
|
+
this.y = 0;
|
|
84894
|
+
}
|
|
84895
|
+
const context = this.image.getContext("2d");
|
|
84896
|
+
const pixels = context.createImageData(width, GLYPH_HEIGHT);
|
|
84897
|
+
for (let y5 = 0; y5 < GLYPH_HEIGHT; y5++) {
|
|
84898
|
+
for (let x4 = 0; x4 < width; x4++) {
|
|
84899
|
+
const column = glyph.left + x4;
|
|
84900
|
+
if (column < 0 || column >= glyph.bitWidth || !(glyph.rows[y5] >>> glyph.bitWidth - column - 1 & 1)) continue;
|
|
84901
|
+
pixels.data.fill(255, (y5 * width + x4) * 4, (y5 * width + x4 + 1) * 4);
|
|
84902
|
+
}
|
|
84903
|
+
}
|
|
84904
|
+
const result = { image: this.image, x: this.x, y: this.y };
|
|
84905
|
+
context.putImageData(pixels, this.x, this.y);
|
|
84906
|
+
this.x += width;
|
|
84907
|
+
return result;
|
|
84908
|
+
}
|
|
84909
|
+
};
|
|
84910
|
+
atlases = /* @__PURE__ */ new WeakMap();
|
|
84911
|
+
}
|
|
84912
|
+
});
|
|
84913
|
+
|
|
84685
84914
|
// src/assets/Fonts.ts
|
|
84686
84915
|
var Fonts;
|
|
84687
84916
|
var init_Fonts = __esm({
|
|
@@ -84695,7 +84924,7 @@ ${key}` : key;
|
|
|
84695
84924
|
init_ModelTextures();
|
|
84696
84925
|
init_Caching();
|
|
84697
84926
|
Fonts = class {
|
|
84698
|
-
/** Combines font definitions in source-priority order.
|
|
84927
|
+
/** Combines font definitions in source-priority order. TrueType providers are skipped. */
|
|
84699
84928
|
static async get(key = "minecraft:default") {
|
|
84700
84929
|
const fontKey = typeof key === "string" ? AssetKey.parse("font", key) : key;
|
|
84701
84930
|
return await Caching.fontCache.get(fontKey.serialize(), () => this.load(fontKey, []));
|
|
@@ -84711,6 +84940,7 @@ ${key}` : key;
|
|
|
84711
84940
|
const stack = await AssetLoader.getAll(key, "json" /* JSON */);
|
|
84712
84941
|
if (stack.length === 0) throw new Error(`Could not load font ${key.toNamespacedString()}`);
|
|
84713
84942
|
const glyphs = /* @__PURE__ */ new Map();
|
|
84943
|
+
const providers = [];
|
|
84714
84944
|
for (const asset2 of stack) {
|
|
84715
84945
|
for (const provider of asset2.providers) {
|
|
84716
84946
|
if (provider.filter?.uniform || provider.filter?.jp) continue;
|
|
@@ -84729,17 +84959,43 @@ ${key}` : key;
|
|
|
84729
84959
|
break;
|
|
84730
84960
|
case "reference":
|
|
84731
84961
|
case "minecraft:reference":
|
|
84732
|
-
|
|
84962
|
+
const reference = await this.load(this.relatedKey("font", provider.id, key), [...parents, serialized]);
|
|
84963
|
+
if (reference.resolve) {
|
|
84964
|
+
providers.push(async (characters) => {
|
|
84965
|
+
await reference.resolve(characters);
|
|
84966
|
+
return reference.glyphs;
|
|
84967
|
+
});
|
|
84968
|
+
continue;
|
|
84969
|
+
}
|
|
84970
|
+
provided = reference.glyphs;
|
|
84733
84971
|
break;
|
|
84972
|
+
case "unihex":
|
|
84973
|
+
case "minecraft:unihex":
|
|
84974
|
+
providers.push(async (characters) => (await Promise.resolve().then(() => (init_Unihex(), Unihex_exports))).loadUnihex(provider, key, characters));
|
|
84975
|
+
continue;
|
|
84734
84976
|
default:
|
|
84735
84977
|
continue;
|
|
84736
84978
|
}
|
|
84737
|
-
for (const [character, glyph] of provided) {
|
|
84979
|
+
if (providers.every((provider2) => provider2 instanceof Map)) for (const [character, glyph] of provided) {
|
|
84738
84980
|
if (character !== "\0" && !glyphs.has(character)) glyphs.set(character, glyph);
|
|
84739
84981
|
}
|
|
84982
|
+
providers.push(provided);
|
|
84740
84983
|
}
|
|
84741
84984
|
}
|
|
84742
|
-
return { glyphs
|
|
84985
|
+
return { glyphs, resolve: providers.every((provider) => provider instanceof Map) ? void 0 : async (characters) => {
|
|
84986
|
+
const remaining = new Set([...characters].filter((character) => character !== "\0" && character !== "\n" && character !== "\r" && !glyphs.has(character)));
|
|
84987
|
+
for (const provider of providers) {
|
|
84988
|
+
if (!remaining.size) break;
|
|
84989
|
+
const provided = provider instanceof Map ? provider : await provider([...remaining].join(""));
|
|
84990
|
+
for (const character of remaining) {
|
|
84991
|
+
const glyph = provided.get(character);
|
|
84992
|
+
if (glyph) {
|
|
84993
|
+
glyphs.set(character, glyph);
|
|
84994
|
+
remaining.delete(character);
|
|
84995
|
+
}
|
|
84996
|
+
}
|
|
84997
|
+
}
|
|
84998
|
+
} };
|
|
84743
84999
|
}
|
|
84744
85000
|
static async bitmap(provider, fontKey) {
|
|
84745
85001
|
const rows = provider.chars.map((row) => [...row]);
|
|
@@ -87964,6 +88220,7 @@ ${key}` : key;
|
|
|
87964
88220
|
}
|
|
87965
88221
|
const font = await Fonts.get(options.font);
|
|
87966
88222
|
const runs = typeof text2 === "string" ? [{ text: text2 }] : text2;
|
|
88223
|
+
await font.resolve?.(runs.map((run) => run.text).join(""));
|
|
87967
88224
|
const glyphs = [], lineWidths = [];
|
|
87968
88225
|
let line = [], width = 0;
|
|
87969
88226
|
let trailingNewline = false;
|
|
@@ -87990,7 +88247,7 @@ ${key}` : key;
|
|
|
87990
88247
|
continue;
|
|
87991
88248
|
}
|
|
87992
88249
|
const glyph = font.glyphs.get(character);
|
|
87993
|
-
const advance = (glyph?.advance ?? 6) + (style.bold ? 1 : 0);
|
|
88250
|
+
const advance = (glyph?.advance ?? 6) + (style.bold ? glyph?.boldOffset ?? 1 : 0);
|
|
87994
88251
|
line.push({ character, glyph, advance, style, x: 0, y: 0 });
|
|
87995
88252
|
width += advance;
|
|
87996
88253
|
while (width > maxWidth && line.length > 1) {
|
|
@@ -88018,7 +88275,7 @@ ${key}` : key;
|
|
|
88018
88275
|
batches.push(batch);
|
|
88019
88276
|
}
|
|
88020
88277
|
const color3 = new Color(isShadow ? (style.color & 16579836) >> 2 : style.color);
|
|
88021
|
-
const offset = isShadow ? 1 : 0;
|
|
88278
|
+
const offset = isShadow ? glyph?.shadowOffset ?? 1 : 0;
|
|
88022
88279
|
const top = glyph ? 7 - glyph.ascent : 0;
|
|
88023
88280
|
const height = glyph ? glyph.height * glyph.scale : 8;
|
|
88024
88281
|
const width = glyph ? glyph.width * glyph.scale : 5;
|
|
@@ -88048,7 +88305,7 @@ ${key}` : key;
|
|
|
88048
88305
|
for (let i4 = 0; i4 < 4; i4++) batch.colors.push(color3.r, color3.g, color3.b);
|
|
88049
88306
|
batch.indices.push(base, base + 2, base + 1, base + 2, base + 3, base + 1);
|
|
88050
88307
|
};
|
|
88051
|
-
for (const boldOffset of style.bold ? [0, 1] : [0]) {
|
|
88308
|
+
for (const boldOffset of style.bold ? [0, glyph?.boldOffset ?? 1] : [0]) {
|
|
88052
88309
|
if (glyph) quad(0, top, width, top + height, boldOffset);
|
|
88053
88310
|
else {
|
|
88054
88311
|
quad(0, 0, 5, 1, boldOffset);
|
|
@@ -104158,7 +104415,7 @@ gl_FragDepth=readDepth(vUv);
|
|
|
104158
104415
|
|
|
104159
104416
|
// src/world/SectionGeometry.ts
|
|
104160
104417
|
function buildSectionGeometry(input) {
|
|
104161
|
-
const { count, indices, templates, cullMasks, templateData, atlases, maxAtlasSize, fluids, light, ambientLight, ambientOcclusion, biomeTints } = input;
|
|
104418
|
+
const { count, indices, templates, cullMasks, templateData, atlases: atlases2, maxAtlasSize, fluids, light, ambientLight, ambientOcclusion, biomeTints } = input;
|
|
104162
104419
|
if (!Number.isInteger(maxAtlasSize) || maxAtlasSize < 1) throw new RangeError("Section atlas size must be a positive integer");
|
|
104163
104420
|
if (count > indices.length || count > templates.length || count > cullMasks.length) throw new RangeError("Section entry count exceeds its arrays");
|
|
104164
104421
|
if (biomeTints && biomeTints.length !== count * 3) throw new RangeError("Section biome tints must contain RGB for each placement");
|
|
@@ -104193,8 +104450,8 @@ gl_FragDepth=readDepth(vUv);
|
|
|
104193
104450
|
const locations = /* @__PURE__ */ new Map();
|
|
104194
104451
|
for (const [layer, layerAtlases] of [...visibleAtlases].sort(([a4], [b4]) => a4 - b4)) {
|
|
104195
104452
|
const firstPage = pages.length;
|
|
104196
|
-
for (const atlas of [...layerAtlases].sort((a4, b4) => Number(
|
|
104197
|
-
const { width, height, animated } =
|
|
104453
|
+
for (const atlas of [...layerAtlases].sort((a4, b4) => Number(atlases2[a4].animated) - Number(atlases2[b4].animated) || (atlases2[a4].animated ? a4 - b4 : atlases2[b4].height - atlases2[a4].height))) {
|
|
104454
|
+
const { width, height, animated } = atlases2[atlas];
|
|
104198
104455
|
if (width > maxAtlasSize || height > maxAtlasSize) throw new RangeError("Model atlas exceeds the section atlas size limit");
|
|
104199
104456
|
let selected = -1;
|
|
104200
104457
|
for (let i4 = firstPage; !animated && i4 < pages.length; i4++) {
|
|
@@ -104237,7 +104494,7 @@ gl_FragDepth=readDepth(vUv);
|
|
|
104237
104494
|
});
|
|
104238
104495
|
if (!quads.sprites.length) continue;
|
|
104239
104496
|
if (!fluidPages.has(fluid)) {
|
|
104240
|
-
const { width, height } =
|
|
104497
|
+
const { width, height } = atlases2[data.atlas];
|
|
104241
104498
|
if (width > maxAtlasSize || height > maxAtlasSize) throw new RangeError("Model atlas exceeds the section atlas size limit");
|
|
104242
104499
|
fluidPages.set(fluid, {
|
|
104243
104500
|
layer: 2,
|
|
@@ -104255,7 +104512,7 @@ gl_FragDepth=readDepth(vUv);
|
|
|
104255
104512
|
const tint = fluid === "water" && fluids.waterTints ? fluids.waterTints.subarray(tintIndex, tintIndex + 3) : data.tint;
|
|
104256
104513
|
fluidPages.get(fluid).fluids.push({ quads, x: x4, y: y5, z: z4, data, tint });
|
|
104257
104514
|
}
|
|
104258
|
-
pages.push(...[...fluidPages.values()].sort((a4, b4) => Number(
|
|
104515
|
+
pages.push(...[...fluidPages.values()].sort((a4, b4) => Number(atlases2[a4.placements[0].atlas].animated) - Number(atlases2[b4.placements[0].atlas].animated) || a4.placements[0].atlas - b4.placements[0].atlas));
|
|
104259
104516
|
}
|
|
104260
104517
|
return pages.map((page) => {
|
|
104261
104518
|
let faces = page.fluids.reduce((sum, fluid) => sum + fluid.quads.sprites.length, 0);
|
|
@@ -104272,7 +104529,7 @@ gl_FragDepth=readDepth(vUv);
|
|
|
104272
104529
|
let vertex2 = 0, indexOffset = 0;
|
|
104273
104530
|
for (const entry of page.entries) {
|
|
104274
104531
|
const template = templateData[templates[entry]];
|
|
104275
|
-
const atlas =
|
|
104532
|
+
const atlas = atlases2[template.atlas];
|
|
104276
104533
|
const placement = locations.get(template.atlas);
|
|
104277
104534
|
const mapU = (u4) => (placement.x + u4 * atlas.width) / page.width;
|
|
104278
104535
|
const mapV = (v5) => 1 - (placement.y + (1 - v5) * atlas.height) / page.height;
|
|
@@ -104311,7 +104568,7 @@ gl_FragDepth=readDepth(vUv);
|
|
|
104311
104568
|
}
|
|
104312
104569
|
}
|
|
104313
104570
|
for (const { quads, x: x4, y: y5, z: z4, data, tint } of page.fluids) {
|
|
104314
|
-
const atlas =
|
|
104571
|
+
const atlas = atlases2[data.atlas];
|
|
104315
104572
|
const placement = page.placements[0];
|
|
104316
104573
|
const mapU = (u4) => (placement.x + u4 * atlas.width) / page.width;
|
|
104317
104574
|
const mapV = (v5) => 1 - (placement.y + (1 - v5) * atlas.height) / page.height;
|
|
@@ -104415,7 +104672,7 @@ gl_FragDepth=readDepth(vUv);
|
|
|
104415
104672
|
var WATER_TINT = new Color(4159204).toArray();
|
|
104416
104673
|
function toInput(entries, maxAtlasSize, fluids, lighting) {
|
|
104417
104674
|
if (!Number.isInteger(maxAtlasSize) || maxAtlasSize < 1) throw new RangeError("Section atlas size must be a positive integer");
|
|
104418
|
-
const
|
|
104675
|
+
const atlases2 = [];
|
|
104419
104676
|
const atlasIds = /* @__PURE__ */ new Map();
|
|
104420
104677
|
const templateIds = /* @__PURE__ */ new Map();
|
|
104421
104678
|
const input = {
|
|
@@ -104438,9 +104695,9 @@ gl_FragDepth=readDepth(vUv);
|
|
|
104438
104695
|
if (id === void 0) {
|
|
104439
104696
|
let atlas = atlasIds.get(template.atlas);
|
|
104440
104697
|
if (atlas === void 0) {
|
|
104441
|
-
atlas =
|
|
104698
|
+
atlas = atlases2.length;
|
|
104442
104699
|
atlasIds.set(template.atlas, atlas);
|
|
104443
|
-
|
|
104700
|
+
atlases2.push(template.atlas);
|
|
104444
104701
|
input.atlases.push({ width: template.atlas.image.width, height: template.atlas.image.height, animated: template.atlas.hasAnimation });
|
|
104445
104702
|
}
|
|
104446
104703
|
let data = templateCache.get(template);
|
|
@@ -104499,9 +104756,9 @@ gl_FragDepth=readDepth(vUv);
|
|
|
104499
104756
|
if (!atlas) continue;
|
|
104500
104757
|
let id = atlasIds.get(atlas);
|
|
104501
104758
|
if (id === void 0) {
|
|
104502
|
-
id =
|
|
104759
|
+
id = atlases2.length;
|
|
104503
104760
|
atlasIds.set(atlas, id);
|
|
104504
|
-
|
|
104761
|
+
atlases2.push(atlas);
|
|
104505
104762
|
input.atlases.push({ width: atlas.image.width, height: atlas.image.height, animated: atlas.hasAnimation });
|
|
104506
104763
|
}
|
|
104507
104764
|
input.fluids[kind] = {
|
|
@@ -104512,7 +104769,7 @@ gl_FragDepth=readDepth(vUv);
|
|
|
104512
104769
|
};
|
|
104513
104770
|
}
|
|
104514
104771
|
}
|
|
104515
|
-
return { input, atlases };
|
|
104772
|
+
return { input, atlases: atlases2 };
|
|
104516
104773
|
}
|
|
104517
104774
|
var SectionMesh = class _SectionMesh extends Group {
|
|
104518
104775
|
constructor() {
|
|
@@ -104527,23 +104784,23 @@ gl_FragDepth=readDepth(vUv);
|
|
|
104527
104784
|
}
|
|
104528
104785
|
/** Builds section-local meshes from visible quads. `maxAtlasSize` limits each atlas dimension in pixels. */
|
|
104529
104786
|
static build(entries, maxAtlasSize = 2048, fluids, lighting) {
|
|
104530
|
-
const { input, atlases } = toInput(entries, maxAtlasSize, fluids, lighting);
|
|
104531
|
-
return this.fromPages(buildSectionGeometry(input),
|
|
104787
|
+
const { input, atlases: atlases2 } = toInput(entries, maxAtlasSize, fluids, lighting);
|
|
104788
|
+
return this.fromPages(buildSectionGeometry(input), atlases2);
|
|
104532
104789
|
}
|
|
104533
104790
|
/** Builds section-local meshes in a browser worker when available, with synchronous fallback. */
|
|
104534
104791
|
static async buildAsync(entries, maxAtlasSize = 2048, fluids, lighting) {
|
|
104535
|
-
const { input, atlases } = toInput(entries, maxAtlasSize, fluids, lighting);
|
|
104792
|
+
const { input, atlases: atlases2 } = toInput(entries, maxAtlasSize, fluids, lighting);
|
|
104536
104793
|
const worker = SectionWorker.shared();
|
|
104537
104794
|
const pages = worker ? await worker.build(input).catch(() => buildSectionGeometry(input)) : buildSectionGeometry(input);
|
|
104538
|
-
return this.fromPages(pages,
|
|
104795
|
+
return this.fromPages(pages, atlases2);
|
|
104539
104796
|
}
|
|
104540
|
-
static fromPages(pages,
|
|
104797
|
+
static fromPages(pages, atlases2) {
|
|
104541
104798
|
const section = new _SectionMesh();
|
|
104542
104799
|
for (const page of pages) {
|
|
104543
104800
|
const canvas = createCanvas(page.width, page.height);
|
|
104544
104801
|
const context = canvas.getContext("2d");
|
|
104545
104802
|
for (const { atlas, x: x4, y: y5 } of page.placements) {
|
|
104546
|
-
context.drawImage(
|
|
104803
|
+
context.drawImage(atlases2[atlas].image.canvas, x4, y5);
|
|
104547
104804
|
}
|
|
104548
104805
|
const geometry = new BufferGeometry();
|
|
104549
104806
|
geometry.setAttribute("position", new Float32BufferAttribute(page.positions.buffer, 3));
|
|
@@ -104554,7 +104811,7 @@ gl_FragDepth=readDepth(vUv);
|
|
|
104554
104811
|
geometry.setIndex(new Uint32BufferAttribute(page.indices.buffer, 1));
|
|
104555
104812
|
geometry.computeBoundingBox();
|
|
104556
104813
|
geometry.computeBoundingSphere();
|
|
104557
|
-
const transparent = page.layer === 2 ?
|
|
104814
|
+
const transparent = page.layer === 2 ? atlases2[page.placements[0].atlas].hasTranslucency : page.layer === 1;
|
|
104558
104815
|
const material = Materials.createShadedCanvasMaterial(canvas, transparent, false, true);
|
|
104559
104816
|
material.side = FrontSide;
|
|
104560
104817
|
if (page.layer === 2) {
|
|
@@ -104569,7 +104826,7 @@ gl_FragDepth=readDepth(vUv);
|
|
|
104569
104826
|
section.blockIndices.set(mesh, page.blockIndices);
|
|
104570
104827
|
const unsubscribe = [];
|
|
104571
104828
|
for (const { atlas: id, x: x4, y: y5 } of page.placements) {
|
|
104572
|
-
const atlas =
|
|
104829
|
+
const atlas = atlases2[id];
|
|
104573
104830
|
if (!atlas.hasAnimation) continue;
|
|
104574
104831
|
unsubscribe.push(atlas.subscribe(() => {
|
|
104575
104832
|
context.clearRect(x4, y5, atlas.image.width, atlas.image.height);
|