//////////////////////////////////////////////////////////////////////////
// initialise
//virtual
void ScnParticleSystemComponent::initialise( const Json::Value& Object )
{
	Super::initialise( Object );

	// Grab number of particles.
	NoofParticles_ = Object["noofparticles"].asUInt();
	ScnMaterialRef Material = getPackage()->getPackageCrossRef( Object["material"].asUInt() );
	if( !CsCore::pImpl()->createResource( BcName::INVALID, getPackage(), MaterialComponent_, Material, scnSPF_PARTICLE_3D ) )
	{
		BcAssertMsg( BcFalse, "Material invalid blah." );
	}

	IsLocalSpace_ = Object["localspace"].asBool();

	// Cache texture bounds.
	ScnTextureRef Texture = Material->getTexture( "aDiffuseTex" );
	for( BcU32 Idx = 0; Idx < Texture->noofRects(); ++Idx )
	{
		ScnRect Rect = Texture->getRect( Idx );
		UVBounds_.push_back( MaVec4d( Rect.X_, Rect.Y_, Rect.X_ + Rect.W_, Rect.Y_ + Rect.H_ ) );
	}

	WorldTransformParam_ = MaterialComponent_->findParameter( "uWorldTransform" );

	BcMemZero( &VertexBuffers_, sizeof( VertexBuffers_ ) );
	pParticleBuffer_ = NULL;
	CurrentVertexBuffer_ = 0;

	PotentialFreeParticle_ = 0;
}
//////////////////////////////////////////////////////////////////////////
// initialise
//virtual
void ScnParticleSystemComponent::initialise()
{
	Super::initialise();

	// Cache texture bounds.
	if( Material_ != nullptr )
	{
		ScnTextureRef Texture = Material_->getTexture( "aDiffuseTex" );
		if( Texture.isValid() )
		{
			UVBounds_.reserve( Texture->noofRects() );
			for( BcU32 Idx = 0; Idx < Texture->noofRects(); ++Idx )
			{
				ScnRect Rect = Texture->getRect( Idx );
				UVBounds_.push_back( MaVec4d( Rect.X_, Rect.Y_, Rect.X_ + Rect.W_, Rect.Y_ + Rect.H_ ) );
			}
		}
		else
		{
			UVBounds_.push_back( MaVec4d( 0.0f, 0.0f, 1.0f, 1.0f ) );
		}
	}
}