Skip to content

Commit

Permalink
tested
Browse files Browse the repository at this point in the history
  • Loading branch information
AlvaroHG committed Nov 21, 2024
1 parent c55873f commit ef9e76e
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 35 deletions.
29 changes: 15 additions & 14 deletions test_distortion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand Down Expand Up @@ -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},
Expand All @@ -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']}")
Expand Down
10 changes: 8 additions & 2 deletions unity/Assets/Scripts/AgentManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down
24 changes: 13 additions & 11 deletions unity/Assets/Scripts/CapturePass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;

Expand Down Expand Up @@ -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 ?
Expand All @@ -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);
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);


Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
Expand Down
22 changes: 14 additions & 8 deletions unity/Assets/Scripts/RenderingManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void EnablePasses(IEnumerable<string> activePassesNames, bool cameraChang
var mainCamera = GetComponent<Camera>();

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);
Expand All @@ -90,7 +90,7 @@ public void EnablePasses(IEnumerable<string> 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()));
Expand Down Expand Up @@ -118,29 +118,35 @@ public void EnablePasses(IEnumerable<string> 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<Camera>();
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<Camera>();
bool supportsAntialiasing = false;
var antiAliasLevel = supportsAntialiasing ? Mathf.Max(1, QualitySettings.antiAliasing) : 1;
Expand Down Expand Up @@ -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;
}
}
Expand Down

0 comments on commit ef9e76e

Please sign in to comment.