我用另一个几何体创建了一个带顶点和uv的网格,如下所示:
var geom = mesh.geometry;
var projectGeometry = new THREE.Geometry();
var faces = [];
for(var i = 0; i < geom.faces.length; i++){
var verts = [geom.faces[i].a, geom.faces[i].b, geom.faces[i].c];
var uvs = [geom.faceVertexUvs[0][i][0], geom.faceVertexUvs[0][i][1], geom.faceVertexUvs[0][i][2]];
var pts = [];
var uvpts = {};
var uv = [];
var vec = geom.vertices[verts[v]].clone();
for(var n = 0; n < 3; n++){
uv.push(new THREE.Vector2( (vec[n].x + 1) / 2, (vec[n].y + 1) / 2));
uvpts = { x: 2*geom.faceVertexUvs[0][i][n].x - 1, y: 2*geom.faceVertexUvs[0][i][n].y - 1, z: 0};
projectGeometry.vertices.push( uvpts );
}
projectGeometry.faceVertexUvs[0].push(uv);
var newFace = geom.faces[i].clone();
newFace.a = decalGeometry.vertices.length - 3;
newFace.b = decalGeometry.vertices.length - 2;
newFace.c = decalGeometry.vertices.length - 1;
var newUvFace = new THREE.Face3( newFace.a, newFace.b, newFace.c );
newUvFace.normal = {x: 0, y: 0, z: 1};
newUvFace.color = {r: 1, g: 1, b: 1};
newUvFace.vertexNormals.push({x: 0, y: 0, z: 1});
newUvFace.vertexNormals.push({x: 0, y: 0, z: 1});
newUvFace.vertexNormals.push({x: 0, y: 0, z: 1});
projectGeometry.faces.push(newUvFace);
}
我将网格物体添加到场景中:
var mesh = new THREE.Mesh(projectGeometry, material.clone());
scene.add(mesh);
使用如下定义的材料:
texture = THREE.ImageUtils.loadTexture("tex.png");
material: new THREE.MeshPhongMaterial({
side: THREE.DoubleSide,
color: 0xffffff,
map: texture,
polygonOffset: true,
polygonOffsetFactor: -4,
transparent: true,
depthWrite: false,
shininess: 150,
specular: 0xffffff
});
纹理有一些透明度,所以我可以看到&#34;形状&#34;纹理是正确的,但没有应用颜色。它全黑了。
答案 0 :(得分:0)
这是一个轻微的问题。由于我的纹理材质具有透明度,因此我使用了PhongMaterial。我配置了DirectionalLight来照亮场景。由于某种原因,纹理颜色呈现黑色。我将灯光改为AmbientLight,一切都很好。