EngineLoadTXD: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (prefer normal note)
(24 intermediate revisions by 12 users not shown)
Line 1: Line 1:
{{Client function}}
{{Client function}}
__NOTOC__
__NOTOC__{{Note|Please note the loading order that is used in the examples as other orders can cause collisions, textures or the DFF not to load due to technical limitations}}
 
This function loads a RenderWare Texture Dictionary (TXD) file into GTA. The texture dictionary can then be used to provide textures.
This function loads a RenderWare Texture Dictionary (TXD) file into GTA. The texture dictionary can then be used to provide textures.


This is a client side function. Be sure to transfer your TXD file by including it in the meta file.
This is a client side function. Be sure to transfer your TXD file by including it in the meta file.
{{Tip|Do your TXD files take megabytes of disk space? You can read some [[Optimize_Custom_TXD|tips on reducing the size of TXD files]] to compress them without ruining texture quality.}}


==Syntax==  
==Syntax==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
txd engineLoadTXD ( string txd_file [, bool filteringEnabled = true ] )  
txd engineLoadTXD ( string txd_file / string raw_data [, bool filteringEnabled = true ] )
</syntaxhighlight>  
</syntaxhighlight>
[[Image:Filtering.jpg|thumb|Difference between texture filtering modes (left = filtering disabled, right = filtering enabled).|284x230px]]
[[Image:Filtering.jpg|thumb|Difference between texture filtering modes (left = filtering disabled, right = filtering enabled).|284x230px]]
{{OOP||[[TXD|EngineTXD]]}}
===Required Arguments===  
===Required Arguments===  
*'''txd_file:''' The [[filepath]] to the txd file you want to load
*'''txd_file / raw_data:''' The [[filepath]] to the TXD file you want to load or whole data buffer of the TXD file.
 
===Optional Arguments===
===Optional Arguments===
*'''filteringEnabled:''' Whether to enable texture filtering.
*'''filteringEnabled:''' Whether to enable texture filtering.
===Returns===
===Returns===
Returns a [[TXD]] if the file was loaded, ''false'' otherwise.
Returns a [[TXD]] if the file was loaded, ''false'' otherwise.
===Remarks===
[[Image:Texfilter_comparison.png|thumb|'''Left:''' anisotropic + mipmaps; '''Middle:''' filteringEnabled = true; '''Right:''': linear interpolation + mipmaps without anisot]]
The '''filteringEnabled''' property overrides the filtering modes in each texture of the TXD with point filtering. It also sets the uAddressing and vAddressing to WRAP. If textures come with mipmaps then they are disabled which is especially visible without ''anisotropic filtering''. It is recommended to set ''filteringEnabled'' to false if the TXD was created with mipmaps (the filtering mode can be changed in a TXD editor).


==Example==  
==Example==  
'''Example 1:''' This example loads a combination of a custom DFF and TXD file to replace the Euros vehicle in-game. The collisions are embedded inside the DFF file, with a command handler you just type the command you want and it will replace the TXD and the DFF.
'''Example 1:''' This example loads a combination of a custom DFF and TXD file to replace the Euros vehicle in-game. The collisions are embedded inside the DFF file.
<syntaxhighlight lang="lua">
txd = engineLoadTXD ("data/euros.txd")
engineImportTXD (txd, 587)
 
dff = engineLoadDFF ("data/euros.dff")
engineReplaceModel (dff, 587)
</syntaxhighlight>
 
'''Example 2:''' This example replaces a standard SA skin (in this example ID '190) with a custom skin model (DFF & TXD)
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function Replace
addEventHandler ( "onClientResourceStart", resourceRoot,
outputChatBox ( "> replacing the euros vehicle" )
function ()
txd = engineLoadTXD ( "skinmodel.txd" ); -- change 'skinmodel' to your mod's file name
engineImportTXD ( txd, 190 ); -- change the ID 190 into the GTA skin ID you with to replace with mod


txd = engineLoadTXD ( "data/euros.txd" )
dff = engineLoadDFF ( "skinmodel.dff" ); -- change 'skinmodel' to your mod's file name
engineImportTXD ( txd, 587 )
engineReplaceModel ( dff, 190 ); -- change the ID 190 into the GTA skin ID you with to replace with mod
dff = engineLoadDFF ( "data/euros.dff", 587 )
end
engineReplaceModel ( dff, 587 )
);
--You can also add a commandHandler for the replacing
addCommandHandler ( "reloadeuros", Replace )
--if you start this resource you have to type /reloadeuros ingame to replace the TXD and the DFF
</syntaxhighlight>
</syntaxhighlight>


'''Example 3:''' This example replaces a default weapon with a custom weapon mod (TXD & DFF)
<syntaxhighlight lang="lua">
addEventHandler ( "onClientResourceStart", resourceRoot,
function ()
txd = engineLoadTXD ( "m4.txd" )
engineImportTXD ( txd, 356)


'''Example 2:''' This example loads a combination of custom DFF, TXD and COL files to replace an in-game model of a set of floors.
dff = engineLoadDFF ( "m4.dff" ) -- use weapon model ID, not GTA weapon ID (model ID from https://wiki.multitheftauto.com/wiki/Weapons)
engineReplaceModel ( dff, 356) -- Likewise, model ID, for M4 as example it's 356
end
);
</syntaxhighlight>
 
'''Example 4:''' This example loads a combination of custom COL, TXD and DFF files to replace an in-game model of a set of floors.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
outputChatBox ( "> loading floor objects" )
col_floors = engineLoadCOL ("models/office_floors.col")
txd_floors = engineLoadTXD ( "models/office_floors.txd" )
engineReplaceCOL (col_floors, 3781 )
engineImportTXD ( txd_floors, 3781 )
col_floors = engineLoadCOL ( "models/office_floors.col" )
dff_floors = engineLoadDFF ( "models/office_floors.dff", 0 )
engineReplaceCOL ( col_floors, 3781 )
engineReplaceModel ( dff_floors, 3781 )


txd_floors = engineLoadTXD ("models/office_floors.txd")
engineImportTXD (txd_floors, 3781 )
dff_floors = engineLoadDFF ("models/office_floors.dff")
engineReplaceModel (dff_floors, 3781)
</syntaxhighlight>
</syntaxhighlight>
==Changelog==
{{ChangelogHeader}}
{{ChangelogItem|1.4.1-9.07088|Added option to use raw data instead of a file name}}


==See Also==
==See Also==
{{Engine_functions}}
{{Engine_functions}}

Revision as of 08:36, 7 September 2019

[[{{{image}}}|link=|]] Note: Please note the loading order that is used in the examples as other orders can cause collisions, textures or the DFF not to load due to technical limitations

This function loads a RenderWare Texture Dictionary (TXD) file into GTA. The texture dictionary can then be used to provide textures.

This is a client side function. Be sure to transfer your TXD file by including it in the meta file.

[[{{{image}}}|link=|]] Tip: Do your TXD files take megabytes of disk space? You can read some tips on reducing the size of TXD files to compress them without ruining texture quality.

Syntax

txd engineLoadTXD ( string txd_file / string raw_data [, bool filteringEnabled = true ] )
Difference between texture filtering modes (left = filtering disabled, right = filtering enabled).

OOP Syntax Help! I don't understand this!

Method: EngineTXD(...)


Required Arguments

  • txd_file / raw_data: The filepath to the TXD file you want to load or whole data buffer of the TXD file.

Optional Arguments

  • filteringEnabled: Whether to enable texture filtering.

Returns

Returns a TXD if the file was loaded, false otherwise.

Remarks

Left: anisotropic + mipmaps; Middle: filteringEnabled = true; Right:: linear interpolation + mipmaps without anisot

The filteringEnabled property overrides the filtering modes in each texture of the TXD with point filtering. It also sets the uAddressing and vAddressing to WRAP. If textures come with mipmaps then they are disabled which is especially visible without anisotropic filtering. It is recommended to set filteringEnabled to false if the TXD was created with mipmaps (the filtering mode can be changed in a TXD editor).

Example

Example 1: This example loads a combination of a custom DFF and TXD file to replace the Euros vehicle in-game. The collisions are embedded inside the DFF file.

txd = engineLoadTXD ("data/euros.txd")
engineImportTXD (txd, 587)

dff = engineLoadDFF ("data/euros.dff")
engineReplaceModel (dff, 587)

Example 2: This example replaces a standard SA skin (in this example ID '190) with a custom skin model (DFF & TXD)

addEventHandler ( "onClientResourceStart", resourceRoot,
	function ()
		txd = engineLoadTXD ( "skinmodel.txd" ); -- change 'skinmodel' to your mod's file name
		engineImportTXD ( txd, 190 ); -- change the ID 190 into the GTA skin ID you with to replace with mod

		dff = engineLoadDFF ( "skinmodel.dff" ); -- change 'skinmodel' to your mod's file name
		engineReplaceModel ( dff, 190 ); -- change the ID 190 into the GTA skin ID you with to replace with mod
	end
);

Example 3: This example replaces a default weapon with a custom weapon mod (TXD & DFF)

addEventHandler ( "onClientResourceStart", resourceRoot,
	function ()
		txd = engineLoadTXD ( "m4.txd" )
		engineImportTXD ( txd, 356)

		dff = engineLoadDFF ( "m4.dff" ) -- use weapon model ID, not GTA weapon ID (model ID from https://wiki.multitheftauto.com/wiki/Weapons)
		engineReplaceModel ( dff, 356) -- Likewise, model ID, for M4 as example it's 356
	end
);

Example 4: This example loads a combination of custom COL, TXD and DFF files to replace an in-game model of a set of floors.

col_floors = engineLoadCOL ("models/office_floors.col")
engineReplaceCOL (col_floors, 3781 )

txd_floors = engineLoadTXD ("models/office_floors.txd")
engineImportTXD (txd_floors, 3781 )

dff_floors = engineLoadDFF ("models/office_floors.dff")
engineReplaceModel (dff_floors, 3781)

Changelog

Version Description
1.4.1-9.07088 Added option to use raw data instead of a file name

See Also