public MmdBone(MmdImport import, MmdModel model, int index)
 {
     this.import = import;
     this.Model  = model;
     this.Index  = index;
 }
 public MmdBone(MmdImport import, MmdModel model, int index)
 {
     this.import = import;
     this.Model = model;
     this.Index = index;
 }
        void SynchronizeTransformation(MmdModel mmdModel, ref Action reset)
        {
            if (mmdModel == null)
                return;

            var model = this.Scene.ActiveModel;
            var bones = model.Bones;
            var morphs = model.Morphs;
            var boneList = mmdModel.Bones.Select(_ => new BoneTuple
            {
                MmdBone = _,
                Transform = _.Transform,
                Bone = bones[_.Name],
            }).Where(_ => _.Bone != null).ToArray();

            if (reset != null)
            {
                reset();
                reset = null;
            }

            foreach (var i in boneList)
            {
                var layer = i.Bone.Layers.First();
                var local = layer.CurrentLocalMotion;
                var isSelected = layer.Selected;
                var transform = i.Transform;
                var initialPosition = i.Bone.InitialPosition;
                Vector3 translation;
                Quaternion rotation;
                Vector3 scale;

                ResolveParent(boneList, i, ref transform, ref initialPosition);
                ResolveAffect(boneList, i, ref transform, ref initialPosition);

                transform *= Matrix.Translation(-initialPosition);
                transform.Decompose(out scale, out rotation, out translation);

                reset += () =>
                {
                    layer.CurrentLocalMotion = local;
                    layer.Selected = isSelected;
                };

                layer.CurrentLocalMotion = new MotionData((i.Bone.BoneFlags & BoneType.XYZ) != 0 ? translation : Vector3.Zero, rotation);
                layer.Selected = true;
            }

            foreach (var i in mmdModel.Morphs)
            {
                var morph = morphs[i.Name];

                if (morph != null)
                {
                    var local = morph.CurrentWeight;
                    var newWeight = i.Weight;

                    reset += () => morph.CurrentWeight = local;
                    morph.CurrentWeight = newWeight;
                    morph.Selected = true;
                }
            }
        }
Beispiel #4
0
        void SynchronizeTransformation(MmdModel mmdModel, ref Action reset)
        {
            if (mmdModel == null)
            {
                return;
            }

            var model    = this.Scene.ActiveModel;
            var bones    = model.Bones;
            var morphs   = model.Morphs;
            var boneList = mmdModel.Bones.Select(_ => new BoneTuple
            {
                MmdBone   = _,
                Transform = _.Transform,
                Bone      = bones[_.Name],
            }).Where(_ => _.Bone != null).ToArray();

            if (reset != null)
            {
                reset();
                reset = null;
            }

            foreach (var i in boneList)
            {
                var        layer           = i.Bone.Layers.First();
                var        local           = layer.CurrentLocalMotion;
                var        isSelected      = layer.Selected;
                var        transform       = i.Transform;
                var        initialPosition = i.Bone.InitialPosition;
                Vector3    translation;
                Quaternion rotation;
                Vector3    scale;

                ResolveParent(boneList, i, ref transform, ref initialPosition);
                ResolveAffect(boneList, i, ref transform, ref initialPosition);

                transform *= Matrix.Translation(-initialPosition);
                transform.Decompose(out scale, out rotation, out translation);

                reset += () =>
                {
                    layer.CurrentLocalMotion = local;
                    layer.Selected           = isSelected;
                };

                layer.CurrentLocalMotion = new MotionData((i.Bone.BoneFlags & BoneType.XYZ) != 0 ? translation : Vector3.Zero, rotation);
                layer.Selected           = true;
            }

            foreach (var i in mmdModel.Morphs)
            {
                var morph = morphs[i.Name];

                if (morph != null)
                {
                    var local     = morph.CurrentWeight;
                    var newWeight = i.Weight;

                    reset += () => morph.CurrentWeight = local;
                    morph.CurrentWeight = newWeight;
                    morph.Selected      = true;
                }
            }
        }