Exemplo n.º 1
0
        public libTechModel(libTechModel Clone) : this()
        {
            foreach (var B in Clone.Bones)
            {
                Bones.Add(B.Key, B.Value);
            }

            foreach (var M in Clone.GetMeshes())
            {
                AddMesh(new libTechMesh(M));
            }

            Scale    = Clone.Scale;
            Position = Clone.Position;
            Rotation = Clone.Rotation;
            Enabled  = true;
        }
Exemplo n.º 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);
                    }