-- -- File:: %RS_TOOLSLIB%/util/ragebuilder/convert.rbs -- Description:: Asset conversion control script. -- ----------------------------------------------------------------------------- -- Uses ----------------------------------------------------------------------------- require( 'archive.rbs' ) require( 'util.rbs' ) ----------------------------------------------------------------------------- -- Locals ----------------------------------------------------------------------------- local outputSettings = false local dirTemp = "c:/temp/" local isTemporary = false local doRebuild = false local customScript = "custom.rbs" local customScriptEnd = "custom_finish.rbs" ----------------------------------------------------------------------------- -- Functions ----------------------------------------------------------------------------- -- -- name: setBuildFlags -- desc: Set Ragebuilder build options. -- function setBuildFlags( options ) textureMinValue = 1 textureMaxValue = -1 textureScale = 1.0 maxMipMapCount = -1 compressResources = 0 triStripping = 1 texOverload = "" if options ~= nil then in_textureMinValue = getParam(options, "texMinValue") in_textureMaxValue = getParam(options, "texMaxValue") in_textureScale = getParam(options, "texScale") in_maxMipMapCount = getParam(options, "texMaxMips") in_compressResources = getParam(options, "compressResources") in_triStripping = getParam(options, "triStrip") in_texOverload = getParam(options, "texOverload") if in_textureMinValue ~= nil then textureMinValue = 0 + in_textureMinValue end if in_textureMaxValue ~= nil then textureMaxValue = 0 + in_textureMaxValue end if in_textureScale ~= nil then textureScale = 0 + in_textureScale end if in_maxMipMapCount ~= nil then maxMipMapCount = 0 + in_maxMipMapCount end if in_compressResources ~= nil then compressResources = 0 + in_compressResources end if in_triStripping ~= nil then triStripping = 0 + in_triStripping end if in_texOverload ~= nil then texOverload = in_texOverload end end set_texture_minmipmap(textureMinValue) set_texture_max(textureMaxValue) set_texture_scale(textureScale) set_mipmapcount_max(maxMipMapCount) set_overload_texture_src(texOverload) set_compress_resources(compressResources) set_tristripping(triStripping) end -- -- name: convertInner -- desc: Convert a file to a specific platform based on extension. -- function convertInner( input, output, platform, projBin ) output = convert_filename_to_platform( output, platform ) create_leadingpath(output) if ( input == output ) then return ( true ) end trace1( "Converting " .. input .. " to " .. output .. " [" .. platform .. "]" ) registerTextureNames( ) local filename = get_filename_from_path( input ) local ext = get_extension_from_path( filename ) local secext = get_extension_from_path( remove_extension_from_path( filename ) ) local converted = true if( ext==".rpf" ) then result = convertRpf( input, output, platform, projBin ) elseif ( ext==".zip" and secext==nil ) then result = convertZip( input, output, platform, projBin ) elseif( ext==".idr" or secext==".idr" ) then result = convertIdr( input, output, platform ) elseif( ext==".itd" or secext==".itd" ) then result = convertItd( input, output, platform ) elseif( ext==".ibd" or secext==".ibd" ) then result = convertIbd( input, output, platform ) elseif( ext==".ibn" or secext==".ibn" ) then result = convertIbn( input, output, platform ) elseif( ext==".idd" or secext==".idd" ) then result = convertIdd( input, output, platform ) elseif( ext==".ild" or secext==".ild" ) then result = convertIld( input, output, platform ) elseif( ext==".ift" or secext==".ift" ) then result = convertIft( input, output, platform ) elseif( ext==".ibs" or secext==".ibs" ) then result = convertIbs( input, output, platform ) elseif( ext==".isd" or secext==".isd" ) then result = convertIsd( input, output, platform ) elseif( ext==".ipt" or secext==".ipt" ) then result = convertIpt( input, output, platform ) elseif( ext==".icd" or secext==".icd" ) then result = convertIcd( input, output, platform ) elseif( ext==".ipm" or secext==".ipm" ) then result = convertIpm( input, output, platform ) elseif( ext==".ied" or secext==".ied" ) then result = convertIed( input, output, platform ) elseif( ext==".ifd" or secext==".ifd" ) then result = convertIfd( input, output, platform ) elseif( ext==".ipl" ) then result = convertIpl( input, output, platform ) elseif( ext==".ind" ) then result = convertInd( input, output, platform ) elseif( ext==".inv" ) then result = convertInv( input, output, platform ) elseif( ext==".inh" ) then result = convertInh( input, output, platform ) elseif( ext==".ihn" ) then result = convertIhn( input, output, platform ) elseif( ext==".iwr" ) then result = convertIwr( input, output, platform ) elseif( ext==".ivr" ) then result = convertIvr( input, output, platform ) elseif( ext==".iam" ) then result = convertIam( input, output, platform ) elseif( ext==".meta" and secext==".pso" ) then result = convertMeta( input, output, platform, true ) elseif( ext==".meta" ) then result = convertMeta( input, output, platform, false ) elseif ( ext==".imap" ) then result = convertImap( input, output, platform ) elseif ( ext==".ityp" ) then result = convertItyp( input, output, platform ) elseif ( ext==".imf" ) then result = convertImf( input, output, platform ) elseif ( ext==".mrf" ) then result = convertDefault( input, output, platform ) elseif ( ext==".gfx" ) then result = convertDefault( input, output, platform ) elseif ( ext==".cut" ) then result = convertDefault( input, output, platform ) elseif ( ext==".cutxml" ) then result = convertCutxml( input, output, platform ) elseif ( ext==".ipdb" ) then result = convertDefault( input, output, platform ) elseif ( ext==".sco" ) then result = convertSco( input, output, platform ) elseif( ext==".ildb" ) then result = convertIldb( input, output, platform ) else --# JWR - B* 692193 - prevent files from being blindly copied to target data converted = false result = true end if converted then set_file_attrib(output, "readonly", false) end return ( result ) end -- -- name: execCustomScript -- desc: Requires a pack:/ custom script for handling custom properties. -- function execCustomScript( mount ) script = mount .. customScript if file_exists( script ) then print( "Executing " .. customScript .. "..." ) require( script ) end end -- -- name: execCustomScriptEnd -- desc: Requires a pack:/ custom script end for cleaning up custom properties. -- function execCustomScriptEnd( mount ) script = mount .. customScriptEnd if file_exists( script ) then print( "Executing " .. customScriptEnd .. "..." ) require( script ) end end -- convert (default) - merely copies the file. function convertDefault( input, output, platform ) if (copy_file( input, output ) == 0) then error("Error copying " .. input .. " to " .. output) return 0 end set_file_attrib(output, "readonly", false) return 1 end -- -- name: convertIpt -- desc: Convert effect IPT asset -- function convertIpt( input, output, platform ) local inbasename = remove_all_extensions_from_path(input) local effectname = get_filename_from_path(inbasename) local outbasename = remove_all_extensions_from_path(output) start_build() mount( input, "pack:/" ) execCustomScript( "pack:/" ) set_effectpath( "pack:/" ) load_effect( "pack:/fxlists/" .. effectname .. "/" .. effectname .. ".fxlist" ) local result = save_effect(outbasename) execCustomScriptEnd( "pack:/" ) unmount( input ) return result end -- convert path region function convertInd( input, output, platform ) local basename = remove_extension_from_path(output) start_build() load_pathregion(input) local result = save_pathregion(basename) return result end -- convert navmesh function convertInv( input, output, platform ) local basename = remove_extension_from_path(output) start_build() load_navmesh(input) local result = save_navmesh(basename) return result end -- convert heightmesh function convertInh( input, output, platform ) local basename = remove_extension_from_path(output) start_build() load_heightmesh(input) local result = save_heightmesh(basename) return result end -- convert hierarchical nav data function convertIhn( input, output, platform ) local basename = remove_extension_from_path(output) start_build() load_hierarchicalnav(input) local result = save_hierarchicalnav(basename) return result end -- convert waypoint recording data function convertIwr( input, output, platform ) local basename = remove_extension_from_path(output) start_build() load_waypointrecording(input) local result = save_waypointrecording(basename) return result end -- -- name: convertItd -- desc: Convert texture dictionary ITD asset -- function convertItd( input, output, platform ) local basename = remove_all_extensions_from_path(output) local corename = get_filename_from_path(basename) push_buildvars() start_build() mount(input, "pack:/" ) execCustomScript( "pack:/" ) if file_exists( "pack:/" .. "info.rbs" ) then require( "pack:/" .. "info.rbs" ) end load_textures( "pack:/" ) local result = save_texture_dictionary( basename, "hi" ) execCustomScriptEnd( "pack:/" ) unmount(input) pop_buildvars() return ( result ) end -- -- name: convertIdr -- desc: Convert drawable IDR asset -- function convertIdr( input, output, platform ) local basename = remove_extension_from_path(output) start_build() mount( input, "pack:/" ) execCustomScript( "pack:/" ) local subname = get_filename_from_path(remove_extension_from_path(input)) if file_exists( "pack:/" .. "info.rbs" ) then require( "pack:/" .. "info.rbs" ) end local texture_count = load_textures( "pack:/" ) if ( texture_count > 0 ) then set_auto_texdict( true ) end load_model( "pack:/" .. "entity.type" ) local result = save_model( basename ) -- Save the (optional) hi-MIP texture dictionary. result = result and save_texture_dictionary_himip( basename, "hidr" ) execCustomScriptEnd( "pack:/" ) unmount( input ) set_auto_texdict(false) return result end -- convert blendshape object function convertIbs( input, output, platform ) local inputBasename = remove_extension_from_path(input) local outputBaseName = remove_extension_from_path(output) start_build() mount(input, "pack:/" ) execCustomScript( "pack:/" ) clear_definitions() load_model( "pack:/" .. "entity.type" ) local result = save_blendshape(inputBasename, outputBaseName) execCustomScriptEnd( "pack:/" ) unmount(input) return result end -- -- name: convertIft -- desc: Convert fragment IFT asset -- function convertIft( input, output, platform ) local basename = remove_all_extensions_from_path( output ) start_build() local tunename = get_filename_from_path(remove_all_extensions_from_path(input)) mount(input, "pack:/" .. tunename .. "/") execCustomScript( "pack:/" .. tunename .. "/" ) local ide_filename = "pack:/" .. tunename .. "/" .. tunename .. ".ide" clear_definitions() if ( file_exists( ide_filename ) ) then load_definitions( ide_filename ) end local texture_count = load_textures( "pack:/" .. tunename .. "/" ) if ( texture_count > 0 ) then set_auto_texdict( true ) end load_fragment( "pack:/" .. tunename .. "/entity.type" ) if load_nm_data ~= nil then load_nm_data(find_xml_match(input,"$(core_assets)/characters/nm.xml")) end local result = save_fragment(basename) -- Save the (optional) hi-MIP texture dictionary. result = result and save_texture_dictionary_himip( basename, "hifr" ) execCustomScriptEnd( "pack:/" ) unmount(input) return result end -- -- name: convertIcd -- desc: Convert a clip dictionary ICD asset (no compression). -- function convertIcd( input, output, platform ) local basename = remove_all_extensions_from_path( output ) start_build() mount( input, "pack:/" ) load_clip( "pack:/" .. "*.clip" ) local result = save_clip_dictionary(basename, 1) unmount(input) return result end -- convert param motion dictionary function convertIpm( input, output, platform ) local basename = remove_extension_from_path(output) start_build() mount( input, "pack:/" ) load_param_motion( "pack:/" .. "*.spm" ) local result = save_param_motion_dictionary(basename) unmount(input) return result end -- convert expressions dictionary function convertIed( input, output, platform ) local basename = remove_extension_from_path(output) start_build() mount( input, "pack:/" ) load_expressions( "pack:/*.expr" ) local result = save_expressions_dictionary(basename) unmount( input ) return result end -- convert framefilter dictionary function convertIfd( input, output, platform ) local basename = remove_extension_from_path(output) start_build() mount( input, "pack:/" ) load_framefilter( "pack:/*.iff" ) local result = save_framefilter_dictionary(basename) unmount( input ) return result end -- convert bound object function convertIbn( input, output, platform ) local basename = remove_extension_from_path(output) start_build() mount(input, "pack:/" ) execCustomScript( "pack:/" ) load_bound( "pack:/*.bnd" ) local result = save_bound(basename) execCustomScriptEnd( "pack:/" ) unmount(input) return result end -- convert bounds dictionary function convertIbd( input, output, platform ) local basename = remove_extension_from_path(output) start_build() mount( input, "pack:/" ) execCustomScript( "pack:/" ) load_bounds( "pack:/*.bnd" ) result = save_bound_dictionary(basename) execCustomScriptEnd( "pack:/" ) unmount( input ) return result end -- convert drawable dictionary function convertIdd( input, output, platform ) local basename = remove_extension_from_path(output) start_build() mount( input, "pack:/" ) execCustomScript( "pack:/" ) local drawables = find_dirs( "pack:/" ) local texture_count = 0 for key, value in drawables do texture_count = texture_count + load_textures( "pack:/" .. value .. "/" ) load_model( "pack:/" .. value .. "/entity.type" ) end if ( texture_count > 0 ) then set_auto_texdict( true ) end result = save_model_dictionary(basename) -- Save the (optional) hi-MIP texture dictionary. if ( texture_count > 0 ) then result = result and save_texture_dictionary_himip( basename, "hidd" ) end execCustomScriptEnd( "pack:/" ) unmount( input ) return result end -- convert cloth dictionary function convertIld( input, output, platform ) local basename = remove_extension_from_path(output) start_build() mount( input, "pack:/" ) execCustomScript( "pack:/" ) local drawables = find_dirs( "pack:/" ) for key, value in drawables do load_model( "pack:/" .. value .. "/entity.type" ) end result = save_cloth_dictionary(basename) execCustomScriptEnd( "pack:/" ) unmount( input ) return result end -- convert blendshape dictionary function convertIsd( input, output, platform ) local basename = remove_extension_from_path(output) start_build() mount( input, "pack:/" ) execCustomScript( "pack:/" ) local drawables = find_dirs( "pack:/" ) for key, value in drawables do load_blendshape( "pack:/" .. value .. "/entity.type" ) end execCustomScriptEnd( "pack:/" ) result = save_blendshape_dictionary(basename) unmount( input ) return result end -- -- name: convertIpl -- desc: Convert instances IPL asset -- function convertIpl( input, output, platform ) start_build() set_platform("independent") load_placements( input ) set_platform( platform ) result = save_placements(output) return result end -- convert text database function convertIldb( input, output, platform ) local basename = remove_extension_from_path(output) start_build() load_meta(input) local result = save_textdatabase(basename) end -- -- Convert an RPF file, recursively. This function is called internally in -- the main convertRpf function and should not be called elsewhere. -- function convertRpfRecurse( root_mount, relative_mount, platform, projBin, temporary_files ) -- Recurse into RPF directories, depth-first recursion. local mount_point = root_mount .. relative_mount print( "mount_point: " .. mount_point ) local dirs = find_dirs( mount_point ) for key, value in dirs do -- Prevent too many slashes. local dir_mount = "" if ( "" == relative_mount ) then dir_mount = value else dir_mount = relative_mount .. "/" .. value end convertRpfRecurse( root_mount, dir_mount, platform, projBin, temporary_files ) end -- Loop through all files in the current RPF directory. local files = find_files( mount_point .. "/*.*" ) for key, value in files do local src_file = mount_point .. "/" .. value local filename = get_filename_from_path( value ) local basename = remove_extension_from_path( filename ) local ext = get_extension_from_path( filename ) local dst_file = relative_mount .. "/" .. basename .. "." .. get_platform_extension(ext) -- Set dirTemp if its not currently set. if ( nil == dirTemp ) then dirTemp = "c:/temp/" end temp = dirTemp .. "/" .. dst_file if ( filetime_compare( temp, src_file ) == 1 ) or ( doRebuild == true ) then convertInner( src_file, temp, platform, projBin ) end add_to_pack( temp, dst_file ) table.insert( temporary_files, temp ) end end -- -- Convert an RPF file. RPF files can have, and do, a folder hierarchy so we -- need to ensure we recurse correctly across this. -- function convertRpf( input, output, platform, projBin ) local mount = "image:/" local temporary_files = {} print( "convertRpf : starting uncompressed RPF output" ) start_uncompressed_pack( false ) mount_pack( input, mount ) execCustomScript( mount ) convertRpfRecurse( mount, "", platform, projBin, temporary_files ) local result = save_pack(output) execCustomScriptEnd( mount ) unmount_pack(input) close_pack() -- Cleanup temporary files (if applicable) if ( isTemporary ) then for key, value in temporary_files do del_file( value ) end end return ( result ) end -- -- name: convertZip -- desc: Convert a ZIP file (to RPF). ZIP files can have a folder hierarchy -- so we need to ensure we recurse correctly across this. -- function convertZip( input, output, platform, projBin ) local mount = "zip:/" local temporary_files = {} print( "convertZip : starting uncompressed RPF output" ) start_uncompressed_pack( false ) mount_zip( input, mount ) execCustomScript( mount ) convertRpfRecurse( mount, "", platform, projBin, temporary_files ) local result = save_pack( output ) execCustomScriptEnd( mount ) unmount_zip( input ) close_pack( ) -- Cleanup temporary files (if applicable) if ( isTemporary ) then for key, value in temporary_files do del_file( value ) end end return ( result ) end -- -- name: convertIvr -- desc: Convert vehicle recording IVR asset. -- function convertIvr( input, output, platform ) local basename = remove_extension_from_path(output) start_build() load_vehiclerecording(input) local result = save_vehiclerecording(basename) return result end -- -- name: convertIam -- desc: -- function convertIam( input, output, platform ) local basename = remove_extension_from_path(output) start_build() load_audmesh(input) local result = save_audmesh(basename) return result end -- -- name: convertMeta -- desc: Convert metadata file asset. -- function convertMeta( input, output, platform, outputPSO ) local basename = remove_extension_from_path(output) load_meta(input) local result if ( outputPSO ) then if (string.find(basename, ".*_srl" ) or string.find(basename, ".*[\\/]scenario[\\/]") or string.find(basename, "player_.*") or string.find(basename, "cs_.*") or string.find(basename, "a_c_.*") or string.find(basename, "a_f_.*") or string.find(basename, "a_m_.*") or string.find(basename, "csb_.*") or string.find(basename, "g_f_y_.*") or string.find(basename, "g_m_.*") or string.find(basename, "hc_.*") or string.find(basename, "ig_.*") or string.find(basename, "mp_.*") or string.find(basename, "s_f_.*") or string.find(basename, "s_m_.*") or string.find(basename, "slot_.*") or string.find(basename, "u_f_.*") or string.find(basename, "u_m_.*") or string.find(basename, "z_.*")) then result = save_pso_as(basename, "rsc") else result = save_pso(basename) end else result = save_rbf(basename) end return result end -- -- name: convertImap -- desc: Convert map data file asset. -- function convertImap( input, output, platform ) local basename = remove_extension_from_path( output ) load_meta( input ) local result = save_mapdata( basename ) return result end -- -- name: convertItyp -- desc: convert map type data file asset -- function convertItyp( input, output, platform ) local basename = remove_extension_from_path( output ) load_meta( input ) local result = save_maptypes( basename ) end -- -- name: convertCutxml -- desc: convert cutxml data file asset -- function convertCutxml( input, output, platform ) local basename = remove_extension_from_path( output ) load_meta( input ) local result = save_cutfile( basename ) end -- -- name: convertImf -- desc: convert manifest file asset -- function convertImf( input, output, platform ) local basename = remove_extension_from_path( output ) load_meta( input ) local result = save_imf( basename ) end -- -- name: convertSco -- desc: Convert SCO script file asset. -- function convertSco( input, output, platform ) local basename = remove_extension_from_path( output ) load_script( input ) local result = save_script( basename ) return result end -- -- name: convert2 -- desc: Simplified version of the convert function; removing parameters no -- longer required for Asset Pipeline 3. -- function convert2( input, output, platform, build, materials, procedurals, shader, shaderdb, options, bindir, core_assets, assets, metadata_definitions ) --todo: put a check in here to load the preload.list --and check it against the shaders in the shader folder --as all hell breaks loose internally in rage if there are --any inconsistencies here... --a higher level check should probably also be put in in ruby code setBuildFlags( options ) set_buildpath( build ) set_shaderpath( shader ) set_shaderdbpath( shaderdb ) set_platform( platform ) set_coreassetspath( core_assets ) set_assetspath( assets ) set_metadatadefinitionspath( metadata_definitions ) loadMaterials( build, materials, procedurals ) if ( false == outputSettings ) then print( "Platform: " .. platform ) print( "Build Path: " .. build ) print( "Shaders Path: " .. shader ) print( "Shaders DB: " .. shaderdb ) print( "Build Path: " .. build ) print( "Core Assets Path: " .. core_assets ) print( "Assets Path: " .. assets ) print( "Metadata Definitions Path: " .. metadata_definitions ) if ( options ~= nil ) then print( "Options: " .. options ) else print( "Options: nil" ) end outputSettings = true end print( "Converting:" ) print( "Input file: " .. input ) print( "Output file: " .. output ) convertInner( input, output, platform, bindir ) end -- -- name: convert2directory -- desc: Method to convert files matching (search_pattern) in a directory of independent files (input_dir) to a directory of platform specific files (output_dir). -- -- param: resourcePrefix - used for map DLC to ensure assets are uniquely named. -- function convert2directory( input_dir, search_pattern, output_dir, platform, build, materials, procedurals, shader, shaderdb, options, bindir, core_assets, assets, metadata_definitions, resource_prefix ) setBuildFlags( options ) set_buildpath( build ) set_shaderpath( shader ) set_shaderdbpath( shaderdb ) set_platform( platform ) set_coreassetspath( core_assets ) set_assetspath( assets ) set_metadatadefinitionspath( metadata_definitions ) loadMaterials( build, materials, procedurals ) if ( false == outputSettings ) then print( "Platform: " .. platform ) print( "Build Path: " .. build ) print( "Shaders Path: " .. shader ) print( "Shaders DB: " .. shaderdb ) print( "Build Path: " .. build ) print( "Core Assets Path: " .. core_assets ) print( "Assets Path: " .. assets ) print( "Metadata Definitions Path: " .. metadata_definitions ) if ( resource_prefix ~= nil ) then print( "Resource Prefix: " .. resource_prefix ) else print( "Resource Prefix: nil" ) end if ( options ~= nil ) then print( "Options: " .. options ) else print( "Options: nil" ) end outputSettings = true end print( "Converting:" ) local input_filenames = find_files( input_dir .. "/" .. search_pattern ) for index, input_filename in input_filenames do local input_pathname = input_dir .. "/" .. input_filename --build the output_pathname local output_filename = input_filename local input_extension = get_extension_from_path( input_filename ) if ( input_extension == ".zip" ) then output_filename = remove_extension_from_path( input_filename ) end output_filename = convert_filename_to_platform( output_filename, platform ) local output_pathname = "" if ( ( resource_prefix ~= nil ) and ( ".ityp" ~= input_extension ) and nil == string.find( output_filename, resource_prefix ) ) then output_pathname = output_dir .. "/" .. resource_prefix .. output_filename else output_pathname = output_dir .. "/" .. output_filename end print( "Input file: " .. input_pathname ) print( "Output file: " .. output_pathname ) convertInner( input_pathname, output_pathname, platform, bindir ) end end -- -- name: convert -- desc: Convert input file to output file. -- function convert( input, output, platform, build, shader, shaderdb, folder, temporary, rebuild, options, projBin ) dirTemp = folder isTemporary = temporary doRebuild = rebuild --todo: put a check in here to load the preload.list --and check it against the shaders in the shader folder --as all hell breaks loose internally in rage if there are --any inconsistencies here... --a higher level check should probably also be put in in ruby code setBuildFlags( options ) set_shaderpath( shader ) set_shaderdbpath( shaderdb ) set_platform( platform ) loadMaterials( build, nil, nil ) if ( false == outputSettings ) then print( "Platform: " .. platform ) print( "Shaders Path: " .. shader ) print( "Shaders DB: " .. shaderdb ) print( "Build Path: " .. build ) if ( dirTemp ~= nil ) then print( "Temp Path: " .. dirTemp ) else print( "Temp Path: nil" ) end if ( isTemporary ) then print( "Temp Enabled: true" ) else print( "Temp Enabled: false" ) end if ( rebuild ) then print( "Rebuild: true" ) else print( "Rebuild: false" ) end if ( options ~= nil ) then print( "Options: " .. options ) else print( "Options: nil" ) end outputSettings = true end print( "Converting:" ) print( "Input file: " .. input ) print( "Output file: " .. output ) convertInner( input, output, platform, projBin ) end -- %RS_TOOLSLIB%/util/ragebuilder/convert.rbs