Exemplo n.º 1
0
    private void SetGeometryData(string data)
    {
        string[] lines            = data.Split("\n".ToCharArray());
        Regex    regexWhitespaces = new Regex(@"\s+");
        bool     isFirstInGroup   = true;
        bool     isFaceIndexPlus  = true;

        for (int i = 0; i < lines.Length; i++)
        {
            string l = lines[i].Trim();

            if (l.IndexOf("#") != -1)              // comment line
            {
                continue;
            }
            string[] p = regexWhitespaces.Split(l);
            switch (p[0])
            {
            case O:
                buffer.PushObject(p[1].Trim());
                isFirstInGroup = true;
                break;

            case G:
                string groupName = null;
                if (p.Length >= 2)
                {
                    groupName = p[1].Trim();
                }
                isFirstInGroup = true;
                buffer.PushGroup(groupName);
                break;

            case V:
                buffer.PushVertex(new Vector3(cf(p[1]), cf(p[2]), cf(p[3])));
                break;

            case VT:
                buffer.PushUV(new Vector2(cf(p[1]), cf(p[2])));
                break;

            case VN:
                buffer.PushNormal(new Vector3(cf(p[1]), cf(p[2]), cf(p[3])));
                break;

            case F:
                FaceIndices[] faces = new FaceIndices[p.Length - 1];
                if (isFirstInGroup)
                {
                    isFirstInGroup = false;
                    string[] c = p[1].Trim().Split("/".ToCharArray());
                    isFaceIndexPlus = (ci(c[0]) >= 0);
                }
                GetFaceIndicesByOneFaceLine(faces, p, isFaceIndexPlus);
                if (p.Length == 4)
                {
                    buffer.PushFace(faces[0]);
                    buffer.PushFace(faces[1]);
                    buffer.PushFace(faces[2]);
                }
                else if (p.Length == 5)
                {
                    buffer.PushFace(faces[0]);
                    buffer.PushFace(faces[1]);
                    buffer.PushFace(faces[3]);
                    buffer.PushFace(faces[3]);
                    buffer.PushFace(faces[1]);
                    buffer.PushFace(faces[2]);
                }
                else
                {
                    //Debug.LogWarning("face vertex count :"+(p.Length-1)+" larger than 4:");
                }
                break;

            case MTL:
                mtllib = l.Substring(p[0].Length + 1).Trim();
                break;

            case UML:
                buffer.PushMaterialName(p[1].Trim());
                break;
            }
        }

        // buffer.Trace();
    }
    private void SetGeometryData(string data)
    {
        string[] lines = data.Split("\n".ToCharArray());

        for (int i = 0; i < lines.Length; i++)
        {
            string l = lines[i];
            l = l.Replace("  ", " |").Replace("| ", "").Replace("|", "");
            if (l.IndexOf("#") != -1)
            {
                l = l.Substring(0, l.IndexOf("#"));
            }
            string[] p = l.Split(" ".ToCharArray());
            switch (p[0])
            {
            case O:
                //buffer.PushObject(p[1].Trim());
                break;

            case G:
                buffer.PushGroup(p[1].Trim());
                break;

            case V:
                buffer.PushVertex(new Vector3(cf(p[1]), cf(p[2]), cf(p[3])));
                break;

            case VT:
                buffer.PushUV(new Vector2(cf(p[1]), cf(p[2])));
                break;

            case VN:
                buffer.PushNormal(new Vector3(cf(p[1]), cf(p[2]), cf(p[3])));
                break;

            case F:
                for (int j = 1; j < p.Length; j++)
                {
                    string[]    c  = p[j].Trim().Split("/".ToCharArray());
                    FaceIndices fi = new FaceIndices();
                    if (c[0] != "")
                    {
                        fi.vi = ci(c[0]) - 1;
                    }
                    if (c.Length > 1 && c[1] != "")
                    {
                        fi.vu = ci(c[1]) - 1;
                    }
                    if (c.Length > 2 && c[2] != "")
                    {
                        fi.vn = ci(c[2]) - 1;
                    }
                    if (c[0] != "")
                    {
                        buffer.PushFace(fi);
                    }
                }
                break;

            case MTL:
                mtllib = p[1].Trim();
                break;

            case UML:
                buffer.PushMaterialName(p[1].Trim());
                break;
            }
        }

        //buffer.Trace();
    }
Exemplo n.º 3
0
    private IEnumerator SetGeometryData(string data)
    {
        yield return(0);        // play nice by not hogging the main thread

        string[] lines = data.Split("\n".ToCharArray());

        bool isFirstInGroup  = true;
        bool isFaceIndexPlus = true;

        for (int i = 0; i < lines.Length; i++)
        {
            string l = lines[i].Trim();

            if (l.Length > 0 && l[0] == '#')              // comment line
            {
                continue;
            }
            string[] p = l.Replace("  ", " ").Split(' ');

            switch (p[0])
            {
            case O:
                buffer.PushObject(p[1].Trim());
                isFirstInGroup = true;
                break;

            case G:
                string groupName = null;
                if (p.Length >= 2)
                {
                    groupName = p[1].Trim();
                }
                isFirstInGroup = true;
                buffer.PushGroup(groupName);
                break;

            case V:
                buffer.PushVertex(new Vector3(cf(p[1]), cf(p[2]), cf(p[3])));
                break;

            case VT:
                buffer.PushUV(new Vector2(cf(p[1]), cf(p[2])));
                break;

            case VN:
                buffer.PushNormal(new Vector3(cf(p[1]), cf(p[2]), cf(p[3])));
                break;

            case F:
                FaceIndices[] faces = new FaceIndices[p.Length - 1];
                if (isFirstInGroup)
                {
                    isFirstInGroup = false;
                    string[] c = p[1].Trim().Split("/".ToCharArray());
                    isFaceIndexPlus = (ci(c[0]) >= 0);
                }
                GetFaceIndicesByOneFaceLine(faces, p, isFaceIndexPlus);
                if (p.Length == 4)
                {
                    buffer.PushFace(faces[0]);
                    buffer.PushFace(faces[1]);
                    buffer.PushFace(faces[2]);
                }
                else if (p.Length == 5)
                {
                    buffer.PushFace(faces[0]);
                    buffer.PushFace(faces[1]);
                    buffer.PushFace(faces[3]);
                    buffer.PushFace(faces[3]);
                    buffer.PushFace(faces[1]);
                    buffer.PushFace(faces[2]);
                }
                else
                {
                    //Debug.LogWarning("face vertex count :"+(p.Length-1)+" larger than 4:");
                }
                break;

            case MTL:
                mtllib = l.Substring(p[0].Length + 1).Trim();
                break;

            case UML:
                buffer.PushMaterialName(p[1].Trim());
                break;
            }
            if (i % 7000 == 0)
            {
                yield return(0);                           // play nice with main thread while parsing large objs
            }
        }
        // buffer.Trace();
    }
Exemplo n.º 4
0
    private void SetGeometryData(string data)
    {
        string[] lines = data.Split("\n".ToCharArray());

        for (int i = 0; i < lines.Length; i++)
        {
            string l = lines[i];

            if (l.IndexOf("#") != -1)
            {
                l = l.Substring(0, l.IndexOf("#"));
            }
            string[] p = l.Split(" ".ToCharArray());

            switch (p[0])
            {
            case O:
                buffer.PushObject(p[1].Trim());
                break;

            case G:
                buffer.PushGroup(p[1].Trim());
                break;

            case V:
                //Unity has a left-handed coordinates system while Molecular OBJs are right-handed
                //So we have to negate the X coordinates
                buffer.PushVertex(new Vector3(-cf(p[1]), cf(p[2]), cf(p[3])));
                compteurvertice++;
                break;

            case VT:
                buffer.PushUV(new Vector2(cf(p[1]), cf(p[2])));
                break;

            case VN:
                //Unity has a left-handed coordinates system while Molecular OBJs are right-handed
                //So we have to negate the X coordinates
                //Here it affects only light ! The winding reverse is in GeometryBuffer::PopulateMeshes
                Vector3 norm = new Vector3(-cf(p[1]), cf(p[2]), cf(p[3]));
                norm.Normalize();
                buffer.PushNormal(norm);
                break;

            case F:
                for (int j = 1; j < p.Length; j++)
                {
                    string[] c = p[j].Trim().Split("/".ToCharArray());
//						Debug.Log("" +p[j]);
                    FaceIndices fi = new FaceIndices();
                    fi.vi = ci(c[0]) - 1;
                    if (c.Length > 1 && c[1] != "")
                    {
                        fi.vu = ci(c[1]) - 1;
                    }
                    if (c.Length > 2 && c[2] != "")
                    {
                        fi.vn = ci(c[2]) - 1;
                    }
//						Debug.Log("vi "+fi.vi+" vu "+fi.vu+ " vn "+fi.vn);
                    buffer.PushFace(fi);
                }
                break;

            case MTL:
                if (mtl_reader != null)
                {
                    mtllib = p[1].Trim();
                }
                break;

            case UML:
                if (mtl_reader != null)
                {
                    buffer.PushMaterialName(p[1].Trim());
                }
                break;
            }
        }

        // buffer.Trace();
    }
Exemplo n.º 5
0
        public static void SetGeometryData(string data, GeometryBuffer buffer)
        {
            var lines = data.Split("\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

            for (var i = 0; i < lines.Length; i++)
            {
                var l = lines[i].Trim();

                if (l.IndexOf("#") != -1)
                    l = l.Substring(0, l.IndexOf("#"));
                var p = l.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                if (p.Length > 1)
                {
                    switch (p[0])
                    {
                        case O:
                            buffer.PushObject(p[1].Trim());
                            break;
                        case G:
                            buffer.PushGroup(p[1].Trim());
                            break;
                        case V:
                            buffer.PushVertex(new Vector3(
                                Cf(p[1]),
                                Cf(p[2]),
                                Cf(p[3]))
                                );
                            break;
                        case Vt:
                            buffer.PushUv(new Vector2(Cf(p[1]), Cf(p[2])));
                            break;
                        case Vn:
                            buffer.PushNormal(new Vector3(Cf(p[1]), Cf(p[2]), Cf(p[3])));
                            break;
                        case F:
                            for (var j = 1; j < p.Length; j++)
                            {
                                var c = p[j].Trim().Split("/".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                                var fi = new FaceIndices();
                                fi.Vi = Ci(c[0]) - 1;
                                if (c.Length > 1)
                                {
                                    fi.Vu = Ci(c[1]) - 1;
                                }
                                if (c.Length > 2)
                                {
                                    fi.Vn = Ci(c[2]) - 1;
                                }
                                buffer.PushFace(fi);
                            }
                            break;
                        case Mtl:
                            // mtllib = p[1].Trim();
                            break;
                        case Uml:
                            buffer.PushMaterialName(p[1].Trim());
                            break;
                    }
                }
            }
            // buffer.Trace();
        }