Notifications
Clear all
[Closed] MapChannel value copy
Nov 10, 2006 12:29 am
hi,
never used maxscript before but have good grasp on programming,
what I’m trying to do is write a quick script that copies a specific MapChannel value (R, G or B) into another Channel (it’s R G or B)
I’ve found plenty of ChannelCopy scripts around, but they all copy the entire Channel RGB/UVW, I just want particular values copied – reason being is that a game side shader uses the U V and W as seperate blenders in a shader, so they are essentially unique vales I’m trying to deal with. So copying U to U, or U to W for example.
So, any help here would be great!
Cheers
1 Reply
Nov 10, 2006 12:29 am
Do you want just to copy U to W (for example) on the same object and the same channel ?
If that is all you need, this code should work:
fn partialChannelCopy objUnwrapMod theChannel sourcePChannel destPChannel =
(
local objUnwrap1=objUnwrapMod.unwrap
local objUnwrap2=objUnwrapMod.unwrap2
if objUnwrap1.getMapChannel() != theChannel do (
objUnwrap1.setMapChannel theChannel
modPanel.setCurrentObject objUnwrapMod -- update
)
local objNumMapverts = objUnwrap1.NumberVertices()
local objFaces=#{1..objUnwrap1.numberPolygons()}
local objUnwrap1numberPointsInFace = objUnwrap1.numberPointsInFace
local objUnwrap1getVertexIndexFromFace = objUnwrap1.getVertexIndexFromFace
local objUnwrap1getVertexPosition = objUnwrap1.getVertexPosition
local objUnwrap1SetVertexPosition = objUnwrap1.SetVertexPosition
local mapVertsFlag=#{}
local thisFace
for thisFace in objFaces do (
local numPoints=objUnwrap1numberPointsInFace thisFace
local currentFaceVertex
for currentFaceVertex=1 to numPoints do (
local currentMapVert = objUnwrap1getVertexIndexFromFace thisFace currentFaceVertex
if not mapVertsFlag[currentMapVert] do (
local pos=objUnwrap1getVertexPosition 0f currentMapVert
local currentValue
case sourcePChannel of
(
1: currentValue=pos.x
2: currentValue=pos.y
3: currentValue=pos.z
)
case destPChannel of
(
1: pos.x=currentValue
2: pos.y=currentValue
3: pos.z=currentValue
)
objUnwrap1SetVertexPosition 0f currentMapVert pos
)
mapVertsFlag[currentMapVert]=true
)
)
objUnwrap2.selectFaces #{}
)--fn
if selection.count==1 do (
max modify mode
local obj=selection[1]
select obj
if classof obj.modifiers[1]==Unwrap_UVW
then (
local objUnwrapMod=obj.modifiers[1]
local theChannel=1
partialChannelCopy objUnwrapMod theChannel 1 3 -- from U to W (1 to 3)
)
else messageBox("no unwrap found")
)