minerender 2.1.0-alpha.73 → 2.1.0-alpha.74
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 +3 -1
- package/dist/browser/index.d.ts +3 -1
- package/dist/browser/index.js +71 -12
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/index.mjs +71 -12
- package/dist/browser/index.mjs.map +1 -1
- package/dist/bundle.js +71 -12
- package/dist/bundle.js.map +1 -1
- package/dist/node/index.d.mts +3 -1
- package/dist/node/index.d.ts +3 -1
- package/dist/node/index.js +71 -12
- package/dist/node/index.js.map +1 -1
- package/dist/node/index.mjs +71 -12
- package/dist/node/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/node/index.d.mts
CHANGED
|
@@ -292,7 +292,7 @@ declare class Materials {
|
|
|
292
292
|
*/
|
|
293
293
|
static createEntityCanvasMaterial(canvas: HTMLCanvasElement, mode?: EntityRenderMode, tint?: ColorRepresentation): MeshBasicMaterial;
|
|
294
294
|
static createGuiCanvasMaterial(canvas: HTMLCanvasElement): MeshBasicMaterial;
|
|
295
|
-
static createShadedCanvasMaterial(canvas: HTMLCanvasElement, transparent?: boolean, shade?: boolean): Material;
|
|
295
|
+
static createShadedCanvasMaterial(canvas: HTMLCanvasElement, transparent?: boolean, shade?: boolean, boundUvs?: boolean): Material;
|
|
296
296
|
static getImage(key: MaterialKey): Material;
|
|
297
297
|
static needsUpdate(mat: Material): void;
|
|
298
298
|
}
|
|
@@ -694,6 +694,8 @@ declare class UVMapper {
|
|
|
694
694
|
static setCubeUvs(geometry: BoxGeometry, originalTextureSize: DoubleArray, actualTextureSize: DoubleArray, faces: ModelFaces): void;
|
|
695
695
|
static facesToUvArray(faces: ModelFaces, originalTextureSize: DoubleArray, actualTextureSize: DoubleArray): number[];
|
|
696
696
|
static facesToUv(faces: ModelFaces, originalTextureSize: DoubleArray, actualTextureSize: DoubleArray): Float32BufferAttribute;
|
|
697
|
+
/** Bounds texture sampling to texel centres without changing cropped face UVs. */
|
|
698
|
+
static setAtlasUvBounds(geometry: BoxGeometry, faces: ModelFaces, atlas: TextureAtlas): void;
|
|
697
699
|
static lockUvs(geometry: BoxGeometry, faces: ModelFaces, atlas: TextureAtlas, rotation: Euler): void;
|
|
698
700
|
static getAtlas(model: Model): Promise<Maybe<TextureAtlas>>;
|
|
699
701
|
static fillMissingTextureKeys<T>(textures: ModelTextures, target: {
|
package/dist/node/index.d.ts
CHANGED
|
@@ -292,7 +292,7 @@ declare class Materials {
|
|
|
292
292
|
*/
|
|
293
293
|
static createEntityCanvasMaterial(canvas: HTMLCanvasElement, mode?: EntityRenderMode, tint?: ColorRepresentation): MeshBasicMaterial;
|
|
294
294
|
static createGuiCanvasMaterial(canvas: HTMLCanvasElement): MeshBasicMaterial;
|
|
295
|
-
static createShadedCanvasMaterial(canvas: HTMLCanvasElement, transparent?: boolean, shade?: boolean): Material;
|
|
295
|
+
static createShadedCanvasMaterial(canvas: HTMLCanvasElement, transparent?: boolean, shade?: boolean, boundUvs?: boolean): Material;
|
|
296
296
|
static getImage(key: MaterialKey): Material;
|
|
297
297
|
static needsUpdate(mat: Material): void;
|
|
298
298
|
}
|
|
@@ -694,6 +694,8 @@ declare class UVMapper {
|
|
|
694
694
|
static setCubeUvs(geometry: BoxGeometry, originalTextureSize: DoubleArray, actualTextureSize: DoubleArray, faces: ModelFaces): void;
|
|
695
695
|
static facesToUvArray(faces: ModelFaces, originalTextureSize: DoubleArray, actualTextureSize: DoubleArray): number[];
|
|
696
696
|
static facesToUv(faces: ModelFaces, originalTextureSize: DoubleArray, actualTextureSize: DoubleArray): Float32BufferAttribute;
|
|
697
|
+
/** Bounds texture sampling to texel centres without changing cropped face UVs. */
|
|
698
|
+
static setAtlasUvBounds(geometry: BoxGeometry, faces: ModelFaces, atlas: TextureAtlas): void;
|
|
697
699
|
static lockUvs(geometry: BoxGeometry, faces: ModelFaces, atlas: TextureAtlas, rotation: Euler): void;
|
|
698
700
|
static getAtlas(model: Model): Promise<Maybe<TextureAtlas>>;
|
|
699
701
|
static fillMissingTextureKeys<T>(textures: ModelTextures, target: {
|
package/dist/node/index.js
CHANGED
|
@@ -1032,7 +1032,7 @@ var init_Materials = __esm({
|
|
|
1032
1032
|
};
|
|
1033
1033
|
return material;
|
|
1034
1034
|
}
|
|
1035
|
-
static createShadedCanvasMaterial(canvas, transparent = false, shade = false) {
|
|
1035
|
+
static createShadedCanvasMaterial(canvas, transparent = false, shade = false, boundUvs = false) {
|
|
1036
1036
|
const vertShader = `
|
|
1037
1037
|
uniform bool SHADE;
|
|
1038
1038
|
|
|
@@ -1042,6 +1042,10 @@ var init_Materials = __esm({
|
|
|
1042
1042
|
#else
|
|
1043
1043
|
varying vec2 vUv;
|
|
1044
1044
|
#endif
|
|
1045
|
+
#ifdef BOUND_UVS
|
|
1046
|
+
attribute vec4 uvBounds;
|
|
1047
|
+
flat out vec4 vUvBounds;
|
|
1048
|
+
#endif
|
|
1045
1049
|
varying vec3 vTint;
|
|
1046
1050
|
varying float light;
|
|
1047
1051
|
varying float lift;
|
|
@@ -1077,13 +1081,17 @@ var init_Materials = __esm({
|
|
|
1077
1081
|
}
|
|
1078
1082
|
|
|
1079
1083
|
vUv = uv;
|
|
1084
|
+
#ifdef BOUND_UVS
|
|
1085
|
+
vUvBounds = uvBounds;
|
|
1086
|
+
#endif
|
|
1080
1087
|
vTint = color;
|
|
1081
1088
|
|
|
1089
|
+
vec4 mvPosition = vec4(position, 1.0);
|
|
1082
1090
|
#ifdef USE_INSTANCING
|
|
1083
|
-
|
|
1084
|
-
#else
|
|
1085
|
-
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
|
1091
|
+
mvPosition = instanceMatrix * mvPosition;
|
|
1086
1092
|
#endif
|
|
1093
|
+
mvPosition = modelViewMatrix * mvPosition;
|
|
1094
|
+
gl_Position = projectionMatrix * mvPosition;
|
|
1087
1095
|
|
|
1088
1096
|
}
|
|
1089
1097
|
`;
|
|
@@ -1103,13 +1111,22 @@ var init_Materials = __esm({
|
|
|
1103
1111
|
#else
|
|
1104
1112
|
varying vec2 vUv;
|
|
1105
1113
|
#endif
|
|
1114
|
+
#ifdef BOUND_UVS
|
|
1115
|
+
flat in vec4 vUvBounds;
|
|
1116
|
+
#endif
|
|
1106
1117
|
varying vec3 vTint;
|
|
1107
1118
|
varying float light;
|
|
1108
1119
|
varying float lift;
|
|
1109
1120
|
|
|
1110
1121
|
void main(void)
|
|
1111
1122
|
{
|
|
1112
|
-
|
|
1123
|
+
#ifdef BOUND_UVS
|
|
1124
|
+
// Keep edge samples inside their texture even without centroid interpolation.
|
|
1125
|
+
vec2 mapUv = clamp(vUv, vUvBounds.xy, vUvBounds.zw);
|
|
1126
|
+
#else
|
|
1127
|
+
vec2 mapUv = vUv;
|
|
1128
|
+
#endif
|
|
1129
|
+
vec4 color = texture2D(map, mapUv);
|
|
1113
1130
|
color.rgb *= vTint;
|
|
1114
1131
|
|
|
1115
1132
|
if (color.a < 0.01) discard;
|
|
@@ -1130,7 +1147,8 @@ var init_Materials = __esm({
|
|
|
1130
1147
|
}
|
|
1131
1148
|
`;
|
|
1132
1149
|
try {
|
|
1133
|
-
|
|
1150
|
+
const material = new import_three5.ShaderMaterial({
|
|
1151
|
+
defines: boundUvs ? { BOUND_UVS: true } : {},
|
|
1134
1152
|
uniforms: {
|
|
1135
1153
|
SHADE: { value: true },
|
|
1136
1154
|
BRIGHTNESS: { value: 1 },
|
|
@@ -1148,6 +1166,8 @@ var init_Materials = __esm({
|
|
|
1148
1166
|
side: transparent ? import_three5.DoubleSide : import_three5.FrontSide,
|
|
1149
1167
|
alphaTest: 0.5
|
|
1150
1168
|
});
|
|
1169
|
+
Object.assign(material.defaultAttributeValues, { uvBounds: [0, 0, 1, 1] });
|
|
1170
|
+
return material;
|
|
1151
1171
|
} catch (e) {
|
|
1152
1172
|
console.warn(e);
|
|
1153
1173
|
}
|
|
@@ -3068,6 +3088,37 @@ var init_UVMapper = __esm({
|
|
|
3068
3088
|
static facesToUv(faces, originalTextureSize, actualTextureSize) {
|
|
3069
3089
|
return new import_three9.Float32BufferAttribute(this.facesToUvArray(faces, originalTextureSize, actualTextureSize), 2);
|
|
3070
3090
|
}
|
|
3091
|
+
/** Bounds texture sampling to texel centres without changing cropped face UVs. */
|
|
3092
|
+
static setAtlasUvBounds(geometry, faces, atlas) {
|
|
3093
|
+
const uv = geometry.getAttribute("uv");
|
|
3094
|
+
const bounds = new Float32Array(uv.count * 4);
|
|
3095
|
+
for (const [faceIndex, faceName] of CUBE_FACES.entries()) {
|
|
3096
|
+
const texture = faces[faceName]?.texture?.substring(1);
|
|
3097
|
+
const position = texture && atlas.positions[texture];
|
|
3098
|
+
const size = texture && atlas.sizes[texture];
|
|
3099
|
+
let minU = Infinity, minV = Infinity, maxU = -Infinity, maxV = -Infinity;
|
|
3100
|
+
if (position && size) {
|
|
3101
|
+
minU = position[0] / atlas.image.width;
|
|
3102
|
+
maxU = (position[0] + size[0]) / atlas.image.width;
|
|
3103
|
+
minV = 1 - (position[1] + size[1]) / atlas.image.height;
|
|
3104
|
+
maxV = 1 - position[1] / atlas.image.height;
|
|
3105
|
+
} else {
|
|
3106
|
+
for (let corner = 0; corner < 4; corner++) {
|
|
3107
|
+
const index = faceIndex * 4 + corner;
|
|
3108
|
+
minU = Math.min(minU, uv.getX(index));
|
|
3109
|
+
minV = Math.min(minV, uv.getY(index));
|
|
3110
|
+
maxU = Math.max(maxU, uv.getX(index));
|
|
3111
|
+
maxV = Math.max(maxV, uv.getY(index));
|
|
3112
|
+
}
|
|
3113
|
+
}
|
|
3114
|
+
const insetU = Math.min(0.5 / atlas.image.width, (maxU - minU) / 2);
|
|
3115
|
+
const insetV = Math.min(0.5 / atlas.image.height, (maxV - minV) / 2);
|
|
3116
|
+
for (let corner = 0; corner < 4; corner++) {
|
|
3117
|
+
bounds.set([minU + insetU, minV + insetV, maxU - insetU, maxV - insetV], (faceIndex * 4 + corner) * 4);
|
|
3118
|
+
}
|
|
3119
|
+
}
|
|
3120
|
+
geometry.setAttribute("uvBounds", new import_three9.Float32BufferAttribute(bounds, 4));
|
|
3121
|
+
}
|
|
3071
3122
|
static lockUvs(geometry, faces, atlas, rotation) {
|
|
3072
3123
|
const uv = geometry.getAttribute("uv");
|
|
3073
3124
|
for (let faceIndex = 0; faceIndex < CUBE_FACES.length; faceIndex++) {
|
|
@@ -5470,6 +5521,7 @@ var init_ModelObject = __esm({
|
|
|
5470
5521
|
if (this.options.uvLockRotation) {
|
|
5471
5522
|
UVMapper.lockUvs(elGeo, el.faces, this.atlas, new import_three25.Euler(...this.options.uvLockRotation));
|
|
5472
5523
|
}
|
|
5524
|
+
UVMapper.setAtlasUvBounds(elGeo, el.faces, this.atlas);
|
|
5473
5525
|
if (this.options.tints) {
|
|
5474
5526
|
const colors = new Float32Array(elGeo.getAttribute("position").count * 3).fill(1);
|
|
5475
5527
|
for (const [faceIndex, faceName] of CUBE_FACES.entries()) {
|
|
@@ -5535,7 +5587,7 @@ var init_ModelObject = __esm({
|
|
|
5535
5587
|
}
|
|
5536
5588
|
applyTextures() {
|
|
5537
5589
|
if (this.atlas) {
|
|
5538
|
-
const mat = Materials.createShadedCanvasMaterial(this.atlas.image.canvas, this.atlas.hasTransparency, false);
|
|
5590
|
+
const mat = Materials.createShadedCanvasMaterial(this.atlas.image.canvas, this.atlas.hasTransparency, false, true);
|
|
5539
5591
|
this.atlasMaterial = mat;
|
|
5540
5592
|
this.atlasTexture = mat.uniforms?.map?.value ?? mat.map;
|
|
5541
5593
|
this.iterateAllMeshes((mesh) => {
|
|
@@ -15605,14 +15657,17 @@ var SectionMesh = class _SectionMesh extends import_three40.Group {
|
|
|
15605
15657
|
for (const { atlas, x, y } of page.placements) {
|
|
15606
15658
|
context.drawImage(atlas.image.canvas, x, y);
|
|
15607
15659
|
}
|
|
15608
|
-
const positions = [], normals = [], uvs = [], colors = [], indices = [];
|
|
15660
|
+
const positions = [], normals = [], uvs = [], uvBounds = [], colors = [], indices = [];
|
|
15609
15661
|
for (const { index, template, cullMask } of page.entries) {
|
|
15610
15662
|
const position = template.geometry.getAttribute("position");
|
|
15611
15663
|
const normal = template.geometry.getAttribute("normal");
|
|
15612
15664
|
const uv = template.geometry.getAttribute("uv");
|
|
15665
|
+
const bounds = template.geometry.getAttribute("uvBounds");
|
|
15613
15666
|
const color = template.geometry.getAttribute("color");
|
|
15614
15667
|
const sourceIndices = template.geometry.getIndex();
|
|
15615
15668
|
const placement = locations.get(template.atlas).placement;
|
|
15669
|
+
const mapU = (u) => (placement.x + u * template.atlas.image.width) / page.width;
|
|
15670
|
+
const mapV = (v) => 1 - (placement.y + (1 - v) * template.atlas.image.height) / page.height;
|
|
15616
15671
|
const offsetX = index % 16 * 16;
|
|
15617
15672
|
const offsetY = Math.floor(index / 256) * 16;
|
|
15618
15673
|
const offsetZ = Math.floor(index / 16) % 16 * 16;
|
|
@@ -15623,9 +15678,12 @@ var SectionMesh = class _SectionMesh extends import_three40.Group {
|
|
|
15623
15678
|
const vertex = face * 4 + corner;
|
|
15624
15679
|
positions.push(position.getX(vertex) + offsetX, position.getY(vertex) + offsetY, position.getZ(vertex) + offsetZ);
|
|
15625
15680
|
normals.push(normal.getX(vertex), normal.getY(vertex), normal.getZ(vertex));
|
|
15626
|
-
uvs.push(
|
|
15627
|
-
|
|
15628
|
-
|
|
15681
|
+
uvs.push(mapU(uv.getX(vertex)), mapV(uv.getY(vertex)));
|
|
15682
|
+
uvBounds.push(
|
|
15683
|
+
mapU(bounds?.getX(vertex) ?? 0),
|
|
15684
|
+
mapV(bounds?.getY(vertex) ?? 0),
|
|
15685
|
+
mapU(bounds?.getZ(vertex) ?? 1),
|
|
15686
|
+
mapV(bounds?.getW(vertex) ?? 1)
|
|
15629
15687
|
);
|
|
15630
15688
|
colors.push(color?.getX(vertex) ?? 1, color?.getY(vertex) ?? 1, color?.getZ(vertex) ?? 1);
|
|
15631
15689
|
}
|
|
@@ -15636,11 +15694,12 @@ var SectionMesh = class _SectionMesh extends import_three40.Group {
|
|
|
15636
15694
|
geometry.setAttribute("position", new import_three40.Float32BufferAttribute(positions, 3));
|
|
15637
15695
|
geometry.setAttribute("normal", new import_three40.Float32BufferAttribute(normals, 3));
|
|
15638
15696
|
geometry.setAttribute("uv", new import_three40.Float32BufferAttribute(uvs, 2));
|
|
15697
|
+
geometry.setAttribute("uvBounds", new import_three40.Float32BufferAttribute(uvBounds, 4));
|
|
15639
15698
|
geometry.setAttribute("color", new import_three40.Float32BufferAttribute(colors, 3));
|
|
15640
15699
|
geometry.setIndex(indices);
|
|
15641
15700
|
geometry.computeBoundingBox();
|
|
15642
15701
|
geometry.computeBoundingSphere();
|
|
15643
|
-
const material = Materials.createShadedCanvasMaterial(canvas, false);
|
|
15702
|
+
const material = Materials.createShadedCanvasMaterial(canvas, false, false, true);
|
|
15644
15703
|
material.vertexColors = true;
|
|
15645
15704
|
const texture = material.uniforms?.map?.value ?? material.map;
|
|
15646
15705
|
const mesh = new import_three40.Mesh(geometry, material);
|