function BallUpdate(idx)
	local as = gSportsRNA
	local state = as:GetTable("wvState")
	local ball = as:GetTable("wvBall", idx)

	db.ball[idx].model = as:GetInt(ball, "ballModel") 
	db.ball[idx].envLighting = as:GetInt(state, "wvAttribEnvLighting")
	db.ball[idx].stadLightID = as:GetInt(state, "wvAttribStadLightID")
	db.ball[idx].stadiumID = as:GetInt(state, "wvAttribStadID")
	
	
	local wipe3d = as:GetTable("wvWipe", idx)
	local stadium = as:GetTable("wvStadium", idx)
	
	db.ball[idx].ballTournID = as:GetInt(wipe3d, "leagueID")
	db.ball[idx].ballTournID = getTournamentGraphics(db.ball[idx].ballTournID)
	db.ball[idx].ballTeamID = as:GetInt(stadium, "homeKitTeamID" )
	
	local weather = as:GetInt(state, "wvAttribStadWeather" )
	
	db.ball[idx].ballWinter = -1
	if (isWinter) then
	db.ball[idx].ballWinter = 1
	end
	
	db.ball[idx].ballSnow = -1
	if (weather == 2) then
	db.ball[idx].ballSnow = 2
	end
	
	db.ball[idx].ballTournGenID = -1
	if (teamTournament[db.ball[idx].ballTeamID] ~= nil) then
	db.ball[idx].ballTournGenID = teamTournament[db.ball[idx].ballTeamID]
	end
	
end

function BallAssetBind(ball)
	local gr = gRenderables
   	local lod = 0

	gr:AddCallback(ball, lod, "BallUpdate(?)")
	gr:AddAsset(ball, lod, "shader", "data/fifarna/shader.big")
	gr:AddAsset(ball, lod, "ballmesh", "${GetRMBall(?,0)}data/sceneassets/ball/ball_${db.ball[?].model}.rx3")
	gr:AddAsset(ball, lod, "balltex", "${GetRMBall(?,1)}data/sceneassets/ball/ball_${db.ball[?].model}_textures.rx3")
	gr:AddAsset(ball, lod, "charcmn", "data/sceneassets/charactercmn/charactercmn_${db.ball[?].envLighting}.rx3")	
	gr:CreateMaterialFromAttribulator(ball, lod, "ballmesh", "ball", "${AttribMaterial('ball')}" )
	gr:SetTexture(ball, lod, "ballmesh", "textures", "diffuseTexture", "balltex", "ball_cm")
	gr:SetTexture(ball, lod, "ballmesh", "textures", "normalMap", "balltex", "ball_nm")
	gr:SetTexture(ball, lod, "ballmesh", "textures", "envDiffuseTexture", "charcmn", "envd_")
	gr:SetTexture(ball, lod, "ballmesh", "textures", "envSpecTexture", "charcmn", "envs_")
	gr:SetTextureFromRuntime(ball, lod, "ballmesh", "textures", "coverageMap", "covmap_${db.ball[?].stadiumID}_${db.ball[?].stadLightID}")
	return ball
end


function GetRMBall(idx,isModel)
	local ballorder = ""
	local fileType = ""
	
	if (isModel == 1) then
	fileType = "_textures"
	end

	ballorder = ballorder.."data/sceneassets/ball/specificball_"..db.ball[idx].ballTeamID.."_"..db.ball[idx].ballTournID.."_"..db.ball[idx].ballSnow..""..fileType..".rx3;"
	ballorder = ballorder.."data/sceneassets/ball/specificball_"..db.ball[idx].ballTeamID.."_"..db.ball[idx].ballTournID.."_"..db.ball[idx].ballWinter..""..fileType..".rx3;"
	ballorder = ballorder.."data/sceneassets/ball/specificball_"..db.ball[idx].ballTeamID.."_"..db.ball[idx].ballTournID.."_0"..fileType..".rx3;"
	ballorder = ballorder.."data/sceneassets/ball/specificball_0_"..db.ball[idx].ballTournID.."_"..db.ball[idx].ballSnow..""..fileType..".rx3;"
	ballorder = ballorder.."data/sceneassets/ball/specificball_0_"..db.ball[idx].ballTournID.."_"..db.ball[idx].ballWinter..""..fileType..".rx3;"
	ballorder = ballorder.."data/sceneassets/ball/specificball_0_"..db.ball[idx].ballTournID.."_0"..fileType..".rx3;"
	ballorder = ballorder.."data/sceneassets/ball/specificball_"..db.ball[idx].ballTeamID.."_0_"..db.ball[idx].ballSnow..""..fileType..".rx3;"
	ballorder = ballorder.."data/sceneassets/ball/specificball_"..db.ball[idx].ballTeamID.."_0_"..db.ball[idx].ballWinter..""..fileType..".rx3;"
	ballorder = ballorder.."data/sceneassets/ball/specificball_"..db.ball[idx].ballTeamID.."_0_0"..fileType..".rx3;"
	ballorder = ballorder.."data/sceneassets/ball/specificball_0_"..db.ball[idx].ballTournGenID.."_"..db.ball[idx].ballSnow..""..fileType..".rx3;"
	ballorder = ballorder.."data/sceneassets/ball/specificball_0_"..db.ball[idx].ballTournGenID.."_"..db.ball[idx].ballWinter..""..fileType..".rx3;"
	ballorder = ballorder.."data/sceneassets/ball/specificball_0_"..db.ball[idx].ballTournGenID.."_0"..fileType..".rx3;"
	ballorder = ballorder.."data/sceneassets/ball/specificball_0_0_0"..fileType..".rx3;"
	return ballorder
end


isWinter = false

function useWinterBalls()
isWinter = true
end

--Revolution Mod 14 1.0
--Edited by scouser09
