-- BakeTextureToCPV -- GunnarD -- 10/06/2010 -- Baking textures to vertex channel filein (RsConfigGetWildwestDir() + "Script/3dsMax/Maps/Materials/terrain_helperFunctions.ms") global vertQueryMethod fn RsGetColourAtVert model vertnum = ( local facelist = meshop.getFacesUsingVert model #{vertnum} -- lookup all texmaps local textureNamesArraysMap = #() local textureArraysMap = #() for f in facelist do ( local myMatId = getfacematid model f if textureArraysMap[myMatId]!=undefined then continue LocalTexMapNames = #() LocalTexMapsBmps = #() collMaterial = "default" RsSetMapsFlags false diff:true spec:false normal:false RsGetTexMapsFromObjWithMaps model LocalTexMapNames LocalTexMapsBmps id:myMatId --matID RsSetMapsFlags true diff:true spec:true normal:true -- print (model.name+", "+LocalTexMapNames.count as string) -- for tex in LocalTexMapsBmps do print (" "+tex.filename) local theMaterial = model.material if multimaterial==(classof theMaterial) then theMaterial = theMaterial.materialList[myMatId] local evaluated = false local shadername = theMaterial.name if Rage_Shader==(classof theMaterial) then ( shadername = rstgetshadername theMaterial if matchPattern shadername pattern:"*terrain*" then ( local theTexMap = GetDominantTextureFromTerrainFace model theMaterial myMatId f textureNamesArraysMap[myMatId] = theTexMap.name textureArraysMap[myMatId] = theTexMap.bitmap -- print ("IS terrain shader!!!:"+shadername) evaluated = true ) ) if not evaluated then ( -- print ("not terrain shader?!?:"+shadername) textureNamesArraysMap[myMatId] = LocalTexMapNames[1] textureArraysMap[myMatId] = LocalTexMapsBmps[1].bitmap ) ) -- print (textureNamesArraysMap as string) local vertColor = (color 1 1 1 1) for f in facelist do ( local myMatId = getfacematid model f if textureArraysMap[myMatId] == undefined then ( print ("matid "+myMatId+" hasn't got maps") continue ) local vertIndeces = getFace model f local myIndex = if (vertIndeces.x==vertnum) then 1 else if (vertIndeces.y==vertnum) then 2 else if (vertIndeces.z==vertnum) then 3 else 0 if myIndex==0 then ( print ("failed at :"+vertnum) return false ) local myUvFace = (getTvFace model f) local myUv = getTVert model myUvFace[myIndex] local moduloedUvs = [(mod myUv[1] 1.0), (mod myUv[2] 1.0)] local firstBitmaptex = textureArraysMap[myMatId] if moduloedUvs[1] < 0 then moduloedUvs[1] = 1.0 + moduloedUvs[1] if moduloedUvs[2] < 0 then moduloedUvs[2] = 1.0 + moduloedUvs[2] moduloedUvs = moduloedUvs * (point2 firstBitmaptex.width firstBitmaptex.height) try( vertColor += (getPixels firstBitmaptex moduloedUvs 1)[1] )catch(print (getcurrentException())) ) -- print vertColor -- print facelist.numberSet return vertColor /= facelist.numberSet ) fn GetVertCloseToPos mesh pos = ( local lastDistance = 999 local lastIndex = 0 for vIndex=1 to mesh.verts.count do ( local currDistance = length ((getvert mesh vIndex)-pos) if vIndex==1 or currDistance