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/node/index.mjs
CHANGED
|
@@ -2765,26 +2765,40 @@ var Entities = class {
|
|
|
2765
2765
|
};
|
|
2766
2766
|
return collect("");
|
|
2767
2767
|
}
|
|
2768
|
-
static async
|
|
2768
|
+
static async getModelFile(modelKey) {
|
|
2769
2769
|
const path = isAssetKey(modelKey) ? modelKey.getFullPath() : modelKey.path;
|
|
2770
2770
|
const key = new AssetKey(modelKey.namespace, path, void 0, void 0, "entity-models", ".json");
|
|
2771
|
-
|
|
2771
|
+
return Caching.entityModelCache.get(key.serialize(), () => AssetLoader.get(key, "json" /* JSON */));
|
|
2772
|
+
}
|
|
2773
|
+
static async getLayerList(modelKey) {
|
|
2774
|
+
return Object.keys((await this.getModelFile(modelKey))?.layers ?? {});
|
|
2775
|
+
}
|
|
2776
|
+
static async getEntity(modelKey, textureKey, options) {
|
|
2777
|
+
const model = await this.getModelFile(modelKey);
|
|
2772
2778
|
if (!model) return void 0;
|
|
2773
|
-
const
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
|
|
2779
|
+
const names = [...new Set(options?.layers ?? [options?.layer ?? "main"])];
|
|
2780
|
+
if (names.length === 0) throw new MineRenderError(`Entity ${model.id} requires at least one layer`);
|
|
2781
|
+
const selected = names.map((name) => {
|
|
2782
|
+
const layer = model.layers[name];
|
|
2783
|
+
if (!layer) {
|
|
2784
|
+
throw new MineRenderError(`Entity ${model.id} has no layer "${name}". Available layers: ${Object.keys(model.layers).join(", ")}`);
|
|
2785
|
+
}
|
|
2786
|
+
return { name, layer };
|
|
2787
|
+
});
|
|
2788
|
+
const layers = Object.fromEntries(await Promise.all(selected.map(async ({ name, layer }, index) => {
|
|
2789
|
+
const override = options?.textures?.[name] ?? (index === 0 ? textureKey : void 0);
|
|
2790
|
+
let texture;
|
|
2791
|
+
if (override) {
|
|
2792
|
+
const path = isAssetKey(override) ? override.getFullPath() : override.path;
|
|
2793
|
+
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);
|
|
2794
|
+
} else if (layer.textureLocation !== void 0) {
|
|
2795
|
+
texture = AssetKey.parse("textures", layer.textureLocation.replace(/^([^:]+:)?textures\//, "$1"));
|
|
2796
|
+
} else {
|
|
2797
|
+
texture = await this.resolveTexture(modelKey);
|
|
2798
|
+
}
|
|
2799
|
+
return [name, { key: override ?? modelKey, texture, layer }];
|
|
2800
|
+
})));
|
|
2801
|
+
return { ...layers[names[0]], id: model.id, layers };
|
|
2788
2802
|
}
|
|
2789
2803
|
static async resolveTexture(modelKey) {
|
|
2790
2804
|
const path = isAssetKey(modelKey) ? modelKey.getFullPath() : modelKey.path;
|
|
@@ -2818,7 +2832,7 @@ var Entities = class {
|
|
|
2818
2832
|
};
|
|
2819
2833
|
|
|
2820
2834
|
// src/renderer/SceneObject.ts
|
|
2821
|
-
import { Euler as Euler3, InstancedMesh, MathUtils, Matrix4 as Matrix43, Mesh as Mesh3, Object3D as Object3D2, Quaternion as Quaternion3, Vector3 as Vector35 } from "three";
|
|
2835
|
+
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";
|
|
2822
2836
|
|
|
2823
2837
|
// src/instance/InstanceReference.ts
|
|
2824
2838
|
var InstanceReference = class {
|
|
@@ -2830,32 +2844,42 @@ var InstanceReference = class {
|
|
|
2830
2844
|
nextInstance() {
|
|
2831
2845
|
return this.instanceable.nextInstance();
|
|
2832
2846
|
}
|
|
2847
|
+
get activeInstanceable() {
|
|
2848
|
+
if (!this.instanceable.isInstanceActive(this.index, this)) throw new MineRenderError("Instance has been removed");
|
|
2849
|
+
return this.instanceable;
|
|
2850
|
+
}
|
|
2851
|
+
removeFromScene() {
|
|
2852
|
+
if (this.instanceable.isInstanceActive(this.index, this)) this.instanceable.removeInstanceAt(this.index);
|
|
2853
|
+
}
|
|
2854
|
+
dispose() {
|
|
2855
|
+
this.removeFromScene();
|
|
2856
|
+
}
|
|
2833
2857
|
getMatrix(matrix) {
|
|
2834
|
-
return this.
|
|
2858
|
+
return this.activeInstanceable.getMatrixAt(this.index, matrix);
|
|
2835
2859
|
}
|
|
2836
2860
|
setMatrix(matrix) {
|
|
2837
|
-
this.
|
|
2861
|
+
this.activeInstanceable.setMatrixAt(this.index, matrix);
|
|
2838
2862
|
}
|
|
2839
2863
|
setPositionRotationScale(position, rotation, scale) {
|
|
2840
|
-
this.
|
|
2864
|
+
this.activeInstanceable.setPositionRotationScaleAt(this.index, position, rotation, scale);
|
|
2841
2865
|
}
|
|
2842
2866
|
setPosition(position) {
|
|
2843
|
-
this.
|
|
2867
|
+
this.activeInstanceable.setPositionAt(this.index, position);
|
|
2844
2868
|
}
|
|
2845
2869
|
getPosition() {
|
|
2846
|
-
return this.
|
|
2870
|
+
return this.activeInstanceable.getPositionAt(this.index);
|
|
2847
2871
|
}
|
|
2848
2872
|
setRotation(rotation) {
|
|
2849
|
-
this.
|
|
2873
|
+
this.activeInstanceable.setRotationAt(this.index, rotation);
|
|
2850
2874
|
}
|
|
2851
2875
|
getRotation() {
|
|
2852
|
-
return this.
|
|
2876
|
+
return this.activeInstanceable.getRotationAt(this.index);
|
|
2853
2877
|
}
|
|
2854
2878
|
setScale(scale) {
|
|
2855
|
-
this.
|
|
2879
|
+
this.activeInstanceable.setScaleAt(this.index, scale);
|
|
2856
2880
|
}
|
|
2857
2881
|
getScale() {
|
|
2858
|
-
return this.
|
|
2882
|
+
return this.activeInstanceable.getScaleAt(this.index);
|
|
2859
2883
|
}
|
|
2860
2884
|
//TODO: support for custom methods e.g. setting block variants
|
|
2861
2885
|
};
|
|
@@ -2873,6 +2897,8 @@ var SceneObject = class _SceneObject extends Object3D2 {
|
|
|
2873
2897
|
this.materialCallbacks = {};
|
|
2874
2898
|
this._isInstanced = false;
|
|
2875
2899
|
this._instanceCounter = 0;
|
|
2900
|
+
this.instanceReferences = /* @__PURE__ */ new Map();
|
|
2901
|
+
this.freeInstanceIndices = [];
|
|
2876
2902
|
this.options = (0, import_ts_deepmerge3.default)({}, _SceneObject.DEFAULT_OPTIONS, options ?? {});
|
|
2877
2903
|
console.log("SceneObject options", this.options);
|
|
2878
2904
|
}
|
|
@@ -2976,6 +3002,8 @@ var SceneObject = class _SceneObject extends Object3D2 {
|
|
|
2976
3002
|
createInstancedMesh(name, geometry, material, count) {
|
|
2977
3003
|
const mesh = new InstancedMesh(geometry, material, count);
|
|
2978
3004
|
mesh.count = 0;
|
|
3005
|
+
this.instanceMesh = mesh;
|
|
3006
|
+
this._isInstanced = true;
|
|
2979
3007
|
if (name) {
|
|
2980
3008
|
mesh.name = `mesh:${name}`;
|
|
2981
3009
|
}
|
|
@@ -3043,40 +3071,70 @@ var SceneObject = class _SceneObject extends Object3D2 {
|
|
|
3043
3071
|
return new InstanceReference(this, i);
|
|
3044
3072
|
}
|
|
3045
3073
|
nextInstance() {
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
this.
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
|
|
3054
|
-
if (
|
|
3055
|
-
|
|
3056
|
-
|
|
3057
|
-
|
|
3058
|
-
|
|
3074
|
+
const mesh = this.instanceMesh;
|
|
3075
|
+
if (!mesh) throw new MineRenderError("Object is not instanced");
|
|
3076
|
+
const index = this.freeInstanceIndices.pop() ?? mesh.count;
|
|
3077
|
+
if (index >= mesh.instanceMatrix.count) this.growInstances(index + 1);
|
|
3078
|
+
const reference = this.constructInstanceReference(index);
|
|
3079
|
+
this.instanceReferences.set(index, reference);
|
|
3080
|
+
this._instanceCounter = this.instanceReferences.size;
|
|
3081
|
+
mesh.count = Math.max(mesh.count, index + 1);
|
|
3082
|
+
if (mesh.instanceColor) {
|
|
3083
|
+
mesh.setColorAt(index, new Color2(16777215));
|
|
3084
|
+
mesh.instanceColor.needsUpdate = true;
|
|
3085
|
+
}
|
|
3086
|
+
if (this._scene) this._scene.stats.instanceCount++;
|
|
3087
|
+
this.setMatrixAt(index, new Matrix43());
|
|
3088
|
+
return reference;
|
|
3089
|
+
}
|
|
3090
|
+
isInstanceActive(index, reference) {
|
|
3091
|
+
return this.instanceReferences.get(index) === reference;
|
|
3092
|
+
}
|
|
3093
|
+
removeInstanceAt(index) {
|
|
3094
|
+
if (!this.instanceReferences.has(index)) return;
|
|
3095
|
+
const mesh = this.instanceMesh;
|
|
3096
|
+
this.setMatrixAt(index, new Matrix43().makeScale(0, 0, 0));
|
|
3097
|
+
this.instanceReferences.delete(index);
|
|
3098
|
+
this.freeInstanceIndices.push(index);
|
|
3099
|
+
this._instanceCounter = this.instanceReferences.size;
|
|
3100
|
+
while (mesh.count > 0 && !this.instanceReferences.has(mesh.count - 1)) mesh.count--;
|
|
3101
|
+
if (this._scene) this._scene.stats.instanceCount--;
|
|
3102
|
+
}
|
|
3103
|
+
growInstances(required) {
|
|
3104
|
+
const mesh = this.instanceMesh;
|
|
3105
|
+
const capacity = Math.max(required, mesh.instanceMatrix.count * 2);
|
|
3106
|
+
const grow = (attribute, fill) => {
|
|
3107
|
+
const array = new Float32Array(capacity * attribute.itemSize).fill(fill);
|
|
3108
|
+
array.set(attribute.array);
|
|
3109
|
+
return new InstancedBufferAttribute(array, attribute.itemSize, attribute.normalized, attribute.meshPerAttribute).setUsage(attribute.usage);
|
|
3110
|
+
};
|
|
3111
|
+
const matrix = grow(mesh.instanceMatrix, 0);
|
|
3112
|
+
const color = mesh.instanceColor ? grow(mesh.instanceColor, 1) : null;
|
|
3113
|
+
mesh.dispose();
|
|
3114
|
+
mesh.instanceMatrix = matrix;
|
|
3115
|
+
mesh.instanceColor = color;
|
|
3116
|
+
}
|
|
3117
|
+
*activeInstanceIndices() {
|
|
3118
|
+
if (this.instanceMesh) {
|
|
3119
|
+
yield* this.instanceReferences.keys();
|
|
3120
|
+
} else {
|
|
3121
|
+
for (let i = 0; i < this.instanceCounter; i++) yield i;
|
|
3059
3122
|
}
|
|
3060
|
-
this.notifyDirty();
|
|
3061
|
-
return this.constructInstanceReference(i);
|
|
3062
3123
|
}
|
|
3063
3124
|
//</editor-fold>
|
|
3064
3125
|
//<editor-fold desc="TRANSFORMATION">
|
|
3065
3126
|
getMatrixAt(index, matrix = new Matrix43()) {
|
|
3066
|
-
if (!this.
|
|
3067
|
-
|
|
3068
|
-
if (child && isInstancedMesh(child)) {
|
|
3069
|
-
child.getMatrixAt(index, matrix);
|
|
3070
|
-
}
|
|
3127
|
+
if (!this.instanceReferences.has(index)) throw new MineRenderError("Instance is not active");
|
|
3128
|
+
this.instanceMesh.getMatrixAt(index, matrix);
|
|
3071
3129
|
return matrix;
|
|
3072
3130
|
}
|
|
3073
3131
|
setMatrixAt(index, matrix) {
|
|
3074
|
-
if (!this.
|
|
3075
|
-
const
|
|
3076
|
-
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
|
|
3132
|
+
if (!this.instanceReferences.has(index)) throw new MineRenderError("Instance is not active");
|
|
3133
|
+
const mesh = this.instanceMesh;
|
|
3134
|
+
mesh.setMatrixAt(index, matrix);
|
|
3135
|
+
mesh.instanceMatrix.needsUpdate = true;
|
|
3136
|
+
mesh.boundingBox = null;
|
|
3137
|
+
mesh.boundingSphere = null;
|
|
3080
3138
|
this.notifyDirty();
|
|
3081
3139
|
}
|
|
3082
3140
|
setPositionRotationScaleAt(index, position, rotation, scale) {
|
|
@@ -3127,7 +3185,7 @@ var SceneObject = class _SceneObject extends Object3D2 {
|
|
|
3127
3185
|
}
|
|
3128
3186
|
setPositionRotationScale(position, rotation, scale) {
|
|
3129
3187
|
if (this.isInstanced) {
|
|
3130
|
-
for (
|
|
3188
|
+
for (const i of this.activeInstanceIndices()) {
|
|
3131
3189
|
this.setPositionRotationScaleAt(i, position, rotation, scale);
|
|
3132
3190
|
}
|
|
3133
3191
|
} else {
|
|
@@ -3145,7 +3203,7 @@ var SceneObject = class _SceneObject extends Object3D2 {
|
|
|
3145
3203
|
}
|
|
3146
3204
|
setPosition(position) {
|
|
3147
3205
|
if (this.isInstanced) {
|
|
3148
|
-
for (
|
|
3206
|
+
for (const i of this.activeInstanceIndices()) {
|
|
3149
3207
|
this.setPositionRotationScaleAt(i, position);
|
|
3150
3208
|
}
|
|
3151
3209
|
} else {
|
|
@@ -3155,14 +3213,14 @@ var SceneObject = class _SceneObject extends Object3D2 {
|
|
|
3155
3213
|
}
|
|
3156
3214
|
getPosition() {
|
|
3157
3215
|
if (this.isInstanced) {
|
|
3158
|
-
return this.getPositionAt(0);
|
|
3216
|
+
return this.getPositionAt(this.instanceReferences.keys().next().value ?? 0);
|
|
3159
3217
|
} else {
|
|
3160
3218
|
return this.position;
|
|
3161
3219
|
}
|
|
3162
3220
|
}
|
|
3163
3221
|
setRotation(rotation) {
|
|
3164
3222
|
if (this.isInstanced) {
|
|
3165
|
-
for (
|
|
3223
|
+
for (const i of this.activeInstanceIndices()) {
|
|
3166
3224
|
this.setPositionRotationScaleAt(i, void 0, rotation);
|
|
3167
3225
|
}
|
|
3168
3226
|
} else {
|
|
@@ -3172,14 +3230,14 @@ var SceneObject = class _SceneObject extends Object3D2 {
|
|
|
3172
3230
|
}
|
|
3173
3231
|
getRotation() {
|
|
3174
3232
|
if (this.isInstanced) {
|
|
3175
|
-
return this.getRotationAt(0);
|
|
3233
|
+
return this.getRotationAt(this.instanceReferences.keys().next().value ?? 0);
|
|
3176
3234
|
} else {
|
|
3177
3235
|
return this.rotation;
|
|
3178
3236
|
}
|
|
3179
3237
|
}
|
|
3180
3238
|
setScale(scale) {
|
|
3181
3239
|
if (this.isInstanced) {
|
|
3182
|
-
for (
|
|
3240
|
+
for (const i of this.activeInstanceIndices()) {
|
|
3183
3241
|
this.setPositionRotationScaleAt(i, void 0, void 0, scale);
|
|
3184
3242
|
}
|
|
3185
3243
|
} else {
|
|
@@ -3189,7 +3247,7 @@ var SceneObject = class _SceneObject extends Object3D2 {
|
|
|
3189
3247
|
}
|
|
3190
3248
|
getScale() {
|
|
3191
3249
|
if (this.isInstanced) {
|
|
3192
|
-
return this.getScaleAt(0);
|
|
3250
|
+
return this.getScaleAt(this.instanceReferences.keys().next().value ?? 0);
|
|
3193
3251
|
} else {
|
|
3194
3252
|
return this.scale;
|
|
3195
3253
|
}
|
|
@@ -3213,6 +3271,17 @@ var SceneObject = class _SceneObject extends Object3D2 {
|
|
|
3213
3271
|
this.notifyDirty();
|
|
3214
3272
|
}
|
|
3215
3273
|
disposeAndRemoveAllChildren() {
|
|
3274
|
+
if (this.instanceMesh) {
|
|
3275
|
+
if (this._scene) this._scene.stats.instanceCount -= this.instanceReferences.size;
|
|
3276
|
+
this.instanceReferences.clear();
|
|
3277
|
+
this.freeInstanceIndices.length = 0;
|
|
3278
|
+
this._instanceCounter = 0;
|
|
3279
|
+
this.instanceMesh.count = 0;
|
|
3280
|
+
this.instanceMesh.dispose();
|
|
3281
|
+
this.instanceMesh.removeFromParent();
|
|
3282
|
+
this.instanceMesh = void 0;
|
|
3283
|
+
this._isInstanced = false;
|
|
3284
|
+
}
|
|
3216
3285
|
while (this.children.length > 0) {
|
|
3217
3286
|
let c = this.children[0];
|
|
3218
3287
|
if (isDisposable(c)) {
|
|
@@ -3253,9 +3322,21 @@ var EntityObject = class _EntityObject extends SceneObject {
|
|
|
3253
3322
|
dispose() {
|
|
3254
3323
|
super.dispose();
|
|
3255
3324
|
}
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
|
|
3325
|
+
getLayerGroup(name) {
|
|
3326
|
+
return super.getGroupByName(`layer:${name}`);
|
|
3327
|
+
}
|
|
3328
|
+
getGroupByName(name, layerName) {
|
|
3329
|
+
return layerName === void 0 ? super.getGroupByName(name) : this.getLayerGroup(layerName)?.getObjectByName(`group:${name}`);
|
|
3330
|
+
}
|
|
3331
|
+
getMeshByName(name, layerName) {
|
|
3332
|
+
return layerName === void 0 ? super.getMeshByName(name) : this.getLayerGroup(layerName)?.getObjectByName(`mesh:${name}`);
|
|
3333
|
+
}
|
|
3334
|
+
get entityLayers() {
|
|
3335
|
+
return this.entity.layers ?? { main: this.entity };
|
|
3336
|
+
}
|
|
3337
|
+
getTextureKey(layer) {
|
|
3338
|
+
if (layer.texture) return layer.texture;
|
|
3339
|
+
const key = layer.key;
|
|
3259
3340
|
return new AssetKey(
|
|
3260
3341
|
key.namespace,
|
|
3261
3342
|
isAssetKey(key) ? key.getFullPath() : key.path,
|
|
@@ -3265,18 +3346,22 @@ var EntityObject = class _EntityObject extends SceneObject {
|
|
|
3265
3346
|
".png"
|
|
3266
3347
|
);
|
|
3267
3348
|
}
|
|
3268
|
-
async loadTextures() {
|
|
3269
|
-
|
|
3349
|
+
async loadTextures(layer = this.entity) {
|
|
3350
|
+
return ModelTextures.get(this.getTextureKey(layer));
|
|
3270
3351
|
}
|
|
3271
3352
|
createMeshes(force = false) {
|
|
3272
3353
|
if (this.meshesCreated && !force) return;
|
|
3273
3354
|
const modelRoot = new Object3D3();
|
|
3274
3355
|
if (this.options.flip) modelRoot.scale.set(-1, -1, 1);
|
|
3275
3356
|
this.add(modelRoot);
|
|
3276
|
-
|
|
3357
|
+
Object.entries(this.entityLayers).forEach(([name, layer], index) => {
|
|
3358
|
+
const group = this.createGroup(`layer:${name}`);
|
|
3359
|
+
modelRoot.add(group);
|
|
3360
|
+
this.createPart("root", layer.layer.root, group, layer.layer.texture, Materials.MISSING_TEXTURE, index);
|
|
3361
|
+
});
|
|
3277
3362
|
this.meshesCreated = true;
|
|
3278
3363
|
}
|
|
3279
|
-
createPart(name, part, parent, textureSize, material) {
|
|
3364
|
+
createPart(name, part, parent, textureSize, material, renderOrder) {
|
|
3280
3365
|
const anchor = this.createGroup(name);
|
|
3281
3366
|
anchor.position.fromArray(part.pose.offset);
|
|
3282
3367
|
anchor.rotation.set(...part.pose.rotation, "ZYX");
|
|
@@ -3296,30 +3381,31 @@ var EntityObject = class _EntityObject extends SceneObject {
|
|
|
3296
3381
|
).clone();
|
|
3297
3382
|
geometry.translate(cube.origin[0] + width / 2, cube.origin[1] + height / 2, cube.origin[2] + depth / 2);
|
|
3298
3383
|
const mesh = this.createMesh(name, geometry, material);
|
|
3384
|
+
mesh.renderOrder = renderOrder;
|
|
3299
3385
|
anchor.add(mesh);
|
|
3300
3386
|
if (this.options.wireframe) addWireframeToMesh(geometry, mesh);
|
|
3301
3387
|
}
|
|
3302
3388
|
for (const [childName, child] of Object.entries(part.children)) {
|
|
3303
|
-
this.createPart(childName, child, anchor, size, material);
|
|
3389
|
+
this.createPart(childName, child, anchor, size, material, renderOrder);
|
|
3304
3390
|
}
|
|
3305
3391
|
}
|
|
3306
3392
|
async applyTextures() {
|
|
3307
|
-
|
|
3308
|
-
|
|
3309
|
-
|
|
3310
|
-
|
|
3311
|
-
|
|
3312
|
-
|
|
3313
|
-
|
|
3314
|
-
|
|
3315
|
-
|
|
3316
|
-
|
|
3317
|
-
|
|
3318
|
-
|
|
3319
|
-
|
|
3320
|
-
|
|
3321
|
-
|
|
3322
|
-
});
|
|
3393
|
+
await Promise.all(Object.entries(this.entityLayers).map(async ([name, layer]) => {
|
|
3394
|
+
const assetKeyStr = this.getTextureKey(layer).serialize();
|
|
3395
|
+
const keyStr = `entity:${assetKeyStr}`;
|
|
3396
|
+
let mat = Caching.materialCache.getIfPresent(keyStr);
|
|
3397
|
+
if (!mat) {
|
|
3398
|
+
const cachedAsset = Caching.textureAssetCache.getIfPresent(assetKeyStr);
|
|
3399
|
+
const imageData = await this.loadTextures(layer);
|
|
3400
|
+
if (!imageData) return;
|
|
3401
|
+
const canvas = imageData.data.canvas;
|
|
3402
|
+
const createMaterial = () => Materials.createBasicCanvasMaterial(canvas);
|
|
3403
|
+
mat = cachedAsset && Caching.textureAssetCache.getIfPresent(assetKeyStr) === cachedAsset ? Caching.materialCache.get(keyStr, createMaterial) : createMaterial();
|
|
3404
|
+
}
|
|
3405
|
+
this.getLayerGroup(name)?.traverse((object) => {
|
|
3406
|
+
if (isMesh(object)) object.material = mat;
|
|
3407
|
+
});
|
|
3408
|
+
}));
|
|
3323
3409
|
this.notifyDirty();
|
|
3324
3410
|
}
|
|
3325
3411
|
};
|
|
@@ -4418,10 +4504,6 @@ var ModelObject = class _ModelObject extends SceneObject {
|
|
|
4418
4504
|
this.createMeshes();
|
|
4419
4505
|
this.applyTextures();
|
|
4420
4506
|
}
|
|
4421
|
-
dispose() {
|
|
4422
|
-
super.dispose();
|
|
4423
|
-
this.atlas?.dispose();
|
|
4424
|
-
}
|
|
4425
4507
|
get textureAtlas() {
|
|
4426
4508
|
return this.atlas;
|
|
4427
4509
|
}
|
|
@@ -4535,7 +4617,7 @@ function isModelObject(obj) {
|
|
|
4535
4617
|
|
|
4536
4618
|
// src/model/block/scene/BlockObject.ts
|
|
4537
4619
|
var import_ts_deepmerge6 = __toESM(require_dist());
|
|
4538
|
-
import { Euler as Euler5, Matrix4 as Matrix45
|
|
4620
|
+
import { Euler as Euler5, Matrix4 as Matrix45 } from "three";
|
|
4539
4621
|
var p10 = prefix("BlockObject");
|
|
4540
4622
|
function matchesCondition(condition, state) {
|
|
4541
4623
|
return Object.entries(condition).every(([key, value]) => {
|
|
@@ -4590,18 +4672,21 @@ var BlockObject = class _BlockObject extends SceneObject {
|
|
|
4590
4672
|
}
|
|
4591
4673
|
}
|
|
4592
4674
|
dispose() {
|
|
4675
|
+
this.clearModels();
|
|
4593
4676
|
super.dispose();
|
|
4594
4677
|
}
|
|
4595
4678
|
removeFromScene() {
|
|
4596
|
-
|
|
4597
|
-
if (isModelObject(model)) {
|
|
4598
|
-
model.removeFromScene();
|
|
4599
|
-
} else if (isInstanceReference(model)) {
|
|
4600
|
-
model.setScale(new Vector37(0, 0, 0));
|
|
4601
|
-
}
|
|
4602
|
-
}
|
|
4679
|
+
this.clearModels();
|
|
4603
4680
|
super.removeFromScene();
|
|
4604
4681
|
}
|
|
4682
|
+
clearModels() {
|
|
4683
|
+
for (const model of this._models.splice(0)) {
|
|
4684
|
+
model.removeFromScene();
|
|
4685
|
+
if (!isInstanceReference(model)) model.dispose();
|
|
4686
|
+
}
|
|
4687
|
+
this._isInstanced = false;
|
|
4688
|
+
this._instanceCounter = 0;
|
|
4689
|
+
}
|
|
4605
4690
|
get state() {
|
|
4606
4691
|
return this._state;
|
|
4607
4692
|
}
|
|
@@ -4650,22 +4735,7 @@ var BlockObject = class _BlockObject extends SceneObject {
|
|
|
4650
4735
|
return out;
|
|
4651
4736
|
}
|
|
4652
4737
|
async recreateModels() {
|
|
4653
|
-
|
|
4654
|
-
if (this.isInstanced) {
|
|
4655
|
-
for (let i = 0; i < this.instanceCounter; i++) {
|
|
4656
|
-
instanceInfo[i] = this.getMatrixAt(i);
|
|
4657
|
-
}
|
|
4658
|
-
}
|
|
4659
|
-
for (let model of this._models) {
|
|
4660
|
-
if (isInstanceReference(model)) {
|
|
4661
|
-
model.setScale(new Vector37(0, 0, 0));
|
|
4662
|
-
} else {
|
|
4663
|
-
model.dispose();
|
|
4664
|
-
}
|
|
4665
|
-
}
|
|
4666
|
-
while (this._models.length > 0) {
|
|
4667
|
-
this._models.shift();
|
|
4668
|
-
}
|
|
4738
|
+
this.clearModels();
|
|
4669
4739
|
const variantsToCreate = await this.mapStateToVariant(this.state);
|
|
4670
4740
|
this._variants = variantsToCreate;
|
|
4671
4741
|
for (let blockStateVariant of variantsToCreate) {
|
|
@@ -4716,6 +4786,7 @@ var BlockObject = class _BlockObject extends SceneObject {
|
|
|
4716
4786
|
this._instanceCounter = 1;
|
|
4717
4787
|
}
|
|
4718
4788
|
obj.setRotation(rotation);
|
|
4789
|
+
obj.setPosition(this.position);
|
|
4719
4790
|
return obj;
|
|
4720
4791
|
}
|
|
4721
4792
|
async resetState() {
|