3

我在 ThreeJS 上创建带有拉伸几何的随机形状,现在我想在其上应用纹理,但结果很难看。我不知道如何生成 UVMapping 以正确显示纹理。

我摆弄了我的问题:http: //jsfiddle.net/PsBtn/8/

在左边的网格上,一个面的纹理不正确,因为面是平的,我希望纹理不歪斜。

在右边,纹理被旋转但我不想要这个结果。

是否有一种自动生成 UVMapping 的方法,以便在这两个网格(挤出几何)上获得相同的纹理渲染?

这是我生成网格的方式:

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);
4

1 回答 1

1

我找到了一个解决方案,我必须从我的自定义表单中计算出 uv。这个网页对它非常有用:

http://paulyg.f2s.com/uv.htm

于 2013-02-26T16:51:58.943 回答