예제 #1
0
    void Start()
    {
        Texture2D atlas    = GetTextureAtlas();
        Material  material = new Material(Shader.Find("Standard"));

        atlas.filterMode     = FilterMode.Point;
        material.mainTexture = atlas;;
        /*material.SetTexture("_BaseColorMap", atlas);*/
        material.SetFloat("_Metallic", 0f);
        material.SetFloat("_Glossiness", 0f);
        blockMaterial[0] = material;

        Texture2D transparentAtlas = GetTextureAtlas(true);

        transparentAtlas.filterMode = FilterMode.Point;

        Material transparentMaterial = new Material(Shader.Find("Unlit/Transparent"));

        transparentAtlas.alphaIsTransparency = true;
        //player.SetActive(false);

        transparentMaterial.mainTexture = transparentAtlas;
        blockMaterial[1] = transparentMaterial;


        // Application.targetFrameRate = 70;
        // RenderSettings.ambientLight = Color.white * lightIntensity;
        ChunkUtils.GenerateRandomOffset();
        GenerateBlockTypes();
        GenerateWorld();
        StartCoroutine(BuildWorld());
    }
예제 #2
0
파일: Biome.cs 프로젝트: MAK-9/MakuCraft
 protected virtual void GenerateTerrainValues(float x, float y, float z)
 {
     typeProbabilty     = ChunkUtils.CalculateBlockProbability(x, y, z, typeIncrement);
     generated1stLayerY = (int)ChunkUtils.Generate1stLayerHeight(x, z, firstLayerIncrement);
     generated2ndLayerY =
         (int)ChunkUtils.Generate2ndLayerHeight(x, z, generated1stLayerY, secondLayerIncrement);
 }
예제 #3
0
        // Gradient Fills
        //public override void DrawGradientRectangle(GradientRect gRect)
        //{
        //    BufferChunk chunk = new BufferChunk(1024);
        //    chunk += GDI32.EMR_GRADIENTFILL;

        //    // Pack the vertices
        //    ChunkUtils.Pack(chunk, gRect.Vertices);

        //    // Pack the gradient mesh
        //    ChunkUtils.Pack(chunk, gRect.Boundary);

        //    // pack the mode
        //    chunk += (int)gRect.Direction;

        //    SendCommand(chunk);
        //}

        /// DrawEllipse
        ///
        public override void DrawEllipse(IPen aPen, Rectangle rect)
        {
            BufferChunk chunk = new BufferChunk(128);

            chunk += GDI32.EMR_ELLIPSE;
            ChunkUtils.Pack(chunk, rect.X, rect.Y, rect.Width, rect.Height);

            SendCommand(chunk);
        }
예제 #4
0
        // Draw a Polygon
        public override void Polygon(Point[] points)
        {
            BufferChunk chunk = new BufferChunk(points.Length * 8 + 16);

            chunk += GDI32.EMR_POLYGON;

            ChunkUtils.Pack(chunk, points);

            SendCommand(chunk);
        }
예제 #5
0
        // Drawing Primitives
        /// Our first pass will be to implement everything as
        /// taking explicit int parameters.
        /// We'll assume that drawing with a different pen will
        /// be accomplished by setting the Pen property on the
        /// port before drawing.  This will keep our API count
        /// low and alleviate the need to pass the same
        /// parameter every time.  We can add more later.
        ///
        public override void SetPixel(int x, int y, Color colorref)
        {
            BufferChunk chunk = new BufferChunk(128);

            chunk += GDI32.EMR_SETTEXTCOLOR;
            ChunkUtils.Pack(chunk, x, y);
            chunk += colorref.ToArgb();

            SendCommand(chunk);
        }
예제 #6
0
 public BaseBlock GetBlock(Vector3Int pos)
 {
     if (ChunkUtils.IsInChunkBounds(pos, ChunkSize))
     {
         return(Blocks[pos.x, pos.y, pos.z]);
     }
     else
     {
         throw new Exception("Position out of chunk bounds: " + pos.ToString());
     }
 }
예제 #7
0
    void Start()
    {
        Texture2D atlas    = GetTextureAtlas();
        Material  material = new Material(Shader.Find("Standard"));

        material.mainTexture = atlas;
        blockMaterial        = material;
        ChunkUtils.GenerateRandomOffset();
        GenerateBlockTypes();
        GenerateWorld();
        StartCoroutine(BuildWorld(true));
    }
예제 #8
0
        public override void DrawString(int x, int y, string aString)
        {
            BufferChunk chunk = new BufferChunk(128);

            chunk += GDI32.EMR_EXTTEXTOUTW;
            ChunkUtils.Pack(chunk, x, y);
            chunk += aString.Length;
            chunk += aString;
            //chunk += GDI32.GM_ADVANCED;

            SendCommand(chunk);
        }
예제 #9
0
        public override void DrawRoundRect(IPen aPen, Rectangle rect, int xRadius, int yRadius)
        {
            BufferChunk chunk = new BufferChunk(128);

            chunk += GDI32.EMR_ROUNDRECT;
            ChunkUtils.Pack(chunk, rect.X, rect.Y, rect.Width, rect.Height);
            ChunkUtils.Pack(chunk, xRadius, yRadius);

            ChunkUtils.Pack(chunk, aPen);

            SendCommand(chunk);
        }
예제 #10
0
        //public override void DrawBezier(GDIPen aPen, Point[] points)
        //{
        //    BufferChunk chunk = new BufferChunk(points.Length * 8 + 16);
        //    chunk += GDI32.EMR_POLYBEZIER;

        //    Pack(chunk, points);

        //    SendCommand(chunk);
        //}

        public override void DrawLine(IPen aPen, Point startPoint, Point endPoint)
        {
            BufferChunk chunk = new BufferChunk(1024);

            chunk += GDI32.EMR_LINETO;
            ChunkUtils.Pack(chunk, startPoint);
            ChunkUtils.Pack(chunk, endPoint);

            // Pack the pen
            ChunkUtils.Pack(chunk, aPen);

            SendCommand(chunk);
        }
예제 #11
0
        public override void DrawLines(IPen aPen, Point[] points)
        {
            BufferChunk chunk = new BufferChunk(points.Length * 8 + 128);

            chunk += GDI32.EMR_POLYLINE;

            // Pack the pen
            ChunkUtils.Pack(chunk, aPen);

            // Pack the points
            ChunkUtils.Pack(chunk, points);


            SendCommand(chunk);
        }
예제 #12
0
        // Generalized bit block transfer
        public override void PixBlt(PixelArray pixBuff, int x, int y)
        {
            // Create a buffer
            // It has to be big enough for the bitmap data, as well as the x,y, and command
            int         dataSize = pixBuff.BytesPerRow * pixBuff.Height;
            BufferChunk chunk    = new BufferChunk(dataSize + 128);

            // now put the basic command and simple components in
            chunk += GDI32.EMR_BITBLT;
            ChunkUtils.Pack(chunk, x, y);
            ChunkUtils.Pack(chunk, pixBuff.Width, pixBuff.Height);
            chunk += dataSize;

            // Finally, copy in the data
            chunk.CopyFrom(pixBuff.PixelData, dataSize);

            SendCommand(chunk);
        }
예제 #13
0
        public override void DrawPath(IPen aPen, GPath aPath)
        {
            BufferChunk chunk = new BufferChunk(aPath.Vertices.Length * 8 + 128);

            chunk += GDI32.EMR_POLYDRAW;

            ChunkUtils.Pack(chunk, aPath.Vertices);


            for (int i = 0; i < aPath.Vertices.Length; i++)
            {
                chunk += aPath.Commands[i];
            }

            // Pack the pen
            ChunkUtils.Pack(chunk, aPen);

            SendCommand(chunk);
        }
예제 #14
0
    void Start()
    {
        Texture2D atlas    = GetTextureAtlas();
        Material  material = new Material(Shader.Find("Standard"));

        material.mainTexture = atlas;
        blockMaterial[0]     = material;

        Texture2D transparentAtlas    = GetTextureAtlas(true);
        Material  transparentMaterial = new Material(Shader.Find("Unlit/Transparent"));

        transparentMaterial.mainTexture = transparentAtlas;
        blockMaterial[1] = transparentMaterial;

        ChunkUtils.GenerateRandomOffset();
        GenerateBlockTypes();
        GenerateWorld();
        StartCoroutine(BuildWorld());
    }
예제 #15
0
    public static bool IsBlockVisible(Vector3Int vec, BaseBlock[,,] blocks, int chunkSize)
    {
        Vector3Int right = new Vector3Int(vec.x + 1, vec.y, vec.z);
        Vector3Int left  = new Vector3Int(vec.x - 1, vec.y, vec.z);
        Vector3Int above = new Vector3Int(vec.x, vec.y + 1, vec.z);
        Vector3Int below = new Vector3Int(vec.x, vec.y - 1, vec.z);
        Vector3Int front = new Vector3Int(vec.x, vec.y, vec.z + 1);
        Vector3Int back  = new Vector3Int(vec.x, vec.y, vec.z - 1);

        if (!ChunkUtils.IsInChunkBounds(vec, chunkSize))
        {
            throw new Exception("Position out of chunk bounds: " + vec.ToString());
        }
        else
        {
            if (!ChunkUtils.IsInChunkBounds(right, chunkSize) ||
                !ChunkUtils.IsInChunkBounds(left, chunkSize) ||
                !ChunkUtils.IsInChunkBounds(above, chunkSize) ||
                !ChunkUtils.IsInChunkBounds(below, chunkSize) ||
                !ChunkUtils.IsInChunkBounds(front, chunkSize) ||
                !ChunkUtils.IsInChunkBounds(back, chunkSize))
            {
                return(true);
            }
            else if (blocks[right.x, right.y, right.z].Transparent ||
                     blocks[left.x, left.y, left.z].Transparent ||
                     blocks[above.x, above.y, above.z].Transparent ||
                     blocks[below.x, below.y, below.z].Transparent ||
                     blocks[front.x, front.y, front.z].Transparent ||
                     blocks[back.x, back.y, back.z].Transparent)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
    }
예제 #16
0
    public List <Vector3Int> cull(Chunk chunk)
    {
        List <Vector3Int> culled = new List <Vector3Int>();

        int chunkSize = chunk.ChunkSize;

        for (int z = 0; z < chunk.ChunkSize; z++)
        {
            for (int y = 0; y < chunk.ChunkSize; y++)
            {
                for (int x = 0; x < chunk.ChunkSize; x++)
                {
                    //Vector3Int pos = new Vector3Int(x, y, z);
                    if (ChunkUtils.IsBlockVisible(new Vector3Int(x, y, z), chunk.Blocks, chunk.ChunkSize))
                    {
                        culled.Add(new Vector3Int(x, y, z));
                    }
                }
            }
        }
        return(culled);
    }
예제 #17
0
    public static Biome SelectBiome(Vector3 chunkPos)
    {
        float temperature = ChunkUtils.GenerateTemperature(chunkPos.x / World.chunkSize, chunkPos.z / World.chunkSize);
        float moisture    = ChunkUtils.GenerateMoisture(chunkPos.x / World.chunkSize, chunkPos.z / World.chunkSize);
        Biome biome       = new DefaultBiome();

        if (temperature < 0.45f)
        {
            biome = new SnowBiome();
        }
        else
        {
            if (moisture < 0.4f && temperature > 0.6f)
            {
                biome = new DesertBiome();
            }
            else
            {
                biome = new DefaultBiome();
            }
        }
        return(biome);
    }
예제 #18
0
        public RawMesh GenerateMesh(Chunk chunk)
        {
            BaseBlock[,,] blocks = chunk.Blocks;

            List <Vector3Int> visibleBlockPositions = terrainCuller.cull(chunk);

            var mesh = initRawMesh(chunk);

            //process visible faces
            for (int a = 0; a < visibleBlockPositions.Count; a++)
            {
                int       x     = visibleBlockPositions[a].x;
                int       y     = visibleBlockPositions[a].y;
                int       z     = visibleBlockPositions[a].z;
                BaseBlock block = blocks[x, y, z];
                if (ChunkUtils.IsInsideOfChunk(x, y, z, chunk.ChunkSize))
                {
                    //front
                    if (blocks[x, y, z - 1].Transparent)
                    {
                        AppendFace(mesh, block, Face.Front, x, y, z);
                    }
                    //back
                    if (blocks[x, y, z + 1].Transparent)
                    {
                        AppendFace(mesh, block, Face.Back, x, y, z);
                    }
                    //left
                    if (blocks[x - 1, y, z].Transparent)
                    {
                        AppendFace(mesh, block, Face.Left, x, y, z);
                    }
                    //right
                    if (blocks[x + 1, y, z].Transparent)
                    {
                        AppendFace(mesh, block, Face.Right, x, y, z);
                    }
                    //top
                    if (blocks[x, y + 1, z].Transparent)
                    {
                        AppendFace(mesh, block, Face.Top, x, y, z);
                    }
                    //bottom
                    if (blocks[x, y - 1, z].Transparent)
                    {
                        AppendFace(mesh, block, Face.Bottom, x, y, z);
                    }
                }
                else
                {
                    //front
                    if (!ChunkUtils.IsInChunkBounds(x, y, z - 1, chunk.ChunkSize) || blocks[x, y, z - 1].Transparent)
                    {
                        AppendFace(mesh, block, Face.Front, x, y, z);
                    }
                    //back
                    if (!ChunkUtils.IsInChunkBounds(x, y, z + 1, chunk.ChunkSize) || blocks[x, y, z + 1].Transparent)
                    {
                        AppendFace(mesh, block, Face.Back, x, y, z);
                    }
                    //left
                    if (!ChunkUtils.IsInChunkBounds(x - 1, y, z, chunk.ChunkSize) || blocks[x - 1, y, z].Transparent)
                    {
                        AppendFace(mesh, block, Face.Left, x, y, z);
                    }
                    //right
                    if (!ChunkUtils.IsInChunkBounds(x + 1, y, z, chunk.ChunkSize) || blocks[x + 1, y, z].Transparent)
                    {
                        AppendFace(mesh, block, Face.Right, x, y, z);
                    }
                    //top
                    if (!ChunkUtils.IsInChunkBounds(x, y + 1, z, chunk.ChunkSize) || blocks[x, y + 1, z].Transparent)
                    {
                        AppendFace(mesh, block, Face.Top, x, y, z);
                    }
                    //bottom
                    if (!ChunkUtils.IsInChunkBounds(x, y - 1, z, chunk.ChunkSize) || blocks[x, y - 1, z].Transparent)
                    {
                        AppendFace(mesh, block, Face.Bottom, x, y, z);
                    }
                }
            }

            return(mesh);
        }