def generate_planes(n): dyn_array = util.DynamicArray(Plane.struct()) planes = [] for x in range(n): plane = Plane.generate_plane() dyn_array.add_instance(plane.struct_params()) planes.append(plane) return planes, dyn_array
def generate_plane(): x = random.random() * 10.0 y = random.random() * 10.0 z = random.random() * 10.0 dir_x = random.random() * 10.0 - 5.0 dir_y = random.random() * 10.0 - 5.0 dir_z = random.random() * 10.0 - 5.0 point = Vector3(x, y, z) normal = Vector3(dir_x, dir_y, dir_z) normal.normalize() plane = Plane(point, normal, 3) return plane
hit_point = None for s in objs: hit = s.intersect(ray, min_dist) if hit is False: continue if hit.t < min_dist: min_dist = hit.t hit_point = hit return hit_point if __name__ == "__main__": asm = util.get_asm() mc = asm.assemble(ASM) #mc.print_machine_code() runtime = Runtime() Plane.intersect_asm(runtime, "_plane_intersect") intersect_ray_shape_array("plane", runtime, "plane_array", "_plane_intersect") ds = runtime.load("test", mc) planes, dyn_planes = generate_planes(10000) ray = generate_ray() hp = ray_objects(ray, planes) adr = dyn_planes.get_addr() ds["ptr_planes"] = adr ds["nplanes"] = dyn_planes.size ds["r1.origin"] = v4(ray.origin) ds["r1.dir"] = v4(ray.dir)
hp = isect(ray, shape_db.shapes()) hp2 = isect_ray_scene(ray) asm = util.get_asm() dy_spheres = shape_db.asm_shapes[Sphere] dy_planes = shape_db.asm_shapes[Plane] #ds["r1.origin"] = v4(ray.origin) #ds["r1.dir"] = v4(ray.dir) runtime = Runtime() Sphere.intersect_asm(runtime, "_sphere_intersect") intersect_ray_shape_array("sphere", runtime, "sphere_array", "_sphere_intersect") Plane.intersect_asm(runtime, "_plane_intersect") intersect_ray_shape_array("plane", runtime, "plane_array", "_plane_intersect") mc = asm.assemble(ASM) ds = runtime.load("test", mc) ds["r1.origin"] = v4(ray.origin) ds["r1.dir"] = v4(ray.dir) ds["ptr_spheres"] = dy_spheres.get_addr() ds["nspheres"] = dy_spheres.size ds["ptr_planes"] = dy_planes.get_addr() ds["nplanes"] = dy_planes.size #runtime.run("test") t = timeit.Timer(lambda : runtime.run("test"))
origin = Vector3(x, y, z) direction = Vector3(dir_x, dir_y, dir_z) direction.normalize() ray = Ray(origin, direction) return ray def v4(v3): return (v3.x, v3.y, v3.z, 0.0) if __name__ == "__main__": asm = util.get_asm() mc = asm.assemble(ASM) #mc.print_machine_code() runtime = Runtime() Plane.intersectbool_asm(runtime, "_plane_intersect") ds = runtime.load("test", mc) for x in range(100000): #pl = generate_plane() pl = Plane.generate_plane() ray = generate_ray() ds["r1.origin"] = v4(ray.origin) ds["r1.dir"] = v4(ray.dir) ds["p1.point"] = v4(pl.point) ds["p1.normal"] = v4(pl.normal) ds["p1.mat_index"] = pl.material h = pl.intersect(ray)
origin = Vector3(x, y, z) direction = Vector3(dir_x, dir_y, dir_z) direction.normalize() ray = Ray(origin, direction) return ray def v4(v3): return (v3.x, v3.y, v3.z, 0.0) if __name__ == "__main__": asm = util.get_asm() mc = asm.assemble(ASM) #mc.print_machine_code() runtime = Runtime() Plane.intersect_asm(runtime, "_plane_intersect") ds = runtime.load("test", mc) for x in range(100000): #pl = generate_plane() pl = Plane.generate_plane() ray = generate_ray() ds["r1.origin"] = v4(ray.origin) ds["r1.dir"] = v4(ray.dir) ds["p1.point"] = v4(pl.point) ds["p1.normal"] = v4(pl.normal) h = pl.intersect(ray) runtime.run("test")