minerender 2.1.0-alpha.59 → 2.1.0-alpha.60
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/index.d.mts +28 -1
- package/dist/browser/index.d.ts +28 -1
- package/dist/browser/index.js +926 -705
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/index.mjs +810 -589
- package/dist/browser/index.mjs.map +1 -1
- package/dist/bundle.js +817 -595
- package/dist/bundle.js.map +1 -1
- package/dist/node/index.d.mts +28 -1
- package/dist/node/index.d.ts +28 -1
- package/dist/node/index.js +928 -706
- package/dist/node/index.js.map +1 -1
- package/dist/node/index.mjs +811 -590
- package/dist/node/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/browser/index.js
CHANGED
|
@@ -1085,6 +1085,26 @@ var init_Materials = __esm({
|
|
|
1085
1085
|
}
|
|
1086
1086
|
});
|
|
1087
1087
|
|
|
1088
|
+
// src/model/Model.ts
|
|
1089
|
+
function isDoubleArray(obj) {
|
|
1090
|
+
return Array.isArray(obj) && obj.length === 2;
|
|
1091
|
+
}
|
|
1092
|
+
function isTripleArray(obj) {
|
|
1093
|
+
return Array.isArray(obj) && obj.length === 3;
|
|
1094
|
+
}
|
|
1095
|
+
function isQuadArray(obj) {
|
|
1096
|
+
return Array.isArray(obj) && obj.length === 4;
|
|
1097
|
+
}
|
|
1098
|
+
var ITEM_GENERATED, BUILTIN_GENERATED, BUILTIN_ENTITY, DEFAULT_ELEMENTS;
|
|
1099
|
+
var init_Model = __esm({
|
|
1100
|
+
"src/model/Model.ts"() {
|
|
1101
|
+
ITEM_GENERATED = "item/generated";
|
|
1102
|
+
BUILTIN_GENERATED = "builtin/generated";
|
|
1103
|
+
BUILTIN_ENTITY = "builtin/entity";
|
|
1104
|
+
DEFAULT_ELEMENTS = [];
|
|
1105
|
+
}
|
|
1106
|
+
});
|
|
1107
|
+
|
|
1088
1108
|
// ../../node_modules/ts-deepmerge/dist/index.js
|
|
1089
1109
|
var require_dist = __commonJS({
|
|
1090
1110
|
"../../node_modules/ts-deepmerge/dist/index.js"(exports) {
|
|
@@ -1343,6 +1363,7 @@ var init_DisplayTransforms = __esm({
|
|
|
1343
1363
|
var import_ts_deepmerge, ModelMerger;
|
|
1344
1364
|
var init_ModelMerger = __esm({
|
|
1345
1365
|
"src/model/ModelMerger.ts"() {
|
|
1366
|
+
init_Model();
|
|
1346
1367
|
init_Models();
|
|
1347
1368
|
import_ts_deepmerge = __toESM(require_dist());
|
|
1348
1369
|
init_AssetKey();
|
|
@@ -1368,6 +1389,7 @@ var init_ModelMerger = __esm({
|
|
|
1368
1389
|
}
|
|
1369
1390
|
const models = [];
|
|
1370
1391
|
const parentKey = AssetKey.parse("models", model.parent);
|
|
1392
|
+
if (parentKey.namespace === "minecraft" && parentKey.getFullPath() === BUILTIN_ENTITY) return models;
|
|
1371
1393
|
parentKey.root = model.key?.root;
|
|
1372
1394
|
const parentModel = await Models.getRaw(parentKey);
|
|
1373
1395
|
if (parentModel) {
|
|
@@ -1434,12 +1456,12 @@ var init_Models = __esm({
|
|
|
1434
1456
|
const result = await AssetLoader.getFirst([itemKey, key], "json" /* JSON */);
|
|
1435
1457
|
if (!result) return void 0;
|
|
1436
1458
|
if (result.key.assetType !== "items") return { ...result.asset, key };
|
|
1437
|
-
const
|
|
1438
|
-
const modelKey = AssetKey.parse("models",
|
|
1459
|
+
const selected = this.defaultItemModel(result.asset.model, key);
|
|
1460
|
+
const modelKey = AssetKey.parse("models", selected.model);
|
|
1439
1461
|
modelKey.root = key.root;
|
|
1440
1462
|
const model2 = await this.getRaw(modelKey);
|
|
1441
|
-
if (!model2) throw new Error(`Item ${key.toNamespacedString()} references missing model ${
|
|
1442
|
-
return model2;
|
|
1463
|
+
if (!model2) throw new Error(`Item ${key.toNamespacedString()} references missing model ${selected.model}`);
|
|
1464
|
+
return selected.special ? { ...model2, special: selected.special } : model2;
|
|
1443
1465
|
});
|
|
1444
1466
|
return model ? { ...model, key: Object.assign(new AssetKey("", ""), model.key) } : void 0;
|
|
1445
1467
|
}
|
|
@@ -1450,8 +1472,25 @@ var init_Models = __esm({
|
|
|
1450
1472
|
}
|
|
1451
1473
|
switch (node.type.replace(/^minecraft:/, "")) {
|
|
1452
1474
|
case "model":
|
|
1453
|
-
if (typeof node.model === "string" && node.model) return node.model;
|
|
1475
|
+
if (typeof node.model === "string" && node.model) return { model: node.model };
|
|
1454
1476
|
break;
|
|
1477
|
+
case "special": {
|
|
1478
|
+
if (!node.base || !node.model || typeof node.model !== "object") break;
|
|
1479
|
+
const special = node.model;
|
|
1480
|
+
switch (special.type) {
|
|
1481
|
+
case "chest":
|
|
1482
|
+
case "minecraft:chest":
|
|
1483
|
+
case "bed":
|
|
1484
|
+
case "minecraft:bed":
|
|
1485
|
+
if (typeof special.texture === "string" && special.texture) return { model: node.base, special };
|
|
1486
|
+
break;
|
|
1487
|
+
case "head":
|
|
1488
|
+
case "minecraft:head":
|
|
1489
|
+
if (typeof special.kind === "string" && special.kind) return { model: node.base, special };
|
|
1490
|
+
break;
|
|
1491
|
+
}
|
|
1492
|
+
throw new Error(`Unsupported special item renderer ${special.type} for ${key.toNamespacedString()}`);
|
|
1493
|
+
}
|
|
1455
1494
|
case "condition":
|
|
1456
1495
|
return this.defaultItemModel(node.on_false, key);
|
|
1457
1496
|
case "select": {
|
|
@@ -3014,6 +3053,102 @@ var init_UVMapper = __esm({
|
|
|
3014
3053
|
}
|
|
3015
3054
|
});
|
|
3016
3055
|
|
|
3056
|
+
// src/MinecraftCubeTexture.ts
|
|
3057
|
+
var MinecraftCubeTexture;
|
|
3058
|
+
var init_MinecraftCubeTexture = __esm({
|
|
3059
|
+
"src/MinecraftCubeTexture.ts"() {
|
|
3060
|
+
init_UVMapper();
|
|
3061
|
+
init_CubeFace();
|
|
3062
|
+
MinecraftCubeTexture = class {
|
|
3063
|
+
constructor(u, v, width, height) {
|
|
3064
|
+
this.u = u;
|
|
3065
|
+
this.v = v;
|
|
3066
|
+
this.width = width;
|
|
3067
|
+
this.height = height;
|
|
3068
|
+
}
|
|
3069
|
+
mapW(x) {
|
|
3070
|
+
return x / this.width;
|
|
3071
|
+
}
|
|
3072
|
+
mapH(x) {
|
|
3073
|
+
return 1 - x / this.height;
|
|
3074
|
+
}
|
|
3075
|
+
getUvEast(w, h, l) {
|
|
3076
|
+
return [
|
|
3077
|
+
[this.mapW(this.u + l + w + l), this.mapH(this.v + l + h)],
|
|
3078
|
+
[this.mapW(this.u + l + w), this.mapH(this.v + l + h)],
|
|
3079
|
+
[this.mapW(this.u + l + w + l), this.mapH(this.v + l)],
|
|
3080
|
+
[this.mapW(this.u + l + w), this.mapH(this.v + l)]
|
|
3081
|
+
];
|
|
3082
|
+
}
|
|
3083
|
+
getUvWest(w, h, l) {
|
|
3084
|
+
return [
|
|
3085
|
+
[this.mapW(this.u + l), this.mapH(this.v + l + h)],
|
|
3086
|
+
[this.mapW(this.u), this.mapH(this.v + l + h)],
|
|
3087
|
+
[this.mapW(this.u + l), this.mapH(this.v + l)],
|
|
3088
|
+
[this.mapW(this.u), this.mapH(this.v + l)]
|
|
3089
|
+
];
|
|
3090
|
+
}
|
|
3091
|
+
getUvUp(w, h, l) {
|
|
3092
|
+
return [
|
|
3093
|
+
[this.mapW(this.u + l + w), this.mapH(this.v + l)],
|
|
3094
|
+
[this.mapW(this.u + l + w + w), this.mapH(this.v + l)],
|
|
3095
|
+
[this.mapW(this.u + l + w), this.mapH(this.v)],
|
|
3096
|
+
[this.mapW(this.u + l + w + w), this.mapH(this.v)]
|
|
3097
|
+
];
|
|
3098
|
+
}
|
|
3099
|
+
getUvDown(w, h, l) {
|
|
3100
|
+
return [
|
|
3101
|
+
[this.mapW(this.u + l), this.mapH(this.v)],
|
|
3102
|
+
[this.mapW(this.u + l + w), this.mapH(this.v)],
|
|
3103
|
+
[this.mapW(this.u + l), this.mapH(this.v + l)],
|
|
3104
|
+
[this.mapW(this.u + l + w), this.mapH(this.v + l)]
|
|
3105
|
+
];
|
|
3106
|
+
}
|
|
3107
|
+
getUvSouth(w, h, l) {
|
|
3108
|
+
return [
|
|
3109
|
+
[this.mapW(this.u + l + w + l + w), this.mapH(this.v + l + h)],
|
|
3110
|
+
[this.mapW(this.u + l + w + l), this.mapH(this.v + l + h)],
|
|
3111
|
+
[this.mapW(this.u + l + w + l + w), this.mapH(this.v + l)],
|
|
3112
|
+
[this.mapW(this.u + l + w + l), this.mapH(this.v + l)]
|
|
3113
|
+
];
|
|
3114
|
+
}
|
|
3115
|
+
getUvNorth(w, h, l) {
|
|
3116
|
+
return [
|
|
3117
|
+
[this.mapW(this.u + l + w), this.mapH(this.v + l + h)],
|
|
3118
|
+
[this.mapW(this.u + l), this.mapH(this.v + l + h)],
|
|
3119
|
+
[this.mapW(this.u + l + w), this.mapH(this.v + l)],
|
|
3120
|
+
[this.mapW(this.u + l), this.mapH(this.v + l)]
|
|
3121
|
+
];
|
|
3122
|
+
}
|
|
3123
|
+
getFaceUv(face, w, h, l) {
|
|
3124
|
+
switch (face) {
|
|
3125
|
+
case "east" /* EAST */:
|
|
3126
|
+
return this.getUvEast(w, h, l);
|
|
3127
|
+
case "west" /* WEST */:
|
|
3128
|
+
return this.getUvWest(w, h, l);
|
|
3129
|
+
case "up" /* UP */:
|
|
3130
|
+
return this.getUvUp(w, h, l);
|
|
3131
|
+
case "down" /* DOWN */:
|
|
3132
|
+
return this.getUvDown(w, h, l);
|
|
3133
|
+
case "south" /* SOUTH */:
|
|
3134
|
+
return this.getUvSouth(w, h, l);
|
|
3135
|
+
case "north" /* NORTH */:
|
|
3136
|
+
return this.getUvNorth(w, h, l);
|
|
3137
|
+
}
|
|
3138
|
+
}
|
|
3139
|
+
toUvArray(w, h, l, mirror = false) {
|
|
3140
|
+
const uv = [];
|
|
3141
|
+
for (let i = 0; i < CUBE_FACES.length; i++) {
|
|
3142
|
+
const face = mirror && i < 2 ? CUBE_FACES[1 - i] : CUBE_FACES[i];
|
|
3143
|
+
const corners = this.getFaceUv(face, w, h, l);
|
|
3144
|
+
UVMapper.setFaceUvInArray(uv, i * 4, mirror ? [corners[1], corners[0], corners[3], corners[2]] : corners);
|
|
3145
|
+
}
|
|
3146
|
+
return uv;
|
|
3147
|
+
}
|
|
3148
|
+
};
|
|
3149
|
+
}
|
|
3150
|
+
});
|
|
3151
|
+
|
|
3017
3152
|
// src/error/MineRenderError.ts
|
|
3018
3153
|
var MineRenderError;
|
|
3019
3154
|
var init_MineRenderError = __esm({
|
|
@@ -3030,6 +3165,248 @@ var init_MineRenderError = __esm({
|
|
|
3030
3165
|
}
|
|
3031
3166
|
});
|
|
3032
3167
|
|
|
3168
|
+
// src/assets/Entities.ts
|
|
3169
|
+
var Entities;
|
|
3170
|
+
var init_Entities = __esm({
|
|
3171
|
+
"src/assets/Entities.ts"() {
|
|
3172
|
+
init_AssetKey();
|
|
3173
|
+
init_AssetLoader();
|
|
3174
|
+
init_source();
|
|
3175
|
+
init_Caching();
|
|
3176
|
+
init_Assets();
|
|
3177
|
+
init_MineRenderError();
|
|
3178
|
+
init_ModelTextures();
|
|
3179
|
+
Entities = class {
|
|
3180
|
+
static async getEntityList() {
|
|
3181
|
+
const collect = async (path) => {
|
|
3182
|
+
const prefix2 = path ? `${path}/` : "";
|
|
3183
|
+
const key = new AssetKey(DEFAULT_NAMESPACE, `${prefix2}_list`, void 0, void 0, "entity-models", ".json");
|
|
3184
|
+
const list = await Caching.listAssetCache.get(key.serialize(), () => AssetLoader.get(key, "list" /* LIST */));
|
|
3185
|
+
if (!list) return [];
|
|
3186
|
+
const files = list.files.filter((file) => file.endsWith(".json") && file !== "_list.json").map((file) => `${prefix2}${file.slice(0, -5)}`);
|
|
3187
|
+
const children = await Promise.all(list.directories.map((directory) => collect(`${prefix2}${directory}`)));
|
|
3188
|
+
return [...files, ...children.flat()];
|
|
3189
|
+
};
|
|
3190
|
+
return collect("");
|
|
3191
|
+
}
|
|
3192
|
+
static async getModelFile(modelKey) {
|
|
3193
|
+
const path = isAssetKey(modelKey) ? modelKey.getFullPath() : modelKey.path;
|
|
3194
|
+
const key = new AssetKey(modelKey.namespace, path, void 0, void 0, "entity-models", ".json", isAssetKey(modelKey) ? modelKey.root : void 0);
|
|
3195
|
+
return Caching.entityModelCache.get(key.serialize(), () => AssetLoader.get(key, "json" /* JSON */));
|
|
3196
|
+
}
|
|
3197
|
+
static async getLayerList(modelKey) {
|
|
3198
|
+
return Object.keys((await this.getModelFile(modelKey))?.layers ?? {});
|
|
3199
|
+
}
|
|
3200
|
+
/** The dataset's extra draws on top of `main`; their `when` labels are the states `EntityModelOptions.when` can enable. */
|
|
3201
|
+
static async getPassList(modelKey) {
|
|
3202
|
+
return (await this.getModelFile(modelKey))?.passes ?? [];
|
|
3203
|
+
}
|
|
3204
|
+
static async getEntity(modelKey, textureKey, options) {
|
|
3205
|
+
const model = await this.getModelFile(modelKey);
|
|
3206
|
+
if (!model) return void 0;
|
|
3207
|
+
const passes = options?.layers || options?.layer !== void 0 ? [] : (model.passes ?? []).filter((pass) => pass.when === void 0 || options?.when?.includes(pass.when));
|
|
3208
|
+
const draws = [...new Set(options?.layers ?? [options?.layer ?? "main"])].map((layer) => ({ layer }));
|
|
3209
|
+
if (draws.length === 0) throw new MineRenderError(`Entity ${model.id} requires at least one layer`);
|
|
3210
|
+
draws.push(...passes);
|
|
3211
|
+
const names = [];
|
|
3212
|
+
const selected = draws.map((pass) => {
|
|
3213
|
+
const layer = model.layers[pass.layer];
|
|
3214
|
+
if (!layer) {
|
|
3215
|
+
throw new MineRenderError(`Entity ${model.id} has no layer "${pass.layer}". Available layers: ${Object.keys(model.layers).join(", ")}`);
|
|
3216
|
+
}
|
|
3217
|
+
let name = pass.layer;
|
|
3218
|
+
for (let n = 2; names.includes(name); n++) name = `${pass.layer}#${n}`;
|
|
3219
|
+
names.push(name);
|
|
3220
|
+
return { name, layer, pass };
|
|
3221
|
+
});
|
|
3222
|
+
const layers = Object.fromEntries(await Promise.all(selected.map(async ({ name, layer, pass }, index) => {
|
|
3223
|
+
const override = options?.textures?.[name] ?? (index === 0 ? textureKey : void 0);
|
|
3224
|
+
const textureLocation = pass.textureLocation ?? layer.textureLocation;
|
|
3225
|
+
let texture;
|
|
3226
|
+
if (override) {
|
|
3227
|
+
const path = isAssetKey(override) ? override.getFullPath() : override.path;
|
|
3228
|
+
texture = isAssetKey(override) && override.assetType === "textures" && path.startsWith("entity/") ? override : new AssetKey(override.namespace, path, "textures", "entity", "assets", ".png", isAssetKey(override) ? override.root : void 0);
|
|
3229
|
+
} else if (textureLocation !== void 0) {
|
|
3230
|
+
texture = AssetKey.parse("textures", textureLocation.replace(/^([^:]+:)?textures\//, "$1"));
|
|
3231
|
+
if (isAssetKey(modelKey)) texture.root = modelKey.root;
|
|
3232
|
+
} else {
|
|
3233
|
+
texture = await this.resolveTexture(modelKey);
|
|
3234
|
+
}
|
|
3235
|
+
const render = pass.render ?? layer.render;
|
|
3236
|
+
return [name, { key: override ?? modelKey, texture, layer, ...render && { render }, ...pass.tint && { tint: pass.tint } }];
|
|
3237
|
+
})));
|
|
3238
|
+
return { ...layers[names[0]], id: model.id, layers, ...model.transform && { transform: model.transform } };
|
|
3239
|
+
}
|
|
3240
|
+
/**
|
|
3241
|
+
* Vanilla's keyframe animations of a model by name, or undefined when the model or the selected version has none.
|
|
3242
|
+
*/
|
|
3243
|
+
static async getAnimations(modelKey) {
|
|
3244
|
+
const path = isAssetKey(modelKey) ? modelKey.getFullPath() : modelKey.path;
|
|
3245
|
+
const key = new AssetKey(modelKey.namespace, path, void 0, void 0, "entity-models/animations", ".json");
|
|
3246
|
+
const file = await Caching.entityAnimationCache.get(key.serialize(), () => AssetLoader.get(key, "json" /* JSON */));
|
|
3247
|
+
return file?.animations;
|
|
3248
|
+
}
|
|
3249
|
+
static async resolveTexture(modelKey) {
|
|
3250
|
+
const path = isAssetKey(modelKey) ? modelKey.getFullPath() : modelKey.path;
|
|
3251
|
+
const root = isAssetKey(modelKey) ? modelKey.root : void 0;
|
|
3252
|
+
const key = new AssetKey(modelKey.namespace, path, void 0, void 0, "entity-models", ".json", root);
|
|
3253
|
+
return Caching.entityTextureCache.get(key.serialize(), async () => {
|
|
3254
|
+
const name = path.split("/").pop();
|
|
3255
|
+
for (const candidate of [path, `${path}/${name}`]) {
|
|
3256
|
+
const texture2 = new AssetKey(modelKey.namespace, candidate, "textures", "entity", "assets", ".png", root);
|
|
3257
|
+
if (await ModelTextures.get(texture2)) return texture2;
|
|
3258
|
+
}
|
|
3259
|
+
const listKey = new AssetKey(modelKey.namespace, "_list", `${name}_variant`, void 0, "data", ".json", root);
|
|
3260
|
+
const list = await AssetLoader.get(listKey, "list" /* LIST */);
|
|
3261
|
+
const files = list?.files.filter((file2) => file2.endsWith(".json") && file2 !== "_list.json");
|
|
3262
|
+
const file = files?.find((file2) => file2 === "temperate.json") ?? files?.[0];
|
|
3263
|
+
if (!file) return void 0;
|
|
3264
|
+
const variantKey = new AssetKey(modelKey.namespace, file.slice(0, -5), `${name}_variant`, void 0, "data", ".json", root);
|
|
3265
|
+
const variant = await AssetLoader.get(variantKey, "json" /* JSON */);
|
|
3266
|
+
const assets = variant?.assets;
|
|
3267
|
+
const textureId = variant?.asset_id ?? (typeof assets?.wild === "string" ? assets.wild : Object.values(assets ?? {}).find((value) => typeof value === "string"));
|
|
3268
|
+
if (typeof textureId !== "string") return void 0;
|
|
3269
|
+
const texture = AssetKey.parse("textures", textureId);
|
|
3270
|
+
texture.root = root;
|
|
3271
|
+
return texture;
|
|
3272
|
+
});
|
|
3273
|
+
}
|
|
3274
|
+
/** @deprecated Use getEntityList(); block entities share the entity dataset. */
|
|
3275
|
+
static getBlockList() {
|
|
3276
|
+
return this.getEntityList();
|
|
3277
|
+
}
|
|
3278
|
+
/** @deprecated Use getEntity(); block entities share the entity dataset. */
|
|
3279
|
+
static getBlock(modelKey, textureKey, options) {
|
|
3280
|
+
return this.getEntity(modelKey, textureKey, options);
|
|
3281
|
+
}
|
|
3282
|
+
};
|
|
3283
|
+
}
|
|
3284
|
+
});
|
|
3285
|
+
|
|
3286
|
+
// src/entity/EntityAnimation.ts
|
|
3287
|
+
function catmullRom(delta, p0, p1, p22, p32) {
|
|
3288
|
+
return 0.5 * (2 * p1 + (p22 - p0) * delta + (2 * p0 - 5 * p1 + 4 * p22 - p32) * delta * delta + (3 * p1 - p0 - 3 * p22 + p32) * delta * delta * delta);
|
|
3289
|
+
}
|
|
3290
|
+
function sampleEntityKeyframes(keyframes, time) {
|
|
3291
|
+
if (keyframes.length === 0) return [0, 0, 0];
|
|
3292
|
+
let low = 0, high = keyframes.length;
|
|
3293
|
+
while (low < high) {
|
|
3294
|
+
const middle = low + high >>> 1;
|
|
3295
|
+
if (time <= keyframes[middle].time) high = middle;
|
|
3296
|
+
else low = middle + 1;
|
|
3297
|
+
}
|
|
3298
|
+
const a = Math.max(0, low - 1);
|
|
3299
|
+
const b = Math.min(keyframes.length - 1, a + 1);
|
|
3300
|
+
const from = keyframes[a];
|
|
3301
|
+
const to = keyframes[b];
|
|
3302
|
+
const delta = a === b ? 0 : Math.min(1, Math.max(0, (time - from.time) / (to.time - from.time)));
|
|
3303
|
+
if (to.interpolation === "catmullrom") {
|
|
3304
|
+
const before = keyframes[Math.max(0, a - 1)].value;
|
|
3305
|
+
const after = keyframes[Math.min(keyframes.length - 1, b + 1)].value;
|
|
3306
|
+
return [0, 1, 2].map((i) => catmullRom(delta, before[i], from.value[i], to.value[i], after[i]));
|
|
3307
|
+
}
|
|
3308
|
+
const target = to.pre ?? to.value;
|
|
3309
|
+
return [0, 1, 2].map((i) => from.value[i] + (target[i] - from.value[i]) * delta);
|
|
3310
|
+
}
|
|
3311
|
+
function entityAnimationTime(animation, time, loop = animation.loop) {
|
|
3312
|
+
return loop && animation.length > 0 ? time % animation.length : time;
|
|
3313
|
+
}
|
|
3314
|
+
function sampleEntityAnimation(animation, time, loop = animation.loop) {
|
|
3315
|
+
const elapsed = entityAnimationTime(animation, time, loop);
|
|
3316
|
+
const pose = {};
|
|
3317
|
+
for (const [name, bone] of Object.entries(animation.bones)) {
|
|
3318
|
+
const sampled = pose[name] = {};
|
|
3319
|
+
for (const channel of ENTITY_ANIMATION_CHANNELS) {
|
|
3320
|
+
const keyframes = bone[channel];
|
|
3321
|
+
if (keyframes?.length) sampled[channel] = sampleEntityKeyframes(keyframes, elapsed);
|
|
3322
|
+
}
|
|
3323
|
+
}
|
|
3324
|
+
return pose;
|
|
3325
|
+
}
|
|
3326
|
+
var ENTITY_ANIMATION_CHANNELS;
|
|
3327
|
+
var init_EntityAnimation = __esm({
|
|
3328
|
+
"src/entity/EntityAnimation.ts"() {
|
|
3329
|
+
ENTITY_ANIMATION_CHANNELS = ["position", "rotation", "scale"];
|
|
3330
|
+
}
|
|
3331
|
+
});
|
|
3332
|
+
|
|
3333
|
+
// src/entity/scene/EntityAnimationPlayer.ts
|
|
3334
|
+
var ZERO, EntityAnimationPlayer;
|
|
3335
|
+
var init_EntityAnimationPlayer = __esm({
|
|
3336
|
+
"src/entity/scene/EntityAnimationPlayer.ts"() {
|
|
3337
|
+
init_EntityAnimation();
|
|
3338
|
+
ZERO = [0, 0, 0];
|
|
3339
|
+
EntityAnimationPlayer = class {
|
|
3340
|
+
constructor() {
|
|
3341
|
+
this.parts = [];
|
|
3342
|
+
this._time = 0;
|
|
3343
|
+
this.loop = false;
|
|
3344
|
+
this.speed = 1;
|
|
3345
|
+
}
|
|
3346
|
+
get animation() {
|
|
3347
|
+
return this._animation;
|
|
3348
|
+
}
|
|
3349
|
+
get time() {
|
|
3350
|
+
return this._time;
|
|
3351
|
+
}
|
|
3352
|
+
/**
|
|
3353
|
+
* Starts an animation on the named parts below each layer root. The current pose of a part becomes its default;
|
|
3354
|
+
* bones without a matching part are skipped.
|
|
3355
|
+
*/
|
|
3356
|
+
play(layers, animation, options = {}) {
|
|
3357
|
+
this.stop();
|
|
3358
|
+
this._animation = animation;
|
|
3359
|
+
this._time = options.time ?? 0;
|
|
3360
|
+
this.loop = options.loop ?? animation.loop;
|
|
3361
|
+
this.speed = options.speed ?? 1;
|
|
3362
|
+
for (const layer of layers) {
|
|
3363
|
+
for (const bone of Object.keys(animation.bones)) {
|
|
3364
|
+
const object = layer.getObjectByName(`group:${bone}`);
|
|
3365
|
+
if (!object) continue;
|
|
3366
|
+
this.parts.push({ bone, object, position: object.position.clone(), rotation: object.rotation.clone(), scale: object.scale.clone() });
|
|
3367
|
+
}
|
|
3368
|
+
}
|
|
3369
|
+
this.apply();
|
|
3370
|
+
}
|
|
3371
|
+
/** Restores the default poses. Returns whether an animation was active. */
|
|
3372
|
+
stop() {
|
|
3373
|
+
if (!this._animation) return false;
|
|
3374
|
+
for (const part of this.parts) {
|
|
3375
|
+
part.object.position.copy(part.position);
|
|
3376
|
+
part.object.rotation.copy(part.rotation);
|
|
3377
|
+
part.object.scale.copy(part.scale);
|
|
3378
|
+
}
|
|
3379
|
+
this.clear();
|
|
3380
|
+
return true;
|
|
3381
|
+
}
|
|
3382
|
+
/** Forgets the animation without touching the parts, for parts that no longer exist. */
|
|
3383
|
+
clear() {
|
|
3384
|
+
this.parts = [];
|
|
3385
|
+
this._animation = void 0;
|
|
3386
|
+
this._time = 0;
|
|
3387
|
+
}
|
|
3388
|
+
setTime(seconds) {
|
|
3389
|
+
if (!this._animation) return false;
|
|
3390
|
+
this._time = seconds;
|
|
3391
|
+
this.apply();
|
|
3392
|
+
return true;
|
|
3393
|
+
}
|
|
3394
|
+
advance(deltaSeconds) {
|
|
3395
|
+
return this.setTime(this._time + deltaSeconds * this.speed);
|
|
3396
|
+
}
|
|
3397
|
+
apply() {
|
|
3398
|
+
const pose = sampleEntityAnimation(this._animation, this._time, this.loop);
|
|
3399
|
+
for (const part of this.parts) {
|
|
3400
|
+
const { position = ZERO, rotation = ZERO, scale = ZERO } = pose[part.bone];
|
|
3401
|
+
part.object.position.set(part.position.x + position[0], part.position.y + position[1], part.position.z + position[2]);
|
|
3402
|
+
part.object.rotation.set(part.rotation.x + rotation[0], part.rotation.y + rotation[1], part.rotation.z + rotation[2], part.rotation.order);
|
|
3403
|
+
part.object.scale.set(part.scale.x + scale[0], part.scale.y + scale[1], part.scale.z + scale[2]);
|
|
3404
|
+
}
|
|
3405
|
+
}
|
|
3406
|
+
};
|
|
3407
|
+
}
|
|
3408
|
+
});
|
|
3409
|
+
|
|
3033
3410
|
// src/instance/InstanceReference.ts
|
|
3034
3411
|
function isInstanceReference(obj) {
|
|
3035
3412
|
return obj.isInstanceReference;
|
|
@@ -3526,6 +3903,241 @@ var init_SceneObject = __esm({
|
|
|
3526
3903
|
}
|
|
3527
3904
|
});
|
|
3528
3905
|
|
|
3906
|
+
// src/entity/scene/EntityObject.ts
|
|
3907
|
+
function isEntityObject(obj) {
|
|
3908
|
+
return obj.isEntityObject;
|
|
3909
|
+
}
|
|
3910
|
+
var import_ts_deepmerge4, import_three13, _EntityObject, EntityObject;
|
|
3911
|
+
var init_EntityObject = __esm({
|
|
3912
|
+
"src/entity/scene/EntityObject.ts"() {
|
|
3913
|
+
init_SceneObject();
|
|
3914
|
+
init_Caching();
|
|
3915
|
+
import_ts_deepmerge4 = __toESM(require_dist());
|
|
3916
|
+
import_three13 = require("three");
|
|
3917
|
+
init_Ticker();
|
|
3918
|
+
init_model();
|
|
3919
|
+
init_ModelTextures();
|
|
3920
|
+
init_AssetKey();
|
|
3921
|
+
init_Materials();
|
|
3922
|
+
init_MinecraftCubeTexture();
|
|
3923
|
+
init_three();
|
|
3924
|
+
init_EntityAnimationPlayer();
|
|
3925
|
+
_EntityObject = class _EntityObject extends SceneObject {
|
|
3926
|
+
constructor(entity, options) {
|
|
3927
|
+
super();
|
|
3928
|
+
this.entity = entity;
|
|
3929
|
+
this.isEntityObject = true;
|
|
3930
|
+
this.meshesCreated = false;
|
|
3931
|
+
this.geometries = /* @__PURE__ */ new Set();
|
|
3932
|
+
this.disposeWireframes = [];
|
|
3933
|
+
/** Scrolling materials are owned: their texture offset follows this entity's age. */
|
|
3934
|
+
this.scrollMaterials = [];
|
|
3935
|
+
/** Entity age in ticks, as vanilla's `ageInTicks`; drives the scrolling render modes. */
|
|
3936
|
+
this.age = 0;
|
|
3937
|
+
this.animationPlayer = new EntityAnimationPlayer();
|
|
3938
|
+
this.options = (0, import_ts_deepmerge4.default)({}, _EntityObject.DEFAULT_OPTIONS, options ?? {});
|
|
3939
|
+
this.addEventListener("added", () => this.updateScrollSubscription());
|
|
3940
|
+
this.addEventListener("removed", () => this.updateScrollSubscription());
|
|
3941
|
+
}
|
|
3942
|
+
async init() {
|
|
3943
|
+
this.createMeshes();
|
|
3944
|
+
await this.applyTextures();
|
|
3945
|
+
}
|
|
3946
|
+
dispose() {
|
|
3947
|
+
super.dispose();
|
|
3948
|
+
}
|
|
3949
|
+
disposeAndRemoveAllChildren() {
|
|
3950
|
+
this.clearScrollMaterials();
|
|
3951
|
+
for (const geometry of this.geometries) geometry.dispose();
|
|
3952
|
+
this.geometries.clear();
|
|
3953
|
+
for (const dispose of this.disposeWireframes.splice(0)) dispose();
|
|
3954
|
+
this.animationPlayer.clear();
|
|
3955
|
+
super.disposeAndRemoveAllChildren();
|
|
3956
|
+
}
|
|
3957
|
+
clearScrollMaterials() {
|
|
3958
|
+
Ticker.remove(this.scrollTicker);
|
|
3959
|
+
this.scrollTicker = void 0;
|
|
3960
|
+
for (const { material } of this.scrollMaterials.splice(0)) {
|
|
3961
|
+
material.map?.dispose();
|
|
3962
|
+
material.dispose();
|
|
3963
|
+
}
|
|
3964
|
+
}
|
|
3965
|
+
updateScrollSubscription() {
|
|
3966
|
+
if (this.parent && this.scrollMaterials.length) {
|
|
3967
|
+
if (this.scrollTicker === void 0) {
|
|
3968
|
+
this.scrollTicker = Ticker.add(() => {
|
|
3969
|
+
this.age++;
|
|
3970
|
+
this.updateScroll();
|
|
3971
|
+
});
|
|
3972
|
+
}
|
|
3973
|
+
} else {
|
|
3974
|
+
Ticker.remove(this.scrollTicker);
|
|
3975
|
+
this.scrollTicker = void 0;
|
|
3976
|
+
}
|
|
3977
|
+
}
|
|
3978
|
+
/** Applies the entity age to the scrolling materials; the ticker calls this 20 times per second. */
|
|
3979
|
+
updateScroll() {
|
|
3980
|
+
for (const { offset, speed } of this.scrollMaterials) {
|
|
3981
|
+
offset.set(this.age * speed[0] % 1, 0 - this.age * speed[1] % 1);
|
|
3982
|
+
}
|
|
3983
|
+
this.notifyDirty();
|
|
3984
|
+
}
|
|
3985
|
+
//<editor-fold desc="ANIMATION">
|
|
3986
|
+
/** The animation started by {@link playAnimation}, until {@link stopAnimation} or disposal. */
|
|
3987
|
+
get animation() {
|
|
3988
|
+
return this.animationPlayer.animation;
|
|
3989
|
+
}
|
|
3990
|
+
/** Seconds since the animation started, before looping. */
|
|
3991
|
+
get animationTime() {
|
|
3992
|
+
return this.animationPlayer.time;
|
|
3993
|
+
}
|
|
3994
|
+
/**
|
|
3995
|
+
* Poses the object from a keyframe animation of {@link Entities.getAnimations}, replacing the current one.
|
|
3996
|
+
* Parts of every layer are matched by name and their current pose is the default the offsets add to.
|
|
3997
|
+
* The object owns no clock: call {@link advanceAnimation} per frame, or {@link setAnimationTime}.
|
|
3998
|
+
*/
|
|
3999
|
+
playAnimation(animation, options) {
|
|
4000
|
+
this.createMeshes();
|
|
4001
|
+
const layers = Object.keys(this.entityLayers).map((name) => this.getLayerGroup(name)).filter((layer) => !!layer);
|
|
4002
|
+
this.animationPlayer.play(layers, animation, options);
|
|
4003
|
+
this.notifyDirty();
|
|
4004
|
+
}
|
|
4005
|
+
/** Stops the animation and restores the default pose. */
|
|
4006
|
+
stopAnimation() {
|
|
4007
|
+
if (this.animationPlayer.stop()) this.notifyDirty();
|
|
4008
|
+
}
|
|
4009
|
+
/** Poses the object at an explicit time in seconds. Has no effect without an animation. */
|
|
4010
|
+
setAnimationTime(seconds) {
|
|
4011
|
+
if (this.animationPlayer.setTime(seconds)) this.notifyDirty();
|
|
4012
|
+
}
|
|
4013
|
+
/** Advances the animation by a frame delta in seconds, scaled by its speed. Has no effect without an animation. */
|
|
4014
|
+
advanceAnimation(deltaSeconds) {
|
|
4015
|
+
if (this.animationPlayer.advance(deltaSeconds)) this.notifyDirty();
|
|
4016
|
+
}
|
|
4017
|
+
//</editor-fold>
|
|
4018
|
+
getLayerGroup(name) {
|
|
4019
|
+
return super.getGroupByName(`layer:${name}`);
|
|
4020
|
+
}
|
|
4021
|
+
getGroupByName(name, layerName) {
|
|
4022
|
+
return layerName === void 0 ? super.getGroupByName(name) : this.getLayerGroup(layerName)?.getObjectByName(`group:${name}`);
|
|
4023
|
+
}
|
|
4024
|
+
getMeshByName(name, layerName) {
|
|
4025
|
+
return layerName === void 0 ? super.getMeshByName(name) : this.getLayerGroup(layerName)?.getObjectByName(`mesh:${name}`);
|
|
4026
|
+
}
|
|
4027
|
+
get entityLayers() {
|
|
4028
|
+
return this.entity.layers ?? { main: this.entity };
|
|
4029
|
+
}
|
|
4030
|
+
getTextureKey(layer) {
|
|
4031
|
+
if (layer.texture) return layer.texture;
|
|
4032
|
+
const key = layer.key;
|
|
4033
|
+
return new AssetKey(
|
|
4034
|
+
key.namespace,
|
|
4035
|
+
isAssetKey(key) ? key.getFullPath() : key.path,
|
|
4036
|
+
"textures",
|
|
4037
|
+
"entity",
|
|
4038
|
+
"assets",
|
|
4039
|
+
".png"
|
|
4040
|
+
);
|
|
4041
|
+
}
|
|
4042
|
+
async loadTextures(layer = this.entity) {
|
|
4043
|
+
return ModelTextures.get(this.getTextureKey(layer));
|
|
4044
|
+
}
|
|
4045
|
+
createMeshes(force = false) {
|
|
4046
|
+
if (this.meshesCreated && !force) return;
|
|
4047
|
+
const modelRoot = new import_three13.Object3D();
|
|
4048
|
+
const transform = this.options.flip === void 0 ? this.entity.transform : void 0;
|
|
4049
|
+
if (transform) {
|
|
4050
|
+
for (const op of transform) {
|
|
4051
|
+
const matrix = new import_three13.Matrix4();
|
|
4052
|
+
if ("scale" in op) matrix.makeScale(...op.scale);
|
|
4053
|
+
else if ("translate" in op) matrix.makeTranslation(...op.translate);
|
|
4054
|
+
else matrix.makeRotationFromEuler(new import_three13.Euler(...op.rotate, "ZYX"));
|
|
4055
|
+
modelRoot.matrix.multiply(matrix);
|
|
4056
|
+
}
|
|
4057
|
+
modelRoot.matrixAutoUpdate = false;
|
|
4058
|
+
} else if (this.options.flip ?? true) {
|
|
4059
|
+
modelRoot.scale.set(-1, -1, 1);
|
|
4060
|
+
}
|
|
4061
|
+
this.add(modelRoot);
|
|
4062
|
+
Object.entries(this.entityLayers).forEach(([name, layer], index) => {
|
|
4063
|
+
const group = this.createGroup(`layer:${name}`);
|
|
4064
|
+
modelRoot.add(group);
|
|
4065
|
+
const inward = !Materials.entityModeCulls(layer.render ?? layer.layer.render);
|
|
4066
|
+
this.createPart("root", layer.layer.root, group, layer.layer.texture, Materials.MISSING_TEXTURE, index, inward);
|
|
4067
|
+
});
|
|
4068
|
+
this.meshesCreated = true;
|
|
4069
|
+
}
|
|
4070
|
+
createPart(name, part, parent, textureSize, material, renderOrder, inward = true) {
|
|
4071
|
+
const anchor = this.createGroup(name);
|
|
4072
|
+
anchor.position.fromArray(part.pose.offset);
|
|
4073
|
+
anchor.rotation.set(...part.pose.rotation, "ZYX");
|
|
4074
|
+
anchor.scale.fromArray(part.pose.scale ?? [1, 1, 1]);
|
|
4075
|
+
parent.add(anchor);
|
|
4076
|
+
const size = part.texture ?? textureSize;
|
|
4077
|
+
for (const cube of part.cubes) {
|
|
4078
|
+
const [width, height, depth] = cube.size;
|
|
4079
|
+
const [growX, growY, growZ] = cube.grow ?? [0, 0, 0];
|
|
4080
|
+
const texture = new MinecraftCubeTexture(...cube.uv, ...size);
|
|
4081
|
+
const uv = size[0] === 0 || size[1] === 0 ? new Array(48).fill(0) : texture.toUvArray(width, height, depth, cube.mirror);
|
|
4082
|
+
const geometry = this._getBoxGeometryForDimensionsAndUv(
|
|
4083
|
+
width + growX * 2,
|
|
4084
|
+
height + growY * 2,
|
|
4085
|
+
depth + growZ * 2,
|
|
4086
|
+
uv
|
|
4087
|
+
).clone();
|
|
4088
|
+
this.geometries.add(geometry);
|
|
4089
|
+
geometry.translate(cube.origin[0] + width / 2, cube.origin[1] + height / 2, cube.origin[2] + depth / 2);
|
|
4090
|
+
if (inward && Math.min(width + growX * 2, height + growY * 2, depth + growZ * 2) > 0) {
|
|
4091
|
+
const index = Array.from(geometry.getIndex().array);
|
|
4092
|
+
geometry.setIndex(index.concat(index.slice().reverse()));
|
|
4093
|
+
}
|
|
4094
|
+
const mesh = this.createMesh(name, geometry, material);
|
|
4095
|
+
mesh.renderOrder = renderOrder;
|
|
4096
|
+
anchor.add(mesh);
|
|
4097
|
+
if (this.options.wireframe) this.disposeWireframes.push(addWireframeToMesh(geometry, mesh));
|
|
4098
|
+
}
|
|
4099
|
+
for (const [childName, child] of Object.entries(part.children)) {
|
|
4100
|
+
this.createPart(childName, child, anchor, size, material, renderOrder, inward);
|
|
4101
|
+
}
|
|
4102
|
+
}
|
|
4103
|
+
async applyTextures() {
|
|
4104
|
+
this.clearScrollMaterials();
|
|
4105
|
+
await Promise.all(Object.entries(this.entityLayers).map(async ([name, layer]) => {
|
|
4106
|
+
const mode = layer.render ?? layer.layer.render ?? "cutout";
|
|
4107
|
+
const tint = layer.tint === void 0 ? void 0 : this.options.tints?.[layer.tint];
|
|
4108
|
+
const scroll = Materials.entityModeScroll(mode);
|
|
4109
|
+
const assetKeyStr = this.getTextureKey(layer).serialize();
|
|
4110
|
+
const keyStr = `entity:${mode}:${tint === void 0 ? "" : new import_three13.Color(tint).getHexString()}:${assetKeyStr}`;
|
|
4111
|
+
let mat = scroll ? void 0 : Caching.materialCache.getIfPresent(keyStr);
|
|
4112
|
+
if (!mat) {
|
|
4113
|
+
const cachedAsset = Caching.textureAssetCache.getIfPresent(assetKeyStr);
|
|
4114
|
+
const imageData = await this.loadTextures(layer);
|
|
4115
|
+
if (!imageData) return;
|
|
4116
|
+
const canvas = imageData.data.canvas;
|
|
4117
|
+
const createMaterial = () => Materials.createEntityCanvasMaterial(canvas, mode, tint);
|
|
4118
|
+
mat = !scroll && cachedAsset && Caching.textureAssetCache.getIfPresent(assetKeyStr) === cachedAsset ? Caching.materialCache.get(keyStr, createMaterial) : createMaterial();
|
|
4119
|
+
if (scroll) {
|
|
4120
|
+
this.scrollMaterials.push({ material: mat, offset: mat.map.offset, speed: scroll });
|
|
4121
|
+
}
|
|
4122
|
+
}
|
|
4123
|
+
this.getLayerGroup(name)?.traverse((object) => {
|
|
4124
|
+
if (isMesh(object)) object.material = mat;
|
|
4125
|
+
});
|
|
4126
|
+
}));
|
|
4127
|
+
if (!this.children.length) {
|
|
4128
|
+
this.clearScrollMaterials();
|
|
4129
|
+
} else if (this.scrollMaterials.length) {
|
|
4130
|
+
this.updateScroll();
|
|
4131
|
+
}
|
|
4132
|
+
this.updateScrollSubscription();
|
|
4133
|
+
this.notifyDirty();
|
|
4134
|
+
}
|
|
4135
|
+
};
|
|
4136
|
+
_EntityObject.DEFAULT_OPTIONS = (0, import_ts_deepmerge4.default)({}, SceneObject.DEFAULT_OPTIONS);
|
|
4137
|
+
EntityObject = _EntityObject;
|
|
4138
|
+
}
|
|
4139
|
+
});
|
|
4140
|
+
|
|
3529
4141
|
// src/three/BufferGeometryUtils.js
|
|
3530
4142
|
function computeTangents(geometry) {
|
|
3531
4143
|
geometry.computeTangents();
|
|
@@ -4105,37 +4717,189 @@ var init_ModelCulling = __esm({
|
|
|
4105
4717
|
}
|
|
4106
4718
|
});
|
|
4107
4719
|
|
|
4720
|
+
// src/model/SpecialItems.ts
|
|
4721
|
+
var import_three22, SpecialItems;
|
|
4722
|
+
var init_SpecialItems = __esm({
|
|
4723
|
+
"src/model/SpecialItems.ts"() {
|
|
4724
|
+
import_three22 = require("three");
|
|
4725
|
+
init_AssetKey();
|
|
4726
|
+
init_Entities();
|
|
4727
|
+
SpecialItems = class {
|
|
4728
|
+
/** Resolves the static entity parts drawn by a special item renderer, in model units. */
|
|
4729
|
+
static async getParts(special, root) {
|
|
4730
|
+
const texture = (id, directory) => {
|
|
4731
|
+
const key = AssetKey.parse("textures", id);
|
|
4732
|
+
return new AssetKey(
|
|
4733
|
+
key.namespace,
|
|
4734
|
+
[directory, key.getFullPath()].filter(Boolean).join("/"),
|
|
4735
|
+
"textures",
|
|
4736
|
+
"entity",
|
|
4737
|
+
"assets",
|
|
4738
|
+
".png",
|
|
4739
|
+
root
|
|
4740
|
+
);
|
|
4741
|
+
};
|
|
4742
|
+
const load = async (id, textureKey, transform, rotations = {}) => {
|
|
4743
|
+
const key = new AssetKey("minecraft", id, void 0, void 0, "entity-models", ".json", root);
|
|
4744
|
+
const model = await Entities.getEntity(key, textureKey, { layer: "main" });
|
|
4745
|
+
if (!model) throw new Error(`Missing entity model minecraft:${id} for special item ${special.type}`);
|
|
4746
|
+
return { model, transform, rotations };
|
|
4747
|
+
};
|
|
4748
|
+
switch (special.type) {
|
|
4749
|
+
case "minecraft:chest":
|
|
4750
|
+
case "chest": {
|
|
4751
|
+
const angle = -(special.openness ?? 0) * Math.PI / 2;
|
|
4752
|
+
const chest = await load("chest", texture(special.texture, "chest"), new import_three22.Matrix4(), {
|
|
4753
|
+
lid: [angle, 0, 0],
|
|
4754
|
+
lock: [angle, 0, 0]
|
|
4755
|
+
});
|
|
4756
|
+
chest.model = { ...chest.model, render: "solid", layers: void 0 };
|
|
4757
|
+
return [chest];
|
|
4758
|
+
}
|
|
4759
|
+
case "minecraft:bed":
|
|
4760
|
+
case "bed": {
|
|
4761
|
+
const transform = new import_three22.Matrix4().makeTranslation(0, 9, 0).multiply(new import_three22.Matrix4().makeRotationX(Math.PI / 2)).multiply(new import_three22.Matrix4().makeTranslation(8, 8, 8)).multiply(new import_three22.Matrix4().makeRotationZ(Math.PI)).multiply(new import_three22.Matrix4().makeTranslation(-8, -8, -8));
|
|
4762
|
+
const key = texture(special.texture, "bed");
|
|
4763
|
+
return Promise.all([
|
|
4764
|
+
load("bed_head", key, transform),
|
|
4765
|
+
load("bed_foot", key, new import_three22.Matrix4().makeTranslation(0, 0, -16).multiply(transform))
|
|
4766
|
+
]);
|
|
4767
|
+
}
|
|
4768
|
+
case "minecraft:head":
|
|
4769
|
+
case "head": {
|
|
4770
|
+
const models = {
|
|
4771
|
+
skeleton: "skeleton_skull",
|
|
4772
|
+
wither_skeleton: "wither_skeleton_skull",
|
|
4773
|
+
zombie: "zombie_head",
|
|
4774
|
+
creeper: "creeper_head",
|
|
4775
|
+
dragon: "dragon_skull",
|
|
4776
|
+
piglin: "piglin_head"
|
|
4777
|
+
};
|
|
4778
|
+
const id = Object.prototype.hasOwnProperty.call(models, special.kind) ? models[special.kind] : void 0;
|
|
4779
|
+
if (!id) throw new Error(`Unsupported special item head kind ${special.kind}`);
|
|
4780
|
+
const animation = (special.animation ?? 0) * Math.PI * 0.2;
|
|
4781
|
+
const rotations = { head: [0, Math.PI, 0] };
|
|
4782
|
+
if (special.kind === "dragon") rotations.jaw = [(Math.sin(animation) + 1) * 0.2, 0, 0];
|
|
4783
|
+
if (special.kind === "piglin") {
|
|
4784
|
+
rotations.left_ear = [0, 0, -(Math.cos(animation * 1.2) + 2.5) * 0.2];
|
|
4785
|
+
rotations.right_ear = [0, 0, (Math.cos(animation) + 2.5) * 0.2];
|
|
4786
|
+
}
|
|
4787
|
+
return [await load(
|
|
4788
|
+
id,
|
|
4789
|
+
special.texture ? texture(special.texture, "") : void 0,
|
|
4790
|
+
new import_three22.Matrix4().makeTranslation(8, 0, 8).multiply(new import_three22.Matrix4().makeScale(-1, -1, 1)),
|
|
4791
|
+
rotations
|
|
4792
|
+
)];
|
|
4793
|
+
}
|
|
4794
|
+
}
|
|
4795
|
+
}
|
|
4796
|
+
/** An owned material with model-preview shading; its entity texture remains shared. */
|
|
4797
|
+
static createMaterial(source, shade) {
|
|
4798
|
+
const material = source.clone();
|
|
4799
|
+
if (shade) {
|
|
4800
|
+
material.onBeforeCompile = (shader) => {
|
|
4801
|
+
shader.vertexShader = `varying float itemLight;
|
|
4802
|
+
${shader.vertexShader}`.replace("#include <begin_vertex>", `
|
|
4803
|
+
#include <begin_vertex>
|
|
4804
|
+
vec3 N = inverseTransformDirection(normalMatrix * normal, viewMatrix);
|
|
4805
|
+
itemLight = (1.0 + N.y) * 0.25 - N.x * N.x * 0.15 + N.z * N.z * 0.05 + 0.5;
|
|
4806
|
+
`);
|
|
4807
|
+
shader.fragmentShader = `varying float itemLight;
|
|
4808
|
+
${shader.fragmentShader}`.replace(
|
|
4809
|
+
"#include <color_fragment>",
|
|
4810
|
+
"#include <color_fragment>\ndiffuseColor.rgb *= itemLight;"
|
|
4811
|
+
);
|
|
4812
|
+
};
|
|
4813
|
+
material.customProgramCacheKey = () => "special-item-side";
|
|
4814
|
+
}
|
|
4815
|
+
return material;
|
|
4816
|
+
}
|
|
4817
|
+
};
|
|
4818
|
+
}
|
|
4819
|
+
});
|
|
4820
|
+
|
|
4821
|
+
// src/model/GuiLight.ts
|
|
4822
|
+
var GuiLight;
|
|
4823
|
+
var init_GuiLight = __esm({
|
|
4824
|
+
"src/model/GuiLight.ts"() {
|
|
4825
|
+
GuiLight = /* @__PURE__ */ ((GuiLight2) => {
|
|
4826
|
+
GuiLight2["FRONT"] = "front";
|
|
4827
|
+
GuiLight2["SIDE"] = "side";
|
|
4828
|
+
return GuiLight2;
|
|
4829
|
+
})(GuiLight || {});
|
|
4830
|
+
}
|
|
4831
|
+
});
|
|
4832
|
+
|
|
4108
4833
|
// src/model/scene/ModelObject.ts
|
|
4109
4834
|
function isModelObject(obj) {
|
|
4110
4835
|
return obj.isModelObject;
|
|
4111
4836
|
}
|
|
4112
|
-
var
|
|
4837
|
+
var import_three23, import_ts_deepmerge5, p7, _ModelObject, ModelObject;
|
|
4113
4838
|
var init_ModelObject = __esm({
|
|
4114
4839
|
"src/model/scene/ModelObject.ts"() {
|
|
4115
4840
|
init_SceneObject();
|
|
4116
4841
|
init_Materials();
|
|
4117
4842
|
init_UVMapper();
|
|
4118
|
-
|
|
4843
|
+
import_three23 = require("three");
|
|
4119
4844
|
init_BufferGeometryUtils();
|
|
4120
4845
|
init_model();
|
|
4121
4846
|
import_ts_deepmerge5 = __toESM(require_dist());
|
|
4122
4847
|
init_log();
|
|
4123
4848
|
init_CubeFace();
|
|
4849
|
+
init_DisplayPosition();
|
|
4124
4850
|
init_DisplayTransforms();
|
|
4125
4851
|
init_ModelCulling();
|
|
4852
|
+
init_SpecialItems();
|
|
4853
|
+
init_EntityObject();
|
|
4854
|
+
init_GuiLight();
|
|
4126
4855
|
p7 = prefix("ModelObject");
|
|
4127
4856
|
_ModelObject = class _ModelObject extends SceneObject {
|
|
4128
4857
|
constructor(originalModel, options) {
|
|
4129
4858
|
super(options);
|
|
4130
4859
|
this.originalModel = originalModel;
|
|
4131
4860
|
this.isModelObject = true;
|
|
4861
|
+
this.specialMaterials = /* @__PURE__ */ new Map();
|
|
4132
4862
|
this.meshesCreated = false;
|
|
4133
4863
|
this.options = (0, import_ts_deepmerge5.default)({}, _ModelObject.DEFAULT_OPTIONS, options ?? {});
|
|
4864
|
+
if (originalModel.special) this.options.instanceMeshes = false;
|
|
4134
4865
|
if (this.options.tints) this.options.tints = { ...this.options.tints };
|
|
4135
4866
|
this.addEventListener("added", () => this.updateAnimationSubscription());
|
|
4136
4867
|
this.addEventListener("removed", () => this.updateAnimationSubscription());
|
|
4137
4868
|
}
|
|
4138
4869
|
async init() {
|
|
4870
|
+
const special = this.originalModel.special;
|
|
4871
|
+
if (special) {
|
|
4872
|
+
const parts = await SpecialItems.getParts(special, this.originalModel.key?.root);
|
|
4873
|
+
const transform = this.options.displayPosition ? DisplayTransforms.getMatrix(this.originalModel.display, this.options.displayPosition) : new import_three23.Matrix4();
|
|
4874
|
+
transform.multiply(new import_three23.Matrix4().makeTranslation(-8, -8, -8));
|
|
4875
|
+
try {
|
|
4876
|
+
for (const part of parts) {
|
|
4877
|
+
const object = new EntityObject(part.model, { flip: false, wireframe: this.options.wireframe });
|
|
4878
|
+
object.matrix.copy(transform).multiply(part.transform);
|
|
4879
|
+
object.matrixAutoUpdate = false;
|
|
4880
|
+
this.add(object);
|
|
4881
|
+
await object.init();
|
|
4882
|
+
object.iterateAllMeshes((mesh) => {
|
|
4883
|
+
const source = mesh.material;
|
|
4884
|
+
let material = this.specialMaterials.get(source);
|
|
4885
|
+
if (!material) {
|
|
4886
|
+
const front = this.options.displayPosition === "gui" /* GUI */ && this.originalModel.gui_light === "front" /* FRONT */;
|
|
4887
|
+
material = SpecialItems.createMaterial(source, !front);
|
|
4888
|
+
this.specialMaterials.set(source, material);
|
|
4889
|
+
}
|
|
4890
|
+
mesh.material = material;
|
|
4891
|
+
});
|
|
4892
|
+
for (const [name, rotation] of Object.entries(part.rotations)) {
|
|
4893
|
+
object.getGroupByName(name)?.rotation.set(...rotation, "ZYX");
|
|
4894
|
+
}
|
|
4895
|
+
}
|
|
4896
|
+
} catch (error) {
|
|
4897
|
+
this.disposeAndRemoveAllChildren();
|
|
4898
|
+
throw error;
|
|
4899
|
+
}
|
|
4900
|
+
this.notifyDirty();
|
|
4901
|
+
return;
|
|
4902
|
+
}
|
|
4139
4903
|
await this.loadTextures();
|
|
4140
4904
|
this.createMeshes();
|
|
4141
4905
|
this.applyTextures();
|
|
@@ -4169,7 +4933,7 @@ var init_ModelObject = __esm({
|
|
|
4169
4933
|
elGeo.clearGroups();
|
|
4170
4934
|
}
|
|
4171
4935
|
if (this.options.uvLockRotation) {
|
|
4172
|
-
UVMapper.lockUvs(elGeo, el.faces, this.atlas, new
|
|
4936
|
+
UVMapper.lockUvs(elGeo, el.faces, this.atlas, new import_three23.Euler(...this.options.uvLockRotation));
|
|
4173
4937
|
}
|
|
4174
4938
|
if (this.options.tints) {
|
|
4175
4939
|
const colors = new Float32Array(elGeo.getAttribute("position").count * 3).fill(1);
|
|
@@ -4178,19 +4942,19 @@ var init_ModelObject = __esm({
|
|
|
4178
4942
|
if (tintIndex === void 0 || tintIndex < 0) continue;
|
|
4179
4943
|
const tint = this.options.tints[tintIndex];
|
|
4180
4944
|
if (tint === void 0) continue;
|
|
4181
|
-
const color = new
|
|
4945
|
+
const color = new import_three23.Color(tint);
|
|
4182
4946
|
for (let vertex = 0; vertex < 4; vertex++) {
|
|
4183
4947
|
color.toArray(colors, (faceIndex * 4 + vertex) * 3);
|
|
4184
4948
|
}
|
|
4185
4949
|
}
|
|
4186
|
-
elGeo.setAttribute("color", new
|
|
4950
|
+
elGeo.setAttribute("color", new import_three23.BufferAttribute(colors, 3));
|
|
4187
4951
|
}
|
|
4188
|
-
elGeo.applyMatrix4(new
|
|
4189
|
-
elGeo.applyMatrix4(new
|
|
4952
|
+
elGeo.applyMatrix4(new import_three23.Matrix4().makeTranslation((el.to[0] - el.from[0]) / 2, (el.to[1] - el.from[1]) / 2, (el.to[2] - el.from[2]) / 2));
|
|
4953
|
+
elGeo.applyMatrix4(new import_three23.Matrix4().makeTranslation(el.from[0], el.from[1], el.from[2]));
|
|
4190
4954
|
if (el.rotation) {
|
|
4191
4955
|
applyElementRotation(el.rotation, elGeo);
|
|
4192
4956
|
}
|
|
4193
|
-
elGeo.applyMatrix4(new
|
|
4957
|
+
elGeo.applyMatrix4(new import_three23.Matrix4().makeTranslation(-8, -8, -8));
|
|
4194
4958
|
if (displayTransform) DisplayTransforms.apply(elGeo, displayTransform);
|
|
4195
4959
|
if (this.options.mergeMeshes) {
|
|
4196
4960
|
allGeos.push(elGeo);
|
|
@@ -4212,7 +4976,7 @@ var init_ModelObject = __esm({
|
|
|
4212
4976
|
if (allGeos.length > 0) {
|
|
4213
4977
|
combinedGeo = mergeBufferGeometries(allGeos);
|
|
4214
4978
|
} else {
|
|
4215
|
-
combinedGeo = new
|
|
4979
|
+
combinedGeo = new import_three23.BoxGeometry(16, 16, 16);
|
|
4216
4980
|
if (displayTransform) DisplayTransforms.apply(combinedGeo, displayTransform);
|
|
4217
4981
|
}
|
|
4218
4982
|
combinedGeo.computeBoundingBox();
|
|
@@ -4280,6 +5044,8 @@ var init_ModelObject = __esm({
|
|
|
4280
5044
|
this.atlasMaterial?.dispose();
|
|
4281
5045
|
this.atlasTexture = void 0;
|
|
4282
5046
|
this.atlasMaterial = void 0;
|
|
5047
|
+
for (const material of this.specialMaterials.values()) material.dispose();
|
|
5048
|
+
this.specialMaterials.clear();
|
|
4283
5049
|
super.disposeAndRemoveAllChildren();
|
|
4284
5050
|
}
|
|
4285
5051
|
};
|
|
@@ -4322,7 +5088,7 @@ function ownHeight(sample) {
|
|
|
4322
5088
|
return (level === 0 || level >= 8 ? 8 : 8 - level) / 9;
|
|
4323
5089
|
}
|
|
4324
5090
|
function createFluidGeometry(kind, sample) {
|
|
4325
|
-
const geometry = new
|
|
5091
|
+
const geometry = new import_three28.BufferGeometry();
|
|
4326
5092
|
const positions = [], normals = [], uvs = [], indices = [];
|
|
4327
5093
|
const self = sample(0, 0, 0);
|
|
4328
5094
|
const height = (x, z) => {
|
|
@@ -4421,16 +5187,16 @@ function createFluidGeometry(kind, sample) {
|
|
|
4421
5187
|
1
|
|
4422
5188
|
);
|
|
4423
5189
|
}
|
|
4424
|
-
geometry.setAttribute("position", new
|
|
4425
|
-
geometry.setAttribute("normal", new
|
|
4426
|
-
geometry.setAttribute("uv", new
|
|
5190
|
+
geometry.setAttribute("position", new import_three28.Float32BufferAttribute(positions, 3));
|
|
5191
|
+
geometry.setAttribute("normal", new import_three28.Float32BufferAttribute(normals, 3));
|
|
5192
|
+
geometry.setAttribute("uv", new import_three28.Float32BufferAttribute(uvs, 2));
|
|
4427
5193
|
geometry.setIndex(indices);
|
|
4428
5194
|
return geometry;
|
|
4429
5195
|
}
|
|
4430
|
-
var
|
|
5196
|
+
var import_three28, fluidRules, HORIZONTAL, EPSILON;
|
|
4431
5197
|
var init_FluidGeometry = __esm({
|
|
4432
5198
|
"src/model/fluid/FluidGeometry.ts"() {
|
|
4433
|
-
|
|
5199
|
+
import_three28 = require("three");
|
|
4434
5200
|
init_fluidBlocks();
|
|
4435
5201
|
fluidRules = fluidBlocks_default;
|
|
4436
5202
|
HORIZONTAL = [[0, -1], [0, 1], [-1, 0], [1, 0]];
|
|
@@ -4459,10 +5225,10 @@ function sampleFluid(kind, sample) {
|
|
|
4459
5225
|
}
|
|
4460
5226
|
return { key: key.join(""), sample: (x, y, z) => cells[(y + 1) * 9 + (z + 1) * 3 + x + 1] };
|
|
4461
5227
|
}
|
|
4462
|
-
var
|
|
5228
|
+
var import_three29, FluidModelObject;
|
|
4463
5229
|
var init_FluidModelObject = __esm({
|
|
4464
5230
|
"src/model/fluid/FluidModelObject.ts"() {
|
|
4465
|
-
|
|
5231
|
+
import_three29 = require("three");
|
|
4466
5232
|
init_AssetKey();
|
|
4467
5233
|
init_Materials();
|
|
4468
5234
|
init_ModelObject();
|
|
@@ -4495,10 +5261,10 @@ var init_FluidModelObject = __esm({
|
|
|
4495
5261
|
}
|
|
4496
5262
|
}
|
|
4497
5263
|
geometry.clearGroups();
|
|
4498
|
-
const color = new
|
|
5264
|
+
const color = new import_three29.Color(this.options.tints?.[0] ?? (this.kind === "water" ? 4159204 : 16777215));
|
|
4499
5265
|
const colors = new Float32Array(geometry.getAttribute("position").count * 3);
|
|
4500
5266
|
for (let i = 0; i < colors.length; i += 3) color.toArray(colors, i);
|
|
4501
|
-
geometry.setAttribute("color", new
|
|
5267
|
+
geometry.setAttribute("color", new import_three29.BufferAttribute(colors, 3));
|
|
4502
5268
|
geometry.computeBoundingBox();
|
|
4503
5269
|
geometry.computeBoundingSphere();
|
|
4504
5270
|
if (this.options.instanceMeshes) {
|
|
@@ -4512,7 +5278,7 @@ var init_FluidModelObject = __esm({
|
|
|
4512
5278
|
super.applyTextures();
|
|
4513
5279
|
this.iterateAllMeshes((mesh) => {
|
|
4514
5280
|
const material = mesh.material;
|
|
4515
|
-
material.side =
|
|
5281
|
+
material.side = import_three29.DoubleSide;
|
|
4516
5282
|
material.forceSinglePass = true;
|
|
4517
5283
|
material.depthWrite = !material.transparent;
|
|
4518
5284
|
});
|
|
@@ -4616,6 +5382,7 @@ __export(index_browser_exports, {
|
|
|
4616
5382
|
SkinPart: () => SkinPart,
|
|
4617
5383
|
SkinTextures: () => SkinTextures,
|
|
4618
5384
|
Skins: () => Skins,
|
|
5385
|
+
SpecialItems: () => SpecialItems,
|
|
4619
5386
|
StructureParser: () => StructureParser,
|
|
4620
5387
|
TextureAtlas: () => TextureAtlas,
|
|
4621
5388
|
TextureLoader: () => TextureLoader,
|
|
@@ -4845,96 +5612,8 @@ var Meshes = class _Meshes {
|
|
|
4845
5612
|
}
|
|
4846
5613
|
};
|
|
4847
5614
|
|
|
4848
|
-
// src/
|
|
4849
|
-
|
|
4850
|
-
init_CubeFace();
|
|
4851
|
-
var MinecraftCubeTexture = class {
|
|
4852
|
-
constructor(u, v, width, height) {
|
|
4853
|
-
this.u = u;
|
|
4854
|
-
this.v = v;
|
|
4855
|
-
this.width = width;
|
|
4856
|
-
this.height = height;
|
|
4857
|
-
}
|
|
4858
|
-
mapW(x) {
|
|
4859
|
-
return x / this.width;
|
|
4860
|
-
}
|
|
4861
|
-
mapH(x) {
|
|
4862
|
-
return 1 - x / this.height;
|
|
4863
|
-
}
|
|
4864
|
-
getUvEast(w, h, l) {
|
|
4865
|
-
return [
|
|
4866
|
-
[this.mapW(this.u + l + w + l), this.mapH(this.v + l + h)],
|
|
4867
|
-
[this.mapW(this.u + l + w), this.mapH(this.v + l + h)],
|
|
4868
|
-
[this.mapW(this.u + l + w + l), this.mapH(this.v + l)],
|
|
4869
|
-
[this.mapW(this.u + l + w), this.mapH(this.v + l)]
|
|
4870
|
-
];
|
|
4871
|
-
}
|
|
4872
|
-
getUvWest(w, h, l) {
|
|
4873
|
-
return [
|
|
4874
|
-
[this.mapW(this.u + l), this.mapH(this.v + l + h)],
|
|
4875
|
-
[this.mapW(this.u), this.mapH(this.v + l + h)],
|
|
4876
|
-
[this.mapW(this.u + l), this.mapH(this.v + l)],
|
|
4877
|
-
[this.mapW(this.u), this.mapH(this.v + l)]
|
|
4878
|
-
];
|
|
4879
|
-
}
|
|
4880
|
-
getUvUp(w, h, l) {
|
|
4881
|
-
return [
|
|
4882
|
-
[this.mapW(this.u + l + w), this.mapH(this.v + l)],
|
|
4883
|
-
[this.mapW(this.u + l + w + w), this.mapH(this.v + l)],
|
|
4884
|
-
[this.mapW(this.u + l + w), this.mapH(this.v)],
|
|
4885
|
-
[this.mapW(this.u + l + w + w), this.mapH(this.v)]
|
|
4886
|
-
];
|
|
4887
|
-
}
|
|
4888
|
-
getUvDown(w, h, l) {
|
|
4889
|
-
return [
|
|
4890
|
-
[this.mapW(this.u + l), this.mapH(this.v)],
|
|
4891
|
-
[this.mapW(this.u + l + w), this.mapH(this.v)],
|
|
4892
|
-
[this.mapW(this.u + l), this.mapH(this.v + l)],
|
|
4893
|
-
[this.mapW(this.u + l + w), this.mapH(this.v + l)]
|
|
4894
|
-
];
|
|
4895
|
-
}
|
|
4896
|
-
getUvSouth(w, h, l) {
|
|
4897
|
-
return [
|
|
4898
|
-
[this.mapW(this.u + l + w + l + w), this.mapH(this.v + l + h)],
|
|
4899
|
-
[this.mapW(this.u + l + w + l), this.mapH(this.v + l + h)],
|
|
4900
|
-
[this.mapW(this.u + l + w + l + w), this.mapH(this.v + l)],
|
|
4901
|
-
[this.mapW(this.u + l + w + l), this.mapH(this.v + l)]
|
|
4902
|
-
];
|
|
4903
|
-
}
|
|
4904
|
-
getUvNorth(w, h, l) {
|
|
4905
|
-
return [
|
|
4906
|
-
[this.mapW(this.u + l + w), this.mapH(this.v + l + h)],
|
|
4907
|
-
[this.mapW(this.u + l), this.mapH(this.v + l + h)],
|
|
4908
|
-
[this.mapW(this.u + l + w), this.mapH(this.v + l)],
|
|
4909
|
-
[this.mapW(this.u + l), this.mapH(this.v + l)]
|
|
4910
|
-
];
|
|
4911
|
-
}
|
|
4912
|
-
getFaceUv(face, w, h, l) {
|
|
4913
|
-
switch (face) {
|
|
4914
|
-
case "east" /* EAST */:
|
|
4915
|
-
return this.getUvEast(w, h, l);
|
|
4916
|
-
case "west" /* WEST */:
|
|
4917
|
-
return this.getUvWest(w, h, l);
|
|
4918
|
-
case "up" /* UP */:
|
|
4919
|
-
return this.getUvUp(w, h, l);
|
|
4920
|
-
case "down" /* DOWN */:
|
|
4921
|
-
return this.getUvDown(w, h, l);
|
|
4922
|
-
case "south" /* SOUTH */:
|
|
4923
|
-
return this.getUvSouth(w, h, l);
|
|
4924
|
-
case "north" /* NORTH */:
|
|
4925
|
-
return this.getUvNorth(w, h, l);
|
|
4926
|
-
}
|
|
4927
|
-
}
|
|
4928
|
-
toUvArray(w, h, l, mirror = false) {
|
|
4929
|
-
const uv = [];
|
|
4930
|
-
for (let i = 0; i < CUBE_FACES.length; i++) {
|
|
4931
|
-
const face = mirror && i < 2 ? CUBE_FACES[1 - i] : CUBE_FACES[i];
|
|
4932
|
-
const corners = this.getFaceUv(face, w, h, l);
|
|
4933
|
-
UVMapper.setFaceUvInArray(uv, i * 4, mirror ? [corners[1], corners[0], corners[3], corners[2]] : corners);
|
|
4934
|
-
}
|
|
4935
|
-
return uv;
|
|
4936
|
-
}
|
|
4937
|
-
};
|
|
5615
|
+
// src/index.ts
|
|
5616
|
+
init_MinecraftCubeTexture();
|
|
4938
5617
|
|
|
4939
5618
|
// src/SceneStats.ts
|
|
4940
5619
|
var SceneStats = class {
|
|
@@ -5028,116 +5707,7 @@ var BlockEntities = class {
|
|
|
5028
5707
|
|
|
5029
5708
|
// src/assets/index.ts
|
|
5030
5709
|
init_BlockStates();
|
|
5031
|
-
|
|
5032
|
-
// src/assets/Entities.ts
|
|
5033
|
-
init_AssetKey();
|
|
5034
|
-
init_AssetLoader();
|
|
5035
|
-
init_source();
|
|
5036
|
-
init_Caching();
|
|
5037
|
-
init_Assets();
|
|
5038
|
-
init_MineRenderError();
|
|
5039
|
-
init_ModelTextures();
|
|
5040
|
-
var Entities = class {
|
|
5041
|
-
static async getEntityList() {
|
|
5042
|
-
const collect = async (path) => {
|
|
5043
|
-
const prefix2 = path ? `${path}/` : "";
|
|
5044
|
-
const key = new AssetKey(DEFAULT_NAMESPACE, `${prefix2}_list`, void 0, void 0, "entity-models", ".json");
|
|
5045
|
-
const list = await Caching.listAssetCache.get(key.serialize(), () => AssetLoader.get(key, "list" /* LIST */));
|
|
5046
|
-
if (!list) return [];
|
|
5047
|
-
const files = list.files.filter((file) => file.endsWith(".json") && file !== "_list.json").map((file) => `${prefix2}${file.slice(0, -5)}`);
|
|
5048
|
-
const children = await Promise.all(list.directories.map((directory) => collect(`${prefix2}${directory}`)));
|
|
5049
|
-
return [...files, ...children.flat()];
|
|
5050
|
-
};
|
|
5051
|
-
return collect("");
|
|
5052
|
-
}
|
|
5053
|
-
static async getModelFile(modelKey) {
|
|
5054
|
-
const path = isAssetKey(modelKey) ? modelKey.getFullPath() : modelKey.path;
|
|
5055
|
-
const key = new AssetKey(modelKey.namespace, path, void 0, void 0, "entity-models", ".json");
|
|
5056
|
-
return Caching.entityModelCache.get(key.serialize(), () => AssetLoader.get(key, "json" /* JSON */));
|
|
5057
|
-
}
|
|
5058
|
-
static async getLayerList(modelKey) {
|
|
5059
|
-
return Object.keys((await this.getModelFile(modelKey))?.layers ?? {});
|
|
5060
|
-
}
|
|
5061
|
-
/** The dataset's extra draws on top of `main`; their `when` labels are the states `EntityModelOptions.when` can enable. */
|
|
5062
|
-
static async getPassList(modelKey) {
|
|
5063
|
-
return (await this.getModelFile(modelKey))?.passes ?? [];
|
|
5064
|
-
}
|
|
5065
|
-
static async getEntity(modelKey, textureKey, options) {
|
|
5066
|
-
const model = await this.getModelFile(modelKey);
|
|
5067
|
-
if (!model) return void 0;
|
|
5068
|
-
const passes = options?.layers || options?.layer !== void 0 ? [] : (model.passes ?? []).filter((pass) => pass.when === void 0 || options?.when?.includes(pass.when));
|
|
5069
|
-
const draws = [...new Set(options?.layers ?? [options?.layer ?? "main"])].map((layer) => ({ layer }));
|
|
5070
|
-
if (draws.length === 0) throw new MineRenderError(`Entity ${model.id} requires at least one layer`);
|
|
5071
|
-
draws.push(...passes);
|
|
5072
|
-
const names = [];
|
|
5073
|
-
const selected = draws.map((pass) => {
|
|
5074
|
-
const layer = model.layers[pass.layer];
|
|
5075
|
-
if (!layer) {
|
|
5076
|
-
throw new MineRenderError(`Entity ${model.id} has no layer "${pass.layer}". Available layers: ${Object.keys(model.layers).join(", ")}`);
|
|
5077
|
-
}
|
|
5078
|
-
let name = pass.layer;
|
|
5079
|
-
for (let n = 2; names.includes(name); n++) name = `${pass.layer}#${n}`;
|
|
5080
|
-
names.push(name);
|
|
5081
|
-
return { name, layer, pass };
|
|
5082
|
-
});
|
|
5083
|
-
const layers = Object.fromEntries(await Promise.all(selected.map(async ({ name, layer, pass }, index) => {
|
|
5084
|
-
const override = options?.textures?.[name] ?? (index === 0 ? textureKey : void 0);
|
|
5085
|
-
const textureLocation = pass.textureLocation ?? layer.textureLocation;
|
|
5086
|
-
let texture;
|
|
5087
|
-
if (override) {
|
|
5088
|
-
const path = isAssetKey(override) ? override.getFullPath() : override.path;
|
|
5089
|
-
texture = isAssetKey(override) && override.assetType === "textures" && path.startsWith("entity/") ? override : new AssetKey(override.namespace, path, "textures", "entity", "assets", ".png", isAssetKey(override) ? override.root : void 0);
|
|
5090
|
-
} else if (textureLocation !== void 0) {
|
|
5091
|
-
texture = AssetKey.parse("textures", textureLocation.replace(/^([^:]+:)?textures\//, "$1"));
|
|
5092
|
-
} else {
|
|
5093
|
-
texture = await this.resolveTexture(modelKey);
|
|
5094
|
-
}
|
|
5095
|
-
const render = pass.render ?? layer.render;
|
|
5096
|
-
return [name, { key: override ?? modelKey, texture, layer, ...render && { render }, ...pass.tint && { tint: pass.tint } }];
|
|
5097
|
-
})));
|
|
5098
|
-
return { ...layers[names[0]], id: model.id, layers, ...model.transform && { transform: model.transform } };
|
|
5099
|
-
}
|
|
5100
|
-
/**
|
|
5101
|
-
* Vanilla's keyframe animations of a model by name, or undefined when the model or the selected version has none.
|
|
5102
|
-
*/
|
|
5103
|
-
static async getAnimations(modelKey) {
|
|
5104
|
-
const path = isAssetKey(modelKey) ? modelKey.getFullPath() : modelKey.path;
|
|
5105
|
-
const key = new AssetKey(modelKey.namespace, path, void 0, void 0, "entity-models/animations", ".json");
|
|
5106
|
-
const file = await Caching.entityAnimationCache.get(key.serialize(), () => AssetLoader.get(key, "json" /* JSON */));
|
|
5107
|
-
return file?.animations;
|
|
5108
|
-
}
|
|
5109
|
-
static async resolveTexture(modelKey) {
|
|
5110
|
-
const path = isAssetKey(modelKey) ? modelKey.getFullPath() : modelKey.path;
|
|
5111
|
-
const key = new AssetKey(modelKey.namespace, path, void 0, void 0, "entity-models", ".json");
|
|
5112
|
-
return Caching.entityTextureCache.get(key.serialize(), async () => {
|
|
5113
|
-
const name = path.split("/").pop();
|
|
5114
|
-
for (const candidate of [path, `${path}/${name}`]) {
|
|
5115
|
-
const texture = new AssetKey(modelKey.namespace, candidate, "textures", "entity", "assets", ".png");
|
|
5116
|
-
if (await ModelTextures.get(texture)) return texture;
|
|
5117
|
-
}
|
|
5118
|
-
const listKey = new AssetKey(modelKey.namespace, "_list", `${name}_variant`, void 0, "data", ".json");
|
|
5119
|
-
const list = await AssetLoader.get(listKey, "list" /* LIST */);
|
|
5120
|
-
const files = list?.files.filter((file2) => file2.endsWith(".json") && file2 !== "_list.json");
|
|
5121
|
-
const file = files?.find((file2) => file2 === "temperate.json") ?? files?.[0];
|
|
5122
|
-
if (!file) return void 0;
|
|
5123
|
-
const variantKey = new AssetKey(modelKey.namespace, file.slice(0, -5), `${name}_variant`, void 0, "data", ".json");
|
|
5124
|
-
const variant = await AssetLoader.get(variantKey, "json" /* JSON */);
|
|
5125
|
-
const assets = variant?.assets;
|
|
5126
|
-
const textureId = variant?.asset_id ?? (typeof assets?.wild === "string" ? assets.wild : Object.values(assets ?? {}).find((value) => typeof value === "string"));
|
|
5127
|
-
return typeof textureId === "string" ? AssetKey.parse("textures", textureId) : void 0;
|
|
5128
|
-
});
|
|
5129
|
-
}
|
|
5130
|
-
/** @deprecated Use getEntityList(); block entities share the entity dataset. */
|
|
5131
|
-
static getBlockList() {
|
|
5132
|
-
return this.getEntityList();
|
|
5133
|
-
}
|
|
5134
|
-
/** @deprecated Use getEntity(); block entities share the entity dataset. */
|
|
5135
|
-
static getBlock(modelKey, textureKey, options) {
|
|
5136
|
-
return this.getEntity(modelKey, textureKey, options);
|
|
5137
|
-
}
|
|
5138
|
-
};
|
|
5139
|
-
|
|
5140
|
-
// src/assets/index.ts
|
|
5710
|
+
init_Entities();
|
|
5141
5711
|
init_ModelTextures();
|
|
5142
5712
|
init_Models();
|
|
5143
5713
|
init_source();
|
|
@@ -5182,346 +5752,12 @@ function trimCanvas(source) {
|
|
|
5182
5752
|
return canvas;
|
|
5183
5753
|
}
|
|
5184
5754
|
|
|
5185
|
-
// src/entity/
|
|
5186
|
-
|
|
5187
|
-
function catmullRom(delta, p0, p1, p22, p32) {
|
|
5188
|
-
return 0.5 * (2 * p1 + (p22 - p0) * delta + (2 * p0 - 5 * p1 + 4 * p22 - p32) * delta * delta + (3 * p1 - p0 - 3 * p22 + p32) * delta * delta * delta);
|
|
5189
|
-
}
|
|
5190
|
-
function sampleEntityKeyframes(keyframes, time) {
|
|
5191
|
-
if (keyframes.length === 0) return [0, 0, 0];
|
|
5192
|
-
let low = 0, high = keyframes.length;
|
|
5193
|
-
while (low < high) {
|
|
5194
|
-
const middle = low + high >>> 1;
|
|
5195
|
-
if (time <= keyframes[middle].time) high = middle;
|
|
5196
|
-
else low = middle + 1;
|
|
5197
|
-
}
|
|
5198
|
-
const a = Math.max(0, low - 1);
|
|
5199
|
-
const b = Math.min(keyframes.length - 1, a + 1);
|
|
5200
|
-
const from = keyframes[a];
|
|
5201
|
-
const to = keyframes[b];
|
|
5202
|
-
const delta = a === b ? 0 : Math.min(1, Math.max(0, (time - from.time) / (to.time - from.time)));
|
|
5203
|
-
if (to.interpolation === "catmullrom") {
|
|
5204
|
-
const before = keyframes[Math.max(0, a - 1)].value;
|
|
5205
|
-
const after = keyframes[Math.min(keyframes.length - 1, b + 1)].value;
|
|
5206
|
-
return [0, 1, 2].map((i) => catmullRom(delta, before[i], from.value[i], to.value[i], after[i]));
|
|
5207
|
-
}
|
|
5208
|
-
const target = to.pre ?? to.value;
|
|
5209
|
-
return [0, 1, 2].map((i) => from.value[i] + (target[i] - from.value[i]) * delta);
|
|
5210
|
-
}
|
|
5211
|
-
function entityAnimationTime(animation, time, loop = animation.loop) {
|
|
5212
|
-
return loop && animation.length > 0 ? time % animation.length : time;
|
|
5213
|
-
}
|
|
5214
|
-
function sampleEntityAnimation(animation, time, loop = animation.loop) {
|
|
5215
|
-
const elapsed = entityAnimationTime(animation, time, loop);
|
|
5216
|
-
const pose = {};
|
|
5217
|
-
for (const [name, bone] of Object.entries(animation.bones)) {
|
|
5218
|
-
const sampled = pose[name] = {};
|
|
5219
|
-
for (const channel of ENTITY_ANIMATION_CHANNELS) {
|
|
5220
|
-
const keyframes = bone[channel];
|
|
5221
|
-
if (keyframes?.length) sampled[channel] = sampleEntityKeyframes(keyframes, elapsed);
|
|
5222
|
-
}
|
|
5223
|
-
}
|
|
5224
|
-
return pose;
|
|
5225
|
-
}
|
|
5226
|
-
|
|
5227
|
-
// src/entity/scene/EntityAnimationPlayer.ts
|
|
5228
|
-
var ZERO = [0, 0, 0];
|
|
5229
|
-
var EntityAnimationPlayer = class {
|
|
5230
|
-
constructor() {
|
|
5231
|
-
this.parts = [];
|
|
5232
|
-
this._time = 0;
|
|
5233
|
-
this.loop = false;
|
|
5234
|
-
this.speed = 1;
|
|
5235
|
-
}
|
|
5236
|
-
get animation() {
|
|
5237
|
-
return this._animation;
|
|
5238
|
-
}
|
|
5239
|
-
get time() {
|
|
5240
|
-
return this._time;
|
|
5241
|
-
}
|
|
5242
|
-
/**
|
|
5243
|
-
* Starts an animation on the named parts below each layer root. The current pose of a part becomes its default;
|
|
5244
|
-
* bones without a matching part are skipped.
|
|
5245
|
-
*/
|
|
5246
|
-
play(layers, animation, options = {}) {
|
|
5247
|
-
this.stop();
|
|
5248
|
-
this._animation = animation;
|
|
5249
|
-
this._time = options.time ?? 0;
|
|
5250
|
-
this.loop = options.loop ?? animation.loop;
|
|
5251
|
-
this.speed = options.speed ?? 1;
|
|
5252
|
-
for (const layer of layers) {
|
|
5253
|
-
for (const bone of Object.keys(animation.bones)) {
|
|
5254
|
-
const object = layer.getObjectByName(`group:${bone}`);
|
|
5255
|
-
if (!object) continue;
|
|
5256
|
-
this.parts.push({ bone, object, position: object.position.clone(), rotation: object.rotation.clone(), scale: object.scale.clone() });
|
|
5257
|
-
}
|
|
5258
|
-
}
|
|
5259
|
-
this.apply();
|
|
5260
|
-
}
|
|
5261
|
-
/** Restores the default poses. Returns whether an animation was active. */
|
|
5262
|
-
stop() {
|
|
5263
|
-
if (!this._animation) return false;
|
|
5264
|
-
for (const part of this.parts) {
|
|
5265
|
-
part.object.position.copy(part.position);
|
|
5266
|
-
part.object.rotation.copy(part.rotation);
|
|
5267
|
-
part.object.scale.copy(part.scale);
|
|
5268
|
-
}
|
|
5269
|
-
this.clear();
|
|
5270
|
-
return true;
|
|
5271
|
-
}
|
|
5272
|
-
/** Forgets the animation without touching the parts, for parts that no longer exist. */
|
|
5273
|
-
clear() {
|
|
5274
|
-
this.parts = [];
|
|
5275
|
-
this._animation = void 0;
|
|
5276
|
-
this._time = 0;
|
|
5277
|
-
}
|
|
5278
|
-
setTime(seconds) {
|
|
5279
|
-
if (!this._animation) return false;
|
|
5280
|
-
this._time = seconds;
|
|
5281
|
-
this.apply();
|
|
5282
|
-
return true;
|
|
5283
|
-
}
|
|
5284
|
-
advance(deltaSeconds) {
|
|
5285
|
-
return this.setTime(this._time + deltaSeconds * this.speed);
|
|
5286
|
-
}
|
|
5287
|
-
apply() {
|
|
5288
|
-
const pose = sampleEntityAnimation(this._animation, this._time, this.loop);
|
|
5289
|
-
for (const part of this.parts) {
|
|
5290
|
-
const { position = ZERO, rotation = ZERO, scale = ZERO } = pose[part.bone];
|
|
5291
|
-
part.object.position.set(part.position.x + position[0], part.position.y + position[1], part.position.z + position[2]);
|
|
5292
|
-
part.object.rotation.set(part.rotation.x + rotation[0], part.rotation.y + rotation[1], part.rotation.z + rotation[2], part.rotation.order);
|
|
5293
|
-
part.object.scale.set(part.scale.x + scale[0], part.scale.y + scale[1], part.scale.z + scale[2]);
|
|
5294
|
-
}
|
|
5295
|
-
}
|
|
5296
|
-
};
|
|
5755
|
+
// src/entity/index.ts
|
|
5756
|
+
init_EntityAnimation();
|
|
5297
5757
|
|
|
5298
|
-
// src/entity/scene/
|
|
5299
|
-
|
|
5300
|
-
|
|
5301
|
-
var import_ts_deepmerge4 = __toESM(require_dist());
|
|
5302
|
-
var import_three13 = require("three");
|
|
5303
|
-
init_Ticker();
|
|
5304
|
-
init_model();
|
|
5305
|
-
init_ModelTextures();
|
|
5306
|
-
init_AssetKey();
|
|
5307
|
-
init_Materials();
|
|
5308
|
-
init_three();
|
|
5309
|
-
var _EntityObject = class _EntityObject extends SceneObject {
|
|
5310
|
-
constructor(entity, options) {
|
|
5311
|
-
super();
|
|
5312
|
-
this.entity = entity;
|
|
5313
|
-
this.isEntityObject = true;
|
|
5314
|
-
this.meshesCreated = false;
|
|
5315
|
-
this.geometries = /* @__PURE__ */ new Set();
|
|
5316
|
-
this.disposeWireframes = [];
|
|
5317
|
-
/** Scrolling materials are owned: their texture offset follows this entity's age. */
|
|
5318
|
-
this.scrollMaterials = [];
|
|
5319
|
-
/** Entity age in ticks, as vanilla's `ageInTicks`; drives the scrolling render modes. */
|
|
5320
|
-
this.age = 0;
|
|
5321
|
-
this.animationPlayer = new EntityAnimationPlayer();
|
|
5322
|
-
this.options = (0, import_ts_deepmerge4.default)({}, _EntityObject.DEFAULT_OPTIONS, options ?? {});
|
|
5323
|
-
this.addEventListener("added", () => this.updateScrollSubscription());
|
|
5324
|
-
this.addEventListener("removed", () => this.updateScrollSubscription());
|
|
5325
|
-
}
|
|
5326
|
-
async init() {
|
|
5327
|
-
this.createMeshes();
|
|
5328
|
-
await this.applyTextures();
|
|
5329
|
-
}
|
|
5330
|
-
dispose() {
|
|
5331
|
-
super.dispose();
|
|
5332
|
-
}
|
|
5333
|
-
disposeAndRemoveAllChildren() {
|
|
5334
|
-
this.clearScrollMaterials();
|
|
5335
|
-
for (const geometry of this.geometries) geometry.dispose();
|
|
5336
|
-
this.geometries.clear();
|
|
5337
|
-
for (const dispose of this.disposeWireframes.splice(0)) dispose();
|
|
5338
|
-
this.animationPlayer.clear();
|
|
5339
|
-
super.disposeAndRemoveAllChildren();
|
|
5340
|
-
}
|
|
5341
|
-
clearScrollMaterials() {
|
|
5342
|
-
Ticker.remove(this.scrollTicker);
|
|
5343
|
-
this.scrollTicker = void 0;
|
|
5344
|
-
for (const { material } of this.scrollMaterials.splice(0)) {
|
|
5345
|
-
material.map?.dispose();
|
|
5346
|
-
material.dispose();
|
|
5347
|
-
}
|
|
5348
|
-
}
|
|
5349
|
-
updateScrollSubscription() {
|
|
5350
|
-
if (this.parent && this.scrollMaterials.length) {
|
|
5351
|
-
if (this.scrollTicker === void 0) {
|
|
5352
|
-
this.scrollTicker = Ticker.add(() => {
|
|
5353
|
-
this.age++;
|
|
5354
|
-
this.updateScroll();
|
|
5355
|
-
});
|
|
5356
|
-
}
|
|
5357
|
-
} else {
|
|
5358
|
-
Ticker.remove(this.scrollTicker);
|
|
5359
|
-
this.scrollTicker = void 0;
|
|
5360
|
-
}
|
|
5361
|
-
}
|
|
5362
|
-
/** Applies the entity age to the scrolling materials; the ticker calls this 20 times per second. */
|
|
5363
|
-
updateScroll() {
|
|
5364
|
-
for (const { offset, speed } of this.scrollMaterials) {
|
|
5365
|
-
offset.set(this.age * speed[0] % 1, 0 - this.age * speed[1] % 1);
|
|
5366
|
-
}
|
|
5367
|
-
this.notifyDirty();
|
|
5368
|
-
}
|
|
5369
|
-
//<editor-fold desc="ANIMATION">
|
|
5370
|
-
/** The animation started by {@link playAnimation}, until {@link stopAnimation} or disposal. */
|
|
5371
|
-
get animation() {
|
|
5372
|
-
return this.animationPlayer.animation;
|
|
5373
|
-
}
|
|
5374
|
-
/** Seconds since the animation started, before looping. */
|
|
5375
|
-
get animationTime() {
|
|
5376
|
-
return this.animationPlayer.time;
|
|
5377
|
-
}
|
|
5378
|
-
/**
|
|
5379
|
-
* Poses the object from a keyframe animation of {@link Entities.getAnimations}, replacing the current one.
|
|
5380
|
-
* Parts of every layer are matched by name and their current pose is the default the offsets add to.
|
|
5381
|
-
* The object owns no clock: call {@link advanceAnimation} per frame, or {@link setAnimationTime}.
|
|
5382
|
-
*/
|
|
5383
|
-
playAnimation(animation, options) {
|
|
5384
|
-
this.createMeshes();
|
|
5385
|
-
const layers = Object.keys(this.entityLayers).map((name) => this.getLayerGroup(name)).filter((layer) => !!layer);
|
|
5386
|
-
this.animationPlayer.play(layers, animation, options);
|
|
5387
|
-
this.notifyDirty();
|
|
5388
|
-
}
|
|
5389
|
-
/** Stops the animation and restores the default pose. */
|
|
5390
|
-
stopAnimation() {
|
|
5391
|
-
if (this.animationPlayer.stop()) this.notifyDirty();
|
|
5392
|
-
}
|
|
5393
|
-
/** Poses the object at an explicit time in seconds. Has no effect without an animation. */
|
|
5394
|
-
setAnimationTime(seconds) {
|
|
5395
|
-
if (this.animationPlayer.setTime(seconds)) this.notifyDirty();
|
|
5396
|
-
}
|
|
5397
|
-
/** Advances the animation by a frame delta in seconds, scaled by its speed. Has no effect without an animation. */
|
|
5398
|
-
advanceAnimation(deltaSeconds) {
|
|
5399
|
-
if (this.animationPlayer.advance(deltaSeconds)) this.notifyDirty();
|
|
5400
|
-
}
|
|
5401
|
-
//</editor-fold>
|
|
5402
|
-
getLayerGroup(name) {
|
|
5403
|
-
return super.getGroupByName(`layer:${name}`);
|
|
5404
|
-
}
|
|
5405
|
-
getGroupByName(name, layerName) {
|
|
5406
|
-
return layerName === void 0 ? super.getGroupByName(name) : this.getLayerGroup(layerName)?.getObjectByName(`group:${name}`);
|
|
5407
|
-
}
|
|
5408
|
-
getMeshByName(name, layerName) {
|
|
5409
|
-
return layerName === void 0 ? super.getMeshByName(name) : this.getLayerGroup(layerName)?.getObjectByName(`mesh:${name}`);
|
|
5410
|
-
}
|
|
5411
|
-
get entityLayers() {
|
|
5412
|
-
return this.entity.layers ?? { main: this.entity };
|
|
5413
|
-
}
|
|
5414
|
-
getTextureKey(layer) {
|
|
5415
|
-
if (layer.texture) return layer.texture;
|
|
5416
|
-
const key = layer.key;
|
|
5417
|
-
return new AssetKey(
|
|
5418
|
-
key.namespace,
|
|
5419
|
-
isAssetKey(key) ? key.getFullPath() : key.path,
|
|
5420
|
-
"textures",
|
|
5421
|
-
"entity",
|
|
5422
|
-
"assets",
|
|
5423
|
-
".png"
|
|
5424
|
-
);
|
|
5425
|
-
}
|
|
5426
|
-
async loadTextures(layer = this.entity) {
|
|
5427
|
-
return ModelTextures.get(this.getTextureKey(layer));
|
|
5428
|
-
}
|
|
5429
|
-
createMeshes(force = false) {
|
|
5430
|
-
if (this.meshesCreated && !force) return;
|
|
5431
|
-
const modelRoot = new import_three13.Object3D();
|
|
5432
|
-
const transform = this.options.flip === void 0 ? this.entity.transform : void 0;
|
|
5433
|
-
if (transform) {
|
|
5434
|
-
for (const op of transform) {
|
|
5435
|
-
const matrix = new import_three13.Matrix4();
|
|
5436
|
-
if ("scale" in op) matrix.makeScale(...op.scale);
|
|
5437
|
-
else if ("translate" in op) matrix.makeTranslation(...op.translate);
|
|
5438
|
-
else matrix.makeRotationFromEuler(new import_three13.Euler(...op.rotate, "ZYX"));
|
|
5439
|
-
modelRoot.matrix.multiply(matrix);
|
|
5440
|
-
}
|
|
5441
|
-
modelRoot.matrixAutoUpdate = false;
|
|
5442
|
-
} else if (this.options.flip ?? true) {
|
|
5443
|
-
modelRoot.scale.set(-1, -1, 1);
|
|
5444
|
-
}
|
|
5445
|
-
this.add(modelRoot);
|
|
5446
|
-
Object.entries(this.entityLayers).forEach(([name, layer], index) => {
|
|
5447
|
-
const group = this.createGroup(`layer:${name}`);
|
|
5448
|
-
modelRoot.add(group);
|
|
5449
|
-
const inward = !Materials.entityModeCulls(layer.render ?? layer.layer.render);
|
|
5450
|
-
this.createPart("root", layer.layer.root, group, layer.layer.texture, Materials.MISSING_TEXTURE, index, inward);
|
|
5451
|
-
});
|
|
5452
|
-
this.meshesCreated = true;
|
|
5453
|
-
}
|
|
5454
|
-
createPart(name, part, parent, textureSize, material, renderOrder, inward = true) {
|
|
5455
|
-
const anchor = this.createGroup(name);
|
|
5456
|
-
anchor.position.fromArray(part.pose.offset);
|
|
5457
|
-
anchor.rotation.set(...part.pose.rotation, "ZYX");
|
|
5458
|
-
anchor.scale.fromArray(part.pose.scale ?? [1, 1, 1]);
|
|
5459
|
-
parent.add(anchor);
|
|
5460
|
-
const size = part.texture ?? textureSize;
|
|
5461
|
-
for (const cube of part.cubes) {
|
|
5462
|
-
const [width, height, depth] = cube.size;
|
|
5463
|
-
const [growX, growY, growZ] = cube.grow ?? [0, 0, 0];
|
|
5464
|
-
const texture = new MinecraftCubeTexture(...cube.uv, ...size);
|
|
5465
|
-
const uv = size[0] === 0 || size[1] === 0 ? new Array(48).fill(0) : texture.toUvArray(width, height, depth, cube.mirror);
|
|
5466
|
-
const geometry = this._getBoxGeometryForDimensionsAndUv(
|
|
5467
|
-
width + growX * 2,
|
|
5468
|
-
height + growY * 2,
|
|
5469
|
-
depth + growZ * 2,
|
|
5470
|
-
uv
|
|
5471
|
-
).clone();
|
|
5472
|
-
this.geometries.add(geometry);
|
|
5473
|
-
geometry.translate(cube.origin[0] + width / 2, cube.origin[1] + height / 2, cube.origin[2] + depth / 2);
|
|
5474
|
-
if (inward && Math.min(width + growX * 2, height + growY * 2, depth + growZ * 2) > 0) {
|
|
5475
|
-
const index = Array.from(geometry.getIndex().array);
|
|
5476
|
-
geometry.setIndex(index.concat(index.slice().reverse()));
|
|
5477
|
-
}
|
|
5478
|
-
const mesh = this.createMesh(name, geometry, material);
|
|
5479
|
-
mesh.renderOrder = renderOrder;
|
|
5480
|
-
anchor.add(mesh);
|
|
5481
|
-
if (this.options.wireframe) this.disposeWireframes.push(addWireframeToMesh(geometry, mesh));
|
|
5482
|
-
}
|
|
5483
|
-
for (const [childName, child] of Object.entries(part.children)) {
|
|
5484
|
-
this.createPart(childName, child, anchor, size, material, renderOrder, inward);
|
|
5485
|
-
}
|
|
5486
|
-
}
|
|
5487
|
-
async applyTextures() {
|
|
5488
|
-
this.clearScrollMaterials();
|
|
5489
|
-
await Promise.all(Object.entries(this.entityLayers).map(async ([name, layer]) => {
|
|
5490
|
-
const mode = layer.render ?? layer.layer.render ?? "cutout";
|
|
5491
|
-
const tint = layer.tint === void 0 ? void 0 : this.options.tints?.[layer.tint];
|
|
5492
|
-
const scroll = Materials.entityModeScroll(mode);
|
|
5493
|
-
const assetKeyStr = this.getTextureKey(layer).serialize();
|
|
5494
|
-
const keyStr = `entity:${mode}:${tint === void 0 ? "" : new import_three13.Color(tint).getHexString()}:${assetKeyStr}`;
|
|
5495
|
-
let mat = scroll ? void 0 : Caching.materialCache.getIfPresent(keyStr);
|
|
5496
|
-
if (!mat) {
|
|
5497
|
-
const cachedAsset = Caching.textureAssetCache.getIfPresent(assetKeyStr);
|
|
5498
|
-
const imageData = await this.loadTextures(layer);
|
|
5499
|
-
if (!imageData) return;
|
|
5500
|
-
const canvas = imageData.data.canvas;
|
|
5501
|
-
const createMaterial = () => Materials.createEntityCanvasMaterial(canvas, mode, tint);
|
|
5502
|
-
mat = !scroll && cachedAsset && Caching.textureAssetCache.getIfPresent(assetKeyStr) === cachedAsset ? Caching.materialCache.get(keyStr, createMaterial) : createMaterial();
|
|
5503
|
-
if (scroll) {
|
|
5504
|
-
this.scrollMaterials.push({ material: mat, offset: mat.map.offset, speed: scroll });
|
|
5505
|
-
}
|
|
5506
|
-
}
|
|
5507
|
-
this.getLayerGroup(name)?.traverse((object) => {
|
|
5508
|
-
if (isMesh(object)) object.material = mat;
|
|
5509
|
-
});
|
|
5510
|
-
}));
|
|
5511
|
-
if (!this.children.length) {
|
|
5512
|
-
this.clearScrollMaterials();
|
|
5513
|
-
} else if (this.scrollMaterials.length) {
|
|
5514
|
-
this.updateScroll();
|
|
5515
|
-
}
|
|
5516
|
-
this.updateScrollSubscription();
|
|
5517
|
-
this.notifyDirty();
|
|
5518
|
-
}
|
|
5519
|
-
};
|
|
5520
|
-
_EntityObject.DEFAULT_OPTIONS = (0, import_ts_deepmerge4.default)({}, SceneObject.DEFAULT_OPTIONS);
|
|
5521
|
-
var EntityObject = _EntityObject;
|
|
5522
|
-
function isEntityObject(obj) {
|
|
5523
|
-
return obj.isEntityObject;
|
|
5524
|
-
}
|
|
5758
|
+
// src/entity/scene/index.ts
|
|
5759
|
+
init_EntityAnimationPlayer();
|
|
5760
|
+
init_EntityObject();
|
|
5525
5761
|
|
|
5526
5762
|
// src/error/index.ts
|
|
5527
5763
|
init_MineRenderError();
|
|
@@ -8097,7 +8333,7 @@ var GuiHelper = class {
|
|
|
8097
8333
|
};
|
|
8098
8334
|
|
|
8099
8335
|
// src/gui/scene/GuiObject.ts
|
|
8100
|
-
var
|
|
8336
|
+
var import_three24 = require("three");
|
|
8101
8337
|
init_AssetKey();
|
|
8102
8338
|
init_ModelTextures();
|
|
8103
8339
|
init_Models();
|
|
@@ -8106,22 +8342,14 @@ init_SceneObject();
|
|
|
8106
8342
|
init_Materials();
|
|
8107
8343
|
init_ModelObject();
|
|
8108
8344
|
init_DisplayPosition();
|
|
8109
|
-
|
|
8110
|
-
// src/model/GuiLight.ts
|
|
8111
|
-
var GuiLight = /* @__PURE__ */ ((GuiLight2) => {
|
|
8112
|
-
GuiLight2["FRONT"] = "front";
|
|
8113
|
-
GuiLight2["SIDE"] = "side";
|
|
8114
|
-
return GuiLight2;
|
|
8115
|
-
})(GuiLight || {});
|
|
8116
|
-
|
|
8117
|
-
// src/gui/scene/GuiObject.ts
|
|
8345
|
+
init_GuiLight();
|
|
8118
8346
|
var GuiObject = class extends SceneObject {
|
|
8119
8347
|
constructor(textureLayers, options) {
|
|
8120
8348
|
super({ ...options, instanceMeshes: false, mergeMeshes: false });
|
|
8121
8349
|
this.textureLayers = textureLayers;
|
|
8122
8350
|
this.isGuiObject = true;
|
|
8123
8351
|
/** Local bounds in GUI pixels, with y growing down from the origin. */
|
|
8124
|
-
this.bounds = new
|
|
8352
|
+
this.bounds = new import_three24.Box2();
|
|
8125
8353
|
this.geometries = /* @__PURE__ */ new Set();
|
|
8126
8354
|
this.ownedMaterials = /* @__PURE__ */ new Set();
|
|
8127
8355
|
this.initialized = false;
|
|
@@ -8137,19 +8365,19 @@ var GuiObject = class extends SceneObject {
|
|
|
8137
8365
|
const item = await this.createItem(layer, index);
|
|
8138
8366
|
item.position.set(x + width2 / 2, -y - height2 / 2, 0);
|
|
8139
8367
|
item.scale.set(width2 / 16, height2 / 16, width2 / 16);
|
|
8140
|
-
item.
|
|
8141
|
-
const
|
|
8368
|
+
item.updateWorldMatrix(true, true);
|
|
8369
|
+
const inverse = this.matrixWorld.clone().invert();
|
|
8370
|
+
const bounds = new import_three24.Box3();
|
|
8142
8371
|
item.iterateAllMeshes((mesh2) => {
|
|
8143
8372
|
mesh2.geometry.computeBoundingBox();
|
|
8144
|
-
bounds.union(mesh2.geometry.boundingBox);
|
|
8373
|
+
bounds.union(mesh2.geometry.boundingBox.clone().applyMatrix4(new import_three24.Matrix4().multiplyMatrices(inverse, mesh2.matrixWorld)));
|
|
8145
8374
|
});
|
|
8146
|
-
bounds.applyMatrix4(item.matrix);
|
|
8147
8375
|
item.position.z = depth - bounds.min.z;
|
|
8148
8376
|
depth += bounds.max.z - bounds.min.z + 0.01;
|
|
8149
|
-
this.bounds.expandByPoint(new
|
|
8150
|
-
this.bounds.expandByPoint(new
|
|
8151
|
-
this.bounds.expandByPoint(new
|
|
8152
|
-
this.bounds.expandByPoint(new
|
|
8377
|
+
this.bounds.expandByPoint(new import_three24.Vector2(x, y));
|
|
8378
|
+
this.bounds.expandByPoint(new import_three24.Vector2(x + width2, y + height2));
|
|
8379
|
+
this.bounds.expandByPoint(new import_three24.Vector2(bounds.min.x, -bounds.max.y));
|
|
8380
|
+
this.bounds.expandByPoint(new import_three24.Vector2(bounds.max.x, -bounds.min.y));
|
|
8153
8381
|
continue;
|
|
8154
8382
|
}
|
|
8155
8383
|
const key = typeof layer.texture === "string" ? AssetKey.parse("textures", layer.texture) : layer.texture;
|
|
@@ -8157,7 +8385,7 @@ var GuiObject = class extends SceneObject {
|
|
|
8157
8385
|
const image = material.map.image;
|
|
8158
8386
|
const [cropX, cropY, cropWidth, cropHeight] = layer.crop ?? [0, 0, image.width, image.height];
|
|
8159
8387
|
const [width, height] = layer.size ?? [cropWidth, cropHeight];
|
|
8160
|
-
const geometry = new
|
|
8388
|
+
const geometry = new import_three24.PlaneGeometry(width, height);
|
|
8161
8389
|
this.geometries.add(geometry);
|
|
8162
8390
|
const uv = geometry.getAttribute("uv");
|
|
8163
8391
|
for (let i = 0; i < uv.count; i++) {
|
|
@@ -8167,13 +8395,13 @@ var GuiObject = class extends SceneObject {
|
|
|
8167
8395
|
1 - (cropY + (1 - uv.getY(i)) * cropHeight) / image.height
|
|
8168
8396
|
);
|
|
8169
8397
|
}
|
|
8170
|
-
const mesh = new
|
|
8398
|
+
const mesh = new import_three24.Mesh(geometry, material);
|
|
8171
8399
|
mesh.name = `mesh:${layer.name ?? index}`;
|
|
8172
8400
|
mesh.position.set(x + width / 2, -y - height / 2, depth);
|
|
8173
8401
|
mesh.renderOrder = index;
|
|
8174
8402
|
this.add(mesh);
|
|
8175
|
-
this.bounds.expandByPoint(new
|
|
8176
|
-
this.bounds.expandByPoint(new
|
|
8403
|
+
this.bounds.expandByPoint(new import_three24.Vector2(x, y));
|
|
8404
|
+
this.bounds.expandByPoint(new import_three24.Vector2(x + width, y + height));
|
|
8177
8405
|
depth += 0.01;
|
|
8178
8406
|
}
|
|
8179
8407
|
for (const child of this.children) child.position.z -= depth - 0.01;
|
|
@@ -8198,7 +8426,7 @@ var GuiObject = class extends SceneObject {
|
|
|
8198
8426
|
this.add(item);
|
|
8199
8427
|
await item.init();
|
|
8200
8428
|
item.iterateAllMeshes((mesh) => {
|
|
8201
|
-
this.geometries.add(mesh.geometry);
|
|
8429
|
+
if (!model.special) this.geometries.add(mesh.geometry);
|
|
8202
8430
|
mesh.name = `mesh:${layer.name ?? index}`;
|
|
8203
8431
|
mesh.renderOrder = index;
|
|
8204
8432
|
for (const material of Array.isArray(mesh.material) ? mesh.material : [mesh.material]) {
|
|
@@ -8248,7 +8476,7 @@ function isGuiObject(obj) {
|
|
|
8248
8476
|
init_image();
|
|
8249
8477
|
|
|
8250
8478
|
// src/inspector/SceneInspector.ts
|
|
8251
|
-
var
|
|
8479
|
+
var import_three25 = require("three");
|
|
8252
8480
|
init_SceneObject();
|
|
8253
8481
|
init_util();
|
|
8254
8482
|
init_log();
|
|
@@ -8258,11 +8486,11 @@ var help = "<span>Ctrl/Cmd+Click to Select<br/></span><br/>";
|
|
|
8258
8486
|
var SceneInspector = class {
|
|
8259
8487
|
constructor(renderer) {
|
|
8260
8488
|
this.renderer = renderer;
|
|
8261
|
-
this.mouse = new
|
|
8489
|
+
this.mouse = new import_three25.Vector2();
|
|
8262
8490
|
this.listeners = new AbortController();
|
|
8263
8491
|
this.objectInfoContainer = document.createElement("div");
|
|
8264
8492
|
this.objectControlsContainer = document.createElement("div");
|
|
8265
|
-
this.raycaster = new
|
|
8493
|
+
this.raycaster = new import_three25.Raycaster();
|
|
8266
8494
|
this.init();
|
|
8267
8495
|
}
|
|
8268
8496
|
init() {
|
|
@@ -8656,29 +8884,15 @@ function isInstanceable(obj) {
|
|
|
8656
8884
|
// src/model/index.ts
|
|
8657
8885
|
init_DisplayPosition();
|
|
8658
8886
|
init_DisplayTransforms();
|
|
8659
|
-
|
|
8660
|
-
|
|
8661
|
-
var ITEM_GENERATED = "item/generated";
|
|
8662
|
-
var BUILTIN_GENERATED = "builtin/generated";
|
|
8663
|
-
var BUILTIN_ENTITY = "builtin/entity";
|
|
8664
|
-
var DEFAULT_ELEMENTS = [];
|
|
8665
|
-
function isDoubleArray(obj) {
|
|
8666
|
-
return Array.isArray(obj) && obj.length === 2;
|
|
8667
|
-
}
|
|
8668
|
-
function isTripleArray(obj) {
|
|
8669
|
-
return Array.isArray(obj) && obj.length === 3;
|
|
8670
|
-
}
|
|
8671
|
-
function isQuadArray(obj) {
|
|
8672
|
-
return Array.isArray(obj) && obj.length === 4;
|
|
8673
|
-
}
|
|
8674
|
-
|
|
8675
|
-
// src/model/index.ts
|
|
8887
|
+
init_GuiLight();
|
|
8888
|
+
init_Model();
|
|
8676
8889
|
init_ModelCulling();
|
|
8677
8890
|
init_ModelGenerator();
|
|
8678
8891
|
init_ModelMerger();
|
|
8892
|
+
init_SpecialItems();
|
|
8679
8893
|
|
|
8680
8894
|
// src/model/block/BlockStateResolver.ts
|
|
8681
|
-
var
|
|
8895
|
+
var import_three27 = require("three");
|
|
8682
8896
|
init_BlockStates();
|
|
8683
8897
|
init_MineRenderError();
|
|
8684
8898
|
init_util();
|
|
@@ -8756,7 +8970,7 @@ var BlockStateResolver = class {
|
|
|
8756
8970
|
return variants[variants.length - 1];
|
|
8757
8971
|
}
|
|
8758
8972
|
static rotation(variant) {
|
|
8759
|
-
const rotation = new
|
|
8973
|
+
const rotation = new import_three27.Euler();
|
|
8760
8974
|
if (typeof variant.x !== "undefined") {
|
|
8761
8975
|
rotation.x = toRadians(clampRotationDegrees(variant.x));
|
|
8762
8976
|
}
|
|
@@ -8863,12 +9077,13 @@ init_SceneObject();
|
|
|
8863
9077
|
init_ModelObject();
|
|
8864
9078
|
init_Models();
|
|
8865
9079
|
var import_ts_deepmerge6 = __toESM(require_dist());
|
|
8866
|
-
var
|
|
9080
|
+
var import_three30 = require("three");
|
|
8867
9081
|
init_MineRenderError();
|
|
8868
9082
|
init_InstanceReference();
|
|
8869
9083
|
init_AssetKey();
|
|
8870
9084
|
init_ModelCulling();
|
|
8871
9085
|
init_FluidGeometry();
|
|
9086
|
+
init_Entities();
|
|
8872
9087
|
var _BlockObject = class _BlockObject extends SceneObject {
|
|
8873
9088
|
constructor(blockState, options) {
|
|
8874
9089
|
super(options);
|
|
@@ -8884,7 +9099,7 @@ var _BlockObject = class _BlockObject extends SceneObject {
|
|
|
8884
9099
|
this._models = [];
|
|
8885
9100
|
this._cullMask = 0;
|
|
8886
9101
|
this._entities = [];
|
|
8887
|
-
this._entityPlacement = new
|
|
9102
|
+
this._entityPlacement = new import_three30.Matrix4();
|
|
8888
9103
|
this._entityGeneration = 0;
|
|
8889
9104
|
this.options = (0, import_ts_deepmerge6.default)({}, _BlockObject.DEFAULT_OPTIONS, options ?? {});
|
|
8890
9105
|
}
|
|
@@ -8964,7 +9179,7 @@ var _BlockObject = class _BlockObject extends SceneObject {
|
|
|
8964
9179
|
return true;
|
|
8965
9180
|
}
|
|
8966
9181
|
placeEntities() {
|
|
8967
|
-
const matrix = new
|
|
9182
|
+
const matrix = new import_three30.Matrix4().makeTranslation(this.position.x - 8, this.position.y - 8, this.position.z - 8).multiply(this._entityPlacement);
|
|
8968
9183
|
for (const entity of this._entities) {
|
|
8969
9184
|
matrix.decompose(entity.position, entity.quaternion, entity.scale);
|
|
8970
9185
|
}
|
|
@@ -8983,12 +9198,12 @@ var _BlockObject = class _BlockObject extends SceneObject {
|
|
|
8983
9198
|
getModelCullMask(model, worldMask) {
|
|
8984
9199
|
const object = isInstanceReference(model) ? model.instanceable : model;
|
|
8985
9200
|
if (object.options.displayPosition) return 0;
|
|
8986
|
-
const position = new
|
|
8987
|
-
const rotation = new
|
|
8988
|
-
const scale = new
|
|
9201
|
+
const position = new import_three30.Vector3();
|
|
9202
|
+
const rotation = new import_three30.Quaternion();
|
|
9203
|
+
const scale = new import_three30.Vector3();
|
|
8989
9204
|
this.getModelMatrix(model).decompose(position, rotation, scale);
|
|
8990
|
-
if (position.distanceToSquared(this.position) > 1e-10 || scale.distanceToSquared(new
|
|
8991
|
-
return ModelCulling.toLocalMask(worldMask, new
|
|
9205
|
+
if (position.distanceToSquared(this.position) > 1e-10 || scale.distanceToSquared(new import_three30.Vector3(1, 1, 1)) > 1e-10) return 0;
|
|
9206
|
+
return ModelCulling.toLocalMask(worldMask, new import_three30.Euler().setFromQuaternion(rotation));
|
|
8992
9207
|
}
|
|
8993
9208
|
async setCullMask(worldMask) {
|
|
8994
9209
|
worldMask &= 63;
|
|
@@ -9050,7 +9265,7 @@ var _BlockObject = class _BlockObject extends SceneObject {
|
|
|
9050
9265
|
() => new FluidModelObject2(kind, surface.sample, this.blockState.key, this.options)
|
|
9051
9266
|
);
|
|
9052
9267
|
const previous = this._fluidModel;
|
|
9053
|
-
const matrix = previous ? this.getModelMatrix(previous) : new
|
|
9268
|
+
const matrix = previous ? this.getModelMatrix(previous) : new import_three30.Matrix4().makeTranslation(...this.position.toArray());
|
|
9054
9269
|
if (isInstanceReference(replacement)) replacement.setMatrix(matrix);
|
|
9055
9270
|
else matrix.decompose(replacement.position, replacement.quaternion, replacement.scale);
|
|
9056
9271
|
this._models = this._models.filter((model) => model !== previous);
|
|
@@ -9188,7 +9403,7 @@ var _BlockObject = class _BlockObject extends SceneObject {
|
|
|
9188
9403
|
setPositionRotationScaleAt(index, position, rotation, scale) {
|
|
9189
9404
|
super.setPositionRotationScaleAt(index, position, rotation, scale);
|
|
9190
9405
|
}
|
|
9191
|
-
getMatrixAt(index, matrix = new
|
|
9406
|
+
getMatrixAt(index, matrix = new import_three30.Matrix4()) {
|
|
9192
9407
|
if (!this.isInstanced) throw new MineRenderError("Object is not instanced");
|
|
9193
9408
|
const child = this._models[0];
|
|
9194
9409
|
if (child && isModelObject(child)) {
|
|
@@ -11059,7 +11274,7 @@ init_ModelObject();
|
|
|
11059
11274
|
init_nbt();
|
|
11060
11275
|
|
|
11061
11276
|
// src/renderer/MineRenderScene.ts
|
|
11062
|
-
var
|
|
11277
|
+
var import_three32 = require("three");
|
|
11063
11278
|
init_SceneObject();
|
|
11064
11279
|
var import_ts_deepmerge8 = __toESM(require_dist());
|
|
11065
11280
|
init_ModelObject();
|
|
@@ -11792,7 +12007,7 @@ var import_ts_deepmerge7 = __toESM(require_dist());
|
|
|
11792
12007
|
init_util();
|
|
11793
12008
|
|
|
11794
12009
|
// src/skin/SkinTextures.ts
|
|
11795
|
-
var
|
|
12010
|
+
var import_three31 = require("three");
|
|
11796
12011
|
init_Caching();
|
|
11797
12012
|
init_CacheKey();
|
|
11798
12013
|
init_MineRenderError();
|
|
@@ -11876,11 +12091,11 @@ var SkinTextures = class {
|
|
|
11876
12091
|
});
|
|
11877
12092
|
}
|
|
11878
12093
|
static createMaterial(pixels, width, height, transparent = true) {
|
|
11879
|
-
const texture = Textures.initTextureProps(new
|
|
11880
|
-
texture.colorSpace =
|
|
12094
|
+
const texture = Textures.initTextureProps(new import_three31.DataTexture(pixels, width, height));
|
|
12095
|
+
texture.colorSpace = import_three31.SRGBColorSpace;
|
|
11881
12096
|
texture.flipY = true;
|
|
11882
12097
|
texture.needsUpdate = true;
|
|
11883
|
-
return new
|
|
12098
|
+
return new import_three31.MeshBasicMaterial({ map: texture, transparent, side: transparent ? import_three31.DoubleSide : import_three31.FrontSide, alphaTest: transparent ? 0.1 : 0 });
|
|
11884
12099
|
}
|
|
11885
12100
|
static isSlim(image, scale) {
|
|
11886
12101
|
for (const [x, y] of [[46, 52], [54, 20]]) {
|
|
@@ -12108,7 +12323,8 @@ var SkinObject = class extends SceneObject {
|
|
|
12108
12323
|
};
|
|
12109
12324
|
|
|
12110
12325
|
// src/renderer/MineRenderScene.ts
|
|
12111
|
-
|
|
12326
|
+
init_EntityObject();
|
|
12327
|
+
var _MineRenderScene = class _MineRenderScene extends import_three32.Scene {
|
|
12112
12328
|
constructor(options) {
|
|
12113
12329
|
super();
|
|
12114
12330
|
this.isMineRenderScene = true;
|
|
@@ -12235,19 +12451,20 @@ function isMineRenderScene(obj) {
|
|
|
12235
12451
|
}
|
|
12236
12452
|
|
|
12237
12453
|
// src/renderer/Renderer.ts
|
|
12238
|
-
var
|
|
12454
|
+
var import_three34 = require("three");
|
|
12239
12455
|
var import_ts_deepmerge9 = __toESM(require_dist());
|
|
12240
12456
|
var import_stats = __toESM(require("stats.js"));
|
|
12241
12457
|
var import_postprocessing = require("postprocessing");
|
|
12242
12458
|
init_util();
|
|
12459
|
+
init_Model();
|
|
12243
12460
|
init_three();
|
|
12244
12461
|
|
|
12245
12462
|
// src/three/OrbitControls.js
|
|
12246
|
-
var
|
|
12463
|
+
var import_three33 = require("three");
|
|
12247
12464
|
var _changeEvent = { type: "change" };
|
|
12248
12465
|
var _startEvent = { type: "start" };
|
|
12249
12466
|
var _endEvent = { type: "end" };
|
|
12250
|
-
var OrbitControls = class extends
|
|
12467
|
+
var OrbitControls = class extends import_three33.EventDispatcher {
|
|
12251
12468
|
constructor(object, domElement) {
|
|
12252
12469
|
super();
|
|
12253
12470
|
if (domElement === void 0) console.warn('THREE.OrbitControls: The second parameter "domElement" is now mandatory.');
|
|
@@ -12256,7 +12473,7 @@ var OrbitControls = class extends import_three32.EventDispatcher {
|
|
|
12256
12473
|
this.domElement = domElement;
|
|
12257
12474
|
this.domElement.style.touchAction = "none";
|
|
12258
12475
|
this.enabled = true;
|
|
12259
|
-
this.target = new
|
|
12476
|
+
this.target = new import_three33.Vector3();
|
|
12260
12477
|
this.minDistance = 0;
|
|
12261
12478
|
this.maxDistance = Infinity;
|
|
12262
12479
|
this.minZoom = 0;
|
|
@@ -12278,8 +12495,8 @@ var OrbitControls = class extends import_three32.EventDispatcher {
|
|
|
12278
12495
|
this.autoRotate = false;
|
|
12279
12496
|
this.autoRotateSpeed = 2;
|
|
12280
12497
|
this.keys = { LEFT: "ArrowLeft", UP: "ArrowUp", RIGHT: "ArrowRight", BOTTOM: "ArrowDown" };
|
|
12281
|
-
this.mouseButtons = { LEFT:
|
|
12282
|
-
this.touches = { ONE:
|
|
12498
|
+
this.mouseButtons = { LEFT: import_three33.MOUSE.ROTATE, MIDDLE: import_three33.MOUSE.DOLLY, RIGHT: import_three33.MOUSE.PAN };
|
|
12499
|
+
this.touches = { ONE: import_three33.TOUCH.ROTATE, TWO: import_three33.TOUCH.DOLLY_PAN };
|
|
12283
12500
|
this.target0 = this.target.clone();
|
|
12284
12501
|
this.position0 = this.object.position.clone();
|
|
12285
12502
|
this.zoom0 = this.object.zoom;
|
|
@@ -12308,11 +12525,11 @@ var OrbitControls = class extends import_three32.EventDispatcher {
|
|
|
12308
12525
|
state = STATE.NONE;
|
|
12309
12526
|
};
|
|
12310
12527
|
this.update = function() {
|
|
12311
|
-
const offset = new
|
|
12312
|
-
const quat = new
|
|
12528
|
+
const offset = new import_three33.Vector3();
|
|
12529
|
+
const quat = new import_three33.Quaternion().setFromUnitVectors(object.up, new import_three33.Vector3(0, 1, 0));
|
|
12313
12530
|
const quatInverse = quat.clone().invert();
|
|
12314
|
-
const lastPosition = new
|
|
12315
|
-
const lastQuaternion = new
|
|
12531
|
+
const lastPosition = new import_three33.Vector3();
|
|
12532
|
+
const lastQuaternion = new import_three33.Quaternion();
|
|
12316
12533
|
const twoPI = 2 * Math.PI;
|
|
12317
12534
|
return function update() {
|
|
12318
12535
|
const position = scope.object.position;
|
|
@@ -12398,20 +12615,20 @@ var OrbitControls = class extends import_three32.EventDispatcher {
|
|
|
12398
12615
|
};
|
|
12399
12616
|
let state = STATE.NONE;
|
|
12400
12617
|
const EPS = 1e-6;
|
|
12401
|
-
const spherical = new
|
|
12402
|
-
const sphericalDelta = new
|
|
12618
|
+
const spherical = new import_three33.Spherical();
|
|
12619
|
+
const sphericalDelta = new import_three33.Spherical();
|
|
12403
12620
|
let scale = 1;
|
|
12404
|
-
const panOffset = new
|
|
12621
|
+
const panOffset = new import_three33.Vector3();
|
|
12405
12622
|
let zoomChanged = false;
|
|
12406
|
-
const rotateStart = new
|
|
12407
|
-
const rotateEnd = new
|
|
12408
|
-
const rotateDelta = new
|
|
12409
|
-
const panStart = new
|
|
12410
|
-
const panEnd = new
|
|
12411
|
-
const panDelta = new
|
|
12412
|
-
const dollyStart = new
|
|
12413
|
-
const dollyEnd = new
|
|
12414
|
-
const dollyDelta = new
|
|
12623
|
+
const rotateStart = new import_three33.Vector2();
|
|
12624
|
+
const rotateEnd = new import_three33.Vector2();
|
|
12625
|
+
const rotateDelta = new import_three33.Vector2();
|
|
12626
|
+
const panStart = new import_three33.Vector2();
|
|
12627
|
+
const panEnd = new import_three33.Vector2();
|
|
12628
|
+
const panDelta = new import_three33.Vector2();
|
|
12629
|
+
const dollyStart = new import_three33.Vector2();
|
|
12630
|
+
const dollyEnd = new import_three33.Vector2();
|
|
12631
|
+
const dollyDelta = new import_three33.Vector2();
|
|
12415
12632
|
const pointers = [];
|
|
12416
12633
|
const pointerPositions = {};
|
|
12417
12634
|
function getAutoRotationAngle() {
|
|
@@ -12427,7 +12644,7 @@ var OrbitControls = class extends import_three32.EventDispatcher {
|
|
|
12427
12644
|
sphericalDelta.phi -= angle;
|
|
12428
12645
|
}
|
|
12429
12646
|
const panLeft = function() {
|
|
12430
|
-
const v = new
|
|
12647
|
+
const v = new import_three33.Vector3();
|
|
12431
12648
|
return function panLeft2(distance, objectMatrix) {
|
|
12432
12649
|
v.setFromMatrixColumn(objectMatrix, 0);
|
|
12433
12650
|
v.multiplyScalar(-distance);
|
|
@@ -12435,7 +12652,7 @@ var OrbitControls = class extends import_three32.EventDispatcher {
|
|
|
12435
12652
|
};
|
|
12436
12653
|
}();
|
|
12437
12654
|
const panUp = function() {
|
|
12438
|
-
const v = new
|
|
12655
|
+
const v = new import_three33.Vector3();
|
|
12439
12656
|
return function panUp2(distance, objectMatrix) {
|
|
12440
12657
|
if (scope.screenSpacePanning === true) {
|
|
12441
12658
|
v.setFromMatrixColumn(objectMatrix, 1);
|
|
@@ -12448,7 +12665,7 @@ var OrbitControls = class extends import_three32.EventDispatcher {
|
|
|
12448
12665
|
};
|
|
12449
12666
|
}();
|
|
12450
12667
|
const pan = function() {
|
|
12451
|
-
const offset = new
|
|
12668
|
+
const offset = new import_three33.Vector3();
|
|
12452
12669
|
return function pan2(deltaX, deltaY) {
|
|
12453
12670
|
const element = scope.domElement;
|
|
12454
12671
|
if (scope.object.isPerspectiveCamera) {
|
|
@@ -12697,12 +12914,12 @@ var OrbitControls = class extends import_three32.EventDispatcher {
|
|
|
12697
12914
|
mouseAction = -1;
|
|
12698
12915
|
}
|
|
12699
12916
|
switch (mouseAction) {
|
|
12700
|
-
case
|
|
12917
|
+
case import_three33.MOUSE.DOLLY:
|
|
12701
12918
|
if (scope.enableZoom === false) return;
|
|
12702
12919
|
handleMouseDownDolly(event);
|
|
12703
12920
|
state = STATE.DOLLY;
|
|
12704
12921
|
break;
|
|
12705
|
-
case
|
|
12922
|
+
case import_three33.MOUSE.ROTATE:
|
|
12706
12923
|
if (event.ctrlKey || event.metaKey || event.shiftKey) {
|
|
12707
12924
|
if (scope.enablePan === false) return;
|
|
12708
12925
|
handleMouseDownPan(event);
|
|
@@ -12713,7 +12930,7 @@ var OrbitControls = class extends import_three32.EventDispatcher {
|
|
|
12713
12930
|
state = STATE.ROTATE;
|
|
12714
12931
|
}
|
|
12715
12932
|
break;
|
|
12716
|
-
case
|
|
12933
|
+
case import_three33.MOUSE.PAN:
|
|
12717
12934
|
if (event.ctrlKey || event.metaKey || event.shiftKey) {
|
|
12718
12935
|
if (scope.enableRotate === false) return;
|
|
12719
12936
|
handleMouseDownRotate(event);
|
|
@@ -12769,12 +12986,12 @@ var OrbitControls = class extends import_three32.EventDispatcher {
|
|
|
12769
12986
|
switch (pointers.length) {
|
|
12770
12987
|
case 1:
|
|
12771
12988
|
switch (scope.touches.ONE) {
|
|
12772
|
-
case
|
|
12989
|
+
case import_three33.TOUCH.ROTATE:
|
|
12773
12990
|
if (scope.enableRotate === false) return;
|
|
12774
12991
|
handleTouchStartRotate();
|
|
12775
12992
|
state = STATE.TOUCH_ROTATE;
|
|
12776
12993
|
break;
|
|
12777
|
-
case
|
|
12994
|
+
case import_three33.TOUCH.PAN:
|
|
12778
12995
|
if (scope.enablePan === false) return;
|
|
12779
12996
|
handleTouchStartPan();
|
|
12780
12997
|
state = STATE.TOUCH_PAN;
|
|
@@ -12785,12 +13002,12 @@ var OrbitControls = class extends import_three32.EventDispatcher {
|
|
|
12785
13002
|
break;
|
|
12786
13003
|
case 2:
|
|
12787
13004
|
switch (scope.touches.TWO) {
|
|
12788
|
-
case
|
|
13005
|
+
case import_three33.TOUCH.DOLLY_PAN:
|
|
12789
13006
|
if (scope.enableZoom === false && scope.enablePan === false) return;
|
|
12790
13007
|
handleTouchStartDollyPan();
|
|
12791
13008
|
state = STATE.TOUCH_DOLLY_PAN;
|
|
12792
13009
|
break;
|
|
12793
|
-
case
|
|
13010
|
+
case import_three33.TOUCH.DOLLY_ROTATE:
|
|
12794
13011
|
if (scope.enableZoom === false && scope.enableRotate === false) return;
|
|
12795
13012
|
handleTouchStartDollyRotate();
|
|
12796
13013
|
state = STATE.TOUCH_DOLLY_ROTATE;
|
|
@@ -12857,7 +13074,7 @@ var OrbitControls = class extends import_three32.EventDispatcher {
|
|
|
12857
13074
|
function trackPointer(event) {
|
|
12858
13075
|
let position = pointerPositions[event.pointerId];
|
|
12859
13076
|
if (position === void 0) {
|
|
12860
|
-
position = new
|
|
13077
|
+
position = new import_three33.Vector2();
|
|
12861
13078
|
pointerPositions[event.pointerId] = position;
|
|
12862
13079
|
}
|
|
12863
13080
|
position.set(event.pageX, event.pageY);
|
|
@@ -12877,10 +13094,10 @@ var MapControls = class extends OrbitControls {
|
|
|
12877
13094
|
constructor(object, domElement) {
|
|
12878
13095
|
super(object, domElement);
|
|
12879
13096
|
this.screenSpacePanning = false;
|
|
12880
|
-
this.mouseButtons.LEFT =
|
|
12881
|
-
this.mouseButtons.RIGHT =
|
|
12882
|
-
this.touches.ONE =
|
|
12883
|
-
this.touches.TWO =
|
|
13097
|
+
this.mouseButtons.LEFT = import_three33.MOUSE.PAN;
|
|
13098
|
+
this.mouseButtons.RIGHT = import_three33.MOUSE.ROTATE;
|
|
13099
|
+
this.touches.ONE = import_three33.TOUCH.PAN;
|
|
13100
|
+
this.touches.TWO = import_three33.TOUCH.DOLLY_ROTATE;
|
|
12884
13101
|
}
|
|
12885
13102
|
};
|
|
12886
13103
|
|
|
@@ -12931,14 +13148,14 @@ var _Renderer = class _Renderer {
|
|
|
12931
13148
|
switch (this.options.camera.type) {
|
|
12932
13149
|
case "perspective":
|
|
12933
13150
|
default:
|
|
12934
|
-
return new
|
|
13151
|
+
return new import_three34.PerspectiveCamera(
|
|
12935
13152
|
this.options.camera.perspective.fov,
|
|
12936
13153
|
this.options.camera.perspective.aspect ?? this.viewWidth / this.viewHeight,
|
|
12937
13154
|
this.options.camera.near,
|
|
12938
13155
|
this.options.camera.far
|
|
12939
13156
|
);
|
|
12940
13157
|
case "orthographic":
|
|
12941
|
-
return new
|
|
13158
|
+
return new import_three34.OrthographicCamera(
|
|
12942
13159
|
this.options.camera.orthographic.left ?? this.viewWidth / -2,
|
|
12943
13160
|
this.options.camera.orthographic.right ?? this.viewWidth / 2,
|
|
12944
13161
|
this.options.camera.orthographic.top ?? this.viewHeight / 2,
|
|
@@ -12949,7 +13166,7 @@ var _Renderer = class _Renderer {
|
|
|
12949
13166
|
}
|
|
12950
13167
|
}
|
|
12951
13168
|
createRenderer() {
|
|
12952
|
-
const renderer = new
|
|
13169
|
+
const renderer = new import_three34.WebGLRenderer({
|
|
12953
13170
|
antialias: this.options.render.antialias,
|
|
12954
13171
|
alpha: true,
|
|
12955
13172
|
powerPreference: "high-performance",
|
|
@@ -12957,8 +13174,8 @@ var _Renderer = class _Renderer {
|
|
|
12957
13174
|
});
|
|
12958
13175
|
renderer.setClearColor(0, 0);
|
|
12959
13176
|
renderer.shadowMap.enabled = true;
|
|
12960
|
-
renderer.shadowMap.type =
|
|
12961
|
-
renderer.outputColorSpace =
|
|
13177
|
+
renderer.shadowMap.type = import_three34.PCFSoftShadowMap;
|
|
13178
|
+
renderer.outputColorSpace = import_three34.SRGBColorSpace;
|
|
12962
13179
|
renderer.setPixelRatio(this.options.render.pixelRatio ?? 1);
|
|
12963
13180
|
renderer.setSize(this.viewWidth, this.viewHeight);
|
|
12964
13181
|
return renderer;
|
|
@@ -12993,20 +13210,20 @@ var _Renderer = class _Renderer {
|
|
|
12993
13210
|
window["__THREE_DEVTOOLS__"].dispatchEvent(new CustomEvent("observe", { detail: this.scene }));
|
|
12994
13211
|
}
|
|
12995
13212
|
if (this.options.debug.grid) {
|
|
12996
|
-
const gridHelper = new
|
|
13213
|
+
const gridHelper = new import_three34.GridHelper(128, 16);
|
|
12997
13214
|
this._debugHelpers.push(gridHelper);
|
|
12998
13215
|
this.scene.add(gridHelper);
|
|
12999
|
-
const gridHelper2 = new
|
|
13216
|
+
const gridHelper2 = new import_three34.GridHelper(128, 16);
|
|
13000
13217
|
this._debugHelpers.push(gridHelper2);
|
|
13001
13218
|
gridHelper2.rotation.x = 90 * (Math.PI / 180);
|
|
13002
13219
|
this.scene.add(gridHelper2);
|
|
13003
|
-
const gridHelper3 = new
|
|
13220
|
+
const gridHelper3 = new import_three34.GridHelper(128, 16);
|
|
13004
13221
|
this._debugHelpers.push(gridHelper3);
|
|
13005
13222
|
gridHelper3.rotation.z = 90 * (Math.PI / 180);
|
|
13006
13223
|
this.scene.add(gridHelper3);
|
|
13007
13224
|
}
|
|
13008
13225
|
if (this.options.debug.axes) {
|
|
13009
|
-
const axesHelper = new
|
|
13226
|
+
const axesHelper = new import_three34.AxesHelper(64);
|
|
13010
13227
|
this._debugHelpers.push(axesHelper);
|
|
13011
13228
|
this.scene.add(axesHelper);
|
|
13012
13229
|
}
|
|
@@ -13265,8 +13482,8 @@ _Renderer.DEFAULT_OPTIONS = (0, import_ts_deepmerge9.default)({}, {
|
|
|
13265
13482
|
top: void 0,
|
|
13266
13483
|
bottom: void 0
|
|
13267
13484
|
},
|
|
13268
|
-
position: new
|
|
13269
|
-
lookingAt: new
|
|
13485
|
+
position: new import_three34.Vector3(50, 50, 50),
|
|
13486
|
+
lookingAt: new import_three34.Vector3(0, 0, 0)
|
|
13270
13487
|
},
|
|
13271
13488
|
render: {
|
|
13272
13489
|
fpsLimit: 60,
|
|
@@ -13730,19 +13947,20 @@ var AnvilParser = class {
|
|
|
13730
13947
|
};
|
|
13731
13948
|
|
|
13732
13949
|
// src/world/Chunk.ts
|
|
13733
|
-
var
|
|
13950
|
+
var import_three39 = require("three");
|
|
13734
13951
|
init_BlockStates();
|
|
13735
13952
|
init_AssetKey();
|
|
13736
13953
|
|
|
13737
13954
|
// src/world/MineRenderWorld.ts
|
|
13738
|
-
var
|
|
13955
|
+
var import_three37 = require("three");
|
|
13956
|
+
init_Model();
|
|
13739
13957
|
init_BatchedExecutor();
|
|
13740
13958
|
init_AssetKey();
|
|
13741
13959
|
init_BlockStates();
|
|
13742
13960
|
init_CubeFace();
|
|
13743
13961
|
|
|
13744
13962
|
// src/world/SectionModels.ts
|
|
13745
|
-
var
|
|
13963
|
+
var import_three36 = require("three");
|
|
13746
13964
|
init_AssetKey();
|
|
13747
13965
|
init_Models();
|
|
13748
13966
|
init_CubeFace();
|
|
@@ -13808,12 +14026,12 @@ var SectionModels = class {
|
|
|
13808
14026
|
});
|
|
13809
14027
|
await object.init();
|
|
13810
14028
|
const geometry = object.children[0].geometry;
|
|
13811
|
-
geometry.applyMatrix4(new
|
|
14029
|
+
geometry.applyMatrix4(new import_three36.Matrix4().makeRotationFromEuler(rotation));
|
|
13812
14030
|
object.clear();
|
|
13813
14031
|
const cullFaces = CUBE_FACES.map((face) => {
|
|
13814
14032
|
const local = CUBE_FACES.findIndex((name) => name === atlas.model.elements[0].faces[face]?.cullface);
|
|
13815
14033
|
if (local < 0) return 0;
|
|
13816
|
-
const normal = new
|
|
14034
|
+
const normal = new import_three36.Vector3(...CUBE_FACE_OFFSETS[local]).applyEuler(rotation);
|
|
13817
14035
|
const world = CUBE_FACE_OFFSETS.findIndex(([x, y, z]) => Math.abs(normal.x - x) < 1e-6 && Math.abs(normal.y - y) < 1e-6 && Math.abs(normal.z - z) < 1e-6);
|
|
13818
14036
|
return 1 << world;
|
|
13819
14037
|
});
|
|
@@ -13843,20 +14061,20 @@ var MineRenderWorld = class {
|
|
|
13843
14061
|
}
|
|
13844
14062
|
getBlockAt(posOrX, y, z) {
|
|
13845
14063
|
if (typeof posOrX == "number") {
|
|
13846
|
-
return this.getBlockAt(new
|
|
14064
|
+
return this.getBlockAt(new import_three37.Vector3(posOrX, y, z));
|
|
13847
14065
|
}
|
|
13848
14066
|
if (isTripleArray(posOrX)) {
|
|
13849
|
-
return this.getBlockAt(new
|
|
14067
|
+
return this.getBlockAt(new import_three37.Vector3(posOrX[0], posOrX[1], posOrX[2]));
|
|
13850
14068
|
}
|
|
13851
14069
|
this.validatePosBounds(posOrX);
|
|
13852
14070
|
return this.getChunkAt(posOrX)?.getBlockAt(posOrX);
|
|
13853
14071
|
}
|
|
13854
14072
|
async setBlockAt(posOrX, yOrBlock, z, block) {
|
|
13855
14073
|
if (typeof posOrX == "number") {
|
|
13856
|
-
return this.setBlockAt(new
|
|
14074
|
+
return this.setBlockAt(new import_three37.Vector3(posOrX, yOrBlock, z), block);
|
|
13857
14075
|
}
|
|
13858
14076
|
if (isTripleArray(posOrX)) {
|
|
13859
|
-
return this.setBlockAt(new
|
|
14077
|
+
return this.setBlockAt(new import_three37.Vector3(posOrX[0], posOrX[1], posOrX[2]), yOrBlock);
|
|
13860
14078
|
}
|
|
13861
14079
|
return this.placeBlock(posOrX, yOrBlock);
|
|
13862
14080
|
}
|
|
@@ -13877,7 +14095,7 @@ var MineRenderWorld = class {
|
|
|
13877
14095
|
const collect = async (positions2) => {
|
|
13878
14096
|
for (const pos of positions2) changes.set(pos.toArray().join(","), pos);
|
|
13879
14097
|
};
|
|
13880
|
-
const place = (block) => this.placeBlock(new
|
|
14098
|
+
const place = (block) => this.placeBlock(new import_three37.Vector3(...block.position), block, collect);
|
|
13881
14099
|
const keys = /* @__PURE__ */ new Map();
|
|
13882
14100
|
for (const block of multiblock.blocks) {
|
|
13883
14101
|
if (Chunk.isAir(block)) continue;
|
|
@@ -13955,13 +14173,13 @@ var MineRenderWorld = class {
|
|
|
13955
14173
|
for (const pos of positions) {
|
|
13956
14174
|
this.pendingCulling.set(pos.toArray().join(","), pos.clone());
|
|
13957
14175
|
for (const offset of CUBE_FACE_OFFSETS) {
|
|
13958
|
-
const neighbor = pos.clone().add(new
|
|
14176
|
+
const neighbor = pos.clone().add(new import_three37.Vector3(...offset));
|
|
13959
14177
|
this.pendingCulling.set(neighbor.toArray().join(","), neighbor);
|
|
13960
14178
|
}
|
|
13961
14179
|
for (let y = -1; y <= 1; y++) {
|
|
13962
14180
|
for (let z = -1; z <= 1; z++) {
|
|
13963
14181
|
for (let x = -1; x <= 1; x++) {
|
|
13964
|
-
const neighbor = pos.clone().add(new
|
|
14182
|
+
const neighbor = pos.clone().add(new import_three37.Vector3(x, y, z));
|
|
13965
14183
|
if (this.getBlockAt(neighbor)?.object?.fluidKind) {
|
|
13966
14184
|
this.pendingCulling.set(neighbor.toArray().join(","), neighbor);
|
|
13967
14185
|
}
|
|
@@ -13983,7 +14201,7 @@ var MineRenderWorld = class {
|
|
|
13983
14201
|
if (!block) continue;
|
|
13984
14202
|
if (block.object?.fluidKind) {
|
|
13985
14203
|
await block.object.updateFluid((x, y, z) => {
|
|
13986
|
-
const neighbor = pos.clone().add(new
|
|
14204
|
+
const neighbor = pos.clone().add(new import_three37.Vector3(x, y, z));
|
|
13987
14205
|
const section = this.getChunkAt(neighbor);
|
|
13988
14206
|
const object = section?.getBlockAt(neighbor)?.object;
|
|
13989
14207
|
return {
|
|
@@ -13995,7 +14213,7 @@ var MineRenderWorld = class {
|
|
|
13995
14213
|
}
|
|
13996
14214
|
let mask = 0;
|
|
13997
14215
|
for (const [face, offset] of CUBE_FACE_OFFSETS.entries()) {
|
|
13998
|
-
const neighbor = pos.clone().add(new
|
|
14216
|
+
const neighbor = pos.clone().add(new import_three37.Vector3(...offset));
|
|
13999
14217
|
if (this.getChunkAt(neighbor)?.isOccludingAt(neighbor)) {
|
|
14000
14218
|
mask |= 1 << face;
|
|
14001
14219
|
}
|
|
@@ -14029,14 +14247,14 @@ var MineRenderWorld = class {
|
|
|
14029
14247
|
return this._chunks.get(this.worldPosToChunkKey(pos));
|
|
14030
14248
|
}
|
|
14031
14249
|
static worldToScenePosition(pos) {
|
|
14032
|
-
return new
|
|
14250
|
+
return new import_three37.Vector3(
|
|
14033
14251
|
pos.x * 16,
|
|
14034
14252
|
pos.y * 16,
|
|
14035
14253
|
pos.z * 16
|
|
14036
14254
|
);
|
|
14037
14255
|
}
|
|
14038
14256
|
static sceneToWorldPosition(pos) {
|
|
14039
|
-
return new
|
|
14257
|
+
return new import_three37.Vector3(
|
|
14040
14258
|
pos.x / 16,
|
|
14041
14259
|
pos.y / 16,
|
|
14042
14260
|
pos.z / 16
|
|
@@ -14055,11 +14273,14 @@ var MineRenderWorld = class {
|
|
|
14055
14273
|
}
|
|
14056
14274
|
};
|
|
14057
14275
|
|
|
14276
|
+
// src/world/Chunk.ts
|
|
14277
|
+
init_Model();
|
|
14278
|
+
|
|
14058
14279
|
// src/world/SectionMesh.ts
|
|
14059
|
-
var
|
|
14280
|
+
var import_three38 = require("three");
|
|
14060
14281
|
init_CanvasCompat();
|
|
14061
14282
|
init_Materials();
|
|
14062
|
-
var SectionMesh = class _SectionMesh extends
|
|
14283
|
+
var SectionMesh = class _SectionMesh extends import_three38.Group {
|
|
14063
14284
|
constructor() {
|
|
14064
14285
|
super(...arguments);
|
|
14065
14286
|
this.ownedMeshes = [];
|
|
@@ -14132,18 +14353,18 @@ var SectionMesh = class _SectionMesh extends import_three37.Group {
|
|
|
14132
14353
|
for (let corner = 0; corner < 6; corner++) indices.push(start + sourceIndices.getX(face * 6 + corner) - face * 4);
|
|
14133
14354
|
}
|
|
14134
14355
|
}
|
|
14135
|
-
const geometry = new
|
|
14136
|
-
geometry.setAttribute("position", new
|
|
14137
|
-
geometry.setAttribute("normal", new
|
|
14138
|
-
geometry.setAttribute("uv", new
|
|
14139
|
-
geometry.setAttribute("color", new
|
|
14356
|
+
const geometry = new import_three38.BufferGeometry();
|
|
14357
|
+
geometry.setAttribute("position", new import_three38.Float32BufferAttribute(positions, 3));
|
|
14358
|
+
geometry.setAttribute("normal", new import_three38.Float32BufferAttribute(normals, 3));
|
|
14359
|
+
geometry.setAttribute("uv", new import_three38.Float32BufferAttribute(uvs, 2));
|
|
14360
|
+
geometry.setAttribute("color", new import_three38.Float32BufferAttribute(colors, 3));
|
|
14140
14361
|
geometry.setIndex(indices);
|
|
14141
14362
|
geometry.computeBoundingBox();
|
|
14142
14363
|
geometry.computeBoundingSphere();
|
|
14143
14364
|
const material = Materials.createShadedCanvasMaterial(canvas, false);
|
|
14144
14365
|
material.vertexColors = true;
|
|
14145
14366
|
const texture = material.uniforms?.map?.value ?? material.map;
|
|
14146
|
-
const mesh = new
|
|
14367
|
+
const mesh = new import_three38.Mesh(geometry, material);
|
|
14147
14368
|
section.add(mesh);
|
|
14148
14369
|
section.ownedMeshes.push({ mesh, texture });
|
|
14149
14370
|
}
|
|
@@ -14177,10 +14398,10 @@ var Chunk = class _Chunk {
|
|
|
14177
14398
|
}
|
|
14178
14399
|
getBlockAt(posOrX, y, z) {
|
|
14179
14400
|
if (typeof posOrX == "number") {
|
|
14180
|
-
return this.getBlockAt(new
|
|
14401
|
+
return this.getBlockAt(new import_three39.Vector3(posOrX, y, z));
|
|
14181
14402
|
}
|
|
14182
14403
|
if (isTripleArray(posOrX)) {
|
|
14183
|
-
return this.getBlockAt(new
|
|
14404
|
+
return this.getBlockAt(new import_three39.Vector3(posOrX[0], posOrX[1], posOrX[2]));
|
|
14184
14405
|
}
|
|
14185
14406
|
const pos = this.worldPosToChunkPos(posOrX);
|
|
14186
14407
|
const index = _Chunk.chunkPosToBlockIndex(pos);
|
|
@@ -14188,10 +14409,10 @@ var Chunk = class _Chunk {
|
|
|
14188
14409
|
}
|
|
14189
14410
|
async setBlockAt(posOrX, yOrBlock, z, block) {
|
|
14190
14411
|
if (typeof posOrX == "number") {
|
|
14191
|
-
return this.setBlockAt(new
|
|
14412
|
+
return this.setBlockAt(new import_three39.Vector3(posOrX, yOrBlock, z), block);
|
|
14192
14413
|
}
|
|
14193
14414
|
if (isTripleArray(posOrX)) {
|
|
14194
|
-
return this.setBlockAt(new
|
|
14415
|
+
return this.setBlockAt(new import_three39.Vector3(posOrX[0], posOrX[1], posOrX[2]), yOrBlock);
|
|
14195
14416
|
}
|
|
14196
14417
|
const worldPos = posOrX;
|
|
14197
14418
|
const pos = this.worldPosToChunkPos(worldPos);
|
|
@@ -14277,7 +14498,7 @@ var Chunk = class _Chunk {
|
|
|
14277
14498
|
}
|
|
14278
14499
|
async clear(onBlocksChanged = this.onBlocksChanged) {
|
|
14279
14500
|
const positions = [...this.renderedBlocks.keys()].map((index) => this.chunkPosToWorldPos(
|
|
14280
|
-
new
|
|
14501
|
+
new import_three39.Vector3(index % 16, Math.floor(index / 256), Math.floor(index / 16) % 16)
|
|
14281
14502
|
));
|
|
14282
14503
|
for (const info of this.renderedBlocks.values()) info.object?.removeFromScene();
|
|
14283
14504
|
this.sectionBlocks.clear();
|
|
@@ -14301,14 +14522,14 @@ var Chunk = class _Chunk {
|
|
|
14301
14522
|
return pos.y * 16 * 16 + pos.z * 16 + pos.x;
|
|
14302
14523
|
}
|
|
14303
14524
|
worldPosToChunkPos(pos) {
|
|
14304
|
-
return new
|
|
14525
|
+
return new import_three39.Vector3(
|
|
14305
14526
|
pos.x - this.x * 16,
|
|
14306
14527
|
pos.y - this.y * 16,
|
|
14307
14528
|
pos.z - this.z * 16
|
|
14308
14529
|
);
|
|
14309
14530
|
}
|
|
14310
14531
|
chunkPosToWorldPos(pos) {
|
|
14311
|
-
return new
|
|
14532
|
+
return new import_three39.Vector3(
|
|
14312
14533
|
this.x * 16 + pos.x,
|
|
14313
14534
|
this.y * 16 + pos.y,
|
|
14314
14535
|
this.z * 16 + pos.z
|