So I’ve only made a single structural change here, which is adding the “undo on” wrapping. This makes it so that the entire macroscript takes up only a single block in 3d Studio Max’s undo history. This way any changes made within this codeblock can be undone with a single command. Neat huh?<\/p>\n
The remaining stuff is all comments. I usually start my scripts off by hammering out comments that say what needs to get done. I recommend that you consider doing the same; it helps you stay organized and think things through. In this case, you see we need to create a white material and apply it to all the objects in the scene. Then we need to delete all the lights, which is easier than turning them off and back on again. We also have to create the shadowing skylight so that we get the smooth shading effect. After that, we can store the current render settings, and switch over to scanline. Finally, we render and then revert back to the old Renderer.<\/p>\n
Step 4: Fill code.<\/h1>\nmacroScript Clay_Renderer\r\ncategory:\"Custom\"\r\ntooltip:\"Take a clay render\"\r\nbuttontext:\"Clay Render\"\r\n(\r\n\tundo on\r\n\t(\r\n\t\t-- Create a white material and assign it to everything.\r\n\t\tWhiteMat = standard diffuse:(color 220 220 220) twosided:true\r\n\t\tfor obj in objects do obj.material = WhiteMat\r\n\r\n\t\t-- Delete all the lights and create a skylight instead.\r\n\t\tfor lux in lights do delete lux\r\n\t\tThisSkylight = skylight castShadows:true rays_per_sample:12\r\n\r\n\t\t-- Store the current render settings, and set to scanline.\r\n\r\n\t\t-- Render\r\n\r\n\t\t-- Revert to the old renderer\r\n\t)\r\n\t-- Undo everything we did, leaving only the render.\r\n)<\/pre>\nSo we’ve added the information regarding the material. In this case we’re creating a material called “WhiteMat” which is a standard material with a diffuse color of 220 grey and it’s two-sided. Why? Because if you think about it, a clay render doesn’t show off all the geometry if it can’t render backfacing polygons. Worse yet, even though backfacing polygons wouldn’t show up in the render, they’ll still affect the lighting solution which would create some unpleasant artifacts. It’s best to just set this parameter to true.<\/p>\n
Next I’ve added in the code for deleting the lights and creating the skylight. What we’re basically saying in the first line is “For each light ‘lux’, delete it”. This can always be undone at the end of the script. In the next line, we create a new skylight called “ThisSkylight”, which is casting shadows at a rate of 12 rays per sample.<\/p>\n
macroScript Clay_Renderer\r\ncategory:\"Custom\"\r\ntooltip:\"Take a clay render\"\r\nbuttontext:\"Clay Render\"\r\n(\r\n\tundo on\r\n\t(\r\n\t\t-- Create a white material and assign it to everything.\r\n\t\tWhiteMat = standard diffuse:(color 220 220 220) twosided:true\r\n\t\tfor obj in objects do obj.material = WhiteMat\r\n\r\n\t\t-- Delete all the lights and create a skylight instead.\r\n\t\tfor lux in lights do delete lux\r\n\t\tThisSkylight = skylight castShadows:true rays_per_sample:12\r\n\r\n\t\t-- Store the current render settings, and set to scanline.\r\n\t\tExistingRenderSettings = renderers.production\r\n\t\trenderers.production = default_scanline_renderer()\r\n\r\n\t\t-- Render\r\n\t\trender()\r\n\r\n\t\t-- Revert to the old renderer\r\n\t\trenderers.production = ExistingRenderSettings\r\n\t)\r\n\t-- Undo everything we did, leaving only the render.\r\n\tmax undo\r\n)<\/pre>\nHere we see the storage and changing of the renderer. We take this extra step because if you’re working on a scene in mental ray, but want a clay render, you shouldn’t have to go through the trouble of a) writing a totally different clay render script or b) storing your settings manually. We store the production renderer to a variable, and then set it to a fresh instance of the default scanline renderer. A fresh instance has all the default values, so we know there won’t be any kind of crazy settings getting in the way of the clay render.<\/p>\n
Finally, we can take the render. Once that is complete, the script resets the production renderer back to what it should be, and undoes any weird changes (like deleted lights) that the script executed. We’re back to where we started except now we have an awesome clay render in the render window!<\/p>\n
The best part of this is that now we have a button that we can place anywhere in the 3dsMax user interface that will create a clay render on command!<\/p>\n
Hit the hotkey Ctrl+E to run the script so that it will appear as a macroscript. You can save the file to your <3dsMax Root>\/UI\/Macroscripts directory, and it’ll be loaded automatically every time you start 3d Studio Max. To add your new “Clay Render” button to the main toolbar, just click on the menu “Customize > Customize User Interface”. Go to the “Toolbars” tab, and from the category pulldown select “Custom”, and you’ll see your clay render button. Just drag and drop it from the “Action” window to the main toolbar, and the button will appear.<\/p>\n
<\/a><\/p>\nAdding the button to your tool bar.<\/p>\n<\/div>\n
And there you have it! Now you can get a clean clay render no matter what your material, lighting, or rendering setup is!<\/p>\n
Until next time, happy rendering!<\/p>\n","protected":false},"excerpt":{"rendered":"
I was thinking hard about the 3d Studio Max clay rendering tutorial I wrote a few days ago, and was pondering about what an extension might be. Then it struck me! “Gosh, wouldn’t it be cool to have a button in the 3dsMax interface that you could click, and have it automatically turn out a […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,111,20,16],"tags":[2567,22,2565,88],"_links":{"self":[{"href":"http:\/\/www.mrbluesummers.com\/wp-json\/wp\/v2\/posts\/269"}],"collection":[{"href":"http:\/\/www.mrbluesummers.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.mrbluesummers.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.mrbluesummers.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.mrbluesummers.com\/wp-json\/wp\/v2\/comments?post=269"}],"version-history":[{"count":0,"href":"http:\/\/www.mrbluesummers.com\/wp-json\/wp\/v2\/posts\/269\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.mrbluesummers.com\/wp-json\/wp\/v2\/media?parent=269"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.mrbluesummers.com\/wp-json\/wp\/v2\/categories?post=269"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.mrbluesummers.com\/wp-json\/wp\/v2\/tags?post=269"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}