Example #1
0
        // Use this for initialization
        void Awake()
        {
            associatedChunkMeshCluster = null;
            generateMeshWorkFunction   = new BatchProcessor.WorkFunction(GenerateMeshThread);
            meshGenerationState        = MeshGenerationState.Waiting;

            verticesList  = new List <Vector3>();
            uvList        = new List <Vector2>();
            trianglesList = new List <int>();
            normalsList   = new List <Vector3>();
            colorList     = new List <Color32>();

            rendererType = RendererType.Solid;

            // Load up our mesh double buffering
            activeMesh          = 0;
            meshes              = new Mesh[2];
            rendererGameObjects = new GameObject[2];
            int index = 0;

            foreach (Transform child in transform)
            {
                rendererGameObjects[index] = child.gameObject;
                rendererGameObjects[index].SetActive(false);
                meshes[index] = child.gameObject.GetComponent <MeshFilter>().mesh;
                meshes[index].Clear();
                index++;
            }
        }
Example #2
0
        public void IterateOnFinishishingMeshGeneration()
        {
            if (meshGenerationState == MeshGenerationState.Waiting)
            {
                meshGenerationState = MeshGenerationState.SettingVertices;
            }

            if (verticesList.Count > 0)
            {
                Mesh mesh = GetInactiveMesh();
                if (meshGenerationState == MeshGenerationState.SettingVertices)
                {
                    mesh.vertices = verticesList.ToArray();
                    mesh.colors32 = colorList.ToArray();
                    int inactiveMesh = (activeMesh == 0 ? 1 : 0);
                    SetRendererToCurrentRendererType(inactiveMesh);
                    meshGenerationState = MeshGenerationState.SettingTriangles;
                }
                else if (meshGenerationState == MeshGenerationState.SettingTriangles)
                {
                    mesh.triangles      = trianglesList.ToArray();
                    meshGenerationState = MeshGenerationState.SettingUVs;
                }
                else if (meshGenerationState == MeshGenerationState.SettingUVs)
                {
                    mesh.uv             = uvList.ToArray();
                    meshGenerationState = MeshGenerationState.SettingNormals;
                }
                else if (meshGenerationState == MeshGenerationState.SettingNormals)
                {
                    mesh.normals        = normalsList.ToArray();
                    meshGenerationState = MeshGenerationState.Optimize;
                }
                else if (meshGenerationState == MeshGenerationState.Optimize)
                {
                    mesh.RecalculateBounds();
                    mesh.Optimize();
                    mesh.UploadMeshData(false);
                    meshGenerationState = MeshGenerationState.Done;
                }
            }
            else
            {
                meshGenerationState = MeshGenerationState.Done;
            }

            if (meshGenerationState == MeshGenerationState.Done)
            {
                associatedChunkMeshCluster.SignalFinished(rendererType);
                meshGenerationState = MeshGenerationState.Waiting;

                FlipBuffers();
            }
        }