javascript - 三.js Shader修改TextGeometry
问题描述
我对三个完全陌生,因此这个问题对其他人来说可能很明显。
所以我实现了加载我的字体并相应地构建了一个 TextGeometry。此外,我使用 EdgesGeometry 创建了一种边框。这工作正常。
但是我如何实现几何图形/网格的行为如下:https ://edoardosmerilli.com/overview/ - 换句话说:它从左到中心弯曲,反之亦然(就像旧的电子管电视的屏幕)到滚动位置。我怎样才能达到这样的效果?它是一个顶点着色器吗?是不是三个向量产生了这种效果?
我感谢每一个提示!
export default class Title {
constructor($el, $scene) {
this.scene = $scene;
this.title = $el.firstElementChild;
this.offset = new THREE.Vector2(0, 0);
const loader = new THREE.FontLoader();
loader.load('/RL-Unno.json', (font) => {
const geometry = new THREE.TextGeometry(this.title.innerHTML, {
font: font,
size: 120,
height: 1
});
geometry.center();
this.init(geometry);
})
}
init = (geometry) => {
const material = new THREE.MeshBasicMaterial({opacity: 0});
this.mesh = new THREE.Mesh(geometry, material);
this.getPosition();
this.mesh.position.set(this.offset.x, this.offset.y, 0);
this.scene.add(this.mesh);
const geo = new THREE.EdgesGeometry(geometry);
const outline = new THREE.LineBasicMaterial({
linewidth: 4
});
this.border = new THREE.LineSegments(geo, outline);
this.border.position.set(this.mesh.position.x, this.mesh.position.y, 0);
this.scene.add(this.border);
this.createListeners();
};
getPosition = () => {
const {width, height, top, left} = this.title.getBoundingClientRect();
this.offset.set(left - window.innerWidth / 2 + width / 2, -top + window.innerHeight / 2 - height / 2);
};
createListeners = () => {
this.title.addEventListener('mouseenter', () => {
gsap.timeline().set(this.mesh.material, {
opacity: 1
})
});
this.title.addEventListener('mouseleave', () => {
gsap.timeline().set(this.mesh.material, {
opacity: 0
})
});
};
update = () => {
if (!this.mesh) return;
this.getPosition();
gsap.timeline().set([this.mesh.position, this.border.position], {
x: this.offset.x,
y: this.offset.y,
});
}
}
解决方案
推荐阅读
- html - 动态 SVG 模式作为背景:可能吗?我举个例子
- c++ - 错误:从 'std::__1::__wrap_iter 没有可行的转换
'到'int' - c - 数组中的二分查找
- javascript - NodeJS API 获取每个类别的 Items 数组
- c - 从文件指示的文件中读取
- flutter - 颤动 - 如何使用 Chewie 控制器恢复播放先前持续时间的视频?
- scala - Scala Map调用多个函数
- python-3.x - 在Python中发出http请求时如何在代理密码字符串中转义@字符
- python - Python动态属性文件
- javascript - 如何在玩笑中强制函数的返回值?