Notifications
Clear all

[Closed] render to texture & UVWunwrap

Hi guys,

First I have to confess I’m a newbie in maxscript and I just use it for 3DS exporting (put some .3Ds in a 3D engine).

The engine is not suited for multi texturing and materials : only one texture per object.

I made a script to split all the objects of a scene, process a render to texture, save bmp file in the same directory and map the new texture. Everything work exept a UVW problem.

here is my code :


for Obj in geometry do
(

local fullFileName = “d:\ exture\ exture-exemple.bmp”

fPath=getFilenamePath fullFileName

fType=getFilenameType fullFileName

id_obj_str = id_obj as string

fName= “m” + id_obj_str

id_obj += 1

print Obj

aUVWadd = UVW_Mapping_Add()

addModifier Obj aUVWadd

print “newUnwrap”

myUnwrapUVW = UVWunwrap()

myUnwrapUVW.setMapChannel 2

print “newUnwrap added”

addModifier Obj myUnwrapUVW

select Obj

print “flatten”

myUnwrapUVW.unwrap4.flattenMapByMatID 45.0 0.02 true 0 true true

currentMapType = DiffuseMap()
currentMapType.filename=fName

currentMapType.fileType=fType

currentMapType.lightingOn = true

currentMapType.shadowsOn = true

currentMapType.outputSzX = 1024

currentMapType.outputSzY = 1024

currentMapType.targetMapSlotName=“Diffuse Color”

currentMapType.filenameUnique = true

bi = Obj.INodeBakeProperties
bi.addBakeElement currentMapType

bi.bakeChannel=2

bi.activeWidth= 1024

bi.activeHeight= 1024

finalUnwrap = myUnwrapUVW
– RTT processing

render rendertype:#bakeSelected outputwidth:1024 outputheight:1024 outputFile:(fPath+fName+fType) vfb:off

Obj.removeAllBakeElements()

Obj.bakeEnabled = false

maxOps.CollapseNode $ off

finalUnwrap.setMapChannel 2

addModifier Obj finalUnwrap

mo = standard()

mo.diffuseMap = Bitmaptexture fileName:(fPath+fName+fType)

Obj.material = mo

)

messagebox “End of procedure”


I know this is not the most beautiful script you saw

When I look to the texture editor, the texture is well mapped, but the render give me a false mapping. If I save the uvw file, delete the uvw modifier, recreate it and load the uvw file it works…

default value of unwrapp different between script and gui ???