devNotes 4-27-16 fibonacci nodes – triangulation and meshing

prizm-32342

Prism_2

Prizm_1

Prizm_4

Prizm_5

Prizm_6

seedspiralsIMA50c (1)seedspiralsIMA50 seedspiralsIMA50b

Untitled-5

POPPIPIP

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

public class ArgosFibonacci : MonoBehaviour
{
    public float m_fRadius = 1.5f;

    public ArgosMeshDraft_Fibonacci aMF_Base = new ArgosMeshDraft_Fibonacci();
    public ArgosMeshDraft_Fibonacci aMF_Full = new ArgosMeshDraft_Fibonacci();

    StreamWriter sWrite;

    public GameObject vert_Prefab;

    public class GO_Tracker
    {
        public GameObject go;
        public FibVert fV_FuncVert;
    }

    public List<GO_Tracker> lstFIB_GO = new List<GO_Tracker>();

    void Start ()
    {
        sWrite = new StreamWriter("Argos_Fib_Voronoi.txt");

        Quaternion q;
        Vector3 vN_In;

        sphere_fibonacci_build_cartesian(2500);

        for (int i = 0; i < aMF_Base.funcVerts.Count; i++)
        {
            vN_In = aMF_Base.funcVerts[i].vPos.normalized;
            q = Quaternion.LookRotation(vN_In);
            int lev0, lev1, lev2, lev3;
            GameObject gO;
            GO_Tracker gT;

            gO = (GameObject)Instantiate(vert_Prefab, aMF_Base.funcVerts[i].vPos, q);
            gT = new GO_Tracker();
            gT.fV_FuncVert = new FibVert();
            gT.go = gO;
            gT.fV_FuncVert.vPos = aMF_Base.funcVerts[i].vPos;
            lstFIB_GO.Add(gT);

            lstFIB_GO[lstFIB_GO.Count - 1].go.GetComponentInChildren<Text>().text = i.ToString();

        }
        foreach (GO_Tracker gActedUpon in lstFIB_GO)
        {
            gActedUpon.go.transform.position = gActedUpon.fV_FuncVert.vPos;
        }


    }

    void sphere_fibonacci_build_cartesian(int num)
    {
        float fSeam = 0.5f;
        float offset = 2.0f / num;
        float increment = Mathf.PI * (3 - Mathf.Sqrt(5.0f));

        for (int i = 0; i < num; i++)
        {
            float y = (i * offset) - 1 + (offset / 2.0f);
            float r = Mathf.Sqrt(1 - Mathf.Pow(y, 2));
            float phi = ((i + fSeam) % num) * increment;
            float x = Mathf.Cos(phi) * r;
            float z = Mathf.Sin(phi) * r;

            FibVert fV = new FibVert();

            fV.vPos = new Vector3(x, y, z);
            fV.vPos *= m_fRadius;
            fV.idx = i;
            aMF_Base.funcVerts.Add(fV);
        }
    }

    void Update ()
    {
	
	}
}
using UnityEngine;
using System;
using System.Collections;
using ProceduralToolkit;
using System.Collections.Generic;

namespace ProceduralToolkit
{
    public class FibVert
    {
        public Vector3 vPos;
        public float dist;
        public Vector3 vForce; //constrain position to sphere radius
        public Vector3 vVel;
        public float maxDistToNeighbor = 0;
        public float minDistToNeighbor = float.MaxValue;
        public int idx;

        public class NB
        {
            public FibVert fV;
            public float distFrom;

            public NB()
            {
                fV = null;
                distFrom = float.MaxValue;
            }
        }

        public List<NB> avNeigbor = new List<NB>();

        public FibVert()
        {
            for (int i = 0; i < 6; i++)
            {
                avNeigbor.Add(new NB());
                avNeigbor[i].fV = this;
            }
            vPos = new Vector3();
        }

        public float getMaxDistToNeighbor()
        {
            maxDistToNeighbor = 0;
            for (int i = 0; i < 6; i++)
            {
                if (avNeigbor[i].distFrom > maxDistToNeighbor)
                {
                    maxDistToNeighbor = avNeigbor[i].distFrom;
                }
            }
            return maxDistToNeighbor;
        }

        public float getMinDistToNeighbor()
        {
            minDistToNeighbor = float.MaxValue;
            for (int i = 0; i < 6; i++)
            {
                if (avNeigbor[i].distFrom < minDistToNeighbor)
                {
                    minDistToNeighbor = avNeigbor[i].distFrom;
                }
            }
            return minDistToNeighbor;

        }

        public bool isAVinNeighborList(FibVert fV)
        {
            for (int i = 0; i < 6; i++)
            {
                if (avNeigbor[i].fV == fV) return true;
            }
            return false;
        }

        public int isLessThan(float dist)
        {
            for (int i = 0; i < 6; i++)
            {
                if (dist < avNeigbor[i].distFrom) return i;
            }
            return -1;
        }

        public bool goesHere(int i, float dist, FibVert aV_Contender)
        {
            if (dist < avNeigbor[i].distFrom)
            {

                NB nb = new NB();
                nb.fV = aV_Contender;
                nb.distFrom = dist;
                avNeigbor.Insert(i, nb);
                avNeigbor.RemoveAt(6);
                return true;
            }
            return false;
        }


        public void insNeighbor_One_Shot(float dist, FibVert aV_Contender)
        {
            for (int i = 0; i < 6; i++)
            {
                if (goesHere(i, dist, aV_Contender)) return;
            }
        }
    }

    public class ArgosMeshDraft_Fibonacci : MeshDraft
    {
        public List<Vector3> vTriCenter = new List<Vector3>();
        public List<int> vQual = new List<int>();
        public List<FibVert> funcVerts = new List<FibVert>();

        public ArgosMeshDraft_Fibonacci() : base()
        {

        }

        public void Add_ITN_Node(MeshDraft tri, int sector, int nodePath, int ITG_idx)
        {
            Vector3 vC = (tri.vertices[0] + tri.vertices[1] + tri.vertices[2]) / 3f;

            FibVert fV = new FibVert();

            fV.vPos = vC;
            fV.idx = ITG_idx;

            funcVerts.Add(fV);
        }

        public void SetSortDist(Vector3 Apex)
        {
            foreach (FibVert fV in funcVerts)
            {
                fV.dist = (fV.vPos - Apex).magnitude;
            }
        }

        public void sortPointCloud()
        {
            funcVerts.Sort((x, y) => x.dist.CompareTo(y.dist));
        }

        public void AddTriQual(MeshDraft tri)
        {
            Vector3 vC = (tri.vertices[0] + tri.vertices[1] + tri.vertices[2]) / 3f;
            Add(tri);

            for (int i = 0; i < 3; i++)//Track the quality of the triangle UVs
            {
                vTriCenter.Add(vC);
                //vQual.Add(qual);
            }
        }

        public void AddHex(MeshDraft tri)//from triangle see: http://argos.vu/wp-content/uploads/2016/04/HCs-1.png
        {
            Vector3 HC = (tri.vertices[0] + tri.vertices[1] + tri.vertices[2]) / 3f;

            Vector3 H0 = (tri.vertices[1] + tri.vertices[0]) / 2f;

            Vector3 H1 = (tri.vertices[1] + HC) / 2f;

            Vector3 H2 = (tri.vertices[2] + tri.vertices[1]) / 2f;

            Vector3 H3 = (tri.vertices[2] + HC) / 2f;

            Vector3 H4 = (tri.vertices[0] + tri.vertices[2]) / 2f;

            Vector3 H5 = (tri.vertices[0] + HC) / 2f;

            List<Vector3> vL = new List<Vector3>(8) { HC, H0, H1, H2, H3, H4, H5, H0 };

            List<Vector2> uvMapL = new List<Vector2>(8) { new Vector2(0.5f, 0.5f), new Vector2(0.5f, 1f), new Vector2(1, 0.75f), new Vector2(1, 0.25f), new Vector2(0.5f, 0), new Vector2(0, 0.25f), new Vector2(0, 0.75f), new Vector2(0.5f, 1f) };

            Add(HexFan(vL, uvMapL));
        }

        public void AddTriQual(MeshDraft tri, int qual)
        {
            Vector3 vC = (tri.vertices[0] + tri.vertices[1] + tri.vertices[2]) / 3f;

            Add(tri);

            for (int i = 0; i < 3; i++)//Track the quality of the triangle UVs
            {
                vTriCenter.Add(vC);
                vQual.Add(qual);
            }
        }
    }
}

 

fib_1

dfnfhnfh

fghjhgfjfhj

dfhjfhj

Voronio_4_27_16_Baked

dgfhdgfhgfdhg