cosplay: Touhou/Houjuu Nue #4

Open
aniva wants to merge 189 commits from touhou/houjuu-nue into main
3 changed files with 47 additions and 3 deletions
Showing only changes of commit 3ad17f0c3e - Show all commits

View File

@ -163,5 +163,22 @@ class TestUtils(unittest.TestCase):
self.assertAlmostEqual(bbox.ylen, 15)
self.assertAlmostEqual(bbox.zlen, 5)
def test_abs_location(self):
box = Cq.Solid.makeBox(1, 1, 1)
assembly = (
Cq.Assembly()
.add(box, name="b1")
.add(box, name="b2", loc=Cq.Location((0,0,1)))
.add(box, name="b3", loc=Cq.Location((0,0,2)))
)
(x, y, z), _ = assembly.get_abs_location("b2@faces@>Y").toTuple()
self.assertAlmostEqual(x, 0.5)
self.assertAlmostEqual(y, 1)
self.assertAlmostEqual(z, 1.5)
(rx, ry, rz), _ = assembly.get_abs_direction("b2@faces@>Y").toTuple()
self.assertAlmostEqual(rx, 0)
self.assertAlmostEqual(ry, 1)
self.assertAlmostEqual(rz, 0)
if __name__ == '__main__':
unittest.main()

View File

@ -30,7 +30,7 @@ class TestJoints(unittest.TestCase):
Tests the arm radius
"""
j = MJ.ShoulderJoint()
for deflection in [0, 40, 95, 120]:
for deflection in [0, 40, j.angle_max_deflection]:
with self.subTest(deflection=deflection):
a = j.assembly(deflection=deflection)
# Axle

View File

@ -1,9 +1,10 @@
"""
Utility functions for cadquery objects
"""
import math
import functools
import math
import cadquery as Cq
from cadquery.occ_impl.solver import ConstraintSpec
from nhf import Role
from typing import Union, Tuple, cast
from nhf.materials import KEY_ITEM, KEY_MATERIAL
@ -198,14 +199,40 @@ Cq.Assembly.markPlane = mark_plane
def get_abs_location(self: Cq.Assembly,
tag: str) -> Cq.Location:
"""
Gets the location of a tag
BUG: Currently bugged. See `nhf/test.py` for example
"""
name, shape = self._query(tag)
loc_self = shape.location()
loc_self = Cq.Location(shape.Center())
loc_parent, _ = self._subloc(name)
loc = loc_parent * loc_self
return loc
Cq.Assembly.get_abs_location = get_abs_location
def get_abs_direction(self: Cq.Assembly,
tag: str) -> Cq.Location:
"""
Gets the location of a tag
"""
name, shape = self._query(tag)
# Must match `cadquery.occ_impl.solver.ConstraintSpec._getAxis`
if isinstance(shape, Cq.Face):
vec_dir = shape.normalAt()
elif isinstance(shape, Cq.Edge) and shape.geomType() != "CIRCLE":
vec_dir = shape.tangentAt()
elif isinstance(shape, Cq.Edge) and shape.geomType() == "CIRCLE":
vec_dir = shape.normal()
else:
raise ValueError(f"Cannot construct Axis for {shape}")
loc_self = Cq.Location(vec_dir)
loc_parent, _ = self._subloc(name)
loc = loc_parent * loc_self
return loc
Cq.Assembly.get_abs_direction = get_abs_direction
# Tallying functions