0xZohar commited on
Commit
25d2ec9
·
verified ·
1 Parent(s): d91502d

Upload code/cube3d/render/render_bricks_safe.py with huggingface_hub

Browse files
code/cube3d/render/render_bricks_safe.py CHANGED
@@ -286,13 +286,37 @@ except Exception as e:
286
  print(f"已生成占位图片: {out_file}")
287
  return
288
 
289
- cmd = [
290
- BLENDER_PATH, '--background', #'--factory-startup',
291
- '--python', script_path, #'--enable-autoexec'
292
- ]
293
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
294
  print(f"执行命令: {' '.join(cmd)}")
295
-
 
 
296
  result = subprocess.run(
297
  cmd,
298
  stdout=subprocess.PIPE,
@@ -300,15 +324,20 @@ except Exception as e:
300
  text=True,
301
  timeout=300
302
  )
303
-
304
  # 输出Blender日志
 
305
  if result.stdout:
306
  print("=== Blender标准输出 ===")
307
  print(result.stdout)
308
-
 
 
309
  if result.stderr:
310
  print("=== Blender错误输出 ===")
311
  print(result.stderr)
 
 
312
 
313
  if result.returncode != 0:
314
  raise RuntimeError(f"Blender返回错误码: {result.returncode}")
 
286
  print(f"已生成占位图片: {out_file}")
287
  return
288
 
289
+ # 首先测试 Blender 是否能正常运行
290
+ test_cmd = [BLENDER_PATH, '--version']
291
+ print(f"测试Blender: {' '.join(test_cmd)}")
292
+ try:
293
+ test_result = subprocess.run(test_cmd, capture_output=True, text=True, timeout=10)
294
+ print(f"Blender测试返回码: {test_result.returncode}")
295
+ if test_result.stdout:
296
+ print(f"Blender版本信息: {test_result.stdout.strip()}")
297
+ if test_result.stderr:
298
+ print(f"Blender测试错误: {test_result.stderr.strip()}")
299
+ except Exception as test_e:
300
+ print(f"Blender测试失败: {test_e}")
301
+
302
+ # 在 Linux 上使用 xvfb-run 以支持无头渲染
303
+ if platform.system() == 'Linux' and os.path.exists('/usr/bin/xvfb-run'):
304
+ cmd = [
305
+ 'xvfb-run', '-a', '-s', '-screen 0 1024x768x24',
306
+ BLENDER_PATH, '--background',
307
+ '--python', script_path
308
+ ]
309
+ print("使用 xvfb-run 进行无头渲染")
310
+ else:
311
+ cmd = [
312
+ BLENDER_PATH, '--background',
313
+ '--python', script_path
314
+ ]
315
+
316
  print(f"执行命令: {' '.join(cmd)}")
317
+ print(f"脚本路径: {script_path}")
318
+ print(f"脚本是否存在: {os.path.exists(script_path)}")
319
+
320
  result = subprocess.run(
321
  cmd,
322
  stdout=subprocess.PIPE,
 
324
  text=True,
325
  timeout=300
326
  )
327
+
328
  # 输出Blender日志
329
+ print(f"=== Blender返回码: {result.returncode} ===")
330
  if result.stdout:
331
  print("=== Blender标准输出 ===")
332
  print(result.stdout)
333
+ else:
334
+ print("(无标准输出)")
335
+
336
  if result.stderr:
337
  print("=== Blender错误输出 ===")
338
  print(result.stderr)
339
+ else:
340
+ print("(无错误输出)")
341
 
342
  if result.returncode != 0:
343
  raise RuntimeError(f"Blender返回错误码: {result.returncode}")