Ejemplo n.º 1
0
    private void Start()
    {
        string fileName = Path.Combine(Application.streamingAssetsPath, objFile);

        if (!File.Exists(fileName))
        {
            Debug.LogError("FILE COULD NOT BE FOUND!");
            return;
        }

        string objData = File.ReadAllText(fileName);
        int    objLen  = (int)(objData.Split('o').Length * 1.2f);

        debugMeshes = new List <Mesh>(objLen);
        gameWorld   = new world(objLen);
        MeshHelpers.CreateMeshesFromEpa(objData);
        Raycast.InitRaycastData(ref gameWorld);

        //Generate Ground plane.
        bounds ground = new bounds();

        ground.minPoints = new float3(-1000, -.1f, -1000);
        ground.maxPoints = new float3(1000, .1f, 1000);

        groundMesh = MeshHelpers.MakeCubeFromBounds(ground);
        groundMesh.RecalculateBounds();
        entity groundEntity = new entity();

        groundEntity.bounds.minPoints = groundMesh.bounds.min;
        groundEntity.bounds.maxPoints = groundMesh.bounds.max;
        groundEntity.name             = "Ground";
        GameWorld.AddEntity(ref gameWorld, ref groundEntity);
    }
Ejemplo n.º 2
0
    public bounds SetBounds(ref bounds _b, float _x, float _y, float _z)
    {
        bounds result = _b;

        if (_b.minPoints.x > _x)
        {
            result.minPoints.x = _x;
        }
        else if (_b.maxPoints.x < _x)
        {
            result.maxPoints.x = _x;
        }

        if (_b.minPoints.y > _y)
        {
            result.minPoints.y = _y;
        }
        else if (_b.maxPoints.y < _y)
        {
            result.maxPoints.y = _y;
        }

        if (_b.minPoints.z > _z)
        {
            result.minPoints.z = _z;
        }
        else if (_b.maxPoints.z < _z)
        {
            result.maxPoints.z = _z;
        }

        return(result);
    }
Ejemplo n.º 3
0
        /// <summary>
        /// Generates and saves a single minecraft chunk using current settings.
        /// </summary>
        /// <param name="xi">X coordinate of the chunk.</param>
        /// <param name="zi">Y coordinate of the chunk.</param>
        public void generateSingleChunk(int xi, int zi)
        {
            // This line will create a default empty chunk, and create a
            // backing region file if necessary (which will immediately be
            // written to disk)
            ChunkRef chunk = currentWorld.GetChunkManager().CreateChunk(xi, zi);

            // This will make sure all the necessary things like trees and
            // ores are generated for us.
            chunk.IsTerrainPopulated = false;

            // Auto light recalculation is horrifically bad for creating
            // chunks from scratch, because we're placing thousands
            // of blocks.  Turn it off.
            chunk.Blocks.AutoLight = false;

            // This scales the dimensions based off the blocksPerEmbarkTile [1..8]
            bounds bound = new bounds(xi, zi);

            // Make the terrain
            HeightMapChunk(chunk, bound);

            // Reset and rebuild the lighting for the entire chunk at once
            chunk.Blocks.RebuildHeightMap();
            chunk.Blocks.RebuildBlockLight();
            chunk.Blocks.RebuildSkyLight();

            // Save the chunk to disk so it doesn't hang around in RAM
            currentWorld.GetChunkManager().Save();
        }
Ejemplo n.º 4
0
    public static bounds MakeBoundsFromVector(float3 _start, float3 _end)
    {
        bounds result = new bounds();

        result.maxPoints.x = _end.x;
        result.minPoints.x = _start.x;
        result.maxPoints.y = _end.y;
        result.minPoints.y = _start.y;
        result.maxPoints.z = _end.z;
        result.minPoints.z = _start.z;

        if (_start.x > _end.x)
        {
            result.maxPoints.x = _start.x;
            result.minPoints.x = _end.x;
        }
        if (_start.y > _end.y)
        {
            result.maxPoints.y = _start.y;
            result.minPoints.y = _end.y;
        }
        if (_start.z > _end.z)
        {
            result.maxPoints.z = _start.z;
            result.minPoints.z = _end.z;
        }
        return(result);
    }
Ejemplo n.º 5
0
        /* public void simpleWriteTest()
        {
            initializeMinecraftWorld();
            IChunkManager cm = currentWorld.GetChunkManager();

            loadDwarfMaps();

            int cropWidth = 40;
            int cropHeight = 40;

            Settings.Default.borderWest = 40;
            Settings.Default.borderEast = Settings.Default.borderWest + cropWidth;

            Settings.Default.borderNorth = 40;
            Settings.Default.borderSouth = Settings.Default.borderNorth + cropHeight;

            //FIXME get rid of this junk
            Settings.Default.mapCenterX = (Settings.Default.borderWest + Settings.Default.borderEast) / 2;
            Settings.Default.mapCenterY = (Settings.Default.borderNorth + Settings.Default.borderSouth) / 2;


            Console.WriteLine("Starting conversion now.");
            Stopwatch watch = Stopwatch.StartNew();
            for (int xi = getChunkStartX(); xi < getChunkFinishX(); xi++)
            {
                for (int zi = getChunkStartY(); zi < getChunkFinishY(); zi++)
                {
                    // This line will create a default empty chunk, and create a
                    // backing region file if necessary (which will immediately be
                    // written to disk)
                    ChunkRef chunk = cm.CreateChunk(xi, zi);

                    // This will make sure all the necessary things like trees and
                    // ores are generated for us.
                    chunk.IsTerrainPopulated = false;

                    // Auto light recalculation is horrifically bad for creating
                    // chunks from scratch, because we're placing thousands
                    // of blocks.  Turn it off.
                    chunk.Blocks.AutoLight = false;

                    double xMin = ((xi * 16.0 / (double)Settings.Default.blocksPerEmbarkTile) + Settings.Default.mapCenterX);
                    double xMax = (((xi + 1) * 16.0 / (double)Settings.Default.blocksPerEmbarkTile) + Settings.Default.mapCenterX);
                    double yMin = ((zi * 16.0 / (double)Settings.Default.blocksPerEmbarkTile) + Settings.Default.mapCenterY);
                    double yMax = (((zi + 1) * 16.0 / (double)Settings.Default.blocksPerEmbarkTile) + Settings.Default.mapCenterY);


                    // Make the terrain
                    HeightMapChunk(chunk, xMin, xMax, yMin, yMax);

                    // Reset and rebuild the lighting for the entire chunk at once
                    chunk.Blocks.RebuildHeightMap();
                    if (Settings.Default.lightGenerationEnable)
                    {
                        chunk.Blocks.RebuildBlockLight();
                        chunk.Blocks.RebuildSkyLight();
                    }

                    // Save the chunk to disk so it doesn't hang around in RAM
                    cm.Save();
                }
                //TimeSpan elapsedTime = watch.Elapsed;
                //int finished = xi - chunkStartX + 1;
                //int left = chunkFinishX - xi - 1;
                //TimeSpan remainingTime = TimeSpan.FromTicks(elapsedTime.Ticks / finished * left);
                //Console.WriteLine("Built Chunk Row {0} of {1}. {2}:{3}:{4} elapsed, {5}:{6}:{7} remaining.",
                //    finished, chunkFinishX - chunkStartX,
                //    elapsedTime.Hours, elapsedTime.Minutes, elapsedTime.Seconds,
                //    remainingTime.Hours, remainingTime.Minutes, remainingTime.Seconds);
                maxHeight = int.MinValue;
                minHeight = int.MaxValue;
            }

            saveMinecraftWorld();
        }
        */

        public internalData generateInternalMapChunk(bounds bound)
        {
            return new internalData(
                 (int)currentDwarfMap.getElevation(bound.mux, bound.muy) + shift,
                 currentDwarfMap.getBiome(bound.MuxInt(), bound.MuyInt()),
                 currentDwarfMap.getRiverType(bound.MuxInt(), bound.MuyInt()),
                 currentDwarfMap.getRiverLevel(bound.MuxInt(), bound.MuyInt()) + shift,
                 currentDwarfMap.getWaterbodyLevel(bound.MuxInt(), bound.MuyInt()) + shift,
                 currentDwarfMap.getStructureMap(bound.MuxInt(), bound.MuyInt())
                 );
        }
Ejemplo n.º 6
0
    public static bool AABBSphereOverlap(bounds _a, sphereBounds _s)
    {
        float x = Mathf.Max(_a.minPoints.x, Mathf.Min(_s.center.x, _a.maxPoints.x));
        float y = Mathf.Max(_a.minPoints.y, Mathf.Min(_s.center.y, _a.maxPoints.y));
        float z = Mathf.Max(_a.minPoints.z, Mathf.Min(_s.center.z, _a.maxPoints.z));

        float distance = Mathf.Sqrt(
            (x - _s.center.x) * (x - _s.center.x) +
            (y - _s.center.y) * (y - _s.center.y) +
            (z - _s.center.z) * (z - _s.center.z));

        return(distance < _s.radius);
    }
Ejemplo n.º 7
0
        public void Execute()
        {
            var xmin = float.PositiveInfinity;
            var ymin = float.PositiveInfinity;
            var zmin = float.PositiveInfinity;
            var xmax = float.NegativeInfinity;
            var ymax = float.NegativeInfinity;
            var zmax = float.NegativeInfinity;

            var length = vertices.Length;

            for (int i = 0; i < length; i++)
            {
                var p = vertices[i];

                if (p.x < xmin)
                {
                    xmin = p.x;
                }
                if (p.y < ymin)
                {
                    ymin = p.y;
                }
                if (p.z < zmin)
                {
                    zmin = p.z;
                }

                if (p.x > xmax)
                {
                    xmax = p.x;
                }
                if (p.y > ymax)
                {
                    ymax = p.y;
                }
                if (p.z > zmax)
                {
                    zmax = p.z;
                }
            }

            var b = new bounds();

            b.min = float3(xmin, ymin, zmin);
            b.max = float3(xmax, ymax, zmax);

            bounds[0] = b;
        }
Ejemplo n.º 8
0
    public static Mesh MakeCubeFromBounds(bounds _b)
    {
        Mesh result = new Mesh();
        List<Vector3> verts = new List<Vector3>();
        List<int> tris = new List<int>();

        float minx = _b.minPoints.x;
        float miny = _b.minPoints.y;
        float minz = _b.minPoints.z;
        float maxx = _b.maxPoints.x;
        float maxy = _b.maxPoints.y;
        float maxz = _b.maxPoints.z;

        verts.Add(new Vector3(minx, miny, minz));
        verts.Add(new Vector3(minx, miny, maxz));
        verts.Add(new Vector3(minx, maxy, minz));
        verts.Add(new Vector3(minx, maxy, maxz));
        verts.Add(new Vector3(maxx, miny, minz));
        verts.Add(new Vector3(maxx, miny, maxz));
        verts.Add(new Vector3(maxx, maxy, minz));
        verts.Add(new Vector3(maxx, maxy, maxz));

        tris.AddRange(new int[] { 0, 1, 2 });
        tris.AddRange(new int[] { 1, 3, 2 });
        tris.AddRange(new int[] { 0, 2, 6 });
        tris.AddRange(new int[] { 0, 6, 4 });
        tris.AddRange(new int[] { 4, 6, 7 });
        tris.AddRange(new int[] { 4, 7, 5 });
        tris.AddRange(new int[] { 5, 7, 3 });
        tris.AddRange(new int[] { 5, 3, 1 });
        tris.AddRange(new int[] { 2, 3, 6 });
        tris.AddRange(new int[] { 3, 7, 6 });
        tris.AddRange(new int[] { 0, 4, 5 });
        tris.AddRange(new int[] { 0, 5, 1 });

        result.SetVertices(verts);
        result.SetTriangles(tris, 0);
        result.RecalculateNormals();
        return result;

    }
Ejemplo n.º 9
0
        void HeightMapChunk(ChunkRef chunk, bounds bound)
        {
            double mapXMin = bound.xMin;
            double mapXMax = bound.xMax;
            double mapYMin = bound.yMin;
            double mapYMax = bound.yMax;

            int size = 16;
            internalData[,] mapData = new internalData[3*size+2,  3*size+2];
            for (int x = -size-1; x <= 2*size; x++)
            {
                for (int z = -size-1; z <= 2 * size; z++)
                {
                    bound.updateBound(x, z);
                    // build 48x48 chunk of source maps for use below
                    mapData[x+size+1, z+size+1] = generateInternalMapChunk(bound);
                }
            }
            
            for (int x = 0; x < 16; x++)
            {
                for (int z = 0; z < 16; z++)
                {
                    bound.updateBound(x, z);


                   

                    internalData id = mapData[x+1, z+1]; // .getInternalData(xt, zt);
                    int height      = id.height;
                    int waterLevel  = id.waterLevel;
                    int riverLevel  = id.riverLevel;
                    int depth       = id.riverType;
                    Structures.Type structure   = id.structureType;
                    int biomeIndex  = id.biomeIndex < 0 ? 0 : id.biomeIndex;



                    if (height > maxHeight) maxHeight = height;
                    if (height < minHeight) minHeight = height;

                    
                    chunk.Biomes.SetBiome(x, z, BiomeList.biomes[biomeIndex].mineCraftBiome);
                    //create bedrock
                    for (int y = 0; y < 2; y++)
                    {
                        chunk.Blocks.SetID(x, y, z, BlockType.BEDROCK);
                    }
                    ////deal with rivers
                    // BezierRivers.MakeRivers mr = new BezierRivers.MakeRivers();
                    // mr.makeRivers();

                    if (riverLevel >= 0)
                    {
                        chunk.Biomes.SetBiome(x, z, BiomeType.River);

                        height = riverLevel;

                        // All DF rivers are 1 px wide.  
                        // That scales into embarkWidth regardless of type of river
                        // This metric allows us to fine-tune river width beyond that of embarkWidth
                        double oX = (mapXMax - mapXMin) * x % 16 - 8;
                        double oY = (mapYMax - mapYMin) * z % 16 - 8;
                        // Console.WriteLine("[{3},{4},({2}): {0},{1}  (({5},{6})) [{7},{8}]", oX, oY, depth,x,z, mux, muy, mux-Math.Floor(mux + 0.5), muy-Math.Floor(muy+0.5));
                        int scale = Settings.Default.blocksPerEmbarkTile;

                        // can account for depth of river here 
                        for (int y = 0; y < height - depth - 2; y++)
                        {
                            chunk.Blocks.SetID(x, y, z, BlockType.STONE);
                        }
                        for (int y = height - depth - 2; y < height - depth - 1; y++)
                        {
                            chunk.Blocks.SetID(x, y, z, BlockType.GRAVEL);
                        }
                        for (int y = height - depth - 1; y < height; y++)
                        {
                            chunk.Blocks.SetID(x, y, z, BlockType.WATER);
                        }
                        for (int y = height; y < height + 1; y++)//Just to blockupdate for flowing water(falls).
                        {
                            chunk.Blocks.SetID(x, y, z, BlockType.AIR);
                        }
                    }
                    else if (BiomeList.biomes[biomeIndex].mineCraftBiome == BiomeID.DeepOcean && waterLevel <= height)
                    {
                        //make beaches
                        chunk.Biomes.SetBiome(x, z, BiomeType.Beach);
                        height = 98 + shift;
                        for (int y = 0; y < height - 4; y++)
                        {
                            chunk.Blocks.SetID(x, y, z, BlockType.STONE);
                        }
                        for (int y = height - 4; y < height - 3; y++)
                        {
                            chunk.Blocks.SetID(x, y, z, BlockType.SANDSTONE);
                        }
                        for (int y = height - 3; y < height; y++)
                        {
                            chunk.Blocks.SetID(x, y, z, BlockType.SAND);
                        }

                    }
                    else
                    {
                        // Create the rest, according to biome
                        for (int y = 2; y < height; y++)
                        {
                            if (y >= chunk.Blocks.YDim) break;
                            chunk.Blocks.SetID(x, y, z, BiomeList.biomes[biomeIndex].getBlockID(height - y, x + (chunk.X * 16), z + (chunk.Z * 16)));
                        }
                    }
                    //// Create Oceans and lakes
                    for (int y = height; y < waterLevel; y++)
                    {
                        if (y < 2) continue;
                        if (y >= chunk.Blocks.YDim) break;
                        chunk.Blocks.SetID(x, y, z, BlockType.STATIONARY_WATER);
                    }

                    // Fill caves
                    for (int y = 2; y < height; y++)
                    {
                        if (y >= chunk.Blocks.YDim) break;
                        int caveID = currentCaveMap.getCaveBlock(bound.mux, y - shift, bound.muy);
                        if (caveID == -2)
                            break;
                        if (caveID >= 0)
                            chunk.Blocks.SetID(x, y, z, caveID);
                    }

                    // Populate Structures
                    int tunnelHeight = 5;
                    int tunnelDepth = 10;
                    // structureNeighbor:
                    // 1 2 3
                    // 4 X 5
                    // 6 7 8

                    // 

                   switch (structure)
                    {
                        case Structures.Type.Underground_Road:
                            chunk.Blocks.SetID(x, height - tunnelDepth - tunnelHeight, z, BlockType.COBBLESTONE);
                            for (int y = height - tunnelHeight - tunnelDepth; y < height - tunnelDepth; y++)
                            {
                                chunk.Blocks.SetID(x, y, z, BlockType.AIR);
                            }
                            chunk.Blocks.SetID(x, height - tunnelHeight, z, BlockType.COBBLESTONE);
                            break;
                        case Structures.Type.Road: // road
                            for (int y = height - 2; y < height; y++)
                            {
                                chunk.Blocks.SetID(x, y, z, BlockType.STONE_BRICK);
                                if (mapData[x + 1 - 1, z +1 ].structureType == Structures.Type.Bridge)
                                {
                                    chunk.Blocks.SetID(x, height + 1, z, BlockType.COBBLESTONE_STAIRS);
                                    chunk.Blocks.GetBlock(x, height + 1, z).Data = (int)StairOrientation.ASCEND_WEST;
                                }
                                if (mapData[x + 1 + 1, z + 1 ].structureType == Structures.Type.Bridge)
                                {
                                    chunk.Blocks.SetID(x, height + 1, z, BlockType.COBBLESTONE_STAIRS);
                                    chunk.Blocks.GetBlock(x, height + 1, z).Data = (int)StairOrientation.ASCEND_EAST;
                                }

                            }
                            break;
                        case Structures.Type.Bridge: // bridge
                            chunk.Blocks.SetID(x, height + 1, z, BlockType.HARDENED_CLAY);
                            break;
                        case Structures.Type.HumanCity1: // wheat?
                            chunk.Blocks.SetID(x, height - 1, z, BlockType.GOLD_BLOCK);
                            break;
                        case Structures.Type.HumanCity2: // potato
                            chunk.Blocks.SetID(x, height - 1, z, BlockType.HAY_BLOCK);
                            break;
                        case Structures.Type.HumanCity3: // carrot
                            chunk.Blocks.SetID(x, height - 1, z, BlockType.OBSIDIAN);
                            break;
                        case Structures.Type.HumanCity4: // carrot
                            chunk.Blocks.SetID(x, height - 1, z, BlockType.BIRCH_WOOD_STAIRS);
                            break;
                        case Structures.Type.Fortress: // Fort?
                            chunk.Blocks.SetID(x, height - 1, z, BlockType.IRON_BLOCK);
                            break;
                        case Structures.Type.ElvenCity1: // Farm?
                            chunk.Blocks.SetID(x, height - 1, z, BlockType.FARMLAND);
                            break;
                        case Structures.Type.ElvenCity2: // Farm?
                            chunk.Blocks.SetID(x, height - 1, z, BlockType.MELON);
                            break;
                        case Structures.Type.ElvenCity3: // Farm?
                            chunk.Blocks.SetID(x, height - 1, z, BlockType.PUMPKIN);
                            break;
                        default:
                            directions neighbor = getRoadEdge(mapData, x + 1, z + 1);  // +1 for edge shift

                            switch (neighbor)
                            {
                                case directions.north:
                                case directions.south:
                                    if (x % 4 < 3)
                                    {
                                        if (x % 8 == 1)
                                        {
                                            chunk.Blocks.SetID(x, height + 1, z, BlockType.TORCH);
                                            currentWorld.
                                            chunk.Blocks.GetBlock(x, height + 1, z).SetTileEntity(                                        }
                                        chunk.Blocks.SetID(x, height, z, BlockType.FENCE);
                                    }
                                    break;
                                case directions.west:
                                case directions.east:
                                    if (z % 4 < 3)
                                    {
                                        chunk.Blocks.SetID(x, height, z, BlockType.FENCE);
                                        if (z % 8 == 1)
                                        {
                                            chunk.Blocks.SetID(x, height + 1, z, BlockType.TORCH);
                                        }
                                    }
                                    break;
                            }

                            break;
                    }
                }
            }
        }
Ejemplo n.º 10
0
 if (R_RadiusCullLocalBox(bounds, modelMatrix, numPlanes, planes))
 {
     return(true);
Ejemplo n.º 11
0
 public static bool IsInside(bounds _b, float3 _pos)
 {
     return((_b.maxPoints.x > _pos.x && _b.maxPoints.y > _pos.y && _b.maxPoints.z > _pos.z) &&
            (_b.minPoints.x < _pos.x && _b.minPoints.y < _pos.y && _b.minPoints.z < _pos.z));
 }
Ejemplo n.º 12
0
 public static bool AABBOverlap(bounds _a, bounds _b)
 {
     return((_a.minPoints.x <= _b.maxPoints.x && _a.maxPoints.x >= _b.minPoints.x) &&
            (_a.minPoints.y <= _b.maxPoints.y && _a.maxPoints.y >= _b.minPoints.y) &&
            (_a.minPoints.z <= _b.maxPoints.z && _a.maxPoints.z >= _b.minPoints.z));
 }