我正在使用对象加载器加载基本的多维数据集(几何体),并且希望获得线框视图。
它没有出现!
当我使用(otherGeometry)-从three.js原语时,它可以使用以下代码将其渲染得很好:
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/90/three.min.js"></script>
<script src="https://threejs.org/examples/js/controls/OrbitControls.js"></script>
<script src="https://threejs.org/examples/js/loaders/OBJLoader.js"></script>
var material = new THREE.MeshBasicMaterial({color: 0xffffff});
var objLoader = new THREE.OBJLoader();
var geometry = objLoader.parse(testObj);
var otherGeometry = new THREE.BoxGeometry(100, 100, 5);
var geo = new THREE.WireframeGeometry(geometry);
var mat = new THREE.LineBasicMaterial({color: 0xff0000, linewidth: 1});
var wireframe = new THREE.LineSegments(geo, mat);
scene.add(wireframe);
var testObj = `# cube.obj
#
g cube
v 0.0 0.0 0.0
v 0.0 0.0 1.0
v 0.0 1.0 0.0
v 0.0 1.0 1.0
v 1.0 0.0 0.0
v 1.0 0.0 1.0
v 1.0 1.0 0.0
v 1.0 1.0 1.0
vn 0.0 0.0 1.0
vn 0.0 0.0 -1.0
vn 0.0 1.0 0.0
vn 0.0 -1.0 0.0
vn 1.0 0.0 0.0
vn -1.0 0.0 0.0
f 1//2 7//2 5//2
f 1//2 3//2 7//2
f 1//6 4//6 3//6
f 1//6 2//6 4//6
f 3//3 8//3 7//3
f 3//3 4//3 8//3
f 5//5 7//5 8//5
f 5//5 8//5 6//5
f 1//4 5//4 6//4
f 1//4 6//4 2//4
f 2//1 6//1 8//1
f 2//1 8//1 4//1`;
答案 0 :(得分:1)
OBJLoader.parse()
不返回几何,而是返回THREE.Group
的实例。在特定情况下,您必须选择第一个孩子的几何形状。
var group = objLoader.parse( testObj )
var geometry = group.children[ 0 ].geometry;
Ta-da!出现一个奇妙的线框(。◕‿‿◕。)