I'm trying to create a set of images for our web team, and am a bit lost on how to make the following happen:
1. Turn on only a specific group of parts (in this case I have "frame" and "body" as the two groups of parts)
2. Apply a material to that group of parts (I've got 114 different materials to apply...57 paints in 2 finishes)
3. Put that image in a filepath depending on the finish (gloss or matte) and the part with the file name being the material name (candy_apple, diamond, etc.). For example, a Candy Apple gloss frame would go in ...\parts\gloss\frame under the name "candy-apple"
4. Repeat for all the parts/colors/finishes
I read through most of the threads on this board and got some ideas, especially from this thread: https://www.keyshot.com/forum/index.php?topic=11656.0, especially "ryanfenik's" post with the cube example, and I can kind of get it to work. My problem arises in not knowing how to make it call a material from a certain folder if I have the same named material in multiple folders ("candy_apple" in gloss folder and in matte folder, different material though).
I'm a relative novice to coding, but do have enough background in it between simple websites and some stuff in college to understand the gist of it.
My first advice would be to make sure you have unique names for all materials. This is a good practice in general.
So maybe you can name the shiny and matte finishes 'candy_apple_shiny' and 'candy_apple_matte' respectively.
And maybe it's even better to have a unique identifier at the beginning, so that the result is like 'Wookiee_candy_apple_shiny'. 'Wookiee' could be the prduct name... :)
It would be easier if we could work from there.
Dries
Here is my attempt at doing this...
See attached for a sample scene, material package and script.
If you wish to test this sample, then please import the material package in KeyShot first.
So here is how I thought this could work...
The idea is to embed the name of the colorway into the material names. So for a colorway 'Wookiee', the materials are named 'Wookiee_blue_shiny', 'Wookiee_orange_shiny' etc.
You can enter the name of the colorway in the script. The script will find all materials with a name that contains the colorway name.
You can enter the name of the groups/parts that the colorways should be applied to.
So in this case, all the 'Wookiee' materials in the library will be applied to all parts in the scene with name 'Jedi'. (Sorry, I am in a Star Wars mood today... ;D).
You can also specify a suffix.
The image filenames will look something like this: 'Colorways-test_2016-05-22_Wookiee_blue_shiny.png'
I provided a few additional options:
- Select a Lighting Preset from a combobox.
- Set resolution.
- Set quality as amount of maximum samples.
- Add to Queue.
- Process Queue after the script is finished.
- Reload the scene.
Let me know how this works for you.
It is not exactly what you asked for, but this should get you started. :)
Dries
Okay, I changed the script a little...
Now when rendering, only the specified parts will be shown.
You can now render all combinations by running the script twice, for 'frame' and 'body'.
Dries
OK, last change for today...
I added a checkbox to enable/disable hiding of other parts.
Dries
Many thanks Dries!!!
This is awesome! I just started learning about scripting and have a long way to go, but the power of it is always impressive.
Thanks a ton Dries! That worked like a charm. Only thing I don't like is how the files are named, would prefer just the color to be the name since they need to go in their own folders anyway. But I found a quick little tool to rename all the files at once, so that fixed that!
I did run into one little issue. Even though you can type in what resolution you want to render the images at, it still appears to be dependent on the viewport resolution in keyshot. The first time I ran it the images came out at the right resolution according to the details of the file, but the visible portions of the image were definitely not that resolution. Just a weird little thing to watch out for
The render resolution will be dependent on the aspect ratio set in the image tab.
Quote from: maf1909 on May 24, 2016, 11:47:06 AM
...
Only thing I don't like is how the files are named, would prefer just the color to be the name since they need to go in their own folders anyway.
...
Well, you can always change the script so that it only sets the material name as the file name. :)
And then you could also add some conditional statements to put the images in different folders depending on the material name. ;)
Quote from: maf1909 on May 24, 2016, 11:47:06 AM
...
Even though you can type in what resolution you want to render the images at, it still appears to be dependent on the viewport resolution in keyshot. The first time I ran it the images came out at the right resolution according to the details of the file, but the visible portions of the image were definitely not that resolution.
That is weird, as resolutions explicitly set through scripting should always be respected for rendering.
Can you show some examples of what you are seeing?
Quote from: thomasteger on May 24, 2016, 10:28:39 PM
The render resolution will be dependent on the aspect ratio set in the image tab.
This is true for regular offline rendering, but not for rendering through scripting when you explicitly set the height and width of the image.
Like this:
width = 1920
height = 1080
lux.renderImage(width = width, height = height)
Dries
Quote from: DriesV on May 25, 2016, 12:05:16 AM
Well, you can always change the script so that it only sets the material name as the file name. :)
And then you could also add some conditional statements to put the images in different folders depending on the material name. ;)
I tried setting the script to make only the material the file name, and it would go through the process of rendering the image and then not actually put the image anywhere. I assume I did it wrong, but this method works too. Either way, since I had to make the materials a different name (xx_gloss and xx_matte), I have to go through and remove that anyway.
Quote
That is weird, as resolutions explicitly set through scripting should always be respected for rendering.
Can you show some examples of what you are seeing?
Quote from: thomasteger on May 24, 2016, 10:28:39 PM
The render resolution will be dependent on the aspect ratio set in the image tab.
This is true for regular offline rendering, but not for rendering through scripting when you explicitly set the height and width of the image.
Like this:
width = 1920
height = 1080
lux.renderImage(width = width, height = height)
Dries
The "2560x1536.png" file was rendered offline, with the ratio in the image tab set to 1280x768 (half the final output). The "1000x800 to 2560x1536.png" was rendered through the script, with the image tab set to 1000x800, and the resolution in the script set to 2560x1536. Both come out the same resolution according to the details of the file, but if you try to layer them so the first image sits on top of the second image, they're clearly not the same, as you can see in the "layered.png"
Quote from: thomasteger on May 24, 2016, 10:28:39 PM
The render resolution will be dependent on the aspect ratio set in the image tab.
This is true for regular offline rendering, but not for rendering through scripting when you explicitly set the height and width of the image.
Like this:
width = 1920
height = 1080
lux.renderImage(width = width, height = height)
Dries
[/quote]
But you don't want to do this, because the camera may not match. This is why we disabled this in the render tab, so you can only enter a value that is a multiple of the aspect ratio.
And this shows in @maf1909's example. Your aspect ratio in the realtime window is 1.25, while your output resolution has an aspect ratio of 1.6667. Your camera has shifted.
Try that in the realtime window and you will see what happens with the camera.
KeyShot is not like other rendering applications where you can set up a render window of your scene. Maybe that's where the confusion comes in.
As long as the camera hasn't changed and no transformations have been done in the script, the images should always overlap when rendered at the same resolution.
@ maf1909:
Are these parts (black & red) from 2 different scenes?
Are they positioned to be aligned perfectly?
Are the camera settings identical for both scenes?
If those conditions are met, then the renderings should align perfectly, when rendered at the same resolution through the script, regardless of the aspect ratio in realtime.
You can test this with attached simple scenes. The scenes are identical (geometry and camera), except for the aspect ratio. When rendered at the same resolution through the script, they align perfectly.
Of course, as soon as the camera is adjusted in one of the scenes, the images won't match.
Dries
Quote from: DriesV on May 26, 2016, 05:30:05 AM
As long as the camera hasn't changed and no transformations have been done in the script, the images should always overlap when rendered at the same resolution.
@ maf1909:
Are these parts (black & red) from 2 different scenes?
Are they positioned to be aligned perfectly?
Are the camera settings identical for both scenes?
If those conditions are met, then the renderings should align perfectly, when rendered at the same resolution through the script, regardless of the aspect ratio in realtime.
You can test this with attached simple scenes. The scenes are identical (geometry and camera), except for the aspect ratio. When rendered at the same resolution through the script, they align perfectly.
Of course, as soon as the camera is adjusted in one of the scenes, the images won't match.
Dries
The parts are from the same scene, the black is designed to be a foreground layer since it's the fabric and rubber for that particular product.
The camera is locked, the only change I made was the resolution under the "image" tab.
Can you share the scene?
You can use keyshot.wetransfer.com (http://keyshot.wetransfer.com). Send to dries@luxion.com.
Dries
Looking the camera or not makes no difference. Lock the camera, change the resolution including aspect ratio, and notice what's happening.
Interesting scene. The realtime image temporarily compresses/elongates as you change the aspect ratio. This reflects in the rendering through the script, as you specify a different aspect ratio, so that the red parts appear to not fit.
So the script is actully rendering the 'stretched state'. I think this is a bug. I will investigate.
I didn't see this issue in my own testing, but this scene clearly shows it.
Dries
Quote from: DriesV on May 26, 2016, 02:15:03 PM
Interesting scene. The realtime image temporarily compresses/elongates as you change the aspect ratio. This reflects in the rendering through the script, as you specify a different aspect ratio, so that the red parts appear to not fit.
So the script is actully rendering the 'stretched state'. I think this is a bug. I will investigate.
I didn't see this issue in my own testing, but this scene clearly shows it.
Dries
With any luck, I'll be able to use this to put a final product on our website. This product is just a start of what we have in mind!
For now, just make sure you have the correct aspect ratio in realtime. Then the image shouldn't stretch.
I will keep you updated.
Dries
Quote from: DriesV on May 26, 2016, 02:24:10 PM
For now, just make sure you have the correct aspect ratio in realtime. Then the image shouldn't stretch.
I will keep you updated.
Dries
how would this need to be changed to keep labels when it changes materials?
Quote from: maf1909 on May 27, 2016, 07:29:22 AM
Quote from: DriesV on May 26, 2016, 02:24:10 PM
For now, just make sure you have the correct aspect ratio in realtime. Then the image shouldn't stretch.
I will keep you updated.
Dries
how would this need to be changed to keep labels when it changes materials?
This is currently not possible, as you can't access the material properties through scripting. A label is a part of the material.
Material access is planned for a future version of KeyShot.
Can you put the shared label on a separate piece of gometry than the base material? E.g. with an opacity map?
Dries
@ maf1909:
Btw, the issue you saw with stretching of images (due to setting a different aspect ratio through scripting) will be solved in KeyShot 6.2, which is to be released very soon.
There was a bug for setting the resolution when using an orthographic camera (as you did).
Dries
Quote from: DriesV on June 07, 2016, 08:22:25 AM
@ maf1909:
Btw, the issue you saw with stretching of images (due to setting a different aspect ratio through scripting) will be solved in KeyShot 6.2, which is to be released very soon.
There was a bug for setting the resolution when using an orthographic camera (as you did).
Dries
awesome, good to hear!
Is it possible to make this script render to photoshop with layers? It's looking like that's the way I'm going to have to do these images.
Quote from: maf1909 on June 07, 2016, 08:35:48 AM
...
Is it possible to make this script render to photoshop with layers? It's looking like that's the way I'm going to have to do these images.
It is currently not possible to render to PSD with scripting.
You can render all passes and render layers to images though.
Dries
Quote from: DriesV on June 07, 2016, 12:23:20 PM
Quote from: maf1909 on June 07, 2016, 08:35:48 AM
...
Is it possible to make this script render to photoshop with layers? It's looking like that's the way I'm going to have to do these images.
It is currently not possible to render to PSD with scripting.
You can render all passes and render layers to images though.
Dries
will it be possible to render to PSD with scripting in a future update? That would save me a HUGE amount of time considering I have 116 materials to drag over, type in the name, and add to queue.