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

Update Define Joint operator #352

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion phobos/blender/operators/editing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1507,6 +1507,8 @@ class DefineJointConstraintsOperator(Operator):
name="Joint Axis", default=[0.0, 0.0, 1], description="Damping constant of the joint", size=3
)

executeMessage = []

def draw(self, context):
"""

Expand All @@ -1517,6 +1519,8 @@ def draw(self, context):

"""
layout = self.layout
for msg in self.executeMessage:
layout.label(text=msg)
if self.name.replace(" ", "_") != self.name:
layout.label(text="Created as "+self.name.replace(" ", "_"))
if len(context.selected_objects) == 1:
Expand Down Expand Up @@ -1566,6 +1570,7 @@ def invoke(self, context, event):

"""
obj = context.active_object
self.name = ""
if any([k.startswith("joint") for k in obj.keys()]):
if "joint/limits/lower" in obj:
self.lower = obj["joint/limits/lower"]
Expand All @@ -1592,6 +1597,7 @@ def execute(self, context):

"""
log('Defining joint constraints for joint: ', 'INFO')
self.executeMessage = []
lower = 0
upper = 0
velocity = self.maxvelocity
Expand Down Expand Up @@ -1622,8 +1628,10 @@ def execute(self, context):
# Check if joints can be created
if max(axis) == 0 and min(axis) == 0:
validInput = False
self.executeMessage.append("Please set the joint axis to define the joint")
# set properties for each joint
if validInput:
defined = 0
for joint in (obj for obj in context.selected_objects if obj.phobostype == 'link'):
context.view_layer.objects.active = joint
if joint.parent is None or joint.parent.phobostype != "link":
Expand All @@ -1642,6 +1650,7 @@ def execute(self, context):
damping=self.damping,
axis=(np.array(axis) / np.linalg.norm(axis)).tolist() if axis is not None else None
)
defined = defined+1

if "joint/name" not in joint:
joint["joint/name"] = joint.name + "_joint"
Expand All @@ -1656,6 +1665,8 @@ def execute(self, context):
),
linkobj=joint
)
jointPluralS = "" if defined == 1 else "s"
self.executeMessage.append(f"Defined {defined} joint{jointPluralS}")

return {'FINISHED'}

Expand Down Expand Up @@ -3070,7 +3081,6 @@ def draw(self, context):
for t in self.executeMessage:
layout.label(text=t)


def execute(self, context):
"""

Expand Down