From a36402686c5638a3ce56192aaba43a4d30fe33cb Mon Sep 17 00:00:00 2001 From: Thomas FORGIONE Date: Wed, 18 Jan 2017 15:07:22 +0100 Subject: [PATCH] Update tools --- d3/model/tools.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/d3/model/tools.py b/d3/model/tools.py index 72fa143..7a427cc 100644 --- a/d3/model/tools.py +++ b/d3/model/tools.py @@ -10,20 +10,41 @@ from types import ModuleType supported_formats = [] class ModelType: + """Represents a type of coding of 3D object, and the module enabling + parsing and exporting + """ 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.inner_module = inner_module 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) def create_parser(self, *args, **kwargs): + """Creates a parser of the current type + """ return getattr(self.inner_module, self.typename.upper() + 'Parser')(*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) 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: if type.test_type(filename): return type @@ -34,6 +55,11 @@ for name in formats.__dict__: supported_formats.append(type) 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 type = find_type(path, supported_formats) @@ -46,6 +72,11 @@ def load_model(path, up_conversion = None): return parser 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 type = find_type(path, supported_formats) @@ -56,6 +87,12 @@ def export_model(model, path): return exporter 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) exporter = export_model(model, output) return str(exporter)