Beispiel #1
0
 public static List<FbxMesh> Load(string path, Device device, out Scene scene)
 {
     byte[] input;
     using (var stream = new FileStream(path, FileMode.Open))
     {
         input = new byte[stream.Length];
         stream.Read(input, 0, (int)stream.Length);
     }
     bool isBinary = false;
     List<Token> tokens;
     if (Encoding.ASCII.GetString(input, 0, 18) == "Kaydara FBX Binary")
     {
         isBinary = true;
         BinaryTokenizer.TokenizeBinary(out tokens, input, input.Length);
     }
     else
     {
         Tokenizer.Tokenize(out tokens, input);
     }
     var parser = new Parser(tokens, isBinary);
     var settings = ImporterSettings.Default;
     var doc = new Document(parser, settings);
     FbxConverter.ConvertToScene(out scene, doc);
     var result = new List<FbxMesh>();
     foreach (var assimpMesh in scene.Meshes)
     {
         var mat = scene.Materials[assimpMesh.MaterialIndex];
         var fbxMesh = new FbxMesh(assimpMesh, mat, device, path);
         result.Add(fbxMesh);
     }
     return result;
 }
Beispiel #2
0
        public Document(Parser parser, ImporterSettings settings)
        {
            this.settings = settings;
            this.parser = parser;

            for(int i=0; i<7 ; i++)
            {
                creationTimeStamp[i] = 0;
            }

            ReadHeader();
            ReadPropertyTemplates();
            ReadGlobalSettings();
            ReadObjects();
            ReadConnections();
        }
Beispiel #3
0
        public Element(Token keyToken, Parser parser)
        {
            this.keyToken = keyToken;

            Token n;
            do
            {
                n = parser.AdvanceToNextToken();
                if (n == null)
                {
                    throw (new Exception("unexpected end of file, expected closing bracket"));
                }
                if (n.Type == TokenType.Data)
                {
                    tokens.Add(n);
                    n = parser.AdvanceToNextToken();
                    if (n == null)
                    {
                        throw (new Exception("unexpected end of file, expected bracket, comma or key"));
                    }
                    TokenType ty = n.Type;
                    if (ty != TokenType.OpenBracket && ty != TokenType.CloseBracket && ty != TokenType.Comma && ty != TokenType.Key)
                    {
                        throw (new Exception("unexpected token; expected bracket, comma or key"));
                    }
                }
                if (n.Type == TokenType.OpenBracket)
                {
                    compound = new Scope(parser);

                    // current token should be a TOK_CLOSE_BRACKET
                    n = parser.CurrentToken;
                    Debug.Assert(n != null);

                    if (n.Type != TokenType.CloseBracket)
                    {
                        throw (new Exception("expected closing bracket"));
                    }
                    parser.AdvanceToNextToken();
                    return;
                }
            }
            while (n.Type != TokenType.Key && n.Type != TokenType.CloseBracket);
        }
Beispiel #4
0
        public Scope(Parser parser, bool topLevel = false)
        {
            if (!topLevel)
            {
                Token t = parser.CurrentToken;
                if (t.Type != TokenType.OpenBracket)
                {
                    throw (new Exception("expected open bracket"));
                }
            }

            Token n = parser.AdvanceToNextToken();
            if (n == null)
            {
                throw( new Exception("unexpected end of file"));
            }
            while ( n.Type != TokenType.CloseBracket)
            {
                if (n.Type != TokenType.Key)
                {
                    throw (new Exception("unexpected token, expected TOK_KEY"));
                }

                string str = n.StringContents;
                if (!elements.ContainsKey(str))
                {
                    elements.Add(str, new List<Element>());
                }
                elements[str].Add(new Element(n, parser));

                n = parser.CurrentToken;
                if (n == null)
                {
                    if (topLevel)
                    {
                        return;
                    }
                    throw (new Exception("unexpected end of file"));
                }
            }
        }
Beispiel #5
0
 public Scene ReadFile(string file)
 {
     byte[] input;
     using (var stream = new FileStream(file, FileMode.Open))
     {
         input = new byte[stream.Length];
         stream.Read(input, 0, (int)stream.Length);
     }
     bool isBinary = false;
     List<Token> tokens;
     if (Encoding.ASCII.GetString(input, 0, 18) == "Kaydara FBX Binary")
     {
         isBinary = true;
         BinaryTokenizer.TokenizeBinary(out tokens, input, input.Length);
     }
     else
     {
         Tokenizer.Tokenize(out tokens, input);
     }
     Parser parser = new Parser(tokens, isBinary);
     Document doc = new Document(parser, settings);
     Scene scene;
     FbxConverter.ConvertToScene(out scene, doc);
     return scene;
 }
Beispiel #6
0
 public void LoadFile()
 {
     var file = "../../models-nonbsd/FBX/2013_ASCII/Cinema4D.fbx";
     byte[] input;
     using (var stream = new FileStream(file, FileMode.Open))
     {
         input = new byte[stream.Length];
         stream.Read(input, 0, (int)stream.Length);
     }
     bool isBinary = false;
     List<Token> tokens;
     if (Encoding.ASCII.GetString(input, 0, 18) == "Kaydara FBX Binary")
     {
         isBinary = true;
         BinaryTokenizer.TokenizeBinary(out tokens, input, input.Length);
     }
     else
     {
         Tokenizer.Tokenize(out tokens, input);
     }
     Parser parser = new Parser(tokens, isBinary);
     ImporterSettings settings = new ImporterSettings();
     this.Document = new Document(parser, settings);
 }