Esempio n. 1
0
        private void RenderMapElements(LipSyncMapData mapData, IElementNode element, PhonemeType phoneme)
        {
            LipSyncMapItem item = mapData.FindMapItem(element.Id);

            if (item == null)
            {
                return;
            }

            if (mapData.IsFaceComponentType(FaceComponent.Outlines, item))
            {
                var colorVal = mapData.ConfiguredColorAndIntensity(item);
                var result   = CreateIntentsForElement(element, colorVal.Item1, colorVal.Item2, TimeSpan);
                _elementData.Add(result);
            }
            else if (mapData.IsFaceComponentType(FaceComponent.EyesOpen, item))
            {
                var colorVal = mapData.ConfiguredColorAndIntensity(item);
                var result   = CreateIntentsForElement(element, colorVal.Item1, colorVal.Item2, TimeSpan);
                _elementData.Add(result);
            }
            else
            {
                if (LipSyncMode == LipSyncMode.MarkCollection && _marks != null)
                {
                    TimeSpan lastMarkTime = StartTime;
                    foreach (var mark in _marks)
                    {
                        if (!AllowMarkGaps)
                        {
                            var gapDuration = mark.StartTime - lastMarkTime;
                            if (gapDuration.TotalMilliseconds > 10 && mapData.PhonemeState("REST", item))
                            {
                                //Fill the gap with a rest
                                var colorVal = mapData.ConfiguredColorAndIntensity(item);
                                var result   = CreateIntentsForElement(element, colorVal.Item1, colorVal.Item2, gapDuration);
                                result.OffsetAllCommandsByTime(lastMarkTime - StartTime);
                                _elementData.Add(result);
                            }

                            lastMarkTime = mark.EndTime;
                        }
                        if (mapData.PhonemeState(mark.Text, item))
                        {
                            var colorVal = mapData.ConfiguredColorAndIntensity(item);
                            var result   = CreateIntentsForElement(element, colorVal.Item1, colorVal.Item2, mark.Duration);
                            result.OffsetAllCommandsByTime(mark.StartTime - StartTime);
                            _elementData.Add(result);
                        }
                    }

                    if (!AllowMarkGaps)
                    {
                        var gapDuration = StartTime + TimeSpan - lastMarkTime;
                        if (gapDuration.TotalMilliseconds > 10 && mapData.PhonemeState("REST", item))
                        {
                            //Fill the gap with a rest
                            var colorVal = mapData.ConfiguredColorAndIntensity(item);
                            var result   = CreateIntentsForElement(element, colorVal.Item1, colorVal.Item2, gapDuration);
                            result.OffsetAllCommandsByTime(lastMarkTime - StartTime);
                            _elementData.Add(result);
                        }
                    }
                }
                else
                {
                    if (mapData.PhonemeState(phoneme.ToString(), item))
                    {
                        var colorVal = mapData.ConfiguredColorAndIntensity(item);
                        var result   = CreateIntentsForElement(element, colorVal.Item1, colorVal.Item2, TimeSpan);
                        _elementData.Add(result);
                    }
                }
            }
        }
Esempio n. 2
0
        // renders the given node to the internal ElementData dictionary. If the given node is
        // not a element, will recursively descend until we render its elements.
        private void RenderNodes()
        {
            EffectIntents      result;
            LipSyncMapData     mapData     = null;
            List <ElementNode> renderNodes = TargetNodes.SelectMany(x => x.GetNodeEnumerator()).ToList();

            if (LipSyncMode == LipSyncMode.MarkCollection)
            {
                SetupMarks();
            }

            if (_data.PhonemeMapping != null)
            {
                if (!_library.Library.ContainsKey(_data.PhonemeMapping))
                {
                    _data.PhonemeMapping = _library.DefaultMappingName;
                }

                PhonemeType phoneme = _data.StaticPhoneme;
                if (_library.Library.TryGetValue(_data.PhonemeMapping, out mapData))
                {
                    if (mapData.IsMatrix)
                    {
                        SetupPictureEffect();
                        if (LipSyncMode == LipSyncMode.MarkCollection)
                        {
                            foreach (var mark in _marks)
                            {
                                var file = mapData.PictureFileName(mark.Text.ToUpper());
                                _thePic.Image    = LoadImage(file);
                                _thePic.TimeSpan = mark.Duration;
                                _thePic.MarkDirty();
                                result = _thePic.Render();
                                result.OffsetAllCommandsByTime(mark.StartTime - StartTime);
                                _elementData.Add(result);
                                //}
                            }
                        }
                        else
                        {
                            var file = mapData.PictureFileName(phoneme);
                            if (File.Exists(file))
                            {
                                _thePic.Image = LoadImage(file);
                                result        = _thePic.Render();
                                _elementData.Add(result);
                            }
                        }

                        if (null != _thePic)
                        {
                            result = _thePic.Render();
                            _elementData.Add(result);
                        }
                    }
                    else
                    {
                        renderNodes.ForEach(delegate(ElementNode element)
                        {
                            LipSyncMapItem item = mapData.FindMapItem(element.Name);
                            if (item != null)
                            {
                                if (LipSyncMode == LipSyncMode.MarkCollection && _marks != null)
                                {
                                    foreach (var mark in _marks)
                                    {
                                        if (mapData.PhonemeState(element.Name, mark.Text.ToUpper(), item))
                                        {
                                            var colorVal = mapData.ConfiguredColorAndIntensity(element.Name, mark.Text.ToUpper(), item);
                                            result       = CreateIntentsForPhoneme(element, colorVal.Item1, colorVal.Item2, mark.Duration);
                                            result.OffsetAllCommandsByTime(mark.StartTime - StartTime);
                                            _elementData.Add(result);
                                        }
                                    }
                                }
                                else
                                {
                                    if (mapData.PhonemeState(element.Name, phoneme.ToString(), item))
                                    {
                                        var colorVal = mapData.ConfiguredColorAndIntensity(element.Name, phoneme.ToString(), item);
                                        result       = CreateIntentsForPhoneme(element, colorVal.Item1, colorVal.Item2, TimeSpan);
                                        _elementData.Add(result);
                                    }
                                }
                            }
                        });

                        TearDownPictureEffect();
                    }
                }
            }
        }