hi folks!
I’am create some hit fx with flare fx and after that smoke fx.
[video]https://www.youtube.com/watch?v=cruJQ8F-1Ik[/video]
then flare fx end’s his life it produce smoke fx.
and in this smoke fx i’am do - StaticModel.GetMaterial(0).Clone() base material of smoke prefab for private animation state for each instant of smoke fx in scene.
in this case i’m curious how it manages with temporarily cloned material, they also deleted then smoke deleted? ( SmokeNode.Remove() )
for test this i’m want count of all materials in scene then i’m fire(create a lot instances of hit fx)
some code of that
Flare
void ScriptHitFx::Start()
{
ResourceCache* cache = GetSubsystem<ResourceCache>();
maxLifeTime = 0.25f; // ???????
currentLifeTime_ = 0.0f;
scaleAnim_ = SharedPtr<ValueAnimation>(new ValueAnimation(context_));
float startSize = 0.5f;
float endSize = 1.0f;
scaleAnim_->SetKeyFrame(0.0f, Vector3(startSize, startSize, startSize));
scaleAnim_->SetKeyFrame(0.25f, Vector3(endSize, endSize*2, endSize));
GetNode()->SetScale(startSize);
GetNode()->SetAttributeAnimation("Scale", scaleAnim_, WM_LOOP);
prefabSmokeFx_ = cache->GetResource<XMLFile>("Objects/SmokeFx.xml");
}
void ScriptHitFx::Update(float timeStep)
{
}
void ScriptHitFx::FixedUpdate(float timeStep)
{
if (currentLifeTime_ > maxLifeTime)
{
//Node* player = GetScene()->GetChild("playerNode", true);
Vector3 pos = GetNode()->GetWorldPosition();
Vector3 playerPos = player->GetWorldPosition();
Quaternion quat;
quat = GetNode()->GetRotation();
smokeFX_= SharedPtr<Node>(GetNode()->GetScene()->InstantiateXML(prefabSmokeFx_->GetRoot(), pos, quat, LOCAL));
smokeFX_->CreateComponent<ScriptSmokeFx>();
GetNode()->Remove();
}
currentLifeTime_ += timeStep;
}
Smoke Start Script
class ScriptSmokeFx : public LogicComponent
{
OBJECT(ScriptSmokeFx);
public:
/// Construct.
ScriptSmokeFx(Context* context);
/// Register object factory and attributes.
static void RegisterObject(Context* context);
virtual void Start();
void Update(float timeStep);
virtual void FixedUpdate(float timeStep);
float maxLifeTime;
private:
float currentLifeTime_;
SharedPtr<ValueAnimation> scaleAnim_;
SharedPtr<ValueAnimation> factorAnim_;
SharedPtr<ValueAnimation> colorAnim_;
SharedPtr<Material> mat_;
};
void ScriptSmokeFx::Start()
{
ResourceCache* cache = GetSubsystem<ResourceCache>();
maxLifeTime = 1.0f; // ???????
currentLifeTime_ = 0.0f;
scaleAnim_ = SharedPtr<ValueAnimation>(new ValueAnimation(context_));
float startSize = 1.0f;
float endSize = 3.0f;
scaleAnim_->SetKeyFrame(0.0f, Vector3(startSize, startSize, startSize));
scaleAnim_->SetKeyFrame(maxLifeTime, Vector3(endSize, endSize, endSize));
GetNode()->SetScale(startSize);
GetNode()->SetAttributeAnimation("Scale", scaleAnim_, WM_LOOP);
StaticModel* model = GetComponent<StaticModel>();
#if 1
mat_ = model->GetMaterial(0)->Clone("");
#else
mat_ = model->GetMaterial(0);
#endif
// alpha factor
factorAnim_ = SharedPtr<ValueAnimation>(new ValueAnimation(context_));
factorAnim_->SetKeyFrame(0.0f, 0.0f);
factorAnim_->SetKeyFrame(maxLifeTime / 5.0f, 0.2f);
factorAnim_->SetKeyFrame(maxLifeTime, 1.0f);
mat_->SetShaderParameterAnimation("Factor", factorAnim_);
mat_->SetScene(GetScene());
// color fade
colorAnim_ = SharedPtr<ValueAnimation>(new ValueAnimation(context_));
colorAnim_->SetKeyFrame(0.0f, Vector3(1.0f,1.0f,1.0f));
colorAnim_->SetKeyFrame((maxLifeTime / 3.0f), Vector3(1.0f,1.0f,1.0f));
colorAnim_->SetKeyFrame(maxLifeTime, Vector3(0.2f,0.2f,0.2f));
mat_->SetShaderParameterAnimation("MatDiffColor", colorAnim_);
mat_->SetScene(GetScene());
model->SetMaterial(0,mat_);
}