public bool CreateGeometry()
        {
            bool result = false;

            try
            {
                for (int i = 0; i < objMeshes.Count; i++)
                {
                    ObjMesh mesh = objMeshes[i];

                    List <Curve> curveList = new List <Curve>();

                    ObjVertice startV = mesh.ObjVertex[mesh.ObjVertex.Count - 1];
                    ObjVertice endV   = mesh.ObjVertex[0];

                    XYZ startPoint = new XYZ(startV.XValue, startV.YValue, startV.ZValue);
                    XYZ endPoint   = new XYZ(endV.XValue, endV.YValue, endV.ZValue);

                    Line line = Line.CreateBound(startPoint, endPoint);
                    curveList.Add(line);

                    for (int j = 0; j < mesh.ObjVertex.Count - 1; j++)
                    {
                        startV = mesh.ObjVertex[j];
                        endV   = mesh.ObjVertex[j + 1];

                        startPoint = new XYZ(startV.XValue, startV.YValue, startV.ZValue);
                        endPoint   = new XYZ(endV.XValue, endV.YValue, endV.ZValue);

                        line = Line.CreateBound(startPoint, endPoint);
                        curveList.Add(line);
                    }
                    CurveLoop        curveLoop = CurveLoop.Create(curveList);
                    List <CurveLoop> profile   = new List <CurveLoop>();
                    profile.Add(curveLoop);
                    Solid extrusion = GeometryCreationUtilities.CreateExtrusionGeometry(profile, new XYZ(0, 0, 1), 1);

                    if (null != extrusion)
                    {
                        foreach (Face face in extrusion.Faces)
                        {
                            XYZ normal = face.ComputeNormal(new UV(0, 0));
                            if (normal.Z > 0)
                            {
                                displayingFaces.Add(face); break;
                            }
                        }
                    }
                }
                result = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to create geometry for surfaces to be visulized with data.\n" + ex.Message, "Analysis Data Manager - Create Geometry", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                result = false;
            }
            return(result);
        }
Exemplo n.º 2
0
        public static bool ReadObjFile(string objFile, out List <ObjMesh> meshes)
        {
            bool result = false;

            meshes = new List <ObjMesh>();
            try
            {
                using (StreamReader reader = new StreamReader(objFile))
                {
                    string  line = string.Empty;
                    ObjMesh mesh = null;

                    while ((line = reader.ReadLine()) != null)
                    {
                        string[] split = line.Split(' ');
                        if (line.StartsWith("o "))
                        {
                            if (split.Length > 1)
                            {
                                if (null != mesh)
                                {
                                    meshes.Add(mesh);
                                }
                                string name = split[1];
                                mesh = new ObjMesh(name);
                            }
                        }
                        else if (line.StartsWith("v "))
                        {
                            if (split.Length > 3)
                            {
                                ObjVertice vertice = new ObjVertice(double.Parse(split[1]), double.Parse(split[2]), double.Parse(split[3]));
                                if (null != mesh)
                                {
                                    mesh.ObjVertex.Add(vertice);
                                }
                            }
                        }
                    }
                    meshes.Add(mesh);
                }
                result = true;
            }
            catch (Exception ex)
            {
                string message = ex.Message;
                result = false;
            }
            return(result);
        }