//---------------------------------------------- //---------------------------------------------- //---------------------------------------------- //---------------------------------------------- //---------------------------------------------- //---------------------------------------------- private unsafe int writeChunk(XTDTerrainChunk chunk, BinaryWriter mem) { mem.Write(Xbox_EndianSwap.endSwapI32(chunk.gridLocX)); mem.Write(Xbox_EndianSwap.endSwapI32(chunk.gridLocZ)); mem.Write(Xbox_EndianSwap.endSwapI32(chunk.maxVertStride)); mem.Write(Xbox_EndianSwap.endSwapF32(chunk.mMin.X)); mem.Write(Xbox_EndianSwap.endSwapF32(chunk.mMin.Y)); mem.Write(Xbox_EndianSwap.endSwapF32(chunk.mMin.Z)); mem.Write(Xbox_EndianSwap.endSwapF32(chunk.mMax.X)); mem.Write(Xbox_EndianSwap.endSwapF32(chunk.mMax.Y)); mem.Write(Xbox_EndianSwap.endSwapF32(chunk.mMax.Z)); bool canCastShadows = true; if (chunk.mMax.Y - chunk.mMin.Y < 2) { canCastShadows = false; } mem.Write(canCastShadows); return(0); }
private void generateGridChunks(ref XTDVisualHeader header) { //Create and write our flat terrain quadnode chunks BTerrainQuadNode[] mLeafNodes = TerrainGlobals.getTerrain().getQuadNodeLeafArray(); for (int i = 0; i < mLeafNodes.Length; i++) { int width = (int)BTerrainQuadNode.getMaxNodeWidth(); ECF.ECFChunkHolder chunkHolder = new ECF.ECFChunkHolder(); chunkHolder.mDataMemStream = new MemoryStream(); BinaryWriter binWriter = new BinaryWriter(chunkHolder.mDataMemStream); XTDTerrainChunk gridNode = new XTDTerrainChunk(); int locX = mLeafNodes[i].getDesc().mMinXVert / width; int locZ = mLeafNodes[i].getDesc().mMinZVert / width; gridNode.gridLocX = locX; gridNode.gridLocZ = locZ; //calculate our chunk data gridNode.heightmapOnly = false; gridNode.maxVertStride = 64; //lets get our verts, normals, and ambOcclu int mnX = locX * width; int mnZ = locZ * width; BBoundingBox bb = new BBoundingBox(); bb.empty(); for (int z = 0; z < width + 1; z++) { for (int x = 0; x < width + 1; x++) { int xVal = (int)(mnX + x); int zVal = (int)(mnZ + z); Vector3 v = TerrainGlobals.getTerrain().getPos(xVal, zVal); bb.addPoint(v); } } gridNode.mMin = bb.min; gridNode.mMax = bb.max; //IF WE CONTAIN FOLIAGE! increase the size of our bounding boxes.. if (FoliageManager.isChunkUsed(mLeafNodes[i])) { BBoundingBox bbA = FoliageManager.giveMaxBBs(); gridNode.mMin += bbA.min; gridNode.mMax += bbA.max; } //expand our box a tad float scle = TerrainGlobals.getTerrain().getTileScale(); gridNode.mMin -= new Vector3(scle, scle, scle); gridNode.mMax += new Vector3(scle, scle, scle); //send the verts off to the compressor to be compressed properly into an image (using whatever technique) //be sure to assign a corolary ID so we can reference it later. writeChunk(gridNode, binWriter); //add this chunk to our main data stream ExportTo360.mECF.addChunk((int)eXTD_ChunkID.cXTD_TerrainChunk, chunkHolder, binWriter.BaseStream.Length); binWriter.Close(); binWriter = null; chunkHolder.Close(); chunkHolder = null; } mLeafNodes = null; }