The International Simutrans Forum

 

Author Topic: Rendering multiple Blender files  (Read 7777 times)

0 Members and 1 Guest are viewing this topic.

Offline IgorEliezer br

  • Devotee
  • Administrator
  • *
  • Posts: 4069
  • Cake recipes are cool.... REALLY!
    • Igor Eliezer Architect and Urban Planner/Arquiteto e Urbanista
  • Languages: PT, EN, AutoLISP, Python
Rendering multiple Blender files
« on: December 30, 2014, 11:32:06 AM »
Won't anybody think of the pakset maintainers? It'd take months to re-render all of the Pak128.Britain .blends...
umm, where are those blend files? Just for curiosity.

----

MOD EDIT: This is a topic split from http://forum.simutrans.com/index.php?topic=14243.msg141155#msg141155.
« Last Edit: January 06, 2015, 12:49:06 AM by IgorEliezer »

Offline jamespetts gb

  • Simutrans-Extended project coordinator
  • Devotee
  • *
  • Posts: 17661
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Rendering multiple Blender files
« Reply #1 on: December 30, 2014, 11:42:03 AM »
A large number of them are here. Many more are here. Some are missing, such as .blends for aircraft and the latest Underground trains, but I am sure that Milko and The Hood could supply them if necessary.

Offline IgorEliezer br

  • Devotee
  • Administrator
  • *
  • Posts: 4069
  • Cake recipes are cool.... REALLY!
    • Igor Eliezer Architect and Urban Planner/Arquiteto e Urbanista
  • Languages: PT, EN, AutoLISP, Python
Re: Rendering multiple Blender files
« Reply #2 on: December 30, 2014, 12:22:14 PM »
A large number of them are here.
"Sorry, we had to truncate this directory to 1,000 files. 2,447 entries were omitted from the list. "

Ouch! That is huge. I believe that all blender files have their render scene set up.

Offline jamespetts gb

  • Simutrans-Extended project coordinator
  • Devotee
  • *
  • Posts: 17661
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Rendering multiple Blender files
« Reply #3 on: December 30, 2014, 12:29:50 PM »
"Sorry, we had to truncate this directory to 1,000 files. 2,447 entries were omitted from the list. "

Ouch! That is huge. I believe that all blender files have their render scene set up.

I did tell you! And that's not even all of them. They do indeed have the render scene largely set up, however, although it does sometimes require manual turning on of the relevant layers, and, in the case of older blender models, manual setting of the file-names and the type. There are a few blender models missing, too, and one where only a much earlier version is available in a totally different scale (the LSWR M7 class steam locomotive).

Offline IgorEliezer br

  • Devotee
  • Administrator
  • *
  • Posts: 4069
  • Cake recipes are cool.... REALLY!
    • Igor Eliezer Architect and Urban Planner/Arquiteto e Urbanista
  • Languages: PT, EN, AutoLISP, Python
Re: Rendering multiple Blender files
« Reply #4 on: January 02, 2015, 08:54:54 PM »
I did tell you! And that's not even all of them. They do indeed have the render scene largely set up, however, although it does sometimes require manual turning on of the relevant layers, and, in the case of older blender models, manual setting of the file-names and the type. There are a few blender models missing, too, and one where only a much earlier version is available in a totally different scale (the LSWR M7 class steam locomotive).
I have good news: I wrote a small Python application which generates a batch file to render PNG images of large quantity of blender files stored in a folder. It is almost done.

The problem is what you said, the blender files do not follow an "ready-to-render" standard. I tested my app with 16 blender files, they all rendered just fine but with alpha channel and no proper background color.

Offline jamespetts gb

  • Simutrans-Extended project coordinator
  • Devotee
  • *
  • Posts: 17661
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Rendering multiple Blender files
« Reply #5 on: January 02, 2015, 09:13:50 PM »
I have good news: I wrote a small Python application which generates a batch file to render PNG images of large quantity of blender files stored in a folder. It is almost done.

The problem is what you said, the blender files do not follow an "ready-to-render" standard. I tested my app with 16 blender files, they all rendered just fine but with alpha channel and no proper background color.

When I use Blender, I do not find that they output an alpha channel, but this is ignored by Makeobj (albeit with a warning), so this is not a real problem. The background colour is more of an issue: the only way to do this is have a black background with no anti-aliasing and then use the GIMP's flood fill with a tolerance of zero to replace all of the black background with the right colour. Trying to set the background colour in Blender results in it trying to anti-alias it, resulting in light blueish pixels at the edge of everything. For some reason, the only background colour that works without anti-aliasing is black. The normal workflow is to use Image Masker to process the images into a single graphic per vehicle, then use the Gimp to replace the black background all at once: this can be quite efficient.

The thing that takes most of the time is actually setting it up in Blender. Your script might actually, therefore, be very useful, and this is a very interesting development that might further improve the efficiency of graphics production. Presumably, the render settings (including the file name, and whether we want 4 or 8 rotations, normal or vehicle) have to be set up in each individual Blender file first?

Offline Sarlock

  • Devotee
  • *
  • Posts: 1340
  • Languages: EN
Re: Rendering multiple Blender files
« Reply #6 on: January 02, 2015, 09:57:47 PM »
Interesting.  When I am using Blender, I export to a PNG with alpha channel (using F3), load the PNG in to GIMP, strip the alpha channel out with the Threshold tool, choosing a level that looks the best (usually around 50-100) and then drop the image on to the blue background for Simutrans and presto it's done.  Takes about 30 seconds.

Offline jamespetts gb

  • Simutrans-Extended project coordinator
  • Devotee
  • *
  • Posts: 17661
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Rendering multiple Blender files
« Reply #7 on: January 02, 2015, 10:05:16 PM »
30 seconds per image? Goodness: that's much longer than the method that I describe. (I assume that you mean per image assembled in Image Masker, rather than per rotation, or else that would be 4 minutes for every vehicle, which would just be painful).

Offline IgorEliezer br

  • Devotee
  • Administrator
  • *
  • Posts: 4069
  • Cake recipes are cool.... REALLY!
    • Igor Eliezer Architect and Urban Planner/Arquiteto e Urbanista
  • Languages: PT, EN, AutoLISP, Python
Re: Rendering multiple Blender files
« Reply #8 on: January 02, 2015, 11:18:38 PM »
*post*
And
*post*
If I'm sure there was a way to disable alpha channel and anti-aliasing and set up the background color right off the bat in blender so you wouldn't need any post-render edit. I remember there was a way because Raven taught me how to do so (edit: but I forgot it) when I used to post my horrible buildings like this: http://archive.forum.simutrans.com/topic/07334.0/index.html
« Last Edit: January 02, 2015, 11:36:01 PM by IgorEliezer »

Offline jamespetts gb

  • Simutrans-Extended project coordinator
  • Devotee
  • *
  • Posts: 17661
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Rendering multiple Blender files
« Reply #9 on: January 03, 2015, 12:11:14 AM »
If anyone knows/remembers a way of doing this, I should be very grateful to know!

Offline Ters

  • Coder/patcher
  • Devotee
  • *
  • Posts: 5317
  • Languages: EN, NO
Re: Rendering multiple Blender files
« Reply #10 on: January 03, 2015, 10:40:38 AM »
AndIf I'm sure there was a way to disable alpha channel and anti-aliasing and set up the background color right off the bat in blender so you wouldn't need any post-render edit.

You mean, like disable anti-aliasing and setting a solid background color? The former is done in the render window and the latter is set in the world settings. By default, Blender doesn't output alpha transparency. However, if you want anti-aliasing everywhere except on edges against the background, I'm not sure if that's easily achiveable.

Offline jamespetts gb

  • Simutrans-Extended project coordinator
  • Devotee
  • *
  • Posts: 17661
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Rendering multiple Blender files
« Reply #11 on: January 03, 2015, 10:42:56 AM »
You mean, like disable anti-aliasing and setting a solid background color? The former is done in the render window and the latter is set in the world settings. By default, Blender doesn't output alpha transparency. However, if you want anti-aliasing everywhere except on edges against the background, I'm not sure if that's easily achiveable.

Yes, that latter problem is the issue, I think, as internal edges need to be anti-aliased.

Offline Fabio

  • Devotee
  • Administrator
  • *
  • Posts: 2898
  • The Pak128 Guy
    • Visit me on Facebook
  • Languages: EN, IT, RO, FR
Re: Rendering multiple Blender files
« Reply #12 on: January 03, 2015, 02:48:59 PM »
You could render with no antialiasing at all and correct background (if possible), to be used as a mask on the render with black background and full antialiasing, then combine with the mask using a batch editor like imagemagik. The latter program is extremely powerful for post editing.


Sent from my iPhone using Tapatalk

Offline jamespetts gb

  • Simutrans-Extended project coordinator
  • Devotee
  • *
  • Posts: 17661
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Rendering multiple Blender files
« Reply #13 on: January 03, 2015, 02:59:56 PM »
That sounds more time consuming than the present method, which is actually quite efficient.

Offline Fabio

  • Devotee
  • Administrator
  • *
  • Posts: 2898
  • The Pak128 Guy
    • Visit me on Facebook
  • Languages: EN, IT, RO, FR
Re: Rendering multiple Blender files
« Reply #14 on: January 03, 2015, 03:23:26 PM »
Not if you can script the rendering, but I'm Blender illiterate. It might just be a script to launch on a folder, go grab a coffee/tea and be back with the job done.


Sent from my iPhone using Tapatalk

Offline jamespetts gb

  • Simutrans-Extended project coordinator
  • Devotee
  • *
  • Posts: 17661
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Rendering multiple Blender files
« Reply #15 on: January 03, 2015, 03:29:01 PM »
If somebody could actually set up all of the steps end to end fully automated, that would be significant progress, but I do not have the skills to do that.

Offline Ters

  • Coder/patcher
  • Devotee
  • *
  • Posts: 5317
  • Languages: EN, NO
Re: Rendering multiple Blender files
« Reply #16 on: January 03, 2015, 03:46:58 PM »
You could render with no antialiasing at all and correct background (if possible), to be used as a mask on the render with black background and full antialiasing, then combine with the mask using a batch editor like imagemagik. The latter program is extremely powerful for post editing.


Sent from my iPhone using Tapatalk

You might perhaps not need to use an external program. Blender has a very complex node system for post-processing. Understanding it is another matter. In either case, there might be a problem that anti-aliasing bleeds both ways, so there is a mix of the background color inside the mask as well. One could perhaps get around that somehow by adding the background color in a post-processing node, after the edges have been made aliased somehow.


Sent from my computer using a browser

Offline jamespetts gb

  • Simutrans-Extended project coordinator
  • Devotee
  • *
  • Posts: 17661
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Rendering multiple Blender files
« Reply #17 on: January 03, 2015, 04:01:06 PM »
If anyone can find a way of doing that (preferably automatically), then that would be splendid.

Offline Sarlock

  • Devotee
  • *
  • Posts: 1340
  • Languages: EN
Re: Rendering multiple Blender files
« Reply #18 on: January 03, 2015, 07:54:43 PM »
Perhaps I am not fully understanding the issue, but you can output to an RGBA alpha PNG in Blender.  This still does all of the anti-aliasing and then you just have to strip the alpha channel out (either fully or at some determined percentage) and you have a nicely anti-aliased image internally with sharp edges on the outside.  This way you do not get any anti-aliased blending with the background colour, since there is none.

If your script outputs all of the images together on one PNG for the different rotations, it just takes one quick operation to strip the alpha channel and it's ready to import to Simutrans.  Further, I believe this alpha channel removal could be automated using GIMP's command line feature (you could do an entire folder of files in one command line operation).

If the alpha enabled PNGs are kept separate, then you even have a quick way to make an alpha-channel ready pakset, if ever that should be a possibility in the future.  But I dream...  ;)

Offline jamespetts gb

  • Simutrans-Extended project coordinator
  • Devotee
  • *
  • Posts: 17661
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Rendering multiple Blender files
« Reply #19 on: January 03, 2015, 08:20:31 PM »
That is an interesting idea, but, unless the post-processing could be automated, it'd be no better than the current arrangement, where it's just a single click in the GIMP with the fill tool to post process a single vehicle after it has been through Image Masker to combine it into one image (the Blender output produces one image per rotation, not per vehicle, and I suspect that this would be hard to change).

Offline Sarlock

  • Devotee
  • *
  • Posts: 1340
  • Languages: EN
Re: Rendering multiple Blender files
« Reply #20 on: January 03, 2015, 08:30:17 PM »
Could the script output the images from Blender with filenames that are numbered/ordered so that a second, later, script can be run to auto process these images through GIMP and makeobj?  You could process a whole batch of images through Blender, then quickly script process those same images with a single click to import them to Simutrans as .pak files.  You could conceivably process dozens or more vehicles/buildings/etc in a matter of seconds.

Offline IgorEliezer br

  • Devotee
  • Administrator
  • *
  • Posts: 4069
  • Cake recipes are cool.... REALLY!
    • Igor Eliezer Architect and Urban Planner/Arquiteto e Urbanista
  • Languages: PT, EN, AutoLISP, Python
Re: Rendering multiple Blender files
« Reply #21 on: January 03, 2015, 08:43:59 PM »
Could the script output the images from Blender with filenames that are numbered/ordered so that a second, later, script can be run to auto process these images through GIMP and makeobj?
As to the 1st script: I wrote one to render every blender file "as-is" stored in a directory: http://github.com/IgorEliezer/RenderTrans, but it still needs some final tweaks.

Offline jamespetts gb

  • Simutrans-Extended project coordinator
  • Devotee
  • *
  • Posts: 17661
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Rendering multiple Blender files
« Reply #22 on: January 03, 2015, 09:44:40 PM »
Yes, the output files do have determinate names and numbers that are used for semi-automatic processing by Image Masker.

Offline Ters

  • Coder/patcher
  • Devotee
  • *
  • Posts: 5317
  • Languages: EN, NO
Re: Rendering multiple Blender files
« Reply #23 on: January 03, 2015, 10:31:29 PM »
Perhaps I am not fully understanding the issue, but you can output to an RGBA alpha PNG in Blender.  This still does all of the anti-aliasing and then you just have to strip the alpha channel out (either fully or at some determined percentage) and you have a nicely anti-aliased image internally with sharp edges on the outside.  This way you do not get any anti-aliased blending with the background colour, since there is none.

I was thinking the same, and now I tried it out. But it appears Blender anti-aliases against black when there is no background.

Offline jamespetts gb

  • Simutrans-Extended project coordinator
  • Devotee
  • *
  • Posts: 17661
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Rendering multiple Blender files
« Reply #24 on: January 03, 2015, 10:49:42 PM »
Another issue is that quite a number of the Blender graphics, particularly for railway vehicles are made by having one Blender file for a whole set of different but related vehicles, such as different configurations of the same basic type of carriage, or even one layer for a steam locomotive and one for its tender.

Offline IgorEliezer br

  • Devotee
  • Administrator
  • *
  • Posts: 4069
  • Cake recipes are cool.... REALLY!
    • Igor Eliezer Architect and Urban Planner/Arquiteto e Urbanista
  • Languages: PT, EN, AutoLISP, Python
Re: Rendering multiple Blender files
« Reply #25 on: January 03, 2015, 11:13:10 PM »
I think we should split the topic and move all Blender-related posts to PakSets and Customization section before our bored programmer comes in and say "Get off my lawn!" :D

Agreed?

EDIT: Blender has an internal Python API so it's possible to run a script "in" Blender to set up things right... not a trivial task though.

Offline jamespetts gb

  • Simutrans-Extended project coordinator
  • Devotee
  • *
  • Posts: 17661
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Rendering multiple Blender files
« Reply #26 on: January 03, 2015, 11:25:03 PM »
Agreed - seems sensible to me.

Offline Markohs

  • DevTeam, Coder/patcher
  • Devotees (Inactive)
  • *
  • Posts: 1559
  • Languages: EN,ES,CAT
Re: Rendering multiple Blender files
« Reply #27 on: January 03, 2015, 11:32:49 PM »
I'm not that bored anymore, but yes, get out! ;)

Offline Yona-TYT ve

  • Devotee
  • *
  • Posts: 1115
    • Simutrans-BLOG
  • Languages: ES
Re: Rendering multiple Blender files
« Reply #28 on: January 03, 2015, 11:57:51 PM »
I think there is enough material to entertaining here.  ;D

Offline IgorEliezer br

  • Devotee
  • Administrator
  • *
  • Posts: 4069
  • Cake recipes are cool.... REALLY!
    • Igor Eliezer Architect and Urban Planner/Arquiteto e Urbanista
  • Languages: PT, EN, AutoLISP, Python
Re: Rendering multiple Blender files
« Reply #29 on: January 06, 2015, 12:50:08 AM »