minerender 2.1.0-alpha.23 → 2.1.0-alpha.25

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/bundle.js CHANGED
@@ -45353,7 +45353,6 @@ return ${compiler2.callType("value", tagType)}
45353
45353
  BUILTIN_GENERATED: () => BUILTIN_GENERATED,
45354
45354
  BasicAssetKey: () => BasicAssetKey,
45355
45355
  BatchedExecutor: () => BatchedExecutor,
45356
- BlockEntityModels: () => BlockEntityModels,
45357
45356
  BlockObject: () => BlockObject,
45358
45357
  BlockStates: () => BlockStates,
45359
45358
  BlockTints: () => BlockTints,
@@ -45375,7 +45374,6 @@ return ${compiler2.callType("value", tagType)}
45375
45374
  DisplayPosition: () => DisplayPosition,
45376
45375
  DisplayTransforms: () => DisplayTransforms,
45377
45376
  Entities: () => Entities,
45378
- EntityModels: () => EntityModels,
45379
45377
  EntityObject: () => EntityObject,
45380
45378
  Env: () => Env,
45381
45379
  Geometries: () => Geometries,
@@ -45427,7 +45425,6 @@ return ${compiler2.callType("value", tagType)}
45427
45425
  addWireframeToObject: () => addWireframeToObject,
45428
45426
  applyElementRotation: () => applyElementRotation,
45429
45427
  applyGenericRotation: () => applyGenericRotation,
45430
- applyModelPartRotation: () => applyModelPartRotation,
45431
45428
  axisToVec3: () => axisToVec3,
45432
45429
  base64decode: () => base64decode,
45433
45430
  base64encode: () => base64encode,
@@ -66383,7 +66380,8 @@ return ${compiler2.callType("value", tagType)}
66383
66380
  this.listAssetCache,
66384
66381
  this.defaultBlockStatesCache,
66385
66382
  this.blockTintCache,
66386
- this.entityModelsCache
66383
+ this.entityModelCache,
66384
+ this.entityTextureCache
66387
66385
  ];
66388
66386
  }
66389
66387
  static clear() {
@@ -66426,7 +66424,8 @@ return ${compiler2.callType("value", tagType)}
66426
66424
  _Caching.listAssetCache = _Caching.createAssetCache();
66427
66425
  _Caching.defaultBlockStatesCache = _Caching.createAssetCache();
66428
66426
  _Caching.blockTintCache = _Caching.createAssetCache();
66429
- _Caching.entityModelsCache = _Caching.createAssetCache();
66427
+ _Caching.entityModelCache = _Caching.createAssetCache();
66428
+ _Caching.entityTextureCache = _Caching.createAssetCache();
66430
66429
  var Caching = _Caching;
66431
66430
 
66432
66431
  // src/Geometries.ts
@@ -67605,14 +67604,6 @@ return ${compiler2.callType("value", tagType)}
67605
67604
  }
67606
67605
  geometry.translate(origin.x, origin.y, origin.z);
67607
67606
  }
67608
- function applyModelPartRotation(modelPart, geometry) {
67609
- const origin = new Vector3(modelPart.pivotX, modelPart.pivotY, modelPart.pivotZ);
67610
- geometry.translate(-origin.x, -origin.y, -origin.z);
67611
- geometry.rotateX(toRadians(modelPart.pitch));
67612
- geometry.rotateY(toRadians(modelPart.yaw));
67613
- geometry.rotateZ(toRadians(modelPart.roll));
67614
- geometry.translate(origin.x, origin.y, origin.z);
67615
- }
67616
67607
  function applyGenericRotation(axis, rotation, obj) {
67617
67608
  switch (axis) {
67618
67609
  case "x" /* X */:
@@ -78140,18 +78131,18 @@ return ${compiler2.callType("value", tagType)}
78140
78131
  }
78141
78132
  getUvEast(w4, h5, l4) {
78142
78133
  return [
78143
- [this.mapW(this.u), this.mapH(this.v + l4 + h5)],
78144
- [this.mapW(this.u + l4), this.mapH(this.v + l4 + h5)],
78145
- [this.mapW(this.u), this.mapH(this.v + l4)],
78146
- [this.mapW(this.u + l4), this.mapH(this.v + l4)]
78134
+ [this.mapW(this.u + l4 + w4 + l4), this.mapH(this.v + l4 + h5)],
78135
+ [this.mapW(this.u + l4 + w4), this.mapH(this.v + l4 + h5)],
78136
+ [this.mapW(this.u + l4 + w4 + l4), this.mapH(this.v + l4)],
78137
+ [this.mapW(this.u + l4 + w4), this.mapH(this.v + l4)]
78147
78138
  ];
78148
78139
  }
78149
78140
  getUvWest(w4, h5, l4) {
78150
78141
  return [
78151
- [this.mapW(this.u + l4 + w4), this.mapH(this.v + l4 + h5)],
78152
- [this.mapW(this.u + l4 + w4 + l4), this.mapH(this.v + l4 + h5)],
78153
- [this.mapW(this.u + l4 + w4), this.mapH(this.v + l4)],
78154
- [this.mapW(this.u + l4 + w4 + l4), this.mapH(this.v + l4)]
78142
+ [this.mapW(this.u + l4), this.mapH(this.v + l4 + h5)],
78143
+ [this.mapW(this.u), this.mapH(this.v + l4 + h5)],
78144
+ [this.mapW(this.u + l4), this.mapH(this.v + l4)],
78145
+ [this.mapW(this.u), this.mapH(this.v + l4)]
78155
78146
  ];
78156
78147
  }
78157
78148
  getUvUp(w4, h5, l4) {
@@ -78164,26 +78155,26 @@ return ${compiler2.callType("value", tagType)}
78164
78155
  }
78165
78156
  getUvDown(w4, h5, l4) {
78166
78157
  return [
78167
- [this.mapW(this.u + l4), this.mapH(this.v + l4)],
78168
- [this.mapW(this.u + l4 + w4), this.mapH(this.v + l4)],
78169
78158
  [this.mapW(this.u + l4), this.mapH(this.v)],
78170
- [this.mapW(this.u + l4 + w4), this.mapH(this.v)]
78159
+ [this.mapW(this.u + l4 + w4), this.mapH(this.v)],
78160
+ [this.mapW(this.u + l4), this.mapH(this.v + l4)],
78161
+ [this.mapW(this.u + l4 + w4), this.mapH(this.v + l4)]
78171
78162
  ];
78172
78163
  }
78173
78164
  getUvSouth(w4, h5, l4) {
78174
78165
  return [
78175
- [this.mapW(this.u + l4 + w4 + l4), this.mapH(this.v + l4 + h5)],
78176
78166
  [this.mapW(this.u + l4 + w4 + l4 + w4), this.mapH(this.v + l4 + h5)],
78177
- [this.mapW(this.u + l4 + w4 + l4), this.mapH(this.v + l4)],
78178
- [this.mapW(this.u + l4 + w4 + l4 + w4), this.mapH(this.v + l4)]
78167
+ [this.mapW(this.u + l4 + w4 + l4), this.mapH(this.v + l4 + h5)],
78168
+ [this.mapW(this.u + l4 + w4 + l4 + w4), this.mapH(this.v + l4)],
78169
+ [this.mapW(this.u + l4 + w4 + l4), this.mapH(this.v + l4)]
78179
78170
  ];
78180
78171
  }
78181
78172
  getUvNorth(w4, h5, l4) {
78182
78173
  return [
78183
- [this.mapW(this.u + l4), this.mapH(this.v + l4 + h5)],
78184
78174
  [this.mapW(this.u + l4 + w4), this.mapH(this.v + l4 + h5)],
78185
- [this.mapW(this.u + l4), this.mapH(this.v + l4)],
78186
- [this.mapW(this.u + l4 + w4), this.mapH(this.v + l4)]
78175
+ [this.mapW(this.u + l4), this.mapH(this.v + l4 + h5)],
78176
+ [this.mapW(this.u + l4 + w4), this.mapH(this.v + l4)],
78177
+ [this.mapW(this.u + l4), this.mapH(this.v + l4)]
78187
78178
  ];
78188
78179
  }
78189
78180
  getFaceUv(face, w4, h5, l4) {
@@ -78202,10 +78193,12 @@ return ${compiler2.callType("value", tagType)}
78202
78193
  return this.getUvNorth(w4, h5, l4);
78203
78194
  }
78204
78195
  }
78205
- toUvArray(w4, h5, l4) {
78196
+ toUvArray(w4, h5, l4, mirror = false) {
78206
78197
  const uv = [];
78207
78198
  for (let i4 = 0; i4 < CUBE_FACES.length; i4++) {
78208
- UVMapper.setFaceUvInArray(uv, i4 * 4, this.getFaceUv(CUBE_FACES[i4], w4, h5, l4));
78199
+ const face = mirror && i4 < 2 ? CUBE_FACES[1 - i4] : CUBE_FACES[i4];
78200
+ const corners = this.getFaceUv(face, w4, h5, l4);
78201
+ UVMapper.setFaceUvInArray(uv, i4 * 4, mirror ? [corners[1], corners[0], corners[3], corners[2]] : corners);
78209
78202
  }
78210
78203
  return uv;
78211
78204
  }
@@ -78266,68 +78259,83 @@ return ${compiler2.callType("value", tagType)}
78266
78259
  init_dirname();
78267
78260
  init_buffer2();
78268
78261
  init_process2();
78269
- var Entities = class {
78270
- static async getBlockEntityModels() {
78271
- const key = AssetKey.parse("models", "minerender:blockEntityModels");
78272
- console.log(key);
78273
- return Caching.entityModelsCache.get(key.serialize(), () => {
78274
- return AssetLoader.get(key, "json" /* JSON */);
78275
- });
78276
- }
78277
- static async getEntityModels() {
78278
- const key = AssetKey.parse("models", "minerender:entityModels");
78279
- console.log(key);
78280
- return Caching.entityModelsCache.get(key.serialize(), () => {
78281
- return AssetLoader.get(key, "json" /* JSON */);
78282
- });
78262
+
78263
+ // src/error/MineRenderError.ts
78264
+ init_dirname();
78265
+ init_buffer2();
78266
+ init_process2();
78267
+ var MineRenderError = class _MineRenderError extends Error {
78268
+ constructor(msg) {
78269
+ super(msg);
78270
+ Object.setPrototypeOf(this, _MineRenderError.prototype);
78283
78271
  }
78284
- // BlockEntity names are hardcoded
78285
- static async getBlockList() {
78286
- const models = await this.getBlockEntityModels();
78287
- if (!models) {
78288
- return [];
78289
- }
78290
- return Object.keys(models);
78272
+ get name() {
78273
+ return "MineRenderError";
78291
78274
  }
78275
+ };
78276
+
78277
+ // src/assets/Entities.ts
78278
+ var Entities = class {
78292
78279
  static async getEntityList() {
78293
- const models = await this.getEntityModels();
78294
- if (!models) {
78295
- return [];
78296
- }
78297
- return Object.keys(models);
78298
- }
78299
- static async getBlock(modelKey, textureKey) {
78300
- const models = await this.getBlockEntityModels();
78301
- if (!models) {
78302
- return void 0;
78303
- }
78304
- if (!textureKey) {
78305
- textureKey = modelKey;
78306
- }
78307
- const baseKey = modelKey.path.includes("/") ? new BasicAssetKey(modelKey.namespace, modelKey.path.split("/")[0]) : modelKey;
78308
- return {
78309
- key: textureKey,
78310
- parts: models[baseKey.toNamespacedString()]
78280
+ const collect = async (path) => {
78281
+ const prefix2 = path ? `${path}/` : "";
78282
+ const key = new AssetKey(DEFAULT_NAMESPACE, `${prefix2}_list`, void 0, void 0, "entity-models", ".json");
78283
+ const list = await Caching.listAssetCache.get(key.serialize(), () => AssetLoader.get(key, "list" /* LIST */));
78284
+ if (!list) return [];
78285
+ const files = list.files.filter((file) => file.endsWith(".json") && file !== "_list.json").map((file) => `${prefix2}${file.slice(0, -5)}`);
78286
+ const children = await Promise.all(list.directories.map((directory) => collect(`${prefix2}${directory}`)));
78287
+ return [...files, ...children.flat()];
78311
78288
  };
78289
+ return collect("");
78290
+ }
78291
+ static async getEntity(modelKey, textureKey, options) {
78292
+ const path = isAssetKey(modelKey) ? modelKey.getFullPath() : modelKey.path;
78293
+ const key = new AssetKey(modelKey.namespace, path, void 0, void 0, "entity-models", ".json");
78294
+ const model = await Caching.entityModelCache.get(key.serialize(), () => AssetLoader.get(key, "json" /* JSON */));
78295
+ if (!model) return void 0;
78296
+ const layerName = options?.layer ?? "main";
78297
+ const layer = model.layers[layerName];
78298
+ if (!layer) {
78299
+ throw new MineRenderError(`Entity ${model.id} has no layer "${layerName}". Available layers: ${Object.keys(model.layers).join(", ")}`);
78300
+ }
78301
+ let texture;
78302
+ if (textureKey) {
78303
+ const path2 = isAssetKey(textureKey) ? textureKey.getFullPath() : textureKey.path;
78304
+ texture = isAssetKey(textureKey) && textureKey.assetType === "textures" && path2.startsWith("entity/") ? textureKey : new AssetKey(textureKey.namespace, path2, "textures", "entity", "assets", ".png", isAssetKey(textureKey) ? textureKey.root : void 0);
78305
+ } else {
78306
+ texture = await this.resolveTexture(modelKey);
78307
+ }
78308
+ return { key: textureKey ?? modelKey, texture, layer, id: model.id };
78309
+ }
78310
+ static async resolveTexture(modelKey) {
78311
+ const path = isAssetKey(modelKey) ? modelKey.getFullPath() : modelKey.path;
78312
+ const key = new AssetKey(modelKey.namespace, path, void 0, void 0, "entity-models", ".json");
78313
+ return Caching.entityTextureCache.get(key.serialize(), async () => {
78314
+ const name2 = path.split("/").pop();
78315
+ for (const candidate of [path, `${path}/${name2}`]) {
78316
+ const texture = new AssetKey(modelKey.namespace, candidate, "textures", "entity", "assets", ".png");
78317
+ if (await ModelTextures.get(texture)) return texture;
78318
+ }
78319
+ const listKey = new AssetKey(modelKey.namespace, "_list", `${name2}_variant`, void 0, "data", ".json");
78320
+ const list = await AssetLoader.get(listKey, "list" /* LIST */);
78321
+ const files = list?.files.filter((file2) => file2.endsWith(".json") && file2 !== "_list.json");
78322
+ const file = files?.find((file2) => file2 === "temperate.json") ?? files?.[0];
78323
+ if (!file) return void 0;
78324
+ const variantKey = new AssetKey(modelKey.namespace, file.slice(0, -5), `${name2}_variant`, void 0, "data", ".json");
78325
+ const variant = await AssetLoader.get(variantKey, "json" /* JSON */);
78326
+ const assets = variant?.assets;
78327
+ const textureId = variant?.asset_id ?? (typeof assets?.wild === "string" ? assets.wild : Object.values(assets ?? {}).find((value) => typeof value === "string"));
78328
+ return typeof textureId === "string" ? AssetKey.parse("textures", textureId) : void 0;
78329
+ });
78312
78330
  }
78313
- static async getEntity(modelKey, textureKey) {
78314
- const models = await this.getEntityModels();
78315
- if (!models) {
78316
- return void 0;
78317
- }
78318
- if (!textureKey) {
78319
- textureKey = modelKey;
78320
- }
78321
- const baseKey = modelKey.path.includes("/") ? new BasicAssetKey(modelKey.namespace, modelKey.path.split("/")[0]) : modelKey;
78322
- return {
78323
- key: textureKey,
78324
- parts: models[baseKey.toNamespacedString()]
78325
- };
78331
+ /** @deprecated Use getEntityList(); block entities share the entity dataset. */
78332
+ static getBlockList() {
78333
+ return this.getEntityList();
78334
+ }
78335
+ /** @deprecated Use getEntity(); block entities share the entity dataset. */
78336
+ static getBlock(modelKey, textureKey, options) {
78337
+ return this.getEntity(modelKey, textureKey, options);
78326
78338
  }
78327
- };
78328
- var EntityModels = class {
78329
- };
78330
- var BlockEntityModels = class {
78331
78339
  };
78332
78340
 
78333
78341
  // src/bedrock/index.ts
@@ -78436,20 +78444,6 @@ return ${compiler2.callType("value", tagType)}
78436
78444
  return obj.isInstanceReference;
78437
78445
  }
78438
78446
 
78439
- // src/error/MineRenderError.ts
78440
- init_dirname();
78441
- init_buffer2();
78442
- init_process2();
78443
- var MineRenderError = class _MineRenderError extends Error {
78444
- constructor(msg) {
78445
- super(msg);
78446
- Object.setPrototypeOf(this, _MineRenderError.prototype);
78447
- }
78448
- get name() {
78449
- return "MineRenderError";
78450
- }
78451
- };
78452
-
78453
78447
  // src/renderer/SceneObject.ts
78454
78448
  var import_ts_deepmerge3 = __toESM(require_dist());
78455
78449
  var p9 = prefix("SceneObject");
@@ -78575,15 +78569,8 @@ return ${compiler2.callType("value", tagType)}
78575
78569
  return this.toggleObjectVisibility(this.getMeshByName(name2), visible);
78576
78570
  }
78577
78571
  iterateAllMeshes(cb) {
78578
- this.children.forEach((obj) => {
78579
- if (obj.isMesh) {
78580
- cb(obj);
78581
- }
78582
- obj.children.forEach((obj1) => {
78583
- if (obj1.isMesh) {
78584
- cb(obj1);
78585
- }
78586
- });
78572
+ this.traverse((obj) => {
78573
+ if (isMesh(obj)) cb(obj);
78587
78574
  });
78588
78575
  }
78589
78576
  //</editor-fold>
@@ -78827,13 +78814,13 @@ return ${compiler2.callType("value", tagType)}
78827
78814
 
78828
78815
  // src/entity/scene/EntityObject.ts
78829
78816
  var import_ts_deepmerge4 = __toESM(require_dist());
78830
- var EntityObject = class extends SceneObject {
78817
+ var _EntityObject = class _EntityObject extends SceneObject {
78831
78818
  constructor(entity, options) {
78832
78819
  super();
78833
78820
  this.entity = entity;
78834
78821
  this.isEntityObject = true;
78835
78822
  this.meshesCreated = false;
78836
- this.options = (0, import_ts_deepmerge4.default)({}, SceneObject.DEFAULT_OPTIONS, options ?? {});
78823
+ this.options = (0, import_ts_deepmerge4.default)({}, _EntityObject.DEFAULT_OPTIONS, options ?? {});
78837
78824
  }
78838
78825
  async init() {
78839
78826
  this.createMeshes();
@@ -78843,10 +78830,11 @@ return ${compiler2.callType("value", tagType)}
78843
78830
  super.dispose();
78844
78831
  }
78845
78832
  get textureKey() {
78833
+ if (this.entity.texture) return this.entity.texture;
78834
+ const key = this.entity.key;
78846
78835
  return new AssetKey(
78847
- this.entity.key?.namespace ?? DEFAULT_NAMESPACE,
78848
- this.entity.key.path,
78849
- //TODO: texture may differ from entity name; most of them are in subdirectories for multiple variants etc.
78836
+ key.namespace,
78837
+ isAssetKey(key) ? key.getFullPath() : key.path,
78850
78838
  "textures",
78851
78839
  "entity",
78852
78840
  "assets",
@@ -78856,36 +78844,41 @@ return ${compiler2.callType("value", tagType)}
78856
78844
  async loadTextures() {
78857
78845
  this.imageData = await ModelTextures.get(this.textureKey);
78858
78846
  }
78859
- //TODO: abstract this, since extracted model data can be used for entities, blocks, players
78860
78847
  createMeshes(force = false) {
78861
78848
  if (this.meshesCreated && !force) return;
78862
- const mat = Materials.MISSING_TEXTURE;
78863
- for (let partName in this.entity.parts) {
78864
- const part = this.entity.parts[partName];
78865
- const texture = new MinecraftCubeTexture(part.textureOffsetU, part.textureOffsetV, part.textureWidth, part.textureHeight);
78866
- const partAnchor = new Object3D();
78867
- partAnchor.position.x = part.pivotX;
78868
- partAnchor.position.y = part.pivotY;
78869
- partAnchor.position.z = part.pivotZ;
78870
- for (let cube of part.cubes) {
78871
- const w4 = cube.maxX - cube.minX;
78872
- const h5 = cube.maxY - cube.minY;
78873
- const l4 = cube.maxZ - cube.minZ;
78874
- const uv = texture.toUvArray(w4, h5, l4);
78875
- const cubeGeo = this._getBoxGeometryForDimensionsAndUv(w4, h5, l4, uv).clone();
78876
- cubeGeo.applyMatrix4(new Matrix4().makeTranslation(w4 / 2, h5 / 2, l4 / 2));
78877
- cubeGeo.applyMatrix4(new Matrix4().makeTranslation(cube.minX, cube.minY, cube.minZ));
78878
- applyModelPartRotation(part, cubeGeo);
78879
- const mesh = this.createMesh(partName, cubeGeo, mat);
78880
- partAnchor.add(mesh);
78881
- if (this.options.wireframe) {
78882
- addWireframeToMesh(cubeGeo, mesh);
78883
- }
78884
- }
78885
- this.add(partAnchor);
78886
- }
78849
+ const modelRoot = new Object3D();
78850
+ if (this.options.flip) modelRoot.scale.set(-1, -1, 1);
78851
+ this.add(modelRoot);
78852
+ this.createPart("root", this.entity.layer.root, modelRoot, this.entity.layer.texture, Materials.MISSING_TEXTURE);
78887
78853
  this.meshesCreated = true;
78888
78854
  }
78855
+ createPart(name2, part, parent, textureSize, material) {
78856
+ const anchor = this.createGroup(name2);
78857
+ anchor.position.fromArray(part.pose.offset);
78858
+ anchor.rotation.set(...part.pose.rotation, "ZYX");
78859
+ anchor.scale.fromArray(part.pose.scale ?? [1, 1, 1]);
78860
+ parent.add(anchor);
78861
+ const size = part.texture ?? textureSize;
78862
+ for (const cube of part.cubes) {
78863
+ const [width, height, depth] = cube.size;
78864
+ const [growX, growY, growZ] = cube.grow ?? [0, 0, 0];
78865
+ const texture = new MinecraftCubeTexture(...cube.uv, ...size);
78866
+ const uv = size[0] === 0 || size[1] === 0 ? new Array(48).fill(0) : texture.toUvArray(width, height, depth, cube.mirror);
78867
+ const geometry = this._getBoxGeometryForDimensionsAndUv(
78868
+ width + growX * 2,
78869
+ height + growY * 2,
78870
+ depth + growZ * 2,
78871
+ uv
78872
+ ).clone();
78873
+ geometry.translate(cube.origin[0] + width / 2, cube.origin[1] + height / 2, cube.origin[2] + depth / 2);
78874
+ const mesh = this.createMesh(name2, geometry, material);
78875
+ anchor.add(mesh);
78876
+ if (this.options.wireframe) addWireframeToMesh(geometry, mesh);
78877
+ }
78878
+ for (const [childName, child] of Object.entries(part.children)) {
78879
+ this.createPart(childName, child, anchor, size, material);
78880
+ }
78881
+ }
78889
78882
  async applyTextures() {
78890
78883
  const assetKeyStr = this.textureKey.serialize();
78891
78884
  const keyStr = `entity:${assetKeyStr}`;
@@ -78906,7 +78899,8 @@ return ${compiler2.callType("value", tagType)}
78906
78899
  this.notifyDirty();
78907
78900
  }
78908
78901
  };
78909
- EntityObject.DEFAULT_OPTIONS = (0, import_ts_deepmerge4.default)({}, SceneObject.DEFAULT_OPTIONS, {});
78902
+ _EntityObject.DEFAULT_OPTIONS = (0, import_ts_deepmerge4.default)({}, SceneObject.DEFAULT_OPTIONS, { flip: true });
78903
+ var EntityObject = _EntityObject;
78910
78904
  function isEntityObject(obj) {
78911
78905
  return obj.isEntityObject;
78912
78906
  }
@@ -79411,11 +79405,6 @@ return ${compiler2.callType("value", tagType)}
79411
79405
  init_buffer2();
79412
79406
  init_process2();
79413
79407
 
79414
- // src/model/ModelPart.ts
79415
- init_dirname();
79416
- init_buffer2();
79417
- init_process2();
79418
-
79419
79408
  // src/model/block/index.ts
79420
79409
  init_dirname();
79421
79410
  init_buffer2();