我做了一个小工具,我可以选择一个物体的面,并获得每个边和角的长度和角度。更新到Three.js Face4的r67时消失了,我无法重新创建之前的内容。 n =(f instanceof THREE.Face3)? 3:4会这样,所以我可以为Face4增加4个uv。但我现在还没有看到一种方法可以知道什么时候会有Face4,所以我可以添加2 Face3。
下面的代码是一个获取obj的几何的函数。
function draw(g)
{
objectContainer = new THREE.Object3D();
texture = THREE.ImageUtils.loadTexture('uvmap.png');
texture.flipY = false;
materials = [];
materials.push(new THREE.MeshLambertMaterial({
map: texture,
vertexColors: THREE.VertexColors
}));
var faceIndices = ['a','b','c','d'];
var color = new THREE.Color(0xffffff);
color.setHex(0x333333);
var uvs = [];
uvs.push(new THREE.Vector2(0,1));
uvs.push(new THREE.Vector2(0,0));
uvs.push(new THREE.Vector2(1,1));
uvs.push(new THREE.Vector2(1,0));
for (i = 0; i < g.faces.length; i++)
{
face = g.faces[i];
geo = new THREE.Geometry();
geo.faces.push(new THREE.Face3(0,1,2));
geo.faceVertexUvs[0] = [];
geo.faceVertexUvs[0].push([uvs[0], uvs[1], uvs[3]]);
geo.faces[0].materialIndex = 0;
for (j = 0; j < 3; j++)
{
fi = face[faceIndices[j]];
v = g.vertices[fi];
geo.vertices.push(new THREE.Vector3(v.x,v.y,v.z));
geo.faces[0].vertexColors[j] = color;
}
geo.computeVertexNormals();
geo.computeBoundingBox();
obj = new THREE.SceneUtils.createMultiMaterialObject(geo, materials);
objectContainer.add(obj);
}
scene.add(objectContainer);
}
答案 0 :(得分:0)
你应该在face3上只设置3个uv值!
/* create faces and uv's */
if (n == 3)
{
g.faces.push(new THREE.Face3(0,1,2));
g.faceVertexUvs[0].push([ uvs[0], uvs[1], uvs[2], uvs[3] ]);
}
不应该设置uvs [3]!