UnitConverter obj->bfxm

A forum for the discussion and development of programs to assist working on or playing with the Vegastrike engine and data sets.
Post Reply
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

There never was a vp; it uses high_shader.vp, for now.
That's strange; when it fails to compile for me something comes up in stderr.txt.
Are you sure there's nothing there? It doesn't come with a nice heading like "compiling cinemut_opaque.fp"; it's
rather kind of lost in the middle; after Loading Star System, like...

Code: Select all

Loading a starsystem
Loading Star System Special/ModelviewFOUND MODIFICATION = player FOR PLAYER #0
(305) : error C0000: syntax error, unexpected identifier, expecting ';' or ',' at token "vutocclusion"
(305) : error C0501: type name expected at token "vutocclusion"
(305) : error C1038: declaration of "vutocclusion" conflicts with previous declaration at (303)
(305) : error C1038: declaration of "vutocclusion" conflicts with previous declaration at (303)

Fragment Program Error: Failed to compile cinemut_opaque
Compilation of technique cinemut_opaque failed... trying default
Cause: Error compiling program vp:"highend" fp:"cinemut_opaque"
(45) : warning C7506: OpenGL does not define the global type float2
(64) : warning C7011: implicit cast from "int" to "float"
(65) : warning C7011: implicit cast from "float" to "vec4"
(94) : warning C7011: implicit cast from "vec4" to "float"
(96) : warning C7011: implicit cast from "float" to "vec3"
(64) : warning C7011: implicit cast from "int" to "float"
The last part is warnings about default.fp, after it gave up on cinemut (I caused it by removing a semicolon).
pyramid
Expert Mercenary
Expert Mercenary
Posts: 988
Joined: Thu Jun 15, 2006 1:02 am
Location: Somewhere in the vastness of space
Contact:

Post by pyramid »

chuck_starchaser wrote:Are you sure there's nothing there?
Absolutely positive:

Code: Select all

...
OpenGL Extensions supported: GL_ARB_color_buffer_float ...
...
OpenGL::EXTColorTable unsupported
0 joysticks were found.

The names of the joysticks are:
FactionXML:LoadXML factions.xml
Contents of star system:
<system name="Modelview" background="backgrounds/starfield2"
...
</system>

Initializing optimizer
UNIT HAS DIED: white_star White_Star (file white_star)
UNIT HAS DIED: university university (file university)
Compiling python module modules/dj.py
Min (0.000000, 0.000000, 0.000000) Max(0.000000, 0.000000, 0.000000) 
...
MinLumin 1.000000, MaxLumin 1.000000Read In Star Count 0 used: 38
Loading a starsystem
Loading Star System Special/ModelviewFOUND MODIFICATION = player FOR PLAYER #0
CREATING A LOCAL SHIP : Clydesdale
Hi helper play 0
...
HereHi helper play 0
...
Loading completed, now network init
Loading active missions True
It would be nice to have a confirmation on which shader was actually loaded.
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

I'm at a loss...
Here's my cinemut_opaque.technique file, in case there might be something different...

Code: Select all

<?xml version="1.0"?>
<technique fallback="default">
    <!-- Full-blown shader technique, with Z-write prepass to avoid
         shading overhead for occluded fragments.
         
         This technique implements normal-mapping, specmaps with intensity-derived
         shininess modulation, variable-kernel filtered environmental reflections
         (based on shininess), specularity normalization, fading damage maps with
         specmap perturbation, and supports up to 8 lights.
         
         This is a one-pass technique, so only the first 2 lights are done 
         per-pixel, the remaining ones use per-vertex lighting.
    -->

    <!-- Z-write prepasses go at sequence 10 -->
    <pass type="shader" sequence="10" cwrite="false">
        <vertex_program src="zwrite"/>
        <fragment_program src="zwrite"/>
        <texture_unit src="decal:0" default="file:white.bmp" name="diffuseMap"/>
    </pass>
    
    <!-- first and only lighting pass -->
    <pass type="shader" sequence="15">
        <vertex_program src="highend"/>
        <fragment_program src="cinemut_opaque"/>
        
         <texture_unit src="decal:0" name="diffMap"/>
        <texture_unit src="environment" name="envMap"/>
        <texture_unit src="decal:1" name="specMap"/>
        <texture_unit src="decal:3" name="glowMap"/>
        <texture_unit src="decal:4" name="normMap"/>
        <texture_unit src="decal:2" name="damgMap"/>
        <texture_unit src="file:cm_detail.png" name="detailMap"/>
        <texture_unit src="file:moto_PRT.png" name="prtMap"/>
        
        <auto_param name="light_enabled" semantic="ActiveLightsArray" optional="true"/>
        <auto_param name="max_light_enabled" semantic="NumLights" optional="true"/>
        <auto_param name="ucloaking" semantic="CloakingPhase" optional="true"/>
        <auto_param name="udamage" semantic="Damage" optional="true"/>
    </pass>
</technique>
pyramid
Expert Mercenary
Expert Mercenary
Posts: 988
Joined: Thu Jun 15, 2006 1:02 am
Location: Somewhere in the vastness of space
Contact:

Post by pyramid »

Nope. Continues like a vegetable show: red and green. But nicely shaded indeed :wink:

Maybe it would be easier if you posted your most recent textures and the blender + bfxm files. I'm actually testing with your first bike, not the second one.
pyramid
Expert Mercenary
Expert Mercenary
Posts: 988
Joined: Thu Jun 15, 2006 1:02 am
Location: Somewhere in the vastness of space
Contact:

Post by pyramid »

Here's the first UnitConverter version 0.23 that is error-free and offers basic functionality.

Models workspace:
Image

Help is integrated in every screen describing briefly the various elements of the screen.
In this screen you can add models to workspace. For simple models just point to the obj file of the model. Internally shield models are handled differently (since the shield.bfxm information needs to go into a different column in units.csv) therefore one requirement is that the shield obj file actually contains the word "shield". Letter case and position of the word is of no importance.
Unfortunately I didn't convince tkinter to update the label information correctly (known bug) so when you change the models in workspace, the info for the first model will remain there (will be fixed in later versions).
Once the models are added, select the model you want to add textures to and change to the next screen.

Texture editor:
Image

Add default textures. Leave the technique entry empty if you are integrating for current shaders or select cinemut_opaque if you are integrating for the new shader. Then save and convert your model to the bfxm file, compress textures, copy everything (a directory with the model name will be created if it does not exist previously).
Once you have the default textures created and copied, you may want to add faction textures. First better clean the texture space by clicking the small "x" button on the right side of the faction. Add the faction texture(s) and again compress and copy. It won't be necessary to recreate the bfxm file as it only holds the default texture information. Then to the next step.

HUD Image editor
Image

You may want to add a hud image, compress it and copy ot to the units model directory. On compressing, the corresponding sprite file will be created, too. On to unit editing.

Unit editor
Image

Has only rudimentary information required to make the model display correctly in VegaStrike. Default information will be created for new models. If default information is shown for existing models, try changing the name to all lowercase and Load the information from units.csv again. The additional model dimensions are retrieved from the obj file. You may adjust the scale to correspond to the pretended size (but make sure you test turret placement as it might get borked with changed scale). The resulting in-game size will be the multiplication of scale and model dimensions. You are ready to view the unit. *EDIT* Meanwhile more functionality was added which is discussed in a later post.

Viewer
Image

For testing teh default textures, you may leave the faction entry at "privateer". For testing faction textures, choose the corresponding faction. That's it if you have configured correctly the paths (nmext screen).

Configuration
Image

To convert the model from obj to bfxm, you'll need the mesher path set. To compress textures, you'll need nvcompress configured. To view the model and edit unit information, you need to set the vegastrike data directory. The working directory is informational only.

About
Image

For the sake of completeness, I have included this screen with version and license information.

Have a nice testing of your units.
Last edited by pyramid on Mon Sep 15, 2008 9:12 pm, edited 1 time in total.
charlieg
Elite Mercenary
Elite Mercenary
Posts: 1329
Joined: Thu Mar 27, 2003 11:51 pm
Location: Manchester, UK
Contact:

Post by charlieg »

Just to be pedantic, it's hellcatv@users.sourceforge.net for the contact... I would put the forums though (or a mailing list if there is one).
Free Gamer - free software games compendium and commentary!
FreeGameDev forum - open source game development community
pyramid
Expert Mercenary
Expert Mercenary
Posts: 988
Joined: Thu Jun 15, 2006 1:02 am
Location: Somewhere in the vastness of space
Contact:

Post by pyramid »

Thanks. Escaped me completely.
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

Great stuff, Pyramid !!!

Been thinking about the issue of weapons, engines, and other key locations. We could add a simple shape like this...

Image

...to Blender's set of fundamental shapes (using Blender as example), so that you just press space-bar and click on "location_marker" and it places the shape wherever the cursor is.
The shape is 1 units wide in X, 2 units tall in Y, 4 units long in Z. Four vertices in total. The center between the two vertices on X is the origin; the vertex on Z marks the forward direction; the vertex on Y marks the up direction. Then you name the object "gun_medium_light_3" for position 3.
If you can read exported object names and get an unordered list of vertex locations, I can write the code for you that returns position, forward and up normalized vectors.

EDIT:
In fact, if we do this we wouldn't need to worry about mesh rotations; we could deduce mesh rotation from the marker for "pilot", and rotate the mesh automatically as needed.

EDIT2:
I'll be testing the converter in a couple of days, as soon as I have a basic set of textures ready for the Hammer.
pyramid
Expert Mercenary
Expert Mercenary
Posts: 988
Joined: Thu Jun 15, 2006 1:02 am
Location: Somewhere in the vastness of space
Contact:

Post by pyramid »

Great idea, Chuck. If you could give me a sample model e.g. the Hammer with the placements, I could start doing the code for it, it should be no problem. Essentially, we'd need four types of markers:
* center
* turret
* pilot
* engine

Center might be omitted with the assumption that the rotation center is exactly in the middle between X, Y, Z extensions or simply taking the model origin assuming that artists already did the correct placement.
The pilot is actually not used in the game engine, unless I am mistaken, so could be easily disregarded.
Turret helper would be used for placing turret, where in the UnitConverter the user would select the turret type for each or a set of positions. And the equivalent behavior would be for the engine placement.

I assume the helper meshes could be exported altogether into a separate obj file to be parsed separately so as not to interfere with the model conversion. Parsing of object names from obj files is relatively easy.
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

Or it can be just one type of marker, and you just name the objects according to a convention. This is more flexible, as it allows you to number the gun placements, define their types (light, medium, heavy) via your naming of the objects. Do objects have names in the .obj file? If not, then we have to have types of markers.

The pilot marker is definitely used by the engine: That's where the camera is positioned relative to the ship's xyz coordinates. Unless we made the pilot's eye be the center of the ship; but that's not usually the case. Even when your ship's mesh is not shown, because you're in the cockpit, the ship's position IS computed, and the camera position computed from it.
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

Here's a blend file people could load and save as the default blender start.
Starts with a marker smack in the middle.
You can move it to another layer, later duplicate it as needed to place copies at key locations.
http://wcjunction.com/temp_images/cinem ... tart.blend
You can also import the marker into another blend file:
Open whatever.blend, go to File -> Append Or Link
Navigate to where goodstart.blend is.
Go to the Objects folder, and click on the "marker" object.
To duplicate an object, in object mode, select and shift-D.
To rename your duplicated object, hit F9 and, towards the left,
where it says OB:Marker click in the middle of it and then
type "gunmount_0_light_medium" or whatever.
See if the exported obj has the object names.
pyramid
Expert Mercenary
Expert Mercenary
Posts: 988
Joined: Thu Jun 15, 2006 1:02 am
Location: Somewhere in the vastness of space
Contact:

Post by pyramid »

I have not expressed myself clearly. What I meant by type was not the shape type but the naming convention as you also propose. It still can be the only one shape. The obj files store names for separate objects. Didn't know the engine used the pilot information.

Draft for naming convention:

Code: Select all

type_subtype_identifier
with type:
* pilot
* gunmount
* turretmount
* engine

and subtype being optional (convention tbd),
and identifier being either a number or a description and optional.

So you might define for example:
* pilot
* pilot_john
* gunmount_lightmedium_0
* turrentmount_frontleft
* engine_retro_left

I'll test that with your file.
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

pyramid wrote:Didn't know the engine used the pilot information.
My statement was more about how things should be than a statement of fact: It could be that the engine doesn't use it, but that would be a "bug". I know that in PU, if I'm flying between asteroids in external camera mode, and if an asteroid is visibly too high to hit my ship but it hits "me" (the camera), instead, the ship still receives the hit and damage, --which looks absurd--; but so it could very well be that you are right and there's a HUGE bug there. I was merely trying to express that the pilot info is *necessary* info, whether or not it is used in fact.
If there's such a bug there, one should hope it will be fixed; and, when that happens, the pilot info had better be there, for ALL the units, and be right... The models should not cater to a bug in the engine, IOW; --otherwise we'd be creating a dependency on a bug.
Draft for naming convention:
...
Looks good.
AzureSky
Merchant
Merchant
Posts: 32
Joined: Fri Sep 22, 2006 6:41 pm
Contact:

Post by AzureSky »

chuck_starchaser wrote:Great stuff, Pyramid !!!

Been thinking about the issue of weapons, engines, and other key locations. We could add a simple shape like this...

{img}

...to Blender's set of fundamental shapes (using Blender as example), so that you just press space-bar and click on "location_marker" and it places the shape wherever the cursor is.
The shape is 1 units wide in X, 2 units tall in Y, 4 units long in Z. Four vertices in total. The center between the two vertices on X is the origin; the vertex on Z marks the forward direction; the vertex on Y marks the up direction. Then you name the object "gun_medium_light_3" for position 3.
If you can read exported object names and get an unordered list of vertex locations, I can write the code for you that returns position, forward and up normalized vectors.

I was looking at something similar to this, a set of custom primitive in the Add menu, and a blender script export the mount and camera locations. The python part is easy, but what I've had trouble finding info on is how to add a new custom primitive to the Add menu.

In the meantime, I've just used an Empty object. Getting the location, scale, and rotation is simple, but the Empty object's representation makes rotating or scaling it sort of useless.
pyramid
Expert Mercenary
Expert Mercenary
Posts: 988
Joined: Thu Jun 15, 2006 1:02 am
Location: Somewhere in the vastness of space
Contact:

Post by pyramid »

chuck_starchaser wrote:My statement was more about how things should be than a statement of fact ...
Makes sense to me.
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

@AzureSky:
Well, what I've been thinking, but told no one, is that once Pyramid's unit converter has matured, since it's already Python, perhaps it could be turned into a Blender script. Just convert all the interface screens into Blender interface screens. This would have the added advantage that you wouldn't even have to use the .obj exporter script on each mesh; the unit converter script could call the .obj exporter script on your behalf. So, I'd say yes and no; good to have a script in Blender to export weapons positions to a file; but I think it would be much better to build the functionality into unit converter, and then bring it into Blender later, together with everything else.
Also because if we build a weapons positions exporter for Blender, it will only be good for Blender users, whereas the unit converter would continue to have a stand-alone version.
pyramid
Expert Mercenary
Expert Mercenary
Posts: 988
Joined: Thu Jun 15, 2006 1:02 am
Location: Somewhere in the vastness of space
Contact:

Post by pyramid »

Following my proposed practice (in another wiki thread), I'll be putting relevant information (helper, naming convention) on the wiki, temporarily (until better structuring) here: http://vegastrike.sourceforge.net/wiki/ ... Guidelines

The helper meshes are easy going for a blender n00b like me. Example for the Archimedes:
Image
On the bottom of the image you can see the object name in blender.

And the preliminary result from code reading the object names (only, so far) from a separate obj file containing only the helper objects:

Code: Select all

Object Extensions (L/W/H Min/Max) =  -1260.050659 1242.108032 -422.625 422.625 -119.968346 119.9683
Object Dimensions (L/W/H) =  2502.158691 845.25 239.936646
Helper Objects =  ['engine_L3_Cube.003', 'engine_L2_Cube.001', 'engine_L1_Cube.002']
This is derived from a special object that can be added to the workspace. Unique requirement is that it contains the word "mount". The object extensions and dimensions refer to the main mesh.

Getting vertices and calculation of the position will be done next:
* get vector lengths between all vertices ( ||v|| = sqrt[(dx * dx) + (dy * dy) + (dz * dz)] = sqrt(dot(vec,vec) )
* position is the middle point between the shortest vector (local x axis)

Then will come the writing of the positions into the "Sub_Units" column for turrets and "Light" column for engines depending on the helper object name.

More tomorrow.
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

What happened? I posted a reply here and my post disappeared!

Shorter this time. I was saying you could also "snap" the forward and "up" vectors to the orthogonal directions if they are very close. Meshes can suffer small distortions through scalings and conversions, and it wouldn't be nice if some of the guns were permanently poorly aimed. If the forward vector you calculate is (0.000012345, -0.00000077, 0.999999999999999876), you can assume the intended vector was (0,0,1).

Here's snapping code in pseudo c++/glsl :):

Code: Select all

float dot( vec3 a, vec3 b )
{
  return (a.x*b.x) + (a.y*b.y) + (a.z*b.z);
}
void try_snap( vec3 &v, vec3 ref, float threshold )
{
  if( dot(v,ref) >= threshold )
    v = ref;
}
void try_snap_to_any_axes( vec3 &v, float thresh = 0.998 )
{
  normalize( v ); //...be really sure it's normalized, first of all, then...
  try_snap( v, vec3(+1,0,0), thresh );
  try_snap( v, vec3(-1,0,0), thresh );
  try_snap( v, vec3(0,+1,0), thresh );
  try_snap( v, vec3(0,-1,0), thresh );
  try_snap( v, vec3(0,0,+1), thresh );
  try_snap( v, vec3(0,0,-1), thresh );
}
.....
main()
{
  ....
  vec3 test = vec3(0.000012345, -0.00000077, 0.999999999999999876);
  try_snap_to_any_axes( test, 0.997 );
  show( test );
}
pyramid
Expert Mercenary
Expert Mercenary
Posts: 988
Joined: Thu Jun 15, 2006 1:02 am
Location: Somewhere in the vastness of space
Contact:

Post by pyramid »

@Chuck,
I have the habit of using rounding in programming (for display and export, not internal storage or calculations) so I have not seen any issues with using distorted helper meshes. Should this however become necessary, I will surely get back to this proposal. Or I might as well implement it in the vector class for future peruse.
For interest, the objparse class implements the calculation of helper center, normalized forward and up vectors.

@all,
UnitConverter version 0.24 is out. It makes use of mount helper objects for engine and turret placement as described previously by chuck. Requirements for proper functioning:
* Helper objects must follow the convention as described in the wiki (engine_*, turret_*).
* You may use substrings of turret types available in data/units/subunits directory for the subtype naming, e.g. turret_PminusBeam will create a turret of type turretLR_PminusBeam
* Helper objects must be exported all together to a separate obj file.
* The obj file must contain the word "mount", the sentence case is unimportant (so it can be e.g. "Mounts"
* You must add this obj file to the workspace in UnitsConverter to make use of it.

I still need to write a manual for the tool on the wiki.

*EDIT*
OK, snap is now available in the vector class (tested but not yet committed):

Code: Select all

def vsnap(vector, vref, threshold):
  if dot(vector, vref)>=threshold:
    return vref
  else:
    return vector

def vsnapany(v, thresh=0.998):
  v = vnormal(v) #...be really sure it's normalized, first of all, then...
  v = vsnap( v, vector([+1,0,0]), thresh )
  v = vsnap( v, vector([-1,0,0]), thresh )
  v = vsnap( v, vector([0,+1,0]), thresh )
  v = vsnap( v, vector([0,-1,0]), thresh )
  v = vsnap( v, vector([0,0,+1]), thresh )
  v = vsnap( v, vector([0,0,-1]), thresh )
  return v

if __name__ == "__main__":
  test = vector([0.000012345, -0.00000077, 0.999999999999999876])
  test = vsnapany( test, 0.997 )
  print test
result:

Code: Select all

[0, 0, 1]
:D
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

YEY! :D
Congrats!
You're right that rounding could solve the problem with vectors intended to be orthogonal, but... Watch out!: Rounding could royally mess up vectors NOT intended to be orthogonal, such as a petagonal station with sub-units that must mount at each corner of the pentagon.
By the way, do you have a marker class/name for placements of sub-units?
loki1950
The Shepherd
Posts: 5841
Joined: Fri May 13, 2005 8:37 pm
Location: Ottawa
Contact:

Post by loki1950 »

I still need to write a manual for the tool on the wiki.
First question how do you get your models into the workspace (copy/paste) :shock: and i can't seem to be able to browse for the file path in the model page and you can not paste a path in. Just my first niggles :wink: if we are going to get this tool Homer proof :lol:

Enjoy the Choice :)
my box::HP Envy i5-6400 @2Q70GHzx4 8 Gb ram/1 Tb(Win10 64)/3 Tb Mint 19.2/GTX745 4Gb acer S243HL K222HQL
Q8200/Asus P5QDLX/8 Gb ram/WD 2Tb 2-500 G HD/GF GT640 2Gb Mint 17.3 64 bit Win 10 32 bit acer and Lenovo ideapad 320-15ARB Win 10/Mint 19.2
pyramid
Expert Mercenary
Expert Mercenary
Posts: 988
Joined: Thu Jun 15, 2006 1:02 am
Location: Somewhere in the vastness of space
Contact:

Post by pyramid »

To load a model into the workspace, press the "..." button and point to the appropriate .obj file. Hmm, browse should work (it does on linux/windows like a charm). Make sure you have python 2.5 installed.
Paste should work, but there are no event handler for that yet, so the model will not be added to the workspace by just pasting the path.

@chuck,
marker class/name for placements of sub-units? short answer: no.
Not sure yet how this is working. The Archimedes has 3 subunits that were exported all in one obj file, so the positioning is already given by the model coordinates.
Were you thinking about a naming convention for the helper objects to mark the centers of the subunits in case they are exported in different obj files? *thinks* but the coordinates are still there relative to each other already... Please give me an example as I don't understand.
loki1950
The Shepherd
Posts: 5841
Joined: Fri May 13, 2005 8:37 pm
Location: Ottawa
Contact:

Post by loki1950 »

The browse button does not work on the model page it does on the other pages though so you may have forgotten to tie an event to it.

Enjoy the Choice :)
my box::HP Envy i5-6400 @2Q70GHzx4 8 Gb ram/1 Tb(Win10 64)/3 Tb Mint 19.2/GTX745 4Gb acer S243HL K222HQL
Q8200/Asus P5QDLX/8 Gb ram/WD 2Tb 2-500 G HD/GF GT640 2Gb Mint 17.3 64 bit Win 10 32 bit acer and Lenovo ideapad 320-15ARB Win 10/Mint 19.2
Post Reply