简体   繁体   English

用three.js加载OBJMTL对象并获取网格的几何参数

[英]Loading an OBJMTL Object with three.js and get geometry parameter of the Mesh

I just load an MTLOBJ and everything is fine but when I want to get the Geometry attribute of the object to get the vertices, there is no way because apparently, it loads a Object3D which should have a Mesh. 我只是加载了一个MTLOBJ,一切都很好,但是当我想获取对象的Geometry属性以获取顶点时,就没有办法了,因为显然,它加载了应该具有Mesh的Object3D。 But I hardly try to find a way to solve this problem. 但是我几乎没有尝试找到解决这个问题的方法。

It seems that Mrdoob proposes to get the parses data but every parameters used in the parse function are set private .. 看来Mrdoob建议获取解析数据,但在解析函数中使用的每个参数都设置为private ..

I try to get the vertices parameters from the geometry parameter which should be in a mesh but no way, even looking through the doc. 我尝试从几何参数中获取顶点参数,该参数应该在网格中,但是即使在文档中也无法找到。

You can find the geometry in the hierarchy by doing this: 您可以通过执行以下操作在层次结构中找到几何:

object.traverse( function ( child ) {

    if ( child.geometry !== undefined ) {

        console.log( child.geometry.vertices );

    }

} );

After some researchs, it appeared that the Object3D is composed with Meshs . 经过一些研究,看来Object3D是由Meshs组成的

And in the case of loading an OBJMTL (.obj and .mtl), the Object3D named modele had the Mesh accessible by doing modele.children[O] and the array vertices of geometry by doing modele.children[0].geometry.vertices . 在加载OBJMTL(.obj和.mtl)的情况下, 通过执行modele.children [O]可访问名为modele的Object3D,并通过执行modele.children [0] .geometry.vertices 可访问几何体的网格顶点。

I was looking for a way to be sure the object I attribute to my modele was the Mesh with his geometry parameter, thank you Mr Doob for that. 我正在寻找一种方法来确保我归因于我的模型的对象是带有其几何参数的网格,谢谢杜布先生。

function loadModel(obj, mtl) {
    loader.load(obj, mtl, function ( object ) {
        modele = object;
        //loadingDone = true;
        analyseModel();
        //putModel();
    });
}

function analyseModel() {
    analyser = new AnalyseObj(modele.children[0]); //I give the Mesh of my model
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM