Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--[DO NOT MERGE] : HSSD SIRo AO Scene Work scripts #2338

Draft
wants to merge 159 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
159 commits
Select commit Hold shift + click to select a range
1e77874
first draft of collision_shape_automation.py
aclegg3 Mar 1, 2023
32fc619
profiling, refactors, efficiency improvements, stats
aclegg3 Mar 6, 2023
1b62fa5
add jittered sampling
aclegg3 Mar 7, 2023
820072e
Implement stateful API class for easier iteration and export of batch…
aclegg3 Mar 7, 2023
2e62aa6
add check and solution for invalid raycasts (hits outside bounding sh…
aclegg3 Mar 7, 2023
93ef8e2
don't use navmesh in object viewer
aclegg3 Mar 8, 2023
8a59dfa
only evaluate objects with receptacles defined
aclegg3 Mar 8, 2023
df61c68
add debug peek images for ground truth and proxy shapes. Add specifie…
aclegg3 Mar 8, 2023
e1b0be2
refactor to better modularize debug image capture suring proxy phase.…
aclegg3 Mar 9, 2023
2fbcb93
receptacle sampling and caching
aclegg3 Mar 9, 2023
ea4e165
magenta/alpha clear color for better object contrast. Add Receptacle …
aclegg3 Mar 10, 2023
2a82a24
Added: receptacle access metrics v1, receptacle density sampling, hem…
aclegg3 Mar 11, 2023
1c25396
debug visualization of receptacle access metrics and receptacle verti…
aclegg3 Mar 13, 2023
f1e009f
implement saving receptacle access metrics to CSV
aclegg3 Mar 13, 2023
1fb3cbe
prototype VHACD optimization loop. Minor bugfixes.
aclegg3 Mar 14, 2023
5dabf57
bugfix shape id tracking. VHACD collision shape optimization for sele…
aclegg3 Mar 14, 2023
c456710
receptacle stability analysis
aclegg3 Mar 15, 2023
c4ae110
initial physics metric tests
aclegg3 Mar 24, 2023
585269a
add receptacle debug_draw in viewer. Limit processed objects to those…
aclegg3 Apr 3, 2023
d86da23
refactor to align data cache protocal with design
aclegg3 Apr 4, 2023
1ab696a
minor settle test fix
aclegg3 Apr 5, 2023
18d0750
add viewer snapping util for receptacle debugging
aclegg3 Apr 5, 2023
899b2bc
simpler constructed cylinder and receptacle stability test improvements
aclegg3 Apr 7, 2023
77dd58b
multi-colored render for different receptacles
aclegg3 Apr 12, 2023
f82137b
re-align API with habitat-lab mesh_data changes. Add object re-orient…
aclegg3 Apr 14, 2023
4f1a5ef
enable running per-scene evaluations
aclegg3 Apr 14, 2023
d1124e2
use CollisionProxyOptimizer in viewer tool and remove outdated evalua…
aclegg3 Apr 14, 2023
4942997
separate obj_viewer and (scene)viewer. Add scene viewer features to v…
aclegg3 Apr 14, 2023
16d4edf
add mouse object info in right click for scene viewer
aclegg3 Apr 15, 2023
5289880
add CPO use in viewer to discplay rec metrics and filter. Add termina…
aclegg3 Apr 15, 2023
d1c2ae7
add caching and disply of per-point access and stability metrics
aclegg3 Apr 15, 2023
55b737f
minor fixes and cleanup for obj_viewer
aclegg3 Apr 18, 2023
bdfddf2
changes supporting collision shape optimization at scene level
aclegg3 Apr 18, 2023
dcd44aa
viewer.py changes supporting receptacle filtering and loading/saving …
aclegg3 Apr 18, 2023
e7e867c
COACD optimization, shape score improvement, viewer documentation.
aclegg3 Apr 19, 2023
4458b53
polish UI and add CLI
aclegg3 Apr 19, 2023
5a1c1fd
save coacd output for each shape_id for later copy instead of additio…
aclegg3 Apr 19, 2023
2fb86d0
fix coverge of debug image flag
aclegg3 Apr 19, 2023
bfc7d46
exclude objects with CLI
aclegg3 Apr 20, 2023
3bf6cd5
add ModelCategorizer workflow compatibility
aclegg3 Apr 20, 2023
33c4714
option to override the coacd threshold values from CLI
aclegg3 Apr 21, 2023
917a335
add a file annotating object ids which cause caocd trouble to use as …
aclegg3 Apr 21, 2023
ec6584c
add the option to optimize all objects with receptacles defined in th…
aclegg3 Apr 21, 2023
3b1fa06
start and end index CLI + exception handling and failure tracking output
aclegg3 Apr 24, 2023
4fe9a11
load rec data when cpo is not initialized
aclegg3 Apr 24, 2023
4238e48
add object sampling logic to the viewer app for scene investigation
aclegg3 Apr 25, 2023
d15897d
minor change to documentation and console output
aclegg3 Apr 25, 2023
def3dc4
add CLI additional CLI options for part only and file defined objects
aclegg3 Apr 26, 2023
97fabc1
refactor viewer for faster rec drawing and collision optimization for…
aclegg3 Apr 27, 2023
499c507
remove VHACD integration
aclegg3 Apr 27, 2023
fc43799
refactor improve interactive object sampling
aclegg3 Apr 27, 2023
b542211
Improve clutter generation utility in viewer
aclegg3 Apr 28, 2023
daa6f72
add spot_viewer application for evaluating navigability
aclegg3 Apr 29, 2023
cca2596
minor useability fixes for spot_viewer
aclegg3 Apr 29, 2023
f0e8a79
spot_viewer: move robot strafe to 'qe' keys. Add mouse raycast object…
aclegg3 May 1, 2023
a73edab
spot_viewer: Add object modification interface features.
aclegg3 May 1, 2023
6fbec1a
add clutter removal with 'c' + tracking in removed_clutter.txt
aclegg3 May 1, 2023
11fe157
obj_viewer compares can with cylinder
aclegg3 May 1, 2023
a49eec3
UI improvements for viewer app
aclegg3 May 1, 2023
da9a72e
useability improvements for spot_viewer.py
aclegg3 May 16, 2023
c285e26
add ssd removal script for post-processing scene_instance.json files …
aclegg3 May 16, 2023
b07e6ab
protect from crash when raycast hits nothing
aclegg3 May 19, 2023
b379083
viewer.py receptacle filter view no longer requires cpo
aclegg3 Jun 1, 2023
664c545
additional changes to support navmesh refactor
aclegg3 Jun 1, 2023
3e9f76f
remove navmesh recompute from cpo settings in viewer.py
aclegg3 Jun 1, 2023
e1a74bf
minor utility updates for GUI
aclegg3 Jun 14, 2023
9597e72
add slick hit visualization to easier identify roof hits
aclegg3 Aug 7, 2023
ad1b423
update message
aclegg3 Sep 6, 2023
53794b9
refactor to support new requirement in robot API init
aclegg3 Oct 2, 2023
f8ebc1e
add automated outdoor object removal
aclegg3 Oct 2, 2023
571c983
minor updates
aclegg3 Oct 3, 2023
1d927ba
add automated filter file loading to viewer tool
aclegg3 Oct 3, 2023
18c8c12
snap to largest island in viewer app
aclegg3 Oct 3, 2023
7570a2c
largest navmesh snapping and magnum API update
aclegg3 Nov 18, 2023
008707b
object getter util
aclegg3 Feb 9, 2024
62bbc97
fixes for aos
aclegg3 Feb 9, 2024
545d73e
enable AO receptacle selection
aclegg3 Feb 9, 2024
6fe2570
update to support selecting and transforming ArticulatedObjects
aclegg3 Feb 23, 2024
d94da56
rebase apps on habitat-lab main
aclegg3 Feb 28, 2024
f7f21ea
missed in merge
aclegg3 Feb 28, 2024
a6edc00
--missed stuff in rebase
jturner65 Mar 5, 2024
35f3173
--rebase issue
jturner65 Mar 5, 2024
9935ec5
--minor cleanup; add scene ID to screen text
jturner65 Mar 12, 2024
7bb6400
--fix for embedded paths
jturner65 Mar 12, 2024
983a4c2
--add command line to not build navmesh
jturner65 Mar 13, 2024
0f52d1c
add blender armature to urdf converter tool
aclegg3 Aug 15, 2023
702e5f5
turn off debug vis flags
aclegg3 Aug 15, 2023
f9c6744
fix bugs introduced by flaker :(
aclegg3 Aug 16, 2023
fbd1998
refactor to correct for rest pose and corrdinate change in prismatic …
aclegg3 Aug 16, 2023
cb93e12
export urdf with armature name
aclegg3 Aug 17, 2023
5cb05b9
add commandline arguements and instructions for the script
aclegg3 Aug 17, 2023
9610cef
add receptacle classification for meshes
aclegg3 Sep 27, 2023
42e7dca
exporting receptacle meshes
aclegg3 Oct 3, 2023
63ead64
add batched converter script
aclegg3 Oct 19, 2023
a488673
use epsilon error instead of equality comparison for scale floats
aclegg3 Oct 23, 2023
ca90919
add support for collision spheres
aclegg3 Oct 23, 2023
12ead8d
add ao_config export and scne limited batching
aclegg3 Nov 2, 2023
c20a4e4
export full receptacle information with config
aclegg3 Nov 2, 2023
592fbe2
first draft of scene-level script to replace rigid objects with artic…
aclegg3 Nov 2, 2023
3593ad6
add root rotation correction to converter
aclegg3 Nov 3, 2023
2f64fa5
expose ArticulatedObject creation_attributes
aclegg3 Nov 3, 2023
d0eccde
bugfixes
aclegg3 Nov 3, 2023
f864708
bugfix
aclegg3 Nov 6, 2023
baa0a09
adds a report generator for checking the output of a converted batch …
aclegg3 Nov 29, 2023
d6a300e
force OBJECT context to avoid context errors with API
aclegg3 Nov 29, 2023
49f916e
add option to export receptacles meshes as visual shapes in URDF
aclegg3 Dec 4, 2023
676a201
add option to round collision scales to 4 decimal places
aclegg3 Dec 4, 2023
a70b18c
add option to flip negative scales for collision shapes
aclegg3 Dec 4, 2023
1f91c87
minor update to output and valid urdf migration
aclegg3 Jan 31, 2024
5c8e09e
better error message
aclegg3 Feb 9, 2024
4e34b16
try z up
aclegg3 Feb 9, 2024
ab0ff01
support export of multi-mesh receptacles
aclegg3 Feb 12, 2024
0d6b972
--remove erroneous ArticulatedObject's local initializationAttributes_
jturner65 Mar 14, 2024
8987eca
--remove early exit; conditionally build urdf; fix ao config json save.
jturner65 Mar 14, 2024
0459569
--add ability to just see kitchen regions
jturner65 Mar 19, 2024
5dc4cc6
--reorganize ctor code to collect per-scene init code
jturner65 Mar 19, 2024
74c6522
clear joint states on spot_viewer save with 'i'
aclegg3 Mar 20, 2024
a9d62da
add a keybind 'j' for clearing joint states manually
aclegg3 Mar 20, 2024
5329840
include AOs on the navmesh for spot_viewer
aclegg3 Mar 20, 2024
f39b059
add script to automatically check siro scenes with initial joint popp…
aclegg3 Mar 20, 2024
63f3661
--update spot viewer
jturner65 Mar 21, 2024
131fc46
--allow casting/obj selecttion through scene ceiling/roof
jturner65 Mar 21, 2024
8917f49
--clean up viewer some
jturner65 Mar 21, 2024
359091c
add region debug image output in script
aclegg3 Mar 21, 2024
bef1160
add semantic analysis from habitat-llm MEtadataInterface
aclegg3 Mar 21, 2024
737c060
bugfix
aclegg3 Mar 21, 2024
446edd3
-- Only exit if shift is pressed when pressing i
jturner65 Mar 21, 2024
c038e33
--add func to (re)load spot; reload/reset spot for scene instance save
jturner65 Mar 21, 2024
58b006e
--added joint state clearing from spot script.
jturner65 Mar 22, 2024
3b5148c
recompute navmesh after joint reset
aclegg3 Mar 22, 2024
a7152f6
--expand edit capabilities to provide 3 axis rotation
jturner65 Mar 24, 2024
559aac7
--allow for different spot locations; cleanup
jturner65 Mar 25, 2024
f8cd0bf
--enable very small movement amount
jturner65 Mar 25, 2024
068982b
--clear joint vels along with joint pos
jturner65 Mar 25, 2024
678a932
add material correction to Blender conversion scripts for Vlad
aclegg3 Mar 25, 2024
f5cee01
add --no-replace option to batched converter to skip already converte…
aclegg3 Mar 25, 2024
d6bb457
update no-replace to check for expected contents instead of only a di…
aclegg3 Mar 26, 2024
86274ad
add ao smoke test and correct receptacle check for ao converter valid…
aclegg3 Mar 26, 2024
d24fa0d
update URDF migration script to be more configurable from CLI
aclegg3 Mar 26, 2024
aeaf155
--increase radius of receptacle view
jturner65 Mar 26, 2024
b9c0504
--temp mechanism to save scene instance and exit.
jturner65 Mar 27, 2024
0bce732
add option to restrict batch processing to one or a set of assets wit…
aclegg3 Mar 28, 2024
96fe216
make output json human readable
aclegg3 Mar 28, 2024
e48ec67
--add undo function : Return current selected obj to orig state
jturner65 Mar 29, 2024
583b14d
add AO import to spot_viewer with 'v'. Add ao category sorting and vi…
aclegg3 Mar 29, 2024
2df7771
cleanup ao script and add joint opener to spot_viewer
aclegg3 Mar 29, 2024
b5f26d6
minor change to naming of region files
aclegg3 Apr 1, 2024
c858875
add region count to siro scene check script
aclegg3 Apr 1, 2024
b2113f1
Merge branch 'main' into hssd_ao_utilities
jturner65 Apr 3, 2024
2ac033d
default link logic, receptacle filtering, refactor
aclegg3 Apr 5, 2024
75e9470
Merge branch 'main' into hssd_ao_utilities
jturner65 Apr 8, 2024
8107ac5
Merge remote-tracking branch 'origin/main' into hssd_ao_utilities
aclegg3 Apr 12, 2024
a433158
Merge remote-tracking branch 'origin/main' into hssd_ao_utilities
aclegg3 Apr 19, 2024
d56c374
add utility for "within_set" computation to the siro scene checker
aclegg3 Apr 22, 2024
8d9d54e
Merge remote-tracking branch 'origin/main' into hssd_ao_utilities
aclegg3 Apr 23, 2024
33e3302
refactor to allow non TriangleMesh receptacles and AnyObjectReceptacles
aclegg3 Apr 26, 2024
35fdae4
Merge remote-tracking branch 'origin/main' into hssd_ao_utilities
aclegg3 May 6, 2024
e795404
refactor check_siro_scenes.py
aclegg3 May 7, 2024
799a61a
add faucet point visualizer to the check set
aclegg3 May 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,419 changes: 1,419 additions & 0 deletions examples/obj_viewer.py

Large diffs are not rendered by default.

1,546 changes: 1,546 additions & 0 deletions examples/spot_viewer.py

Large diffs are not rendered by default.

1,489 changes: 1,296 additions & 193 deletions examples/viewer.py

Large diffs are not rendered by default.

239 changes: 239 additions & 0 deletions tools/batched_armature_to_urdf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
# Copyright (c) Meta Platforms, Inc. and its affiliates.
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

import argparse
import csv
import os
from collections import defaultdict
from typing import Callable, Dict, List


def file_endswith(filepath: str, end_str: str) -> bool:
"""
Return whether or not the file ends with a string.
"""
return filepath.endswith(end_str)


def find_files(
root_dir: str, discriminator: Callable[[str, str], bool], disc_str: str
) -> List[str]:
"""
Recursively find all filepaths under a root directory satisfying a particular constraint as defined by a discriminator function.

:param root_dir: The roor directory for the recursive search.
:param discriminator: The discriminator function which takes a filepath and discriminator string and returns a bool.

:return: The list of all absolute filepaths found satisfying the discriminator.
"""
filepaths: List[str] = []

if not os.path.exists(root_dir):
print(" Directory does not exist: " + str(dir))
return filepaths

for entry in os.listdir(root_dir):
entry_path = os.path.join(root_dir, entry)
if os.path.isdir(entry_path):
sub_dir_filepaths = find_files(entry_path, discriminator, disc_str)
filepaths.extend(sub_dir_filepaths)
# apply a user-provided discriminator function to cull filepaths
elif discriminator(entry_path, disc_str):
filepaths.append(entry_path)
return filepaths


def load_scene_map_file(filepath: str) -> Dict[str, List[str]]:
"""
Loads a csv file containing a mapping of scenes to objects. Returns that mapping as a Dict.
NOTE: Assumes column 0 is object id and column 1 is scene id
"""
assert os.path.exists(filepath)
assert filepath.endswith(".csv")

scene_object_map = defaultdict(lambda: [])
with open(filepath, newline="") as f:
reader = csv.reader(f)
for rix, row in enumerate(reader):
if rix == 0:
pass
# column labels
else:
scene_id = row[1]
object_hash = row[0]
scene_object_map[scene_id].append(object_hash)

return scene_object_map


def run_armature_urdf_conversion(blend_file: str, export_path: str, script_path: str):
assert os.path.exists(blend_file), f"'{blend_file}' does not exist."
os.makedirs(export_path, exist_ok=True)
base_command = f"blender {blend_file} --background --python {script_path} -- --export-path {export_path}"
# first export the meshes
os.system(base_command + " --export-meshes --fix-materials")
# then export the URDF
os.system(
base_command
+ " --export-urdf --export-ao-config --round-collision-scales --fix-collision-scales"
)


def get_dirs_in_dir(dirpath: str) -> List[str]:
"""
Get the directory names inside a directory path.
"""
return [
entry.split(".glb")[0]
for entry in os.listdir(dirpath)
if os.path.isdir(os.path.join(dirpath, entry))
]


def get_dirs_in_dir_complete(dirpath: str) -> List[str]:
"""
Get the directory names inside a directory path for directories which contain:
- urdf
- ao_config.json
- at least 2 .glb files (for articulation)
TODO: check the urdf contents for all .glbs
"""
relevant_entries = []
for entry in os.listdir(dirpath):
entry_path = os.path.join(dirpath, entry)
entry_name = entry.split(".glb")[0]
if os.path.isdir(entry_path):
contents = os.listdir(entry_path)
urdfs = [file for file in contents if file.endswith(".urdf")]
configs = [file for file in contents if file.endswith(".ao_config.json")]
glbs = [file for file in contents if file.endswith(".glb")]
if len(urdfs) > 0 and len(configs) > 0 and len(glbs) > 2:
relevant_entries.append(entry_name)

return relevant_entries


# -----------------------------------------
# Batches blender converter calls over a directory of blend files
# e.g. python tools/batched_armature_to_urdf.py --root-dir ~/Downloads/OneDrive_1_9-27-2023/ --out-dir tools/armature_out_test/ --converter-script-path tools/blender_armature_to_urdf.py
# e.g. add " --skip-strings wardrobe" to skip all objects with "wardrobe" in the filepath
# -----------------------------------------
def main():
parser = argparse.ArgumentParser(
description="Run Blender Armature to URDF converter for all .blend files in a directory."
)
parser.add_argument(
"--root-dir",
type=str,
help="Path to a directory containing .blend files for conversion.",
)
parser.add_argument(
"--out-dir",
type=str,
help="Path to a directory for exporting URDF and assets.",
)
parser.add_argument(
"--converter-script-path",
type=str,
help="Path to blender_armature_to_urdf.py.",
default="tools/blender_armature_to_urdf.py",
)
parser.add_argument(
"--skip-strings",
nargs="+",
type=str,
help="Substrings which indicate a path which should be skippped. E.g. an object hash '6f57e5076e491f54896631bfe4e9cfcaa08899e2' to skip that object's blend file.",
default=None,
)
parser.add_argument(
"--scene-map-file",
type=str,
default=None,
help="Path to a csv file with scene to object mappings. Used in conjuction with 'scenes' to limit conversion to a small batch.",
)
parser.add_argument(
"--scenes",
nargs="+",
type=str,
help="Substrings which indicate scenes which should be converted. Must be provided with a scene map file. When provided, only these scenes are converted.",
default=None,
)
parser.add_argument(
"--no-replace",
default=False,
action="store_true",
help="If specified, cull candidate .blend files if there already exists a matching output directory for the asset.",
)
parser.add_argument(
"--assets",
nargs="+",
type=str,
help="Asset name substrings which indicate the subset of assets which should be converted. When provided, only these assets are converted.",
default=None,
)

args = parser.parse_args()
root_dir = args.root_dir
assert os.path.isdir(root_dir), "directory must exist."
assert os.path.exists(
args.converter_script_path
), f"provided script path '{args.converter_script_path}' does not exist."

# get blend files
blend_paths = find_files(root_dir, file_endswith, ".blend")
if args.skip_strings is not None:
skipped_strings = [
path
for skip_str in args.skip_strings
for path in blend_paths
if skip_str in path
]
blend_paths = list(set(blend_paths) - set(skipped_strings))

if args.no_replace:
# out_dir_dirs = get_dirs_in_dir(args.out_dir)
out_dir_dirs = get_dirs_in_dir_complete(args.out_dir)
remaining_blend_paths = [
blend
for blend in blend_paths
if blend.split("/")[-1].split(".")[0] not in out_dir_dirs
]
print(f"original blends = {len(blend_paths)}")
print(f"existing dirs = {len(out_dir_dirs)}")
print(f"remaining_blend_paths = {len(remaining_blend_paths)}")
remaining_hashes = [
blend_path.split("/")[-1] for blend_path in remaining_blend_paths
]
print(f"remaining_hashes = {remaining_hashes}")
blend_paths = remaining_blend_paths
# use this to check, but not commit to trying again
# exit()

if args.scene_map_file is not None and args.scenes is not None:
# load the scene map file and limit the object set by scenes
scene_object_map = load_scene_map_file(args.scene_map_file)
limited_object_paths = []
for scene in args.scenes:
for object_id in scene_object_map[scene]:
for blend_path in blend_paths:
if object_id in blend_path:
limited_object_paths.append(blend_path)
blend_paths = list(set(limited_object_paths))

if args.assets is not None:
asset_blend_paths = []
for name_str in args.assets:
asset_blend_paths.extend([path for path in blend_paths if name_str in path])
blend_paths = asset_blend_paths

for blend_path in blend_paths:
run_armature_urdf_conversion(
blend_file=blend_path,
export_path=args.out_dir,
script_path=args.converter_script_path,
)


if __name__ == "__main__":
main()
Loading