static public BBoundingBox giveMaxBBs() { BBoundingBox bb = new BBoundingBox(); bb.empty(); for (int i = 0; i < getNumSets(); i++) { bb.addPoint(mFoliageSets[i].mBBMin); bb.addPoint(mFoliageSets[i].mBBMax); } return(bb); }
void recalculateCellBB(SpatialQuadTreeCell spatialCell) { BBoundingBox bb = new BBoundingBox(); bb.empty(); RealLOSRepQuadCell cell = ((RealLOSRepQuadCell)spatialCell.mExternalData); for (uint i = (uint)cell.mMinXVert; i <= cell.mMinXVert + mNumXVertsPerCell; i++) { for (uint j = (uint)cell.mMinZVert; j <= cell.mMinZVert + mNumZVertsPerCell; j++) { if (i >= mWidth || j >= mHeight) { continue; } float3 worldPos = getWorldspacePoint((int)i, (int)j); bb.addPoint(worldPos.toVec3()); } } spatialCell.setBounds(new float3(bb.min), new float3(bb.max)); bb = null; }
void writeTempModelsToZip(ZipArchive zip) { SceneObjectsXML sceneObjects = new SceneObjectsXML(); BBoundingBox objectAABB = new BBoundingBox(); objectAABB.empty(); string baseDir = CoreGlobals.getWorkPaths().mGameDirectory; if (mIncludeObjects) { //searalize an XML file to memorystream holding position and model names List <EditorObject> editObjs = SimGlobals.getSimMain().getEditorObjects(false, SimMain.eFilterTypes.cFilterAll, -1, false); for (int objIdx = 0; objIdx < editObjs.Count; objIdx++) { if (editObjs[objIdx] == null) { continue; } if (editObjs[objIdx].GetType() == typeof(SimObject)) { SimObject obj = editObjs[objIdx] as SimObject; if (obj.IgnoreToAO) { continue; } if (obj != null && obj.ProtoObject != null) { string grannyName = obj.ProtoObject.getGrannyFileName(); if (grannyName == "") { continue; } if (grannyName.Contains(baseDir)) { grannyName = grannyName.Remove(0, baseDir.Length); } //if this GR2 isn't already listed, then list it. if (!sceneObjects.objectGR2Names.Contains(grannyName)) { sceneObjects.objectGR2Names.Add(grannyName); } //add our instance ObjectInstanceXML inst = new ObjectInstanceXML(); inst.GR2Filename = grannyName; inst.setOrientation(obj.getMatrix()); sceneObjects.objectinstances.Add(inst); //add our transformed BB to the global BB list if (obj != null && obj.mVisual != null) { if (!obj.IgnoreToAO) { objectAABB.addPoint(obj.mAABB.max + obj.getPosition()); objectAABB.addPoint(obj.mAABB.min + obj.getPosition()); } } } } } sceneObjects.aabbmin = TextVectorHelper.ToString(objectAABB.min); sceneObjects.aabbmax = TextVectorHelper.ToString(objectAABB.max); } //write it to an XML stream AbstractFile md = zip.CreateFile("modelPositions.xml", true); Stream stream = md.OpenWrite(true); XmlSerializer s = new XmlSerializer(typeof(SceneObjectsXML), new Type[] { }); s.Serialize(stream, sceneObjects); stream.Close(); //Create a folder and copy our GR2s into it //AbstractFolder fold = zip.CreateFolder("models"); //if (mIncludeObjects) //{ // for (int modelIdx = 0; modelIdx < sceneObjects.objectGR2Names.Count; modelIdx++) // { // if (mWorkerThread.CancellationPending) // return; // try // { // if (fullGR2Names[modelIdx] == "") // continue; // DiskFile modelFile = new DiskFile(fullGR2Names[modelIdx]); // modelFile.CopyTo(fold, true); // } // catch (Exception e) // { // continue; // } // } //} }
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; }