protected override void Start() { m_input = GetComponent <BaseHandleInput>(); if (m_input == null || m_input.Handle != this) { m_input = gameObject.AddComponent <BaseHandleInput>(); m_input.Handle = this; } IRTEGraphicsLayer graphicsLayer = Window.IOCContainer.Resolve <IRTEGraphicsLayer>(); if (graphicsLayer != null) { m_rteCamera = graphicsLayer.Camera; } if (m_rteCamera == null && Window.Camera != null) { IRTEGraphics graphics = IOC.Resolve <IRTEGraphics>(); if (graphics != null) { m_rteCamera = graphics.GetOrCreateCamera(Window.Camera, CameraEvent.AfterImageEffectsOpaque); } if (m_rteCamera == null) { m_rteCamera = Window.Camera.gameObject.AddComponent <RTECamera>(); m_rteCamera.Event = CameraEvent.AfterImageEffectsOpaque; } } if (Model == null && m_rteCamera != null) { m_prevScale = transform.localScale; m_prevCamPosition = m_rteCamera.Camera.transform.position; m_prevCamRotation = m_rteCamera.Camera.transform.rotation; m_prevCamOrthographic = m_rteCamera.Camera.orthographic; m_prevCamOrthographicsSize = m_rteCamera.Camera.orthographicSize; m_prevCamRect = m_rteCamera.Camera.rect; m_rteCamera.CommandBufferRefresh += OnCommandBufferRefresh; m_rteCamera.RefreshCommandBuffer(); } #pragma warning disable CS0618 OnStartOverride(); #pragma warning restore CS0618 }
protected override void OnActiveWindowChanged(RuntimeWindow deactivatedWindow) { base.OnActiveWindowChanged(deactivatedWindow); if (m_rteCamera != null) { m_rteCamera.CommandBufferRefresh -= OnCommandBufferRefresh; m_rteCamera.Destroy(); m_rteCamera = null; } if (Editor.ActiveWindow == null || Editor.ActiveWindow.WindowType != RuntimeWindowType.Scene) { Window = null; } else { Window = Editor.ActiveWindow; m_rteCamera = Window.Camera.gameObject.AddComponent <RTECamera>(); m_rteCamera.Event = CameraEvent.AfterImageEffects; m_rteCamera.CommandBufferRefresh += OnCommandBufferRefresh; m_rteCamera.RefreshCommandBuffer(); } }
private void Init() { Camera camera = Window.Camera; IRTEGraphicsLayer graphicsLayer = Window.IOCContainer.Resolve <IRTEGraphicsLayer>(); if (graphicsLayer != null && graphicsLayer.Camera != null) { camera = graphicsLayer.Camera.Camera; } if (camera == null) { return; } IRTEGraphics graphics = IOC.Resolve <IRTEGraphics>(); m_rteCamera = graphics.CreateCamera(camera, CameraEvent.AfterImageEffects, false, true); m_rteCamera.RenderersCache.Add(m_output.GetComponent <Renderer>()); m_rteCamera.RefreshCommandBuffer(); DoSceneGizmo(); if (BtnProjection != null) { BtnProjection.gameObject.SetActive(true); } }
private void Start() { m_input = GetComponent <BaseHandleInput>(); if (m_input == null || m_input.Handle != this) { m_input = gameObject.AddComponent <BaseHandleInput>(); m_input.Handle = this; } IRTEGraphicsLayer graphicsLayer = Window.IOCContainer.Resolve <IRTEGraphicsLayer>(); if (graphicsLayer != null) { m_rteCamera = graphicsLayer.Camera; } if (m_rteCamera == null && Window.Camera != null) { m_rteCamera = Window.Camera.GetComponent <IRTECamera>(); if (m_rteCamera == null) { m_rteCamera = Window.Camera.gameObject.AddComponent <RTECamera>(); m_rteCamera.Event = UnityEngine.Rendering.CameraEvent.AfterImageEffectsOpaque; } } if (Model == null && m_rteCamera != null) { m_prevScale = transform.localScale; m_prevCamPosition = m_rteCamera.Camera.transform.position; m_prevCamRotation = m_rteCamera.Camera.transform.rotation; m_prevCamOrthographic = m_rteCamera.Camera.orthographic; m_prevCamOrthographicsSize = m_rteCamera.Camera.orthographicSize; m_prevCamRect = m_rteCamera.Camera.rect; m_rteCamera.CommandBufferRefresh += OnCommandBufferRefresh; m_rteCamera.RefreshCommandBuffer(); } OnStartOverride(); }
protected override void OnDestroy() { base.OnDestroy(); BaseGizmoInput gizmoInput = GetComponent <BaseGizmoInput>(); if (gizmoInput) { Destroy(gizmoInput); } if (Window != null && Window.Editor != null && Window.Editor.Tools.ActiveTool == this) { Window.Editor.Tools.ActiveTool = null; } if (m_rteCamera != null) { m_rteCamera.CommandBufferRefresh -= OnCommandBufferRefresh; m_rteCamera.RefreshCommandBuffer(); } }
protected override void Execute(ScriptableRenderContext renderContext, CommandBuffer cmd, HDCamera hdCamera, CullingResults cullingResult) { List <IRTECamera> list; if (m_cameras.TryGetValue(hdCamera.camera, out list)) { for (int i = 0; i < list.Count; ++i) { IRTECamera rteCamera = list[i]; rteCamera.CommandBufferOverride = cmd; rteCamera.RefreshCommandBuffer(); } } }
protected override void AwakeOverride() { base.AwakeOverride(); if (m_renderer == null) { m_renderer = gameObject.AddComponent <LineStripRenderer>(); } if (m_output != null) { m_output.GetComponent <Renderer>().enabled = false; } if (Window != null) { m_rteCamera = Window.Camera.gameObject.AddComponent <RTECamera>(); m_rteCamera.Event = CameraEvent.AfterImageEffects; m_rteCamera.CommandBufferRefresh += OnCommandBufferRefresh; m_rteCamera.RefreshCommandBuffer(); } if (m_pointerRenderer == null) { GameObject pointerGo = new GameObject("Pointer"); pointerGo.transform.SetParent(transform, false); pointerGo.transform.position = Vector3.one * 10000; m_pointerRenderer = pointerGo.AddComponent <LineStripRenderer>(); } m_pointerRenderer.Vertices = new[] { Vector3.zero }; Transform[] transforms = m_renderer.GetComponentsInChildren <Transform>(true); for (int i = 0; i < transforms.Length; ++i) { transforms[i].gameObject.layer = Editor.CameraLayerSettings.AllScenesLayer; } }
protected override void Awake() { base.Awake(); if (m_rteCamera == null) { IRTEGraphics graphics = IOC.Resolve <IRTEGraphics>(); if (graphics != null) { m_rteCamera = graphics.GetOrCreateCamera(Window.Camera, CameraEvent.AfterForwardAlpha); } if (m_rteCamera == null) { m_rteCamera = Window.Camera.gameObject.AddComponent <RTECamera>(); m_rteCamera.Event = CameraEvent.AfterForwardAlpha; } } m_rteCamera.CommandBufferRefresh += OnCommandBufferRefresh; NavMeshTriangulation triangulation = NavMesh.CalculateTriangulation(); m_facesMaterial = new Material(Shader.Find("Battlehub/RTNavigation/UnlitColor")); m_facesMaterial.color = new Color(1, 1, 1, 0.5f); m_facesMaterial.SetInt("_ZTest", (int)CompareFunction.LessEqual); m_facesMaterial.SetFloat("_ZWrite", 0); m_edgesMaterial = new Material(Shader.Find("Battlehub/RTCommon/LineBillboard")); m_edgesMaterial.color = new Color(0, 0, 0, 0.15f); m_edgesMaterial.SetFloat("_Scale", 1.0f); m_edgesMaterial.SetInt("_HandleZTest", (int)CompareFunction.LessEqual); m_verticesMaterial = new Material(Shader.Find("Hidden/RTHandles/PointBillboard")); m_verticesMaterial.color = new Color(0, 0, 0, 0.3f); m_verticesMaterial.SetFloat("_Scale", 1.25f); m_verticesMaterial.SetInt("_HandleZTest", (int)CompareFunction.LessEqual); Vector3[] verts = triangulation.vertices; int[] tris = triangulation.indices; m_facesMesh = new Mesh { name = "Faces" }; m_facesMesh.vertices = verts; m_facesMesh.triangles = tris; int[] areas = triangulation.areas; Color32[] colors = new Color32[triangulation.vertices.Length]; for (int i = 0; i < areas.Length; i++) { int area = areas[i]; Color32 color = Colors.Kellys[(area + 3) % Colors.Kellys.Length]; colors[tris[i * 3]] = color; colors[tris[i * 3 + 1]] = color; colors[tris[i * 3 + 2]] = color; } m_facesMesh.colors32 = colors; m_edgesMesh = new Mesh { name = "Edges" }; m_edgesMesh.vertices = verts; int[] indices = new int[tris.Length * 2]; for (int i = 0; i < tris.Length; i += 3) { indices[i * 2] = tris[i]; indices[i * 2 + 1] = tris[i + 1]; indices[i * 2 + 2] = tris[i + 1]; indices[i * 2 + 3] = tris[i + 2]; indices[i * 2 + 4] = tris[i + 2]; indices[i * 2 + 5] = tris[i]; } m_edgesMesh.SetIndices(indices, MeshTopology.Lines, 0); m_verticesMesh = new Mesh { name = "Vertices" }; m_verticesMesh.vertices = verts; m_verticesMesh.indexFormat = IndexFormat.UInt32; m_verticesMesh.SetIndices(Enumerable.Range(0, verts.Length).ToArray(), MeshTopology.Points, 0); m_rteCamera.RefreshCommandBuffer(); }
private static Texture2D Render( Camera camera, Shader shader, Renderer[] renderers, int width = -1, int height = -1) { bool autoSize = width < 0 || height < 0; int _width = autoSize ? (int)camera.pixelRect.width : width; int _height = autoSize ? (int)camera.pixelRect.height : height; GameObject go = new GameObject(); Camera renderCam = go.AddComponent <Camera>(); renderCam.CopyFrom(camera); renderCam.renderingPath = RenderingPath.Forward; renderCam.enabled = false; renderCam.clearFlags = CameraClearFlags.SolidColor; renderCam.backgroundColor = Color.white; renderCam.cullingMask = 0; IRenderPipelineCameraUtility cameraUtility = IOC.Resolve <IRenderPipelineCameraUtility>(); if (cameraUtility != null) { cameraUtility.EnablePostProcessing(renderCam, false); cameraUtility.SetBackgroundColor(renderCam, Color.white); } renderCam.allowHDR = false; renderCam.allowMSAA = false; renderCam.forceIntoRenderTexture = true; float aspect = renderCam.aspect; renderCam.rect = new Rect(Vector2.zero, Vector2.one); renderCam.aspect = aspect; RenderTextureDescriptor descriptor = new RenderTextureDescriptor() { width = _width, height = _height, colorFormat = RenderTextureFormat, autoGenerateMips = false, depthBufferBits = 16, dimension = TextureDimension.Tex2D, enableRandomWrite = false, memoryless = RenderTextureMemoryless.None, sRGB = true, useMipMap = false, volumeDepth = 1, msaaSamples = 1 }; RenderTexture rt = RenderTexture.GetTemporary(descriptor); RenderTexture prev = RenderTexture.active; renderCam.targetTexture = rt; RenderTexture.active = rt; Material replacementMaterial = new Material(shader); IRTEGraphics graphics = IOC.Resolve <IRTEGraphics>(); IRTECamera rteCamera = graphics.CreateCamera(renderCam, CameraEvent.AfterForwardAlpha, false, true); rteCamera.RenderersCache.MaterialOverride = replacementMaterial; rteCamera.Camera.name = "BoxSelectionCamera"; foreach (Renderer renderer in renderers) { Material[] materials = renderer.sharedMaterials; for (int i = 0; i < materials.Length; ++i) { if (materials[i] != null) { rteCamera.RenderersCache.Add(renderer); } } } rteCamera.RefreshCommandBuffer(); if (RenderPipelineInfo.Type != RPType.Standard) { bool invertCulling = GL.invertCulling; GL.invertCulling = true; renderCam.projectionMatrix *= Matrix4x4.Scale(new Vector3(1, -1, 1)); renderCam.Render(); GL.invertCulling = invertCulling; } else { renderCam.Render(); } Texture2D img = new Texture2D(_width, _height, TextureFormat, false, false); img.ReadPixels(new Rect(0, 0, _width, _height), 0, 0); img.Apply(); RenderTexture.active = prev; RenderTexture.ReleaseTemporary(rt); UnityObject.DestroyImmediate(go); UnityObject.Destroy(replacementMaterial); rteCamera.Destroy(); //System.IO.File.WriteAllBytes("Assets/box_selection.png", img.EncodeToPNG()); return(img); }
private void Start() { BaseGizmoInput input = GetComponent <BaseGizmoInput>(); if (input == null || input.Gizmo != this) { input = gameObject.AddComponent <BaseGizmoInput>(); input.Gizmo = this; } if (SceneCamera == null) { SceneCamera = Window.Camera; } if (SceneCamera == null) { SceneCamera = Camera.main; } if (Target == null) { Target = transform; } if (EnableUndo) { if (!RuntimeUndoInput.IsInitialized) { GameObject runtimeUndo = new GameObject(); runtimeUndo.name = "RuntimeUndo"; runtimeUndo.AddComponent <RuntimeUndoInput>(); } } IRTEGraphicsLayer graphicsLayer = Window.IOCContainer.Resolve <IRTEGraphicsLayer>(); if (graphicsLayer != null) { m_rteCamera = graphicsLayer.Camera; } if (m_rteCamera == null && SceneCamera != null) { m_rteCamera = SceneCamera.GetComponent <IRTECamera>(); if (m_rteCamera == null) { m_rteCamera = SceneCamera.gameObject.AddComponent <RTECamera>(); m_rteCamera.Event = UnityEngine.Rendering.CameraEvent.AfterImageEffectsOpaque; } } if (m_rteCamera != null) { m_prevPosition = transform.position; m_prevRotation = transform.rotation; m_prevScale = transform.localScale; m_prevCamPosition = m_rteCamera.Camera.transform.position; m_prevCamRotation = m_rteCamera.Camera.transform.rotation; m_prevOrthographic = m_rteCamera.Camera.orthographic; m_rteCamera.CommandBufferRefresh += OnCommandBufferRefresh; m_rteCamera.RefreshCommandBuffer(); } StartOverride(); }