/// <summary> /// Render the emulated environment in the specified manner. /// </summary> /// <param name="renderTarget">Render target to render into.</param> /// <param name="dataTypeToRender">Type of data to render (e.g. color camera, depth data).</param> /// <param name="renderCameraPosition">Position (relative to emulated environment) /// for the simulation camera to render from.</param> /// <param name="renderCameraRotation">Rotation (relative to emulated environment) /// for the simulation camera to render at.</param> public static void RenderEmulatedEnvironment(RenderTexture renderTarget, EmulatedDataType dataTypeToRender, Vector3 renderCameraPosition, Quaternion renderCameraRotation) { Material renderMaterial = null; switch (dataTypeToRender) { case EmulatedDataType.DEPTH: renderMaterial = m_emulatedDepthMaterial; break; case EmulatedDataType.COLOR_CAMERA: renderMaterial = m_emulatedColorCameraMaterial; break; } if (renderMaterial == null) { return; } // Set up camera m_emulationCamera.transform.position = renderCameraPosition; m_emulationCamera.transform.rotation = renderCameraRotation; // Stash current render state Camera previousCamera = Camera.current; RenderTexture previousRenderTexture = RenderTexture.active; // Set up new render state Camera.SetupCurrent(m_emulationCamera); Graphics.SetRenderTarget(renderTarget); GL.Clear(true, true, Color.black); // Render if (m_renderObject != null) { for (int i = 0; i < renderMaterial.passCount; i++) { if (renderMaterial.SetPass(i)) { Graphics.DrawMeshNow(m_renderObject, Matrix4x4.identity); } } } // Restore previous render state Camera.SetupCurrent(previousCamera); RenderTexture.active = previousRenderTexture; }
/// <summary> /// Render the emulated environment in the specified manner. /// </summary> /// <param name="renderTarget">Render target to render into.</param> /// <param name="dataTypeToRender">Type of data to render (e.g. color camera, depth data).</param> /// <param name="renderCameraPosition">Position (relative to emulated environment) /// for the simulation camera to render from.</param> /// <param name="renderCameraRotation">Rotation (relative to emulated environment) /// for the simulation camera to render at.</param> public static void RenderEmulatedEnvironment(RenderTexture renderTarget, EmulatedDataType dataTypeToRender, Vector3 renderCameraPosition, Quaternion renderCameraRotation) { Material renderMaterial = null; switch (dataTypeToRender) { case EmulatedDataType.DEPTH: renderMaterial = m_emulatedDepthMaterial; break; case EmulatedDataType.COLOR_CAMERA: renderMaterial = m_emulatedColorCameraMaterial; break; } if (renderMaterial == null) { return; } // Set up camera m_emulationCamera.transform.position = renderCameraPosition; m_emulationCamera.transform.rotation = renderCameraRotation; // Stash current render state Camera previousCamera = Camera.current; RenderTexture previousRenderTexture = RenderTexture.active; // Set up new render state Camera.SetupCurrent(m_emulationCamera); Graphics.SetRenderTarget(renderTarget); GL.Clear(true, true, Color.black); // Render if(m_renderObject != null) { for (int i = 0; i < renderMaterial.passCount; i++) { if (renderMaterial.SetPass(i)) { Graphics.DrawMeshNow(m_renderObject, Matrix4x4.identity); } } } // Restore previous render state Camera.SetupCurrent(previousCamera); RenderTexture.active = previousRenderTexture; }