The International Simutrans Forum

PakSets and Customization => Pak128.Britain => Topic started by: The Hood on January 27, 2014, 08:48:42 PM

Title: Blender to png
Post by: The Hood on January 27, 2014, 08:48:42 PM
This thread gives a summary of how to use the rendering add-on for blender and Zeno's ImageMasker program to create full pngs for pak128.Britain. This works for 1x1 buildings and all vehicles.


Step 1: make blender model and scale correctly:
- best to start from an existing blender file so the lighting is set up correctly.
- Ensure vehicle is correctly aligned - centred down its direction of travel, z-aligned with wheels on the z=0 plane, 4 blender guide squares in front of the vertical axis looking side on (see an existing example of a blend for what I mean here).


Step 2: use the rendering add-on to output the images (see attachment):
- make sure the py script in the attachment is in the python add-ons folder in blender: e.g. C:\Users\XXXXX\AppData\Roaming\Blender Foundation\Blender\2.64\scripts\addons
- enable the addon in blender: User preferences->addons->render tab, make sure the check box is ticked on the right:
(http://imagizer.imageshack.us/v2/800x600q90/837/be1u.jpg) (https://imageshack.com/i/n9be1uj)
- Back in the properties window in blender you should now see an extra box in the render tab:
(http://imagizer.imageshack.us/v2/800x600q90/24/l58m.jpg) (https://imageshack.com/i/0ol58mj)
- give the image a name in the first box (NO FILE SUFFIX)
- choose render option: 4 views for buildings, 8 views vehicle alignment FOR RAIL VEHICLES, 8 views normal alignment FOR ALL OTHER VEHICLES
- Hit the render views button and wait
- "MAKE MASK" is if you want to automatically create a shadeless, non anti-aliased images which can be used to give sharper edges and auto player colour in the next step, but this doesn't work too well and pak128.Britain graphics do not generally use this feature.


Step 3: Load up ImageMasker (http://forum.simutrans.com/index.php?topic=4552.msg91435#msg91435)
- Choose 4 or 8 views as appropriate
- open button - select the 4 or 8 output pngs
- select the SAME 4 or 8 files at the second prompt again, unless you have created a mask set of images in which case use those.
- hit process
- hit save and save the output png where you need it


Step 4: Use a graphics program eg GIMP to convert black background to #e7ffff simutrans transparency colour on the output png and resave


Step 5: Get the dat file right
- NB image definition 1.0 is WEST, 1.1 is NW etc.
- apply any offsets. I have now worked out the offsets for road vehicles - this works for vehicles centre-aligned in blender and with the drive_left flag set to 1 in compat.tab:


EmptyImage[E]=./images/aec-swift.1.4,-28,14
EmptyImage[SE]=./images/aec-swift.1.5,-13,0
EmptyImage[S]=./images/aec-swift.1.6,4,4
EmptyImage[SW]=./images/aec-swift.1.7,0,18
EmptyImage[W]=./images/aec-swift.1.0,4,5
EmptyImage[NW]=./images/aec-swift.1.1,12,10
EmptyImage[N]=./images/aec-swift.1.2,28,14
EmptyImage[NE]=./images/aec-swift.1.3,0,24



Step 6: Compile with makeobj and enjoy


Moderator note: The original download link (below) is now broken, but you can download an updated version of the file here (http://bridgewater-brunel.me.uk/downloads/render_SimutransRender_pak128Britain-65.py) instead. - Jamespetts.

Moderator note 2: For this workflow to work correctly, it is essential to use Blender version 2.65 (or earlier, but not all earlier versions have been tested). Version 2.65 can be downloaded for Windows, Linux and MacOS X here (http://download.blender.org/release/Blender2.65/).
Title: Re: Blender to png
Post by: jamespetts on January 27, 2014, 09:48:15 PM
Ahh, you have the road vehicle offsets - excellent! This is of great assistance. When you write "centre aligned" in respect of road vehicles, do you mean using the "normal" rather than "vehicle" settings?

Finally, I wonder whether there is anything to be said for using the road vehicle offsets for river and canal boats...?
Title: Re: Blender to png
Post by: The Hood on January 27, 2014, 09:54:23 PM
Either. What I mean is make sure the vehicle straddles the y-axis along its length.
Title: Re: Blender to png
Post by: jamespetts on January 27, 2014, 10:02:32 PM
Ahh, I see what you mean by that; but surely the offsets would need to be different if the vehicle was in "normal" than "vehicle" alignment? Was it "vehicle" alignment that you used?
Title: Re: Blender to png
Post by: The Hood on January 27, 2014, 10:05:01 PM
All in the first post... (look carefully at step 2) :)
Title: Re: Blender to png
Post by: jamespetts on January 27, 2014, 10:59:44 PM
Ahh, the road vehicle offsets are indeed based on the "vehicle" settings?
Title: Re: Blender to png
Post by: Sarlock on January 27, 2014, 11:03:28 PM
Excellent!  Thank you for this :)
Title: Re: Blender to png
Post by: The Hood on January 28, 2014, 08:02:24 AM
Quote
- choose render option: 4 views for buildings, 8 views vehicle alignment FOR RAIL VEHICLES, 8 views normal alignment FOR ALL OTHER VEHICLES

Am I missing something here or is this not clear enough? Road vehicles are based on NORMAL settings. I should probably rename "vehicle alignment" to "rail alignment" in the python script though.
Title: Re: Blender to png
Post by: jamespetts on January 28, 2014, 10:29:42 AM
By "rail vehicles", I assume that you mean to include rail, narrow gauge, tram, monorail and maglev?
Title: Re: Blender to png
Post by: The Hood on January 28, 2014, 10:41:21 AM
Well I've never made any monorail and maglev vehicles so I don't know about those, but the first three yes.
Title: How to make graphics
Post by: fam621 on October 21, 2016, 03:58:13 PM
How do you get the trains and make them on blend then into a dat file then a pak file James? I'm trying out blender for a bit to see if I can make liveries? :)
Title: Re: Blender to png
Post by: jamespetts on October 21, 2016, 07:38:43 PM
Fam621 - you originally posted in a thread about an unrelated bug, so I have split your topic and merged it with this thread, which contains the answer to your question.
Title: Re: Blender to png
Post by: jamespetts on December 18, 2016, 11:16:30 PM
After extensive testing, I have found that Blender versions newer than 2.65 cannot produce usable graphics unless they are exported in full alpha. This is because the way in which Blender handled image transparency was modified in version 2.66: see here (https://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.66/Image_Transparency) for details of the change.

The problem is that, in the newer rendering system, when a black background is used, objects tend to be surrounded by a thick, black line because the renderer now blends the black background pixels with the image pixels in a way that it used not to do when the render output was set to "straight alpha" (which is no longer available from version 2.66 onwards).

Despite the statement on Blender's own page (linked above), however, that the alpha convert node could be used to revert to the previous behaviour, I have not been able to get the alpha convert node to have any effect (I suspect because nodes are not compatible with the Blender rendering script).