Skip to content

Commit

Permalink
glTF parsing improvement (scaling of the points), nodes importing
Browse files Browse the repository at this point in the history
  • Loading branch information
danila-schelkov committed Sep 11, 2022
1 parent a61f513 commit 8294a40
Show file tree
Hide file tree
Showing 28 changed files with 195 additions and 178 deletions.
9 changes: 2 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
## Python 3D Models Converter

**Version**: 0.8.8
A module, which helps convert different 3d formats

### **THIS IS NOT RELEASE VERSION!**

### Thanks a lot for motivating [AMIRMISTIK]!


[AMIRMISTIK]: https://www.youtube.com/channel/UCksd1LeoySP5St6dKlv6mvQ
**Version**: 0.9.0
3 changes: 2 additions & 1 deletion models_converter/formats/gltf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@
'Scene',
'Skin',
'Texture',
'Parser'
'Parser',
'Writer'
]
6 changes: 3 additions & 3 deletions models_converter/formats/gltf/accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ def __init__(self):
def __init__(self):
super().__init__()
self.count = None
self.indices = self.Indices()
self.values = self.Values()
self.indices = self.Indices
self.values = self.Values

def __init__(self):
super().__init__()
Expand All @@ -35,5 +35,5 @@ def __init__(self):
self.normalized = False
self.max = None
self.min = None
self.sparse = self.Sparse()
self.sparse = self.Sparse
self.name = None
6 changes: 3 additions & 3 deletions models_converter/formats/gltf/animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ def __init__(self):
def __init__(self):
super().__init__()
self.sampler = None
self.target = self.Target()
self.target = self.Target

def __init__(self):
super().__init__()
self.channels = self.Channel()
self.samplers = self.AnimationSampler()
self.channels = self.Channel
self.samplers = self.AnimationSampler

self.name = None

28 changes: 14 additions & 14 deletions models_converter/formats/gltf/gltf.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@
class GlTF(GlTFProperty):
def __init__(self):
super().__init__()
self.asset = Asset()
self.asset = Asset

self.extensions_used = None
self.extensions_required = None

self.accessors = Accessor()
self.animations = Animation()
self.buffers = Buffer()
self.buffer_views = BufferView()
self.cameras = Camera()
self.images = Image()
self.materials = Material()
self.meshes = Mesh()
self.nodes = Node()
self.samplers = Sampler()
self.accessors = Accessor
self.animations = Animation
self.buffers = Buffer
self.buffer_views = BufferView
self.cameras = Camera
self.images = Image
self.materials = Material
self.meshes = Mesh
self.nodes = Node
self.samplers = Sampler
self.scene = None
self.scenes = Scene()
self.skins = Skin()
self.textures = Texture()
self.scenes = Scene
self.skins = Skin
self.textures = Texture
32 changes: 17 additions & 15 deletions models_converter/formats/gltf/gltf_property.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
from models_converter.utilities.math import Vector3, Quaternion
from models_converter.utilities.matrix.matrix4x4 import Matrix4x4


def to_camelcase(property_name: str):
words = property_name.split('_')
for word_index in range(len(words)):
Expand All @@ -9,19 +13,16 @@ def to_camelcase(property_name: str):
return camelcase_name


def to_lowercase(property_name: str):
letters = list(property_name)

for letter_index in range(len(letters)):
letter = letters[letter_index]
def to_lowercase(property_name: str) -> str:
result = ''

if letter.isupper():
letter = f'_{letter.lower()}'
for char in property_name:
if char.isupper():
char = f'_{char.lower()}'

letters[letter_index] = letter
result += char

lowercase_name = ''.join(letters)
return lowercase_name
return result


class GlTFProperty:
Expand All @@ -36,13 +37,14 @@ def from_dict(self, dictionary: dict):
value_type = type(value)

attribute_value = getattr(self, attribute_name)
attribute_value_type = type(attribute_value)

if attribute_value is None or value_type in [int, str]:
if attribute_value is None or value_type in (int, str, bool):
attribute_value = value
elif issubclass(attribute_value_type, GlTFProperty):
elif type(attribute_value) in (Vector3, Quaternion, Matrix4x4) and type(value) is list:
attribute_value = type(attribute_value)(*value)
elif issubclass(attribute_value, GlTFProperty):
if value_type is list:
value_type = attribute_value_type
value_type = attribute_value
values = []

for item in value:
Expand All @@ -53,7 +55,7 @@ def from_dict(self, dictionary: dict):

attribute_value = values
else:
attribute_value = attribute_value_type()
attribute_value = attribute_value()
attribute_value.from_dict(value)

setattr(self, attribute_name, attribute_value)
Expand Down
2 changes: 1 addition & 1 deletion models_converter/formats/gltf/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def __init__(self):

def __init__(self):
super().__init__()
self.primitives = self.Primitive()
self.primitives = self.Primitive

self.weights = None
self.name = None
10 changes: 6 additions & 4 deletions models_converter/formats/gltf/node.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from .gltf_property import GlTFProperty
from ...utilities.math import Vector3, Quaternion
from ...utilities.matrix.matrix4x4 import Matrix4x4


class Node(GlTFProperty):
Expand All @@ -7,10 +9,10 @@ def __init__(self):
self.camera = None
self.children = None
self.skin = None
self.matrix = None # Default: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]
self.matrix = Matrix4x4(size=(4, 4))
self.mesh = None
self.rotation = None # Default: [0, 0, 0, 1]
self.scale = None # Default: [1, 1, 1]
self.translation = None # Default: [0, 0, 0]
self.rotation = Quaternion() # Default: [0, 0, 0, 1]
self.scale = Vector3(1, 1, 1) # Default: [1, 1, 1]
self.translation = Vector3() # Default: [0, 0, 0]
self.weights = None
self.name = None
Loading

0 comments on commit 8294a40

Please sign in to comment.