我有一个容器,我将图像应用于使用 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)