minerender 2.1.0-alpha.18 → 2.1.0-alpha.19
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 +9 -0
- package/dist/browser/index.d.ts +9 -0
- package/dist/browser/index.js +92 -17
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/index.mjs +141 -66
- package/dist/browser/index.mjs.map +1 -1
- package/dist/bundle.js +92 -17
- package/dist/bundle.js.map +1 -1
- package/dist/node/index.d.mts +9 -0
- package/dist/node/index.d.ts +9 -0
- package/dist/node/index.js +92 -17
- package/dist/node/index.js.map +1 -1
- package/dist/node/index.mjs +141 -66
- package/dist/node/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/node/index.d.mts
CHANGED
|
@@ -555,6 +555,7 @@ declare class UVMapper {
|
|
|
555
555
|
static setCubeUvs(geometry: BoxGeometry, originalTextureSize: DoubleArray, actualTextureSize: DoubleArray, faces: ModelFaces): void;
|
|
556
556
|
static facesToUvArray(faces: ModelFaces, originalTextureSize: DoubleArray, actualTextureSize: DoubleArray): number[];
|
|
557
557
|
static facesToUv(faces: ModelFaces, originalTextureSize: DoubleArray, actualTextureSize: DoubleArray): Float32BufferAttribute;
|
|
558
|
+
static lockUvs(geometry: BoxGeometry, faces: ModelFaces, atlas: TextureAtlas, rotation: Euler): void;
|
|
558
559
|
static getAtlas(model: Model): Promise<Maybe<TextureAtlas>>;
|
|
559
560
|
static fillMissingTextureKeys<T>(textures: ModelTextures, target: {
|
|
560
561
|
[k: string]: T;
|
|
@@ -848,6 +849,8 @@ declare class ModelObject extends SceneObject {
|
|
|
848
849
|
protected applyTextures(): void;
|
|
849
850
|
}
|
|
850
851
|
interface ModelObjectOptions extends SceneObjectOptions {
|
|
852
|
+
/** Quarter-turn block rotation in radians to compensate when locking UVs. */
|
|
853
|
+
uvLockRotation?: TripleArray;
|
|
851
854
|
}
|
|
852
855
|
declare function isModelObject(obj: any): obj is ModelObject;
|
|
853
856
|
|
|
@@ -1539,6 +1542,8 @@ declare class Skins {
|
|
|
1539
1542
|
static capeFromUsername(username: string): Promise<Maybe<string>>;
|
|
1540
1543
|
static capeFromCapesDev(uuid: string, capeType?: string): Promise<Maybe<string>>;
|
|
1541
1544
|
private static usernameToUuid;
|
|
1545
|
+
private static usernameToUuidMcProxy;
|
|
1546
|
+
/** @deprecated **/
|
|
1542
1547
|
private static usernameToUuidSkinProxy;
|
|
1543
1548
|
private static usernameToUuidMineTools;
|
|
1544
1549
|
private static getProfileFromMinetools;
|
|
@@ -1548,8 +1553,12 @@ declare class Skins {
|
|
|
1548
1553
|
private static getCrafatarCapeUrl;
|
|
1549
1554
|
private static getMcHeadsSkinUrl;
|
|
1550
1555
|
private static getMineSkinPlayerSkinUrl;
|
|
1556
|
+
/** @deprecated **/
|
|
1551
1557
|
private static getSkinProxySkinUrl;
|
|
1558
|
+
/** @deprecated **/
|
|
1552
1559
|
private static getSkinProxyCapeUrl;
|
|
1560
|
+
private static getMcProxySkinUrl;
|
|
1561
|
+
private static getMcProxyCapeUrl;
|
|
1553
1562
|
}
|
|
1554
1563
|
|
|
1555
1564
|
declare class TextureLoader {
|
package/dist/node/index.d.ts
CHANGED
|
@@ -555,6 +555,7 @@ declare class UVMapper {
|
|
|
555
555
|
static setCubeUvs(geometry: BoxGeometry, originalTextureSize: DoubleArray, actualTextureSize: DoubleArray, faces: ModelFaces): void;
|
|
556
556
|
static facesToUvArray(faces: ModelFaces, originalTextureSize: DoubleArray, actualTextureSize: DoubleArray): number[];
|
|
557
557
|
static facesToUv(faces: ModelFaces, originalTextureSize: DoubleArray, actualTextureSize: DoubleArray): Float32BufferAttribute;
|
|
558
|
+
static lockUvs(geometry: BoxGeometry, faces: ModelFaces, atlas: TextureAtlas, rotation: Euler): void;
|
|
558
559
|
static getAtlas(model: Model): Promise<Maybe<TextureAtlas>>;
|
|
559
560
|
static fillMissingTextureKeys<T>(textures: ModelTextures, target: {
|
|
560
561
|
[k: string]: T;
|
|
@@ -848,6 +849,8 @@ declare class ModelObject extends SceneObject {
|
|
|
848
849
|
protected applyTextures(): void;
|
|
849
850
|
}
|
|
850
851
|
interface ModelObjectOptions extends SceneObjectOptions {
|
|
852
|
+
/** Quarter-turn block rotation in radians to compensate when locking UVs. */
|
|
853
|
+
uvLockRotation?: TripleArray;
|
|
851
854
|
}
|
|
852
855
|
declare function isModelObject(obj: any): obj is ModelObject;
|
|
853
856
|
|
|
@@ -1539,6 +1542,8 @@ declare class Skins {
|
|
|
1539
1542
|
static capeFromUsername(username: string): Promise<Maybe<string>>;
|
|
1540
1543
|
static capeFromCapesDev(uuid: string, capeType?: string): Promise<Maybe<string>>;
|
|
1541
1544
|
private static usernameToUuid;
|
|
1545
|
+
private static usernameToUuidMcProxy;
|
|
1546
|
+
/** @deprecated **/
|
|
1542
1547
|
private static usernameToUuidSkinProxy;
|
|
1543
1548
|
private static usernameToUuidMineTools;
|
|
1544
1549
|
private static getProfileFromMinetools;
|
|
@@ -1548,8 +1553,12 @@ declare class Skins {
|
|
|
1548
1553
|
private static getCrafatarCapeUrl;
|
|
1549
1554
|
private static getMcHeadsSkinUrl;
|
|
1550
1555
|
private static getMineSkinPlayerSkinUrl;
|
|
1556
|
+
/** @deprecated **/
|
|
1551
1557
|
private static getSkinProxySkinUrl;
|
|
1558
|
+
/** @deprecated **/
|
|
1552
1559
|
private static getSkinProxyCapeUrl;
|
|
1560
|
+
private static getMcProxySkinUrl;
|
|
1561
|
+
private static getMcProxyCapeUrl;
|
|
1553
1562
|
}
|
|
1554
1563
|
|
|
1555
1564
|
declare class TextureLoader {
|
package/dist/node/index.js
CHANGED
|
@@ -2246,6 +2246,14 @@ var DEFAULT_UV = [0, 0, 16, 16];
|
|
|
2246
2246
|
var X = 0;
|
|
2247
2247
|
var Y = 1;
|
|
2248
2248
|
var Z = 2;
|
|
2249
|
+
var FACE_UV_AXES = {
|
|
2250
|
+
east: [new import_three8.Vector3(0, 0, -1), new import_three8.Vector3(0, -1, 0)],
|
|
2251
|
+
west: [new import_three8.Vector3(0, 0, 1), new import_three8.Vector3(0, -1, 0)],
|
|
2252
|
+
up: [new import_three8.Vector3(1, 0, 0), new import_three8.Vector3(0, 0, 1)],
|
|
2253
|
+
down: [new import_three8.Vector3(1, 0, 0), new import_three8.Vector3(0, 0, -1)],
|
|
2254
|
+
south: [new import_three8.Vector3(1, 0, 0), new import_three8.Vector3(0, -1, 0)],
|
|
2255
|
+
north: [new import_three8.Vector3(-1, 0, 0), new import_three8.Vector3(0, -1, 0)]
|
|
2256
|
+
};
|
|
2249
2257
|
var UVMapper = class {
|
|
2250
2258
|
static makeUv(uvCoord, originalTextureSize, actualTextureSize) {
|
|
2251
2259
|
if (uvCoord === 0) return 0;
|
|
@@ -2343,6 +2351,42 @@ var UVMapper = class {
|
|
|
2343
2351
|
static facesToUv(faces, originalTextureSize, actualTextureSize) {
|
|
2344
2352
|
return new import_three8.Float32BufferAttribute(this.facesToUvArray(faces, originalTextureSize, actualTextureSize), 2);
|
|
2345
2353
|
}
|
|
2354
|
+
static lockUvs(geometry, faces, atlas, rotation) {
|
|
2355
|
+
const uv = geometry.getAttribute("uv");
|
|
2356
|
+
for (let faceIndex = 0; faceIndex < CUBE_FACES.length; faceIndex++) {
|
|
2357
|
+
const faceName = CUBE_FACES[faceIndex];
|
|
2358
|
+
const texture = faces[faceName]?.texture?.substring(1);
|
|
2359
|
+
const position = texture && atlas.positions[texture];
|
|
2360
|
+
const size = texture && atlas.sizes[texture];
|
|
2361
|
+
if (!position || !size) continue;
|
|
2362
|
+
const [sourceU, sourceV] = FACE_UV_AXES[faceName];
|
|
2363
|
+
const uAxis = sourceU.clone().applyEuler(rotation);
|
|
2364
|
+
const vAxis = sourceV.clone().applyEuler(rotation);
|
|
2365
|
+
const normal = vAxis.clone().cross(uAxis);
|
|
2366
|
+
const targetFace = CUBE_FACES.find((name) => {
|
|
2367
|
+
const [u, v] = FACE_UV_AXES[name];
|
|
2368
|
+
return v.clone().cross(u).dot(normal) > 0.5;
|
|
2369
|
+
});
|
|
2370
|
+
const [targetU, targetV] = FACE_UV_AXES[targetFace];
|
|
2371
|
+
const uu = Math.round(targetU.dot(uAxis));
|
|
2372
|
+
const uvCross = Math.round(targetU.dot(vAxis));
|
|
2373
|
+
const vu = Math.round(targetV.dot(uAxis));
|
|
2374
|
+
const vv = Math.round(targetV.dot(vAxis));
|
|
2375
|
+
for (let corner = 0; corner < 4; corner++) {
|
|
2376
|
+
const index = faceIndex * 4 + corner;
|
|
2377
|
+
const u = (uv.getX(index) * atlas.image.width - position[0]) / size[0] - 0.5;
|
|
2378
|
+
const v = ((1 - uv.getY(index)) * atlas.image.height - position[1]) / size[1] - 0.5;
|
|
2379
|
+
const lockedU = uu * u + uvCross * v + 0.5;
|
|
2380
|
+
const lockedV = vu * u + vv * v + 0.5;
|
|
2381
|
+
uv.setXY(
|
|
2382
|
+
index,
|
|
2383
|
+
(position[0] + lockedU * size[0]) / atlas.image.width,
|
|
2384
|
+
1 - (position[1] + lockedV * size[1]) / atlas.image.height
|
|
2385
|
+
);
|
|
2386
|
+
}
|
|
2387
|
+
}
|
|
2388
|
+
uv.needsUpdate = true;
|
|
2389
|
+
}
|
|
2346
2390
|
static async getAtlas(model) {
|
|
2347
2391
|
const keyStr = model.key.serialize();
|
|
2348
2392
|
return Caching.modelTextureAtlasCache.get(keyStr, (k) => {
|
|
@@ -2957,6 +3001,7 @@ var SceneObject = class _SceneObject extends import_three9.Object3D {
|
|
|
2957
3001
|
}
|
|
2958
3002
|
createInstancedMesh(name, geometry, material, count) {
|
|
2959
3003
|
const mesh = new import_three9.InstancedMesh(geometry, material, count);
|
|
3004
|
+
mesh.count = 0;
|
|
2960
3005
|
if (name) {
|
|
2961
3006
|
mesh.name = `mesh:${name}`;
|
|
2962
3007
|
}
|
|
@@ -3034,6 +3079,10 @@ var SceneObject = class _SceneObject extends import_three9.Object3D {
|
|
|
3034
3079
|
if (!this.isInstanced) throw new MineRenderError("Object is not instanced");
|
|
3035
3080
|
const i = this._instanceCounter++;
|
|
3036
3081
|
this.setMatrixAt(i, new import_three9.Matrix4());
|
|
3082
|
+
const mesh = this.children[0];
|
|
3083
|
+
if (mesh && isInstancedMesh(mesh)) {
|
|
3084
|
+
mesh.count = Math.min(this._instanceCounter, mesh.instanceMatrix.count);
|
|
3085
|
+
}
|
|
3037
3086
|
console.debug(p6, "nextInstance " + i);
|
|
3038
3087
|
if (i === this.options.maxInstanceCount) {
|
|
3039
3088
|
console.warn(p6, "Max instance count reached for " + this);
|
|
@@ -4334,6 +4383,9 @@ var ModelObject = class _ModelObject extends SceneObject {
|
|
|
4334
4383
|
if (this.atlas.model.elements) {
|
|
4335
4384
|
this.atlas.model.elements?.forEach((el) => {
|
|
4336
4385
|
const elGeo = this._getBoxGeometryFromElement(el).clone();
|
|
4386
|
+
if (this.options.uvLockRotation) {
|
|
4387
|
+
UVMapper.lockUvs(elGeo, el.faces, this.atlas, new import_three15.Euler(...this.options.uvLockRotation));
|
|
4388
|
+
}
|
|
4337
4389
|
elGeo.applyMatrix4(new import_three15.Matrix4().makeTranslation((el.to[0] - el.from[0]) / 2, (el.to[1] - el.from[1]) / 2, (el.to[2] - el.from[2]) / 2));
|
|
4338
4390
|
elGeo.applyMatrix4(new import_three15.Matrix4().makeTranslation(el.from[0], el.from[1], el.from[2]));
|
|
4339
4391
|
if (el.rotation) {
|
|
@@ -4571,25 +4623,24 @@ var BlockObject = class _BlockObject extends SceneObject {
|
|
|
4571
4623
|
await this.createVariant(variant);
|
|
4572
4624
|
}
|
|
4573
4625
|
async createVariant(variant) {
|
|
4574
|
-
const
|
|
4575
|
-
const obj = await this.scene.addModel(model, this.options);
|
|
4576
|
-
if (isInstanceReference(obj) || obj.isInstanced) {
|
|
4577
|
-
this._isInstanced = true;
|
|
4578
|
-
this._instanceCounter = 1;
|
|
4579
|
-
}
|
|
4580
|
-
let rotation = new import_three16.Euler(0, 0, 0);
|
|
4626
|
+
const rotation = new import_three16.Euler();
|
|
4581
4627
|
if (typeof variant.x !== "undefined") {
|
|
4582
4628
|
rotation.x = toRadians(clampRotationDegrees(variant.x));
|
|
4583
4629
|
}
|
|
4584
4630
|
if (typeof variant.y !== "undefined") {
|
|
4585
|
-
|
|
4586
|
-
|
|
4587
|
-
|
|
4588
|
-
|
|
4589
|
-
|
|
4631
|
+
rotation.y = toRadians(clampRotationDegrees(typeof variant.x !== "undefined" ? variant.y : 360 - variant.y));
|
|
4632
|
+
}
|
|
4633
|
+
const model = await Models.getMerged(AssetKey.parse("models", variant.model));
|
|
4634
|
+
const options = {
|
|
4635
|
+
...this.options,
|
|
4636
|
+
uvLockRotation: variant.uvlock && (rotation.x !== 0 || rotation.y !== 0) ? [rotation.x, rotation.y, rotation.z] : void 0
|
|
4637
|
+
};
|
|
4638
|
+
const obj = await this.scene.addModel(model, options);
|
|
4639
|
+
if (isInstanceReference(obj) || obj.isInstanced) {
|
|
4640
|
+
this._isInstanced = true;
|
|
4641
|
+
this._instanceCounter = 1;
|
|
4590
4642
|
}
|
|
4591
4643
|
obj.setRotation(rotation);
|
|
4592
|
-
console.log(obj);
|
|
4593
4644
|
return obj;
|
|
4594
4645
|
}
|
|
4595
4646
|
async resetState() {
|
|
@@ -5651,7 +5702,8 @@ var MineRenderScene = class _MineRenderScene extends import_three17.Scene {
|
|
|
5651
5702
|
const obj = await objectSupplier();
|
|
5652
5703
|
if (obj?.options?.instanceMeshes && asset.key && asset.key?.assetType === "models") {
|
|
5653
5704
|
console.log("instanceMeshes + key");
|
|
5654
|
-
const
|
|
5705
|
+
const uvLockRotation = isModelObject(obj) ? obj.options.uvLockRotation : void 0;
|
|
5706
|
+
const key = asset.key.serialize() + (uvLockRotation ? `|uvlock:${uvLockRotation.join(",")}` : "");
|
|
5655
5707
|
return this.instanceManager.getOrCreate(key, async () => {
|
|
5656
5708
|
obj.scene = this;
|
|
5657
5709
|
await obj.init();
|
|
@@ -6687,7 +6739,7 @@ var Skins = class {
|
|
|
6687
6739
|
return this.fromUsername(uuidOrUsername);
|
|
6688
6740
|
}
|
|
6689
6741
|
static async fromUuid(uuid) {
|
|
6690
|
-
return this.
|
|
6742
|
+
return this.getMcProxySkinUrl(uuid);
|
|
6691
6743
|
}
|
|
6692
6744
|
static async fromUsername(username) {
|
|
6693
6745
|
return this.usernameToUuid(username).then((uuid) => {
|
|
@@ -6714,7 +6766,7 @@ var Skins = class {
|
|
|
6714
6766
|
return this.capeFromUsername(uuidOrUsername);
|
|
6715
6767
|
}
|
|
6716
6768
|
static async capeFromUuid(uuid) {
|
|
6717
|
-
return this.
|
|
6769
|
+
return this.getMcProxyCapeUrl(uuid);
|
|
6718
6770
|
}
|
|
6719
6771
|
static async capeFromUsername(username) {
|
|
6720
6772
|
return this.usernameToUuid(username).then((uuid) => {
|
|
@@ -6735,8 +6787,23 @@ var Skins = class {
|
|
|
6735
6787
|
//</editor-fold>
|
|
6736
6788
|
//<editor-fold desc="Helpers">
|
|
6737
6789
|
static async usernameToUuid(username) {
|
|
6738
|
-
return this.
|
|
6790
|
+
return this.usernameToUuidMcProxy(username);
|
|
6739
6791
|
}
|
|
6792
|
+
static async usernameToUuidMcProxy(username) {
|
|
6793
|
+
return Requests.genericRequest({
|
|
6794
|
+
baseURL: "https://mcproxy.dev",
|
|
6795
|
+
url: "/uuid/" + username
|
|
6796
|
+
}).then((res) => {
|
|
6797
|
+
if (res.status === 200) {
|
|
6798
|
+
return res.data["data"]["id"];
|
|
6799
|
+
}
|
|
6800
|
+
return void 0;
|
|
6801
|
+
}).catch((err) => {
|
|
6802
|
+
console.warn(err);
|
|
6803
|
+
return void 0;
|
|
6804
|
+
});
|
|
6805
|
+
}
|
|
6806
|
+
/** @deprecated **/
|
|
6740
6807
|
static async usernameToUuidSkinProxy(username) {
|
|
6741
6808
|
return Requests.genericRequest({
|
|
6742
6809
|
baseURL: "https://minecraft-skin-proxy.inventive.workers.dev",
|
|
@@ -6815,12 +6882,20 @@ var Skins = class {
|
|
|
6815
6882
|
static getMineSkinPlayerSkinUrl(uuid) {
|
|
6816
6883
|
return "https://mineskin.org/skin/player/" + uuid;
|
|
6817
6884
|
}
|
|
6885
|
+
/** @deprecated **/
|
|
6818
6886
|
static getSkinProxySkinUrl(uuid) {
|
|
6819
6887
|
return "https://minecraft-skin-proxy.inventive.workers.dev/skin/" + uuid;
|
|
6820
6888
|
}
|
|
6889
|
+
/** @deprecated **/
|
|
6821
6890
|
static getSkinProxyCapeUrl(uuid) {
|
|
6822
6891
|
return "https://minecraft-skin-proxy.inventive.workers.dev/cape/" + uuid;
|
|
6823
6892
|
}
|
|
6893
|
+
static getMcProxySkinUrl(uuid) {
|
|
6894
|
+
return "https://mcproxy.dev/skin/" + uuid;
|
|
6895
|
+
}
|
|
6896
|
+
static getMcProxyCapeUrl(uuid) {
|
|
6897
|
+
return "https://mcproxy.dev/cape/" + uuid;
|
|
6898
|
+
}
|
|
6824
6899
|
//</editor-fold>
|
|
6825
6900
|
};
|
|
6826
6901
|
|