将具有纹理的两个平面合并为一个网格

时间:2015-01-14 11:29:02

标签: three.js

我想在threejs中合并两个网格。我想创建一个两个垂直相交的平面的几何。两个平面必须具有相同的纹理。 我尝试了以下方法。

目前发生此错误:THREE.Geometry.merge():geometry不是THREE.Geometry的实例。

  var texture = THREE.ImageUtils.loadTexture('/img/foo.png');
var material = new THREE.MeshPhongMaterial( { map: texture, side: THREE.DoubleSide, transparent: true });
var m_plane_1 = new THREE.PlaneGeometry( 128, 128); 
var m_plane_2 = new THREE.PlaneGeometry(128, 128);
var plane_1 = new THREE.Mesh(m_plane_1, material);
var plane_2 = new THREE.Mesh(m_plane_2, material);
plane_2.rotation.y = Math.PI / 2;

var combined =   new THREE.Geometry();

combined.merge(plane_1); // does not work 
//combined.merge(plane_1.geometry, plane_1.matrix); // this does not work
//combined.merge(m_plane_1.geometry, m_plane_1.matrix); // this does not work

scene.add(combined);

我试图阅读merge()的源代码,但无法得出任何结论。我已经读过stackoverflow线程,但他们的方法对我不起作用。 我该如何解决这个问题?

3 个答案:

答案 0 :(得分:1)

您想获得几何的交集。然后,您可以将任何纹理应用于新几何体。

要获得交叉点,您应该使用Chandler Prall的构造实体几何代码:http://evanw.github.io/csg.js/

答案 1 :(得分:0)

有几种方法可以合并两个几何,但实现所需的最简单方法可能是使用以下模式:

var geometry = new THREE.PlaneGeometry( 128, 128 );
var geometry2 = new THREE.PlaneGeometry( 128, 128 );
geometry2.applyMatrix( new THREE.Matrix4().makeRotationY( Math.PI / 2 ) );
geometry.merge( geometry2 );

three.js r.69

答案 2 :(得分:-1)

试试这个:

plane_1.updateMatrix();
//Now the function merge
combined.merge(plane_1.geometry, plane_1.matrix);


//combined.merge(plane_1); // does not work
//combined.merge(plane_1.geometry, plane_1.matrix); // this does not work
//combined.merge(m_plane_1.geometry, m_plane_1.matrix); // this does not work