← Commit history

Rotate via geometry verts (not scene transform) so silk faces default camera AND pin lift animation stays correct

John Lauer ·8e53b9ea64 ·3mo ago ·parent f719da6
3 files changed +11−8
AdomMachinePins-4pin-animated.glb
⋯ 1 unchanged line ⋯
AdomMachinePins-complete.zip
⋯ 1 unchanged line ⋯
scripts/build_board_glb.py+11−8
@@ -81,7 +81,13 @@ print("board top z (mm):", round(board_top*1000,3))  scene = trimesh.Scene() +ROT_CENTER=None   # once set to (cx,cy) below, every mesh is rotated 180 about the board-centre Z axis+def _rot(vv):+    if ROT_CENTER is None: return vv+    cx,cy=ROT_CENTER; out=np.asarray(vv,dtype=float).copy()+    out[:,0]=2*cx-out[:,0]; out[:,1]=2*cy-out[:,1]; return out def add_mesh(vv,f,rgba,name,metal=False,double=True):+    vv=_rot(vv)     m=trimesh.Trimesh(vertices=vv,faces=f,process=False)     r,gr,b,a=rgba     m.visual=trimesh.visual.TextureVisuals(material=trimesh.visual.material.PBRMaterial(@@ -94,6 +100,7 @@ def add_mesh(vv,f,rgba,name,metal=False,double=True): # (we rebuild copper as real 1oz layers below). board_xy=np.vstack([vv[:,:2] for vv,f,col in board_meshes]) bx0,by0=board_xy.min(0); bx1,by1=board_xy.max(0)+ROT_CENTER=((bx0+bx1)/2,(by0+by1)/2)   # rotate the whole assembly 180 so silk faces the default camera  FR4_T=0.0016   # 1.6mm standard FR4 board_bottom=board_top-FR4_T@@ -204,19 +211,15 @@ img.save("/tmp/v7_texture.png") img=img.transpose(Image.FLIP_LEFT_RIGHT)   # GLB export mirrors this face in X; pre-flip so print + arrows read correct  # add the board with the silkscreen texture (planar UVs; single-sided transparent print)+# UV from ORIGINAL vertex positions (planar), then rotate the board verts with the rest of the+# assembly so the printed silkscreen faces the viewer's default camera. UV stays per-vertex, so the+# texture rotates with the board. Node transform stays identity -> the pin lift animation is unaffected. uv=np.column_stack([(slab.vertices[:,0]-bx0)/(bx1-bx0), 1.0-(slab.vertices[:,1]-by0)/(by1-by0)])-bmesh=trimesh.Trimesh(vertices=slab.vertices, faces=slab.faces, process=False)+bmesh=trimesh.Trimesh(vertices=_rot(slab.vertices), faces=slab.faces, process=False) bmesh.visual=trimesh.visual.TextureVisuals(uv=uv, material=trimesh.visual.material.PBRMaterial(     baseColorFactor=[255,255,255,255], baseColorTexture=img, metallicFactor=0.2, roughnessFactor=0.55,     alphaMode="BLEND", doubleSided=False)) scene.add_geometry(bmesh, node_name="board_fr4", geom_name="board_fr4") -# Rotate the WHOLE assembly 180 deg about the board-centre Z axis so the silkscreen faces the-# viewer's DEFAULT camera (reads left-to-right). Everything (board+texture, pins, copper, balls,-# arrows) rotates together, so labels/arrows stay matched to their pins. Z-axis rotation keeps the-# insertion lift pointing +Z.-Rz=trimesh.transformations.rotation_matrix(np.pi,[0,0,1],point=[(bx0+bx1)/2,(by0+by1)/2,board_top])-scene.apply_transform(Rz)- scene.export(OUT) print("exported",OUT)