Esempio n. 1
0
        private void ConvertBone(Dictionary <Vitaboy.Bone, NodeBuilder> all, Vitaboy.Bone bone, NodeBuilder target)
        {
            all[bone] = target;
            var len = (bone.Children.Length == 0) ? 0.1f : bone.Children.Where(x => x.Translation.Length() > 0).Average(x => x.Translation.Length() * MeshScale);

            if (len == 0)
            {
                len = 0.1f;
            }
            var recursiveScale = RecursiveScale(target);

            if (target.Parent != null)
            {
                len = len / recursiveScale;
            }
            //var len = Vec3Convert(bone.Translation).Length();
            var quat  = QuatConvert(bone.Rotation);
            var trans = Vec3Convert(bone.Translation) / recursiveScale;

            if (bone.Name == "ROOT")
            {
                quat  = RotateQ * quat;
                trans = Vector3.Transform(trans, RotateM);
            }
            target.WithLocalRotation(quat)
            .WithLocalTranslation(trans)
            .WithLocalScale(Vector3.One * len);

            foreach (var child in bone.Children)
            {
                ConvertBone(all, child, target.CreateNode(child.Name));
            }
        }
Esempio n. 2
0
        public Vitaboy.Bone NodeToBone(Node bone, Matrix4x4 worldMat)
        {
            AffineTransform worldTransform = AffineTransform.WorldToLocal(Matrix4x4.Identity, worldMat);
            var             vbone          = new Vitaboy.Bone();

            vbone.Name = bone.Name;
            var isroot = bone.Name == "ROOT";

            if (bone.VisualParent == null || isroot)
            {
                vbone.ParentName = "NULL";
            }
            else
            {
                vbone.ParentName = bone.VisualParent.Name;
            }
            vbone.HasProps     = false;
            vbone.Properties   = new List <Vitaboy.PropertyListItem>();
            vbone.CanBlend     = 1;
            vbone.CanRotate    = 1;
            vbone.CanTranslate = 1;
            var recursiveScale = RecursiveScale(bone.VisualParent);

            var transform = bone.LocalTransform;
            var baseQuat  = transform.Rotation;

            if (isroot)
            {
                baseQuat = RotateQ * worldTransform.Rotation * baseQuat;         //worldTransform.Rotation * baseQuat;
            }
            vbone.Rotation = QuatConvert(baseQuat);

            var baseTrans = transform.Translation;

            if (isroot)
            {
                baseTrans = Vector3.Transform(baseTrans, worldMat * RotateM); //worldMat * RotateM);
            }
            baseTrans        *= recursiveScale;
            vbone.Translation = Vec3Convert(baseTrans);
            return(vbone);
        }