// // SizeByVelocityModule.cpp // cocos2d_libs // // Created by 徐俊杰 on 2020/4/24. // #include "rparticle/Modules/SizeByVelocityModule.h" //#include "UnityPrefix.h" //#include "rparticle/Modules/SizeByVelocityModule.h" //#include "Runtime/BaseClasses/ObjectDefines.h" #include "rparticle/Serialize/TransferFunctions/SerializeTransfer.h" #include "rparticle/ParticleSystemUtils.h" NS_RRP_BEGIN SizeBySpeedModule::SizeBySpeedModule () : ParticleSystemModule(false) , m_Range (0.0f, 1.0f) {} template void UpdateTpl(const MinMaxCurve& curve, const ParticleSystemParticles& ps, float* tempSize, size_t fromIndex, size_t toIndex, const Vector2f offsetScale) { for (size_t q = fromIndex; q < toIndex; ++q) { const Vector3f vel = ps.velocity[q] + ps.animatedVelocity[q]; const float t = InverseLerpFast01 (offsetScale, Magnitude (vel)); const float random = GenerateRandom(ps.randomSeed[q] + kParticleSystemSizeBySpeedCurveId); tempSize[q] *= MAX(0.0f, Evaluate (curve, t, random)); } } template void UpdateTplSingle(const MinMaxCurve& curve, const ParticleSystemParticle& particle, float& tempSize, const Vector2f& scaleOffset) { const Vector3f vel = particle.velocity + particle.animatedVelocity; const float t = InverseLerpFast01(scaleOffset, Magnitude(vel)); const float random = GenerateRandom(particle.randomSeed + kParticleSystemSizeBySpeedCurveId); tempSize *= std::max(0.0f, Evaluate(curve, t, random)); } void SizeBySpeedModule::Update (const ParticleSystemReadOnlyState& roState, const ParticleSystemParticles& ps, float* tempSize, size_t fromIndex, size_t toIndex) { DebugAssert(toIndex <= ps.array_size ()); Vector2f offsetScale = CalculateInverseLerpOffsetScale(m_Range * roState.GetRenderScale()); if (m_Curve.minMaxState == kMMCScalar) UpdateTpl (m_Curve, ps, tempSize, fromIndex, toIndex, offsetScale); else if (m_Curve.IsOptimized() && m_Curve.UsesMinMax()) UpdateTpl (m_Curve, ps, tempSize, fromIndex, toIndex, offsetScale); else if(m_Curve.IsOptimized()) UpdateTpl (m_Curve, ps, tempSize, fromIndex, toIndex, offsetScale); else UpdateTpl (m_Curve, ps, tempSize, fromIndex, toIndex, offsetScale); } void SizeBySpeedModule::UpdateSingle(const ParticleSystemReadOnlyState& roState, const ParticleSystemParticle& particle, bool uses3DSize, float& tempSize) const { Vector2f offsetScale = CalculateInverseLerpOffsetScale(m_Range * roState.GetRenderScale()); if (m_Curve.minMaxState == kMMCScalar) UpdateTplSingle (m_Curve, particle, tempSize, offsetScale); else if (m_Curve.IsOptimized() && m_Curve.UsesMinMax()) UpdateTplSingle (m_Curve, particle, tempSize, offsetScale); else if(m_Curve.IsOptimized()) UpdateTplSingle (m_Curve, particle, tempSize, offsetScale); else UpdateTplSingle (m_Curve, particle, tempSize, offsetScale); } void SizeBySpeedModule::CheckConsistency () { const float MyEpsilon = 0.001f; m_Range.x = std::min (m_Range.x, m_Range.y - MyEpsilon); } template void SizeBySpeedModule::Transfer (TransferFunction& transfer) { ParticleSystemModule::Transfer (transfer); transfer.Transfer (m_Curve, "curve"); transfer.Transfer (m_Range, "range"); } INSTANTIATE_TEMPLATE_TRANSFER(SizeBySpeedModule) NS_RRP_END