diff --git a/nhf/materials.py b/nhf/materials.py index f87b796..714995c 100644 --- a/nhf/materials.py +++ b/nhf/materials.py @@ -54,16 +54,18 @@ ROLE_COLOR_MAP = { class Material(Enum): """ A catalog of common material properties + + Density listed is in g/cm^3 or mg/mm^3 """ - WOOD_BIRCH = 0.8, _color('bisque', 0.9) - PLASTIC_PLA = 0.5, _color('mistyrose', 0.8) - RESIN_TRANSPERENT = 1.1, _color('cadetblue2', 0.6) - RESIN_TOUGH_1500 = 1.1, _color('seashell3', 0.7) - ACRYLIC_BLACK = 0.5, _color('gray5', 0.8) - ACRYLIC_TRANSLUSCENT = 0.5, _color('ivory2', 0.8) - ACRYLIC_TRANSPARENT = 0.5, _color('ghostwhite', 0.5) - STEEL_SPRING = 1.0, _color('gray', 0.8) + WOOD_BIRCH = 0.71, _color('bisque', 0.9) + PLASTIC_PLA = 1.2, _color('mistyrose', 0.8) + RESIN_TRANSPERENT = 1.17, _color('cadetblue2', 0.6) + RESIN_TOUGH_1500 = 1.17, _color('seashell3', 0.7) + ACRYLIC_BLACK = 1.18, _color('gray5', 0.8) + ACRYLIC_TRANSLUSCENT = 1.18, _color('ivory2', 0.8) + ACRYLIC_TRANSPARENT = 1.18, _color('ghostwhite', 0.5) + STEEL_SPRING = 7.8, _color('gray', 0.8) def __init__(self, density: float, color: Cq.Color): self.density = density @@ -110,3 +112,16 @@ def color_by_role(self: Cq.Assembly, avg: bool = True) -> Cq.Assembly: a.color = role.color_avg() if avg else role.color_head() return self Cq.Assembly.color_by_role = color_by_role + +def total_mass(self: Cq.Assembly) -> float: + """ + Calculates the total mass in units of g + """ + total = 0.0 + for _, a in self.traverse(): + if 'material' not in a.metadata: + continue + vol = a.toCompound().Volume() + total += vol * a.metadata['material'].density + return total / 1000.0 +Cq.Assembly.total_mass = total_mass diff --git a/nhf/touhou/houjuu_nue/__init__.py b/nhf/touhou/houjuu_nue/__init__.py index 4c24b10..a9cb819 100644 --- a/nhf/touhou/houjuu_nue/__init__.py +++ b/nhf/touhou/houjuu_nue/__init__.py @@ -146,11 +146,19 @@ class Parameters(Model): bbox = a.toCompound().BoundingBox() return { "wing-span": bbox.xlen, - "wing-thickness": bbox.ylen, + "wing-depth": bbox.ylen, "wing-height": bbox.zlen, + "wing-mass": a.total_mass(), } if __name__ == '__main__': + import sys + p = Parameters() - p.build_all() + if len(sys.argv) == 1: + p.build_all() + sys.exit(0) + + if sys.argv[1] == 'stat': + print(p.stat())