Ejemplo n.º 1
0
    //float EaseOutQuad (float t) { return (--t) * t * t + 1; }

    private void LateUpdate()
    {
        InitializeIfNeeded();
        ControlsToScales();

        // GetParticles is allocation free because we reuse the m_Particles buffer between updates
        int numParticlesAlive = m_System.GetParticles(m_Particles);

        // Change only the particles that are alive
        for (int i = 0; i < numParticlesAlive; i++)
        {
            float id = (float)m_Particles [i].randomSeed * .00001f;

            int   index = (int)(m_Particles [i].randomSeed % numParticlesAlive);
            float s     = Mathf.Min(1, ((m_Particles [i].startLifetime - m_Particles [i].remainingLifetime) / m_Particles [i].startLifetime));         // * lerpToTarget.w);
            //s = EasingFunction.EaseOutCubic (0,1,s);
            Vector3 offset = GetNoisePosition(id) * CatmullRomSpline.GetSplinePos(scales, s).magnitude;

            float timeLerp = map(s, lerpToTarget.x, lerpToTarget.y, 0, 1);
            m_Particles [i].position =
                Vector3.Lerp(
                    (CatmullRomSpline.GetSplinePos(pos, s) + offset),
                    endTarget.localToWorldMatrix.MultiplyPoint(endTargetPos[i]),
                    Mathf.SmoothStep(0, 1, timeLerp * lerpToTarget.z)
                    );
            m_Particles [i].position  += GetNoisePosition(noiseData.w + (m_Particles [i].position.x * noiseData.x) + Time.time * noiseData.y) * noiseData.z;
            m_Particles [i].startColor = Color.Lerp(m_Particles [i].startColor, lerpToColor, timeLerp * amountToLerpColor);
            m_Particles [i].startSize  = map(particleSize[i], 0, 1, particleSizeMinMax.x, particleSizeMinMax.y);
        }

        // Apply the particle changes to the particle system
        m_System.SetParticles(m_Particles, numParticlesAlive);
    }
Ejemplo n.º 2
0
    // public Vector3 startPoint;
    // public Color color;

    public override void Rebuild()
    {
        Vector3[] points = new Vector3[length];
        Vector3[] line   = new Vector3[detail];

        print(startPoint);
        for (int i = 0; i < points.Length; i++)
        {
            if (i == 0)
            {
                points[i] = startPoint;
            }
            // print(points[i]);
            else
            {
                points[i] = points[i - 1] + Random.insideUnitSphere * strokeLength;
            }
        }

        for (int i = 0; i < line.Length; i++)
        {
            float percent = (float)i / (float)line.Length;
            line[i] = CatmullRomSpline.GetSplinePos(points, percent);
        }

        lineRenderer.positionCount = detail;
        lineRenderer.SetPositions(line);
        lineRenderer.startColor      = color;
        lineRenderer.endColor        = color;
        lineRenderer.widthMultiplier = width;
    }
Ejemplo n.º 3
0
    public override void Rebuild(Vector3[] positions, Color[] colors)
    {
        Vector3[] line = new Vector3[detail];

        for (int i = 0; i < line.Length; i++)
        {
            float percent = (float)i / (float)line.Length;
            line[i] = CatmullRomSpline.GetSplinePos(positions, percent);
        }

        lineRenderer.positionCount = detail;
        lineRenderer.SetPositions(line);
        Gradient g = new Gradient();

        GradientColorKey[] keys = new GradientColorKey[colors.Length];
        for (int i = 0; i < colors.Length; i++)
        {
            GradientColorKey k = new GradientColorKey();
            k.color = colors[i];
            k.time  = (float)i / (float)colors.Length;
            keys[i] = k;
            // print(keys[i].color);
        }
        g.colorKeys = keys;
        lineRenderer.colorGradient = g;
        // lineRenderer.startColor = color;
        // lineRenderer.endColor = color;
        lineRenderer.widthMultiplier = scale;
    }
Ejemplo n.º 4
0
 Vector3 BezierSurface(float u, float v)
 {
     return(Vector3.Lerp(
                CatmullRomSpline.GetSplinePos(LineA, u),
                CatmullRomSpline.GetSplinePos(LineB, u),
                v));
 }
Ejemplo n.º 5
0
 void OnDrawGizmos()
 {
     // Draw a yellow sphere at the transform's position
     Gizmos.color = Color.yellow;
     for (int i = 0; i < 29; i++)
     {
         Gizmos.DrawLine(CatmullRomSpline.GetSplinePos(pos, (float)i / 30),
                         CatmullRomSpline.GetSplinePos(pos, ((float)i + 1) / 30));
     }
 }
Ejemplo n.º 6
0
 // Update is called once per frame
 void Update()
 {
     if (speed != 0)
     {
         t += Time.deltaTime * speed;
     }
     this.transform.position = CatmullRomSpline.GetSplinePos(pos, Mathf.Clamp(t % 1, 0, 1));
     this.transform.LookAt(CatmullRomSpline.GetSplinePos(pos, Mathf.Clamp((t - .001f) % 1, 0, 1)));
     prev = this.transform.position;
 }
Ejemplo n.º 7
0
 void Update()
 {
     for (int i = 0; i < detail; i++)
     {
         if (tube.vertices != null)
         {
             if (tube.vertices[i] != null)
             {
                 tube.vertices[i].point  = CatmullRomSpline.GetSplinePos(tubePoints, (float)i / detail);
                 tube.vertices[i].radius = width;
             }
         }
     }
 }
 // Update is called once per frame
 void Update()
 {
     if (root != null)
     {
         Destroy(root);
     }
     root = new GameObject();
     line.positionCount = detail;
     Vector3[] points = new Vector3[detail];
     for (int i = 0; i < detail; i++)
     {
         GameObject g = Instantiate(transforms[0].gameObject);
         g.transform.parent   = root.transform;
         points[i]            = CatmullRomSpline.GetSplinePos(transforms, (float)i / 100f);
         g.transform.position = points[i];
     }
     line.SetPositions(points);
 }
Ejemplo n.º 9
0
    public void AddPoint(Vector3 newPoint)
    {
        pointsList.Add(newPoint);
        int listCount = pointsList.Count;

        if (listCount >= 3)
        {
            pointsList[listCount - 2] = Vector3.Lerp(pointsList[listCount - 3], pointsList[listCount - 1], 0.5f);
        }

        pointsArray = new Vector3[listCount];

        for (int i = 0; i < listCount; i++)
        {
            pointsArray[i] = pointsList[i];
        }

        splineArray = new Vector3[multiplier * listCount];
        for (int i = 0; i < multiplier * listCount; i++)
        {
            splineArray[i] = CatmullRomSpline.GetSplinePos(pointsArray, (float)i / (multiplier * listCount));
        }

        radiusArray = new float[multiplier * listCount];
        for (int i = 0; i < multiplier * listCount; i++)
        {
            radiusArray[i] = radius;
            if (i == multiplier * listCount - 1)
            {
                radiusArray[i] = radius * 0.5f;
            }
            if (i == multiplier * listCount - 2)
            {
                radiusArray[i] = radius * 0.75f;
            }
        }

        deleteArray = new Vector3[multiplier * listCount];
    }
Ejemplo n.º 10
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            myList.Add(Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 10)));
            GameObject mysphere = Instantiate(sphere);
            mysphere.transform.position = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 10));
        }
        if (Input.GetMouseButton(0))
        {
            if (Vector3.Distance(myList[myList.Count - 1], Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 10))) > 1f)
            {
                myList.Add(Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 10)));
                GameObject mysphere = Instantiate(sphere);
                mysphere.transform.position = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 10));

                myArray = new Vector3[myList.Count];
                for (int i = 0; i < myList.Count; i++)
                {
                    myArray[i] = myList[i];
                }

                splineArray = new Vector3[myList.Count * 2];
                //transformArray = new Transform[myList.Count * 2];

                for (int i = 0; i < myList.Count * 2; i++)
                {
                    splineArray[i] = CatmullRomSpline.GetSplinePos(myArray, (float) i / (myList.Count * 2));
                    //GameObject myGO = new GameObject();
                    //myGO.transform.position = CatmullRomSpline.GetSplinePos(myArray, (float)i / (myList.Count * 2));
                    //transformArray[i] = myGO.transform;
                }

                tube.SetPoints(splineArray, 0.06f, Color.white);
            }
        }
    }
Ejemplo n.º 11
0
 // Update is called once per frame
 void Update()
 {
     this.transform.position = CatmullRomSpline.GetSplinePos(pos, Mathf.Clamp(t, 0, 1));
 }