首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Three.js (faces)中渲染网格三维顶点

在Three.js (faces)中渲染网格三维顶点
EN

Stack Overflow用户
提问于 2016-07-12 16:38:43
回答 2查看 865关注 0票数 0

给定由200+ API生成的向量数组{X:,Y:,Z:}生成的AutoCad顶点,我试图在没有运气的情况下在THREE.js中呈现它们。

目前,我正在对数字200进行所有可能的排列,并将所有顶点连接在一起--,我不认为它是这样做的,因为它给出了超过200 k的面。

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

AutoCAD代码:

代码语言:javascript
复制
//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代码:

代码语言: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);
    }
}

致以敬意,

伊万

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-07-12 18:04:18

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

票数 0
EN

Stack Overflow用户

发布于 2016-07-12 17:04:27

相反,我建议您使用锻造模型衍生API从文件中提取可查看的内容。翻译完文件后,可以使用查看器 (基于Three.js,但针对工程文件进行优化)查看它。您可以在这个吉特布上找到几个示例。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38334625

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档