示例#1
0
        /*IEnumerable<StudioVertex[]> LoadMdl(IResourceProvider Res) {
         *      for (int BodyPartIdx = 0; BodyPartIdx < Mdl.BodyPartCount; BodyPartIdx++) {
         *              StudioModelFile.StudioModel[] Models = Mdl.GetModels(BodyPartIdx).ToArray();
         *
         *              for (int ModelIndex = 0; ModelIndex < Models.Length; ModelIndex++) {
         *                      StudioModelFile.StudioModel Model = Models[ModelIndex];
         *                      StudioModelFile.StudioMesh[] Meshes = Mdl.GetMeshes(ref Model).ToArray();
         *
         *                      for (int MeshIndex = 0; MeshIndex < Meshes.Length; MeshIndex++) {
         *                              StudioModelFile.StudioMesh Mesh = Meshes[MeshIndex];
         *
         *                              StudioVertex[] StudioVerts = new StudioVertex[Tris.GetVertexCount(BodyPartIdx, ModelIndex, 0, MeshIndex)];
         *                              Tris.GetVertices(BodyPartIdx, ModelIndex, 0, MeshIndex, StudioVerts);
         *
         *                              int[] Indices = new int[Tris.GetIndexCount(BodyPartIdx, ModelIndex, 0, MeshIndex)];
         *                              Tris.GetIndices(BodyPartIdx, ModelIndex, 0, MeshIndex, Indices);
         *
         *                              List<StudioVertex> Vts = new List<StudioVertex>();
         *                              for (int i = 0; i < Indices.Length; i++)
         *                                      Vts.Add(StudioVerts[Indices[i]]);
         *
         *                              yield return Vts.ToArray();
         *                      }
         *              }
         *      }
         * }*/

        public static SourceMdl FromFile(string FilePath, IResourceProvider Res)
        {
            FilePath = FilePath.Substring(0, FilePath.Length - Path.GetExtension(FilePath).Length);

            SourceMdl Model = new SourceMdl();

            Model.Mdl   = StudioModelFile.FromProvider(FilePath + ".mdl", Res);
            Model.Verts = ValveVertexFile.FromProvider(FilePath + ".vvd", Res);
            Model.Tris  = ValveTriangleFile.FromProvider(FilePath + ".dx90.vtx", Model.Mdl, Model.Verts, Res);

            return(Model);
        }
示例#2
0
        public static libTechModel FromSourceMdl(SourceMdl Mdl, string ShaderOverride = null)
        {
            libTechModel Model = new libTechModel();

            string[] MaterialNames = Mdl.GetMaterialNames();
            string[] BodyNames     = Mdl.GetBodyNames();

            StudioModelFile.StudioBone[] Bones = Mdl.Mdl.GetBones();
            string[] BoneNames = Mdl.Mdl.GetBoneNames();

            for (int i = 0; i < Bones.Length; i++)
            {
                Model.Bones.Add(BoneNames[i], new libTechBone(BoneNames[i], Bones[i]));
            }


            // BODIES
            for (int BodyPartIdx = 0; BodyPartIdx < Mdl.Mdl.BodyPartCount; BodyPartIdx++)
            {
                StudioModelFile.StudioModel[] StudioModels = Mdl.Mdl.GetModels(BodyPartIdx).ToArray();

                // MODELS
                for (int ModelIdx = 0; ModelIdx < StudioModels.Length; ModelIdx++)
                {
                    ref StudioModelFile.StudioModel StudioModel  = ref StudioModels[ModelIdx];
                    StudioModelFile.StudioMesh[]    StudioMeshes = Mdl.Mdl.GetMeshes(ref StudioModel).ToArray();

                    // MESHES
                    for (int MeshIdx = 0; MeshIdx < StudioMeshes.Length; MeshIdx++)
                    {
                        ref StudioModelFile.StudioMesh StudioMesh = ref StudioMeshes[MeshIdx];

                        StudioVertex[] StudioVerts = new StudioVertex[Mdl.Tris.GetVertexCount(BodyPartIdx, ModelIdx, 0, MeshIdx)];
                        Mdl.Tris.GetVertices(BodyPartIdx, ModelIdx, 0, MeshIdx, StudioVerts);

                        int[] Indices = new int[Mdl.Tris.GetIndexCount(BodyPartIdx, ModelIdx, 0, MeshIdx)];
                        Mdl.Tris.GetIndices(BodyPartIdx, ModelIdx, 0, MeshIdx, Indices);

                        List <Vertex3> Vts = new List <Vertex3>();
                        for (int i = 0; i < Indices.Length; i++)
                        {
                            ref StudioVertex V = ref StudioVerts[Indices[i]];
                            Vts.Add(new Vertex3(new Vector3(V.Position.X, V.Position.Y, V.Position.Z), new Vector2(V.TexCoordX, 1.0f - V.TexCoordY), Color.White));
                        }

                        string   MatName = MaterialNames[StudioMesh.Material];
                        Material Mat     = Engine.GetMaterial(MatName);

                        if (Mat == Engine.GetMaterial("error"))
                        {
                            Mat = ValveMaterial.CreateMaterial(MatName);

                            if (Mat != Engine.GetMaterial("error"))
                            {
                                Engine.RegisterMaterial(Mat);
                            }
                        }

                        libTechMesh Msh = new libTechMesh(Vts.ToArray(), Mat);
                        Msh.Name = StudioModel.Name;
                        Model.AddMesh(Msh);
                    }