예제 #1
0
        protected override void OnLoad()
        {
            GL.ClearColor(0.2f, 0.3f, 0.3f, 1.0f);

            GL.Enable(EnableCap.DepthTest);

            GL.Enable(EnableCap.CullFace);

            mesh  = new Mesh(new Meshes.VertexAttribute[] { Meshes.VertexAttribute.GenerateAttribute <float>(3, "aPosition", VertexAttribPointerType.Float), Meshes.VertexAttribute.GenerateAttribute <float>(2, "aTexCoord", VertexAttribPointerType.Float) });
            _mesh = new ChunkMesh();

            _camera = new Camera(Vector3.UnitZ * 3, (float)Size.X / Size.Y);

            mesh.UpdateProjection(_camera.GetProjectionMatrix());
            mesh.UpdateView(_camera.GetViewMatrix());
            mesh.UpdateModel(Matrix4.Identity);

            mesh.SetData(new float[]
            {
                0, 0, -2, 0, 0,
                1, 0, -2, 1, 0,
                1, 1, -2, 1, 1,
                0, 1, -2, 0, 1,
            },
                         new uint[]
            {
                0, 1, 2,
                0, 2, 3
            }
                         );

            _mesh.UpdateProjection(_camera.GetProjectionMatrix());
            _mesh.UpdateView(_camera.GetViewMatrix());
            _mesh.UpdateModel(OpenToolkit.Mathematics.Matrix4.Identity);
            _mesh.SetTexture("Core/Textures/tilemap.png");


            _world = new World();

            double timer = 0;

            ChunkMeshGenerator.GenerateMesh(_mesh, _world._chunks[new Vector3i()], ref timer);


            Common.VoxelEngine.Spaceship.SmallShip.Chunk chunk = new Common.VoxelEngine.Spaceship.SmallShip.Chunk();

            for (int i = 0; i < Common.VoxelEngine.Spaceship.SmallShip.SmallShipComponent.CHUNK_SIZE_CUBE; i++)
            {
                if (i % 2 == 0)
                {
                    chunk.blocks[i] = 1;
                }
            }

            base.OnLoad();
        }
예제 #2
0
    public void RenderBlock(Block originBlock)
    {
        if (meshGenerator == null)
        {
            meshGenerator = GetComponent <ChunkMeshGenerator>();
        }
        if (meshGenerator == null)
        {
            return;
        }
        MyBlock blockOwner = new MyBlock(Vector3Int.zero, originBlock);

        meshGenerator.ChunkOrigin = Vector3Int.zero;
        meshGenerator.ChunkSize   = 1;
        meshGenerator.BlockOwner  = blockOwner;
        meshGenerator.GenerateMesh();
    }