devNotes 8-8-16 UI Interaction Stone Fox – 12 Horns

sdfgdfg

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

public class Argos_Hex_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();

        amDraft.initQuadPool(5000);
    }

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

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



        //Vector3 vH0 = a12horns.v12HORN_Norms[0];
        Quaternion q;

        //for (int i = 0; i < 12; i++)
        //{
            //q = Quaternion.FromToRotation(vH0, a12horns.v12HORN_Norms[i]);

            q = Quaternion.identity;
            //print(q.ToString());
            Graphics.DrawMesh(GetComponent<MeshFilter>().mesh, Vector3.zero, q, _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, float fade_start)
    {
        if (amDraft != null)
        {
            amDraft.Quad_Paint(v0, v1, v2, v3, col, duration, fade_start);
        }
    }

    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();
        }
    }
}

public class ARGOS_12HORNS

public class Argos_Brush

using UnityEngine;
using System.Collections;
using ProceduralToolkit;
using System.Collections.Generic;
using System.IO;



public class ArgosSphere_Indexing : MonoBehaviour
{
    StreamWriter sWrite;

    public float radius = 1f;
    public int longitudeSegments = 64;
    public int latitudeSegments = 64;

    //public Slider angVelSlider;
    //public Text avSlideVal;
    //float angularVelDegsPerSec = 0f;

    //public Text DBG_Text;

    public class H_Element
    {
        public MeshDraft mdH = new MeshDraft();
        public float timer;
        public int[] neighborLoc = new int[6];
        public int myIndex;

        public Vector3 GetCenter()
        {
            Vector3 vc = mdH.vertices[0] + mdH.vertices[1] + mdH.vertices[2] + mdH.vertices[3];
            return vc / 4f;
        }

        public Quaternion GetQuat()
        {
            Vector3 vFwd = GetCenter().normalized;
            Vector3 vUp = (mdH.vertices[0] - mdH.vertices[1]).normalized;
            return Quaternion.LookRotation(vFwd, vUp);
        }
    }

    public class Quad_Element
    {
        public MeshDraft mdQuad = new MeshDraft();
        public H_Element[] H = new H_Element[4];
        public int[] H_idx = new int[4]; //Hex locations
        public int myIndex;
    }

    public List<Quad_Element> LLQuads = new List<Quad_Element>();
    public List<H_Element> HexQuads = new List<H_Element>();

    MeshDraft meshDraft_Sphere = new MeshDraft();


    private void Awake()
    {
        sWrite = new StreamWriter("Argos_Scene_Objects.txt");
        meshDraft_Sphere = new MeshDraft();
        meshDraft_Sphere = MeshDraft.Sphere_Argos(radius, longitudeSegments, latitudeSegments);
        GetComponent<MeshFilter>().mesh = meshDraft_Sphere.ToMesh();

        Build_LLQuad_List();
        Build_HexQuad_List();
        LinkLists();

        transform.RotateAround(transform.position, transform.forward, 0f);
    }

    void OnApplicationQuit()
    {
        GetAllObjectsInScene();
        sWrite.Close();
    }

    void GetAllObjectsInScene()
    {
        int count = 0;

        List<GameObject> RootGameObjects = new List<GameObject>();
        List<Component> components = new List<Component>();

        UnityEngine.SceneManagement.SceneManager.GetActiveScene().GetRootGameObjects(RootGameObjects);

        foreach (GameObject go in RootGameObjects)
        {
            //if (go.hideFlags == HideFlags.NotEditable || go.hideFlags == HideFlags.HideAndDontSave)
            //    continue;
            count++;
            sWrite.WriteLine(count.ToString() + "  " + go.name);

            Component[] comp = go.GetComponents(typeof(Component));

            foreach(Component c in comp)
            {
                sWrite.WriteLine("  " + "  - " + c.GetType().ToString());
            }
            sWrite.WriteLine("  ");
            int cc = go.transform.childCount;
            for(int i = 0; i< cc; i++)
            {
                sWrite.WriteLine("     " + go.transform.GetChild(i).name);
                Component[] compa = go.transform.GetChild(i).GetComponents(typeof(Component));
                foreach (Component c in compa)
                {
                    sWrite.WriteLine("  " + "  - " + c.GetType().ToString());
                }
                sWrite.WriteLine("  " );
                int cc2 = go.transform.GetChild(i).childCount;
                for(int j = 0; j<cc2; j++)
                {
                    sWrite.WriteLine("        " + go.transform.GetChild(i).GetChild(j).name);
                    Component[] comp1 = go.transform.GetChild(i).GetChild(j).GetComponents(typeof(Component));
                    foreach (Component c in comp1)
                    {
                        sWrite.WriteLine("        " + "  - " + c.GetType().ToString());
                    }
                    sWrite.WriteLine("  ");
                    int cc3 = go.transform.GetChild(i).GetChild(j).childCount;
                    for(int k = 0; k<cc3; k++)
                    {
                        sWrite.WriteLine("            " + go.transform.GetChild(i).GetChild(j).GetChild(k).name);
                        Component[] comp2 = go.transform.GetChild(i).GetChild(j).GetChild(k).GetComponents(typeof(Component));
                        foreach (Component c in comp2)
                        {
                            sWrite.WriteLine("            " + "  - " + c.GetType().ToString());
                        }
                        sWrite.WriteLine("  ");
                        int cc4 = go.transform.GetChild(i).GetChild(j).GetChild(k).childCount;
                        for (int l = 0; l < cc4; l++)
                        {
                            sWrite.WriteLine("                    " + go.transform.GetChild(i).GetChild(j).GetChild(k).GetChild(l).name);
                            Component[] comp3 = go.transform.GetChild(i).GetChild(j).GetChild(k).GetChild(l).GetComponents(typeof(Component));
                            foreach (Component c in comp3)
                            {
                                sWrite.WriteLine("                    " + "  - " + c.GetType().ToString());
                            }
                            sWrite.WriteLine("  ");
                            int cc5 = go.transform.GetChild(i).GetChild(j).GetChild(k).GetChild(l).childCount;
                            for (int m = 0; m < cc5; m++)
                            {
                                sWrite.WriteLine("                        " + go.transform.GetChild(i).GetChild(j).GetChild(k).GetChild(l).GetChild(m).name);
                                Component[] comp4 = go.transform.GetChild(i).GetChild(j).GetChild(k).GetChild(l).GetChild(m).GetComponents(typeof(Component));
                                foreach (Component c in comp4)
                                {
                                    sWrite.WriteLine("                        " + "  - " + c.GetType().ToString());
                                }
                            }
                            sWrite.WriteLine("  ");
                        }
                    }
                }
            }
        }
    }

    void GetAllObjectsInSceneRecurse()
    {
        int count = 0;

        List<GameObject> RootGameObjects = new List<GameObject>();

        UnityEngine.SceneManagement.SceneManager.GetActiveScene().GetRootGameObjects(RootGameObjects);


        foreach (GameObject go in RootGameObjects)
        {
            if (go.hideFlags == HideFlags.NotEditable || go.hideFlags == HideFlags.HideAndDontSave)
                continue;
            count++;
            sWrite.WriteLine(count.ToString() + "  " + go.name);
            int cc = go.transform.childCount;
            for (int i = 0; i < cc; i++)
            {
                sWrite.WriteLine("     " + go.transform.GetChild(i).name);
                int cc2 = go.transform.GetChild(i).childCount;
                for (int j = 0; j < cc2; j++)
                {
                    sWrite.WriteLine("        " + go.transform.GetChild(i).GetChild(j).name);

                    int cc3 = go.transform.GetChild(i).GetChild(j).childCount;
                    for (int k = 0; k < cc3; k++)
                    {
                        sWrite.WriteLine("            " + go.transform.GetChild(i).GetChild(j).GetChild(k).name);

                        int cc4 = go.transform.GetChild(i).GetChild(j).GetChild(k).childCount;
                        for (int l = 0; l < cc4; l++)
                        {
                            sWrite.WriteLine("                    " + go.transform.GetChild(i).GetChild(j).GetChild(k).GetChild(l).name);
                            int cc5 = go.transform.GetChild(i).GetChild(j).GetChild(k).GetChild(l).childCount;
                            for (int m = 0; m < cc5; m++)
                            {
                                sWrite.WriteLine("                        " + go.transform.GetChild(i).GetChild(j).GetChild(k).GetChild(l).GetChild(m).name);
                            }
                        }
                    }
                }
            }
        }
    }


    public void OnSliderChanged()
    {
        //angularVelDegsPerSec  = angVelSlider.value;
        //avSlideVal.text = angularVelDegsPerSec.ToString("F0") + " dps";
    }

    private void Update()
    {
        //transform.RotateAround(transform.position, transform.up, angularVelDegsPerSec * Time.deltaTime);
    }

    public Vector2 getLatLong(Vector3 point)
    {
        float fLat, fLong;

        fLong = Mathf.Atan2(point.x, point.z);
        if (fLong < 0.0f)
        {
            fLong = 2f * Mathf.PI + fLong;
        }
        fLat = Mathf.Atan2(point.y, Mathf.Sqrt(point.x * point.x + point.z * point.z));
        return new Vector2(fLat, fLong);
    }

    public int getHexIdx(Vector3 point)//error code means point outside of 1% tolerance
    {
        int qIdx = getLLQuadIdx(point);

        if (qIdx == -1) return -1; //point outside of 1% radius tolerance 

        //DBG_Text.text = "qIdx = " + qIdx.ToString() + "   H0 = " + LLQuads[qIdx].H_idx[0].ToString() + " H1 = " + LLQuads[qIdx].H_idx[1].ToString() + " H2 = " + LLQuads[qIdx].H_idx[2].ToString() + " H3 = " + LLQuads[qIdx].H_idx[3].ToString();

        Vector3 v0 = LLQuads[qIdx].mdQuad.vertices[0];
        Vector3 v1 = LLQuads[qIdx].mdQuad.vertices[1];
        Vector3 v2 = LLQuads[qIdx].mdQuad.vertices[2];
        Vector3 v3 = LLQuads[qIdx].mdQuad.vertices[3];

        Vector3 vXn = v2 - v0; float magX = vXn.magnitude;  vXn.Normalize();
        Vector3 vYn = v1 - v0; float magY = vYn.magnitude; vYn.Normalize();

        Vector3 vP = point - v0;
        //float magP = vP.magnitude;

        if (Vector3.Dot(vXn, vP) < (1f / 6f) * magX) return LLQuads[qIdx].H_idx[0];

        if (Vector3.Dot(vXn, vP) > (5f / 6f) * magX) return LLQuads[qIdx].H_idx[3];

        if (Vector3.Dot(vXn, vP) > ((1f / 3f) * magX) && Vector3.Dot(vXn, vP) < ((2f / 3f) * magX))
        {
            if (Vector3.Dot(vYn, vP) < (1f / 2f) * magY) return LLQuads[qIdx].H_idx[1];
            else return LLQuads[qIdx].H_idx[2];
        }

        Vector3 A = v0 + (1f / 6f) * vXn * magX;
        Vector3 B = v0 + (1f / 3f) * vXn * magX + (1f/2f) * vYn * magY;
        Vector3 C = v1 + (1f / 6f) * vXn * magX; 
        Vector3 D = v2 - (1f / 6f) * vXn * magX; 
        Vector3 E = v2 - (1f / 3f) * vXn * magX + (1f / 2f) * vYn * magY;
        Vector3 F = v3 - (1f / 6f) * vXn * magX; 

        Vector3 APos = point - A;
        Vector3 AB = B - A;

        Vector3 CPos = point - C;
        Vector3 CB = B - C;

        Vector3 vFwd = point.normalized;

        //float yDot = Vector3.Dot(vYn, vP);
        //float halfMag = (1f / 2f) * magY;
        //float outDot = Vector3.Dot(Vector3.Cross(DPos, DE), vFwd);
        //DBG_Text.text = "qIdx = " + qIdx.ToString() + "   H0 = " + LLQuads[qIdx].H_idx[0].ToString() + " H1 = " + LLQuads[qIdx].H_idx[1].ToString() + " H2 = " + LLQuads[qIdx].H_idx[2].ToString() + " H3 = " + LLQuads[qIdx].H_idx[3].ToString();
        //DBG_Text.text = "yDot = " + yDot.ToString("F4") + "   (1f/2f)* magY " + halfMag.ToString("F4") + " outDot = " + outDot.ToString("F4") + " H2 = " + LLQuads[qIdx].H_idx[2].ToString() + " H3 = " + LLQuads[qIdx].H_idx[3].ToString();

        if (Vector3.Dot(vXn, vP) > (1f/6f)*magX && Vector3.Dot(vXn, vP) < (1f/3f)*magX)
        {
            if (Vector3.Dot(vYn, vP) < (1f/2f)* magY)
            {
                if (Vector3.Dot(Vector3.Cross(APos, AB), vFwd) > 0) return LLQuads[qIdx].H_idx[0];
                return LLQuads[qIdx].H_idx[1];
            }
            else
            {
                if (Vector3.Dot(Vector3.Cross(CPos, CB), vFwd) < 0) return LLQuads[qIdx].H_idx[0];
                return LLQuads[qIdx].H_idx[2];
            }
        }

        Vector3 DPos = point - D;
        Vector3 DE = E - D;

        Vector3 FPos = point - F;
        Vector3 FE = E - F;       

        if (Vector3.Dot(vXn, vP) > (2f/3f) * magX && Vector3.Dot(vXn, vP) < (5f/6f) * magX)
        {
            if (Vector3.Dot(vYn, vP) < (1f/2f)*magY)
            {
                if(Vector3.Dot(Vector3.Cross(DPos, DE), vFwd) > 0) return LLQuads[qIdx].H_idx[1];
                return LLQuads[qIdx].H_idx[3];
            }
            else
            {
                if (Vector3.Dot(Vector3.Cross(FPos, FE), vFwd) > 0) return LLQuads[qIdx].H_idx[3];
                return LLQuads[qIdx].H_idx[2];
            }
        }
        return -1;
    }

    public int getLLQuadIdx(Vector3 point)
    {
        float fLat, fLong;
        int idx;

        //check if valid

        if (point.magnitude > 1.01f * radius || point.magnitude < 0.99f * radius) return -1;


        float longitudeSegmentAngle = Mathf.PI * 2 / longitudeSegments;
        float latitudeSegmentAngle = Mathf.PI / latitudeSegments;

        fLong = Mathf.Atan2(point.x, point.z);
        if (fLong < 0.0f)
        {
            fLong = 2f * Mathf.PI + fLong;
        }
        fLat = Mathf.Atan2(point.y, Mathf.Sqrt(point.x * point.x + point.z * point.z));

        float ring = (Mathf.PI/2f - fLat)/latitudeSegmentAngle;
        float spars = fLong / longitudeSegmentAngle;

        idx = ((int)ring) * longitudeSegments + (int)spars;

        return idx;
    }

    private void LinkLists()
    {
        //float longitudeSegmentAngle = 360f / longitudeSegments;
        //float latitudeSegmentAngle = 180f / latitudeSegments;

        for (var ring = 0; ring < latitudeSegments; ring++)
        {
            //H1   Even Row - 0,2,4,6,
            for (int i = 0; i < longitudeSegments; i++)
            {
                int qIdx = ring * longitudeSegments + i;

                //H0 = (TX-1, TY*2-1) -> (i-1) + (ring*2 -1)*longitudeSegments
                //H1 = (TX,   TY*2-2) ->   i   + (ring*2 -2)*longitudeSegments
                //H2 = (TX,   TY*2)   ->   i   + (ring*2)   *longitudeSegments
                //H3 = (TX,   TY*2-1) ->   i   + (ring*2 -1)*longitudeSegments

                if ((ring == 0) || (ring == latitudeSegments - 1))
                {
                    LLQuads[qIdx].H[0] = HexQuads[0];
                    LLQuads[qIdx].H[1] = HexQuads[0];
                    LLQuads[qIdx].H[2] = HexQuads[0];
                    LLQuads[qIdx].H[3] = HexQuads[0];

                    LLQuads[qIdx].H_idx[0] = 0;
                    LLQuads[qIdx].H_idx[1] = 0;
                    LLQuads[qIdx].H_idx[2] = 0;
                    LLQuads[qIdx].H_idx[3] = 0;
                }
                else
                {

                    if (i == 0)
                    {
                        LLQuads[qIdx].H[0] = HexQuads[(ring * 2) * longitudeSegments + (2*longitudeSegments-1)];
                        LLQuads[qIdx].H_idx[0] = (ring * 2) * longitudeSegments + (2 * longitudeSegments - 1);
                    }
                    else
                    {
                        LLQuads[qIdx].H[0] = HexQuads[(i - 1) + (ring * 2 + 1) * longitudeSegments];
                        LLQuads[qIdx].H_idx[0] = (i - 1) + ((ring * 2 + 1) * longitudeSegments);
                    }
                    LLQuads[qIdx].H[1] = HexQuads[i + (ring * 2 ) * longitudeSegments];
                    LLQuads[qIdx].H[2] = HexQuads[i + (ring * 2 + 2) * longitudeSegments];
                    LLQuads[qIdx].H[3] = HexQuads[i + (ring * 2 + 1 ) * longitudeSegments];

                    LLQuads[qIdx].H_idx[1] = i + (ring * 2 ) * longitudeSegments;
                    LLQuads[qIdx].H_idx[2] = i + (ring * 2 + 2) * longitudeSegments;
                    LLQuads[qIdx].H_idx[3] = i + (ring * 2 + 1) * longitudeSegments;


                    //sWrite.WriteLine("ring = {0} seg = {1}  qIdx = {2} H0 = {3} H1 = {4} H2 = {5} H3 = {6}  LAT = {7:f2}° LONG = {8:f2}°", ring, i, qIdx, LLQuads[qIdx].H[0].myIndex, LLQuads[qIdx].H[1].myIndex, LLQuads[qIdx].H[2].myIndex, LLQuads[qIdx].H[3].myIndex, ring * latitudeSegmentAngle, i * longitudeSegmentAngle);


                    //LLQuads[qIdx].H[0] = HexQuads[(i - 1) + (ring * 2 - 1) * longitudeSegments];
                    //LLQuads[qIdx].H[1] = HexQuads[i + (ring * 2 - 2) * longitudeSegments];
                    //LLQuads[qIdx].H[2] = HexQuads[i + (ring * 2) * longitudeSegments];
                    //LLQuads[qIdx].H[3] = HexQuads[i + (ring * 2 - 1) * longitudeSegments];

                    //LLQuads[qIdx].H_idx[0] = (i - 1) +(ring * 2 - 1) * longitudeSegments;
                    //LLQuads[qIdx].H_idx[1] = i + (ring * 2 - 2) * longitudeSegments;
                    //LLQuads[qIdx].H_idx[2] = i + (ring * 2) * longitudeSegments;
                    //LLQuads[qIdx].H_idx[3] = i + (ring * 2 - 1) * longitudeSegments;
                }
            }
        }
    }

    public int getSpawnLoc(int iHexQuadLoc, int iNeighborIdx)
    {

        if(iHexQuadLoc > -1 && iHexQuadLoc < HexQuads.Count-1)
        {
            return HexQuads[iHexQuadLoc].neighborLoc[iNeighborIdx];
            //return iHexQuadLoc + longitudeSegments;
        }
        return -1;
    }

    private void Build_HexQuad_List()
    {
        H_Element HE;

        int nEl = 0;

        for (var ring = 0; ring < latitudeSegments; ring++)
        {
            //H1   Even Row - 0,2,4,6,
            for (int i = 0; i < longitudeSegments; i++)
            {
                HE = new H_Element();

                HE.myIndex = nEl;

                Vector3 v0, v1, v2, v3, vCent;

                int qIdx = ring * longitudeSegments + i;

                v0 = LLQuads[qIdx].mdQuad.vertices[0];
                v1 = LLQuads[qIdx].mdQuad.vertices[1];
                v2 = LLQuads[qIdx].mdQuad.vertices[2];
                v3 = LLQuads[qIdx].mdQuad.vertices[3];

                vCent = (v0 + v1 + v2 + v3) / 4f;

                Vector3 vRight = v2 - v0;
                Vector3 vUp = v0 - v1;

                HE.mdH.vertices.Add(v0 + (1f / 6f) * vRight + (1f / 2f) * vUp);
                HE.mdH.vertices.Add(v0 + (1f / 6f) * vRight - (1f / 2f) * vUp);
                HE.mdH.vertices.Add(v2 - (1f / 6f) * vRight + (1f / 2f) * vUp);
                HE.mdH.vertices.Add(v2 - (1f / 6f) * vRight - (1f / 2f) * vUp);

                HE.mdH.normals.Add(vCent.normalized);
                HE.mdH.normals.Add(vCent.normalized);
                HE.mdH.normals.Add(vCent.normalized);
                HE.mdH.normals.Add(vCent.normalized);

                HE.mdH.uv.Add(new Vector2(0f, 1f));
                HE.mdH.uv.Add(new Vector2(0f, 0f));
                HE.mdH.uv.Add(new Vector2(1f, 1f));
                HE.mdH.uv.Add(new Vector2(1f, 0f));

                //Evens
                if (ring > 1 && ring < latitudeSegments - 2 )
                {
                    HE.neighborLoc[0] = nEl - longitudeSegments * 2;
                    HE.neighborLoc[1] = nEl - longitudeSegments;
                    HE.neighborLoc[2] = nEl + longitudeSegments;
                    HE.neighborLoc[3] = nEl + longitudeSegments * 2;

                    if (i == 0)
                    {
                        HE.neighborLoc[4] = nEl + 2 * longitudeSegments - 1;
                        HE.neighborLoc[5] = nEl - 1;
                    }
                    else
                    {
                        HE.neighborLoc[4] = nEl + longitudeSegments - 1;
                        HE.neighborLoc[5] = nEl - (longitudeSegments + 1);
                    }
                }
                else
                {
                    HE.neighborLoc[0] = 0;
                    HE.neighborLoc[1] = 0;
                    HE.neighborLoc[2] = 0;
                    HE.neighborLoc[3] = 0;
                    HE.neighborLoc[4] = 0;
                    HE.neighborLoc[5] = 0;
                }

                HE.mdH.triangles.AddRange(new[] { 0, 2, 1, 1, 2, 3 });
                HexQuads.Add(HE);

                nEl++;
            }

            //H3 Odd Row - 1,3,5,7,
            for (int i = 0; i < longitudeSegments; i++)
            {
                HE = new H_Element();

                HE.myIndex = nEl;

                Vector3 v0, v1, v2, v3, vCent;

                int qIdx = ring * longitudeSegments + i;

                v0 = LLQuads[qIdx].mdQuad.vertices[0];
                v1 = LLQuads[qIdx].mdQuad.vertices[1];
                v2 = LLQuads[qIdx].mdQuad.vertices[2];
                v3 = LLQuads[qIdx].mdQuad.vertices[3];

                vCent = (v0 + v1 + v2 + v3) / 4f;

                Vector3 vRight = v2 - v0;
                //Vector3 vUp = v0 - v1;

                HE.mdH.vertices.Add(v2 - (1f / 3f) * vRight);
                HE.mdH.vertices.Add(v3 - (1f / 3f) * vRight);
                HE.mdH.vertices.Add(v2 + (1f / 3f) * vRight);
                HE.mdH.vertices.Add(v3 + (1f / 3f) * vRight);

                HE.mdH.normals.Add(vCent.normalized);
                HE.mdH.normals.Add(vCent.normalized);
                HE.mdH.normals.Add(vCent.normalized);
                HE.mdH.normals.Add(vCent.normalized);

                HE.mdH.uv.Add(new Vector2(0f, 1f));
                HE.mdH.uv.Add(new Vector2(0f, 0f));
                HE.mdH.uv.Add(new Vector2(1f, 1f));
                HE.mdH.uv.Add(new Vector2(1f, 0f));

                //Odds
                if (ring > 1 && ring < latitudeSegments - 2)
                {
                    HE.neighborLoc[0] = nEl - longitudeSegments * 2;

                    if (i == longitudeSegments - 1)
                    {
                        HE.neighborLoc[1] = nEl - 2 * longitudeSegments + 1;
                        HE.neighborLoc[2] = nEl + 1;
                    }
                    else
                    {
                        HE.neighborLoc[1] = nEl - longitudeSegments + 1;
                        HE.neighborLoc[2] = nEl + longitudeSegments + 1;
                    } 
                    HE.neighborLoc[3] = nEl + longitudeSegments * 2;
                    HE.neighborLoc[4] = nEl + longitudeSegments;
                    HE.neighborLoc[5] = nEl - longitudeSegments;
                }
                else
                {
                    HE.neighborLoc[0] = 0;
                    HE.neighborLoc[1] = 0;
                    HE.neighborLoc[2] = 0;
                    HE.neighborLoc[3] = 0;
                    HE.neighborLoc[4] = 0;
                    HE.neighborLoc[5] = 0;
                }

                HE.mdH.triangles.AddRange(new[] { 0, 2, 1, 1, 2, 3 });
                HexQuads.Add(HE);

                nEl++;
            }
        }
    }

    private void Build_LLQuad_List()
    {
        //using (var writer = new StreamWriter("Index_Check.txt"))
        //{
            Quad_Element QE;
            int myIdx = 0;
            int idx_runner = 0;
            for (var ring = 0; ring < latitudeSegments; ring++)
            {
                for (int i = 0; i < longitudeSegments; i++)
                {
                    QE = new Quad_Element();
                    QE.mdQuad.vertices.Add(meshDraft_Sphere.vertices[meshDraft_Sphere.triangles[idx_runner]]);
                    QE.mdQuad.vertices.Add(meshDraft_Sphere.vertices[meshDraft_Sphere.triangles[idx_runner+1]]);
                    QE.mdQuad.vertices.Add(meshDraft_Sphere.vertices[meshDraft_Sphere.triangles[idx_runner+2]]);
                    QE.mdQuad.vertices.Add(meshDraft_Sphere.vertices[meshDraft_Sphere.triangles[idx_runner+5]]);

                    QE.mdQuad.normals.Add(meshDraft_Sphere.normals[meshDraft_Sphere.triangles[idx_runner]]);
                    QE.mdQuad.normals.Add(meshDraft_Sphere.normals[meshDraft_Sphere.triangles[idx_runner + 1]]);
                    QE.mdQuad.normals.Add(meshDraft_Sphere.normals[meshDraft_Sphere.triangles[idx_runner + 2]]);
                    QE.mdQuad.normals.Add(meshDraft_Sphere.normals[meshDraft_Sphere.triangles[idx_runner + 5]]);

                    QE.mdQuad.uv.Add(new Vector2(0f,1f));
                    QE.mdQuad.uv.Add(new Vector2(0f, 0f));
                    QE.mdQuad.uv.Add(new Vector2(1f, 1f));
                    QE.mdQuad.uv.Add(new Vector2(1f, 0f));

                    QE.mdQuad.triangles.AddRange(new[] { 0,1,2,2,1,3});

                    QE.myIndex = myIdx;
                    
                    LLQuads.Add(QE);

                    //writer.WriteLine(meshDraft_Sphere.vertices[meshDraft_Sphere.triangles[idx_runner]].ToString("F3"));

                    idx_runner += 6;
                    myIdx++;

                }
                //writer.WriteLine("---------------------------");
                //currentLatitude -= latitudeSegmentAngle;
            }
            //Vector3 pt, ptcheck;

            //Vector3 ptAdd,v13;
            //int InputIdx, idx;
            //for (var ring = 1; ring < latitudeSegments; ring++)
            //{
            //    for (int i = 0; i < longitudeSegments; i++)
            //    {
            //        InputIdx = i + ring * longitudeSegments;
            //        pt = Quads[InputIdx].mdQuad.vertices[0];
            //        ptAdd = Quads[InputIdx].mdQuad.vertices[3];
            //        v13 = ptAdd - pt;

            //        pt = pt + 0.01f * v13;

            //        idx = getQuadIdx(pt);

            //        ptcheck = Quads[idx].mdQuad.vertices[0];

            //        //writer.WriteLine("Input {0} OutIdx {1} vertex =" + pt.ToString("F3"), InputIdx, idx);
            //        //writer.WriteLine("-------------ptcheck vertex =" + ptcheck.ToString("F3"));

            //    }
            //    //writer.WriteLine("---------------------------");
            //}
            //writer.Close();
        //}
    }


}

Malcolm Muggeridge

Feedback Loop – Springs

 http://www.omnido.me/armillary-sphere-02-vray-w

armillary-sphere-02-vray-c

WINDOW on Other Monitor

Windows 7 has a cool new feature that should help.  Click the icon in the taskbar to ensure that the program has focus. Then hold down the Windows key and press the right-arrow a few times. That should move the window across your screens and eventually bring it back onto the screen that is still active.

 

Getting Your Hidden Window Back with the Keyboard Trick

There’s a simple trick to get around this. First make sure you’ve alt-tabbed to the window, or clicked on it once to bring it into focus. Then right-click on the taskbar and choose Move.

Note: If you’re using Windows 8 or 10 you might have to hold down the SHIFT key before right-clicking in order to get the Move menu item to show up.

At this point, you should notice that your cursor changes to the “Move” cursor, but you still can’t move anything.

Just hit any one of the arrow keys (Left, Right, Down, Up), move your mouse, and the window should magically “pop” back onto the screen.

Note: For keyboard savvy people, you can just alt-tab to the window, use Alt+Space, then M, then Arrow key, and then move your mouse.


namespace VRTK
{
    using UnityEngine;

    public class VRTK_SimplePointer : VRTK_WorldPointer
    {
        public float pointerThickness = 0.002f;
        public float pointerLength = 100f;
        public bool showPointerTip = true;
        public GameObject customPointerCursor;
        public LayerMask layersToIgnore = Physics.IgnoreRaycastLayer;

        private GameObject pointerHolder;
        private GameObject pointer;
        private GameObject pointerTip;
        private Vector3 pointerTipScale = new Vector3(0.05f, 0.05f, 0.05f);

        // material of customPointerCursor (if defined)
        private Material customPointerMaterial;

        protected override void OnEnable()
        {
            base.OnEnable();
            InitPointer();
        }

        protected override void OnDisable()
        {
            base.OnDisable();
            if (pointerHolder != null)
            {
                Destroy(pointerHolder);
            }
        }

        protected override void Update()
        {
            base.Update();
            if (pointer.gameObject.activeSelf)
            {
                Ray pointerRaycast = new Ray(transform.position, transform.forward);
                RaycastHit pointerCollidedWith;
                var rayHit = Physics.Raycast(pointerRaycast, out pointerCollidedWith, pointerLength, ~layersToIgnore);
                var pointerBeamLength = GetPointerBeamLength(rayHit, pointerCollidedWith);
                SetPointerTransform(pointerBeamLength, pointerThickness);
            }
        }

        protected override void InitPointer()
        {
            pointerHolder = new GameObject(string.Format("[{0}]WorldPointer_SimplePointer_Holder", gameObject.name));
            Utilities.SetPlayerObject(pointerHolder, VRTK_PlayerObject.ObjectTypes.Pointer);
            pointerHolder.transform.parent = transform;
            pointerHolder.transform.localPosition = Vector3.zero;

            pointer = GameObject.CreatePrimitive(PrimitiveType.Cube);
            pointer.transform.name = string.Format("[{0}]WorldPointer_SimplePointer_Pointer", gameObject.name);
            Utilities.SetPlayerObject(pointer, VRTK_PlayerObject.ObjectTypes.Pointer);
            pointer.transform.parent = pointerHolder.transform;

            pointer.GetComponent<BoxCollider>().isTrigger = true;
            pointer.AddComponent<Rigidbody>().isKinematic = true;
            pointer.layer = LayerMask.NameToLayer("Ignore Raycast");

            if (customPointerCursor == null)
            {
                pointerTip = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                pointerTip.transform.localScale = pointerTipScale;
            }
            else
            {
                Renderer renderer = customPointerCursor.GetComponentInChildren<MeshRenderer>();
                if (renderer)
                {
                    customPointerMaterial = Material.Instantiate(renderer.sharedMaterial);
                }
                pointerTip = Instantiate(customPointerCursor);
                foreach (Renderer mr in pointerTip.GetComponentsInChildren<Renderer>())
                {
                    mr.material = customPointerMaterial;
                }
            }

            pointerTip.transform.name = string.Format("[{0}]WorldPointer_SimplePointer_PointerTip", gameObject.name);
            Utilities.SetPlayerObject(pointerTip, VRTK_PlayerObject.ObjectTypes.Pointer);
            pointerTip.transform.parent = pointerHolder.transform;

            pointerTip.GetComponent<Collider>().isTrigger = true;
            pointerTip.AddComponent<Rigidbody>().isKinematic = true;
            pointerTip.layer = LayerMask.NameToLayer("Ignore Raycast");

            base.InitPointer();

            SetPointerTransform(pointerLength, pointerThickness);
            TogglePointer(false);
        }

        protected override void SetPointerMaterial()
        {
            base.SetPointerMaterial();
            pointer.GetComponent<Renderer>().material = pointerMaterial;
            if (customPointerMaterial != null)
            {
                customPointerMaterial.color = pointerMaterial.color;
            }
            else
            {
                pointerTip.GetComponent<Renderer>().material = pointerMaterial;
            }
        }

        protected override void TogglePointer(bool state)
        {
            state = (pointerVisibility == pointerVisibilityStates.Always_On ? true : state);
            base.TogglePointer(state);
            pointer.gameObject.SetActive(state);

            var tipState = (showPointerTip ? state : false);
            pointerTip.gameObject.SetActive(tipState);

            if (pointer.GetComponent<Renderer>() && pointerVisibility == pointerVisibilityStates.Always_Off)
            {
                pointer.GetComponent<Renderer>().enabled = false;
            }
        }

        private void SetPointerTransform(float setLength, float setThicknes)
        {
            //if the additional decimal isn't added then the beam position glitches
            var beamPosition = setLength / (2 + 0.00001f);

            pointer.transform.localScale = new Vector3(setThicknes, setThicknes, setLength);
            pointer.transform.localPosition = new Vector3(0f, 0f, beamPosition);
            pointerTip.transform.localPosition = new Vector3(0f, 0f, setLength - (pointerTip.transform.localScale.z / 2));
            pointerHolder.transform.localRotation = Quaternion.identity;
            base.SetPlayAreaCursorTransform(pointerTip.transform.position);
        }

        private float GetPointerBeamLength(bool hasRayHit, RaycastHit collidedWith)
        {
            var actualLength = pointerLength;

            //reset if beam not hitting or hitting new target
            if (!hasRayHit || (pointerContactTarget && pointerContactTarget != collidedWith.transform))
            {
                if (pointerContactTarget != null)
                {
                    base.PointerOut();
                }

                pointerContactDistance = 0f;
                pointerContactTarget = null;
                destinationPosition = Vector3.zero;

                UpdatePointerMaterial(pointerMissColor);
            }

            //check if beam has hit a new target
            if (hasRayHit)
            {
                pointerContactDistance = collidedWith.distance;
                pointerContactTarget = collidedWith.transform;
                destinationPosition = pointerTip.transform.position;

                UpdatePointerMaterial(pointerHitColor);

                base.PointerIn();
            }

            //adjust beam length if something is blocking it
            if (hasRayHit && pointerContactDistance < pointerLength)
            {
                actualLength = pointerContactDistance;
            }

            return actualLength;
        }
    }
}

 

dfhjhhjfh

dfghgfhd1