3526 lines
88 KiB
Plaintext
Executable File
3526 lines
88 KiB
Plaintext
Executable File
-- Rockstar Material Utilities
|
|
-- Rockstar North
|
|
-- 14/3/2005
|
|
-- by Greg Smith
|
|
-- by Luke Openshaw
|
|
|
|
-- if you get add any functions to get texture maps
|
|
-- make sure they come out lower case. lots of comparisons
|
|
-- assume this. RsMakeSafeTextureName will return a lowercase
|
|
-- name
|
|
|
|
-----------------------------------------------------------------------------
|
|
-- Uses
|
|
-----------------------------------------------------------------------------
|
|
filein "pipeline/util/file.ms"
|
|
filein "pipeline/util/string.ms"
|
|
filein "rockstar/util/mapobj.ms"
|
|
filein "rockstar/export/settings.ms"
|
|
filein "pipeline/util/drawablelod.ms"
|
|
|
|
-----------------------------------------------------------------------------
|
|
-- Globals
|
|
-----------------------------------------------------------------------------
|
|
|
|
--RsDiffuseTexMaxSize = 512
|
|
--RsOtherTexMaxSize = 256
|
|
|
|
RsDiffuseTexMaxSize = 1024
|
|
RsOtherTexMaxSize = 1024
|
|
|
|
RsPackingForSingleTextures = true -- Marked for deletion once all references have been removed
|
|
|
|
incDefault = true
|
|
incDiffuse = true
|
|
incSpec = true
|
|
incNormal = true
|
|
incID = -1
|
|
|
|
-----------------------------------------------------------------------------
|
|
-- Functions
|
|
-----------------------------------------------------------------------------
|
|
|
|
--------------------------------------------------------------
|
|
--
|
|
--------------------------------------------------------------
|
|
fn RsSetMapsFlags indefault indiffuse inspec innormal = (
|
|
|
|
incDefault = indefault
|
|
incDiffuse = indiffuse
|
|
incSpec = inspec
|
|
incNormal = innormal
|
|
)
|
|
|
|
--------------------------------------------------------------
|
|
-- Returns a list of objs without packed textured objects
|
|
--------------------------------------------------------------
|
|
fn RsGetInputObjectList inputobjlist outputobjlist = (
|
|
|
|
idxPackTextures = getattrindex "Gta Object" "Pack Textures"
|
|
idxFragment = getattrindex "Gta Object" "Is Fragment"
|
|
|
|
for obj in inputobjlist do (
|
|
|
|
if getattrclass obj == "Gta Object" then (
|
|
|
|
if (getattr obj idxFragment == true) or (getattr obj idxPackTextures == false) then (
|
|
|
|
append outputobjlist obj
|
|
)
|
|
) else (
|
|
|
|
append outputobjlist obj
|
|
)
|
|
)
|
|
)
|
|
|
|
----------------------------------------------------------------------------------------
|
|
--
|
|
----------------------------------------------------------------------------------------
|
|
fn RsIsDiffuseMap mapname = (
|
|
|
|
retval = false
|
|
|
|
if mapname != undefined then (
|
|
|
|
if findstring mapname "Diffuse " != undefined then (
|
|
|
|
retval = true
|
|
)
|
|
)
|
|
|
|
retval
|
|
)
|
|
|
|
----------------------------------------------------------------------------------------
|
|
--
|
|
----------------------------------------------------------------------------------------
|
|
fn RsIsSpecMap mapname = (
|
|
|
|
retval = false
|
|
|
|
if mapname != undefined then (
|
|
|
|
if findstring mapname "Specular Texture" != undefined then (
|
|
|
|
retval = true
|
|
)
|
|
)
|
|
|
|
retval
|
|
)
|
|
|
|
----------------------------------------------------------------------------------------
|
|
--
|
|
----------------------------------------------------------------------------------------
|
|
fn RsIsBumpMap mapname = (
|
|
|
|
retval = false
|
|
|
|
if mapname != undefined then (
|
|
|
|
if findstring mapname "Bump Texture" != undefined then (
|
|
|
|
retval = true
|
|
)
|
|
)
|
|
|
|
retval
|
|
)
|
|
|
|
fn RsIsTintPalette mapname = (
|
|
retval = false
|
|
if mapname != undefined then (
|
|
if mapname == "Tint Palette" then (
|
|
retval = true
|
|
)
|
|
)
|
|
|
|
retval
|
|
)
|
|
|
|
|
|
fn RsIsResizeExempt map maptypename = (
|
|
-- LPXO: We may want to make other texture types resize exempt
|
|
local idx = getAttrIndex "Gta Texture" "optimised"
|
|
retval = RsIsTintPalette maptypename or not (getAttr map idx)
|
|
|
|
retval
|
|
)
|
|
|
|
fn RsGetDistanceAlphaMapResultMap distAlphaMap =
|
|
(
|
|
--make my name safe
|
|
distAlphaMap.name = substituteString distAlphaMap.name " " "_"
|
|
distAlphaMap.name = substituteString distAlphaMap.name "#" ""
|
|
|
|
--make sure result is not downscaled
|
|
local idx = getattrindex "Gta Texture" "optimised"
|
|
setAttr distAlphaMap idx false
|
|
|
|
local resultmap = ""
|
|
if undefined!=distAlphaMap.resultmap then
|
|
resultmap = distAlphaMap.resultmap.filename
|
|
-- then check whether it's a valid file path and if not, export it
|
|
if resultmap=="" or 0==(getFileSize resultmap) then --rebuild if necessary
|
|
(
|
|
local diffusemappath = "C:\\"
|
|
if distAlphaMap.diffusemap != undefined then
|
|
diffusemappath = distAlphaMap.diffusemap.filename
|
|
diffusemappath = RsRemoveFile diffusemappath
|
|
if distAlphaMap.Create false diffusemappath then
|
|
resultmap = distAlphaMap.resultmap.filename
|
|
print ("Building new Distance map to "+resultmap)
|
|
--doublecheck whether it worked
|
|
if resultmap=="" then
|
|
(
|
|
local msg=stringstream ""
|
|
format "Result for distanceAlphaMap % could not be created!" distAlphaMap.name to:msg
|
|
messagebox msg
|
|
)
|
|
)
|
|
return resultmap
|
|
)
|
|
|
|
----------------------------------------------------------------------------------------
|
|
--
|
|
----------------------------------------------------------------------------------------
|
|
fn RsMatGetMapIdsUsedOnObjectWithCount obj mapList polycount:undefined faceidlists:undefined =
|
|
(
|
|
if
|
|
(
|
|
(
|
|
isKindOf obj Editable_Mesh or
|
|
isKindOf obj Editable_Poly or
|
|
isKindOf obj PolyMeshObject
|
|
) and
|
|
(obj.material != undefined) and
|
|
((hasProperty obj.material "materialList") == true)
|
|
) then
|
|
(
|
|
local ObjGetFaceMatId = if (isKindOf obj Editable_Mesh) then getfacematid else polyop.getfacematid
|
|
local matID
|
|
for i = 1 to (getnumfaces obj) do
|
|
(
|
|
matID = ObjGetFaceMatId obj i
|
|
if matID != undefined do
|
|
(
|
|
idxFound = finditem mapList matID
|
|
if idxFound == 0 then
|
|
(
|
|
append mapList matID
|
|
if polycount != undefined then append polycount 1
|
|
if faceidlists != undefined then append faceidlists #(i)
|
|
) else
|
|
(
|
|
if polycount != undefined then polycount[idxFound] = polycount[idxFound] + 1
|
|
if faceidlists != undefined then append faceidlists[idxFound] i
|
|
)
|
|
)
|
|
)
|
|
) else
|
|
(
|
|
append mapList -1
|
|
if undefined!=polycount then append polycount 0
|
|
)
|
|
)
|
|
|
|
----------------------------------------------------------------------------------------
|
|
--
|
|
----------------------------------------------------------------------------------------
|
|
fn RsMatGetMapIdsUsedOnObjectWithIsScaleUVInfo obj mapList uvInfoList =
|
|
(
|
|
convertToColl = false
|
|
|
|
if classof obj == Col_Mesh then
|
|
(
|
|
col2mesh obj
|
|
convertToColl = true
|
|
)
|
|
|
|
if classof obj == Editable_Mesh or classof obj == Editable_Poly or classof obj == PolyMeshObject then
|
|
(
|
|
if (hasProperty obj.material "materialList") == true then
|
|
(
|
|
|
|
numFaces = getnumfaces obj
|
|
|
|
for j = 1 to numFaces do (
|
|
|
|
isUvScaled = false
|
|
tvface = gettvface obj j
|
|
|
|
for k = 1 to 3 do (
|
|
|
|
tvert = gettvert obj tvface[k]
|
|
|
|
if tvert[k] < 0.0 or tvert[k] > 1.0 then (
|
|
|
|
isUvScaled = true
|
|
)
|
|
)
|
|
|
|
if classof obj == Editable_Mesh then (
|
|
|
|
matID = getfacematid obj j
|
|
) else if classof obj == Editable_Poly or classof obj == PolyMeshObject then (
|
|
|
|
matID = polyop.getfacematid obj j
|
|
)
|
|
|
|
if matID != undefined then
|
|
(
|
|
idxFound = finditem mapList matID
|
|
if idxFound == 0 then
|
|
(
|
|
append mapList matID
|
|
append uvInfoList isUvScaled
|
|
)
|
|
else
|
|
(
|
|
if isUvScaled then uvInfoList[idxFound] = isUvScaled
|
|
)
|
|
)
|
|
)
|
|
|
|
) else (
|
|
|
|
append mapList -1
|
|
)
|
|
|
|
) else (
|
|
|
|
append mapList -1
|
|
)
|
|
|
|
-- sort mapList
|
|
|
|
if convertToColl then (
|
|
|
|
mesh2col obj
|
|
)
|
|
)
|
|
|
|
----------------------------------------------------------------------------------------
|
|
--
|
|
----------------------------------------------------------------------------------------
|
|
fn RsMatGetMapIdsUsedOnObject obj mapList =
|
|
(
|
|
undo off -- Don't put collision-conversion into undo queue
|
|
(
|
|
convertToColl = false
|
|
|
|
if classof obj == Col_Mesh then
|
|
(
|
|
col2mesh obj
|
|
convertToColl = true
|
|
)
|
|
|
|
if
|
|
(
|
|
(
|
|
isKindOf obj Editable_Mesh or
|
|
isKindOf obj Editable_Poly or
|
|
isKindOf obj PolyMeshObject
|
|
) and
|
|
(obj.material != undefined) and
|
|
((hasProperty obj.material "materialList") == true)
|
|
)
|
|
then
|
|
(
|
|
numFaces = getnumfaces obj
|
|
for j = 1 to numFaces do
|
|
(
|
|
if classof obj == Editable_Mesh then
|
|
(
|
|
matID = getfacematid obj j
|
|
)
|
|
else if classof obj == Editable_Poly or classof obj == PolyMeshObject then
|
|
(
|
|
matID = polyop.getfacematid obj j
|
|
)
|
|
|
|
if matID != undefined then
|
|
(
|
|
if finditem mapList matID == 0 then
|
|
(
|
|
|
|
append mapList matID
|
|
)
|
|
)
|
|
)
|
|
)
|
|
else
|
|
(
|
|
append mapList -1
|
|
)
|
|
|
|
sort mapList
|
|
|
|
if convertToColl then
|
|
(
|
|
mesh2col obj
|
|
)
|
|
)
|
|
)
|
|
|
|
----------------------------------------------------------------------------------------
|
|
-- returns the nth texmap name in the rage shader
|
|
----------------------------------------------------------------------------------------
|
|
fn RsGetTexMapNameFromRsShader mat texmapidx =
|
|
(
|
|
texmapidx = texmapidx - 1
|
|
numVars = RstGetVariableCount mat
|
|
texmapCount = -1
|
|
|
|
retval = undefined
|
|
if numVars != undefined and numVars >= 1 do
|
|
(
|
|
for i = 1 to numVars
|
|
where (RstGetVariableType mat i == "texmap") and (retval == undefined)
|
|
do
|
|
(
|
|
texmapCount += 1
|
|
if texmapCount == texmapidx do (retval = (RstGetVariableName mat i))
|
|
)
|
|
)
|
|
retval
|
|
)
|
|
|
|
----------------------------------------------------------------------------------------
|
|
-- removes spaces from texture file names
|
|
----------------------------------------------------------------------------------------
|
|
fn RsMakeSafeTextureName namein =
|
|
(
|
|
nameout = ""
|
|
namein = RsMakeSafeSlashes namein
|
|
|
|
index = RsFindLast namein "/"
|
|
searchString = namein
|
|
|
|
if index != -1 then
|
|
(
|
|
nameout = substring namein 1 index
|
|
namein = substring namein (index + 1) (namein.count - index)
|
|
)
|
|
|
|
for i = 1 to namein.count do
|
|
(
|
|
character = namein[i]
|
|
|
|
-- if character != " " then (
|
|
|
|
nameout = nameout + character
|
|
-- )
|
|
)
|
|
|
|
RsLowercase(nameout)
|
|
)
|
|
|
|
----------------------------------------------------------------------------------------
|
|
-- fills texmaplist with the texture maps used by a material
|
|
----------------------------------------------------------------------------------------
|
|
fn RsStripTexturePathSingle texpath =
|
|
(
|
|
if (texpath != undefined) then
|
|
(
|
|
return getFilenameFile texpath
|
|
)
|
|
return ""
|
|
)
|
|
|
|
----------------------------------------------------------------------------------------
|
|
-- fills texmaplist with the texture maps used by a material
|
|
----------------------------------------------------------------------------------------
|
|
fn RsStripTexturePath texpath = (
|
|
|
|
retval = ""
|
|
|
|
if texpath != undefined and texpath != "" then
|
|
(
|
|
local texpathList = filterstring texpath "+>"
|
|
|
|
local texpathout = RsStripTexturePathSingle texpathList[1]
|
|
|
|
if texpathList.count > 1 then (
|
|
|
|
for i = 2 to texpathList.count do (
|
|
|
|
texpathout = texpathout + RsStripTexturePathSingle texpathList[i]
|
|
)
|
|
)
|
|
|
|
retval = texpathout
|
|
)
|
|
|
|
retval
|
|
)
|
|
|
|
----------------------------------------------------------------------------------------
|
|
--
|
|
----------------------------------------------------------------------------------------
|
|
fn RsGetTexMapVariableIndex mat texmapid = (
|
|
|
|
texmapcount = 0
|
|
count = RstGetVariableCount mat
|
|
|
|
for i = 1 to count do (
|
|
|
|
if RstGetVariableType mat i == "texmap" then (
|
|
|
|
texmapcount = texmapcount + 1
|
|
|
|
if texmapcount == texmapid then (
|
|
|
|
return i
|
|
)
|
|
)
|
|
)
|
|
|
|
return 0
|
|
)
|
|
|
|
----------------------------------------------------------------------------------------
|
|
--
|
|
----------------------------------------------------------------------------------------
|
|
fn RsGetProceduralFaces obj mat facesout = (
|
|
|
|
if obj != undefined and classof obj != XrefObject and mat != undefined then (
|
|
|
|
if classof mat == MultiMaterial then (
|
|
|
|
for i = 1 to mat.materialIDList.count do (
|
|
|
|
if classof mat.materiallist[i] == RexBoundMtl then (
|
|
|
|
if RexGetProceduralName mat.materiallist[i] != "" then (
|
|
|
|
numFaces = getnumfaces obj
|
|
|
|
for j = 1 to numFaces do (
|
|
|
|
if classof obj == Editable_Mesh then (
|
|
|
|
matID = getfacematid obj j
|
|
) else if classof obj == Editable_Poly or classof obj == PolyMeshObject then (
|
|
|
|
matID = polyop.getfacematid obj j
|
|
)
|
|
|
|
if matID == mat.materialIDList[i] then (
|
|
|
|
append facesout j
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
) else if classof mat == RexBoundMtl then (
|
|
|
|
if RexGetProceduralName mat != "" then (
|
|
|
|
numFaces = getnumfaces obj
|
|
|
|
for j = 1 to numFaces do (
|
|
|
|
append facesout j
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
return false
|
|
)
|
|
|
|
----------------------------------------------------------------------------------------
|
|
--
|
|
----------------------------------------------------------------------------------------
|
|
fn RsGetDoesObjUseProcedurals obj mat = (
|
|
|
|
if obj != undefined and classof obj != XrefObject and mat != undefined then (
|
|
|
|
if classof mat == MultiMaterial then (
|
|
|
|
matlist = #()
|
|
|
|
RsMatGetMapIdsUsedOnObject obj matlist
|
|
|
|
for i = 1 to matlist.count do (
|
|
|
|
matidx = finditem mat.materialIDList matlist[i]
|
|
|
|
if matidx != 0 then (
|
|
|
|
if RsGetDoesObjUseProcedurals obj mat.materiallist[matidx] == true then (
|
|
|
|
return true
|
|
)
|
|
)
|
|
)
|
|
) else if classof mat == RexBoundMtl then (
|
|
|
|
if RexGetProceduralName mat != "" then (
|
|
|
|
return true
|
|
)
|
|
)
|
|
)
|
|
|
|
return false
|
|
)
|
|
|
|
fn RsSpecularMapHack obj mat = (
|
|
|
|
if obj != undefined and (not (isKindOf obj XrefObject)) and mat != undefined do
|
|
(
|
|
case classof mat of
|
|
(
|
|
MultiMaterial:
|
|
(
|
|
matlist = #()
|
|
RsMatGetMapIdsUsedOnObject obj matlist
|
|
for i = 1 to matlist.count do (
|
|
if id == matlist[i] then (
|
|
matidx = finditem mat.materialIDList matlist[i]
|
|
if matidx != 0 then (
|
|
RsSpecularMapHack obj mat.materiallist[matidx]
|
|
)
|
|
)
|
|
)
|
|
)
|
|
Rage_Shader:
|
|
(
|
|
numVars = RstGetVariableCount mat
|
|
for i = 1 to numVars do
|
|
(
|
|
nameVar = RstGetVariableName mat i
|
|
if nameVar == "Specular Falloff" then
|
|
(
|
|
specVar = RstGetVariable mat i
|
|
if specVar > 199.0 and specVar < 201.0 then (
|
|
RstSetVariable mat i 201.5
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
fn RsSetMaterialToAllDefault mat =
|
|
(
|
|
case classof mat of
|
|
(
|
|
MultiMaterial:
|
|
(
|
|
for childmat in mat.materiallist do (RsSetMaterialToAllDefault childmat)
|
|
)
|
|
Rage_Shader:
|
|
(
|
|
RstSetShaderName mat "gta_default.sps"
|
|
)
|
|
)
|
|
)
|
|
|
|
----------------------------------------------------------------------------------------
|
|
-- fills texmaplist with the main texture maps used by an object
|
|
----------------------------------------------------------------------------------------
|
|
fn RsGetTexMapList obj mat texmaplist shaderlist matidlist slotlist shaderid:1 matid:1 = (
|
|
|
|
if obj != undefined and classof obj != XrefObject and mat != undefined then (
|
|
|
|
if classof mat == MultiMaterial then (
|
|
|
|
matlist = #()
|
|
uvInfoList = #()
|
|
|
|
RsMatGetMapIdsUsedOnObjectWithIsScaleUVInfo obj matlist uvInfoList
|
|
|
|
for i = 1 to matlist.count do (
|
|
|
|
if uvInfoList[i] == false then (
|
|
|
|
matidx = finditem mat.materialIDList matlist[i]
|
|
|
|
if matidx != 0 then (
|
|
|
|
RsGetTexMapList obj mat.materiallist[matidx] texmaplist shaderlist matidlist slotlist shaderid:i matid:matidx
|
|
)
|
|
)
|
|
)
|
|
)
|
|
else if classof mat == XRef_Material then (
|
|
|
|
RsGetTexMapList obj (mat.getsrcitem()) texmaplist
|
|
)
|
|
else (
|
|
|
|
isAlphaShader = false
|
|
numTexMaps = getNumSubTexmaps mat
|
|
|
|
if RstGetIsAlphaShader mat then (
|
|
|
|
isAlphaShader = true
|
|
numTexMaps = numTexMaps / 2
|
|
numTexMaps = numTexMaps + 1
|
|
)
|
|
|
|
numValidTexMaps = 0
|
|
|
|
for i = 1 to numTexMaps do (
|
|
|
|
subTexMap = getSubTexmap mat i
|
|
|
|
if classof subTexMap == DistanceAlphaMap then
|
|
(
|
|
--print "validation check"
|
|
subTexMap = RsGetDistanceAlphaMapResultMap subTexMap
|
|
)
|
|
|
|
if classof subTexMap == Bitmaptexture then (
|
|
if subTexMap.filename != "" then numValidTexMaps = numValidTexMaps + 1
|
|
)
|
|
|
|
)
|
|
|
|
if numValidTexMaps == 1 then (
|
|
|
|
slotIdx = 1
|
|
|
|
for i = 1 to numTexMaps do (
|
|
|
|
subTexMap = getSubTexmap mat i
|
|
|
|
isAlpha = false
|
|
|
|
if (classof mat == Standardmaterial) and (i == 7) then (
|
|
|
|
isAlpha = true
|
|
) else if isAlphaShader and (i == numTexMaps) then (
|
|
|
|
isAlpha = true
|
|
)
|
|
|
|
if classof subTexMap == DistanceAlphaMap then
|
|
(
|
|
--print "validation check 2"
|
|
subTexMap = RsGetDistanceAlphaMapResultMap subTexMap
|
|
)
|
|
if classof subTexMap == Bitmaptexture then (
|
|
|
|
if subTexMap.filename != "" then (
|
|
|
|
append texmaplist subTexMap
|
|
append shaderlist shaderid
|
|
append matidlist matid
|
|
|
|
if isAlpha then
|
|
append slotlist (-1)
|
|
else
|
|
append slotlist slotIdx
|
|
)
|
|
|
|
if isAlpha == false then slotIdx = slotIdx + 1
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
----------------------------------------------------------------------------------------
|
|
-- fills texmaplist with the main texture maps used by an object
|
|
----------------------------------------------------------------------------------------
|
|
fn RsGetMainTexMapsFromMaterial obj mat texmaplist firstpass:true = (
|
|
|
|
if obj != undefined and classof obj != XrefObject and mat != undefined then (
|
|
|
|
if classof mat == MultiMaterial then (
|
|
|
|
matlist = #()
|
|
|
|
RsMatGetMapIdsUsedOnObject obj matlist
|
|
|
|
for i = 1 to matlist.count do (
|
|
|
|
matidx = finditem mat.materialIDList matlist[i]
|
|
|
|
if matidx != 0 then (
|
|
|
|
RsGetMainTexMapsFromMaterial obj mat.materiallist[matidx] texmaplist firstpass:false
|
|
)
|
|
)
|
|
)
|
|
else if classof mat == XRef_Material then (
|
|
|
|
RsGetMainTexMapsFromMaterial obj (mat.getsrcitem()) texmaplist
|
|
)
|
|
else if classof mat == Standardmaterial then (
|
|
|
|
diffuseName = ""
|
|
subTexMap = getSubTexmap mat 2
|
|
|
|
append texmaplist subTexMap
|
|
) else if classof mat == Rage_Shader then (
|
|
|
|
numTexMap = getNumSubTexmaps mat
|
|
|
|
if numTexMap > 0 then (
|
|
|
|
subTexMap = getSubTexmap mat 1
|
|
|
|
append texmaplist subTexMap
|
|
)
|
|
)
|
|
else if classof mat == DirectX_9_Shader then (
|
|
|
|
numTexMap = getNumSubTexmaps mat
|
|
|
|
if numTexMap > 0 then (
|
|
|
|
subTexMap = getSubTexmap mat 1
|
|
|
|
append texmaplist subTexMap
|
|
)
|
|
)
|
|
|
|
if firstpass then (
|
|
|
|
for childobj in obj.children do (
|
|
|
|
RsGetMainTexMapsFromMaterial childobj childobj.material texmaplist
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
----------------------------------------------------------------------------------------
|
|
-- fills texmaplist with the main texture maps used by an object
|
|
----------------------------------------------------------------------------------------
|
|
fn RsGetMainTexMapsFromMaterialByID obj mat id texmaplist = (
|
|
|
|
if obj != undefined and classof obj != XrefObject and mat != undefined then (
|
|
|
|
if classof mat == MultiMaterial then (
|
|
|
|
matlist = #()
|
|
|
|
RsMatGetMapIdsUsedOnObject obj matlist
|
|
|
|
for i = 1 to matlist.count do (
|
|
|
|
if id == matlist[i] then (
|
|
|
|
matidx = finditem mat.materialIDList matlist[i]
|
|
|
|
if matidx != 0 then (
|
|
|
|
RsGetMainTexMapsFromMaterial obj mat.materiallist[matidx] texmaplist
|
|
)
|
|
)
|
|
)
|
|
)
|
|
else if classof mat == XRef_Material then (
|
|
|
|
RsGetMainTexMapsFromMaterial obj (mat.getsrcitem()) texmaplist
|
|
)
|
|
else if classof mat == Standardmaterial then (
|
|
|
|
diffuseName = ""
|
|
subTexMap = getSubTexmap mat 2
|
|
|
|
append texmaplist subTexMap
|
|
) else if classof mat == Rage_Shader then (
|
|
|
|
numTexMap = getNumSubTexmaps mat
|
|
|
|
if numTexMap > 1 then (
|
|
|
|
subTexMap = getSubTexmap mat 1
|
|
|
|
append texmaplist subTexMap
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
fn RsGetEmptyTexMaps obj mat slotlist objnamelist texmapnamelist currentslot:-1 = (
|
|
|
|
if obj != undefined and classof obj != XrefObject and mat != undefined then (
|
|
|
|
if classof mat == MultiMaterial then (
|
|
|
|
matlist = #()
|
|
|
|
RsMatGetMapIdsUsedOnObject obj matlist
|
|
|
|
for i = 1 to matlist.count do (
|
|
|
|
if incID == -1 or matlist[i] == incID then (
|
|
|
|
matidx = finditem mat.materialIDList matlist[i]
|
|
|
|
if matidx != 0 then (
|
|
|
|
RsGetEmptyTexMaps obj mat.materiallist[matidx] slotlist objnamelist texmapnamelist currentslot:matlist[i]
|
|
)
|
|
)
|
|
)
|
|
) else if classof mat == Rage_Shader then (
|
|
|
|
varCount = RstGetVariableCount mat
|
|
texmapCount = 0
|
|
|
|
if varCount != undefined and varCount >= 1 then (
|
|
|
|
for i = 1 to varCount do (
|
|
|
|
if retval == undefined and RstGetVariableType mat i == "texmap" then (
|
|
|
|
texmapCount = texmapCount + 1
|
|
|
|
if ( getNumSubTexmaps mat < texmapCount ) then
|
|
continue
|
|
|
|
varName = RstGetVariableName mat i
|
|
varSubMap = getSubTexmap mat texmapCount
|
|
|
|
if classof varSubMap == DistanceAlphaMap then
|
|
(
|
|
--print "validation check 3"
|
|
varSubMap = varSubMap.resultmap
|
|
)
|
|
if classof varSubMap != CompositeTexturemap then (
|
|
|
|
varFilename = ""
|
|
|
|
if classof varSubMap == Bitmaptexture then (
|
|
|
|
if ( ( undefined != varSubMap.filename ) and ( "" != varSubMap.filename ) ) then (
|
|
|
|
varFilename = RsMakeSafeTextureName(RsStripTexturePath(RsLowercase(varSubMap.filename)))
|
|
)
|
|
)
|
|
|
|
if varFilename == "" and varName != "Diffuse Texture" then (
|
|
|
|
append objnamelist obj.name
|
|
append slotlist currentslot
|
|
append texmapnamelist varName
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
----------------------------------------------------------------------------------------
|
|
--
|
|
----------------------------------------------------------------------------------------
|
|
fn RsGetTexMapsFromMaterialWithMap obj mat texmaplist bitmaplist = (
|
|
|
|
for childobj in obj.children do (
|
|
|
|
if isproperty childobj "shadowprojectormap" then (
|
|
|
|
if childobj.shadowprojectormap != undefined then (
|
|
|
|
texmapname = RsMakeSafeTextureName(RsStripTexturePath (RsLowercase(childobj.shadowprojectormap.filename)))
|
|
|
|
if ( "" == texmapname ) then
|
|
continue
|
|
|
|
--format "% TexMap: % (%)\n" childobj.name texmapname childobj.shadowprojectormap.filename
|
|
append texmaplist texmapname
|
|
append bitmaplist (RsLowercase(childobj.shadowprojectormap.filename))
|
|
)
|
|
)
|
|
)
|
|
|
|
if obj != undefined and classof obj != XrefObject and mat != undefined then (
|
|
|
|
if classof mat == MultiMaterial then (
|
|
|
|
if classof obj == SpeedTree_4 then (
|
|
|
|
for i = 1 to mat.materiallist.count do (
|
|
|
|
RsGetTexMapsFromMaterialWithMap obj mat.materiallist[i] texmaplist bitmaplist
|
|
)
|
|
) else (
|
|
|
|
matlist = #()
|
|
|
|
RsMatGetMapIdsUsedOnObject obj matlist
|
|
|
|
for i = 1 to matlist.count do (
|
|
|
|
if incID == -1 or matlist[i] == incID then (
|
|
|
|
matidx = finditem mat.materialIDList matlist[i]
|
|
|
|
if matidx != 0 then (
|
|
|
|
RsGetTexMapsFromMaterialWithMap obj mat.materiallist[matidx] texmaplist bitmaplist
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
else if classof mat == XRef_Material then (
|
|
|
|
RsGetTexMapsFromMaterialWithMap obj (mat.getsrcitem()) texmaplist bitmaplist
|
|
)
|
|
else if classof mat == Standardmaterial then (
|
|
|
|
diffuseName = ""
|
|
subTexMap = getSubTexmap mat 2
|
|
subTexMapMain = getSubTexmap mat 2
|
|
|
|
if classof subTexMap == DistanceAlphaMap then
|
|
(
|
|
--print "validation check 4"
|
|
subTexMap = RsGetDistanceAlphaMapResultMap subTexMap
|
|
)
|
|
|
|
if classof subTexMap == Bitmaptexture then (
|
|
|
|
if subTexMap.filename != "" then (
|
|
|
|
texmapname = RsLowercase(subTexMap.filename)
|
|
|
|
diffuseName = texmapname
|
|
)
|
|
|
|
subTexMap = getSubTexmap mat 7
|
|
|
|
if classof subTexMap == Bitmaptexture then (
|
|
|
|
if subTexMap.filename != "" then (
|
|
|
|
texmapname = RsLowercase(subTexMap.filename)
|
|
|
|
diffuseName = diffuseName + "+" + texmapname
|
|
)
|
|
)
|
|
)
|
|
|
|
if diffuseName != "" then (
|
|
|
|
diffuseName = RsMakeSafeTextureName(RsStripTexturePath diffuseName)
|
|
|
|
if finditem texmaplist diffuseName == 0 then (
|
|
|
|
append texmaplist diffuseName
|
|
append bitmaplist subTexMapMain
|
|
)
|
|
)
|
|
|
|
numTexMap = getNumSubTexmaps mat
|
|
|
|
for i = 1 to numTexMap do (
|
|
|
|
if (i != 2) and (i != 7) then (
|
|
|
|
subTexMap = getSubTexmap mat i
|
|
|
|
if classof subTexMap == DistanceAlphaMap then
|
|
(
|
|
--print "validation check 5"
|
|
subTexMap = RsGetDistanceAlphaMapResultMap subTexMap
|
|
)
|
|
if classof subTexMap == Bitmaptexture then (
|
|
|
|
if subTexMap.filename != "" then (
|
|
|
|
texmapname = RsMakeSafeTextureName(RsStripTexturePath (RsLowercase(subTexMap.filename)))
|
|
|
|
if finditem texmaplist texmapname == 0 then (
|
|
|
|
append texmaplist texmapname
|
|
append bitmaplist subTexMap
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
) else if classof mat == Rage_Shader then (
|
|
|
|
numTexMap = getNumSubTexmaps mat
|
|
|
|
if RstGetIsAlphaShader mat then (
|
|
|
|
numTexMap = numTexMap / 2
|
|
)
|
|
|
|
for i = 1 to numTexMap do (
|
|
|
|
texmapname = ""
|
|
|
|
subTexMap = getSubTexmap mat i
|
|
|
|
if classof subTexMap == DistanceAlphaMap then
|
|
(
|
|
--print "validation check 6"
|
|
subTexMap = RsGetDistanceAlphaMapResultMap subTexMap
|
|
)
|
|
if classof subTexMap == Bitmaptexture then (
|
|
|
|
if subTexMap.filename != "" then (
|
|
|
|
texmapname = RsMakeSafeTextureName(RsStripTexturePath(RsLowercase(subTexMap.filename)))
|
|
)
|
|
|
|
if RstGetIsAlphaShader mat then (
|
|
|
|
local alphaTexMap = getSubTexmap mat (i + numTexMap)
|
|
|
|
if classof alphaTexMap == Bitmaptexture then (
|
|
|
|
if alphaTexMap.filename != "" then (
|
|
|
|
texmapname += "+" + RsMakeSafeTextureName(RsStripTexturePath (RsLowercase(alphaTexMap.filename)))
|
|
)
|
|
)
|
|
)
|
|
)
|
|
else if classof subTexMap == CompositeTexturemap then (
|
|
|
|
numMaps = getnumsubtexmaps subTexMap
|
|
|
|
for j = 1 to numMaps do (
|
|
|
|
subsubTexMap = getSubTexmap subTexMap j
|
|
|
|
if classof subsubTexMap == Bitmaptexture then (
|
|
|
|
if subsubTexMap.filename != "" then (
|
|
|
|
if j != 1 then (
|
|
|
|
texmapname += ">"
|
|
)
|
|
|
|
texmapname += RsMakeSafeTextureName(RsStripTexturePath(RsLowercase(subsubTexMap.filename)))
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
if texmapname != "" then (
|
|
|
|
if finditem texmaplist texmapname == 0 then (
|
|
|
|
texmaptype = RsGetTexMapNameFromRsShader mat i
|
|
|
|
addMap = incDefault
|
|
|
|
if RsIsDiffuseMap texmaptype then addMap = incDiffuse
|
|
if RsIsSpecMap texmaptype then addMap = incSpec
|
|
if RsIsBumpMap texmaptype then addMap = incNormal
|
|
|
|
if addMap then (
|
|
|
|
append texmaplist texmapname
|
|
append bitmaplist subTexMap
|
|
)
|
|
)
|
|
)
|
|
)
|
|
) else if classof mat == DirectX_9_Shader then (
|
|
|
|
numTexMap = getNumSubTexmaps mat
|
|
|
|
|
|
for i = 1 to numTexMap do (
|
|
|
|
texmapname = ""
|
|
|
|
subTexMap = getSubTexmap mat i
|
|
|
|
if classof subTexMap == DistanceAlphaMap then
|
|
(
|
|
--print "validation check 7"
|
|
subTexMap = RsGetDistanceAlphaMapResultMap subTexMap
|
|
)
|
|
if classof subTexMap == Bitmaptexture then (
|
|
|
|
if subTexMap.filename != "" then (
|
|
|
|
texmapname = RsMakeSafeTextureName(RsStripTexturePath(RsLowercase(subTexMap.filename)))
|
|
)
|
|
|
|
if RstGetIsAlphaShader mat then (
|
|
|
|
local alphaTexMap = getSubTexmap mat (i + numTexMap)
|
|
|
|
if classof alphaTexMap == Bitmaptexture then (
|
|
|
|
if alphaTexMap.filename != "" then (
|
|
|
|
texmapname += "+" + RsMakeSafeTextureName(RsStripTexturePath (RsLowercase(alphaTexMap.filename)))
|
|
)
|
|
)
|
|
)
|
|
)
|
|
-- Do we need want composite tex map support on dx terrain shaders
|
|
/*else if classof subTexMap == CompositeTexturemap then (
|
|
|
|
numMaps = getnumsubtexmaps subTexMap
|
|
|
|
for j = 1 to numMaps do (
|
|
|
|
subsubTexMap = getSubTexmap subTexMap j
|
|
|
|
if classof subsubTexMap == Bitmaptexture then (
|
|
|
|
if subsubTexMap.filename != "" then (
|
|
|
|
if j != 1 then (
|
|
|
|
texmapname += ">"
|
|
)
|
|
|
|
texmapname += RsMakeSafeTextureName(RsStripTexturePath(RsLowercase(subsubTexMap.filename)))
|
|
)
|
|
)
|
|
)
|
|
)*/
|
|
|
|
if texmapname != "" then (
|
|
|
|
if finditem texmaplist texmapname == 0 then (
|
|
append texmaplist texmapname
|
|
append bitmaplist subTexMap
|
|
)
|
|
)
|
|
)
|
|
--)
|
|
) else (
|
|
numTexMap = getNumSubTexmaps mat
|
|
|
|
for i = 1 to numTexMap do (
|
|
|
|
subTexMap = getSubTexmap mat i
|
|
|
|
if classof subTexMap == DistanceAlphaMap then
|
|
(
|
|
--print "validation check 7.5"
|
|
subTexMap = RsGetDistanceAlphaMapResultMap subTexMap
|
|
)
|
|
if classof subTexMap == Bitmaptexture then (
|
|
|
|
if subTexMap.filename != "" then (
|
|
|
|
texmapname = RsMakeSafeTextureName(RsStripTexturePath (RsLowercase(subTexMap.filename)))
|
|
|
|
if finditem texmaplist texmapname == 0 then (
|
|
|
|
append texmaplist texmapname
|
|
append bitmaplist subTexMap
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
----------------------------------------------------------------------------------------
|
|
-- fills texmaplist with the texture maps used by a material
|
|
----------------------------------------------------------------------------------------
|
|
fn RsGetTexMapsInfoFromMaterial obj mat texmaplist objPolys objWidth objHeight objSize objMatID objTexMaps objObjects objObjectFaces matid:-1 polys:0 faceidlist:undefined = (
|
|
|
|
if obj != undefined and classof obj != XrefObject and mat != undefined then (
|
|
|
|
if classof mat == MultiMaterial then (
|
|
|
|
matlist = #()
|
|
polyCountList = #()
|
|
faceIDLists = #()
|
|
|
|
RsMatGetMapIdsUsedOnObjectWithCount obj matlist polycount:polyCountList faceidlists:faceIDLists
|
|
|
|
for i = 1 to matlist.count do (
|
|
|
|
matidx = finditem mat.materialIDList matlist[i]
|
|
|
|
if matidx != 0 then (
|
|
|
|
RsGetTexMapsInfoFromMaterial obj mat.materiallist[matidx] texmaplist objPolys objWidth objHeight objSize objMatID objTexMaps objObjects objObjectFaces matid:matlist[i] polys:polyCountList[i] faceidlist:faceIDLists[i]
|
|
)
|
|
)
|
|
)
|
|
else if classof mat == XRef_Material then (
|
|
|
|
RsGetTexMapsInfoFromMaterial obj (mat.getsrcitem()) texmaplist objPolys objWidth objHeight objSize objMatID objTexMaps objObjects objObjectFaces matid:-1 polys:0 faceidlist:faceidlist
|
|
) else (
|
|
|
|
numTexMap = getNumSubTexmaps mat
|
|
|
|
for i = 1 to numTexMap do (
|
|
|
|
subTexMap = getSubTexmap mat i
|
|
|
|
if classof subTexMap == DistanceAlphaMap then
|
|
(
|
|
--print "validation check 8"
|
|
subTexMap = RsGetDistanceAlphaMapResultMap subTexMap
|
|
)
|
|
if classof subTexMap == Bitmaptexture then (
|
|
|
|
if subTexMap.filename != "" then (
|
|
|
|
texmapname = RsMakeSafeTextureName(RsStripTexturePath (RsLowercase(subTexMap.filename)))
|
|
|
|
idxTex = finditem texmaplist texmapname
|
|
|
|
if idxTex == 0 then (
|
|
|
|
append objObjects #(obj)
|
|
append objObjectFaces #(faceidlist)
|
|
append texmaplist texmapname
|
|
|
|
if matid == -1 then (
|
|
|
|
append objMatID 0
|
|
append objPolys (obj.numfaces)
|
|
) else (
|
|
|
|
append objMatID matid
|
|
append objPolys polys
|
|
)
|
|
|
|
append objTexMaps subTexMap
|
|
|
|
currWidth = 0
|
|
|
|
try (
|
|
currWidth = subTexMap.bitmap.width
|
|
) catch (
|
|
|
|
)
|
|
|
|
append objWidth currWidth
|
|
|
|
currHeight = 0
|
|
|
|
try (
|
|
currHeight = subTexMap.bitmap.height
|
|
) catch (
|
|
|
|
)
|
|
|
|
append objHeight currHeight
|
|
|
|
bmpFileSize = (getfilesize subTexMap.filename) / 1024
|
|
|
|
append objSize bmpFileSize
|
|
) else (
|
|
|
|
idxFound = finditem objObjects[idxTex] obj
|
|
|
|
if idxFound == 0 then (
|
|
|
|
append objObjects[idxTex] obj
|
|
append objObjectFaces[idxTex] faceidlist
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
----------------------------------------------------------------------------------------
|
|
-- fills texmaplist with the texture maps used by a material
|
|
----------------------------------------------------------------------------------------
|
|
fn RsGetTexMapsFromMaterial obj mat texmaplist maxsizelist isbumplist = (
|
|
|
|
for childobj in obj.children do (
|
|
|
|
if isproperty childobj "shadowprojectormap" then (
|
|
|
|
if childobj.shadowprojectormap != undefined then (
|
|
|
|
texmapname = (RsMakeSafeTextureName(RsStripTexturePath (RsLowercase(childobj.shadowprojectormap.filename))))
|
|
if ( "" == texmapname ) then
|
|
continue
|
|
|
|
--format "% TexMap: % (%)\n" childobj.name texmapname childobj.shadowprojectormap.filename
|
|
append texmaplist texmapname
|
|
append maxsizelist 1024
|
|
append isbumplist false
|
|
)
|
|
)
|
|
)
|
|
|
|
if obj != undefined and classof obj != XrefObject and mat != undefined then (
|
|
|
|
if classof mat == MultiMaterial then (
|
|
|
|
--print "multi"
|
|
|
|
if classof obj == SpeedTree_4 then (
|
|
|
|
for i = 1 to mat.materiallist.count do (
|
|
|
|
RsGetTexMapsFromMaterial obj mat.materiallist[i] texmaplist maxsizelist isbumplist
|
|
)
|
|
) else (
|
|
|
|
matlist = #()
|
|
|
|
RsMatGetMapIdsUsedOnObject obj matlist
|
|
|
|
for i = 1 to matlist.count do (
|
|
|
|
matidx = finditem mat.materialIDList matlist[i]
|
|
|
|
if matidx != 0 then (
|
|
|
|
RsGetTexMapsFromMaterial obj mat.materiallist[matidx] texmaplist maxsizelist isbumplist
|
|
)
|
|
)
|
|
)
|
|
)
|
|
else if classof mat == XRef_Material then (
|
|
|
|
RsGetTexMapsFromMaterial obj (mat.getsrcitem()) texmaplist maxsizelist isbumplist
|
|
)
|
|
else if classof mat == Standardmaterial then (
|
|
|
|
--print "standard"
|
|
|
|
diffuseName = ""
|
|
doAlpha = false
|
|
|
|
subTexMap = getSubTexmap mat 1
|
|
|
|
if subTexMap == undefined then (
|
|
|
|
doAlpha = true
|
|
subTexMap = getSubTexmap mat 2
|
|
)
|
|
|
|
if classof subTexMap == DistanceAlphaMap then
|
|
(
|
|
--print "validation check 9"
|
|
subTexMap = RsGetDistanceAlphaMapResultMap subTexMap
|
|
)
|
|
if classof subTexMap == Bitmaptexture then (
|
|
|
|
if ( ( undefined != subTexMap.filename ) and ( "" != subTexMap.filename ) ) then (
|
|
|
|
texmapname = RsLowercase(subTexMap.filename)
|
|
|
|
diffuseName = texmapname
|
|
)
|
|
|
|
if doAlpha then (
|
|
|
|
subTexMap = getSubTexmap mat 7
|
|
|
|
if classof subTexMap == Bitmaptexture then (
|
|
|
|
if ( ( undefined != subTexMap.filename ) and ( "" != subTexMap.filename ) ) then (
|
|
|
|
texmapname = RsLowercase(subTexMap.filename)
|
|
|
|
diffuseName = diffuseName + "+" + texmapname
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
if diffuseName != "" then (
|
|
|
|
diffuseName = RsMakeSafeTextureName(RsStripTexturePath diffuseName)
|
|
|
|
if finditem texmaplist diffuseName == 0 then (
|
|
|
|
--print diffuseName
|
|
--print RsDiffuseTexMaxSize
|
|
|
|
append texmaplist diffuseName
|
|
append maxsizelist RsDiffuseTexMaxSize
|
|
append isbumplist false
|
|
)
|
|
)
|
|
|
|
numTexMap = getNumSubTexmaps mat
|
|
|
|
for i = 1 to numTexMap do (
|
|
|
|
if (i != 2) and (i != 7) then (
|
|
|
|
subTexMap = getSubTexmap mat i
|
|
|
|
if classof subTexMap == DistanceAlphaMap then
|
|
(
|
|
--print "validation check 10"
|
|
subTexMap = RsGetDistanceAlphaMapResultMap subTexMap
|
|
)
|
|
if classof subTexMap == Bitmaptexture then (
|
|
|
|
if ( ( undefined != subTexMap.filename ) and ( "" != subTexMap.filename ) ) then (
|
|
|
|
texmapname = RsMakeSafeTextureName(RsStripTexturePath (RsLowercase(subTexMap.filename)))
|
|
|
|
if finditem texmaplist texmapname == 0 then (
|
|
|
|
--print texmapname
|
|
--print RsOtherTexMaxSize
|
|
|
|
append texmaplist texmapname
|
|
append maxsizelist RsOtherTexMaxSize
|
|
|
|
if i == 9 then (
|
|
append isbumplist true
|
|
) else (
|
|
append isbumplist false
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
) else if classof mat == Rage_Shader then (
|
|
|
|
--print "rage"
|
|
|
|
numTexMap = getNumSubTexmaps mat
|
|
|
|
if RstGetIsAlphaShader mat then (
|
|
|
|
numTexMap = numTexMap / 2
|
|
)
|
|
|
|
for i = 1 to numTexMap do (
|
|
|
|
texmapname = ""
|
|
|
|
subTexMap = getSubTexmap mat i
|
|
|
|
if classof subTexMap == DistanceAlphaMap then
|
|
(
|
|
--print "validation check 11"
|
|
subTexMap = RsGetDistanceAlphaMapResultMap subTexMap
|
|
)
|
|
if classof subTexMap == Bitmaptexture then (
|
|
|
|
if ( ( undefined != subTexMap.filename ) and ( "" != subTexMap.filename ) ) then (
|
|
|
|
texmapname = RsMakeSafeTextureName(RsStripTexturePath(RsLowercase(subTexMap.filename)))
|
|
)
|
|
|
|
if RstGetIsAlphaShader mat then (
|
|
|
|
local alphaTexMap = getSubTexmap mat (i + numTexMap)
|
|
|
|
if classof alphaTexMap == Bitmaptexture then (
|
|
|
|
if alphaTexMap.filename != "" then (
|
|
|
|
texmapname += "+" + RsMakeSafeTextureName(RsStripTexturePath (RsLowercase(alphaTexMap.filename)))
|
|
)
|
|
)
|
|
)
|
|
)
|
|
else if classof subTexMap == CompositeTexturemap then (
|
|
|
|
numMaps = getnumsubtexmaps subTexMap
|
|
|
|
for j = 1 to numMaps do (
|
|
|
|
subsubTexMap = getSubTexmap subTexMap j
|
|
|
|
if classof subsubTexMap == Bitmaptexture then (
|
|
|
|
if ( ( undefined != subsubTexMap.filename ) and ( "" != subsubTexMap.filename ) ) then (
|
|
|
|
if j != 1 then (
|
|
|
|
texmapname += ">"
|
|
)
|
|
|
|
texmapname += RsMakeSafeTextureName(RsStripTexturePath(RsLowercase(subsubTexMap.filename)))
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
if ( ( undefined != texmapname ) and ( "" != texmapname ) ) then (
|
|
|
|
if finditem texmaplist texmapname == 0 then (
|
|
|
|
texmaptype = RsGetTexMapNameFromRsShader mat i
|
|
|
|
addMap = incDefault
|
|
|
|
if RsIsDiffuseMap texmaptype then addMap = incDiffuse
|
|
if RsIsSpecMap texmaptype then addMap = incSpec
|
|
if RsIsBumpMap texmaptype then addMap = incNormal
|
|
|
|
if addMap then (
|
|
|
|
--print texmapname
|
|
|
|
append texmaplist texmapname
|
|
|
|
if RsIsBumpMap texmaptype then (
|
|
|
|
append isbumplist true
|
|
) else (
|
|
|
|
append isbumplist false
|
|
)
|
|
|
|
if RsIsDiffuseMap texmaptype then (
|
|
|
|
--print RsDiffuseTexMaxSize
|
|
append maxsizelist RsDiffuseTexMaxSize
|
|
) else (
|
|
|
|
--print RsOtherTexMaxSize
|
|
append maxsizelist RsOtherTexMaxSize
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
) else (
|
|
|
|
numTexMap = getNumSubTexmaps mat
|
|
|
|
for i = 1 to numTexMap do (
|
|
|
|
subTexMap = getSubTexmap mat i
|
|
|
|
if classof subTexMap == DistanceAlphaMap then
|
|
(
|
|
--print "validation check 12"
|
|
subTexMap = RsGetDistanceAlphaMapResultMap subTexMap
|
|
)
|
|
if classof subTexMap == Bitmaptexture then (
|
|
|
|
if subTexMap.filename != "" then (
|
|
|
|
texmapname = RsMakeSafeTextureName(RsStripTexturePath (RsLowercase(subTexMap.filename)))
|
|
|
|
if finditem texmaplist texmapname == 0 then (
|
|
|
|
--print texmapname
|
|
|
|
append texmaplist texmapname
|
|
append isbumplist false
|
|
|
|
texmapname = RsGetTexMapNameFromRsShader mat i
|
|
|
|
if RsIsDiffuseMap texmapname then (
|
|
|
|
--print RsDiffuseTexMaxSize
|
|
|
|
append maxsizelist RsDiffuseTexMaxSize
|
|
) else (
|
|
|
|
--print RsOtherTexMaxSize
|
|
|
|
append maxsizelist RsOtherTexMaxSize
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
----------------------------------------------------------------------------------------
|
|
-- fills texmaplist with the texture maps used by a material
|
|
----------------------------------------------------------------------------------------
|
|
fn RsGetTexMapsFromMaterialNoStrip obj mat texmaplist maxsizelist isbumplist bSpeedTree exemptionList:#() = (
|
|
|
|
for childobj in obj.children do (
|
|
|
|
if isproperty childobj "shadowprojectormap" then (
|
|
|
|
if childobj.shadowprojectormap != undefined then (
|
|
|
|
texmapname = (RsLowercase(childobj.shadowprojectormap.filename))
|
|
if ( "" == texmapname ) then
|
|
continue
|
|
|
|
--format "% TexMap: % (%)\n" childobj.name texmapname childobj.shadowprojectormap.filename
|
|
append texmaplist texmapname
|
|
append maxsizelist 1024
|
|
append isbumplist false
|
|
append exemptionList false
|
|
)
|
|
)
|
|
)
|
|
|
|
if classof obj != XrefObject and mat != undefined then (
|
|
|
|
if classof mat == MultiMaterial then (
|
|
|
|
--print "multi"
|
|
|
|
if classof obj == SpeedTree_4 then (
|
|
|
|
for i = 1 to mat.materiallist.count do (
|
|
|
|
RsGetTexMapsFromMaterialNoStrip obj mat.materiallist[i] texmaplist maxsizelist isbumplist bSpeedTree exemptionList:exemptionList
|
|
)
|
|
) else (
|
|
|
|
matlist = #()
|
|
|
|
RsMatGetMapIdsUsedOnObject obj matlist
|
|
|
|
for i = 1 to matlist.count do (
|
|
|
|
if i == 1 or bSpeedTree == false then (
|
|
|
|
matidx = finditem mat.materialIDList matlist[i]
|
|
|
|
--print matlist[i]
|
|
|
|
if matidx != 0 then (
|
|
|
|
RsGetTexMapsFromMaterialNoStrip obj mat.materiallist[matidx] texmaplist maxsizelist isbumplist bSpeedTree exemptionList:exemptionList
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
else if classof mat == XRef_Material then (
|
|
|
|
RsGetTexMapsFromMaterialNoStrip obj (mat.getsrcitem()) texmaplist maxsizelist isbumplist bSpeedTree exemptionList:exemptionList
|
|
|
|
) else if classof mat == Standardmaterial then (
|
|
|
|
--print "standard"
|
|
|
|
diffuseName = ""
|
|
|
|
doAlpha = false
|
|
subTexMap = getSubTexmap mat 1
|
|
|
|
if subTexMap == undefined then (
|
|
|
|
doAlpha = true
|
|
subTexMap = getSubTexmap mat 2
|
|
)
|
|
|
|
if classof subTexMap == DistanceAlphaMap then
|
|
(
|
|
--print "validation check 13"
|
|
subTexMap = RsGetDistanceAlphaMapResultMap subTexMap
|
|
)
|
|
if classof subTexMap == Bitmaptexture then (
|
|
|
|
if ( ( undefined != subTexMap.filename ) and ( "" != subTexMap.filename ) ) then (
|
|
|
|
texmapname = RsLowercase(subTexMap.filename)
|
|
|
|
diffuseName = texmapname
|
|
)
|
|
|
|
if doAlpha then (
|
|
|
|
subTexMap = getSubTexmap mat 7
|
|
|
|
if classof subTexMap == Bitmaptexture then (
|
|
|
|
if ( ( undefined != subTexMap.filename ) and ( "" != subTexMap.filename ) ) then (
|
|
|
|
if false == bSpeedTree then (
|
|
|
|
texmapname = RsLowercase(subTexMap.filename)
|
|
|
|
diffuseName = diffuseName + "+" + texmapname
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
if diffuseName != "" then (
|
|
|
|
diffuseName = RsMakeSafeTextureName(diffuseName)
|
|
|
|
if finditem texmaplist diffuseName == 0 then (
|
|
|
|
-- format "Texture map: %\n" diffuseName
|
|
--print RsDiffuseTexMaxSize
|
|
|
|
append texmaplist diffuseName
|
|
append maxsizelist RsDiffuseTexMaxSize
|
|
append isbumplist false
|
|
append exemptionList false
|
|
)
|
|
)
|
|
|
|
numTexMap = getNumSubTexmaps mat
|
|
|
|
for i = 1 to numTexMap do (
|
|
|
|
if (i != 2) and (i != 7) then (
|
|
|
|
subTexMap = getSubTexmap mat i
|
|
|
|
if classof subTexMap == DistanceAlphaMap then
|
|
(
|
|
--print "validation check 14"
|
|
subTexMap = RsGetDistanceAlphaMapResultMap subTexMap
|
|
)
|
|
if classof subTexMap == Bitmaptexture then (
|
|
|
|
if ( ( undefined != subTexMap.filename ) and ( "" != subTexMap.filename ) ) then (
|
|
|
|
texmapname = RsMakeSafeTextureName(RsLowercase(subTexMap.filename))
|
|
|
|
if finditem texmaplist texmapname == 0 then (
|
|
|
|
-- format "Texture map: %\n" texmapname
|
|
--print RsOtherTexMaxSize
|
|
|
|
append texmaplist texmapname
|
|
append maxsizelist RsOtherTexMaxSize
|
|
append exemptionList false
|
|
|
|
if i == 9 then (
|
|
append isbumplist true
|
|
) else (
|
|
append isbumplist false
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
) else if classof mat == Rage_Shader then (
|
|
|
|
--print "rage"
|
|
|
|
numTexMap = getNumSubTexmaps mat
|
|
|
|
if RstGetIsAlphaShader mat then (
|
|
|
|
numTexMap = numTexMap / 2
|
|
)
|
|
|
|
for i = 1 to numTexMap do (
|
|
|
|
texmapname = ""
|
|
|
|
subTexMap = getSubTexmap mat i
|
|
|
|
if classof subTexMap == DistanceAlphaMap then
|
|
(
|
|
--print "validation check 15"
|
|
subTexMap = RsGetDistanceAlphaMapResultMap subTexMap
|
|
)
|
|
if classof subTexMap == Bitmaptexture then (
|
|
|
|
if ( ( undefined != subTexMap.filename ) and ( "" != subTexMap.filename ) ) then (
|
|
|
|
texmapname = RsMakeSafeTextureName((RsLowercase(subTexMap.filename)))
|
|
)
|
|
|
|
if RstGetIsAlphaShader mat then (
|
|
|
|
local alphaTexMap = getSubTexmap mat (i + numTexMap)
|
|
|
|
if classof alphaTexMap == Bitmaptexture then (
|
|
|
|
if ( ( undefined != alphaTexMap.filename ) and ( "" != alphaTexMap.filename ) ) then (
|
|
|
|
texmapname += "+" + RsMakeSafeTextureName((RsLowercase(alphaTexMap.filename)))
|
|
)
|
|
)
|
|
)
|
|
)
|
|
else if classof subTexMap == CompositeTexturemap then (
|
|
|
|
numMaps = getnumsubtexmaps subTexMap
|
|
|
|
for j = 1 to numMaps do (
|
|
|
|
subsubTexMap = getSubTexmap subTexMap j
|
|
|
|
if classof subsubTexMap == Bitmaptexture then (
|
|
|
|
if ( ( undefined != subsubTexMap.filename ) and ( "" != subsubTexMap.filename ) ) then (
|
|
|
|
if j != 1 then (
|
|
|
|
texmapname += ">"
|
|
)
|
|
|
|
texmapname += RsMakeSafeTextureName(RsLowercase(subsubTexMap.filename))
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
if texmapname != "" then (
|
|
|
|
if finditem texmaplist texmapname == 0 then (
|
|
|
|
texmaptype = RsGetTexMapNameFromRsShader mat i
|
|
|
|
addMap = incDefault
|
|
|
|
if RsIsDiffuseMap texmaptype then addMap = incDiffuse
|
|
if RsIsSpecMap texmaptype then addMap = incSpec
|
|
if RsIsBumpMap texmaptype then addMap = incNormal
|
|
|
|
if addMap then (
|
|
|
|
append texmaplist texmapname
|
|
|
|
--format "Texture map: % (Rage_Shader)\n" texmapname
|
|
|
|
if RsIsBumpMap texmaptype then (
|
|
|
|
append isbumplist true
|
|
) else (
|
|
|
|
append isbumplist false
|
|
)
|
|
|
|
if RsIsResizeExempt subTexMap texmaptype then (
|
|
--print( texmapname + " with texmaptype of " + texmaptype + " is exempt" )
|
|
append exemptionList true
|
|
) else (
|
|
append exemptionList false
|
|
)
|
|
|
|
|
|
if RsIsDiffuseMap texmaptype then (
|
|
|
|
--print RsDiffuseTexMaxSize
|
|
|
|
append maxsizelist RsDiffuseTexMaxSize
|
|
) else (
|
|
|
|
--print RsOtherTexMaxSize
|
|
|
|
append maxsizelist RsOtherTexMaxSize
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
) else (
|
|
|
|
numTexMap = getNumSubTexmaps mat
|
|
|
|
for i = 1 to numTexMap do (
|
|
|
|
subTexMap = getSubTexmap mat i
|
|
|
|
if classof subTexMap == DistanceAlphaMap then
|
|
(
|
|
--print "validation check 0"
|
|
subTexMap = RsGetDistanceAlphaMapResultMap subTexMap
|
|
)
|
|
if classof subTexMap == Bitmaptexture then (
|
|
|
|
if subTexMap.filename != "" then (
|
|
|
|
texmapname = RsMakeSafeTextureName(RsLowercase(subTexMap.filename))
|
|
|
|
if finditem texmaplist texmapname == 0 then (
|
|
|
|
--print texmapname
|
|
|
|
append texmaplist texmapname
|
|
append isbumplist false
|
|
append exemptionList false
|
|
|
|
texmapname = RsGetTexMapNameFromRsShader mat i
|
|
|
|
if RsIsDiffuseMap texmapname then (
|
|
|
|
--print RsDiffuseTexMaxSize
|
|
|
|
append maxsizelist RsDiffuseTexMaxSize
|
|
) else (
|
|
|
|
--print RsOtherTexMaxSize
|
|
|
|
append maxsizelist RsOtherTexMaxSize
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
----------------------------------------------------------------------------------------
|
|
-- takes a texmaplist and strips the paths in it
|
|
----------------------------------------------------------------------------------------
|
|
fn RsStripPaths texmaplist = (
|
|
|
|
for i = 1 to texmaplist.count do (
|
|
|
|
texmaplist[i] = RsStripTexturePath(texmaplist[i])
|
|
)
|
|
)
|
|
|
|
----------------------------------------------------------------------------------------
|
|
-- fills texmaplist with the texture maps used by an object
|
|
----------------------------------------------------------------------------------------
|
|
fn RsGetTexMapsFromObjWithMapsRec obj texmaplist bitmaplist = (
|
|
|
|
if obj != undefined then (
|
|
|
|
RsGetTexMapsFromMaterialWithMap obj obj.material texmaplist bitmaplist
|
|
|
|
for childobj in obj.children do (
|
|
RsGetTexMapsFromObjWithMapsRec childobj texmaplist bitmaplist
|
|
)
|
|
|
|
if ( RsLodDrawable_HasLowerDetailModel obj ) then
|
|
(
|
|
local ldobj = ( RsLodDrawable_GetLowerDetailModel obj )
|
|
format "LD Model: RsGetTexMapsFromObjWithMapsRec %\n" ldobj
|
|
RsGetTexMapsFromObjWithMapsRec ldobj texmaplist bitmaplist
|
|
)
|
|
)
|
|
)
|
|
|
|
----------------------------------------------------------------------------------------
|
|
-- fills texmaplist with the texture maps used by an object
|
|
----------------------------------------------------------------------------------------
|
|
fn RsGetTexMapsFromObjWithMaps obj texmaplist bitmaplist id:-1 = (
|
|
|
|
incID = id
|
|
|
|
RsGetTexMapsFromObjWithMapsRec obj texmaplist bitmaplist
|
|
|
|
RsStripPaths texmaplist
|
|
|
|
incID = -1
|
|
)
|
|
|
|
----------------------------------------------------------------------------------------
|
|
-- fills texmaplist with the texture maps used by an object
|
|
----------------------------------------------------------------------------------------
|
|
fn RsGetTexMapsFromObjRec obj texmaplist maxsizelist isbumplist = (
|
|
|
|
if obj != undefined then (
|
|
|
|
RsGetTexMapsFromMaterial obj obj.material texmaplist maxsizelist isbumplist
|
|
|
|
for childobj in obj.children do (
|
|
|
|
RsGetTexMapsFromObjRec childobj texmaplist maxsizelist isbumplist
|
|
)
|
|
|
|
if ( RsLodDrawable_HasLowerDetailModel obj ) then
|
|
(
|
|
local ldobj = ( RsLodDrawable_GetLowerDetailModel obj )
|
|
format "LD Model: RsGetTexMapsFromObjWithMapsRec %\n" ldobj
|
|
RsGetTexMapsFromObjRec ldobj texmaplist maxsizelist isbumplist
|
|
)
|
|
)
|
|
)
|
|
|
|
----------------------------------------------------------------------------------------
|
|
-- fills texmaplist with the texture maps used by an object
|
|
----------------------------------------------------------------------------------------
|
|
fn RsGetTexMapsFromObj obj texmaplist maxsizelist isbumplist = (
|
|
|
|
RsGetTexMapsFromObjRec obj texmaplist maxsizelist isbumplist
|
|
|
|
RsStripPaths texmaplist
|
|
)
|
|
|
|
----------------------------------------------------------------------------------------
|
|
-- fills texmaplist with the texture maps used by an object
|
|
----------------------------------------------------------------------------------------
|
|
fn RsGetTexMapsFromObjNoStripRec obj texmaplist maxsizelist isbumplist exemptionList:#() = (
|
|
|
|
bSpeedTree = classof obj == SpeedTree_4
|
|
RsGetTexMapsFromMaterialNoStrip obj obj.material texmaplist maxsizelist isbumplist bSpeedTree exemptionList:exemptionList
|
|
|
|
for childobj in obj.children do (
|
|
|
|
RsGetTexMapsFromObjNoStripRec childobj texmaplist maxsizelist isbumplist exemptionList:exemptionList
|
|
)
|
|
|
|
if ( RsLodDrawable_HasLowerDetailModel obj ) then
|
|
(
|
|
local ldobj = ( RsLodDrawable_GetLowerDetailModel obj )
|
|
format "LD Model: RsGetTexMapsFromObjWithMapsRec %\n" ldobj
|
|
RsGetTexMapsFromObjNoStripRec ldobj texmaplist maxsizelist isbumplist exemptionList:exemptionList
|
|
)
|
|
)
|
|
|
|
----------------------------------------------------------------------------------------
|
|
-- fills texmaplist with the texture maps used by an object
|
|
----------------------------------------------------------------------------------------
|
|
fn RsGetTexMapsFromObjNoStrip obj texmaplist maxsizelist isbumplist exemptionList:#() = (
|
|
|
|
bSpeedTree = classof obj == SpeedTree_4
|
|
RsGetTexMapsFromObjNoStripRec obj texmaplist maxsizelist isbumplist exemptionList:exemptionList
|
|
|
|
retval = true
|
|
|
|
if bSpeedTree then (
|
|
|
|
retval = RsConvertAndAppendSpeedTree obj texmaplist maxsizelist isbumplist
|
|
)
|
|
|
|
retval
|
|
)
|
|
|
|
----------------------------------------------------------------------------------------
|
|
--
|
|
----------------------------------------------------------------------------------------
|
|
fn RsMergeTextureUsage texmaplist maxsizelist isbumplist usagelist exemptionlist objtexmaplist objmaxsizelist objisbumplist infiniteusage objexemptionlist = (
|
|
|
|
for i = 1 to objtexmaplist.count do (
|
|
|
|
objtexmap = objtexmaplist[i]
|
|
|
|
idxFound = finditem texmaplist objtexmap
|
|
|
|
if idxFound == 0 then (
|
|
|
|
append texmaplist objtexmap
|
|
append maxsizelist objmaxsizelist[i]
|
|
append isbumplist objisbumplist[i]
|
|
append exemptionlist objexemptionlist[i]
|
|
|
|
if infiniteusage then (
|
|
|
|
append usagelist -1
|
|
) else (
|
|
|
|
append usagelist 1
|
|
)
|
|
) else (
|
|
|
|
if infiniteusage or usagelist[idxFound] == -1 then (
|
|
|
|
usagelist[idxFound] = -1
|
|
) else (
|
|
|
|
usagelist[idxFound] = usagelist[idxFound] + 1
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
----------------------------------------------------------------------------------------
|
|
--
|
|
----------------------------------------------------------------------------------------
|
|
fn RsIsTXDUsedOnLod txdname srcobjlist:rootnode.children = (
|
|
|
|
idxTXD = getattrindex "Gta Object" "TXD"
|
|
allobjs = #()
|
|
|
|
RsGetMapObjects srcobjlist allobjs
|
|
|
|
for obj in allobjs do (
|
|
|
|
if (getattrclass obj == "Gta Object") and (classof obj != XRefObject) then (
|
|
|
|
if RsLowercase(getattr obj idxTXD) == txdname then (
|
|
|
|
if RsIsAnyLOD obj then (
|
|
|
|
return true
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
false
|
|
)
|
|
|
|
----------------------------------------------------------------------------------------
|
|
-- fills texmaplist with the texture maps used by all objects with specified txd
|
|
----------------------------------------------------------------------------------------
|
|
fn RsGetTexMapsByTxdNameNoStrip texmaplist maxsizelist isbumplist usagelist txdname srcobjlist:rootnode.children isCutsceneObject:false exemptionlist:#() = (
|
|
|
|
txdname = RsLowercase txdname
|
|
idxTXD = getattrindex "Gta Object" "TXD"
|
|
idxModelGroup = getattrindex "Gta Object" "Model Group"
|
|
idxFragment = getattrindex "Gta Object" "Is Fragment"
|
|
|
|
allobjs = #()
|
|
|
|
RsGetMapObjects srcobjlist allobjs isCutsceneObject:isCutsceneObject
|
|
|
|
for obj in allobjs do (
|
|
|
|
if classof obj == Gta_MILO then (
|
|
|
|
for childobj in obj.children do (
|
|
|
|
if (getattrclass childobj == "Gta Object") and (classof childobj != XRefObject) then (
|
|
|
|
if RsLowercase(getattr childobj idxTXD) == txdname then (
|
|
|
|
objtexmaplist = #()
|
|
objmaxsizelist = #()
|
|
objisbumplist = #()
|
|
objexemptionlist = #()
|
|
|
|
RsGetTexMapsFromObjNoStrip childobj objtexmaplist objmaxsizelist objisbumplist exemptionlist:objexemptionlist
|
|
RsMergeTextureUsage texmaplist maxsizelist isbumplist usagelist exemptionlist objtexmaplist objmaxsizelist objisbumplist false objexemptionlist
|
|
)
|
|
)
|
|
)
|
|
)
|
|
else if classof obj == SpeedTree_4 then (
|
|
|
|
if (getattrclass obj == "Gta Object") and (classof obj != XRefObject) then (
|
|
|
|
if RsLowercase(getattr obj idxTXD) == txdname then (
|
|
|
|
objtexmaplist = #()
|
|
objmaxsizelist = #()
|
|
objisbumplist = #()
|
|
objexemptionlist = #()
|
|
|
|
RsGetTexMapsFromObjNoStrip obj objtexmaplist objmaxsizelist objisbumplist exemptionlist:objexemptionlist
|
|
RsMergeTextureUsage texmaplist maxsizelist isbumplist usagelist exemptionlist objtexmaplist objmaxsizelist objisbumplist true objexemptionlist
|
|
)
|
|
)
|
|
)
|
|
else (
|
|
|
|
if (getattrclass obj == "Gta Object") and (classof obj != XRefObject) then (
|
|
|
|
if RsLowercase(getattr obj idxTXD) == txdname then (
|
|
|
|
--print ("object: " + obj.name)
|
|
|
|
objtexmaplist = #()
|
|
objmaxsizelist = #()
|
|
objisbumplist = #()
|
|
objexemptionlist = #()
|
|
|
|
infiniteUsage = false
|
|
valModelGroup = getattr obj idxModelGroup
|
|
valFragment = getattr obj idxFragment
|
|
|
|
if valModelGroup != "null" then infiniteUsage = true
|
|
if valFragment == true then infiniteUsage = true
|
|
|
|
RsGetTexMapsFromObjNoStrip obj objtexmaplist objmaxsizelist objisbumplist exemptionlist:objexemptionlist
|
|
RsMergeTextureUsage texmaplist maxsizelist isbumplist usagelist exemptionlist objtexmaplist objmaxsizelist objisbumplist infiniteUsage objexemptionlist
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
----------------------------------------------------------------------------------------
|
|
-- fills texmaplist with the texture maps used by all objects with specified txd
|
|
----------------------------------------------------------------------------------------
|
|
fn RsGetTexMapsByTxdName texmaplist maxsizelist isbumplist usagelist txdname srcobjlist:rootnode.children isCutsceneObject:false resizeexemptionlist:#() = (
|
|
|
|
newtexmaplist = #()
|
|
newmaxsizelist = #()
|
|
newisbumplist = #()
|
|
newusagelist = #()
|
|
newresizeexemptionlist = #()
|
|
|
|
|
|
|
|
RsGetTexMapsByTxdNameNoStrip newtexmaplist newmaxsizelist newisbumplist newusagelist txdname srcobjlist:srcobjlist isCutsceneObject:isCutsceneObject exemptionlist:resizeexemptionlist
|
|
|
|
RsStripPaths newtexmaplist
|
|
|
|
-- we need to do this because there will be multiple entries if the same texture name
|
|
-- has been used from a different path or extension
|
|
|
|
for i = 1 to newtexmaplist.count do (
|
|
|
|
texmap = newtexmaplist[i]
|
|
|
|
idxFound = finditem texmaplist texmap
|
|
|
|
if idxFound == 0 then (
|
|
|
|
append texmaplist newtexmaplist[i]
|
|
append maxsizelist newmaxsizelist[i]
|
|
append isbumplist newisbumplist[i]
|
|
append usagelist newusagelist[i]
|
|
append resizeexemptionlist newresizeexemptionlist[i]
|
|
|
|
) else if usagelist[idxFound] != -1 and newusagelist[i] != -1 then (
|
|
|
|
usagelist[idxFound] = usagelist[idxFound] + newusagelist[i]
|
|
) else if newusagelist[i] == -1 then (
|
|
|
|
usagelist[idxFound] = -1
|
|
)
|
|
)
|
|
)
|
|
|
|
----------------------------------------------------------------------------------------
|
|
--
|
|
----------------------------------------------------------------------------------------
|
|
fn RsGetTxdFromObject obj txdlist txdobjlist = (
|
|
|
|
idxGroupTXD = getattrindex "Gta Group" "TXD"
|
|
idxTXD = getattrindex "Gta Object" "TXD"
|
|
idxDontExport = GetAttrIndex "Gta Object" "Dont Export"
|
|
|
|
if getattrclass obj == "Gta Object" and (classof obj != XRefObject) and (classof obj != InternalRef) then (
|
|
|
|
valDontExport = getattr obj idxDontExport
|
|
|
|
if valDontExport == false then (
|
|
|
|
txd = RsLowercase(getattr obj idxTXD)
|
|
|
|
ixdTxd = finditem txdlist txd
|
|
|
|
if ixdTxd == 0 then (
|
|
|
|
append txdlist txd
|
|
append txdobjlist #(obj)
|
|
) else (
|
|
|
|
append txdobjlist[ixdTxd] obj
|
|
)
|
|
)
|
|
) else if Container == classof obj then (
|
|
|
|
-- Iterate through container's children.
|
|
if ( obj.IsOpen() ) then
|
|
(
|
|
for o in obj.children do
|
|
(
|
|
RsGetTxdFromObject o txdlist txdobjlist
|
|
)
|
|
)
|
|
|
|
) else if classof obj == GtaGroup then (
|
|
|
|
txd = RsLowercase(getattr obj idxGroupTXD)
|
|
|
|
ixdTxd = finditem txdlist txd
|
|
|
|
if ixdTxd == 0 then (
|
|
|
|
append txdlist txd
|
|
append txdobjlist #(obj)
|
|
) else (
|
|
|
|
append txdobjlist[ixdTxd] obj
|
|
)
|
|
)
|
|
)
|
|
|
|
----------------------------------------------------------------------------------------
|
|
-- get all the txd names in the scene
|
|
----------------------------------------------------------------------------------------
|
|
fn RsGetTxdList objlist txdlist txdobjlist = (
|
|
|
|
for obj in objlist do (
|
|
|
|
if classof obj == Gta_MILO then (
|
|
|
|
for childobj in obj.children do (
|
|
|
|
if classof childobj == GtaMloRoom then (
|
|
|
|
for actualobj in childobj.children do (
|
|
|
|
RsGetTxdFromObject actualobj txdlist txdobjlist
|
|
)
|
|
) else (
|
|
|
|
RsGetTxdFromObject childobj txdlist txdobjlist
|
|
)
|
|
)
|
|
) else (
|
|
|
|
RsGetTxdFromObject obj txdlist txdobjlist
|
|
)
|
|
)
|
|
|
|
idxItem = finditem txdlist "null"
|
|
if idxItem != 0 then (
|
|
|
|
deleteitem txdlist idxItem
|
|
deleteitem txdobjlist idxItem
|
|
)
|
|
|
|
-- sort txdlist
|
|
)
|
|
|
|
----------------------------------------------------------------------------------------
|
|
-- get all the txd names in the scene
|
|
----------------------------------------------------------------------------------------
|
|
fn RsGetSortedTxdList objlist txdlist = (
|
|
|
|
txdobjlist = #()
|
|
|
|
RsGetTxdList objlist txdlist txdobjlist
|
|
|
|
sort txdlist
|
|
)
|
|
|
|
|
|
----------------------------------------------------------------------------------------
|
|
--
|
|
----------------------------------------------------------------------------------------
|
|
fn RsStdMatIsMapUsedByObject obj mapidx = (
|
|
|
|
retval = false
|
|
|
|
objmat = obj.material
|
|
|
|
if objmat != undefined then (
|
|
|
|
if classof objmat == XRef_Material then (
|
|
|
|
objmat = objmat.getsrcitem()
|
|
)
|
|
|
|
if classof objmat == Standardmaterial then (
|
|
|
|
if objmat.mapEnables[mapidx] == true then (
|
|
|
|
retval = true
|
|
)
|
|
)
|
|
else if classof objmat == Multimaterial then (
|
|
|
|
mapList = #()
|
|
RsMatGetMapIdsUsedOnObject obj mapList
|
|
|
|
for i = 1 to objmat.materialList.count do (
|
|
|
|
id = objmat.materialIDList[i]
|
|
|
|
if retval == false and finditem mapList id != 0 then (
|
|
|
|
mat = objmat.materialList[i]
|
|
|
|
if classof mat == Standardmaterial then (
|
|
|
|
if mat.mapEnables[mapidx] == true then (
|
|
|
|
retval = true
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
retval
|
|
)
|
|
|
|
----------------------------------------------------------------------------------------
|
|
--
|
|
----------------------------------------------------------------------------------------
|
|
fn RsDoesObjUseShader obj shaderName = (
|
|
|
|
retval = false
|
|
|
|
if classof obj == Editable_Mesh or classof obj == Editable_Poly then (
|
|
|
|
objmat = obj.material
|
|
|
|
if objmat != undefined then (
|
|
|
|
if classof objmat == XRef_Material then (
|
|
|
|
objmat = objmat.getsrcitem()
|
|
)
|
|
)
|
|
|
|
if objmat != undefined then (
|
|
|
|
if classof objmat == Multimaterial then (
|
|
|
|
mapList = #()
|
|
RsMatGetMapIdsUsedOnObject obj mapList
|
|
|
|
for i = 1 to objmat.materialList.count do (
|
|
|
|
if retval == false then (
|
|
|
|
id = objmat.materialIDList[i]
|
|
|
|
if finditem mapList id != 0 then (
|
|
|
|
mat = objmat.materialList[i]
|
|
|
|
if classof mat == Rage_Shader then (
|
|
|
|
if (RsRemoveExtension(RstGetShaderName mat)) == shaderName then (
|
|
|
|
retval = true
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
if classof objmat == Rage_Shader then (
|
|
|
|
if (RsRemoveExtension(RstGetShaderName objmat)) == shaderName then (
|
|
|
|
retval = true
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
retval
|
|
)
|
|
|
|
----------------------------------------------------------------------------------------
|
|
--
|
|
----------------------------------------------------------------------------------------
|
|
fn RsGetObjFacesUsingShader obj shaderName faceidlistout = (
|
|
|
|
retval = false
|
|
|
|
if classof obj == Editable_Mesh or classof obj == Editable_Poly then (
|
|
|
|
objmat = obj.material
|
|
|
|
if objmat != undefined then (
|
|
|
|
if classof objmat == XRef_Material then (
|
|
|
|
objmat = objmat.getsrcitem()
|
|
)
|
|
)
|
|
|
|
if objmat != undefined then (
|
|
|
|
if classof objmat == Multimaterial then (
|
|
|
|
mapList = #()
|
|
polyCountList = #()
|
|
faceIDLists = #()
|
|
|
|
RsMatGetMapIdsUsedOnObjectWithCount obj mapList polycount:polyCountList faceidlists:faceIDLists
|
|
|
|
for i = 1 to objmat.materialList.count do (
|
|
|
|
id = objmat.materialIDList[i]
|
|
idxFound = finditem mapList id
|
|
|
|
if idxFound != 0 then (
|
|
|
|
mat = objmat.materialList[i]
|
|
|
|
if classof mat == Rage_Shader then (
|
|
|
|
if (RsRemoveExtension(RstGetShaderName mat)) == shaderName then (
|
|
|
|
for item in faceIDLists[idxFound] do (
|
|
|
|
append faceidlistout item
|
|
)
|
|
|
|
retval = true
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
if classof objmat == Rage_Shader then (
|
|
|
|
if (RsRemoveExtension(RstGetShaderName objmat)) == shaderName then (
|
|
|
|
retval = true
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
retval
|
|
)
|
|
|
|
----------------------------------------------------------------------------------------
|
|
--
|
|
----------------------------------------------------------------------------------------
|
|
fn RsGetActualShaderName shaderName alpha = (
|
|
|
|
shaderName = RsRemoveExtension(shaderName)
|
|
|
|
if alpha then (
|
|
/*
|
|
if shaderName == "gta_default" then (
|
|
|
|
shaderName = "gta_alpha"
|
|
)
|
|
else if shaderName == "gta_normal" then (
|
|
|
|
shaderName = "gta_normal_alpha"
|
|
)
|
|
else if shaderName == "gta_normal_spec" then (
|
|
|
|
shaderName = "gta_normal_spec_alpha"
|
|
)
|
|
else if shaderName == "gta_normal_spec_reflect" then (
|
|
|
|
shaderName = "gta_normal_spec_reflect_alpha"
|
|
)
|
|
else if shaderName == "gta_normal_reflect" then (
|
|
|
|
shaderName = "gta_normal_reflect_alpha"
|
|
)
|
|
else if shaderName == "gta_spec" then (
|
|
|
|
shaderName = "gta_spec_alpha"
|
|
)
|
|
else if shaderName == "gta_spec_reflect" then (
|
|
|
|
shaderName = "gta_spec_reflect_alpha"
|
|
)
|
|
else if shaderName == "gta_reflect" then (
|
|
|
|
shaderName = "gta_reflect_alpha"
|
|
) */
|
|
if shaderName == "gta_emissive" then (
|
|
|
|
shaderName = "gta_emissive_alpha"
|
|
)
|
|
else if shaderName == "gta_emissivestrong" then (
|
|
|
|
shaderName = "gta_emissivestrong_alpha"
|
|
)
|
|
else if shaderName == "gta_emissivenight" then (
|
|
|
|
shaderName = "gta_emissivenight_alpha"
|
|
)
|
|
else if shaderName == "gta_normal_spec_reflect_emissive" then (
|
|
|
|
shaderName = "gta_normal_spec_reflect_emissive_alpha"
|
|
)
|
|
else if shaderName == "gta_normal_spec_reflect_emissivenight" then (
|
|
|
|
shaderName = "gta_normal_spec_reflect_emissivenight_alpha"
|
|
)
|
|
else if shaderName == "gta_glass_emissive" then (
|
|
|
|
shaderName = "gta_glass_emissive_alpha"
|
|
)
|
|
else if shaderName == "gta_glass_emissivenight" then (
|
|
|
|
shaderName = "gta_glass_emissivenight_alpha"
|
|
)
|
|
|
|
) else (
|
|
/*
|
|
if shaderName == "gta_alpha" then (
|
|
|
|
shaderName = "gta_default"
|
|
)
|
|
else if shaderName == "gta_normal_alpha" then (
|
|
|
|
shaderName = "gta_normal"
|
|
)
|
|
else if shaderName == "gta_normal_spec_alpha" then (
|
|
|
|
shaderName = "gta_normal_spec"
|
|
)
|
|
else if shaderName == "gta_normal_spec_reflect_alpha" then (
|
|
|
|
shaderName = "gta_normal_spec_reflect"
|
|
)
|
|
else if shaderName == "gta_normal_reflect_alpha" then (
|
|
|
|
shaderName = "gta_normal_reflect"
|
|
)
|
|
else if shaderName == "gta_spec_alpha" then (
|
|
|
|
shaderName = "gta_spec"
|
|
)
|
|
else if shaderName == "gta_spec_reflect_alpha" then (
|
|
|
|
shaderName = "gta_spec_reflect"
|
|
)
|
|
else if shaderName == "gta_reflect_alpha" then (
|
|
|
|
shaderName = "gta_reflect"
|
|
)*/
|
|
if shaderName == "gta_emissive_alpha" then (
|
|
|
|
shaderName = "gta_emissive"
|
|
)
|
|
else if shaderName == "gta_emissivestrong_alpha" then (
|
|
|
|
shaderName = "gta_emissivestrong"
|
|
)
|
|
else if shaderName == "gta_emissivenight_alpha" then (
|
|
|
|
shaderName = "gta_emissivenight"
|
|
)
|
|
else if shaderName == "gta_normal_spec_reflect_emissive_alpha" then (
|
|
|
|
shaderName = "gta_normal_spec_reflect_emissive"
|
|
)
|
|
else if shaderName == "gta_normal_spec_reflect_emissivenight_alpha" then (
|
|
|
|
shaderName = "gta_normal_spec_reflect_emissivenight"
|
|
)
|
|
else if shaderName == "gta_glass_emissive_alpha" then (
|
|
|
|
shaderName = "gta_glass_emissive"
|
|
)
|
|
else if shaderName == "gta_glass_emissivenight_alpha" then (
|
|
|
|
shaderName = "gta_glass_emissivenight"
|
|
)
|
|
)
|
|
|
|
shaderName
|
|
)
|
|
|
|
----------------------------------------------------------------------------------------
|
|
--
|
|
----------------------------------------------------------------------------------------
|
|
fn RsCheckIsAlphad obj = (
|
|
|
|
isAlpha = false
|
|
|
|
if classof obj == Editable_Mesh or classof obj == Editable_Poly then (
|
|
|
|
objmat = obj.material
|
|
|
|
if objmat != undefined then (
|
|
|
|
if classof objmat == XRef_Material then (
|
|
|
|
objmat = objmat.getsrcitem()
|
|
)
|
|
)
|
|
|
|
if objmat != undefined then (
|
|
|
|
if classof objmat == Multimaterial then (
|
|
|
|
mapList = #()
|
|
RsMatGetMapIdsUsedOnObject obj mapList
|
|
|
|
for i = 1 to objmat.materialList.count do (
|
|
|
|
id = objmat.materialIDList[i]
|
|
|
|
if finditem mapList id != 0 then (
|
|
|
|
mat = objmat.materialList[i]
|
|
|
|
if rexHasAlpha obj mat then (
|
|
|
|
isAlpha = true
|
|
)
|
|
)
|
|
)
|
|
)
|
|
else (
|
|
|
|
if rexHasAlpha obj objmat then (
|
|
|
|
isAlpha = true
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
isAlpha
|
|
)
|
|
|
|
|
|
----------------------------------------------------------------------------------------
|
|
--
|
|
----------------------------------------------------------------------------------------
|
|
fn RsCheckAlphaShaders obj = (
|
|
|
|
if classof obj == Editable_Mesh or classof obj == Editable_Poly then (
|
|
|
|
objmat = obj.material
|
|
|
|
if objmat != undefined then (
|
|
|
|
if classof objmat == XRef_Material then (
|
|
|
|
objmat = objmat.getsrcitem()
|
|
)
|
|
)
|
|
|
|
if objmat != undefined then (
|
|
|
|
if classof objmat == Multimaterial then (
|
|
|
|
mapList = #()
|
|
RsMatGetMapIdsUsedOnObject obj mapList
|
|
|
|
for i = 1 to objmat.materialList.count do (
|
|
|
|
id = objmat.materialIDList[i]
|
|
|
|
if finditem mapList id != 0 then (
|
|
|
|
mat = objmat.materialList[i]
|
|
|
|
if classof mat == Rage_Shader then (
|
|
|
|
shaderName = RsLowercase (RstGetShaderName mat)
|
|
shaderActualName = (RsGetActualShaderName shaderName (rexHasAlpha obj mat))
|
|
|
|
if shaderActualName != shaderName and shaderActualName != undefined then (
|
|
|
|
RstSetShaderName mat shaderActualName
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
else if classof objmat == Rage_Shader then (
|
|
|
|
shaderName = RsLowercase (RstGetShaderName objmat)
|
|
shaderActualName = (RsGetActualShaderName shaderName (rexHasAlpha obj objmat))
|
|
|
|
if shaderActualName != shaderName then (
|
|
|
|
RstSetShaderName objmat shaderActualName
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
----------------------------------------------------------------------------------------
|
|
--
|
|
----------------------------------------------------------------------------------------
|
|
fn RsDoesObjUseShaderOnly obj shaderName = (
|
|
|
|
retval = false
|
|
|
|
if classof obj == Editable_Mesh or classof obj == Editable_Poly then (
|
|
|
|
objmat = obj.material
|
|
|
|
if objmat != undefined then (
|
|
|
|
if classof objmat == XRef_Material then (
|
|
|
|
objmat = objmat.getsrcitem()
|
|
)
|
|
)
|
|
|
|
if objmat != undefined then (
|
|
|
|
retval = true
|
|
|
|
if classof objmat == Multimaterial then (
|
|
|
|
mapList = #()
|
|
RsMatGetMapIdsUsedOnObject obj mapList
|
|
|
|
-- check that the objects map id's are available in the material
|
|
|
|
for mapListID in mapList do (
|
|
|
|
if retval == true then (
|
|
|
|
if finditem objmat.materialIDList mapListID == 0 then (
|
|
|
|
retval = false
|
|
)
|
|
)
|
|
)
|
|
|
|
if retval == true then (
|
|
|
|
for i = 1 to objmat.materialList.count do (
|
|
|
|
if retval == true then (
|
|
|
|
id = objmat.materialIDList[i]
|
|
|
|
if finditem mapList id != 0 then (
|
|
|
|
mat = objmat.materialList[i]
|
|
|
|
if classof mat == Rage_Shader then (
|
|
|
|
if (RsRemoveExtension(RstGetShaderName mat)) != shaderName then (
|
|
|
|
retval = false
|
|
)
|
|
) else retval = false
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
else if classof objmat == Rage_Shader then (
|
|
|
|
if (RsRemoveExtension(RstGetShaderName objmat)) != shaderName then (
|
|
|
|
retval = false
|
|
)
|
|
)
|
|
else retval = false
|
|
)
|
|
)
|
|
|
|
retval
|
|
)
|
|
|
|
----------------------------------------------------------------------------------------
|
|
--
|
|
----------------------------------------------------------------------------------------
|
|
fn RsDoesObjUseInstanceShaderOnly obj = (
|
|
|
|
return RsDoesObjUseShaderOnly obj "gta_diffuse_instance"
|
|
)
|
|
|
|
----------------------------------------------------------------------------------------
|
|
--
|
|
----------------------------------------------------------------------------------------
|
|
fn RsDoesObjUseInstanceShader obj = (
|
|
|
|
return RsDoesObjUseShader obj "gta_diffuse_instance"
|
|
)
|
|
|
|
----------------------------------------------------------------------------------------
|
|
--
|
|
----------------------------------------------------------------------------------------
|
|
fn RsDoesObjUseGlassShader obj = (
|
|
|
|
retval = false
|
|
|
|
if RsDoesObjUseShader obj "gta_glass" then retval = true
|
|
if RsDoesObjUseShader obj "gta_vehicle_glass" then retval = true
|
|
if RsDoesObjUseShader obj "gta_glass_spec" then retval = true
|
|
if RsDoesObjUseShader obj "gta_glass_reflect" then retval = true
|
|
if RsDoesObjUseShader obj "gta_glass_emissive" then retval = true
|
|
if RsDoesObjUseShader obj "gta_glass_emissivenight" then retval = true
|
|
if RsDoesObjUseShader obj "gta_glass_normal_spec_reflect" then retval = true
|
|
if RsDoesObjUseShader obj "gta_vehicle_glass_dmg" then retval = true
|
|
|
|
retval
|
|
)
|
|
|
|
fn GetCompositeFileName fileNameIn = (
|
|
-- Sort Wierdness in SpeedTreeCad where sometimes
|
|
-- the compositefilename stored in the .spt file
|
|
-- will not have the ".tga" extension amd sometimes it will
|
|
|
|
strExt = substring fileNameIn (fileNameIn.count - 3) 4
|
|
if strExt == ".tga" then (
|
|
fileNameOut = fileNameIn
|
|
)
|
|
else (
|
|
fileNameOut = fileNameIn + ".tga"
|
|
)
|
|
return fileNameOut
|
|
)
|
|
|
|
fn RsConvertAndAppendSpeedTree obj texmaplist maxsizelist isbumplist = (
|
|
-- Convert SpeedTree Composite file to ".dds" file
|
|
-- and append it to the texturemap list
|
|
|
|
-- Get Spt file From Obj
|
|
mapName = (filterstring maxfilename ".")[1]
|
|
SptFileName = RsConfigGetMapStreamDir() + "maps/" + mapName + "/" + obj.name + "/" + obj.name + ".spt"
|
|
files = getFiles SptFileName
|
|
if files.count == 0 then (
|
|
msg = "Cannot Find File : " + SptFileName + " - It may need exporting"
|
|
MessageBox msg
|
|
return false
|
|
)
|
|
|
|
strPath = RsConfigGetSpeedTexDir()
|
|
strOutPath = RsConfigGetTexDir()
|
|
|
|
-- Get Composite File Name
|
|
compositeFileName = GetSpeedTreeCompositeFile SptFileName
|
|
|
|
if compositeFileName == false then (
|
|
|
|
srcFolder = RsConfigGetMapStreamDir() + "maps/" + mapName + "/" + obj.name + "/build/out/"
|
|
|
|
SptFileName = srcFolder + obj.name + ".spt"
|
|
|
|
files = getFiles SptFileName
|
|
if files.count == 0 then (
|
|
msg = "Cannot Find File : " + SptFileName + " - It may need exporting"
|
|
MessageBox msg
|
|
return false
|
|
)
|
|
|
|
compositeFileName = GetSpeedTreeCompositeFile SptFileName
|
|
|
|
if compositeFileName != false then (
|
|
|
|
compositeFileName = RsRemovePathAndExtension(compositeFileName)
|
|
|
|
inputFile = (srcFolder + compositeFileName + ".dds")
|
|
outputFile = (strOutPath + compositeFileName + ".dds")
|
|
|
|
rexExportTexture inputFile outputFile
|
|
|
|
append texmaplist outputFile
|
|
append maxsizelist RsDiffuseTexMaxSize
|
|
append isbumplist false
|
|
)
|
|
|
|
) else (
|
|
|
|
compositeFileName = RsRemovePathAndExtension(compositeFileName)
|
|
|
|
fileToFind = strPath + compositeFileName + ".tga"
|
|
inputFiles = getfiles fileToFind
|
|
|
|
if(inputFiles.count != 0) then (
|
|
|
|
inputFile = inputFiles[1]
|
|
-- exit
|
|
)
|
|
|
|
if(inputFile == undefined) then (
|
|
|
|
msg = "Can't find Composite File : (" + fileToFind + ") for SpeedTree :" + obj.name
|
|
MessageBox msg
|
|
return true
|
|
)
|
|
|
|
outputFile = (strOutPath + compositeFileName + ".dds")
|
|
|
|
rexExportTexture inputFile outputFile
|
|
|
|
append texmaplist outputFile
|
|
append maxsizelist RsDiffuseTexMaxSize
|
|
append isbumplist false
|
|
)
|
|
|
|
true
|
|
)
|
|
|
|
|
|
---------------------------------------------------------------------------------
|
|
-- Return whether the specified object uses the specified shader
|
|
--
|
|
-- This is an enhanced version of the RsDoesObjUseShader2 above as it also
|
|
-- considers Standard materials that can be converted to shaders.
|
|
--
|
|
-- [return] true iff object uses shader, false otherwise
|
|
---------------------------------------------------------------------------------
|
|
fn RsDoesObjUseShader2 obj shaderName = (
|
|
|
|
retval = false
|
|
|
|
if classof obj == Editable_Mesh or classof obj == Editable_Poly then (
|
|
|
|
objmat = obj.material
|
|
|
|
if objmat != undefined then (
|
|
|
|
if classof objmat == XRef_Material then (
|
|
|
|
objmat = objmat.getsrcitem()
|
|
)
|
|
)
|
|
|
|
if objmat != undefined then (
|
|
|
|
if classof objmat == Multimaterial then (
|
|
|
|
mapList = #()
|
|
RsMatGetMapIdsUsedOnObject obj mapList
|
|
|
|
for i = 1 to objmat.materialList.count do (
|
|
|
|
if retval == false then (
|
|
|
|
id = objmat.materialIDList[i]
|
|
|
|
if finditem mapList id != 0 then (
|
|
|
|
mat = objmat.materialList[i]
|
|
|
|
if classof mat == Rage_Shader then (
|
|
|
|
if (RsRemoveExtension(RstGetShaderName mat)) == shaderName then (
|
|
|
|
retval = true
|
|
)
|
|
)
|
|
else if classof mat == Standardmaterial then (
|
|
|
|
-- Check materials shader equivalent (if available)
|
|
matShaderName = ( rexStdMatShaderName mat )
|
|
if ( String != classof matShaderName ) then
|
|
continue
|
|
|
|
if ( RsRemoveExtension( matShaderName ) == shaderName ) then (
|
|
|
|
retval = true
|
|
)
|
|
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
if classof objmat == Rage_Shader then (
|
|
|
|
if (RsRemoveExtension(RstGetShaderName objmat)) == shaderName then (
|
|
|
|
retval = true
|
|
)
|
|
)
|
|
else if classof objmat == Standardmaterial then (
|
|
|
|
-- Check materials shader equivalent (if available)
|
|
matShaderName = ( rexStdMatShaderName objmat )
|
|
if ( String != classof matShaderName ) then
|
|
continue
|
|
|
|
if ( RsRemoveExtension( matShaderName ) == shaderName ) then (
|
|
retval = true
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
retval
|
|
)
|
|
|
|
---------------------------------------------------------------------------------
|
|
-- Return number of Rage Shader and Standard materials (and submaterials)
|
|
-- only Standard materials that can be converted to Rage Shaders are included.
|
|
--
|
|
-- [return] Number of Rage Shader supported materials in the scene
|
|
---------------------------------------------------------------------------------
|
|
function RsGetMaterialCount &numRageShaderMaterials &numShaderStandardMaterials &numStandardMaterials = (
|
|
|
|
numRageShaderMaterials = 0
|
|
numShaderStandardMaterials = 0
|
|
numStandardMaterials = 0
|
|
|
|
for mat in sceneMaterials do
|
|
(
|
|
if ( Rage_Shader == classof mat ) then
|
|
numRageShaderMaterials += 1
|
|
|
|
else if ( Standard == classof mat ) then
|
|
(
|
|
shaderName = ( rexStdMatShaderName mat )
|
|
if ( String == classof shaderName ) then
|
|
numShaderStandardMaterials += 1
|
|
else
|
|
numStandardMaterials += 1
|
|
)
|
|
|
|
else if ( Multimaterial == classof mat ) then
|
|
(
|
|
for submat in mat.materialList do
|
|
(
|
|
if ( Rage_Shader == classof submat ) then
|
|
numRageShaderMaterials += 1
|
|
else if ( Standard == classof mat ) then
|
|
(
|
|
shaderName = ( rexStdMatShaderName mat )
|
|
if ( String == classof shaderName ) then
|
|
numShaderStandardMaterials += 1
|
|
else
|
|
numStandardMaterials += 1
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
true
|
|
)
|
|
|
|
---------------------------------------------------------------------------------
|
|
-- Return list of shaders
|
|
--
|
|
-- [return] Array of shader name strings (path and extension removed)
|
|
---------------------------------------------------------------------------------
|
|
function RsGetShaderList = (
|
|
|
|
spsPath = RsConfigGetCommonDir() + "shaders/db/*.sps"
|
|
tempShaderList = #()
|
|
tempShaderList = getFiles spsPath
|
|
|
|
shaderList = #()
|
|
for sh in tempShaderList do
|
|
(
|
|
append shaderList ( RsRemovePathAndExtension sh )
|
|
)
|
|
|
|
shaderList
|
|
)
|
|
|
|
---------------------------------------------------------------------------------
|
|
-- Return list of shaders in current scene
|
|
--
|
|
-- [return] Array of shader name strings (path and extension removed)
|
|
---------------------------------------------------------------------------------
|
|
function RsGetSceneShaderList = (
|
|
|
|
shaderList = #()
|
|
|
|
for mat in sceneMaterials do
|
|
(
|
|
if ( Rage_Shader == classof mat ) then
|
|
(
|
|
local shaderName = ( RstGetShaderName mat )
|
|
if ( 0 == ( findItem shaderList shaderName ) ) then
|
|
append shaderList shaderName
|
|
)
|
|
|
|
else if ( Multimaterial == classof mat ) then
|
|
(
|
|
for submat in mat.materialList do
|
|
(
|
|
if ( Rage_Shader == classof submat ) then
|
|
(
|
|
local shaderName = ( RstGetShaderName submat )
|
|
if ( 0 == ( findItem shaderList shaderName ) ) then
|
|
append shaderList shaderName
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
sort shaderList
|
|
shaderList
|
|
)
|
|
|
|
---------------------------------------------------------------------------------
|
|
-- Return list of shaders for a set of objects
|
|
--
|
|
-- [return] Array of shader name strings (path and extension removed)
|
|
---------------------------------------------------------------------------------
|
|
function RsGetShaderListForObjects objs = (
|
|
|
|
shaderList = #()
|
|
|
|
for o in objs do
|
|
(
|
|
if ( undefined == o.material ) then
|
|
continue
|
|
|
|
if ( Rage_Shader == classof o.material ) then
|
|
(
|
|
local shaderName = ( RstGetShaderName o.material )
|
|
if ( 0 == ( findItem shaderList shaderName ) ) then
|
|
append shaderList shaderName
|
|
)
|
|
else if ( Multimaterial == classof o.material ) then
|
|
(
|
|
for submat in o.material.materialList do
|
|
(
|
|
if ( Rage_Shader == classof submat ) then
|
|
(
|
|
local shaderName = ( RstGetShaderName submat )
|
|
if ( 0 == ( findItem shaderList shaderName ) ) then
|
|
append shaderList shaderName
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
shaderList
|
|
)
|
|
|
|
---------------------------------------------------------------------------------
|
|
-- Return list of Standard Materials for a set of objects
|
|
--
|
|
-- [in] objs List of objects to get list of Standard Materials for
|
|
-- [out] matList List of Standard Materials used by objs
|
|
-- [out[ parentList List of material's in matList's parents (per mat)
|
|
---------------------------------------------------------------------------------
|
|
function RsGetStdMatListForObjects objs &nameList &matList &parentList = (
|
|
|
|
nameList = #()
|
|
matList = #()
|
|
parentList = #()
|
|
|
|
for o in objs do
|
|
(
|
|
|
|
if ( undefined == o.material ) then
|
|
continue
|
|
|
|
if ( StandardMaterial == classof o.material ) then
|
|
(
|
|
if ( 0 == findItem matList o.material ) then
|
|
(
|
|
append nameList o.name
|
|
append matList o.material
|
|
append parentList undefined
|
|
)
|
|
)
|
|
else if ( Multimaterial == classof o.material ) then
|
|
(
|
|
for subMat in o.material.materialList do
|
|
(
|
|
if ( StandardMaterial == classof subMat ) then
|
|
(
|
|
if ( 0 == findItem matList subMat ) then
|
|
(
|
|
append nameList o.name
|
|
append matList subMat
|
|
append parentList o.material
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
---------------------------------------------------------------------------------
|
|
-- Return list of Rage Shader Materials for a set of objects
|
|
--
|
|
-- [in] objs List of objects to get list of Rage Shader Materials for
|
|
-- [out] matList List of Rage Shader Materials used by objs
|
|
-- [out[ parentList List of material's in matList's parents (per mat)
|
|
---------------------------------------------------------------------------------
|
|
function RsGetRageShaderMatListForObjects objs &matList &parentList = (
|
|
|
|
matList = #()
|
|
parentList = #()
|
|
|
|
for o in objs do
|
|
(
|
|
|
|
if ( undefined == o.material ) then
|
|
continue
|
|
|
|
if ( Rage_Shader == classof o.material ) then
|
|
(
|
|
if ( 0 == findItem matList o.material ) then
|
|
(
|
|
append matList o.material
|
|
append parentList undefined
|
|
)
|
|
)
|
|
else if ( Multimaterial == classof o.material ) then
|
|
(
|
|
for subMat in o.material.materialList do
|
|
(
|
|
if ( Rage_Shader == classof subMat ) then
|
|
(
|
|
if ( 0 == findItem matList subMat ) then
|
|
(
|
|
append matList subMat
|
|
append parentList o.material
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
---------------------------------------------------------------------------------
|
|
-- Return object shader usage counts for object list and shader list
|
|
--
|
|
-- [in] objs List of objects to get usage information for
|
|
-- [in] shaders List of shaders to get usage information for
|
|
---------------------------------------------------------------------------------
|
|
function RsGetObjectShaderCounts objs shaders = (
|
|
|
|
shaderObjectCounts = #()
|
|
local shaderCount = shaders.count
|
|
|
|
-- Initialise shaderObjectCount entries
|
|
for sh in shaders do
|
|
append shaderObjectCounts 0
|
|
|
|
for i = 1 to shaderCount do
|
|
(
|
|
for o in objs do
|
|
(
|
|
if ( RsDoesObjUseShader2 o shaders[i] ) then
|
|
(
|
|
shaderObjectCounts[i] += 1
|
|
)
|
|
)
|
|
)
|
|
|
|
shaderObjectCounts
|
|
)
|
|
|
|
---------------------------------------------------------------------------------
|
|
-- Fetches object shader usage counts and object, materials lists using each shader
|
|
--
|
|
-- [in] objs List of objects to get usage information for
|
|
-- [in] shaders List of shaders to get usage information for
|
|
-- [out] shaderObjectLists Array of array of object references per shader
|
|
---------------------------------------------------------------------------------
|
|
function RsGetObjectShaderUsageData objs shaders &shaderObjectLists &shaderMaterialLists = (
|
|
|
|
-- Initialise parameter reference data
|
|
shaderObjectLists = #()
|
|
local shaderCount = shaders.count
|
|
|
|
-- Now iterate through shaders and objects to collect our usage data
|
|
for i = 1 to shaderCount do
|
|
(
|
|
shaderObjectList = #()
|
|
shaderMaterialList = #()
|
|
|
|
for o in objs do
|
|
(
|
|
if ( RsDoesObjUseShader2 o shaders[i] ) then
|
|
(
|
|
append shaderObjectList o
|
|
|
|
if ( Multimaterial == classof o.material ) then
|
|
(
|
|
for mat in o.material.materialList do
|
|
(
|
|
|
|
if ( Standard == classof mat ) then
|
|
(
|
|
shaderName = ( rexStdMatShaderName mat )
|
|
if ( ( undefined == shaderName ) or ( classof shaderName != String ) ) then
|
|
continue
|
|
|
|
if ( (RsRemoveExtension(shaderName)) == shaders[i] ) then
|
|
if ( 0 == findItem shaderMaterialList mat ) then
|
|
append shaderMaterialList mat
|
|
)
|
|
else if ( Rage_Shader == classof mat ) then
|
|
(
|
|
shaderName = ( RstGetShaderName mat )
|
|
|
|
if ( (RsRemoveExtension(shaderName)) == shaders[i] ) then
|
|
if ( 0 == findItem shaderMaterialList mat ) then
|
|
append shaderMaterialList mat
|
|
)
|
|
|
|
)
|
|
)
|
|
else if ( Standard == classof o.material ) then
|
|
(
|
|
shaderName = ( rexStdMatShaderName o.material )
|
|
if ( ( undefined == shaderName ) or ( classof shaderName != String ) ) then
|
|
continue
|
|
|
|
if ( (RsRemoveExtension(shaderName)) == shaders[i] ) then
|
|
if ( 0 == findItem shaderMaterialList o.material ) then
|
|
append shaderMaterialList o.material
|
|
)
|
|
else if ( Rage_Shader == classof o.material ) then
|
|
(
|
|
shaderName = ( RstGetShaderName o.material )
|
|
|
|
if ( (RsRemoveExtension(shaderName)) == shaders[i] ) then
|
|
if ( 0 == findItem shaderMaterialList o.material ) then
|
|
append shaderMaterialList o.material
|
|
)
|
|
|
|
)
|
|
)
|
|
|
|
append shaderObjectLists shaderObjectList
|
|
append shaderMaterialLists shaderMaterialList
|
|
)
|
|
|
|
true
|
|
)
|
|
|
|
---------------------------------------------------------------------------------------------------
|
|
-- Return a different index depending on whether the object has a decal an alpha or an other shader
|
|
---------------------------------------------------------------------------------------------------
|
|
fn RsDetermineAlphaAndDecalShadedObjects mat obj = (
|
|
|
|
if classof mat == Multimaterial then (
|
|
matlist = #()
|
|
RsMatGetMapIdsUsedOnObject obj matlist
|
|
|
|
for i = 1 to matlist.count do (
|
|
|
|
matidx = finditem mat.materialIDList matlist[i]
|
|
|
|
if matidx != 0 then (
|
|
|
|
if classof mat.materiallist[matidx] == Rage_Shader then (
|
|
shaderIdx = RsDetermineAlphaAndDecalShadedObjects mat.materiallist[matidx] obj
|
|
if shaderIdx != 0 then return shaderIdx
|
|
|
|
)
|
|
|
|
)
|
|
)
|
|
|
|
)
|
|
else if classof mat == Rage_Shader then (
|
|
shaderPreset = RstGetShaderName mat
|
|
if shaderPreset == "gta_alpha.sps" then return 1
|
|
else if shaderPreset == "gta_decal.sps" or shaderPreset == "gta_normal_spec_decal.sps" or shaderPreset == "gta_decal_glue.sps" then return 2
|
|
|
|
|
|
|
|
)
|
|
return 0
|
|
)
|
|
|
|
---------------------------------------------------------------------------------------------------
|
|
-- Work out if the mesh is using a micromovement shader
|
|
---------------------------------------------------------------------------------------------------
|
|
fn RsHasMicromovement obj mat = (
|
|
retval = false
|
|
if classof mat == Multimaterial then (
|
|
matlist = #()
|
|
RsMatGetMapIdsUsedOnObject obj matlist
|
|
|
|
for i = 1 to matlist.count do (
|
|
|
|
matidx = finditem mat.materialIDList matlist[i]
|
|
|
|
if matidx != 0 then (
|
|
|
|
if classof mat.materiallist[matidx] == Rage_Shader then (
|
|
retval = RsHasMicromovement obj mat.materiallist[matidx]
|
|
if retval == true then return retval
|
|
)
|
|
)
|
|
)
|
|
|
|
)
|
|
else if classof mat == Rage_Shader then (
|
|
shadername = RstGetShaderName mat
|
|
shadername = RsRemoveExtension shadername
|
|
postfix = substring shadername (shadername.count - 2) shadername.count
|
|
|
|
if postfix == "_um" then (
|
|
return true
|
|
)
|
|
)
|
|
return false
|
|
)
|
|
|
|
-- End of script
|