minerender 2.1.0-alpha.32 → 2.1.0-alpha.34
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 +32 -7
- package/dist/browser/index.d.ts +32 -7
- package/dist/browser/index.js +287 -216
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/index.mjs +183 -112
- package/dist/browser/index.mjs.map +1 -1
- package/dist/bundle.js +181 -110
- package/dist/bundle.js.map +1 -1
- package/dist/node/index.d.mts +32 -7
- package/dist/node/index.d.ts +32 -7
- package/dist/node/index.js +287 -216
- package/dist/node/index.js.map +1 -1
- package/dist/node/index.mjs +183 -112
- package/dist/node/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/browser/index.mjs
CHANGED
|
@@ -2721,26 +2721,40 @@ var Entities = class {
|
|
|
2721
2721
|
};
|
|
2722
2722
|
return collect("");
|
|
2723
2723
|
}
|
|
2724
|
-
static async
|
|
2724
|
+
static async getModelFile(modelKey) {
|
|
2725
2725
|
const path = isAssetKey(modelKey) ? modelKey.getFullPath() : modelKey.path;
|
|
2726
2726
|
const key = new AssetKey(modelKey.namespace, path, void 0, void 0, "entity-models", ".json");
|
|
2727
|
-
|
|
2727
|
+
return Caching.entityModelCache.get(key.serialize(), () => AssetLoader.get(key, "json" /* JSON */));
|
|
2728
|
+
}
|
|
2729
|
+
static async getLayerList(modelKey) {
|
|
2730
|
+
return Object.keys((await this.getModelFile(modelKey))?.layers ?? {});
|
|
2731
|
+
}
|
|
2732
|
+
static async getEntity(modelKey, textureKey, options) {
|
|
2733
|
+
const model = await this.getModelFile(modelKey);
|
|
2728
2734
|
if (!model) return void 0;
|
|
2729
|
-
const
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2735
|
+
const names = [...new Set(options?.layers ?? [options?.layer ?? "main"])];
|
|
2736
|
+
if (names.length === 0) throw new MineRenderError(`Entity ${model.id} requires at least one layer`);
|
|
2737
|
+
const selected = names.map((name) => {
|
|
2738
|
+
const layer = model.layers[name];
|
|
2739
|
+
if (!layer) {
|
|
2740
|
+
throw new MineRenderError(`Entity ${model.id} has no layer "${name}". Available layers: ${Object.keys(model.layers).join(", ")}`);
|
|
2741
|
+
}
|
|
2742
|
+
return { name, layer };
|
|
2743
|
+
});
|
|
2744
|
+
const layers = Object.fromEntries(await Promise.all(selected.map(async ({ name, layer }, index) => {
|
|
2745
|
+
const override = options?.textures?.[name] ?? (index === 0 ? textureKey : void 0);
|
|
2746
|
+
let texture;
|
|
2747
|
+
if (override) {
|
|
2748
|
+
const path = isAssetKey(override) ? override.getFullPath() : override.path;
|
|
2749
|
+
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);
|
|
2750
|
+
} else if (layer.textureLocation !== void 0) {
|
|
2751
|
+
texture = AssetKey.parse("textures", layer.textureLocation.replace(/^([^:]+:)?textures\//, "$1"));
|
|
2752
|
+
} else {
|
|
2753
|
+
texture = await this.resolveTexture(modelKey);
|
|
2754
|
+
}
|
|
2755
|
+
return [name, { key: override ?? modelKey, texture, layer }];
|
|
2756
|
+
})));
|
|
2757
|
+
return { ...layers[names[0]], id: model.id, layers };
|
|
2744
2758
|
}
|
|
2745
2759
|
static async resolveTexture(modelKey) {
|
|
2746
2760
|
const path = isAssetKey(modelKey) ? modelKey.getFullPath() : modelKey.path;
|
|
@@ -2774,7 +2788,7 @@ var Entities = class {
|
|
|
2774
2788
|
};
|
|
2775
2789
|
|
|
2776
2790
|
// src/renderer/SceneObject.ts
|
|
2777
|
-
import { Euler as Euler3, InstancedMesh, MathUtils, Matrix4 as Matrix43, Mesh as Mesh3, Object3D as Object3D2, Quaternion as Quaternion3, Vector3 as Vector35 } from "three";
|
|
2791
|
+
import { Color as Color2, Euler as Euler3, InstancedBufferAttribute, InstancedMesh, MathUtils, Matrix4 as Matrix43, Mesh as Mesh3, Object3D as Object3D2, Quaternion as Quaternion3, Vector3 as Vector35 } from "three";
|
|
2778
2792
|
|
|
2779
2793
|
// src/instance/InstanceReference.ts
|
|
2780
2794
|
var InstanceReference = class {
|
|
@@ -2786,32 +2800,42 @@ var InstanceReference = class {
|
|
|
2786
2800
|
nextInstance() {
|
|
2787
2801
|
return this.instanceable.nextInstance();
|
|
2788
2802
|
}
|
|
2803
|
+
get activeInstanceable() {
|
|
2804
|
+
if (!this.instanceable.isInstanceActive(this.index, this)) throw new MineRenderError("Instance has been removed");
|
|
2805
|
+
return this.instanceable;
|
|
2806
|
+
}
|
|
2807
|
+
removeFromScene() {
|
|
2808
|
+
if (this.instanceable.isInstanceActive(this.index, this)) this.instanceable.removeInstanceAt(this.index);
|
|
2809
|
+
}
|
|
2810
|
+
dispose() {
|
|
2811
|
+
this.removeFromScene();
|
|
2812
|
+
}
|
|
2789
2813
|
getMatrix(matrix) {
|
|
2790
|
-
return this.
|
|
2814
|
+
return this.activeInstanceable.getMatrixAt(this.index, matrix);
|
|
2791
2815
|
}
|
|
2792
2816
|
setMatrix(matrix) {
|
|
2793
|
-
this.
|
|
2817
|
+
this.activeInstanceable.setMatrixAt(this.index, matrix);
|
|
2794
2818
|
}
|
|
2795
2819
|
setPositionRotationScale(position, rotation, scale) {
|
|
2796
|
-
this.
|
|
2820
|
+
this.activeInstanceable.setPositionRotationScaleAt(this.index, position, rotation, scale);
|
|
2797
2821
|
}
|
|
2798
2822
|
setPosition(position) {
|
|
2799
|
-
this.
|
|
2823
|
+
this.activeInstanceable.setPositionAt(this.index, position);
|
|
2800
2824
|
}
|
|
2801
2825
|
getPosition() {
|
|
2802
|
-
return this.
|
|
2826
|
+
return this.activeInstanceable.getPositionAt(this.index);
|
|
2803
2827
|
}
|
|
2804
2828
|
setRotation(rotation) {
|
|
2805
|
-
this.
|
|
2829
|
+
this.activeInstanceable.setRotationAt(this.index, rotation);
|
|
2806
2830
|
}
|
|
2807
2831
|
getRotation() {
|
|
2808
|
-
return this.
|
|
2832
|
+
return this.activeInstanceable.getRotationAt(this.index);
|
|
2809
2833
|
}
|
|
2810
2834
|
setScale(scale) {
|
|
2811
|
-
this.
|
|
2835
|
+
this.activeInstanceable.setScaleAt(this.index, scale);
|
|
2812
2836
|
}
|
|
2813
2837
|
getScale() {
|
|
2814
|
-
return this.
|
|
2838
|
+
return this.activeInstanceable.getScaleAt(this.index);
|
|
2815
2839
|
}
|
|
2816
2840
|
//TODO: support for custom methods e.g. setting block variants
|
|
2817
2841
|
};
|
|
@@ -2829,6 +2853,8 @@ var _SceneObject = class _SceneObject extends Object3D2 {
|
|
|
2829
2853
|
this.materialCallbacks = {};
|
|
2830
2854
|
this._isInstanced = false;
|
|
2831
2855
|
this._instanceCounter = 0;
|
|
2856
|
+
this.instanceReferences = /* @__PURE__ */ new Map();
|
|
2857
|
+
this.freeInstanceIndices = [];
|
|
2832
2858
|
this.options = (0, import_ts_deepmerge3.default)({}, _SceneObject.DEFAULT_OPTIONS, options ?? {});
|
|
2833
2859
|
console.log("SceneObject options", this.options);
|
|
2834
2860
|
}
|
|
@@ -2924,6 +2950,8 @@ var _SceneObject = class _SceneObject extends Object3D2 {
|
|
|
2924
2950
|
createInstancedMesh(name, geometry, material, count) {
|
|
2925
2951
|
const mesh = new InstancedMesh(geometry, material, count);
|
|
2926
2952
|
mesh.count = 0;
|
|
2953
|
+
this.instanceMesh = mesh;
|
|
2954
|
+
this._isInstanced = true;
|
|
2927
2955
|
if (name) {
|
|
2928
2956
|
mesh.name = `mesh:${name}`;
|
|
2929
2957
|
}
|
|
@@ -2991,40 +3019,70 @@ var _SceneObject = class _SceneObject extends Object3D2 {
|
|
|
2991
3019
|
return new InstanceReference(this, i);
|
|
2992
3020
|
}
|
|
2993
3021
|
nextInstance() {
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
this.
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
|
|
3000
|
-
|
|
3001
|
-
|
|
3002
|
-
if (
|
|
3003
|
-
|
|
3004
|
-
|
|
3005
|
-
|
|
3006
|
-
|
|
3022
|
+
const mesh = this.instanceMesh;
|
|
3023
|
+
if (!mesh) throw new MineRenderError("Object is not instanced");
|
|
3024
|
+
const index = this.freeInstanceIndices.pop() ?? mesh.count;
|
|
3025
|
+
if (index >= mesh.instanceMatrix.count) this.growInstances(index + 1);
|
|
3026
|
+
const reference = this.constructInstanceReference(index);
|
|
3027
|
+
this.instanceReferences.set(index, reference);
|
|
3028
|
+
this._instanceCounter = this.instanceReferences.size;
|
|
3029
|
+
mesh.count = Math.max(mesh.count, index + 1);
|
|
3030
|
+
if (mesh.instanceColor) {
|
|
3031
|
+
mesh.setColorAt(index, new Color2(16777215));
|
|
3032
|
+
mesh.instanceColor.needsUpdate = true;
|
|
3033
|
+
}
|
|
3034
|
+
if (this._scene) this._scene.stats.instanceCount++;
|
|
3035
|
+
this.setMatrixAt(index, new Matrix43());
|
|
3036
|
+
return reference;
|
|
3037
|
+
}
|
|
3038
|
+
isInstanceActive(index, reference) {
|
|
3039
|
+
return this.instanceReferences.get(index) === reference;
|
|
3040
|
+
}
|
|
3041
|
+
removeInstanceAt(index) {
|
|
3042
|
+
if (!this.instanceReferences.has(index)) return;
|
|
3043
|
+
const mesh = this.instanceMesh;
|
|
3044
|
+
this.setMatrixAt(index, new Matrix43().makeScale(0, 0, 0));
|
|
3045
|
+
this.instanceReferences.delete(index);
|
|
3046
|
+
this.freeInstanceIndices.push(index);
|
|
3047
|
+
this._instanceCounter = this.instanceReferences.size;
|
|
3048
|
+
while (mesh.count > 0 && !this.instanceReferences.has(mesh.count - 1)) mesh.count--;
|
|
3049
|
+
if (this._scene) this._scene.stats.instanceCount--;
|
|
3050
|
+
}
|
|
3051
|
+
growInstances(required) {
|
|
3052
|
+
const mesh = this.instanceMesh;
|
|
3053
|
+
const capacity = Math.max(required, mesh.instanceMatrix.count * 2);
|
|
3054
|
+
const grow = (attribute, fill) => {
|
|
3055
|
+
const array = new Float32Array(capacity * attribute.itemSize).fill(fill);
|
|
3056
|
+
array.set(attribute.array);
|
|
3057
|
+
return new InstancedBufferAttribute(array, attribute.itemSize, attribute.normalized, attribute.meshPerAttribute).setUsage(attribute.usage);
|
|
3058
|
+
};
|
|
3059
|
+
const matrix = grow(mesh.instanceMatrix, 0);
|
|
3060
|
+
const color = mesh.instanceColor ? grow(mesh.instanceColor, 1) : null;
|
|
3061
|
+
mesh.dispose();
|
|
3062
|
+
mesh.instanceMatrix = matrix;
|
|
3063
|
+
mesh.instanceColor = color;
|
|
3064
|
+
}
|
|
3065
|
+
*activeInstanceIndices() {
|
|
3066
|
+
if (this.instanceMesh) {
|
|
3067
|
+
yield* this.instanceReferences.keys();
|
|
3068
|
+
} else {
|
|
3069
|
+
for (let i = 0; i < this.instanceCounter; i++) yield i;
|
|
3007
3070
|
}
|
|
3008
|
-
this.notifyDirty();
|
|
3009
|
-
return this.constructInstanceReference(i);
|
|
3010
3071
|
}
|
|
3011
3072
|
//</editor-fold>
|
|
3012
3073
|
//<editor-fold desc="TRANSFORMATION">
|
|
3013
3074
|
getMatrixAt(index, matrix = new Matrix43()) {
|
|
3014
|
-
if (!this.
|
|
3015
|
-
|
|
3016
|
-
if (child && isInstancedMesh(child)) {
|
|
3017
|
-
child.getMatrixAt(index, matrix);
|
|
3018
|
-
}
|
|
3075
|
+
if (!this.instanceReferences.has(index)) throw new MineRenderError("Instance is not active");
|
|
3076
|
+
this.instanceMesh.getMatrixAt(index, matrix);
|
|
3019
3077
|
return matrix;
|
|
3020
3078
|
}
|
|
3021
3079
|
setMatrixAt(index, matrix) {
|
|
3022
|
-
if (!this.
|
|
3023
|
-
const
|
|
3024
|
-
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
|
|
3080
|
+
if (!this.instanceReferences.has(index)) throw new MineRenderError("Instance is not active");
|
|
3081
|
+
const mesh = this.instanceMesh;
|
|
3082
|
+
mesh.setMatrixAt(index, matrix);
|
|
3083
|
+
mesh.instanceMatrix.needsUpdate = true;
|
|
3084
|
+
mesh.boundingBox = null;
|
|
3085
|
+
mesh.boundingSphere = null;
|
|
3028
3086
|
this.notifyDirty();
|
|
3029
3087
|
}
|
|
3030
3088
|
setPositionRotationScaleAt(index, position, rotation, scale) {
|
|
@@ -3075,7 +3133,7 @@ var _SceneObject = class _SceneObject extends Object3D2 {
|
|
|
3075
3133
|
}
|
|
3076
3134
|
setPositionRotationScale(position, rotation, scale) {
|
|
3077
3135
|
if (this.isInstanced) {
|
|
3078
|
-
for (
|
|
3136
|
+
for (const i of this.activeInstanceIndices()) {
|
|
3079
3137
|
this.setPositionRotationScaleAt(i, position, rotation, scale);
|
|
3080
3138
|
}
|
|
3081
3139
|
} else {
|
|
@@ -3093,7 +3151,7 @@ var _SceneObject = class _SceneObject extends Object3D2 {
|
|
|
3093
3151
|
}
|
|
3094
3152
|
setPosition(position) {
|
|
3095
3153
|
if (this.isInstanced) {
|
|
3096
|
-
for (
|
|
3154
|
+
for (const i of this.activeInstanceIndices()) {
|
|
3097
3155
|
this.setPositionRotationScaleAt(i, position);
|
|
3098
3156
|
}
|
|
3099
3157
|
} else {
|
|
@@ -3103,14 +3161,14 @@ var _SceneObject = class _SceneObject extends Object3D2 {
|
|
|
3103
3161
|
}
|
|
3104
3162
|
getPosition() {
|
|
3105
3163
|
if (this.isInstanced) {
|
|
3106
|
-
return this.getPositionAt(0);
|
|
3164
|
+
return this.getPositionAt(this.instanceReferences.keys().next().value ?? 0);
|
|
3107
3165
|
} else {
|
|
3108
3166
|
return this.position;
|
|
3109
3167
|
}
|
|
3110
3168
|
}
|
|
3111
3169
|
setRotation(rotation) {
|
|
3112
3170
|
if (this.isInstanced) {
|
|
3113
|
-
for (
|
|
3171
|
+
for (const i of this.activeInstanceIndices()) {
|
|
3114
3172
|
this.setPositionRotationScaleAt(i, void 0, rotation);
|
|
3115
3173
|
}
|
|
3116
3174
|
} else {
|
|
@@ -3120,14 +3178,14 @@ var _SceneObject = class _SceneObject extends Object3D2 {
|
|
|
3120
3178
|
}
|
|
3121
3179
|
getRotation() {
|
|
3122
3180
|
if (this.isInstanced) {
|
|
3123
|
-
return this.getRotationAt(0);
|
|
3181
|
+
return this.getRotationAt(this.instanceReferences.keys().next().value ?? 0);
|
|
3124
3182
|
} else {
|
|
3125
3183
|
return this.rotation;
|
|
3126
3184
|
}
|
|
3127
3185
|
}
|
|
3128
3186
|
setScale(scale) {
|
|
3129
3187
|
if (this.isInstanced) {
|
|
3130
|
-
for (
|
|
3188
|
+
for (const i of this.activeInstanceIndices()) {
|
|
3131
3189
|
this.setPositionRotationScaleAt(i, void 0, void 0, scale);
|
|
3132
3190
|
}
|
|
3133
3191
|
} else {
|
|
@@ -3137,7 +3195,7 @@ var _SceneObject = class _SceneObject extends Object3D2 {
|
|
|
3137
3195
|
}
|
|
3138
3196
|
getScale() {
|
|
3139
3197
|
if (this.isInstanced) {
|
|
3140
|
-
return this.getScaleAt(0);
|
|
3198
|
+
return this.getScaleAt(this.instanceReferences.keys().next().value ?? 0);
|
|
3141
3199
|
} else {
|
|
3142
3200
|
return this.scale;
|
|
3143
3201
|
}
|
|
@@ -3161,6 +3219,17 @@ var _SceneObject = class _SceneObject extends Object3D2 {
|
|
|
3161
3219
|
this.notifyDirty();
|
|
3162
3220
|
}
|
|
3163
3221
|
disposeAndRemoveAllChildren() {
|
|
3222
|
+
if (this.instanceMesh) {
|
|
3223
|
+
if (this._scene) this._scene.stats.instanceCount -= this.instanceReferences.size;
|
|
3224
|
+
this.instanceReferences.clear();
|
|
3225
|
+
this.freeInstanceIndices.length = 0;
|
|
3226
|
+
this._instanceCounter = 0;
|
|
3227
|
+
this.instanceMesh.count = 0;
|
|
3228
|
+
this.instanceMesh.dispose();
|
|
3229
|
+
this.instanceMesh.removeFromParent();
|
|
3230
|
+
this.instanceMesh = void 0;
|
|
3231
|
+
this._isInstanced = false;
|
|
3232
|
+
}
|
|
3164
3233
|
while (this.children.length > 0) {
|
|
3165
3234
|
let c = this.children[0];
|
|
3166
3235
|
if (isDisposable(c)) {
|
|
@@ -3205,9 +3274,21 @@ var _EntityObject = class _EntityObject extends SceneObject {
|
|
|
3205
3274
|
dispose() {
|
|
3206
3275
|
super.dispose();
|
|
3207
3276
|
}
|
|
3208
|
-
|
|
3209
|
-
|
|
3210
|
-
|
|
3277
|
+
getLayerGroup(name) {
|
|
3278
|
+
return super.getGroupByName(`layer:${name}`);
|
|
3279
|
+
}
|
|
3280
|
+
getGroupByName(name, layerName) {
|
|
3281
|
+
return layerName === void 0 ? super.getGroupByName(name) : this.getLayerGroup(layerName)?.getObjectByName(`group:${name}`);
|
|
3282
|
+
}
|
|
3283
|
+
getMeshByName(name, layerName) {
|
|
3284
|
+
return layerName === void 0 ? super.getMeshByName(name) : this.getLayerGroup(layerName)?.getObjectByName(`mesh:${name}`);
|
|
3285
|
+
}
|
|
3286
|
+
get entityLayers() {
|
|
3287
|
+
return this.entity.layers ?? { main: this.entity };
|
|
3288
|
+
}
|
|
3289
|
+
getTextureKey(layer) {
|
|
3290
|
+
if (layer.texture) return layer.texture;
|
|
3291
|
+
const key = layer.key;
|
|
3211
3292
|
return new AssetKey(
|
|
3212
3293
|
key.namespace,
|
|
3213
3294
|
isAssetKey(key) ? key.getFullPath() : key.path,
|
|
@@ -3217,18 +3298,22 @@ var _EntityObject = class _EntityObject extends SceneObject {
|
|
|
3217
3298
|
".png"
|
|
3218
3299
|
);
|
|
3219
3300
|
}
|
|
3220
|
-
async loadTextures() {
|
|
3221
|
-
|
|
3301
|
+
async loadTextures(layer = this.entity) {
|
|
3302
|
+
return ModelTextures.get(this.getTextureKey(layer));
|
|
3222
3303
|
}
|
|
3223
3304
|
createMeshes(force = false) {
|
|
3224
3305
|
if (this.meshesCreated && !force) return;
|
|
3225
3306
|
const modelRoot = new Object3D3();
|
|
3226
3307
|
if (this.options.flip) modelRoot.scale.set(-1, -1, 1);
|
|
3227
3308
|
this.add(modelRoot);
|
|
3228
|
-
|
|
3309
|
+
Object.entries(this.entityLayers).forEach(([name, layer], index) => {
|
|
3310
|
+
const group = this.createGroup(`layer:${name}`);
|
|
3311
|
+
modelRoot.add(group);
|
|
3312
|
+
this.createPart("root", layer.layer.root, group, layer.layer.texture, Materials.MISSING_TEXTURE, index);
|
|
3313
|
+
});
|
|
3229
3314
|
this.meshesCreated = true;
|
|
3230
3315
|
}
|
|
3231
|
-
createPart(name, part, parent, textureSize, material) {
|
|
3316
|
+
createPart(name, part, parent, textureSize, material, renderOrder) {
|
|
3232
3317
|
const anchor = this.createGroup(name);
|
|
3233
3318
|
anchor.position.fromArray(part.pose.offset);
|
|
3234
3319
|
anchor.rotation.set(...part.pose.rotation, "ZYX");
|
|
@@ -3248,30 +3333,31 @@ var _EntityObject = class _EntityObject extends SceneObject {
|
|
|
3248
3333
|
).clone();
|
|
3249
3334
|
geometry.translate(cube.origin[0] + width / 2, cube.origin[1] + height / 2, cube.origin[2] + depth / 2);
|
|
3250
3335
|
const mesh = this.createMesh(name, geometry, material);
|
|
3336
|
+
mesh.renderOrder = renderOrder;
|
|
3251
3337
|
anchor.add(mesh);
|
|
3252
3338
|
if (this.options.wireframe) addWireframeToMesh(geometry, mesh);
|
|
3253
3339
|
}
|
|
3254
3340
|
for (const [childName, child] of Object.entries(part.children)) {
|
|
3255
|
-
this.createPart(childName, child, anchor, size, material);
|
|
3341
|
+
this.createPart(childName, child, anchor, size, material, renderOrder);
|
|
3256
3342
|
}
|
|
3257
3343
|
}
|
|
3258
3344
|
async applyTextures() {
|
|
3259
|
-
|
|
3260
|
-
|
|
3261
|
-
|
|
3262
|
-
|
|
3263
|
-
|
|
3264
|
-
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
-
|
|
3270
|
-
|
|
3271
|
-
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
});
|
|
3345
|
+
await Promise.all(Object.entries(this.entityLayers).map(async ([name, layer]) => {
|
|
3346
|
+
const assetKeyStr = this.getTextureKey(layer).serialize();
|
|
3347
|
+
const keyStr = `entity:${assetKeyStr}`;
|
|
3348
|
+
let mat = Caching.materialCache.getIfPresent(keyStr);
|
|
3349
|
+
if (!mat) {
|
|
3350
|
+
const cachedAsset = Caching.textureAssetCache.getIfPresent(assetKeyStr);
|
|
3351
|
+
const imageData = await this.loadTextures(layer);
|
|
3352
|
+
if (!imageData) return;
|
|
3353
|
+
const canvas = imageData.data.canvas;
|
|
3354
|
+
const createMaterial = () => Materials.createBasicCanvasMaterial(canvas);
|
|
3355
|
+
mat = cachedAsset && Caching.textureAssetCache.getIfPresent(assetKeyStr) === cachedAsset ? Caching.materialCache.get(keyStr, createMaterial) : createMaterial();
|
|
3356
|
+
}
|
|
3357
|
+
this.getLayerGroup(name)?.traverse((object) => {
|
|
3358
|
+
if (isMesh(object)) object.material = mat;
|
|
3359
|
+
});
|
|
3360
|
+
}));
|
|
3275
3361
|
this.notifyDirty();
|
|
3276
3362
|
}
|
|
3277
3363
|
};
|
|
@@ -4369,10 +4455,6 @@ var _ModelObject = class _ModelObject extends SceneObject {
|
|
|
4369
4455
|
this.createMeshes();
|
|
4370
4456
|
this.applyTextures();
|
|
4371
4457
|
}
|
|
4372
|
-
dispose() {
|
|
4373
|
-
super.dispose();
|
|
4374
|
-
this.atlas?.dispose();
|
|
4375
|
-
}
|
|
4376
4458
|
get textureAtlas() {
|
|
4377
4459
|
return this.atlas;
|
|
4378
4460
|
}
|
|
@@ -4488,7 +4570,7 @@ function isModelObject(obj) {
|
|
|
4488
4570
|
|
|
4489
4571
|
// src/model/block/scene/BlockObject.ts
|
|
4490
4572
|
var import_ts_deepmerge6 = __toESM(require_dist());
|
|
4491
|
-
import { Euler as Euler5, Matrix4 as Matrix45
|
|
4573
|
+
import { Euler as Euler5, Matrix4 as Matrix45 } from "three";
|
|
4492
4574
|
var p10 = prefix("BlockObject");
|
|
4493
4575
|
function matchesCondition(condition, state) {
|
|
4494
4576
|
return Object.entries(condition).every(([key, value]) => {
|
|
@@ -4538,18 +4620,21 @@ var _BlockObject = class _BlockObject extends SceneObject {
|
|
|
4538
4620
|
}
|
|
4539
4621
|
}
|
|
4540
4622
|
dispose() {
|
|
4623
|
+
this.clearModels();
|
|
4541
4624
|
super.dispose();
|
|
4542
4625
|
}
|
|
4543
4626
|
removeFromScene() {
|
|
4544
|
-
|
|
4545
|
-
if (isModelObject(model)) {
|
|
4546
|
-
model.removeFromScene();
|
|
4547
|
-
} else if (isInstanceReference(model)) {
|
|
4548
|
-
model.setScale(new Vector37(0, 0, 0));
|
|
4549
|
-
}
|
|
4550
|
-
}
|
|
4627
|
+
this.clearModels();
|
|
4551
4628
|
super.removeFromScene();
|
|
4552
4629
|
}
|
|
4630
|
+
clearModels() {
|
|
4631
|
+
for (const model of this._models.splice(0)) {
|
|
4632
|
+
model.removeFromScene();
|
|
4633
|
+
if (!isInstanceReference(model)) model.dispose();
|
|
4634
|
+
}
|
|
4635
|
+
this._isInstanced = false;
|
|
4636
|
+
this._instanceCounter = 0;
|
|
4637
|
+
}
|
|
4553
4638
|
get state() {
|
|
4554
4639
|
return this._state;
|
|
4555
4640
|
}
|
|
@@ -4598,22 +4683,7 @@ var _BlockObject = class _BlockObject extends SceneObject {
|
|
|
4598
4683
|
return out;
|
|
4599
4684
|
}
|
|
4600
4685
|
async recreateModels() {
|
|
4601
|
-
|
|
4602
|
-
if (this.isInstanced) {
|
|
4603
|
-
for (let i = 0; i < this.instanceCounter; i++) {
|
|
4604
|
-
instanceInfo[i] = this.getMatrixAt(i);
|
|
4605
|
-
}
|
|
4606
|
-
}
|
|
4607
|
-
for (let model of this._models) {
|
|
4608
|
-
if (isInstanceReference(model)) {
|
|
4609
|
-
model.setScale(new Vector37(0, 0, 0));
|
|
4610
|
-
} else {
|
|
4611
|
-
model.dispose();
|
|
4612
|
-
}
|
|
4613
|
-
}
|
|
4614
|
-
while (this._models.length > 0) {
|
|
4615
|
-
this._models.shift();
|
|
4616
|
-
}
|
|
4686
|
+
this.clearModels();
|
|
4617
4687
|
const variantsToCreate = await this.mapStateToVariant(this.state);
|
|
4618
4688
|
this._variants = variantsToCreate;
|
|
4619
4689
|
for (let blockStateVariant of variantsToCreate) {
|
|
@@ -4664,6 +4734,7 @@ var _BlockObject = class _BlockObject extends SceneObject {
|
|
|
4664
4734
|
this._instanceCounter = 1;
|
|
4665
4735
|
}
|
|
4666
4736
|
obj.setRotation(rotation);
|
|
4737
|
+
obj.setPosition(this.position);
|
|
4667
4738
|
return obj;
|
|
4668
4739
|
}
|
|
4669
4740
|
async resetState() {
|