Blender S3O Import/Export + BOS Export Plugin v0.6

Blender S3O Import/Export + BOS Export Plugin v0.6

Tutorials & Resources For Modellers & Skinners

Moderators: MR.D, Moderators

User avatar
thesleepless
Posts: 417
Joined: 24 Oct 2007, 04:49

Blender S3O Import/Export + BOS Export Plugin v0.6

Post by thesleepless »

Hi, S3O Import/Export plugin for blender is now functional.

BOS Export is now functional

DOWNLOAD
blender_spring_plugins-0.6.zip
(7.69 KiB) Downloaded 1020 times
README
- Installation
Just extract the zip file into your blender scripts directory and you're good to go.

- S3O Importer
Just select "Import Spring S3O" from Blender's Import Menu
Select your .s3o file and it'll hopefully be loaded into the scene
You'll also get an Empty Sphere representing the Radius of the model
and a little Empty Arrow above the model representing its Height

- S3O Exporter
The best way to start is by importing an s3o using the importer and working from there, but if you're starting from scratch you'll need to do some setup.

- create a base object and rotate it 90 degrees on the X axis (select it and hit "r x 90 enter" while in object mode) This is because spring units are rotated 90 degress on the x axis compared to blender, now you can start modelling, all other pieces need to be children of this base object, they don't need to be rotated as they'll inherit it from their parents
- create a new empty, name it "SpringRadius" and choose Sphere display type. Move and Scale it until it best represents your model.
- create a new empty, name it "SpringHeight" and choose Single Arrow display type, place it just above the top of your model, this represents the Height of your model
- to export the texture names you need to create a new material called "SpringMat", give it two image textures and load the 1st image into the 1st texture and the 2nd image into the 2nd texture
Now once you're done just go File->Export->Spring S3O and select the file to save. I'd recommend saving to a new file incase something goes wrong.

- BOS Exporter
BOS Exporter will export KEYFRAME/IPO animation (not IK/bone stuff) for all Mesh and Empty objects from your scene
It will also export any marked frames as comments, this is useful for figuring out what part is what ^^
It can also export show/hide commands. to set this up you'll need to make layer keys for your pieces. if a piece is on Layer 1, it is visible, otherwise it will be hidden.

eg. the export from a simple animation of a Solar Collector opening and closing its panels.

Code: Select all

/* BOS Script Generated from Blender animation */

piece base, solbase, solar_4, solar_3, solar_2, solar_1, solarpan_1, solarpan_2, solarpan_3;

// OpenPanels
turn solar_4 to x-axis <-135.00> speed <177.63>		// frame 1
turn solar_3 to x-axis <135.00> speed <177.63>		// frame 1
turn solar_2 to z-axis <-135.00> speed <177.63>		// frame 1
turn solar_1 to z-axis <135.00> speed <177.63>		// frame 1
wait-for-turn solar_1 around z-axis		// frame 20
wait-for-turn solar_2 around z-axis		// frame 20
wait-for-turn solar_3 around x-axis		// frame 20
wait-for-turn solar_4 around x-axis		// frame 20
// ClosePanels (40)
turn solar_4 to x-axis <0.00> speed <168.75>		// frame 40
turn solar_3 to x-axis <0.00> speed <168.75>		// frame 40
turn solar_2 to z-axis <0.00> speed <168.75>		// frame 40
turn solar_1 to z-axis <0.00> speed <168.75>		// frame 40
wait-for-turn solar_1 around z-axis		// frame 60
wait-for-turn solar_2 around z-axis		// frame 60
wait-for-turn solar_3 around x-axis		// frame 60
wait-for-turn solar_4 around x-axis		// frame 60

Change Log
version 0.6
- Added BOS Exporter
- Now uses an extra Empty object for Height named 'SpringHeight', represented by an arrow so you can manually set the Height

version 0.5
- Exporter now functional
- Tested output in Spring

version 0.2
- Now handles hierarchy correctly, no weird offsets
- Loads uvmaps for .png files mirrored so they appear correctly

Known Issues
- Spring doesn't seem to handle quad output, you may need to convert your mesh to triangles first (CTRL+T in edit mode with everything selected)
- The importer doesn't handle tristrips yet (although i've never seen them used in any s3o files
- You'll need to Apply any rotation and scale you've made to objects before exporting, planned to be fixed in a later release
- Currently when importing we just rotate the base object 90 degrees on the X-Axis to get it to be lined up in blender since blender's Z axis points up where in S3Os the Y axis points up, we should probably just load the verts with the Y and Z axes swapped

any ideas, feature suggestions, or bug reports are most welcome, feel free to play with the code and send any useful patches
Last edited by BrainDamage on 22 Dec 2008, 21:42, edited 8 times in total.
Reason: stickied
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Blender S3O Import/Export Plugin

Post by Argh »

Best guess as to why you're seeing weird offsets is that the S3Os have weird offsets in them still. A lot of people don't have their Pieces at 0,0,0 offsets, but leave them at "weird" relative values vs. the origin of the root, because they moved the root and didn't reset that offset correctly. UpSpring handles that correctly, Spring doesn't care, but Blender obviously doesn't like it.

You need to read those existing offsets and apply them, instead of assuming that geometry is where it "should be", basically. Moreover, for this tool to be useful, you also need to get the offsets for the centroids, because .S3O, like 3DO, assumes that all Pieces have their own centers, and uses those centers to perform correct rotations.
User avatar
thesleepless
Posts: 417
Joined: 24 Oct 2007, 04:49

Re: Blender S3O Import/Export Plugin

Post by thesleepless »

problem solved! it was being caused by blender's makeparent function, something about non-inverse. oh well, it works perfectly now!

but found another issue, a minority of models seem to have their uv maps mirrored on the v axis. i think this is a problem with the models themselves since they have the same problem in upspring, but i don't notice this problem in spring itself, so it's a bit odd.

eg. AEnergyStorage, and ARadar from CA

also what would be great is a spring shader for blender that shows teamcolour, illumination, reflection and such in GLSL texture mode. if anyone has one or is good at making that kind of thing, it'd be great to intergrate into the importer
User avatar
yuritch
Spring 1944 Developer
Posts: 1018
Joined: 11 Oct 2005, 07:18

Re: Blender S3O Import/Export Plugin

Post by yuritch »

In my experience texture mirroring has something to do with texture file format. Some formats (dds) cause no mirroring, while others (jpg or png? hard to remember exactly) show up mirrored in Upspring, but not in Spring.
User avatar
thesleepless
Posts: 417
Joined: 24 Oct 2007, 04:49

Re: Blender S3O Import/Export Plugin

Post by thesleepless »

yuritch wrote:In my experience texture mirroring has something to do with texture file format. Some formats (dds) cause no mirroring, while others (jpg or png? hard to remember exactly) show up mirrored in Upspring, but not in Spring.
thanks! yes the png ones are indeed mirrored. maybe spring loads pngs upside down?
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Blender S3O Import/Export Plugin

Post by Argh »

Yes. Anything but DDS is loaded upside down. Which is stupid, but it's how it works.

As for the GLSL shader for everything, jK posted one here, presumably licensed GPL (although I'd ask before using it):

Code: Select all

{
  vertex = [[
//#define use_shadow
    uniform mat4 camera;   //ViewMatrix (gl_ModelViewMatrix is ModelMatrix!)
    uniform vec3 cameraPos;
    uniform vec3 sunPos;
    uniform vec3 sunDiffuse;
    uniform vec3 sunAmbient;
  #ifdef use_shadow
    uniform mat4 shadowMatrix;
    uniform vec4 shadowParams;
  #endif

    varying vec3 normal;
    varying vec3 cameraDir;
    varying vec3 teamColor;
    varying vec3 light;


    void main(void)
    {
      gl_TexCoord[0].st = gl_MultiTexCoord0.st;

      vec4 worldPos = gl_ModelViewMatrix * gl_Vertex;

      normal    = normalize(gl_NormalMatrix * gl_Normal);
      cameraDir = worldPos.xyz - cameraPos;

      teamColor = gl_TextureEnvColor[0].rgb;

      float a = max( dot(normal, sunPos), 0.0);
      light   = a * sunDiffuse + sunAmbient;

     #ifdef use_shadow
      gl_TexCoord[1] = shadowMatrix * worldPos;
      gl_TexCoord[1].st = gl_TexCoord[1].st * (inversesqrt( abs(gl_TexCoord[1].st) + shadowParams.z) + shadowParams.w) + shadowParams.xy;
     #endif

      gl_Position = gl_ProjectionMatrix * camera * gl_ModelViewMatrix * gl_Vertex;
    }
  ]],
  fragment = [[
//#define use_shadow
    uniform sampler2D textureS3o1;
    uniform sampler2D textureS3o2;
    uniform samplerCube specularMap;
    uniform samplerCube reflectMap;

    uniform sampler2D detailMap;

  #ifdef use_shadow
    uniform sampler2DShadow shadowMap;
    uniform float shadowDensity;
    uniform vec3 sunAmbient;
  #endif

    varying vec3 normal;
    varying vec3 cameraDir;
    varying vec3 teamColor;
    varying vec3 light;

    void main(void)
    {
       gl_FragColor    = texture2D(textureS3o1, gl_TexCoord[0].st);
       vec4 extraColor = texture2D(textureS3o2, gl_TexCoord[0].st);

       vec3 reflectDir = reflect(cameraDir, normalize(normal));
       vec3 specular   = textureCube(specularMap, reflectDir).rgb * 4.0 * max(extraColor.g,0.7);
       vec3 reflection = textureCube(reflectMap,  reflectDir).rgb;

     #ifdef use_shadow
       float shadow = shadow2DProj(shadowMap, gl_TexCoord[1]).r;
       shadow      = 1.0 - (1.0 - shadow) * shadowDensity;
       vec3 shade  = mix(sunAmbient, light, shadow);
       reflection  = mix(shade, reflection, extraColor.g);
       reflection += extraColor.r;
       specular   *= shadow;
     #else
       reflection  = mix(light, reflection, extraColor.g);
       reflection += extraColor.rrr;
     #endif

       gl_FragColor.rgb = mix(gl_FragColor.rgb, teamColor, gl_FragColor.a); //teamcolor
       gl_FragColor.rgb = gl_FragColor.rgb * reflection + specular;
       gl_FragColor.a   = extraColor.a;
    }
  ]],
  uniformInt = {
    textureS3o1 = 0,
    textureS3o2 = 1,
    shadowMap   = 2,
    specularMap = 3,
    reflectMap  = 4,
  },
  uniform = {
    sunPos = {gl.GetSun("pos")},
    sunAmbient = {gl.GetSun("ambient" ,"unit")},
    sunDiffuse = {gl.GetSun("diffuse" ,"unit")},
    shadowDensity = {gl.GetSun("shadowDensity" ,"unit")},
    shadowParams  = {gl.GetShadowMapParams()},
  },
  uniformMatrix = {
    shadowMatrix = {gl.GetMatrixData("shadow")},
  },
}
So, all you need to do is determine which is texture1 and which is texture2, set up some simple cubemap like UpSpring does, cut the shadow stuff... and there you go.
User avatar
rattle
Damned Developer
Posts: 8278
Joined: 01 Jun 2006, 13:15

Re: Blender S3O Import/Export Plugin

Post by rattle »

thesleepless wrote:
yuritch wrote:In my experience texture mirroring has something to do with texture file format. Some formats (dds) cause no mirroring, while others (jpg or png? hard to remember exactly) show up mirrored in Upspring, but not in Spring.
thanks! yes the png ones are indeed mirrored. maybe spring loads pngs upside down?
I think the DDS loader reads them in a different order or some code flips the UV coords. Upspring also saves the model flipped, you can see this on asymetric models.
el_matarife
Posts: 933
Joined: 27 Feb 2006, 02:04

Re: Blender S3O Import/Export Plugin

Post by el_matarife »

thesleepless wrote:any ideas or feature suggestions are most welcome
I don't suppose you'd be interested in writing an import / export plugin for Google Sketchup? There's a whole ton of models in their 3D Warehouse that might be licensed appropriately for Spring use, and Sketchup is by far the easiest to use 3D modeling tool I've ever seen.
User avatar
Pressure Line
Posts: 2283
Joined: 21 May 2007, 02:09

Re: Blender S3O Import/Export Plugin

Post by Pressure Line »

but idk if sketchup has a uvmapper.

and if you have pro you can just export the 3dwarehouse stuff to obj (or whatever) uvmap it and away you go.
el_matarife
Posts: 933
Joined: 27 Feb 2006, 02:04

Re: Blender S3O Import/Export Plugin

Post by el_matarife »

It has some basic texturing capabilities. Not sure if they're as advanced as uvmapper, but as a "let's build a ton of low poly units quickly" tool it would be spectacular, even if we have to export into something else to texture.
User avatar
Pressure Line
Posts: 2283
Joined: 21 May 2007, 02:09

Re: Blender S3O Import/Export Plugin

Post by Pressure Line »

the only thing i really like about sketchup is the ability to place arbitrary points (great when working off a blueprint) Sketchup also issues with putting the inside face of a closed mesh on the outside (not all of them. just 1 or 2 :( )

better to just use Wings imo. its really not that hard to pick up, and hell of a lot easier than many of the tools i use/have used at work (I am a draftsman, I do architechtural work in ArchiCAD and AutoCAD. I have also done work on Smallworld GIS for a utility company, so im not trying to blow smoke up anyones ass)

i could turn out a dozen 200-500 poly uv-mapped (colour fill textured) units, fully scripted (obviously needing balance tweaks for turret rotation etc) in a weekend. but i need to know what to draw, and thats what the real kicker is...

people say they want to make units, for faction-x in universe-y, but they fail to see that you cant just say "i need sum tanks plx" and expect to get something you are happy with straight off the bat. (even things from an existing universe fall victim to this, as people put their own spin on the artwork, and people cry because its not what they expected, see the early MrD threads and Smoths Morty thread for examples) you need to provide clear and consistent concept art if you want to get someone to model something for you. hell, try it yourself you'll see that you'll spend HOURS on a single unit, trying to fix one little bit you arent happy with.


OMG EPIC RANT. andi already told you that SketchUp Pro can export to .obj, so it can be loaded into any uv-mapping program (which is why i suggested using wings, since it doesnt cost 500USD...
User avatar
Hoi
Posts: 2917
Joined: 13 May 2008, 16:51

Re: Blender S3O Import/Export Plugin [IT WORKS!]

Post by Hoi »

it works!
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Re: Blender S3O Import/Export Plugin [IT WORKS!]

Post by KDR_11k »

TGAs get mirrored too.

Spring loads models reversed on the x axis, might need to account for that too.
User avatar
Tribulexrenamed
Posts: 775
Joined: 22 Apr 2008, 19:06

Re: Blender S3O Import/Export Plugin [IT WORKS!]

Post by Tribulexrenamed »

A billion thanks.


are you a woman?
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: Blender S3O Import/Export Plugin [IT WORKS!]

Post by jK »

Just an assumption, but I know DirectX has TopLeft origin for their screen coords. OpenGL in contrast has a math-like BottomLeft origin. Now I assume DirectX does the same with TexCoords.
Also DDS means DirectDrawSurface, so I assume it is DDS that inverts the image and it isn't spring that inverts the images for all other image formats ;)
Just Upspring is broken because it assumes the DDS are in the correct flip and inverts the texcoords for pngs ..

(PS: many DDS compressor even have an invert flag)
(PPS: Ozone even wrote their own o3tc fileformat to avoid this)
User avatar
thesleepless
Posts: 417
Joined: 24 Oct 2007, 04:49

Re: Blender S3O Import/Export Plugin [IT WORKS!]

Post by thesleepless »

Tribulex wrote:A billion thanks.
are you a woman?
You're welcome, sorry, nope.



Now working on a BOS exporter based on animations in blender
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Re: Blender S3O Import/Export + BOS Export Plugin v0.6

Post by KDR_11k »

Does it handle constraints (i.e. will it use the actual bone rotations) or only keyframe data? I've had trouble getting IK to bake properly and having to "compile" animations before exporting them is annoying anyway. Would be helpful if it would use exactly what gets displayed.
User avatar
thesleepless
Posts: 417
Joined: 24 Oct 2007, 04:49

Re: Blender S3O Import/Export + BOS Export Plugin v0.6

Post by thesleepless »

KDR_11k wrote:Does it handle constraints (i.e. will it use the actual bone rotations) or only keyframe data? I've had trouble getting IK to bake properly and having to "compile" animations before exporting them is annoying anyway. Would be helpful if it would use exactly what gets displayed.
At the moment it only uses Location, Rotation and Layer keyframes, (spring doesn't handle scale transforms) Hopefully i'll be able to improve it to work with IK and such, or at least look into baking the animation for export.

[UPDATE]

hmm seems there's a script for baking constraints into keyframe data that BOS Export can use. the problem is that constraint baker exports the locations of each piece rather than their movement relative to their parent since they don't have their normal parents when they're parented to the bones.

i'll look into modifying the constraint baker to suit our purposes for spring and include the modified version in the BOS exporter.
User avatar
danuker
Posts: 53
Joined: 04 Feb 2008, 22:37

Re: Blender S3O Import/Export + BOS Export Plugin v0.6

Post by danuker »

THANK YOU!!!!!!!
User avatar
thesleepless
Posts: 417
Joined: 24 Oct 2007, 04:49

Re: Blender S3O Import/Export + BOS Export Plugin v0.6

Post by thesleepless »

update: haven't had much luck with exporting IK animation from blender so far.

blender has rather large flaw where only Armature objects can have IK
so i've made a script which generates an armature from your objects, placing a bone for each piece (with the piece's name) and then parenting each piece to the bone

you can then animate the model using the armature with IK and then hopefully i'll be able to export the animation of the armature using the bos exporter with a few modifications.


also, is there any word from devs on a new model format for spring that can do deforming skeletal animation or is this still a far off pipe dream?
Post Reply

Return to “Modelling & Texturing Tutorials & Resources”