Example #1
0
        private BabylonAnimation ExportAnimation(string property, Func <int, float[]> extractValueFunc, BabylonAnimation.DataType dataType, bool removeLinearAnimationKeys = true)
        {
            var optimizeAnimations = !Loader.Core.RootNode.GetBoolProperty("babylonjs_donotoptimizeanimations"); // reverse negation for clarity

            var start = Loader.Core.AnimRange.Start;
            var end   = Loader.Core.AnimRange.End;

            float[] previous = null;
            var     keys     = new List <BabylonAnimationKey>();

            for (var key = start; key <= end; key += Loader.Global.TicksPerFrame)
            {
                var current = extractValueFunc(key);

                keys.Add(new BabylonAnimationKey()
                {
                    frame  = key / Loader.Global.TicksPerFrame,
                    values = current
                });

                previous = current;
            }
            var keysFull = new List <BabylonAnimationKey>(keys);

            if (optimizeAnimations)
            {
                OptimizeAnimations(keys, removeLinearAnimationKeys);
            }

            if (IsAnimationKeysRelevant(keys))
            {
                if (keys[keys.Count - 1].frame != end / Loader.Global.TicksPerFrame)
                {
                    keys.Add(new BabylonAnimationKey()
                    {
                        frame  = end / Loader.Global.TicksPerFrame,
                        values = (float[])keys[keys.Count - 1].values.Clone()
                    });
                }

                var babylonAnimation = new BabylonAnimation
                {
                    dataType       = (int)dataType,
                    name           = property + " animation",
                    keys           = keys.ToArray(),
                    keysFull       = keysFull,
                    framePerSecond = Loader.Global.FrameRate,
                    loopBehavior   = (int)BabylonAnimation.LoopBehavior.Cycle,
                    property       = property
                };
                return(babylonAnimation);
            }
            return(null);
        }
Example #2
0
        private static bool ExportController(IControl control, string property, List <BabylonAnimation> animations, uint classId, BabylonAnimation.DataType dataType, Func <int, IIKeyControl, BabylonAnimationKey> generateFunc)
        {
            if (control == null)
            {
                return(false);
            }

            var keyControl = control.GetInterface(InterfaceID.Keycontrol) as IIKeyControl;

            if (keyControl == null)
            {
                return(false);
            }

            if (control.ClassID.PartA != classId)
            {
                return(false);
            }

            BabylonAnimation.LoopBehavior loopBehavior;
            switch (control.GetORT(2))
            {
            case 2:
                loopBehavior = BabylonAnimation.LoopBehavior.Cycle;
                break;

            default:
                loopBehavior = BabylonAnimation.LoopBehavior.Relative;
                break;
            }

            var keys = new List <BabylonAnimationKey>();

            for (var index = 0; index < keyControl.NumKeys; index++)
            {
                keys.Add(generateFunc(index, keyControl));
            }

            return(ExportBabylonKeys(keys, property, animations, dataType, loopBehavior));
        }
Example #3
0
        private void ExportAnimation(string property, List <BabylonAnimation> animations, Func <int, float[]> extractValueFunc, BabylonAnimation.DataType dataType, bool removeLinearAnimationKeys = true)
        {
            var babylonAnimation = ExportAnimation(property, extractValueFunc, dataType, removeLinearAnimationKeys);

            if (babylonAnimation != null)
            {
                animations.Add(babylonAnimation);
            }
        }
Example #4
0
        private static bool ExportBabylonKeys(List <BabylonAnimationKey> keys, string property, List <BabylonAnimation> animations, BabylonAnimation.DataType dataType, BabylonAnimation.LoopBehavior loopBehavior)
        {
            if (keys.Count == 0)
            {
                return(false);
            }

            var end = Loader.Core.AnimRange.End;

            if (keys[keys.Count - 1].frame != end / Loader.Global.TicksPerFrame)
            {
                keys.Add(new BabylonAnimationKey()
                {
                    frame  = end / Loader.Global.TicksPerFrame,
                    values = keys[keys.Count - 1].values
                });
            }

            var babylonAnimation = new BabylonAnimation
            {
                dataType       = (int)dataType,
                name           = property + " animation",
                keys           = keys.ToArray(),
                framePerSecond = Loader.Global.FrameRate,
                loopBehavior   = (int)loopBehavior,
                property       = property
            };

            animations.Add(babylonAnimation);

            return(true);
        }
Example #5
0
        private bool ExportGameController(IIGameControl control, string property, List <BabylonAnimation> animations, IGameControlType type, BabylonAnimation.DataType dataType, Func <IIGameKey, float[]> extractValueFunc)
        {
            var keys = ExportBabylonKeysFromGameController(control, type, extractValueFunc);

            if (keys == null)
            {
                return(false);
            }

            var loopBehavior = BabylonAnimation.LoopBehavior.Cycle;

            return(ExportBabylonKeys(keys, property, animations, dataType, loopBehavior));
        }
Example #6
0
        private static void ExportAnimation(string property, List <BabylonAnimation> animations, Func <int, float[]> extractValueFunc, BabylonAnimation.DataType dataType)
        {
            var exportNonOptimizedAnimations = Loader.Core.RootNode.GetBoolProperty("babylonjs_exportnonoptimizedanimations");

            var start = Loader.Core.AnimRange.Start;
            var end   = Loader.Core.AnimRange.End;

            float[] previous = null;
            var     keys     = new List <BabylonAnimationKey>();

            for (var key = start; key <= end; key += Ticks)
            {
                var current = extractValueFunc(key);

                if (exportNonOptimizedAnimations && previous != null && previous.IsEqualTo(current))
                {
                    continue; // Do not add key
                }

                keys.Add(new BabylonAnimationKey()
                {
                    frame  = key / Ticks,
                    values = current
                });

                previous = current;
            }

            if (!exportNonOptimizedAnimations)
            {
                RemoveLinearAnimationKeys(keys);
            }

            if (keys.Count > 1)
            {
                var animationPresent = true;

                if (keys.Count == 2)
                {
                    if (keys[0].values.IsEqualTo(keys[1].values))
                    {
                        animationPresent = false;
                    }
                }

                if (animationPresent)
                {
                    if (keys[keys.Count - 1].frame != end / Ticks)
                    {
                        keys.Add(new BabylonAnimationKey()
                        {
                            frame  = end / Ticks,
                            values = keys[keys.Count - 1].values
                        });
                    }

                    var babylonAnimation = new BabylonAnimation
                    {
                        dataType       = (int)dataType,
                        name           = property + " animation",
                        keys           = keys.ToArray(),
                        framePerSecond = Loader.Global.FrameRate,
                        loopBehavior   = (int)BabylonAnimation.LoopBehavior.Cycle,
                        property       = property
                    };

                    animations.Add(babylonAnimation);
                }
            }
        }
Example #7
0
        private static bool ExportController(IControl control, string property, List <BabylonAnimation> animations, uint classId, BabylonAnimation.DataType dataType, Func <int, IIKeyControl, BabylonAnimationKey> generateFunc)
        {
            if (control == null)
            {
                return(false);
            }

            var keyControl = control.GetInterface(InterfaceID.Keycontrol) as IIKeyControl;

            if (keyControl == null)
            {
                return(false);
            }

            if (control.ClassID.PartA != classId)
            {
                return(false);
            }

            var keys = new List <BabylonAnimationKey>();

            BabylonAnimation.LoopBehavior loopBehavior;

            switch (control.GetORT(2))
            {
            case 2:
                loopBehavior = BabylonAnimation.LoopBehavior.Cycle;
                break;

            default:
                loopBehavior = BabylonAnimation.LoopBehavior.Relative;
                break;
            }

            for (var index = 0; index < keyControl.NumKeys; index++)
            {
                keys.Add(generateFunc(index, keyControl));
            }

            if (keys.Count == 0)
            {
                return(false);
            }

            var end = Loader.Core.AnimRange.End;

            if (keys[keys.Count - 1].frame != end / Ticks)
            {
                keys.Add(new BabylonAnimationKey()
                {
                    frame  = end / Ticks,
                    values = keys[keys.Count - 1].values
                });
            }

            var babylonAnimation = new BabylonAnimation
            {
                dataType       = (int)dataType,
                name           = property + " animation",
                keys           = keys.ToArray(),
                framePerSecond = Loader.Global.FrameRate,
                loopBehavior   = (int)loopBehavior,
                property       = property
            };

            animations.Add(babylonAnimation);

            return(true);
        }
        private static void ExportAnimation(string property, List <BabylonAnimation> animations, Func <int, float[]> extractValueFunc, BabylonAnimation.DataType dataType)
        {
            var start = Loader.Core.AnimRange.Start;
            var end   = Loader.Core.AnimRange.End;

            float[] previous = null;
            var     keys     = new List <BabylonAnimationKey>();

            for (var key = start; key <= end; key += Ticks)
            {
                var current = extractValueFunc(key);


                keys.Add(new BabylonAnimationKey()
                {
                    frame  = key / Ticks,
                    values = current
                });


                previous = current;
            }
            RemoveLinearAnimationKeys(keys);
            if (keys.Count > 0)
            {
                var animationPresent = true;

                if (keys.Count == 2)
                {
                    if (keys[0].values.IsEqualTo(keys[1].values))
                    {
                        animationPresent = false;
                    }
                }

                if (animationPresent)
                {
                    if (keys[keys.Count - 1].frame != end / Ticks)
                    {
                        keys.Add(new BabylonAnimationKey()
                        {
                            frame  = end / Ticks,
                            values = keys[keys.Count - 1].values
                        });
                    }

                    var babylonAnimation = new BabylonAnimation
                    {
                        dataType       = dataType,
                        name           = property + " animation",
                        keys           = keys.ToArray(),
                        framePerSecond = Loader.Global.FrameRate,
                        loopBehavior   = BabylonAnimation.LoopBehavior.Cycle,
                        property       = property
                    };

                    animations.Add(babylonAnimation);
                }
            }
        }
Example #9
0
        private BabylonAnimation ExportAnimation(string property, Func <int, float[]> extractValueFunc, BabylonAnimation.DataType dataType, bool removeLinearAnimationKeys = true, bool optimizeAnimations = false, string name = null)
        {
            var start = Loader.Core.AnimRange.Start;
            var end   = Loader.Core.AnimRange.End;

            float[] previous = null;
            var     keys     = new List <BabylonAnimationKey>();

            for (var key = start; key <= end; key += Loader.Global.TicksPerFrame)
            {
                var current = extractValueFunc(key);

                keys.Add(new BabylonAnimationKey()
                {
                    frame  = key / Loader.Global.TicksPerFrame,
                    values = current
                });

                previous = current;
            }
            var keysFull = new List <BabylonAnimationKey>(keys);

            // Optimization process always keeps first and last frames
            if (optimizeAnimations)
            {
                OptimizeAnimations(keys, removeLinearAnimationKeys, out int keyRemovedCount);
                if (keyRemovedCount > 0)
                {
                    logger?.RaiseMessage("Optimization | Removed " + keyRemovedCount + " keys from the animation '" + property + "' of '" + (name == null ? "" : name) + "'");
                }
            }

            if (IsAnimationKeysRelevant(keys))
            {
                if (keys[keys.Count - 1].frame != end / Loader.Global.TicksPerFrame)
                {
                    keys.Add(new BabylonAnimationKey()
                    {
                        frame  = end / Loader.Global.TicksPerFrame,
                        values = (float[])keys[keys.Count - 1].values.Clone()
                    });
                }

                var babylonAnimation = new BabylonAnimation
                {
                    dataType       = (int)dataType,
                    name           = property + " animation",
                    keys           = keys.ToArray(),
                    keysFull       = keysFull,
                    framePerSecond = Loader.Global.FrameRate,
                    loopBehavior   = (int)BabylonAnimation.LoopBehavior.Cycle,
                    property       = property
                };
                return(babylonAnimation);
            }
            return(null);
        }
        private static BabylonAnimation ExportAnimation(string property, Func <int, float[]> extractValueFunc, BabylonAnimation.DataType dataType, bool removeLinearAnimationKeys = true)
        {
            var optimizeAnimations = !Loader.Core.RootNode.GetBoolProperty("babylonjs_donotoptimizeanimations"); // reverse negation for clarity

            var start = Loader.Core.AnimRange.Start;
            var end   = Loader.Core.AnimRange.End;

            float[] previous = null;
            var     keys     = new List <BabylonAnimationKey>();

            for (var key = start; key <= end; key += Ticks)
            {
                var current = extractValueFunc(key);

                // if animations are not optimized, all keys from start to end are created
                // otherwise, keys are added only for non constant values
                if (optimizeAnimations && previous != null && previous.IsEqualTo(current))
                {
                    continue; // Do not add key
                }

                keys.Add(new BabylonAnimationKey()
                {
                    frame  = key / Ticks,
                    values = current
                });

                previous = current;
            }

            // if animations are not optimized, do the following as minimal optimization
            if (removeLinearAnimationKeys && !optimizeAnimations)
            {
                RemoveLinearAnimationKeys(keys);
            }

            if (keys.Count > 1)
            {
                var animationPresent = true;

                if (keys.Count == 2)
                {
                    if (keys[0].values.IsEqualTo(keys[1].values))
                    {
                        animationPresent = false;
                    }
                }

                if (animationPresent)
                {
                    if (keys[keys.Count - 1].frame != end / Ticks)
                    {
                        keys.Add(new BabylonAnimationKey()
                        {
                            frame  = end / Ticks,
                            values = keys[keys.Count - 1].values
                        });
                    }

                    var babylonAnimation = new BabylonAnimation
                    {
                        dataType       = (int)dataType,
                        name           = property + " animation",
                        keys           = keys.ToArray(),
                        framePerSecond = Loader.Global.FrameRate,
                        loopBehavior   = (int)BabylonAnimation.LoopBehavior.Cycle,
                        property       = property
                    };
                    return(babylonAnimation);
                }
            }
            return(null);
        }