def __init__(self,type, size, x, y, z, shadprog): #code to define the object type, in the following we will generate here the vertex buffer data if type == 'Cube': self.type = 'Cube' self.size = size elif type == 'Sphere': self.type = 'Sphere' self.size = size elif type == 'Custom': self.type = 'Custom' #declare custom data - for the vbo test vertices = np.array([[0,10,0],[-10,-10,0],[10,-10,0]],dtype='float32') indices = np.array([[0,1,2]],dtype='uint16') self.vertexVBO = vbo.VBO(data=vertices, usage=GL_DYNAMIC_DRAW, target=GL_ARRAY_BUFFER) self.indexVBO = vbo.VBO(data=indices, usage=GL_DYNAMIC_DRAW,target=GL_ELEMENT_ARRAY_BUFFER) self.vertexVBO.bind() #wrapper of glBindBuffer ... tocheck self.indexVBO.bind() #tocontinue..... else : self.type = 'Cube' self.size = 1 self.position = [x,y,z] self.orientation = qts.Quat([0.0,30.0,0.0]) self.program = shadprog RendObject.ListRends.append(self) #funny test code rand_axis = np.array([random.random(),random.random(),random.random()]) norma = np.linalg.norm(rand_axis) rand_axis /= norma self.axis = np.array([0.0,1.0,0.0]) self.rand_angle = 0.02 * (random.uniform(0.0,20.0)-10)
def update(self): #funny test: rotate o fa fraction around the rand_axis ca = np.cos(self.rand_angle / 2) sa = np.sin(self.rand_angle / 2) v = np.append(self.axis * sa, ca) qr = qts.Quat(v) self.orientation = qr.__mul__(self.orientation)
def __init__(self, type, size, x, y, z, shadprog): #declare custom data - for the vbo test vertices = np.array([[0.0, 0.0, 0.0], [0.0, 15.0, 0.0], [15.0, 0.0, 0.0], [0.0, 0.0, -15]], 'float32') indices = np.array([[0, 1, 2], [2, 1, 3], [0, 3, 1], [0, 2, 3]], dtype='uint16') self.vertexVBO = vbo.VBO(data=vertices, usage=GL_DYNAMIC_DRAW, target=GL_ARRAY_BUFFER) self.indexVBO = vbo.VBO(data=indices, usage=GL_DYNAMIC_DRAW, target=GL_ELEMENT_ARRAY_BUFFER) self.position = [x, y, z] self.orientation = qts.Quat([0.0, 30.0, 0.0]) # here we set up the program. here we get the attributes indices self.program = shadprog self.attrib_position = glGetAttribLocation(self.program, 'position') #self.attrib_color = glGetAttribLocation(self.program,'color') RendObjectVBO.ListRends.append(self) #funny test code rand_axis = np.array( [random.random(), random.random(), random.random()]) norma = np.linalg.norm(rand_axis) rand_axis /= norma #self.axis = np.array([0.0,1.0,0.0]) self.axis = rand_axis self.rand_angle = 0.02 * (random.uniform(0.0, 20.0) - 10)
def update(self): #funny test: rotate o fa fraction around the rand_axis ca = np.cos(self.rand_angle / 2) sa = np.sin(self.rand_angle / 2) v = np.append(self.axis * sa, ca) qr = qts.Quat(v) self.orientation = qr.__mul__(self.orientation) #adapt near plane to current distance obj_space_distance = np.linalg.norm(self.ActiveCamera.position - self.position) / self.scale near_plane = smoothstephilo(0.1, 10, 1.005, 1.1, obj_space_distance) self.ActiveCamera.set_near_far(near_plane, 200000.0) GlobalSignals.set('near distance: ', near_plane) #check if we tessellate RequestManager.add_request(self.CheckTessellation, []) #check if a reduction of lod is required if self.TexAtlas.free_below_level(0.05): self.kdiv *= 0.995 self.kred *= 0.995 elif self.kdiv < 3.0 and self.TexAtlas.free_over_level(0.25): self.kdiv *= 1.001 self.kred *= 1.001 GlobalSignals.set('kdiv: ', self.kdiv) GlobalSignals.set('kred: ', self.kred) #debug GlobalSignals.set('req nr', RequestManager.get_queue_length()) GlobalSignals.set('req max time', RequestManager.get_queue_max_wait_time_ms()) GlobalSignals.set( 'size of patch:', 2 * 3.14 * self.PlanetDescriptor.radius / 4 / (2**GlobalSignals.read('level:'))) GlobalSignals.set('size of unit:', GlobalSignals.read('size of patch:') / 16)
def __init__(self, type, x, y, z, SceneUtils, PlanetDesc): # create the texture atlas for the cube self.TexAtlas = TextureAtlasArray(96 * 4, 128, 128) self.PlanetDescriptor = PlanetDesc #in the future, the active camera should be linked to the object using a more global methods # or making sceneutils a global access object self.ActiveCamera = SceneUtils['cam'] self.SceneMgr = SceneUtils['fbo'] #code to be put only if the planet has water bodies #set up a helper fbo for difraction maps self.helpfbo = FBO_RTT(1024, 1024) # and one for reflection maps self.helpfbo2 = FBO_RTT(1024, 1024) # state of the main texture data: 0 = full, <>0, not fully completed self.state = 1 #create the cube face object # - define corners c000 = np.array([-1.0, -1.0, 1.0], dtype='float32') c010 = np.array([-1.0, 1.0, 1.0], dtype='float32') c110 = np.array([1.0, 1.0, 1.0], dtype='float32') c100 = np.array([1.0, -1.0, 1.0], dtype='float32') c001 = np.array([-1.0, -1.0, -1.0], dtype='float32') c011 = np.array([-1.0, 1.0, -1.0], dtype='float32') c111 = np.array([1.0, 1.0, -1.0], dtype='float32') c101 = np.array([1.0, -1.0, -1.0], dtype='float32') t00 = np.array([0.0, 0.0, 0.0, 1.0, 0.0, 0.0], dtype='float32') t10 = np.array([1.0, 0.0, 0.0, 1.0, 1.0, 0.0], dtype='float32') t11 = np.array([1.0, 1.0, 0.0, 1.0, 1.0, 1.0], dtype='float32') t01 = np.array([0.0, 1.0, 0.0, 1.0, 0.0, 1.0], dtype='float32') # - create the 6 cube faces, specifying vertices and texture coordinates with np.lib.append([x,y,z],[s,t]) calls self.face = [] self.face.append( SurfaceNode(0, 0, 0, 0, np.lib.append(c000, t00), np.lib.append(c010, t01), np.lib.append(c110, t11), np.lib.append(c100, t10), SceneUtils, PlanetDesc, self.TexAtlas)) self.face.append( SurfaceNode(1, 0, 0, 0, np.lib.append(c001, t00), np.lib.append(c011, t01), np.lib.append(c010, t11), np.lib.append(c000, t10), SceneUtils, PlanetDesc, self.TexAtlas)) self.face.append( SurfaceNode(2, 0, 0, 0, np.lib.append(c101, t00), np.lib.append(c111, t01), np.lib.append(c011, t11), np.lib.append(c001, t10), SceneUtils, PlanetDesc, self.TexAtlas)) self.face.append( SurfaceNode(3, 0, 0, 0, np.lib.append(c100, t00), np.lib.append(c110, t01), np.lib.append(c111, t11), np.lib.append(c101, t10), SceneUtils, PlanetDesc, self.TexAtlas)) self.face.append( SurfaceNode(4, 0, 0, 0, np.lib.append(c001, t00), np.lib.append(c000, t01), np.lib.append(c100, t11), np.lib.append(c101, t10), SceneUtils, PlanetDesc, self.TexAtlas)) self.face.append( SurfaceNode(5, 0, 0, 0, np.lib.append(c010, t00), np.lib.append(c011, t01), np.lib.append(c111, t11), np.lib.append(c110, t10), SceneUtils, PlanetDesc, self.TexAtlas)) # generate heigthmap #self.GenHeightMapTex(SceneUtils['fbo']) RequestManager.add_request(self.CheckLevelZeroTexComplete, []) for aface in self.face: #aface.tessellate_all_to_level(2) aface.do_triangles(True) aface.VBO_All_Updated() #parameters for dynamic level of detail self.kdiv = 3.0 self.kred = 3.2 leng = 0 self.activeVBO = [0, 0, 0, 0, 0, 0] #implementing doublevbo self.VBO_need_update = [3, 3, 3, 3, 3, 3] # to check self.sidetocheck = 6 #temporarily we check one side at a time to see if we tessellate self.updatelist = [] self.vbotocomplete = [7, 7] #face number and active number self.vertexVBO = [[]] self.indexVBO = [[]] self.vertexVBO.append([]) self.indexVBO.append([]) index = 0 for i in self.face: i.faceindex = index index += 1 self.vertici = np.array( np.array(i.datadict['vertex'], dtype='float32')) self.vertexVBO[0].append( vbo.VBO(data=self.vertici, usage=GL_DYNAMIC_DRAW, target=GL_ARRAY_BUFFER)) self.vertexVBO[1].append( vbo.VBO(data=self.vertici, usage=GL_DYNAMIC_DRAW, target=GL_ARRAY_BUFFER)) self.indici = np.array( np.array(i.datadict['index'], dtype='uint32')) self.indexVBO[0].append( vbo.VBO(data=self.indici, usage=GL_DYNAMIC_DRAW, target=GL_ELEMENT_ARRAY_BUFFER)) self.indexVBO[1].append( vbo.VBO(data=self.indici, usage=GL_DYNAMIC_DRAW, target=GL_ELEMENT_ARRAY_BUFFER)) leng += self.vertici.shape[0] # assign other object properties self.scale = PlanetDesc.radius self.position = [x, y, z] self.orientation = qts.Quat([0.0, 0.3, 0.5]) #add a light as a test ..light should not be there self.light = RendLight((2000000.0, 0.0, 0.0), (1.0, 1.0, 0.8)) #add a test skydome object self.sky = RenderableSkydome(16) self.sky.attach_light(self.light) # assign the shader and get attribute and uniform indexes (pointers) self.program = MaterialManager.Materials[PlanetDesc.main_material] self.program_sea = MaterialManager.Materials['planetsea'] self.attrib_position = glGetAttribLocation(self.program, 'position') self.attrib_texcoord = glGetAttribLocation(self.program, 'texcoord') self.attrib_texcoord2 = glGetAttribLocation(self.program, 'texcoord2') self.attrib_scale = glGetAttribLocation(self.program, 'nodescale') self.main_attribs = { 'position': glGetAttribLocation(self.program, 'position'), 'texcoord': glGetAttribLocation(self.program, 'texcoord'), 'nodescale': glGetAttribLocation(self.program, 'nodescale'), 'texcoord2': glGetAttribLocation(self.program, 'texcoord2'), } self.sea_attribs = { 'position': glGetAttribLocation(self.program_sea, 'position'), 'texcoord': glGetAttribLocation(self.program_sea, 'texcoord'), 'nodescale': glGetAttribLocation(self.program_sea, 'nodescale'), 'texcoord2': glGetAttribLocation(self.program_sea, 'texcoord2'), } self.main_unifs = { 'u_model': glGetUniformLocation(self.program, 'u_model'), 'u_view': glGetUniformLocation(self.program, 'u_view'), 'u_normal': glGetUniformLocation(self.program, 'u_normal'), 'u_proj': glGetUniformLocation(self.program, 'u_proj'), 'u_lposition3': glGetUniformLocation(self.program, 'u_lposition3'), 'u_lintensity3': glGetUniformLocation(self.program, 'u_lintensity3'), 'planet_radius': glGetUniformLocation(self.program, 'planet_radius'), 'planet_height': glGetUniformLocation(self.program, 'planet_height'), 'sea_level': glGetUniformLocation(self.program, 'sea_level'), 'camdist': glGetUniformLocation(self.program, 'camdist'), 'skirt_off': glGetUniformLocation(self.program, 'skirt_off'), 'state': glGetUniformLocation(self.program, 'state'), 'verse': glGetUniformLocation(self.program, 'verse'), } self.sea_unifs = { 'model_m': glGetUniformLocation(self.program_sea, 'model_m'), 'view_m': glGetUniformLocation(self.program_sea, 'view_m'), 'normal_m': glGetUniformLocation(self.program_sea, 'normal_m'), 'proj_m': glGetUniformLocation(self.program_sea, 'proj_m'), 'u_lposition3': glGetUniformLocation(self.program_sea, 'u_lposition3'), 'u_lintensity3': glGetUniformLocation(self.program_sea, 'u_lintensity3'), 'planetradius': glGetUniformLocation(self.program_sea, 'planetradius'), 'planetheight': glGetUniformLocation(self.program_sea, 'planetheight'), 'sealevel': glGetUniformLocation(self.program_sea, 'sealevel'), 'time': glGetUniformLocation(self.program_sea, 'time'), 'camdist': glGetUniformLocation(self.program_sea, 'camdist'), 'skirt_off': glGetUniformLocation(self.program_sea, 'skirt_off'), } # inscribe the object in the static list of the parent object RenderablePlanet.ListRends.append(self) # funny test code rand_axis = np.array( [random.random(), random.random(), random.random()]) norma = np.linalg.norm(rand_axis) rand_axis /= norma #self.axis = np.array([0.0,1.0,0.0]) self.axis = rand_axis self.rand_angle = 0.000 * (random.uniform(0.0, 20.0) - 10) self.cam_distance = 10 ##test signals for the hud GlobalSignals.set('Triangles', leng) GlobalSignals.set('req nr', 0) GlobalSignals.set('req max time', 0) GlobalSignals.set('draw ms', 0) GlobalSignals.set('tessel ms', 0) GlobalSignals.set('tex slot free', 0) GlobalSignals.set('Nodes', leng)