Exemple #1
0
  def intersects(self,ray,closest=True):
    '''
    Call intersect but return ray as well

    and do hierarchical intersections
    '''
    from PyRatBox import PyRatBox
    import numpy as np
    # transform ray
    transformed_ray = ray.copy()

    try:
      transformed_ray.sourceOfRay = ray.sourceOfRay
    except:
      pass

    try:
      transformed_ray.origin -= self.offset
    except:
      pass

    try:
      transformed_ray.direction = np.array(np.matrix(ray.direction) * self.matrix.T).flatten()
      mod_ray_direction=sqrt(dot(transformed_ray.direction,transformed_ray.direction))
      transformed_ray.direction /= mod_ray_direction
      transformed_ray.origin = np.array(np.matrix(transformed_ray.origin) * self.matrix.T).flatten()
      # to account for scaling effects
      transformed_ray.origin /= (mod_ray_direction*mod_ray_direction)
      transformed_ray.length /= mod_ray_direction
      transformed_ray.tnear /= mod_ray_direction
      transformed_ray.tfar /= mod_ray_direction
      transformed_ray.big /= mod_ray_direction
    except:
      pass
    # with a clone, we are not interested in the intersection other
    # than the transformation we apply
    # contents[0] will always be the contents of a clone as it
    # points to a group which must be a bounding box
    #import pdb;pdb.set_trace()
    hit,thisRay  = PyRatBox.intersects(self.contents[0],transformed_ray,closest=closest)
    if hit:
      try:
        #import pdb;pdb.set_trace()
        thisRay.localNormal = np.array(np.matrix(thisRay.localNormal) * self.matrix).flatten()
        mod = sqrt(dot(thisRay.localNormal,thisRay.localNormal))
        thisRay.localNormal /= mod
      except:
        pass

      try:
        thisRay.length *= self.scale
        thisRay.tnear *= self.scale
        thisRay.tfar *= self.scale
        thisRay.big *= self.scale
      except:
        pass

      try:
        #import pdb;pdb.set_trace()
        #thisRay.length *= mod_ray_direction
        thisRay.origin = ray.origin
        thisRay.direction = ray.direction
      except:
        pass
      ray.ccopy(thisRay)
    return hit,ray
Exemple #2
0
    def intersects(self, ray, closest=True):
        '''
    Call intersect but return ray as well

    and do hierarchical intersections
    '''
        from PyRatBox import PyRatBox
        import numpy as np
        # transform ray
        transformed_ray = ray.copy()

        try:
            transformed_ray.sourceOfRay = ray.sourceOfRay
        except:
            pass

        try:
            transformed_ray.origin -= self.offset
        except:
            pass

        try:
            transformed_ray.direction = np.array(
                np.matrix(ray.direction) * self.matrix.T).flatten()
            mod_ray_direction = sqrt(
                dot(transformed_ray.direction, transformed_ray.direction))
            transformed_ray.direction /= mod_ray_direction
            transformed_ray.origin = np.array(
                np.matrix(transformed_ray.origin) * self.matrix.T).flatten()
            # to account for scaling effects
            transformed_ray.origin /= (mod_ray_direction * mod_ray_direction)
            transformed_ray.length /= mod_ray_direction
            transformed_ray.tnear /= mod_ray_direction
            transformed_ray.tfar /= mod_ray_direction
            transformed_ray.big /= mod_ray_direction
        except:
            pass
        # with a clone, we are not interested in the intersection other
        # than the transformation we apply
        # contents[0] will always be the contents of a clone as it
        # points to a group which must be a bounding box
        #import pdb;pdb.set_trace()
        hit, thisRay = PyRatBox.intersects(self.contents[0],
                                           transformed_ray,
                                           closest=closest)
        if hit:
            try:
                #import pdb;pdb.set_trace()
                thisRay.localNormal = np.array(
                    np.matrix(thisRay.localNormal) * self.matrix).flatten()
                mod = sqrt(dot(thisRay.localNormal, thisRay.localNormal))
                thisRay.localNormal /= mod
            except:
                pass

            try:
                thisRay.length *= self.scale
                thisRay.tnear *= self.scale
                thisRay.tfar *= self.scale
                thisRay.big *= self.scale
            except:
                pass

            try:
                #import pdb;pdb.set_trace()
                #thisRay.length *= mod_ray_direction
                thisRay.origin = ray.origin
                thisRay.direction = ray.direction
            except:
                pass
            ray.ccopy(thisRay)
        return hit, ray