aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Virtools/3dxml.py31
1 files changed, 17 insertions, 14 deletions
diff --git a/Virtools/3dxml.py b/Virtools/3dxml.py
index 149d9c6..c95cbf8 100644
--- a/Virtools/3dxml.py
+++ b/Virtools/3dxml.py
@@ -5,7 +5,7 @@ bl_info={
"description":"Import 3D XML 3.0",
"author":"Chris Xiong",
"version":(0,1),
- "blender":(2,79,0),
+ "blender":(2,80,0),
"category":"Import-Export",
"support":"TESTING"
}
@@ -56,11 +56,11 @@ def load_textures(tree):
txp=[]
if txd.is_dir():
txp=[i for i in txd.iterdir() if i.stem.lower()==txname.lower()]
- if len(txp)<1 and tex.attrib["href"] is not None:
+ if len(txp)<1 and tex.attrib["href"] is not None and tex.attrib["href"] in texturefiles:
txp=[texturefiles[tex.attrib["href"]]]
- tx=bpy.data.textures.new(txname,'IMAGE')
+ tx=None
try:
- tx.image=bpy.data.images.load(str(txp[0]),True)
+ tx=bpy.data.images.load(str(txp[0]),check_existing=True)
except IndexError:
print(txname)
textures[tex.attrib["id"]]=tx
@@ -69,15 +69,20 @@ def load_materials(tree):
for mat in tree.findall(f".//{NS}GraphicMaterial"):
mname=mat.attrib["name"]
m=bpy.data.materials.new(mname)
- mslot=m.texture_slots.add()
+ m.use_nodes=True
+ for node in m.node_tree.nodes:
+ m.node_tree.nodes.remove(node)
+ bnode=m.node_tree.nodes.new(type="ShaderNodeBsdfPrincipled")
+ inode=m.node_tree.nodes.new(type="ShaderNodeTexImage")
+ mnode=m.node_tree.nodes.new(type="ShaderNodeOutputMaterial")
try:
- mslot.texture=textures[mat.attrib["texture"].split(":")[-1]]
+ inode.image=textures[mat.attrib["texture"].split(":")[-1]]
except KeyError:
pass
- m.diffuse_color=[float(mat.find(f"{NS}Diffuse").attrib[i])for i in ["red","green","blue"]]
- m.diffuse_intensity=float(mat.attrib["diffuseCoef"])
+ m.node_tree.links.new(inode.outputs[0],bnode.inputs[0])
+ m.node_tree.links.new(bnode.outputs[0],mnode.inputs[0])
+ m.diffuse_color=[float(mat.find(f"{NS}Diffuse").attrib[i])for i in ["red","green","blue"]]+[float(mat.attrib["diffuseCoef"])]
m.specular_color=[float(mat.find(f"{NS}Specular").attrib[i])for i in ["red","green","blue"]]
- m.specular_alpha=float(mat.find(f"{NS}Specular").attrib["alpha"])
m.specular_intensity=float(mat.attrib["specularCoef"])
materials[mat.attrib["id"]]=m
@@ -129,9 +134,7 @@ def load_objects(tree):
obj.data.materials.append(materials[m])
obj.matrix_world=_wmat
scn=bpy.context.scene
- scn.objects.link(obj)
- scn.objects.active=obj
- obj.select=True
+ scn.collection.objects.link(obj)
bpy.ops.object.shade_smooth()
def create_mesh(verts,faces,facemat,uvs,meshidx):
@@ -229,11 +232,11 @@ def menu_func_import_tdxml(self,context):
def register():
bpy.utils.register_class(ImportDialog)
bpy.utils.register_class(_3DXMLImport)
- bpy.types.INFO_MT_file_import.append(menu_func_import_tdxml)
+ bpy.types.TOPBAR_MT_file_import.append(menu_func_import_tdxml)
def unregister():
bpy.utils.unregister_class(_3DXMLImport)
- bpy.utils.unregister_class(ImportDialog)
+ bpy.utils.unrigister_class(ImportDialog)
if __name__=="__main__":
register()