static public void scaleSelection(float amt, bool addOrPercent) { int totalNumVerts = TerrainGlobals.getTerrain().getNumXVerts(); float fact = 0; for (int x = 0; x < totalNumVerts; x++) { for (int z = 0; z < totalNumVerts; z++) { if (Masking.isPointSelected(x, z, ref fact)) { if (addOrPercent) { fact = BMathLib.Clamp(fact + amt, 0, 1); } else { fact = BMathLib.Clamp(fact * amt, 0, 1); } Masking.addSelectedVert(x, z, fact); } } } rebuildVisualsAfterSelection(); }
static public void addSelectedVert(int x, int z, float selAmt) { int i = x * TerrainGlobals.getTerrain().getNumXVerts() + z; float factor = 1.0f; if (checkBaseWritePermission(x, z, out factor)) { selAmt = Masking.combineValueWithBaseMask(factor, selAmt); extendCurrSelectionMask(x, z); mCurrSelectionMask.SetMaskWeight((int)i, selAmt); } }
static public void addSelectedVert(long id, float selAmt) { float factor = 1.0f; if (checkBaseWritePermission(id, out factor)) { selAmt = Masking.combineValueWithBaseMask(factor, selAmt); int stride = TerrainGlobals.getTerrain().getNumZVerts(); int x = (int)(id / stride); int z = (int)(id - x * stride); extendCurrSelectionMask(x, z); mCurrSelectionMask.SetMaskWeight(id, selAmt); } }
static public void contractSelection(int numVerts) { Masking.invertSelectionMask(); ConvMatrix filter = new ConvMatrix(1, 1, 1, 1, 0, 1, 1, 1, 1); filter.mFactor = 1; filter.mOffset = 0; for (int i = 0; i < numVerts; i++) { applyConvMatrix(filter); } Masking.invertSelectionMask(); }
public void Load() { OpenFileDialog d = new OpenFileDialog(); d.Filter = "Image (*.bmp)|*.bmp"; if (d.ShowDialog() == DialogResult.OK) { Image loadedImage = Masking.GetScaledImageFromFile(d.FileName, TerrainGlobals.getTerrain().getNumXVerts(), TerrainGlobals.getTerrain().getNumZVerts()); IMask mask = Masking.CreateMask(loadedImage); //MasklImage newImage = new MasklImage(); this.SetMask(mask, TerrainGlobals.getTerrain().getNumXVerts(), TerrainGlobals.getTerrain().getNumZVerts()); //TerrainGlobals.getEditor().mCurrentAbstractImage = newImage; } }
//---------------------------------------------- unsafe static public bool setMaskAlphaToTextureBlending(BTerrainQuadNode node, uint dstImgWidth, uint dstImgHeight, UInt32 *mskImg, uint mskImgWidth, uint mskImgHeight, float intensity, int xpos, int ypos, bool alternate) { BTerrainQuadNodeDesc desc = node.getDesc(); bool changed = false; //create our position in the dst img, adjust for boundries int mskMaxX = (int)mskImgWidth; if (mskImgWidth + xpos >= dstImgWidth) { mskMaxX -= ((int)mskImgWidth) + xpos - ((int)dstImgWidth); } int mskMaxY = (int)mskImgHeight; if (mskImgHeight + ypos >= dstImgHeight) { mskMaxY -= ((int)mskImgHeight) + ypos - ((int)dstImgHeight); } int mskMinX = 0; int mskMinY = 0; if (xpos < 0) { mskMinX = -xpos; } if (ypos < 0) { mskMinY = -ypos; } //validate extents... if (mskMinX > mskImgWidth || mskMinY > mskImgHeight) { return(false); } int minX = (int)(desc.m_min.X / TerrainGlobals.getTerrain().getTileScale()); int maxX = (int)(desc.m_max.X / TerrainGlobals.getTerrain().getTileScale()); int minZ = (int)(desc.m_min.Z / TerrainGlobals.getTerrain().getTileScale()); int maxZ = (int)(desc.m_max.Z / TerrainGlobals.getTerrain().getTileScale()); for (int x = minX; x <= maxX; x++) { for (int z = minZ; z <= maxZ; z++) { int maskX = x - minX + mskMinX; int maskY = z - minZ + mskMinY; int mIP = maskX * ((int)mskImgWidth) + maskY; char alpha = (char)(((mskImg[mIP] & 0xFF000000) >> 24)); float factor = alpha / 255.0f * intensity;; int vertIndex = (int)(x * TerrainGlobals.getTerrain().getNumZVerts() + z); float curWeight = Masking.getCurrSelectionMaskWeights().GetMaskWeight(vertIndex); float newWeight; if (!alternate) { newWeight = (curWeight > factor) ? curWeight : factor; } else//CLM Changes to erasing.. { newWeight = BMathLib.Clamp(curWeight - factor, 0, 1); } Masking.addSelectedVert(x, z, newWeight); changed = true; } } return(changed); }
//---------------------------------------------- unsafe static public bool setIndexToMaskedArea(BTerrainQuadNode node, int minxvert, int minzvert, int maxxvert, int maxzvert, char index) { bool changed = false; uint dstImgWidth = BTerrainTexturing.getAlphaTextureWidth(); uint dstImgHeight = BTerrainTexturing.getAlphaTextureWidth(); float vertsToPixelsRatio = BTerrainTexturing.getAlphaTextureWidth() / (float)BTerrainQuadNode.getMaxNodeWidth(); BTerrainLayerContainer layers = node.mLayerContainer; int layerIndex = layers.giveLayerIndex(index, BTerrainTexturingLayer.eLayerType.cLayer_Splat); if (TerrainGlobals.getEditor().mEraseTextureInstead&& layerIndex == 0) { return(false); } //layers.removeRedundantLayers();//CLM is this still needed?!??! if (layerIndex == -1) { if (TerrainGlobals.getEditor().mEraseTextureInstead) //we're erasing, and the texture doesn't exist.. { return(false); } //i don't exist yet. newSplatLayerEverywhere(index); layerIndex = layers.giveLayerIndex(index, BTerrainTexturingLayer.eLayerType.cLayer_Splat); BTerrainTexturingLayer tLayer = layers.giveLayer(layerIndex); for (int x = 0; x < BTerrainTexturing.getAlphaTextureWidth(); x++) { for (int z = 0; z < BTerrainTexturing.getAlphaTextureWidth(); z++) { //find the closest vert int cX = (int)((x * vertsToPixelsRatio) + minxvert); int cZ = (int)((z * vertsToPixelsRatio) + minzvert); int vertIndex = (int)(cX * TerrainGlobals.getTerrain().getNumZVerts() + cZ); float curWeight = 1.0f; if (Masking.isPointSelected(vertIndex, ref curWeight)) { curWeight = BMathLib.Clamp(curWeight, 0, 1); int dIP = x + ((int)BTerrainTexturing.getAlphaTextureHeight()) * z; byte val = (byte)(curWeight * byte.MaxValue); tLayer.mAlphaLayer[dIP] = val; } } } changed = true; } else { BTerrainTexturingLayer tLayer = layers.giveLayer(layerIndex); //this layer already exists. //If a pixel exists above me, subtract me from it, rather than adding to me. for (int x = 0; x < BTerrainTexturing.getAlphaTextureWidth(); x++) { for (int z = 0; z < BTerrainTexturing.getAlphaTextureWidth(); z++) { //find the closest vert int cX = (int)((x * vertsToPixelsRatio) + minxvert); int cZ = (int)((z * vertsToPixelsRatio) + minzvert); int vertIndex = (int)(cX * TerrainGlobals.getTerrain().getNumZVerts() + cZ); float curWeight = 1.0f; if (Masking.isPointSelected(vertIndex, ref curWeight)) { changed = true; int dIP = x + ((int)BTerrainTexturing.getAlphaTextureHeight()) * z; curWeight = BMathLib.Clamp(curWeight, 0, 1); byte val = (byte)(curWeight * byte.MaxValue); valToLayerColumn(layers, tLayer, dIP, val, layerIndex); } } } } layers.removeBlankLayers(); return(changed); }
public void applySimRepBrush(bool alternate) { if (TerrainGlobals.getEditor().getStrokeInputType() == BTerrainEditor.eEditorStrokeInput.cStrokeInputMouse) { //raycast and get our intersection Vector3 orig = TerrainGlobals.getEditor().getRayPosFromMouseCoords(false); Vector3 dir = TerrainGlobals.getEditor().getRayPosFromMouseCoords(true) - orig; dir = BMathLib.Normalize(dir); //get our intersect point if (!getClosestIntersectionPoint(new float3(orig), new float3(dir), out mLastMoustIntPt)) { return; } //If we're in tile mode, shift our center over to better match what our cursor is doing... if (TerrainGlobals.getEditor().getMode() == BTerrainEditor.eEditorMode.cModeSimBuildibility || TerrainGlobals.getEditor().getMode() == BTerrainEditor.eEditorMode.cModeSimPassibility || TerrainGlobals.getEditor().getMode() == BTerrainEditor.eEditorMode.cModeSimFloodPassibility || TerrainGlobals.getEditor().getMode() == BTerrainEditor.eEditorMode.cModeSimScarabPassibility) { mLastMoustIntPt.X += mTileScale; mLastMoustIntPt.Z += mTileScale; } // Undo info // addVertexUndoNodes(nodes, false); // Find affected points List <int> points = new List <int>(); getPointsIntersectingSphere(points, mLastMoustIntPt, TerrainGlobals.getEditor().mBrushInfo.mRadius); Vector3 intPoint = mLastMoustIntPt.toVec3(); Vector3 intNormal = BMathLib.unitY; BrushInfo bi = TerrainGlobals.getEditor().getCurrentBrushInfo(); ((BTerrainSimBrush)TerrainGlobals.getEditor().getCurrentBrush()).applyOnBrush(points, ref intPoint, ref intNormal, ref bi, alternate); // addVertexUndoNodes(nodes, true); } else if (TerrainGlobals.getEditor().getStrokeInputType() == BTerrainEditor.eEditorStrokeInput.cStrokeInputKeyboard) { BrushInfo bi = TerrainGlobals.getEditor().getCurrentBrushInfo(); ((BTerrainSimBrush)TerrainGlobals.getEditor().getCurrentBrush()).applyOnSelection(Masking.getCurrSelectionMaskWeights(), bi.mIntensity, alternate); } }