diff --git a/test_distortion.py b/test_distortion.py index 3d56819d61..d0cbdbec9c 100644 --- a/test_distortion.py +++ b/test_distortion.py @@ -40,6 +40,7 @@ def load_scene(scene_name, house_path=None, run_in_editor=False, platform=None, renderDistortionImage=distortion, renderSemanticSegmentation=True, renderInstanceSegmentation=True, + fieldOfView=120, **args, ) @@ -102,19 +103,19 @@ def load_scene(scene_name, house_path=None, run_in_editor=False, platform=None, intensityY=0.93 ) - xpos = dict(x=0.0, y=0.900992214679718, z=0.0786) - sr = controller.step( - action="Teleport", position=xpos, rotation=dict(x=0, y=0, z=0), forceAction=True - ) - if not sr.metadata["lastActionSuccess"]: - print(f"Error teleporting to {xpos}") - current_pos = controller.last_event.metadata["agent"]["position"] - print(f"Current position: {current_pos}") - # print("Teleported to calibration room") - # print(f"Current position: {thor_controller.last_event.metadata['agent']['position']}") - # controller.step( - # {"action": "RotateCameraMount", "degrees": 13, "secondary": False} - # ) + # xpos = dict(x=0.0, y=0.900992214679718, z=0.0786) + # # sr = controller.step( + # # action="Teleport", position=xpos, rotation=dict(x=0, y=0, z=0), forceAction=True + # # ) + # # if not sr.metadata["lastActionSuccess"]: + # # print(f"Error teleporting to {xpos}") + # # current_pos = controller.last_event.metadata["agent"]["position"] + # # print(f"Current position: {current_pos}") + # # print("Teleported to calibration room") + # # print(f"Current position: {thor_controller.last_event.metadata['agent']['position']}") + # # controller.step( + # # {"action": "RotateCameraMount", "degrees": 13, "secondary": False} + # # ) cam_param = { "position": {"x": -0.1211464, "y": 0.561659, "z": 0.03892733}, "rotation": {"x": 20.0, "y": 0.0, "z": 0.0}, @@ -128,7 +129,7 @@ def load_scene(scene_name, house_path=None, run_in_editor=False, platform=None, position=cam_param["position"], rotation=cam_param["rotation"], fieldOfView=cam_param["fov"], - agentId=0, + agentId=0 ) print(f"Action {controller.last_action['action']} success: {evt.metadata['lastActionSuccess']}") diff --git a/unity/Assets/Scripts/AgentManager.cs b/unity/Assets/Scripts/AgentManager.cs index fda7f639f2..600e0cfb9e 100644 --- a/unity/Assets/Scripts/AgentManager.cs +++ b/unity/Assets/Scripts/AgentManager.cs @@ -753,8 +753,12 @@ private void updateCameraProperties( {"_flow", this.renderFlowImage}, {"_distortion", this.renderDistortionImage} }.Where(x => x.Value).Select(x => x.Key); + renderingManager.EnablePasses(activeCapturePassList, cameraChange: true); + + // this.updateRenderingManagers(activeCapturePassList, true); + + - this.updateRenderingManagers(activeCapturePassList, true); this.activeAgent().actionFinished(success: true); } @@ -2020,7 +2024,9 @@ public void ProcessControlCommand(DynamicServerAction controlCommand) { // Call with flags updateThirdPartyCameraImageSynthesis(true); } - updateRenderingManagers(activeCapturePassList, true); + + // TODO: not sure if needed just after initialize + // updateRenderingManagers(activeCapturePassList, true); // let's look in the agent's set of actions for the action this.activeAgent().ProcessControlCommand(controlCommand: controlCommand); diff --git a/unity/Assets/Scripts/CapturePass.cs b/unity/Assets/Scripts/CapturePass.cs index 734f38af52..7553602b71 100644 --- a/unity/Assets/Scripts/CapturePass.cs +++ b/unity/Assets/Scripts/CapturePass.cs @@ -147,7 +147,7 @@ public virtual string GetName() { } public virtual void AddToCommandBuffer(CommandBuffer commandBuffer) { - Debug.Log("-------- AddToCommandBuffer " + name); + // Debug.Log("-------- AddToCommandBuffer " + name); // int screenCopyID = Shader.PropertyToID("_MainTex"); // cb.GetTemporaryRT(screenCopyID, -1, -1, 0, FilterMode.Bilinear); @@ -161,7 +161,7 @@ public virtual void AddToCommandBuffer(CommandBuffer commandBuffer) { // cb.SetRenderTarget(RenderTargetIdentifier); // cb.Blit(this.GetRenderTarget(), RenderTexture.active); - Debug.Log("------- command buffer set for " + this.name); + // Debug.Log("------- command buffer set for " + this.name); // cb.SetRenderTarget(new RenderTargetIdentifier(null as Texture)); //this.camera.targetTexture = null; @@ -232,12 +232,12 @@ private RenderTexture CreateRenderTexture(int width, int height) { } if (this.tex == null) { - Debug.Log($"------------ texture format {Enum.GetName(typeof(TextureFormat), readTextureFormat)} val {readTextureFormat}"); + // Debug.Log($"------------ texture format {Enum.GetName(typeof(TextureFormat), readTextureFormat)} val {readTextureFormat}"); tex = new Texture2D(Screen.width, Screen.height, readTextureFormat, false); } rt.antiAliasing = antiAliasLevel; if (rt.Create()) { - Debug.Log("Created Render Texture with width= " + width + " height=" + height); + // Debug.Log("Created Render Texture with width= " + width + " height=" + height); return rt; } else { // throw exception ? @@ -248,10 +248,10 @@ private RenderTexture CreateRenderTexture(int width, int height) { public virtual void OnInitialize(Camera mainCamera) { - Debug.Log("++++ initialize called for " + this.name); + // Debug.Log("++++ initialize called for " + this.name); if (!shader && !string.IsNullOrEmpty(shaderName)) { - Debug.Log("---- loading shader " + shaderName); + // Debug.Log("---- loading shader " + shaderName); shader = Shader.Find(shaderName); } @@ -281,7 +281,7 @@ public virtual void OnInitialize(Camera mainCamera) { public virtual void OnCameraChange(Camera mainCamera) { - Debug.Log("-------OnCameraChange " + name); + Debug.Log($"-------OnCameraChange {name} on object {mainCamera.gameObject.name}"); if (tex != null) { UnityEngine.Object.Destroy(tex); tex = null; @@ -336,7 +336,7 @@ public virtual void OnCameraChange(Camera mainCamera) { else { cb = new CommandBuffer(); } - Debug.Log("------- Before command buffer " + name); + // Debug.Log("------- Before command buffer " + name); this.AddToCommandBuffer(cb); @@ -459,7 +459,7 @@ public override void AddToCommandBuffer(CommandBuffer commandBuffer) { this.camera.renderingPath = RenderingPath.Forward; this.camera.AddCommandBuffer(CameraEvent.BeforeForwardOpaque, cb); this.camera.AddCommandBuffer(CameraEvent.BeforeFinalPass, cb); - Debug.Log($"------ AddToCommandBuffer for {this.name}"); + // Debug.Log($"------ AddToCommandBuffer for {this.name}"); this.camera.SetReplacementShader(shader, ""); this.camera.backgroundColor = Color.blue; this.camera.clearFlags = CameraClearFlags.SolidColor; @@ -496,7 +496,7 @@ public override void AddToCommandBuffer(CommandBuffer commandBuffer) { //this.camera.targetTexture = null; // cb.Blit(this.GetRenderTarget(), BuiltinRenderTextureType.CurrentActive); - Debug.Log($"----------- Blit for multipass"); + // Debug.Log($"----------- Blit for multipass"); // If rendering to display if (this.toDisplayId.HasValue) { @@ -527,8 +527,10 @@ public override void OnInitialize(Camera mainCamera) { base.OnInitialize(mainCamera); } + private bool done = false; + public override void OnCameraChange(Camera mainCamera) { - Debug.Log($"----------- Multipass OnCameraChange for {this.passDict.Values.Select(x => x.GetName())}"); + // Debug.Log($"----------- Multipass OnCameraChange for {this.passDict.Values.Select(x => x.GetName())}"); foreach (var pair in this.passDict) { pair.Value.OnCameraChange(mainCamera); } diff --git a/unity/Assets/Scripts/RenderingManager.cs b/unity/Assets/Scripts/RenderingManager.cs index ca7e80e60a..934719437a 100644 --- a/unity/Assets/Scripts/RenderingManager.cs +++ b/unity/Assets/Scripts/RenderingManager.cs @@ -80,7 +80,7 @@ public void EnablePasses(IEnumerable activePassesNames, bool cameraChang var mainCamera = GetComponent(); if (activePassesNames != null) { - Debug.Log($"--------- Enabling passes 0 {string.Join(", ", activePassesNames)}"); + // Debug.Log($"--------- Enabling passes 0 {string.Join(", ", activePassesNames)}"); var newActive = activePassesNames.Select(name => { ICapturePass capturePass; var exists = availablePasses.TryGetValue(name, out capturePass); @@ -90,7 +90,7 @@ public void EnablePasses(IEnumerable activePassesNames, bool cameraChang if (newActive.Any(x => x == null)) { throw new InvalidOperationException($"Invalid capture passes `{string.Join(", ", newActive.Where(x => x == null))}`"); } - Debug.Log($"--------- Enabling passes 2 {string.Join(", ", newActive.Select(x => x.GetName()))}"); + // Debug.Log($"--------- Enabling passes 2 {string.Join(", ", newActive.Select(x => x.GetName()))}"); var toInitialize = newActive.Where( x => ! x.IsInitialized()); // if this is one of the passes that is part of a MultiPass var mainMultiPassUpdate = toInitialize.Where(x => this.WithMainMultiPass.Contains(x.GetName())); @@ -118,29 +118,35 @@ public void EnablePasses(IEnumerable activePassesNames, bool cameraChang // Initialize calls OnCameraChange var onCameraChange = activePasses.Values.Where(x => !this.WithMainMultiPass.Contains(x.GetName())); - Debug.Log($"--------- OnCameraChange passes 3 {string.Join(", ", onCameraChange)}"); + // Debug.Log($"--------- OnCameraChange passes 3 {string.Join(", ", onCameraChange)}"); foreach (var pass in onCameraChange) { // && !initialized.Contains(x.GetName()))) { pass.OnCameraChange(mainCamera); } } - Debug.Log($"--------- Enabling passes 4 activePasses {string.Join(", ", this.activePasses)}"); + // Debug.Log($"--------- Enabling passes 4 activePasses {string.Join(", ", this.activePasses)}"); } } public void OnCameraChange() { - Debug.Log($"===== OnCameraChange multipass for {string.Join(", ", this.activePasses.Values.Select(x => x.GetName()))}"); + // Debug.Log($"===== OnCameraChange multipass for {string.Join(", ", this.activePasses.Values.Select(x => x.GetName()))}"); var mainCamera = GetComponent(); foreach (var pass in this.activePasses.Values) { pass.OnCameraChange(mainCamera); } } + // public void OnCameraChange(Camera camera) { + // foreach (var pass in this.activePasses.Values) { + // pass.OnCameraChange(mainCamera); + // } + // } + void Awake() { - Debug.Log("=-------- Rendering Manager Awake"); + Debug.Log($"=-------- Rendering Manager Awake parent {this.gameObject.transform.name}"); var camera = GetComponent(); bool supportsAntialiasing = false; var antiAliasLevel = supportsAntialiasing ? Mathf.Max(1, QualitySettings.antiAliasing) : 1; @@ -228,9 +234,9 @@ public byte[] GetCaptureBytes(string passName, bool jpeg = false) { return (new byte[0]); } else { - Debug.Log($"--- call GetBytes on pass {passName}"); + // Debug.Log($"--- call GetBytes on pass {passName}"); var bytes = pass.GetBytes(jpeg); - Debug.Log($"-------- bytes size {bytes.Length}"); + // Debug.Log($"-------- bytes size {bytes.Length}"); return bytes; } }