krishnax12/hyprland-macropad
A tscircuit package created by krishnax12.
- Version
- 1.0.7
- License
- CC-BY-SA-3.0
- Stars
- 0
Use with the tscircuit CLI
tsci is the tscircuit CLI. Install it with npm install -g tscircuit.
tsci clone krishnax12/hyprland-macropad # download the package files into ./hyprland-macropad
tsci add krishnax12/hyprland-macropad # add it to your project as @tsci/krishnax12.hyprland-macropadIn a cloned or new (tsci init) project: tsci dev starts a local preview, tsci build outputs Circuit JSON, and tsci push publishes to tscircuit.com.
enclosure/export-preview.py
"""Convert the CadQuery tessellation to coloured glTF binary preview assets."""
import json,struct,math,gzip,hashlib
from pathlib import Path
ROOT=Path(__file__).resolve().parent
for source in sorted((ROOT/'meshes').glob('*.json.gz')):
mesh=json.loads(gzip.decompress(source.read_bytes()))
positions=[]; normals=[]
for face in mesh['faces']:
a,b,c=[mesh['vertices'][i] for i in face]
u=[b[i]-a[i] for i in range(3)];v=[c[i]-a[i] for i in range(3)]
n=[u[1]*v[2]-u[2]*v[1],u[2]*v[0]-u[0]*v[2],u[0]*v[1]-u[1]*v[0]]
length=math.sqrt(sum(x*x for x in n))
n=[x/length if length else 0 for x in n]
positions.extend([a,b,c]);normals.extend([n,n,n])
count=len(positions)
pos=struct.pack('<'+'f'*(count*3),*(x for p in positions for x in p))
normal=struct.pack('<'+'f'*(count*3),*(x for p in normals for x in p))
binary=pos+normal
doc={'asset':{'version':'2.0','generator':'Hyprpad CadQuery mesh exporter'},'scene':0,'scenes':[{'nodes':[0]}],'nodes':[{'mesh':0,'name':mesh['name']}],
'meshes':[{'primitives':[{'attributes':{'POSITION':0,'NORMAL':1},'material':0}]}],
'materials':[{'pbrMetallicRoughness':{'baseColorFactor':mesh['color']+[1],'metallicFactor':0.1,'roughnessFactor':0.55},'doubleSided':False}],
'buffers':[{'byteLength':len(binary)}],'bufferViews':[{'buffer':0,'byteOffset':0,'byteLength':len(pos),'target':34962},{'buffer':0,'byteOffset':len(pos),'byteLength':len(normal),'target':34962}],
'accessors':[{'bufferView':0,'componentType':5126,'count':count,'type':'VEC3','min':[min(p[i] for p in positions) for i in range(3)],'max':[max(p[i] for p in positions) for i in range(3)]},{'bufferView':1,'componentType':5126,'count':count,'type':'VEC3'}]}
header=json.dumps(doc,separators=(',',':')).encode();header+=b' '*((-len(header))%4)
glb=struct.pack('<III',0x46546c67,2,12+8+len(header)+8+len(binary))+struct.pack('<II',len(header),0x4e4f534a)+header+struct.pack('<II',len(binary),0x004e4942)+binary
(ROOT/'models'/f"{mesh['name']}-{hashlib.sha256(glb).hexdigest()[:12]}.glb").write_bytes(glb)
print(mesh['name'],len(glb))