Ejemplo n.º 1
0
  def update_active_flag(self):

    _screens_to_check = self.USER_REPRESENTATION.screens

    ## condition 1: check if tool representation is inside according frustum ##
    _tool_repr_in_frustum = False

    # iterate over every screen of user representation
    for _screen in _screens_to_check:
      _visible = Utilities.is_inside_frustum(POINT = self.get_world_transform().get_translate()
                                           , USER_REPRESENTATION = self.USER_REPRESENTATION
                                           , SCREEN = _screen)

      # if visible in one screen's frustum, the check was successful
      if _visible == True:
        _tool_repr_in_frustum = True
        break

    ## condition 2: check if tool representation intersects according frustum ##
    # implementation will be postponed

    # update active flag
    if _tool_repr_in_frustum != self.active:
      self.active = _tool_repr_in_frustum
      self.TOOL_INSTANCE.handle_correct_visibility_groups_for(self.USER_REPRESENTATION.DISPLAY_GROUP)
  def create_candidate_list(self):
    
    _candidate_list = []
    self.primary_tool_representations = []

    # only go on if a user is assigned to the ray
    if self.assigned_user != None:

      # iterate over all tool representations of the tool
      for _tool_repr in self.tool_representations:

        # do not consider virtual displays that are not visible
        # or inactive tool representations
        if _tool_repr.is_in_virtual_display() and _tool_repr.DISPLAY_GROUP.visible == "False" or \
           _tool_repr.active == False:
          continue

        # do not consider tool representations that have already been considered as primary
        if _tool_repr in self.primary_tool_representations:
          continue

        if _tool_repr.user_id == self.assigned_user.id: # check only tool representations of the assigned user
       
          # compute pick result for current tool representation
          _world_transform = _tool_repr.get_world_transform()
          _mf_pick_result = self.compute_pick_result(_world_transform)
          #_mf_pick_result = self.compute_pick_result2(_tool_repr)

          # if a pick was found
          if len(_mf_pick_result.value) > 0:

            _pick_result = _mf_pick_result.value[0] # get first pick result
            # manually compute world position --> WorldPosition of point clous not correct
            _pick_world_position = _pick_result.Object.value.WorldTransform.value * _pick_result.Position.value
            _pick_world_position = avango.gua.Vec3(_pick_world_position.x, _pick_world_position.y, _pick_world_position.z)
            #_pick_world_position = _pick_result.WorldPosition.value
            #print(_pick_world_position)
            
            # is pick position in frustum of assigned user?
            _user_repr = self.assigned_user.get_user_representation_at(_tool_repr.DISPLAY_GROUP)

            _user_head_world_mat = _user_repr.head.WorldTransform.value
            _user_nav_mat = _user_repr.view_transform_node.Transform.value

            # pick is visible when visible in one of the display group's screens
            #print(_user_repr.screens)
            _visible = False

            for _screen in _user_repr.screens:

              _visible = Utilities.is_inside_frustum(_pick_world_position
                                                   , _user_repr
                                                   , _screen)

              if _visible == True:
                # append to candidate list if visible
                _tool_world_transform = _tool_repr.tool_transform_node.WorldTransform.value

                _intersection_in_nav_space = avango.gua.make_inverse_mat(_tool_world_transform) * \
                                             (avango.gua.make_trans_mat(_pick_world_position) * \
                                             avango.gua.make_scale_mat(_user_nav_mat.get_scale() * -1))

                # if a virtual proxy geometry is hit, just shorten the ray, without adding it to the candidate list
                if "virtual_proxy" in _pick_result.Object.value.GroupNames.value:

                  # if the tool representations intersects a virtual display, the ones of other users
                  # do so as well (when they have the same navigation), so get all tool representations
                  # at display group (as all of them have to be shortened)
                  _tool_reprs_at_display_group = []

                  for _tool_repr_2 in self.tool_representations:
                    if _tool_repr_2.DISPLAY_GROUP == _tool_repr.DISPLAY_GROUP:

                      _ray_length = abs(_intersection_in_nav_space.get_translate().z)
                      _tool_repr_2.hide_intersection_geometry()
                      _tool_repr_2.set_ray_distance(_ray_length)
                      self.primary_tool_representations.append(_tool_repr_2)

                else:

                  _candidate_list.append( (_pick_result, _tool_repr, _intersection_in_nav_space) )

                break

    return _candidate_list