This commit is contained in:
2025-11-29 16:40:17 +02:00
parent 2078cef20b
commit f383d9d548
2 changed files with 37 additions and 18 deletions
@@ -1,4 +1,4 @@
import { TextureLoader, MeshStandardMaterial, MeshBasicMaterial, PlaneGeometry, Mesh, DoubleSide } from "three";
import { TextureLoader, MeshStandardMaterial, MeshBasicMaterial, PlaneGeometry, Mesh, DoubleSide, Vector3 } from "three";
import { assignParams } from "@/lib/MeshUtils";
class ImageObject {
@@ -28,6 +28,25 @@ class ImageObject {
}
}
this.object = new Mesh(geo, mp.metalness ? new MeshStandardMaterial(mp) : new MeshBasicMaterial(mp));
if (obj.distance) {
const o = this.object;
let dstm = obj.distance;
var oldBR = o.onBeforeRender;
o.material.opacity = 0.01;
o.onBeforeRender = function (renderer, scene, camera) {
oldBR && oldBR.apply(this, arguments);
var v = new Vector3();
o.getWorldPosition(v);
var dst = camera.position.distanceTo(v);
if (dst < dstm * 2 && dst > dstm * 1) {
o.material.opacity = dstm * 1 - (dst - dstm * 1);
}
if (dst < .5 * dstm) {
o.material.opacity = dstm * dst * 2;
}
};
}
resolve(this)
})
}