Example #1
0
        public override Asset Import(string path)
        {
            ACT act = ACT.Load(path);
            Model model = new Model();
            int boneIndex = 0;

            string fileName = path.Substring(path.LastIndexOf("\\") + 1);
            path = path.Replace(fileName, "");

            Model dat = SceneManager.Current.Content.Load<Model, DATImporter>(fileName.Replace(".act", ".dat", StringComparison.OrdinalIgnoreCase), path);
            Material material = null;

            foreach (var section in act.Sections)
            {
                switch (section.Section)
                {
                    case Section.Name:
                        boneIndex = model.AddMesh(null, boneIndex);
                        model.SetName(section.Identifier, boneIndex);
                        material = null;
                        break;

                    case Section.Material:
                        material = (Material)SceneManager.Current.Materials.Entries.Find(m => m.Name == section.Material);
                        if (material == null)
                        {
                            material = new Material() { Name = section.Material };
                            SceneManager.Current.Add(material);
                        }
                        break;

                    case Section.Model:
                        model.SetMesh(new ModelMesh(dat.FindMesh((section.Model.Contains(".") ? section.Model.Substring(0, section.Model.IndexOf(".")) : section.Model))), boneIndex);
                        if (material != null)
                        {
                            foreach (var modelmesh in model.Meshes)
                            {
                                foreach (var meshpart in modelmesh.MeshParts)
                                {
                                    if (meshpart.Material == null) { meshpart.Material = material; }
                                }
                            }
                        }
                        break;

                    case Section.Matrix:
                        model.SetTransform(
                            new Matrix4(
                                section.Transform.M11, section.Transform.M12, section.Transform.M13, 0,
                                section.Transform.M21, section.Transform.M22, section.Transform.M23, 0,
                                section.Transform.M31, section.Transform.M32, section.Transform.M33, 0,
                                section.Transform.M41, section.Transform.M42, section.Transform.M43, 1
                            ), boneIndex
                        );
                        break;

                    case Section.SubLevelBegin:
                        break;

                    case Section.SubLevelEnd:
                        boneIndex = model.Bones[boneIndex].Parent.Index;
                        break;
                }
            }

            SceneManager.Current.UpdateProgress(string.Format("Loaded {0}", fileName));

            return model;
        }
Example #2
0
        static void ProcessNode(TDRNode node, Model model, Model mshses, HIE hie, int ParentBoneIndex = 0)
        {
            int boneIndex = ParentBoneIndex;

            if (exit) { return; }

            switch (node.Type)
            {
                case TDRNode.NodeType.Matrix:
                    boneIndex = model.AddMesh(null, boneIndex);

                    model.SetName(node.Name, boneIndex);
                    model.SetTransform(
                        new Matrix4 (
                            node.Transform.M11, node.Transform.M12, node.Transform.M13, 0,
                            node.Transform.M21, node.Transform.M22, node.Transform.M23, 0,
                            node.Transform.M31, node.Transform.M32, node.Transform.M33, 0,
                            node.Transform.M41, node.Transform.M42, node.Transform.M43, 1
                        ), boneIndex);
                    break;

                case TDRNode.NodeType.Mesh:
                    int index = node.Index;
                    mshses.Meshes[index].MeshParts[0].Material = material;

                    if (model.Bones[ParentBoneIndex].Mesh == null)
                    {
                        model.SetMesh(mshses.Meshes[index], boneIndex);
                        //exit = true;
                        //Console.WriteLine("Adding mesh #{0} \"{1}\" to bone #{2} \"{3}\"", index, mshses.Meshes[index].Name, boneIndex, model.Bones[boneIndex].Name);
                    }
                    else
                    {
                        boneIndex = model.AddMesh(mshses.Meshes[index], ParentBoneIndex);
                        model.SetName(mshses.Meshes[index].Name, boneIndex);

                        //model.SetName(mshses.Meshes[index].Name, model.AddMesh(mshses.Meshes[index], ParentBoneIndex));
                        //Console.WriteLine("Adding mesh #{0} \"{1}\" to brand new bone", index, mshses.Meshes[index].Name);
                    }
                    break;

                case TDRNode.NodeType.Texture:
                    if (node.Index > -1)
                    {
                        material = SceneManager.Current.Content.Load<Material, TXImporter>(hie.Textures[node.Index]);
                    }
                    else
                    {
                        material = null;
                    }
                    break;
            }

            foreach (var child in node.Children)
            {
                ProcessNode(child, model, mshses, hie, boneIndex);
            }
        }