Exemplo n.º 1
0
        public void renderChunk(Chunk c)
        {
            string chunk = "Chunk_" + c.x + "_" + c.z;
            SceneNode root = (SceneNode)mSceneMgr.RootSceneNode;
            SceneNode cn;
            if(chunksm.ContainsKey(chunk))
            {
                cn = (SceneNode)root.GetChild(chunk);
                mSceneMgr.DestroyManualObject("MeshManChunk" + c.x + "_" + c.z);
                cn.RemoveAndDestroyAllChildren();
            }else{
                cn = mSceneMgr.RootSceneNode.CreateChildSceneNode(chunk);
                cn.SetPosition(c.x * 16, 0, c.z * 16);
                chunksm.Add(chunk,cn);
            }

            cn.AttachObject(chunkMesh(c));
        }
Exemplo n.º 2
0
        ManualObject chunkMesh(Chunk c)
        {
            Mogre.ManualObject MeshChunk = mSceneMgr.CreateManualObject("MeshManChunk" + c.x + "_" + c.z);

            MeshChunk.Begin("BoxColor",RenderOperation.OperationTypes.OT_TRIANGLE_LIST);

            uint iVertex = 0;
            Block Block;
            Block Block1;
            float bo = 1f / 16f;
            //Console.WriteLine(bo);
            float U1, U2, V1, V2;
            for (int z = 0; z < 16; ++z)
            {
                for (int y = 0; y < 256; ++y)
                {
                    for (int x = 0; x < 16; ++x)
                    {
                        Block = c.blocks[x, y, z];
                        if (Block == null) continue;
                        if (Block.ID == 0) continue;

                        //Compute the block's texture coordinates
                        U1 = bo * (float)(Block.U());
                        U2 = U1 + bo;
                        V1 = bo * (float)(Block.V());
                        V2 = V1 + bo;
                        //x-1

                        Block1 = new Block(x, y, z, 0, 0);
                        if (x > 0) Block1 = c.blocks[x-1,y,z];
                        //if (x == 0) Block1 = chunks[(c.x - 1) + "_" + c.z].blocks[15, y, z];

                        if (Block1.ID == 0)
                        {
                            MeshChunk.Position(x, y,   z+1);	MeshChunk.Normal(-1,0,0);	MeshChunk.TextureCoord(U2, V2);
                            MeshChunk.Position(x, y+1, z+1);	MeshChunk.Normal(-1,0,0);	MeshChunk.TextureCoord(U2, V1);
                            MeshChunk.Position(x, y+1, z);		MeshChunk.Normal(-1,0,0);	MeshChunk.TextureCoord(U1, V1);
                            MeshChunk.Position(x, y,   z);		MeshChunk.Normal(-1,0,0);	MeshChunk.TextureCoord(U1, V2);

                            //MeshChunk.Triangle(iVertex, iVertex+1, iVertex+2);
                            //MeshChunk.Triangle(iVertex+2, iVertex+3, iVertex);
                            MeshChunk.Quad(iVertex, iVertex + 1, iVertex + 2, iVertex + 3);

                            iVertex += 4;
                        }

                        //x+1
                        Block1 = new Block(x, y, z, 0, 0);
                        if (x < 15) Block1 = c.blocks[x + 1, y, z];
                        //if (x == 15) Block1 = chunks[(c.x + 1) + "_" + c.z].blocks[0, y, z];

                        if (Block1.ID == 0)
                        {
                            MeshChunk.Position(x+1, y,   z);	MeshChunk.Normal(1,0,0); MeshChunk.TextureCoord(U2, V2);
                            MeshChunk.Position(x+1, y+1, z);	MeshChunk.Normal(1,0,0); MeshChunk.TextureCoord(U2, V1);
                            MeshChunk.Position(x+1, y+1, z+1);	MeshChunk.Normal(1,0,0); MeshChunk.TextureCoord(U1, V1);
                            MeshChunk.Position(x+1, y,   z+1);	MeshChunk.Normal(1,0,0); MeshChunk.TextureCoord(U1, V2);

                            //MeshChunk.Triangle(iVertex, iVertex+1, iVertex+2);
                            //MeshChunk.Triangle(iVertex+2, iVertex+3, iVertex);
                            MeshChunk.Quad(iVertex, iVertex + 1, iVertex + 2, iVertex + 3);

                            iVertex += 4;
                        }

                        //y-1
                        Block1 = new Block(x, y, z, 0, 0);
                        if (y > 0) Block1 = c.blocks[x, y - 1, z];

                        //if (Block1 == null) Block1 = new Block(x, y, z, 0, 0);

                        if (Block1.ID == 0)
                        {
                            MeshChunk.Position(x,   y, z);		MeshChunk.Normal(0,-1,0); MeshChunk.TextureCoord(U1, V2);
                            MeshChunk.Position(x+1, y, z);		MeshChunk.Normal(0,-1,0); MeshChunk.TextureCoord(U2, V2);
                            MeshChunk.Position(x+1, y, z+1);	MeshChunk.Normal(0,-1,0); MeshChunk.TextureCoord(U2,V1);
                            MeshChunk.Position(x,   y, z+1);	MeshChunk.Normal(0,-1,0); MeshChunk.TextureCoord(U1,V1);

                            //MeshChunk.Triangle(iVertex, iVertex+1, iVertex+2);
                            //MeshChunk.Triangle(iVertex+2, iVertex+3, iVertex);
                            MeshChunk.Quad(iVertex, iVertex + 1, iVertex + 2, iVertex + 3);

                            iVertex += 4;
                        }

                        //y+1
                        Block1 = new Block(x, y, z, 0, 0);
                        if (y < 256 - 1) Block1 = c.blocks[x, y + 1, z];
                        //if (Block1 == null) Block1 = new Block(x, y, z, 0, 0);

                        if (Block1.ID == 0)
                        {
                            MeshChunk.Position(x,   y+1, z+1);		MeshChunk.Normal(0,1,0); MeshChunk.TextureCoord(U1, V2);
                            MeshChunk.Position(x+1, y+1, z+1);		MeshChunk.Normal(0,1,0); MeshChunk.TextureCoord(U2, V2);
                            MeshChunk.Position(x+1, y+1, z);		MeshChunk.Normal(0,1,0); MeshChunk.TextureCoord(U2,V1);
                            MeshChunk.Position(x,   y+1, z);		MeshChunk.Normal(0,1,0); MeshChunk.TextureCoord(U1,V1);

                            //MeshChunk.Triangle(iVertex, iVertex+1, iVertex+2);
                            //MeshChunk.Triangle(iVertex+2, iVertex+3, iVertex);
                            MeshChunk.Quad(iVertex, iVertex + 1, iVertex + 2, iVertex + 3);

                            iVertex += 4;
                        }

                        //z-1
                        Block1 = new Block(x, y, z, 0, 0);
                        if (z > 0) Block1 = c.blocks[x, y, z - 1];
                        //if (x == 0) Block1 = chunks[c.x + "_" + (c.z - 1)].blocks[x, y, 15];
                        //if (Block1 == null) Block1 = new Block(x, y, z, 0, 0);

                        if (Block1.ID == 0)
                        {
                            MeshChunk.Position(x,   y+1, z);		MeshChunk.Normal(0,0,-1); MeshChunk.TextureCoord(U2, V1);
                            MeshChunk.Position(x+1, y+1, z);		MeshChunk.Normal(0,0,-1); MeshChunk.TextureCoord(U1, V1);
                            MeshChunk.Position(x+1, y,   z);		MeshChunk.Normal(0,0,-1); MeshChunk.TextureCoord(U1, V2);
                            MeshChunk.Position(x,   y,   z);		MeshChunk.Normal(0,0,-1); MeshChunk.TextureCoord(U2, V2);

                            //MeshChunk.Triangle(iVertex, iVertex+1, iVertex+2);
                            //MeshChunk.Triangle(iVertex+2, iVertex+3, iVertex);
                            MeshChunk.Quad(iVertex, iVertex + 1, iVertex + 2, iVertex + 3);
                            iVertex += 4;
                        }

                            //z+1
                        Block1 = new Block(x,y,z,0,0);
                        if (z < 15) Block1 = c.blocks[x, y, z + 1];
                        //if (x == 15) Block1 = chunks[c.x+"_"+(c.z + 1)].blocks[x, y, 0];

                        //if (Block1 == null) Block1 = new Block(x, y, z, 0, 0);

                        if (Block1.ID == 0)
                        {
                            MeshChunk.Position(x,   y,   z+1);		MeshChunk.Normal(0,0,1); MeshChunk.TextureCoord(U1, V2);
                            MeshChunk.Position(x+1, y,   z+1);		MeshChunk.Normal(0,0,1); MeshChunk.TextureCoord(U2, V2);
                            MeshChunk.Position(x+1, y+1, z+1);		MeshChunk.Normal(0,0,1); MeshChunk.TextureCoord(U2,V1);
                            MeshChunk.Position(x,   y+1, z+1);		MeshChunk.Normal(0,0,1); MeshChunk.TextureCoord(U1,V1);

                            //MeshChunk.Triangle(iVertex, iVertex+1, iVertex+2);
                            //MeshChunk.Triangle(iVertex+2, iVertex+3, iVertex);
                            MeshChunk.Quad(iVertex, iVertex + 1, iVertex + 2, iVertex + 3);

                            iVertex += 4;
                        }
                    }
                }
            }

            MeshChunk.End();
            return MeshChunk;
        }
Exemplo n.º 3
0
 public void QueueChunk(Chunk c)
 {
     lock(chunkq)
         chunkq.Enqueue(c);
 }