gpt4 book ai didi

javascript - 如何在 three.js 中创建带有法线和 UV 的动态网格?

转载 作者:搜寻专家 更新时间:2023-11-01 05:25:15 26 4
gpt4 key购买 nike

我知道如何在 three.js 中动态创建网格,但不清楚如何在网格中添加自定义 UV 和法线。这是创建自定义网格的方法,我们如何以编程方式向该网格添加 UV 和法线?

谢谢!

var imgTexture = THREE.ImageUtils.loadTexture(image);
var avatarGeom = new THREE.Geometry();

avatarGeom.vertices.push(new THREE.Vector3(0.895813,0.732893,0));
avatarGeom.vertices.push(new THREE.Vector3(-1.007173,0.732893,0));
avatarGeom.vertices.push(new THREE.Vector3(0.895813,-1.390674,0));
avatarGeom.vertices.push(new THREE.Vector3(-1.007173,-1.390674,0));

var face = new THREE.Face3(2,3,1);
avatarGeom.faces.push(face);

face = new THREE.Face3(0,2,1);
avatarGeom.faces.push(face);

var avatar = new THREE.Mesh(avatarGeom,new THREE.MeshLambertMaterial(imgTexture));
avatar.doubleSided = true;
scene.add(avatar);

最佳答案

正常进入 face . UV 进入 geometry .

var imgTexture = THREE.ImageUtils.loadTexture(image);
var avatarGeom = new THREE.Geometry();

avatarGeom.vertices.push(new THREE.Vector3(0.895813,0.732893,0));
avatarGeom.vertices.push(new THREE.Vector3(-1.007173,0.732893,0));
avatarGeom.vertices.push(new THREE.Vector3(0.895813,-1.390674,0));
avatarGeom.vertices.push(new THREE.Vector3(-1.007173,-1.390674,0));

var face = new THREE.Face3(2,3,1);
face.normal.set(0,0,1); // normal
avatarGeom.faces.push(face);
avatarGeom.faceVertexUvs[0].push([new THREE.UV(1,1),new THREE.UV(0,1),new THREE.UV(1,0)]); // uvs

face = new THREE.Face3(0,2,1);
face.normal.set(0,0,1); // normal
avatarGeom.faces.push(face);
avatarGeom.faceVertexUvs[0].push([new THREE.UV(0,0),new THREE.UV(1,1),new THREE.UV(1,0)]); // uvs

var avatar = new THREE.Mesh(avatarGeom,new THREE.MeshLambertMaterial(imgTexture));
avatar.doubleSided = true;
scene.add(avatar);

UVs 进入几何体的原因是因为这样我们可以有不同的 channel (相同几何体的不同 UVs 集)。

关于javascript - 如何在 three.js 中创建带有法线和 UV 的动态网格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10776614/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com