Update tools
This commit is contained in:
parent
db3f3065b9
commit
a36402686c
|
@ -10,20 +10,41 @@ from types import ModuleType
|
||||||
supported_formats = []
|
supported_formats = []
|
||||||
|
|
||||||
class ModelType:
|
class ModelType:
|
||||||
|
"""Represents a type of coding of 3D object, and the module enabling
|
||||||
|
parsing and exporting
|
||||||
|
"""
|
||||||
def __init__(self, typename, inner_module):
|
def __init__(self, typename, inner_module):
|
||||||
|
"""Creates a ModelType
|
||||||
|
|
||||||
|
:param typename: the name of the 3D format
|
||||||
|
:param inner_module: the module that will parse and export the format
|
||||||
|
"""
|
||||||
self.typename = typename
|
self.typename = typename
|
||||||
self.inner_module = inner_module
|
self.inner_module = inner_module
|
||||||
|
|
||||||
def test_type(self, file):
|
def test_type(self, file):
|
||||||
|
"""Tests if a file has the correct type
|
||||||
|
|
||||||
|
:param file: path to the file to test
|
||||||
|
"""
|
||||||
return getattr(self.inner_module, 'is_' + self.typename)(file)
|
return getattr(self.inner_module, 'is_' + self.typename)(file)
|
||||||
|
|
||||||
def create_parser(self, *args, **kwargs):
|
def create_parser(self, *args, **kwargs):
|
||||||
|
"""Creates a parser of the current type
|
||||||
|
"""
|
||||||
return getattr(self.inner_module, self.typename.upper() + 'Parser')(*args, **kwargs)
|
return getattr(self.inner_module, self.typename.upper() + 'Parser')(*args, **kwargs)
|
||||||
|
|
||||||
def create_exporter(self, *args, **kwargs):
|
def create_exporter(self, *args, **kwargs):
|
||||||
|
"""Creates an exporter of the current type
|
||||||
|
"""
|
||||||
return getattr(self.inner_module, self.typename.upper() + 'Exporter')(*args, **kwargs)
|
return getattr(self.inner_module, self.typename.upper() + 'Exporter')(*args, **kwargs)
|
||||||
|
|
||||||
def find_type(filename, supported_formats):
|
def find_type(filename, supported_formats):
|
||||||
|
"""Find the correct type from a filename
|
||||||
|
|
||||||
|
:param filename: path to the file
|
||||||
|
:param supported_formats: list of formats that we have modules for
|
||||||
|
"""
|
||||||
for type in supported_formats:
|
for type in supported_formats:
|
||||||
if type.test_type(filename):
|
if type.test_type(filename):
|
||||||
return type
|
return type
|
||||||
|
@ -34,6 +55,11 @@ for name in formats.__dict__:
|
||||||
supported_formats.append(type)
|
supported_formats.append(type)
|
||||||
|
|
||||||
def load_model(path, up_conversion = None):
|
def load_model(path, up_conversion = None):
|
||||||
|
"""Loads a model from a path
|
||||||
|
|
||||||
|
:param path: path to the file to load
|
||||||
|
:param up_conversion: conversion of up vectors
|
||||||
|
"""
|
||||||
parser = None
|
parser = None
|
||||||
type = find_type(path, supported_formats)
|
type = find_type(path, supported_formats)
|
||||||
|
|
||||||
|
@ -46,6 +72,11 @@ def load_model(path, up_conversion = None):
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def export_model(model, path):
|
def export_model(model, path):
|
||||||
|
"""Exports a model to a path
|
||||||
|
|
||||||
|
:param model: model to export
|
||||||
|
:param path: path to save the model
|
||||||
|
"""
|
||||||
exporter = None
|
exporter = None
|
||||||
type = find_type(path, supported_formats)
|
type = find_type(path, supported_formats)
|
||||||
|
|
||||||
|
@ -56,6 +87,12 @@ def export_model(model, path):
|
||||||
return exporter
|
return exporter
|
||||||
|
|
||||||
def convert(input, output, up_conversion = None):
|
def convert(input, output, up_conversion = None):
|
||||||
|
"""Converts a model
|
||||||
|
|
||||||
|
:param input: path of the input model
|
||||||
|
:param output: path to the output
|
||||||
|
:param up_conversion: convert the up vector
|
||||||
|
"""
|
||||||
model = load_model(input, up_conversion)
|
model = load_model(input, up_conversion)
|
||||||
exporter = export_model(model, output)
|
exporter = export_model(model, output)
|
||||||
return str(exporter)
|
return str(exporter)
|
||||||
|
|
Loading…
Reference in New Issue