Ejemplo n.º 1
0
 public static Vector3[] Createvertices(byte[,,] m_voxels, VoxelChunk chunk, int lod)
 {
     Vector3[] vertices = MarchingCubes.CreateVertices(m_voxels, chunk, 2, 2, lod);
     return(vertices);
 }
Ejemplo n.º 2
0
        public void Initialize()
        {
            ActiveChunks     = new List <VoxelChunk>();
            MeshChunks       = new Queue <VoxelChunk>();
            GenerateVertices = new Queue <VoxelChunk>();
            GenerateVoxels   = new Queue <VoxelChunk>();
            EditedChunks     = new Queue <VoxelChunk>();
            Trash            = new Queue <VoxelChunk>();
            Createvertices   = new Queue <myAction>();
            EditedActions    = new Queue <myAction>();
            m_voxelChunk     = new DoubleKeyDictionary <Vector3, Vector3, VoxelChunk>();
            if (UseOrignalShader)
            {
                m_material.SetTexture("_TextureOne", textures[0]);
                m_material.SetTexture("_TextureTwo", textures[1]);
                m_material.SetTexture("_TextureThree", textures[2]);
                m_material.SetTexture("_TextureFour", textures[3]);
                m_material.SetTexture("_TextureOneN", Normals[0]);
                m_material.SetTexture("_TextureTwoN", Normals[1]);
                m_material.SetTexture("_TextureThreeN", Normals[2]);
                m_material.SetTexture("_TextureFourN", Normals[3]);
            }
            if (Grass.Length > 0)
            {
                for (int i = 0; i < Grass.Length; i++)
                {
                    GameObject gameo = Instantiate(Grass[i], new Vector3(0, 10000, 0), Quaternion.identity) as GameObject;
                    Grass[i] = gameo;
                }
            }


            if (Zone == null)
            {
                Debug.LogError("No WindZone detected will attempt to find one in the scene");
                Zone = GameObject.FindObjectOfType <WindZone>();
                if (Zone == null)
                {
                    Debug.LogError("No WindZone Found Please add one to the scene");
                }
            }
            for (int i = 0; i < Trees.Length; i++)
            {
                if (Trees[i] == null)
                {
                    Debug.LogError("One Tree in the array is null please fix and start again ");
                    return;
                }
            }
            for (int i = 0; i < Grass.Length; i++)
            {
                if (Grass[i] == null)
                {
                    Debug.LogError("One Grass mesh in the array is null please fix and start again ");
                    return;
                }
            }
            if (Grass.Length == 0)
            {
                HasGrass = false;
            }
            else
            {
                HasGrass = true;
            }

            if (Trees.Length == 0)
            {
                HasTrees = false;
            }
            else
            {
                HasTrees = true;
            }

            if (Grass.Length != GrassWeights.Length && HasGrass)
            {
                Debug.LogError("Grass Length does not equal GrassWeights Length , will assign the extra weights to 0");
                float[] grassW = GrassWeights;
                GrassWeights = new float[Grass.Length];
                for (int i = 0; i < GrassWeights.Length; i++)
                {
                    if (i < grassW.Length)
                    {
                        GrassWeights[i] = grassW[i];
                    }
                    else
                    {
                        GrassWeights[i] = 0;
                    }
                }
            }
            if (GrassWeights.Length > 0 && HasGrass == false)
            {
                GrassWeights = null;
            }

            Generator = this;

            Parent = transform;

            VoxelChunk.parent = transform;

            VoxelChunk.generator = Generator;

            MeshFactory.generator = Generator;

            MeshFactory.MakeCaves = MakeCaves;

            MarchingCubes.SetTarget(126);

            MarchingCubes.SetWindingOrder(0, 1, 2);

            CanGenerate = true;
            if (thread == null)
            {
                thread = new Thread[Environment.ProcessorCount];
            }
            for (int i = 0; i < thread.Length; i++)
            {
                if (thread[i] != null)
                {
                    thread[i].Abort();
                }
            }


            StartThreads();
        }