我在ThreeJS上使用拉伸几何创建随机形状,现在我想在其上应用纹理,但结果很难看。我无法弄清楚如何生成UVMapping以正确显示纹理。
我摆弄了我的问题: http://jsfiddle.net/PsBtn/8/
在左侧网格上,一个面部没有正确纹理,因为面部是平的,我希望纹理不会歪斜。
在右侧,旋转纹理,但我不想要这个结果。
是否有一种自动生成UVMapping的方法,以便在这两个网格上获得相同的纹理渲染(Extrude Geometry)?
以下是我生成网格的方法:
var points = []
points.push(new THREE.Vector2(-1000, -700));
points.push(new THREE.Vector2(-1000, -300));
points.push(new THREE.Vector2(-300, -300));
points.push(new THREE.Vector2(-300, -500));
shape = new THREE.Shape(points);
var geometry = new THREE.ExtrudeGeometry(shape, extrudeSettings),
texture = new THREE.Texture(canvas);
texture.needsUpdate = true;
var material = new THREE.MeshBasicMaterial({
color: 0xFF00FF,
map: texture
});
geometry.faceUvs = [[]];
geometry.faceVertexUvs = [[]];
for (var f = 0; f < geometry.faces.length; f++) {
var faceuv = [
new THREE.Vector2(0, 1),
new THREE.Vector2(1, 1),
new THREE.Vector2(1, 0),
new THREE.Vector2(0, 0)
];
geometry.faceUvs[0].push(new THREE.Vector2(0, 1));
geometry.faceVertexUvs[0].push(faceuv);
}
mesh = THREE.SceneUtils.createMultiMaterialObject(geometry, [material, new THREE.MeshBasicMaterial({
color: 0x000000,
wireframe: true,
transparent: true
})]);
mesh.position.z = -100;
mesh.position.y = 200;
scene.add(mesh);