Exemplo n.º 1
0
        public override NodeContent Import(string filename, ContentImporterContext context)
        {
            System.Threading.Thread currentThread = System.Threading.Thread.CurrentThread;
            CultureInfo             culture       = new CultureInfo("en-US");

            currentThread.CurrentCulture   = culture;
            currentThread.CurrentUICulture = culture;
            this.fileName = filename;
            this.context  = context;
            // Create an instance of a class that splits a .X file into tokens and provides
            // functionality for iterating and parsing the tokens
            tokens = new XFileTokenizer(filename);

            // skip header
            tokens.SkipTokens(3);
            root          = new NodeContent();
            root.Identity = new ContentIdentity(fileName, "Animation Library XImporter");
            // fill in the tree
            ImportRoot();

            Matrix absoluteMeshTransform = Matrix.Identity;
            List <SkinTransformContent[]> skinTransforms = new List <SkinTransformContent[]>();
            List <Matrix> absMeshTransforms = new List <Matrix>();

            // Now that we have mapped bone names to their indices, we can create the vertices
            // in each mesh so that they contain indices and weights
            foreach (XMeshImporter mesh in meshes)
            {
                mesh.CreateGeometry();
                SkinTransformContent[] meshSkinTransforms = mesh.SkinTransforms;
                skinTransforms.Add(mesh.SkinTransforms);
                if (mesh.SkinTransforms != null && mesh.SkinTransforms.Length > 0)
                {
                    absoluteMeshTransform = mesh.Mesh.AbsoluteTransform;
                }
                absMeshTransforms.Add(mesh.Mesh.AbsoluteTransform);
            }

            FindBones(root);
            root.OpaqueData.Add("AbsoluteMeshTransforms", absMeshTransforms);
            // Calculates bind pose as required for compatibility with Xna Content DOM
            Dictionary <string, Matrix> absTransformsDict = new Dictionary <string, Matrix>(skinTransforms.Count);
            int k = 0;

            foreach (SkinTransformContent[] sst in skinTransforms)
            {
                if (sst != null)
                {
                    absoluteMeshTransform = meshes[k].Mesh.AbsoluteTransform;
                    foreach (SkinTransformContent st in sst)
                    {
                        Matrix abs = Matrix.Invert(Matrix.Invert(absoluteMeshTransform) * st.Transform);
                        absTransformsDict.Add(st.BoneName, abs);
                    }
                }
                k++;
            }



            FixBindPose(root, absTransformsDict);

            return(root);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Creates a new instance of XMeshImporter
 /// </summary>
 /// <param name="model">The object that is importing the model from
 /// the current .X file</param>
 public XMeshImporter(XModelImporter model)
 {
     this.tokens = model.tokens;
     this.model  = model;
     model.meshes.Add(this);
 }