diff --git a/src/components/InteractiveObjects/ImageObject.js b/src/components/InteractiveObjects/ImageObject.js index 98712ec..8665d49 100644 --- a/src/components/InteractiveObjects/ImageObject.js +++ b/src/components/InteractiveObjects/ImageObject.js @@ -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) }) } diff --git a/src/components/InteractiveObjects/TextObject.js b/src/components/InteractiveObjects/TextObject.js index f00d524..f8ebdc3 100644 --- a/src/components/InteractiveObjects/TextObject.js +++ b/src/components/InteractiveObjects/TextObject.js @@ -30,23 +30,23 @@ class TextObject { txt.sync(); this.txt = txt; this.object = txt; - // if (obj.effect == 'distance') { - // let dstm = .8; - // var oldBR = txt.onBeforeRender; - // txt.material[1].opacity = 0.01; - // txt.onBeforeRender = function (renderer, scene, camera) { - // oldBR && oldBR.apply(this, arguments); - // var v = new Vector3(); - // txt.getWorldPosition(v); - // var dst = camera.position.distanceTo(v); - // if (dst < dstm * 2 && dst > dstm * 1) { - // txt.material[1].opacity = dstm * 1 - (dst - dstm * 1); - // } - // if (dst < .5 * dstm) { - // txt.material[1].opacity = dstm * dst * 2; - // } - // }; - // } + if (obj.distance) { + let dstm = obj.distance; + var oldBR = txt.onBeforeRender; + txt.material[1].opacity = 0.01; + txt.onBeforeRender = function (renderer, scene, camera) { + oldBR && oldBR.apply(this, arguments); + var v = new Vector3(); + txt.getWorldPosition(v); + var dst = camera.position.distanceTo(v); + if (dst < dstm * 2 && dst > dstm * 1) { + txt.material[1].opacity = dstm * 1 - (dst - dstm * 1); + } + if (dst < .5 * dstm) { + txt.material[1].opacity = dstm * dst * 2; + } + }; + } } }