From edd226da50ab7e960aee5e12004d9e8c42e23d24 Mon Sep 17 00:00:00 2001 From: Chris Xiong Date: Fri, 7 Sep 2018 12:31:34 +0800 Subject: Short description for the 3D XML addon. Readme for the repo. --- Virtools/3dxml.py | 45 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 9 deletions(-) (limited to 'Virtools/3dxml.py') diff --git a/Virtools/3dxml.py b/Virtools/3dxml.py index 5846497..149d9c6 100644 --- a/Virtools/3dxml.py +++ b/Virtools/3dxml.py @@ -1,14 +1,39 @@ -#Chris Xiong 2018 -#Expat (MIT) License +# Chris Xiong 2018 +# Expat (MIT) License bl_info={ - "name":"3DXML (3.0) import", - "description":"Import 3DXML 3.0", + "name":"3D XML (3.0) import", + "description":"Import 3D XML 3.0", "author":"Chris Xiong", "version":(0,1), "blender":(2,79,0), "category":"Import-Export", "support":"TESTING" } +################################################################ +# This addon enables blender to import 3D XML 3.0 documents. +# It partially implemented the 3D XML specification 3.0 from +# Dassault Systèmes. Testing was done with files exported +# from 3DVIA Virtools 5.0. +# +# The development took place solely on Linux. It may experience +# problems on other platforms. +# +# This addon started off as a fork of this script: +# https://www.blender.org/forum/viewtopic.php?t=18299 +# Later it was rewritten from scratch to better reflect the +# specification. +# +# To report bugs, mail me a minimal 3D XML file that can +# reproduce the issue together with the details of the bug. +# +# References: +# 1) 3D XML Reference Documentation 3.0: +# http://media.3ds.com/3dxml/3dxmldoc/Reference_Guide/3DXML_Reference_Guide.html +# 2) 3D XML 3.0 XSD schema: +# http://media.3ds.com/3dxml/3dxmldoc/3DXML.xsd +# 3) 3D XML User's Guide 3.0: +# http://media.3ds.com/3dxml/3dxmldoc/3DXML_User_Guide.pdf +################################################################ import bpy,bmesh,bpy_extras,mathutils import xml.etree.ElementTree as etree import pathlib,zipfile,time,os,tempfile @@ -109,10 +134,10 @@ def load_objects(tree): obj.select=True bpy.ops.object.shade_smooth() -def create_mesh(verts,faces,facemat,uvs,objidx): +def create_mesh(verts,faces,facemat,uvs,meshidx): if len(uvs)>len(verts): uvs.append([uvs[0]]*(len(verts)-len(uvs))) - objname=f"Mesh_{objidx}" + meshname=f"Mesh_{meshidx}" mesh=bmesh.new() for i in verts: mesh.verts.new(i) @@ -129,10 +154,10 @@ def create_mesh(verts,faces,facemat,uvs,objidx): for face in mesh.faces: for lp in face.loops: lp[uv].uv=mathutils.Vector(uvs[lp.vert.index]) - msh=bpy.data.meshes.new(objname) + msh=bpy.data.meshes.new(meshname) mesh.to_mesh(msh) msh.use_auto_smooth=True - meshes[objidx]=msh + meshes[meshidx]=msh mesh.free() def unflatten(seq,func,step,fac=1): @@ -149,7 +174,7 @@ def read(filename): try: member=zf.namelist().index("Root.3dxml") except ValueError: - print("not a 3DXML 3.0 file!") + raise RuntimeError("not a 3D XML 3.0 file!") filename=zf.open("Root.3dxml") for im in zf.namelist(): if im.endswith(".tga"): @@ -158,6 +183,8 @@ def read(filename): tf.flush() texturefiles[im]=tf.name tf.close() + else: + print("Warning: the file will be treated as a bare XML document.") tree=etree.parse(filename) load_textures(tree) load_materials(tree) -- cgit v1.2.3