Esempio n. 1
0
    def get_intersection(self, ray: Ray, dg: DifferentialGeometry) -> (bool, float):

        # ray from word_space_to_object_space
        ray_o = ray * self.worldToObject

        denominator = Vector3d.dot(self.normal, ray_o.direction)
        if math.fabs(denominator) < CONST_EPSILON:
            return False, 0.0

        o = Vector3d.create_from_point3d(ray_o.origin)

        t = -(Vector3d.dot(self.normal, o) + self.distance) / denominator
        if ray_o.min_t <= t < ray_o.max_t:
            dg.point = ray_o.get_at(t) * self.objectToWorld
            dg.normal = self.normal  * self.objectToWorld
            dg.shape = self
            return True, t
        return False, 0.0
Esempio n. 2
0
    def get_intersection(self, ray: Ray, dg: DifferentialGeometry) -> (bool, float):
        p1_index = self.mesh.index[self.triangle_index*3 + 0]
        p2_index = self.mesh.index[self.triangle_index*3 + 2]
        p3_index = self.mesh.index[self.triangle_index*3 + 1]

        p1 = self.mesh.points[p1_index]
        p2 = self.mesh.points[p2_index]
        p3 = self.mesh.points[p3_index]

        e1 = p2 - p1
        e2 = p3 - p1
        s1 = Vector3d.cross(ray.direction, e2)
        divisor = Vector3d.dot(s1, e1)

        if divisor == 0.0:
            return False, 0.0
        invDivisor = 1.0 / divisor

        # Compute first barycentric coordinate
        d = ray.origin - p1
        b1 = Vector3d.dot(d, s1) * invDivisor
        if b1 < 0.0 or b1 > 1.0:
            return False, 0.0

        #Compute second barycentric coordinate
        s2 = Vector3d.cross(d, e1)
        b2 = Vector3d.dot(ray.direction, s2) * invDivisor
        if b2 < 0.0 or (b1 + b2) > 1.0:
            return False, 0.0

        # Compute _t_ to intersection point
        t = Vector3d.dot(e2, s2) * invDivisor
        if t < ray.min_t or t > ray.max_t:
            return False, 0.0

        dg.shape = self
        dg.point = ray.get_at(t)
        dg.normal = Normal.create_from_vector3d( Vector3d.cross(e1, e2).get_normalized())

        return True, t
Esempio n. 3
0
    def get_intersection(self, ray: Ray, dg: DifferentialGeometry) -> (bool, float):

        # ray from word_space_to_object_space
        ray_o = ray * self.worldToObject

        t0, t1 = self.internal_solve(ray_o, ray)

        if t0 is None and t1 is None:
            return False, 0.0

        if ray_o.min_t <= t0 < ray_o.max_t:
            dg.point = ray_o.get_at(t0) * self.objectToWorld
            # intersection.differentialGeometry.point = ray.get_at(intersection.ray_epsilon)
            # * self.objectToWorld
            # intersection.differentialGeometry.normal = Normal.create_from_point3d(intersection.differentialGeometry.point);

            v = Vector4d(dg.point.x, dg.point.y, dg.point.z, 1.0) * self.worldToObject
            v = Vector3d(v.x, v.y, v.z).get_normalized()
            dg.normal = Normal(v.x, v.y, v.z) * self.objectToWorld
            dg.shape = self
            return True, t0
        return False, 0.0
Esempio n. 4
0
 def get_shading_geometry(self, obj2world: Transform, dg: DifferentialGeometry, dgShading: DifferentialGeometry):
     dgShading.normal = dg.normal
     dgShading.point = dg.point
     dgShading.shape = dg.shape