Datasets:
Download code/robohome/src/apply_wall_paint_scene.py from RoboParty/RoboHome: direct link, hf CLI and curl.
- Browser
- Download file 4.04 kB
-
https://huggingface.co/datasets/RoboParty/RoboHome/resolve/main/code/robohome/src/apply_wall_paint_scene.py
- Command line
-
hf download hf://datasets/RoboParty/RoboHome/code/robohome/src/apply_wall_paint_scene.py
-
curl -L -o apply_wall_paint_scene.py https://huggingface.co/datasets/RoboParty/RoboHome/resolve/main/code/robohome/src/apply_wall_paint_scene.py
4.04 kB
| """Create a saved-scene derivative with cream-white walls outside the children room.""" | |
| from __future__ import annotations | |
| import argparse | |
| import copy | |
| import hashlib | |
| import json | |
| import sys | |
| from pathlib import Path | |
| import bpy | |
| def digest(path): | |
| h = hashlib.sha256() | |
| with Path(path).open('rb') as stream: | |
| for block in iter(lambda: stream.read(4 * 1024 * 1024), b''): | |
| h.update(block) | |
| return h.hexdigest() | |
| def main(): | |
| parser = argparse.ArgumentParser(description=__doc__) | |
| parser.add_argument('--tree', type=Path, required=True) | |
| parser.add_argument('--scene', type=Path, required=True) | |
| parser.add_argument('--output', type=Path, required=True) | |
| args = parser.parse_args(sys.argv[sys.argv.index('--') + 1:]) | |
| if args.output.exists(): | |
| raise SystemExit('Output already exists: ' + str(args.output)) | |
| code = args.tree / 'engine/source/scripts/internal/scene_generation' | |
| sys.path[:0] = [str(args.tree), str(args.tree / 'engine'), str(code), | |
| str(code / 'real_assets'), str(code / 'base')] | |
| from wall_paint_revision import apply | |
| manifest_path = args.scene / 'composition_manifest.runtime.json' | |
| manifest = json.loads(manifest_path.read_text()) | |
| source_blend = args.scene / (manifest['scene_id'] + '.blend') | |
| if not source_blend.is_file(): | |
| raise FileNotFoundError(source_blend) | |
| source_scene_hash = digest(source_blend) | |
| source_manifest_hash = digest(manifest_path) | |
| bpy.ops.wm.open_mainfile(filepath=str(source_blend)) | |
| before_geometry = { | |
| obj.name: hashlib.sha256(repr((obj.type, tuple(tuple(row) for row in obj.matrix_world))).encode()).hexdigest() | |
| for obj in bpy.context.scene.objects | |
| if obj.type == 'MESH' | |
| } | |
| receipt = apply(bpy, manifest) | |
| args.output.mkdir(parents=True) | |
| output_blend = args.output / source_blend.name | |
| bpy.ops.wm.save_as_mainfile(filepath=str(output_blend), relative_remap=False) | |
| bpy.ops.wm.open_mainfile(filepath=str(output_blend)) | |
| after_geometry = { | |
| obj.name: hashlib.sha256(repr((obj.type, tuple(tuple(row) for row in obj.matrix_world))).encode()).hexdigest() | |
| for obj in bpy.context.scene.objects | |
| if obj.type == 'MESH' | |
| } | |
| if before_geometry != after_geometry: | |
| raise ValueError('Wall paint revision changed mesh transforms or object types') | |
| reread = json.loads(bpy.context.scene['rhg_wall_paint_revision_json']) | |
| if reread != receipt: | |
| raise ValueError('Wall paint receipt changed after saved-scene reread') | |
| manifest['wall_paint_revision']['source_blend_sha256'] = source_scene_hash | |
| manifest['wall_paint_revision']['source_manifest_sha256'] = source_manifest_hash | |
| manifest['wall_paint_revision']['output_blend_sha256'] = digest(output_blend) | |
| manifest['wall_paint_revision']['saved_reopen_passed'] = True | |
| (args.output / 'composition_manifest.runtime.json').write_text( | |
| json.dumps(manifest, ensure_ascii=False, indent=2) + '\n') | |
| (args.output / 'wall_paint_receipt.json').write_text( | |
| json.dumps(manifest['wall_paint_revision'], ensure_ascii=False, indent=2) + '\n') | |
| # The existing interior renderer requires a source-bound receipt. This | |
| # derivative is its own immutable render source, so bind the receipt to | |
| # the saved blend and the final runtime manifest written above. | |
| render_receipt = { | |
| 'schema': 'rhg.home-revision-receipt.v1', | |
| 'passed': True, | |
| 'scene_id': manifest['scene_id'], | |
| 'source_blend_sha256': digest(output_blend), | |
| 'source_manifest_sha256': digest(args.output / 'composition_manifest.runtime.json'), | |
| 'source_unchanged': True, | |
| 'wall_paint_revision': manifest['wall_paint_revision'], | |
| } | |
| (args.output / 'home_revision_receipt.json').write_text( | |
| json.dumps(render_receipt, ensure_ascii=False, indent=2) + '\n') | |
| print(json.dumps(dict(passed=True, output=str(output_blend), receipt=receipt), ensure_ascii=False)) | |
| if __name__ == '__main__': | |
| main() | |