def intersect(self, ray, intersection): """Compute an intersection.""" w2p = self.world_to_primitive.interpolate(ray.time) ray_primitive = w2p(ray) intersection = Intersection() if not self.primitive.intersect(ray_primitive, intersection): return False ray.maxt = ray_primitive.maxt intersection.primitive_id = self.primitive_id if not w2p.is_identity(): # Compute world-to-object transformation for instance intersection.world_to_object = intersection.world_to_object * w2p intersection.object_to_world = inverse( intersection.world_to_object) p2w = inverse(w2p) # Transform instance's differential geometry to world space intersection.dg.p = p2w(intersection.dg.p) intersection.dg.nn = normalize(p2w(intersection.dg.nn)) intersection.dg.dpdu = p2w(intersection.dg.dp_du) intersection.dg.dpdv = p2w(intersection.dg.dp_dv) intersection.dg.dndu = p2w(intersection.dg.dn_du) intersection.dg.dndv = p2w(intersection.dg.dn_dv) return True
def from_intersection(cls, p, dp_du, dp_dv, dn_du, dn_dv, uu, vv, shape=None): """Construct a DifferentialGeometry instance. Arguments: p : Point dp_du : Vector dp_dv : Vector dn_du : Normal dn_dv : Normal uu : float vv : float shape : optional Shape """ # call default constructor diff_geom = cls() diff_geom.p = p diff_geom.dp_du = dp_du diff_geom.dp_dv = dp_dv diff_geom.dn_du = dn_du diff_geom.dn_dv = dn_dv diff_geom.nn = Normal.from_vector(normalize(cross(dp_du, dp_dv))) diff_geom.u = uu diff_geom.v = vv diff_geom.shape = shape if shape and \ (shape.reverse_orientation ^ shape.transform_swap_handedness): diff_geom.nn *= -1.0 return diff_geom
def intersect(self, ray, intersection): """Compute an intersection.""" w2p = self.world_to_primitive.interpolate(ray.time) ray_primitive = w2p(ray) intersection = Intersection() if not self.primitive.intersect(ray_primitive, intersection): return False ray.maxt = ray_primitive.maxt intersection.primitive_id = self.primitive_id if not w2p.is_identity(): # Compute world-to-object transformation for instance intersection.world_to_object = intersection.world_to_object * w2p intersection.object_to_world = inverse(intersection.world_to_object) p2w = inverse(w2p) # Transform instance's differential geometry to world space intersection.dg.p = p2w(intersection.dg.p) intersection.dg.nn = normalize(p2w(intersection.dg.nn)) intersection.dg.dpdu = p2w(intersection.dg.dp_du) intersection.dg.dpdv = p2w(intersection.dg.dp_dv) intersection.dg.dndu = p2w(intersection.dg.dn_du) intersection.dg.dndv = p2w(intersection.dg.dn_dv) return True