News:

Simutrans.com Portal
Our Simutrans site. You can find everything about Simutrans from here.

Render Post-Processor tool

Started by Zeno, February 23, 2010, 12:42:34 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Zeno

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!)

jamespetts

#1
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).
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.

Zeno

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.

jamespetts

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.

Zeno

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.

skreyola

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.

Zeno

Quote from: skreyola 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?
Images rendered with OSA are much more beautiful, considering a "realistic" drawing style.

jamespetts

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.

Zeno

Quote from: jamespetts 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?

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 :)

jamespetts

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.

Zeno

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)

jamespetts

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.

Zeno

#12
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 [dot] us (site down, do not visit) ]/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.

skreyola

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.

Zeno

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.

skreyola

Quote from: Zeno 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.
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.

Zeno

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 :)

skreyola

Zeno: I can totally respect that.
--Skreyola
You can also help translate for your language with SimuTranslator.

jamespetts

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:


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.

Zeno

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?

jamespetts

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.

Zeno

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! ;-)

jamespetts

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.

Zeno

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?

jamespetts

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.

TygerFish

The download link appears broken... is the source code available?

Zeno


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.

Zeno

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.

jamespetts

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.

Zeno

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).

The Hood

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?

Zeno

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.

The Hood

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...

Zeno

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