minerender 2.1.0-alpha.48 → 2.1.0-alpha.49
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 +35 -5
- package/dist/browser/index.d.ts +35 -5
- package/dist/browser/index.js +274 -145
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/index.mjs +149 -20
- package/dist/browser/index.mjs.map +1 -1
- package/dist/bundle.js +243 -3
- package/dist/bundle.js.map +1 -1
- package/dist/node/index.d.mts +35 -5
- package/dist/node/index.d.ts +35 -5
- package/dist/node/index.js +276 -145
- package/dist/node/index.js.map +1 -1
- package/dist/node/index.mjs +149 -20
- package/dist/node/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/browser/index.mjs
CHANGED
|
@@ -799,7 +799,7 @@ var init_Textures = __esm({
|
|
|
799
799
|
});
|
|
800
800
|
|
|
801
801
|
// src/Materials.ts
|
|
802
|
-
import { Color, DoubleSide, FrontSide, MeshBasicMaterial, MeshStandardMaterial, ShaderMaterial } from "three";
|
|
802
|
+
import { Color, DoubleSide, FrontSide, MeshBasicMaterial, MeshStandardMaterial, ShaderChunk, ShaderMaterial } from "three";
|
|
803
803
|
var _Materials, Materials;
|
|
804
804
|
var init_Materials = __esm({
|
|
805
805
|
"src/Materials.ts"() {
|
|
@@ -838,6 +838,31 @@ var init_Materials = __esm({
|
|
|
838
838
|
alphaTest: 0.5
|
|
839
839
|
});
|
|
840
840
|
}
|
|
841
|
+
static createGuiCanvasMaterial(canvas) {
|
|
842
|
+
const material = new MeshBasicMaterial({
|
|
843
|
+
map: Textures.createCanvasTexture(canvas),
|
|
844
|
+
transparent: true,
|
|
845
|
+
depthWrite: false,
|
|
846
|
+
side: DoubleSide,
|
|
847
|
+
toneMapped: false
|
|
848
|
+
});
|
|
849
|
+
material.onBeforeCompile = (shader) => {
|
|
850
|
+
for (const [stage, direction] of [["vertex", "out"], ["fragment", "in"]]) {
|
|
851
|
+
const chunk = `uv_pars_${stage}`;
|
|
852
|
+
shader[`${stage}Shader`] = shader[`${stage}Shader`].replace(
|
|
853
|
+
`#include <${chunk}>`,
|
|
854
|
+
ShaderChunk[chunk].replace("varying vec2 vMapUv;", `
|
|
855
|
+
#if __VERSION__ >= 300
|
|
856
|
+
centroid ${direction} vec2 vMapUv;
|
|
857
|
+
#else
|
|
858
|
+
varying vec2 vMapUv;
|
|
859
|
+
#endif
|
|
860
|
+
`)
|
|
861
|
+
);
|
|
862
|
+
}
|
|
863
|
+
};
|
|
864
|
+
return material;
|
|
865
|
+
}
|
|
841
866
|
static createShadedCanvasMaterial(canvas, transparent = false, shade = false) {
|
|
842
867
|
const vertShader = `
|
|
843
868
|
uniform bool SHADE;
|
|
@@ -2983,6 +3008,10 @@ var init_SceneObject = __esm({
|
|
|
2983
3008
|
async init() {
|
|
2984
3009
|
}
|
|
2985
3010
|
notifyDirty() {
|
|
3011
|
+
this.traverseAncestors((parent) => {
|
|
3012
|
+
const scene = parent;
|
|
3013
|
+
if (scene.isMineRenderScene) scene.dirty = true;
|
|
3014
|
+
});
|
|
2986
3015
|
this.dispatchEvent(changeEvent);
|
|
2987
3016
|
}
|
|
2988
3017
|
//<editor-fold desc="GROUPS">
|
|
@@ -3326,6 +3355,7 @@ var init_SceneObject = __esm({
|
|
|
3326
3355
|
} else {
|
|
3327
3356
|
object.visible = !object.visible;
|
|
3328
3357
|
}
|
|
3358
|
+
this.notifyDirty();
|
|
3329
3359
|
return object.visible;
|
|
3330
3360
|
}
|
|
3331
3361
|
this.notifyDirty();
|
|
@@ -3358,8 +3388,8 @@ var init_SceneObject = __esm({
|
|
|
3358
3388
|
this.notifyDirty();
|
|
3359
3389
|
}
|
|
3360
3390
|
removeFromScene() {
|
|
3361
|
-
this._scene?.remove(this);
|
|
3362
3391
|
this.notifyDirty();
|
|
3392
|
+
this.removeFromParent();
|
|
3363
3393
|
}
|
|
3364
3394
|
//</editor-fold>
|
|
3365
3395
|
};
|
|
@@ -4880,11 +4910,100 @@ function isEntityObject(obj) {
|
|
|
4880
4910
|
// src/error/index.ts
|
|
4881
4911
|
init_MineRenderError();
|
|
4882
4912
|
|
|
4913
|
+
// src/gui/GuiHelper.ts
|
|
4914
|
+
var GuiHelper = class {
|
|
4915
|
+
static inventorySlot(slot, origin = [0, 0], offset = [18, 18], rowSize = 9) {
|
|
4916
|
+
const [column, row] = typeof slot === "number" ? [slot % rowSize, Math.floor(slot / rowSize)] : slot;
|
|
4917
|
+
return [origin[0] + column * offset[0], origin[1] + row * offset[1]];
|
|
4918
|
+
}
|
|
4919
|
+
};
|
|
4920
|
+
|
|
4883
4921
|
// src/gui/scene/GuiObject.ts
|
|
4922
|
+
init_AssetKey();
|
|
4923
|
+
init_ModelTextures();
|
|
4924
|
+
init_Caching();
|
|
4884
4925
|
init_SceneObject();
|
|
4926
|
+
init_Materials();
|
|
4927
|
+
import { Box2, Mesh as Mesh4, PlaneGeometry, Vector2 as Vector22 } from "three";
|
|
4885
4928
|
var GuiObject = class extends SceneObject {
|
|
4886
|
-
|
|
4929
|
+
constructor(textureLayers, options) {
|
|
4930
|
+
super({ ...options, instanceMeshes: false, mergeMeshes: false });
|
|
4931
|
+
this.textureLayers = textureLayers;
|
|
4932
|
+
this.isGuiObject = true;
|
|
4933
|
+
/** Local bounds in GUI pixels, with y growing down from the origin. */
|
|
4934
|
+
this.bounds = new Box2();
|
|
4935
|
+
this.geometries = /* @__PURE__ */ new Set();
|
|
4936
|
+
this.ownedMaterials = /* @__PURE__ */ new Set();
|
|
4937
|
+
this.initialized = false;
|
|
4938
|
+
}
|
|
4939
|
+
async init() {
|
|
4940
|
+
if (this.initialized) return;
|
|
4941
|
+
try {
|
|
4942
|
+
for (const [index, layer] of this.textureLayers.entries()) {
|
|
4943
|
+
const key = typeof layer.texture === "string" ? AssetKey.parse("textures", layer.texture) : layer.texture;
|
|
4944
|
+
const material = await this.loadMaterial(key);
|
|
4945
|
+
const image = material.map.image;
|
|
4946
|
+
const [cropX, cropY, cropWidth, cropHeight] = layer.crop ?? [0, 0, image.width, image.height];
|
|
4947
|
+
const [width, height] = layer.size ?? [cropWidth, cropHeight];
|
|
4948
|
+
const [x, y] = layer.position ?? [0, 0];
|
|
4949
|
+
const geometry = new PlaneGeometry(width, height);
|
|
4950
|
+
this.geometries.add(geometry);
|
|
4951
|
+
const uv = geometry.getAttribute("uv");
|
|
4952
|
+
for (let i = 0; i < uv.count; i++) {
|
|
4953
|
+
uv.setXY(
|
|
4954
|
+
i,
|
|
4955
|
+
(cropX + uv.getX(i) * cropWidth) / image.width,
|
|
4956
|
+
1 - (cropY + (1 - uv.getY(i)) * cropHeight) / image.height
|
|
4957
|
+
);
|
|
4958
|
+
}
|
|
4959
|
+
const mesh = new Mesh4(geometry, material);
|
|
4960
|
+
mesh.name = `mesh:${layer.name ?? index}`;
|
|
4961
|
+
mesh.position.set(x + width / 2, -y - height / 2, 0);
|
|
4962
|
+
mesh.renderOrder = index;
|
|
4963
|
+
this.add(mesh);
|
|
4964
|
+
this.bounds.expandByPoint(new Vector22(x, y));
|
|
4965
|
+
this.bounds.expandByPoint(new Vector22(x + width, y + height));
|
|
4966
|
+
}
|
|
4967
|
+
this.initialized = true;
|
|
4968
|
+
this.notifyDirty();
|
|
4969
|
+
} catch (error) {
|
|
4970
|
+
this.disposeAndRemoveAllChildren();
|
|
4971
|
+
throw error;
|
|
4972
|
+
}
|
|
4973
|
+
}
|
|
4974
|
+
async loadMaterial(key) {
|
|
4975
|
+
const assetKey = key.serialize();
|
|
4976
|
+
const materialKey = `gui:${assetKey}`;
|
|
4977
|
+
const cached2 = Caching.materialCache.getIfPresent(materialKey);
|
|
4978
|
+
if (cached2) return cached2;
|
|
4979
|
+
const pending = ModelTextures.get(key);
|
|
4980
|
+
const cachedAsset = Caching.textureAssetCache.getIfPresent(assetKey);
|
|
4981
|
+
const image = await pending;
|
|
4982
|
+
if (!image) throw new Error(`Could not load GUI texture ${key.toNamespacedString()}`);
|
|
4983
|
+
const create = () => Materials.createGuiCanvasMaterial(image.data.canvas);
|
|
4984
|
+
if (cachedAsset && Caching.textureAssetCache.getIfPresent(assetKey) === cachedAsset) {
|
|
4985
|
+
return Caching.materialCache.get(materialKey, create);
|
|
4986
|
+
}
|
|
4987
|
+
const material = create();
|
|
4988
|
+
this.ownedMaterials.add(material);
|
|
4989
|
+
return material;
|
|
4990
|
+
}
|
|
4991
|
+
disposeAndRemoveAllChildren() {
|
|
4992
|
+
for (const geometry of this.geometries) geometry.dispose();
|
|
4993
|
+
this.geometries.clear();
|
|
4994
|
+
for (const material of this.ownedMaterials) {
|
|
4995
|
+
material.map.dispose();
|
|
4996
|
+
material.dispose();
|
|
4997
|
+
}
|
|
4998
|
+
this.ownedMaterials.clear();
|
|
4999
|
+
this.bounds.makeEmpty();
|
|
5000
|
+
this.initialized = false;
|
|
5001
|
+
super.disposeAndRemoveAllChildren();
|
|
5002
|
+
}
|
|
4887
5003
|
};
|
|
5004
|
+
function isGuiObject(obj) {
|
|
5005
|
+
return obj.isGuiObject;
|
|
5006
|
+
}
|
|
4888
5007
|
|
|
4889
5008
|
// src/index.ts
|
|
4890
5009
|
init_image();
|
|
@@ -4892,7 +5011,7 @@ init_image();
|
|
|
4892
5011
|
// src/inspector/SceneInspector.ts
|
|
4893
5012
|
init_SceneObject();
|
|
4894
5013
|
init_util();
|
|
4895
|
-
import { Raycaster, Vector2 as
|
|
5014
|
+
import { Raycaster, Vector2 as Vector23 } from "three";
|
|
4896
5015
|
init_log();
|
|
4897
5016
|
init_three();
|
|
4898
5017
|
var p7 = prefix("SceneInspector");
|
|
@@ -4900,7 +5019,7 @@ var help = "<span>Ctrl/Cmd+Click to Select<br/></span><br/>";
|
|
|
4900
5019
|
var SceneInspector = class {
|
|
4901
5020
|
constructor(renderer) {
|
|
4902
5021
|
this.renderer = renderer;
|
|
4903
|
-
this.mouse = new
|
|
5022
|
+
this.mouse = new Vector23();
|
|
4904
5023
|
this.listeners = new AbortController();
|
|
4905
5024
|
this.objectInfoContainer = document.createElement("div");
|
|
4906
5025
|
this.objectControlsContainer = document.createElement("div");
|
|
@@ -8373,7 +8492,7 @@ init_util();
|
|
|
8373
8492
|
init_Caching();
|
|
8374
8493
|
init_CacheKey();
|
|
8375
8494
|
init_MineRenderError();
|
|
8376
|
-
import { DataTexture, DoubleSide as DoubleSide3, FrontSide as FrontSide2, MeshBasicMaterial as
|
|
8495
|
+
import { DataTexture, DoubleSide as DoubleSide3, FrontSide as FrontSide2, MeshBasicMaterial as MeshBasicMaterial4, SRGBColorSpace as SRGBColorSpace3 } from "three";
|
|
8377
8496
|
|
|
8378
8497
|
// src/skin/SkinImage.ts
|
|
8379
8498
|
init_Caching();
|
|
@@ -8458,7 +8577,7 @@ var SkinTextures = class {
|
|
|
8458
8577
|
texture.colorSpace = SRGBColorSpace3;
|
|
8459
8578
|
texture.flipY = true;
|
|
8460
8579
|
texture.needsUpdate = true;
|
|
8461
|
-
return new
|
|
8580
|
+
return new MeshBasicMaterial4({ map: texture, transparent, side: transparent ? DoubleSide3 : FrontSide2, alphaTest: transparent ? 0.1 : 0 });
|
|
8462
8581
|
}
|
|
8463
8582
|
static isSlim(image, scale) {
|
|
8464
8583
|
for (const [x, y] of [[46, 52], [54, 20]]) {
|
|
@@ -8801,6 +8920,14 @@ var _MineRenderScene = class _MineRenderScene extends Scene2 {
|
|
|
8801
8920
|
async addEntity(entity, options, parent = this) {
|
|
8802
8921
|
return this.addSceneObject(entity, () => new EntityObject(entity, options), options, parent);
|
|
8803
8922
|
}
|
|
8923
|
+
async addGui(layers, options, parent = this) {
|
|
8924
|
+
const obj = new GuiObject(layers, options);
|
|
8925
|
+
obj.scene = this;
|
|
8926
|
+
await obj.init();
|
|
8927
|
+
parent.add(obj);
|
|
8928
|
+
this.dirty = true;
|
|
8929
|
+
return obj;
|
|
8930
|
+
}
|
|
8804
8931
|
};
|
|
8805
8932
|
_MineRenderScene.DEFAULT_OPTIONS = (0, import_ts_deepmerge8.default)({}, {});
|
|
8806
8933
|
var MineRenderScene = _MineRenderScene;
|
|
@@ -8823,7 +8950,7 @@ import {
|
|
|
8823
8950
|
Quaternion as Quaternion5,
|
|
8824
8951
|
Spherical,
|
|
8825
8952
|
TOUCH,
|
|
8826
|
-
Vector2 as
|
|
8953
|
+
Vector2 as Vector24,
|
|
8827
8954
|
Vector3 as Vector39
|
|
8828
8955
|
} from "three";
|
|
8829
8956
|
var _changeEvent = { type: "change" };
|
|
@@ -8985,15 +9112,15 @@ var OrbitControls = class extends EventDispatcher {
|
|
|
8985
9112
|
let scale = 1;
|
|
8986
9113
|
const panOffset = new Vector39();
|
|
8987
9114
|
let zoomChanged = false;
|
|
8988
|
-
const rotateStart = new
|
|
8989
|
-
const rotateEnd = new
|
|
8990
|
-
const rotateDelta = new
|
|
8991
|
-
const panStart = new
|
|
8992
|
-
const panEnd = new
|
|
8993
|
-
const panDelta = new
|
|
8994
|
-
const dollyStart = new
|
|
8995
|
-
const dollyEnd = new
|
|
8996
|
-
const dollyDelta = new
|
|
9115
|
+
const rotateStart = new Vector24();
|
|
9116
|
+
const rotateEnd = new Vector24();
|
|
9117
|
+
const rotateDelta = new Vector24();
|
|
9118
|
+
const panStart = new Vector24();
|
|
9119
|
+
const panEnd = new Vector24();
|
|
9120
|
+
const panDelta = new Vector24();
|
|
9121
|
+
const dollyStart = new Vector24();
|
|
9122
|
+
const dollyEnd = new Vector24();
|
|
9123
|
+
const dollyDelta = new Vector24();
|
|
8997
9124
|
const pointers = [];
|
|
8998
9125
|
const pointerPositions = {};
|
|
8999
9126
|
function getAutoRotationAngle() {
|
|
@@ -9439,7 +9566,7 @@ var OrbitControls = class extends EventDispatcher {
|
|
|
9439
9566
|
function trackPointer(event) {
|
|
9440
9567
|
let position = pointerPositions[event.pointerId];
|
|
9441
9568
|
if (position === void 0) {
|
|
9442
|
-
position = new
|
|
9569
|
+
position = new Vector24();
|
|
9443
9570
|
pointerPositions[event.pointerId] = position;
|
|
9444
9571
|
}
|
|
9445
9572
|
position.set(event.pageX, event.pageY);
|
|
@@ -10575,7 +10702,7 @@ var MineRenderWorld = class {
|
|
|
10575
10702
|
// src/world/SectionMesh.ts
|
|
10576
10703
|
init_CanvasCompat();
|
|
10577
10704
|
init_Materials();
|
|
10578
|
-
import { BufferGeometry as BufferGeometry4, Float32BufferAttribute as Float32BufferAttribute5, Group, Mesh as
|
|
10705
|
+
import { BufferGeometry as BufferGeometry4, Float32BufferAttribute as Float32BufferAttribute5, Group, Mesh as Mesh8 } from "three";
|
|
10579
10706
|
var SectionMesh = class _SectionMesh extends Group {
|
|
10580
10707
|
constructor() {
|
|
10581
10708
|
super(...arguments);
|
|
@@ -10660,7 +10787,7 @@ var SectionMesh = class _SectionMesh extends Group {
|
|
|
10660
10787
|
const material = Materials.createShadedCanvasMaterial(canvas, false);
|
|
10661
10788
|
material.vertexColors = true;
|
|
10662
10789
|
const texture = material.uniforms?.map?.value ?? material.map;
|
|
10663
|
-
const mesh = new
|
|
10790
|
+
const mesh = new Mesh8(geometry, material);
|
|
10664
10791
|
section.add(mesh);
|
|
10665
10792
|
section.ownedMeshes.push({ mesh, texture });
|
|
10666
10793
|
}
|
|
@@ -10874,6 +11001,7 @@ export {
|
|
|
10874
11001
|
Env,
|
|
10875
11002
|
FluidModelObject,
|
|
10876
11003
|
Geometries,
|
|
11004
|
+
GuiHelper,
|
|
10877
11005
|
GuiLight,
|
|
10878
11006
|
GuiObject,
|
|
10879
11007
|
HostedAssetSource,
|
|
@@ -10951,6 +11079,7 @@ export {
|
|
|
10951
11079
|
isDisposable,
|
|
10952
11080
|
isDoubleArray,
|
|
10953
11081
|
isEntityObject,
|
|
11082
|
+
isGuiObject,
|
|
10954
11083
|
isInstanceManager,
|
|
10955
11084
|
isInstanceReference,
|
|
10956
11085
|
isInstanceable,
|