minerender 2.1.0-alpha.17 → 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 +10 -0
- package/dist/browser/index.d.ts +10 -0
- package/dist/browser/index.js +99 -20
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/index.mjs +148 -69
- package/dist/browser/index.mjs.map +1 -1
- package/dist/bundle.js +99 -20
- package/dist/bundle.js.map +1 -1
- package/dist/node/index.d.mts +10 -0
- package/dist/node/index.d.ts +10 -0
- package/dist/node/index.js +99 -20
- package/dist/node/index.js.map +1 -1
- package/dist/node/index.mjs +148 -69
- package/dist/node/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/browser/index.d.mts
CHANGED
|
@@ -173,6 +173,7 @@ declare class AssetKey extends BasicAssetKey {
|
|
|
173
173
|
rootType: "assets" | "data" | string;
|
|
174
174
|
extension: ".json" | ".png" | string;
|
|
175
175
|
root?: string | undefined;
|
|
176
|
+
readonly isAssetKey: true;
|
|
176
177
|
constructor(namespace: string, path: string, assetType?: AssetType | undefined, type?: string | undefined, rootType?: "assets" | "data" | string, extension?: ".json" | ".png" | string, root?: string | undefined);
|
|
177
178
|
static parse(assetType: AssetType, str: string, origin?: AssetKey): AssetKey;
|
|
178
179
|
toString(): string;
|
|
@@ -553,6 +554,7 @@ declare class UVMapper {
|
|
|
553
554
|
static setCubeUvs(geometry: BoxGeometry, originalTextureSize: DoubleArray, actualTextureSize: DoubleArray, faces: ModelFaces): void;
|
|
554
555
|
static facesToUvArray(faces: ModelFaces, originalTextureSize: DoubleArray, actualTextureSize: DoubleArray): number[];
|
|
555
556
|
static facesToUv(faces: ModelFaces, originalTextureSize: DoubleArray, actualTextureSize: DoubleArray): Float32BufferAttribute;
|
|
557
|
+
static lockUvs(geometry: BoxGeometry, faces: ModelFaces, atlas: TextureAtlas, rotation: Euler): void;
|
|
556
558
|
static getAtlas(model: Model): Promise<Maybe<TextureAtlas>>;
|
|
557
559
|
static fillMissingTextureKeys<T>(textures: ModelTextures, target: {
|
|
558
560
|
[k: string]: T;
|
|
@@ -846,6 +848,8 @@ declare class ModelObject extends SceneObject {
|
|
|
846
848
|
protected applyTextures(): void;
|
|
847
849
|
}
|
|
848
850
|
interface ModelObjectOptions extends SceneObjectOptions {
|
|
851
|
+
/** Quarter-turn block rotation in radians to compensate when locking UVs. */
|
|
852
|
+
uvLockRotation?: TripleArray;
|
|
849
853
|
}
|
|
850
854
|
declare function isModelObject(obj: any): obj is ModelObject;
|
|
851
855
|
|
|
@@ -1537,6 +1541,8 @@ declare class Skins {
|
|
|
1537
1541
|
static capeFromUsername(username: string): Promise<Maybe<string>>;
|
|
1538
1542
|
static capeFromCapesDev(uuid: string, capeType?: string): Promise<Maybe<string>>;
|
|
1539
1543
|
private static usernameToUuid;
|
|
1544
|
+
private static usernameToUuidMcProxy;
|
|
1545
|
+
/** @deprecated **/
|
|
1540
1546
|
private static usernameToUuidSkinProxy;
|
|
1541
1547
|
private static usernameToUuidMineTools;
|
|
1542
1548
|
private static getProfileFromMinetools;
|
|
@@ -1546,8 +1552,12 @@ declare class Skins {
|
|
|
1546
1552
|
private static getCrafatarCapeUrl;
|
|
1547
1553
|
private static getMcHeadsSkinUrl;
|
|
1548
1554
|
private static getMineSkinPlayerSkinUrl;
|
|
1555
|
+
/** @deprecated **/
|
|
1549
1556
|
private static getSkinProxySkinUrl;
|
|
1557
|
+
/** @deprecated **/
|
|
1550
1558
|
private static getSkinProxyCapeUrl;
|
|
1559
|
+
private static getMcProxySkinUrl;
|
|
1560
|
+
private static getMcProxyCapeUrl;
|
|
1551
1561
|
}
|
|
1552
1562
|
|
|
1553
1563
|
declare class TextureLoader {
|
package/dist/browser/index.d.ts
CHANGED
|
@@ -173,6 +173,7 @@ declare class AssetKey extends BasicAssetKey {
|
|
|
173
173
|
rootType: "assets" | "data" | string;
|
|
174
174
|
extension: ".json" | ".png" | string;
|
|
175
175
|
root?: string | undefined;
|
|
176
|
+
readonly isAssetKey: true;
|
|
176
177
|
constructor(namespace: string, path: string, assetType?: AssetType | undefined, type?: string | undefined, rootType?: "assets" | "data" | string, extension?: ".json" | ".png" | string, root?: string | undefined);
|
|
177
178
|
static parse(assetType: AssetType, str: string, origin?: AssetKey): AssetKey;
|
|
178
179
|
toString(): string;
|
|
@@ -553,6 +554,7 @@ declare class UVMapper {
|
|
|
553
554
|
static setCubeUvs(geometry: BoxGeometry, originalTextureSize: DoubleArray, actualTextureSize: DoubleArray, faces: ModelFaces): void;
|
|
554
555
|
static facesToUvArray(faces: ModelFaces, originalTextureSize: DoubleArray, actualTextureSize: DoubleArray): number[];
|
|
555
556
|
static facesToUv(faces: ModelFaces, originalTextureSize: DoubleArray, actualTextureSize: DoubleArray): Float32BufferAttribute;
|
|
557
|
+
static lockUvs(geometry: BoxGeometry, faces: ModelFaces, atlas: TextureAtlas, rotation: Euler): void;
|
|
556
558
|
static getAtlas(model: Model): Promise<Maybe<TextureAtlas>>;
|
|
557
559
|
static fillMissingTextureKeys<T>(textures: ModelTextures, target: {
|
|
558
560
|
[k: string]: T;
|
|
@@ -846,6 +848,8 @@ declare class ModelObject extends SceneObject {
|
|
|
846
848
|
protected applyTextures(): void;
|
|
847
849
|
}
|
|
848
850
|
interface ModelObjectOptions extends SceneObjectOptions {
|
|
851
|
+
/** Quarter-turn block rotation in radians to compensate when locking UVs. */
|
|
852
|
+
uvLockRotation?: TripleArray;
|
|
849
853
|
}
|
|
850
854
|
declare function isModelObject(obj: any): obj is ModelObject;
|
|
851
855
|
|
|
@@ -1537,6 +1541,8 @@ declare class Skins {
|
|
|
1537
1541
|
static capeFromUsername(username: string): Promise<Maybe<string>>;
|
|
1538
1542
|
static capeFromCapesDev(uuid: string, capeType?: string): Promise<Maybe<string>>;
|
|
1539
1543
|
private static usernameToUuid;
|
|
1544
|
+
private static usernameToUuidMcProxy;
|
|
1545
|
+
/** @deprecated **/
|
|
1540
1546
|
private static usernameToUuidSkinProxy;
|
|
1541
1547
|
private static usernameToUuidMineTools;
|
|
1542
1548
|
private static getProfileFromMinetools;
|
|
@@ -1546,8 +1552,12 @@ declare class Skins {
|
|
|
1546
1552
|
private static getCrafatarCapeUrl;
|
|
1547
1553
|
private static getMcHeadsSkinUrl;
|
|
1548
1554
|
private static getMineSkinPlayerSkinUrl;
|
|
1555
|
+
/** @deprecated **/
|
|
1549
1556
|
private static getSkinProxySkinUrl;
|
|
1557
|
+
/** @deprecated **/
|
|
1550
1558
|
private static getSkinProxyCapeUrl;
|
|
1559
|
+
private static getMcProxySkinUrl;
|
|
1560
|
+
private static getMcProxyCapeUrl;
|
|
1551
1561
|
}
|
|
1552
1562
|
|
|
1553
1563
|
declare class TextureLoader {
|
package/dist/browser/index.js
CHANGED
|
@@ -1279,6 +1279,7 @@ var AssetKey = class _AssetKey extends BasicAssetKey {
|
|
|
1279
1279
|
this.rootType = rootType;
|
|
1280
1280
|
this.extension = extension;
|
|
1281
1281
|
this.root = root;
|
|
1282
|
+
this.isAssetKey = true;
|
|
1282
1283
|
}
|
|
1283
1284
|
static parse(assetType, str, origin) {
|
|
1284
1285
|
let namespace = origin?.namespace || DEFAULT_NAMESPACE;
|
|
@@ -1294,7 +1295,10 @@ var AssetKey = class _AssetKey extends BasicAssetKey {
|
|
|
1294
1295
|
split.shift();
|
|
1295
1296
|
}
|
|
1296
1297
|
let path = split.join("/");
|
|
1297
|
-
|
|
1298
|
+
const extension = assetType === "textures" ? ".png" : origin?.extension ?? ".json";
|
|
1299
|
+
if (extension && path.endsWith(extension)) {
|
|
1300
|
+
path = path.slice(0, -extension.length);
|
|
1301
|
+
}
|
|
1298
1302
|
return new _AssetKey(namespace, path, assetType, type, "assets", extension, origin?.root);
|
|
1299
1303
|
}
|
|
1300
1304
|
toString() {
|
|
@@ -1324,10 +1328,10 @@ var AssetKey = class _AssetKey extends BasicAssetKey {
|
|
|
1324
1328
|
}
|
|
1325
1329
|
};
|
|
1326
1330
|
function isBasicAssetKey(obj) {
|
|
1327
|
-
return "
|
|
1331
|
+
return obj !== null && typeof obj === "object" && typeof obj.namespace === "string" && typeof obj.path === "string";
|
|
1328
1332
|
}
|
|
1329
1333
|
function isAssetKey(obj) {
|
|
1330
|
-
return isBasicAssetKey(obj) &&
|
|
1334
|
+
return isBasicAssetKey(obj) && obj.isAssetKey === true;
|
|
1331
1335
|
}
|
|
1332
1336
|
|
|
1333
1337
|
// src/model/ModelMerger.ts
|
|
@@ -2205,6 +2209,14 @@ var DEFAULT_UV = [0, 0, 16, 16];
|
|
|
2205
2209
|
var X = 0;
|
|
2206
2210
|
var Y = 1;
|
|
2207
2211
|
var Z = 2;
|
|
2212
|
+
var FACE_UV_AXES = {
|
|
2213
|
+
east: [new import_three8.Vector3(0, 0, -1), new import_three8.Vector3(0, -1, 0)],
|
|
2214
|
+
west: [new import_three8.Vector3(0, 0, 1), new import_three8.Vector3(0, -1, 0)],
|
|
2215
|
+
up: [new import_three8.Vector3(1, 0, 0), new import_three8.Vector3(0, 0, 1)],
|
|
2216
|
+
down: [new import_three8.Vector3(1, 0, 0), new import_three8.Vector3(0, 0, -1)],
|
|
2217
|
+
south: [new import_three8.Vector3(1, 0, 0), new import_three8.Vector3(0, -1, 0)],
|
|
2218
|
+
north: [new import_three8.Vector3(-1, 0, 0), new import_three8.Vector3(0, -1, 0)]
|
|
2219
|
+
};
|
|
2208
2220
|
var UVMapper = class {
|
|
2209
2221
|
static makeUv(uvCoord, originalTextureSize, actualTextureSize) {
|
|
2210
2222
|
if (uvCoord === 0) return 0;
|
|
@@ -2302,6 +2314,42 @@ var UVMapper = class {
|
|
|
2302
2314
|
static facesToUv(faces, originalTextureSize, actualTextureSize) {
|
|
2303
2315
|
return new import_three8.Float32BufferAttribute(this.facesToUvArray(faces, originalTextureSize, actualTextureSize), 2);
|
|
2304
2316
|
}
|
|
2317
|
+
static lockUvs(geometry, faces, atlas, rotation) {
|
|
2318
|
+
const uv = geometry.getAttribute("uv");
|
|
2319
|
+
for (let faceIndex = 0; faceIndex < CUBE_FACES.length; faceIndex++) {
|
|
2320
|
+
const faceName = CUBE_FACES[faceIndex];
|
|
2321
|
+
const texture = faces[faceName]?.texture?.substring(1);
|
|
2322
|
+
const position = texture && atlas.positions[texture];
|
|
2323
|
+
const size = texture && atlas.sizes[texture];
|
|
2324
|
+
if (!position || !size) continue;
|
|
2325
|
+
const [sourceU, sourceV] = FACE_UV_AXES[faceName];
|
|
2326
|
+
const uAxis = sourceU.clone().applyEuler(rotation);
|
|
2327
|
+
const vAxis = sourceV.clone().applyEuler(rotation);
|
|
2328
|
+
const normal = vAxis.clone().cross(uAxis);
|
|
2329
|
+
const targetFace = CUBE_FACES.find((name) => {
|
|
2330
|
+
const [u, v] = FACE_UV_AXES[name];
|
|
2331
|
+
return v.clone().cross(u).dot(normal) > 0.5;
|
|
2332
|
+
});
|
|
2333
|
+
const [targetU, targetV] = FACE_UV_AXES[targetFace];
|
|
2334
|
+
const uu = Math.round(targetU.dot(uAxis));
|
|
2335
|
+
const uvCross = Math.round(targetU.dot(vAxis));
|
|
2336
|
+
const vu = Math.round(targetV.dot(uAxis));
|
|
2337
|
+
const vv = Math.round(targetV.dot(vAxis));
|
|
2338
|
+
for (let corner = 0; corner < 4; corner++) {
|
|
2339
|
+
const index = faceIndex * 4 + corner;
|
|
2340
|
+
const u = (uv.getX(index) * atlas.image.width - position[0]) / size[0] - 0.5;
|
|
2341
|
+
const v = ((1 - uv.getY(index)) * atlas.image.height - position[1]) / size[1] - 0.5;
|
|
2342
|
+
const lockedU = uu * u + uvCross * v + 0.5;
|
|
2343
|
+
const lockedV = vu * u + vv * v + 0.5;
|
|
2344
|
+
uv.setXY(
|
|
2345
|
+
index,
|
|
2346
|
+
(position[0] + lockedU * size[0]) / atlas.image.width,
|
|
2347
|
+
1 - (position[1] + lockedV * size[1]) / atlas.image.height
|
|
2348
|
+
);
|
|
2349
|
+
}
|
|
2350
|
+
}
|
|
2351
|
+
uv.needsUpdate = true;
|
|
2352
|
+
}
|
|
2305
2353
|
static async getAtlas(model) {
|
|
2306
2354
|
const keyStr = model.key.serialize();
|
|
2307
2355
|
return Caching.modelTextureAtlasCache.get(keyStr, (k) => {
|
|
@@ -2908,6 +2956,7 @@ var _SceneObject = class _SceneObject extends import_three9.Object3D {
|
|
|
2908
2956
|
}
|
|
2909
2957
|
createInstancedMesh(name, geometry, material, count) {
|
|
2910
2958
|
const mesh = new import_three9.InstancedMesh(geometry, material, count);
|
|
2959
|
+
mesh.count = 0;
|
|
2911
2960
|
if (name) {
|
|
2912
2961
|
mesh.name = `mesh:${name}`;
|
|
2913
2962
|
}
|
|
@@ -2985,6 +3034,10 @@ var _SceneObject = class _SceneObject extends import_three9.Object3D {
|
|
|
2985
3034
|
if (!this.isInstanced) throw new MineRenderError("Object is not instanced");
|
|
2986
3035
|
const i = this._instanceCounter++;
|
|
2987
3036
|
this.setMatrixAt(i, new import_three9.Matrix4());
|
|
3037
|
+
const mesh = this.children[0];
|
|
3038
|
+
if (mesh && isInstancedMesh(mesh)) {
|
|
3039
|
+
mesh.count = Math.min(this._instanceCounter, mesh.instanceMatrix.count);
|
|
3040
|
+
}
|
|
2988
3041
|
console.debug(p6, "nextInstance " + i);
|
|
2989
3042
|
if (i === this.options.maxInstanceCount) {
|
|
2990
3043
|
console.warn(p6, "Max instance count reached for " + this);
|
|
@@ -4287,6 +4340,9 @@ var _ModelObject = class _ModelObject extends SceneObject {
|
|
|
4287
4340
|
if (this.atlas.model.elements) {
|
|
4288
4341
|
this.atlas.model.elements?.forEach((el) => {
|
|
4289
4342
|
const elGeo = this._getBoxGeometryFromElement(el).clone();
|
|
4343
|
+
if (this.options.uvLockRotation) {
|
|
4344
|
+
UVMapper.lockUvs(elGeo, el.faces, this.atlas, new import_three15.Euler(...this.options.uvLockRotation));
|
|
4345
|
+
}
|
|
4290
4346
|
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));
|
|
4291
4347
|
elGeo.applyMatrix4(new import_three15.Matrix4().makeTranslation(el.from[0], el.from[1], el.from[2]));
|
|
4292
4348
|
if (el.rotation) {
|
|
@@ -4521,25 +4577,24 @@ var _BlockObject = class _BlockObject extends SceneObject {
|
|
|
4521
4577
|
await this.createVariant(variant);
|
|
4522
4578
|
}
|
|
4523
4579
|
async createVariant(variant) {
|
|
4524
|
-
const
|
|
4525
|
-
const obj = await this.scene.addModel(model, this.options);
|
|
4526
|
-
if (isInstanceReference(obj) || obj.isInstanced) {
|
|
4527
|
-
this._isInstanced = true;
|
|
4528
|
-
this._instanceCounter = 1;
|
|
4529
|
-
}
|
|
4530
|
-
let rotation = new import_three16.Euler(0, 0, 0);
|
|
4580
|
+
const rotation = new import_three16.Euler();
|
|
4531
4581
|
if (typeof variant.x !== "undefined") {
|
|
4532
4582
|
rotation.x = toRadians(clampRotationDegrees(variant.x));
|
|
4533
4583
|
}
|
|
4534
4584
|
if (typeof variant.y !== "undefined") {
|
|
4535
|
-
|
|
4536
|
-
|
|
4537
|
-
|
|
4538
|
-
|
|
4539
|
-
|
|
4585
|
+
rotation.y = toRadians(clampRotationDegrees(typeof variant.x !== "undefined" ? variant.y : 360 - variant.y));
|
|
4586
|
+
}
|
|
4587
|
+
const model = await Models.getMerged(AssetKey.parse("models", variant.model));
|
|
4588
|
+
const options = {
|
|
4589
|
+
...this.options,
|
|
4590
|
+
uvLockRotation: variant.uvlock && (rotation.x !== 0 || rotation.y !== 0) ? [rotation.x, rotation.y, rotation.z] : void 0
|
|
4591
|
+
};
|
|
4592
|
+
const obj = await this.scene.addModel(model, options);
|
|
4593
|
+
if (isInstanceReference(obj) || obj.isInstanced) {
|
|
4594
|
+
this._isInstanced = true;
|
|
4595
|
+
this._instanceCounter = 1;
|
|
4540
4596
|
}
|
|
4541
4597
|
obj.setRotation(rotation);
|
|
4542
|
-
console.log(obj);
|
|
4543
4598
|
return obj;
|
|
4544
4599
|
}
|
|
4545
4600
|
async resetState() {
|
|
@@ -5602,7 +5657,8 @@ var _MineRenderScene = class _MineRenderScene extends import_three17.Scene {
|
|
|
5602
5657
|
const obj = await objectSupplier();
|
|
5603
5658
|
if (obj?.options?.instanceMeshes && asset.key && asset.key?.assetType === "models") {
|
|
5604
5659
|
console.log("instanceMeshes + key");
|
|
5605
|
-
const
|
|
5660
|
+
const uvLockRotation = isModelObject(obj) ? obj.options.uvLockRotation : void 0;
|
|
5661
|
+
const key = asset.key.serialize() + (uvLockRotation ? `|uvlock:${uvLockRotation.join(",")}` : "");
|
|
5606
5662
|
return this.instanceManager.getOrCreate(key, async () => {
|
|
5607
5663
|
obj.scene = this;
|
|
5608
5664
|
await obj.init();
|
|
@@ -6639,7 +6695,7 @@ var Skins = class {
|
|
|
6639
6695
|
return this.fromUsername(uuidOrUsername);
|
|
6640
6696
|
}
|
|
6641
6697
|
static async fromUuid(uuid) {
|
|
6642
|
-
return this.
|
|
6698
|
+
return this.getMcProxySkinUrl(uuid);
|
|
6643
6699
|
}
|
|
6644
6700
|
static async fromUsername(username) {
|
|
6645
6701
|
return this.usernameToUuid(username).then((uuid) => {
|
|
@@ -6666,7 +6722,7 @@ var Skins = class {
|
|
|
6666
6722
|
return this.capeFromUsername(uuidOrUsername);
|
|
6667
6723
|
}
|
|
6668
6724
|
static async capeFromUuid(uuid) {
|
|
6669
|
-
return this.
|
|
6725
|
+
return this.getMcProxyCapeUrl(uuid);
|
|
6670
6726
|
}
|
|
6671
6727
|
static async capeFromUsername(username) {
|
|
6672
6728
|
return this.usernameToUuid(username).then((uuid) => {
|
|
@@ -6687,8 +6743,23 @@ var Skins = class {
|
|
|
6687
6743
|
//</editor-fold>
|
|
6688
6744
|
//<editor-fold desc="Helpers">
|
|
6689
6745
|
static async usernameToUuid(username) {
|
|
6690
|
-
return this.
|
|
6746
|
+
return this.usernameToUuidMcProxy(username);
|
|
6747
|
+
}
|
|
6748
|
+
static async usernameToUuidMcProxy(username) {
|
|
6749
|
+
return Requests.genericRequest({
|
|
6750
|
+
baseURL: "https://mcproxy.dev",
|
|
6751
|
+
url: "/uuid/" + username
|
|
6752
|
+
}).then((res) => {
|
|
6753
|
+
if (res.status === 200) {
|
|
6754
|
+
return res.data["data"]["id"];
|
|
6755
|
+
}
|
|
6756
|
+
return void 0;
|
|
6757
|
+
}).catch((err) => {
|
|
6758
|
+
console.warn(err);
|
|
6759
|
+
return void 0;
|
|
6760
|
+
});
|
|
6691
6761
|
}
|
|
6762
|
+
/** @deprecated **/
|
|
6692
6763
|
static async usernameToUuidSkinProxy(username) {
|
|
6693
6764
|
return Requests.genericRequest({
|
|
6694
6765
|
baseURL: "https://minecraft-skin-proxy.inventive.workers.dev",
|
|
@@ -6767,12 +6838,20 @@ var Skins = class {
|
|
|
6767
6838
|
static getMineSkinPlayerSkinUrl(uuid) {
|
|
6768
6839
|
return "https://mineskin.org/skin/player/" + uuid;
|
|
6769
6840
|
}
|
|
6841
|
+
/** @deprecated **/
|
|
6770
6842
|
static getSkinProxySkinUrl(uuid) {
|
|
6771
6843
|
return "https://minecraft-skin-proxy.inventive.workers.dev/skin/" + uuid;
|
|
6772
6844
|
}
|
|
6845
|
+
/** @deprecated **/
|
|
6773
6846
|
static getSkinProxyCapeUrl(uuid) {
|
|
6774
6847
|
return "https://minecraft-skin-proxy.inventive.workers.dev/cape/" + uuid;
|
|
6775
6848
|
}
|
|
6849
|
+
static getMcProxySkinUrl(uuid) {
|
|
6850
|
+
return "https://mcproxy.dev/skin/" + uuid;
|
|
6851
|
+
}
|
|
6852
|
+
static getMcProxyCapeUrl(uuid) {
|
|
6853
|
+
return "https://mcproxy.dev/cape/" + uuid;
|
|
6854
|
+
}
|
|
6776
6855
|
//</editor-fold>
|
|
6777
6856
|
};
|
|
6778
6857
|
|