小编Joh*_*nny的帖子

Three.js 不要拉伸网格纹理(图像) - 让它覆盖它的容器

我有一个容器,我将图像应用于使用 Three.js 和网格。

这就是我将网格应用于场景的方式:

this.$els = {
    el: el,
    image: el.querySelector('.ch__image') <-- size of container image is being applied to
};

this.loader = new THREE.TextureLoader();
this.image = this.loader.load(this.$els.image.dataset.src);
this.sizes = new THREE.Vector2(0, 0);
this.offset = new THREE.Vector2(0, 0);

getSizes() {
    const { width, height, top, left } = this.$els.image.getBoundingClientRect();

    this.sizes.set(width, height);
    this.offset.set(left - window.innerWidth / 2 + width / 2, -top + window.innerHeight / 2 - height / 2)
}

createMesh() {
    this.geometry = new THREE.PlaneBufferGeometry(1, 1, 1, 1);
    this.material …
Run Code Online (Sandbox Code Playgroud)

javascript css three.js

2
推荐指数
1
解决办法
730
查看次数

标签 统计

css ×1

javascript ×1

three.js ×1