Пример #1
0
    void OnDrawGizmos()
    {
        return;

        Vector3 toCenter = (parent.transform.position - transform.position).normalized;
        Vector3 up       = Vector3.Cross(Vector3.right, toCenter).normalized;
        Vector3 right    = Vector3.Cross(toCenter, up).normalized;
        float   radius   = CURRENT_SIZE;

        //draw an icon for each group this vertex belongs to
        float angleStep = 360f / groups.Count;

        for (int i = 0; i < groups.Count; i++)
        {
            VertGroup group = groups[i];
            Gizmos.color = group.color;
            float   angle    = angleStep * i;
            float   rad      = Mathf.Deg2Rad * angle;
            float   x        = Mathf.Cos(rad) * radius;
            float   y        = Mathf.Sin(rad) * radius;
            Vector3 position = transform.position + right * x + up * y;
            Gizmos.DrawCube(position, Vector3.one * CURRENT_SIZE * .5f);
        }

        //draw the selectable cube
        Gizmos.color = color;
        selected     = Selection.Contains(this.gameObject);//IsSelected();
        if (selected)
        {
            Gizmos.color = Color.black;
        }
        Gizmos.DrawCube(transform.position, Vector3.one * CURRENT_SIZE);
    }
Пример #2
0
    private void CreateObject()
    {
        Mesh mesh = new Mesh();

        mesh.vertices  = meshVertices.ToArray();
        mesh.triangles = meshIndices.ToArray();
        mesh.colors    = meshColors.ToArray();

        VertGroup vertGroup = Instantiate(vertGroupPrefab);

        vertGroup.colors = meshColors.ToArray();

        GameObject obj = vertGroup.gameObject;

        obj.name                    = "VertGroup_" + vertIndex;
        obj.transform.parent        = EarthVertGroupParent.transform;
        obj.transform.localPosition = Vector3.zero;
        obj.transform.localRotation = Quaternion.identity;
        obj.transform.localScale    = Vector3.one;

        obj.AddComponent <MeshFilter>().mesh       = mesh;
        obj.AddComponent <MeshRenderer>().material = PointMaterial;
        obj.transform.parent = EarthVertGroupParent.transform;

        meshVertices.Clear();
        meshIndices.Clear();
        meshColors.Clear();
    }
Пример #3
0
    void Update()
    {
        // Change the size if the user requests it
        if (lastKnownSize != _size)
        {
            lastKnownSize = _size;
            CURRENT_SIZE  = _size;
        }

        // Ensure the rest of the gizmos know the size has changed...
        if (CURRENT_SIZE != lastKnownSize)
        {
            lastKnownSize = CURRENT_SIZE;
            _size         = lastKnownSize;
        }


        if (first)
        {
            Vector3 toCenter = (parent.transform.position - transform.position).normalized;
            Vector3 up       = Vector3.Cross(Vector3.right, toCenter).normalized;
            Vector3 right    = Vector3.Cross(toCenter, up).normalized;
            float   radius   = CURRENT_SIZE;

            //draw an icon for each group this vertex belongs to
            float angleStep = 360f / groups.Count;
            for (int i = 0; i < groups.Count; i++)
            {
                VertGroup group = groups[i];
                Gizmos.color = group.color;
                float   angle    = angleStep * i;
                float   rad      = Mathf.Deg2Rad * angle;
                float   x        = Mathf.Cos(rad) * radius;
                float   y        = Mathf.Sin(rad) * radius;
                Vector3 position = transform.position + right * x + up * y;

                Gizmos.DrawCube(position, Vector3.one * CURRENT_SIZE * .5f);
            }

            //draw the selectable cube
            Gizmos.color = color;
            selected     = Selection.Contains(this.gameObject); //IsSelected();
            if (selected)
            {
                Gizmos.color = Color.black;
            }
            Gizmos.DrawCube(transform.position, Vector3.one * CURRENT_SIZE);

            first = false;
        }


        if (destroy)
        {
            DestroyImmediate(parent);
        }
    }
Пример #4
0
 public bool HasGroup(VertGroup g)
 {
     foreach (VertGroup group in groups)
     {
         if (group.name == g.name)
         {
             return(true);
         }
     }
     return(false);
 }
Пример #5
0
 public VertGroup(VertGroup selectedGroup)
 {
     name        = selectedGroup.name;
     vertHandles = new List <GameObject>();
     color       = selectedGroup.color;
     foreach (GameObject vertHandle in selectedGroup.vertHandles)
     {
         vertHandles.Add(vertHandle);
         VertHandleGizmo gizmo = vertHandle.GetComponent <VertHandleGizmo>();
         gizmo.groups.Add(this);
     }
 }
Пример #6
0
    public void UpdateInfectionPointColor(InfectionPoint point)
    {
        if (point == null)
        {
            return;
        }

        Color      newColor    = Colors.Evaluate(point.Infection);
        int        objectIndex = (point.vertIndex / 65000);                                       //which object is it in
        VertGroup  vertGroup   = EarthVertGroupParent.transform.GetChild(objectIndex).GetComponent <VertGroup>();
        GameObject obj         = EarthVertGroupParent.transform.GetChild(objectIndex).gameObject; //get the object it is in
        int        indexStart  = point.vertIndex % 65000;

        Color[] colors = vertGroup.colors;
        for (int i = indexStart; i < indexStart + 20; i++)
        {
            colors[i] = newColor;
        }
        vertGroup.colors = colors;
    }
Пример #7
0
    void Update()
    {
        if (destroy)
        {
            destroy = false;
            DestroyImmediate(this);
            return;
        }



        if (groupSelected)
        {
            groupSelected = false;
            bool newGroup = true;
            //for all existing groups
            foreach (VertGroup group in groups)
            {
                //if this group has the same name as what's in the selected group
                if (group.name == selectedHandles.name)
                {
                    //this group already exists
                    newGroup = false;
                    //add any new edges to the group
                    foreach (GameObject vertHandle in selectedHandles.vertHandles)
                    {
                        if (!group.vertHandles.Contains(vertHandle))
                        {
                            group.vertHandles.Add(vertHandle);
                        }
                        //make the edge know about the group it now belongs to
                        VertHandleGizmo gizmo = vertHandle.GetComponent <VertHandleGizmo>();
                        if (!gizmo.HasGroup(group))
                        {
                            gizmo.groups.Add(group);
                        }
                    }
                    //set the group color
                    group.color = selectedHandles.color;
                }
            }
            if (newGroup)
            {
                VertGroup g = new VertGroup(selectedHandles);// selectedHandles.name, selectedHandles.edges, selectedHandles.color);
                groups.Add(g);
            }
        }

        if (removeFromGroup)
        {
            removeFromGroup = false;
            foreach (VertGroup group in groups)
            {
                if (group.name == selectedHandles.name)
                {
                    foreach (GameObject vertHandle in selectedHandles.vertHandles)
                    {
                        if (group.vertHandles.Contains(vertHandle))
                        {
                            group.vertHandles.Remove(vertHandle);
                            VertHandleGizmo gizmo = vertHandle.GetComponent <VertHandleGizmo>();
                            if (gizmo.groups.Contains(group))
                            {
                                gizmo.groups.Remove(group);
                            }
                        }
                    }
                }
            }
            CleanGroups();
        }

        if (removeFromAll)
        {
            removeFromAll = false;
            foreach (VertGroup group in groups)
            {
                foreach (GameObject vertHandle in selectedHandles.vertHandles)
                {
                    if (group.vertHandles.Contains(vertHandle))
                    {
                        group.vertHandles.Remove(vertHandle);
                        VertHandleGizmo gizmo = vertHandle.GetComponent <VertHandleGizmo>();
                        if (gizmo.groups.Contains(group))
                        {
                            gizmo.groups.Remove(group);
                        }
                    }
                }
            }
            CleanGroups();
        }


        for (int i = 0; i < verts.Length; i++)
        {
            verts[i] = handles[i].transform.localPosition;
        }
        mesh.vertices = verts;
        mesh.RecalculateBounds();
        mesh.RecalculateNormals();
    }