0xrabbyte / TinyRayTracer-Taichi

An implementation of Ray Tracing in One Weekend using Taichi
MIT License
30 stars 4 forks source link

TypeError: unsupported operand type(s) for -: 'SNodeHostAccess' and 'float' #3

Open 13253591602 opened 2 years ago

13253591602 commented 2 years ago

[Taichi] version 0.8.1, llvm 10.0.0, commit cc2dd342, win, python 3.8.13 [Taichi] Starting on arch=cuda 2527 Generated Objects Traceback (most recent call last): File "E:/files/作业/计算机图形学/TinyRayTracer-Taichi/raytracing.py", line 970, in build_bvh_tree(0, world.objects) File "E:/files/作业/计算机图形学/TinyRayTracer-Taichi/raytracing.py", line 508, in build_bvh_tree build_bvh_tree(bvh_tree[u].left, objs[:mid]) File "E:/files/作业/计算机图形学/TinyRayTracer-Taichi/raytracing.py", line 508, in build_bvh_tree build_bvh_tree(bvh_tree[u].left, objs[:mid]) File "E:/files/作业/计算机图形学/TinyRayTracer-Taichi/raytracing.py", line 508, in build_bvh_tree build_bvh_tree(bvh_tree[u].left, objs[:mid]) [Previous line repeated 9 more times] File "E:/files/作业/计算机图形学/TinyRayTracer-Taichi/raytracing.py", line 512, in build_bvh_tree is_hit, box_a = get_bounding_box(objs_id[bvh_tree[u].left], bvh_tree[u].time0, bvh_tree[u].time1) File "E:/files/作业/计算机图形学/TinyRayTracer-Taichi/raytracing.py", line 313, in get_bounding_box return sphere(sphere_centers[objs_ind[id]], sphere_radius[objs_ind[id]], File "D:\software\Anaconda\envs\master\lib\site-packages\taichi\lang\kernel_impl.py", line 99, in decorated return fun.call(args) File "D:\software\Anaconda\envs\master\lib\site-packages\taichi\lang\kernel_impl.py", line 135, in call return self.func(args) File "E:/files/作业/计算机图形学/TinyRayTracer-Taichi/raytracing.py", line 584, in bounding_box return True, AABB(self.center - ti.Vector([self.radius, self.radius, self.radius]), File "D:\software\Anaconda\envs\master\lib\site-packages\taichi\lang\common_ops.py", line 24, in sub return ti.sub(self, other) File "D:\software\Anaconda\envs\master\lib\site-packages\taichi\lang\ops.py", line 74, in wrapped return a.element_wise_binary(imp_foo, b) File "D:\software\Anaconda\envs\master\lib\site-packages\taichi\lang\matrix.py", line 159, in element_wise_binary ret.entries[i] = foo(self.entries[i], other.entries[i]) File "D:\software\Anaconda\envs\master\lib\site-packages\taichi\lang\ops.py", line 63, in imp_foo return foo(x, y) File "D:\software\Anaconda\envs\master\lib\site-packages\taichi\lang\ops.py", line 441, in sub return _binary_operation(_ti_core.expr_sub, _bt_ops_mod.sub, a, b) File "D:\software\Anaconda\envs\master\lib\site-packages\taichi\lang\ops.py", line 176, in _binary_operation return python_op(a, b) TypeError: unsupported operand type(s) for -: 'SNodeHostAccess' and 'float'

0xrabbyte commented 2 years ago

看起来是由于Vector与实数进行了减法而报错

我这里无法复现此错误,可能是由于对gen_objects()此函数中对于球体的定义(球心坐标定义成实数?)改写错了?

当然非常建议将Taichi版本升级至v1.0.0及以上,便可以方便地使用vec3()等函数,可以优雅地避免此错误。当然由此引起的修改可能很多,欢迎pr!😆