Example #1
0
        /*private void DrawBranchPoints(Color color)
         * {
         *      ivyInfo = (IvyInfo)target;
         *      Handles.color = color;
         *
         *      RTBakedIvy bakedIvy = ivyInfo.GetComponent<RTBakedIvy>();
         *
         *      BranchContainer branch = bakedIvy.ivyContainer.branches[1];
         *
         *      //BranchContainer currentBranch = ivyInfo.infoPool.ivyContainer.branches[i];
         *      Handles.color = Color.blue;
         *      Handles.CubeHandleCap(0, branch.branchPoints[0].point, Quaternion.identity, 0.0025f, EventType.Repaint);
         *      for (int j = 1; j < branch.branchPoints.Count; j++)
         *      {
         *              Handles.color = color;
         *              Handles.CubeHandleCap(0, branch.branchPoints[j].point, Quaternion.identity, 0.0025f, EventType.Repaint);
         *      }
         *
         * }*/

        private void DrawBuildingMesh(Color color)
        {
            ivyInfo       = (IvyInfo)target;
            Handles.color = color;


            RuntimeBakedIvy bakedIvy = ivyInfo.GetComponent <RuntimeBakedIvy>();



            if (bakedIvy != null && bakedIvy.meshBuilder != null)
            {
                RTMeshData meshData    = bakedIvy.meshBuilder.buildingMeshData;
                int        maxVertices = meshData.VertexCount();
                int        initIndex   = meshData.VertexCount() - 200;
                initIndex = Mathf.Clamp(initIndex, 0, int.MaxValue);

                maxVertices = Mathf.Clamp(maxVertices, 0, 100);

                for (int i = 0; i < meshData.VertexCount(); i++)
                {
                    Vector3 pos = ivyInfo.transform.TransformPoint(meshData.vertices[i]);

                    Handles.CubeHandleCap(0, pos, Quaternion.identity, 0.0025f, EventType.Repaint);


                    Handles.Label(pos, "" + i);
                }
            }


            //ivyMesh.vertices.Length - 25
        }
Example #2
0
        private void DrawProcessedMeshVertices(Color[] colorPerBranch)
        {
            ivyInfo = (IvyInfo)target;



            RuntimeBakedIvy bakedIvy = ivyInfo.GetComponent <RuntimeBakedIvy>();

            RTMeshData         processedMeshData        = bakedIvy.meshBuilder.processedMeshData;
            List <List <int> > verticesIndicesPerBranch = bakedIvy.meshBuilder.processedVerticesIndicesPerBranch;
            int verticesPerLoop = bakedIvy.meshBuilder.ivyParameters.sides + 1;

            int initIndex = verticesIndicesPerBranch.Count - (verticesPerLoop * 4);

            initIndex = Mathf.Clamp(initIndex, 0, int.MaxValue);

            Handles.color = Color.yellow;
            for (int j = 0; j < bakedIvy.meshBuilder.processedMeshData.VertexCount(); j++)
            {
                Vector3 vertex = bakedIvy.meshBuilder.processedMeshData.vertices[j];
                Vector3 pos    = ivyInfo.transform.TransformPoint(vertex);
                Handles.CubeHandleCap(0, pos, Quaternion.identity, 0.01f, EventType.Repaint);
            }



            for (int j = 0; j < verticesIndicesPerBranch[verticesIndicesPerBranch.Count - 1].Count; j++)
            {
                int     index = verticesIndicesPerBranch[verticesIndicesPerBranch.Count - 1][j];
                Vector3 pos   = ivyInfo.transform.TransformPoint(processedMeshData.vertices[index]);
                Handles.CubeHandleCap(0, pos, Quaternion.identity, 0.01f, EventType.Repaint);
            }
        }
        private void OnSelectionChanged()
        {
            GameObject activeGameObject = Selection.activeGameObject;

            if (activeGameObject != null)
            {
                IvyInfo ivyInfo = activeGameObject.GetComponent <IvyInfo>();

                if (ivyInfo != null)
                {
                    ModifyIvy(ivyInfo);
                }
                else
                {
                    currentIvyInfo = null;
                }
            }
            else
            {
                if (ivyGO == null)
                {
                    infoPool.ivyContainer.Clear();
                    CreateNewIvy();
                }

                currentIvyInfo = null;
            }
        }
 public void OnScriptReloaded(IvyPreset selectedPreset)
 {
     if (Selection.activeGameObject == null)
     {
         CreateNewIvy(selectedPreset);
     }
     else
     {
         IvyInfo selectedIvyInfo = Selection.activeGameObject.GetComponent <IvyInfo>();
         if (selectedIvyInfo != null)
         {
             ModifyIvy(selectedIvyInfo);
         }
     }
 }
Example #5
0
        public override void OnInspectorGUI()
        {
            GUILayout.Space(12f);
            GUILayoutUtility.GetRect(0f, 38f);
            Rect texRect = new Rect(GUILayoutUtility.GetLastRect().width / 2 - 70f, GUILayoutUtility.GetLastRect().y, 151f, 38f);

            GUI.DrawTexture(texRect, logo);
            GUILayout.Space(10f);
            EditorGUILayout.HelpBox("This component holds the information for further editability of the Ivy.\r\n\r\nThe performance cost of this component is minimum, " +
                                    "but you can remove it if you want and the mesh will be preserved in the current state.", MessageType.Info);
            GUILayout.Space(5f);
            if (GUILayout.Button("Edit in Real Ivy Editor"))
            {
                IvyInfo ivyInfo = (IvyInfo)target;
                RealIvyWindow.Init();
                RealIvyWindow.controller.ModifyIvy(ivyInfo);
            }
            GUILayout.Space(5f);
        }
Example #6
0
        private void DrawBranchVertices(Color color)
        {
            ivyInfo       = (IvyInfo)target;
            Handles.color = color;


            RuntimeBakedIvy bakedIvy = ivyInfo.GetComponent <RuntimeBakedIvy>();

            //Mesh ivyMesh = bakedIvy.meshFilter.mesh;


            //ivyMesh.vertices.Length - 25
            for (int i = 0; i < bakedIvy.meshBuilder.buildingMeshData.VertexCount(); i++)
            {
                Vector3 pos = ivyInfo.transform.TransformPoint(bakedIvy.meshBuilder.buildingMeshData.vertices[i]);

                Handles.CubeHandleCap(0, pos, Quaternion.identity, 0.01f, EventType.Repaint);
            }
        }
        public void ModifyIvy(IvyInfo ivyInfo)
        {
            this.currentIvyInfo = ivyInfo;
            this.selectedPreset = ivyInfo.originalPreset;

            this.infoPool = ivyInfo.infoPool;
            this.infoPool.ivyContainer.ivyGO = ivyInfo.gameObject;

            this.mf    = ivyInfo.meshFilter;
            this.mr    = ivyInfo.meshRenderer;
            this.ivyGO = ivyInfo.gameObject;

            this.infoPool.growth.growing = false;

            this.infoPool.ivyParameters.branchesMaterial = this.mr.sharedMaterials[0];

            ivyParametersGUI.CopyFrom(infoPool.ivyParameters);

            infoPool.meshBuilder.InitLeavesData();
        }
        public void CreateIvyGO(Vector3 position, Vector3 normal)
        {
            ivyGO = new GameObject();
            ivyGO.transform.position = position + normal * infoPool.ivyParameters.minDistanceToSurface;
            ivyGO.transform.rotation = Quaternion.LookRotation(normal);
            ivyGO.transform.RotateAround(ivyGO.transform.position, ivyGO.transform.right, 90f);
            ivyGO.name = "New Ivy";
            //Selection.activeGameObject = ivyGO;

            infoPool.ivyContainer.ivyGO = ivyGO;
            infoPool.growth.origin      = ivyGO.transform.position;

            mr = ivyGO.AddComponent <MeshRenderer>();
            Material[] materials = new Material[1];
            materials[0]       = infoPool.ivyParameters.branchesMaterial;
            mr.sharedMaterials = materials;

            mf = ivyGO.AddComponent <MeshFilter>();



            IvyInfo ivyInfo = ivyGO.AddComponent <IvyInfo>();

            ivyInfo.Setup(infoPool, mf, mr, selectedPreset);



            ModifyIvy(ivyInfo);

            infoPool.ivyContainer.RecordCreated();

            if (OnIvyGoCreated != null)
            {
                OnIvyGoCreated();
            }
        }