Spaces:
Running
Running
Fix 3D garment visualization: anatomically correct body, proper garment positioning and scaling
Browse files- 17-landmark shaped body (not a simple cylinder)
- Garment radii derived from circumference/(2*pi) (not raw measurement*body_radius)
- Shirt/dress torso at Z=89-145 (chest area, not starting from feet)
- Sleeves as tilted tubes from shoulder outward/downward
- Pants legs offset from center (cx=±hip_rx*0.45)
- Skirt flares from waist downward
- Collar at neck height (Z=148-156)
- Fabric-like Plotly lighting (high ambient, low specular)
- aspectmode="data" prevents distortion
- garment_3d.py +523 -227
garment_3d.py
CHANGED
|
@@ -1,278 +1,574 @@
|
|
| 1 |
"""
|
| 2 |
-
3D Garment Visualizer
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
"""
|
| 5 |
import numpy as np
|
| 6 |
import plotly.graph_objects as go
|
| 7 |
-
from typing import Dict
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
return X, Y, Z
|
| 40 |
|
| 41 |
-
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
bust = params.get("bust", 92)
|
| 44 |
waist = params.get("waist", 74)
|
| 45 |
-
hip = params.get("hip", 96)
|
| 46 |
shoulder = params.get("shoulder_width", 42)
|
| 47 |
-
|
| 48 |
sleeve_len = params.get("sleeve_length", 60)
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
flare = params.get("flare", 0)
|
| 52 |
fit = params.get("fit", "regular")
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
surfaces = []
|
| 57 |
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
if t < 0.25:
|
| 66 |
-
|
|
|
|
| 67 |
elif t < 0.55:
|
| 68 |
-
f = (t-0.25)/0.
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
else:
|
| 76 |
-
f = (t-0.
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
for side in [1, -1]:
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
t = z_sl[j] / sleeve_len
|
| 95 |
-
R_s[j,:] = bicep_r * (1-t) + wrist_r * t + ease*0.5
|
| 96 |
-
sx_center = side * (shoulder*0.85 + ease*0.3)
|
| 97 |
-
sy_center = 0
|
| 98 |
-
sz_top = body_len * 0.92
|
| 99 |
-
X_s = sx_center + R_s * np.cos(Theta_s) * 0.7 + side * np.linspace(0, sleeve_len*0.15, n_sl).reshape(-1,1)
|
| 100 |
-
Y_s = sy_center + R_s * np.sin(Theta_s) * 0.5 + np.linspace(0, -sleeve_len*0.4, n_sl).reshape(-1,1)
|
| 101 |
-
Z_s = sz_top - Z_s * 0.3
|
| 102 |
-
color = "#6BB3E0" if side > 0 else "#4A90D9"
|
| 103 |
-
surfaces.append((X_s, Y_s, Z_s, color, "Sleeve", 0.65))
|
| 104 |
-
|
| 105 |
-
# Collar
|
| 106 |
if params.get("has_collar", False):
|
| 107 |
collar_h = params.get("collar_height", 4)
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
Z_c = Z_c + body_len - 2
|
| 118 |
-
surfaces.append((X_c, Y_c, Z_c, "#FFFFFF", "Collar", 0.9))
|
| 119 |
|
| 120 |
return surfaces
|
| 121 |
-
|
| 122 |
-
|
|
|
|
|
|
|
| 123 |
waist = params.get("waist", 74)
|
| 124 |
hip = params.get("hip", 96)
|
| 125 |
thigh = params.get("thigh", 56)
|
| 126 |
ankle = params.get("ankle", 24)
|
| 127 |
pant_len = params.get("pant_length", 100)
|
| 128 |
-
crotch = params.get("crotch_depth", 27)
|
| 129 |
fit = params.get("fit", "regular")
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
surfaces = []
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
return surfaces
|
| 169 |
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
|
|
|
| 173 |
hip = params.get("hip", 96)
|
| 174 |
skirt_len = params.get("skirt_length", 55)
|
| 175 |
flare = params.get("flare", 5)
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 185 |
if t < 0.3:
|
| 186 |
f = t / 0.3
|
| 187 |
-
|
|
|
|
| 188 |
else:
|
| 189 |
-
f = (t-0.3)/0.7
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 215 |
else:
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 223 |
return surfaces
|
| 224 |
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
"
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 237 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 238 |
def create_3d_figure(analysis: Dict) -> go.Figure:
|
| 239 |
-
"""Create interactive 3D garment visualization
|
| 240 |
garment_type = analysis.get("garment_type", "shirt").lower()
|
| 241 |
measurements = analysis.get("measurements", {})
|
| 242 |
features = analysis.get("features", {})
|
| 243 |
params = {**measurements, **features}
|
| 244 |
-
|
| 245 |
-
waist_m = params.get("waist", 74)
|
| 246 |
-
hip_m = params.get("hip", 96)
|
| 247 |
fig = go.Figure()
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
fig.add_trace(
|
| 251 |
-
|
| 252 |
-
surfacecolor=np.ones_like(BX) * 0.8,
|
| 253 |
-
colorscale=[[0,"#E8D0B0"],[1,"#E8D0B0"]],
|
| 254 |
-
opacity=0.25, showscale=False, name="Body",
|
| 255 |
-
hoverinfo="skip", lighting=dict(ambient=0.9, diffuse=0.1, specular=0)))
|
| 256 |
# Garment surfaces
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
for
|
| 260 |
-
fig.add_trace(
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
colorscale=[[0, color], [1, color]],
|
| 264 |
-
opacity=opacity, showscale=False, name=name,
|
| 265 |
-
hoverinfo="name",
|
| 266 |
-
lighting=dict(ambient=0.6, diffuse=0.4, specular=0.2, roughness=0.5)))
|
| 267 |
fig.update_layout(
|
| 268 |
scene=dict(
|
| 269 |
-
xaxis=dict(showgrid=False, showticklabels=False, title="",
|
| 270 |
-
|
| 271 |
-
|
|
|
|
|
|
|
|
|
|
| 272 |
aspectmode="data",
|
| 273 |
-
camera=dict(
|
| 274 |
-
|
| 275 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 276 |
title=dict(text=f"3D Preview: {garment_type.title()}", font=dict(size=14)),
|
| 277 |
-
paper_bgcolor="#fafafa"
|
| 278 |
-
|
|
|
|
|
|
|
|
|
| 1 |
"""
|
| 2 |
+
3D Garment Visualizer — Anatomically Correct Mannequin + Garment Surfaces
|
| 3 |
+
|
| 4 |
+
Creates realistic 3D garment previews on a shaped parametric body using Plotly.
|
| 5 |
+
Uses two core primitives:
|
| 6 |
+
1. Revolution surfaces (body, torso, skirt, collar, waistband)
|
| 7 |
+
2. Tilted tubes (sleeves)
|
| 8 |
+
|
| 9 |
+
All Z values are in cm, Z=0 at floor, Z=170 at head top.
|
| 10 |
+
Garment radii are derived from circumference measurements:
|
| 11 |
+
radius = circumference / (2*pi) (for circular cross-section)
|
| 12 |
+
For elliptical: rx = circ / (2*pi) * 1.1, ry = circ / (2*pi) * 0.9
|
| 13 |
"""
|
| 14 |
import numpy as np
|
| 15 |
import plotly.graph_objects as go
|
| 16 |
+
from typing import Dict, List, Tuple
|
| 17 |
+
|
| 18 |
+
TWO_PI = 2 * np.pi
|
| 19 |
+
|
| 20 |
+
# ── Anatomical body profile (female mannequin, 170 cm) ─────────────────────
|
| 21 |
+
# 17 landmarks from feet to head (all radii in cm)
|
| 22 |
+
_BODY_Z = [0, 7, 30, 45, 65, 88, 100, 104, 112, 120, 132, 140, 145, 150, 158, 162, 170]
|
| 23 |
+
_BODY_RX = [4.0, 3.0, 4.5, 4.0, 6.5, 9.5, 8.0, 7.0, 8.5, 10.0, 9.0, 8.5, 11.5, 3.5, 3.0, 5.5, 4.5]
|
| 24 |
+
_BODY_RY = [3.0, 2.5, 4.0, 4.0, 6.0, 8.5, 7.5, 6.5, 8.0, 9.0, 8.0, 7.5, 8.0, 3.5, 3.0, 5.0, 4.5]
|
| 25 |
+
|
| 26 |
+
# Key anatomical Z heights (cm from floor)
|
| 27 |
+
Z_FLOOR = 0
|
| 28 |
+
Z_ANKLE = 7
|
| 29 |
+
Z_KNEE = 45
|
| 30 |
+
Z_HIP = 88
|
| 31 |
+
Z_WAIST = 104
|
| 32 |
+
Z_BUST = 120
|
| 33 |
+
Z_SHOULDER = 145
|
| 34 |
+
Z_NECK_BASE = 150
|
| 35 |
+
Z_HEAD_TOP = 170
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
# ── Helpers: circumference → elliptical radii ──────────────────────────────
|
| 39 |
+
def _circ_to_rx(circ):
|
| 40 |
+
"""Convert circumference to X-radius (wider front-back)."""
|
| 41 |
+
return circ / TWO_PI * 1.10
|
| 42 |
+
|
| 43 |
+
def _circ_to_ry(circ):
|
| 44 |
+
"""Convert circumference to Y-radius (narrower side-side)."""
|
| 45 |
+
return circ / TWO_PI * 0.90
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
# ── Primitive 1: Revolution surface ─────────────────────────────────────────
|
| 49 |
+
def _revolution_surface(z_heights, rx_vals, ry_vals,
|
| 50 |
+
n_theta=36, cx=0.0, cy=0.0):
|
| 51 |
+
"""Surface of revolution with elliptical cross-sections."""
|
| 52 |
+
theta = np.linspace(0, 2 * np.pi, n_theta)
|
| 53 |
+
z_arr = np.asarray(z_heights, float)
|
| 54 |
+
rx = np.asarray(rx_vals, float)
|
| 55 |
+
ry = np.asarray(ry_vals, float)
|
| 56 |
+
Z = np.outer(z_arr, np.ones(n_theta))
|
| 57 |
+
X = cx + np.outer(rx, np.cos(theta))
|
| 58 |
+
Y = cy + np.outer(ry, np.sin(theta))
|
| 59 |
+
return X, Y, Z
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
# ── Primitive 2: Tilted tube (for sleeves) ──────────────────────────────────
|
| 63 |
+
def _tilted_tube(start, end, r_start, r_end, n_theta=24, n_z=12):
|
| 64 |
+
"""Tapered tube between two 3D points."""
|
| 65 |
+
s = np.array(start, float)
|
| 66 |
+
e = np.array(end, float)
|
| 67 |
+
axis = e - s
|
| 68 |
+
length = np.linalg.norm(axis)
|
| 69 |
+
if length < 0.01:
|
| 70 |
+
return np.zeros((n_z, n_theta)), np.zeros((n_z, n_theta)), np.zeros((n_z, n_theta))
|
| 71 |
+
|
| 72 |
+
axis_n = axis / length
|
| 73 |
+
ref = np.array([0., 0., 1.]) if abs(axis_n[2]) < 0.9 else np.array([1., 0., 0.])
|
| 74 |
+
right = np.cross(axis_n, ref)
|
| 75 |
+
right /= np.linalg.norm(right)
|
| 76 |
+
up = np.cross(right, axis_n)
|
| 77 |
+
|
| 78 |
+
theta = np.linspace(0, 2 * np.pi, n_theta)
|
| 79 |
+
t_vals = np.linspace(0, 1, n_z)
|
| 80 |
+
|
| 81 |
+
X = np.zeros((n_z, n_theta))
|
| 82 |
+
Y = np.zeros((n_z, n_theta))
|
| 83 |
+
Z = np.zeros((n_z, n_theta))
|
| 84 |
+
|
| 85 |
+
for i, t in enumerate(t_vals):
|
| 86 |
+
center = s + t * axis
|
| 87 |
+
r = r_start + t * (r_end - r_start)
|
| 88 |
+
for j, th in enumerate(theta):
|
| 89 |
+
offset = r * (np.cos(th) * right + np.sin(th) * up)
|
| 90 |
+
X[i, j] = center[0] + offset[0]
|
| 91 |
+
Y[i, j] = center[1] + offset[1]
|
| 92 |
+
Z[i, j] = center[2] + offset[2]
|
| 93 |
+
|
| 94 |
return X, Y, Z
|
| 95 |
|
| 96 |
+
|
| 97 |
+
# ── Surface helper ──────────────────────────────────────────────────────────
|
| 98 |
+
def _make_surface(X, Y, Z, color, name, opacity=0.88, lighting=None):
|
| 99 |
+
"""Create a Plotly Surface trace with fabric-like shading."""
|
| 100 |
+
if lighting is None:
|
| 101 |
+
lighting = dict(ambient=0.65, diffuse=0.85, specular=0.15, roughness=0.8)
|
| 102 |
+
return go.Surface(
|
| 103 |
+
x=X, y=Y, z=Z,
|
| 104 |
+
surfacecolor=np.ones_like(X),
|
| 105 |
+
colorscale=[[0, color], [1, color]],
|
| 106 |
+
opacity=opacity,
|
| 107 |
+
showscale=False,
|
| 108 |
+
name=name,
|
| 109 |
+
hoverinfo="name",
|
| 110 |
+
lighting=lighting,
|
| 111 |
+
lightposition=dict(x=100, y=200, z=300),
|
| 112 |
+
)
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
# ── Body mannequin ──────────────────────────────────────────────────────────
|
| 116 |
+
def _make_body():
|
| 117 |
+
"""Create the translucent mannequin body."""
|
| 118 |
+
X, Y, Z = _revolution_surface(_BODY_Z, _BODY_RX, _BODY_RY, n_theta=48)
|
| 119 |
+
return go.Surface(
|
| 120 |
+
x=X, y=Y, z=Z,
|
| 121 |
+
surfacecolor=np.ones_like(X) * 0.8,
|
| 122 |
+
colorscale=[[0, "#E8D0B0"], [1, "#E8D0B0"]],
|
| 123 |
+
opacity=0.20,
|
| 124 |
+
showscale=False,
|
| 125 |
+
name="Body",
|
| 126 |
+
hoverinfo="skip",
|
| 127 |
+
lighting=dict(ambient=0.9, diffuse=0.1, specular=0, roughness=1.0),
|
| 128 |
+
)
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
# ── Helper: interpolate body radius at arbitrary Z ──────────────────────────
|
| 132 |
+
def _body_rx(z_val):
|
| 133 |
+
return float(np.interp(z_val, _BODY_Z, _BODY_RX))
|
| 134 |
+
|
| 135 |
+
def _body_ry(z_val):
|
| 136 |
+
return float(np.interp(z_val, _BODY_Z, _BODY_RY))
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
# ── Garment builders ────────────────────────────────────────────────────────
|
| 140 |
+
|
| 141 |
+
def _build_shirt(params, color="#4A90D9"):
|
| 142 |
+
"""Build shirt/blouse/top/t-shirt surfaces."""
|
| 143 |
bust = params.get("bust", 92)
|
| 144 |
waist = params.get("waist", 74)
|
|
|
|
| 145 |
shoulder = params.get("shoulder_width", 42)
|
| 146 |
+
bodice_len = params.get("bodice_length", 72)
|
| 147 |
sleeve_len = params.get("sleeve_length", 60)
|
| 148 |
+
bicep = params.get("bicep", 30)
|
| 149 |
+
wrist_circ = params.get("wrist", 18)
|
|
|
|
| 150 |
fit = params.get("fit", "regular")
|
| 151 |
+
flare = params.get("flare", 0)
|
| 152 |
+
|
| 153 |
+
ease = {"fitted": 0.5, "regular": 1.2, "oversized": 3.0, "loose": 2.2}.get(fit, 1.2)
|
| 154 |
+
|
| 155 |
+
bust_rx = _circ_to_rx(bust) + ease
|
| 156 |
+
bust_ry = _circ_to_ry(bust) + ease
|
| 157 |
+
waist_rx = _circ_to_rx(waist) + ease
|
| 158 |
+
waist_ry = _circ_to_ry(waist) + ease
|
| 159 |
+
shoulder_rx = shoulder / 2
|
| 160 |
+
|
| 161 |
surfaces = []
|
| 162 |
|
| 163 |
+
extra_length = max(0, bodice_len - 42) * 0.5
|
| 164 |
+
hem_z = max(Z_WAIST - extra_length, Z_HIP - 5)
|
| 165 |
+
|
| 166 |
+
n_torso = 16
|
| 167 |
+
torso_z = np.linspace(hem_z, Z_SHOULDER, n_torso)
|
| 168 |
+
torso_rx_arr = []
|
| 169 |
+
torso_ry_arr = []
|
| 170 |
+
|
| 171 |
+
for z in torso_z:
|
| 172 |
+
t = (z - hem_z) / (Z_SHOULDER - hem_z)
|
| 173 |
+
|
| 174 |
if t < 0.25:
|
| 175 |
+
rx = waist_rx + flare * (0.25 - t) / 0.25
|
| 176 |
+
ry = waist_ry + flare * 0.8 * (0.25 - t) / 0.25
|
| 177 |
elif t < 0.55:
|
| 178 |
+
f = (t - 0.25) / 0.30
|
| 179 |
+
rx = waist_rx + (bust_rx - waist_rx) * f
|
| 180 |
+
ry = waist_ry + (bust_ry - waist_ry) * f
|
| 181 |
+
elif t < 0.8:
|
| 182 |
+
f = (t - 0.55) / 0.25
|
| 183 |
+
rx = bust_rx + (bust_rx * 0.92 - bust_rx) * f
|
| 184 |
+
ry = bust_ry + (bust_ry * 0.92 - bust_ry) * f
|
| 185 |
else:
|
| 186 |
+
f = (t - 0.8) / 0.2
|
| 187 |
+
rx = bust_rx * 0.92 + (shoulder_rx - bust_rx * 0.92) * f
|
| 188 |
+
ry = bust_ry * 0.92 * (1 - 0.15 * f)
|
| 189 |
+
|
| 190 |
+
rx = max(rx, _body_rx(z) + 0.8)
|
| 191 |
+
ry = max(ry, _body_ry(z) + 0.8)
|
| 192 |
+
torso_rx_arr.append(rx)
|
| 193 |
+
torso_ry_arr.append(ry)
|
| 194 |
+
|
| 195 |
+
X, Y, Zt = _revolution_surface(torso_z, torso_rx_arr, torso_ry_arr, n_theta=36)
|
| 196 |
+
surfaces.append(_make_surface(X, Y, Zt, color, "Torso", opacity=0.85))
|
| 197 |
+
|
| 198 |
+
shoulder_attach_rx = torso_rx_arr[-1]
|
| 199 |
+
shoulder_attach_z = Z_SHOULDER - 3
|
| 200 |
+
|
| 201 |
+
sleeve_drop = sleeve_len * 0.45
|
| 202 |
+
sleeve_spread = sleeve_len * 0.30
|
| 203 |
+
|
| 204 |
+
r_bicep = bicep / TWO_PI + ease * 0.4
|
| 205 |
+
r_wrist = wrist_circ / TWO_PI + ease * 0.3
|
| 206 |
+
|
| 207 |
for side in [1, -1]:
|
| 208 |
+
start = (side * shoulder_attach_rx, 0, shoulder_attach_z)
|
| 209 |
+
end = (side * (shoulder_attach_rx + sleeve_spread), 0,
|
| 210 |
+
shoulder_attach_z - sleeve_drop)
|
| 211 |
+
Xs, Ys, Zs = _tilted_tube(start, end, r_bicep, r_wrist, n_theta=20, n_z=14)
|
| 212 |
+
sleeve_color = _lighten_color(color, 0.08) if side > 0 else _darken_color(color, 0.08)
|
| 213 |
+
surfaces.append(_make_surface(Xs, Ys, Zs, sleeve_color, "Sleeve", opacity=0.80))
|
| 214 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 215 |
if params.get("has_collar", False):
|
| 216 |
collar_h = params.get("collar_height", 4)
|
| 217 |
+
n_c = 6
|
| 218 |
+
collar_z = np.linspace(Z_NECK_BASE - 2, Z_NECK_BASE + collar_h, n_c)
|
| 219 |
+
collar_rx = []
|
| 220 |
+
collar_ry = []
|
| 221 |
+
for z in collar_z:
|
| 222 |
+
collar_rx.append(_body_rx(z) + 1.5)
|
| 223 |
+
collar_ry.append(_body_ry(z) + 1.5)
|
| 224 |
+
Xc, Yc, Zc = _revolution_surface(collar_z, collar_rx, collar_ry, n_theta=28)
|
| 225 |
+
surfaces.append(_make_surface(Xc, Yc, Zc, "#FFFFFF", "Collar", opacity=0.92))
|
|
|
|
|
|
|
| 226 |
|
| 227 |
return surfaces
|
| 228 |
+
|
| 229 |
+
|
| 230 |
+
def _build_pants(params, color="#2C5F8A"):
|
| 231 |
+
"""Build pants/trousers/jeans surfaces."""
|
| 232 |
waist = params.get("waist", 74)
|
| 233 |
hip = params.get("hip", 96)
|
| 234 |
thigh = params.get("thigh", 56)
|
| 235 |
ankle = params.get("ankle", 24)
|
| 236 |
pant_len = params.get("pant_length", 100)
|
|
|
|
| 237 |
fit = params.get("fit", "regular")
|
| 238 |
+
flare = params.get("flare", 0)
|
| 239 |
+
|
| 240 |
+
ease = {"fitted": 0.5, "regular": 1.0, "oversized": 2.5, "loose": 2.0}.get(fit, 1.0)
|
| 241 |
+
|
| 242 |
surfaces = []
|
| 243 |
+
|
| 244 |
+
hip_rx = _circ_to_rx(hip) + ease
|
| 245 |
+
hip_ry = _circ_to_ry(hip) + ease
|
| 246 |
+
waist_rx = _circ_to_rx(waist) + ease
|
| 247 |
+
waist_ry = _circ_to_ry(waist) + ease
|
| 248 |
+
|
| 249 |
+
n_wb = 8
|
| 250 |
+
wb_z = np.linspace(Z_HIP, Z_WAIST, n_wb)
|
| 251 |
+
wb_rx_arr = []
|
| 252 |
+
wb_ry_arr = []
|
| 253 |
+
for z in wb_z:
|
| 254 |
+
t = (z - Z_HIP) / (Z_WAIST - Z_HIP)
|
| 255 |
+
rx = hip_rx + (waist_rx - hip_rx) * t
|
| 256 |
+
ry = hip_ry + (waist_ry - hip_ry) * t
|
| 257 |
+
rx = max(rx, _body_rx(z) + 0.8)
|
| 258 |
+
ry = max(ry, _body_ry(z) + 0.8)
|
| 259 |
+
wb_rx_arr.append(rx)
|
| 260 |
+
wb_ry_arr.append(ry)
|
| 261 |
+
|
| 262 |
+
Xw, Yw, Zw = _revolution_surface(wb_z, wb_rx_arr, wb_ry_arr, n_theta=36)
|
| 263 |
+
surfaces.append(_make_surface(Xw, Yw, Zw, _darken_color(color, 0.12), "Waistband", opacity=0.90))
|
| 264 |
+
|
| 265 |
+
hem_z = max(Z_HIP - pant_len * 0.85, Z_ANKLE - 5)
|
| 266 |
+
hem_z = max(hem_z, 2)
|
| 267 |
+
|
| 268 |
+
leg_cx = hip_rx * 0.45
|
| 269 |
+
|
| 270 |
+
r_thigh = thigh / TWO_PI + ease
|
| 271 |
+
r_ankle = ankle / TWO_PI + ease + flare * 0.15
|
| 272 |
+
|
| 273 |
+
n_leg = 18
|
| 274 |
+
leg_z = np.linspace(Z_HIP, hem_z, n_leg)
|
| 275 |
+
|
| 276 |
+
for side_idx, side in enumerate([1, -1]):
|
| 277 |
+
leg_rx = []
|
| 278 |
+
leg_ry = []
|
| 279 |
+
for i, z in enumerate(leg_z):
|
| 280 |
+
t = i / (n_leg - 1)
|
| 281 |
+
rx = r_thigh + (r_ankle - r_thigh) * t
|
| 282 |
+
ry = rx * 0.85
|
| 283 |
+
leg_rx.append(rx)
|
| 284 |
+
leg_ry.append(ry)
|
| 285 |
+
|
| 286 |
+
cx = side * leg_cx
|
| 287 |
+
Xl, Yl, Zl = _revolution_surface(leg_z, leg_rx, leg_ry, n_theta=28, cx=cx)
|
| 288 |
+
leg_color = color if side_idx == 0 else _lighten_color(color, 0.06)
|
| 289 |
+
surfaces.append(_make_surface(Xl, Yl, Zl, leg_color, "Leg", opacity=0.85))
|
| 290 |
+
|
| 291 |
return surfaces
|
| 292 |
|
| 293 |
+
|
| 294 |
+
def _build_skirt(params, color="#C48BB8"):
|
| 295 |
+
"""Build skirt surfaces."""
|
| 296 |
+
waist = params.get("waist", 72)
|
| 297 |
hip = params.get("hip", 96)
|
| 298 |
skirt_len = params.get("skirt_length", 55)
|
| 299 |
flare = params.get("flare", 5)
|
| 300 |
+
fit = params.get("fit", "regular")
|
| 301 |
+
|
| 302 |
+
ease = {"fitted": 0.5, "regular": 1.0, "oversized": 2.5, "loose": 2.0}.get(fit, 1.0)
|
| 303 |
+
|
| 304 |
+
surfaces = []
|
| 305 |
+
|
| 306 |
+
hem_z = max(Z_WAIST - skirt_len, Z_ANKLE - 5)
|
| 307 |
+
hem_z = max(hem_z, 2)
|
| 308 |
+
|
| 309 |
+
waist_rx = _circ_to_rx(waist) + ease
|
| 310 |
+
waist_ry = _circ_to_ry(waist) + ease
|
| 311 |
+
hip_rx = _circ_to_rx(hip) + ease
|
| 312 |
+
hip_ry = _circ_to_ry(hip) + ease
|
| 313 |
+
|
| 314 |
+
n_sk = 16
|
| 315 |
+
skirt_z = np.linspace(Z_WAIST, hem_z, n_sk)
|
| 316 |
+
skirt_rx = []
|
| 317 |
+
skirt_ry = []
|
| 318 |
+
|
| 319 |
+
for i, z in enumerate(skirt_z):
|
| 320 |
+
t = i / (n_sk - 1)
|
| 321 |
if t < 0.3:
|
| 322 |
f = t / 0.3
|
| 323 |
+
rx = waist_rx + (hip_rx - waist_rx) * f
|
| 324 |
+
ry = waist_ry + (hip_ry - waist_ry) * f
|
| 325 |
else:
|
| 326 |
+
f = (t - 0.3) / 0.7
|
| 327 |
+
rx = hip_rx + flare * f
|
| 328 |
+
ry = hip_ry + flare * 0.85 * f
|
| 329 |
+
|
| 330 |
+
rx = max(rx, _body_rx(z) + 1.0)
|
| 331 |
+
ry = max(ry, _body_ry(z) + 1.0)
|
| 332 |
+
skirt_rx.append(rx)
|
| 333 |
+
skirt_ry.append(ry)
|
| 334 |
+
|
| 335 |
+
Xs, Ys, Zs = _revolution_surface(skirt_z, skirt_rx, skirt_ry, n_theta=36)
|
| 336 |
+
surfaces.append(_make_surface(Xs, Ys, Zs, color, "Skirt", opacity=0.82))
|
| 337 |
+
|
| 338 |
+
n_wb = 4
|
| 339 |
+
wb_height = params.get("waistband_height", 4)
|
| 340 |
+
wb_z = np.linspace(Z_WAIST, Z_WAIST + wb_height, n_wb)
|
| 341 |
+
wb_rx = [waist_rx + 0.3] * n_wb
|
| 342 |
+
wb_ry = [waist_ry + 0.3] * n_wb
|
| 343 |
+
Xwb, Ywb, Zwb = _revolution_surface(wb_z, wb_rx, wb_ry, n_theta=36)
|
| 344 |
+
surfaces.append(_make_surface(Xwb, Ywb, Zwb, _darken_color(color, 0.15), "Waistband", opacity=0.92))
|
| 345 |
+
|
| 346 |
+
return surfaces
|
| 347 |
+
|
| 348 |
+
|
| 349 |
+
def _build_dress(params, color="#8E44AD"):
|
| 350 |
+
"""Build dress = bodice top + skirt bottom."""
|
| 351 |
+
surfaces = []
|
| 352 |
+
bodice_params = dict(params)
|
| 353 |
+
bodice_params["bodice_length"] = params.get("bodice_length", 42)
|
| 354 |
+
surfaces.extend(_build_shirt(bodice_params, color=color))
|
| 355 |
+
|
| 356 |
+
skirt_params = dict(params)
|
| 357 |
+
skirt_params["skirt_length"] = params.get("skirt_length", 55)
|
| 358 |
+
surfaces.extend(_build_skirt(skirt_params, color=_lighten_color(color, 0.05)))
|
| 359 |
+
|
| 360 |
+
return surfaces
|
| 361 |
+
|
| 362 |
+
|
| 363 |
+
def _build_hoodie(params, color="#27AE60"):
|
| 364 |
+
"""Build hoodie = shirt + hood."""
|
| 365 |
+
surfaces = _build_shirt(params, color=color)
|
| 366 |
+
|
| 367 |
+
n_hood = 10
|
| 368 |
+
hood_z = np.linspace(Z_SHOULDER, Z_HEAD_TOP + 2, n_hood)
|
| 369 |
+
hood_rx = []
|
| 370 |
+
hood_ry = []
|
| 371 |
+
|
| 372 |
+
for i, z in enumerate(hood_z):
|
| 373 |
+
t = i / (n_hood - 1)
|
| 374 |
+
if t < 0.2:
|
| 375 |
+
rx = _body_rx(Z_SHOULDER) + 2.5
|
| 376 |
+
elif t < 0.6:
|
| 377 |
+
f = (t - 0.2) / 0.4
|
| 378 |
+
rx = _body_rx(min(z, Z_HEAD_TOP)) + 3.0 + 2.0 * np.sin(f * np.pi)
|
| 379 |
+
else:
|
| 380 |
+
f = (t - 0.6) / 0.4
|
| 381 |
+
rx = _body_rx(min(z, Z_HEAD_TOP)) + 3.0 * (1 - f * 0.6)
|
| 382 |
+
hood_rx.append(rx)
|
| 383 |
+
hood_ry.append(rx * 0.85)
|
| 384 |
+
|
| 385 |
+
Xh, Yh, Zh = _revolution_surface(hood_z, hood_rx, hood_ry, n_theta=28)
|
| 386 |
+
surfaces.append(_make_surface(Xh, Yh, Zh, _darken_color(color, 0.12), "Hood", opacity=0.78))
|
| 387 |
+
|
| 388 |
+
return surfaces
|
| 389 |
+
|
| 390 |
+
|
| 391 |
+
def _build_jacket(params, color="#7F8C8D"):
|
| 392 |
+
"""Build jacket/coat/blazer — like a shirt but longer, wider."""
|
| 393 |
+
jacket_params = dict(params)
|
| 394 |
+
jacket_len = params.get("jacket_length", params.get("bodice_length", 70))
|
| 395 |
+
jacket_params["bodice_length"] = jacket_len
|
| 396 |
+
|
| 397 |
+
original_fit = params.get("fit", "regular")
|
| 398 |
+
if original_fit == "fitted":
|
| 399 |
+
jacket_params["fit"] = "regular"
|
| 400 |
+
elif original_fit == "regular":
|
| 401 |
+
jacket_params["fit"] = "loose"
|
| 402 |
+
|
| 403 |
+
surfaces = _build_shirt(jacket_params, color=color)
|
| 404 |
+
|
| 405 |
+
if params.get("has_hood", False):
|
| 406 |
+
surfaces.extend(_build_hood_only(params, color))
|
| 407 |
+
|
| 408 |
+
return surfaces
|
| 409 |
+
|
| 410 |
+
|
| 411 |
+
def _build_hood_only(params, color):
|
| 412 |
+
"""Just the hood part."""
|
| 413 |
+
n_hood = 10
|
| 414 |
+
hood_z = np.linspace(Z_SHOULDER, Z_HEAD_TOP + 2, n_hood)
|
| 415 |
+
hood_rx = []
|
| 416 |
+
hood_ry = []
|
| 417 |
+
|
| 418 |
+
for i, z in enumerate(hood_z):
|
| 419 |
+
t = i / (n_hood - 1)
|
| 420 |
+
if t < 0.2:
|
| 421 |
+
rx = _body_rx(Z_SHOULDER) + 2.5
|
| 422 |
+
elif t < 0.6:
|
| 423 |
+
f = (t - 0.2) / 0.4
|
| 424 |
+
rx = _body_rx(min(z, Z_HEAD_TOP)) + 3.0 + 2.0 * np.sin(f * np.pi)
|
| 425 |
+
else:
|
| 426 |
+
f = (t - 0.6) / 0.4
|
| 427 |
+
rx = _body_rx(min(z, Z_HEAD_TOP)) + 3.0 * (1 - f * 0.6)
|
| 428 |
+
hood_rx.append(rx)
|
| 429 |
+
hood_ry.append(rx * 0.85)
|
| 430 |
+
|
| 431 |
+
Xh, Yh, Zh = _revolution_surface(hood_z, hood_rx, hood_ry, n_theta=28)
|
| 432 |
+
return [_make_surface(Xh, Yh, Zh, _darken_color(color, 0.12), "Hood", opacity=0.78)]
|
| 433 |
+
|
| 434 |
+
|
| 435 |
+
def _build_vest(params, color="#D4A574"):
|
| 436 |
+
"""Build vest — sleeveless bodice."""
|
| 437 |
+
bust = params.get("bust", 92)
|
| 438 |
+
waist = params.get("waist", 74)
|
| 439 |
+
shoulder = params.get("shoulder_width", 42)
|
| 440 |
+
fit = params.get("fit", "regular")
|
| 441 |
+
flare = params.get("flare", 0)
|
| 442 |
+
|
| 443 |
+
ease = {"fitted": 0.5, "regular": 1.2, "oversized": 3.0, "loose": 2.2}.get(fit, 1.2)
|
| 444 |
+
|
| 445 |
+
bust_rx = _circ_to_rx(bust) + ease
|
| 446 |
+
bust_ry = _circ_to_ry(bust) + ease
|
| 447 |
+
waist_rx = _circ_to_rx(waist) + ease
|
| 448 |
+
waist_ry = _circ_to_ry(waist) + ease
|
| 449 |
+
shoulder_rx = shoulder / 2
|
| 450 |
+
|
| 451 |
+
surfaces = []
|
| 452 |
+
vest_len = params.get("vest_length", params.get("bodice_length", 55))
|
| 453 |
+
extra = max(0, vest_len - 42) * 0.5
|
| 454 |
+
hem_z = max(Z_WAIST - extra, Z_HIP)
|
| 455 |
+
|
| 456 |
+
n = 14
|
| 457 |
+
torso_z = np.linspace(hem_z, Z_SHOULDER, n)
|
| 458 |
+
torso_rx = []
|
| 459 |
+
torso_ry = []
|
| 460 |
+
|
| 461 |
+
for z in torso_z:
|
| 462 |
+
t = (z - hem_z) / (Z_SHOULDER - hem_z)
|
| 463 |
+
if t < 0.25:
|
| 464 |
+
rx = waist_rx + flare * (0.25 - t) / 0.25
|
| 465 |
+
ry = waist_ry + flare * 0.8 * (0.25 - t) / 0.25
|
| 466 |
+
elif t < 0.55:
|
| 467 |
+
f = (t - 0.25) / 0.30
|
| 468 |
+
rx = waist_rx + (bust_rx - waist_rx) * f
|
| 469 |
+
ry = waist_ry + (bust_ry - waist_ry) * f
|
| 470 |
+
elif t < 0.8:
|
| 471 |
+
f = (t - 0.55) / 0.25
|
| 472 |
+
rx = bust_rx * (1 - 0.08 * f)
|
| 473 |
+
ry = bust_ry * (1 - 0.08 * f)
|
| 474 |
else:
|
| 475 |
+
f = (t - 0.8) / 0.2
|
| 476 |
+
rx = bust_rx * 0.92 + (shoulder_rx - bust_rx * 0.92) * f
|
| 477 |
+
ry = bust_ry * 0.92 * (1 - 0.15 * f)
|
| 478 |
+
|
| 479 |
+
rx = max(rx, _body_rx(z) + 0.8)
|
| 480 |
+
ry = max(ry, _body_ry(z) + 0.8)
|
| 481 |
+
torso_rx.append(rx)
|
| 482 |
+
torso_ry.append(ry)
|
| 483 |
+
|
| 484 |
+
X, Y, Zt = _revolution_surface(torso_z, torso_rx, torso_ry, n_theta=36)
|
| 485 |
+
surfaces.append(_make_surface(X, Y, Zt, color, "Vest", opacity=0.85))
|
| 486 |
+
|
| 487 |
return surfaces
|
| 488 |
|
| 489 |
+
|
| 490 |
+
# ── Color helpers ───────────────────────────────────────────────────────────
|
| 491 |
+
def _hex_to_rgb(hex_color):
|
| 492 |
+
hex_color = hex_color.lstrip('#')
|
| 493 |
+
return tuple(int(hex_color[i:i + 2], 16) for i in (0, 2, 4))
|
| 494 |
+
|
| 495 |
+
def _rgb_to_hex(r, g, b):
|
| 496 |
+
return f"#{int(r):02x}{int(g):02x}{int(b):02x}"
|
| 497 |
+
|
| 498 |
+
def _lighten_color(hex_color, amount=0.1):
|
| 499 |
+
r, g, b = _hex_to_rgb(hex_color)
|
| 500 |
+
return _rgb_to_hex(min(255, r + int(255 * amount)),
|
| 501 |
+
min(255, g + int(255 * amount)),
|
| 502 |
+
min(255, b + int(255 * amount)))
|
| 503 |
+
|
| 504 |
+
def _darken_color(hex_color, amount=0.1):
|
| 505 |
+
r, g, b = _hex_to_rgb(hex_color)
|
| 506 |
+
return _rgb_to_hex(max(0, r - int(255 * amount)),
|
| 507 |
+
max(0, g - int(255 * amount)),
|
| 508 |
+
max(0, b - int(255 * amount)))
|
| 509 |
+
|
| 510 |
+
|
| 511 |
+
# ── Default garment colors ─────────────────────────────────────────────────
|
| 512 |
+
GARMENT_COLORS = {
|
| 513 |
+
"shirt": "#4A90D9", "blouse": "#D98CB3", "top": "#5B9BD5",
|
| 514 |
+
"t-shirt": "#4A90D9", "tee": "#4A90D9",
|
| 515 |
+
"dress": "#8E44AD", "skirt": "#C48BB8",
|
| 516 |
+
"pants": "#2C5F8A", "trousers": "#2C5F8A", "jeans": "#1A3D6C",
|
| 517 |
+
"jacket": "#7F8C8D", "coat": "#5D6D7E", "blazer": "#6C757D",
|
| 518 |
+
"hoodie": "#27AE60", "sweatshirt": "#27AE60",
|
| 519 |
+
"vest": "#D4A574",
|
| 520 |
}
|
| 521 |
+
|
| 522 |
+
GARMENT_BUILDERS = {
|
| 523 |
+
"shirt": _build_shirt, "blouse": _build_shirt,
|
| 524 |
+
"top": _build_shirt, "t-shirt": _build_shirt, "tee": _build_shirt,
|
| 525 |
+
"dress": _build_dress, "skirt": _build_skirt,
|
| 526 |
+
"pants": _build_pants, "trousers": _build_pants, "jeans": _build_pants,
|
| 527 |
+
"jacket": _build_jacket, "coat": _build_jacket, "blazer": _build_jacket,
|
| 528 |
+
"hoodie": _build_hoodie, "sweatshirt": _build_hoodie,
|
| 529 |
+
"vest": _build_vest,
|
| 530 |
+
}
|
| 531 |
+
|
| 532 |
+
|
| 533 |
+
# ── Main entry point ───────────────────────────────────────────────────────
|
| 534 |
def create_3d_figure(analysis: Dict) -> go.Figure:
|
| 535 |
+
"""Create interactive 3D garment visualization on a mannequin body."""
|
| 536 |
garment_type = analysis.get("garment_type", "shirt").lower()
|
| 537 |
measurements = analysis.get("measurements", {})
|
| 538 |
features = analysis.get("features", {})
|
| 539 |
params = {**measurements, **features}
|
| 540 |
+
|
|
|
|
|
|
|
| 541 |
fig = go.Figure()
|
| 542 |
+
|
| 543 |
+
# Mannequin body
|
| 544 |
+
fig.add_trace(_make_body())
|
| 545 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
| 546 |
# Garment surfaces
|
| 547 |
+
color = GARMENT_COLORS.get(garment_type, "#4A90D9")
|
| 548 |
+
builder = GARMENT_BUILDERS.get(garment_type, _build_shirt)
|
| 549 |
+
for surf in builder(params, color=color):
|
| 550 |
+
fig.add_trace(surf)
|
| 551 |
+
|
| 552 |
+
# Scene layout
|
|
|
|
|
|
|
|
|
|
|
|
|
| 553 |
fig.update_layout(
|
| 554 |
scene=dict(
|
| 555 |
+
xaxis=dict(showgrid=False, showticklabels=False, title="",
|
| 556 |
+
zeroline=False, range=[-35, 35]),
|
| 557 |
+
yaxis=dict(showgrid=False, showticklabels=False, title="",
|
| 558 |
+
zeroline=False, range=[-35, 35]),
|
| 559 |
+
zaxis=dict(showgrid=False, showticklabels=False, title="",
|
| 560 |
+
zeroline=False, range=[0, 180]),
|
| 561 |
aspectmode="data",
|
| 562 |
+
camera=dict(
|
| 563 |
+
eye=dict(x=1.8, y=1.2, z=0.5),
|
| 564 |
+
center=dict(x=0, y=0, z=-0.1),
|
| 565 |
+
),
|
| 566 |
+
bgcolor="rgba(245,245,248,1)",
|
| 567 |
+
),
|
| 568 |
+
margin=dict(l=0, r=0, t=35, b=0),
|
| 569 |
+
height=550,
|
| 570 |
title=dict(text=f"3D Preview: {garment_type.title()}", font=dict(size=14)),
|
| 571 |
+
paper_bgcolor="#fafafa",
|
| 572 |
+
)
|
| 573 |
+
|
| 574 |
+
return fig
|