Exemplo n.º 1
0
        public void Start()
        {
            target = Camera.main.transform;

            Cam = Camera.main;

            Player = transform.InverseTransformPoint(target.position);

            Generator = this;

            Parent = transform;

            VoxelChunk.parent = transform;

            VoxelChunk.generator = Generator;

            MeshFactory.m_surfaceLevel = m_surfaceLevel;

            MeshFactory.generator = Generator;

            m_surfacePerlin = new PerlinNoise(m_surfaceSeed);

            m_cavePerlin = new PerlinNoise(m_surfaceSeed / 2);

            MeshFactory.SurfacePerlin = m_surfacePerlin;

            MeshFactory.CavePerlin = m_cavePerlin;

            MeshFactory.MarchingCubes = new MarchingCubes();

            MeshFactory.MarchingCubesVoxels = new MarchingCubes();

            MeshFactory.MakeCaves = MakeCaves;

            Offset = new Vector3(m_voxelWidth, m_voxelHeight / 2, m_voxelLength);

            ParentPos = Parent.position;

            MarchingCubes.SetTarget(126);

            MarchingCubes.SetWindingOrder(0, 1, 2);

            CanContinue = true;
            StartCoroutine(StartThreads());
        }
Exemplo 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();
        }
Exemplo n.º 3
0
    // Use this for initialization
    void Start()
    {
        cam =Camera.main;
        player = Camera.main.transform;
        if(m_Terrain==null){
            m_Terrain = GameObject.FindObjectOfType<VoxelTerrainEngine>();
        }
            thispos = new Vector3(transform.position.x+(m_Terrain.m_voxelWidth/2)
            ,transform.position.y+(m_Terrain.m_voxelHeight/2),transform.position.z
            +(m_Terrain.m_voxelWidth/2));

            UnityEngine.Random.seed =m_Terrain.m_surfaceSeed;
            //Fill arrays with grass and trees from terrain engine
        if(maxTrees==0){

            maxTrees = m_Terrain.MaxTrees;

            maxGrass = m_Terrain.MaxGrass;

            Grass = m_Terrain.Grass;

            Trees = m_Terrain.Trees;

            GrassWeights = m_Terrain.GrassWeights;

            TreesWeights= m_Terrain.TreesWeights;
        }
            int g = Grass.Length;

            for(int t=0;t<GrassWeights.Length;t++)
            totalweights+=GrassWeights[t];

        if(mesh==null){

            mesh = new Mesh[g];

            material = new Material[g];

        for(int i =0;i < g;i++){

            mesh[i]=Grass[i].GetComponent<MeshFilter>().mesh;

            material[i]=Grass[i].GetComponent<MeshRenderer>().material;

            }}
            StartCoroutine(spawnstuff());
    }
        public void Start()
        {
            target = Camera.main.transform;

                Cam = Camera.main;

                Player = transform.InverseTransformPoint(target.position );

                Generator = this;

                Parent = transform;

                VoxelChunk.parent = transform;

                VoxelChunk.generator = Generator;

                MeshFactory.m_surfaceLevel = m_surfaceLevel;

                MeshFactory.generator = Generator;

                m_surfacePerlin = new PerlinNoise(m_surfaceSeed);

                m_cavePerlin = new PerlinNoise(m_surfaceSeed/2);

                MeshFactory.SurfacePerlin = m_surfacePerlin;

                MeshFactory.CavePerlin = m_cavePerlin;

                MeshFactory.MarchingCubes = new MarchingCubes();

                MeshFactory.MarchingCubesVoxels = new MarchingCubes();

                MeshFactory.MakeCaves = MakeCaves;

                Offset = new Vector3(m_voxelWidth, m_voxelHeight/2, m_voxelLength);

                ParentPos = Parent.position;

                MarchingCubes.SetTarget(126);

                MarchingCubes.SetWindingOrder(0, 1, 2);

                CanContinue = true;
                StartCoroutine(StartThreads());
        }