minerender 2.1.0-alpha.47 → 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 +37 -5
- package/dist/browser/index.d.ts +37 -5
- package/dist/browser/index.js +280 -145
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/index.mjs +155 -20
- package/dist/browser/index.mjs.map +1 -1
- package/dist/bundle.js +249 -3
- package/dist/bundle.js.map +1 -1
- package/dist/node/index.d.mts +37 -5
- package/dist/node/index.d.ts +37 -5
- package/dist/node/index.js +282 -145
- package/dist/node/index.js.map +1 -1
- package/dist/node/index.mjs +155 -20
- package/dist/node/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/node/index.mjs
CHANGED
|
@@ -843,7 +843,7 @@ var init_Textures = __esm({
|
|
|
843
843
|
});
|
|
844
844
|
|
|
845
845
|
// src/Materials.ts
|
|
846
|
-
import { Color, DoubleSide, FrontSide, MeshBasicMaterial, MeshStandardMaterial, ShaderMaterial } from "three";
|
|
846
|
+
import { Color, DoubleSide, FrontSide, MeshBasicMaterial, MeshStandardMaterial, ShaderChunk, ShaderMaterial } from "three";
|
|
847
847
|
var Materials;
|
|
848
848
|
var init_Materials = __esm({
|
|
849
849
|
"src/Materials.ts"() {
|
|
@@ -885,6 +885,31 @@ var init_Materials = __esm({
|
|
|
885
885
|
alphaTest: 0.5
|
|
886
886
|
});
|
|
887
887
|
}
|
|
888
|
+
static createGuiCanvasMaterial(canvas) {
|
|
889
|
+
const material = new MeshBasicMaterial({
|
|
890
|
+
map: Textures.createCanvasTexture(canvas),
|
|
891
|
+
transparent: true,
|
|
892
|
+
depthWrite: false,
|
|
893
|
+
side: DoubleSide,
|
|
894
|
+
toneMapped: false
|
|
895
|
+
});
|
|
896
|
+
material.onBeforeCompile = (shader) => {
|
|
897
|
+
for (const [stage, direction] of [["vertex", "out"], ["fragment", "in"]]) {
|
|
898
|
+
const chunk = `uv_pars_${stage}`;
|
|
899
|
+
shader[`${stage}Shader`] = shader[`${stage}Shader`].replace(
|
|
900
|
+
`#include <${chunk}>`,
|
|
901
|
+
ShaderChunk[chunk].replace("varying vec2 vMapUv;", `
|
|
902
|
+
#if __VERSION__ >= 300
|
|
903
|
+
centroid ${direction} vec2 vMapUv;
|
|
904
|
+
#else
|
|
905
|
+
varying vec2 vMapUv;
|
|
906
|
+
#endif
|
|
907
|
+
`)
|
|
908
|
+
);
|
|
909
|
+
}
|
|
910
|
+
};
|
|
911
|
+
return material;
|
|
912
|
+
}
|
|
888
913
|
static createShadedCanvasMaterial(canvas, transparent = false, shade = false) {
|
|
889
914
|
const vertShader = `
|
|
890
915
|
uniform bool SHADE;
|
|
@@ -3073,6 +3098,10 @@ var init_SceneObject = __esm({
|
|
|
3073
3098
|
async init() {
|
|
3074
3099
|
}
|
|
3075
3100
|
notifyDirty() {
|
|
3101
|
+
this.traverseAncestors((parent) => {
|
|
3102
|
+
const scene = parent;
|
|
3103
|
+
if (scene.isMineRenderScene) scene.dirty = true;
|
|
3104
|
+
});
|
|
3076
3105
|
this.dispatchEvent(changeEvent);
|
|
3077
3106
|
}
|
|
3078
3107
|
//<editor-fold desc="GROUPS">
|
|
@@ -3416,6 +3445,7 @@ var init_SceneObject = __esm({
|
|
|
3416
3445
|
} else {
|
|
3417
3446
|
object.visible = !object.visible;
|
|
3418
3447
|
}
|
|
3448
|
+
this.notifyDirty();
|
|
3419
3449
|
return object.visible;
|
|
3420
3450
|
}
|
|
3421
3451
|
this.notifyDirty();
|
|
@@ -3448,8 +3478,8 @@ var init_SceneObject = __esm({
|
|
|
3448
3478
|
this.notifyDirty();
|
|
3449
3479
|
}
|
|
3450
3480
|
removeFromScene() {
|
|
3451
|
-
this._scene?.remove(this);
|
|
3452
3481
|
this.notifyDirty();
|
|
3482
|
+
this.removeFromParent();
|
|
3453
3483
|
}
|
|
3454
3484
|
//</editor-fold>
|
|
3455
3485
|
};
|
|
@@ -4927,11 +4957,100 @@ function isEntityObject(obj) {
|
|
|
4927
4957
|
// src/error/index.ts
|
|
4928
4958
|
init_MineRenderError();
|
|
4929
4959
|
|
|
4960
|
+
// src/gui/GuiHelper.ts
|
|
4961
|
+
var GuiHelper = class {
|
|
4962
|
+
static inventorySlot(slot, origin = [0, 0], offset = [18, 18], rowSize = 9) {
|
|
4963
|
+
const [column, row] = typeof slot === "number" ? [slot % rowSize, Math.floor(slot / rowSize)] : slot;
|
|
4964
|
+
return [origin[0] + column * offset[0], origin[1] + row * offset[1]];
|
|
4965
|
+
}
|
|
4966
|
+
};
|
|
4967
|
+
|
|
4930
4968
|
// src/gui/scene/GuiObject.ts
|
|
4969
|
+
init_AssetKey();
|
|
4970
|
+
init_ModelTextures();
|
|
4971
|
+
init_Caching();
|
|
4931
4972
|
init_SceneObject();
|
|
4973
|
+
init_Materials();
|
|
4974
|
+
import { Box2, Mesh as Mesh4, PlaneGeometry, Vector2 as Vector22 } from "three";
|
|
4932
4975
|
var GuiObject = class extends SceneObject {
|
|
4933
|
-
|
|
4976
|
+
constructor(textureLayers, options) {
|
|
4977
|
+
super({ ...options, instanceMeshes: false, mergeMeshes: false });
|
|
4978
|
+
this.textureLayers = textureLayers;
|
|
4979
|
+
this.isGuiObject = true;
|
|
4980
|
+
/** Local bounds in GUI pixels, with y growing down from the origin. */
|
|
4981
|
+
this.bounds = new Box2();
|
|
4982
|
+
this.geometries = /* @__PURE__ */ new Set();
|
|
4983
|
+
this.ownedMaterials = /* @__PURE__ */ new Set();
|
|
4984
|
+
this.initialized = false;
|
|
4985
|
+
}
|
|
4986
|
+
async init() {
|
|
4987
|
+
if (this.initialized) return;
|
|
4988
|
+
try {
|
|
4989
|
+
for (const [index, layer] of this.textureLayers.entries()) {
|
|
4990
|
+
const key = typeof layer.texture === "string" ? AssetKey.parse("textures", layer.texture) : layer.texture;
|
|
4991
|
+
const material = await this.loadMaterial(key);
|
|
4992
|
+
const image = material.map.image;
|
|
4993
|
+
const [cropX, cropY, cropWidth, cropHeight] = layer.crop ?? [0, 0, image.width, image.height];
|
|
4994
|
+
const [width, height] = layer.size ?? [cropWidth, cropHeight];
|
|
4995
|
+
const [x, y] = layer.position ?? [0, 0];
|
|
4996
|
+
const geometry = new PlaneGeometry(width, height);
|
|
4997
|
+
this.geometries.add(geometry);
|
|
4998
|
+
const uv = geometry.getAttribute("uv");
|
|
4999
|
+
for (let i = 0; i < uv.count; i++) {
|
|
5000
|
+
uv.setXY(
|
|
5001
|
+
i,
|
|
5002
|
+
(cropX + uv.getX(i) * cropWidth) / image.width,
|
|
5003
|
+
1 - (cropY + (1 - uv.getY(i)) * cropHeight) / image.height
|
|
5004
|
+
);
|
|
5005
|
+
}
|
|
5006
|
+
const mesh = new Mesh4(geometry, material);
|
|
5007
|
+
mesh.name = `mesh:${layer.name ?? index}`;
|
|
5008
|
+
mesh.position.set(x + width / 2, -y - height / 2, 0);
|
|
5009
|
+
mesh.renderOrder = index;
|
|
5010
|
+
this.add(mesh);
|
|
5011
|
+
this.bounds.expandByPoint(new Vector22(x, y));
|
|
5012
|
+
this.bounds.expandByPoint(new Vector22(x + width, y + height));
|
|
5013
|
+
}
|
|
5014
|
+
this.initialized = true;
|
|
5015
|
+
this.notifyDirty();
|
|
5016
|
+
} catch (error) {
|
|
5017
|
+
this.disposeAndRemoveAllChildren();
|
|
5018
|
+
throw error;
|
|
5019
|
+
}
|
|
5020
|
+
}
|
|
5021
|
+
async loadMaterial(key) {
|
|
5022
|
+
const assetKey = key.serialize();
|
|
5023
|
+
const materialKey = `gui:${assetKey}`;
|
|
5024
|
+
const cached2 = Caching.materialCache.getIfPresent(materialKey);
|
|
5025
|
+
if (cached2) return cached2;
|
|
5026
|
+
const pending = ModelTextures.get(key);
|
|
5027
|
+
const cachedAsset = Caching.textureAssetCache.getIfPresent(assetKey);
|
|
5028
|
+
const image = await pending;
|
|
5029
|
+
if (!image) throw new Error(`Could not load GUI texture ${key.toNamespacedString()}`);
|
|
5030
|
+
const create = () => Materials.createGuiCanvasMaterial(image.data.canvas);
|
|
5031
|
+
if (cachedAsset && Caching.textureAssetCache.getIfPresent(assetKey) === cachedAsset) {
|
|
5032
|
+
return Caching.materialCache.get(materialKey, create);
|
|
5033
|
+
}
|
|
5034
|
+
const material = create();
|
|
5035
|
+
this.ownedMaterials.add(material);
|
|
5036
|
+
return material;
|
|
5037
|
+
}
|
|
5038
|
+
disposeAndRemoveAllChildren() {
|
|
5039
|
+
for (const geometry of this.geometries) geometry.dispose();
|
|
5040
|
+
this.geometries.clear();
|
|
5041
|
+
for (const material of this.ownedMaterials) {
|
|
5042
|
+
material.map.dispose();
|
|
5043
|
+
material.dispose();
|
|
5044
|
+
}
|
|
5045
|
+
this.ownedMaterials.clear();
|
|
5046
|
+
this.bounds.makeEmpty();
|
|
5047
|
+
this.initialized = false;
|
|
5048
|
+
super.disposeAndRemoveAllChildren();
|
|
5049
|
+
}
|
|
4934
5050
|
};
|
|
5051
|
+
function isGuiObject(obj) {
|
|
5052
|
+
return obj.isGuiObject;
|
|
5053
|
+
}
|
|
4935
5054
|
|
|
4936
5055
|
// src/index.ts
|
|
4937
5056
|
init_image();
|
|
@@ -4939,7 +5058,7 @@ init_image();
|
|
|
4939
5058
|
// src/inspector/SceneInspector.ts
|
|
4940
5059
|
init_SceneObject();
|
|
4941
5060
|
init_util();
|
|
4942
|
-
import { Raycaster, Vector2 as
|
|
5061
|
+
import { Raycaster, Vector2 as Vector23 } from "three";
|
|
4943
5062
|
init_log();
|
|
4944
5063
|
init_three();
|
|
4945
5064
|
var p7 = prefix("SceneInspector");
|
|
@@ -4947,7 +5066,7 @@ var help = "<span>Ctrl/Cmd+Click to Select<br/></span><br/>";
|
|
|
4947
5066
|
var SceneInspector = class {
|
|
4948
5067
|
constructor(renderer) {
|
|
4949
5068
|
this.renderer = renderer;
|
|
4950
|
-
this.mouse = new
|
|
5069
|
+
this.mouse = new Vector23();
|
|
4951
5070
|
this.listeners = new AbortController();
|
|
4952
5071
|
this.objectInfoContainer = document.createElement("div");
|
|
4953
5072
|
this.objectControlsContainer = document.createElement("div");
|
|
@@ -8421,7 +8540,7 @@ init_util();
|
|
|
8421
8540
|
init_Caching();
|
|
8422
8541
|
init_CacheKey();
|
|
8423
8542
|
init_MineRenderError();
|
|
8424
|
-
import { DataTexture, DoubleSide as DoubleSide3, FrontSide as FrontSide2, MeshBasicMaterial as
|
|
8543
|
+
import { DataTexture, DoubleSide as DoubleSide3, FrontSide as FrontSide2, MeshBasicMaterial as MeshBasicMaterial4, SRGBColorSpace as SRGBColorSpace3 } from "three";
|
|
8425
8544
|
|
|
8426
8545
|
// src/skin/SkinImage.ts
|
|
8427
8546
|
init_Caching();
|
|
@@ -8506,7 +8625,7 @@ var SkinTextures = class {
|
|
|
8506
8625
|
texture.colorSpace = SRGBColorSpace3;
|
|
8507
8626
|
texture.flipY = true;
|
|
8508
8627
|
texture.needsUpdate = true;
|
|
8509
|
-
return new
|
|
8628
|
+
return new MeshBasicMaterial4({ map: texture, transparent, side: transparent ? DoubleSide3 : FrontSide2, alphaTest: transparent ? 0.1 : 0 });
|
|
8510
8629
|
}
|
|
8511
8630
|
static isSlim(image, scale) {
|
|
8512
8631
|
for (const [x, y] of [[46, 52], [54, 20]]) {
|
|
@@ -8852,6 +8971,14 @@ var MineRenderScene = class _MineRenderScene extends Scene2 {
|
|
|
8852
8971
|
async addEntity(entity, options, parent = this) {
|
|
8853
8972
|
return this.addSceneObject(entity, () => new EntityObject(entity, options), options, parent);
|
|
8854
8973
|
}
|
|
8974
|
+
async addGui(layers, options, parent = this) {
|
|
8975
|
+
const obj = new GuiObject(layers, options);
|
|
8976
|
+
obj.scene = this;
|
|
8977
|
+
await obj.init();
|
|
8978
|
+
parent.add(obj);
|
|
8979
|
+
this.dirty = true;
|
|
8980
|
+
return obj;
|
|
8981
|
+
}
|
|
8855
8982
|
};
|
|
8856
8983
|
function isMineRenderScene(obj) {
|
|
8857
8984
|
return obj.isMineRenderScene;
|
|
@@ -8872,7 +8999,7 @@ import {
|
|
|
8872
8999
|
Quaternion as Quaternion5,
|
|
8873
9000
|
Spherical,
|
|
8874
9001
|
TOUCH,
|
|
8875
|
-
Vector2 as
|
|
9002
|
+
Vector2 as Vector24,
|
|
8876
9003
|
Vector3 as Vector39
|
|
8877
9004
|
} from "three";
|
|
8878
9005
|
var _changeEvent = { type: "change" };
|
|
@@ -9034,15 +9161,15 @@ var OrbitControls = class extends EventDispatcher {
|
|
|
9034
9161
|
let scale = 1;
|
|
9035
9162
|
const panOffset = new Vector39();
|
|
9036
9163
|
let zoomChanged = false;
|
|
9037
|
-
const rotateStart = new
|
|
9038
|
-
const rotateEnd = new
|
|
9039
|
-
const rotateDelta = new
|
|
9040
|
-
const panStart = new
|
|
9041
|
-
const panEnd = new
|
|
9042
|
-
const panDelta = new
|
|
9043
|
-
const dollyStart = new
|
|
9044
|
-
const dollyEnd = new
|
|
9045
|
-
const dollyDelta = new
|
|
9164
|
+
const rotateStart = new Vector24();
|
|
9165
|
+
const rotateEnd = new Vector24();
|
|
9166
|
+
const rotateDelta = new Vector24();
|
|
9167
|
+
const panStart = new Vector24();
|
|
9168
|
+
const panEnd = new Vector24();
|
|
9169
|
+
const panDelta = new Vector24();
|
|
9170
|
+
const dollyStart = new Vector24();
|
|
9171
|
+
const dollyEnd = new Vector24();
|
|
9172
|
+
const dollyDelta = new Vector24();
|
|
9046
9173
|
const pointers = [];
|
|
9047
9174
|
const pointerPositions = {};
|
|
9048
9175
|
function getAutoRotationAngle() {
|
|
@@ -9488,7 +9615,7 @@ var OrbitControls = class extends EventDispatcher {
|
|
|
9488
9615
|
function trackPointer(event) {
|
|
9489
9616
|
let position = pointerPositions[event.pointerId];
|
|
9490
9617
|
if (position === void 0) {
|
|
9491
|
-
position = new
|
|
9618
|
+
position = new Vector24();
|
|
9492
9619
|
pointerPositions[event.pointerId] = position;
|
|
9493
9620
|
}
|
|
9494
9621
|
position.set(event.pageX, event.pageY);
|
|
@@ -9527,6 +9654,10 @@ var Renderer = class _Renderer {
|
|
|
9527
9654
|
this._dirty = true;
|
|
9528
9655
|
};
|
|
9529
9656
|
this.options = (0, import_ts_deepmerge9.default)({}, _Renderer.DEFAULT_OPTIONS, options ?? {});
|
|
9657
|
+
const pixelRatio = this.options.render.pixelRatio ?? 1;
|
|
9658
|
+
if (!Number.isFinite(pixelRatio) || pixelRatio <= 0) {
|
|
9659
|
+
throw new RangeError("render.pixelRatio must be a finite positive number");
|
|
9660
|
+
}
|
|
9530
9661
|
this._animationLoop = this.animate.bind(this);
|
|
9531
9662
|
this._frameInterval = this.options.render.fpsLimit > 0 ? 1e3 / this.options.render.fpsLimit : void 0;
|
|
9532
9663
|
this._scene = this.createScene();
|
|
@@ -9561,6 +9692,7 @@ var Renderer = class _Renderer {
|
|
|
9561
9692
|
},
|
|
9562
9693
|
render: {
|
|
9563
9694
|
fpsLimit: 60,
|
|
9695
|
+
pixelRatio: 1,
|
|
9564
9696
|
stats: false,
|
|
9565
9697
|
antialias: true,
|
|
9566
9698
|
shade: true,
|
|
@@ -9615,6 +9747,7 @@ var Renderer = class _Renderer {
|
|
|
9615
9747
|
renderer.shadowMap.enabled = true;
|
|
9616
9748
|
renderer.shadowMap.type = PCFSoftShadowMap;
|
|
9617
9749
|
renderer.outputColorSpace = SRGBColorSpace4;
|
|
9750
|
+
renderer.setPixelRatio(this.options.render.pixelRatio ?? 1);
|
|
9618
9751
|
renderer.setSize(this.viewWidth, this.viewHeight);
|
|
9619
9752
|
return renderer;
|
|
9620
9753
|
}
|
|
@@ -10619,7 +10752,7 @@ var MineRenderWorld = class {
|
|
|
10619
10752
|
// src/world/SectionMesh.ts
|
|
10620
10753
|
init_CanvasCompat();
|
|
10621
10754
|
init_Materials();
|
|
10622
|
-
import { BufferGeometry as BufferGeometry4, Float32BufferAttribute as Float32BufferAttribute5, Group, Mesh as
|
|
10755
|
+
import { BufferGeometry as BufferGeometry4, Float32BufferAttribute as Float32BufferAttribute5, Group, Mesh as Mesh8 } from "three";
|
|
10623
10756
|
var SectionMesh = class _SectionMesh extends Group {
|
|
10624
10757
|
constructor() {
|
|
10625
10758
|
super(...arguments);
|
|
@@ -10704,7 +10837,7 @@ var SectionMesh = class _SectionMesh extends Group {
|
|
|
10704
10837
|
const material = Materials.createShadedCanvasMaterial(canvas, false);
|
|
10705
10838
|
material.vertexColors = true;
|
|
10706
10839
|
const texture = material.uniforms?.map?.value ?? material.map;
|
|
10707
|
-
const mesh = new
|
|
10840
|
+
const mesh = new Mesh8(geometry, material);
|
|
10708
10841
|
section.add(mesh);
|
|
10709
10842
|
section.ownedMeshes.push({ mesh, texture });
|
|
10710
10843
|
}
|
|
@@ -10916,6 +11049,7 @@ export {
|
|
|
10916
11049
|
Env,
|
|
10917
11050
|
FluidModelObject,
|
|
10918
11051
|
Geometries,
|
|
11052
|
+
GuiHelper,
|
|
10919
11053
|
GuiLight,
|
|
10920
11054
|
GuiObject,
|
|
10921
11055
|
HostedAssetSource,
|
|
@@ -10995,6 +11129,7 @@ export {
|
|
|
10995
11129
|
isDisposable,
|
|
10996
11130
|
isDoubleArray,
|
|
10997
11131
|
isEntityObject,
|
|
11132
|
+
isGuiObject,
|
|
10998
11133
|
isInstanceManager,
|
|
10999
11134
|
isInstanceReference,
|
|
11000
11135
|
isInstanceable,
|