Spaces:
Paused
Paused
Upload code/cube3d/render/render_bricks_safe.py with huggingface_hub
Browse files
code/cube3d/render/render_bricks_safe.py
CHANGED
|
@@ -305,7 +305,7 @@ def _manual_import_importldraw(module_dir: Path):
|
|
| 305 |
try:
|
| 306 |
print("尝试导入ImportLDraw...")
|
| 307 |
import ImportLDraw
|
| 308 |
-
from ImportLDraw.loadldraw.loadldraw import FileSystem
|
| 309 |
print("ImportLDraw导入成功")
|
| 310 |
print(f"ImportLDraw文件位置: {{ImportLDraw.__file__}}")
|
| 311 |
except ImportError as import_error:
|
|
@@ -314,7 +314,7 @@ except ImportError as import_error:
|
|
| 314 |
try:
|
| 315 |
print("尝试手动加载 ImportLDraw...")
|
| 316 |
ImportLDraw = _manual_import_importldraw(IMPORT_LDRAW_MODULE_DIR)
|
| 317 |
-
from ImportLDraw.loadldraw.loadldraw import FileSystem
|
| 318 |
print("✅ 手动加载 ImportLDraw 成功")
|
| 319 |
except Exception as manual_error:
|
| 320 |
print(f"❌ 手动加载 ImportLDraw 失败: {{manual_error}}")
|
|
@@ -340,32 +340,51 @@ try:
|
|
| 340 |
for i, line in enumerate(content.split('\\n')[:5]):
|
| 341 |
print(f" {{i+1}}: {{line}}")
|
| 342 |
|
| 343 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 344 |
bpy.ops.object.select_all(action='DESELECT')
|
| 345 |
bpy.ops.object.select_by_type(type='MESH')
|
| 346 |
bpy.ops.object.delete()
|
| 347 |
print("场景清理完成")
|
| 348 |
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
print("使用 Blender operator 导入 LDR 文件...")
|
| 355 |
-
ldr_file_path = FileSystem.locate("{input_file}")
|
| 356 |
-
print(f"LDR 文件路径: {{ldr_file_path}}")
|
| 357 |
-
|
| 358 |
-
# 使用 Blender operator 导入(Blender 自动提供正确的 context)
|
| 359 |
-
try:
|
| 360 |
-
bpy.ops.import_scene.importldraw(
|
| 361 |
-
filepath=ldr_file_path,
|
| 362 |
-
ldrawPath="{ldraw_path}"
|
| 363 |
-
)
|
| 364 |
-
print("✅ LDR 文件导入成功")
|
| 365 |
-
except Exception as import_error:
|
| 366 |
-
print(f"❌ LDR 导入失败: {{import_error}}")
|
| 367 |
-
traceback.print_exc()
|
| 368 |
-
sys.exit(1)
|
| 369 |
|
| 370 |
# 检查加载的对象
|
| 371 |
mesh_objects = [obj for obj in bpy.data.objects if obj.type == 'MESH']
|
|
|
|
| 305 |
try:
|
| 306 |
print("尝试导入ImportLDraw...")
|
| 307 |
import ImportLDraw
|
| 308 |
+
from ImportLDraw.loadldraw.loadldraw import Options, Configure, loadFromFile, FileSystem
|
| 309 |
print("ImportLDraw导入成功")
|
| 310 |
print(f"ImportLDraw文件位置: {{ImportLDraw.__file__}}")
|
| 311 |
except ImportError as import_error:
|
|
|
|
| 314 |
try:
|
| 315 |
print("尝试手动加载 ImportLDraw...")
|
| 316 |
ImportLDraw = _manual_import_importldraw(IMPORT_LDRAW_MODULE_DIR)
|
| 317 |
+
from ImportLDraw.loadldraw.loadldraw import Options, Configure, loadFromFile, FileSystem
|
| 318 |
print("✅ 手动加载 ImportLDraw 成功")
|
| 319 |
except Exception as manual_error:
|
| 320 |
print(f"❌ 手动加载 ImportLDraw 失败: {{manual_error}}")
|
|
|
|
| 340 |
for i, line in enumerate(content.split('\\n')[:5]):
|
| 341 |
print(f" {{i+1}}: {{line}}")
|
| 342 |
|
| 343 |
+
# 设置 ImportLDraw 选项(demo.zip 原始实现)
|
| 344 |
+
print("设置 ImportLDraw Options...")
|
| 345 |
+
Options.ldrawDirectory = "{ldraw_path}"
|
| 346 |
+
Options.instructionsLook = {instructions_look_bool}
|
| 347 |
+
Options.useLogoStuds = True
|
| 348 |
+
Options.useUnofficialParts = True
|
| 349 |
+
Options.gaps = True
|
| 350 |
+
Options.studLogoDirectory = os.path.join(str(plugin_path), 'studs')
|
| 351 |
+
Options.LSynthDirectory = os.path.join(str(plugin_path), 'lsynth')
|
| 352 |
+
Options.verbose = 1
|
| 353 |
+
Options.overwriteExistingMaterials = True
|
| 354 |
+
Options.overwriteExistingMeshes = True
|
| 355 |
+
Options.scale = 0.01
|
| 356 |
+
Options.createInstances = True
|
| 357 |
+
Options.removeDoubles = True
|
| 358 |
+
Options.positionObjectOnGroundAtOrigin = True
|
| 359 |
+
Options.flattenHierarchy = False
|
| 360 |
+
Options.edgeSplit = True
|
| 361 |
+
Options.addBevelModifier = True
|
| 362 |
+
Options.bevelWidth = 0.5
|
| 363 |
+
Options.addEnvironmentTexture = True
|
| 364 |
+
Options.scriptDirectory = os.path.join(str(plugin_path), 'loadldraw')
|
| 365 |
+
Options.addWorldEnvironmentTexture = True
|
| 366 |
+
Options.addGroundPlane = True
|
| 367 |
+
Options.setRenderSettings = True
|
| 368 |
+
Options.removeDefaultObjects = True
|
| 369 |
+
Options.positionCamera = {reposition_camera_bool}
|
| 370 |
+
Options.cameraBorderPercent = 0.05
|
| 371 |
+
print("✅ Options 设置完成")
|
| 372 |
+
|
| 373 |
+
print("执行 Configure()...")
|
| 374 |
+
Configure()
|
| 375 |
+
print("✅ Configure 执行成功")
|
| 376 |
+
|
| 377 |
+
print("清理场景...")
|
| 378 |
bpy.ops.object.select_all(action='DESELECT')
|
| 379 |
bpy.ops.object.select_by_type(type='MESH')
|
| 380 |
bpy.ops.object.delete()
|
| 381 |
print("场景清理完成")
|
| 382 |
|
| 383 |
+
print("尝试加载 LDR 文件(使用 loadFromFile)...")
|
| 384 |
+
ldr_file = FileSystem.locate("{input_file}")
|
| 385 |
+
print(f"找到 LDR 文件: {{ldr_file}}")
|
| 386 |
+
loadFromFile(None, ldr_file)
|
| 387 |
+
print("✅ LDR 文件加载成功")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 388 |
|
| 389 |
# 检查加载的对象
|
| 390 |
mesh_objects = [obj for obj in bpy.data.objects if obj.type == 'MESH']
|