public override void OnSceneGUI(Terrain terrain, IOnSceneGUI editContext) { commonUI.OnSceneGUI2D(terrain, editContext); // only do the rest if user mouse hits valid terrain or they are using the // brush parameter hotkeys to resize, etc if (!editContext.hitValidTerrain && !commonUI.isInUse) { return; } // update brush UI group commonUI.OnSceneGUI(terrain, editContext); ProcessInput(terrain, editContext); if (!commonUI.isInUse) { UpdateBrushLocations(terrain, editContext); } // dont render preview if this isnt a repaint. losing performance if we do if (Event.current.type != EventType.Repaint) { return; } DrawBrushPreviews(terrain, editContext); }
public override void OnSceneGUI(Terrain terrain, IOnSceneGUI editContext) { commonUI.OnSceneGUI2D(terrain, editContext); // only do the rest if user mouse hits valid terrain or they are using the // brush parameter hotkeys to resize, etc if (!editContext.hitValidTerrain && !commonUI.isInUse) { return; } // update brush UI group commonUI.OnSceneGUI(terrain, editContext); // dont render preview if this isnt a repaint. losing performance if we do if (Event.current.type != EventType.Repaint) { return; } using (IBrushRenderPreviewUnderCursor brushRender = new BrushRenderPreviewUIGroupUnderCursor(commonUI, "SmudgeHeight", editContext.brushTexture)) { if (brushRender.CalculateBrushTransform(out BrushTransform brushXform)) { PaintContext ctx = brushRender.AcquireHeightmap(false, brushXform.GetBrushXYBounds(), 1); brushRender.RenderBrushPreview(ctx, TerrainPaintUtilityEditor.BrushPreview.SourceRenderTexture, brushXform, TerrainPaintUtilityEditor.GetDefaultBrushPreviewMaterial(), 0); } } }
public override void OnSceneGUI(Terrain terrain, IOnSceneGUI editContext) { commonUI.OnSceneGUI2D(terrain, editContext); // only do the rest if user mouse hits valid terrain or they are using the // brush parameter hotkeys to resize, etc if (!editContext.hitValidTerrain && !commonUI.isInUse) { return; } // update brush UI group commonUI.OnSceneGUI(terrain, editContext); // dont render preview if this isnt a repaint. losing performance if we do if (Event.current.type != EventType.Repaint) { return; } using (IBrushRenderPreviewUnderCursor brushRender = new BrushRenderPreviewUIGroupUnderCursor(commonUI, "WindErosion", editContext.brushTexture)) { if (brushRender.CalculateBrushTransform(out BrushTransform brushXform)) { PaintContext ctx = brushRender.AcquireHeightmap(false, brushXform.GetBrushXYBounds(), 1); brushRender.RenderBrushPreview(ctx, TerrainPaintUtilityEditor.BrushPreview.SourceRenderTexture, brushXform, TerrainPaintUtilityEditor.GetDefaultBrushPreviewMaterial(), 0); Quaternion windRot = Quaternion.AngleAxis(commonUI.brushRotation, new Vector3(0.0f, 1.0f, 0.0f)); Handles.ArrowHandleCap(0, commonUI.raycastHitUnderCursor.point, windRot, 0.5f * commonUI.brushSize, EventType.Repaint); } } }
public override void OnSceneGUI(Terrain terrain, IOnSceneGUI editContext) { commonUI.OnSceneGUI2D(terrain, editContext); if (!editContext.hitValidTerrain && !commonUI.isInUse) { return; } commonUI.OnSceneGUI(terrain, editContext); Event evt = Event.current; if (evt.control && (evt.type == EventType.ScrollWheel)) { const float k_mouseWheelToHeightRatio = -0.0004f; stampToolProperties.m_StampHeight += Event.current.delta.y * k_mouseWheelToHeightRatio * editContext.raycastHit.distance; evt.Use(); editContext.Repaint(); SaveSetting(); } // We're only doing painting operations, early out if it's not a repaint if (evt.type != EventType.Repaint) { return; } if (commonUI.isRaycastHitUnderCursorValid) { Texture brushTexture = editContext.brushTexture; using (IBrushRenderPreviewUnderCursor brushRender = new BrushRenderPreviewUIGroupUnderCursor(commonUI, "Stamp", brushTexture)) { if (brushRender.CalculateBrushTransform(out BrushTransform brushXform)) { PaintContext paintContext = brushRender.AcquireHeightmap(false, brushXform.GetBrushXYBounds(), 1); Material material = TerrainPaintUtilityEditor.GetDefaultBrushPreviewMaterial(); brushRender.RenderBrushPreview(paintContext, TerrainPaintUtilityEditor.BrushPreview.SourceRenderTexture, brushXform, material, 0); // draw result preview { ApplyBrushInternal(brushRender, paintContext, commonUI.brushStrength, brushTexture, brushXform, terrain); // restore old render target RenderTexture.active = paintContext.oldRenderTexture; material.SetTexture("_HeightmapOrig", paintContext.sourceRenderTexture); brushRender.RenderBrushPreview(paintContext, TerrainPaintUtilityEditor.BrushPreview.DestinationRenderTexture, brushXform, material, 1); } TerrainPaintUtility.ReleaseContextResources(paintContext); } } } }
public override void OnSceneGUI(Terrain terrain, IOnSceneGUI editContext) { commonUI.OnSceneGUI2D(terrain, editContext); // only do the rest if user mouse hits valid terrain or they are using the // brush parameter hotkeys to resize, etc if (!editContext.hitValidTerrain && !commonUI.isInUse) { return; } // update brush UI group commonUI.OnSceneGUI(terrain, editContext); // dont render preview if this isnt a repaint. losing performance if we do if (Event.current.type != EventType.Repaint) { return; } if (commonUI.isRaycastHitUnderCursorValid) { Texture brushTexture = editContext.brushTexture; using (IBrushRenderPreviewUnderCursor brushRender = new BrushRenderPreviewUIGroupUnderCursor(commonUI, "Twist", editContext.brushTexture)) { //draw brush circle if (brushRender.CalculateBrushTransform(out BrushTransform brushXform)) { Material material = TerrainPaintUtilityEditor.GetDefaultBrushPreviewMaterial(); PaintContext ctx = brushRender.AcquireHeightmap(false, brushXform.GetBrushXYBounds(), 1); brushRender.RenderBrushPreview(ctx, TerrainPaintUtilityEditor.BrushPreview.SourceRenderTexture, brushXform, TerrainPaintUtilityEditor.GetDefaultBrushPreviewMaterial(), 0); // draw result preview { float finalTwistAmount = m_TwistAmount * -0.002f; //scale to a reasonable value and negate so default mode is clockwise if (Event.current.shift) { finalTwistAmount *= -1.0f; } ApplyBrushInternal(brushRender, ctx, commonUI.brushStrength, finalTwistAmount, brushTexture, brushXform); // restore old render target RenderTexture.active = ctx.oldRenderTexture; material.SetTexture("_HeightmapOrig", ctx.sourceRenderTexture); brushRender.RenderBrushPreview(ctx, TerrainPaintUtilityEditor.BrushPreview.DestinationRenderTexture, brushXform, material, 1); } } } } }
public override void OnSceneGUI(Terrain terrain, IOnSceneGUI editContext) { commonUI.OnSceneGUI2D(terrain, editContext); // only do the rest if user mouse hits valid terrain or they are using the // brush parameter hotkeys to resize, etc if (!editContext.hitValidTerrain && !commonUI.isInUse) { return; } // update brush UI group commonUI.OnSceneGUI(terrain, editContext); // dont render preview if this isnt a repaint. losing performance if we do if (Event.current.type != EventType.Repaint) { return; } Texture brushTexture = editContext.brushTexture; using (IBrushRenderPreviewUnderCursor brushRender = new BrushRenderPreviewUIGroupUnderCursor(commonUI, "SetHeightTool", brushTexture)) { if (brushRender.CalculateBrushTransform(out BrushTransform brushTransform)) { Rect brushBounds = brushTransform.GetBrushXYBounds(); PaintContext paintContext = brushRender.AcquireHeightmap(false, brushBounds, 1); Material material = TerrainPaintUtilityEditor.GetDefaultBrushPreviewMaterial(); brushRender.RenderBrushPreview(paintContext, TerrainPaintUtilityEditor.BrushPreview.SourceRenderTexture, brushTransform, material, 0); // draw result preview { ApplyBrushInternal(paintContext, brushRender, commonUI.brushStrength, brushTexture, brushTransform, terrain); // restore old render target RenderTexture.active = paintContext.oldRenderTexture; material.SetTexture("_HeightmapOrig", paintContext.sourceRenderTexture); brushRender.RenderBrushPreview(paintContext, TerrainPaintUtilityEditor.BrushPreview.DestinationRenderTexture, brushTransform, material, 1); } } } }
public override void OnSceneGUI(Terrain terrain, IOnSceneGUI editContext) { commonUI.OnSceneGUI2D(terrain, editContext); if (editContext.hitValidTerrain || commonUI.isInUse) { commonUI.OnSceneGUI(terrain, editContext); if (Event.current.type != EventType.Repaint) { return; } float endWidth = Mathf.Abs(bridgeToolProperties.widthProfile.Evaluate(1.0f)); BrushTransform brushXform = TerrainPaintUtility.CalculateBrushTransform(terrain, commonUI.raycastHitUnderCursor.textureCoord, commonUI.brushSize * endWidth, commonUI.brushRotation); PaintContext ctx = TerrainPaintUtility.BeginPaintHeightmap(terrain, brushXform.GetBrushXYBounds(), 1); TerrainPaintUtilityEditor.DrawBrushPreview(ctx, TerrainPaintUtilityEditor.BrushPreview.SourceRenderTexture, editContext.brushTexture, brushXform, TerrainPaintUtilityEditor.GetDefaultBrushPreviewMaterial(), 0); TerrainPaintUtility.ReleaseContextResources(ctx); } if (Event.current.type != EventType.Repaint) { return; } //display a brush preview at the bridge starting location, using starting size from width profile if (m_StartTerrain != null) { float startWidth = Mathf.Abs(bridgeToolProperties.widthProfile.Evaluate(0.0f)); BrushTransform brushTransform = TerrainPaintUtility.CalculateBrushTransform(m_StartTerrain, m_StartPoint, commonUI.brushSize * startWidth, commonUI.brushRotation); PaintContext sampleContext = TerrainPaintUtility.BeginPaintHeightmap(m_StartTerrain, brushTransform.GetBrushXYBounds()); TerrainPaintUtilityEditor.DrawBrushPreview(sampleContext, TerrainPaintUtilityEditor.BrushPreview.SourceRenderTexture, editContext.brushTexture, brushTransform, TerrainPaintUtilityEditor.GetDefaultBrushPreviewMaterial(), 0); TerrainPaintUtility.ReleaseContextResources(sampleContext); } }
public override void OnSceneGUI(Terrain terrain, IOnSceneGUI editContext) { Init(); // m_rtCollection.DebugGUI( editContext.sceneView ); brushUI.OnSceneGUI2D(terrain, editContext); // only do the rest if user mouse hits valid terrain or they are using the // brush parameter hotkeys to resize, etc if (!editContext.hitValidTerrain && !brushUI.isInUse && !m_editTransform && !debugOrtho) { return; } // update brush UI group brushUI.OnSceneGUI(terrain, editContext); bool justPressedEditKey = m_editTransform && !m_prevEditTransform; bool justReleaseEditKey = m_prevEditTransform && !m_editTransform; m_prevEditTransform = m_editTransform; if (justPressedEditKey) { (brushUI as MeshBrushUIGroup).LockTerrainUnderCursor(true); m_baseHandlePos = brushUI.raycastHitUnderCursor.point; m_handleHeightOffsetWS = 0; } else if (justReleaseEditKey) { (brushUI as MeshBrushUIGroup).UnlockTerrainUnderCursor(); m_handleHeightOffsetWS = 0; } // don't render mesh previews, etc. if the mesh field has not been populated yet if (activeMesh == null) { return; } // dont render preview if this isnt a repaint. losing performance if we do if (Event.current.type == EventType.Repaint) { Terrain currTerrain = brushUI.terrainUnderCursor; Vector2 uv = brushUI.raycastHitUnderCursor.textureCoord; float brushSize = brushUI.brushSize; float brushRotation = brushUI.brushRotation; if (/* debugOrtho || */ brushUI.isRaycastHitUnderCursorValid) { // if(debugOrtho) // { // uv = Vector2.one * .5f; // } BrushTransform brushTransform = TerrainPaintUtility.CalculateBrushTransform(currTerrain, uv, brushSize, brushRotation); PaintContext ctx = TerrainPaintUtility.BeginPaintHeightmap(brushUI.terrainUnderCursor, brushTransform.GetBrushXYBounds(), 1); Material material = TerrainPaintUtilityEditor.GetDefaultBrushPreviewMaterial(); // don't draw the brush mask preview // but draw the resulting mesh stamp preview { ApplyBrushInternal(terrain, ctx, brushTransform); TerrainPaintUtilityEditor.DrawBrushPreview(ctx, TerrainPaintUtilityEditor.BrushPreview.SourceRenderTexture, m_rtCollection[RenderTextureIDs.meshStamp], brushTransform, material, 0); RenderTexture.active = ctx.oldRenderTexture; material.SetTexture("_HeightmapOrig", ctx.sourceRenderTexture); TerrainPaintUtility.SetupTerrainToolMaterialProperties(ctx, brushTransform, material); TerrainPaintUtilityEditor.DrawBrushPreview(ctx, TerrainPaintUtilityEditor.BrushPreview.DestinationRenderTexture, m_rtCollection[RenderTextureIDs.meshStamp], brushTransform, material, 1); TerrainPaintUtility.ReleaseContextResources(ctx); } } } if (m_editTransform) { EditorGUI.BeginChangeCheck(); { Vector3 prevHandlePosWS = m_baseHandlePos + Vector3.up * m_handleHeightOffsetWS; // draw transform handles float handleSize = HandleUtility.GetHandleSize(prevHandlePosWS); toolSettings.scale = Handles.ScaleHandle(toolSettings.scale, prevHandlePosWS, toolSettings.rotation, handleSize * 1.5f); Quaternion brushRotation = Quaternion.AngleAxis(brushUI.brushRotation, Vector3.up); toolSettings.rotation = Handles.RotationHandle(toolSettings.rotation, prevHandlePosWS); Vector3 currHandlePosWS = Handles.Slider(prevHandlePosWS, Vector3.up, handleSize, Handles.ArrowHandleCap, 1f); float deltaHeight = (currHandlePosWS.y - prevHandlePosWS.y); m_handleHeightOffsetWS += deltaHeight; toolSettings.stampHeight += deltaHeight; } if (EditorGUI.EndChangeCheck()) { editContext.Repaint(); SaveSettings(); } } }