def remove_resource(self, resource): # Remove it from the TextureManager TextureManager.get_instance().remove_texture(resource)
def render(self, material, mesh, transform): # self.set_uniform_data('material.ambient', material.ambient) # self.set_uniform_data('material.diffuse', material.diffuse) # self.set_uniform_data('material.specular', material.specular) # self.set_uniform_data('material.shininess', material.shininess) # this is a kind of roundabout of accessing this world_mat = transform.world_matrix #world_mat.transpose() self.set_uniform_data('model', world_mat) texture = TextureManager.get_instance().get_texture_by_name( material.texture ) if texture is not None: self.set_uniform_data('diffuse_texture', texture) if self.attributes_valid(): self.enable_attribute_arrays() if mesh.vertex_buffer.is_setup: with mesh.vertex_buffer as vb: if self.attributes_valid(): glVertexAttribPointer(self.get_attribute_location("position"), *vb.GetVertexAttribute()) glVertexAttribPointer(self.get_attribute_location("normal"), *vb.GetNormalAttribute()) glVertexAttribPointer(self.get_attribute_location("colour"), *vb.GetColourAttribute()) glVertexAttribPointer(self.get_attribute_location("texture_coordinate"), *vb.GetTexCoordAttribute()) glDrawElements(GL_TRIANGLES, vb.count, GL_UNSIGNED_SHORT, vb.indices) if self.attributes_valid(): self.disable_attribute_arrays() #QuitEvent().send()
def process_resource(self, filename, name): # new_texture = None # Does the Texture already exist in the Texture Manager new_texture = TextureManager.get_instance().get_texture_by_filename(filename) # for texture in TextureManager.get_instance().textures: # if texture.filename == filename: # new_texture = texture # break # If the texture isn't in the texture manager if new_texture is None: # Load the image new_texture = Texture(filename=filename, name=name) # Add it to the TextureManager TextureManager.get_instance().add_texture(new_texture) # Create a Resource object that also contains the Texture object within the data property # new_resource = Texture(filename=filename) # Return the new Resource return new_texture
def texture(self, new_tex): the_texture = None if isinstance(new_tex, Texture): the_texture = new_tex elif isinstance(new_tex, str): # Get Texture from TextureManager the_texture = TextureManager.get_instance().get_texture(new_tex) if the_texture is not None: self._tex_obj = the_texture self._tex_name = the_texture.name else: Logger.Log("Can't find texture: %s" % new_tex)
def _gen_texture(self, address, resolution=None): texture_name = None # If the a texture for the address has already been generated if address in self._generated_textures: texture_name = self._generated_textures[address] # Otherwise generate a new texture else: face = CubeSphereMap.get_address_face(address) level = len(address) name = "planet_texture" size = self._increments #256 if not resolution is None: size = resolution data = None format_size = 4 pitch = size * format_size format = "RGBA" #b = datetime.now() # Generate the data for the texture #perlin = Perlin(12345) # Generate sphere coordinates for the address # verts = [] # for x in range(size): # o = "" # x /= float(size) # for y in range(size): # y /= float(size) # # verts.append( Vector3(x, y, 0.5) ) # coord = CubeSphereMap.get_sphere_vector(x, y, face) * self._radius # # #print coord # verts.append( coord ) # o += " (%1.2f, %1.2f)" % (x, y) #verts = self._gen_verts(address) # mesh = self._generated_meshes[address] # verts = mesh.vertices #print o #ignoring faces #print verts # as image data is loaded from bottom-left to top-right vertex data # needs to be transformed as it is generated top-left to bottom-right # t_data = [] # for x in xrange(size-1, -1, -1): # row_start = x * size # row_end = row_start + size # t_data += verts[row_start:row_end] # for x in range(size): # row_start = x * size # row_end = row_start + size # o = "" # for v in verts[row_start:row_end]: # o += " (%1.2f, %1.2f, %1.2f)" % (v.x, v.y, v.z) # Generate noise #data = [self._noise.ridged_multi_fractal3(v[0], v[1], v[2], 0, 1.0) for v in t_data] #data = [self._noise.ridged_multi_fractal3(v[0], v[1], v[2], 0, 1.0) for v in t_data] # data = [perlin.noise3(v.x, v.x, v.x) * 255.0 for v in verts] # first_scale = 8 * self._octaves #second_scale = 0.5 * self._octaves # data = [] noise = self._generated_noise[address] # t_data = [] # for x in xrange(size-1, -1, -1): # row_start = x * size # row_end = row_start + size # t_data += noise[row_start:row_end] # for x in range(size): # row_start = x * size # row_end = row_start + size # noise = t_data colour_data = [] #for v in verts: # for n in noise: for y in range(self._increments):#,-1,-1): nv = [] for x in range(self._increments):#,-1,-1): n = noise[x][y] # # convert the height to a colour value # #height = ( (v.magnitude() - self._radius) / self._max_height ) * 255.0 #nv.append(n) # if n > 1.0: # print "n: %3.2f x: %d y: %d" % ( n, x, y) height = (n * 128.0) + 128.0 # #height = 150.0 # #print height colour = Preset.white if 200 >= height >= 150: colour = Preset.green elif 150 > height > 100: colour = Preset.yellow elif 100 >= height: colour = Preset.blue # if 50 > height: # colour = Preset.blue # else: # colour = Preset.red # if x == 0 or x == self._increments-1: # colour = Preset.yellow # if y == 0 or y == self._increments-1: # colour = Preset.green # colour = Preset.red # colour = colour.tinted(Preset.green, (y/float(size))) # colour = colour.tinted(Preset.blue, (x/float(size))) colour_data += [colour.r * 255.0, colour.g * 255.0, colour.b * 255.0, colour.a * 255.0] # s = "" # for n in noise[x]: # s += "\t%0.3f," % n # print s #e = datetime.now() - b #print "%s Tex Colours Gen time: %3.5f" % (address, e.total_seconds())#(e.seconds + (e.microseconds / 1000000.0) ) ) # colour_data = [] # for n in noise: # nv.append(n) # height = (n * 128.0) + 128.0 # if 100 > height: # colour = Preset.blue # else: # colour = Preset.red # colour_data += [colour.r * 255.0, colour.g * 255.0, colour.b * 255.0, colour.a * 255.0] #b = datetime.now() # Transform noise to colour data array_data = numpy.array(colour_data, 'f') # array_data = numpy.random.random_integers(low=0, # high=255, # size = (size * size, format_size)) #array_data *= 255 # array_data[:,3] = 255 array_data.shape = -1 tex_data = (GLubyte * array_data.size)(*array_data.astype('u1')) #test_plane = SceneManager.get_instance().current_scene.root.transform.get_child_with_name("test_plane") texture_name = "planet_texture_%s" % address new_planet_texture = GeneratedTexture(name=texture_name, width=size, height=size) new_planet_texture.wrapped = False new_planet_texture.smoothed = True new_planet_texture.set_data(format, pitch, tex_data) TextureManager.get_instance().add_texture(new_planet_texture) #test_plane.node.renderer.material.texture = "planet_texture" #e = datetime.now() - b #print "%s Tex Gen Vid card copy time: %3.5f" % (address, e.total_seconds())#(e.seconds + (e.microseconds / 1000000.0) ) ) #new_planet_texture.image.save(texture_name+'.png') self._generated_textures[address] = texture_name return texture_name
def __init__(self): # Load Configuration settings ConfigurationManager.load_configuration() #Start Logger method = Settings.get('LoggerSettings','method') filename = Settings.get('LoggerSettings','filename') to_console = Settings.get('LoggerSettings','log_to_console') Logger.Configure(method, filename, to_console) Logger.Log('Initialising Core Systems') # The order of initialisation in this function is extremely important # as it determines the order in which classes will receive events. # For instance it is important that input is processed # Start Event System so it can receive new listeners when the # classes below are initialised self._event_manager = EventManager.get_instance() #Register Core Event Listener for detecting quit self._core_listener = CoreListener(False) # Initialise Time self._time = Time.get_instance() # Create a Scene self._scene = SceneManager.get_instance() self._scene.init() #Start Render System self._render_manager = RenderManager.get_instance() self._render_manager.init( Settings.get('DisplaySettings','resolution')[0], Settings.get('DisplaySettings','resolution')[1], Settings.get('DisplaySettings','window_title') ) # Setup the framework callbacks self._framework = FrameworkManager.framework() self._framework.setup = self.setup self._framework.run_loop = self.update self._framework.on_draw = self._render_manager.draw self._framework.on_shutdown = self.shutdown # Setup Frame Start/End Events self._frame_start = FrameStarted() self._frame_end = FrameEnded() #Get the Texture Manager self._texture_manager = TextureManager.get_instance() # Start the ShaderManager self._shader_manager = ShaderManager.get_instance() # Start Scripting System self._script_manager = ScriptManager.get_instance() # Start the UI Manager and setup the MainUI self._ui_manager = UIManager.get_instance() self._main_ui = MainUI() # Start the GizmoManager system self._gizmo_manager = GizmoManager.get_instance() # Configure the ResourceManager self._resource_manager = ResourceManager.get_instance() # enable Image Loading self._resource_manager.add_handler(ImageResourceHandler()) # enable Scene Loading self._resource_manager.add_handler(SceneResourceHandler()) # enable Wavefront Obj Loading self._resource_manager.add_handler(WavefrontResourceHandler())
# Get the name name = None if "name" in node.attrib: name = node.attrib["name"] # If the texture is referenced by filename if "filename" in node.attrib: # Load the texture filename = node.attrib["filename"] texture = ResourceManager.get_instance().process_resource(filename, name) # If the texture is just a reference, retrieve it from the TextureManager for assignment if texture is None and name is not None: texture = TextureManager.get_instance().get_texture_by_name(name) # If the current parent is a Material node, set the material node's texture if not parent is None: if isinstance(parent, BaseMaterial) and not texture is None: parent.texture = texture # elif node.tag == "shader": # pass # Unknown XML tag else: self._log.Log("WARNING: Unknown XML Tag: " + node.tag) # If it's not a node that has already had it's children processed if not node.tag in ["children","scripts","material"]: