[Closed] Render To Texture with Maxscrip
Hey all, im trying to make an interface that does a render to texture of the diffuse channel, specifying the size, output dir, output file type etc. I have looked in the help under RTT_Methods but am now more confused than when I started. Can anyone give me a bit of a starting point to the RTT interface and how to do it. Cheers!!!
[color=white] [/color]
It took me a while to figure this out also. For some time I just thought it couldn’t be done, but after staring at the help docs long enough, and a bit of trial and error, I got it working.
The two interfaces you want to look at are INodeBakeProperties and INodeBakeProjProperties. Plus, take a look at the Macro_BakeTextures.mcr file (if you’re feeling brave).
Here’s a sample script to render the diffuse channel from one object to another:
-- add project modifier and projection objects
fn addProjMod lowResObj highResObjs cageOffset =
(
modMode = getCommandPanelTaskMode()
setCommandPanelTaskMode #modify
projMod = projection()
addModifier lowResObj projMod
for obj in highResObjs do
(
projMod.addObjectNode obj
)
projMod.resetCage()
projMod.pushCage cageOffset
projMod.displayCage = true
projMod.name = "ProjMod"
setCommandPanelTaskMode modMode
projMod
)
-- set up the objects
theObj = sphere radius:50 segs:32 mapcoords:on
theProjObj = sphere radius:50.5 segs:32 mapcoords:on
theProjObj.material = standard diffuseMap:(Perlin_Marble ())
-- define variables
renderSize = 512
fileName = theObj.name + "_Diffuse.tif"
filePath = "c:\\" + diff.filename
-- the bake object needs to be selected
select theObj
-- set up the bake interfaces
bakeProps = theObj.INodeBakeProperties
bakeProjProps = theObj.INodeBakeProjProperties
-- add diffuse element
diff = DiffuseMap()
bakeProps.addBakeElement diff
-- file name
diff.filename = fileName
diff.filetype = filePath
-- map size
diff.outputSzX = renderSize
diff.outputSzY = renderSize
diff.enabled = true
-- projection
bakeProjProps.enabled = true
bakeProjProps.projectionMod = (addProjMod theObj #(theProjObj) 1)
-- open and close RTT
macros.run "Render" "BakeDialog"
destroyDialog gTextureBakeDialog
-- do the render
curBM = bitmap renderSize renderSize
render rendertype:#bakeSelected frame:0 to:curBM vfb:true cancelled:&wasCanceled
close curBM
-- display the diffuse map
display (openBitMap filePath)
Cheers for that. It works great, only it always saves the element as 640×480, not the specified 1024×1024. It renders as 1024×1024 but only saves the top left 640×480 segement of it.
Im using vray and the VRay_DiffuseFilterMap() Element and im setting the element size, and the curBM (bitmap) size and even the render() size all with the same property (1024)
It seems that if i choose .exr as an output format it will only save a 640×480 segment of the render, while using .tiff will save the whole 1024×1024 image. Weird
Have you seen this thread?
Look towards the end where he talks about the difference between rendering directly to the bitmap versus copying the result to a new bitmap and then saving that one. That might help with this issue too.