Exemplo n.º 1
0
        public VoxelMeshBuilder(VoxelObject vo, float cubeSize, float ao)
        {
            this.vo = vo;
            this.ao = ao;

            SetCubeSize(cubeSize);

            frontNormal  = Vector3.UnitZ;
            backNormal   = -Vector3.UnitZ;
            leftNormal   = -Vector3.UnitX;
            rightNormal  = Vector3.UnitX;
            topNormal    = Vector3.UnitY;
            bottomNormal = -Vector3.UnitY;
        }
Exemplo n.º 2
0
        Mesh PrepareVO(VoxelObject vo, RenderPass pass)
        {
            Mesh mesh = pass.HasFlag(RenderPass.Alpha) ? vo.AlphaMesh : vo.Mesh;

            if (mesh == null && pass.HasFlag(RenderPass.Normal))
            {
                throw new InvalidOperationException("Attempted to render null opaque mesh!");
            }

            if (mesh != null)
            {
                Master.PrepareMesh(mesh, pass);
            }

            return(mesh);
        }
Exemplo n.º 3
0
 public void Batch(VoxelObject vo, Matrix4 mat4)
 {
     rawBatch.BatchItem(vo, mat4);
 }
Exemplo n.º 4
0
        public void Batch(VoxelObject vo, Vector3 position)
        {
            Matrix4 mat4 = Maths.CreateTransformationMatrix(position, vo.MeshRotation, vo.MeshScale);

            Batch(vo, mat4);
        }
Exemplo n.º 5
0
 public void BatchFront(VoxelObject vo, Matrix4 worldMatrix)
 {
     rawBatchFront.BatchItem(vo, worldMatrix);
 }
Exemplo n.º 6
0
        void RenderEntityList(Shader shader, RenderPass pass, List <BatchedEntity> list, VoxelObject commonVO = null)
        {
            // Pre-load mesh
            Mesh mesh = null;

            if (commonVO != null)
            {
                mesh = PrepareVO(commonVO, pass);
                if (mesh == null)
                {
                    return;
                }
            }

            // Go through batch
            foreach (BatchedEntity ent in list)
            {
                if (ent.OnlyRenderFor.HasValue && !ent.OnlyRenderFor.Value.HasFlag(pass))
                {
                    continue;
                }

                // Load mesh if were not using a common vo
                if (commonVO == null)
                {
                    mesh = PrepareVO(ent.VoxelObject, pass);
                    if (mesh == null)
                    {
                        continue;
                    }
                }

                // Determine the world matrix
                Matrix4 worldMatrix = ent.CustomMatrix
                                      ?? Maths.CreateTransformationMatrix(ent.Position, ent.MeshRotation, ent.VoxelObject.MeshScale);
                shader.LoadMatrix4("transformationMatrix", worldMatrix);

                // Prepare the entity
                //if (ent.RenderFront && pass != RenderPass.Shadow) StateManager.DepthFunc(DepthFunction.Always);
                //else StateManager.DepthFunc(DepthFunction.Less);

                StateManager.ToggleWireframe(ent.RenderAsWireframe);

                if (!pass.HasFlag(RenderPass.Shadow))
                {
                    shader.LoadBool("skipLight", ent.ApplyNoLighting);
                    shader.LoadColor4("colorOverlay", ent.ColorOverlay);
                    shader.LoadFloat("entityLighting", 1f);
                }

                // Render the entity
                GL.DrawElements(mesh.BeginMode, mesh.VertexCount, DrawElementsType.UnsignedInt, IntPtr.Zero);

                // If we're not using a common vo, end it's mesh
                if (commonVO == null)
                {
                    Master.EndMesh();
                }
            }

            // If we are using a common vo, end it's mesh last
            if (commonVO != null)
            {
                Master.EndMesh();
            }
        }