Skip to content

Commit

Permalink
Merge pull request #352 from AlpenAalAlex/issue350-Define-Joint-dialo…
Browse files Browse the repository at this point in the history
…g-remembers-and-applies-last-joint-name

Update Define Joint operator
  • Loading branch information
hwiedPro authored Jun 13, 2024
2 parents b0d7dc9 + 6aa8c9c commit 4e37f7f
Showing 1 changed file with 11 additions and 1 deletion.
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

0 comments on commit 4e37f7f

Please sign in to comment.