Пример #1
0
        public static Model Create(Mqo.Document mqoDocument, string strPrefix, float fScale)
        {
            Model         model        = new Model();
            List <Vertex> listVertices = new List <Vertex>();
            List <Edge>   listEdges    = new List <Edge>();

            int nVertexOffset = 0;

            foreach (Mqo.Object mqoObject in mqoDocument.Object)
            {
                if (mqoObject.visible == 0 && strPrefix == "")
                {
                    continue;
                }

                if (strPrefix != "")
                {
                    if (mqoObject.Name.Length < strPrefix.Length)
                    {
                        continue;
                    }

                    if (mqoObject.Name.Substring(0, strPrefix.Length) != strPrefix)
                    {
                        continue;
                    }
                }
                else
                {
                    if (mqoObject.visible == 0)
                    {
                        continue;
                    }
                }

                foreach (Mqo.Float3 f3Vertex in mqoObject.vertex)
                {
                    listVertices.Add(new Vertex(f3Vertex.X * fScale, -f3Vertex.Y * fScale, f3Vertex.Z * fScale));
                }

                foreach (Mqo.Face face in mqoObject.face)
                {
                    for (int i = 0; i < face.Vertices; i++)
                    {
                        int  i0   = i;
                        int  i1   = (i + 1) % face.Vertices;
                        Edge edge = new Edge(nVertexOffset + face.V[i0], nVertexOffset + face.V[i1]);
                        AddEdge(listEdges, edge);
                    }
                }
                nVertexOffset += mqoObject.vertex.Length;
            }

            model.Vertices = listVertices.ToArray();
            model.Edges    = listEdges.ToArray();

            return(model);
        }
Пример #2
0
        static void Main(string[] args)
        {
            string strInput  = "";
            string strOutput = "";
            float  fScale    = 1.0f;
            string strPrefix = "";
            string strName   = "";

            string strType = "ugxmodel";

            for (int i = 0; i < args.Length; i++)
            {
                string arg = args[i];
                switch (arg)
                {
                case "-i":
                    i++;
                    strInput = args[i];
                    break;

                case "-o":
                    i++;
                    strOutput = args[i];
                    break;

                case "-scale":
                    i++;
                    float.TryParse(args[i], out fScale);
                    break;

                case "-prefix":
                    i++;
                    strPrefix = args[i];
                    break;

                case "-name":
                    i++;
                    strName = args[i];
                    break;

                case "-type":
                    i++;
                    strType = args[i];
                    break;
                }
            }

            if (strInput == "")
            {
                Console.WriteLine("-i がない");
                return;
            }

            if (strOutput == "")
            {
                Console.WriteLine("-o がない");
                return;
            }

            if (strName == "")
            {
                Console.WriteLine("-name がない");
                return;
            }


            List <Mqo.Token> listTokens = Mqo.Tokenizer.Tokenize(strInput);

            if (listTokens == null)
            {
                Console.WriteLine(strInput + "が読めない");
                return;
            }

            /*
             * System.IO.StreamWriter writer = new System.IO.StreamWriter("tokens.txt");
             * tokenizer.Dump(writer);
             * writer.Close();
             */

            Mqo.Tree tree = new Mqo.Tree(listTokens);

            /*
             * writer = new System.IO.StreamWriter("tree.txt");
             * tree.Dump(writer);
             * writer.Close();
             */

            Mqo.NodeIterator it = new Mqo.NodeIterator(tree.RootNode, 0);

            Mqo.Document document = Mqo.Parser.ParseDocument(it.GetChildren());

            Ugx.Model model = Ugx.ModelFactory.Create(document, strPrefix, fScale);

            if (strType == "ugxmodel")
            {
                Ugx.ModelWriter.Write(strOutput, model, strName);
            }
            else if (strType == "ugxmesh")
            {
                Ugx.ModelWriter.WriteMesh(strOutput, model, strName);
            }
        }