From f120e9e966c58a7d43ffa55a442363a47bc0bc16 Mon Sep 17 00:00:00 2001 From: weiweiliang Date: Thu, 29 May 2025 21:08:21 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E7=AE=AD=E5=A4=B4=E9=95=BF?= =?UTF-8?q?=E5=BA=A6=E6=98=BE=E7=A4=BA=EF=BC=9A=E5=A2=9E=E5=8A=A0=E5=9F=BA?= =?UTF-8?q?=E5=87=86=E9=95=BF=E5=BA=A6=E5=88=B015%=EF=BC=8C=E8=8C=83?= =?UTF-8?q?=E5=9B=B48%-20%=EF=BC=8C=E6=8F=90=E5=8D=87=E5=8F=AF=E8=A7=86?= =?UTF-8?q?=E5=8C=96=E6=95=88=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- comfyui_vggt_nodes.py | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/comfyui_vggt_nodes.py b/comfyui_vggt_nodes.py index 9c97301..7d616e3 100644 --- a/comfyui_vggt_nodes.py +++ b/comfyui_vggt_nodes.py @@ -148,16 +148,24 @@ def _create_traj_preview(extrinsic: torch.Tensor) -> torch.Tensor: position_range = positions.max(axis=0) - positions.min(axis=0) scene_scale = np.linalg.norm(position_range) - # 避免除零,设置最小场景尺度 + # 更明显的箭头长度计算,确保箭头清晰可见 if scene_scale < 1e-6: - direction_length = 0.5 + direction_length = 0.5 # 极小场景使用更大的默认长度 else: - direction_length = max(0.3, scene_scale * 0.08) + # 使用更明显的比例:8%~20% + direction_length = scene_scale * 0.15 # 基准 15% + min_len = scene_scale * 0.08 # 最小8% + max_len = scene_scale * 0.20 # 最大20% + direction_length = max(min_len, min(direction_length, max_len)) + + # 进一步限制最大长度,避免箭头过长 + absolute_max_length = scene_scale * 0.4 # 绝对不超过场景尺度的40% + direction_length = min(direction_length, absolute_max_length) # 绘制箭头,确保索引不越界 arrow_count = 0 for i in range(0, len(positions), step): - if i < len(orientations) and arrow_count < 15: # 最多15个箭头 + if i < len(orientations) and arrow_count < 12: # 减少到最多12个箭头 pos = positions[i] direction = orientations[i] @@ -167,9 +175,20 @@ def _create_traj_preview(extrinsic: torch.Tensor) -> torch.Tensor: direction = direction / direction_norm direction_scaled = direction * direction_length + # 检查箭头终点是否会超出场景边界 + arrow_end = pos + direction_scaled + scene_min = positions.min(axis=0) + scene_max = positions.max(axis=0) + + # 如果箭头会超出边界,进一步缩短 + for axis in range(3): + if arrow_end[axis] < scene_min[axis] or arrow_end[axis] > scene_max[axis]: + direction_scaled *= 0.7 # 缩短30% + break + ax.quiver(pos[0], pos[1], pos[2], direction_scaled[0], direction_scaled[1], direction_scaled[2], - color='orange', alpha=0.7, arrow_length_ratio=0.15) + color='orange', alpha=0.8, arrow_length_ratio=0.2, linewidth=1.5) arrow_count += 1 # 设置坐标轴