合并网格上的均匀纹理

时间:2017-01-09 15:13:09

标签: javascript three.js texture-mapping

如何将几何体中的合并网格物体在一个平静点而不是3个中进行纹理化?在我的示例代码中,纹理在每个分离的几何体上完成(参见图像,点1和2)。两个立方体和一个圆柱。

Wrong result 使用的代码:

$home = file_get_contents('http://192.168.1.XXX/wordpress/read.html');
$dom = new DOMDocument();
$dom->loadHTML($home);
if(($body=$dom->getElementsByTagName("body"))->length>0){
    $text=$body[0]->nodeValue
}

2 个答案:

答案 0 :(得分:1)

您需要确保合并网格之间的UV匹配。该接缝是由不同对象具有不同UV布局的事实引起的。您需要在创建的几何体上编辑faceVertexUvs或faceUvs以使UV是连续的,然后设置uvsNeedUpdate

答案 1 :(得分:0)

仅限社区。这是我用来修复它的功能。在mergeMes​​hes()之后调用它。

function assignUVs(geometry) {
 geometry.computeBoundingBox();

 var max = geometry.boundingBox.max, min = geometry.boundingBox.min;
 var offset = new THREE.Vector2(0 - min.x, 0 - min.y);
 var range = new THREE.Vector2(max.x - min.x, max.y - min.y);
 var faces = geometry.faces;
 var vertices = geometry.vertices;

 geometry.faceVertexUvs[0] = [];
 for (var i = 0, il = faces.length; i < il; i++) {
  var v1 = vertices[faces[i].a], v2 = vertices[faces[i].b], v3 = vertices[faces[i].c];

  geometry.faceVertexUvs[0].push([
   new THREE.Vector2((v1.x + offset.x) / range.x, (v1.y + offset.y) / range.y),
   new THREE.Vector2((v2.x + offset.x) / range.x, (v2.y + offset.y) / range.y),
   new THREE.Vector2((v3.x + offset.x) / range.x, (v3.y + offset.y) / range.y)
  ]);
 }
 geometry.uvsNeedUpdate = true;
}