def update_attribute(entity_name, index, value, tuple_bit=-1, type_val=None): global _entity_configs cast_map = {'string': str, 'float': float, 'int': int} if type_val != None: if type_val != 'list': value = cast_map[type_val](value) else: value = value.split(',') attrib_name = None for i, val in enumerate(_entity_configs[entity_name].keys()): if i == index: attrib_name = val print(attrib_name) e = diskovery.entity(entity_name) if tuple_bit != -1: v = _entity_configs[entity_name][attrib_name] if tuple_bit == 0: setattr(e, attrib_name, glm.vec3(float(value), v[1], v[2])) if tuple_bit == 1: setattr(e, attrib_name, glm.vec3(v[0], float(value), v[2])) if tuple_bit == 2: setattr(e, attrib_name, glm.vec3(v[0], v[1], float(value))) else: if hasattr(e, attrib_name): if attrib_name != 'name': setattr(e, attrib_name, value) else: l = getattr(e, attrib_name) l = value if hasattr( e, 'heightmap' ) and attrib_name != 'position' and attrib_name != 'name': e.make_mesh() if hasattr(e, attrib_name): update_config(e, None, attrib_name) if e.chi != None: child = diskovery.entity(e.chi) if tuple_bit != -1: v = _entity_configs[entity_name][attrib_name] if tuple_bit == 0: setattr(child, attrib_name, glm.vec3(float(value), v[1], v[2])) if tuple_bit == 1: setattr(child, attrib_name, glm.vec3(v[0], float(value), v[2])) if tuple_bit == 2: setattr(child, attrib_name, glm.vec3(v[0], v[1], float(value))) else: setattr(child, attrib_name, value) update_config(child, entity_name, attrib_name)
def delete_entity(self, e): global _selected, _root item = self.env.curselection()[0] print(diskovery.entity(self.env.get(item)).chi) if diskovery.entity(self.env.get(item)).chi != None: diskovery.remove_entity(diskovery.entity(self.env.get(item)).chi) diskovery.remove_entity(self.env.get(item)) diskovery_scene_manager.remove_config(self.env.get(item)) self.env.delete(item) diskovery.deselect() _selected = None
def update(self, ind): diskovery.RenderedEntity.update(self, ind) lit = Boolean(self.is_lit) self.uniforms[2].update(lit.get_data(), ind) tint = Tint(self.tint) self.uniforms[3].update(tint.get_data(), ind) selected = Boolean(self.selected) self.uniforms[4].update(selected.get_data(), ind) col = Color(self.color) self.uniforms[5].update(col.get_data(), ind) if self.selected: diskovery.entity("Cursor").show() diskovery.entity("Cursor").position = self.position diskovery.entity("Cursor").rotation = self.rotation manip_param = self.position manip_param += self.left() * self.speed * diskovery.input( "ObjMoveX") * diskovery.frame_time() manip_param += -self.forward() * self.speed * diskovery.input( "ObjMoveZ") * diskovery.frame_time() manip_param += -self.up() * self.speed * diskovery.input( "ObjMoveY") * diskovery.frame_time() if self.chi != None: diskovery.entity(self.chi).position = self.position diskovery.entity(self.chi).rotation = self.rotation diskovery_scene_manager.update_config(self, self.name, 'position')
def __init__(self, position, rotation, scale): diskovery.RenderedEntity.__init__( self, position=position, rotation=rotation, scale=scale, shader_str=self.presets['shader_str'], mesh_str=self.presets['mesh_str'], textures_str=self.presets['textures_str'], light_scene="Terrain") self.position.y = get_height(self.position.x, self.position.z, diskovery.entity("land")) + 0.01
def update(self, ind): diskovery.AnimatedEntity.update(self, ind) self.position += self.forward() * -self.speed * diskovery.input( "WalkY") * diskovery.frame_time() self.position += self.left() * self.speed * diskovery.input( "WalkX") * diskovery.frame_time() if diskovery.input("WalkX") == 0 and diskovery.input("WalkY") == 0: self.running = False else: self.running = True if self.running and not self.animator.playing(): self.animator.play("Run") elif not self.running and self.animator.playing(): self.animator.stop() self.position.y = get_height(self.position.x, self.position.z, diskovery.entity("land")) self.rotation.y += diskovery.input( "Rotate") * -self.speed * diskovery.frame_time() * 0.05