예제 #1
0
        private void WriteSkelAnimation(AnimationClip clipAnimation, GameObject root, BinaryWriter writer)
        {
            var      trackBones = CloneTree(root).Select(_ => new BoneTrack(_)).ToList();
            var      cloneRoot  = trackBones[0].gameObject;
            ISampler sampler;

            if (clipAnimation.legacy)
            {
                sampler = new LegacySampler(cloneRoot, clipAnimation);
            }
            else
            {
                sampler = new AnimatorSampler(cloneRoot, clipAnimation);
            }
            using (sampler)
            {
                var timeStep     = 1.0f / clipAnimation.frameRate;
                var numKeyFrames = 1 + (int)(clipAnimation.length * clipAnimation.frameRate);

                for (var frame = 0; frame < numKeyFrames; ++frame)
                {
                    var t = frame * timeStep;
                    sampler.Sample(t);
                    //clipAnimation.SampleAnimation(cloneRoot, t);
                    //foreach (var trackBone in trackBones)
                    //{
                    //    clipAnimation.SampleAnimation(trackBone.gameObject, t);
                    //}
                    foreach (var trackBone in trackBones)
                    {
                        trackBone.Sample(t);
                    }
                }
            }

            writer.Write(trackBones.Count);
            foreach (var bone in trackBones)
            {
                WriteStringSZ(writer, _engine.DecorateName(bone.gameObject.name));
                writer.Write((byte)7);
                writer.Write(bone.translation.Count);
                for (var frame = 0; frame < bone.translation.Count; ++frame)
                {
                    writer.Write(bone.keys[frame]);
                    Write(writer, bone.translation[frame]);
                    Write(writer, bone.rotation[frame]);
                    Write(writer, bone.scale[frame]);
                }
            }

            //foreach (var bone in trackBones)
            //{
            //    bone.Reset();
            //}
            Object.DestroyImmediate(trackBones[0].gameObject);
        }
예제 #2
0
 public TransitionJson(AnimatorStateTransition transition, Urho3DEngine engine, PrefabContext prefabContext)
 {
     this.destinationState = engine.DecorateName(transition.destinationState.name);
     this.duration         = transition.duration;
     // this.hasFixedDuration = transition.hasFixedDuration;
     // this.canTransitionToSelf = transition.canTransitionToSelf;
     // this.exitTime = transition.exitTime;
     // this.hasExitTime = transition.hasExitTime;
     // this.offset = transition.offset;
     // this.orderedInterruption = transition.orderedInterruption;
     this.conditions = transition.conditions.Select(_ => new ConditionJson(_, engine, prefabContext)).ToArray();
     // this.isExit = transition.isExit;
     // this.mute = transition.mute;
     // this.solo = transition.solo;
 }
예제 #3
0
 public BlendTreeJson(BlendTree blendTree, Urho3DEngine engine, PrefabContext prefabContext)
 {
     this.name                   = engine.DecorateName(blendTree.name);
     this.blendParameter         = blendTree.blendParameter;
     this.blendParameterY        = blendTree.blendParameterY;
     this.blendType              = blendTree.blendType;
     this.maxThreshold           = blendTree.maxThreshold;
     this.minThreshold           = blendTree.minThreshold;
     this.useAutomaticThresholds = blendTree.useAutomaticThresholds;
     this.apparentSpeed          = blendTree.apparentSpeed;
     this.averageAngularSpeed    = blendTree.averageAngularSpeed;
     this.averageDuration        = blendTree.averageDuration;
     this.averageSpeed           = blendTree.averageSpeed;
     this.isHumanMotion          = blendTree.isHumanMotion;
     this.isLooping              = blendTree.isLooping;
     this.legacy                 = blendTree.legacy;
     this.children               = blendTree.children.Select(_ => new ChildMotionJson(_, engine, prefabContext)).ToArray();
 }
예제 #4
0
            public StateJson(AnimatorState state, Urho3DEngine engine, PrefabContext prefabContext)
            {
                this.name = engine.DecorateName(state.name);
                // this.speed = state.speed;
                // this.cycleOffset = state.cycleOffset;
                var motion = state.motion;

                if (motion is AnimationClip animationClip)
                {
                    // this.animationClip = engine.EvaluateAnimationName(animationClip, prefabContext);
                    engine.ScheduleAssetExport(animationClip, prefabContext);
                }
                else if (motion is BlendTree blendTree)
                {
                    // this.hasBlendTree = true;
                    // this.blendTree = new BlendTreeJson(blendTree, engine, prefabContext);
                }

                transitions = state.transitions.Select(_ => new TransitionJson(_, engine, prefabContext)).ToArray();
            }
예제 #5
0
 public ControllerJson(AnimatorController animationController, string assetName, Urho3DEngine engine, PrefabContext prefabContext)
 {
     this.name = engine.DecorateName(animationController.name);
     layers    = animationController.layers.Select((_, index) => new LayerJson(_, assetName, index, engine, prefabContext)).ToArray();
 }
예제 #6
0
 public StateMachineJson(AnimatorStateMachine stateMachine, Urho3DEngine engine, PrefabContext prefabContext)
 {
     this.defaultState        = engine.DecorateName(stateMachine.defaultState?.name);
     this.anyStateTransitions = stateMachine.anyStateTransitions.Select(_ => new TransitionJson(_, engine, prefabContext)).ToArray();
     states = stateMachine.states.Select(_ => new StateJson(_.state, engine, prefabContext)).ToArray();
 }
예제 #7
0
        private void WriteSkelAnimation(AnimationClip clipAnimation, GameObject root, BinaryWriter writer)
        {
            var      trackBones = CloneTree(root).Select(_ => new BoneTrack(_)).ToList();
            var      cloneRoot  = trackBones[0].gameObject;
            ISampler sampler;

            if (!clipAnimation.isHumanMotion)
            {
                sampler = new LegacySampler(cloneRoot, clipAnimation);
            }
            else
            {
                sampler = new AnimatorSampler(cloneRoot, clipAnimation);
            }
            using (sampler)
            {
                var timeStep     = 1.0f / clipAnimation.frameRate;
                var numKeyFrames = 1 + (int)(clipAnimation.length * clipAnimation.frameRate);

                for (var frame = 0; frame < numKeyFrames; ++frame)
                {
                    var t = frame * timeStep;
                    sampler.Sample(t);
                    //clipAnimation.SampleAnimation(cloneRoot, t);
                    //foreach (var trackBone in trackBones)
                    //{
                    //    clipAnimation.SampleAnimation(trackBone.gameObject, t);
                    //}
                    foreach (var trackBone in trackBones)
                    {
                        trackBone.Sample(t);
                    }
                }
            }

            writer.Write(trackBones.Count);
            foreach (var bone in trackBones)
            {
                bone.Optimize();
            }
            foreach (var bone in trackBones)
            {
                var  mask           = 0;
                bool hasTranslation = false;
                bool hasRotation    = false;
                bool hasScale       = false;
                if (bone.translation != null && bone.translation.Count > 0)
                {
                    mask          |= 1;
                    hasTranslation = true;
                }

                if (bone.rotation != null && bone.rotation.Count > 0)
                {
                    mask       |= 2;
                    hasRotation = true;
                }

                if (bone.scale != null && bone.scale.Count > 0)
                {
                    mask    |= 4;
                    hasScale = true;
                }
                if (mask == 0)
                {
                    continue;
                }
                WriteStringSZ(writer, _engine.DecorateName(bone.gameObject.name));
                writer.Write((byte)mask);
                writer.Write(bone.keys.Count);
                for (var frame = 0; frame < bone.keys.Count; ++frame)
                {
                    writer.Write(bone.keys[frame]);
                    if (hasTranslation)
                    {
                        Write(writer, bone.translation[frame]);
                    }
                    if (hasRotation)
                    {
                        Write(writer, bone.rotation[frame]);
                    }
                    if (hasScale)
                    {
                        Write(writer, bone.scale[frame]);
                    }
                }
            }

            //foreach (var bone in trackBones)
            //{
            //    bone.Reset();
            //}
            Object.DestroyImmediate(trackBones[0].gameObject);
        }