Skip to content

Commit abdf53b

Browse files
committed
little fixes
1 parent cbe1126 commit abdf53b

2 files changed

Lines changed: 41 additions & 48 deletions

File tree

io_scene_udatasmith/data_types.py

Lines changed: 40 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -359,46 +359,36 @@ def __init__(self):
359359
UDShader.shader_count += 1
360360

361361
class UDMasterMaterial(UDMaterial):
362-
class Prop:
363-
prop_type = None
364-
def __init__(self, value):
365-
self.value = value
366-
def render(self, parent, name):
367-
return ElementTree.SubElement(parent, 'KeyValueProperty', name=name, type=self.prop_type, val=repr(self))
368-
def __repr__(self):
369-
return repr(self.value)
370-
class PropColor(Prop):
371-
prop_type = 'Color'
372-
def __init__(self, value):
373-
self.parse(value) if type(value) == str else super().__init__(value)
374-
def parse(self, src):
375-
import re
376-
self.value = tuple(map(float, re.match(r"\(R=(-?[\d.]*),G=(-?[\d.]*),B=(-?[\d.]*),A=(-?[\d.]*)\)", src).groups()))
377-
def __repr__(self):
378-
r, g, b, a = (1.0,1.0,1.0,1.0)
379-
return '(R={:6f},G={:6f},B={:6f},A={:6f})'.format(r, g, b, a)
380-
class PropBool(Prop):
381-
prop_type = 'Bool'
382-
def __init__(self, value):
383-
self.value = value
384-
if type(value) is str:
385-
self.value = True if value == 'true' else False
386-
def __repr__(self):
387-
return 'true' if self.b else 'false'
388-
class PropTexture(Prop):
389-
prop_type = 'Texture'
390-
class PropFloat(Prop):
391-
prop_type = 'Float'
392-
def __init__(self, value):
393-
self.value = value
394-
if type(value) is str:
395-
self.value = float(value)
362+
def prop_color(value):
363+
data = {
364+
'prop_type': 'Color'
365+
}
366+
data['value'] = tuple(map(float, re.match(r"\(R=(-?[\d.]*),G=(-?[\d.]*),B=(-?[\d.]*),A=(-?[\d.]*)\)", src).groups()))
367+
return data
368+
369+
def prop_bool(Prop):
370+
data = {
371+
'prop_type': 'Bool'
372+
}
373+
data['value'] = True if value == 'true' else False
374+
return data
375+
376+
def prop_texture(value):
377+
return {
378+
'prop_type': 'Texture'
379+
}
380+
381+
def prop_float(value):
382+
return {
383+
'prop_type': 'Float',
384+
'value': float(value),
385+
}
396386

397387
types = {
398-
"Color": PropColor,
399-
"Bool": PropBool,
400-
"Texture":PropTexture,
401-
"Float": PropFloat,
388+
"Color": prop_color,
389+
"Bool": prop_bool,
390+
"Texture": prop_texture,
391+
"Float": prop_float,
402392
}
403393

404394
'''sketchup datasmith outputs Master material, it may be different'''
@@ -409,15 +399,17 @@ def __init__(self, *args, node=None, **kwargs):
409399
self.properties = {}
410400
if node is not None:
411401
for prop in node.findall('KeyValueProperty'):
412-
self.properties[prop.attrib['name']] = UDMasterMaterial.types[prop.attrib['type']](prop.attrib['val'])
402+
prop_name = prop.attrib['name']
403+
prop_type = prop.attrib['type']
413404

414-
def render(self, parent):
415-
elem = super().render(parent)
416-
elem.attrib['Type'] = '1'
417-
elem.attrib['Quality'] = '0'
418-
elem.attrib['label'] = self.name
419-
for name, prop in self.properties.items():
420-
prop.render(name=name, parent=elem)
405+
self.properties[name] = UDMasterMaterial.types[prop.attrib['type']](prop.attrib['val'])
406+
407+
@staticmethod
408+
def new(name, parent, node):
409+
ob = UDScene.current_scene.get_field(UDMasterMaterial, name)
410+
if ob:
411+
return ob
412+
return UDMasterMaterial(node=node, name=name)
421413

422414
class UDTexture(UDElement):
423415
node_type = 'Texture'
@@ -655,7 +647,7 @@ def __init__(self, source=None):
655647
def get_field(self, cls, name):
656648
group = getattr(self, cls.node_group)
657649
if not group:
658-
print("trying to write invalid group")
650+
log.error("trying to get invalid group")
659651

660652
if name in group:
661653
return group[name]
@@ -699,6 +691,7 @@ def init_with_path(self, path):
699691

700692
mappings = {cls.node_type:cls for cls in classes}
701693

694+
UDScene.current_scene = self
702695
for node in root:
703696
name = node.get('name') # most relevant nodes have a name as identifier
704697
cls = mappings.get(node.tag)

io_scene_udatasmith/export_datasmith.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ def collect_object(bl_obj, uscene, context, parent = None, dupli_matrix=None, na
276276

277277
obj_mat = matrix_datasmith @ mat_basis @ matrix_datasmith.inverted()
278278

279-
if bl_obj.type == 'CAMERA' or bl_obj.type == 'LAMP':
279+
if bl_obj.type == 'CAMERA' or bl_obj.type == 'LIGHT':
280280
# use this correction because lights/cameras in blender point -Z
281281
obj_mat = obj_mat @ matrix_forward
282282

0 commit comments

Comments
 (0)