Hello all,
I have implemented some of the features I was requesting for the realXtend scene format:
- Fix .rex file extension to .txml as it should be, this is the extension of the format it is generating.
- Split big Scene.material file to individual material files. This means "material MyTestMaterial { ...}" will get MyTestMaterial.material file.
- Fix rex scene document material references to point to these individual files depending on what materials the object is using. Multiple materials are supported also with the proper ; separated list that Tundra understands. I left note there though as the submesh indexes might not align with the obj.data.materials list indexes. But like this its already much better than precious "Scene.material" for each. Even if submesh indexes end they have the data in the scene and can switch between materials in the Tundra viewer.
- Dont insert anyting to material ref value if object does not have values, this will only produce ugly warning/error prints when you import the .txml file into Tundra.
- Fixed file:// to local:// as this is the proper schema for local files in Tundras AssetAPI.
Now my problem is to get this code in
I have been added as a contributor but I don't have rights to commit. So
SRombauts or
bret please apply the changes to the repo.
Here is the patch file hopefully it is easy to apply. This has been done agains the "Default" branch, not the "BlendeSVN". Im sure the patch will apply to the other branch with no problems too. I'm unsure how hg uses patch files, tried to google em but didn't find much, the gui tool let me at least generate one.
http://dl.dropbox.com/u/3589544/code/tu ... ents.patch Let me know when its applied, I have people ready to test it! Thanks!
Once more in text format so people can read it:
Code: Select all
@@ -4137,10 +4137,17 @@
M = MISSING_MATERIAL + '\n'
for mat in mats:
Report.materials.append( mat.name )
- M += self.gen_dot_material( mat, path, convert_textures=True )
+ data = self.gen_dot_material( mat, path, convert_textures=True )
+ M += data
+ self.dot_material_write_separate( mat, data, path )
url = os.path.join(path, '%s.material' %bpy.context.scene.name)
f = open( url, 'wb' ); f.write( bytes(M,'utf-8') ); f.close()
print('saved', url)
+
+ def dot_material_write_separate( self, mat, data, path = '/tmp' ):
+ url = os.path.join(path, '%s.material' % mat.name)
+ f = open(url, 'wb'); f.write( bytes(data,'utf-8') ); f.close()
+ print('saved', url)
## python note: classmethods prefer attributes defined at the classlevel, kinda makes sense, (even if called by an instance)
@classmethod
@@ -4214,16 +4221,33 @@
a = doc.createElement('attribute'); c.appendChild(a)
a.setAttribute('name', "Mesh ref" )
- a.setAttribute('value', "file://%s.mesh"%ob.data.name )
+ a.setAttribute('value', "local://%s.mesh"%ob.data.name )
a = doc.createElement('attribute'); c.appendChild(a)
a.setAttribute('name', "Mesh materials" )
- a.setAttribute('value', "file://%s.material"%bpy.context.scene.name )
+
+ # Query object its materials and make a proper material ref string of it.
+ # note: We assume blindly here that the 'submesh' indexes are correct in the material list.
+ # the most common usecase is to have one material per object for rex artists.
+ # They can now assign multiple and they will at least go to the .txml data but I cant
+ # guarantee that they are in correct submesh index slots! At least they have the refs and
+ # can manually shift them around in the viewer.
+ mymaterials = ob.data.materials
+ if mymaterials != None and len(mymaterials) > 0:
+ mymatstring = ''
+ # generate ; separated material list and remove last ;
+ for mymat in mymaterials:
+ mymatstring += 'local://' + mymat.name + '.material;'
+ mymatstring = mymatstring[0:-1]
+ a.setAttribute('value', mymatstring )
+ else:
+ # defaul to nothing to avoid error prints in .txml import
+ a.setAttribute('value', "" )
if ob.find_armature():
a = doc.createElement('attribute'); c.appendChild(a)
a.setAttribute('name', "Skeleton ref" )
- a.setAttribute('value', "file://%s.skeleton"%ob.data.name )
+ a.setAttribute('value', "local://%s.skeleton"%ob.data.name )
a = doc.createElement('attribute'); c.appendChild(a)
a.setAttribute('name', "Draw distance" )
@@ -4415,7 +4439,7 @@
if self.EX_SCENE:
data = rex.toprettyxml()
- f = open( url+'.rex', 'wb' ); f.write( bytes(data,'utf-8') ); f.close()
+ f = open( url+'.txml', 'wb' ); f.write( bytes(data,'utf-8') ); f.close()
print('realxtend scene dumped', url)
data = doc.toprettyxml()
Ps. I was very suprised that the whole file used TABs instead of 4 spaces :I Well that I can get over with. But SRombauts was right that the one big >4000 lines python file is not good, I spent 10x more time looking at the spots I need to poke than to write the actual implementation. "class MaterialManager" in a separate file would have helped immensely