Пример #1
0
def convert_by_type(file_type, file_path, is_bin=False):
    file_type = file_type.lower()
    # 1. check file_type
    if file_type not in ['stl', 'stp', 'iges', 'obj', 'fbx']:
        raise ConvertException('convert file type is not support, type:' +
                               file_type)
    result = False
    # 1.1 check file_path
    if not os.path.exists(file_path):
        raise ConvertException('convert file need exists, file:' + file_path)
    # 2. file_type to handler
    model = ModelFactory.make_model(file_type)

    result = model.handler(file_path, is_bin)
    return result
Пример #2
0
def get_convert_information(redis, req_id):
    json_str = redis.get(info_key_prefix + str(req_id))

    if json_str == None:
        raise ConvertException(
            'convert file information is not found,req_id: ' + str(req_id))
    return json.loads(json_str)
Пример #3
0
 def convert_to_draco_gltf(file_path,
                           convert_stl_path,
                           is_bin=False,
                           clear_stl_source=False,
                           clear_convert_stl=False):
     # todo:: remove too many flag
     # 1. convert binary stl to gltf
     if is_bin:
         convert_gltf_path = file_path + '.glb'
         out_convert_gltf_path = file_path + '.zip' + '.glb'
         stl_to_gltf(convert_stl_path, convert_gltf_path, is_bin)
     else:
         convert_gltf_path = file_path + '.gltf'
         output_path = os.path.dirname(convert_gltf_path)
         out_convert_gltf_path = os.path.join(output_path, 'out.gltf')
         stl_to_gltf(convert_stl_path, output_path, is_bin)
     # 2. gltf-pipeline
     try:
         if not gltf_pipeline(convert_gltf_path, out_convert_gltf_path):
             raise ConvertException('gltf draco fail, file:' +
                                    convert_gltf_path)
     finally:
         if clear_stl_source:
             StlModel.clear_file(file_path)
         if clear_convert_stl:
             StlModel.clear_file(convert_stl_path)
         StlModel.clear_file(convert_gltf_path)
     return out_convert_gltf_path
Пример #4
0
def convert_obj_handler(file_path, is_bin=False):
    if is_bin:
        convert_gltf_path = file_path + '.glb'
    else:
        convert_gltf_path = file_path + '.gltf'
    if not obj2gltf(file_path, convert_gltf_path, is_bin):
        raise ConvertException('obj convert draco gltf fail, file:' + convert_gltf_path)
    return convert_gltf_path
def convert_by_type(file_type, file_path):
    file_type = file_type.lower()
    # 1. check file_type
    if file_type not in ['stl', 'stp', 'iges']:
        raise ConvertException('convert file type is not support, type:' + file_type)
    result = False
    # 1.1 check file_path
    if not os.path.exists(file_path):
        raise ConvertException('convert file need exists, file:' + file_path)
    # 2. file_type to handler
    if file_type == 'stl':
        result = convert_stl_handler(file_path)
    elif file_type == 'stp':
        result = convert_stp_handler(file_path)
    elif file_type == 'iges':
        result = convert_iges_handler(file_path)

    return result
Пример #6
0
 def handler(self, file_path, is_bin):
     super(ObjModel, self).handler(file_path, is_bin)
     if is_bin:
         convert_gltf_path = file_path + '.glb'
     else:
         convert_gltf_path = file_path + '.gltf'
     if not obj2gltf(file_path, convert_gltf_path, is_bin):
         raise ConvertException('obj convert draco gltf fail, file:' +
                                convert_gltf_path)
     return convert_gltf_path
def convert_stl_to_draco_gltf(file_path, convert_stl_path):
    # 2. convert binary stl to gltf
    convert_gltf_path = file_path + '.glb'
    stl_to_gltf(convert_stl_path, convert_gltf_path, True)
    # 3. gltf-pipeline
    out_convert_gltf_path = file_path + '.zip' + '.glb'
    if not gltf_pipeline(convert_gltf_path, out_convert_gltf_path):
        raise ConvertException('gltf draco fail, file:' + convert_gltf_path)
    from setting import config
    if not config['app']['save_upload_temp_file']:
        clear_file(file_path, convert_stl_path, convert_gltf_path)
    return out_convert_gltf_path
Пример #8
0
 def make_model(file_type):
     if file_type == 'stl':
         return StlModel()
     elif file_type == 'stp':
         return StpModel()
     elif file_type == 'iges':
         return IgesModel()
     elif file_type == 'obj':
         return ObjModel()
     elif file_type == 'fbx':
         return FbxModel()
     else:
         raise ConvertException(file_type + ' model is not support')
Пример #9
0
def convert_stl_to_draco_gltf(file_path, convert_stl_path, is_bin=False):
    # 2. convert binary stl to gltf
    if is_bin:
        convert_gltf_path = file_path + '.glb'
        out_convert_gltf_path = file_path + '.zip' + '.glb'
        stl_to_gltf(convert_stl_path, convert_gltf_path, is_bin)
    else:
        convert_gltf_path = file_path + '.gltf'
        output_path = os.path.dirname(convert_gltf_path)
        out_convert_gltf_path = os.path.join(output_path, 'out.gltf')
        stl_to_gltf(convert_stl_path, output_path, is_bin)
    # 3. gltf-pipeline
    if not gltf_pipeline(convert_gltf_path, out_convert_gltf_path):
        raise ConvertException('gltf draco fail, file:' + convert_gltf_path)
    if not config['app']['save_upload_temp_file']:
        clear_file(file_path, convert_stl_path)
    if not config['app']['save_convert_temp_file']:
        clear_file(convert_gltf_path)
    return out_convert_gltf_path
def convert_fbx_handler(file_path):
    convert_gltf_path = file_path + '.glb'
    if not fbx2gltf(file_path, convert_gltf_path):
        raise ConvertException('fbx convert draco gltf fail, file:' + convert_gltf_path)
    return convert_gltf_path
def convert_obj_handler(file_path):
    convert_gltf_path = file_path + '.glb'
    if not obj2gltf(file_path, convert_gltf_path):
        raise ConvertException('obj convert draco gltf fail, file:' + convert_gltf_path)
    return convert_gltf_path
Пример #12
0
 def handler(self, file_path, is_bin):
     if not file_path:
         raise ConvertException("convert file can't be empty")
     if not (os.path.exists(file_path) and os.path.isfile(file_path)):
         raise ConvertException("convert file should be exists")