Ejemplo n.º 1
0
        public static void GenerateVoxelGeometry(
            RawPrimitive Into,
            VoxelHandle Voxel,
            TerrainTileSheet TileSheet,
            WorldManager World,
            SliceCache Cache)
        {
            BuildDesignationGeometry(Into, Voxel, Cache, TileSheet, World);
            if (Voxel.IsEmpty && Voxel.IsExplored)
            {
                return;
            }

            var templateSolid = TemplateSolidLibrary.GetTemplateSolid(Voxel.Type.TemplateSolid);

            foreach (var face in templateSolid.Faces)
            {
                GenerateFaceGeometry(Into, Voxel, face, TileSheet, World, Cache);
            }
        }
Ejemplo n.º 2
0
        private static bool IsFaceVisible(VoxelHandle voxel, VoxelHandle neighbor, Geo.TemplateFace face)
        {
            if (!voxel.IsValid)
            {
                return(false);
            }

            if (!neighbor.IsValid)
            {
                if (voxel.IsExplored)
                {
                    return(!voxel.IsEmpty);
                }
                else
                {
                    return(true);
                }
            }
            else
            {
                if (!voxel.IsExplored)
                {
                    if (!neighbor.IsVisible)
                    {
                        return(true);
                    }

                    if (neighbor.IsExplored && neighbor.IsEmpty)
                    {
                        return(true);
                    }

                    if (!neighbor.Type.CanRamp)
                    {
                        return(false);
                    }

                    if (neighbor.RampType == RampType.None)
                    {
                        return(false);
                    }

                    if (!IsSideFace(face))
                    {
                        return(false);
                    }

                    if (!neighbor.IsExplored)
                    {
                        return(false);
                    }

                    return(true);
                }
                else
                {
                    if (neighbor.IsExplored && neighbor.IsEmpty)
                    {
                        return(true);
                    }

                    if (face.Orientation == FaceOrientation.Top && !neighbor.IsVisible)
                    {
                        return(true);
                    }

                    if (neighbor.Type.IsTransparent && !voxel.Type.IsTransparent)
                    {
                        return(true);
                    }

                    var neighborSideOrientation = OrientationHelper.GetOppositeFace(face.Orientation);
                    var neighborSolid           = TemplateSolidLibrary.GetTemplateSolid(neighbor.Type.TemplateSolid);
                    var neighborSide            = neighborSolid.Faces.FirstOrDefault(s => s.Orientation == neighborSideOrientation);
                    if (neighborSide == null)
                    {
                        return(true);
                    }
                    if (neighborSide.FaceShape == TemplateFaceShapes.LowerSlab && face.FaceShape != TemplateFaceShapes.LowerSlab)
                    {
                        return(true);
                    }

                    if (neighbor.Type.CanRamp &&
                        neighbor.RampType != RampType.None &&
                        IsSideFace(face) &&
                        ShouldDrawFace(face.Orientation, neighbor.RampType, voxel.RampType) &&
                        neighbor.IsExplored)
                    {
                        return(true);
                    }

                    return(false);
                }
            }
        }
Ejemplo n.º 3
0
        private static void BuildDesignationGeometry(
            RawPrimitive Into,
            VoxelHandle Voxel,
            SliceCache Cache,
            TerrainTileSheet TileSheet,
            WorldManager World)
        {
            // Todo: Store designations per chunk.
            foreach (var designation in World.PersistentData.Designations.EnumerateDesignations(Voxel).ToList())
            {
                if ((designation.Type & World.Renderer.PersistentSettings.VisibleTypes) != designation.Type) // If hidden by player, do not draw.
                {
                    return;
                }

                var designationProperties = Library.GetDesignationTypeProperties(designation.Type).Value;
                var designationVisible    = false;

                if (designationProperties.DrawType == DesignationDrawType.PreviewVoxel)
                {
                    designationVisible = Voxel.Coordinate.Y < World.Renderer.PersistentSettings.MaxViewingLevel;
                }
                else
                {
                    designationVisible = VoxelHelpers.DoesVoxelHaveVisibleSurface(World, Voxel);
                }

                if (designationVisible &&
                    Library.GetVoxelPrimitive(Library.DesignationVoxelType).HasValue(out BoxPrimitive designationPrimitive))
                {
                    switch (designationProperties.DrawType)
                    {
                    case DesignationDrawType.FullBox:
                    {
                        var solid = TemplateSolidLibrary.GetTemplateSolid(Voxel.Type.TemplateSolid);
                        for (var f = 0; f < solid.Faces.Count; ++f)
                        {
                            var face = solid.Faces[f];
                            if (face.CullType == Geo.FaceCullType.Cull && !IsFaceVisible(Voxel, face, World.ChunkManager, out var neighbor))
                            {
                                continue;
                            }

                            PrepVerticies(World, Voxel, face, Cache, GetVoxelVertexExploredNeighbors(Voxel, face, Cache), TileSheet, new Point(0, 0), false, 0.02f);
                            SetVertexTint(Cache.FaceGeometry, designationProperties.Color);
                            AddQuad(Into, Cache.FaceGeometry, QuadIndicies);
                        }
                    }
                    break;

                    case DesignationDrawType.TopBox:
                    {
                        var solid = TemplateSolidLibrary.GetTemplateSolid(Voxel.Type.TemplateSolid);
                        for (var f = 0; f < solid.Faces.Count; ++f)
                        {
                            var face = solid.Faces[f];
                            if (face.Orientation != FaceOrientation.Top)
                            {
                                continue;
                            }
                            if (face.CullType == Geo.FaceCullType.Cull && !IsFaceVisible(Voxel, face, World.ChunkManager, out var neighbor))
                            {
                                continue;
                            }

                            PrepVerticies(World, Voxel, face, Cache, GetVoxelVertexExploredNeighbors(Voxel, face, Cache), TileSheet, new Point(0, 0), false, 0.02f);
                            SetVertexTint(Cache.FaceGeometry, designationProperties.Color);
                            AddQuad(Into, Cache.FaceGeometry, QuadIndicies);
                        }
                    }
                    break;

                    case DesignationDrawType.PreviewVoxel:
                    {
                        if (Library.GetVoxelType(designation.Tag.ToString()).HasValue(out VoxelType voxelType))
                        {
                            var solid = TemplateSolidLibrary.GetTemplateSolid(voxelType.TemplateSolid);
                            for (var f = 0; f < solid.Faces.Count; ++f)
                            {
                                var face = solid.Faces[f];
                                if (face.CullType == Geo.FaceCullType.Cull && !IsFaceVisible(Voxel, face, World.ChunkManager, out var neighbor))
                                {
                                    continue;
                                }

                                PrepVerticies(World, Voxel, face, Cache, GetVoxelVertexExploredNeighbors(Voxel, face, Cache), TileSheet, SelectTile(voxelType, face.Orientation), false, 0.0f);
                                SetVertexTint(Cache.FaceGeometry, designationProperties.Color);
                                AddQuad(Into, Cache.FaceGeometry, QuadIndicies);
                            }
                        }
                    }
                    break;
                    }
                }
            }
        }