static public void setBladeToGrid(int x, int z, string setName, int bladeIndex, bool erase, bool forceErase) { int terrainToFoliageGridMultiple = (int)(BTerrainQuadNode.cMaxWidth / FoliageManager.cNumUsedXBladesPerChunk); if (x % terrainToFoliageGridMultiple != 0 || z % terrainToFoliageGridMultiple != 0) { return; } int setIndex = giveIndexOfSet(setName); int idx = x + TerrainGlobals.getTerrain().getNumXVerts() * z; int minQNX = (int)(x / BTerrainQuadNode.cMaxWidth); int minQNZ = (int)(z / BTerrainQuadNode.cMaxHeight); int numXChunks = (int)(TerrainGlobals.getTerrain().getNumXVerts() / BTerrainQuadNode.cMaxWidth); int qnIndex = minQNX + numXChunks * minQNZ; int idex = giveChunkWithParentIndex(qnIndex); if (erase) { if (mVertData.ContainsValue(idx)) { if (!forceErase) { FoliageVertData vRep = mVertData.GetValue(idx); if (giveIndexOfSet(vRep.mFoliageSetName) != setIndex || vRep.mFoliageSetBladeIndex != bladeIndex) { return; } } mVertData.SetValue(idx, new FoliageVertData()); //Default 'empty' for a jagged<T> value is the default constructor.. if (idex != -1) { mQNChunks[idex].destroyRenderVBs(); } } } else { mVertData.SetValue(idx, new FoliageVertData(setName, bladeIndex)); if (idex == -1)//we need to add a new chunk { idex = mQNChunks.Count; addNewChunk(qnIndex); } mQNChunks[idex].bladeAdded(mFoliageSets[setIndex].mFullFileName); } }
//------------------------------------- public void createRenderVBs() { destroyRenderVBs(); int width = TerrainGlobals.getTerrain().getNumXVerts(); for (int setI = 0; setI < mSetsUsed.Count; setI++) { List <int> validIndexes = new List <int>(); List <int> validBladeIndexes = new List <int>(); for (int x = 0; x < BTerrainQuadNode.cMaxWidth; x++) { for (int z = 0; z < BTerrainQuadNode.cMaxWidth; z++) { int index = (x + mOwnerNodeDesc.mMinXVert) + width * (z + mOwnerNodeDesc.mMinZVert); FoliageVertData fvd = FoliageManager.mVertData.GetValue(index); if (fvd.compare(FoliageManager.cEmptyVertData)) { continue; } if (FoliageManager.giveIndexOfSet(fvd.mFoliageSetName) == FoliageManager.giveIndexOfSet(mSetsUsed[setI])) { int localIndex = x + FoliageManager.cNumXBladesPerChunk * z; validIndexes.Add(localIndex); validBladeIndexes.Add(fvd.mFoliageSetBladeIndex); } } } if (validIndexes.Count == 0) { //remove this set from us mSetsUsed.RemoveAt(setI); setI--; continue; } //now that we have our valid indexes int numVertsPerBlade = 10; int totalNumVerts = (validIndexes.Count * numVertsPerBlade); //VERTEX BUFFERS mSetVBs.Add(new VertexBuffer(typeof(VertexTypes.Pos), totalNumVerts, BRenderDevice.getDevice(), Usage.WriteOnly, VertexTypes.Pos.FVF_Flags, Pool.Default)); GraphicsStream gStream = mSetVBs[setI].Lock(0, 0, LockFlags.None); unsafe { VertexTypes.Pos *verts = (VertexTypes.Pos *)gStream.InternalDataPointer; mSetVertCount.Add(0); //ADD OTHER STRIPS for (int i = 0; i < validIndexes.Count; i++) { int vC = mSetVertCount[setI]; int startInd = validIndexes[i] * numVertsPerBlade; //add 10 verts with: index (x*width+z), bladeIndex, 0, 0 for (int k = 0; k < numVertsPerBlade; k++) { verts[vC].x = startInd + k; verts[vC].y = validBladeIndexes[i]; vC++; } mSetVertCount[setI] += numVertsPerBlade; } } gStream.Close(); mSetVBs[setI].Unlock(); //INDEX BUFFERS (UGG WE SHOULD BE USING TRI-STRIPS!!!) int numInds = (validIndexes.Count * ((numVertsPerBlade - 2) * 3)); mSetIBs.Add(new IndexBuffer(typeof(short), numInds, BRenderDevice.getDevice(), Usage.WriteOnly, Pool.Default)); gStream = mSetIBs[setI].Lock(0, 0, LockFlags.None); unsafe { short *inds = (short *)gStream.InternalDataPointer; mSetPolyCount.Add(0); //add first strip short startInd = (short)(0); int vC = 0; for (int i = 0; i < validIndexes.Count; i++) { startInd = (short)(i * (numVertsPerBlade)); short pC = (short)((numVertsPerBlade - 2) >> 1); short sI = 0; for (int k = 0; k < pC; k++) { inds[vC++] = (short)(startInd + sI + 0); inds[vC++] = (short)(startInd + sI + 1); inds[vC++] = (short)(startInd + sI + 2); inds[vC++] = (short)(startInd + sI + 1); inds[vC++] = (short)(startInd + sI + 2); inds[vC++] = (short)(startInd + sI + 3); sI += 2; } mSetPolyCount[setI] += (numVertsPerBlade - 2); } } gStream.Close(); mSetIBs[setI].Unlock(); } //COOL! }
public bool compare(FoliageVertData a) { return(a.mFoliageSetName == mFoliageSetName && a.mFoliageSetBladeIndex == mFoliageSetBladeIndex); }