Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Joints in custom parts #823

Open
gumyr opened this issue Dec 18, 2024 Discussed in #822 · 1 comment
Open

Joints in custom parts #823

gumyr opened this issue Dec 18, 2024 Discussed in #822 · 1 comment
Labels
bug Something isn't working

Comments

@gumyr
Copy link
Owner

gumyr commented Dec 18, 2024

Discussed in #822

Originally posted by mortisj December 17, 2024
Based on a recent discussion about creating custom part objects I tried to convert some existing naive part classes to subclass BasePartObject:

class CustomCylinder(bd.BasePartObject):
    def __init__(self):
        part = bd.Cylinder(radius = 2, height = 2)
        bd.RigidJoint(
            label = "bottom",
            to_part = part,
            joint_location = bd.Location((0, 0, -1), (0, 0, 0)))
        super().__init__(part=part)

After I did this any attempt to connect_to an instance of the custom part silently failed. The call succeeded but the part was not moved.

The trick was to change to order of things slightly:

class CustomCylinder(bd.BasePartObject):
    def __init__(self):
        part = bd.Cylinder(radius = 2, height = 2)
        super().__init__(part=part)
        bd.RigidJoint(
            label = "bottom",
            to_part = self,
            joint_location = bd.Location((0, 0, -1), (0, 0, 0)))

With the first (incorrect) version it is strange that the connect_to succeeded without a KeyError. It looks like the super.init() copies the joints dict from the subpart to the new object, but it doesn't adjust the joints' parent attribute appropriately. I'm not sure if that is a bug, but it certainly tripped me up!

Cheers.

@gumyr gumyr added the bug Something isn't working label Dec 18, 2024
@gumyr gumyr added this to the Gating Release 1.0.0 milestone Dec 18, 2024
@mortisj
Copy link

mortisj commented Dec 22, 2024

It looks like the color attribute is missed also.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants