private void markOverrideTessellations(ErrorMetricRefine refiner) { JaggedContainer <byte> v = TerrainGlobals.getEditor().getJaggedTesselation(); int width = TerrainGlobals.getTerrain().getNumXVerts(); long id; byte maskValue; v.ResetIterator(); while (v.MoveNext(out id, out maskValue)) { if (maskValue == BTerrainEditor.cTesselationEmptyVal) { continue; } int x = (int)(id / width); int z = (int)(id - x * width); if (maskValue == (int)BTerrainEditor.eTessOverrideVal.cTess_Max) { refiner.setMarkedPt(x, z, true); } else if (maskValue == (int)BTerrainEditor.eTessOverrideVal.cTess_Min) { refiner.setMarkedPt(x, z, false); } } }
public bool LoadV2(BinaryReader b) { int count = b.ReadInt32(); for (int i = 0; i < count; i++) { MaskItem item = new MaskItem(); item.mMask = MaskFactory.GetNewMask(); item.Name = b.ReadString(); JaggedContainer <float> container = item.mMask as JaggedContainer <float>; container.LoadByStripe(b, (JaggedContainer <float> .LoadStripeDelegate)(delegate(BinaryReader r, float[] values) { for (int j = 0; j < values.Length; j++) { values[j] = r.ReadSingle(); } })); //CLM [07.27.07] //these older versions need to be scaled by 0.5 because of a //massive terrain scaling change. int oldSize = TerrainGlobals.getTerrain().getNumXVerts() * 2; resampleJaggedArrayFloat(ref container, oldSize, oldSize, TerrainGlobals.getTerrain().getNumXVerts(), TerrainGlobals.getTerrain().getNumXVerts(), 0); MaskCheckList.Items.Add(item, false); } return(true); }
public bool LoadV1(int count, Stream s) { MaskCheckList.Items.Clear(); BinaryReader b = new BinaryReader(s); //int count = b.ReadInt32(); for (int i = 0; i < count; i++) { MaskItem item = new MaskItem(); item.mMask = MaskFactory.GetNewMask(); item.Name = b.ReadString(); int hashSize = b.ReadInt32(); for (int j = 0; j < hashSize; j++) { long key = b.ReadInt64(); float val = b.ReadSingle(); item.mMask.SetMaskWeight(key, val); } //MaskListView.Items.Add(item); //CLM [07.27.07] //these older versions need to be scaled by 0.5 because of a //massive terrain scaling change. int oldSize = TerrainGlobals.getTerrain().getNumXVerts() * 2; JaggedContainer <float> container = item.mMask as JaggedContainer <float>; resampleJaggedArrayFloat(ref container, oldSize, oldSize, TerrainGlobals.getTerrain().getNumXVerts(), TerrainGlobals.getTerrain().getNumXVerts(), 0); MaskCheckList.Items.Add(item, false); } return(true); }
private void toolStripButton6_Click(object sender, EventArgs e) { int tWidth = TerrainGlobals.getTerrain().getNumXVerts(); int tHeight = TerrainGlobals.getTerrain().getNumZVerts(); DAGMask resMask = canvasForm.execute(tWidth, tHeight); if (resMask == null) { MessageBox.Show("There was an error computing output"); return; } Masking.clearSelectionMask(); for (int x = 0; x < tWidth; x++) { for (int y = 0; y < tHeight; y++) { float k = resMask[x, y]; Masking.addSelectedVert(x, y, k); } } Masking.rebuildVisualsAfterSelection(); resMask = null; }
public void renderSubWindow(int minXChunk, int minZChunk, int maxXChunk, int maxZChunk) { int numXNodes = (int)(TerrainGlobals.getTerrain().getNumXVerts() / BTerrainQuadNode.cMaxWidth); minXChunk = (int)(BMathLib.Clamp(minXChunk, 0, numXNodes - 1)); minZChunk = (int)(BMathLib.Clamp(minZChunk, 0, numXNodes - 1)); maxXChunk = (int)(BMathLib.Clamp(maxXChunk, 0, numXNodes - 1)); maxZChunk = (int)(BMathLib.Clamp(maxZChunk, 0, numXNodes - 1)); //set LOD Level mTerrainGPUShader.mShader.SetValue(mShaderChunkScaleHandle, TerrainGlobals.getTerrain().getTileScale()); BRenderDevice.getDevice().SetStreamSource(0, mVB, 0); mTerrainGPUShader.mShader.BeginPass((int)mPassNum); BTerrainQuadNode[] mNodes = TerrainGlobals.getTerrain().getQuadNodeLeafArray(); for (int i = minXChunk; i < maxXChunk; i++) { for (int j = minZChunk; j < maxZChunk; j++) { int indx = i * numXNodes + j; renderLeafNode(mNodes[indx]); } } mTerrainGPUShader.mShader.EndPass(); }
void findMaxsMinsRange(ref Vector3 max, ref Vector3 mid, ref Vector3 range) { BBoundingBox bb = TerrainGlobals.getTerrain().getDisplacementBB(); max = bb.max; mid = bb.min; range = (max - mid) * 2.1f; mid = range * 0.5f; mid.X = rangeCompact(mid.X); mid.Y = rangeCompact(mid.Y); mid.Z = rangeCompact(mid.Z); range = (mid * 2.1f); if (range.X == 0) { mid.X = 0; range.X = 1; } if (range.Y == 0) { mid.Y = 0; range.Y = 1; } if (range.Z == 0) { mid.Z = 0; range.Z = 1; } }
override public bool computeOutput(ConnectionPoint connPoint, OutputGenerationParams parms) { if (!verifyInputConnections()) { return(false); } if (!gatherInputAndParameters(parms)) { return(false); } MaskParam mp = ((MaskParam)(connPoint.ParamType)); mp.Value = new DAGMask(InputMask.Width, InputMask.Height); for (int x = 0; x < parms.Width; x++) { for (int y = 0; y < parms.Height; y++) { Vector2 v = TerrainGlobals.getTerrain().getGradiant(x, y); float factor = BMathLib.Clamp(v.Length(), 0, 1); if (factor < 0) { continue; } mp.Value[x, y] = factor; } } return(true); }
private void ExportButton_Click(object sender, EventArgs e) { if (!mIsQuickExport) { TerrainGlobals.getTerrain().setExportSettings(mExportSettings); } this.Close(); }
float calcAdjustedMidValue(float inputMid) { BBoundingBox bb = TerrainGlobals.getTerrain().getDisplacementBB(); float diff = bb.max.Y - bb.min.Y; int qDiff = (int)(diff / 100) * 2; float adjustedMid = qDiff / 10.0f; return(inputMid - adjustedMid); }
Vector3 calcAdjustedMidValue(Vector3 inputMid) { BBoundingBox bb = TerrainGlobals.getTerrain().getDisplacementBB(); Vector3 diff = bb.max - bb.min; int qDiff = (int)(diff.Y / 100) * 2; Vector3 adjustedMid = new Vector3(0, qDiff / 10.0f, 0); return(inputMid - adjustedMid); }
void renderLeafNode(BTerrainQuadNode node) { int lod = (int)BTerrainVisual.eLODLevel.cLOD0; BTerrainQuadNodeDesc desc = node.getDesc(); float scale = TerrainGlobals.getTerrain().getTileScale() * ((int)Math.Pow(2, lod)); Vector4 DataVals = new Vector4(2 * (BTerrainQuadNode.getMaxNodeWidth() >> lod), scale, desc.mMinXVert, desc.mMinZVert); mTerrainGPUShader.mShader.SetValue(mShaderDataValsHandle, DataVals); mTerrainGPUShader.mShader.CommitChanges(); BRenderDevice.getDevice().DrawPrimitives(PrimitiveType.TriangleList, 0, (int)mNumPrims); }
private void button1_Click(object sender, EventArgs e) { TerrainCreationParams prms = new TerrainCreationParams(); prms.initFromVisData(TerrainGlobals.getTerrain().getNumXVerts(), TerrainGlobals.getTerrain().getNumZVerts(), TerrainGlobals.getTerrain().getTileScale(), visToSimMul); TerrainGlobals.getEditor().getSimRep().reinit(prms.mNumSimXTiles, prms.mNumSimZTiles, prms.mSimTileSpacing, 1.0f / (float)visToSimMul); TerrainGlobals.getEditor().getSimRep().update(false, false);// updateSimRep(TerrainGlobals.getEditor().getDetailPoints(), TerrainGlobals.getTerrain().getNumXVerts(), TerrainGlobals.getTerrain().getTileScale(), false); this.Close(); }
private void button1_Click(object sender, EventArgs e) { int tWidth = TerrainGlobals.getTerrain().getNumXVerts(); int tHeight = TerrainGlobals.getTerrain().getNumZVerts(); DAGMask resMask = canvasForm.execute(tWidth, tHeight); if (resMask == null) { MessageBox.Show("There was an error computing output"); return; } PictureBox pixBoxHighRes = new PictureBox(); pixBoxHighRes.Width = tWidth; pixBoxHighRes.Height = tHeight; Bitmap bmp = new Bitmap(tWidth, tHeight, PixelFormat.Format24bppRgb); for (int x = 0; x < tWidth; x++) { for (int y = 0; y < tHeight; y++) { float clampK = resMask[x, y]; if (clampK < 0) { clampK = 0; } if (clampK > 1) { clampK = 1; } byte bc = (byte)(clampK * byte.MaxValue); Color col; if (mColorsImage == null) { col = Color.FromArgb(255, bc, bc, bc); } else { col = mColorsImage.GetPixel(bc, mColorLineIndex); } bmp.SetPixel(x, y, col); } } pixBoxHighRes.Image = bmp; PopupEditor pe = new PopupEditor(); pe.ShowPopup(this, pixBoxHighRes, FormBorderStyle.FixedToolWindow, false, "Preview : " + tWidth + "x" + tHeight); }
public void renderAll() { //set LOD Level mTerrainGPUShader.mShader.SetValue(mShaderChunkScaleHandle, TerrainGlobals.getTerrain().getTileScale()); BRenderDevice.getDevice().SetStreamSource(0, mVB, 0); mTerrainGPUShader.mShader.BeginPass((int)mPassNum); BTerrainQuadNode[] mNodes = TerrainGlobals.getTerrain().getQuadNodeLeafArray(); for (int i = 0; i < mNodes.Length; i++) { renderLeafNode(mNodes[i]); } mTerrainGPUShader.mShader.EndPass(); }
private void ToFileButton_Click(object sender, EventArgs e) { SaveFileDialog d = new SaveFileDialog(); d.Filter = "Raw32 (*.r32)|*.r32"; if (d.ShowDialog() == DialogResult.OK) { BinaryWriter w = new BinaryWriter(File.OpenWrite(d.FileName)); IMask mask = Masking.getCurrSelectionMaskWeights(); long max = TerrainGlobals.getTerrain().getNumXVerts() * TerrainGlobals.getTerrain().getNumXVerts(); for (long i = 0; i < max; i++) { w.Write(mask.GetMaskWeight(i)); } w.Close(); } }
public void computeAOSection(string ouputDumpFilename, int numSections, int mySecetion, Terrain.AmbientOcclusion.eAOQuality quality) { int numSamples = (int)quality; int samplesPerSection = (int)(numSamples / numSections); int startSampleCount = samplesPerSection * mySecetion; int endSampleCount = startSampleCount + samplesPerSection; Terrain.AmbientOcclusion ao = new Terrain.AmbientOcclusion(); float totalTime = 0; float peelTime = 0; float gatherTime = 0; ao.calcualteAO(quality, true, ref totalTime, ref peelTime, ref gatherTime, startSampleCount, endSampleCount); ao.destroy(); ao = null; //write our AO to a binary file FileStream s = File.Open(ouputDumpFilename, FileMode.OpenOrCreate, FileAccess.Write); BinaryWriter f = new BinaryWriter(s); int width = TerrainGlobals.getTerrain().getNumXVerts(); int height = TerrainGlobals.getTerrain().getNumZVerts(); //write our header. f.Write(cMajik); f.Write(numSections); f.Write(mySecetion); f.Write(numSamples); f.Write(startSampleCount); f.Write(endSampleCount); f.Write(width); f.Write(height); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { float AOVal = TerrainGlobals.getTerrain().getAmbientOcclusion(x, y); f.Write(AOVal); } } f.Close(); s.Close(); }
private void initSliders() { boundryTopSlider.Setup(0, TerrainGlobals.getTerrain().getNumXVerts(), false); boundryTopSlider.NumericValue = SimGlobals.getSimProperties().mTopBoundry; boundryTopSlider.ValueChanged += new EventHandler(boundryTopSlider_ValueChanged); boundryBottomSlider.Setup(0, TerrainGlobals.getTerrain().getNumXVerts(), false); boundryBottomSlider.NumericValue = SimGlobals.getSimProperties().mBottomBoundry; boundryBottomSlider.ValueChanged += new EventHandler(boundryBottomSlider_ValueChanged); boundryLeftSlider.Setup(0, TerrainGlobals.getTerrain().getNumXVerts(), false); boundryLeftSlider.NumericValue = SimGlobals.getSimProperties().mLeftBoundry; boundryLeftSlider.ValueChanged += new EventHandler(boundryLeftSlider_ValueChanged); boundryRightSlider.Setup(0, TerrainGlobals.getTerrain().getNumXVerts(), false); boundryRightSlider.NumericValue = SimGlobals.getSimProperties().mRightBoundry; boundryRightSlider.ValueChanged += new EventHandler(boundryRightSlider_ValueChanged); }
public void preRenderSetup() { BRenderDevice.getDevice().VertexDeclaration = VertexTypes.Pos.vertDecl; Matrix g_matView; Matrix g_matProj; g_matView = BRenderDevice.getDevice().Transform.View; g_matProj = BRenderDevice.getDevice().Transform.Projection; Matrix worldViewProjection = g_matView * g_matProj; mTerrainGPUShader.mShader.SetValue(mShaderWVPHandle, worldViewProjection); mTerrainGPUShader.mShader.SetValue(mShaderPositionsTexHandle, mPositionsTexture); mTerrainGPUShader.mShader.SetValue(mShaderNumWorldXVertsHandle, TerrainGlobals.getTerrain().getNumXVerts()); BRenderDevice.getDevice().SetRenderState(RenderStates.CullMode, (int)Cull.None); mTerrainGPUShader.mShader.Begin(0); }
void cleanMap() { //clean detail Vector3[] detialPts = TerrainGlobals.getEditor().getDetailPoints(); int width = TerrainGlobals.getTerrain().getNumXVerts(); for (int x = 0; x < width * width; x++) { detialPts[x].X = 0; detialPts[x].Y = 0; detialPts[x].Z = 0; } //clean textures //clear sim SimGlobals.getSimMain().selectAll(); SimGlobals.getSimMain().DeleteSelected(); }
void findMaxsMinsRange(ref float max, ref float mid, ref float range) { BBoundingBox bb = TerrainGlobals.getTerrain().getDisplacementBB(); max = bb.max.Y; mid = bb.min.Y; range = (max - mid) * 2.1f; mid = range * 0.5f; mid = rangeCompact(mid); range = (mid * 2.1f); if (range == 0) { mid = 0; range = 1; } }
private void toolStripButton5_Click(object sender, EventArgs e) { int tWidth = TerrainGlobals.getTerrain().getNumXVerts(); int tHeight = TerrainGlobals.getTerrain().getNumZVerts(); DAGMask resMask = canvasForm.execute(tWidth, tHeight); if (resMask == null) { MessageBox.Show("There was an error computing output"); return; } GraphBasedMask gbm = new GraphBasedMask(); bool ok = canvasForm.saveCanvasToMemoryStream(gbm.GraphMemStream); if (!ok) { MessageBox.Show("There was an error creating the mask memory stream"); return; } CoreGlobals.getEditorMain().mIMaskPickerUI.AddMaskToList(gbm, "GraphMask" + CoreGlobals.getEditorMain().mIMaskPickerUI.GetNumMasks()); }
public bool Save(Stream s) { BinaryWriter b = new BinaryWriter(s); b.Write(cNewVersionDelimeter); b.Write(MaskCheckList.Items.Count); b.Write(TerrainGlobals.getTerrain().getNumXVerts()); foreach (MaskItem item in MaskCheckList.Items) { b.Write(item.Name); b.Write(item.mMask.GetType().ToString()); if (item.mMask is ArrayBasedMask) { JaggedContainer <float> container = item.mMask as JaggedContainer <float>; container.SaveByStripe(b, (JaggedContainer <float> .SaveStripeDelegate)(delegate(BinaryWriter w, float[] values) { for (int i = 0; i < values.Length; i++) { w.Write(values[i]); } })); } else if (item.mMask is GraphBasedMask) { GraphBasedMask gbm = item.mMask as GraphBasedMask; b.Write(gbm.GraphMemStream.Length); gbm.GraphMemStream.Seek(0, SeekOrigin.Begin); gbm.GraphMemStream.WriteTo(b.BaseStream); } } return(true); }
public void writeQNsToChunk(ref ExportResults results) { DateTime n = DateTime.Now; int totalMemory = 0; int width = TerrainGlobals.getTerrain().getNumXVerts(); for (int qi = 0; qi < FoliageManager.getNumChunks(); qi++) { FoliageQNChunk chunk = FoliageManager.getChunk(qi); List <int> setIndexes = new List <int>(); List <int> setPolyCounts = new List <int>(); int totalPhysicalMemory = 0; List <int> indMemSizes = new List <int>(); List <int> bladeIBs = new List <int>(); for (int setI = 0; setI < chunk.mSetsUsed.Count; setI++) { int numBlades = 0; int startIndex = bladeIBs.Count; FoliageSet fs = FoliageManager.giveSet(chunk.mSetsUsed[setI]); //walk through the main grid for our current chunk //pack the data into proper inds.. for (int x = 0; x < BTerrainQuadNode.cMaxWidth; x++) { for (int z = 0; z < BTerrainQuadNode.cMaxWidth; z++) { int index = (x + chunk.mOwnerNodeDesc.mMinXVert) + width * (z + chunk.mOwnerNodeDesc.mMinZVert); FoliageVertData fvd = FoliageManager.mVertData.GetValue(index); if (fvd.compare(FoliageManager.cEmptyVertData)) { continue; } if (FoliageManager.giveIndexOfSet(fvd.mFoliageSetName) == FoliageManager.giveIndexOfSet(chunk.mSetsUsed[setI])) { numBlades++; //our local blade index is transposed on the 360 int localIndex = x * FoliageManager.cNumXBladesPerChunk + z; int bladeIndex = fvd.mFoliageSetBladeIndex << 16; for (short t = 0; t < fs.mNumVertsPerBlade; t++) { int packedID = bladeIndex | (0xFFFF & (localIndex * fs.mNumVertsPerBlade) + t); bladeIBs.Add(packedID); } bladeIBs.Add(0xFFFF); //360 specific tag to stop a strip. } } } int numVerts = bladeIBs.Count - startIndex; if (numVerts == 0) { continue; } setIndexes.Add(FoliageManager.giveIndexOfSet(chunk.mSetsUsed[setI])); setPolyCounts.Add(numBlades * (fs.mNumVertsPerBlade + 1) - 2); indMemSizes.Add(numVerts * sizeof(int)); totalPhysicalMemory += indMemSizes[indMemSizes.Count - 1]; } //now write this chunk.. ECF.ECFChunkHolder chunkHolder = new ECF.ECFChunkHolder(); chunkHolder.mDataMemStream = new MemoryStream(); BinaryWriter binWriter = new BinaryWriter(chunkHolder.mDataMemStream); //our chunk index is transposed in the game int minQNX = (int)(chunk.mOwnerNodeDesc.mMinXVert / BTerrainQuadNode.cMaxWidth); int minQNZ = (int)(chunk.mOwnerNodeDesc.mMinZVert / BTerrainQuadNode.cMaxHeight); int numXChunks = (int)(TerrainGlobals.getTerrain().getNumXVerts() / BTerrainQuadNode.cMaxWidth); int transposedOwnerIndex = minQNX * numXChunks + minQNZ; binWriter.Write(Xbox_EndianSwap.endSwapI32(transposedOwnerIndex));//chunk.mOwnerQNIndex)); binWriter.Write(Xbox_EndianSwap.endSwapI32(setIndexes.Count)); int numSets = setIndexes.Count; for (int i = 0; i < numSets; i++) { binWriter.Write(Xbox_EndianSwap.endSwapI32(setIndexes[i])); } for (int i = 0; i < numSets; i++) { binWriter.Write(Xbox_EndianSwap.endSwapI32(setPolyCounts[i])); } binWriter.Write(Xbox_EndianSwap.endSwapI32(totalPhysicalMemory)); totalMemory += totalPhysicalMemory; for (int i = 0; i < numSets; i++) { binWriter.Write(Xbox_EndianSwap.endSwapI32(indMemSizes[i])); } for (int i = 0; i < bladeIBs.Count; i++) { binWriter.Write(Xbox_EndianSwap.endSwapI32(bladeIBs[i])); } ExportTo360.mECF.addChunk((int)eXTT_ChunkID.cXTT_FoliageQNChunk, chunkHolder, binWriter.BaseStream.Length); binWriter.Close(); binWriter = null; chunkHolder.Close(); chunkHolder = null; } TimeSpan ts = DateTime.Now - n; results.terrainFoliageTime = ts.TotalMinutes; results.terrainFoliageMemory = totalMemory; }
Vector3 getPt(int x, int z) { return(TerrainGlobals.getTerrain().getPos(mRootX + x, mRootZ + z)); }
static void estimateTerrainMemory() { using (PerfSection p3 = new PerfSection("estimateTerrainMemory")) { int width = TerrainGlobals.getTerrain().getNumXVerts(); //CLM THESE ESTIMATES ARE VALID AS OF [07.24.07] ///XTD //positions & normals - each component is 32bit mMemoryUsageItems.Add(new memoryElement("Terrain Positions & Normals", (width * width * 8), eMainCatagory.eCat_Terrain)); //ALPHA - DXT5A mMemoryUsageItems.Add(new memoryElement("Terrain Alpha", ((width >> 2) * (width >> 2) * 8), eMainCatagory.eCat_Terrain)); //AO - DXT5A mMemoryUsageItems.Add(new memoryElement("Terrain AO", ((width >> 2) * (width >> 2) * 8), eMainCatagory.eCat_Terrain)); //TessData int nodeWidth = 16; int numXPatches = (int)(TerrainGlobals.getTerrain().getNumXVerts() / (float)nodeWidth); int tessMem = numXPatches * numXPatches; tessMem += (numXPatches * numXPatches * 2) * (sizeof(float) * 4); mMemoryUsageItems.Add(new memoryElement("Terrain Tessellation", tessMem, eMainCatagory.eCat_Terrain)); //light data - DXT1 if (LightManager.hasTerrainLightData()) { mMemoryUsageItems.Add(new memoryElement("Terrain Precomputed Lighting", ((width * width) >> 2), eMainCatagory.eCat_Terrain)); } //////XTT //texture alpha data int texAlphaMem = 0; BTerrainQuadNode[] nodes = TerrainGlobals.getTerrain().getQuadNodeLeafArray(); for (int i = 0; i < nodes.Length; i++) { int numAlignedSplatLayers = 4 * (((nodes[i].mLayerContainer.getNumSplatLayers() - 1) >> 2) + 1); int numAlignedDecalLayers = 4 * (((nodes[i].mLayerContainer.getNumDecalLayers() - 1) >> 2) + 1); texAlphaMem += numAlignedSplatLayers * ((64 * 64) >> 2); } mMemoryUsageItems.Add(new memoryElement("Terrain Texture Blends", texAlphaMem, eMainCatagory.eCat_Terrain)); //unique Albedo int uniqueTextureRes = 128; int uniqueWidth = (int)((width / BTerrainQuadNode.cMaxWidth) * uniqueTextureRes); int uniqueMemSize = (int)(uniqueWidth * uniqueWidth); if (BMathLib.isPow2(uniqueWidth)) { uniqueMemSize += (uniqueWidth >> 1) * (uniqueWidth >> 1); } mMemoryUsageItems.Add(new memoryElement("Terrain Unique Albedo Texture", (uniqueMemSize >> 1), eMainCatagory.eCat_Terrain)); //FOLIAGE int totalPhysicalMemory = 0; for (int qi = 0; qi < FoliageManager.getNumChunks(); qi++) { FoliageQNChunk chunk = FoliageManager.getChunk(qi); for (int setI = 0; setI < chunk.mSetsUsed.Count; setI++) { int numBlades = 0; FoliageSet fs = FoliageManager.giveSet(chunk.mSetsUsed[setI]); //walk through the main grid for our current chunk //pack the data into proper inds.. for (int x = 0; x < BTerrainQuadNode.cMaxWidth; x++) { for (int z = 0; z < BTerrainQuadNode.cMaxWidth; z++) { int index = (x + chunk.mOwnerNodeDesc.mMinXVert) + width * (z + chunk.mOwnerNodeDesc.mMinZVert); FoliageVertData fvd = FoliageManager.mVertData.GetValue(index); if (fvd.compare(FoliageManager.cEmptyVertData)) { continue; } if (FoliageManager.giveIndexOfSet(fvd.mFoliageSetName) == FoliageManager.giveIndexOfSet(chunk.mSetsUsed[setI])) { numBlades++; totalPhysicalMemory += (fs.mNumVertsPerBlade + 1) * sizeof(int); } } } } } mMemoryUsageItems.Add(new memoryElement("Terrain Foliage", totalPhysicalMemory, eMainCatagory.eCat_Terrain)); //ROADS /////XTH mMemoryUsageItems.Add(new memoryElement("Terrain Decal Rep", 256 * 256 * sizeof(short) * 2, eMainCatagory.eCat_Terrain)); //CACHES //add in our 360 cache data int cacheMemCount = 0; const int numCachePages = 20; const int cachePageSize = 512; const int numMips = 2; bool albedoCache = true; bool normalCache = true; bool specCache = false; bool selfCache = false; bool envCache = false; for (int i = 0; i < TerrainGlobals.getTexturing().getActiveTextureCount(); i++) { BTerrainActiveTextureContainer ActTex = TerrainGlobals.getTexturing().getActiveTexture(i); String fname = ActTex.mFilename; String ext = ".ddx";// Path.GetExtension(fname); string sname = fname.Substring(0, fname.LastIndexOf("_df")) + "_em" + ext; selfCache |= File.Exists(sname); sname = fname.Substring(0, fname.LastIndexOf("_df")) + "_rm" + ext; envCache |= File.Exists(sname); sname = fname.Substring(0, fname.LastIndexOf("_df")) + "_sp" + ext; specCache |= File.Exists(sname); } for (int i = 0; i < TerrainGlobals.getTexturing().getActiveDecalCount(); i++) { BTerrainActiveDecalContainer ActTex = TerrainGlobals.getTexturing().getActiveDecal(i); String fname = ActTex.mFilename; String ext = ".ddx";// Path.GetExtension(fname); string sname = fname.Substring(0, fname.LastIndexOf("_df")) + "_em" + ext; selfCache |= File.Exists(sname); sname = fname.Substring(0, fname.LastIndexOf("_df")) + "_rm" + ext; envCache |= File.Exists(sname); sname = fname.Substring(0, fname.LastIndexOf("_df")) + "_sp" + ext; specCache |= File.Exists(sname); } if (albedoCache) { cacheMemCount += giveTextureCacheMemoryRequirement(numCachePages, cachePageSize, numMips, 0); //DXT1 * numCachePages (mip0 & mip1) } if (normalCache) { cacheMemCount += giveTextureCacheMemoryRequirement(numCachePages, cachePageSize, numMips, 1); } ; //DXN if (specCache) { cacheMemCount += giveTextureCacheMemoryRequirement(numCachePages, cachePageSize, numMips, 0); //DXT1 } if (envCache) { cacheMemCount += giveTextureCacheMemoryRequirement(numCachePages, cachePageSize, numMips, 0); //DXT1 } if (selfCache) { cacheMemCount += giveTextureCacheMemoryRequirement(numCachePages, cachePageSize, numMips, 1); //DXT5 } mMemoryUsageItems.Add(new memoryElement("Terrain Texture Cache", cacheMemCount, eMainCatagory.eCat_Terrain)); //ARTIST TERRAIN TEXTURES int totalMemTT = 0; for (int i = 0; i < TerrainGlobals.getTexturing().getActiveTextureCount(); i++) { totalMemTT += TerrainGlobals.getTexturing().getActiveTexture(i).m360MemoryFootprint; } for (int i = 0; i < TerrainGlobals.getTexturing().getActiveDecalCount(); i++) { totalMemTT += TerrainGlobals.getTexturing().getActiveDecal(i).m360MemoryFootprint; } mMemoryUsageItems.Add(new memoryElement("Terrain Artist Textures", totalMemTT, eMainCatagory.eCat_Terrain)); } }
private void ImportMaskButton_Click(object sender, EventArgs e) { OpenFileDialog d = new OpenFileDialog(); d.Filter = "Image (*.bmp)|*.bmp|Raw32 (*.r32)|*.r32"; if (d.ShowDialog() == DialogResult.OK) { string tName = Path.GetFileNameWithoutExtension(d.FileName); bool okToLoad = true; for (int i = 0; i < MaskCheckList.Items.Count; i++) { MaskItem mi = MaskCheckList.Items[i] as MaskItem; if (Path.GetFileNameWithoutExtension(mi.Name) == tName) { if (MessageBox.Show("There exists a similar mask name already loaded. Would you still like to import this mask?", "Warning!", MessageBoxButtons.YesNo) != DialogResult.Yes) { okToLoad = false; } break; } } if (!okToLoad) { return; } if (Path.GetExtension(d.FileName.ToLower()) == ".bmp") { Image loadedImage = Masking.GetScaledImageFromFile(d.FileName, TerrainGlobals.getTerrain().getNumXVerts(), TerrainGlobals.getTerrain().getNumZVerts()); MaskItem item = new MaskItem(); item.Name = Path.GetFileName(d.FileName); item.mMask = Masking.CreateMask(loadedImage); MaskCheckList.Items.Add(item, false); Masking.setCurrSelectionMaskWeights(item.mMask.Clone()); } else if (Path.GetExtension(d.FileName.ToLower()) == ".r32") { MaskItem item = new MaskItem(); item.Name = Path.GetFileName(d.FileName); item.mMask = MaskFactory.GetNewMask(); BinaryReader r = new BinaryReader(File.OpenRead(d.FileName)); long index = 0; try { while (true) { item.mMask.SetMaskWeight(index, r.ReadSingle()); index++; } } catch (System.IO.EndOfStreamException ex) { ex.ToString(); } if (scaleToFitCheckbox.Checked) { //rescale this mask to fit current terrain int numX = (int)Math.Sqrt(index); float[] img = new float[numX * numX]; long id; float value; item.mMask.ResetIterator(); while (item.mMask.MoveNext(out id, out value)) { if (value == 0) { continue; } img[id] = value; } int newWidth = TerrainGlobals.getTerrain().getNumXVerts(); float[] outImg = ImageManipulation.resizeF32Img(img, numX, numX, newWidth, newWidth, ImageManipulation.eFilterType.cFilter_Linear); item.mMask.Clear(); for (index = 0; index < newWidth * newWidth; index++) { item.mMask.SetMaskWeight(index, outImg[index]); } } MaskCheckList.Items.Add(item, false); Masking.setCurrSelectionMaskWeights(item.mMask.Clone()); r.Close(); } } //ImageSourcePicker picker = new ImageSourcePicker(); //picker.ImageSelected += new EventHandler(picker_ImageSelected); //PopupEditor editor = new PopupEditor(); //editor.ShowPopup(this, picker); }
public void isActive() { isLoading = true; minXBounds.Setup(0, TerrainGlobals.getTerrain().getNumXVerts(), false); maxXBounds.Setup(0, TerrainGlobals.getTerrain().getNumXVerts(), false); minZBounds.Setup(0, TerrainGlobals.getTerrain().getNumXVerts(), false); maxZBounds.Setup(0, TerrainGlobals.getTerrain().getNumXVerts(), false); minXBounds.NumericValue = CoreGlobals.mPlayableBoundsMinX; maxXBounds.NumericValue = CoreGlobals.mPlayableBoundsMaxX; minZBounds.NumericValue = CoreGlobals.mPlayableBoundsMinZ; maxZBounds.NumericValue = CoreGlobals.mPlayableBoundsMaxZ; textBox1.Text = CoreGlobals.ScenarioMinimapTextureFilename; string[] temp = new string[CoreGlobals.ScenarioSoundbankFilenames.Count]; for (int i = 0; i < CoreGlobals.ScenarioSoundbankFilenames.Count; i++) { temp[i] = CoreGlobals.ScenarioSoundbankFilenames[i]; } soundBankBox.Lines = temp; //-- DJB: Yeah this is ugly, but we're at the end of the project, and it's not gonna change. worldComboBox.Items.Clear(); worldComboBox.Items.Add(""); worldComboBox.Items.Add("Harvest"); worldComboBox.Items.Add("Arcadia"); worldComboBox.Items.Add("SWI"); worldComboBox.Items.Add("SWE"); worldComboBox.Text = CoreGlobals.ScenarioWorld; cinematicListBox.Items.Clear(); talkingHeadVideos.Items.Clear(); int count = CoreGlobals.getGameResources().getNumCinematics(); for (int i = 0; i < count; i++) { EditorCinematic ecin = CoreGlobals.getGameResources().getCinematic(i); cinematicListBox.Items.Add(ecin.Name); } count = CoreGlobals.getGameResources().getNumTalkingHeadVideos(); for (int i = 0; i < count; i++) { EditorCinematic ecin = CoreGlobals.getGameResources().getTalkingHeadVideo(i); talkingHeadVideos.Items.Add(ecin.Name); } count = CoreGlobals.getGameResources().getNumLightsets(); LightsetListBox.Items.Clear(); for (int i = 0; i < count; i++) { EditorLightset ecin = CoreGlobals.getGameResources().getLightset(i); LightsetListBox.Items.Add(ecin.getIDString()); } comboBox1.Items.Clear(); comboBox2.Items.Clear(); int numSplatTex = TerrainGlobals.getTexturing().getActiveTextureCount(); for (int i = 0; i < numSplatTex; i++) { if (TerrainGlobals.getTexturing().getActiveTexture(i) == null) { if (mbThisErrorOnce1 == false) { mbThisErrorOnce1 = true; CoreGlobals.ShowMessage("Please report this error to Andrew and Colt: invalid index in isActive "); } continue; } comboBox1.Items.Add(Path.GetFileName(TerrainGlobals.getTexturing().getActiveTexture(i).mFilename)); comboBox2.Items.Add(Path.GetFileName(TerrainGlobals.getTexturing().getActiveTexture(i).mFilename)); } if (CoreGlobals.ScenarioBuildingTextureIndexUNSC >= comboBox1.Items.Count) { CoreGlobals.ScenarioBuildingTextureIndexUNSC = 0; } comboBox1.SelectedIndex = CoreGlobals.ScenarioBuildingTextureIndexUNSC; if (CoreGlobals.ScenarioBuildingTextureIndexCOVN >= comboBox1.Items.Count) { CoreGlobals.ScenarioBuildingTextureIndexCOVN = 0; } comboBox2.SelectedIndex = CoreGlobals.ScenarioBuildingTextureIndexCOVN; VeterancyCheck.Checked = CoreGlobals.mbAllowVeterancy; LoadVisRepBox.Checked = CoreGlobals.mbLoadTerrainVisRep; GlobalExcludeUnitsOptionChooser.Enabled = true; GlobalExcludeUnitsOptionChooser.SetOptions(TriggerSystemMain.mSimResources.mObjectTypeData.mObjectTypeList); GlobalExcludeUnitsOptionChooser.BoundSelectionList = SimGlobals.getSimMain().GlobalExcludeObjects; GlobalExcludeUnitsOptionChooser.AllowRepeats = false; GlobalExcludeUnitsOptionChooser.AutoSort = true; isLoading = false; }
public void exportRoads(ref ExportResults results) { DateTime n = DateTime.Now; //for each road, for (int roadIndex = 0; roadIndex < RoadManager.giveNumRoads(); roadIndex++) { List <RoadTriangle> triList = new List <RoadTriangle>(); Road rd = RoadManager.giveRoad(roadIndex); if (rd.getNumControlPoints() == 0) //don't export roads w/o points on the map { continue; } //Step 1, generate polygon lists//////////////////////////////////////////////////// for (int rcpIndex = 0; rcpIndex < rd.getNumControlPoints(); rcpIndex++) { roadControlPoint rcp = rd.getPoint(rcpIndex); int numTris = (int)(rcp.mVerts.Count / 3); for (int triIndex = 0; triIndex < numTris; triIndex++) { RoadTriangle rt = new RoadTriangle(); rt.mVerts[0] = new RoadVert(); rt.mVerts[0].mPos = new Vector3(rcp.mVerts[triIndex * 3 + 0].x, rcp.mVerts[triIndex * 3 + 0].y, rcp.mVerts[triIndex * 3 + 0].z); rt.mVerts[0].mUv0 = new Vector2(rcp.mVerts[triIndex * 3 + 0].u0, rcp.mVerts[triIndex * 3 + 0].v0); rt.mVerts[1] = new RoadVert(); rt.mVerts[1].mPos = new Vector3(rcp.mVerts[triIndex * 3 + 1].x, rcp.mVerts[triIndex * 3 + 1].y, rcp.mVerts[triIndex * 3 + 1].z); rt.mVerts[1].mUv0 = new Vector2(rcp.mVerts[triIndex * 3 + 1].u0, rcp.mVerts[triIndex * 3 + 1].v0); rt.mVerts[2] = new RoadVert(); rt.mVerts[2].mPos = new Vector3(rcp.mVerts[triIndex * 3 + 2].x, rcp.mVerts[triIndex * 3 + 2].y, rcp.mVerts[triIndex * 3 + 2].z); rt.mVerts[2].mUv0 = new Vector2(rcp.mVerts[triIndex * 3 + 2].u0, rcp.mVerts[triIndex * 3 + 2].v0); triList.Add(rt); } } //now add our triStrip segments (into triLists) for (int segIndex = 0; segIndex < rd.getNumRoadSegments(); segIndex++) { roadSegment rs = rd.getRoadSegment(segIndex); int numTris = rs.mNumVerts - 2; int vertIndex = rs.mStartVertInParentSegment + 2; for (int i = 0; i < numTris; i++) { RoadTriangle rt = new RoadTriangle(); rt.mVerts[0] = new RoadVert(); rt.mVerts[0].mPos = new Vector3(rd.mVerts[vertIndex - 2].x, rd.mVerts[vertIndex - 2].y, rd.mVerts[vertIndex - 2].z); rt.mVerts[0].mUv0 = new Vector2(rd.mVerts[vertIndex - 2].u0, rd.mVerts[vertIndex - 2].v0); rt.mVerts[1] = new RoadVert(); rt.mVerts[1].mPos = new Vector3(rd.mVerts[vertIndex - 1].x, rd.mVerts[vertIndex - 1].y, rd.mVerts[vertIndex - 1].z); rt.mVerts[1].mUv0 = new Vector2(rd.mVerts[vertIndex - 1].u0, rd.mVerts[vertIndex - 1].v0); rt.mVerts[2] = new RoadVert(); rt.mVerts[2].mPos = new Vector3(rd.mVerts[vertIndex].x, rd.mVerts[vertIndex].y, rd.mVerts[vertIndex].z); rt.mVerts[2].mUv0 = new Vector2(rd.mVerts[vertIndex].u0, rd.mVerts[vertIndex].v0); triList.Add(rt); vertIndex++; } } //Step 2, split Polygons//////////////////////////////////////////////////// int width = (int)(BTerrainQuadNode.cMaxWidth); int numPlanes = (int)(TerrainGlobals.getTerrain().getNumXVerts() / width); //Split along XPlane for (int planeIndex = 0; planeIndex < numPlanes; planeIndex++) { Plane pl = Plane.FromPointNormal(new Vector3(planeIndex * width * TerrainGlobals.getTerrain().getTileScale(), 0, 0), BMathLib.unitX); splitPolyListAgainstPlane(pl, triList); } //split along ZPlane for (int planeIndex = 0; planeIndex < numPlanes; planeIndex++) { Plane pl = Plane.FromPointNormal(new Vector3(0, 0, planeIndex * width * TerrainGlobals.getTerrain().getTileScale()), BMathLib.unitZ); splitPolyListAgainstPlane(pl, triList); } //Step 3, add polies to qn.///////////////////////////////////////////////// List <RoadQN> roadQNs = new List <RoadQN>(); int numQNs = (int)(TerrainGlobals.getTerrain().getNumXVerts() / width); int qnWidth = (int)(width * TerrainGlobals.getTerrain().getTileScale()); for (int qnX = 0; qnX < numQNs; qnX++) { for (int qnZ = 0; qnZ < numQNs; qnZ++) { float x = qnX * qnWidth; float z = qnZ * qnWidth; RoadQN rqn = new RoadQN(); for (int triIndex = 0; triIndex < triList.Count; triIndex++) { if (triContainedInBox(triList[triIndex], x, z, x + qnWidth, z + qnWidth)) { triList[triIndex].ensureWinding(); rqn.mTris.Add(triList[triIndex]); rqn.mOwnerQNIndex = qnX * numQNs + qnZ; } } if (rqn.mTris.Count != 0) { roadQNs.Add(rqn); } } } //Step 4, write road chunk to disk.///////////////////////////////////////////// ECF.ECFChunkHolder chunkHolder = new ECF.ECFChunkHolder(); chunkHolder.mDataMemStream = new MemoryStream(); BinaryWriter binWriter = new BinaryWriter(chunkHolder.mDataMemStream); //Filename string fName = CoreGlobals.getWorkPaths().mRoadsPath + "\\" + rd.getRoadTextureName(); fName = fName.Remove(0, CoreGlobals.getWorkPaths().mGameArtDirectory.Length + 1); char[] filename = new char[32]; fName.CopyTo(0, filename, 0, fName.Length); binWriter.Write(filename); ExportTo360.addTextureChannelDependencies(CoreGlobals.getWorkPaths().mRoadsPath + "\\" + rd.getRoadTextureName()); float zero = 0; int totalMemory = 0; //write our chunks binWriter.Write(Xbox_EndianSwap.endSwapI32(roadQNs.Count)); for (int qnI = 0; qnI < roadQNs.Count; qnI++) { binWriter.Write(Xbox_EndianSwap.endSwapI32(roadQNs[qnI].mOwnerQNIndex)); binWriter.Write(Xbox_EndianSwap.endSwapI32(roadQNs[qnI].mTris.Count)); int memSize = roadQNs[qnI].mTris.Count * (3 * (sizeof(short) * 6)); binWriter.Write(Xbox_EndianSwap.endSwapI32(memSize)); List <float> vList = new List <float>(); for (int c = 0; c < roadQNs[qnI].mTris.Count; c++) { for (int i = 0; i < 3; i++) { vList.Add(roadQNs[qnI].mTris[c].mVerts[i].mPos.X); vList.Add(roadQNs[qnI].mTris[c].mVerts[i].mPos.Y); vList.Add(roadQNs[qnI].mTris[c].mVerts[i].mPos.Z); vList.Add(zero); //padd; vList.Add(roadQNs[qnI].mTris[c].mVerts[i].mUv0.X); vList.Add(roadQNs[qnI].mTris[c].mVerts[i].mUv0.Y); } } float16[] sList = BMathLib.Float32To16Array(vList.ToArray()); for (int c = 0; c < vList.Count; c++) { ushort s = ((ushort)sList[c].getInternalDat()); binWriter.Write(Xbox_EndianSwap.endSwapI16(s)); } totalMemory += memSize; } ExportTo360.mECF.addChunk((int)eXTT_ChunkID.cXTT_RoadsChunk, chunkHolder, binWriter.BaseStream.Length); binWriter.Close(); binWriter = null; chunkHolder.Close(); chunkHolder = null; roadQNs.Clear(); triList.Clear(); TimeSpan ts = DateTime.Now - n; results.terrainRoadTime = ts.TotalMinutes; results.terrainRoadMemory = totalMemory; } }
void heightFieldAlphaToChunk(ref ExportResults results) { //i think for visual reasons, the resolution of this alpha data needs to match //the density of the terrain alpha.. BTerrainSimRep simRep = TerrainGlobals.getEditor().getSimRep(); int width = TerrainGlobals.getTerrain().getNumXVerts(); int height = TerrainGlobals.getTerrain().getNumXVerts(); if (width < 256 || height < 256) { return; //don't write for small maps.. } byte[] AlphaVals = TerrainGlobals.getEditor().getAlphaValues(); DXT3_1111 img = new DXT3_1111(width, height); //walk through all the terrain alpha values, for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { int index = x * width + y; bool visible = AlphaVals[index] > 0;// if it's invisible, so are we. //walk through the sim rep. If it's passable, we're visible. float normalizedX = x / (float)width; float normalizedZ = y / (float)height; bool obstructsLand = simRep.getDataTiles().isLandObstructedComposite(normalizedX, normalizedZ); visible |= !obstructsLand; img.setValue(x, y, visible); } } ECF.ECFChunkHolder chunkHolder = new ECF.ECFChunkHolder(); chunkHolder.mDataMemStream = new MemoryStream(); BinaryWriter binWriter = new BinaryWriter(chunkHolder.mDataMemStream); int packedWidth = width >> 2; binWriter.Write(Xbox_EndianSwap.endSwapI32(packedWidth)); binWriter.Write(Xbox_EndianSwap.endSwapI32(height)); int numBlocks = img.getNumBlocks(); //numXBlocks-1 + numXBlocks * numYBlocks int texelMemSize = numBlocks * sizeof(Int64);// (((width >> 4) - 1) + (width >> 4) * ((height >> 2) - 1)) * sizeof(Int64); binWriter.Write(Xbox_EndianSwap.endSwapI32(texelMemSize)); for (int i = 0; i < numBlocks; i++) { binWriter.Write(img.getBlock(i)); } ExportTo360.mECF.addChunk((int)eXTH_ChunkID.cXTH_TerrainHeightfieldAlpha, chunkHolder, binWriter.BaseStream.Length); binWriter.Close(); binWriter = null; chunkHolder.Close(); chunkHolder = null; results.terrainGPUHeighfieldMemory += texelMemSize; img = null; }
void previewFractalToImage() { Bitmap output = new Bitmap(TerrainGlobals.getTerrain().getNumXVerts(), TerrainGlobals.getTerrain().getNumZVerts(), PixelFormat.Format32bppArgb); if (comboBox1.SelectedIndex == -1) { comboBox1.SelectedIndex = 1; } if (tabControl1.SelectedIndex == 0) { MountainRidgeTerrainFilter mrt = new MountainRidgeTerrainFilter(); //mrt.AddReplaceSubtract = (eFilterOperation)(Enum.Parse(typeof(eFilterOperation), comboBox1.SelectedIndex)); mrt.AddReplaceSubtract = (eFilterOperation)(comboBox1.SelectedIndex); mrt.MacroSeed = trackBar1.Value; mrt.MicroSeed = trackBar2.Value; mrt.ScaleHeight = (float)numericUpDown1.Value; mrt.Frequency = trackBar3.Value * 0.001f; mrt.Detail = trackBar4.Value; mrt.Lacunarity = trackBar5.Value * 0.01f; mrt.mMaskCreationType = mMaskGenType; mrt.previewToBitmap(ref output); mrt = null; } else if (tabControl1.SelectedIndex == 1) { BillowTerrainFilter mrt = new BillowTerrainFilter(); mrt.mAddReplaceSubtract = comboBox1.SelectedIndex; mrt.mMacroSeed = trackBar9.Value; mrt.mMicroSeed = trackBar10.Value; mrt.mScaleHeight = (float)numericUpDown1.Value; mrt.mFrequency = trackBar8.Value * 0.001f; mrt.mDetail = trackBar7.Value; mrt.mLacunarity = trackBar6.Value * 0.01f; mrt.mMaskCreationType = mMaskGenType; mrt.previewToBitmap(ref output); mrt = null; } else if (tabControl1.SelectedIndex == 2) { VoronoiTerrainFilter mrt = new VoronoiTerrainFilter(); mrt.mAddReplaceSubtract = comboBox1.SelectedIndex; mrt.mMacroSeed = trackBar24.Value; mrt.mMicroSeed = trackBar23.Value; mrt.mScaleHeight = (float)numericUpDown1.Value; mrt.mFrequency = trackBar22.Value * 0.01f; mrt.mDisplacement = trackBar21.Value * 0.01f; mrt.mMaskCreationType = mMaskGenType; mrt.previewToBitmap(ref output); mrt = null; } else if (tabControl1.SelectedIndex == 3) { fBMTerrainFilter mrt = new fBMTerrainFilter(); mrt.mAddReplaceSubtract = comboBox1.SelectedIndex; mrt.mMacroSeed = trackBar28.Value; mrt.mMicroSeed = trackBar29.Value; mrt.mScaleHeight = (float)numericUpDown1.Value; mrt.mFrequency = trackBar27.Value * 0.001f; mrt.mDetail = trackBar26.Value; mrt.mLacunarity = trackBar25.Value * 0.01f; mrt.mMaskCreationType = mMaskGenType; mrt.previewToBitmap(ref output); mrt = null; } Bitmap rescale = new Bitmap(output, pictureBox1.Width, pictureBox1.Height); pictureBox1.Image = rescale; pictureBox1.Invalidate(); }