Example #1
0
 public virtual void applyToNode(Node node, TimeIndex timeIndex, float weight, float scale)
 {
     OgrePINVOKE.NodeAnimationTrack_applyToNode__SWIG_0(swigCPtr, Node.getCPtr(node), TimeIndex.getCPtr(timeIndex), weight, scale);
     if (OgrePINVOKE.SWIGPendingException.Pending)
     {
         throw OgrePINVOKE.SWIGPendingException.Retrieve();
     }
 }
 public override void getInterpolatedKeyFrame(TimeIndex timeIndex, KeyFrame kf)
 {
     OgrePINVOKE.VertexAnimationTrack_getInterpolatedKeyFrame(swigCPtr, TimeIndex.getCPtr(timeIndex), KeyFrame.getCPtr(kf));
     if (OgrePINVOKE.SWIGPendingException.Pending)
     {
         throw OgrePINVOKE.SWIGPendingException.Retrieve();
     }
 }
Example #3
0
 public virtual void apply(TimeIndex timeIndex, float weight)
 {
     OgrePINVOKE.AnimationTrack_apply__SWIG_1(swigCPtr, TimeIndex.getCPtr(timeIndex), weight);
     if (OgrePINVOKE.SWIGPendingException.Pending)
     {
         throw OgrePINVOKE.SWIGPendingException.Retrieve();
     }
 }
 public override void apply(TimeIndex timeIndex, float weight, float scale)
 {
     OgrePINVOKE.VertexAnimationTrack_apply__SWIG_0(swigCPtr, TimeIndex.getCPtr(timeIndex), weight, scale);
     if (OgrePINVOKE.SWIGPendingException.Pending)
     {
         throw OgrePINVOKE.SWIGPendingException.Retrieve();
     }
 }
 public override void apply(TimeIndex timeIndex)
 {
     OgrePINVOKE.VertexAnimationTrack_apply__SWIG_2(swigCPtr, TimeIndex.getCPtr(timeIndex));
     if (OgrePINVOKE.SWIGPendingException.Pending)
     {
         throw OgrePINVOKE.SWIGPendingException.Retrieve();
     }
 }
 public virtual void applyToVertexData(VertexData data, TimeIndex timeIndex, float weight, PoseList poseList)
 {
     OgrePINVOKE.VertexAnimationTrack_applyToVertexData__SWIG_0(swigCPtr, VertexData.getCPtr(data), TimeIndex.getCPtr(timeIndex), weight, PoseList.getCPtr(poseList));
     if (OgrePINVOKE.SWIGPendingException.Pending)
     {
         throw OgrePINVOKE.SWIGPendingException.Retrieve();
     }
 }
 public virtual void applyToVertexData(VertexData data, TimeIndex timeIndex)
 {
     OgrePINVOKE.VertexAnimationTrack_applyToVertexData__SWIG_2(swigCPtr, VertexData.getCPtr(data), TimeIndex.getCPtr(timeIndex));
     if (OgrePINVOKE.SWIGPendingException.Pending)
     {
         throw OgrePINVOKE.SWIGPendingException.Retrieve();
     }
 }
Example #8
0
        public void OneKeyTenThousandCalls()
        {
            const string key   = "'gamma";
            const int    count = 10000;

            var results = Enumerable.Range(0, count).Select(index => TimeIndex.GetUnique(key)).ToArray();

            CheckOneKeyResults(results);
        }
        public void HighlightTimeIndex(ref MotionSynthesizer synthesizer, TimeIndex timeIndex, bool debug = false)
        {
            AnimationSampleTime animSampleTime = AnimationSampleTime.CreateFromTimeIndex(Asset, ref synthesizer.Binary, timeIndex);

            if (animSampleTime.IsValid)
            {
                HighlightAnimationClip(animSampleTime.clip);
                HighlightCurrentSamplingTime(animSampleTime.clip, animSampleTime.sampleTimeInSeconds, debug);
            }
        }
Example #10
0
            public virtual bool getInterpolatedKeyFrame(AnimationTrack t, TimeIndex timeIndex, KeyFrame kf)
            {
                bool ret = OgrePINVOKE.AnimationTrack_Listener_getInterpolatedKeyFrame(swigCPtr, AnimationTrack.getCPtr(t), TimeIndex.getCPtr(timeIndex), KeyFrame.getCPtr(kf));

                if (OgrePINVOKE.SWIGPendingException.Pending)
                {
                    throw OgrePINVOKE.SWIGPendingException.Retrieve();
                }
                return(ret);
            }
Example #11
0
        public virtual float getKeyFramesAtTime(TimeIndex timeIndex, SWIGTYPE_p_p_Ogre__KeyFrame keyFrame1, SWIGTYPE_p_p_Ogre__KeyFrame keyFrame2)
        {
            float ret = OgrePINVOKE.AnimationTrack_getKeyFramesAtTime__SWIG_1(swigCPtr, TimeIndex.getCPtr(timeIndex), SWIGTYPE_p_p_Ogre__KeyFrame.getCPtr(keyFrame1), SWIGTYPE_p_p_Ogre__KeyFrame.getCPtr(keyFrame2));

            if (OgrePINVOKE.SWIGPendingException.Pending)
            {
                throw OgrePINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Example #12
0
        public TimeIndex _getTimeIndex(float timePos)
        {
            TimeIndex ret = new TimeIndex(OgrePINVOKE.Animation__getTimeIndex(swigCPtr, timePos), true);

            if (OgrePINVOKE.SWIGPendingException.Pending)
            {
                throw OgrePINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
        public void test_time_ask_past_index()
        {
            var date1 = DateTime.Now.AddDays(1).Date.AddSeconds(-1);
            var date2 = DateTime.Now.AddDays(1);

            var index = TimeIndex.GetIndex(date1);

            TimeIndex.GetIndex(date2);
            var indexToCompare = TimeIndex.GetIndex(date1);

            indexToCompare.Should().Be(index);
        }
        public void time_index_order_test()
        {
            var yearTotalSeconds = TimeSpan.FromDays(366).TotalSeconds;
            var refDate          = DateTime.Now.AddDays(30);
            var prevValue        = 0;

            for (int i = 0; i < yearTotalSeconds; i++)
            {
                var index = TimeIndex.GetIndex(refDate.AddSeconds(i));
                index.Should().BeGreaterThan(prevValue);
                prevValue = index;
            }
        }
Example #15
0
        public void DifferentKeys()
        {
            const string keyA = "'keyA";
            const string keyB = "'keyB";
            const string keyC = "'keyC";

            var resultA = TimeIndex.GetUnique(keyA);
            var resultB = TimeIndex.GetUnique(keyB);
            var resultC = TimeIndex.GetUnique(keyC);

            Assert.AreEqual(0, resultA.Index);
            Assert.AreEqual(0, resultB.Index);
            Assert.AreEqual(0, resultC.Index);
        }
Example #16
0
        public FileName GetFileName()
        {
            string    key       = String.Join("_", Segments);
            TimeIndex timeIndex = TimeIndex.GetUnique(key);

            string dateTimeText = GetDateTimeText(timeIndex.DateTime);
            string value        = dateTimeText + "__" + key;

            if (timeIndex.Index > 0)
            {
                value += "_" + timeIndex.Index;
            }

            value += ".xml";

            var fileName = new FileName(value, timeIndex.DateTime);

            return(fileName);
        }
        CodeBookIndex GetCodeBookIndex(ref Binary binary, TimeIndex timeIndex)
        {
            int numCodeBooks = binary.numCodeBooks;

            for (int i = 0; i < numCodeBooks; ++i)
            {
                ref var codeBook = ref binary.GetCodeBook(i);

                int numIntervals = codeBook.intervals.Length;

                for (int j = 0; j < numIntervals; ++j)
                {
                    var intervalIndex = codeBook.intervals[j];

                    ref var interval = ref binary.GetInterval(intervalIndex);

                    if (interval.segmentIndex == timeIndex.segmentIndex)
                    {
                        return(i);
                    }
                }
Example #18
0
        public void OneKeyMultipleTasks()
        {
            const string key   = "'alpha";
            const int    count = 1000;

            var taskArray = Enumerable.Range(0, count).Select(index =>
                                                              new Task <TimeIndex>(() =>
            {
                var timeIndex = TimeIndex.GetUnique(key);
                Trace.WriteLine("Result = " + timeIndex + " Index = " + index.ToString("000") + " ThreadId = " + Thread.CurrentThread.ManagedThreadId);
                return(timeIndex);
            }
                                                                                   )).ToArray();

            Array.ForEach(taskArray, task => task.Start());
            Task.WaitAll(taskArray);

            var results = taskArray.Select(task => task.Result).ToArray();

            CheckOneKeyResults(results);
        }
Example #19
0
        public void OneKeyMultipleThreads()
        {
            const string key   = "'beta";
            const int    count = 1000;

            var results = new TimeIndex[count];

            var threadArray = Enumerable.Range(0, count).Select(index =>
                                                                new Thread(() =>
            {
                var timeIndex = TimeIndex.GetUnique(key);
                Trace.WriteLine("Result = " + timeIndex + " Index = " + index.ToString("000") + " ThreadId = " + Thread.CurrentThread.ManagedThreadId);
                results[index] = timeIndex;
            }
                                                                           )).ToArray();


            Array.ForEach(threadArray, thread => thread.Start());
            Array.ForEach(threadArray, thread => thread.Join());

            CheckOneKeyResults(results);
        }
Example #20
0
        internal CalculatorResult Calculate(TimeSpan forTime)
        {
            var minIdx        = TimeIndex.GetIndex(DateTime.Now - forTime);
            var maxIdx        = TimeIndex.GetIndex(DateTime.Now - TimeSpan.FromSeconds(1));
            var splitCounters = _counters.Where(kv => kv.Key >= minIdx && kv.Key <= maxIdx).Select(kv => kv.Value).ToList();

            if (splitCounters.Any() == false)
            {
                return new CalculatorResult {
                           Count = 0, AverageTime = TimeSpan.MinValue
                }
            }
            ;

            var totalCount = splitCounters.Sum(c => c.Count);
            var totalTime  = splitCounters.Sum(c => c.TotalMilliseconds);

            return(new CalculatorResult
            {
                Count = totalCount,
                AverageTime = TimeSpan.FromMilliseconds(totalTime / totalCount)
            });
        }
    }
Example #21
0
 public void applyToAnimable(SWIGTYPE_p_Ogre__SharedPtrT_Ogre__AnimableValue_t anim, TimeIndex timeIndex)
 {
     OgrePINVOKE.NumericAnimationTrack_applyToAnimable__SWIG_2(swigCPtr, SWIGTYPE_p_Ogre__SharedPtrT_Ogre__AnimableValue_t.getCPtr(anim), TimeIndex.getCPtr(timeIndex));
     if (OgrePINVOKE.SWIGPendingException.Pending)
     {
         throw OgrePINVOKE.SWIGPendingException.Retrieve();
     }
 }
Example #22
0
        public static AnimationSampleTime CreateFromTimeIndex(Asset asset, ref Binary binary, TimeIndex timeIndex)
        {
            AnimationSampleTimeIndex animSampleTime = binary.GetAnimationSampleTimeIndex(timeIndex);

            if (animSampleTime.IsValid)
            {
                foreach (TaggedAnimationClip clip in asset.AnimationLibrary)
                {
                    if (!clip.Valid)
                    {
                        continue;
                    }

                    if (clip.AnimationClipGuid == animSampleTime.clipGuid)
                    {
                        var inverseSampleRate   = math.rcp(clip.SampleRate);
                        var sampleTimeInSeconds = animSampleTime.animFrameIndex * inverseSampleRate;

                        return(new AnimationSampleTime
                        {
                            clip = clip,
                            sampleTimeInSeconds = sampleTimeInSeconds
                        });
                    }
                }
            }

            return(CreateInvalid());
        }
Example #23
0
                public IEnumerator EncodeFragments(MemoryRef <Binary> binary, TaggedInterval[] intervals, FragmentFactory factory, string fragmentTypeName, Action <ProgressInfo> progressFeedback)
                {
                    progressFeedback.Invoke(new ProgressInfo()
                    {
                        title    = $"Start {fragmentTypeName} fragment encoder",
                        progress = 0.0f
                    });
                    //
                    // Prologue
                    //

                    int metricIndex = settings.metricIndex;

                    var numFeatures = factory.GetNumFeatures(ref binary.Ref, metricIndex);

                    var numQuantizedFeatures = factory.GetNumQuantizedFeatures(ref binary.Ref, metricIndex);

                    var numNormalizedFeatures = factory.GetNumNormalizedFeatures(ref binary.Ref, metricIndex);

                    var numTransformedFeatures = numFeatures - numQuantizedFeatures - numNormalizedFeatures;

                    numFragments = 0;

                    foreach (var interval in intervals)
                    {
                        numFragments += interval.numFrames;
                    }

                    //
                    // Generate fragments
                    //

                    FragmentArray fragmentArray = FragmentArray.Create(metricIndex, numFragments, numFeatures);

                    int writeIndex = 0;

                    foreach (var interval in intervals)
                    {
                        int segmentIndex = interval.segmentIndex;

                        Assert.IsTrue(
                            interval.firstFrame >=
                            interval.segment.destination.FirstFrame);

                        Assert.IsTrue(
                            interval.onePastLastFrame <=
                            interval.segment.destination.OnePastLastFrame);

                        int relativeFirstFrame =
                            interval.firstFrame -
                            interval.segment.destination.FirstFrame;

                        int numFrames = interval.numFrames;

                        for (int i = 0; i < numFrames; ++i)
                        {
                            int frameIndex = relativeFirstFrame + i;

                            var timeIndex =
                                TimeIndex.Create(
                                    segmentIndex, frameIndex);

                            var samplingTime =
                                SamplingTime.Create(timeIndex);


                            fragmentArray.samplingTimes[writeIndex++] = samplingTime;
                        }
                    }

                    Assert.IsTrue(writeIndex == numFragments);

                    progressFeedback.Invoke(new ProgressInfo()
                    {
                        title    = $"Create {fragmentTypeName} fragments",
                        progress = 0.0f
                    });

                    ICreateFragmentsJob createFragmentsJob    = factory.PrepareFragmentCreateJob(ref fragmentArray, ref binary.Ref);
                    JobHandle           createFragmentsHandle = createFragmentsJob.Schedule();

                    yield return(null);

                    if (bCancel)
                    {
                        createFragmentsHandle.Complete();
                        fragmentArray.Dispose();
                        yield break;
                    }

                    createFragmentsHandle.Complete();

                    progressFeedback.Invoke(new ProgressInfo()
                    {
                        title    = $"Quantize {fragmentTypeName} fragments",
                        progress = 0.0f
                    });

                    //
                    // Generate feature quantizers
                    //

                    quantizers =
                        new NativeArray <Quantizer>(
                            numQuantizedFeatures, Allocator.Persistent);

                    ComputeQuantizersJob computeQuantizersJob = new ComputeQuantizersJob()
                    {
                        fragmentArray = fragmentArray,
                        quantizers    = Quantizers
                    };

                    JobHandle computeQuantizersHandle = computeQuantizersJob.Schedule(numQuantizedFeatures, 1);

                    computeQuantizersHandle.Complete();


                    //
                    // Quantize magnitudes and normalize fragments
                    //

                    int numQuantizedValues = numFragments * numQuantizedFeatures;

                    quantizedValues =
                        new NativeArray <byte>(
                            numQuantizedValues, Allocator.Persistent);

                    NormalizeFeaturesJob normalizeFeaturesJob = new NormalizeFeaturesJob()
                    {
                        numQuantizedFeatures = numQuantizedFeatures,
                        quantizers           = Quantizers,
                        quantizedValues      = new MemoryArray <byte>(QuantizedValues),
                        fragmentArray        = fragmentArray
                    };

                    JobHandle normalizeFeaturesHandle = normalizeFeaturesJob.Schedule(numFragments, 1);

                    normalizeFeaturesHandle.Complete();

                    //
                    // Generate bounding boxes for feature normalization
                    //

                    boundingBoxes =
                        new NativeArray <BoundingBox>(
                            numTransformedFeatures, Allocator.Persistent);

                    ComputeBoundingBoxesJob computeBoundingBoxesJob = new ComputeBoundingBoxesJob()
                    {
                        fragmentArray          = fragmentArray,
                        numTransformedFeatures = numTransformedFeatures,
                        transformedIndex       = numFeatures - numTransformedFeatures,
                        boundingBoxes          = BoundingBoxes
                    };

                    JobHandle computeBoundingBoxesHandle = computeBoundingBoxesJob.Schedule(numTransformedFeatures, 1);

                    computeBoundingBoxesHandle.Complete();

                    //
                    // Normalize fragments
                    //

                    NormalizeFragmentsJob normalizeFragmentsJob = new NormalizeFragmentsJob()
                    {
                        numTransformedFeatures = numTransformedFeatures,
                        transformedIndex       = numFeatures - numTransformedFeatures,
                        boundingBoxes          = BoundingBoxes,
                        fragmentArray          = fragmentArray
                    };

                    JobHandle normalizeFragmentsHandle = normalizeFragmentsJob.Schedule(numFragments, 1);

                    normalizeFragmentsHandle.Complete();


                    //
                    // Product Quantization
                    //

                    progressFeedback.Invoke(new ProgressInfo()
                    {
                        title    = $"Prepare training {fragmentTypeName} fragments",
                        progress = 0.0f
                    });

                    yield return(null);

                    if (bCancel)
                    {
                        fragmentArray.Dispose();
                        yield break;
                    }

                    int numCodes = numFragments * numFeatures;

                    int numCodeWords = numFeatures * Binary.CodeBook.kNumCodeValues;

                    codes = new NativeArray <byte>(numCodes, Allocator.Persistent);

                    codeWords = new NativeArray <float3>(numCodeWords, Allocator.Persistent);

                    var pqs = ProductQuantizer.Settings.Default;

                    pqs.numAttempts          = settings.numAttempts;
                    pqs.numIterations        = settings.numIterations;
                    pqs.minimumNumberSamples = settings.minimumNumberSamples;
                    pqs.maximumNumberSamples = settings.maximumNumberSamples;

                    using (var pq = new ProductQuantizer(numFeatures * 3, numFeatures, pqs))
                    {
                        using (ProductQuantizer.TrainingData trainingData = pq.ScheduleTraining(ref fragmentArray))
                        {
                            float progression = 0.0f;
                            do
                            {
                                progression = trainingData.FrameUpdate();

                                progressFeedback.Invoke(new ProgressInfo()
                                {
                                    title    = $"Train {fragmentTypeName} fragments",
                                    progress = progression
                                });

                                yield return(null);

                                if (bCancel)
                                {
                                    trainingData.ForceCompleteCurrentBatch();
                                    fragmentArray.Dispose();
                                    yield break;
                                }
                            }while (progression < 1.0f);

                            trainingData.ForceCompleteCurrentBatch();
                        }

                        progressFeedback.Invoke(new ProgressInfo()
                        {
                            title    = $"Compute {fragmentTypeName} codes",
                            progress = 0.0f
                        });
                        pq.ComputeCodes(ref fragmentArray, Codes);

                        Assert.IsTrue(pq.centroids.Length == numCodeWords * 3);

                        for (int i = 0; i < numCodeWords; ++i)
                        {
                            float x = pq.centroids[i * 3 + 0];
                            float y = pq.centroids[i * 3 + 1];
                            float z = pq.centroids[i * 3 + 2];

                            var centroid = new float3(x, y, z);

                            var words = CodeWords;
                            words[i] = centroid;
                        }
                    }

                    fragmentArray.Dispose();
                }
            public void AddAnimation(MogreAnimation animation, AnimationState animationState)
            {
                Children.ForEach(x => x.AddAnimation(animation, animationState));

                if (!animation.HasNodeTrack(ReferenceBone.Handle))
                    return;

                TimeIndex index = new TimeIndex(animationState.TimePosition);
                TransformKeyFrame keyFrame = new TransformKeyFrame(null, 0);
                animation.GetNodeTrack(ReferenceBone.Handle).GetInterpolatedKeyFrame(index, keyFrame);
                Node.Position += keyFrame.Translate * animationState.Weight;
                Node.Orientation *= Quaternion.Slerp(animationState.Weight, Quaternion.IDENTITY, keyFrame.Rotation);
            }
Example #25
0
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(TimeIndex obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }