This commit is contained in:
2025-10-14 18:36:02 +03:00
parent a6827f4ddb
commit a60d94fe66
16 changed files with 1225 additions and 33 deletions
@@ -0,0 +1,51 @@
import { MeshStandardMaterial, Color, Vector3 } from "three";
import { Text } from "troika-three-text";
import Utils from "@/lib/utils";
class TextObject {
constructor(obj, params) {
const txt = new Text();
// Set properties to configure:
txt.text = obj.text;
txt.fontSize = 0.022;
txt.lineHeight = 1.1;
txt.maxWidth = obj.width || params.wallSize * .73;
txt.textAlign = 'center';
txt.font = params.fontPath;
txt.anchorX = 'center';
txt.anchorY = 'bottom';
txt.curveRadius = 0;
txt.outlineColor = 0xffffff;
txt.outlineWidth = '15%';
txt.outlineBlur = '50%';
Utils.assignMeshParams(txt, obj)
let m = new MeshStandardMaterial({
roughness: .73,
metalness: .37,
});
txt.material = m;
txt.color = new Color(0x0);
txt.sync();
this.txt = txt;
this.mesh = 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;
}
};
}
}
}
export {TextObject}