锥桶自定义更新

This commit is contained in:
cyy_mac
2026-06-16 22:45:15 +08:00
parent 0b41844e72
commit cf94fc566b
6 changed files with 201 additions and 26 deletions

22
main.py
View File

@@ -3,6 +3,7 @@ import json
import math
import os
import random
import tempfile
import threading
from collections import deque
from http.server import BaseHTTPRequestHandler, HTTPServer
@@ -151,7 +152,26 @@ def main():
with RenderApp() as render:
render.opt.set_left_panel_vis(True)
model = load_model("scene.xml")
# Load cone positions and inject into scene
with open("cones.json") as f:
cones = json.load(f)
cone_xml = ""
for i, c in enumerate(cones):
cone_xml += (
f'\n <body name="cone_{i}" pos="{c["x"]} {c["y"]} 0.0">\n'
f' <geom type="box" size="0.10 0.10 0.015" pos="0 0 0.015" class="cone_blue"/>\n'
f' <geom type="mesh" mesh="cone_mesh" pos="0 0 0.03" class="cone_blue"/>\n'
f' <geom type="mesh" mesh="cone_white_mesh" pos="0 0 0.15" rgba="1 1 1 1"/>\n'
f' </body>'
)
with open("scene.xml") as f:
xml = f.read()
xml = xml.replace("<!-- CONES -->", cone_xml)
tmp = tempfile.NamedTemporaryFile(suffix=".xml", delete=False, dir=".", mode="w")
tmp.write(xml)
tmp.close()
model = load_model(tmp.name)
os.unlink(tmp.name)
cameras = model.cameras
front_cam = cameras[0]