def set_block(self, s, d): aoy = m.atan2(s[2], s[0]) aoz = m.atan2(s[1], m.sqrt(s[0]**2 + s[2]**2)) rot = tr.rotation_matrix(aoy, (0, 1, 0)) rot = np.dot(tr.rotation_matrix(-aoz, (0, 0, 1)), rot) rot = np.dot(tr.rotation_matrix(m.pi / 2.0, (0, 0, 1)), rot) v, n, t = self.gen_v(1, 1, s) for x in range(v.shape[0]): for y in range(v.shape[1]): for z in range(v.shape[2]): v[x, y, z] = np.dot(rot, v[x, y, z]) n[x, y, z] = np.resize(np.dot(rot, np.resize(n[x, y, z], 4)), 3) Mesh.__init__(self, buffers=(v, n, t)) self.x = np.array( ((0, 0, 0, 1), (s[0], 0, 0, 1), (0, 0, s[2], 1), (s[0], 0, s[2], 1), (0, s[1], 0, 1), (s[0], s[1], 0, 1), (0, s[1], s[2], 1), (s[0], s[1], s[2], 1)), np.float64) for i in range(len(self.x)): self.x[i] = np.dot(rot, self.x[i]) self.r = np.resize( np.dot(rot, np.array((s[0], s[1], s[2], 0), np.float64) / 2.0), 3) self.m = np.array([d * s[0] * s[1] * s[2] / 8.0] * len(self.x), np.float64) self.M = self.calc_m(self.x, self.m) self.Mi = np.linalg.inv(self.M)
def __init__(self, physics, r_min=0., r_max=None, num_cells=500, too_fine=1e4, Ntol=1e-8, linear_refine=0, linear_start=None, linear_stop=None, r_rm=None, A_rm=25., k_rm=20., adjust_transition=True, k=1., a=5e-2, b=0.): """The constructor""" Mesh.__init__(self, physics, r_min, r_max, num_cells, too_fine, Ntol, linear_refine, linear_start, linear_stop, r_rm, A_rm, k_rm, adjust_transition) # params of the non-linear transform self.k = k self.a = a self.b = b # build the mesh self.mesh = None self.build_mesh()
def __init__(self, physics, r_min=0., r_max=None, num_cells=None, too_fine=1e4, Ntol=1e-8, linear_refine=0, linear_start=None, linear_stop=None, r_rm=None, A_rm=25., k_rm=20., adjust_transition=True, k=None, gamma=None): """The constructor""" if num_cells is None: extra = 0 if physics.ms > 1.: extra = 50 if np.log10(physics.x0) < -2: extra += 50 if physics.D == 3: extra += 75 num_cells = int(200. - 50. * np.log10(physics.x0) + extra) Mesh.__init__(self, physics, r_min, r_max, num_cells, too_fine, Ntol, linear_refine, linear_start, linear_stop, r_rm, A_rm, k_rm, adjust_transition) # params of the non-linear transform if k is None: if (physics.coupling == 'quadratic' and physics.D == 3): if np.log10(physics.x0) < -2.5: k = 300. elif np.log10(physics.ms) > 2.5: k = 50. else: k = 20. else: k = 20. self.k = k if gamma is None: if (physics.D == 3 and np.log10(physics.x0) < -2.5): gamma = 10. else: gamma = 11. - 0.5 * np.log10(physics.x0) self.gamma = gamma # build the mesh self.build_mesh()
def __init__(self, nvert=10, nhoriz=20): n = nvert * nhoriz + 2 vertex_colors = np.zeros((n, 3), 'f') # texture coordinates textureCoords = np.zeros((n, 2), 'f') circles, vertices = self.generate_points(nvert, nhoriz) vertices = np.array(vertices, dtype='f') faces = self.generate_faces(circles) indices = np.array(faces, dtype=np.uint32) Mesh.__init__(self, vertices=vertices, faces=indices, textureCoords=textureCoords, material=Material(Ka=[0.5,0.5,0.5], Kd=[0.6,0.6,0.9], Ks=[1.,1.,0.9], Ns=15.0) )
def __init__(self, parent, color=0xFF0000, x=0, y=0): Mesh.__init__(self) self.parent = parent self.position.x = x self.position.y = y #self.matrix.translate(x, y, 0.0) self.color = color r, g, b = self.toRgb(self.color) v = [ 0.0, 0.0, r, g, b, 0.0 + BLOCK_SIZE, 0.0, r, g, b, 0.0 + BLOCK_SIZE, 0.0 + BLOCK_SIZE, r, g, b, 0.0, 0.0 + BLOCK_SIZE, r, g, b, ] i = [ 0, 1, 2, 2, 3, 0 ] self.set_data(vertices=v, indices=i)
def __init__(self, obj_file_name): self.default_shape_name = obj_file_name or 'initial_shape' self.default_surface_name = 'initial_surface' self.default_material_name = 'default' # Name of the shape/surface/material from the most recently parsed 'o'/'g'/'usemtl' line respectively self.curr_shape_name = self.default_shape_name self.curr_surf_name = self.default_surface_name self.curr_mtl_name = self.default_material_name # To keep of track of number of polygons parsed so far self.next_polygon_index = 0 # A tuple of indices per vertex element self.indices = [ ] # Shortcut to be able to access the current surface in fewer characters and lookups self.curr_surf = Surface(0, self.default_material_name) # Dictionary of names -> shapes. Initialise to a default shape with a default surface self.shapes = { self.default_shape_name : Shape({ self.default_surface_name : self.curr_surf }) } Mesh.__init__(self)
def set_block( self , s , d ) : aoy = m.atan2( s[2] , s[0] ) aoz = m.atan2( s[1] , m.sqrt(s[0]**2+s[2]**2) ) rot = tr.rotation_matrix( aoy , (0,1,0) ) rot = np.dot( tr.rotation_matrix( -aoz , (0,0,1) ) , rot ) rot = np.dot( tr.rotation_matrix( m.pi/2.0 , (0,0,1) ) , rot ) v , n , t = self.gen_v( 1 , 1 , s ) for x in range(v.shape[0]) : for y in range(v.shape[1]) : for z in range(v.shape[2]) : v[x,y,z] = np.dot(rot,v[x,y,z]) n[x,y,z] = np.resize(np.dot(rot,np.resize(n[x,y,z],4)),3) Mesh.__init__( self , buffers = (v,n,t) ) self.x = np.array( ((0,0,0,1),(s[0],0,0,1),(0,0,s[2],1),(s[0],0,s[2],1),(0,s[1],0,1),(s[0],s[1],0,1),(0,s[1],s[2],1),(s[0],s[1],s[2],1)) , np.float64 ) for i in range(len(self.x)) : self.x[i] = np.dot(rot,self.x[i]) self.r = np.resize( np.dot( rot , np.array((s[0],s[1],s[2],0) , np.float64 )/2.0 ) , 3 ) self.m = np.array( [ d*s[0]*s[1]*s[2] / 8.0 ] * len(self.x) , np.float64 ) self.M = self.calc_m( self.x , self.m ) self.Mi = np.linalg.inv( self.M )
def __init__( self , n ) : Mesh.__init__( self , buffers = self.gen_v( n , n ) )
def __init__(self): Mesh.__init__(self)