minerender 2.1.0-alpha.23 → 2.1.0-alpha.24

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,7 @@ return ${compiler2.callType("value", tagType)}
66383
66380
  this.listAssetCache,
66384
66381
  this.defaultBlockStatesCache,
66385
66382
  this.blockTintCache,
66386
- this.entityModelsCache
66383
+ this.entityModelCache
66387
66384
  ];
66388
66385
  }
66389
66386
  static clear() {
@@ -66426,7 +66423,7 @@ return ${compiler2.callType("value", tagType)}
66426
66423
  _Caching.listAssetCache = _Caching.createAssetCache();
66427
66424
  _Caching.defaultBlockStatesCache = _Caching.createAssetCache();
66428
66425
  _Caching.blockTintCache = _Caching.createAssetCache();
66429
- _Caching.entityModelsCache = _Caching.createAssetCache();
66426
+ _Caching.entityModelCache = _Caching.createAssetCache();
66430
66427
  var Caching = _Caching;
66431
66428
 
66432
66429
  // src/Geometries.ts
@@ -67605,14 +67602,6 @@ return ${compiler2.callType("value", tagType)}
67605
67602
  }
67606
67603
  geometry.translate(origin.x, origin.y, origin.z);
67607
67604
  }
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
67605
  function applyGenericRotation(axis, rotation, obj) {
67617
67606
  switch (axis) {
67618
67607
  case "x" /* X */:
@@ -78140,18 +78129,18 @@ return ${compiler2.callType("value", tagType)}
78140
78129
  }
78141
78130
  getUvEast(w4, h5, l4) {
78142
78131
  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)]
78132
+ [this.mapW(this.u + l4 + w4 + l4), this.mapH(this.v + l4 + h5)],
78133
+ [this.mapW(this.u + l4 + w4), this.mapH(this.v + l4 + h5)],
78134
+ [this.mapW(this.u + l4 + w4 + l4), this.mapH(this.v + l4)],
78135
+ [this.mapW(this.u + l4 + w4), this.mapH(this.v + l4)]
78147
78136
  ];
78148
78137
  }
78149
78138
  getUvWest(w4, h5, l4) {
78150
78139
  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)]
78140
+ [this.mapW(this.u + l4), this.mapH(this.v + l4 + h5)],
78141
+ [this.mapW(this.u), this.mapH(this.v + l4 + h5)],
78142
+ [this.mapW(this.u + l4), this.mapH(this.v + l4)],
78143
+ [this.mapW(this.u), this.mapH(this.v + l4)]
78155
78144
  ];
78156
78145
  }
78157
78146
  getUvUp(w4, h5, l4) {
@@ -78164,26 +78153,26 @@ return ${compiler2.callType("value", tagType)}
78164
78153
  }
78165
78154
  getUvDown(w4, h5, l4) {
78166
78155
  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
78156
  [this.mapW(this.u + l4), this.mapH(this.v)],
78170
- [this.mapW(this.u + l4 + w4), this.mapH(this.v)]
78157
+ [this.mapW(this.u + l4 + w4), this.mapH(this.v)],
78158
+ [this.mapW(this.u + l4), this.mapH(this.v + l4)],
78159
+ [this.mapW(this.u + l4 + w4), this.mapH(this.v + l4)]
78171
78160
  ];
78172
78161
  }
78173
78162
  getUvSouth(w4, h5, l4) {
78174
78163
  return [
78175
- [this.mapW(this.u + l4 + w4 + l4), this.mapH(this.v + l4 + h5)],
78176
78164
  [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)]
78165
+ [this.mapW(this.u + l4 + w4 + l4), this.mapH(this.v + l4 + h5)],
78166
+ [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)]
78179
78168
  ];
78180
78169
  }
78181
78170
  getUvNorth(w4, h5, l4) {
78182
78171
  return [
78183
- [this.mapW(this.u + l4), this.mapH(this.v + l4 + h5)],
78184
78172
  [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)]
78173
+ [this.mapW(this.u + l4), this.mapH(this.v + l4 + h5)],
78174
+ [this.mapW(this.u + l4 + w4), this.mapH(this.v + l4)],
78175
+ [this.mapW(this.u + l4), this.mapH(this.v + l4)]
78187
78176
  ];
78188
78177
  }
78189
78178
  getFaceUv(face, w4, h5, l4) {
@@ -78202,10 +78191,12 @@ return ${compiler2.callType("value", tagType)}
78202
78191
  return this.getUvNorth(w4, h5, l4);
78203
78192
  }
78204
78193
  }
78205
- toUvArray(w4, h5, l4) {
78194
+ toUvArray(w4, h5, l4, mirror = false) {
78206
78195
  const uv = [];
78207
78196
  for (let i4 = 0; i4 < CUBE_FACES.length; i4++) {
78208
- UVMapper.setFaceUvInArray(uv, i4 * 4, this.getFaceUv(CUBE_FACES[i4], w4, h5, l4));
78197
+ const face = mirror && i4 < 2 ? CUBE_FACES[1 - i4] : CUBE_FACES[i4];
78198
+ const corners = this.getFaceUv(face, w4, h5, l4);
78199
+ UVMapper.setFaceUvInArray(uv, i4 * 4, mirror ? [corners[1], corners[0], corners[3], corners[2]] : corners);
78209
78200
  }
78210
78201
  return uv;
78211
78202
  }
@@ -78266,68 +78257,55 @@ return ${compiler2.callType("value", tagType)}
78266
78257
  init_dirname();
78267
78258
  init_buffer2();
78268
78259
  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
- });
78260
+
78261
+ // src/error/MineRenderError.ts
78262
+ init_dirname();
78263
+ init_buffer2();
78264
+ init_process2();
78265
+ var MineRenderError = class _MineRenderError extends Error {
78266
+ constructor(msg) {
78267
+ super(msg);
78268
+ Object.setPrototypeOf(this, _MineRenderError.prototype);
78283
78269
  }
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);
78270
+ get name() {
78271
+ return "MineRenderError";
78291
78272
  }
78273
+ };
78274
+
78275
+ // src/assets/Entities.ts
78276
+ var Entities = class {
78292
78277
  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()]
78278
+ const collect = async (path) => {
78279
+ const prefix2 = path ? `${path}/` : "";
78280
+ const key = new AssetKey(DEFAULT_NAMESPACE, `${prefix2}_list`, void 0, void 0, "entity-models", ".json");
78281
+ const list = await Caching.listAssetCache.get(key.serialize(), () => AssetLoader.get(key, "list" /* LIST */));
78282
+ if (!list) return [];
78283
+ const files = list.files.filter((file) => file.endsWith(".json") && file !== "_list.json").map((file) => `${prefix2}${file.slice(0, -5)}`);
78284
+ const children = await Promise.all(list.directories.map((directory) => collect(`${prefix2}${directory}`)));
78285
+ return [...files, ...children.flat()];
78311
78286
  };
78287
+ return collect("");
78312
78288
  }
78313
- static async getEntity(modelKey, textureKey) {
78314
- const models = await this.getEntityModels();
78315
- if (!models) {
78316
- return void 0;
78289
+ static async getEntity(modelKey, textureKey, options) {
78290
+ const path = isAssetKey(modelKey) ? modelKey.getFullPath() : modelKey.path;
78291
+ const key = new AssetKey(modelKey.namespace, path, void 0, void 0, "entity-models", ".json");
78292
+ const model = await Caching.entityModelCache.get(key.serialize(), () => AssetLoader.get(key, "json" /* JSON */));
78293
+ if (!model) return void 0;
78294
+ const layerName = options?.layer ?? "main";
78295
+ const layer = model.layers[layerName];
78296
+ if (!layer) {
78297
+ throw new MineRenderError(`Entity ${model.id} has no layer "${layerName}". Available layers: ${Object.keys(model.layers).join(", ")}`);
78317
78298
  }
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
- };
78299
+ return { key: textureKey ?? modelKey, layer, id: model.id };
78300
+ }
78301
+ /** @deprecated Use getEntityList(); block entities share the entity dataset. */
78302
+ static getBlockList() {
78303
+ return this.getEntityList();
78304
+ }
78305
+ /** @deprecated Use getEntity(); block entities share the entity dataset. */
78306
+ static getBlock(modelKey, textureKey, options) {
78307
+ return this.getEntity(modelKey, textureKey, options);
78326
78308
  }
78327
- };
78328
- var EntityModels = class {
78329
- };
78330
- var BlockEntityModels = class {
78331
78309
  };
78332
78310
 
78333
78311
  // src/bedrock/index.ts
@@ -78436,20 +78414,6 @@ return ${compiler2.callType("value", tagType)}
78436
78414
  return obj.isInstanceReference;
78437
78415
  }
78438
78416
 
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
78417
  // src/renderer/SceneObject.ts
78454
78418
  var import_ts_deepmerge3 = __toESM(require_dist());
78455
78419
  var p9 = prefix("SceneObject");
@@ -78575,15 +78539,8 @@ return ${compiler2.callType("value", tagType)}
78575
78539
  return this.toggleObjectVisibility(this.getMeshByName(name2), visible);
78576
78540
  }
78577
78541
  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
- });
78542
+ this.traverse((obj) => {
78543
+ if (isMesh(obj)) cb(obj);
78587
78544
  });
78588
78545
  }
78589
78546
  //</editor-fold>
@@ -78827,13 +78784,13 @@ return ${compiler2.callType("value", tagType)}
78827
78784
 
78828
78785
  // src/entity/scene/EntityObject.ts
78829
78786
  var import_ts_deepmerge4 = __toESM(require_dist());
78830
- var EntityObject = class extends SceneObject {
78787
+ var _EntityObject = class _EntityObject extends SceneObject {
78831
78788
  constructor(entity, options) {
78832
78789
  super();
78833
78790
  this.entity = entity;
78834
78791
  this.isEntityObject = true;
78835
78792
  this.meshesCreated = false;
78836
- this.options = (0, import_ts_deepmerge4.default)({}, SceneObject.DEFAULT_OPTIONS, options ?? {});
78793
+ this.options = (0, import_ts_deepmerge4.default)({}, _EntityObject.DEFAULT_OPTIONS, options ?? {});
78837
78794
  }
78838
78795
  async init() {
78839
78796
  this.createMeshes();
@@ -78843,10 +78800,10 @@ return ${compiler2.callType("value", tagType)}
78843
78800
  super.dispose();
78844
78801
  }
78845
78802
  get textureKey() {
78803
+ const key = this.entity.key;
78846
78804
  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.
78805
+ key.namespace,
78806
+ isAssetKey(key) ? key.getFullPath() : key.path,
78850
78807
  "textures",
78851
78808
  "entity",
78852
78809
  "assets",
@@ -78856,36 +78813,41 @@ return ${compiler2.callType("value", tagType)}
78856
78813
  async loadTextures() {
78857
78814
  this.imageData = await ModelTextures.get(this.textureKey);
78858
78815
  }
78859
- //TODO: abstract this, since extracted model data can be used for entities, blocks, players
78860
78816
  createMeshes(force = false) {
78861
78817
  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
- }
78818
+ const modelRoot = new Object3D();
78819
+ if (this.options.flip) modelRoot.scale.set(-1, -1, 1);
78820
+ this.add(modelRoot);
78821
+ this.createPart("root", this.entity.layer.root, modelRoot, this.entity.layer.texture, Materials.MISSING_TEXTURE);
78887
78822
  this.meshesCreated = true;
78888
78823
  }
78824
+ createPart(name2, part, parent, textureSize, material) {
78825
+ const anchor = this.createGroup(name2);
78826
+ anchor.position.fromArray(part.pose.offset);
78827
+ anchor.rotation.set(...part.pose.rotation, "ZYX");
78828
+ anchor.scale.fromArray(part.pose.scale ?? [1, 1, 1]);
78829
+ parent.add(anchor);
78830
+ const size = part.texture ?? textureSize;
78831
+ for (const cube of part.cubes) {
78832
+ const [width, height, depth] = cube.size;
78833
+ const [growX, growY, growZ] = cube.grow ?? [0, 0, 0];
78834
+ const texture = new MinecraftCubeTexture(...cube.uv, ...size);
78835
+ const uv = size[0] === 0 || size[1] === 0 ? new Array(48).fill(0) : texture.toUvArray(width, height, depth, cube.mirror);
78836
+ const geometry = this._getBoxGeometryForDimensionsAndUv(
78837
+ width + growX * 2,
78838
+ height + growY * 2,
78839
+ depth + growZ * 2,
78840
+ uv
78841
+ ).clone();
78842
+ geometry.translate(cube.origin[0] + width / 2, cube.origin[1] + height / 2, cube.origin[2] + depth / 2);
78843
+ const mesh = this.createMesh(name2, geometry, material);
78844
+ anchor.add(mesh);
78845
+ if (this.options.wireframe) addWireframeToMesh(geometry, mesh);
78846
+ }
78847
+ for (const [childName, child] of Object.entries(part.children)) {
78848
+ this.createPart(childName, child, anchor, size, material);
78849
+ }
78850
+ }
78889
78851
  async applyTextures() {
78890
78852
  const assetKeyStr = this.textureKey.serialize();
78891
78853
  const keyStr = `entity:${assetKeyStr}`;
@@ -78906,7 +78868,8 @@ return ${compiler2.callType("value", tagType)}
78906
78868
  this.notifyDirty();
78907
78869
  }
78908
78870
  };
78909
- EntityObject.DEFAULT_OPTIONS = (0, import_ts_deepmerge4.default)({}, SceneObject.DEFAULT_OPTIONS, {});
78871
+ _EntityObject.DEFAULT_OPTIONS = (0, import_ts_deepmerge4.default)({}, SceneObject.DEFAULT_OPTIONS, { flip: true });
78872
+ var EntityObject = _EntityObject;
78910
78873
  function isEntityObject(obj) {
78911
78874
  return obj.isEntityObject;
78912
78875
  }
@@ -79411,11 +79374,6 @@ return ${compiler2.callType("value", tagType)}
79411
79374
  init_buffer2();
79412
79375
  init_process2();
79413
79376
 
79414
- // src/model/ModelPart.ts
79415
- init_dirname();
79416
- init_buffer2();
79417
- init_process2();
79418
-
79419
79377
  // src/model/block/index.ts
79420
79378
  init_dirname();
79421
79379
  init_buffer2();