Esempio n. 1
0
    def invoke(self, context, event):
        if context.area.type == 'VIEW_3D':
            # the arguments we pass the the callback
            args = (self, context)
            # Add the region OpenGL drawing callback
            self._timer = context.window_manager.event_timer_add(.1, context.window)  #bpy.types.WindoManager.event_time_add?
            self._handle = bpy.types.SpaceView3D.draw_handler_add(bgl_utils.draw_callback_crevice_walking, args, 'WINDOW', 'POST_PIXEL')

            #initialze important values and gather important info
            region = context.region  
            rv3d = context.space_data.region_3d
            coord = event.mouse_region_x, event.mouse_region_y
            
            self.tracer_name = context.object.name #adding bpy here because getting weird error
            self.target_name = [ob.name for ob in context.selected_editable_objects if ob.name != self.tracer_name][0]
            
            tracer = bpy.data.objects[self.tracer_name]
            target = bpy.data.objects[self.target_name]
            
            #target.select = False
            tracer.select = True
            context.scene.objects.active = tracer
            
            #mod = tracer.modifers['Shrinkwrap']  #going to need to do some checking for dumb scenarios
            #self.target = mod.target
                      
            vec = view3d_utils.region_2d_to_vector_3d(region, rv3d, coord)
            ray_origin = view3d_utils.region_2d_to_location_3d(region, rv3d, coord, vec)    
    
            #raycast onto active object
            ray_target = ray_origin + 10000*vec
            [hit, normal, face] = odcutils.obj_ray_cast(target, target.matrix_world, ray_origin, ray_target)
            
            self.max_iters = 50
            self.keep_iterating = False  #turn this off/on when we get convergence on the bias point or add a new bias point
            self.session_iterations = 0
            
            if hit:
                self.current_bias_point = target.matrix_world * hit
            else:
                self.current_bias_point = target.location
            
            
            self.confirmed_path = []
            self.pending_path = [tracer.location.copy()]
            self.bias_points = []
            self.bias_normals = []  #gotta keep track of the normals so we can re-orient the tracker pointed the right way
            
            self.step_size = .5
            self.convergence_limit = 5
            

            

            context.window_manager.modal_handler_add(self)
            return {'RUNNING_MODAL'}
        else:
            self.report({'WARNING'}, "View3D not found, cannot run operator")
            return {'CANCELLED'}
Esempio n. 2
0
    def invoke(self, context, event):
        if context.area.type == 'VIEW_3D':
            # the arguments we pass the the callback
            args = (self, context)
            # Add the region OpenGL drawing callback
            self._timer = context.window_manager.event_timer_add(
                .1, context.window)  #bpy.types.WindoManager.event_time_add?
            self._handle = bpy.types.SpaceView3D.draw_handler_add(
                bgl_utils.draw_callback_crevice_walking, args, 'WINDOW',
                'POST_PIXEL')

            #initialze important values and gather important info
            region = context.region
            rv3d = context.space_data.region_3d
            coord = event.mouse_region_x, event.mouse_region_y

            self.tracer_name = context.object.name  #adding bpy here because getting weird error
            self.target_name = [
                ob.name for ob in context.selected_editable_objects
                if ob.name != self.tracer_name
            ][0]

            tracer = bpy.data.objects[self.tracer_name]
            target = bpy.data.objects[self.target_name]

            #target.select = False
            tracer.select = True
            context.scene.objects.active = tracer

            #mod = tracer.modifiers['Shrinkwrap']  #going to need to do some checking for dumb scenarios
            #self.target = mod.target

            vec = view3d_utils.region_2d_to_vector_3d(region, rv3d, coord)
            ray_origin = view3d_utils.region_2d_to_location_3d(
                region, rv3d, coord, vec)

            #raycast onto active object
            ray_target = ray_origin + 10000 * vec
            [hit, normal,
             face] = odcutils.obj_ray_cast(target, target.matrix_world,
                                           ray_origin, ray_target)

            self.max_iters = 50
            self.keep_iterating = False  #turn this off/on when we get convergence on the bias point or add a new bias point
            self.session_iterations = 0

            if hit:
                self.current_bias_point = target.matrix_world * hit
            else:
                self.current_bias_point = target.location

            self.confirmed_path = []
            self.pending_path = [tracer.location.copy()]
            self.bias_points = []
            self.bias_normals = [
            ]  #gotta keep track of the normals so we can re-orient the tracker pointed the right way

            self.step_size = .5
            self.convergence_limit = 5

            context.window_manager.modal_handler_add(self)
            return {'RUNNING_MODAL'}
        else:
            self.report({'WARNING'}, "View3D not found, cannot run operator")
            return {'CANCELLED'}
Esempio n. 3
0
    def modal(self, context, event):
        context.area.tag_redraw()

        
        if event.type in {'MIDDLEMOUSE','WHELLUPMOUSE','WHEELDOWNMOUSE'}:
            #let the user pan and rotate around (translate?)
            return {'PASS_THROUGH'}
        
        if event.type == 'TIMER':
            #iterate....check convergence.
            if self.keep_iterating:
                self.iterate(context)

            return {'PASS_THROUGH'}
        
        elif event.type == 'MOUSEMOVE':
            #change the active bias
            region = context.region  
            rv3d = context.space_data.region_3d
            coord = event.mouse_region_x, event.mouse_region_y
            vec = view3d_utils.region_2d_to_vector_3d(region, rv3d, coord)
            ray_origin = view3d_utils.region_2d_to_location_3d(region, rv3d, coord, vec)  - 5000*vec  
            target = bpy.data.objects[self.target_name]
            #raycast onto active object
            ray_target = ray_origin + 5000*vec
            [hit, normal, face] = odcutils.obj_ray_cast(target, target.matrix_world, ray_origin, ray_target)
            
            if hit:
                self.current_bias_point = target.matrix_world * hit

            '''
            if not self.keep_iterating:
                self.bias_point = (event.mouse_region_x, event.mouse_region_y)
                self.keep_iterating = True
            '''
        
        elif event.type == 'LEFTMOUSE' and event.value == "PRESS":
            #confirm the existing walking cache
            
            #if continue_iterating still true, append the last confirmed point to the bias points
            #change the active bias
            region = context.region  
            rv3d = context.space_data.region_3d
            coord = event.mouse_region_x, event.mouse_region_y
            target = bpy.data.objects[self.target_name]
            vec = view3d_utils.region_2d_to_vector_3d(region, rv3d, coord)
            ray_origin = view3d_utils.region_2d_to_location_3d(region, rv3d, coord, vec)    
    
            #raycast onto active object
            ray_target = ray_origin + 3000*vec
            [hit, normal, face] = odcutils.obj_ray_cast(target, target.matrix_world, ray_origin, ray_target)
            
            if hit:
                self.bias_points.append(target.matrix_world * hit)
                
            #keep iterating to mouse projection on model
            self.keep_iterating = not self.keep_iterating
            return {'RUNNING_MODAL'}

        elif event.type == 'RIGHTMOUSE' and event.value == "PRESS":
            #pop off a bias point
            self.bias_points.pop()
            #pop off a bias normal
            
            #pop off stack of confirmed crevice points prior to that
                        #keep iterating to mouse projection on model
            self.keep_iterating = not self.keep_iterating
            return {'RUNNING_MODAL'}


        elif event.type in {'ESC'}:
            context.window_manager.event_timer_remove(self._timer)
            bpy.types.SpaceView3D.draw_handler_remove(self._handle, 'WINDOW')
            return {'CANCELLED'}

        elif event.type in {'RETURN'}:
            context.window_manager.event_time_remove(self._timer)
            bpy.types.SpaceView3D.draw_handler_remove(self._handle, 'WINDOW')
            return {'CANCELLED'}

        return {'RUNNING_MODAL'}
Esempio n. 4
0
    def modal(self, context, event):
        context.area.tag_redraw()

        if event.type in {'MIDDLEMOUSE', 'WHELLUPMOUSE', 'WHEELDOWNMOUSE'}:
            #let the user pan and rotate around (translate?)
            return {'PASS_THROUGH'}

        if event.type == 'TIMER':
            #iterate....check convergence.
            if self.keep_iterating:
                self.iterate(context)

            return {'PASS_THROUGH'}

        elif event.type == 'MOUSEMOVE':
            #change the active bias
            region = context.region
            rv3d = context.space_data.region_3d
            coord = event.mouse_region_x, event.mouse_region_y
            vec = view3d_utils.region_2d_to_vector_3d(region, rv3d, coord)
            ray_origin = view3d_utils.region_2d_to_location_3d(
                region, rv3d, coord, vec) - 5000 * vec
            target = bpy.data.objects[self.target_name]
            #raycast onto active object
            ray_target = ray_origin + 5000 * vec
            [hit, normal,
             face] = odcutils.obj_ray_cast(target, target.matrix_world,
                                           ray_origin, ray_target)

            if hit:
                self.current_bias_point = target.matrix_world * hit
            '''
            if not self.keep_iterating:
                self.bias_point = (event.mouse_region_x, event.mouse_region_y)
                self.keep_iterating = True
            '''

        elif event.type == 'LEFTMOUSE' and event.value == "PRESS":
            #confirm the existing walking cache

            #if continue_iterating still true, append the last confirmed point to the bias points
            #change the active bias
            region = context.region
            rv3d = context.space_data.region_3d
            coord = event.mouse_region_x, event.mouse_region_y
            target = bpy.data.objects[self.target_name]
            vec = view3d_utils.region_2d_to_vector_3d(region, rv3d, coord)
            ray_origin = view3d_utils.region_2d_to_location_3d(
                region, rv3d, coord, vec)

            #raycast onto active object
            ray_target = ray_origin + 3000 * vec
            [hit, normal,
             face] = odcutils.obj_ray_cast(target, target.matrix_world,
                                           ray_origin, ray_target)

            if hit:
                self.bias_points.append(target.matrix_world * hit)

            #keep iterating to mouse projection on model
            self.keep_iterating = not self.keep_iterating
            return {'RUNNING_MODAL'}

        elif event.type == 'RIGHTMOUSE' and event.value == "PRESS":
            #pop off a bias point
            self.bias_points.pop()
            #pop off a bias normal

            #pop off stack of confirmed crevice points prior to that
            #keep iterating to mouse projection on model
            self.keep_iterating = not self.keep_iterating
            return {'RUNNING_MODAL'}

        elif event.type in {'ESC'}:
            context.window_manager.event_timer_remove(self._timer)
            bpy.types.SpaceView3D.draw_handler_remove(self._handle, 'WINDOW')
            return {'CANCELLED'}

        elif event.type in {'RETURN'}:
            context.window_manager.event_time_remove(self._timer)
            bpy.types.SpaceView3D.draw_handler_remove(self._handle, 'WINDOW')
            return {'CANCELLED'}

        return {'RUNNING_MODAL'}