繁体   English   中英

在Three.js中渲染网格3D顶点(面)

[英]Render mesh 3D vertices in Three.js (faces)

鉴于AutoCad API以向量{X:,Y:,Z:}数组形式生成的200多个顶点,我试图在THREE.js中渲染它们没有任何运气。

现在,我正在对数字200进行所有可能的排列,并将所有顶点连接在一起- 我不认为这是完成20万个面的方法。

编辑:我的AutoCAD代码正在获取所有顶点,然后尝试获取其连接的顶点的ID(vertex1和vertex2)。 但是,GetHashCode()不起作用。 问题不在于它返回了巨大的ID号,例如148335760和682610240。问题是这些ID不是唯一的,它们恰好被定义并且没有连接到任何其他顶点。

AutoCAD代码:

//data structures for serialisation
public class EdgeMe
{
    public int vertex1;
    public int vertex2;
}
public class VertexMe
{
    public int id;
    public Point3d Point;
    public List<EdgeMe> Edges = new List<EdgeMe>();
}

public class DataMe{
    public Extents3d extents;
    public string layer;
    public List<VertexMe> points = new List<VertexMe>();
}


//...


// Get each Solid3d in modelspace and add its extents
// to the list
foreach (var id in ms)
{
    var obj = tr.GetObject(id, OpenMode.ForRead);
    var sol = obj as Solid3d;

    DataMe dataMe = new DataMe();
    if (sol != null)
    {
        dataMe.extents = sol.GeometricExtents;
        dataMe.layer = sol.Layer;
        using (var brep = new Autodesk.AutoCAD.BoundaryRepresentation.Brep(sol))
        {
            foreach (var vertex in brep.Vertices)
            {
                VertexMe vertexMe = new VertexMe();
                vertexMe.Point = vertex.Point;
                vertexMe.id = vertex.Brep.GetHashCode();
                foreach(var edge in vertex.Edges)
                {
                    EdgeMe edgeMe = new EdgeMe();
                    edgeMe.vertex1 = edge.Vertex1.Brep.GetHashCode();
                    edgeMe.vertex2 = edge.Vertex2.Brep.GetHashCode();
                    vertexMe.Edges.Add(edgeMe);
                }

                dataMe.points.Add(vertexMe);
            }
        }
    }
    sols.Add(dataMe);
}

JavaScript代码:

var faces = function(vertices) {
    var results = [];

    var vertex = [0, 1, 2];
    results.push(vertex.slice());

    while(true) {
        vertex[2]++;
        if(vertex[2] > vertices) {

            vertex[1]++;
            if(vertex[1] >= vertices) {
                vertex[0]++;
                vertex[1] = vertex[0] + 1;

                if(vertex[0] > vertices - 2)
                    return results;
            }

            vertex[2] = vertex[1] + 1;
        }

        results.push(vertex.slice());
    }

};

var generate = function( ... ) {
    // Process each box, adding it to the scene
    for (var sol in sols) { 
        var s = sols[sol];
        var vertices = [];

        for(var vertix in s.points) {// deserialize
            vertix = s.points[vertix];

            vertices.push(new THREE.Vector3(vertix.X, vertix.Y, vertix.Z));
        }

        var holes = [];
        var triangles, mesh;
        var geometry = new THREE.Geometry();
        geometry.vertices = vertices;
        var xfaces = faces(vertices.length);

        for(var i = 0; i < xfaces.length; i++) {
            geometry.faces.push( new THREE.Face3( xfaces[i][0], xfaces[i][1], xfaces[i][2] ));
        }
        geometry.computeFaceNormals();
        geometry.computeVertexNormals();

        mesh = new THREE.Mesh( geometry, customimg );

        mesh.rotation.set( Math.PI/2, 0, 0);

        root.add(mesh);
    }
}

问候,

约安

相反,我建议您使用Forge Model Derivative API从文件中提取可见内容。 翻译文件后,您可以使用查看器 (基于Three.js,但针对工程文件进行了优化)对其进行查看。 您可以在此Github中找到几个示例。

你不能做你正在做的事。 您正在尝试猜测连接信息。 那不应该是猜测。 该应用程序需要将连接信息返回给您。

暂无
暂无

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

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