def create_shape_sphere(paramset: ParamSet, object2world: Transform, world2object: Transform) -> Sphere: radius = paramset.find_float("radius", 1.0) zmin = paramset.find_float("zmin", -radius) zmax = paramset.find_float("zmax", radius) phimax = paramset.find_float("phimax", 360.0) shape = Sphere(object2world, world2object, radius, zmin, zmax, phimax) return shape
def create_diffuse_area_light(light2world: Transform, paramSet: ParamSet, shape: Shape): L = paramSet.find_spectrum("L", Spectrum(1.0)) sc = paramSet.find_spectrum("scale", Spectrum(1.0)) nSamples = paramSet.find_int("nsamples", 1) # if renderOptions.quickRender: # nSamples = max(1, nSamples / 4) return DiffuseAreaLight(light2world, L * sc, nSamples, shape)
def create_sampler_stratified(paramset: ParamSet, film: Film, camera: Camera) -> StratifiedSampler: jitter = paramset.find_bool("jitter", True) xsamples = paramset.find_int("xsamples", 2) ysamples = paramset.find_int("ysamples", 2) sampler = StratifiedSampler(BucketExtend(0, 0, film.width - 1, film.height - 1), xsamples, ysamples, jitter, camera.shutterOpen, camera.shutterClose) return sampler
def create_shape_triangle_mesh(paramset: ParamSet, object2world: Transform, world2object: Transform) -> TriangleMesh: shape = TriangleMesh( object2world, world2object, paramset.find_points("P"), paramset.find_ints("indices"), None, None ) return shape
def create_perspective_camera(paramset: ParamSet, cam2world: Transform, film: Film) -> PerspectiveCamera: shutteropen = paramset.find_float("shutteropen", 0.0) shutterclose = paramset.find_float("shutterclose", 1.0) if shutterclose < shutteropen: shutterclose, shutteropen = shutteropen, shutterclose lensradius = paramset.find_float("lensradius", 0.0) focaldistance = paramset.find_float("focaldistance", 1e30) frame = paramset.find_float("frameaspectratio", float(film.width) / float(film.height)) fov = paramset.find_float("fov", 90.0) halffov = paramset.find_float("halffov", -1.0) if halffov > 0.0: # hack for structure synth, which exports half of the full fov fov = 2.0 * halffov screen_window = [float] * 4 if frame > 1.0: screen_window[0] = -frame screen_window[1] = frame screen_window[2] = -1.0 screen_window[3] = 1.0 else: screen_window[0] = -1.0 screen_window[1] = 1.0 screen_window[2] = -1.0 / frame screen_window[3] = 1.0 / frame camera = PerspectiveCamera(cam2world, screen_window, shutteropen, shutterclose, lensradius, focaldistance, fov, film) return camera
def create_spotLight(paramSet: ParamSet, light2world: Transform) -> PointLight: from maths.matrix44 import Matrix44 from maths.vector4d import Vector4d I = paramSet.find_spectrum("I", Spectrum(1.0)) sc = paramSet.find_spectrum("scale", Spectrum(1.0)) coneangle = paramSet.find_float("coneangle", 30.0) conedelta = paramSet.find_float("conedeltaangle", 5.0) # Compute spotlight world to light transformation frome = paramSet.find_point("from", Point3d(0.0, 0.0, 0.0)) to = paramSet.find_point("to", Point3d(0.0, 0.0, 1.0)) direction = (to - frome).get_normalized() du, dv = Transform.create_coordinateSystem(dir) m = Matrix44.create_from_vector4d( Vector4d(du.x, du.y, du.z, 0.0), Vector4d(dv.x, dv.y, dv.z, 0.0), Vector4d(direction.x, direction.y, direction.z, 0.0), Vector4d(0.0, 0.0, 0.0, 1.0)) dirToZ = Transform(m) light2world = light2world * Transform.create_translate(frome.ex, frome.ey, frome.ez) * dirToZ.get_invert() return SpotLight(light2world, I * sc, coneangle, coneangle - conedelta)
def create_film_image(paramset: ParamSet, filter: Filter) -> Film: w = paramset.find_int("xresolution", 640) h = paramset.find_int("yresolution", 480) return Film(w, h)
def create_sampler_random(paramset: ParamSet, film: Film, camera: Camera) -> RandomSampler: samples = paramset.find_int("pixelsamples", 1) sampler = RandomSampler(BucketExtend(0, 0, film.width - 1, film.height - 1), samples, camera.shutterOpen, camera.shutterClose) return sampler
def create_aggregator_grid(primitives: [Primitive], paramset: ParamSet) -> UniformGrid: refine_immediately = paramset.find_bool("refineimmediately", True) grid = UniformGrid(primitives, refine_immediately) return grid
def create_surface_integrator_path(paramset: ParamSet) -> DirectLightingIntegrator: samples_count = paramset.find_int("maxdepth", 2) integrator = PathIntegrator(samples_count) return integrator
def create_surface_integrator_direct_lighting(paramset: ParamSet) -> DirectLightingIntegrator: samples_count = paramset.find_int("nsamples", 2048) max_distance = paramset.find_float("maxdist", infinity_max_f) #todo depth etc integrator = DirectLightingIntegrator(samples_count, max_distance) return integrator
def create_surface_integrator_ambient_occlusion(paramset: ParamSet) -> AmbientOcclusionIntegrator: samples_count = paramset.find_int("nsamples", 2048) max_distance = paramset.find_float("maxdist", infinity_max_f) integrator = AmbientOcclusionIntegrator(samples_count, max_distance) return integrator
def create_projection_light(paramSet: ParamSet, light2world: Transform) -> PointLight: I = paramSet.find_spectrum("I", Spectrum(1.0)) sc = paramSet.find_spectrum("scale", Spectrum(1.0)) fov = paramSet.find_float("fov", 45.) texname = paramSet.find_filename("mapname", "") return ProjectionLight(light2world, I * sc, texname, fov)
def create_light_point(paramSet: ParamSet, light2world: Transform) -> PointLight: I = paramSet.find_spectrum("I", Spectrum(1.0)) sc = paramSet.find_spectrum("scale", Spectrum(1.0)) P = paramSet.find_point("from", Point3d(0.0, 0.0, 0.0)) l2w = Transform.create_translate(P.x, P.y, P.z) * light2world return PointLight(l2w, I * sc)
def __init__(self): super(pbrtListener, self).__init__() self.currentParamSet = ParamSet() self.name = None
class PbrtLoader(pbrtListener): def __init__(self): super(pbrtListener, self).__init__() self.currentParamSet = ParamSet() self.name = None # Enter a parse tree produced by pbrtParser#film. def enterFilm(self, ctx): print("enter film") self.currentParamSet.reset() self.name = str(ctx.STRING()).replace('"', '') # Exit a parse tree produced by pbrtParser#film. def exitFilm(self, ctx): print("exit film") pbrtFilm(self.name, self.currentParamSet) # Enter a parse tree produced by pbrtParser#pixelFilter. def enterPixelFilter(self, ctx): print("enter pixel filter") self.currentParamSet.reset() self.name = str(ctx.STRING()).replace('"', '') # Exit a parse tree produced by pbrtParser#pixelFilter. def exitPixelFilter(self, ctx): print("exit pixel filter") pbrtPixelFilter(self.name, self.currentParamSet) # Enter a parse tree produced by pbrtParser#paramset. def enterParamSet(self, ctx): print("enter paramset") p = ctx.paramSetLeft() a = str(p.STRING()).replace('"', '').split(' ') param_type = a[0] param_name = a[1] print("-->" + param_name) if param_type == 'point': print("-->point") i = 0 values = [] while True: if ctx.NUMBER(i) is None: break values.append( Point3d(float(str(ctx.NUMBER(i))), float(str(ctx.NUMBER(i + 1))), float(str(ctx.NUMBER(i + 2))))) i += 3 self.currentParamSet.add_point(param_name, values) elif param_type == 'float': print("-->float") i = 0 values = [] while True: if ctx.NUMBER(i) is None: break values.append(float(str(ctx.NUMBER(i)))) i += 1 self.currentParamSet.add_float(param_name, values) elif param_type == 'integer': print("-->int") i = 0 values = [] while True: if ctx.NUMBER(i) is None: break values.append(int(str(ctx.NUMBER(i)))) i += 1 self.currentParamSet.add_int(param_name, values) elif param_type == 'string': print("-->string") i = 0 values = [] while True: if ctx.STRING(i) is None: break values.append(str(ctx.STRING(i)).replace("\"", "")) i += 1 if len(values) == 1: self.currentParamSet.add_string(param_name, values[0]) else: self.currentParamSet.add_string(param_name, values) elif param_type == 'color': print("-->color") i = 0 values = [] while True: if ctx.NUMBER(i) is None: break values.append(float(str(ctx.NUMBER(i)))) i += 1 self.currentParamSet.add_spectrum(param_name, Spectrum.create_from_array(values)) # key = str(ctx.STRING(0)) # if ctx.STRING(1) is not None: # value = str(ctx.STRING(1)) # elif ctx.INT() is not None: # value = ctx.INT() # elif ctx.FLOAT() is not None: # value = ctx.FLOAT() # print("->("+ str(key)+","+str(value)+")") # Exit a parse tree produced by pbrtParser#paramset. def exitParamSet(self, ctx): print("exit paramset") # Enter a parse tree produced by pbrtParser#lookAt. def enterLookAt(self, ctx): print("enter look at") e = Vector3d(float(str(ctx.vector3(0).NUMBER(0))), float(str(ctx.vector3(0).NUMBER(1))), float(str(ctx.vector3(0).NUMBER(2)))) l = Vector3d(float(str(ctx.vector3(1).NUMBER(0))), float(str(ctx.vector3(1).NUMBER(1))), float(str(ctx.vector3(1).NUMBER(2)))) u = Vector3d(float(str(ctx.vector3(2).NUMBER(0))), float(str(ctx.vector3(2).NUMBER(1))), float(str(ctx.vector3(2).NUMBER(2)))) pbrtLookAt(e, l, u) # Exit a parse tree produced by pbrtParser#lookAt. def exitLookAt(self, ctx): print("exit look at") # Enter a parse tree produced by pbrtParser#program. def enterProgram(self, ctx): pass # Exit a parse tree produced by pbrtParser#program. def exitProgram(self, ctx): pass # Enter a parse tree produced by pbrtParser#camera. def enterCamera(self, ctx): print("enter camera") self.currentParamSet.reset() self.name = str(ctx.STRING()).replace('"', '') # Exit a parse tree produced by pbrtParser#camera. def exitCamera(self, ctx): print("exit camera") pbrtCamera(self.name, self.currentParamSet) # Enter a parse tree produced by pbrtParser#surfaceIntegrator. def enterSurfaceIntegrator(self, ctx): print("enter surface surface_integrator") self.currentParamSet.reset() self.name = str(ctx.STRING()).replace('"', '') # Exit a parse tree produced by pbrtParser#surfaceIntegrator. def exitSurfaceIntegrator(self, ctx): print("exit surface surface_integrator") pbrtSurfaceIntegrator(self.name, self.currentParamSet) # Enter a parse tree produced by pbrtParser#vector3. def enterVector3(self, ctx): print("enter vector3") # Exit a parse tree produced by pbrtParser#vector3. def exitVector3(self, ctx): print("exit vector3") # Enter a parse tree produced by pbrtParser#sampler. def enterSampler(self, ctx): print("enter sampler") self.currentParamSet.reset() self.name = str(ctx.STRING()).replace('"', '') # Exit a parse tree produced by pbrtParser#sampler. def exitSampler(self, ctx): print("exit sampler") pbrtSampler(self.name, self.currentParamSet) # Enter a parse tree produced by pbrtParser#body. def enterBody(self, ctx): pass # Exit a parse tree produced by pbrtParser#body. def exitBody(self, ctx): pass # Enter a parse tree produced by pbrtParser#scale. def enterScale(self, ctx): print("enter scale blok") print("enter translate block") a = float(str(ctx.NUMBER(0))) b = float(str(ctx.NUMBER(1))) c = float(str(ctx.NUMBER(2))) pbrtScale(a, b, c) # Exit a parse tree produced by pbrtParser#scale. def exitScale(self, ctx): print("exit scale") pass # Enter a parse tree produced by pbrtParser#rotate. def enterRotate(self, ctx): print("enter rotate") pass # Exit a parse tree produced by pbrtParser#rotate. def exitRotate(self, ctx): print("exit rotate") pass # Enter a parse tree produced by pbrtParser#transform. def enterTransform(self, ctx): print("enter transform") pass # Exit a parse tree produced by pbrtParser#transform. def exitTransform(self, ctx): print("exit transform") pass # Enter a parse tree produced by pbrtParser#lightSource. def enterLightSource(self, ctx): print("enter lightsource lock") self.currentParamSet.reset() self.name = str(ctx.STRING()).replace('"', '') # Exit a parse tree produced by pbrtParser#lightSource. def exitLightSource(self, ctx): print("exit lightsource lock") pbrtLightSource(self.name, self.currentParamSet) # Enter a parse tree produced by pbrtParser#transformBlock. def enterTransformBlock(self, ctx): print("enter trnasform block") pbrtTransformBegin() # Exit a parse tree produced by pbrtParser#transformBlock. def exitTransformBlock(self, ctx): print("exit ternasform block") pbrtTransformEnd() # Enter a parse tree produced by pbrtParser#texture. def enterTexture(self, ctx): print("enter texture block") self.currentParamSet.reset() self.name = str(ctx.STRING()).replace('"', '') # Exit a parse tree produced by pbrtParser#texture. def exitTexture(self, ctx): print("exit texture block") pbrtTexture(self.name, self.currentParamSet) # Enter a parse tree produced by pbrtParser#accelerator. def enterAccelerator(self, ctx): print("enter accelerator block") self.currentParamSet.reset() self.name = str(ctx.STRING()).replace('"', '') # Exit a parse tree produced by pbrtParser#accelerator. def exitAccelerator(self, ctx): print("exit accelerator block") pbrtAccelerator(self.name, self.currentParamSet) # Enter a parse tree produced by pbrtParser#areaLightSource. def enterAreaLightSource(self, ctx): self.currentParamSet.reset() self.name = str(ctx.STRING()).replace('"', '') # Exit a parse tree produced by pbrtParser#areaLightSource. def exitAreaLightSource(self, ctx): pbrtAreaLightSource(self.name, self.currentParamSet) # Enter a parse tree produced by pbrtParser#shape. def enterShape(self, ctx): print("enter shape block") self.currentParamSet.reset() self.name = str(ctx.STRING()).replace('"', '') # Exit a parse tree produced by pbrtParser#shape. def exitShape(self, ctx): print("exit shape block") pbrtShape(self.name, self.currentParamSet) # Enter a parse tree produced by pbrtParser#material. def enterMaterial(self, ctx): print("enter material block") self.currentParamSet.reset() self.name = str(ctx.STRING()).replace('"', '') # Exit a parse tree produced by pbrtParser#material. def exitMaterial(self, ctx): print("exit material block") pbrtMaterial(self.name, self.currentParamSet) # Enter a parse tree produced by pbrtParser#namedmaterial. def enterNamedmaterial(self, ctx): print("enter named material block") self.currentParamSet.reset() self.name = str(ctx.STRING()).replace('"', '') # Exit a parse tree produced by pbrtParser#namedmaterial. def exitNamedmaterial(self, ctx): print("exit named material block") pbrtNamedMaterial(self.name) # Enter a parse tree produced by pbrtParser#namedmaterial. def enterMakenamedmaterial(self, ctx): print("enter make named material block") self.currentParamSet.reset() self.name = str(ctx.STRING()).replace('"', '') # Exit a parse tree produced by pbrtParser#namedmaterial. def exitMakenamedmaterial(self, ctx): print("exit make named material block") pbrtMakeNamedMaterial(self.name, self.currentParamSet) # Enter a parse tree produced by pbrtParser#renderer. def enterRenderer(self, ctx): print("enter renderer block") self.currentParamSet.reset() self.name = str(ctx.STRING()).replace('"', '') pass # Exit a parse tree produced by pbrtParser#renderer. def exitRenderer(self, ctx): print("exit material block") pbrtRenderer(self.name, self.currentParamSet) # Enter a parse tree produced by pbrtParser#include. def enterInclude(self, ctx): pass # Exit a parse tree produced by pbrtParser#include. def exitInclude(self, ctx): pass # Enter a parse tree produced by pbrtParser#worldBlock. def enterWorldBlock(self, ctx): print("enter world block") pbrtIdentity() # Exit a parse tree produced by pbrtParser#worldBlock. def exitWorldBlock(self, ctx): print("exit world block") pass # Enter a parse tree produced by pbrtParser#objectInstance. def enterObjectInstance(self, ctx): print("enter object block") self.currentParamSet.reset() self.name = str(ctx.STRING()).replace('"', '') # Exit a parse tree produced by pbrtParser#objectInstance. def exitObjectInstance(self, ctx): print("exit object block") pbrtObjectInstance(self.name) # Enter a parse tree produced by pbrtParser#translate. def enterTranslate(self, ctx): print("enter translate block") a = float(str(ctx.NUMBER(0))) b = float(str(ctx.NUMBER(1))) c = float(str(ctx.NUMBER(2))) pbrtTranslate(a, b, c) # Exit a parse tree produced by pbrtParser#translate. def exitTranslate(self, ctx): print("exit translate block") pass # Enter a parse tree produced by pbrtParser#objectBlock. def enterObjectBlock(self, ctx): print("enter object block") pass # Exit a parse tree produced by pbrtParser#objectBlock. def exitObjectBlock(self, ctx): print("exit object block") pass # Enter a parse tree produced by pbrtParser#attributeBlock. def enterAttributeBlock(self, ctx): print("enter attribute block") pbrtAttributeBegin() # Exit a parse tree produced by pbrtParser#attributeBlock. def exitAttributeBlock(self, ctx): print("exit attribute block") pbrtAttributeEnd() # Enter a parse tree produced by pbrtParser#arealightsource. def enterArealightsource(self, ctx): print("exit arealight block") self.currentParamSet.reset() self.name = str(ctx.STRING()).replace('"', '') # Exit a parse tree produced by pbrtParser#arealightsource. def exitArealightsource(self, ctx): pbrtAreaLightSource(self.name, self.currentParamSet)