three.js - THREE.Geometry 上的视频纹理
问题描述
我能找到的唯一例子是在 PlaneGeometry 或 BoxGeometry 上使用的视频纹理。我有一个自定义飞机,我有一个视频应用到。视频播放(颜色变化)并显示,但比例关闭(看起来像放大了)。
视频在右上角播放,绿色平面是视频所在的自定义几何图形。
三、几何
this.geometry = new THREE.Geometry();
this.geometry.vertices.push(
new THREE.Vector3(900, 0, 840)
new THREE.Vector3(-900, 0, 1200),
new THREE.Vector3(900, 900, 840),
new THREE.Vector3(-900, 900, 1200),
);
this.geometry.faces.push(
new THREE.Face3(0, 1, 2),
new THREE.Face3(1, 3, 2),
);
this.geometry.computeFaceNormals();
this.object = new THREE.Mesh(this.geometry, this._videoMaterial());
videoMaterial函数
_videoMaterial() {
let videoImage = document.createElement('canvas');
videoImage.width = 480;
videoImage.height = 204;
this.videoImageContext = videoImage.getContext('2d');
this.videoImageContext.fillStyle = '#211e79';
this.videoImageContext.fillRect(0, 0, videoImage.width, videoImage.height);
this.videoTexture = new THREE.Texture(videoImage);
this.videoTexture.minFilter = THREE.LinearFilter;
this.videoTexture.magFilter = THREE.LinearFilter;
this.videoTexture.format = THREE.RGBFormat;
return new THREE.MeshBasicMaterial({
map: this.videoTexture,
overdraw: true,
side: THREE.DoubleSide
});
}
解决方案
正如囚犯 849 所说,您需要将 UV 添加到您的几何体中,以便它知道如何在其表面上映射纹理
// Add UVs of face 1
this.geometry.faceVertexUvs[0].push([
new THREE.Vector2(0, 0)
new THREE.Vector2(0, 1),
new THREE.Vector2(1, 0)
]);
// Add UVs of face 2
this.geometry.faceVertexUvs[0].push([
new THREE.Vector2(0, 1)
new THREE.Vector2(1, 0),
new THREE.Vector2(1, 1)
]);
this.geometry.uvsNeedUpdate();
您可能需要调整 UV 的顺序以匹配面上顶点的顺序,但您需要这样的排列:
https://threejs.org/docs/index.html#api/en/core/Geometry.faceVertexUvs
推荐阅读
- php - PHP倒数计时器问题,非常感谢帮助
- javascript - 如何将 html/css/js 应用程序部署到 heroku
- c# - 在 C# 中组合绝对和相对 URL 时“无法确定 URI 的格式”
- java - Hibernate JAVA中的多级继承
- python - 如何从python中的较大数字中删除第一个数字
- r - 在 Shiny 中调整图形生成
- node.js - Google Sheets API v4 错误:“无效请求 [0].addFilterView:没有 ID 为 2 的网格”
- mysql - 在 MySQL 中实现 3NF 而不损失查询速度?
- crashlytics - 适用于 Apple Watch 的 Firebase Crashlytics
- python - 如何使用 asyncio 更新具有两个不同时间间隔的 Dataframe