THREE.js:在拉伸文本上添加一条线

时间:2015-08-31 09:36:17

标签: javascript three.js

我想在文本上添加一条水平线,然后将其拉伸:

var geo = new THREE.TextGeometry("x", geometry_options);
var mat = new THREE.MeshBasicMaterial({color: 0, side:THREE.DoubleSide});
geo.computeBoundingBox ();
var vec = new THREE.Shape();
vec.moveTo(geo.boundingBox.min.x, geo.boundingBox.max.y);
vec.lineTo(geo.boundingBox.max.x, geo.boundingBox.max.y);
geo.addShape(vec);
var mesh = new THREE.Mesh(geo, mat);

调用geo.addShape(vec)时发生Javascript错误。我想我有一些误解。我对THREE.js还不是很熟悉。任何帮助或替代方法,将非常感激。

1 个答案:

答案 0 :(得分:0)

而不是geo.addShape(vec);尝试

geo.merge(vec.makeGeometry());

但你的几何只是一条线 - 它没有多边形 - 所以它可能不会看起来正确。

另一种选择可能是将两个对象组合在一起,一个是网格,另一个是一行,例如:

 var all = new THREE.Obejct3D();
 var geo = new THREE.TextGeometry("x", geometry_options);
 var mat = new THREE.MeshBasicMaterial({color: 0, side:THREE.DoubleSide});
 geo.computeBoundingBox ();
 var mesh = new THREE.Mesh(geo, mat);
 all.add(mesh);
 var vecg = new THREE.Geometry();
 vecg.vertices.push(
    new THREE.Vector3(geo.boundingBox.min.x, geo.boundingBox.max.y,0),
    new THREE.Vector3(geo.boundingBox.max.x, geo.boundingBox.max.y,0));
 var line = new THREE.Line(vecg, new THREE.LineBasicMaterial());
 all.add(line);

然后根据需要scene.add(all);