private IcoSide InitializeSubdividedSide(IcoSide parent, Vector3 a, Vector3 b, Vector3 c, Vector2 uva, Vector2 uvb, Vector2 uvc) { transform.parent = parent.transform; mat = parent.mat; heightMap = parent.heightMap; player = parent.player; radius = parent.radius; inversePlanet = parent.inversePlanet; rootSide = parent; meshSubdivisionAmount = parent.meshSubdivisionAmount * 1f; depth = parent.depth + 1; maxDepth = parent.maxDepth; corners[0] = a; corners[1] = b; corners[2] = c; uvs[0] = uva; uvs[1] = uvb; uvs[2] = uvc; isSelfUpdating = parent.isSelfUpdating; InitializeValues(); CheckForSubdivision(); if (isSelfUpdating) { StartSelfUpdate(); } return(this); }
public IEnumerator CheckPlayerDistance() { yield return(new WaitForSeconds(Random.Range(0, 0.5f))); //makes each side have a slightly different time in which it updates. Also gives a sick "dissolve" effect when moving about for (;;) { float distanceToPlayer = (center - player.position).magnitude; if (!isSubdivided && depth < maxDepth && distanceToPlayer < criticalDistance) { Subdivide(this, corners[0], corners[1], corners[2], uvs[0], uvs[1], uvs[2]); } //checks if player is far enough away to un-subdivide if (isSubdivided && distanceToPlayer > criticalDistance && depth > 1) { isSubdivided = false; gameObject.GetComponent <MeshRenderer>().enabled = true; foreach (Transform child in transform) { Destroy(child.gameObject); } topSubSide = null; middleSubSide = null; leftSubSide = null; rightSubSide = null; } yield return(new WaitForSeconds(0.5f)); } }
private void Subdivide(IcoSide parent, Vector3 a, Vector3 b, Vector3 c, Vector2 uva, Vector2 uvb, Vector2 uvc) { isSubdivided = true; gameObject.GetComponent <MeshRenderer>().enabled = false; Vector3 midAB = ((a + b) / 2); Vector3 midBC = ((b + c) / 2); Vector3 midAC = ((a + c) / 2); Vector2 midUVab = ((uva + uvb) / 2); Vector2 midUVbc = ((uvb + uvc) / 2); Vector2 midUVac = ((uva + uvc) / 2); topSubSide = new GameObject("Child top D= " + (depth + 1)).AddComponent <IcoSide>().InitializeSubdividedSide(this, a, midAB, midAC, uva, midUVab, midUVac); //top leftSubSide = new GameObject("Child left D= " + (depth + 1)).AddComponent <IcoSide>().InitializeSubdividedSide(this, midAB, b, midBC, midUVab, uvb, midUVbc); //bottom left middleSubSide = new GameObject("Child Middle D= " + (depth + 1)).AddComponent <IcoSide>().InitializeSubdividedSide(this, midBC, midAC, midAB, midUVab, midUVbc, midUVac); //middle rightSubSide = new GameObject("Child Right D= " + (depth + 1)).AddComponent <IcoSide>().InitializeSubdividedSide(this, midAC, midBC, c, midUVac, midUVbc, uvc); //bottom right }
public void SetNeighbors(IcoSide left, IcoSide right, IcoSide bottom) { leftNeighbor = left; rightNeighbor = right; bottomNeighbor = bottom; }
public void UpdateNeighbors() //update all neighbor references { rightNeighbor = getRightNeighbor(); leftNeighbor = getleftNeighbor(); bottomNeighbor = getBottomNeighbor(); }