Ejemplo n.º 1
0
 public virtual void DumpBody(XmlWriter writer, bool alpha)
 {
     writer.WriteAttributeString("spread-mode", SpreadMode.ToString());
     writer.WriteAttributeString("interpolation-mode", InterpolationMode.ToString());
     writer.WriteElementString("ratios", Ratios.Join());
     writer.WriteElementString("colors", Colors.ToHtmlHex(alpha));
 }
Ejemplo n.º 2
0
 public void Spread(SpreadMode mode)
 {
     if (_spreaders.TryGetValue(mode, out var spreader))
     {
         spreader.Spread(Vertices, new Size(250, 250));
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// <para>Swf 8 and later supports up to 15 gradient control points, spread modes and a new</para>
 /// <para>interpolation type.</para>
 /// </summary>
 /// <param name="InitialVersion">The version of the Swf file using this object.</param>
 public Gradient( byte InitialVersion )
     : base(InitialVersion)
 {
     this._spreadMode = SpreadMode.PadMode;
     this._interpolationMode = InterPolation.Linear;
     this._numGradients = 0;
     this._gradientRecords = new List<GradRecord>();
 }
        public void SaveCubemap()
        {
            var prevMode  = spreadMode;
            var wasActive = RenderTexture.active;

            if (filePath == "")
            {
                filePath = Application.dataPath + "/";
            }

            // Force full refresh of cubemap
            spreadMode         = SpreadMode._1Frame;
            m_CurrentFace      = -1;
            m_FlippedRendering = true;
            RenderUpdate();
            m_FlippedRendering = false;

            // Create the output texture
            Texture2D tex = new Texture2D(m_CubeMap.width * 6, m_CubeMap.height, UnityEngine.TextureFormat.RGBAHalf, false, false);

            // Copy each cubemap face
            Graphics.SetRenderTarget(m_CubeMap, 0, CubemapFace.PositiveX);
            tex.ReadPixels(new Rect(0, 0, m_CubeMap.width, m_CubeMap.height), m_CubeMap.width * 0, 0);
            Graphics.SetRenderTarget(m_CubeMap, 0, CubemapFace.NegativeX);
            tex.ReadPixels(new Rect(0, 0, m_CubeMap.width, m_CubeMap.height), m_CubeMap.width * 1, 0);
            Graphics.SetRenderTarget(m_CubeMap, 0, CubemapFace.PositiveY);
            tex.ReadPixels(new Rect(0, 0, m_CubeMap.width, m_CubeMap.height), m_CubeMap.width * 2, 0);
            Graphics.SetRenderTarget(m_CubeMap, 0, CubemapFace.NegativeY);
            tex.ReadPixels(new Rect(0, 0, m_CubeMap.width, m_CubeMap.height), m_CubeMap.width * 3, 0);
            Graphics.SetRenderTarget(m_CubeMap, 0, CubemapFace.PositiveZ);
            tex.ReadPixels(new Rect(0, 0, m_CubeMap.width, m_CubeMap.height), m_CubeMap.width * 4, 0);
            Graphics.SetRenderTarget(m_CubeMap, 0, CubemapFace.NegativeZ);
            tex.ReadPixels(new Rect(0, 0, m_CubeMap.width, m_CubeMap.height), m_CubeMap.width * 5, 0);

            // Encode and output to file
            byte[] bytes;
            bytes = tex.EncodeToEXR();
            System.IO.File.WriteAllBytes(filePath + "OverCloudReflectionProbe.exr", bytes);

            // Clean up
            if (Application.isPlaying)
            {
                Destroy(tex);
            }
            else
            {
                DestroyImmediate(tex);
            }

            Debug.Log("Cubemap saved to " + filePath);

            // Need to render again after resetting so the probe doesn't show the potentially post-processed result
            RenderProbe();

            RenderTexture.active = wasActive;
            spreadMode           = prevMode;
        }
Ejemplo n.º 5
0
        public Gradient(SwfReader r, FillType fillType, bool useAlpha)
        {
            Records       = new List <GradientRecord>();
            this.fillType = fillType;

            GradientMatrix    = new Matrix(r);
            SpreadMode        = (SpreadMode)r.GetBits(2);
            InterpolationMode = (InterpolationMode)(r.GetBits(2) & 1);
            uint numGradients = r.GetBits(4);

            for (int i = 0; i < numGradients; i++)
            {
                Records.Add(new GradientRecord(r, useAlpha));
            }
        }
Ejemplo n.º 6
0
 private static void AddSpreadMode(XElement xml, SpreadMode mode)
 {
     xml.Add(new XAttribute("spreadMode", mode.ToString()));
 }
Ejemplo n.º 7
0
        private void Update(EvaluationContext context)
        {
            if (!(SourcePoints.GetValue(context) is StructuredList <Point> sourcePoints))
            {
                return;
            }

            if (sourcePoints.NumElements == 0)
            {
                sourcePoints.SetLength(0);
                ResultList.Value = sourcePoints;
                return;
            }

            var spread     = Spread.GetValue(context);
            var spreadMode = (SpreadModes)SpreadMode.GetValue(context);

            var indexWithinSegment = 0;
            var lineSegmentLength  = 0f;
            var totalLength        = 0f;
            var maxLength          = float.NegativeInfinity;

            var randomizeStart    = RandomizeStart.GetValue(context);
            var randomizeDuration = RandomizeDuration.GetValue(context);

            // Measure...
            segments.Clear();
            for (var pointIndex = 0; pointIndex < sourcePoints.NumElements; pointIndex++)
            {
                if (float.IsNaN(sourcePoints.TypedElements[pointIndex].W))
                {
                    var hasAtLeastTwoPoints = indexWithinSegment > 1;
                    if (hasAtLeastTwoPoints)
                    {
                        if (lineSegmentLength > maxLength)
                        {
                            maxLength = lineSegmentLength;
                        }

                        totalLength += lineSegmentLength;
                        segments.Add(new Segment
                        {
                            PointIndex        = pointIndex - indexWithinSegment,
                            PointCount        = indexWithinSegment,
                            AccumulatedLength = totalLength,
                            SegmentLength     = lineSegmentLength
                        });
                    }

                    lineSegmentLength  = 0;
                    indexWithinSegment = 0;
                }
                else
                {
                    if (indexWithinSegment > 0)
                    {
                        lineSegmentLength += Vector3.Distance(sourcePoints.TypedElements[pointIndex - 1].Position,
                                                              sourcePoints.TypedElements[pointIndex].Position);
                    }

                    indexWithinSegment++;
                }
            }

            if (totalLength < 0.0001f || segments.Count < 2)
            {
                Log.Warning("Stroke animation requires at least two segments with of some length");
                return;
            }

            // Write offsets...
            float dist = maxLength / (segments.Count - 1);

            _random = new Random(42);

            for (var segmentIndex = 0; segmentIndex < segments.Count; segmentIndex++)
            {
                var segmentOffset = ComputeOverlappingProgress(0, segmentIndex, segments.Count, spread);
                var lengthProgressWithingSegment = 0f;
                var segment = segments[segmentIndex];

                // see https://www.figma.com/file/V5k13NMMIsnAnbWH651clI/Untitled?node-id=205%3A96
                var stackedRange = TimeRange.FromStartAndDuration(segment.AccumulatedLength - segment.SegmentLength, segment.SegmentLength) * (1 / totalLength);

                var anchor      = segmentIndex * segment.SegmentLength / (segments.Count - 1);
                var pGrid       = segmentIndex * dist;
                var packedRange = TimeRange.FromStartAndDuration(pGrid - anchor, segment.SegmentLength) * (1 / maxLength);
                var range       = TimeRange.Lerp(packedRange, stackedRange, spread);

                if (Math.Abs(randomizeStart) > 0.0001f)
                {
                    var randomStart = (float)_random.NextDouble() * (1 - range.Duration);
                    range.Start = MathUtils.Lerp(range.Start, randomStart, randomizeStart);
                }

                if (Math.Abs(randomizeDuration) > 0.0001f)
                {
                    var randomDuration = (float)_random.NextDouble() * (1 - range.Start);
                    range.Duration = MathUtils.Lerp(range.Duration, randomDuration, randomizeDuration);
                }

                for (var pointIndexInSegment = 0; pointIndexInSegment < segment.PointCount; pointIndexInSegment++)
                {
                    var pi = segment.PointIndex + pointIndexInSegment;
                    if (pointIndexInSegment > 0)
                    {
                        lengthProgressWithingSegment += Vector3.Distance(sourcePoints.TypedElements[pi - 1].Position,
                                                                         sourcePoints.TypedElements[pi].Position);
                    }

                    var   normalizedSegmentPosition = pointIndexInSegment / (segment.PointCount - 1);
                    float w = 0;
                    switch (spreadMode)
                    {
                    case SpreadModes.IgnoreStrokeLengths:
                        var f = lengthProgressWithingSegment / segment.SegmentLength.Clamp(0.001f, 999999f);
                        w = (f - segmentOffset) / (segments.Count + 1);
                        break;

                    case SpreadModes.UseStrokeLength:
                        w = MathUtils.Lerp(range.Start, range.End, normalizedSegmentPosition);
                        break;

                    case SpreadModes.Weird:
                        w = segmentOffset * 0.2f + pointIndexInSegment / segment.PointCount / 2;
                        break;
                    }

                    sourcePoints.TypedElements[pi].W = w;
                }
            }

            StrokeCount.Value = segments.Count;
            ResultList.Value  = sourcePoints;
            StrokeCount.DirtyFlag.Clear();
            ResultList.DirtyFlag.Clear();
        }
Ejemplo n.º 8
0
 public void SetSpreadMode(SpreadMode Mode)
 {
     CurrentSpreadMode = Mode;
 }
Ejemplo n.º 9
0
 private static void AddSpreadMode(XElement xml, SpreadMode mode)
 {
     xml.Add(new XAttribute("spreadMode", mode.ToString()));
 }
Ejemplo n.º 10
0
        private static TaleNewsReference DetermineTaleNewsToTransmit(Pawn initiator, Pawn receiver, SpreadMode mode)
        {
            TaleNewsReference result;

            switch (mode)
            {
            case SpreadMode.DISTINCT:
                SelectNewsDistinctly(initiator, receiver, out result);
                break;

            case SpreadMode.RANDOM:
                SelectNewsRandomly(initiator, receiver, out result);
                break;

            default:
                result = TaleNewsReference.DefaultReference;
                break;
            }

            return(result);
        }
Ejemplo n.º 11
0
        public static void SpreadNews(Pawn initiator, Pawn receiver, SpreadMode mode = SpreadMode.RANDOM)
        {
            TaleNewsReference newsToSend = DetermineTaleNewsToTransmit(initiator, receiver, mode);

            AttemptToTransmitNews(initiator, receiver, newsToSend);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="input"></param>
        /// <param name="caller"></param>
        public virtual void Parse( Stream input, TagTypes caller )
        {
            BitStream bits = new BitStream( input );
            GradRecord temp = new GradRecord(this._SwfVersion);

            this._spreadMode = ( SpreadMode )bits.GetBits( 2 );
            this._interpolationMode = ( InterPolation )bits.GetBits( 2 );
            this._numGradients = ( byte )bits.GetBits( 4 );

            bits.Reset();

            for ( int i = 0; i < this._numGradients; i++ )
            {
                temp = new GradRecord( this._SwfVersion );
                temp.Parse( input, caller );
                this._gradientRecords.Add( temp );
            }
        }
Ejemplo n.º 13
0
 public void Show(Graph graph, SpreadMode spreadMode)
 {
     CreateFromStructure(graph);
     AdjacencyMatrix = MakeMe(graph).ToArray();
     Spread(spreadMode);
 }