//---------------------------------------------- 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); }
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); } }