Cosplay/nhf/touhou/houjuu_nue/__init__.py

148 lines
5.0 KiB
Python

"""
To build, execute
```
python3 nhf/touhou/houjuu_nue/__init__.py
```
This cosplay consists of 3 components:
## Trident
The trident is composed of individual segments, made of acrylic, and a 3D
printed head (convention rule prohibits metal) with a metallic paint. To ease
transportation, the trident handle has individual segments with threads and can
be assembled on site.
## Snake
A 3D printed snake with a soft material so it can wrap around and bend
## Wings
This is the crux of the cosplay and the most complex component. The wings mount
on a wearable harness. Each wing consists of 4 segments with 3 joints. Parts of
the wing which demands transluscency are created from 1/16" acrylic panels.
These panels serve double duty as the exoskeleton.
The wings are labeled r1,r2,r3,l1,l2,l3. The segments of the wings are labeled
from root to tip s0 (root),
s1, s2, s3. The joints are named (from root to tip)
shoulder, elbow, wrist in analogy with human anatomy.
"""
from dataclasses import dataclass, field
from typing import Optional
import cadquery as Cq
from nhf.build import Model, TargetKind, target, assembly, submodel
from nhf.parts.joints import HirthJoint, TorsionJoint
import nhf.touhou.houjuu_nue.wing as MW
import nhf.touhou.houjuu_nue.trident as MT
import nhf.touhou.houjuu_nue.joints as MJ
import nhf.touhou.houjuu_nue.harness as MH
import nhf.utils
@dataclass
class Parameters(Model):
"""
Defines dimensions for the Houjuu Nue cosplay
"""
# Harness
harness: MH.Harness = field(default_factory=lambda: MH.Harness())
hs_hirth_joint: HirthJoint = field(default_factory=lambda: HirthJoint(
radius=30,
radius_inner=20,
tooth_height=10,
base_height=5,
n_tooth=24
))
wing_r1: MW.WingR = field(default_factory=lambda: MW.WingR(name="r1"))
wing_r2: MW.WingR = field(default_factory=lambda: MW.WingR(name="r2"))
wing_r3: MW.WingR = field(default_factory=lambda: MW.WingR(name="r3"))
wing_l1: MW.WingL = field(default_factory=lambda: MW.WingL(
name="l1",
wrist_angle=-45.0,
))
wing_l2: MW.WingL = field(default_factory=lambda: MW.WingL(
name="l2",
wrist_angle=-30.0,
))
wing_l3: MW.WingL = field(default_factory=lambda: MW.WingL(
name="l3",
wrist_angle=0.0,
))
trident: MT.Trident = field(default_factory=lambda: MT.Trident())
def __post_init__(self):
super().__init__(name="houjuu-nue")
self.harness.hs_hirth_joint = self.hs_hirth_joint
self.wing_r1.base_joint = self.hs_hirth_joint
self.wing_r2.base_joint = self.hs_hirth_joint
self.wing_r3.base_joint = self.hs_hirth_joint
@submodel(name="harness")
def submodel_harness(self) -> Model:
return self.harness
@submodel(name="wing-r1")
def submodel_wing_r1(self) -> Model:
return self.wing_r1
@submodel(name="wing-r2")
def submodel_wing_r2(self) -> Model:
return self.wing_r2
@submodel(name="wing-r3")
def submodel_wing_r3(self) -> Model:
return self.wing_r3
@submodel(name="wing-r1")
def submodel_wing_l1(self) -> Model:
return self.wing_l1
@submodel(name="wing-l2")
def submodel_wing_l2(self) -> Model:
return self.wing_l2
@submodel(name="wing-l3")
def submodel_wing_l3(self) -> Model:
return self.wing_l3
@assembly()
def wings_harness_assembly(self, parts: Optional[list[str]] = None) -> Cq.Assembly:
"""
Assembly of harness with all the wings
"""
result = (
Cq.Assembly()
.add(self.harness.assembly(), name="harness", loc=Cq.Location((0, 0, 0)))
.add(self.wing_r1.assembly(parts), name="wing_r1")
.add(self.wing_r2.assembly(parts), name="wing_r2")
.add(self.wing_r3.assembly(parts), name="wing_r3")
.add(self.wing_l1.assembly(parts), name="wing_l1")
.add(self.wing_l2.assembly(parts), name="wing_l2")
.add(self.wing_l3.assembly(parts), name="wing_l3")
)
self.hs_hirth_joint.add_constraints(result, "harness/r1", "wing_r1/s0/hs", offset=11)
self.hs_hirth_joint.add_constraints(result, "harness/r2", "wing_r2/s0/hs", offset=10)
self.hs_hirth_joint.add_constraints(result, "harness/r3", "wing_r3/s0/hs", offset=9)
self.hs_hirth_joint.add_constraints(result, "harness/l1", "wing_l1/s0/hs", offset=6)
self.hs_hirth_joint.add_constraints(result, "harness/l2", "wing_l2/s0/hs", offset=7)
self.hs_hirth_joint.add_constraints(result, "harness/l3", "wing_l3/s0/hs", offset=8)
return result.solve()
@submodel(name="trident")
def submodel_trident(self) -> Model:
return self.trident
def stat(self) -> dict[str, float]:
a = self.wings_harness_assembly()
bbox = a.toCompound().BoundingBox()
return {
"wing-span": bbox.xlen,
"wing-thickness": bbox.ylen,
"wing-height": bbox.zlen,
}
if __name__ == '__main__':
p = Parameters()
p.build_all()