/// <summary> /// Convienience method to generate intents that knows how to deal with discrete colors. /// </summary> /// <param name="node"></param> /// <param name="gradient"></param> /// <param name="level"></param> /// <param name="startPos"></param> /// <param name="endPos"></param> /// <param name="duration"></param> /// <param name="startTime"></param> /// <param name="isDiscrete"></param> /// <returns></returns> protected EffectIntents GenerateEffectIntents(ElementNode node, ColorGradient gradient, Curve level, double startPos, double endPos, TimeSpan duration, TimeSpan startTime, bool isDiscrete) { EffectIntents result = new EffectIntents(); if (isDiscrete) { IEnumerable <Color> colors = ColorModule.getValidColorsForElementNode(node, false) .Intersect(gradient.GetColorsInGradient()); foreach (Color color in colors) { double proportion = gradient.GetProportionOfColorAt(startPos, color); var startIntensity = (level.GetValue(startPos * 100) / 100) * proportion; proportion = gradient.GetProportionOfColorAt(endPos, color); var endIntensity = (level.GetValue(endPos * 100) / 100) * proportion; if (startIntensity > 0 && endIntensity > 0) { var intent = CreateDiscreteIntent(color, startIntensity, endIntensity, duration); result.AddIntentForElement(node.Element.Id, intent, startTime); } } } else { var startIntensity = level.GetValue(startPos * 100) / 100; var endIntensity = level.GetValue(endPos * 100) / 100; if (startIntensity > 0 && endIntensity > 0) { var intent = CreateIntent(gradient.GetColorAt(startPos), gradient.GetColorAt(endPos), startIntensity, endIntensity, duration); result.AddIntentForElement(node.Element.Id, intent, startTime); } } return(result); }
//Validate that the we are using valid colors and set appropriate defaults if not. private void CheckForInvalidColorData() { // check for sane default colors when first rendering it HashSet <Color> validColors = new HashSet <Color>(); validColors.AddRange(TargetNodes.SelectMany(x => ColorModule.getValidColorsForElementNode(x, true))); //Validate Color 1 if (validColors.Any() && (!validColors.Contains(_data.Color1.ToArgb()) || !_data.ColorGradient1.GetColorsInGradient().IsSubsetOf(validColors))) { Color1 = validColors.First(); ColorGradient1 = new ColorGradient(validColors.First()); } //Validate color 2 if (validColors.Any() && (!validColors.Contains(_data.Color2.ToArgb()) || !_data.ColorGradient2.GetColorsInGradient().IsSubsetOf(validColors))) { if (validColors.Count > 1) { Color2 = validColors.ElementAt(1); ColorGradient2 = new ColorGradient(validColors.ElementAt(1)); } else { Color2 = validColors.First(); ColorGradient2 = new ColorGradient(validColors.First()); } } }
public static Transform LoadIcon(Transform iconPrefab, Transform icon, Vector3 localPosition, Vector3 localScale, Transform parent, int sortingOrderAdd, Color color, bool forGrid) { Transform transform = UnityEngine.Object.Instantiate <Transform>(iconPrefab, parent); transform.name = icon.name + " (C)"; transform.localPosition = localPosition; transform.localRotation = icon.localRotation; transform.localScale = localScale; transform.gameObject.SetActive(icon.gameObject.activeSelf); if (icon.GetComponent <SpriteRenderer>() != null) { transform.GetComponent <SpriteRenderer>().sprite = icon.GetComponent <SpriteRenderer>().sprite; transform.GetComponent <SpriteRenderer>().sortingOrder = icon.GetComponent <SpriteRenderer>().sortingOrder + sortingOrderAdd; transform.GetComponent <SpriteRenderer>().drawMode = icon.GetComponent <SpriteRenderer>().drawMode; transform.GetComponent <SpriteRenderer>().size = icon.GetComponent <SpriteRenderer>().size; transform.GetComponent <SpriteRenderer>().sharedMaterial = icon.GetComponent <SpriteRenderer>().sharedMaterial; Color b = Color.white; if (forGrid) { ColorModule component = icon.GetComponent <ColorModule>(); if (component != null) { b = component.buildColor; } } transform.GetComponent <SpriteRenderer>().color = icon.GetComponent <SpriteRenderer>().color *color *b; } for (int i = 0; i < icon.childCount; i++) { PartGrid.LoadIcon(iconPrefab, icon.GetChild(i), icon.GetChild(i).localPosition, icon.GetChild(i).localScale, transform, sortingOrderAdd, color, forGrid); } return(transform); }
protected override void _PreRender(CancellationTokenSource tokenSource = null) { _elementData = new EffectIntents(); IEnumerable <ElementNode> targetNodes = GetNodesToRenderOn(); List <IndividualTwinkleDetails> twinkles = null; if (!IndividualElements) { twinkles = GenerateTwinkleData(); } int totalNodes = targetNodes.Count(); double i = 0; foreach (ElementNode node in targetNodes) { if (tokenSource != null && tokenSource.IsCancellationRequested) { return; } if (node != null) { bool discreteColors = HasDiscreteColors && ColorModule.isElementNodeDiscreteColored(node); var intents = RenderElement(node, i++ / totalNodes, discreteColors, twinkles); _elementData.Add(IntentBuilder.ConvertToStaticArrayIntents(intents, TimeSpan, discreteColors)); } } }
private void RenderPulseSegment(TimeSpan startTime, TimeSpan duration, Curve c, ColorGradient cg, IElementNode elementNode) { ColorValue[] values; if (HasDiscreteColors && IsElementDiscrete(elementNode)) { IEnumerable <Color> colors = ColorModule.getValidColorsForElementNode(elementNode, false) .Intersect(cg.GetColorsInGradient()); foreach (Color color in colors) { if (!_colorValueSet.TryGetValue(color, out values)) { values = new ColorValue[(int)(TimeSpan.TotalMilliseconds / FrameTime)]; _colorValueSet.Add(color, values); } RenderPulseSegment(values, startTime, duration, c, cg, color); } } else { if (_colorValueSet.TryGetValue(Color.Empty, out values)) { RenderPulseSegment(values, startTime, duration, c, cg); } } }
// 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 RenderNode(ElementNode node) { //Collect all the points first. double[] allPointsTimeOrdered = _GetAllSignificantDataPoints().ToArray(); foreach (ElementNode elementNode in node.GetLeafEnumerator()) { // this is probably always going to be a single element for the given node, as // we have iterated down to leaf nodes in RenderNode() above. May as well do // it this way, though, in case something changes in future. if (elementNode == null || elementNode.Element == null) { continue; } ElementColorType colorType = ColorModule.getColorTypeForElementNode(elementNode); if (colorType == ElementColorType.FullColor) { addIntentsToElement(elementNode.Element, allPointsTimeOrdered); } else { IEnumerable <Color> colors = ColorModule.getValidColorsForElementNode(elementNode, false) .Intersect(ColorGradient.GetColorsInGradient()); foreach (Color color in colors) { addIntentsToElement(elementNode.Element, allPointsTimeOrdered, color); } } } }
// 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. public static EffectIntents RenderNode(ElementNode node, Curve levelCurve, ColorGradient colorGradient, TimeSpan duration, bool isDiscrete, bool allowZeroIntensity = false) { //Collect all the points first. double[] allPointsTimeOrdered = _GetAllSignificantDataPoints(levelCurve, colorGradient).ToArray(); var elementData = new EffectIntents(); foreach (ElementNode elementNode in node.GetLeafEnumerator()) { // this is probably always going to be a single element for the given node, as // we have iterated down to leaf nodes in RenderNode() above. May as well do // it this way, though, in case something changes in future. if (elementNode == null || elementNode.Element == null) { continue; } //ElementColorType colorType = ColorModule.getColorTypeForElementNode(elementNode); if (isDiscrete && IsElementDiscrete(node)) { IEnumerable <Color> colors = ColorModule.getValidColorsForElementNode(elementNode, false) .Intersect(colorGradient.GetColorsInGradient()); foreach (Color color in colors) { AddIntentsToElement(elementNode.Element, allPointsTimeOrdered, levelCurve, colorGradient, duration, elementData, allowZeroIntensity, color); } } else { AddIntentsToElement(elementNode.Element, allPointsTimeOrdered, levelCurve, colorGradient, duration, elementData, allowZeroIntensity); } } return(elementData); }
public static IEnumerator Fade(this SpriteRenderer renderer, Color start, Color end, float time) { UnityAction <Color> setRendererColor = color => { renderer.color = color; }; yield return(ColorModule.Fade(start, end, time, setRendererColor)); }
public static IEnumerator Fade(this Image image, Color start, Color end, float time) { UnityAction <Color> colorUpdate = color => { image.color = color; }; yield return(ColorModule.Fade(start, end, time, colorUpdate)); }
public static IEnumerator FadeMaterialColor(this LineRenderer line, Color start, Color end, float time) { UnityAction <Color> setRendererColor = color => { line.material.color = color; }; yield return(ColorModule.Fade(start, end, time, setRendererColor)); }
/// <summary> /// Gets the list of valid colors this effect can use and sets the hasDiscreteColors flag if any of it's targeted elements are discrete and have a restricted list. /// </summary> /// <returns></returns> protected HashSet <Color> GetValidColors() { HashSet <Color> validColors = new HashSet <Color>(); validColors.AddRange(TargetNodes.SelectMany(x => ColorModule.getValidColorsForElementNode(x, true))); if (validColors.Any()) { HasDiscreteColors = true; } return(validColors); }
private void CheckForInvalidColorData() { HashSet <Color> validColors = new HashSet <Color>(); validColors.AddRange(TargetNodes.SelectMany(x => ColorModule.getValidColorsForElementNode(x, true))); if (validColors.Any() && !_data.ColorGradient.GetColorsInGradient().IsSubsetOf(validColors)) { //Our color is not valid for any elements we have. //Try to set a default color gradient from our available colors _data.ColorGradient = new ColorGradient(validColors.First()); } }
//Validate that the we are using valid colors and set appropriate defaults if not. private void CheckForInvalidColorData() { HashSet <Color> validColors = new HashSet <Color>(); validColors.AddRange(TargetNodes.SelectMany(x => ColorModule.getValidColorsForElementNode(x, true))); if (validColors.Any() && !validColors.Contains(_data.color.ToArgb())) { //Our color is not valid for any elements we have. //Set a default color Color = validColors.First(); } }
private void EnsureFaceMapColors(IElementNode node) { foreach (var elementNode in node.GetNodeEnumerator()) { var fm = FaceModule.GetFaceModuleForElement(elementNode); if (fm != null) { var color = ColorModule.getValidColorsForElementNode(elementNode, true).FirstOrDefault(); fm.DefaultColor = color; } } }
//Validate that the we are using valid colors and set appropriate defaults if not. private void CheckForInvalidColorData() { HashSet <Color> validColors = new HashSet <Color>(); validColors.AddRange(TargetNodes.SelectMany(x => ColorModule.getValidColorsForElementNode(x, true))); if (validColors.Any() && (!validColors.Contains(_data.StaticColor) || !_data.ColorGradient.GetColorsInGradient().IsSubsetOf(validColors))) //Discrete colors specified { _data.ColorGradient = new ColorGradient(validColors.DefaultIfEmpty(Color.White).First()); _data.StaticColor = validColors.First(); } }
public static IEnumerator FadeGradient(this LineRenderer line, Color start, Color end, float time, GradientFadeType fadeType = GradientFadeType.StartAndEnd) { UnityAction <Color> setRendererGradient = color => { if (fadeType == GradientFadeType.StartOnly || fadeType == GradientFadeType.StartAndEnd) { line.startColor = color; } if (fadeType == GradientFadeType.EndOnly || fadeType == GradientFadeType.StartAndEnd) { line.endColor = color; } }; yield return(ColorModule.Fade(start, end, time, setRendererGradient)); }
// 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. protected override void RenderNode(ElementNode node) { if (!AudioUtilities.AudioLoaded) { return; } foreach (ElementNode elementNode in node.GetLeafEnumerator()) { // this is probably always going to be a single element for the given node, as // we have iterated down to leaf nodes in RenderNode() above. May as well do // it this way, though, in case something changes in future. if (elementNode == null || elementNode.Element == null) { continue; } bool discreteColors = ColorModule.isElementNodeDiscreteColored(elementNode); for (int i = 0; i < (int)((TimeSpan.TotalMilliseconds / Spacing) - 1); i++) { double gradientPosition1 = (AudioUtilities.VolumeAtTime(i * Spacing) + Data.Range) / Data.Range; double gradientPosition2 = (AudioUtilities.VolumeAtTime((i + 1) * Spacing) + Data.Range) / Data.Range; if (gradientPosition1 <= 0) { gradientPosition1 = 0; } if (gradientPosition1 >= 1) { gradientPosition1 = 1; } //Some odd corner cases if (gradientPosition2 <= 0) { gradientPosition2 = 0; } if (gradientPosition2 >= 1) { gradientPosition2 = 1; } TimeSpan startTime = TimeSpan.FromMilliseconds(i * Spacing); ElementData.Add(GenerateEffectIntents(elementNode, WorkingGradient, MeterIntensityCurve, gradientPosition1, gradientPosition2, TimeSpan.FromMilliseconds(Spacing), startTime, discreteColors)); } } }
protected override YAMLMappingNode ExportYAMLRoot(IAssetsExporter exporter) { #warning TODO: values acording to read version (current 2017.3.0f3) YAMLMappingNode node = base.ExportYAMLRoot(exporter); node.AddSerializedVersion(GetSerializedVersion(exporter.Version)); node.Add("lengthInSec", LengthInSec); node.Add("simulationSpeed", SimulationSpeed); node.Add("stopAction", StopAction); node.Add("looping", Looping); node.Add("prewarm", Prewarm); node.Add("playOnAwake", PlayOnAwake); node.Add("useUnscaledTime", UseUnscaledTime); node.Add("autoRandomSeed", AutoRandomSeed); node.Add("useRigidbodyForVelocity", UseRigidbodyForVelocity); node.Add("startDelay", StartDelay.ExportYAML(exporter)); node.Add("moveWithTransform", MoveWithTransform); node.Add("moveWithCustomTransform", MoveWithCustomTransform.ExportYAML(exporter)); node.Add("scalingMode", ScalingMode); node.Add("randomSeed", RandomSeed); node.Add("InitialModule", InitialModule.ExportYAML(exporter)); node.Add("ShapeModule", ShapeModule.ExportYAML(exporter)); node.Add("EmissionModule", EmissionModule.ExportYAML(exporter)); node.Add("SizeModule", SizeModule.ExportYAML(exporter)); node.Add("RotationModule", RotationModule.ExportYAML(exporter)); node.Add("ColorModule", ColorModule.ExportYAML(exporter)); node.Add("UVModule", UVModule.ExportYAML(exporter)); node.Add("VelocityModule", VelocityModule.ExportYAML(exporter)); node.Add("InheritVelocityModule", InheritVelocityModule.ExportYAML(exporter)); node.Add("ForceModule", ForceModule.ExportYAML(exporter)); node.Add("ExternalForcesModule", ExternalForcesModule.ExportYAML(exporter)); node.Add("ClampVelocityModule", ClampVelocityModule.ExportYAML(exporter)); node.Add("NoiseModule", NoiseModule.ExportYAML(exporter)); node.Add("SizeBySpeedModule", SizeBySpeedModule.ExportYAML(exporter)); node.Add("RotationBySpeedModule", RotationBySpeedModule.ExportYAML(exporter)); node.Add("ColorBySpeedModule", ColorBySpeedModule.ExportYAML(exporter)); node.Add("CollisionModule", CollisionModule.ExportYAML(exporter)); node.Add("TriggerModule", TriggerModule.ExportYAML(exporter)); node.Add("SubModule", SubModule.ExportYAML(exporter)); node.Add("LightsModule", LightsModule.ExportYAML(exporter)); node.Add("TrailModule", TrailModule.ExportYAML(exporter)); node.Add("CustomDataModule", CustomDataModule.ExportYAML(exporter)); return(node); }
protected override YAMLMappingNode ExportYAMLRoot(IExportContainer container) { YAMLMappingNode node = base.ExportYAMLRoot(container); node.AddSerializedVersion(ToSerializedVersion(container.ExportVersion)); node.Add(LengthInSecName, LengthInSec); node.Add(SimulationSpeedName, SimulationSpeed); node.Add(StopActionName, (int)StopAction); node.Add(LoopingName, Looping); node.Add(PrewarmName, Prewarm); node.Add(PlayOnAwakeName, PlayOnAwake); node.Add(UseUnscaledTimeName, UseUnscaledTime); node.Add(AutoRandomSeedName, GetAutoRandomSeed(container.Version)); node.Add(UseRigidbodyForVelocityName, GetUseRigidbodyForVelocity(container.Version)); node.Add(StartDelayName, GetStartDelay(container.Version).ExportYAML(container)); node.Add(MoveWithTransformName, (int)MoveWithTransform); node.Add(MoveWithCustomTransformName, MoveWithCustomTransform.ExportYAML(container)); node.Add(ScalingModeName, (int)GetScalingMode(container.Version)); node.Add(RandomSeedName, RandomSeed); node.Add(InitialModuleName, InitialModule.ExportYAML(container)); node.Add(ShapeModuleName, ShapeModule.ExportYAML(container)); node.Add(EmissionModuleName, EmissionModule.ExportYAML(container)); node.Add(SizeModuleName, SizeModule.ExportYAML(container)); node.Add(RotationModuleName, RotationModule.ExportYAML(container)); node.Add(ColorModuleName, ColorModule.ExportYAML(container)); node.Add(UVModuleName, UVModule.ExportYAML(container)); node.Add(VelocityModuleName, VelocityModule.ExportYAML(container)); node.Add(InheritVelocityModuleName, GetInheritVelocityModule(container.Version).ExportYAML(container)); node.Add(ForceModuleName, ForceModule.ExportYAML(container)); node.Add(ExternalForcesModuleName, GetExternalForcesModule(container.Version).ExportYAML(container)); node.Add(ClampVelocityModuleName, ClampVelocityModule.ExportYAML(container)); node.Add(NoiseModuleName, GetNoiseModule(container.Version).ExportYAML(container)); node.Add(SizeBySpeedModuleName, SizeBySpeedModule.ExportYAML(container)); node.Add(RotationBySpeedModuleName, RotationBySpeedModule.ExportYAML(container)); node.Add(ColorBySpeedModuleName, ColorBySpeedModule.ExportYAML(container)); node.Add(CollisionModuleName, CollisionModule.ExportYAML(container)); node.Add(TriggerModuleName, GetTriggerModule(container.Version).ExportYAML(container)); node.Add(SubModuleName, SubModule.ExportYAML(container)); node.Add(LightsModuleName, GetLightsModule(container.Version).ExportYAML(container)); node.Add(TrailModuleName, GetTrailModule(container.Version).ExportYAML(container)); node.Add(CustomDataModuleName, GetCustomDataModule(container.Version).ExportYAML(container)); return(node); }
protected override YAMLMappingNode ExportYAMLRoot(IExportContainer container) { YAMLMappingNode node = base.ExportYAMLRoot(container); node.AddSerializedVersion(GetSerializedVersion(container.Version)); node.Add("lengthInSec", LengthInSec); node.Add("simulationSpeed", SimulationSpeed); node.Add("stopAction", StopAction); node.Add("looping", Looping); node.Add("prewarm", Prewarm); node.Add("playOnAwake", PlayOnAwake); node.Add("useUnscaledTime", UseUnscaledTime); node.Add("autoRandomSeed", GetAutoRandomSeed(container.Version)); node.Add("useRigidbodyForVelocity", GetUseRigidbodyForVelocity(container.Version)); node.Add("startDelay", GetStartDelay(container.Version).ExportYAML(container)); node.Add("moveWithTransform", (int)MoveWithTransform); node.Add("moveWithCustomTransform", MoveWithCustomTransform.ExportYAML(container)); node.Add("scalingMode", (int)GetScalingMode(container.Version)); node.Add("randomSeed", RandomSeed); node.Add("InitialModule", InitialModule.ExportYAML(container)); node.Add("ShapeModule", ShapeModule.ExportYAML(container)); node.Add("EmissionModule", EmissionModule.ExportYAML(container)); node.Add("SizeModule", SizeModule.ExportYAML(container)); node.Add("RotationModule", RotationModule.ExportYAML(container)); node.Add("ColorModule", ColorModule.ExportYAML(container)); node.Add("UVModule", UVModule.ExportYAML(container)); node.Add("VelocityModule", VelocityModule.ExportYAML(container)); node.Add("InheritVelocityModule", GetInheritVelocityModule(container.Version).ExportYAML(container)); node.Add("ForceModule", ForceModule.ExportYAML(container)); node.Add("ExternalForcesModule", GetExternalForcesModule(container.Version).ExportYAML(container)); node.Add("ClampVelocityModule", ClampVelocityModule.ExportYAML(container)); node.Add("NoiseModule", GetNoiseModule(container.Version).ExportYAML(container)); node.Add("SizeBySpeedModule", SizeBySpeedModule.ExportYAML(container)); node.Add("RotationBySpeedModule", RotationBySpeedModule.ExportYAML(container)); node.Add("ColorBySpeedModule", ColorBySpeedModule.ExportYAML(container)); node.Add("CollisionModule", CollisionModule.ExportYAML(container)); node.Add("TriggerModule", GetTriggerModule(container.Version).ExportYAML(container)); node.Add("SubModule", SubModule.ExportYAML(container)); node.Add("LightsModule", GetLightsModule(container.Version).ExportYAML(container)); node.Add("TrailModule", GetTrailModule(container.Version).ExportYAML(container)); node.Add("CustomDataModule", GetCustomDataModule(container.Version).ExportYAML(container)); return(node); }
protected EffectIntents CreateIntentsForElement(ElementNode element, double intensity, Color color, TimeSpan duration) { EffectIntents effectIntents = new EffectIntents(); foreach (ElementNode elementNode in element.GetLeafEnumerator()) { if (HasDiscreteColors && IsElementDiscrete(elementNode)) { IEnumerable <Color> colors = ColorModule.getValidColorsForElementNode(elementNode, false); if (!colors.Contains(color)) { continue; } } IIntent intent = CreateIntent(elementNode, color, intensity, duration); effectIntents.AddIntentForElement(elementNode.Element.Id, intent, TimeSpan.Zero); } return(effectIntents); }
private void AddNodes(List <Element> elements, ElementNode elementNode) { var element = new Element { Id = elementNode.Id, Name = elementNode.Name }; element.Colors = ColorModule.getValidColorsForElementNode(elementNode, true).Select(ColorTranslator.ToHtml).ToList(); elements.Add(element); if (!elementNode.IsLeaf) { var children = new List <Element>(); element.Children = children; foreach (var childNode in elementNode.Children) { AddNodes(children, childNode); } } }
// 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 EffectIntents RenderNode(ElementNode node) { EffectIntents effectIntents = new EffectIntents(); foreach (ElementNode elementNode in node.GetLeafEnumerator()) { if (HasDiscreteColors && IsElementDiscrete(elementNode)) { IEnumerable <Color> colors = ColorModule.getValidColorsForElementNode(elementNode, false); if (!colors.Contains(Color)) { continue; } } IIntent intent = CreateIntent(elementNode, Color, IntensityLevel, TimeSpan); effectIntents.AddIntentForElement(elementNode.Element.Id, intent, TimeSpan.Zero); } return(effectIntents); }
protected HashSet <Color> GetDiscreteColors(Object component) { HashSet <Color> validColors = new HashSet <Color>(); if (component is IEffect) { IEffect effect = (IEffect)component; validColors.AddRange(effect.TargetNodes.SelectMany(x => ColorModule.getValidColorsForElementNode(x, true))); } else if (component is Array) { foreach (var item in (Array)component) { if (item is IEffect) { IEffect effect = (IEffect)item; validColors.AddRange(effect.TargetNodes.SelectMany(x => ColorModule.getValidColorsForElementNode(x, true))); } } } return(validColors); }
//Validate that the we are using valid colors and set appropriate defaults if not. //we only need to check against 1 color variable, //it should be checked at a later time than what this is doing currently private void CheckForInvalidColorData() { // check for sane default colors when first rendering it var validColors = new HashSet <Color>(); validColors.AddRange(TargetNodes.SelectMany(x => ColorModule.getValidColorsForElementNode(x, true))); if (validColors.Any()) { bool changed = false; foreach (GradientLevelPair t in Colors) { if (!t.ColorGradient.GetColorsInGradient().IsSubsetOf(validColors)) { t.ColorGradient = new ColorGradient(validColors.First()); changed = true; } } if (changed) { OnPropertyChanged("Colors"); } } }
private static bool IsElementDiscrete(ElementNode elementNode) { return(ColorModule.isElementNodeTreeDiscreteColored(elementNode)); }
public override void Read(AssetReader reader) { base.Read(reader); LengthInSec = reader.ReadSingle(); if (IsStartDelayFirst(reader.Version)) { if (HasStartDelaySingle(reader.Version)) { StartDelaySingle = reader.ReadSingle(); } else { StartDelay.Read(reader); } } SimulationSpeed = reader.ReadSingle(); if (HasStopAction(reader.Version)) { StopAction = (ParticleSystemStopAction)reader.ReadInt32(); } if (IsRandomSeedFirst(reader.Version)) { RandomSeed = unchecked ((int)reader.ReadUInt32()); } if (HasCullingMode(reader.Version)) { CullingMode = (ParticleSystemCullingMode)reader.ReadInt32(); RingBufferMode = (ParticleSystemRingBufferMode)reader.ReadInt32(); RingBufferLoopRange.Read(reader); } Looping = reader.ReadBoolean(); Prewarm = reader.ReadBoolean(); PlayOnAwake = reader.ReadBoolean(); if (HasUseUnscaledTime(reader.Version)) { UseUnscaledTime = reader.ReadBoolean(); } if (IsMoveWithTransformBool(reader.Version)) { MoveWithTransform = reader.ReadBoolean() ? ParticleSystemSimulationSpace.Local : ParticleSystemSimulationSpace.World; } if (HasAutoRandomSeed(reader.Version)) { AutoRandomSeed = reader.ReadBoolean(); } if (HasUseRigidbodyForVelocity(reader.Version)) { UseRigidbodyForVelocity = reader.ReadBoolean(); } if (IsAlign(reader.Version)) { reader.AlignStream(); } if (!IsStartDelayFirst(reader.Version)) { StartDelay.Read(reader); reader.AlignStream(); } if (!IsMoveWithTransformBool(reader.Version)) { MoveWithTransform = (ParticleSystemSimulationSpace)reader.ReadInt32(); reader.AlignStream(); } if (HasMoveWithCustomTransform(reader.Version)) { MoveWithCustomTransform.Read(reader); } if (HasScalingMode(reader.Version)) { ScalingMode = (ParticleSystemScalingMode)reader.ReadInt32(); } if (!IsRandomSeedFirst(reader.Version)) { RandomSeed = reader.ReadInt32(); } InitialModule.Read(reader); ShapeModule.Read(reader); EmissionModule.Read(reader); SizeModule.Read(reader); RotationModule.Read(reader); ColorModule.Read(reader); UVModule.Read(reader); VelocityModule.Read(reader); if (HasInheritVelocityModule(reader.Version)) { InheritVelocityModule.Read(reader); } ForceModule.Read(reader); if (HasExternalForcesModule(reader.Version)) { ExternalForcesModule.Read(reader); } ClampVelocityModule.Read(reader); if (HasNoiseModule(reader.Version)) { NoiseModule.Read(reader); } SizeBySpeedModule.Read(reader); RotationBySpeedModule.Read(reader); ColorBySpeedModule.Read(reader); CollisionModule.Read(reader); if (HasTriggerModule(reader.Version)) { TriggerModule.Read(reader); } SubModule.Read(reader); if (HasLightsModule(reader.Version)) { LightsModule.Read(reader); TrailModule.Read(reader); } if (HasCustomDataModule(reader.Version)) { CustomDataModule.Read(reader); } }
protected bool IsElementDiscrete(ElementNode elementNode) { return(ColorModule.isElementNodeDiscreteColored(elementNode)); }
private void DoRendering(CancellationTokenSource tokenSource = null) { List <ElementNode> renderNodes = GetNodesToRenderOn(); int targetNodeCount = renderNodes.Count; //If there are no nodes to render on Exit! if (targetNodeCount == 0) { return; } ElementNode lastTargetedNode = null; //Pulse.Pulse pulse; EffectIntents pulseData; // apply the 'background' values to all targets if nonzero if (EnableDefaultLevel) { int i = 0; foreach (ElementNode target in renderNodes) { if (tokenSource != null && tokenSource.IsCancellationRequested) { return; } bool discreteColors = ColorModule.isElementNodeDiscreteColored(target); if (target == null) { continue; } if (target != null) { double level = DefaultLevel * 100.0; // figure out what color gradient to use for the pulse switch (ColorHandling) { case SpinColorHandling.GradientForEachPulse: pulseData = PulseRenderer.RenderNode(target, new Curve(new PointPairList(new double[] { 0, 100 }, new [] { level, level })), StaticColorGradient, TimeSpan, HasDiscreteColors, true); _elementData.Add(pulseData); break; case SpinColorHandling.GradientThroughWholeEffect: pulseData = PulseRenderer.RenderNode(target, new Curve(new PointPairList(new double[] { 0, 100 }, new [] { level, level })), ColorGradient, TimeSpan, HasDiscreteColors, true); _elementData.Add(pulseData); break; case SpinColorHandling.StaticColor: pulseData = PulseRenderer.RenderNode(target, new Curve(new PointPairList(new double[] { 0, 100 }, new[] { level, level })), StaticColorGradient, TimeSpan, HasDiscreteColors, true); _elementData.Add(pulseData); break; case SpinColorHandling.ColorAcrossItems: double positionWithinGroup = i / (double)targetNodeCount; if (discreteColors) { List <Tuple <Color, float> > colorsAtPosition = ColorGradient.GetDiscreteColorsAndProportionsAt(positionWithinGroup); foreach (Tuple <Color, float> colorProportion in colorsAtPosition) { double value = level * colorProportion.Item2; pulseData = PulseRenderer.RenderNode(target, new Curve(new PointPairList(new double[] { 0, 100 }, new [] { value, value })), new ColorGradient(colorProportion.Item1), TimeSpan, HasDiscreteColors, true); _elementData.Add(pulseData); } } else { pulseData = PulseRenderer.RenderNode(target, new Curve(new PointPairList(new double[] { 0, 100 }, new double[] { level, level })), new ColorGradient(ColorGradient.GetColorAt(positionWithinGroup)), TimeSpan, HasDiscreteColors, true); _elementData.Add(pulseData); } break; } i++; } } } // calculate the pulse time and revolution time exactly (based on the parameters from the data) double revTimeMs = 0; // single revolution time (ms) // figure out the relative length of a individual pulse double pulseConstant = 0; // how much of each pulse is a constant time double pulseFractional = 0; // how much of each pulse is a fraction of a single spin if (PulseLengthFormat == SpinPulseLengthFormat.FixedTime) { pulseConstant = PulseTime; } else if (PulseLengthFormat == SpinPulseLengthFormat.PercentageOfRevolution) { pulseFractional = PulsePercentage / 100.0; } else if (PulseLengthFormat == SpinPulseLengthFormat.EvenlyDistributedAcrossSegments) { pulseFractional = 1.0 / (double)targetNodeCount; } // magic number. (the inaccuracy of interpolating the curve into a position. eg. if we have 5 'positions', then // the curve should really be from 0-80% for the last spin, to make sure the last pulse finishes accurately.) double pulseInterpolationOffset = 1.0 / (double)targetNodeCount; // figure out either the revolution count or time, based on what data we have if (SpeedFormat == SpinSpeedFormat.RevolutionCount) { revTimeMs = (TimeSpan.TotalMilliseconds - pulseConstant) / (RevolutionCount + pulseFractional - pulseInterpolationOffset); } else if (SpeedFormat == SpinSpeedFormat.RevolutionFrequency) { revTimeMs = (1.0 / RevolutionFrequency) * 1000.0; // convert Hz to period ms } else if (SpeedFormat == SpinSpeedFormat.FixedTime) { revTimeMs = RevolutionTime; } double pulTimeMs = pulseConstant + (revTimeMs * pulseFractional); TimeSpan revTimeSpan = TimeSpan.FromMilliseconds(revTimeMs); TimeSpan pulseTimeSpan = TimeSpan.FromMilliseconds(pulTimeMs); // figure out which way we're moving through the elements Curve movement; if (ReverseSpin) { movement = new Curve(new PointPairList(new double[] { 0, 100 }, new double[] { 100, 0 })); } else { movement = new Curve(new PointPairList(new double[] { 0, 100 }, new double[] { 0, 100 })); } //TODO: get a better increment time. doing it every X ms is..... shitty at best. //Less crappy is try to make some adjustment if there are a lot of nodes in a shorter time to sample more often. //A hard and fast 2ms was leaving gaps in larger node counts var sampleMs = revTimeSpan.TotalMilliseconds / targetNodeCount / 2.0; if (sampleMs < .25) { sampleMs = .25; } else if (sampleMs > 2) { sampleMs = 2; } TimeSpan increment = TimeSpan.FromTicks((long)(sampleMs * TimeSpan.TicksPerMillisecond)); // iterate up to and including the last pulse generated // a bit iffy, but stops 'carry over' spins past the end (when there's overlapping spins). But we need to go past // (total - pulse) as the last pulse can often be a bit inaccurate due to the rounding of the increment for (TimeSpan current = TimeSpan.Zero; current <= TimeSpan - pulseTimeSpan + increment; current += increment) { if (tokenSource != null && tokenSource.IsCancellationRequested) { return; } double currentPercentageIntoSpin = ((double)(current.Ticks % revTimeSpan.Ticks) / (double)revTimeSpan.Ticks) * 100.0; double targetElementPosition = movement.GetValue(currentPercentageIntoSpin); int currentNodeIndex = (int)((targetElementPosition / 100.0) * targetNodeCount); // on the off chance we hit the 100% mark *exactly*... if (currentNodeIndex == targetNodeCount) { currentNodeIndex--; } if (currentNodeIndex >= targetNodeCount) { Logging.Warn( "Spin effect: rendering, but the current node index is higher or equal to the total target nodes."); continue; } ElementNode currentNode = renderNodes[currentNodeIndex]; if (currentNode == lastTargetedNode) { continue; } bool discreteColors = ColorModule.isElementNodeDiscreteColored(currentNode); // figure out what color gradient to use for the pulse switch (ColorHandling) { case SpinColorHandling.GradientForEachPulse: pulseData = PulseRenderer.RenderNode(currentNode, new Curve(PulseCurve), ColorGradient, pulseTimeSpan, HasDiscreteColors); pulseData.OffsetAllCommandsByTime(current); _elementData.Add(pulseData); break; case SpinColorHandling.GradientThroughWholeEffect: double startPos = ((double)current.Ticks / (double)TimeSpan.Ticks); double endPos = 1.0; if (TimeSpan - current >= pulseTimeSpan) { endPos = ((double)(current + pulseTimeSpan).Ticks / (double)TimeSpan.Ticks); } if (discreteColors) { double range = endPos - startPos; if (range <= 0.0) { Logging.Error("Spin: bad range: " + range + " (SP=" + startPos + ", EP=" + endPos + ")"); break; } ColorGradient cg = ColorGradient.GetSubGradientWithDiscreteColors(startPos, endPos); foreach (Color color in cg.GetColorsInGradient()) { if (tokenSource != null && tokenSource.IsCancellationRequested) { return; } Curve newCurve = new Curve(PulseCurve.Points); foreach (PointPair point in newCurve.Points) { double effectRelativePosition = startPos + ((point.X / 100.0) * range); double proportion = ColorGradient.GetProportionOfColorAt(effectRelativePosition, color); point.Y *= proportion; } pulseData = PulseRenderer.RenderNode(currentNode, newCurve, new ColorGradient(color), pulseTimeSpan, HasDiscreteColors); pulseData.OffsetAllCommandsByTime(current); _elementData.Add(pulseData); } } else { pulseData = PulseRenderer.RenderNode(currentNode, new Curve(PulseCurve), ColorGradient.GetSubGradient(startPos, endPos), pulseTimeSpan, HasDiscreteColors); pulseData.OffsetAllCommandsByTime(current); _elementData.Add(pulseData); } break; case SpinColorHandling.StaticColor: pulseData = PulseRenderer.RenderNode(currentNode, new Curve(PulseCurve), StaticColorGradient, pulseTimeSpan, HasDiscreteColors); pulseData.OffsetAllCommandsByTime(current); _elementData.Add(pulseData); break; case SpinColorHandling.ColorAcrossItems: if (discreteColors) { List <Tuple <Color, float> > colorsAtPosition = ColorGradient.GetDiscreteColorsAndProportionsAt(targetElementPosition / 100.0); foreach (Tuple <Color, float> colorProportion in colorsAtPosition) { if (tokenSource != null && tokenSource.IsCancellationRequested) { return; } float proportion = colorProportion.Item2; // scale all levels of the pulse curve by the proportion that is applicable to this color Curve newCurve = new Curve(PulseCurve.Points); foreach (PointPair pointPair in newCurve.Points) { pointPair.Y *= proportion; } pulseData = PulseRenderer.RenderNode(currentNode, newCurve, new ColorGradient(colorProportion.Item1), pulseTimeSpan, HasDiscreteColors); pulseData.OffsetAllCommandsByTime(current); _elementData.Add(pulseData); } } else { pulseData = PulseRenderer.RenderNode(currentNode, new Curve(PulseCurve), new ColorGradient(ColorGradient.GetColorAt(targetElementPosition / 100.0)), pulseTimeSpan, HasDiscreteColors); pulseData.OffsetAllCommandsByTime(current); _elementData.Add(pulseData); } break; } lastTargetedNode = currentNode; } _elementData = EffectIntents.Restrict(_elementData, TimeSpan.Zero, TimeSpan); }
private void GeneratePulse(ElementNode target, TimeSpan startTime, TimeSpan duration, double currentMovementPosition) { EffectIntents result = null; Pulse.Pulse pulse = new Pulse.Pulse(); pulse.TargetNodes = new[] { target }; pulse.TimeSpan = duration; pulse.LevelCurve = new Curve(PulseCurve); bool discreteColors = ColorModule.isElementNodeDiscreteColored(target); IIntentNode intent; // figure out what color gradient to use for the pulse switch (ColorHandling) { case ChaseColorHandling.GradientForEachPulse: pulse.ColorGradient = ColorGradient; result = pulse.Render(); result.OffsetAllCommandsByTime(startTime); if (ExtendPulseToStart && result.Count > 0) { foreach (var iintentNode in result.FirstOrDefault().Value) { GenerateStartingStaticPulse(target, iintentNode); } } _elementData.Add(result); if (ExtendPulseToEnd && result.Count > 0) { foreach (var iintentNode in result.FirstOrDefault().Value) { GenerateExtendedStaticPulse(target, iintentNode); } } break; case ChaseColorHandling.GradientThroughWholeEffect: double startPos = (startTime.Ticks / (double)TimeSpan.Ticks); double endPos = ((startTime + duration).Ticks / (double)TimeSpan.Ticks); if (startPos < 0.0) { startPos = 0.0; } if (endPos > 1.0) { endPos = 1.0; } if (discreteColors) { double range = endPos - startPos; if (range <= 0.0) { Logging.Error("Chase: bad range: " + range + " (SP=" + startPos + ", EP=" + endPos + ")"); break; } ColorGradient cg = ColorGradient.GetSubGradientWithDiscreteColors(startPos, endPos); foreach (Color color in cg.GetColorsInGradient()) { Curve newCurve = new Curve(PulseCurve.Points); foreach (PointPair point in newCurve.Points) { double effectRelativePosition = startPos + ((point.X / 100.0) * range); double proportion = ColorGradient.GetProportionOfColorAt(effectRelativePosition, color); point.Y *= proportion; } pulse.LevelCurve = newCurve; pulse.ColorGradient = new ColorGradient(color); result = pulse.Render(); result.OffsetAllCommandsByTime(startTime); if (ExtendPulseToStart && result.Count > 0) { intent = result.FirstOrDefault().Value.FirstOrDefault(); GenerateStartingStaticPulse(target, intent); } _elementData.Add(result); if (ExtendPulseToEnd && result.Count > 0) { intent = result.FirstOrDefault().Value.LastOrDefault(); GenerateExtendedStaticPulse(target, intent); } } } else { pulse.ColorGradient = ColorGradient.GetSubGradient(startPos, endPos); result = pulse.Render(); result.OffsetAllCommandsByTime(startTime); if (ExtendPulseToStart && result.Count > 0) { intent = result.FirstOrDefault().Value.FirstOrDefault(); GenerateStartingStaticPulse(target, intent, ColorGradient.GetSubGradient(0, startPos)); } _elementData.Add(result); if (ExtendPulseToEnd && result.Count > 0) { intent = result.FirstOrDefault().Value.LastOrDefault(); GenerateExtendedStaticPulse(target, intent, ColorGradient.GetSubGradient(endPos, 1)); } } break; case ChaseColorHandling.StaticColor: pulse.ColorGradient = StaticColorGradient; result = pulse.Render(); result.OffsetAllCommandsByTime(startTime); if (ExtendPulseToStart && result.Count > 0) { intent = result.FirstOrDefault().Value.FirstOrDefault(); GenerateStartingStaticPulse(target, intent); } _elementData.Add(result); if (ExtendPulseToEnd && result.Count > 0) { intent = result.FirstOrDefault().Value.LastOrDefault(); GenerateExtendedStaticPulse(target, intent); } break; case ChaseColorHandling.ColorAcrossItems: if (discreteColors) { List <Tuple <Color, float> > colorsAtPosition = ColorGradient.GetDiscreteColorsAndProportionsAt(currentMovementPosition / 100.0); foreach (Tuple <Color, float> colorProportion in colorsAtPosition) { float proportion = colorProportion.Item2; // scale all levels of the pulse curve by the proportion that is applicable to this color Curve newCurve = new Curve(PulseCurve.Points); foreach (PointPair pointPair in newCurve.Points) { pointPair.Y *= proportion; } pulse.LevelCurve = newCurve; pulse.ColorGradient = new ColorGradient(colorProportion.Item1); result = pulse.Render(); result.OffsetAllCommandsByTime(startTime); if (ExtendPulseToStart && result.Count > 0) { intent = result.FirstOrDefault().Value.FirstOrDefault(); GenerateStartingStaticPulse(target, intent); } _elementData.Add(result); if (ExtendPulseToEnd && result.Count > 0) { intent = result.FirstOrDefault().Value.LastOrDefault(); GenerateExtendedStaticPulse(target, intent); } } } else { pulse.ColorGradient = new ColorGradient(ColorGradient.GetColorAt(currentMovementPosition / 100.0)); result = pulse.Render(); result.OffsetAllCommandsByTime(startTime); if (ExtendPulseToStart && result.Count > 0) { intent = result.FirstOrDefault().Value.FirstOrDefault(); GenerateStartingStaticPulse(target, intent); } _elementData.Add(result); if (ExtendPulseToEnd && result.Count > 0) { intent = result.FirstOrDefault().Value.LastOrDefault(); GenerateExtendedStaticPulse(target, intent); } } break; } }