Example #1
0
 public ModelBoneCollection(ModelBoneCollection bones)
 {
     foreach (ModelBone bone in bones)
     {
         this.Add(bone.Clone());
     }
 }
Example #2
0
        protected void getChildren(ModelBone parent, ref ModelBoneCollection list)
        {
            foreach (var child in parent.children)
            {
                list.Add(child);

                child.getChildren(child, ref list);
            }
        }
Example #3
0
        public ModelBoneCollection AllChildren(bool bIncludeSelf = true)
        {
            var childs = new ModelBoneCollection();

            if (bIncludeSelf)
            {
                childs.Add(this);
            }
            getChildren(this, ref childs);

            return(childs);
        }
Example #4
0
        private void applyTransforms()
        {
            ModelBoneCollection bones = (chkHierarchy.Checked ? SceneManager.Current.Models[modelIndex].Bones[boneIndex].AllChildren() : new ModelBoneCollection {
                SceneManager.Current.Models[modelIndex].Bones[boneIndex]
            });

            if (rdoScaling.Checked)
            {
                Matrix4D scaleMatrix = Matrix4D.Identity;

                if (rdoScaleWholeModel.Checked)
                {
                    scaleMatrix = Matrix4D.CreateScale(
                        txtScaleWholeModel.Text.ToSingle(),
                        txtScaleWholeModel.Text.ToSingle(),
                        txtScaleWholeModel.Text.ToSingle()
                        );
                }
                else if (rdoScaleByAxis.Checked)
                {
                    scaleMatrix = Matrix4D.CreateScale(
                        txtScaleAxisX.Text.ToSingle(),
                        txtScaleAxisY.Text.ToSingle(),
                        txtScaleAxisZ.Text.ToSingle()
                        );
                }

                ModelManipulator.Scale(bones, scaleMatrix, chkHierarchy.Checked);
            }
            else if (rdoMunging.Checked)
            {
                if (rdoInvert.Checked)
                {
                    //ModelManipulator.FlipAxis(SceneManager.Current.Models[modelIndex].Bones[boneIndex].Mesh, cboInvertAxis.SelectedItem.ToString().ToEnum<Axis>(), chkHierarchy.Checked);
                }
                else if (rdoMeshBoneSwap.Checked)
                {
                    ModelManipulator.MungeMeshWithBone(bones);
                }
                else if (rdoFlipWindingOrder.Checked)
                {
                    ModelManipulator.FlipFaces(bones, chkHierarchy.Checked);
                }
            }
        }
Example #5
0
        public static void Scale(ModelBoneCollection bones, Matrix4 scale, bool bApplyToHierarchy = false)
        {
            var processed = new List <string>();

            foreach (var bone in bones)
            {
                if (bone.Type == BoneType.Mesh && bone.Mesh != null && !processed.Contains(bone.Mesh.Name))
                {
                    var mesh = bone.Mesh;

                    foreach (var meshpart in mesh.MeshParts)
                    {
                        for (int i = 0; i < meshpart.VertexCount; i++)
                        {
                            var position = Vector3.Transform(meshpart.VertexBuffer.Data[i].Position, scale);
                            meshpart.VertexBuffer.ModifyVertexPosition(i, position);
                        }

                        meshpart.VertexBuffer.Initialise();
                    }

                    processed.Add(mesh.Name);
                }

                if (bApplyToHierarchy)
                {
                    var transform = bone.Transform;
                    var position  = Vector3.TransformPosition(transform.ExtractTranslation(), scale);

                    transform.M41 = position.X;
                    transform.M42 = position.Y;
                    transform.M43 = position.Z;

                    bone.Transform = transform;
                }
            }
        }
Example #6
0
        public static void MungeMeshWithBone(ModelBoneCollection bones)
        {
            var processed = new List <string>();

            var offset = (bones[0].Parent != null ? bones[0].Parent.Transform.ExtractTranslation() : OpenTK.Vector3.Zero);

            foreach (var bone in bones)
            {
                if (bone.Type == BoneType.Mesh && bone.Mesh != null && !processed.Contains(bone.Mesh.Name))
                {
                    var mesh       = bone.Mesh;
                    var meshoffset = mesh.BoundingBox.Centre;

                    foreach (var meshpart in mesh.MeshParts)
                    {
                        for (int i = 0; i < meshpart.VertexCount; i++)
                        {
                            meshpart.VertexBuffer.ModifyVertexPosition(i, meshpart.VertexBuffer.Data[i].Position - meshoffset);
                        }
                        meshpart.VertexBuffer.Initialise();
                    }
                    mesh.BoundingBox.Calculate(mesh);

                    var moffset = meshoffset - offset;
                    offset = meshoffset;

                    var m = bone.Transform;
                    m.M41         += moffset.X;
                    m.M42         += moffset.Y;
                    m.M43         += moffset.Z;
                    bone.Transform = m;

                    processed.Add(mesh.Name);
                }
            }
        }
Example #7
0
        public static void FlipFaces(ModelBoneCollection bones, bool bApplyToHierarchy = false)
        {
            var processed = new List <string>();

            foreach (var bone in bones)
            {
                if (bone.Type == BoneType.Mesh && bone.Mesh != null && !processed.Contains(bone.Mesh.Name))
                {
                    var mesh = bone.Mesh;

                    foreach (var meshpart in mesh.MeshParts)
                    {
                        for (int i = 0; i < meshpart.IndexBuffer.Data.Count; i += 3)
                        {
                            meshpart.IndexBuffer.SwapIndices(i + 1, i + 2);
                        }

                        meshpart.IndexBuffer.Initialise();
                    }

                    processed.Add(mesh.Name);
                }
            }
        }
Example #8
0
 public ModelBone()
 {
     children  = new ModelBoneCollection();
     Index     = 0;
     Transform = Matrix4.Identity;
 }
Example #9
0
 public Model()
 {
     bones  = new ModelBoneCollection();
     meshes = new List <ModelMesh>();
 }