devNotes 5-25-2016 GPU instancing, audio echo, list processing

    //Arrow_freq
    //public InputField arrow_freq_Input;
    //public Slider arrow_freq_Slider;
    //bool bArrow_freq_SliderOn = false;
    public void onArrow_freq_EditComplete(string str)
    {      
        float value = float.Parse(arrow_freq_Input.text);
        if (value < arrow_freq_Slider.maxValue && value > arrow_freq_Slider.minValue)
        {
            arrow_freq_Slider.value = value;
        }
    }

    public void onArrow_freq_SliderValueChanged()
    {
        float value = arrow_freq_Slider.value;
        arrow_freq_Input.text = value.ToString("F2") + " Hz";
        bArrow_freq_SliderOn = true;
    }

    //Brush_freq
    //public InputField brush_freq_Input;
    //public Slider brush_freq_Slider;
    //bool bBrush_freq_SliderOn = false;
    public void onBrush_freq_EditComplete(string str)
    {
        float value = float.Parse(brush_freq_Input.text);
        if (value < brush_freq_Slider.maxValue && value > brush_freq_Slider.minValue)
        {
            brush_freq_Slider.value = value;
        }
    }

    public void onBrush_freq_SliderValueChanged()
    {
        float value = brush_freq_Slider.value;
        brush_freq_Input.text = value.ToString("F2") + " Hz";
        bBrush_freq_SliderOn = true;
    }

    //AB_Ratio
    //public InputField ab_ratio_Input;
    //public Slider ab_ratio_Slider;
    //bool bAB_Ratio_SliderOn = false;
    public void onAB_Ratio_EditComplete(string str)
    {
        float value = float.Parse(ab_ratio_Input.text);
        if (value < ab_ratio_Slider.maxValue && value > ab_ratio_Slider.minValue)
        {
            ab_ratio_Slider.value = value;
        }
    }

    public void onAB_Ratio_SliderValueChanged()
    {
        float value = ab_ratio_Slider.value;
        ab_ratio_Input.text = value.ToString("F2") + " ";
        bAB_Ratio_SliderOn = true;
    }

    //Seg_len
    //public InputField seg_len_Input;
    //public Slider seg_len_Slider;
    //bool bSeg_len_SliderOn = false;
    public void onSeg_len_EditComplete(string str)
    {
        float value = float.Parse(seg_len_Input.text);
        if (value < seg_len_Slider.maxValue && value > seg_len_Slider.minValue)
        {
            seg_len_Slider.value = value;
        }
    }

    public void onSeg_len_SliderValueChanged()
    {
        float value = seg_len_Slider.value;
        seg_len_Input.text = value.ToString("F2") + " --";
        bSeg_len_SliderOn = true;
    }

    //Phasor_len
    //public InputField phasor_len_Input;
    //public Slider phasor_len_Slider;
    //bool bPhasor_len_SliderOn = false;
    public void onPhasor_len_EditComplete(string str)
    {
        float value = float.Parse(seg_len_Input.text);
        if (value < phasor_len_Slider.maxValue && value > phasor_len_Slider.minValue)
        {
            phasor_len_Slider.value = value;
        }
    }

    public void onPhasor_len_SliderValueChanged()//len to width
    {
        float value = phasor_len_Slider.value;
        phasor_len_Input.text = value.ToString("F2") + " --";
        bPhasor_len_SliderOn = true;
    }

    //Max_Segments
    //public InputField max_segments_Input;
    //public Slider max_segments_Slider;
    //bool bMax_Segments_SliderOn = false;
    public void onMax_Segments_EditComplete(string str)
    {
        float value = float.Parse(max_segments_Input.text);
        if (value < max_segments_Slider.maxValue && value > max_segments_Slider.minValue)
        {
            max_segments_Slider.value = value;
        }
    }

    public void onMax_Segments_SliderValueChanged()
    {
        float value = max_segments_Slider.value;
        max_segments_Input.text = value.ToString("F2") + " Segs";
        bMax_Segments_SliderOn = true;
    }

    //Duration
    //public InputField duration_Input;
    //public Slider duration_Slider;
    //bool bDuration_SliderOn = false;
    public void onDuration_EditComplete(string str)
    {
        float value = float.Parse(duration_Input.text);
        if (value < duration_Slider.maxValue && value > duration_Slider.minValue)
        {
            duration_Slider.value = value;
        }
    }

    public void onDuration_SliderValueChanged()
    {
        float value = duration_Slider.value;
        duration_Input.text = value.ToString("F2") + " secs";
        bDuration_SliderOn = true;
    }

ghfnhngngn

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class UI_Control : MonoBehaviour
{

    public Canvas UI_Canvas;
    public Sprite locked_sprite;
    public Sprite unlocked_sprite;
    public Button lock_Unlock_Button;

    public Sprite rotate_off_sprite;
    public Sprite rotate_on_sprite;
    public Button rotate_Button;

    public Sprite rotate_OnNavSphere_off_sprite;
    public Sprite rotate_OnNavSphere_on_sprite;
    public Button rotate_OnNavSphere_Button;

    bool isOn = false;
    bool _isLocked_NavSpheretoCam = false;
    bool rotateOn = false;
    bool _rotateOnNavSphere = false;

    GameObject Argos_Camera;
    GameObject NavSphere_Pivot;
    GameObject Argos_NavSphere;

    void Start ()
    {
        Argos_Camera    = GameObject.Find("Argos_Camera");
        NavSphere_Pivot = GameObject.Find("NavSphere_Pivot");
        Argos_NavSphere = GameObject.Find("Argos_NavSphere");
    }

    public bool isLocked_NavSpheretoCam
    {
        get { return _isLocked_NavSpheretoCam; }
    }

    public bool rotateOnNavSphere
    {
        get { return _rotateOnNavSphere; }
    }

    public void onRotateButton()
    {
        rotateOn = !rotateOn;
        SpriteState st = new SpriteState();

        if (rotateOn)
        {
            rotate_Button.image.sprite = rotate_on_sprite;
            st.pressedSprite = rotate_off_sprite;
        }
        else
        {
            rotate_Button.image.sprite = rotate_off_sprite;
            st.pressedSprite = rotate_on_sprite;
        }
        rotate_Button.spriteState = st;
    }

    public void onRotateOnNavSphereButton()
    {
        _rotateOnNavSphere = !_rotateOnNavSphere;
        SpriteState st = new SpriteState();

        if (_rotateOnNavSphere)
        {
            rotate_OnNavSphere_Button.image.sprite = rotate_OnNavSphere_on_sprite;
            st.pressedSprite = rotate_OnNavSphere_off_sprite;
        }
        else
        {
            rotate_OnNavSphere_Button.image.sprite = rotate_OnNavSphere_off_sprite;
            st.pressedSprite = rotate_OnNavSphere_on_sprite;
        }
        rotate_OnNavSphere_Button.spriteState = st;
    }


    public void onNavSphereLockUnlockButton()
    {
        _isLocked_NavSpheretoCam = !_isLocked_NavSpheretoCam;
        SpriteState st = new SpriteState();

        if (_isLocked_NavSpheretoCam)
        {
            lock_Unlock_Button.image.sprite = locked_sprite;
            st.pressedSprite = unlocked_sprite;            
       
            Quaternion q0 = Argos_Camera.transform.rotation;
            Quaternion q1 = NavSphere_Pivot.transform.rotation;

            Argos_NavSphere.transform.rotation = q1 * Quaternion.Inverse(q0)* Argos_NavSphere.transform.rotation;

            NavSphere_Pivot.transform.rotation = q0;
        }
        else
        {
            lock_Unlock_Button.image.sprite = unlocked_sprite;
            st.pressedSprite = locked_sprite;
        }
        lock_Unlock_Button.spriteState = st;
    }

    public void onUIButtonDown()
    {
        isOn = !isOn;
        UI_Canvas.gameObject.SetActive(isOn);
    }


    void Update ()
    {
	

	}
}
using UnityEngine;
using System.Collections;
 
public class ValueUpdate : MonoBehaviour {
 
    private UnityEngine.UI.Slider my_slider;
    private UnityEngine.UI.InputField my_field;
 
    void Start() {
        my_slider = gameObject.GetComponent<UnityEngine.UI.Slider>();
        my_field = gameObject.GetComponent<UnityEngine.UI.InputField>();
    }
 
    public void UpdateValueFromFloat(float value) {
        Debug.Log("float value changed: " + value);
        if (my_slider) { my_slider.value = value; }
        if (my_field) { my_field.text = value.ToString(); }
    }
 
    public void UpdateValueFromString(string value) {
        Debug.Log("string value changed: " + value);
        if (my_slider) { my_slider.value = float.Parse(value); }
        if (my_field) { my_field.text = value; }
    }
}
using UnityEngine;
using System.Collections;
using ProceduralToolkit;
using UnityEngine.UI;

public class Argos_Brush : MonoBehaviour
{
    Mesh mesh;

    [SerializeField]
    Material _material;

    MaterialPropertyBlock _block;

    private ArgosMeshDraft amDraft;
    public ArgosMeshDraft AmDraft
    {
        get { return amDraft; }
    }

    void Start ()
    {
        MeshFilter mf = GetComponent<MeshFilter>();
        if (mf.mesh == null)
            mf.mesh = new Mesh();
        mesh = mf.mesh;
        amDraft = new ArgosMeshDraft();

        _block = new MaterialPropertyBlock();
    }

    float accumTime = 0f;
    void Update ()
    {
        accumTime += Time.deltaTime;

        amDraft.QuadListUpdate();
        GetComponent<MeshFilter>().mesh = amDraft.ToMesh();

        float angle = 5f * accumTime;
        Graphics.DrawMesh(GetComponent<MeshFilter>().mesh, new Vector3(0f,0f,0f), Quaternion.Euler(0f, 0f, angle), _material, gameObject.layer, null, 0, _block);

        Graphics.DrawMesh(GetComponent<MeshFilter>().mesh, new Vector3(0f, 0f, 0f), Quaternion.Euler(0f, angle,0f ), _material, gameObject.layer, null, 0, _block)
    }

    public int GetNumVertices()
    {
        return amDraft.vertices.Count;
    }

    public Vector3 GetVertex(int i)
    {
        return amDraft.vertices[i];
    }

    public void SetVertex(int i, Vector3 v)
    {
        amDraft.vertices[i] = v;
    }

    public void MeshDraft_ToMesh()
    {
        if (amDraft != null)
        {
            GetComponent<MeshFilter>().mesh = amDraft.ToMesh();
        }
    }

    public void initAddMeshDraft(MeshDraft md)
    {
        MeshFilter mf = GetComponent<MeshFilter>();
        if (mf.mesh == null)
            mf.mesh = new Mesh();
        mesh = mf.mesh;
        amDraft = new ArgosMeshDraft();

        if (amDraft != null)
        {
            amDraft.Add(md);
            GetComponent<MeshFilter>().mesh = amDraft.ToMesh();
        }
    }

    public void Paint(Vector3 v0, Vector3 v1, Vector3 v2, Vector3 v3, Color col, float duration)
    {
        if (amDraft != null)
        {
            amDraft.Quad_Paint(v0, v1, v2, v3, col, duration);
        }
    }


    public void AddMeshDraft(MeshDraft md)
    {
        if (amDraft != null)
        {
            amDraft.Add(md);
            GetComponent<MeshFilter>().mesh = amDraft.ToMesh();
        }
    }

    public void AddMeshDraft_Only(MeshDraft md)
    {
        if (amDraft != null)
        {
            amDraft.Add(md);
        }
    }

    public void AddQuad(Vector3 v0, Vector3 v1, Vector3 v2, Vector3 v3)
    {
        if (amDraft != null)
        {
            amDraft.Add(MeshDraft.Quad(v0, v1, v2, v3));
            GetComponent<MeshFilter>().mesh = amDraft.ToMesh();
        }        
    }

    public void AddQuad(Vector3 v0, Vector3 v1, Vector3 v2, Vector3 v3, Color col)
    {
        if (amDraft != null)
        {
            amDraft.Add(MeshDraft.Quad(v0, v1, v2, v3, col));
            GetComponent<MeshFilter>().mesh = amDraft.ToMesh();
        }
    }
}

 

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;

public class ARGOS_12HORNS : MonoBehaviour
{

    //The following Cartesian coordinates define the vertices
    //of an icosahedron with edge-length 2, 
    //centered at the origin:

    //(0, ±1, ±φ)
    //(±1, ±φ, 0)
    //(±φ, 0, ±1)    

    public float freq = 0.05f;

    static float Phi = (Mathf.Sqrt(5f) + 1f)/2f;

    Vector3[] v12HORNS =

    new Vector3[] 
    {
        new Vector3(0, 1f, Phi),
        new Vector3(0, -1f, Phi),
        new Vector3(-Phi, 0, 1),
        new Vector3(Phi, 0, 1f),
        new Vector3(1f, Phi,0),
        new Vector3(1f, -Phi,0),
        new Vector3(-1f, Phi,0),
        new Vector3(-1f, -Phi, 0),
        new Vector3(0, 1f, -Phi),
        new Vector3(0, -1f, -Phi),
        new Vector3(-Phi, 0, -1f), 
        new Vector3(Phi, 0, -1f)
    };

    public GameObject NavSphereWindowPrefab;

    bool isOn_HeadUpDisplay = false;

    public Button LockNavSphereButt;
    public Button RotateNavSphereButt;

    List<Vector3> v12HORN_Norms = new List<Vector3>();
    List<GameObject> goCircs = new List<GameObject>();

    public float minLen = 0.01f;
    public float radius = 5f;
    public float phasorLength = 0.2f;
    public float freq2 = 1f;
    public float ratio = 0.5f;

    float tAccum = 0f;
    List<Vector3> vList = new List<Vector3>();
    Vector3 vLast = Vector3.zero;
    float tLast = 0f;
    float lastAngle;

    public GameObject psRiderPreFab;
    GameObject psRiderInst;
    PS_Rider psRider;
    Phasor phasor_0;

    int[] Color_12_RGB =
    {
        0xffff00,
        0xffc700,
        0xff9100,
        0xff6301,
        0xff0000,
        0xc6037e,
        0x713697,
        0x713697,
        0x444ea1,
        0x2772b2,
        0x2772b2,
        0x008e5b,
        0x008e5b,
        0x8ac819,
    };


    Color fromRGB(int col, float alpha)
    {
        Color c;

        c.r = ((float)((col & 0xff0000) >> 16)) / 256f;
        c.g = ((float)((col & 0x00ff00) >> 8)) / 256f;
        c.b = ((float)((col & 0x0000ff))) / 256f;
        c.a = alpha;
        return c;
    }

    void Start ()
    {
        float mag = v12HORNS[0].magnitude;
        for (int i = 0; i < 12; i++) v12HORN_Norms.Add(v12HORNS[1] / mag);

        float alpha;
        Quaternion q;
        for(int i = 0; i<12; i++)
        {
            q = Quaternion.LookRotation(v12HORNS[i]);
            goCircs.Add((GameObject)Instantiate(NavSphereWindowPrefab, v12HORNS[i], q));
            goCircs[i].gameObject.transform.SetParent(transform);

            goCircs[i].transform.localScale = new Vector3(12.34f, 12.34f, 12.34f);
            goCircs[i].GetComponentInChildren<Phasor>().freq = freq;

            goCircs[i].GetComponentInChildren<Canvas>().GetComponentInChildren<Text>().text = i.ToString();
            alpha = goCircs[i].GetComponentInChildren<Canvas>().GetComponentInChildren<Text>().color.a;
            goCircs[i].GetComponentInChildren<Canvas>().GetComponentInChildren<Text>().color = fromRGB(Color_12_RGB[i], alpha);

            alpha = goCircs[i].GetComponent<Renderer>().material.color.a;
            goCircs[i].GetComponent<Renderer>().material.color = fromRGB(Color_12_RGB[i], alpha);

            goCircs[i].gameObject.SetActive(isOn_HeadUpDisplay);

        }
        GetComponent<MeshRenderer>().enabled = isOn_HeadUpDisplay;
        LockNavSphereButt.gameObject.SetActive(isOn_HeadUpDisplay);
        RotateNavSphereButt.gameObject.SetActive(isOn_HeadUpDisplay);


        InitTestPainting();
    }

    void InitTestPainting()
    {
        psRiderInst = (GameObject)Instantiate(psRiderPreFab, Vector3.zero, Quaternion.identity);
        psRider = psRiderInst.GetComponent<PS_Rider>();
        phasor_0 = goCircs[0].GetComponentInChildren<Phasor>();
    }


    float phasorUpdate()
    {
        float angle = freq * 360f * tAccum;

        phasor_0.transform.localRotation = Quaternion.Euler(0f, 0f, angle);

        return angle;
    }

    void phasorSubFrame(float angle)
    {
        phasor_0.transform.localRotation = Quaternion.Euler(0f, 0f, angle);
    }


    void Update ()
    {
        tAccum += Time.deltaTime;

        float currAngle = phasorUpdate();

        Vector3 vCurr = Func(tAccum);
        vCurr.Normalize();
        vCurr *= radius;

        Vector3 vPointing = vCurr - vLast;

        vList.Clear();
        if(vPointing.magnitude > minLen)
        {
            float numSegs = vPointing.magnitude / minLen;

            if (numSegs > 10) numSegs = 10f;
            float t = tLast;
            float delt = (tAccum - tLast) / numSegs;

            float angle = lastAngle;
            float deltThet = (currAngle - lastAngle) / numSegs;
            for(int i = 0; i<numSegs;i++)
            {
                phasorSubFrame(angle);

                vCurr = Func(t);
                vCurr.Normalize();
                vCurr *= radius;

                vList.Add(vCurr);
                t += delt;
                angle += deltThet;
            }
        }
        psRider.paintList(vList);
        tLast = tAccum;
        vLast = vCurr;
        lastAngle = currAngle;
    }

    Vector3 Func(float t)
    {
        return v12HORNS[0] + phasor_0.transform.right
            * phasorLength * ((1f - ratio) + ratio * Mathf.Sin(freq2 * 2f * Mathf.PI * t));

    }

    void collect_quads(float radius)
    {

    }

    public void onDisplayICO_Button()
    {
        isOn_HeadUpDisplay = !isOn_HeadUpDisplay;
        for(int i = 0; i<12; i++)
        {
            goCircs[i].gameObject.SetActive(isOn_HeadUpDisplay);
        }
        GetComponent<MeshRenderer>().enabled = isOn_HeadUpDisplay;

        LockNavSphereButt.gameObject.SetActive(isOn_HeadUpDisplay);
        RotateNavSphereButt.gameObject.SetActive(isOn_HeadUpDisplay);
    }

    public void onScaleSlider()
    {
        //float scale = Slide.value;
        //for(int i = 0; i<12; i++)
        //{
        //    goCircs[i].transform.localScale = new Vector3(scale, scale, scale);
        //    goCircs[i].GetComponentInChildren<Phasor>().freq = freq;
        //}
        //slideText.text = scale.ToString();
    }
}
using UnityEngine;
using System.Collections;
using ProceduralToolkit;
using System.Collections.Generic;
using System.IO;


public class PS_Rider : MonoBehaviour
{
    StreamWriter sWrite;

    public ArgosMeshDraft_Fibonacci AMD_Base;

    GameObject goMyPivot;
    GameObject goTweenFollower;
    GameObject goPrintHead;

    Quaternion qStart;
    Quaternion qEnd;

    int m_startLoc;
    int m_toLoc;
    int m_deltLoc;
    int m_numPoints;
    public float m_pathTime;

    Quaternion myPaintRotation = Quaternion.identity;
    Vector3 vLastLoc, v1curr, v2curr, v1last, v2last;
    float minPaintLen = 0.01f;
    float lineWidth = 0.1f;
    int iStartPaint = 0;

    Argos_NavSphere argos_NavSphere;

    GameObject gO_InstancedPrefab;

    public Argos_Brush aBrush_Prefab;
    Argos_Brush brushInst;
    Color selColor = new Color(1f, 1f, 1f, 1f);
    bool bInited;

    void Start()
    {
        brushInst = Instantiate(aBrush_Prefab);
        //paintInst.transform.SetParent(transform);
    }


    public void initFromSpawner(int FibLoc, int delt, int numPoints, float pathTime )
    {
        //sWrite = new StreamWriter("Fibo_Rider4.csv");
        m_startLoc = FibLoc;
        m_deltLoc = delt;
        m_toLoc = FibLoc + delt;
        m_pathTime = pathTime;
        m_numPoints = numPoints;

        GameObject gFibSphere = GameObject.Find("Fibonacci_Sphere");
        ArgosFibonacci aF = gFibSphere.GetComponent<ArgosFibonacci>();
        AMD_Base = aF.aMF_Base;

        Quaternion q0, q1;

        q0 = Quaternion.LookRotation(AMD_Base.funcVerts[m_startLoc].vPos.normalized);
        q1 = Quaternion.LookRotation(AMD_Base.funcVerts[m_toLoc].vPos.normalized);
        transform.rotation = q0;
        transform.position = AMD_Base.funcVerts[FibLoc].vPos;

        goTweenFollower = transform.Find("TweenFollower").gameObject;
        goPrintHead = transform.Find("brush_S_PS").gameObject;

        goMyPivot = new GameObject();
        goMyPivot.transform.position = new Vector3(0, 0, 0);
        goMyPivot.transform.rotation = Quaternion.identity;

        transform.SetParent(goMyPivot.transform);
        goTweenFollower.transform.SetParent(transform);//this
        goTweenFollower.transform.position = Vector3.zero;

        qEnd = q1 * Quaternion.Inverse(q0);
        qStart = Quaternion.identity;

        //iTween.MoveTo(goTweenFollower, iTween.Hash("x", 1, "time", m_pathTime, "easetype", "easeInOutBack", "onstart", "fibTweenStarted", "onstartparams", "FIB Rider Started...", "onupdate", "fibTweenUpdate", "onupdateparams", FibLoc.ToString(), "oncomplete", "fibTweenComplete", "oncompleteparams", "fib Tween DONE", "onCompleteTarget", gameObject, "onStartTarget", gameObject, "onUpdateTarget", gameObject));

        m_numPoints--;
    }

    int[] testFibLoc = new int[3] { 2, 450, 750 };

    int currFibLoc = -1;
    public int getNextFibLoc()
    {
        if(++currFibLoc>testFibLoc.Length-1) currFibLoc = 0;
        return testFibLoc[currFibLoc];
    }

    float accumLerp = 0.0f;
    void Update()
    {
        //Vector3 p = transform.position;
        //paint(p);

        if (bInited)
        {
            accumLerp += Time.deltaTime;

            float t = CubicEaseOut(accumLerp, 0, 1, m_pathTime);

            if (accumLerp > m_pathTime)
            {
                accumLerp = 0f;
                t = 1f;
                LerpComplete();
            }
            else
            {
                LerpUpdate(t);
            }
        }
    }

    public void paintList(List<Vector3> pL)
    {
        if (pL.Count < 2) return;

        Vector3 len = pL[0] - vLastLoc;
        Vector3 vFwd = pL[0].normalized;

        Vector3 vUp = Vector3.Cross(vFwd, len);
        vUp.Normalize();
        v1last = vLastLoc + (lineWidth / 2f) * vUp;
        v2last = vLastLoc - (lineWidth / 2f) * vUp;

        for (int i = 1; i < pL.Count; i++)
        {
            v1curr = pL[i] + (lineWidth / 2f) * vUp;
            v2curr = pL[i] - (lineWidth / 2f) * vUp;

            brushInst.Paint(v2last, v1last, v1curr, v2curr, selColor, 3.0f);

            v1last = v1curr;
            v2last = v2curr;
        }
        vLastLoc = pL[pL.Count - 1];
    }




Vector3 vLastLerp;
    void LerpUpdate(float t)
    {
        //Update Slerp Position
        goMyPivot.transform.rotation = Quaternion.LerpUnclamped(qStart, qEnd, t);

        Vector3 p = transform.position;
        paint(p);

        // Calc Tangent to movement
        Vector3 vDir = transform.position - vLastLerp;
        vDir.Normalize();
        Vector3 vNorm = Vector3.Cross(vDir, transform.forward);

        vNorm.Normalize();

        PulseTimer += Time.deltaTime;
        float amp;

        float mag = 0.4f;

        amp = mag * CubicEaseOut(PulseTimer, 1f, -1f, 0.3f);

        goPrintHead.GetComponent<ParticleSystem>().startSize = amp + 0.1f;

        //goPrintHead.transform.rotation = goMyPivot.transform.rotation;
        //goPrintHead.transform.position = transform.position - amp * vNorm;

        vLastLerp = transform.position;
    }

    void LerpComplete()
    {
        Quaternion q0, q1;

        goMyPivot.transform.rotation = Quaternion.LerpUnclamped(qStart, qEnd, 1.0f);

        q0 = Quaternion.LookRotation(AMD_Base.funcVerts[m_toLoc].vPos.normalized);
        m_toLoc = (m_toLoc + 900) % 2500;

        //if (m_toLoc > 2000) m_toLoc = m_startLoc;
        q1 = Quaternion.LookRotation(AMD_Base.funcVerts[m_toLoc].vPos.normalized);

        qEnd = q1 * Quaternion.Inverse(q0) * goMyPivot.transform.rotation;
        qStart = goMyPivot.transform.rotation;

        goTweenFollower.transform.position = Vector3.zero;
    }


    public void initFromEventSytem(ArgosMeshDraft_Fibonacci amd_F, float pathTime)
    {
        m_startLoc = getNextFibLoc();
        m_toLoc = getNextFibLoc();
        m_pathTime = pathTime;
        AMD_Base = amd_F;

        Quaternion q0, q1;

        q0 = Quaternion.LookRotation(AMD_Base.funcVerts[m_startLoc].vPos.normalized);
        q1 = Quaternion.LookRotation(AMD_Base.funcVerts[m_toLoc].vPos.normalized);
        transform.rotation = q0;
        transform.position = AMD_Base.funcVerts[m_startLoc].vPos;

        goTweenFollower = transform.Find("TweenFollower").gameObject;
        goPrintHead = transform.Find("brush_S_PS").gameObject;

        goMyPivot = new GameObject();
        goMyPivot.transform.position = new Vector3(0, 0, 0);
        goMyPivot.transform.rotation = Quaternion.identity;

        transform.SetParent(goMyPivot.transform);
        goTweenFollower.transform.SetParent(transform);//this
        goTweenFollower.transform.position = Vector3.zero;

        //public Argos_Brush aBrush_Prefab;
        //Argos_Brush brushInst;

        brushInst = Instantiate(aBrush_Prefab);
        brushInst.transform.rotation = Quaternion.identity;
        brushInst.transform.localPosition = Vector3.zero;

        qEnd = q1 * Quaternion.Inverse(q0);
        qStart = Quaternion.identity;

        bInited = true;
        //iTween.MoveTo(goTweenFollower, iTween.Hash("x", 1, "time", m_pathTime, "easetype", "linear", "onstart", "SODTweenStarted", "onupdate", "SODTweenUpdate", "oncomplete", "SODTweenComplete", "onCompleteTarget", gameObject, "onStartTarget", gameObject, "onUpdateTarget", gameObject));
    }

    float PulseTimer = float.MaxValue;

    public void onEventTween()
    {
        PulseTimer = 0;
        accumLerp = 0;
        Quaternion q0, q1;

        q0 = goMyPivot.transform.rotation;// Quaternion.LookRotation(AMD_Base.funcVerts[m_toLoc].vPos.normalized);
        m_toLoc = (m_toLoc + 900) % 2500;

        q1 = Quaternion.LookRotation(AMD_Base.funcVerts[m_toLoc].vPos.normalized);

        qEnd = q1 * Quaternion.Inverse(q0) * goMyPivot.transform.rotation;
        qStart = goMyPivot.transform.rotation;
    }

    void SODTweenStarted()
    {

    }


    Vector3 vLast;
    void SODTweenUpdate()
    {
        //Update Slerp Position
        float sTime = goTweenFollower.transform.position.x;
        goMyPivot.transform.rotation = Quaternion.LerpUnclamped(qStart, qEnd, sTime);

        Vector3 p = transform.position;
        paint(p);
        
        // Calc Tangent to movement

        Vector3 vDir = transform.position - vLast;
        vDir.Normalize();
        Vector3 vNorm = Vector3.Cross(vDir, transform.forward);

        vNorm.Normalize();

        PulseTimer += Time.deltaTime;
        float amp;

        float mag = 0.4f;

        amp = mag*CubicEaseOut(PulseTimer, 1f, -1f, 0.3f);

        goPrintHead.GetComponent<ParticleSystem>().startSize = amp+0.1f;

        //goPrintHead.transform.rotation = goMyPivot.transform.rotation;
        //goPrintHead.transform.position = transform.position - amp * vNorm;

        vLast = transform.position;
    }


    /// float t, float b, float c, float d
    /// </summary>
    /// <param name="current">how long into the ease are we</param>
    /// <param name="initialValue">starting value if current were 0</param>
    /// <param name="totalChange">total change in the value (not the end value, but the end - start)</param>
    /// <param name="duration">the total amount of time (when current == duration, the returned value will == initial + totalChange)</param>
    /// <returns></returns>

    public static float CubicEaseOut(float t, float b, float c, float d)
    {
        if (t < d)
        {
            return c * ((t = t / d - 1) * t * t + 1) + b;
        }
        else
        {
            return b + c;
        }
    }

    public static float CubicEaseIn(float t, float b, float c, float d)
    {
        if (t < d)
        {
            return c * (t /= d) * t * t + b;
        }
        else
        {
            return b + c;
        }
    }


    void SODTweenComplete()
    {
        //Quaternion q0, q1;

        //goMyPivot.transform.rotation = Quaternion.LerpUnclamped(qStart, qEnd, 1.0f);

        //q0 = Quaternion.LookRotation(AMD_Base.funcVerts[m_toLoc].vPos.normalized);
        //m_toLoc = (m_toLoc + 900)%2500; 

        //if (m_toLoc > 2000) m_toLoc = m_startLoc;
        //q1 = Quaternion.LookRotation(AMD_Base.funcVerts[m_toLoc].vPos.normalized);

        //qEnd = q1 * Quaternion.Inverse(q0) * goMyPivot.transform.rotation;
        //qStart = goMyPivot.transform.rotation;

        //goTweenFollower.transform.position = Vector3.zero;

        //iTween.MoveTo(goTweenFollower, iTween.Hash("x", 1, "time", m_pathTime, "easetype", "linear", "onstart", "SODTweenStarted", "onupdate", "SODTweenUpdate", "oncomplete", "SODTweenComplete", "onCompleteTarget", gameObject, "onStartTarget", gameObject, "onUpdateTarget", gameObject));
    }


    int CBcount = 0;
    //float fAccumTime = 0.0f;
    void fibTweenUpdate(string textToDisplay)
    {
        float sTime = goTweenFollower.transform.position.x;
        goMyPivot.transform.rotation = Quaternion.LerpUnclamped(qStart, qEnd, sTime);
        CBcount++;
    }


    public void paint(Vector3 p)
    { 
        Vector3 vCurrLoc = p;
        Quaternion LocalRotation = myPaintRotation; //myPaintRotation * Quaternion.Inverse(argos_Sphere.transform.rotation);
        vCurrLoc = LocalRotation* vCurrLoc;
 
        if (vCurrLoc != vLastLoc)
        {
            Vector3 len = vCurrLoc - vLastLoc;
 
            if (len.magnitude > minPaintLen)
            {
                Vector3 vFwd = p.normalized;//userMovement.cursorTran.screenProjTrans.forward;

                Vector3 vFwdRtd = LocalRotation * vFwd;

                Vector3 vUp = Vector3.Cross(vFwdRtd, len);
                vUp.Normalize();
 
                v1curr = vCurrLoc + (lineWidth / 2f) * vUp;
                v2curr = vCurrLoc - (lineWidth / 2f) * vUp;
 
                //sWrite.WriteLine("len =" + v2last.ToString("F3") + " vFwdRtd =" + vFwdRtd.ToString("F3") + " vUp =" + vUp.ToString("F3") + " vLastLoc =" + vLastLoc.ToString("F3") + " vCurrLoc =" + vCurrLoc.ToString("F3"));
 
                if (++iStartPaint > 2) //don't write 2 times though
                {
                    brushInst.Paint(v2last, v1last, v1curr, v2curr, selColor, 3.0f);//TIME FOR TESTING
                    //sWrite.WriteLine("v0 =" + v2last.ToString("F3") + "v1 =" + v1last.ToString("F3") + "v2 =" + v1curr.ToString("F3") + "v3 =" + v2curr.ToString("F3"));
                }
                vLastLoc = vCurrLoc;
 
                v1last = v1curr;
                v2last = v2curr;
 
                //if (currPE_Idx > -1 && paintList[currPE_Idx].Mdraft != null)
                //    InfoLineTxt.text = " Pn = " + (paintList[currPE_Idx].Mdraft.triangles.Count / 2).ToString();
            }
        }
    }
}

 

DRAW MESH Unity Project Keijiro Takahashi

Kiero

dfghdgfdhfged-9