Пример #1
0
    def __init__(self, material_instance_name, **data):
        self.valid = False
        self.isNeedToSave = False
        logger.info("Load Material Instance : " + material_instance_name)
        self.name = material_instance_name
        self.shader_name = data.get('shader_name', 'default')
        self.material = None
        self.material_name = data.get('material_name', 'default')
        self.macros = copy.copy(data.get('macros', OrderedDict()))
        self.linked_uniform_map = dict()
        self.linked_material_component_map = dict()
        self.Attributes = Attributes()

        material = data.get('material')

        # link uniform_buffers and uniform_data
        self.set_material(material)

        if self.material:
            # and set the loaded uniform data.
            uniform_datas = data.get('uniform_datas', {})
            for data_name, data_value in uniform_datas.items():
                self.set_uniform_data_from_string(data_name, data_value)
        else:
            logger.error("%s material instance has no material." % self.name)
            return

        self.valid = True
Пример #2
0
 def bind_uniform(self, texture, num=1, transpose=False):
     if texture:
         glActiveTexture(GL_TEXTURE0 + self.textureIndex)
         # glEnable(GL_TEXTURE_CUBE_MAP)
         texture.bind_texture(
         )  # glBindTexture(texture.target, texture.texture_bind
         glUniform1i(self.location, self.textureIndex)
     else:
         logger.error("%s %s is None" %
                      (self.name, self.__class__.__name__))
Пример #3
0
def CreateVertexArrayBuffer(geometry_data):
    geometry_name = geometry_data.get('name', '')
    logger.info("Load %s geometry." % geometry_name)

    vertex_count = len(geometry_data.get('positions', []))
    if vertex_count == 0:
        logger.error("%s geometry has no position data." % geometry_name)
        return None

    positions = np.array(geometry_data['positions'], dtype=np.float32)

    if 'indices' not in geometry_data:
        logger.error("%s geometry has no index data." % geometry_name)
        return None

    indices = np.array(geometry_data['indices'], dtype=np.uint32)

    bone_indicies = np.array(geometry_data.get('bone_indicies', []),
                             dtype=np.float32)

    bone_weights = np.array(geometry_data.get('bone_weights', []),
                            dtype=np.float32)

    colors = np.array(geometry_data.get('colors', []), dtype=np.float32)
    if len(colors) == 0:
        colors = np.array([[1.0, 1.0, 1.0, 1.0]] * vertex_count,
                          dtype=np.float32)

    texcoords = np.array(geometry_data.get('texcoords', []), dtype=np.float32)
    if len(texcoords) == 0:
        texcoords = np.array([[0.0, 0.0]] * vertex_count, dtype=np.float32)

    normals = np.array(geometry_data.get('normals', []), dtype=np.float32)
    if len(normals) == 0:
        normals = np.array([
            [0.0, 0.0, 1.0],
        ] * vertex_count,
                           dtype=np.float32)

    tangents = np.array(geometry_data.get('tangents', []), dtype=np.float32)
    if len(tangents) == 0:
        tangents = compute_tangent(positions, texcoords, normals, indices)
        geometry_data['tangents'] = tangents.tolist()

    if 0 < len(bone_indicies) and 0 < len(bone_weights):
        vertex_array_buffer = VertexArrayBuffer(geometry_name, [
            positions, colors, normals, tangents, texcoords, bone_indicies,
            bone_weights
        ], indices)
    else:
        vertex_array_buffer = VertexArrayBuffer(
            geometry_name, [positions, colors, normals, tangents, texcoords],
            indices)
    return vertex_array_buffer
Пример #4
0
 def unregist_resource(self, object):
     if object and object.name in self.objectMap:
         object_type = type(object)
         object_list = self.get_object_list(object_type)
         object_list.remove(object)
         self.objectMap.pop(object.name)
         self.update_render_info(object_type)
         self.core_manager.notifyDeleteObject(object.name)
     else:
         logger.error("SceneManager::unregist_resource error. %s" %
                      object.name if object else 'None')
Пример #5
0
 def regist_object(self, object):
     if object and object.name not in self.objectMap:
         object_type = type(object)
         object_list = self.get_object_list(object_type)
         object_list.append(object)
         self.objectMap[object.name] = object
         self.update_render_info(object_type)
         self.core_manager.sendObjectInfo(object)
     else:
         logger.error("SceneManager::regist_object error. %s" %
                      object.name if object else 'None')
Пример #6
0
 def open_project_next_time(self, project_filename):
     try:
         if os.path.exists(project_filename):
             # will be open
             self.next_open_project_filename = project_filename
             self.core_manager.close()
             return
     except:
         logger.error(traceback.format_exc())
     if project_filename:
         logger.error("Failed open %s." % project_filename)
Пример #7
0
 def save_project(self):
     try:
         if self.config and self.project_filename != self.resource_manager.DefaultProjectFile:
             main_camera = self.core_manager.scene_manager.main_camera
             if main_camera:
                 main_camera.write_to_config(self.config)
             self.config.save()
         return
     except:
         logger.error(traceback.format_exc())
     if self.project_filename:
         logger.error("Failed save %s." % self.project_filename)
Пример #8
0
 def set_uniform_data_from_string(self, uniform_name, str_uniform_data):
     uniform = self.linked_uniform_map.get(uniform_name)
     if uniform:
         uniform_buffer = uniform[0]
         if uniform_buffer:
             uniform_data = CreateUniformDataFromString(
                 uniform_buffer.uniform_type, str_uniform_data)
             if uniform_data is not None:
                 uniform[1] = uniform_data
                 return True
     logger.error(
         '%s material instance set data error : %s uniform variable %s.' %
         (self.name, uniform_name, str_uniform_data))
Пример #9
0
    def test_login(self, case):
        logger.info('开始测试:{}'.format(case.title))
        logger.info('测试用例入参:{}'.format(case.data))
        print('开始测试:{}'.format(case.title))
        print('测试用例入参:{}'.format(case.data))

        resp = self.http_request.request(case.method, case.url, case.data)
        try:
            self.assertEqual(case.expected, resp.text)
            self.excel.write_result(case.case_id + 1, resp.text, 'PASS')
        except AssertionError as e:
            self.excel.write_result(case.case_id + 1, resp.text, 'FAILED')
            logger.error('ERROR:{}'.format(e))
            raise e
        logger.info('结束测试:{}'.format(case.title))
Пример #10
0
def CreateUniformBuffer(program, uniform_type, uniform_name):
    """ create uniform buffer from .mat(shader) file """
    uniform_classes = [
        UniformBool, UniformInt, UniformFloat, UniformVector2, UniformVector3,
        UniformVector4, UniformMatrix2, UniformMatrix3, UniformMatrix4,
        UniformTexture2D, UniformTexture2DMultiSample, UniformTexture3D,
        UniformTextureCube
    ]
    for uniform_class in uniform_classes:
        if uniform_class.uniform_type == uniform_type:
            uniform_buffer = uniform_class(program, uniform_name)
            return uniform_buffer if uniform_buffer.valid else None
    else:
        logger.error('Cannot matched to %s type of %s.' %
                     (uniform_type, uniform_name))
    return None
Пример #11
0
    def new_project(self, new_project_dir):
        try:
            if new_project_dir:
                project_name = os.path.split(new_project_dir)[-1]
                self.resource_manager.prepare_project_directory(
                    new_project_dir)

                default_project_filename = os.path.join(
                    new_project_dir,
                    os.path.split(self.resource_manager.DefaultProjectFile)[1])
                project_filename = os.path.join(new_project_dir,
                                                project_name + ".project")
                if os.path.exists(default_project_filename
                                  ) and not os.path.exists(project_filename):
                    os.rename(default_project_filename, project_filename)
                else:
                    config = Config(project_filename, log_level)
                    config.save()

                self.open_project_next_time(project_filename)
        except:
            logger.error(traceback.format_exc())
Пример #12
0
def start_with_computer(enabled):
    """If enabled, create shortcut to start application with computer.
    If disabled, then delete the shortcut."""
    if not enabled:
        # User requests to not automatically start BleachBit
        if os.path.lexists(Common.autostart_path):
            # Delete the shortcut
            FileUtilities.delete(Common.autostart_path)
        return
    # User requests to automatically start BleachBit
    if os.path.lexists(Common.autostart_path):
        # Already automatic, so exit
        return
    if not os.path.exists(Common.launcher_path):
        logger.error('%s does not exist: ' % Common.launcher_path)
        return
    import shutil
    General.makedirs(os.path.dirname(Common.autostart_path))
    shutil.copy(Common.launcher_path, Common.autostart_path)
    os.chmod(Common.autostart_path, 0o755)
    if General.sudo_mode():
        General.chownself(Common.autostart_path)
Пример #13
0
def CreateUniformDataFromString(data_type, strValue=None):
    """ return converted data from string or default data """
    try:
        if data_type == 'bool':
            return np.bool(strValue) if strValue else np.bool(False)
        elif data_type == 'float':
            # return float(strValue) if strValue else 0.0
            return np.float32(strValue) if strValue else np.float32(0)
        elif data_type == 'int':
            # return int(strValue) if strValue else 0
            return np.int32(strValue) if strValue else np.int32(0)
        elif data_type in ('vec2', 'vec3', 'vec4'):
            componentCount = int(data_type[-1])
            if strValue is not None:
                vecValue = eval(
                    strValue) if type(strValue) is str else strValue
                if len(vecValue) == componentCount:
                    return np.array(vecValue, dtype=np.float32)
                else:
                    logger.error(
                        ValueError("%s need %d float members." %
                                   (data_type, componentCount)))
                    raise ValueError
            else:
                return np.array([
                    1.0,
                ] * componentCount, dtype=np.float32)
        elif data_type in ('mat2', 'mat3', 'mat4'):
            componentCount = int(data_type[-1])
            if strValue is not None:
                vecValue = eval(
                    strValue) if type(strValue) is str else strValue
                if len(vecValue) == componentCount:
                    return np.array(vecValue, dtype=np.float32)
                else:
                    logger.error(
                        ValueError("%s need %d float members." %
                                   (data_type, componentCount)))
                    raise ValueError
            else:
                return np.eye(componentCount, dtype=np.float32)
        elif data_type == 'sampler2D':
            texture = CoreManager.instance().resource_manager.getTexture(
                strValue or 'empty')
            return texture
        elif data_type == 'sampler2DMS':
            logger.warn('sampler2DMS need multisample texture.')
            return CoreManager.instance().resource_manager.getTexture('empty')
        elif data_type == 'sampler3D':
            return CoreManager.instance().resource_manager.getTexture(
                'default_3d')
        elif data_type == 'samplerCube':
            texture = CoreManager.instance().resource_manager.getTexture(
                strValue or 'default_cube')
            return texture
    except ValueError:
        logger.error(traceback.format_exc())
    return None