Author Topic: Render Post-Processor tool  (Read 15372 times)

0 Members and 1 Guest are viewing this topic.

Offline Zeno

  • ENASSA Designer
  • Devotee
  • *
  • Posts: 1996
  • Total likes: 3
  • Helpful: 30
    • Zeno's Simutrans Creations
  • Languages: ES, EN, CAT
Render Post-Processor tool
« on: February 23, 2010, 12:42:34 PM »
Since begining of february I've been trying to automate a bit the processes that need to be done since I have a Blender model till I get a Simutrans pak object. This fight has resulted in two small applications:
1) A blender phyton script that can be used together with a blender template, that allows to take 4 or 8 renders from the object, in the needed views.
2) A small application for windows (needs .NET Framework 2.0) that automates the image loading and merging, blurry edge removing and player colors replacing, all in a row.

The phyton scripts are still in a very unstable state, so it's best I tweak them a little more before making them available. The application engine has been tested enough (I've already processed several objects with it), so I think it's stable enough to make a public release and allow other Simutrans content creators to benefit from it. I must say though, that the GUI hasn't been tested as much as the engine, so few issues might still be found there. If you find any, please report them in this same topic!

Before using this application, please read the help file provided with the application (you may also read it by running the application and clicking the top right "Help" button).
This application works only in a very specific workflow, and if you don't like it or just don't want to work this way, then this application won't be of any help for you.


You can download it from the project page at SourceForge here (remember, needs .NET Framework 2.0!)
« Last Edit: January 23, 2013, 06:21:57 PM by Zeno »

Offline jamespetts

  • Simitrans-Extended project coordinator
  • Devotee
  • *
  • Posts: 15551
  • Total likes: 382
  • Helpful: 172
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Render Post-Processor tool
« Reply #1 on: July 17, 2010, 03:14:03 PM »
This looks very interesting - has there been any progress with the Python scripts? This seems to be very similar to the issue discussed some time ago here.

Edit: I cannot get this to work at all. There is no explanation of how to enable oversampling or produce the masks (can oversampling not be made optional in any event?), and whenever I try to select any files, I get an unhandled exception (especially with the mask files, which I had made, as I have no idea how to get Blender to make mask files, by copying and renaming the original files).
« Last Edit: July 17, 2010, 03:26:26 PM by jamespetts »
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

Offline Zeno

  • ENASSA Designer
  • Devotee
  • *
  • Posts: 1996
  • Total likes: 3
  • Helpful: 30
    • Zeno's Simutrans Creations
  • Languages: ES, EN, CAT
Re: Render Post-Processor tool
« Reply #2 on: August 11, 2010, 03:17:35 PM »
My excuses for oversampling not being properly explained. Oversampling is a technique that blender (and many other software) uses to make images look softer. The results look in a very "realistic" style, but it introduces blurry edges to the image. This tool allows to remove this blurry edges by using images rendered without oversampling (mask images). How to enable/disable oversampling? Just look in the blender rendering tools panel (F10) for a button named "OSA".

Then the tool uses one, four or eight images (depending on option selected) for OSA (images) and for non-OSA (masks). These images and masks are expected to be named "filename_N.png",  "filename_NW.png", "filename_W.png", and so on. Masks follow same rule (I usually name them as "vehicle_mask_N.png", etc). When you select an image, the tool looks for the eight images matching the name pattern, and there is where you are probably having this error.

I may post a sample pack of images to process, or a demo video. I'll see later.

Offline jamespetts

  • Simitrans-Extended project coordinator
  • Devotee
  • *
  • Posts: 15551
  • Total likes: 382
  • Helpful: 172
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Render Post-Processor tool
« Reply #3 on: August 11, 2010, 03:31:56 PM »
Zeno,

thank you for your assistance. Presumably, oversampled images look different to non-oversampled images, such that it would look wrong for a pakset to have some oversampled and some non-oversampled images? Is it possible to use your tool without any oversampling at all, just using ordinary, non-oversampled images with no masks?
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

Offline Zeno

  • ENASSA Designer
  • Devotee
  • *
  • Posts: 1996
  • Total likes: 3
  • Helpful: 30
    • Zeno's Simutrans Creations
  • Languages: ES, EN, CAT
Re: Render Post-Processor tool
« Reply #4 on: August 11, 2010, 03:43:46 PM »
Yes, you may take images and masks both as non-OSA images. You aren't forced to use OSA for images at all. But beware the main purpose of the tool and what it is made for:

1) Take images named _N, _NW, _W, etc., and put them together in 1 file.
2) Replace mask colors with proper special colors.
3) Copy all transparency pixels from mask over the image (thus removing blurry edges).
4) Add text label to your file.

Hope this helps.
PS: About mask colors: these are fixed colors that the tool will replace no matter what user thinks (evil function :P). The tool will take any pixel with colour rgb = {255,0,128} (that is bright magenta) and replace it by rgb = {4D4D4D} (that is dark windows that lit at night). It will also COPY any player color pixel in the mask over the image. The way to get these colors to be present in the mask in a uniform surface is to render them with the "Shadeless" option marked in the Material tool box.

Offline skreyola

Re: Render Post-Processor tool
« Reply #5 on: August 11, 2010, 03:55:33 PM »
I'm a little confused. Blender allows you to turn OSA off, to my knowledge, so why render using OSA at all?
--Skreyola
You can also help translate for your language with SimuTranslator.

Offline Zeno

  • ENASSA Designer
  • Devotee
  • *
  • Posts: 1996
  • Total likes: 3
  • Helpful: 30
    • Zeno's Simutrans Creations
  • Languages: ES, EN, CAT
Re: Render Post-Processor tool
« Reply #6 on: August 11, 2010, 04:01:21 PM »
I'm a little confused. Blender allows you to turn OSA off, to my knowledge, so why render using OSA at all?
Images rendered with OSA are much more beautiful, considering a "realistic" drawing style.

Offline jamespetts

  • Simitrans-Extended project coordinator
  • Devotee
  • *
  • Posts: 15551
  • Total likes: 382
  • Helpful: 172
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Render Post-Processor tool
« Reply #7 on: August 11, 2010, 06:43:05 PM »
So, is this tool of any use to those producing graphics for a pakset that does not use OSA?
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

Offline Zeno

  • ENASSA Designer
  • Devotee
  • *
  • Posts: 1996
  • Total likes: 3
  • Helpful: 30
    • Zeno's Simutrans Creations
  • Languages: ES, EN, CAT
Re: Render Post-Processor tool
« Reply #8 on: August 11, 2010, 06:54:50 PM »
So, is this tool of any use to those producing graphics for a pakset that does not use OSA?

As I said, it may be useful if you want to:
Quote
1) Take images named _N, _NW, _W, etc., and put them together in 1 file.
2) Replace mask colors with proper special colors.
3) Copy all transparency pixels from mask over the image (thus removing blurry edges).
4) Add text label to your file.
-Probably you won't use (3) as long as non-OSA images don't have blurry edges.
-You can use it for sure for (1) and (4), if you consider it's worthy.
-If used properly, (2) might took away most work after blender (the one with gimp or photoshop), only if your pakset uses lots of lights and/or player colors. This is a tricky point though. If this is your case (lots of lights and player colors) I can explain how to avoid most by-hand special color adding to your renders with the help of this tool (which was one of its goals).

I hope I explained myself better this time :)

Offline jamespetts

  • Simitrans-Extended project coordinator
  • Devotee
  • *
  • Posts: 15551
  • Total likes: 382
  • Helpful: 172
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Render Post-Processor tool
« Reply #9 on: August 11, 2010, 07:00:12 PM »
Ideally, what is needed is something that turns the render outputs from Blender (black background, individual files, images not aligned in exactly the right places to work) into an image that Simutrans can use (correct blue background, single file, images precisely aligned) automatically, instead of having manually to select, copy, paste, align and then remove the alignment markers from each image. Can your tool do this without adding so many extra OSA-related steps that it is actually no less work than doing it manually without OSA?
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

Offline Zeno

  • ENASSA Designer
  • Devotee
  • *
  • Posts: 1996
  • Total likes: 3
  • Helpful: 30
    • Zeno's Simutrans Creations
  • Languages: ES, EN, CAT
Re: Render Post-Processor tool
« Reply #10 on: August 11, 2010, 07:13:00 PM »
Oh my... Only if you asked for that before... :D
I Let's start with it!

You can set the correct background to your blender render outputs inside blender itself. Into the world panel (press F5 until you see a panel with the tabs "preview", "world", ...), pick the upper left color selector (just below "WO:World") and write in the "Hex" textbox the correct background (E7FFFF). This will work for you only if you select "SKY" option in the render tab (render buttons, the option on the bottom left corner of render tab).

Once your background is the correct one, alignment becomes much easier. It's very difficult to make alignment automatic, but Shades tool makes our task muuuuuch easier. It allows to load a background image that you can use as a template, and with a single mouse click you can pick your vehicle and move it to the correct position. This is done without layers, copying or selecting.

If you never used shades, I encourage you to try it right now! For me it's a must for simutrans content painters!  8)

Offline jamespetts

  • Simitrans-Extended project coordinator
  • Devotee
  • *
  • Posts: 15551
  • Total likes: 382
  • Helpful: 172
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Render Post-Processor tool
« Reply #11 on: August 11, 2010, 07:34:42 PM »
Ahh, this is very interesting - thank you! Where can I find Shades? Also - any progress on the Blender scripts?
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

Offline Zeno

  • ENASSA Designer
  • Devotee
  • *
  • Posts: 1996
  • Total likes: 3
  • Helpful: 30
    • Zeno's Simutrans Creations
  • Languages: ES, EN, CAT
Re: Render Post-Processor tool
« Reply #12 on: August 11, 2010, 08:00:35 PM »
You can find Shadeshere: http://forum.simutrans.com/index.php?topic=5389.0

Here are my blender scripts for rendering different views for simutrans.
http://files.simutrans.us/files/get/MXV8fq-NHR/blender-scripts.7z

The scripts move the camera and the sun of the scene to each of the four/eight needed positions, and then render the scene and saves to disk the image with the proper view suffix. The scripts can only be used if:
a) The scene has a single light source of type "sun" named "sol".
b) The scene has a single camera named "cam".

Cam and sun distance to the object is fixed, but you can modify all that in the script to add more light sources or other objects. As long as I didn't find any way to rotate objects properly, I hardcoded in the script the position and angle for each object.
« Last Edit: August 11, 2010, 08:10:59 PM by Zeno »

Offline skreyola

Re: Render Post-Processor tool
« Reply #13 on: August 11, 2010, 08:06:20 PM »
Alignment shouldn't be a problem. Once you find the right camera positions, you should be able to leave them alone and render multiple objects with the object in the correct position already. Is there some reason I can't think of why alignment should be a problem that has to be solved more than once for each building size? Seems to me there should be one and only one correct camera placement for each rendered tile image.
Once found, that position should be included in the template blend file (as a camera object locked in place).
--Skreyola
You can also help translate for your language with SimuTranslator.

Offline Zeno

  • ENASSA Designer
  • Devotee
  • *
  • Posts: 1996
  • Total likes: 3
  • Helpful: 30
    • Zeno's Simutrans Creations
  • Languages: ES, EN, CAT
Re: Render Post-Processor tool
« Reply #14 on: August 11, 2010, 08:10:43 PM »
That may work with buildings. But think of a vehicle: depending on type of vehicle and vehicle length it must be aligned to the tile heading each direction, not to the camera.

Offline skreyola

Re: Render Post-Processor tool
« Reply #15 on: August 13, 2010, 12:11:44 AM »
That may work with buildings. But think of a vehicle: depending on type of vehicle and vehicle length it must be aligned to the tile heading each direction, not to the camera.
You can have multiple cameras in Blender, so you just position each camera position once (and position the model on the correct side of the center so it'll be on the correct portion of the road)... Oh, I see what you're saying. But that still (seems like it) should be fairly simple to solve, with a little bit of experimentation to produce a table of vehicle center coordinates.
Tip: Have your vehicle model's location center at ground level.
--Skreyola
You can also help translate for your language with SimuTranslator.

Offline Zeno

  • ENASSA Designer
  • Devotee
  • *
  • Posts: 1996
  • Total likes: 3
  • Helpful: 30
    • Zeno's Simutrans Creations
  • Languages: ES, EN, CAT
Re: Render Post-Processor tool
« Reply #16 on: August 13, 2010, 07:33:53 AM »
Of course it can be done, but sincerely, I feel far more easy aligning the render output with Shades (which is really quick) that implementing multiple cameras in Blender (I prefer a single one) and aligning the object to the tile. But anyway, that's a matter of "feeling"; some will be more comfortable working the first way, some will prefer the second way :)

Offline skreyola

Re: Render Post-Processor tool
« Reply #17 on: August 13, 2010, 05:56:25 PM »
Zeno: I can totally respect that.
--Skreyola
You can also help translate for your language with SimuTranslator.

Offline jamespetts

  • Simitrans-Extended project coordinator
  • Devotee
  • *
  • Posts: 15551
  • Total likes: 382
  • Helpful: 172
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Render Post-Processor tool
« Reply #18 on: April 09, 2012, 11:43:34 PM »
For some odd reason, I am having difficulties with this all of a sudden. When I try to load images, I get the following error message:

Code: [Select]
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.ArgumentException: Parameter is not valid.
   at System.Drawing.Bitmap..ctor(String filename)
   at ImageMasker.Form1.CreateDestinationBitmap(Int32 cellsize)
   at ImageMasker.Form1.DrawImagesInPictureBox(String[] images, String[] masks)
   at ImageMasker.Form1.LoadButton_Click(Object sender, EventArgs e)
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

When I click "continue", no loaded images appear. I had it working before without difficulty, and cannot understand what has changed.
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

Offline Zeno

  • ENASSA Designer
  • Devotee
  • *
  • Posts: 1996
  • Total likes: 3
  • Helpful: 30
    • Zeno's Simutrans Creations
  • Languages: ES, EN, CAT
Re: Render Post-Processor tool
« Reply #19 on: April 10, 2012, 07:58:06 AM »
Uhm, looks strange. Make sure all images are created with proper names (remember of view suffix _W, _WE, and so on...), and the proper number of views is selected. Can you give a look at that and let me know if still doesn't work?

Offline jamespetts

  • Simitrans-Extended project coordinator
  • Devotee
  • *
  • Posts: 15551
  • Total likes: 382
  • Helpful: 172
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Render Post-Processor tool
« Reply #20 on: April 10, 2012, 09:39:56 AM »
I think that the problem was that I was using version 1.2, rather than the later version 1.5, which, confusingly, is called "image renderer". Perhaps the title of this thread and the link could be updated to the latest version...?
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

Offline Zeno

  • ENASSA Designer
  • Devotee
  • *
  • Posts: 1996
  • Total likes: 3
  • Helpful: 30
    • Zeno's Simutrans Creations
  • Languages: ES, EN, CAT
Re: Render Post-Processor tool
« Reply #21 on: April 10, 2012, 10:01:50 AM »
Sure I will, when I'm back at home. Btw, I don't remember this tool having other name than Render Post-Processor Tool... you say it was called "image renderer"? Amazing what my hands are able to do when my mind is away on other things! ;-)

Offline jamespetts

  • Simitrans-Extended project coordinator
  • Devotee
  • *
  • Posts: 15551
  • Total likes: 382
  • Helpful: 172
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Render Post-Processor tool
« Reply #22 on: April 10, 2012, 10:24:00 AM »
Hmm - on checking again, the shortcut appears to be called "Image Masker", but the programme itself is still called "Render Post-Processor". Very odd.
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

Offline Zeno

  • ENASSA Designer
  • Devotee
  • *
  • Posts: 1996
  • Total likes: 3
  • Helpful: 30
    • Zeno's Simutrans Creations
  • Languages: ES, EN, CAT
Re: Render Post-Processor tool
« Reply #23 on: April 10, 2012, 11:16:24 AM »
Oh that's right. Image Masker is its "short" name. Funny thing giving two names for same program, sorry for being odd.

Then, everything works for you with version 1.5?

Offline jamespetts

  • Simitrans-Extended project coordinator
  • Devotee
  • *
  • Posts: 15551
  • Total likes: 382
  • Helpful: 172
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Render Post-Processor tool
« Reply #24 on: December 26, 2012, 01:40:26 AM »
Hmm, looking over this thread again for reference, I note that I did not answer your earlier question: apologies. Yes, indeed, everything seems to be working now in version 1.5 aside from the name issue.
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

Offline TygerFish

Re: Render Post-Processor tool
« Reply #25 on: January 01, 2013, 03:38:46 AM »
The download link appears broken... is the source code available?

Offline Zeno

  • ENASSA Designer
  • Devotee
  • *
  • Posts: 1996
  • Total likes: 3
  • Helpful: 30
    • Zeno's Simutrans Creations
  • Languages: ES, EN, CAT
Re: Render Post-Processor tool
« Reply #26 on: January 01, 2013, 05:21:14 PM »
Here you are a new link, no sources though: http://simutrans-germany.com/files/upload/ImageMasker.15.Setup.7z

Offline jamespetts

  • Simitrans-Extended project coordinator
  • Devotee
  • *
  • Posts: 15551
  • Total likes: 382
  • Helpful: 172
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Render Post-Processor tool
« Reply #27 on: January 01, 2013, 05:26:15 PM »
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

Offline Zeno

  • ENASSA Designer
  • Devotee
  • *
  • Posts: 1996
  • Total likes: 3
  • Helpful: 30
    • Zeno's Simutrans Creations
  • Languages: ES, EN, CAT
Re: Render Post-Processor tool
« Reply #28 on: January 21, 2013, 02:14:08 PM »
For your interest, I have been asked by several people about the program, and it seems that there are a lot of users (I never expected more than 2 users, so more than that is already "a lot"). Soooo, this tool has become open source and the project is at sourceforge: http://sourceforge.net/projects/simutransrpp/

If you have any additions for the program, ideas, suggestions or just want a new feat, feel free to ask, post or send whatever you want to be part of the program.
I hope that I'm capable of attending the few question/inqueries that there might be and work on them. Thanks.

Offline jamespetts

  • Simitrans-Extended project coordinator
  • Devotee
  • *
  • Posts: 15551
  • Total likes: 382
  • Helpful: 172
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Render Post-Processor tool
« Reply #29 on: January 21, 2013, 02:23:52 PM »
Splendid! This tool really is very useful - already, many hundreds of vehicle graphics for Pak128.Britain have been made using it.
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

Offline Zeno

  • ENASSA Designer
  • Devotee
  • *
  • Posts: 1996
  • Total likes: 3
  • Helpful: 30
    • Zeno's Simutrans Creations
  • Languages: ES, EN, CAT
Re: Render Post-Processor tool
« Reply #30 on: January 21, 2013, 03:30:33 PM »
I'm glad that you find it useful and take so much benefit from it.

By the way, there's available for download the last update 1.6, which adds a button (big 'M' button) that opens a tool for merging multiple composed images in a single image; that feature was thought in order to put together all different freight images of a single vehicle (e.g. coal + iron + waste + ... + empty).

Offline The Hood

Re: Render Post-Processor tool
« Reply #31 on: January 21, 2013, 05:25:33 PM »
Option to recolour black backgrounds with #e7ffff would be great and save opening GIMP for the last step each time. Seriously, this is a great tool for saving time.

PS did you get any further with the blender script and blender 2.6?

Offline Zeno

  • ENASSA Designer
  • Devotee
  • *
  • Posts: 1996
  • Total likes: 3
  • Helpful: 30
    • Zeno's Simutrans Creations
  • Languages: ES, EN, CAT
Re: Render Post-Processor tool
« Reply #32 on: January 21, 2013, 06:38:29 PM »
No progress done to the script. Maybe tonight I have some time to review it.
About the change you ask for, the background stuff, I have thought of:
- Allow enable/disable the auto-background-fixer feature
- When enabled, the program will take pixel in coordinate (0,0) as used background for every single image; then will replace that background with #e7ffff automatically

I have a question though: I guess the replacing algorithm can't be as simple as replace every "black" pixel (taken from 0,0) with "transparent" pixel, because in that case you wouldn't be able to use black pixels in the objects you're drawing. Should I create an alternative way, such as replace-until-non-black-pixel-found, executed both from left & right sides?

Let me know your thoughts, thanks.

Offline The Hood

Re: Render Post-Processor tool
« Reply #33 on: January 21, 2013, 07:01:13 PM »
Maybe its more work than I thought. I just use the fill tool in GIMP, so that's what I was after. In other words, #000000 not connected to the background would not get converted. But then sometimes you get more than one area of background #000000 separated by image, especially in buildings...

Offline Zeno

  • ENASSA Designer
  • Devotee
  • *
  • Posts: 1996
  • Total likes: 3
  • Helpful: 30
    • Zeno's Simutrans Creations
  • Languages: ES, EN, CAT
Re: Render Post-Processor tool
« Reply #34 on: January 21, 2013, 07:09:32 PM »
So I'll look for a "connected" algorithm and then I'll apply from all 4 corners sequentially, if they're not been already replaced.
Don't have a clue on such algorithms, if anybody has any idea I'll be waiting for it :P

Offline TygerFish

Re: Render Post-Processor tool
« Reply #35 on: January 21, 2013, 07:11:58 PM »
Perhaps this would be useful?
http://code.google.com/p/openpdn/source/browse/src/tools/PaintBucketTool.cs

So I'll look for a "connected" algorithm and then I'll apply from all 4 corners sequentially, if they're not been already replaced.
Don't have a clue on such algorithms, if anybody has any idea I'll be waiting for it :P

Offline Combuijs

  • Web Team
  • Devotee
  • *
  • Posts: 1386
  • Total likes: 22
  • Helpful: 53
  • Maintainer of maps.simutrans.com
    • Combuijs
  • Languages: EN, NL
Re: Render Post-Processor tool
« Reply #36 on: January 21, 2013, 07:17:32 PM »
Can't you start at the top left of the picture? If that is black, then replace it and go further down and right (e.g. coordinates (0, top-1) and (1, top)). If not then stop for that pixel. Kind of recursive algorithm.
Bob Marley: No woman, no cry

Programmer: No user, no bugs



Offline Zeno

  • ENASSA Designer
  • Devotee
  • *
  • Posts: 1996
  • Total likes: 3
  • Helpful: 30
    • Zeno's Simutrans Creations
  • Languages: ES, EN, CAT
Re: Render Post-Processor tool
« Reply #37 on: January 21, 2013, 07:36:46 PM »
@tygerfish: thanks for that, it's what I was looking for, but I think I found one too which is pretty short and seems to work. I'll keep it anyway, and check it out, compare, and implement the one that looks better.

@combuijs: yep, that's the base for a floodfill algorithm. I'm not the most skilled programmer around, so I think I'll ask for some code to some "experts" in the net (googling is fast, got a couple of algorithms in few searches).
...
Well, finally found some code out there in the net that I think will work as a floodfill algorithm. I can execute it from all four corners and looks like working. Maybe I can upload a "beta" before going to bed.
Thank you very much guys for your answers :)



Done, you can download the binary here to test it: http://zeno.simutrans.com/Files/SimutransRPP_161.7z
About that, you better not paint vehicle's tyres in black, otherwise they'll go away without them! :D
Instructions are: press once the "BG" button to leave it checked; then load your images; they will have black background removed (at least, that's the idea).
« Last Edit: January 21, 2013, 09:19:54 PM by Zeno »

Offline jamespetts

  • Simitrans-Extended project coordinator
  • Devotee
  • *
  • Posts: 15551
  • Total likes: 382
  • Helpful: 172
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Render Post-Processor tool
« Reply #38 on: January 21, 2013, 11:14:08 PM »
PS did you get any further with the blender script and blender 2.6?

I have my version working with 2.6, which is a modification of my original modification of your modification of Zeno's original script...
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

Offline Zeno

  • ENASSA Designer
  • Devotee
  • *
  • Posts: 1996
  • Total likes: 3
  • Helpful: 30
    • Zeno's Simutrans Creations
  • Languages: ES, EN, CAT
Re: Render Post-Processor tool
« Reply #39 on: January 22, 2013, 02:04:54 PM »
I have my version working with 2.6, which is a modification of my original modification of your modification of Zeno's original script...
Does it have any extra feature or different thing, or just upgraded for executing in 2.6 without errors?

Offline jamespetts

  • Simitrans-Extended project coordinator
  • Devotee
  • *
  • Posts: 15551
  • Total likes: 382
  • Helpful: 172
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Render Post-Processor tool
« Reply #40 on: January 22, 2013, 10:58:11 PM »
I'm not sure which version that you are comparing it against: I think that I only changed the version numbering from my original modification of The Hood's modification of your original script, but I made some substantial modifications to The Hood's version in order to get vehicles to align automatically.

For reference, here is the full script for the latest version of Blender:

Code: [Select]
bl_info = {
    "name": "Render Simutrans Views Pak128.Britain-refresh",
    "author": "Zeno, the Hood and James E. Petts",
    "version": (1, 3),
    "blender": (2, 6, 1),
    "api": 35853,
    "location": "Render >  Render8viewsBrit",
    "description": "Renders direction views for Simutrans",
    "warning": "",
    "wiki_url": "",
    "tracker_url": "",
    "category": "Render"}

"""
This script has two functions:

1)  Render 4 or 8 fictional views for simutrans game
    What it does is placing the camera and sun in each proper position to make
    each of the requested renders, that means the camera and sun (light) move
    around the objects in the scene, and take the proper renders.
    Ther renders are saved to disk with direction suffixes, such as _W (for west
    view), _NE (for north-east view), and so on.
2)  Enable mask mode for simutrans post processing
    This enables mask mode for the used materials in the scene. That means, the
    script searchs for every material which name starts with "sp_" (special) and
    when found applies the mask to it. The masks changes are:
    a)  Replaces sp_Dark_Wi*, sp_Cold_Wh* and sp_Red_Lig* with the mask color
        (1,0,0.5 magenta), and sets shadeless on for them.
    b)  Sets shadeless on for sp_* materials.

RECOMMENDED:
    * I recommend NOT SAVING the model after using the "Make Masks" function.
    It's much more easy to save your blend file before, then when you need to
    render the masks use the "Make Masks" function, do the renders, and then
    switch back to your blend file back.
    * Be careful when naming your materials. Everything that starts with "sp_"
    will be considered a Simutrans special color!!!!

Be sure to take a look at our Simutrans International Forum at:
http://forum.simutrans.com

You're also welcome to our IRC Chat Room, at #simutrans channel in quakenet network.


History:

v1.0
----
Basic 4/8 view rendering
Masking function for materials named sp_*
Compatibility with Blender 2.56 beta

v1.1
----
Compatibility with Blender 2.57
Several changes to the Masking funcitonality. Read description above.

v1.2
----
Correct alignments for Pak128.Britain without copying and pasting to templates.

v1.3
----
Correct direction names for Pak128.Britain (were 90 degrees off with the Pak128 version)

"""


import bpy
from math import radians
from bpy.props import *

class SCENE_PT_simurender(bpy.types.Panel):
    bl_space_type = "PROPERTIES"
    bl_region_type = "WINDOW"
    bl_context = "render"
    bl_label = "Rendering views for Simutrans"
   
    def draw_header(self, context):
        layout = self.layout
       
    def draw(self, context):
        layout = self.layout
        scene = context.scene
       
        row = layout.column()
        row.prop(scene, "image_name", text="Image name")
       
        row = layout.column()
        row.prop(scene, "op_list", text="Views to render")
           
        row = layout.column()
        row.operator("scene.simurender_render_views", text="Render Views")
        row = layout.column()
        row.operator("scene.simurender_make_mask", text="Make Masks")
       
class SCENE_OT_simurender_make_mask(bpy.types.Operator):
    bl_idname = "scene.simurender_make_mask"
    bl_label = "Make Mask"
    bl_options = {'REGISTER'}
    bl_description = "Swap all special colors to mask colors"
   
    @classmethod
    def poll(cls, context):
        return context.active_object != None
   
    def execute(self, context):
        for mat in bpy.data.materials:
            if mat.name[0:3] == "sp_":
                print("Making mask of " + mat.name)
                # If is window color, replace with magenta mask
                print(mat.name[3:7])
                if mat.name[3:10] == "Dark_Wi" or mat.name[3:10] == "Cold_Wh" or mat.name[3:10] == "Red_Lig":
                    mat.diffuse_color = [1.0, 0.0, 0.5]

                # Enable shadeless for primary/secondary colors
                mat.use_shadeless = True
             
        return("FINISHED")

class SCENE_OT_simurender_render_views(bpy.types.Operator):
    bl_idname = "scene.simurender_render_views"
    bl_label = "Render Simutrans Views Pak128.Britain"
    bl_options = {'REGISTER'}
    bl_description = "Render direction views for Simutrans"

    @classmethod
    def poll(cls, context):
        return context.active_object != None
   
    def execute(self, context):
        if "Camera" in bpy.data.objects:
            cam = bpy.data.objects["Camera"]
        else:
            cam = ""
           
        if "Sphere" in bpy.data.objects:
            sun = bpy.data.objects["Sphere"]
        else:
            sun = ""
       
        if cam=="":
            self.report('WARNING', "Camera not found!")
        else:
            if sun=="":
                self.report('WARNING', "Sun not found!")
            else:
                scn = bpy.context.scene
                cam.rotation_mode = "XYZ"
                name = scn.image_name
               
                # Generate the South Image
                cam.rotation_euler = [radians(60), 0, radians(45)]
                cam.location = [6.6, -7.9, 11.6]
                sun.rotation_euler = [radians(90),0, radians(90)]
                #sun.location = [-70.711, -70.711, 60]
                scn.render.filepath = "//" + name + "_S.png"
                print("Rendering South Image")
                bpy.ops.render.render(animation=False, write_still=True, layer="", scene="")
               
                if scn.op_list == "1":
                    # Generate the South-West Image
                    cam.rotation_euler = [radians(60), 0, radians(90)]
                    cam.location = [7.5, 0.6, 10]
                    sun.rotation_euler = [radians(90), 0, radians(135)]
                    #sun.location = [0, -100, 60]
                    scn.render.filepath = "//" + name + "_SW.png"
                    print("Rendering South-West Image")
                    bpy.ops.render.render(animation=False, write_still=True, layer="", scene="")
                   
                # Generate the West Image
                cam.rotation_euler = [radians(60), 0.0, radians(135)]
                cam.location = [6.72, 8.2, 11.6]
                sun.rotation_euler =[radians(90),0.0,radians(225)]
                #sun.location = [70.711, -70.711, 60]
                scn.render.filepath = "//" + name + "_W.png"
                print("Rendering West Image")
                bpy.ops.render.render(animation=False, write_still=True, layer="", scene="")
               
                if scn.op_list == "1":
                    # Generate the North-West Image
                    cam.rotation_euler = [radians(60), 0.0, radians(180)]
                    cam.location = [0, 14.14, 11.6]
                    sun.rotation_euler = [radians(90),0.0,radians(225)]
                    #sun.location = [100, 0, 60]
                    scn.render.filepath = "//" + name + "_NW.png"
                    print("Rendering North-West Image")
                    bpy.ops.render.render(animation=False, write_still=True, layer="", scene="")
                   
                # Generate the North Image
                cam.rotation_euler = [radians(60), 0.0, radians(225)]
                cam.location = [-7, 8.5, 11.6]
                sun.rotation_euler = [radians(90),0.0,radians(270)]
                #sun.location = [70.711, 70.711, 60]
                scn.render.filepath = "//" + name + "_N.png"
                print("Rendering North Image")
                bpy.ops.render.render(animation=False, write_still=True, layer="", scene="")
               
                if scn.op_list == "1":
                    # Generate the North-East Image
                    cam.rotation_euler = [radians(60), 0.0, radians(270)]
                    cam.location = [-10.3, -0.75, 11.6]
                    sun.rotation_euler = [radians(90),0.0, radians(315)]
                    #sun.location = [0, 100, 60]
                    scn.render.filepath = "//" + name + "_NE.png"
                    print("Rendering North-East Image")
                    bpy.ops.render.render(animation=False, write_still=True, layer="", scene="")
                   
                # Generate the East Image
                cam.rotation_euler = [radians(60), 0.0, radians(315)]
                cam.location = [-32.6, -33.6, 32.5]
                sun.rotation_euler = [radians(90),0.0,radians(45)]
                #sun.location = [-70.711, 70.711, 60]
                scn.render.filepath = "//" + name + "_E.png"
                print("Rendering East Image")
                bpy.ops.render.render(animation=False, write_still=True, layer="", scene="")
               
                if scn.op_list == "1":
                    # Generate the South-East Image (formerly SW)
                    cam.rotation_euler = [radians(60), 0.0, radians(360)]
                    cam.location = [0, -11, 11.6]
                    sun.rotation_euler = [radians(90),0.0,radians(45)]
                    #sun.location = [-100, 0, 60]
                    scn.render.filepath = "//" + name + "_SE.png"
                    print("Rendering South-East Image")
                    bpy.ops.render.render(animation=False, write_still=True, layer="", scene="")

        return{'FINISHED'}
                   

def register():
    bpy.utils.register_module(__name__)
   
    bpy.types.Scene.image_name = StringProperty(
                                name='Image name',
                                description='Base file name for rendered images.')
    opts = []
    opts.append((str(1), "Render 8 Views", str(1)))
    opts.append((str(0), "Render 4 Views", str(0)))
    bpy.types.Scene.op_list = EnumProperty(
        items=opts,
        name="Number of views",
        default='1',
        description='Number of direction views to be rotated and rendered')
   
def unregister():
    bpy.utils.unregister_module(__name__)
   
    del bpy.types.Scene.image_name
   
if __name__ == "__main__":
    register()
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

Offline IgorEliezer

  • Devotee
  • Administrator
  • *
  • Posts: 3941
  • Total likes: 134
  • Helpful: 70
  • Lost In Stupid Parenthesis
    • Igor Eliezer Architect and Urban Planner/Arquiteto e Urbanista
  • Languages: PT, EN, AutoLISP, Python
Re: Render Post-Processor tool
« Reply #41 on: January 23, 2013, 03:25:32 AM »
Hey, Zeno. You might want to update the 1st post, the download link is broken and perhaps the description needs a spruce-up.

BTW, good job dude. :D

Offline Zeno

  • ENASSA Designer
  • Devotee
  • *
  • Posts: 1996
  • Total likes: 3
  • Helpful: 30
    • Zeno's Simutrans Creations
  • Languages: ES, EN, CAT
Re: Render Post-Processor tool
« Reply #42 on: January 23, 2013, 06:25:50 PM »
Link at first post updated, thanks Igor for reporting.

About the script, thanks very much for sharing your modifications james. I'll take a look to the script, I'll try to fix errors if any and then upload the newest version to the project page.

Offline jamespetts

  • Simitrans-Extended project coordinator
  • Devotee
  • *
  • Posts: 15551
  • Total likes: 382
  • Helpful: 172
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Render Post-Processor tool
« Reply #43 on: January 23, 2013, 11:41:15 PM »
Note that my script has modified alignments for exporting Pak128.Britain vehicles (other than road vehicles, which have a different alignment), so it might not work for Pak128, as the alignments are different to the original script. It is designed to work so that no further alignment work is needed after rendering.
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

Offline jamespetts

  • Simitrans-Extended project coordinator
  • Devotee
  • *
  • Posts: 15551
  • Total likes: 382
  • Helpful: 172
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Render Post-Processor tool
« Reply #44 on: May 28, 2016, 04:32:17 PM »
Has anyone ever managed to get this working under Wine? Attempting this in Ubuntu 16.10, I get the error, "there is no windows program configured to open this type of file".
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.