|
17 | 17 | IkVariables as ikv,
|
18 | 18 | InverseKinematics,
|
19 | 19 | )
|
20 |
| - #inverseKinematics, |
21 |
| - #dynComp, |
22 |
| - #iDynTreeModel) |
23 | 20 |
|
24 | 21 | from bpy_extras.io_utils import ImportHelper
|
25 | 22 | from bpy_extras import view3d_utils
|
|
40 | 37 | UIList
|
41 | 38 | )
|
42 | 39 |
|
43 |
| -# global variables |
44 |
| -# inverseKinematics = iDynTree.InverseKinematics() |
45 |
| -# dynComp = iDynTree.KinDynComputations() |
46 |
| -# iDynTreeModel = None |
47 |
| - |
48 |
| -mouse_loc = [0, 0, 0] |
49 |
| - |
50 | 40 | list_of_links = []
|
51 | 41 |
|
52 | 42 | # def printError(self, *args):
|
@@ -489,70 +479,71 @@ def execute(self, context):
|
489 | 479 | # bpy.ops.object.modal_operator('INVOKE_DEFAULT')
|
490 | 480 | return InverseKinematics.execute(self)
|
491 | 481 |
|
492 |
| -# |
493 |
| -# class ModalOperator(bpy.types.Operator): |
494 |
| -# bl_idname = "object.modal_operator" |
495 |
| -# bl_label = "Simple Modal Operator" |
496 |
| - |
497 |
| -# def __init__(self): |
498 |
| -# self.mouse_pos = [0.0, 0.0] |
499 |
| -# self.object = None |
500 |
| -# print("Start") |
501 |
| -# |
502 |
| -# def __del__(self): |
503 |
| -# print("End") |
504 |
| -# |
505 |
| -# def execute(self, context): |
506 |
| -# print("location: ", mouse_loc[0], mouse_loc[1], mouse_loc[2]) |
507 |
| -# return {'FINISHED'} |
508 |
| -# |
509 |
| -# def modal(self, context, event): |
510 |
| -# if event.type == 'L': # Apply |
511 |
| -# print("getting the locations") |
512 |
| -# global mouse_loc |
513 |
| -# self.mouse_pos = [event.mouse_region_x, event.mouse_region_y] |
514 |
| -# |
515 |
| -# self.object = bpy.context.object |
516 |
| -# region = bpy.context.region |
517 |
| -# region3D = bpy.context.space_data.region_3d |
518 |
| -# #The direction indicated by the mouse position from the current view |
519 |
| -# view_vector = view3d_utils.region_2d_to_vector_3d(region, region3D, self.mouse_pos) |
520 |
| -# #The 3D location in this direction |
521 |
| -# mouse_loc = view3d_utils.region_2d_to_location_3d(region, region3D, self.mouse_pos, view_vector) |
522 |
| -# #The 3D location converted in object local coordinates |
523 |
| -# # mouse_loc = self.object.matrix_world.inverted() * mouse_loc |
524 |
| -# |
525 |
| -# self.execute(context) |
526 |
| -# |
527 |
| -# elif event.type == 'O': |
528 |
| -# print("O pressed") |
529 |
| -# return {'FINISHED'} |
530 |
| -# elif event.type in {'P'}: # Cancel |
531 |
| -# print("P pressed") |
532 |
| -# return {'CANCELLED'} |
533 |
| -# |
534 |
| -# return {'RUNNING_MODAL'} |
535 |
| -# |
536 |
| -# def invoke(self, context, event): |
537 |
| -# if context.area.type == 'VIEW_3D': |
538 |
| -# print("Operator invoked") |
539 |
| -# args = (self, context) |
540 |
| -# # self._handle = bpy.types.SpaceView3D.draw_handler_add(draw_callback_px, args, 'WINDOW', 'POST_PIXEL') |
541 |
| -# |
542 |
| -# # Keeps mouse position current 3D location and current object for the draw callback |
543 |
| -# # (not needed to make self attribute if you don't want to use the callback) |
544 |
| -# self.mouse_pos = [0, 0] |
545 |
| -# |
546 |
| -# global mouse_loc |
547 |
| -# mouse_loc = [0, 0, 0] |
548 |
| -# |
549 |
| -# self.object = context.object |
550 |
| -# |
551 |
| -# context.window_manager.modal_handler_add(self) |
552 |
| -# return {'RUNNING_MODAL'} |
553 |
| -# else: |
554 |
| -# self.report({'WARNING'}, "View3D not found, cannot run operator") |
555 |
| -# return {'CANCELLED'} |
| 482 | + |
| 483 | +class ModalOperator(bpy.types.Operator): |
| 484 | + bl_idname = "object.modal_operator" |
| 485 | + bl_label = "Simple Modal Operator" |
| 486 | + |
| 487 | + def __init__(self): |
| 488 | + self.mouse_pos = [0.0, 0.0] |
| 489 | + self.object = None |
| 490 | + self.loc_3d = [0.0, 0.0, 0.0] |
| 491 | + print("Start") |
| 492 | + |
| 493 | + def __del__(self): |
| 494 | + print("End") |
| 495 | + |
| 496 | + def execute(self, context): |
| 497 | + print("location: ", self.loc_3d[0], self.loc_3d[1], self.loc_3d[2]) |
| 498 | + return {'FINISHED'} |
| 499 | + |
| 500 | + def modal(self, context, event): |
| 501 | + if event.type == 'L': # Apply |
| 502 | + print("getting the locations") |
| 503 | + self.loc_3d = [event.mouse_region_x, event.mouse_region_y] |
| 504 | + |
| 505 | + self.object = bpy.context.object |
| 506 | + region = bpy.context.region |
| 507 | + region3D = bpy.context.space_data.region_3d |
| 508 | + #The direction indicated by the mouse position from the current view |
| 509 | + view_vector = view3d_utils.region_2d_to_vector_3d(region, region3D, self.loc_3d) |
| 510 | + #The 3D location in this direction |
| 511 | + self.loc_3d = view3d_utils.region_2d_to_location_3d(region, region3D, self.loc_3d, view_vector) |
| 512 | + #The 3D location converted in object local coordinates |
| 513 | + # self.loc_3d = self.object.matrix_world.inverted() * mouse_loc |
| 514 | + |
| 515 | + InverseKinematics.execute(self, self.loc_3d) |
| 516 | + |
| 517 | + self.execute(context) |
| 518 | + |
| 519 | + elif event.type == 'O': |
| 520 | + print("O pressed") |
| 521 | + return {'FINISHED'} |
| 522 | + elif event.type in {'P'}: # Cancel |
| 523 | + print("P pressed") |
| 524 | + return {'CANCELLED'} |
| 525 | + |
| 526 | + return {'RUNNING_MODAL'} |
| 527 | + |
| 528 | + def invoke(self, context, event): |
| 529 | + if context.area.type == 'VIEW_3D': |
| 530 | + print("Operator invoked") |
| 531 | + args = (self, context) |
| 532 | + # self._handle = bpy.types.SpaceView3D.draw_handler_add(draw_callback_px, args, 'WINDOW', 'POST_PIXEL') |
| 533 | + |
| 534 | + # Keeps mouse position current 3D location and current object for the draw callback |
| 535 | + # (not needed to make self attribute if you don't want to use the callback) |
| 536 | + self.loc_3d = [0, 0] |
| 537 | + |
| 538 | + self.loc_3d = [0, 0, 0] |
| 539 | + |
| 540 | + self.object = context.object |
| 541 | + |
| 542 | + context.window_manager.modal_handler_add(self) |
| 543 | + return {'RUNNING_MODAL'} |
| 544 | + else: |
| 545 | + self.report({'WARNING'}, "View3D not found, cannot run operator") |
| 546 | + return {'CANCELLED'} |
556 | 547 |
|
557 | 548 | # ------------------------------------------------------------------------
|
558 | 549 | # Panel in Object Mode
|
@@ -684,7 +675,7 @@ def parse_conf(self, filepath, context):
|
684 | 675 | def execute(self, context):
|
685 | 676 | filename, extension = os.path.splitext(self.filepath)
|
686 | 677 | self.parse_conf(self.filepath, context)
|
687 |
| - #bpy.ops.object.modal_operator('INVOKE_DEFAULT') |
| 678 | + bpy.ops.object.modal_operator('INVOKE_DEFAULT') |
688 | 679 | return {'FINISHED'}
|
689 | 680 |
|
690 | 681 |
|
|
0 commit comments