Resource:Custom billboards: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Created page with "{{Resource page}} This resource lets You create billboards. The billboard is a quad that always faces the camera. In this case billboard Elements are created using dxDrawMater...")
 
No edit summary
Line 105: Line 105:
for i=1,30 do
for i=1,30 do
for j=1,30 do
for j=1,30 do
corTable[i] = exports.custom_billboards:createbillboard(tex,i * 7,j * 7,10,4,4,math.random()*255,math.random()*255,math.random()*255,1*255)  
corTable[i] = exports.custom_billboards:createBillboard(tex,i * 7,j * 7,10,4,4,math.random()*255,math.random()*255,math.random()*255,1*255)  
end
end
end
end
Line 123: Line 123:


local tex = dxCreateTexture("hello.jpg")
local tex = dxCreateTexture("hello.jpg")
local carLight = exports.custom_billboards:createbillboard(tex,0,0,0,4,4,math.random()*255,math.random()*255,math.random()*255,1*255)
local carLight = exports.custom_billboards:createBillboard(tex,0,0,0,4,4,math.random()*255,math.random()*255,math.random()*255,1*255)
addEventHandler("onClientPreRender", root, function()
addEventHandler("onClientPreRender", root, function()
if vehicle1 then  
if vehicle1 then  
xxx1,yyy1,zzz1 = getElementPosition(vehicle1)
xxx1,yyy1,zzz1 = getElementPosition(vehicle1)
exports.custom_billboards:setbillboardPosition(carLight,xxx1,yyy1,zzz1)
exports.custom_billboards:setBillboardPosition(carLight,xxx1,yyy1,zzz1)
end
end
end
end
Line 139: Line 139:


[http://community.multitheftauto.com/index.php?p=resources&s=details&id=10156 Resource download link]
[http://community.multitheftauto.com/index.php?p=resources&s=details&id=10156 Resource download link]
[http://www.solidfiles.com/d/07ea100174/custom_billboards_test.zip Test resource]
[http://www.solidfiles.com/d/07ea100174/custom_billboards_test.zip Test resource]

Revision as of 23:54, 24 September 2014

This resource lets You create billboards. The billboard is a quad that always faces the camera. In this case billboard Elements are created using dxDrawMaterialLine3d MTA function. I have changed the behaviour of the material to act as cylindrical billboards do. There are many possibilities to use this resource. But that's all up to you.

Overview

It is easy to use, gives a few options to manage billboards.

The resource itself adds exported clientside functions:

Exported functions

createBillboard

Click to collapse [-]
Client

This function creates a shadered materialLine3d billboard.

bool exports.custom_billboards:createBillboard(float posX,posY,posZ,sizeX,sizeY,int colorR,colorG,colorB,colorA)

Required Arguments

  • float posX, posY, posZ: Position in world space.
  • float sizeX, sizeY: Size of the billboard.
  • int colorR,colorG,colorB,colorA: Billboard RGBA color emitted by the billboard (0 - 255).

Returns

The function returns true if set successfully, false otherwise.

destroyBillboard

Click to collapse [-]
Client

This function destroys a shadered materialLine3d billboard element.

bool exports.custom_billboards:destroyBillboard(element billboardElement)

Required Arguments

  • element billboardElement: A previously declared billboard element.

Returns

The function returns true if set successfully, false otherwise.

setBillboardMaterial

Click to collapse [-]
Client

This function sets the billboard material (ex. texture).

bool exports.custom_billboards:setBillboardMaterial(element billboardElement)

Required Arguments

  • element billboardElement: A previously declared billboard element.

Returns

The function returns true if set successfully, false otherwise.

setBillboardPosition

Click to collapse [-]
Client

This function sets billboard position.

bool exports.custom_billboards:setbillboardPosition(element billboardElement,float posX,posY,posZ)

Required Arguments

  • element billboardElement: A previously declared billboard element.
  • float posX, posY, posZ: Position in world space.

Returns

The function returns true if set successfully, false otherwise.

setBillboardSize

Click to collapse [-]
Client

This function sets billboard width and height.

bool exports.custom_billboards:setBillboardSize(element billboardElement,float size)

Required Arguments

  • element billboardElement: A previously declared billboard element.
  • float size: Size of the billboard.

Returns

The function returns true if set successfully, false otherwise.

setBillboardSizeXY

Click to collapse [-]
Client

This function sets billboard width and height.

bool exports.custom_billboards:setBillboardSizeXY(element billboardElement,float sizeX,sizeY)

Required Arguments

  • element billboardElement: A previously declared billboard element.
  • float sizeX,sizeY: The width and height of the billboard.

Returns

The function returns true if set successfully, false otherwise.

setBillboardColor

Click to collapse [-]
Client

This function sets light color values.

bool exports.custom_billboards:setbillboardColor(element billboardElement,float colorR,colorG,colorB,colorA)

Required Arguments

  • element billboardElement: A previously declared billboard element.
  • float colorR,colorG,colorB,colorA: Billboard RGBA color emitted by the billboard (0 - 255).

Returns

The function returns true if set successfully, false otherwise.

setBillboardsDistFade

Click to collapse [-]
Client

Set the Max distance of the billboard to sync and the distance on which the it starts to fade out.

bool exports.custom_billboards:setBillboardsDistFade(int MaxEffectFade,int MinEffectFade)

Required Arguments

  • int MaxEffectFade: Set the Max distance of the billboard to sync.(Must be greater than MinEffectFade).
  • int MinEffectFade: Set the distance on which the billboard starts to fade out.

Returns

The function returns true if set successfully, false otherwise.

Examples

local corTable = {}
local tex = dxCreateTexture("hello.jpg")
function addStuff()
	for i=1,30 do
		for j=1,30 do
			corTable[i] = exports.custom_billboards:createBillboard(tex,i * 7,j * 7,10,4,4,math.random()*255,math.random()*255,math.random()*255,1*255) 
		end	
	end
end

addEventHandler("onClientResourceStart", getResourceRootElement( getThisResource()), addStuff)

This creates 400 lovely billboards near position (0,0,0)

local vehicle1 = nil
addEventHandler("onClientVehicleEnter", getRootElement(),
    function(thePlayer, seat)
        if thePlayer == getLocalPlayer() then
            vehicle1 = source
        end
    end
)

local tex = dxCreateTexture("hello.jpg")
local carLight = exports.custom_billboards:createBillboard(tex,0,0,0,4,4,math.random()*255,math.random()*255,math.random()*255,1*255)
addEventHandler("onClientPreRender", root, function()
	if vehicle1 then 
		xxx1,yyy1,zzz1 = getElementPosition(vehicle1)
		exports.custom_billboards:setBillboardPosition(carLight,xxx1,yyy1,zzz1)
	end
end
) 

This creates a billboard and attaches it to a vehicle that the player enters.

Of course when you want to use these functions in your resources you have to include the custom_billboards resource in meta.

See Also

Resource download link

Test resource