Example #1
0
        public string ToObj(List <Vertex> v, Detail detail, ref int a, ref int b)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendFormat("g {0}\r\n", (quadFlags.HasFlag(QuadFlags.InvisibleTriggers) ? "invisible" : "visible"));
            sb.AppendFormat("o piece_{0}\r\n\r\n", id.ToString("X4"));

            switch (detail)
            {
            case Detail.Low:
            {
                List <Vertex> list = GetVertexListq(v, -1);

                foreach (Vertex vt in list)
                {
                    sb.AppendLine(vt.ToString());
                    sb.AppendLine("vt " + vt.uv.X / 255f + " " + vt.uv.Y / -255f);
                }

                sb.AppendLine("\r\nusemtl " + (ptrTexLow != 0 ? texlow.Tag() : "default"));

                if (objSaveQuads)
                {
                    sb.Append(OBJ.ASCIIQuad("f", a, b));
                }
                else
                {
                    sb.Append(OBJ.ASCIIFace("f", a, b, 1, 3, 2, 1, 3, 2));
                    sb.Append(OBJ.ASCIIFace("f", a, b, 2, 3, 4, 2, 3, 4));
                }

                a += 4;
                b += 4;

                break;
            }

            case Detail.Med:
            {
                for (int i = 0; i < 4; i++)
                {
                    List <Vertex> list = GetVertexListq(v, i);

                    foreach (Vertex vt in list)
                    {
                        sb.AppendLine(vt.ToString());
                        sb.AppendLine("vt " + vt.uv.X / 255f + " " + vt.uv.Y / -255f);
                    }

                    sb.AppendLine("\r\nusemtl " + (ptrTexMid[i] != 0 ? tex[i].midlods[2].Tag() : "default"));

                    if (objSaveQuads)
                    {
                        sb.Append(OBJ.ASCIIQuad("f", a, b));
                    }
                    else
                    {
                        sb.Append(OBJ.ASCIIFace("f", a, b, 1, 3, 2, 1, 3, 2));
                        sb.Append(OBJ.ASCIIFace("f", a, b, 2, 3, 4, 2, 3, 4));
                    }

                    sb.AppendLine();

                    b += 4;
                    a += 4;
                }

                break;
            }
            }

            return(sb.ToString());
        }
Example #2
0
        public string ToObj(List <Vertex> v, Detail detail, ref int a, ref int b)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendFormat("g {0}\r\n", (quadFlags.HasFlag(QuadFlags.InvisibleTriggers) ? "invisible" : "visible"));
            sb.AppendFormat("o piece_{0}\r\n\r\n", id.ToString("X4"));

            switch (detail)
            {
            case Detail.Low:
            {
                List <Vertex> list = GetVertexListq(v, -1);

                foreach (Vertex vt in list)
                {
                    sb.AppendLine(vt.ToString());
                    sb.AppendLine("vt " + vt.uv.X / 255f + " " + vt.uv.Y / -255f);
                }

                sb.AppendLine("\r\nusemtl " + (ptrTexLow != UIntPtr.Zero ? texlow.Tag() : "default"));

                if (objSaveQuads)
                {
                    sb.Append(OBJ.ASCIIQuad("f", a, b));
                }
                else
                {
                    sb.Append(OBJ.ASCIIFace("f", a, b, 1, 3, 2, 1, 3, 2));
                    sb.Append(OBJ.ASCIIFace("f", a, b, 2, 3, 4, 2, 3, 4));
                }

                a += 4;
                b += 4;

                break;
            }

            case Detail.Med:
            {
                for (int i = 0; i < 4; i++)
                {
                    List <Vertex> list = GetVertexListq(v, i);

                    //this normally shouldn't be null
                    if (list != null)
                    {
                        foreach (Vertex vt in list)
                        {
                            sb.AppendLine(vt.ToString());
                            sb.AppendLine("vt " + vt.uv.X / 255f + " " + vt.uv.Y / -255f);
                        }

                        sb.AppendLine("\r\nusemtl " + (ptrTexMid[i] != UIntPtr.Zero ? tex[i].midlods[2].Tag() : "default"));

                        if (objSaveQuads)
                        {
                            sb.Append(OBJ.ASCIIQuad("f", a, b));
                        }
                        else
                        {
                            sb.Append(OBJ.ASCIIFace("f", a, b, 1, 3, 2, 1, 3, 2));
                            sb.Append(OBJ.ASCIIFace("f", a, b, 2, 3, 4, 2, 3, 4));
                        }

                        sb.AppendLine();

                        b += 4;
                        a += 4;
                    }
                    else
                    {
                        Helpers.Panic(this, PanicType.Error, $"something's wrong with quadblock {id} at {pos.ToString("X8")}, happens in secret2_4p and temple2_4p");
                    }
                }

                break;
            }
            }

            return(sb.ToString());
        }