def scene(t): """ Returns the scene at time 't' (in seconds) """ head_location = np.array(location) - np.array([0, 0, head_size]) import vapory light = vapory.LightSource([15, 15, 1], 'color', [light_intensity] * 3) background = vapory.Box( [0, 0, 0], [1, 1, 1], vapory.Texture( vapory.Pigment( vapory.ImageMap('png', '"../files/VISUEL_104.png"', 'once')), vapory.Finish('ambient', 1.2)), 'scale', [self.background_depth, self.background_depth, 0], 'translate', [ -self.background_depth / 2, -.45 * self.background_depth, -self.background_depth / 2 ]) me = vapory.Sphere( head_location, head_size, vapory.Texture(vapory.Pigment('color', [1, 0, 1]))) self.t = t self.update() objects = [background, me, light] for i_lame in range(self.N_lame): #print(i_lame, self.lame_length[i_lame], self.lame_width[i_lame]) objects.append( vapory.Box( [ -self.lame_length[i_lame] / 2, 0, -self.lame_width[i_lame] / 2 ], [ self.lame_length[i_lame] / 2, self.lames_height, self.lame_width[i_lame] / 2 ], vapory.Pigment('color', [1, 1, 1]), vapory.Finish('phong', 0.8, 'reflection', reflection), 'rotate', (0, -self.lames[2, i_lame] * 180 / np.pi, 0), #HACK? 'translate', (self.lames[0, i_lame], 0, self.lames[1, i_lame]))) objects.append(light) return vapory.Scene(vapory.Camera('angle', fov, "location", location, "look_at", look_at), objects=objects, included=["glass.inc"])
def rendered(self): return vap.Box([-s / 2 for s in self._size], [s / 2 for s in self._size], vap.Texture('T_Ruby_Glass' if not self._color else vap. Pigment('color', self._color)), vap.Interior('ior', 4), 'matrix', self.body.getRotation() + self.body.getPosition())
def povray_test(): """ Just a purple sphere """ scene = vapory.Scene( vapory.Camera('location', [0.0, 0.5, -4.0], 'direction', [0,0,1.5], 'look_at', [0, 0, 0]), objects = [ vapory.Background("color", [0.85, 0.75, 0.75]), vapory.LightSource([0, 0, 0], 'color',[1, 1, 1], 'translate', [-5, 5, -5]), vapory.LightSource ([0, 0, 0], 'color', [0.25, 0.25, 0.25], 'translate', [600, -600, -600]), vapory.Box([-0.5, -0.5, -0.5], [0.5, 0.5, 0.5], vapory.Texture( vapory.Pigment( 'color', [1,0,0]), vapory.Finish('specular', 0.6), vapory.Normal('agate', 0.25, 'scale', 0.5)), 'rotate', [45,46,47]) ] ) # We use antialiasing. Remove this option for faster rendering. scene.render("cube.png", width=300, height=300, antialiasing=0.001)
def make_square_spherical_lens(roc1: float, roc2: float, thickness: float, side_length: float, n: float, *args): radius = side_length / 2**0.5 sag1 = functions.calc_sphere_sag(roc1, radius) sag2 = functions.calc_sphere_sag(roc2, radius) hsl = side_length / 2 sections = [] if np.isfinite(roc1): surface1 = vp.Sphere([0, 0, roc1], abs(roc1)) if roc1 > 0: sections.append( vp.Intersection(surface1, vp.Box([-hsl, -hsl, 0], [hsl, hsl, sag1]))) elif roc1 < 0: sections.append( vp.Difference(vp.Box([-hsl, -hsl, sag1], [hsl, hsl, 0]), surface1)) sections.append( vp.Box([-hsl, -hsl, max(sag1, 0)], [hsl, hsl, thickness + min(sag2, 0)])) surface2 = vp.Sphere([0, 0, thickness + roc2], abs(roc2)) if np.isfinite(roc2): if roc2 < 0: sections.append( vp.Intersection( surface2, vp.Box([-hsl, -hsl, thickness + sag2], [hsl, hsl, thickness]))) elif roc2 > 0: sections.append( vp.Difference( vp.Box([-hsl, -hsl, thickness], [hsl, hsl, thickness + sag2]), surface2)) lens = vp.Union( *sections, vp.Texture('T_Glass2'), vp.Interior('ior', n), *args) # , *args) vp.Texture( vp.Pigment( 'color', [1,0,1] )) return lens
def _build_scene(self, shape): """ Creates each object and appends them to the objects list """ objects = [] # add parts to scene positions, sizes = shape.convert_to_positions_sizes() for position, size in zip(positions, sizes): lb = position - (size / 2.0) ub = position + (size / 2.0) objects.append( vapory.Box( lb, ub, vapory.Texture(vapory.Pigment('color', [1.0, 1.0, 1.0])))) # add light objects.append(self.light) return objects
def generateScenes(): delta=0.1 nbcubes=100 light = vapory.LightSource( [2,4,-7], 'color', [2,2,2] ) ambientlight=AmbientLight([1,1,1]) objects=[light] rotation=[np.random.rand()*180,np.random.rand()*180,np.random.rand()*180] for k in range(nbcubes): center=[0+np.random.randn()*3,0+np.random.randn()*2,0+np.random.rand()*2] #sphere=vapory.Sphere( center, 0.5, vapory.Pigment( 'color', [1,1,1])) #sphere=vapory.Sphere( center, 0.5, vapory.Pigment( 'color', np.random.rand(3) ),vapory.Finish('phong', 0.8,'reflection', 0.5)) #objects.append(sphere) #center=[0+np.random.randn()*2,0+np.random.randn()*2,0+np.random.rand()*2] #objects.append(vapory.Box( [-0.5,-0.5,-0.5], [ 0.5,0.5,0.5 ], 'rotate',rotation , 'translate',center ,vapory.Pigment( 'color', np.random.rand(3) ),vapory.Finish('phong', 0.8,'reflection', 0.0))) #center=[0+np.random.randn()*2,0+np.random.randn()*2,0+np.random.rand()*1.0] #sphere=vapory.Sphere( center, 0.5, vapory.Pigment( 'color', [1,1,1])) #sphere=vapory.Sphere( center, 0.5, vapory.Pigment( 'color', np.random.rand(3) ),vapory.Finish('phong', 0.8,'reflection', 0.5)) #objects.append(sphere) center=[0+np.random.randn()*3,0+np.random.randn()*2,0+np.random.rand()*2] #objects.append(vapory.Box( [-0.5,-0.5,-0.5], [ 0.5,0.5,0.5 ], 'rotate',rotation , 'translate',center ,vapory.Pigment( 'color', np.random.rand(3) ),vapory.Finish('phong', 0.8,'reflection', 0.1))) #objects.append(vapory.Box( [-0.5,-0.5,-0.5], [ 0.5,0.5,0.5 ], 'rotate',rotation , 'translate',center ,vapory.Pigment( 'color',[1,1,1] ))) #objects.append(vapory.Box( [-0.5,-0.5,-0.5], [ 0.5,0.5,0.5 ], 'rotate',rotation , 'translate',center,vapory.Texture('Rosewood'))) objects.append(vapory.Box( [-0.5,-0.5,-0.5], [ 0.5,0.5,0.5 ], 'rotate',rotation , 'translate',center,vapory.Texture('White_Marble'))) #ground = vapory.Plane([0,1,0],0, vapory.Texture('Rosewood')) #objects.append(ground) camera_left = vapory.Camera( 'location', [0-delta,0,-5], 'look_at', [0-delta,0,0] ) # <= Increase for better quality camera_right = vapory.Camera( 'location', [0+delta,0,-5], 'look_at', [0+delta,0,0]) # <= Increase for better quality scene_left = vapory.Scene( camera_left, objects= objects,included = ["colors.inc", "textures.inc"],) scene_right = vapory.Scene( camera_right, objects= objects,included = ["colors.inc", "textures.inc"],) return scene_left,scene_right
def scene(pack, cmap=None, rot=0, camera_height=0.7, camera_dist=1.5, angle=None, lightstrength=1.1, orthographic=False, pad=None, floater_color=(.6, .6, .6), bgcolor=(1, 1, 1), box_color=(.5, .5, .5), group_indexes=None, clip=False): """ Render a 3D scene. Requires `vapory` package, which requires the `povray` binary. Parameters ---------- cmap : a colormap box_color : Color to draw the box. 'None' => don't draw box. floater_color : Color for floaters. 'None' => same color as non-floaters (use cmap). group_indexes : a list of indexes for each "group" that should remain together on the same side of the box. clip : clip the spheres at the edge of the box. Returns ------- scene : vapory.Scene, which can be rendered using its `.render()` method. """ import vapory import numpy as np try: import matplotlib as mpl import matplotlib.cm as mcm vmin, vmax = min(pack.diameters), max(pack.diameters) sm = mcm.ScalarMappable(norm=mpl.colors.Normalize(vmin, vmax), cmap=cmap) cols = [sm.to_rgba(s) for s in pack.diameters] except ImportError: if not isinstance(cmap, list): raise ValueError( "matplotlib could not be imported, and cmap not recognizeable as a list" ) cols = list(cmap) except TypeError: if not isinstance(cmap, list): raise ValueError( "matplotlib could not convert cmap to a colormap," + " and cmap not recognizeable as a list") cols = list(cmap) if floater_color is not None: ix, _ = pack.backbone() ns, = np.nonzero(~ix) for n in ns: cols[n] = floater_color mod_add = .5 if not clip else 0. rs = np.remainder(pack.rs + mod_add, 1) - mod_add if group_indexes is not None: for ix in group_indexes: xs = pack.rs[ix, :] com = np.mean(xs, axis=0) comdiff = (np.remainder(com + mod_add, 1) - mod_add) - com rs[ix, :] = xs + comdiff if clip: spheres = [] cube = vapory.Box((-.5, -.5, -.5), (.5, .5, .5)) dxs = [-1., 0.] drs = np.array([(dx, dy, dz) for dx in dxs for dy in dxs for dz in dxs]) maxr = 0 for xyz, s, col in zip(rs, pack.diameters, cols): for dr in drs: r = dr + xyz if np.any(abs(r) - s / 2. > .5): # not in the box continue sphere = vapory.Sphere(r, s / 2.) cutsphere = vapory.Intersection( cube, sphere, vapory.Texture(vapory.Pigment('color', col[:3]))) spheres.append(cutsphere) if np.amax(r) > maxr: maxr = np.amax(r) else: spheres = [ vapory.Sphere(xyz, s / 2., vapory.Texture(vapory.Pigment('color', col[:3]))) for xyz, s, col in zip(rs, pack.diameters, cols) ] maxr = np.amax(np.amax(np.abs(rs), axis=1) + pack.diameters / 2.) extent = (-.5, .5) corners = [ np.array((x, y, z)) for x in extent for y in extent for z in extent ] pairs = [(c1, c2) for c1 in corners for c2 in corners if np.allclose(np.sum((c1 - c2)**2), 1) and sum(c1 - c2) > 0] radius = 0.01 cyls, caps = [], [] if box_color is not None: col = vapory.Texture(vapory.Pigment('color', box_color)) cyls = [vapory.Cylinder(c1, c2, 0.01, col) for c1, c2 in pairs] caps = [vapory.Sphere(c, radius, col) for c in corners] light_locs = [[8., 5., -3.], [-6., 6., -5.], [-6., -7., -4.], [10., -5., 7.]] rotlocs = [[ x * np.cos(rot) - z * np.sin(rot), y, z * np.cos(rot) + x * np.sin(rot) ] for x, y, z in light_locs] lights = [ # vapory.LightSource( [2,3,5], 'color', [1,1,1] ), vapory.LightSource(loc, 'color', [lightstrength] * 3) for loc in rotlocs ] cloc = [ np.cos(rot) * camera_dist, camera_dist * camera_height, np.sin(rot) * camera_dist ] # mag = sqrt(sum([d**2 for d in cloc])) # direction = [-v*2/mag for v in cloc] if angle is None: if pad is None: pad = max(pack.diameters) w = sqrt(2) * maxr + pad angle = float(np.arctan2(w, 2 * camera_dist)) * 2 * 180 / np.pi camera = vapory.Camera('location', cloc, 'look_at', [0, 0, 0], 'angle', angle) # vapory.Camera('orthographic', 'location', cloc, 'direction', # direction, 'up', [0,2,0], 'right', [2,0,0]) return vapory.Scene(camera, objects=(lights + spheres + cyls + caps + [vapory.Background("color", bgcolor)]))
def __init__(self): self.texture = vapory.Texture(vapory.Pigment("color", [1, 0, 1])) self.loop_object = vapory.Box([0, 0, 0], 2, self.texture)