pclord
کاربر متخصص
Quick Clay Render
Submitted by Liam.Davis on Fri, 2009-11-13 15:12.
Version: 1.1
Date Updated: 11/13/2009
One click will render your scene as a 'clay' style image, leaving the scene, materials and all your render settings exactly as they are. Code has been updated to create the floor plane at the lowest vertex in the scene, and to make it easier to customise (different renderers, alter the material colour, environment background and light type).
Additional Info:
When modelling, I often find myself using quick 'clay' renders to get an idea of what my models look like when lit, as it really brings out the edging and detail. But this involved saving my scene, creating a ground plane, positioning it, assigning a clay material to everything, creating the light, rendering it, then reloading the scene because I'd lost all my materials. So I figured I'd give creating a script a go.
It's not perfect, as it's the first proper script I've made, but it does the job. It will find the lowest vertex in the scene, create the ground plane beneath that, sort out the lights and materials, set the renderer to the DSR, do the render, then cleans up after itself (deletes the created nodes, restores all materials, puts the renderer back to whatever you were using).
Only downside - The actual render speed of using skylights isnt great, but that can't be helped, I just love how they look
And yes, this has just been written in the past hour because I got fed up of going through the process I described above. Any suggestions on how to improve it are welcome, but go easy on me, I haven't done this before!
Figure I may as well just post the code, it isn't that long:
macroScript ClayRender category: "LiamDavis"
(
-- Variables to change basic settings
rendererToUse = Default_Scanline_Renderer()
clayColour = [255,255,255]
renderBackground = [255,255,255]
clay = standardMaterial diffuse:clayColour shaderType:1
sun = Skylight castShadows: true enabled: true
in coordsys world
min_v = 99999999999
mat_array = #()
m = 1
-- define the clay material
-- Finds the lowest vertex in the scene
for obj in objects do
(
if superclassof obj == geometryClass then
(
-- Take a snapshot of the current objects mesh
checkMesh = snapshotAsMesh obj
-- Find out how many verticies it has for the coming 'for' loop and test each verticies z position to find the lowest
num_verts = checkMesh.numverts
for v=1 to num_verts do
(
vert = getVert checkMesh v
if min_v > vert.z then
(
min_v = vert.z
)
)
delete checkMesh
)
)
-- Create the floorplane at the lowest point
floorplane = plane lengthsegs:1 widthsegs:1 length:10000 width:10000 pos:[0,0,min_v]
-- Store objects current material in an array then assign the Clay material
for obj in objects do
(
append mat_array obj.material
obj.material = clay
)
-- makes sure it renders using the DSR, but leaves it as whatever the user had it as
backgroundSetBackTo = backgroundColor
backgroundColor = renderBackground
rendererSetBackTo = renderers.current
renderers.current = rendererToUse
max quick render -- render the current viewport
renderers.current = rendererSetBackTo
backgroundColor = backgroundSetBackTo
-- delete the added nodes or repeated use would multiply them
delete floorplane
delete sun
-- restore original materials to scene objects
for obj in objects do
(
obj.material = mat_array[m]
m = m+1
)
)
Submitted by Liam.Davis on Fri, 2009-11-13 15:12.
Version: 1.1
Date Updated: 11/13/2009
One click will render your scene as a 'clay' style image, leaving the scene, materials and all your render settings exactly as they are. Code has been updated to create the floor plane at the lowest vertex in the scene, and to make it easier to customise (different renderers, alter the material colour, environment background and light type).
Additional Info:
When modelling, I often find myself using quick 'clay' renders to get an idea of what my models look like when lit, as it really brings out the edging and detail. But this involved saving my scene, creating a ground plane, positioning it, assigning a clay material to everything, creating the light, rendering it, then reloading the scene because I'd lost all my materials. So I figured I'd give creating a script a go.
It's not perfect, as it's the first proper script I've made, but it does the job. It will find the lowest vertex in the scene, create the ground plane beneath that, sort out the lights and materials, set the renderer to the DSR, do the render, then cleans up after itself (deletes the created nodes, restores all materials, puts the renderer back to whatever you were using).
Only downside - The actual render speed of using skylights isnt great, but that can't be helped, I just love how they look
And yes, this has just been written in the past hour because I got fed up of going through the process I described above. Any suggestions on how to improve it are welcome, but go easy on me, I haven't done this before!
Figure I may as well just post the code, it isn't that long:
macroScript ClayRender category: "LiamDavis"
(
-- Variables to change basic settings
rendererToUse = Default_Scanline_Renderer()
clayColour = [255,255,255]
renderBackground = [255,255,255]
clay = standardMaterial diffuse:clayColour shaderType:1
sun = Skylight castShadows: true enabled: true
in coordsys world
min_v = 99999999999
mat_array = #()
m = 1
-- define the clay material
-- Finds the lowest vertex in the scene
for obj in objects do
(
if superclassof obj == geometryClass then
(
-- Take a snapshot of the current objects mesh
checkMesh = snapshotAsMesh obj
-- Find out how many verticies it has for the coming 'for' loop and test each verticies z position to find the lowest
num_verts = checkMesh.numverts
for v=1 to num_verts do
(
vert = getVert checkMesh v
if min_v > vert.z then
(
min_v = vert.z
)
)
delete checkMesh
)
)
-- Create the floorplane at the lowest point
floorplane = plane lengthsegs:1 widthsegs:1 length:10000 width:10000 pos:[0,0,min_v]
-- Store objects current material in an array then assign the Clay material
for obj in objects do
(
append mat_array obj.material
obj.material = clay
)
-- makes sure it renders using the DSR, but leaves it as whatever the user had it as
backgroundSetBackTo = backgroundColor
backgroundColor = renderBackground
rendererSetBackTo = renderers.current
renderers.current = rendererToUse
max quick render -- render the current viewport
renderers.current = rendererSetBackTo
backgroundColor = backgroundSetBackTo
-- delete the added nodes or repeated use would multiply them
delete floorplane
delete sun
-- restore original materials to scene objects
for obj in objects do
(
obj.material = mat_array[m]
m = m+1
)
)