Blender > .3dp import/export script.

Stop by here for help with RRT3 Editor problems and tips.
User avatar
Gumboots
CEO
Posts: 4813
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: 6503
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: 4813
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: 6503
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: 4813
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: 6503
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: 4813
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: 4813
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)
User avatar
Gumboots
CEO
Posts: 4813
Joined: Mon Aug 13, 2012 4:32 am
Location: Australia

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

Just quoting this over here, so Blender instructions will be in the Blender script thread. !*th_up*!
https://en.wikibooks.org/wiki/Blender_3 ... ng_Windows

IOW, resizing can be done with any window, and works exactly the same way that it does on any desktop. You just click and hold on the border, and drag it.

1/ Getting the skin onto that model is about a one-minute-with-brain-in-neutral job, once you know how to do it. That includes starting from a bare default file and importing the model. It is definitely not the sort of job that will always take half an hour of misery.

2/ Speaking of which, that "little useless box" is simply the default cube model that is in every bare starting file. You can see it labelled as "Cube" in the overview panel at upper right.

You want it gone? Easy. Select it (right click) then go find the "Delete" button on your keyboard. Click that there button. Guess what happens? :-D

Oh, you deleted Elephant by mistake? No worries. Hit Ctrl+Z. Elephant will come back.

You can also delete the default camera. It's of no real use for what we are trying to do.

3/ Rotating the model. It's pretty straightforward. The 5 button on your numpad, over the the right of your keyboard, toggles you from ortho to perspective and back again. The other numpad buttons are all hotkeys for various views.

The 1 button gives you the front view. Ctrl+1 gives you the back view. 3 gives you left side view. Ctrl+3 gives you right side view. 7 gives you top view. Guess what Ctrl+7 does?

2 and 8 do rotation up or down around the horizontal axis. 4 and 6 do rotation around the vertical axis.

9 spins the model 180 degrees around the vertical axis.

Or if you want total freeform, hold own Alt+LMB (Left Mouse Button) then drag your mouse to spin the model anyway you like. You can also use Shift+Alt+LMB to pan in any direction.

If the model is incoveniently placed, you can use the period . button on the numpad to centre the view on the selected object and zoom in on it.

3/ The Alpha setting for texture set to 1, in combination with the Alpha for material being set to zero, will allow transparent sections of the skin (like the gaps between wheel spokes) to be transparent in the viewport. If you are just looking at a loco body skin that has no transparent areas anyway, it makes no difference. Sooner or later though, most likely sooner, you will be grumbling that your wheels look solid and why is Blender doing this? I gave you the settings to avoid that.

The other settings are ones you don't have to worry about unless you want fancy renders. Ignore them. The only thing I usually bother with is turning down the specular on material. I find knocking it back to 0.1 or 0.05 works well with the basic lighting I use.

4/ Importing all the widgety parts at once (mass import) would be cool, but unfortunately the bloke who wrote the import script for us didn't include that option. That's not a Blender fault. It's down to the custom script. I do not currently have the Python skills to code a mass import for the custom script.
And...
Oh and change your bottom window (the one that is almost collapsed) from Timeline to UV/IMage Editor. How? Click on the clock icon in the lowest toolbar to bring up a list of options. Select the one you want.

Edit: And while I think of it, the standard Windows delete button does deletion, but often you just want to hide something. That's what the H key does. H for Hide. Clever, hey?

Don't want it all hidey anymore, and want it to come back where you can thump it? Use Alt+H. Hey presto! Bunnies jump out of hatz. !*th_up*!
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

Well, I am a bit stuck.

I haven't noticed it until now, probably because most stuff I edit ends up having dark coloured textures. But this latest thing is mid-grey and the flat shading jumps out.
RT3_12_24_16__20_49_23.jpg
RT3_12_24_16__20_49_10.jpg
RT3_12_24_16__20_48_46.jpg
I checked my python script. It has:

Code: Select all

file.write(struct.pack("<3f", *f.verts[i].normal))
which should give smooth shading... only, it doesn't. **!!!**
Before export
Before export
After export
After export
In Blender and Milkshape 3D the model is smooth as glass, after export to RT3, flat shaded....

I crawled through the lines of the script and everything is as you say it should be in the earlier posts in this thread, but still flat shading.

I remember that you had said something about flat shading on the Mogul deborkification thread. Did you find a solution?
"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: 4813
Joined: Mon Aug 13, 2012 4:32 am
Location: Australia

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

Yup. I had the wrong version of the script. It was flat shading my Moguls because the script was telling it to. Very well behaved, when you think about it. :mrgreen:

So, I changed it to the smooth shaded version and it's all hunky dory now. It should work. Just make sure that line of code says exactly what is in the box.

Code: Select all

file.write(struct.pack("<3f", *f.verts[i].normal))
The flat-shaded version has this:

Code: Select all

file.write(struct.pack("<3f", *f.loops[i].calc_normal()))
Notice the extra pair of brackets there, right after calc_normal. If you try to make a smooth shaded version by editing the text, but forget about those extra brackets, like this:

Code: Select all

file.write(struct.pack("<3f", *f.verts[i].normal()))
That will cause flat shading, along with all sorts of random weirdness (missing verts counts, missing UV mapping, sometimes, not always, unpredictable).

So just check again and make sure it's exactly this:

Code: Select all

file.write(struct.pack("<3f", *f.verts[i].normal))
Two pairs of brackets only. Should work.
User avatar
Gumboots
CEO
Posts: 4813
Joined: Mon Aug 13, 2012 4:32 am
Location: Australia

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

Oh stuff it. Forget all that. Hang on and I'll dig out my copy that works. !*th_up*!
User avatar
Gumboots
CEO
Posts: 4813
Joined: Mon Aug 13, 2012 4:32 am
Location: Australia

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

Here ya go.
Attachments
This_one_works_for_smooth_shading.zip
(2.16 KiB) Downloaded 253 times
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 have the python script open and this is what I have in that function:

Code: Select all

            file.seek(faces_offset)
            for f in bm.faces:
                for i in range(3):
                    file.write(struct.pack("<i", f.verts[i].index + vc))
                for i in range(3):
                    file.write(struct.pack("<3f", *f.verts[i].normal)) <-- exactly as it should be, right?
                for i in range(3):
                    u, v = f.loops[i][uv_layer].uv
                    file.write(struct.pack("<2f", u, 1-v))
                file.write(b"\0" * 4)
Edit: Just downloaded your shared file and tried it. And I'm still getting flat shading. :-(
"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: 4813
Joined: Mon Aug 13, 2012 4:32 am
Location: Australia

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

Well that's weird. I use that script and I get smooth shading.
User avatar
Gumboots
CEO
Posts: 4813
Joined: Mon Aug 13, 2012 4:32 am
Location: Australia

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

Aha! Idea! May not be a good one but anyway...

It could be related to the format you're importing into Blender. Maybe. Can't think what else it would be. I know if I import and edit an existing .3dp I get smooth shading when I export again. However, the import script does not import normals.

All it does is import mesh and UV mapping. We decided on this because getting it to extract normals from existing .3dp's was being a PITA, while Blender will do normals from the mesh automatically. So, since Blender was going to sort them for us, no point bothering with importing them.

However, if you're using an import format that does include information for face normals, it is possible that Blender is remembering this and using the face normals when it exports to .3dp.

This is a guess, on the basis that nothing else seems remotely logical at the moment. It's a problem I've never encountered.
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

Okay, I will try another format. *crossing fingers*
"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: 4813
Joined: Mon Aug 13, 2012 4:32 am
Location: Australia

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

Hey hang on a doggone minute. I haz another idea. This one might even be useful. :mrgreen:

Since the .3dp import process drops information for normals, it follows that if you took one of the flat-shaded .3dp's and imported that into Blender, then exported it straight away using the smooth-shaded script, it should fix the problem.

Note that I said "should". Might be worth trying.
Post Reply