Skip to content

Commit

Permalink
Merge pull request #2 from zhenyatos/2-fill-texcoords
Browse files Browse the repository at this point in the history
fill texcoord field for Vertex and HitRecord classes
  • Loading branch information
zhenyatos authored Feb 2, 2021
2 parents 7c6e536 + 799e654 commit 2b71f3c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions pyrt/geometry/sphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def hit(self, ray: Ray, hitrecord: HitRecord) -> bool:
hitrecord.normal = hitrecord.normal_g
hitrecord.color = Vec3(1., 1., 1.) # spheres don't have interpolated colors, set to white
hitrecord.material = self.material
hitrecord.texcoord = self.calcTexcoord(hitrecord.point)
return True
return False

Expand Down
4 changes: 3 additions & 1 deletion pyrt/geometry/triangle.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,10 @@ def hit(self, ray: Ray, hitrecord: HitRecord) -> bool:
cV = self.c.color - self.a.color
hitrecord.color = self.a.color + cU * u + cV * v
hitrecord.material = self.material
hitrecord.texcoord = self.calcTexcoord(hitrecord.point)

hitrecord.point = ray.start + t * ray.direction
# why would we?
# hitrecord.point = ray.start + t * ray.direction

return True

Expand Down
8 changes: 5 additions & 3 deletions pyrt/geometry/vertex.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,13 @@ def __init__(self, **kwargs):
else:
raise ValueError("color must be specified as Vec3 or list/tuple with 3 components")

'''
if "texcoord" in kwargs:
if type(kwargs["texcoord"]) == Vec2:
pass
self.texcoord = kwargs["texcoord"].copy()
elif type(kwargs["texcoord"]) == tuple or type(kwargs["texcoord"]) == list:
if len(kwargs["texcoord"]) == 2:
self.texcoord = Vec2(kwargs["texcoord"][0], kwargs["texcoord"][1])
else:
raise ValueError("Wrong number of components for texcoord")
else:
raise ValueError("position must be specified as Vec2 or list/tuple")
'''

0 comments on commit 2b71f3c

Please sign in to comment.