Blender > .3dp import/export script.

Stop by here for help with RRT3 Editor problems and tips.
User avatar
Gumboots
CEO
Posts: 4822
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.
User avatar
Hawk
The Big Dawg
Posts: 6504
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: 4822
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.
User avatar
Hawk
The Big Dawg
Posts: 6504
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: 4822
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).
User avatar
Tomix
Brakeman
Posts: 105
Joined: Sun Sep 29, 2013 9:58 pm

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: 4822
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.
User avatar
Gumboots
CEO
Posts: 4822
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.
User avatar
Gumboots
CEO
Posts: 4822
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*!
Attachments
Blender_3dp_starter_kit_v2.zip
(75.1 KiB) Downloaded 367 times
Last edited by Gumboots on Fri Nov 27, 2015 4:25 pm, edited 7 times in total.
User avatar
Gumboots
CEO
Posts: 4822
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*!
User avatar
Gumboots
CEO
Posts: 4822
Joined: Mon Aug 13, 2012 4:32 am
Location: Australia

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

Just had a brainwave. Rather than waiting for CoDEmanX to feel like fixing something for us, I took a look at some of the Blender Noob to Pro tutorials and found a solution to two of the last niggles with the existing script.

The first niggle was that it just named any imported .3dp's as imported_3dp, imported_3dp.001, imported_3dp.002, etc. This was a nuisance since it meant you had to rename them all after importing, and it wasn't clear what was what until you selected the object and took a look at what it was doing on the model. You could also import the same one twice by mistake, and it would just show as one of the many imported_3dp.00* on the list.

So, reading one of the basic tuts on import scripts shows how that script did it, so that any new imported objects would have the same name as the file they came from. It only required a very slight adaption to fit our .3dp import script (uses a different variable name) and it works perfectly. Any file you import will be given the correct name. If you import ClassY6L_Body.3dp it will now automatically appear on your objects list as ClassY6L_Body.3dp.

This totally rocks. (0!!0)

The second niggle was that the script would export every object in the .blend, regardless of the layer it was on, or whether it was hidden, or whatever. I've managed to fix that too. It will now only export objects you select. There is no longer any need to delete objects you don't want to export. This saves a lot of merging and deleting before exporting, and a lot of Ctrl+Z'ing to step backwards after you've just exported something.

This also totally rocks. ::!**!

So, I've just updated the earlier post with the latest version in a new zip. The base .blend file is the same. Only the Python script has changed.

I've also deleted one of my desktop shortcuts, which was included in the previous zip by mistake. *!*!*!

Pic shows WP&P's famous N&W Y6 2-8-8-2 imported into Blender. All components, correctly named and skinned. Took about five minutes. Well, maybe ten, but it felt like five and I wasn't rushing.
N&W_Y6_imported.jpg
User avatar
Hawk
The Big Dawg
Posts: 6504
Joined: Fri Nov 10, 2006 10:28 am
Location: North Georgia - USA

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

I'm curious. Why do you use the img tags for the images you post instead of placing them inline?
Hawk
User avatar
Gumboots
CEO
Posts: 4822
Joined: Mon Aug 13, 2012 4:32 am
Location: Australia

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

Because that way you can see them without having to load a new page. Saves time and effort. TBH that's one of phpBB's quirks that I find annoying. It must be about the only software that doesn't let you really do inline images. Hey ho.
User avatar
Hawk
The Big Dawg
Posts: 6504
Joined: Fri Nov 10, 2006 10:28 am
Location: North Georgia - USA

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

It's not phpBB so much as it's my settings. By setting images to show as thumbnails, it allows users to attach bigger images.
Hawk
User avatar
Gumboots
CEO
Posts: 4822
Joined: Mon Aug 13, 2012 4:32 am
Location: Australia

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

Well it's personal preference I suppose, but to my mind setting that thumbnail limit effectively makes the inline option completely pointless, because all you end up with is an "inline" thumbnail that still requires reloading the page to see it. So that makes it no different, in reality, to just leaving it as a standard attachment and not bothering about the inline thing. **!!!**

If they are full width in the post they will still fit on anyone's screen, and they will be large enough that you will be able to see sufficient detail without any extra effort. !#2bits#!
User avatar
Hawk
The Big Dawg
Posts: 6504
Joined: Fri Nov 10, 2006 10:28 am
Location: North Georgia - USA

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

Gumboots wrote:Well it's personal preference I suppose,
Fair 'nuff.
Hawk
User avatar
Just Crazy Jim
Dispatcher
Posts: 413
Joined: Fri Oct 14, 2016 9:57 pm
Location: Coal Fields of WV

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

Gumboots wrote:To install the script into Blender, copy it to the C:\Program Files\Blender Foundation\Blender\2.74\scripts folder. Then fire up Blender, go into user preferences > add ons, find the script in the list, and enable it.
Strangely enough, my install doesn't have a 2.74 or scripts folder. So I made them and added them.

Now, I am staring at the User preferences... and, well... there's nothing I am seeing here that lines up with "add ons"
Blender-1.jpg
"We have no patience with other people's vanity because it is offensive to our own."
-- François de La Rochefoucauld. Réflexions ou sentences et maximes morales. 1665.
User avatar
Gumboots
CEO
Posts: 4822
Joined: Mon Aug 13, 2012 4:32 am
Location: Australia

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

That's an installation of Blender 2.49, which is way out of date and which I have never used, so can't help with. I know the script works with 2.74, which is what was current at the time. You can get it here: http://download.blender.org/release/Blender2.74/

They're now up to 2.78a (and yes it is stable despite the "a" that you might think indicates an alpha). I haven't tried playing with that, so do not know if the script will work with it. I'm currently on a roll with modelling and not inclined to experiment with GUI changes. ;-)
User avatar
Just Crazy Jim
Dispatcher
Posts: 413
Joined: Fri Oct 14, 2016 9:57 pm
Location: Coal Fields of WV

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

I understand, I am already certain that Blender and I will not be friends. I had forgotten how much I hated Blender. This effort has constantly reminded me that Milkshape 3D is 10, maybe even 100, times more user-friendly.
"We have no patience with other people's vanity because it is offensive to our own."
-- François de La Rochefoucauld. Réflexions ou sentences et maximes morales. 1665.
User avatar
Gumboots
CEO
Posts: 4822
Joined: Mon Aug 13, 2012 4:32 am
Location: Australia

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

How many hours have you spent using Blender? I hated it the first few times I tried playing with it. I'm fine with it now, and have been for quite a while. AFAICT the main problem with it is that it is so capable that it includes a lot of stuff we'll never want, and which consequently gets in the way sometimes. So if you stripped it back to "only stuff that mugs will use for RT3" then yes, it would be less intimidating at first, but OTOH it would never have been developed and supported to the current level.

Anyway, don't psyche yourself into a position of "Blender is horrible it wants to kill me and I'll never get the hang of it". It's really pretty good, and not that hard to pick up. (0!!0)
Post Reply