Exemplo n.º 1
0
        public static Model SetModel(FMDL fmdl)
        {
            Model model = new Model();

            model.Name = fmdl.Text;
            model.Path = "";

            model.Shapes        = new ResDict <Shape>();
            model.VertexBuffers = new List <VertexBuffer>();
            model.Materials     = new ResDict <Material>();
            model.UserData      = new ResDict <UserData>();
            model.Skeleton      = new Skeleton();
            model.Skeleton      = fmdl.Skeleton.node.SkeletonU;
            model.UserData      = fmdl.ModelU.UserData;

            fmdl.Skeleton.CalculateIndices();

            int i          = 0;
            var duplicates = fmdl.shapes.GroupBy(c => c.Text).Where(g => g.Skip(1).Any()).SelectMany(c => c);

            foreach (var shape in duplicates)
            {
                shape.Text += i++;
            }

            foreach (FSHP shape in fmdl.shapes)
            {
                BFRES.CheckMissingTextures(shape);
                SetShape(shape, shape.ShapeU);

                model.Shapes.Add(shape.Text, shape.ShapeU);
                model.VertexBuffers.Add(shape.VertexBufferU);
                shape.ShapeU.VertexBufferIndex = (ushort)(model.VertexBuffers.Count - 1);

                //   BFRES.SetShaderAssignAttributes(shape.GetMaterial().shaderassign, shape);
            }

            foreach (FMAT mat in fmdl.materials.Values)
            {
                SetMaterial(mat, mat.MaterialU, fmdl.GetResFileU());
                model.Materials.Add(mat.Text, mat.MaterialU);
            }
            return(model);
        }
Exemplo n.º 2
0
        public static Model SetModel(FMDL fmdl)
        {
            Model model = new Model();

            model.Name = fmdl.Text;
            model.Path = "";

            model.Shapes        = new ResDict <Shape>();
            model.VertexBuffers = new List <VertexBuffer>();
            model.Materials     = new ResDict <Material>();
            model.UserData      = new ResDict <UserData>();
            model.Skeleton      = new Skeleton();
            model.Skeleton      = fmdl.Skeleton.node.SkeletonU;
            model.UserData      = fmdl.ModelU.UserData;

            if (model.Skeleton.InverseModelMatrices == null)
            {
                model.Skeleton.InverseModelMatrices = new List <Syroot.Maths.Matrix3x4>();
            }
            if (model.Skeleton.MatrixToBoneList == null)
            {
                model.Skeleton.MatrixToBoneList = new List <ushort>();
            }

            foreach (var bone in fmdl.Skeleton.bones)
            {
                if (model.Skeleton.InverseModelMatrices.Count <= 0)
                {
                    break;
                }

                int inde = 0;
                foreach (var bn in model.Skeleton.Bones.Values)
                {
                    if (bone.Text == bn.Name)
                    {
                        var mat = MatrixExenstion.GetMatrixInverted(bone);

                        if (bn.SmoothMatrixIndex > -1)
                        {
                            model.Skeleton.InverseModelMatrices[bn.SmoothMatrixIndex] = mat;
                        }
                    }
                    inde++;
                }
            }

            int i          = 0;
            var duplicates = fmdl.shapes.GroupBy(c => c.Text).Where(g => g.Skip(1).Any()).SelectMany(c => c);

            foreach (var shape in duplicates)
            {
                shape.Text += i++;
            }

            foreach (FSHP shape in fmdl.shapes)
            {
                BFRES.CheckMissingTextures(shape);
                SetShape(shape, shape.ShapeU);

                model.Shapes.Add(shape.Text, shape.ShapeU);
                model.VertexBuffers.Add(shape.VertexBufferU);
                shape.ShapeU.VertexBufferIndex = (ushort)(model.VertexBuffers.Count - 1);

                //   BFRES.SetShaderAssignAttributes(shape.GetMaterial().shaderassign, shape);
            }

            foreach (FMAT mat in fmdl.materials.Values)
            {
                SetMaterial(mat, mat.MaterialU, fmdl.GetResFileU());
                model.Materials.Add(mat.Text, mat.MaterialU);
            }
            return(model);
        }