Ejemplo n.º 1
0
    public TerrainGen_Overworld(int Seed)
    {
        mNoiseGenerator = new PerlinNoise(Seed);

        // Get cached voxel ids
        vox_Air     = VoxelLibrary.GetID("air");
        vox_Dirt    = VoxelLibrary.GetID("dirt");
        vox_Grass   = VoxelLibrary.GetID("grass");
        vox_Stone   = VoxelLibrary.GetID("stone");
        vox_Water   = VoxelLibrary.GetID("water");
        vox_Bedrock = VoxelLibrary.GetID("bedrock");
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Create a new object to be using in object pool for a terrain
    /// </summary>
    public static VoxelChunk NewPoolObj(VoxelTerrain Terrain)
    {
        // Create inactive game object
        GameObject obj = new GameObject();

        obj.isStatic         = true;
        obj.transform.parent = Terrain.transform;
        obj.layer            = LayerMask.NameToLayer("Terrain");


        // Add (Initialize) component
        VoxelChunk chunk = obj.AddComponent <VoxelChunk>();

        chunk.mTerrain = Terrain;


        // Init data
        chunk.mVoxelData = new VoxelInstance[ChunkWidth, ChunkHeight, ChunkWidth];
        // Fill with air
        ushort air = VoxelLibrary.GetID("air");

        for (int x = 0; x < ChunkWidth; ++x)
        {
            for (int y = 0; y < ChunkHeight; ++y)
            {
                for (int z = 0; z < ChunkWidth; ++z)
                {
                    chunk.mVoxelData[x, y, z] = new VoxelInstance(air);
                }
            }
        }


        // Setup rendering
        {
            GameObject subObj = new GameObject("Terrain");
            subObj.isStatic         = true;
            subObj.transform.parent = obj.transform;

            chunk.mMeshTerrainFilter = subObj.AddComponent <MeshFilter>();
            MeshRenderer renderer = subObj.AddComponent <MeshRenderer>();
            renderer.sharedMaterial    = VoxelLibrary.mTerrainMaterial;
            renderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
            {
                Mesh mesh = new Mesh();
                mesh.name = "Terrain Mesh";
                mesh.MarkDynamic();
                chunk.mMeshTerrainFilter.sharedMesh = mesh;
            }
        }
        {
            GameObject subObj = new GameObject("Liquid");
            subObj.isStatic         = true;
            subObj.transform.parent = obj.transform;

            chunk.mMeshLiquidFilter = subObj.AddComponent <MeshFilter>();
            MeshRenderer renderer = subObj.AddComponent <MeshRenderer>();
            renderer.sharedMaterial    = VoxelLibrary.mLiquidMaterial;
            renderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
            {
                Mesh mesh = new Mesh();
                mesh.name = "Liquid Mesh";
                mesh.MarkDynamic();
                chunk.mMeshLiquidFilter.sharedMesh = mesh;
            }
        }


        // Setup collision
        chunk.mMeshCollider = obj.AddComponent <MeshCollider>();
        chunk.mMeshCollider.sharedMaterial = Resources.Load <PhysicMaterial>("World/Phys_Terrain");
        {
            Mesh mesh = new Mesh();
            mesh.name = "Physics Mesh";
            mesh.MarkDynamic();
            chunk.mMeshCollider.sharedMesh = mesh;
        }


        // Flag as inactive
        obj.name = "Chunk (Inactive)";
        obj.transform.position = Vector3.zero;
        obj.SetActive(false);

        return(chunk);
    }
Ejemplo n.º 3
0
 public ItemData_Material(ushort ID, ItemDataImporter Settings) : base(ID, Settings)
 {
     mVoxelMaterial = VoxelLibrary.GetID(Settings.mVoxelMaterial);
 }