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/bundle.js
CHANGED
|
@@ -42539,7 +42539,7 @@ void main() {
|
|
|
42539
42539
|
};
|
|
42540
42540
|
return material;
|
|
42541
42541
|
}
|
|
42542
|
-
static createShadedCanvasMaterial(canvas, transparent = false, shade = false) {
|
|
42542
|
+
static createShadedCanvasMaterial(canvas, transparent = false, shade = false, boundUvs = false) {
|
|
42543
42543
|
const vertShader = `
|
|
42544
42544
|
uniform bool SHADE;
|
|
42545
42545
|
|
|
@@ -42549,6 +42549,10 @@ void main() {
|
|
|
42549
42549
|
#else
|
|
42550
42550
|
varying vec2 vUv;
|
|
42551
42551
|
#endif
|
|
42552
|
+
#ifdef BOUND_UVS
|
|
42553
|
+
attribute vec4 uvBounds;
|
|
42554
|
+
flat out vec4 vUvBounds;
|
|
42555
|
+
#endif
|
|
42552
42556
|
varying vec3 vTint;
|
|
42553
42557
|
varying float light;
|
|
42554
42558
|
varying float lift;
|
|
@@ -42584,13 +42588,17 @@ void main() {
|
|
|
42584
42588
|
}
|
|
42585
42589
|
|
|
42586
42590
|
vUv = uv;
|
|
42591
|
+
#ifdef BOUND_UVS
|
|
42592
|
+
vUvBounds = uvBounds;
|
|
42593
|
+
#endif
|
|
42587
42594
|
vTint = color;
|
|
42588
42595
|
|
|
42596
|
+
vec4 mvPosition = vec4(position, 1.0);
|
|
42589
42597
|
#ifdef USE_INSTANCING
|
|
42590
|
-
|
|
42591
|
-
#else
|
|
42592
|
-
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
|
42598
|
+
mvPosition = instanceMatrix * mvPosition;
|
|
42593
42599
|
#endif
|
|
42600
|
+
mvPosition = modelViewMatrix * mvPosition;
|
|
42601
|
+
gl_Position = projectionMatrix * mvPosition;
|
|
42594
42602
|
|
|
42595
42603
|
}
|
|
42596
42604
|
`;
|
|
@@ -42610,13 +42618,22 @@ void main() {
|
|
|
42610
42618
|
#else
|
|
42611
42619
|
varying vec2 vUv;
|
|
42612
42620
|
#endif
|
|
42621
|
+
#ifdef BOUND_UVS
|
|
42622
|
+
flat in vec4 vUvBounds;
|
|
42623
|
+
#endif
|
|
42613
42624
|
varying vec3 vTint;
|
|
42614
42625
|
varying float light;
|
|
42615
42626
|
varying float lift;
|
|
42616
42627
|
|
|
42617
42628
|
void main(void)
|
|
42618
42629
|
{
|
|
42619
|
-
|
|
42630
|
+
#ifdef BOUND_UVS
|
|
42631
|
+
// Keep edge samples inside their texture even without centroid interpolation.
|
|
42632
|
+
vec2 mapUv = clamp(vUv, vUvBounds.xy, vUvBounds.zw);
|
|
42633
|
+
#else
|
|
42634
|
+
vec2 mapUv = vUv;
|
|
42635
|
+
#endif
|
|
42636
|
+
vec4 color = texture2D(map, mapUv);
|
|
42620
42637
|
color.rgb *= vTint;
|
|
42621
42638
|
|
|
42622
42639
|
if (color.a < 0.01) discard;
|
|
@@ -42637,7 +42654,8 @@ void main() {
|
|
|
42637
42654
|
}
|
|
42638
42655
|
`;
|
|
42639
42656
|
try {
|
|
42640
|
-
|
|
42657
|
+
const material = new ShaderMaterial({
|
|
42658
|
+
defines: boundUvs ? { BOUND_UVS: true } : {},
|
|
42641
42659
|
uniforms: {
|
|
42642
42660
|
SHADE: { value: true },
|
|
42643
42661
|
BRIGHTNESS: { value: 1 },
|
|
@@ -42655,6 +42673,8 @@ void main() {
|
|
|
42655
42673
|
side: transparent ? DoubleSide : FrontSide,
|
|
42656
42674
|
alphaTest: 0.5
|
|
42657
42675
|
});
|
|
42676
|
+
Object.assign(material.defaultAttributeValues, { uvBounds: [0, 0, 1, 1] });
|
|
42677
|
+
return material;
|
|
42658
42678
|
} catch (e6) {
|
|
42659
42679
|
console.warn(e6);
|
|
42660
42680
|
}
|
|
@@ -87904,6 +87924,37 @@ ${key}` : key;
|
|
|
87904
87924
|
static facesToUv(faces, originalTextureSize, actualTextureSize) {
|
|
87905
87925
|
return new Float32BufferAttribute(this.facesToUvArray(faces, originalTextureSize, actualTextureSize), 2);
|
|
87906
87926
|
}
|
|
87927
|
+
/** Bounds texture sampling to texel centres without changing cropped face UVs. */
|
|
87928
|
+
static setAtlasUvBounds(geometry, faces, atlas) {
|
|
87929
|
+
const uv = geometry.getAttribute("uv");
|
|
87930
|
+
const bounds = new Float32Array(uv.count * 4);
|
|
87931
|
+
for (const [faceIndex, faceName] of CUBE_FACES.entries()) {
|
|
87932
|
+
const texture = faces[faceName]?.texture?.substring(1);
|
|
87933
|
+
const position = texture && atlas.positions[texture];
|
|
87934
|
+
const size = texture && atlas.sizes[texture];
|
|
87935
|
+
let minU = Infinity, minV = Infinity, maxU = -Infinity, maxV = -Infinity;
|
|
87936
|
+
if (position && size) {
|
|
87937
|
+
minU = position[0] / atlas.image.width;
|
|
87938
|
+
maxU = (position[0] + size[0]) / atlas.image.width;
|
|
87939
|
+
minV = 1 - (position[1] + size[1]) / atlas.image.height;
|
|
87940
|
+
maxV = 1 - position[1] / atlas.image.height;
|
|
87941
|
+
} else {
|
|
87942
|
+
for (let corner = 0; corner < 4; corner++) {
|
|
87943
|
+
const index = faceIndex * 4 + corner;
|
|
87944
|
+
minU = Math.min(minU, uv.getX(index));
|
|
87945
|
+
minV = Math.min(minV, uv.getY(index));
|
|
87946
|
+
maxU = Math.max(maxU, uv.getX(index));
|
|
87947
|
+
maxV = Math.max(maxV, uv.getY(index));
|
|
87948
|
+
}
|
|
87949
|
+
}
|
|
87950
|
+
const insetU = Math.min(0.5 / atlas.image.width, (maxU - minU) / 2);
|
|
87951
|
+
const insetV = Math.min(0.5 / atlas.image.height, (maxV - minV) / 2);
|
|
87952
|
+
for (let corner = 0; corner < 4; corner++) {
|
|
87953
|
+
bounds.set([minU + insetU, minV + insetV, maxU - insetU, maxV - insetV], (faceIndex * 4 + corner) * 4);
|
|
87954
|
+
}
|
|
87955
|
+
}
|
|
87956
|
+
geometry.setAttribute("uvBounds", new Float32BufferAttribute(bounds, 4));
|
|
87957
|
+
}
|
|
87907
87958
|
static lockUvs(geometry, faces, atlas, rotation) {
|
|
87908
87959
|
const uv = geometry.getAttribute("uv");
|
|
87909
87960
|
for (let faceIndex = 0; faceIndex < CUBE_FACES.length; faceIndex++) {
|
|
@@ -90345,6 +90396,7 @@ ${shader.fragmentShader}`.replace(
|
|
|
90345
90396
|
if (this.options.uvLockRotation) {
|
|
90346
90397
|
UVMapper.lockUvs(elGeo, el.faces, this.atlas, new Euler(...this.options.uvLockRotation));
|
|
90347
90398
|
}
|
|
90399
|
+
UVMapper.setAtlasUvBounds(elGeo, el.faces, this.atlas);
|
|
90348
90400
|
if (this.options.tints) {
|
|
90349
90401
|
const colors = new Float32Array(elGeo.getAttribute("position").count * 3).fill(1);
|
|
90350
90402
|
for (const [faceIndex, faceName] of CUBE_FACES.entries()) {
|
|
@@ -90410,7 +90462,7 @@ ${shader.fragmentShader}`.replace(
|
|
|
90410
90462
|
}
|
|
90411
90463
|
applyTextures() {
|
|
90412
90464
|
if (this.atlas) {
|
|
90413
|
-
const mat = Materials.createShadedCanvasMaterial(this.atlas.image.canvas, this.atlas.hasTransparency, false);
|
|
90465
|
+
const mat = Materials.createShadedCanvasMaterial(this.atlas.image.canvas, this.atlas.hasTransparency, false, true);
|
|
90414
90466
|
this.atlasMaterial = mat;
|
|
90415
90467
|
this.atlasTexture = mat.uniforms?.map?.value ?? mat.map;
|
|
90416
90468
|
this.iterateAllMeshes((mesh) => {
|
|
@@ -105668,14 +105720,17 @@ gl_FragDepth=readDepth(vUv);
|
|
|
105668
105720
|
for (const { atlas, x: x4, y: y5 } of page.placements) {
|
|
105669
105721
|
context.drawImage(atlas.image.canvas, x4, y5);
|
|
105670
105722
|
}
|
|
105671
|
-
const positions = [], normals = [], uvs = [], colors = [], indices = [];
|
|
105723
|
+
const positions = [], normals = [], uvs = [], uvBounds = [], colors = [], indices = [];
|
|
105672
105724
|
for (const { index, template, cullMask } of page.entries) {
|
|
105673
105725
|
const position = template.geometry.getAttribute("position");
|
|
105674
105726
|
const normal = template.geometry.getAttribute("normal");
|
|
105675
105727
|
const uv = template.geometry.getAttribute("uv");
|
|
105728
|
+
const bounds = template.geometry.getAttribute("uvBounds");
|
|
105676
105729
|
const color2 = template.geometry.getAttribute("color");
|
|
105677
105730
|
const sourceIndices = template.geometry.getIndex();
|
|
105678
105731
|
const placement = locations.get(template.atlas).placement;
|
|
105732
|
+
const mapU = (u4) => (placement.x + u4 * template.atlas.image.width) / page.width;
|
|
105733
|
+
const mapV = (v5) => 1 - (placement.y + (1 - v5) * template.atlas.image.height) / page.height;
|
|
105679
105734
|
const offsetX = index % 16 * 16;
|
|
105680
105735
|
const offsetY = Math.floor(index / 256) * 16;
|
|
105681
105736
|
const offsetZ = Math.floor(index / 16) % 16 * 16;
|
|
@@ -105686,9 +105741,12 @@ gl_FragDepth=readDepth(vUv);
|
|
|
105686
105741
|
const vertex2 = face * 4 + corner;
|
|
105687
105742
|
positions.push(position.getX(vertex2) + offsetX, position.getY(vertex2) + offsetY, position.getZ(vertex2) + offsetZ);
|
|
105688
105743
|
normals.push(normal.getX(vertex2), normal.getY(vertex2), normal.getZ(vertex2));
|
|
105689
|
-
uvs.push(
|
|
105690
|
-
|
|
105691
|
-
|
|
105744
|
+
uvs.push(mapU(uv.getX(vertex2)), mapV(uv.getY(vertex2)));
|
|
105745
|
+
uvBounds.push(
|
|
105746
|
+
mapU(bounds?.getX(vertex2) ?? 0),
|
|
105747
|
+
mapV(bounds?.getY(vertex2) ?? 0),
|
|
105748
|
+
mapU(bounds?.getZ(vertex2) ?? 1),
|
|
105749
|
+
mapV(bounds?.getW(vertex2) ?? 1)
|
|
105692
105750
|
);
|
|
105693
105751
|
colors.push(color2?.getX(vertex2) ?? 1, color2?.getY(vertex2) ?? 1, color2?.getZ(vertex2) ?? 1);
|
|
105694
105752
|
}
|
|
@@ -105699,11 +105757,12 @@ gl_FragDepth=readDepth(vUv);
|
|
|
105699
105757
|
geometry.setAttribute("position", new Float32BufferAttribute(positions, 3));
|
|
105700
105758
|
geometry.setAttribute("normal", new Float32BufferAttribute(normals, 3));
|
|
105701
105759
|
geometry.setAttribute("uv", new Float32BufferAttribute(uvs, 2));
|
|
105760
|
+
geometry.setAttribute("uvBounds", new Float32BufferAttribute(uvBounds, 4));
|
|
105702
105761
|
geometry.setAttribute("color", new Float32BufferAttribute(colors, 3));
|
|
105703
105762
|
geometry.setIndex(indices);
|
|
105704
105763
|
geometry.computeBoundingBox();
|
|
105705
105764
|
geometry.computeBoundingSphere();
|
|
105706
|
-
const material = Materials.createShadedCanvasMaterial(canvas, false);
|
|
105765
|
+
const material = Materials.createShadedCanvasMaterial(canvas, false, false, true);
|
|
105707
105766
|
material.vertexColors = true;
|
|
105708
105767
|
const texture = material.uniforms?.map?.value ?? material.map;
|
|
105709
105768
|
const mesh = new Mesh(geometry, material);
|