Blender > .3dp import/export script.

Stop by here for help with RRT3 Editor problems and tips.
User avatar
Gumboots
CEO
Posts: 1203
Joined: Mon Aug 13, 2012 4:32 am
Location: Australia

Re: Blender > .3dp import/export script. Unread post

Ok cool, the latest version of the script (now attached to the OP of this thread) exports with vertex normals for smooth shading of curved surfaces. So that's good. !*th_up*!

If there are any situations where somebody specifically wants to export with flat shading, which may be preferable for some buildings that are all flat surfaces, then I can zip up the earlier version of the script that exported with face normals. There's no reason why both could not be installed and just given different names (Blender_3dp_flat_shading.py for instance).

The script still won't import UV mapping. It will only import .3dp body meshes. Having it able to also import UV mapping would be very handy for correcting faults in older existing models, but that's going to depend on the good will of the Blender and Python gods for now.

IF anyone wanted to, it would still be possible to import with the current script and fairly quickly reinstate the UV mapping in Blender by using the UV overlay guides that can be exported from 3dConverter. It'd be a bit of a nuisance for complex locomotives, etc, but it's quite doable. For simple buildings or cargo cars it would be pretty easy. The thing could then be customised and exported straight back to .3dp.
Gumbootz Lokomotivfabrik und Bierkeller

LMR Samson 0-4-0 - Pennsy H3 Consolidation - Custom double tank cars set
User avatar
Hawk
The Big Dawg
Posts: 242
Joined: Fri Nov 10, 2006 10:28 am
Location: North Georgia - USA

Re: Blender > .3dp import/export script. Unread post

I have the Trial_3dp_export.zip. Is that the same as the final script for flat shading?
Hawk
User avatar
Gumboots
CEO
Posts: 1203
Joined: Mon Aug 13, 2012 4:32 am
Location: Australia

Re: Blender > .3dp import/export script. Unread post

Yeah I think so. Can't honestly remember what code was in that zip. The bit that was changed to get vertex normals was this:

Code: Select all

# replace the following line:
                    file.write(struct.pack("<3f", *f.loops[i].calc_normal()))

# by this code:
                    file.write(struct.pack("<3f", *f.verts[i].normal))
So if the one in the zip says loops.calc_normal() it will flat shade. If it says vets.normal it will smooth shade.
Gumbootz Lokomotivfabrik und Bierkeller

LMR Samson 0-4-0 - Pennsy H3 Consolidation - Custom double tank cars set
User avatar
Hawk
The Big Dawg
Posts: 242
Joined: Fri Nov 10, 2006 10:28 am
Location: North Georgia - USA

Re: Blender > .3dp import/export script. Unread post

OK! Thanks.

I checked and the only difference between the Trial py script and the newly posted Blender py script is at line 40.

Trial:

Code: Select all

"00 00 3E C0  ED 1E 5F C1  09 0A 4D 40  49 4E 53 54"
New Blender:

Code: Select all

"00 00 00 00  00 00 00 00  00 00 00 00  49 4E 53 54"
So I can delete the Trial zip and just make the change you noted above to have both correct versions, right?

Edit 1: OK! Now I have two versions. Flat and smooth. The only difference in the two is at line 74.

flat

Code: Select all

file.write(struct.pack("<3f", *f.loops[i].calc_normal()))
smooth

Code: Select all

file.write(struct.pack("<3f", *f.verts[i].normal))
Both have line 40 as

Code: Select all

"00 00 00 00  00 00 00 00  00 00 00 00  49 4E 53 54"
Hawk
User avatar
Gumboots
CEO
Posts: 1203
Joined: Mon Aug 13, 2012 4:32 am
Location: Australia

Re: Blender > .3dp import/export script. Unread post

Yup. That sounds right. The line 40 thing was him just throwing in the body attachment point from an example .3dp screenshot that I'd posted over there. It should be all zeroes for loco bodies (I think my example screenshot was from a truck).

I actually made the mistake of exporting a loco body with that code and loading it into the game. It had an interesting effect, in that the loco body was hugging the ground, and set back and to one side. Looked quite radical. :mrgreen:

Line 78 is what determines flat vs smooth shading.

We should get some more improvements to the script sometime this month. CoDEmanX has come down with a case of tendonitis, which is putting a stop to any coding at the moment. Once he has his hands back, he says he'll throw in a few of the tweaks that were being discussed (UV importing, etc).
Gumbootz Lokomotivfabrik und Bierkeller

LMR Samson 0-4-0 - Pennsy H3 Consolidation - Custom double tank cars set
Tomix

Re: Blender > .3dp import/export script. Unread post

This is amazing Gumboots! I'll have to give this a try!
User avatar
Gumboots
CEO
Posts: 1203
Joined: Mon Aug 13, 2012 4:32 am
Location: Australia

Re: Blender > .3dp import/export script. Unread post

Has anyone had a chance to play around with this stuff? CoDEmanX has just threatened to make improvements to the current script, so feedback would be good.
Gumbootz Lokomotivfabrik und Bierkeller

LMR Samson 0-4-0 - Pennsy H3 Consolidation - Custom double tank cars set
User avatar
Gumboots
CEO
Posts: 1203
Joined: Mon Aug 13, 2012 4:32 am
Location: Australia

Re: Blender > .3dp import/export script. Unread post

Ok, we have improvements already. No need for 3dconverter at all any more, and no need to screw around going from .3dp, to .obj, and then into Blender.

The import script will now import the UV mapping as well as the mesh. This means skinning is now a lot easier. You can just import any RT3 model straight into Blender, and see the skin on it, and see how it all maps to the skin. I've already done the Class 01 and the Kriegslok, just to test the new script. Piece of cake. !*th_up*!

Obviously this means that minor changes to existing models are now easier too. You can change the mesh you want to change and leave the rest alone, sort the skin out so it all suits, then export out to .3dp.
Gumbootz Lokomotivfabrik und Bierkeller

LMR Samson 0-4-0 - Pennsy H3 Consolidation - Custom double tank cars set
User avatar
Gumboots
CEO
Posts: 1203
Joined: Mon Aug 13, 2012 4:32 am
Location: Australia

Re: Blender > .3dp import/export script. Unread post

If anyone wants the latest version of this script I've attached a zip to this post. The new script will import UV mapping now, as well as exporting it. This is very useful for quick customisation of existing models.

The zip also includes a basic Blender file (named !Base_file_for_importing.blend) that is already set up with lamps for most layers, so you can import different .3dp's to different layers and immediately be able to see what you're doing. This can be handy for model levels of detail, and for importing a locomotive and its tender to the same file.

The .blend also has a basic material and texture locked in, using settings that will automatically work well for RT3 skinning.

To play around with an existing model, just import all the relevant .3dp files one at a time (batch import is not possible yet). All the imported objects will not have a material and texture assigned yet, so just after import all components will be a basic grey in colour.

There is no need to create any new materials if you are only importing one model. To get the imported model looking like it does in the game, start by setting the loco or building body to the default material (it's called Base Material in the .blend, just to give it an obvious name). Now use the A key twice to select all objects, then use Shift+Right Click to make the loco body the active object. Next, use Ctrl+L to open a pop-up menu, and left click Materials in the menu options. All objects will now be set to the Base Material.

This base material will still be grey until you call in the model's A skin. Once all objects are set to the same material, go to the texture settings and scroll down to the image section. Left click the X button next to where it says Works_grey_base.png (clicking this unlinks the default packed file and unlocks the file browser).

Now open the file browser (Open button, of course) to find and select the model's .dds or .tga A skin. The model should now be skinned correctly. (0!!0)

To see how each component of the model maps to the skin you need to right click on a component to select it, change the view from Object mode to Edit mode, then hit the A key to select all vertices. The mapping for that component will now be visible in the UV editor window, beneath the main 3D window.

If you are only wanting to re-skin an existing model this is all you have to worry about. You don't have to concern yourself with the export side of things. You can just edit your skin image in Photoshop or whatever, and use the update button to update the view in Blender. This will give you a much faster skinning time than having to check it all in the game every time you make a small change.

If you want to customise the mesh for a model there are a few more tricks you need to know.

The script will still only export components that have UV mapping. Any components that do not have UV mapping will cause an error if you try to export them. Before exporting, make sure any components that lack UV mapping are not selected.

This new version of the script will only export selected objects. If you have one object that is your locomotive body and you want to export that, just right click it to select it before running the export script. The created .3dp will only contain the locomotive body.

If you have the loco body split down into several components (boiler, cab, whatever) but you want them all to be included in the finished .3dp, hold down Shift and right click every component you want to include, then run the export script.

After exporting you may need to check the attachment points in the resulting .3dp's. By default they are set to zero on all three axes. This is fine for loco and tender bodies, and for buildings, but will require manual hex editing for some other components (connecting rods, etc). That's not difficult to do. If anyone needs tips on how to do it, just ask. !*th_up*!
Last edited by Gumboots on Fri Nov 27, 2015 4:25 pm, edited 7 times in total.
Gumbootz Lokomotivfabrik und Bierkeller

LMR Samson 0-4-0 - Pennsy H3 Consolidation - Custom double tank cars set
User avatar
Gumboots
CEO
Posts: 1203
Joined: Mon Aug 13, 2012 4:32 am
Location: Australia

Re: Blender > .3dp import/export script. Unread post

Just updated the post above with new files and more information. I've also linked that post from the OP of this thread.

I did notice that the original version of the script, that was in the OP and was not as user-friendly as the current version, was downloaded 15 times. I've removed that now. If anyone wants to try this stuff, grabbing the latest script and preset .blend from the zip just above is a much better option. !*th_up*!
Gumbootz Lokomotivfabrik und Bierkeller

LMR Samson 0-4-0 - Pennsy H3 Consolidation - Custom double tank cars set
Post Reply