Project Blender 2.63 + to Orbiter import/export addon

derludl

New member
Joined
Jun 7, 2010
Messages
4
Reaction score
0
Points
0
Export troubles when adding UV maps

Hello vlad32768,

first of all many thx for endowing us with your Blender 2.5 export addon, really appreciate your efforts! :thumbup:

Note number 7 in your python script
Code:
# 7. Some meshes (XR5 for example) have groups with missing UVs in some vertices. Usually this issue is fixed automatically,
#  but in some cases script could crash with "List index out of range" error. Please report if it happens!
encouraged me to bother you with some troubles I have exporting my models after having added UV maps to them.

I verified my troubles with the most simple setup - by UV unwrapping the cube that is shown when Blender starts. As soon as I add a UV map, exporting the mesh will throw the following error message:

Code:
line 627 in export_msh
  uvs=me.uv_textures[0].data[n].uv_raw[(2*i):(2*i+2)]
IndexError: byp_prop_collection[index]: index 0 out of range, size 0
(unfortunately I could not find out how to attach a screenshot via making a new album ... maybe because this is my first post, and I am not allowed to open a new album before I got approved to post?)

I'm currently using Blender 2.68.1 r38019, 64bit version on Windows7, and your latest export script from http://gitorious.org/blender-orbiter-io/blender-orbiter-io/archive-tarball/master

It should be easy to reproduce the issue by
- starting Blender
- going to edit mode, Unwrap the cube
- try to export the mesh ==> error thrown

Is there something wrong on my end, or some incompatibility between my Version of Blender and your script? Any idea how I could support debugging this issue?

Regards, Ludl

PS: btw, do you know this Blender 2.49->Orbiter.msh export script?: http://sourceforge.net/projects/blorbiter/
That script is nicely written, with plenty of comments, and has some nice features you might want to include in your export module as well, e.g. automatically generating *.dds files by writing and converting a *.bmp directly from python. Neat ;-)
 

derludl

New member
Joined
Jun 7, 2010
Messages
4
Reaction score
0
Points
0
Export troubles when adding UV maps - Update

Started to debug my problems, installed Winpdb to have a closer look what's going on - many things to learn about internal blender data structures ...

What I realized today is that the simple test case I described in my previous post is indeed throwing an error - but actually an other one than what I get when trying to export my own model.

Looks like the export script dislikes being in "Edit Mode" (instead of "Object Mode") when trying to export the UV unwrapped blender cube. Means:

- starting Blender
- going to "Edit Mode", Unwrap the cube
- remain in "Edit Mode" and try to export the mesh ==> will throw an error

while on the other hand:

- starting Blender
- going to "Edit Mode", Unwrap the cube
- switch back to "Object Mode" and try to export the mesh ==> no error!

As soon as I have learned more about Blender's API, I might better understand what's going wrong here. Meanwhile I just can recommend that whoever stumbles across above error should check if he's trying to export while being in "Edit Mode".

Me, for now, will try to look more into the details of the error thrown when trying to export my own model - which happens around line 679

Code:
if has_uv:
file.write(" {} {}".format(v[2][0],1-v[2][1]))

More to come, I hope ...
 

vlad32768

Member
Joined
Oct 11, 2010
Messages
78
Reaction score
0
Points
6
Ludl, thanks for your posts! Sorry for late answer, I was on vacation.

PS: btw, do you know this Blender 2.49->Orbiter.msh export script?:
I know that this script exists, but I didn't look at its code. Blender 2.4 has different API, and I decided not to learn Blender 2.4 API and to write my addon from scratch.
Also, I wanted to learn something about Python and Blender 2.5 API; that's why I wrote the addon.

About .dds converting. AFAIK Blorbiter uses an external utility to convert textures to .dds. I write my addon on a Linux workstation, and I don't know any cross-platform utility that can convert files to .dds. So this feature is not implemented, but it's easy to add it.

Looks like the export script dislikes being in "Edit Mode" (instead of "Object Mode") when trying to export the UV unwrapped blender cube. Means:

- starting Blender
- going to "Edit Mode", Unwrap the cube
- remain in "Edit Mode" and try to export the mesh ==> will throw an error

while on the other hand:

- starting Blender
- going to "Edit Mode", Unwrap the cube
- switch back to "Object Mode" and try to export the mesh ==> no error!

That's interesting! Didn't try to export while in Edit mode yet. Maybe some internal Blender structures are out of sync with Python API wrappers while Blender is in Edit mode.
When I have time I'll test the script with the latest Blender revision (already 2.59:)), reproduce this bug and try to fix it. I think the easiest way is to force Blender to go to the Object mode when necessary.
 

derludl

New member
Joined
Jun 7, 2010
Messages
4
Reaction score
0
Points
0
Export troubles when adding UV maps - Update2

Hello Vlad, thx for your reply, hope you had nice vacations ... ^^ :leaving:

Meanwhile I found out what was the problem when trying to export my model. As one could have expected, there were some issues in the model. There existed several orphaned vertices, some of them easily removed by Blenders "Remove Double" function (forget to do that after spin-duplicating), but after that done, still several hard-to-find vertices remained. Finally I found out that one can find and get them easily selected by commanding

Code:
bpy.ops.mesh.select_by_number_vertices(type='OTHER')
in Blenders Python console (one needs to be in Edit mode for this, I assume). After that done, no more error from your script!

Looking into the details of your script, I understand that the orphaned vertices are added to the vertex list, but as they are not enlisted in any face, your script fails when trying to add an UV index vector to them. Maybe one could just skip such orphaned vertices? For sure one could improve the error message, I assume ;-)

Regarding *.dds export: you are correct, blorbiter script utilizes "DxTex.exe", a Windows executable. If I should come across a linux *.dds converter I'll let you know ^^ (though chances should be small, especially if targeting for an all-platform solution).

Thx again for your export script! Ludl

PS: Blender2.59 - I need to upgrade ^^
 

vlad32768

Member
Joined
Oct 11, 2010
Messages
78
Reaction score
0
Points
6
Some changes:
-- Another fix due to API change. Addon now works with Blender 2.59.
-- Fixed that bug with exporting in Edit mode.
--Added "Delete orphan vertices" feature that helps to avoid "List index out of range" error when there are such vertices in selected meshes. Thanks Ludl for bug investigation!
 
Last edited:

derludl

New member
Joined
Jun 7, 2010
Messages
4
Reaction score
0
Points
0
Hi Vlad,

many thanks for continuing your work on exporting mesh files from Blender.

I've tested your latest version with Blender 2.59 on two of my old models (with orphaned vertices in), and your new option to remove those works like a charm! :thumbup:

Best regards, Ludl
 

vlad32768

Member
Joined
Oct 11, 2010
Messages
78
Reaction score
0
Points
6
Blender 2.63 is released! The long-anticipated Bmesh is finally here!

I updated the script, it should work with blender 2.63 and later. Now you can use NGons in your models. Download and enjoy!

I tested the script with a very little model with some NGons. Try it with your advanced models and report bugs.
 
Last edited:

N_Molson

Addon Developer
Addon Developer
Donator
Joined
Mar 5, 2010
Messages
9,290
Reaction score
3,258
Points
203
Location
Toulouse
How did I miss that thread ? :facepalm:

Now that's a really good reason to use Blender instead of Anim8tor...

Excellent work there ! :thumbup:
 

Hlynkacg

Aspiring rocket scientist
Addon Developer
Tutorial Publisher
Donator
Joined
Dec 27, 2010
Messages
1,870
Reaction score
3
Points
0
Location
San Diego
Havn't found any issues yet.

Thanks again Vlad. Congrats on a job well done.
 

Hielor

Defender of Truth
Donator
Beta Tester
Joined
May 30, 2008
Messages
5,580
Reaction score
2
Points
0
Blender 2.63 is released! The long-anticipated Bmesh is finally here!

I updated the script, it should work with blender 2.63 and later. Now you can use NGons in your models. Download and enjoy!

I tested the script with a very little model with some NGons. Try it with your advanced models and report bugs.
I assume you just triangulate the NGons when exporting to .msh?
 

Traveller

Donator
Donator
Joined
Apr 25, 2012
Messages
27
Reaction score
0
Points
1
Greetings from the Space Coast.

I just recently downloaded this program and some addons. From reading forum posts, about six weeks too late, considering where I live. So my timing is impeccable, as usual.

Anyway, I'm using Blender in modeling for another sim/ game I use. The workflow involving another program became too cumbersome, so I worked on a straight importer/ exporter for Blender. During the course of its development, I found and made use of the Blender 2.5x+ custom properties, and recently using those custom properties in my own UI panels. This was necessary because this particular file format has a lot of data which is not directly related to the 3D model-- though is utilized by the graphics engine for display. So when I read that you do not use ambient and emissive colors because Blender does not have them, I decided to offer up the following.

You can define and access custom properties in Blender. Some slightly modified code from my import and export routines is below. The data in the format I'm accessing is stored in integers and floating point numbers, hence the calls to custom routines in the code. Also, "XHeader" is ultimately a custom data structure into which all of the data is read for import, and then accessed for assignment into Blender variables. But you should be able to adapt it to yours. A lot of examples of of Blender custom properties have the properties tied to the Scene. Since the format I'm working with has custom data at the Object, Mesh, Material and Texture level, I decided to add the appropriate properties at each of those levels. This means that the custom property will only appear in the appropriate properties panel.

The definition (the subtype "COLOR" allows access to the color selector dialog in the UI panel):

Code:
    bpy.types.Material.Ambient_Color = bpy.props.FloatVectorProperty(name='Ambient_Color',size=3,subtype='COLOR',soft_min=0.0,soft_max=1.0,options={'HIDDEN'})
    bpy.types.Material.Ambient_Alpha = bpy.props.FloatProperty(name='Ambient_Alpha',soft_min=0.0,soft_max=1.0,options={'HIDDEN'})
    bpy.types.Material.Emit_Color = bpy.props.FloatVectorProperty(name='Emit_Color',size=3,subtype='COLOR',soft_min=0.0,soft_max=1.0,options={'HIDDEN'})
    bpy.types.Material.Emit_Alpha = bpy.props.FloatProperty(name='Emit_Alpha',soft_min=0.0,soft_max=1.0,options={'HIDDEN'})

The import/ assignment:
Code:
	XHeader.Materials.MaterialEntries[MaterialCount].Material.Ambient = XData.ReadColor()
        XHeader.Materials.MaterialEntries[MaterialCount].Material.Emissive = XData.ReadColor()
	#...a lot of import and assignment code...
        meshMaterial.Ambient_Color = (XHeader.Materials.MaterialEntries[ObjectIndex].Material.Ambient.R[0],
                                      XHeader.Materials.MaterialEntries[ObjectIndex].Material.Ambient.G[0],
                                      XHeader.Materials.MaterialEntries[ObjectIndex].Material.Ambient.B[0])
        meshMaterial.Ambient_Alpha = XHeader.Materials.MaterialEntries[ObjectIndex].Material.Ambient.A[0]
        meshMaterial.Emit_Color = (XHeader.Materials.MaterialEntries[ObjectIndex].Material.Emissive.R[0],
                                   XHeader.Materials.MaterialEntries[ObjectIndex].Material.Emissive.G[0],
                                   XHeader.Materials.MaterialEntries[ObjectIndex].Material.Emissive.B[0])
        meshMaterial.Emit_Alpha = XHeader.Materials.MaterialEntries[ObjectIndex].Material.Emissive.A[0]

The use in a custom UI panel (allows access to color selector, for example):

Code:
class xMaterialSettingsPanel(bpy.types.Panel):
    bl_idname = "MATSTUFF_PT_Select"
    bl_label = "X Material Settings"
    bl_space_type = "PROPERTIES"
    bl_region_type = "WINDOW"
    bl_context = "material"
    
    def draw(self, context):
        try:
            layout = self.layout
            xx = context.material
            box = layout.box()
            box.label('Ambient Color')
            row = box.row()
            row.label('Color:')
            row.prop(xx,'Ambient_Color',text='')
            row = box.row()
            row.label('Alpha:')
            row.prop(xx,'Ambient_Alpha',text='',slider=True)
            box = layout.box()
            box.label('Emissive Color')
            row = box.row()
            row.label('Color:')
            row.prop(xx,'Emit_Color',text='')
            row = box.row()
            row.label('Alpha:')
            row.prop(xx,'Emit_Alpha',text='',slider=True)
        except:
            dummy=0


The export:

Code:
MaterialData.AddColorRGBA(cm.data.materials[0].Ambient_Color,cm.data.materials[0].Ambient_Alpha)        

MaterialData.AddColorRGBA(cm.data.materials[0].Emit_Color,cm.data.materials[0].Emit_Alpha)


Lastly, the format I'm working with has a parent Object-- referred to by the filename, and any number of child material mesh objects inside of it. My import routine creates an Empty object with the filename as its name to act as the parent. Then the material mesh objects are created as children to it. Since I am new to Orbiter, would this type of structure be useful? What I mean is, the importer/ exporter I'm working on can allow the loading of an entire scene-- maybe upwards of a couple hundred objects, each with maybe a half dozen material meshes. You can then access each specific object, or part of it. The file name used for the export of the object is the name of the object in Blender.

For example, would it be advantageous to have the Atlantis.msh be loaded into Blender as the Empty parent Object "Atlantis", with the fifty or so orbiter parts and pieces material meshes children to it?
 

vlad32768

Member
Joined
Oct 11, 2010
Messages
78
Reaction score
0
Points
6
I assume you just triangulate the NGons when exporting to .msh?

I don't have to triangulate NGons by myself, because Blender PyAPI provides access to tesselated data.

---------- Post added at 04:37 PM ---------- Previous post was at 07:31 AM ----------

Hi, Traveller, and thanks for your interesting post.
So when I read that you do not use ambient and emissive colors because Blender does not have them, I decided to offer up the following.
You can define and access custom properties in Blender.
I have never used custom properties before, but it looks interesting. I'll learn something about it if I have time.
Although I don't think that direct definition of ambient and emissive colors is very important. These colors won't affect render result in Blender. IMHO, more important is to export Blender material so that it will look in Orbiter as close to Blender as possible. And the same thing is with import.

For example, would it be advantageous to have the Atlantis.msh be loaded into Blender as the Empty parent Object "Atlantis", with the fifty or so orbiter parts and pieces material meshes children to it?
Yes, it should be useful for those who want to import a Blender model into an existing scene and then do some nice renders etc.
 

Hlynkacg

Aspiring rocket scientist
Addon Developer
Tutorial Publisher
Donator
Joined
Dec 27, 2010
Messages
1,870
Reaction score
3
Points
0
Location
San Diego
Doubled Vertexes

Ok, I've encountered an issue.

The export plugin is adding unwanted vertices. It seems that edges that are not split in the source file are being split in the *.msh. This is a real PITA when it comes to modeling curved surfaces.
 

vlad32768

Member
Joined
Oct 11, 2010
Messages
78
Reaction score
0
Points
6
Ok, I've encountered an issue.

The export plugin is adding unwanted vertices. It seems that edges that are not split in the source file are being split in the *.msh. This is a real PITA when it comes to modeling curved surfaces.

Do these vertices belong to a UV seam?
 

Hlynkacg

Aspiring rocket scientist
Addon Developer
Tutorial Publisher
Donator
Joined
Dec 27, 2010
Messages
1,870
Reaction score
3
Points
0
Location
San Diego
I haven't done any UV mapping (yet) for the mesh in question so I dont think so.
 

vlad32768

Member
Joined
Oct 11, 2010
Messages
78
Reaction score
0
Points
6
I haven't done any UV mapping (yet) for the mesh in question so I dont think so.

I modeled a mesh without UVs and without any splits. Export works fine.
Please give me an example .blend file which reproduces the bug with split vertices.
 

werdna

Astroarchitect
Joined
Dec 16, 2011
Messages
328
Reaction score
0
Points
16
Location
a space colony at the L5 point
I downloaded the latest version of blender 2.63 (r46461) and the latest version of the addon. I could not find it in the user preferences. I put the py file in the lib folder.

Help!


EDIT:

Whoops! Totally realized it was the wrong folder...
 

chpeller

New member
Joined
Mar 9, 2011
Messages
19
Reaction score
0
Points
0
Texures export error message

Hi everybody,

I need help with the export module to ceate Orbiter mesh file.
When i try to export with a UV map i made, i have thie error message :

Traceback (most recent call last):
File "C:\Program Files (x86)\Blender Foundation\Blender\2.62\scripts\addons\io_orbiter_msh.py", line 772, in execute
export_msh(self.filepath,self.convert_coords,self.apply_modifiers,self.delete_orphans)
File "C:\Program Files (x86)\Blender Foundation\Blender\2.62\scripts\addons\io_orbiter_msh.py", line 749, in export_msh
tex.image.save_render(os.path.join(texpath,tex_fname))
RuntimeError: Error: Couldn't write image: C:\Users\cpn\Documents\Orbiter2010\Meshes\aurigatex\


location:<unknown location>:-1

I use the 2.62 Blender version.

If you want i can send you my .blend file and texture file to enable you to check the problem.
I have also a lot of problem to make the textures visible under Orbiter.

Many thanks by advance
 

vlad32768

Member
Joined
Oct 11, 2010
Messages
78
Reaction score
0
Points
6
I use the 2.62 Blender version.

You should use Blender 2.63 or later with the latest version of the add-on. And you shouldn't use spaces in file or directory names.
To make textures visible turn on GLSL viewport shading mode, and don't forget to add some lights.
 
Last edited:

chpeller

New member
Joined
Mar 9, 2011
Messages
19
Reaction score
0
Points
0
Hi Vlad,

Thank you for your help.
I have downloaded Blender 2.63a
I dont have any spaces in the files or directory names
Where is the "GLSL viewport shading mode" i dont find it.
I still have the same error message and can't export the orbiter mesh.

The textures are visible in Blender but not in Orbiter.
 
Top