bool CheckGrassDistance(UTreeGroup group, Vector3 position, float density) { foreach (UTreeInstance ins in group.instances) { if ((ins.position - position).magnitude < density) { return(false); } } return(true); }
void DrawTrees(UTreeGroup group, Camera camera) { float start = m_Terrain.data.treeBillBoardStart; Vector3 pos = camera.transform.position - group.transform.position; Vector3 center = group.center; Vector3 proPos = new Vector3(pos.x, center.y, pos.z); if (Vector3.Distance(center, proPos) - m_MaxRadius < start) { group.instances.ToList().ForEach(ins => { ins.active = Vector3.Distance(ins.position, pos) < start; }); } }
public void AddArea(Vector3 pos, Vector3 scale, float density) { UTreeInstance instance = new UTreeInstance(pos, scale, m_TreeMesh.bounds.size); int groupIndex = GetGroupIndex(instance); UTreeGroup group = m_Groups[groupIndex]; if (CheckGrassDistance(group, instance.position, density)) { group.Add(instance); if (!m_ApplyGroup.Contains(groupIndex)) { m_ApplyGroup.Add(groupIndex); } } }
int GetGroupIndex(UTreeInstance instance) { int index = -1; for (int i = 0; i < m_Groups.Count; i++) { UTreeGroup g = m_Groups[i]; if (Vector3.Distance(instance.position, g.center) < m_MaxRadius && g.length < m_MaxVector) { index = i; break; } } if (index == -1) { m_Groups.Add(new UTreeGroup(this, instance)); index = m_Groups.Count - 1; if (!m_ApplyGroup.Contains(index)) { m_ApplyGroup.Add(index); } } return(index); }