Orbiter-Forum  

Go Back   Orbiter-Forum > Orbiter Addons > Addon Development
Register Blogs Orbinauts List Social Groups FAQ Projects Mark Forums Read

Addon Development Developers post news, updates, & discussions here about your projects in development.

Reply
 
Thread Tools
Old 05-02-2012, 03:08 AM   #91
Traveller
Donator
 
Traveller's Avatar
Default

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?
Traveller is offline   Reply With Quote
Old 05-02-2012, 04:37 PM   #92
vlad32768
Orbinaut
Default

Quote:
Originally Posted by Hielor View Post
 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.
Quote:
Originally Posted by Traveller View 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.

Quote:
Originally Posted by Traveller View Post
 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.
vlad32768 is offline   Reply With Quote
Old 05-04-2012, 09:50 PM   #93
Hlynkacg
Aspiring rocket scientist
 
Hlynkacg's Avatar


Default 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.
Hlynkacg is offline   Reply With Quote
Old 05-04-2012, 11:26 PM   #94
vlad32768
Orbinaut
Default

Quote:
Originally Posted by Hlynkacg View Post
 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?
vlad32768 is offline   Reply With Quote
Old 05-05-2012, 07:02 AM   #95
Hlynkacg
Aspiring rocket scientist
 
Hlynkacg's Avatar


Default

I haven't done any UV mapping (yet) for the mesh in question so I dont think so.
Hlynkacg is offline   Reply With Quote
Old 05-12-2012, 07:31 AM   #96
vlad32768
Orbinaut
Default

Quote:
Originally Posted by Hlynkacg View Post
 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.
vlad32768 is offline   Reply With Quote
Old 06-03-2012, 03:59 AM   #97
werdnaforever
Astroarchitect
 
werdnaforever's Avatar
Default

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...
werdnaforever is offline   Reply With Quote
Old 06-03-2012, 11:54 AM   #98
chpeller
Orbinaut
Default 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_fna me))
RuntimeError: Error: Couldn't write image: C:\Users\cpn\Documents\Orbiter2010\Meshes\aurigate x\


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
chpeller is offline   Reply With Quote
Old 06-05-2012, 06:56 PM   #99
vlad32768
Orbinaut
Default

Quote:
Originally Posted by chpeller View Post
 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 by vlad32768; 06-05-2012 at 07:00 PM.
vlad32768 is offline   Reply With Quote
Old 06-05-2012, 08:08 PM   #100
chpeller
Orbinaut
Default

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.
chpeller is offline   Reply With Quote
Old 06-05-2012, 10:59 PM   #101
SpaceNut
Orbinaut
Default Help!

I'm having a heck of a time here... and it's not because I'm new to either Orbiter (9 years now) or Blender (about 2). I'm also familiar with GraphicAll.org, as I've been getting the latest builds for some time.

I had a heck of a time getting io_orbiter_msh.py, the link on page 1 doesn't lead to the file, it leads to the master file associated with the distributed revision control system, and there are no instructions on how to use it. Anyway, I finally have the python script, but now I'm having issues downloading blender

Any archive that I download from Graphicall.org gives me errors when I attempt to extract the archive... Both winRAR and 7zip both say the same thing... "unsupported compression method". What gives? I've never had trouble using winRAR to extract, and I've tested other archives and they're fine. Anyone have a clue what's causing this and how to resolve?

Thanks in advance to anyone who can help.
SpaceNut is offline   Reply With Quote
Old 06-06-2012, 04:13 PM   #102
vlad32768
Orbinaut
Default

Quote:
Originally Posted by chpeller View Post
 Where is the "GLSL viewport shading mode" i dont find it.
You can select GLSL on the properties tab (press "N" in 3d View window to toggle). You can see it on the first screenshot in the first post (Atlantis)
Oh, I understand. You can't see your exported model's textures in Orbiter engine.

Quote:
I still have the same error message and can't export the orbiter mesh.
Quote:
Originally Posted by chpeller
 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_fna me))
RuntimeError: Error: Couldn't write image: C:\Users\cpn\Documents\Orbiter2010\Meshes\aurigate x\
Are there any spaces in file name "\aurigate x\"?

Anyway, that's strange. I don't know why it can't write the file. Maybe there are some problems with file permissions.
Yes, sending me your .blend file with textures is a good idea
Please also write your Blender revision number.

---------- Post added at 04:13 PM ---------- Previous post was at 03:58 PM ----------

Quote:
Originally Posted by SpaceNut View Post
 I had a heck of a time getting io_orbiter_msh.py, the link on page 1 doesn't lead to the file, it leads to the master file associated with the distributed revision control system, and there are no instructions on how to use it.
The http link doesn't lead to "master file". It leads to automatically generated .tar.gz archive with the latest version of the script. Modern archivers (7zip) can open it.
Of course, you can use Git if you are familiar with it.
Quote:
Originally Posted by SpaceNut View Post
 Any archive that I download from Graphicall.org gives me errors when I attempt to extract the archive...
Try again.
I've just downloaded Blender from Graphicall.org and all is fine.
vlad32768 is offline   Reply With Quote
Old 06-07-2012, 12:52 AM   #103
SpaceNut
Orbinaut
Default

Ok, I've got the script, and I've got Blender, I tried WinZIP and that unpacked the 7z archive and I've got blender, but I don't see the orbiter addon in the addon window... is the script supposed to be in \scripts\addons?

That's where I have it.

Update:
Ok, I've got blender and the python script running, and I can load meshes from the orbiter mesh folder no problems... Thing is, any attempts at loading a mesh I've created (using the blender/python script or not, so I know it's not the python script), I get a CTD with a missing mesh warning. All I'm trying to do is replace a pre-existing mesh with a new one...

Any ideas anyone?

Last edited by SpaceNut; 06-07-2012 at 01:31 PM.
SpaceNut is offline   Reply With Quote
Old 06-07-2012, 01:22 AM   #104
Traveller
Donator
 
Traveller's Avatar
Default

Yes, place the "io_orbiter_msh.py" file in the Blender scripts\addons folder. Once in Blender, look for "Import-Export: Orbiter mesh (.msh)" in the User Preferences/Addons page-- or you can type "orbiter" in the search box on that same page.
Traveller is offline   Reply With Quote
Old 06-07-2012, 07:19 PM   #105
SpaceNut
Orbinaut
Default

Yep, finally got it working! Thanks, and kudos to Vlad for making this great tool. Anim8or has always been the sort of defacto tool the orbiter community turned to for a simple and free 3D modeling program, but Blender is much closer to 3D studio than it is to Anim8or, and it's just as free... so a mesh import/export tool was just the thing we needed to eliminate conversion steps. Thanks again Vlad!

---------- Post added at 03:19 PM ---------- Previous post was at 12:40 PM ----------



Ok, I loaded up the dragon mesh and rendered it using Blender's new cycles rendering engine. The standard Blender render engine was getting a bit long in the tooth, and there are other plugin rendering engines such as Yafaray and LuxRender, but the Blender community has been developing a newer, more realistic rendering engine called Cycles.

One of the neat features is support for CUDA, NVidia's General Purpose GPU platform which basically allows you to code the GPU with C++ as if it were a CPU. GPU's are really good at certain types of computing because they have so many cores (I had a 9800GT with 124 CUDA cores, and this feature alone prompted me to go out and buy a new GTX 570 with 480 CUDA cores!!!).

Besides graphics, certain calculations can benefit from parallel computing such as wave analysis, Analyzing air traffic flow, and other non-graphical uses. Coders were trying to use graphics APIs to gain the advantage of having so many cores, so NVidia stepped up and developed CUDA which enables one to code in C+.

Now.. on the graphical side... you can set Blender to use CUDA so that the video card's GPU does the rendering calculations.... not your CPU, and the results are amazing. The image below was rendered with 2500 passes, and took 58.21 seconds to complete. Now, I didn't render using the CPU to compare, but it would have taken several hours to render using just the CPU.

I loaded up Glider's SpaceX Dragon capsule, set the rendering engine to Cycles, then had to manually re-load the textures because cycles works a bit different than the standard Blender rendering engine, but that's it. I used all the standard textures with the exception of the hatch foil because the white foil didn't look that good, and I set the metal ring to glossy and the windows to glass material types, and this was the result:


Last edited by SpaceNut; 06-07-2012 at 07:29 PM.
SpaceNut is offline   Reply With Quote
Reply

  Orbiter-Forum > Orbiter Addons > Addon Development


Thread Tools

Posting Rules
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Jump


All times are GMT. The time now is 11:44 PM.

Quick Links Need Help?


About Us | Rules & Guidelines | TOS Policy | Privacy Policy

Orbiter-Forum is hosted at Orbithangar.com
Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
Copyright 2007 - 2017, Orbiter-Forum.com. All rights reserved.