コード例 #1
0
ファイル: triangle.py プロジェクト: neodyme60/raypy
    def Sample1(self, u: (float, float), n: Normal) -> Point3d:
        b1, b2 = UniformSampleTriangle(u)
        # Get triangle vertices in _p1_, _p2_, and _p3_
        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]

        p = p1 * b1 + p2 * b2 + p3 * (1.0 - b1 - b2)
        n.Set(Normal.create_from_vector3d(Vector3d.cross(p2-p1, p3-p1)).get_normalized())
#todo        if (ReverseOrientation) *Ns *= -1.f;
        return p
コード例 #2
0
ファイル: triangle.py プロジェクト: neodyme60/raypy
    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
コード例 #3
0
ファイル: point_light.py プロジェクト: neodyme60/raypy
 def Sample_L2(self, scene: Scene, ls: LightSample, u: (float, float), n: Normal, ray: Ray, time: float) -> (
         Spectrum, float):
     ray = Ray(self.lightPos, UniformSampleSphere(ls.uPos), 0.0, infinity_max_f, time)
     n.Set(Normal.create_from_vector3d(ray.direction))
     return self.intensity, UniformSpherePdf()