예제 #1
0
        int readFace(byte *buf, out face fe)
        {
            int i = 0;

            fe = new face();
            while (IS_SPACING(*buf))
            {
                buf++; i++;
            }
            ;
            buf += readInt(buf, out fe.v1) + 1;
            buf += readInt(buf, out fe.t1) + 1;
            buf += readInt(buf, out fe.n1) + 1;
            while (IS_SPACING(*buf))
            {
                buf++; i++;
            }
            buf += readInt(buf, out fe.v2) + 1;
            buf += readInt(buf, out fe.t2) + 1;
            buf += readInt(buf, out fe.n2) + 1;
            while (IS_SPACING(*buf))
            {
                buf++; i++;
            }
            buf += readInt(buf, out fe.v3) + 1;
            buf += readInt(buf, out fe.t3) + 1;
            buf += readInt(buf, out fe.n3) + 1;
            return(i);
        }
예제 #2
0
        public unsafe ObjMesh(string strPath)
            : base(strPath)
        {
            int            approxMem = 295 + m_arData.Length / 1024 * 11;
            List <Vector3> vectors   = new List <Vector3>(approxMem);
            List <Vector3> normals   = new List <Vector3>(approxMem);
            List <Vector2> texcoords = new List <Vector2>(approxMem);

            bool    inComment = false;
            mode    mode      = mode.MODE_NONE;
            Vector3 v3        = new Vector3();
            face    f         = new face();

            fixed(byte *buf = m_arData)
            {
                for (int i = 0; i < m_arData.Length; i++)
                {
                    if (buf[i] == '#')
                    {
                        inComment = true;
                        continue;
                    }
                    else if (inComment && buf[i] != '\n')
                    {
                        continue;
                    }
                    else if (inComment && buf[i] == '\n')
                    {
                        inComment = false;
                        continue;
                    }

                    if (mode == mode.MODE_NONE && !IS_SPACING(m_arData[i]))
                    {
                        if (m_arData[i] == 'f')
                        {
                            mode = mode.MODE_FACE;
                        }
                        else if (buf[i] == 'v')
                        {
                            if (IS_SPACING(buf[i + 1]))
                            {
                                mode = mode.MODE_VERTEX;
                            }
                            else if (buf[i + 1] == 'n')
                            {
                                mode = mode.MODE_NORMAL;
                            }
                            else if (buf[i + 1] == 't')
                            {
                                mode = mode.MODE_TEXTURE;
                            }
                            i++;
                        }
                        else
                        {
                            mode = mode.MODE_UNKNOWN;
                        }
                    }
                    else if (mode != mode.MODE_NONE)
                    {
                        switch (mode)
                        {
                        case mode.MODE_UNKNOWN:
                            if (buf[i] == '\n')
                            {
                                mode = mode.MODE_NONE;
                            }
                            break;

                        case mode.MODE_VERTEX:
                            i += readVector(&buf[i], out v3);
                            vectors.Add(v3);
                            mode = mode.MODE_NONE;
                            break;

                        case mode.MODE_NORMAL:

                            i += readVector(&buf[i], out v3);
                            normals.Add(v3);
                            mode = mode.MODE_NONE;
                            break;

                        case mode.MODE_TEXTURE:
                            i += readVector(&buf[i], out v3);
                            texcoords.Add(new Vector2(v3.X, v3.Y));
                            mode = mode.MODE_NONE;
                            break;

                        case mode.MODE_FACE:
                            i += readFace(&buf[i], out f);
                            base.m_lstVertices.Add(new Vector3(f.v1, f.v2, f.v3),
                                                   new Vector2(f.t1, f.t2),
                                                   new Vector3(f.n1, f.n2, f.n3));

                            mode = mode.MODE_NONE;
                            break;
                        }
                    }
                }
            }
        }