Beispiel #1
0
 public libTechModel(GenericMesh[] Meshes, Material Mat) : this()
 {
     for (int i = 0; i < Meshes.Length; i++)
     {
         libTechMesh Msh = new libTechMesh(Meshes[i].Vertices.ToArray(), Mat);
         AddMesh(Msh);
     }
 }
Beispiel #2
0
 public libTechMesh(libTechMesh Clone) : this(Clone.Vertices, Clone.Material)
 {
 }
Beispiel #3
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);
                    }
Beispiel #4
0
 public void RemoveMesh(libTechMesh Mesh)
 {
     Meshes.Remove(Mesh);
     CalcBounds();
 }
Beispiel #5
0
 public void AddMesh(libTechMesh Mesh)
 {
     Meshes.Add(Mesh);
     CalcBounds();
 }