コード例 #1
0
ファイル: PlyFile.cs プロジェクト: nickcooksey/UtilityLibs
 private void AnalyzeElement(ref IPlyElement element)
 {
     foreach (IPlyProperty property in element.Properties)
     {
         if ((property.Type == PlyPropertyType.nx) |
             (property.Type == PlyPropertyType.ny) |
             (property.Type == PlyPropertyType.nz))
         {
             element.ContainsNormal = true;
         }
         if ((property.Type == PlyPropertyType.x) |
             (property.Type == PlyPropertyType.y) |
             (property.Type == PlyPropertyType.z))
         {
             element.ContainsVertex = true;
         }
         if ((property.Type == PlyPropertyType.red) |
             (property.Type == PlyPropertyType.blue) |
             (property.Type == PlyPropertyType.green))
         {
             element.ContainsColor = true;
         }
     }
     if (element.Type == PlyElementType.vertex)
     {
         _containsVertices = true;
     }
     if (element.Type == PlyElementType.face)
     {
         _containsFaces = true;
     }
     if (element.Type == PlyElementType.edge)
     {
         _containsEdges = true;
     }
     if (element.Type == PlyElementType.material)
     {
         _containsMaterials = true;
     }
 }
コード例 #2
0
ファイル: PlyFile.cs プロジェクト: nickcooksey/UtilityLibs
        public void Open(string fileName)
        {
            try
            {
                using (sr = new StreamReader(fileName))
                {
                    _containsNormals = false;
                    ReadHeader();
                    for (int i = 0; i < this.Header.Elements.Count; i++)
                    {
                        IPlyElement element = Header.Elements.ElementAt(i);
                        AnalyzeElement(ref element);
                        List <string> section = new List <string>(element.Count);
                        for (int k = 0; k < element.Count; k++)
                        {
                            section.Add(NextLine());
                        }

                        ReadBody(section, element);

                        if (element.ContainsVertex && element.ContainsNormal)
                        {
                            _containsNormals = true;
                        }
                    }

                    if (!_containsNormals)
                    {
                        CreateNormals();
                    }
                };
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
        }
コード例 #3
0
ファイル: RPly.cs プロジェクト: Jimbobicus/RPlySharp
 /// <summary>
 /// Returns information about the element originating a callback
 /// </summary>
 /// <param name="argument">handle to argument</param>
 /// <param name="element">receives a the element handle (if non-null)</param>
 /// <param name="instanceIndex">receives the index of the current element instance (if non-null)</param>
 /// <returns>true if successful, false otherwise</returns>
 public static bool GetArgumentElement(IPlyArgument argument, out IPlyElement element, out int instanceIndex)
 {
     throw new NotImplementedException();
 }
コード例 #4
0
ファイル: PlyFile.cs プロジェクト: nickcooksey/UtilityLibs
        private void ReadBody(List <string> section, IPlyElement element)
        {
            foreach (string line in section)
            {
                string[] tokens = line.Split(splitter, StringSplitOptions.RemoveEmptyEntries);
                if (element.Type == PlyElementType.vertex)
                {
                    float[]   floatTokens = new float[tokens.Length];
                    PlyVertex Vertex      = new PlyVertex();
                    for (int i = 0; i < tokens.Length; i++)
                    {
                        string          typeName = element.Properties[i].TypeName;
                        string          name     = element.Properties[i].Name;
                        PlyPropertyType propType = element.Properties[i].Type;
                        byte            r        = 0;
                        byte            g        = 0;
                        byte            b        = 0;
                        if (propType == PlyPropertyType.x)
                        {
                            Vertex.X = float.Parse(tokens[i]);
                        }
                        if (propType == PlyPropertyType.y)
                        {
                            Vertex.Y = float.Parse(tokens[i]);
                        }
                        if (propType == PlyPropertyType.z)
                        {
                            Vertex.Z = float.Parse(tokens[i]);
                        }
                        if (propType == PlyPropertyType.nx)
                        {
                            Vertex.Normal.X = double.Parse(tokens[i]);
                        }
                        if (propType == PlyPropertyType.ny)
                        {
                            Vertex.Normal.Y = double.Parse(tokens[i]);
                        }
                        if (propType == PlyPropertyType.nz)
                        {
                            Vertex.Normal.Z = double.Parse(tokens[i]);
                        }
                        if (propType == PlyPropertyType.red)
                        {
                            r = byte.Parse(tokens[i]);
                        }
                        if (propType == PlyPropertyType.green)
                        {
                            g = byte.Parse(tokens[i]);
                        }
                        if (propType == PlyPropertyType.blue)
                        {
                            b = byte.Parse(tokens[i]);
                        }
                        Vertex.Col = System.Drawing.Color.FromArgb(r, g, b);
                    }

                    Vertices.Add(Vertex);
                }
                if (element.Type == PlyElementType.face)
                {
                    var indexList = new List <int>();
                    for (int i = 1; i < tokens.Length; i++)
                    {
                        int temp = int.Parse(tokens[i]);
                        indexList.Add(temp);
                    }
                    Faces.Add(new PlyFace(indexList));
                }
                if (element.Type == PlyElementType.edge)
                {
                    IPlyEdge edge = new PlyEdge(element.ContainsColor);
                    for (int i = 0; i < tokens.Length; i++)
                    {
                        string          typeName = element.Properties[i].TypeName;
                        string          name     = element.Properties[i].Name;
                        PlyPropertyType propType = element.Properties[i].Type;
                        byte            r        = 0;
                        byte            b        = 0;
                        byte            g        = 0;

                        if (propType == PlyPropertyType.red)
                        {
                            r = byte.Parse(tokens[i]);
                        }
                        if (propType == PlyPropertyType.green)
                        {
                            g = byte.Parse(tokens[i]);
                        }
                        if (propType == PlyPropertyType.blue)
                        {
                            b = byte.Parse(tokens[i]);
                        }
                        if (propType == PlyPropertyType.vertex1)
                        {
                            edge.Vertex1 = int.Parse(tokens[i]);
                        }
                        if (propType == PlyPropertyType.vertex2)
                        {
                            edge.Vertex2 = int.Parse(tokens[i]);
                        }
                        edge.Color = System.Drawing.Color.FromArgb(r, g, b);
                    }
                    Edges.Add(edge);
                }
                if (element.Type == PlyElementType.material)
                {
                    for (int i = 0; i < tokens.Length; i++)
                    {
                    }
                }
                if (element.Type == PlyElementType.other)
                {
                    for (int i = 0; i < tokens.Length; i++)
                    {
                    }
                }
            }
        }