Datasets:
Download generator/scripts/create_minimal_template.py from mage0001/H2SMV-FPV: direct link, hf CLI and curl.
- Browser
- Download file 2.75 kB
-
https://huggingface.co/datasets/mage0001/H2SMV-FPV/resolve/main/generator/scripts/create_minimal_template.py
- Command line
-
hf download hf://datasets/mage0001/H2SMV-FPV/generator/scripts/create_minimal_template.py
-
curl -L -o create_minimal_template.py https://huggingface.co/datasets/mage0001/H2SMV-FPV/resolve/main/generator/scripts/create_minimal_template.py
2.75 kB
| #!/usr/bin/env python3 | |
| """Create an asset-free Blender template satisfying the H2SMV interface.""" | |
| from __future__ import annotations | |
| import argparse | |
| import sys | |
| from pathlib import Path | |
| import bpy | |
| import mathutils | |
| def parse_args() -> argparse.Namespace: | |
| argv = sys.argv[sys.argv.index("--") + 1:] if "--" in sys.argv else [] | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument("--out", required=True, type=Path) | |
| parser.add_argument("--camera-collection", default="CAMERA_PRESETS") | |
| return parser.parse_args(argv) | |
| def point_camera(camera: bpy.types.Object, target: mathutils.Vector) -> None: | |
| direction = target - camera.location | |
| camera.rotation_euler = direction.to_track_quat("-Z", "Y").to_euler() | |
| def main() -> None: | |
| args = parse_args() | |
| bpy.ops.object.select_all(action="SELECT") | |
| bpy.ops.object.delete(use_global=False) | |
| world = bpy.data.worlds.get("H2SMV_WORLD") or bpy.data.worlds.new("H2SMV_WORLD") | |
| world.use_nodes = True | |
| nodes = world.node_tree.nodes | |
| nodes.clear() | |
| output = nodes.new("ShaderNodeOutputWorld") | |
| background = nodes.new("ShaderNodeBackground") | |
| mapping = nodes.new("ShaderNodeMapping") | |
| mapping.name = "H2SMV_MAPPING" | |
| background.inputs["Color"].default_value = (0.055, 0.065, 0.085, 1.0) | |
| background.inputs["Strength"].default_value = 0.8 | |
| world.node_tree.links.new(background.outputs["Background"], output.inputs["Surface"]) | |
| bpy.context.scene.world = world | |
| collection = bpy.data.collections.get(args.camera_collection) | |
| if collection is None: | |
| collection = bpy.data.collections.new(args.camera_collection) | |
| bpy.context.scene.collection.children.link(collection) | |
| presets = [ | |
| ("PORTRAIT_50MM", (0.0, -4.0, 1.25), 50.0), | |
| ("PORTRAIT_65MM", (0.35, -4.6, 1.35), 65.0), | |
| ("PORTRAIT_35MM", (-0.35, -3.6, 1.20), 35.0), | |
| ] | |
| for name, location, lens in presets: | |
| data = bpy.data.cameras.new(name) | |
| data.lens = lens | |
| data.sensor_width = 36.0 | |
| camera = bpy.data.objects.new(name, data) | |
| collection.objects.link(camera) | |
| camera.location = location | |
| point_camera(camera, mathutils.Vector((0.0, 0.0, 1.0))) | |
| bpy.context.scene.camera = bpy.data.objects[presets[0][0]] | |
| bpy.context.scene.render.engine = "BLENDER_EEVEE_NEXT" | |
| bpy.context.scene.render.resolution_x = 768 | |
| bpy.context.scene.render.resolution_y = 1024 | |
| bpy.context.scene.render.resolution_percentage = 100 | |
| args.out = args.out.expanduser().resolve() | |
| args.out.parent.mkdir(parents=True, exist_ok=True) | |
| bpy.ops.wm.save_as_mainfile(filepath=str(args.out)) | |
| print(f"[OK] Wrote asset-free H2SMV template: {args.out}") | |
| if __name__ == "__main__": | |
| main() | |