mirror of
https://github.com/u0u0/Cocos2d-Lua-Community.git
synced 2026-05-06 22:01:44 +08:00
Revert "Merge branch '5.x' of GitHub:u0u0/Cocos2d-Lua-Community"
This reverts commit9314743649, reversing changes made toa5d08e301d.
This commit is contained in:
309
extensions/CMakeLists.txt
Normal file
309
extensions/CMakeLists.txt
Normal file
@@ -0,0 +1,309 @@
|
||||
set(COCOS_EXTENSIONS_HEADER
|
||||
../extensions/Particle3D/CCParticleSystem3D.h
|
||||
../extensions/Particle3D/PU/CCPUDoExpireEventHandler.h
|
||||
../extensions/Particle3D/PU/CCPUParticleSystem3D.h
|
||||
../extensions/Particle3D/PU/CCPUDoStopSystemEventHandler.h
|
||||
../extensions/Particle3D/PU/CCPUAffectorManager.h
|
||||
../extensions/Particle3D/PU/CCPUTechniqueTranslator.h
|
||||
../extensions/Particle3D/PU/CCPURender.h
|
||||
../extensions/Particle3D/PU/CCPUObserver.h
|
||||
../extensions/Particle3D/PU/CCPUMeshSurfaceEmitterTranslator.h
|
||||
../extensions/Particle3D/PU/CCPUAlignAffector.h
|
||||
../extensions/Particle3D/PU/CCPUSphereColliderTranslator.h
|
||||
../extensions/Particle3D/PU/CCPUAffectorTranslator.h
|
||||
../extensions/Particle3D/PU/CCPUTextureRotator.h
|
||||
../extensions/Particle3D/PU/CCPUTextureRotatorTranslator.h
|
||||
../extensions/Particle3D/PU/CCPUParticleSystem3DTranslator.h
|
||||
../extensions/Particle3D/PU/CCPUCircleEmitterTranslator.h
|
||||
../extensions/Particle3D/PU/CCPURandomiser.h
|
||||
../extensions/Particle3D/PU/CCPUBoxCollider.h
|
||||
../extensions/Particle3D/PU/CCPUScriptCompiler.h
|
||||
../extensions/Particle3D/PU/CCPUDynamicAttributeTranslator.h
|
||||
../extensions/Particle3D/PU/CCPUOnRandomObserver.h
|
||||
../extensions/Particle3D/PU/CCPUOnCollisionObserver.h
|
||||
../extensions/Particle3D/PU/CCPUBoxEmitterTranslator.h
|
||||
../extensions/Particle3D/PU/CCPUDoAffectorEventHandler.h
|
||||
../extensions/Particle3D/PU/CCPUEventHandlerTranslator.h
|
||||
../extensions/Particle3D/PU/CCPULineEmitterTranslator.h
|
||||
../extensions/Particle3D/PU/CCPUMaterialTranslator.h
|
||||
../extensions/Particle3D/PU/CCPUVelocityMatchingAffector.h
|
||||
../extensions/Particle3D/PU/CCPUEmitterTranslator.h
|
||||
../extensions/Particle3D/PU/CCPUOnCountObserver.h
|
||||
../extensions/Particle3D/PU/CCPUScriptParser.h
|
||||
../extensions/Particle3D/PU/CCPUOnEmissionObserver.h
|
||||
../extensions/Particle3D/PU/CCPUBaseForceAffectorTranslator.h
|
||||
../extensions/Particle3D/PU/CCPURibbonTrailRender.h
|
||||
../extensions/Particle3D/PU/CCPUDoPlacementParticleEventHandlerTranslator.h
|
||||
../extensions/Particle3D/PU/CCPUDoScaleEventHandler.h
|
||||
../extensions/Particle3D/PU/CCPUScriptTranslator.h
|
||||
../extensions/Particle3D/PU/CCPURandomiserTranslator.h
|
||||
../extensions/Particle3D/PU/CCPUBoxEmitter.h
|
||||
../extensions/Particle3D/PU/CCPUPlaneColliderTranslator.h
|
||||
../extensions/Particle3D/PU/CCPUVortexAffectorTranslator.h
|
||||
../extensions/Particle3D/PU/CCPUUtil.h
|
||||
../extensions/Particle3D/PU/CCPUListener.h
|
||||
../extensions/Particle3D/PU/CCPUGravityAffectorTranslator.h
|
||||
../extensions/Particle3D/PU/CCPUDoEnableComponentEventHandler.h
|
||||
../extensions/Particle3D/PU/CCPUInterParticleCollider.h
|
||||
../extensions/Particle3D/PU/CCPUDoStopSystemEventHandlerTranslator.h
|
||||
../extensions/Particle3D/PU/CCPUPositionEmitterTranslator.h
|
||||
../extensions/Particle3D/PU/CCPUGeometryRotator.h
|
||||
../extensions/Particle3D/PU/CCPUOnEventFlagObserver.h
|
||||
../extensions/Particle3D/PU/CCPULinearForceAffector.h
|
||||
../extensions/Particle3D/PU/CCPUOnTimeObserverTranslator.h
|
||||
../extensions/Particle3D/PU/CCPUBillboardChain.h
|
||||
../extensions/Particle3D/PU/CCPUScaleVelocityAffectorTranslator.h
|
||||
../extensions/Particle3D/PU/CCPUParticleFollower.h
|
||||
../extensions/Particle3D/PU/CCPUPositionEmitter.h
|
||||
../extensions/Particle3D/PU/CCPUTextureAnimatorTranslator.h
|
||||
../extensions/Particle3D/PU/CCPUPlaneCollider.h
|
||||
../extensions/Particle3D/PU/CCPUBehaviour.h
|
||||
../extensions/Particle3D/PU/CCPUOnQuotaObserver.h
|
||||
../extensions/Particle3D/PU/CCPULineAffectorTranslator.h
|
||||
../extensions/Particle3D/PU/CCPUJetAffectorTranslator.h
|
||||
../extensions/Particle3D/PU/CCPUDoEnableComponentEventHandlerTranslator.h
|
||||
../extensions/Particle3D/PU/CCPUForceFieldAffector.h
|
||||
../extensions/Particle3D/PU/CCPUDoFreezeEventHandler.h
|
||||
../extensions/Particle3D/PU/CCPUOnClearObserverTranslator.h
|
||||
../extensions/Particle3D/PU/CCPUAffector.h
|
||||
../extensions/Particle3D/PU/CCPUAlignAffectorTranslator.h
|
||||
../extensions/Particle3D/PU/CCPUEmitterManager.h
|
||||
../extensions/Particle3D/PU/CCPUObserverTranslator.h
|
||||
../extensions/Particle3D/PU/CCPUBaseCollider.h
|
||||
../extensions/Particle3D/PU/CCPUParticleFollowerTranslator.h
|
||||
../extensions/Particle3D/PU/CCPUBaseColliderTranslator.h
|
||||
../extensions/Particle3D/PU/CCPUOnVelocityObserverTranslator.h
|
||||
../extensions/Particle3D/PU/CCPUVertexEmitter.h
|
||||
../extensions/Particle3D/PU/CCPUMaterialManager.h
|
||||
../extensions/Particle3D/PU/CCPUScaleAffectorTranslator.h
|
||||
../extensions/Particle3D/PU/CCPUSphereSurfaceEmitterTranslator.h
|
||||
../extensions/Particle3D/PU/CCPUSphereSurfaceEmitter.h
|
||||
../extensions/Particle3D/PU/CCPUEmitter.h
|
||||
../extensions/Particle3D/PU/CCPUCollisionAvoidanceAffector.h
|
||||
../extensions/Particle3D/PU/CCPUDoFreezeEventHandlerTranslator.h
|
||||
../extensions/Particle3D/PU/CCPUSimpleSpline.h
|
||||
../extensions/Particle3D/PU/CCPUFlockCenteringAffector.h
|
||||
../extensions/Particle3D/PU/CCPUOnExpireObserverTranslator.h
|
||||
../extensions/Particle3D/PU/CCPULineEmitter.h
|
||||
../extensions/Particle3D/PU/CCPUDoAffectorEventHandlerTranslator.h
|
||||
../extensions/Particle3D/PU/CCPUTextureAnimator.h
|
||||
../extensions/Particle3D/PU/CCPUSineForceAffectorTranslator.h
|
||||
../extensions/Particle3D/PU/CCPUCircleEmitter.h
|
||||
../extensions/Particle3D/PU/CCPUSlaveBehaviour.h
|
||||
../extensions/Particle3D/PU/CCPUOnPositionObserverTranslator.h
|
||||
../extensions/Particle3D/PU/CCPUOnEventFlagObserverTranslator.h
|
||||
../extensions/Particle3D/PU/CCPUScriptLexer.h
|
||||
../extensions/Particle3D/PU/CCPUOnExpireObserver.h
|
||||
../extensions/Particle3D/PU/CCPUOnRandomObserverTranslator.h
|
||||
../extensions/Particle3D/PU/CCPURibbonTrail.h
|
||||
../extensions/Particle3D/PU/CCPUColorAffectorTranslator.h
|
||||
../extensions/Particle3D/PU/CCPUEventHandler.h
|
||||
../extensions/Particle3D/PU/CCPUNoise.h
|
||||
../extensions/Particle3D/PU/CCPUEventHandlerManager.h
|
||||
../extensions/Particle3D/PU/CCPUSlaveBehaviourTranslator.h
|
||||
../extensions/Particle3D/PU/CCPUColorAffector.h
|
||||
../extensions/Particle3D/PU/CCPUScaleVelocityAffector.h
|
||||
../extensions/Particle3D/PU/CCPUDynamicAttribute.h
|
||||
../extensions/Particle3D/PU/CCPUSphere.h
|
||||
../extensions/Particle3D/PU/CCPUSlaveEmitter.h
|
||||
../extensions/Particle3D/PU/CCPUBaseForceAffector.h
|
||||
../extensions/Particle3D/PU/CCPUVelocityMatchingAffectorTranslator.h
|
||||
../extensions/Particle3D/PU/CCPUDoScaleEventHandlerTranslator.h
|
||||
../extensions/Particle3D/PU/CCPUGravityAffector.h
|
||||
../extensions/Particle3D/PU/CCPUBeamRender.h
|
||||
../extensions/Particle3D/PU/CCPUOnClearObserver.h
|
||||
../extensions/Particle3D/PU/CCPUOnEmissionObserverTranslator.h
|
||||
../extensions/Particle3D/PU/CCPUJetAffector.h
|
||||
../extensions/Particle3D/PU/CCPUSphereCollider.h
|
||||
../extensions/Particle3D/PU/CCPUPathFollowerTranslator.h
|
||||
../extensions/Particle3D/PU/CCPUOnQuotaObserverTranslator.h
|
||||
../extensions/Particle3D/PU/CCPUPointEmitter.h
|
||||
../extensions/Particle3D/PU/CCPUCollisionAvoidanceAffectorTranslator.h
|
||||
../extensions/Particle3D/PU/CCPUPlane.h
|
||||
../extensions/Particle3D/PU/CCPUGeometryRotatorTranslator.h
|
||||
../extensions/Particle3D/PU/CCPUOnCountObserverTranslator.h
|
||||
../extensions/Particle3D/PU/CCPUDoExpireEventHandlerTranslator.h
|
||||
../extensions/Particle3D/PU/CCPUMeshSurfaceEmitter.h
|
||||
../extensions/Particle3D/PU/CCPULineAffector.h
|
||||
../extensions/Particle3D/PU/CCPUSineForceAffector.h
|
||||
../extensions/Particle3D/PU/CCPUPathFollower.h
|
||||
../extensions/Particle3D/PU/CCPULinearForceAffectorTranslator.h
|
||||
../extensions/Particle3D/PU/CCPUObserverManager.h
|
||||
../extensions/Particle3D/PU/CCPUBoxColliderTranslator.h
|
||||
../extensions/Particle3D/PU/CCPUDoPlacementParticleEventHandler.h
|
||||
../extensions/Particle3D/PU/CCPUOnVelocityObserver.h
|
||||
../extensions/Particle3D/PU/CCPUScaleAffector.h
|
||||
../extensions/Particle3D/PU/CCPUInterParticleColliderTranslator.h
|
||||
../extensions/Particle3D/PU/CCPUPointEmitterTranslator.h
|
||||
../extensions/Particle3D/PU/CCPUVortexAffector.h
|
||||
../extensions/Particle3D/PU/CCPUTranslateManager.h
|
||||
../extensions/Particle3D/PU/CCPUFlockCenteringAffectorTranslator.h
|
||||
../extensions/Particle3D/PU/CCPUOnTimeObserver.h
|
||||
../extensions/Particle3D/PU/CCPUBehaviourManager.h
|
||||
../extensions/Particle3D/PU/CCPUOnCollisionObserverTranslator.h
|
||||
../extensions/Particle3D/PU/CCPURendererTranslator.h
|
||||
../extensions/Particle3D/PU/CCPUSlaveEmitterTranslator.h
|
||||
../extensions/Particle3D/PU/CCPUBehaviourTranslator.h
|
||||
../extensions/Particle3D/PU/CCPUForceField.h
|
||||
../extensions/Particle3D/PU/CCPUForceFieldAffectorTranslator.h
|
||||
../extensions/Particle3D/PU/CCPUOnPositionObserver.h
|
||||
../extensions/Particle3D/CCParticle3DEmitter.h
|
||||
../extensions/Particle3D/CCParticle3DAffector.h
|
||||
../extensions/Particle3D/CCParticle3DRender.h
|
||||
../extensions/cocos-ext.h
|
||||
)
|
||||
|
||||
set(COCOS_EXTENSIONS_SRC
|
||||
|
||||
../extensions/Particle3D/CCParticle3DAffector.cpp
|
||||
../extensions/Particle3D/CCParticle3DEmitter.cpp
|
||||
../extensions/Particle3D/CCParticle3DRender.cpp
|
||||
../extensions/Particle3D/CCParticleSystem3D.cpp
|
||||
../extensions/Particle3D/PU/CCPUDynamicAttribute.cpp
|
||||
../extensions/Particle3D/PU/CCPUDynamicAttributeTranslator.cpp
|
||||
../extensions/Particle3D/PU/CCPUForceField.cpp
|
||||
../extensions/Particle3D/PU/CCPUMaterialManager.cpp
|
||||
../extensions/Particle3D/PU/CCPUMaterialTranslator.cpp
|
||||
../extensions/Particle3D/PU/CCPUNoise.cpp
|
||||
../extensions/Particle3D/PU/CCPUPlane.cpp
|
||||
../extensions/Particle3D/PU/CCPURendererTranslator.cpp
|
||||
../extensions/Particle3D/PU/CCPUScriptCompiler.cpp
|
||||
../extensions/Particle3D/PU/CCPUScriptLexer.cpp
|
||||
../extensions/Particle3D/PU/CCPUScriptParser.cpp
|
||||
../extensions/Particle3D/PU/CCPUScriptTranslator.cpp
|
||||
../extensions/Particle3D/PU/CCPUSimpleSpline.cpp
|
||||
../extensions/Particle3D/PU/CCPUSphere.cpp
|
||||
../extensions/Particle3D/PU/CCPUTechniqueTranslator.cpp
|
||||
../extensions/Particle3D/PU/CCPUTranslateManager.cpp
|
||||
../extensions/Particle3D/PU/CCPUUtil.cpp
|
||||
../extensions/Particle3D/PU/CCPUParticleSystem3D.cpp
|
||||
../extensions/Particle3D/PU/CCPUParticleSystem3DTranslator.cpp
|
||||
../extensions/Particle3D/PU/CCPUListener.cpp
|
||||
../extensions/Particle3D/PU/CCPUAffector.cpp
|
||||
../extensions/Particle3D/PU/CCPUAffectorManager.cpp
|
||||
../extensions/Particle3D/PU/CCPUAffectorTranslator.cpp
|
||||
../extensions/Particle3D/PU/CCPUAlignAffector.cpp
|
||||
../extensions/Particle3D/PU/CCPUAlignAffectorTranslator.cpp
|
||||
../extensions/Particle3D/PU/CCPUBaseCollider.cpp
|
||||
../extensions/Particle3D/PU/CCPUBaseColliderTranslator.cpp
|
||||
../extensions/Particle3D/PU/CCPUBaseForceAffector.cpp
|
||||
../extensions/Particle3D/PU/CCPUBaseForceAffectorTranslator.cpp
|
||||
../extensions/Particle3D/PU/CCPUBoxCollider.cpp
|
||||
../extensions/Particle3D/PU/CCPUBoxColliderTranslator.cpp
|
||||
../extensions/Particle3D/PU/CCPUCollisionAvoidanceAffector.cpp
|
||||
../extensions/Particle3D/PU/CCPUCollisionAvoidanceAffectorTranslator.cpp
|
||||
../extensions/Particle3D/PU/CCPUColorAffector.cpp
|
||||
../extensions/Particle3D/PU/CCPUColorAffectorTranslator.cpp
|
||||
../extensions/Particle3D/PU/CCPUFlockCenteringAffector.cpp
|
||||
../extensions/Particle3D/PU/CCPUFlockCenteringAffectorTranslator.cpp
|
||||
../extensions/Particle3D/PU/CCPUForceFieldAffector.cpp
|
||||
../extensions/Particle3D/PU/CCPUForceFieldAffectorTranslator.cpp
|
||||
../extensions/Particle3D/PU/CCPUGeometryRotator.cpp
|
||||
../extensions/Particle3D/PU/CCPUGeometryRotatorTranslator.cpp
|
||||
../extensions/Particle3D/PU/CCPUGravityAffector.cpp
|
||||
../extensions/Particle3D/PU/CCPUGravityAffectorTranslator.cpp
|
||||
../extensions/Particle3D/PU/CCPUInterParticleCollider.cpp
|
||||
../extensions/Particle3D/PU/CCPUInterParticleColliderTranslator.cpp
|
||||
../extensions/Particle3D/PU/CCPUJetAffector.cpp
|
||||
../extensions/Particle3D/PU/CCPUJetAffectorTranslator.cpp
|
||||
../extensions/Particle3D/PU/CCPULineAffector.cpp
|
||||
../extensions/Particle3D/PU/CCPULineAffectorTranslator.cpp
|
||||
../extensions/Particle3D/PU/CCPULinearForceAffector.cpp
|
||||
../extensions/Particle3D/PU/CCPULinearForceAffectorTranslator.cpp
|
||||
../extensions/Particle3D/PU/CCPUParticleFollower.cpp
|
||||
../extensions/Particle3D/PU/CCPUParticleFollowerTranslator.cpp
|
||||
../extensions/Particle3D/PU/CCPUPathFollower.cpp
|
||||
../extensions/Particle3D/PU/CCPUPathFollowerTranslator.cpp
|
||||
../extensions/Particle3D/PU/CCPUPlaneCollider.cpp
|
||||
../extensions/Particle3D/PU/CCPUPlaneColliderTranslator.cpp
|
||||
../extensions/Particle3D/PU/CCPURandomiser.cpp
|
||||
../extensions/Particle3D/PU/CCPURandomiserTranslator.cpp
|
||||
../extensions/Particle3D/PU/CCPUScaleAffector.cpp
|
||||
../extensions/Particle3D/PU/CCPUScaleAffectorTranslator.cpp
|
||||
../extensions/Particle3D/PU/CCPUScaleVelocityAffector.cpp
|
||||
../extensions/Particle3D/PU/CCPUScaleVelocityAffectorTranslator.cpp
|
||||
../extensions/Particle3D/PU/CCPUSineForceAffector.cpp
|
||||
../extensions/Particle3D/PU/CCPUSineForceAffectorTranslator.cpp
|
||||
../extensions/Particle3D/PU/CCPUSphereCollider.cpp
|
||||
../extensions/Particle3D/PU/CCPUSphereColliderTranslator.cpp
|
||||
../extensions/Particle3D/PU/CCPUTextureAnimator.cpp
|
||||
../extensions/Particle3D/PU/CCPUTextureAnimatorTranslator.cpp
|
||||
../extensions/Particle3D/PU/CCPUTextureRotator.cpp
|
||||
../extensions/Particle3D/PU/CCPUTextureRotatorTranslator.cpp
|
||||
../extensions/Particle3D/PU/CCPUVelocityMatchingAffector.cpp
|
||||
../extensions/Particle3D/PU/CCPUVelocityMatchingAffectorTranslator.cpp
|
||||
../extensions/Particle3D/PU/CCPUVortexAffector.cpp
|
||||
../extensions/Particle3D/PU/CCPUVortexAffectorTranslator.cpp
|
||||
../extensions/Particle3D/PU/CCPUBoxEmitter.cpp
|
||||
../extensions/Particle3D/PU/CCPUBoxEmitterTranslator.cpp
|
||||
../extensions/Particle3D/PU/CCPUCircleEmitter.cpp
|
||||
../extensions/Particle3D/PU/CCPUCircleEmitterTranslator.cpp
|
||||
../extensions/Particle3D/PU/CCPUEmitter.cpp
|
||||
../extensions/Particle3D/PU/CCPUEmitterManager.cpp
|
||||
../extensions/Particle3D/PU/CCPUEmitterTranslator.cpp
|
||||
../extensions/Particle3D/PU/CCPULineEmitter.cpp
|
||||
../extensions/Particle3D/PU/CCPULineEmitterTranslator.cpp
|
||||
../extensions/Particle3D/PU/CCPUMeshSurfaceEmitter.cpp
|
||||
../extensions/Particle3D/PU/CCPUMeshSurfaceEmitterTranslator.cpp
|
||||
../extensions/Particle3D/PU/CCPUPointEmitter.cpp
|
||||
../extensions/Particle3D/PU/CCPUPointEmitterTranslator.cpp
|
||||
../extensions/Particle3D/PU/CCPUPositionEmitter.cpp
|
||||
../extensions/Particle3D/PU/CCPUPositionEmitterTranslator.cpp
|
||||
../extensions/Particle3D/PU/CCPUSlaveEmitter.cpp
|
||||
../extensions/Particle3D/PU/CCPUSlaveEmitterTranslator.cpp
|
||||
../extensions/Particle3D/PU/CCPUSphereSurfaceEmitter.cpp
|
||||
../extensions/Particle3D/PU/CCPUSphereSurfaceEmitterTranslator.cpp
|
||||
../extensions/Particle3D/PU/CCPUVertexEmitter.cpp
|
||||
../extensions/Particle3D/PU/CCPURender.cpp
|
||||
../extensions/Particle3D/PU/CCPUBeamRender.cpp
|
||||
../extensions/Particle3D/PU/CCPUBillboardChain.cpp
|
||||
../extensions/Particle3D/PU/CCPURibbonTrail.cpp
|
||||
../extensions/Particle3D/PU/CCPURibbonTrailRender.cpp
|
||||
../extensions/Particle3D/PU/CCPUDoAffectorEventHandler.cpp
|
||||
../extensions/Particle3D/PU/CCPUDoAffectorEventHandlerTranslator.cpp
|
||||
../extensions/Particle3D/PU/CCPUDoEnableComponentEventHandler.cpp
|
||||
../extensions/Particle3D/PU/CCPUDoEnableComponentEventHandlerTranslator.cpp
|
||||
../extensions/Particle3D/PU/CCPUDoExpireEventHandler.cpp
|
||||
../extensions/Particle3D/PU/CCPUDoExpireEventHandlerTranslator.cpp
|
||||
../extensions/Particle3D/PU/CCPUDoFreezeEventHandler.cpp
|
||||
../extensions/Particle3D/PU/CCPUDoFreezeEventHandlerTranslator.cpp
|
||||
../extensions/Particle3D/PU/CCPUDoPlacementParticleEventHandler.cpp
|
||||
../extensions/Particle3D/PU/CCPUDoPlacementParticleEventHandlerTranslator.cpp
|
||||
../extensions/Particle3D/PU/CCPUDoScaleEventHandler.cpp
|
||||
../extensions/Particle3D/PU/CCPUDoScaleEventHandlerTranslator.cpp
|
||||
../extensions/Particle3D/PU/CCPUDoStopSystemEventHandler.cpp
|
||||
../extensions/Particle3D/PU/CCPUDoStopSystemEventHandlerTranslator.cpp
|
||||
../extensions/Particle3D/PU/CCPUEventHandler.cpp
|
||||
../extensions/Particle3D/PU/CCPUEventHandlerManager.cpp
|
||||
../extensions/Particle3D/PU/CCPUEventHandlerTranslator.cpp
|
||||
../extensions/Particle3D/PU/CCPUObserver.cpp
|
||||
../extensions/Particle3D/PU/CCPUObserverManager.cpp
|
||||
../extensions/Particle3D/PU/CCPUObserverTranslator.cpp
|
||||
../extensions/Particle3D/PU/CCPUOnClearObserver.cpp
|
||||
../extensions/Particle3D/PU/CCPUOnClearObserverTranslator.cpp
|
||||
../extensions/Particle3D/PU/CCPUOnCollisionObserver.cpp
|
||||
../extensions/Particle3D/PU/CCPUOnCollisionObserverTranslator.cpp
|
||||
../extensions/Particle3D/PU/CCPUOnCountObserver.cpp
|
||||
../extensions/Particle3D/PU/CCPUOnCountObserverTranslator.cpp
|
||||
../extensions/Particle3D/PU/CCPUOnEmissionObserver.cpp
|
||||
../extensions/Particle3D/PU/CCPUOnEmissionObserverTranslator.cpp
|
||||
../extensions/Particle3D/PU/CCPUOnEventFlagObserver.cpp
|
||||
../extensions/Particle3D/PU/CCPUOnEventFlagObserverTranslator.cpp
|
||||
../extensions/Particle3D/PU/CCPUOnExpireObserver.cpp
|
||||
../extensions/Particle3D/PU/CCPUOnExpireObserverTranslator.cpp
|
||||
../extensions/Particle3D/PU/CCPUOnPositionObserver.cpp
|
||||
../extensions/Particle3D/PU/CCPUOnPositionObserverTranslator.cpp
|
||||
../extensions/Particle3D/PU/CCPUOnQuotaObserver.cpp
|
||||
../extensions/Particle3D/PU/CCPUOnQuotaObserverTranslator.cpp
|
||||
../extensions/Particle3D/PU/CCPUOnRandomObserver.cpp
|
||||
../extensions/Particle3D/PU/CCPUOnRandomObserverTranslator.cpp
|
||||
../extensions/Particle3D/PU/CCPUOnTimeObserver.cpp
|
||||
../extensions/Particle3D/PU/CCPUOnTimeObserverTranslator.cpp
|
||||
../extensions/Particle3D/PU/CCPUOnVelocityObserver.cpp
|
||||
../extensions/Particle3D/PU/CCPUOnVelocityObserverTranslator.cpp
|
||||
../extensions/Particle3D/PU/CCPUBehaviour.cpp
|
||||
../extensions/Particle3D/PU/CCPUBehaviourManager.cpp
|
||||
../extensions/Particle3D/PU/CCPUBehaviourTranslator.cpp
|
||||
../extensions/Particle3D/PU/CCPUSlaveBehaviour.cpp
|
||||
../extensions/Particle3D/PU/CCPUSlaveBehaviourTranslator.cpp
|
||||
)
|
||||
48
extensions/Particle3D/CCParticle3DAffector.cpp
Executable file
48
extensions/Particle3D/CCParticle3DAffector.cpp
Executable file
@@ -0,0 +1,48 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCParticle3DAffector.h"
|
||||
#include "CCParticleSystem3D.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
Particle3DAffector::Particle3DAffector()
|
||||
: _particleSystem(nullptr)
|
||||
, _isEnabled(true)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Particle3DAffector::~Particle3DAffector()
|
||||
{
|
||||
_particleSystem = nullptr;
|
||||
}
|
||||
|
||||
void Particle3DAffector::updateAffector(Particle3D* /*particle*/, float /*deltaTime*/)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
61
extensions/Particle3D/CCParticle3DAffector.h
Normal file
61
extensions/Particle3D/CCParticle3DAffector.h
Normal file
@@ -0,0 +1,61 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __CC_PARTICLE_3D_AFFECTOR_H__
|
||||
#define __CC_PARTICLE_3D_AFFECTOR_H__
|
||||
|
||||
#include "base/CCRef.h"
|
||||
#include <vector>
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class ParticleSystem3D;
|
||||
struct Particle3D;
|
||||
|
||||
class CC_DLL Particle3DAffector : public Ref
|
||||
{
|
||||
friend class ParticleSystem3D;
|
||||
public:
|
||||
|
||||
virtual void updateAffector(Particle3D* particle, float deltaTime);
|
||||
|
||||
/** Enables or disables the emitter.
|
||||
*/
|
||||
void setEnabled (bool enabled) { _isEnabled = enabled; }
|
||||
|
||||
bool isEnabled() const { return _isEnabled; }
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
Particle3DAffector();
|
||||
virtual ~Particle3DAffector();
|
||||
|
||||
protected:
|
||||
ParticleSystem3D* _particleSystem;
|
||||
bool _isEnabled;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif
|
||||
52
extensions/Particle3D/CCParticle3DEmitter.cpp
Executable file
52
extensions/Particle3D/CCParticle3DEmitter.cpp
Executable file
@@ -0,0 +1,52 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCParticle3DEmitter.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
Particle3DEmitter::Particle3DEmitter()
|
||||
: _particleSystem(nullptr)
|
||||
, _isEnabled(true)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Particle3DEmitter::~Particle3DEmitter()
|
||||
{
|
||||
_particleSystem = nullptr;
|
||||
}
|
||||
|
||||
void Particle3DEmitter::updateEmitter(Particle3D* /*particle*/, float /*deltaTime*/)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Particle3DEmitter::emit(int /*count*/)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
66
extensions/Particle3D/CCParticle3DEmitter.h
Normal file
66
extensions/Particle3D/CCParticle3DEmitter.h
Normal file
@@ -0,0 +1,66 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __CC_PARTICLE_3D_EMITTER_H__
|
||||
#define __CC_PARTICLE_3D_EMITTER_H__
|
||||
|
||||
#include "base/CCRef.h"
|
||||
#include <vector>
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class ParticleSystem3D;
|
||||
struct Particle3D;
|
||||
/**
|
||||
* 3d particle emitter
|
||||
*/
|
||||
class CC_DLL Particle3DEmitter : public Ref
|
||||
{
|
||||
friend class ParticleSystem3D;
|
||||
public:
|
||||
|
||||
virtual void updateEmitter(Particle3D* particle, float deltaTime);
|
||||
|
||||
virtual void emit(int count);
|
||||
|
||||
/** Enables or disables the emitter.
|
||||
*/
|
||||
void setEnabled (bool enabled) { _isEnabled = enabled; }
|
||||
|
||||
bool isEnabled() const { return _isEnabled; }
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
Particle3DEmitter();
|
||||
virtual ~Particle3DEmitter();
|
||||
|
||||
protected:
|
||||
ParticleSystem3D* _particleSystem;
|
||||
int _emitRate;
|
||||
bool _isEnabled;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif
|
||||
416
extensions/Particle3D/CCParticle3DRender.cpp
Executable file
416
extensions/Particle3D/CCParticle3DRender.cpp
Executable file
@@ -0,0 +1,416 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#include "extensions/Particle3D/CCParticleSystem3D.h"
|
||||
#include <stddef.h> // offsetof
|
||||
#include "base/ccTypes.h"
|
||||
#include "extensions/Particle3D/CCParticle3DRender.h"
|
||||
#include "renderer/CCMeshCommand.h"
|
||||
#include "renderer/CCRenderer.h"
|
||||
#include "renderer/CCTextureCache.h"
|
||||
#include "renderer/backend/ProgramState.h"
|
||||
#include "renderer/backend/Buffer.h"
|
||||
#include "renderer/backend/Device.h"
|
||||
#include "renderer/ccShaders.h"
|
||||
#include "base/CCDirector.h"
|
||||
#include "3d/CCSprite3D.h"
|
||||
#include "2d/CCCamera.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
Particle3DQuadRender::Particle3DQuadRender()
|
||||
: _texture(nullptr)
|
||||
, _programState(nullptr)
|
||||
, _indexBuffer(nullptr)
|
||||
, _vertexBuffer(nullptr)
|
||||
, _texFile("")
|
||||
{
|
||||
}
|
||||
|
||||
Particle3DQuadRender::~Particle3DQuadRender()
|
||||
{
|
||||
//CC_SAFE_RELEASE(_texture);
|
||||
CC_SAFE_RELEASE(_programState);
|
||||
CC_SAFE_RELEASE(_vertexBuffer);
|
||||
CC_SAFE_RELEASE(_indexBuffer);
|
||||
}
|
||||
|
||||
Particle3DQuadRender* Particle3DQuadRender::create(const std::string& texFile)
|
||||
{
|
||||
auto ret = new (std::nothrow)Particle3DQuadRender();
|
||||
if (ret && ret->initQuadRender(texFile))
|
||||
{
|
||||
ret->_texFile = texFile;
|
||||
ret->autorelease();
|
||||
}
|
||||
else
|
||||
{
|
||||
CC_SAFE_DELETE(ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void Particle3DQuadRender::render(Renderer* renderer, const Mat4 &transform, ParticleSystem3D* particleSystem)
|
||||
{
|
||||
//batch and generate draw
|
||||
const ParticlePool &particlePool = particleSystem->getParticlePool();
|
||||
if (!_isVisible || particlePool.empty())
|
||||
return;
|
||||
|
||||
if (_vertexBuffer == nullptr){
|
||||
size_t stride = sizeof(Particle3DQuadRender::posuvcolor);
|
||||
_vertexBuffer = backend::Device::getInstance()->newBuffer(stride * 4 * particleSystem->getParticleQuota(), backend::BufferType::VERTEX, backend::BufferUsage::DYNAMIC);
|
||||
if (_vertexBuffer == nullptr)
|
||||
{
|
||||
CCLOG("Particle3DQuadRender::render create vertex buffer failed");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (_indexBuffer == nullptr){
|
||||
_indexBuffer = backend::Device::getInstance()->newBuffer(sizeof(uint16_t) * 6 * particleSystem->getParticleQuota(), backend::BufferType::INDEX, backend::BufferUsage::DYNAMIC);
|
||||
if (_indexBuffer == nullptr)
|
||||
{
|
||||
CCLOG("Particle3DQuadRender::render create index buffer failed");
|
||||
return;
|
||||
}
|
||||
}
|
||||
ParticlePool::PoolList activeParticleList = particlePool.getActiveDataList();
|
||||
if (_posuvcolors.size() < activeParticleList.size() * 4)
|
||||
{
|
||||
_posuvcolors.resize(activeParticleList.size() * 4);
|
||||
_indexData.resize(activeParticleList.size() * 6);
|
||||
}
|
||||
|
||||
auto camera = Camera::getVisitingCamera();
|
||||
auto cameraMat = camera->getNodeToWorldTransform();
|
||||
const Mat4 &viewMat = cameraMat.getInversed();
|
||||
|
||||
Mat4 pRotMat;
|
||||
Vec3 right(cameraMat.m[0], cameraMat.m[1], cameraMat.m[2]);
|
||||
Vec3 up(cameraMat.m[4], cameraMat.m[5], cameraMat.m[6]);
|
||||
Vec3 backward(cameraMat.m[8], cameraMat.m[9], cameraMat.m[10]);
|
||||
|
||||
Vec3 position; //particle position
|
||||
int vertexindex = 0;
|
||||
int index = 0;
|
||||
for (auto iter : activeParticleList)
|
||||
{
|
||||
auto particle = iter;
|
||||
Vec3 halfwidth = particle->width * 0.5f * right;
|
||||
Vec3 halfheight = particle->height * 0.5f * up;
|
||||
//transform.transformPoint(particle->position, &position);
|
||||
position = particle->position;
|
||||
_posuvcolors[vertexindex].position = (position + (- halfwidth - halfheight));
|
||||
_posuvcolors[vertexindex].color = particle->color;
|
||||
_posuvcolors[vertexindex].uv.set(particle->lb_uv);
|
||||
|
||||
_posuvcolors[vertexindex + 1].position = (position + (halfwidth - halfheight));
|
||||
_posuvcolors[vertexindex + 1].color = particle->color;
|
||||
_posuvcolors[vertexindex + 1].uv.set(particle->rt_uv.x, particle->lb_uv.y);
|
||||
|
||||
_posuvcolors[vertexindex + 2].position = (position + (- halfwidth + halfheight));
|
||||
_posuvcolors[vertexindex + 2].color = particle->color;
|
||||
_posuvcolors[vertexindex + 2].uv.set(particle->lb_uv.x, particle->rt_uv.y);
|
||||
|
||||
_posuvcolors[vertexindex + 3].position = (position + (halfwidth + halfheight));
|
||||
_posuvcolors[vertexindex + 3].color = particle->color;
|
||||
_posuvcolors[vertexindex + 3].uv.set(particle->rt_uv);
|
||||
|
||||
|
||||
_indexData[index] = vertexindex;
|
||||
_indexData[index + 1] = vertexindex + 1;
|
||||
_indexData[index + 2] = vertexindex + 3;
|
||||
_indexData[index + 3] = vertexindex;
|
||||
_indexData[index + 4] = vertexindex + 3;
|
||||
_indexData[index + 5] = vertexindex + 2;
|
||||
|
||||
index += 6;
|
||||
vertexindex += 4;
|
||||
}
|
||||
|
||||
_posuvcolors.erase(_posuvcolors.begin() + vertexindex, _posuvcolors.end());
|
||||
_indexData.erase(_indexData.begin() + index, _indexData.end());
|
||||
|
||||
_vertexBuffer->updateData(&_posuvcolors[0], vertexindex * sizeof(_posuvcolors[0]));
|
||||
_indexBuffer->updateData(&_indexData[0], index * sizeof(_indexData[0]));
|
||||
|
||||
float depthZ = -(viewMat.m[2] * transform.m[12] + viewMat.m[6] * transform.m[13] + viewMat.m[10] * transform.m[14] + viewMat.m[14]);
|
||||
|
||||
_beforeCommand.init(depthZ);
|
||||
_meshCommand.init(depthZ);
|
||||
_afterCommand.init(depthZ);
|
||||
|
||||
_meshCommand.setVertexBuffer(_vertexBuffer);
|
||||
_meshCommand.setIndexBuffer(_indexBuffer, MeshCommand::IndexFormat::U_SHORT);
|
||||
|
||||
auto &projectionMatrix = Director::getInstance()->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
|
||||
_programState->setUniform(_locPMatrix, &projectionMatrix.m, sizeof(projectionMatrix.m));
|
||||
|
||||
if (_texture)
|
||||
{
|
||||
_programState->setTexture(_locTexture, 0, _texture->getBackendTexture());
|
||||
}
|
||||
_stateBlock.setBlendFunc(particleSystem->getBlendFunc());
|
||||
auto uColor = Vec4(1, 1, 1, 1);
|
||||
_programState->setUniform(_locColor, &uColor, sizeof(uColor));
|
||||
|
||||
|
||||
_meshCommand.setIndexDrawInfo(0, index);
|
||||
|
||||
renderer->addCommand(&_beforeCommand);
|
||||
renderer->addCommand(&_meshCommand);
|
||||
renderer->addCommand(&_afterCommand);
|
||||
}
|
||||
|
||||
bool Particle3DQuadRender::initQuadRender( const std::string& texFile )
|
||||
{
|
||||
CC_SAFE_RELEASE_NULL(_programState);
|
||||
|
||||
if (!texFile.empty())
|
||||
{
|
||||
auto tex = Director::getInstance()->getTextureCache()->addImage(texFile);
|
||||
if (tex)
|
||||
{
|
||||
_texture = tex;
|
||||
auto* program = backend::Program::getBuiltinProgram(backend::ProgramType::PARTICLE_TEXTURE_3D);
|
||||
_programState = new backend::ProgramState(program);
|
||||
}
|
||||
}
|
||||
|
||||
if (!_programState)
|
||||
{
|
||||
auto* program = backend::Program::getBuiltinProgram(backend::ProgramType::PARTICLE_COLOR_3D);
|
||||
_programState = new backend::ProgramState(program);
|
||||
}
|
||||
|
||||
auto &pipelineDescriptor = _meshCommand.getPipelineDescriptor();
|
||||
pipelineDescriptor.programState = _programState;
|
||||
auto layout = _programState->getVertexLayout();
|
||||
const auto& attributeInfo = _programState->getProgram()->getActiveAttributes();
|
||||
auto iter = attributeInfo.find("a_position");
|
||||
if(iter != attributeInfo.end())
|
||||
{
|
||||
layout->setAttribute("a_position", iter->second.location, backend::VertexFormat::FLOAT3, offsetof(posuvcolor, position), false);
|
||||
}
|
||||
iter = attributeInfo.find("a_texCoord");
|
||||
if(iter != attributeInfo.end())
|
||||
{
|
||||
layout->setAttribute("a_texCoord", iter->second.location, backend::VertexFormat::FLOAT2, offsetof(posuvcolor, uv), false);
|
||||
}
|
||||
iter = attributeInfo.find("a_color");
|
||||
if(iter != attributeInfo.end())
|
||||
{
|
||||
layout->setAttribute("a_color", iter->second.location, backend::VertexFormat::FLOAT4, offsetof(posuvcolor, color), false);
|
||||
}
|
||||
layout->setLayout(sizeof(posuvcolor));
|
||||
|
||||
_locColor = _programState->getUniformLocation("u_color");
|
||||
_locPMatrix = _programState->getUniformLocation("u_PMatrix");
|
||||
_locTexture = _programState->getUniformLocation("u_texture");
|
||||
|
||||
_meshCommand.setTransparent(true);
|
||||
_meshCommand.setSkipBatching(true);
|
||||
|
||||
_stateBlock.setDepthTest(true);
|
||||
_stateBlock.setDepthWrite(false);
|
||||
_stateBlock.setCullFaceSide(backend::CullMode::BACK);
|
||||
_stateBlock.setCullFace(true);
|
||||
|
||||
_beforeCommand.func = CC_CALLBACK_0(Particle3DQuadRender::onBeforeDraw, this);
|
||||
_afterCommand.func = CC_CALLBACK_0(Particle3DQuadRender::onAfterDraw, this);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void Particle3DQuadRender::onBeforeDraw()
|
||||
{
|
||||
auto *renderer = Director::getInstance()->getRenderer();
|
||||
auto &pipelineDescriptor = _meshCommand.getPipelineDescriptor();
|
||||
_rendererDepthTestEnabled = renderer->getDepthTest();
|
||||
_rendererDepthCmpFunc = renderer->getDepthCompareFunction();
|
||||
_rendererCullMode = renderer->getCullMode();
|
||||
_rendererDepthWrite = renderer->getDepthWrite();
|
||||
_rendererWinding = renderer->getWinding();
|
||||
_stateBlock.bind(&pipelineDescriptor);
|
||||
renderer->setDepthTest(true);
|
||||
}
|
||||
|
||||
void Particle3DQuadRender::onAfterDraw()
|
||||
{
|
||||
auto *renderer = Director::getInstance()->getRenderer();
|
||||
renderer->setDepthTest(_rendererDepthTestEnabled);
|
||||
renderer->setDepthCompareFunction(_rendererDepthCmpFunc);
|
||||
renderer->setCullMode(_rendererCullMode);
|
||||
renderer->setDepthWrite(_rendererDepthWrite);
|
||||
renderer->setWinding(_rendererWinding);
|
||||
}
|
||||
|
||||
void Particle3DQuadRender::reset()
|
||||
{
|
||||
this->initQuadRender(_texFile);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
Particle3DModelRender::Particle3DModelRender()
|
||||
: _spriteSize(Vec3::ONE)
|
||||
{
|
||||
|
||||
}
|
||||
Particle3DModelRender::~Particle3DModelRender()
|
||||
{
|
||||
for (auto iter : _spriteList){
|
||||
iter->release();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Particle3DModelRender* Particle3DModelRender::create(const std::string& modelFile, const std::string &texFile)
|
||||
{
|
||||
auto ret = new (std::nothrow) Particle3DModelRender();
|
||||
ret->_modelFile = modelFile;
|
||||
ret->_texFile = texFile;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void Particle3DModelRender::render(Renderer* renderer, const Mat4 &transform, ParticleSystem3D* particleSystem)
|
||||
{
|
||||
if (!_isVisible)
|
||||
return;
|
||||
|
||||
if (_spriteList.empty()){
|
||||
for (unsigned int i = 0; i < particleSystem->getParticleQuota(); ++i){
|
||||
Sprite3D *sprite = Sprite3D::create(_modelFile);
|
||||
if (sprite == nullptr)
|
||||
{
|
||||
CCLOG("failed to load file %s", _modelFile.c_str());
|
||||
continue;
|
||||
}
|
||||
sprite->setTexture(_texFile);
|
||||
sprite->retain();
|
||||
_spriteList.push_back(sprite);
|
||||
}
|
||||
if (!_spriteList.empty()){
|
||||
const AABB &aabb = _spriteList[0]->getAABB();
|
||||
Vec3 corners[8];
|
||||
aabb.getCorners(corners);
|
||||
_spriteSize = corners[3] - corners[6];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const ParticlePool& particlePool = particleSystem->getParticlePool();
|
||||
ParticlePool::PoolList activeParticleList = particlePool.getActiveDataList();
|
||||
Mat4 mat;
|
||||
Mat4 rotMat;
|
||||
Mat4 sclMat;
|
||||
Quaternion q;
|
||||
transform.decompose(nullptr, &q, nullptr);
|
||||
unsigned int index = 0;
|
||||
for (auto iter : activeParticleList)
|
||||
{
|
||||
auto particle = iter;
|
||||
Mat4::createRotation(q * particle->orientation, &rotMat);
|
||||
sclMat.m[0] = particle->width / _spriteSize.x;
|
||||
sclMat.m[5] = particle->height / _spriteSize.y;
|
||||
sclMat.m[10] = particle->depth / _spriteSize.z;
|
||||
mat = rotMat * sclMat;
|
||||
mat.m[12] = particle->position.x;
|
||||
mat.m[13] = particle->position.y;
|
||||
mat.m[14] = particle->position.z;
|
||||
_spriteList[index++]->draw(renderer, mat, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void Particle3DModelRender::reset()
|
||||
{
|
||||
for (auto iter : _spriteList){
|
||||
iter->release();
|
||||
}
|
||||
_spriteList.clear();
|
||||
}
|
||||
|
||||
// MARK: Particle3DRender
|
||||
|
||||
Particle3DRender::Particle3DRender()
|
||||
: _particleSystem(nullptr)
|
||||
, _isVisible(true)
|
||||
, _rendererScale(Vec3::ONE)
|
||||
, _depthTest(true)
|
||||
, _depthWrite(false)
|
||||
{
|
||||
_stateBlock.setCullFace(false);
|
||||
_stateBlock.setCullFaceSide(backend::CullMode::BACK);
|
||||
_stateBlock.setDepthTest(false);
|
||||
_stateBlock.setDepthWrite(false);
|
||||
_stateBlock.setBlend(true);
|
||||
};
|
||||
|
||||
Particle3DRender::~Particle3DRender()
|
||||
{
|
||||
}
|
||||
|
||||
void Particle3DRender::copyAttributesTo (Particle3DRender *render)
|
||||
{
|
||||
render->_stateBlock = _stateBlock;
|
||||
render->_isVisible = _isVisible;
|
||||
render->_rendererScale = _rendererScale;
|
||||
render->_depthTest = _depthTest;
|
||||
render->_depthWrite = _depthWrite;
|
||||
}
|
||||
|
||||
void Particle3DRender::notifyStart()
|
||||
{
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
void Particle3DRender::notifyStop()
|
||||
{
|
||||
setVisible(false);
|
||||
}
|
||||
|
||||
void Particle3DRender::notifyRescaled( const Vec3& scale )
|
||||
{
|
||||
_rendererScale = scale;
|
||||
}
|
||||
|
||||
void Particle3DRender::setDepthTest( bool isDepthTest )
|
||||
{
|
||||
_depthTest = isDepthTest;
|
||||
_stateBlock.setDepthTest(_depthTest);
|
||||
}
|
||||
|
||||
void Particle3DRender::setDepthWrite( bool isDepthWrite )
|
||||
{
|
||||
_depthWrite = isDepthWrite;
|
||||
_stateBlock.setDepthWrite(_depthWrite);
|
||||
}
|
||||
|
||||
void Particle3DRender::setBlendFunc(const BlendFunc &blendFunc)
|
||||
{
|
||||
_stateBlock.setBlendFunc(blendFunc);
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
168
extensions/Particle3D/CCParticle3DRender.h
Normal file
168
extensions/Particle3D/CCParticle3DRender.h
Normal file
@@ -0,0 +1,168 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "renderer/CCRenderState.h"
|
||||
#include "renderer/backend/Types.h"
|
||||
#include "renderer/CCMeshCommand.h"
|
||||
#include "renderer/CCCallbackCommand.h"
|
||||
#include "renderer/backend/Buffer.h"
|
||||
#include "base/CCRef.h"
|
||||
#include "math/CCMath.h"
|
||||
|
||||
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class ParticleSystem3D;
|
||||
class Renderer;
|
||||
class MeshCommand;
|
||||
class Sprite3D;
|
||||
class GLProgramState;
|
||||
class IndexBuffer;
|
||||
class VertexBuffer;
|
||||
class Texture2D;
|
||||
|
||||
/**
|
||||
* 3d particle render
|
||||
*/
|
||||
class CC_DLL Particle3DRender : public Ref
|
||||
{
|
||||
friend class ParticleSystem3D;
|
||||
public:
|
||||
|
||||
virtual void render(Renderer* renderer, const Mat4 &transform, ParticleSystem3D* particleSystem) = 0;
|
||||
|
||||
/** Perform activities when a Renderer is started.
|
||||
*/
|
||||
virtual void notifyStart();
|
||||
/** Perform activities when a Renderer is stopped.
|
||||
*/
|
||||
virtual void notifyStop();
|
||||
/** Notify that the Particle System is rescaled.
|
||||
*/
|
||||
virtual void notifyRescaled(const Vec3& scale);
|
||||
|
||||
void setVisible(bool isVisible) { _isVisible = isVisible; }
|
||||
|
||||
bool isVisible() const { return _isVisible; }
|
||||
|
||||
void setDepthTest(bool isDepthTest);
|
||||
void setDepthWrite(bool isDepthWrite);
|
||||
void setBlendFunc(const BlendFunc& blendFunc);
|
||||
|
||||
void copyAttributesTo (Particle3DRender *render);
|
||||
|
||||
virtual void reset(){}
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
Particle3DRender();
|
||||
virtual ~Particle3DRender();
|
||||
|
||||
protected:
|
||||
ParticleSystem3D *_particleSystem;
|
||||
RenderState::StateBlock _stateBlock;
|
||||
bool _isVisible;
|
||||
Vec3 _rendererScale;
|
||||
bool _depthTest;
|
||||
bool _depthWrite;
|
||||
};
|
||||
|
||||
// particle render for quad
|
||||
class CC_DLL Particle3DQuadRender : public Particle3DRender
|
||||
{
|
||||
public:
|
||||
static Particle3DQuadRender* create(const std::string& texFile = "");
|
||||
|
||||
virtual void render(Renderer* renderer, const Mat4 &transform, ParticleSystem3D* particleSystem) override;
|
||||
|
||||
virtual void reset()override;
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
Particle3DQuadRender();
|
||||
virtual ~Particle3DQuadRender();
|
||||
|
||||
protected:
|
||||
|
||||
bool initQuadRender(const std::string& texFile);
|
||||
|
||||
void onBeforeDraw();
|
||||
void onAfterDraw();
|
||||
|
||||
protected:
|
||||
MeshCommand _meshCommand;
|
||||
CallbackCommand _beforeCommand;
|
||||
CallbackCommand _afterCommand;
|
||||
Texture2D* _texture = nullptr;
|
||||
backend::ProgramState* _programState = nullptr;
|
||||
backend::Buffer* _indexBuffer = nullptr; //index buffer
|
||||
backend::Buffer* _vertexBuffer = nullptr; // vertex buffer
|
||||
|
||||
struct posuvcolor
|
||||
{
|
||||
Vec3 position;
|
||||
Vec2 uv;
|
||||
Vec4 color;
|
||||
};
|
||||
|
||||
std::vector<posuvcolor> _posuvcolors; //vertex data
|
||||
std::vector<uint16_t> _indexData; //index data
|
||||
std::string _texFile;
|
||||
|
||||
backend::UniformLocation _locColor;
|
||||
backend::UniformLocation _locTexture;
|
||||
backend::UniformLocation _locPMatrix;
|
||||
|
||||
//renderer state cache variables
|
||||
bool _rendererDepthTestEnabled = true;
|
||||
backend::CompareFunction _rendererDepthCmpFunc = backend::CompareFunction::LESS;
|
||||
backend::CullMode _rendererCullMode = backend::CullMode::BACK;
|
||||
backend::Winding _rendererWinding = backend::Winding::COUNTER_CLOCK_WISE;
|
||||
bool _rendererDepthWrite = false;
|
||||
};
|
||||
|
||||
// particle render for Sprite3D
|
||||
class CC_DLL Particle3DModelRender : public Particle3DRender
|
||||
{
|
||||
public:
|
||||
static Particle3DModelRender* create(const std::string& modelFile, const std::string &texFile = "");
|
||||
|
||||
virtual void render(Renderer* renderer, const Mat4 &transform, ParticleSystem3D* particleSystem) override;
|
||||
|
||||
virtual void reset()override;
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
Particle3DModelRender();
|
||||
virtual ~Particle3DModelRender();
|
||||
|
||||
protected:
|
||||
std::vector<Sprite3D *> _spriteList;
|
||||
std::string _modelFile;
|
||||
std::string _texFile;
|
||||
Vec3 _spriteSize;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
219
extensions/Particle3D/CCParticleSystem3D.cpp
Executable file
219
extensions/Particle3D/CCParticleSystem3D.cpp
Executable file
@@ -0,0 +1,219 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCParticleSystem3D.h"
|
||||
#include "CCParticle3DEmitter.h"
|
||||
#include "CCParticle3DAffector.h"
|
||||
#include "CCParticle3DRender.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
Particle3D::Particle3D()
|
||||
: color(Vec4::ONE)
|
||||
, rt_uv(Vec2::ONE)
|
||||
, width(1.0f)
|
||||
, height(1.0f)
|
||||
, depth(1.0f)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Particle3D::~Particle3D()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ParticleSystem3D::ParticleSystem3D()
|
||||
: _state(State::STOP)
|
||||
, _emitter(nullptr)
|
||||
, _render(nullptr)
|
||||
, _aliveParticlesCnt(0)
|
||||
, _particleQuota(0)
|
||||
, _blend(BlendFunc::ALPHA_NON_PREMULTIPLIED)
|
||||
, _keepLocal(false)
|
||||
, _isEnabled(true)
|
||||
{
|
||||
|
||||
}
|
||||
ParticleSystem3D::~ParticleSystem3D()
|
||||
{
|
||||
//stopParticle();
|
||||
removeAllAffector();
|
||||
CC_SAFE_RELEASE(_emitter);
|
||||
CC_SAFE_RELEASE(_render);
|
||||
}
|
||||
|
||||
void ParticleSystem3D::startParticleSystem()
|
||||
{
|
||||
if (_state != State::RUNNING)
|
||||
{
|
||||
if (_render)
|
||||
_render->notifyStart();
|
||||
|
||||
scheduleUpdate();
|
||||
_state = State::RUNNING;
|
||||
}
|
||||
}
|
||||
|
||||
void ParticleSystem3D::stopParticleSystem()
|
||||
{
|
||||
if (_state != State::STOP)
|
||||
{
|
||||
if (_render)
|
||||
_render->notifyStop();
|
||||
|
||||
unscheduleUpdate();
|
||||
_state = State::STOP;
|
||||
}
|
||||
}
|
||||
|
||||
void ParticleSystem3D::pauseParticleSystem()
|
||||
{
|
||||
if (_state == State::RUNNING)
|
||||
{
|
||||
_state = State::PAUSE;
|
||||
}
|
||||
}
|
||||
|
||||
void ParticleSystem3D::resumeParticleSystem()
|
||||
{
|
||||
if (_state == State::PAUSE)
|
||||
{
|
||||
_state = State::RUNNING;
|
||||
}
|
||||
}
|
||||
|
||||
void ParticleSystem3D::setEmitter(Particle3DEmitter* emitter)
|
||||
{
|
||||
if (_emitter != emitter)
|
||||
{
|
||||
CC_SAFE_RELEASE(_emitter);
|
||||
emitter->_particleSystem = this;
|
||||
_emitter = emitter;
|
||||
CC_SAFE_RETAIN(_emitter);
|
||||
}
|
||||
}
|
||||
|
||||
void ParticleSystem3D::setRender(Particle3DRender* render)
|
||||
{
|
||||
if (_render != render)
|
||||
{
|
||||
CC_SAFE_RELEASE(_render);
|
||||
_render = render;
|
||||
_render->_particleSystem = this;
|
||||
CC_SAFE_RETAIN(_render);
|
||||
}
|
||||
}
|
||||
|
||||
void ParticleSystem3D::addAffector(Particle3DAffector* affector)
|
||||
{
|
||||
if (affector && std::find(_affectors.begin(), _affectors.end(), affector) == _affectors.end()){
|
||||
affector->_particleSystem = this;
|
||||
affector->retain();
|
||||
_affectors.push_back(affector);
|
||||
}
|
||||
}
|
||||
|
||||
void ParticleSystem3D::removeAffector(int index)
|
||||
{
|
||||
CCASSERT((unsigned int)index < _affectors.size(), "wrong index");
|
||||
_affectors.erase(_affectors.begin() + index);
|
||||
}
|
||||
|
||||
void ParticleSystem3D::removeAllAffector()
|
||||
{
|
||||
//release all affectors
|
||||
for (auto it : _affectors) {
|
||||
it->release();
|
||||
}
|
||||
_affectors.clear();
|
||||
}
|
||||
|
||||
Particle3DAffector* ParticleSystem3D::getAffector(int index)
|
||||
{
|
||||
CCASSERT(index < (int)_affectors.size(), "wrong index");
|
||||
return _affectors[index];
|
||||
}
|
||||
|
||||
void ParticleSystem3D::update(float delta)
|
||||
{
|
||||
if (_state != State::RUNNING)
|
||||
return;
|
||||
|
||||
Particle3D *particle = _particlePool.getFirst();
|
||||
while (particle)
|
||||
{
|
||||
if (_emitter)
|
||||
{
|
||||
_emitter->updateEmitter(particle, delta);
|
||||
}
|
||||
|
||||
for (auto& it : _affectors) {
|
||||
it->updateAffector(particle, delta);
|
||||
}
|
||||
|
||||
particle = _particlePool.getNext();
|
||||
}
|
||||
}
|
||||
|
||||
void ParticleSystem3D::draw(Renderer *renderer, const Mat4 &transform, uint32_t /*flags*/)
|
||||
{
|
||||
if (getAliveParticleCount() && _render)
|
||||
{
|
||||
_render->render(renderer, transform, this);
|
||||
}
|
||||
}
|
||||
|
||||
void ParticleSystem3D::setBlendFunc(const BlendFunc &blendFunc)
|
||||
{
|
||||
_blend = blendFunc;
|
||||
}
|
||||
|
||||
const BlendFunc &ParticleSystem3D::getBlendFunc() const
|
||||
{
|
||||
return _blend;
|
||||
}
|
||||
|
||||
void ParticleSystem3D::setParticleQuota( unsigned int quota )
|
||||
{
|
||||
_particleQuota = quota;
|
||||
}
|
||||
|
||||
unsigned int ParticleSystem3D::getParticleQuota() const
|
||||
{
|
||||
return _particleQuota;
|
||||
}
|
||||
|
||||
void ParticleSystem3D::setKeepLocal( bool keepLocal )
|
||||
{
|
||||
_keepLocal = keepLocal;
|
||||
}
|
||||
|
||||
void ParticleSystem3D::setEnabled( bool enabled )
|
||||
{
|
||||
_isEnabled = enabled;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
299
extensions/Particle3D/CCParticleSystem3D.h
Normal file
299
extensions/Particle3D/CCParticleSystem3D.h
Normal file
@@ -0,0 +1,299 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __CC_PARTICLE_SYSTEM_3D_H__
|
||||
#define __CC_PARTICLE_SYSTEM_3D_H__
|
||||
|
||||
#include "2d/CCNode.h"
|
||||
#include "math/CCMath.h"
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <list>
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
/**
|
||||
* 3d particle system
|
||||
*/
|
||||
class Particle3DEmitter;
|
||||
class Particle3DAffector;
|
||||
class Particle3DRender;
|
||||
|
||||
struct CC_DLL Particle3D
|
||||
{
|
||||
Particle3D();
|
||||
virtual ~Particle3D();
|
||||
// property of particles
|
||||
Vec3 position; // position
|
||||
Quaternion orientation;// Orientation of the particle.
|
||||
Vec4 color; // particle color
|
||||
Vec2 lb_uv; // left bottom uv
|
||||
Vec2 rt_uv; // right top uv
|
||||
float width;//Own width
|
||||
float height;//Own height
|
||||
float depth;//Own depth
|
||||
|
||||
//user defined property
|
||||
std::unordered_map<std::string, void*> userDefs;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class CC_DLL DataPool
|
||||
{
|
||||
public:
|
||||
typedef typename std::list<T*> PoolList;
|
||||
typedef typename std::list<T*>::iterator PoolIterator;
|
||||
|
||||
DataPool(){};
|
||||
~DataPool(){};
|
||||
|
||||
T* createData(){
|
||||
if (_locked.empty()) return nullptr;
|
||||
T* p = _locked.front();
|
||||
//_released.push_back(p);
|
||||
//_locked.erase(_locked.begin());
|
||||
_released.splice(_released.end(), _locked, _locked.begin());
|
||||
return p;
|
||||
}
|
||||
|
||||
void lockLatestData(){
|
||||
_locked.push_back(*_releasedIter);
|
||||
_releasedIter = _released.erase(_releasedIter);
|
||||
if (_releasedIter != _released.begin() && _releasedIter != _released.end())
|
||||
{
|
||||
--_releasedIter;
|
||||
}
|
||||
}
|
||||
|
||||
void lockData(T *data){
|
||||
PoolIterator tempIter = _releasedIter;
|
||||
T *ptr = getFirst();
|
||||
while (ptr)
|
||||
{
|
||||
if (ptr == data) break;
|
||||
ptr = getNext();
|
||||
}
|
||||
if (ptr)
|
||||
lockLatestData();
|
||||
_releasedIter = tempIter;
|
||||
}
|
||||
|
||||
void lockAllDatas(){
|
||||
_locked.splice(_locked.end(), _released);
|
||||
//_locked.insert(_locked.end(), _released.begin(), _released.end());
|
||||
//_released.clear();
|
||||
_releasedIter = _released.begin();
|
||||
}
|
||||
|
||||
T* getFirst(){
|
||||
_releasedIter = _released.begin();
|
||||
if (_releasedIter == _released.end()) return nullptr;
|
||||
return *_releasedIter;
|
||||
}
|
||||
|
||||
T* getNext(){
|
||||
if (_releasedIter == _released.end()) return nullptr;
|
||||
++_releasedIter;
|
||||
if (_releasedIter == _released.end()) return nullptr;
|
||||
return *_releasedIter;
|
||||
}
|
||||
|
||||
const PoolList& getActiveDataList() const { return _released; };
|
||||
const PoolList& getUnActiveDataList() const { return _locked; };
|
||||
|
||||
void addData(T* data){
|
||||
_locked.push_back(data);
|
||||
}
|
||||
|
||||
bool empty() const { return _released.empty(); };
|
||||
|
||||
void removeAllDatas(){
|
||||
lockAllDatas();
|
||||
for (auto iter : _locked){
|
||||
delete iter;
|
||||
}
|
||||
_locked.clear();
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
PoolIterator _releasedIter;
|
||||
PoolList _released;
|
||||
PoolList _locked;
|
||||
};
|
||||
|
||||
typedef DataPool<Particle3D> ParticlePool;
|
||||
|
||||
class CC_DLL ParticleSystem3D : public Node, public BlendProtocol
|
||||
{
|
||||
public:
|
||||
|
||||
enum class State
|
||||
{
|
||||
STOP,
|
||||
RUNNING,
|
||||
PAUSE,
|
||||
};
|
||||
|
||||
/**
|
||||
* override function
|
||||
*/
|
||||
virtual void update(float delta) override;
|
||||
|
||||
/**
|
||||
* override function
|
||||
*/
|
||||
virtual void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) override;
|
||||
|
||||
/**
|
||||
* override function
|
||||
*/
|
||||
virtual void setBlendFunc(const BlendFunc &blendFunc) override;
|
||||
|
||||
/**
|
||||
* override function
|
||||
*/
|
||||
virtual const BlendFunc &getBlendFunc() const override;
|
||||
|
||||
/**
|
||||
* particle system play control
|
||||
*/
|
||||
virtual void startParticleSystem();
|
||||
|
||||
/**
|
||||
* stop particle
|
||||
*/
|
||||
virtual void stopParticleSystem();
|
||||
|
||||
/**
|
||||
* pause particle
|
||||
*/
|
||||
virtual void pauseParticleSystem();
|
||||
|
||||
/**
|
||||
* resume particle
|
||||
*/
|
||||
virtual void resumeParticleSystem();
|
||||
|
||||
/**
|
||||
* set emitter for particle system, can set your own particle emitter
|
||||
*/
|
||||
void setEmitter(Particle3DEmitter* emitter);
|
||||
/**
|
||||
* set particle render, can set your own particle render
|
||||
*/
|
||||
void setRender(Particle3DRender* render);
|
||||
/**
|
||||
* return particle render
|
||||
*/
|
||||
Particle3DRender* getRender(){ return _render; }
|
||||
/**
|
||||
* add particle affector
|
||||
*/
|
||||
void addAffector(Particle3DAffector* affector);
|
||||
|
||||
/**
|
||||
* remove affector by index
|
||||
*/
|
||||
void removeAffector(int index);
|
||||
|
||||
/**
|
||||
* remove all particle affector
|
||||
*/
|
||||
void removeAllAffector();
|
||||
|
||||
/**
|
||||
* get particle quota
|
||||
*/
|
||||
unsigned int getParticleQuota() const;
|
||||
/**
|
||||
* set particle quota
|
||||
*/
|
||||
void setParticleQuota(unsigned int quota);
|
||||
|
||||
/**
|
||||
* get particle affector by index
|
||||
*/
|
||||
Particle3DAffector* getAffector(int index);
|
||||
|
||||
/**
|
||||
* get particle pool
|
||||
*/
|
||||
const ParticlePool& getParticlePool()
|
||||
{
|
||||
return _particlePool;
|
||||
}
|
||||
|
||||
/**
|
||||
* get alive particles count
|
||||
*/
|
||||
virtual int getAliveParticleCount() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* get particle playing state
|
||||
*/
|
||||
State getState() const { return _state; }
|
||||
|
||||
bool isKeepLocal() const { return _keepLocal; }
|
||||
void setKeepLocal(bool keepLocal);
|
||||
|
||||
/**
|
||||
*Enables or disables the system.
|
||||
*/
|
||||
void setEnabled (bool enabled);
|
||||
|
||||
/**
|
||||
* is enabled
|
||||
*/
|
||||
bool isEnabled() const { return _isEnabled; }
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
ParticleSystem3D();
|
||||
virtual ~ParticleSystem3D();
|
||||
|
||||
protected:
|
||||
|
||||
State _state;
|
||||
Particle3DEmitter* _emitter;
|
||||
std::vector<Particle3DAffector*> _affectors;
|
||||
Particle3DRender* _render;
|
||||
|
||||
//particles
|
||||
ParticlePool _particlePool;
|
||||
int _aliveParticlesCnt;
|
||||
unsigned int _particleQuota;
|
||||
|
||||
BlendFunc _blend;
|
||||
|
||||
bool _keepLocal;
|
||||
bool _isEnabled;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif
|
||||
235
extensions/Particle3D/PU/CCPUAffector.cpp
Executable file
235
extensions/Particle3D/PU/CCPUAffector.cpp
Executable file
@@ -0,0 +1,235 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "extensions/Particle3D/PU/CCPUAffector.h"
|
||||
#include "extensions/Particle3D/PU/CCPUEmitter.h"
|
||||
#include "extensions/Particle3D/PU/CCPUParticleSystem3D.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
PUAffector::PUAffector()
|
||||
: _affectorScale(Vec3::ONE)
|
||||
, _affectSpecialisation(AFSP_DEFAULT)
|
||||
, _mass(1.0f)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
PUAffector::~PUAffector()
|
||||
{
|
||||
_particleSystem = nullptr;
|
||||
}
|
||||
|
||||
void PUAffector::updatePUAffector(PUParticle3D* /*particle*/, float /*delta*/)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
const Vec3& PUAffector::getDerivedPosition()
|
||||
{
|
||||
PUParticleSystem3D *ps = static_cast<PUParticleSystem3D *>(_particleSystem);
|
||||
if (ps){
|
||||
Mat4 rotMat;
|
||||
Mat4::createRotation(ps->getDerivedOrientation(), &rotMat);
|
||||
_derivedPosition = ps->getDerivedPosition() + rotMat * Vec3(_position.x * _affectorScale.x, _position.y * _affectorScale.y, _position.z * _affectorScale.z);
|
||||
//_particleSystem->getNodeToWorldTransform().transformPoint(_position, &_derivedPosition);
|
||||
}
|
||||
else
|
||||
_derivedPosition = _position;
|
||||
|
||||
return _derivedPosition;
|
||||
|
||||
//if (mMarkedForEmission)
|
||||
//{
|
||||
// // Use the affector position, because it is emitted
|
||||
// // If a particle is emitted, position and derived position are the same
|
||||
// _derivedPosition = position;
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// // Add the techniques' derived position
|
||||
// _derivedPosition = mParentTechnique->getDerivedPosition() +
|
||||
// mParentTechnique->getParentSystem()->getDerivedOrientation() * (_mAffectorScale * position);
|
||||
//}
|
||||
//return _derivedPosition;
|
||||
}
|
||||
|
||||
float PUAffector::calculateAffectSpecialisationFactor( const PUParticle3D* particle )
|
||||
{
|
||||
// Assume that particle->totalTimeToLive != 0, which is reasonable
|
||||
switch (_affectSpecialisation)
|
||||
{
|
||||
case AFSP_DEFAULT:
|
||||
return 1.0f;
|
||||
break;
|
||||
|
||||
// This means that older particles will be affected MORE than just emitted particles
|
||||
case AFSP_TTL_INCREASE:
|
||||
{
|
||||
if (particle)
|
||||
{
|
||||
return particle->timeFraction;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 1.0f;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
// This means that older particles will be affected LESS than just emitted particles
|
||||
case AFSP_TTL_DECREASE:
|
||||
{
|
||||
if (particle)
|
||||
{
|
||||
return 1.0f - particle->timeFraction;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 1.0f;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
return 1.0f;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void PUAffector::notifyStart()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void PUAffector::notifyStop()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void PUAffector::notifyPause()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void PUAffector::notifyResume()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void PUAffector::preUpdateAffector( float /*deltaTime*/ )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void PUAffector::postUpdateAffector( float /*deltaTime*/ )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void PUAffector::prepare()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void PUAffector::unPrepare()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void PUAffector::initParticleForEmission( PUParticle3D* /*particle*/ )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void PUAffector::notifyRescaled(const Vec3& scale)
|
||||
{
|
||||
_affectorScale = scale;
|
||||
}
|
||||
|
||||
void PUAffector::firstParticleUpdate( PUParticle3D* /*particle*/, float /*deltaTime*/ )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void PUAffector::setMass( float mass )
|
||||
{
|
||||
_mass = mass;
|
||||
}
|
||||
|
||||
float PUAffector::getMass() const
|
||||
{
|
||||
return _mass;
|
||||
}
|
||||
|
||||
void PUAffector::copyAttributesTo( PUAffector* affector )
|
||||
{
|
||||
affector->setName(_name);
|
||||
affector->setAffectorType(_affectorType);
|
||||
affector->_position = _position;
|
||||
affector->_isEnabled = _isEnabled;
|
||||
affector->_particleSystem = _particleSystem;
|
||||
affector->_affectorScale = _affectorScale;
|
||||
affector->_affectSpecialisation = _affectSpecialisation;
|
||||
affector->_excludedEmitters = _excludedEmitters;
|
||||
}
|
||||
|
||||
void PUAffector::addEmitterToExclude( const std::string& emitterName )
|
||||
{
|
||||
auto iter = std::find(_excludedEmitters.begin(), _excludedEmitters.end(), emitterName);
|
||||
if (iter == _excludedEmitters.end()){
|
||||
_excludedEmitters.push_back(emitterName);
|
||||
}
|
||||
}
|
||||
|
||||
void PUAffector::removeEmitterToExclude( const std::string& emitterName )
|
||||
{
|
||||
auto iter = std::find(_excludedEmitters.begin(), _excludedEmitters.end(), emitterName);
|
||||
if (iter != _excludedEmitters.end()){
|
||||
_excludedEmitters.erase(iter);
|
||||
}
|
||||
}
|
||||
|
||||
void PUAffector::process( PUParticle3D* particle, float delta, bool firstParticle )
|
||||
{
|
||||
if (firstParticle){
|
||||
firstParticleUpdate(particle, delta);
|
||||
}
|
||||
|
||||
if (!_excludedEmitters.empty() && particle->parentEmitter){
|
||||
// Return if the emitter which emits this particle is part of the vector
|
||||
std::string emitterName = particle->parentEmitter->getName();
|
||||
auto iter = std::find(_excludedEmitters.begin(), _excludedEmitters.end(), emitterName);
|
||||
if (iter != _excludedEmitters.end())
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
updatePUAffector(particle, delta);
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
147
extensions/Particle3D/PU/CCPUAffector.h
Normal file
147
extensions/Particle3D/PU/CCPUAffector.h
Normal file
@@ -0,0 +1,147 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __CC_PU_PARTICLE_3D_AFFECTOR_H__
|
||||
#define __CC_PU_PARTICLE_3D_AFFECTOR_H__
|
||||
|
||||
#include "base/CCRef.h"
|
||||
#include "math/CCMath.h"
|
||||
#include "extensions/Particle3D/CCParticle3DAffector.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
struct PUParticle3D;
|
||||
class PUParticleSystem3D;
|
||||
|
||||
class CC_DLL PUAffector : public Particle3DAffector
|
||||
{
|
||||
friend class PUParticleSystem3D;
|
||||
public:
|
||||
/**
|
||||
The AffectSpecialisation enumeration is used to specialise the affector even more. This enumeration
|
||||
isn't used by all affectors; in some cases it isn't even applicable.
|
||||
*/
|
||||
enum AffectSpecialisation
|
||||
{
|
||||
AFSP_DEFAULT,
|
||||
AFSP_TTL_INCREASE,
|
||||
AFSP_TTL_DECREASE
|
||||
};
|
||||
|
||||
virtual void notifyStart();
|
||||
virtual void notifyStop();
|
||||
virtual void notifyPause();
|
||||
virtual void notifyResume();
|
||||
virtual void notifyRescaled(const Vec3& scale);
|
||||
virtual void prepare();
|
||||
virtual void unPrepare();
|
||||
virtual void preUpdateAffector(float deltaTime);
|
||||
virtual void updatePUAffector(PUParticle3D* particle, float delta);
|
||||
virtual void postUpdateAffector(float deltaTime);
|
||||
virtual void firstParticleUpdate(PUParticle3D *particle, float deltaTime);
|
||||
virtual void initParticleForEmission(PUParticle3D* particle);
|
||||
void process(PUParticle3D* particle, float delta, bool firstParticle);
|
||||
|
||||
void setLocalPosition(const Vec3 &pos) { _position = pos; };
|
||||
const Vec3 getLocalPosition() const { return _position; };
|
||||
void setMass(float mass);
|
||||
float getMass() const;
|
||||
|
||||
/** Calculate the derived position of the affector.
|
||||
@remarks
|
||||
Note, that in script, the position is set as localspace, while if the affector is
|
||||
emitted, its position is automatically transformed. This function always returns
|
||||
the derived position.
|
||||
*/
|
||||
const Vec3& getDerivedPosition();
|
||||
|
||||
/** Todo
|
||||
*/
|
||||
const AffectSpecialisation& getAffectSpecialisation() const {return _affectSpecialisation;};
|
||||
void setAffectSpecialisation(const AffectSpecialisation& affectSpecialisation) {_affectSpecialisation = affectSpecialisation;};
|
||||
|
||||
/** Todo
|
||||
*/
|
||||
const std::string& getAffectorType() const {return _affectorType;};
|
||||
void setAffectorType(const std::string& affectorType) {_affectorType = affectorType;};
|
||||
|
||||
/** Add a ParticleEmitter name that excludes Particles emitted by this ParticleEmitter from being
|
||||
affected.
|
||||
*/
|
||||
void addEmitterToExclude(const std::string& emitterName);
|
||||
|
||||
/** Remove a ParticleEmitter name that excludes Particles emitted by this ParticleEmitter.
|
||||
*/
|
||||
void removeEmitterToExclude(const std::string& emitterName);
|
||||
|
||||
/** Todo
|
||||
*/
|
||||
const std::string& getName() const {return _name;};
|
||||
void setName(const std::string& name) {_name = name;};
|
||||
|
||||
virtual void copyAttributesTo (PUAffector* affector);
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
PUAffector();
|
||||
virtual ~PUAffector();
|
||||
|
||||
protected:
|
||||
|
||||
float calculateAffectSpecialisationFactor (const PUParticle3D* particle);
|
||||
|
||||
protected:
|
||||
|
||||
Vec3 _position;
|
||||
/** Although the scale is on a Particle System level, the affector can also be scaled.
|
||||
*/
|
||||
Vec3 _affectorScale;
|
||||
/** Because the public attribute position is sometimes used for both localspace and worldspace
|
||||
position, the mDerivedPosition attribute is introduced.
|
||||
*/
|
||||
Vec3 _derivedPosition;
|
||||
|
||||
/** The mAffectSpecialisation is used to specialise the affector. This attribute is comparable with the
|
||||
mAutoDirection of the ParticleEmitter, it is an optional attribute and used in some of the Particle
|
||||
Affectors.
|
||||
*/
|
||||
AffectSpecialisation _affectSpecialisation;
|
||||
|
||||
// Type of the affector
|
||||
std::string _affectorType;
|
||||
|
||||
std::vector<std::string> _excludedEmitters;
|
||||
|
||||
// Name of the affector (optional)
|
||||
std::string _name;
|
||||
|
||||
float _mass;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif
|
||||
188
extensions/Particle3D/PU/CCPUAffectorManager.cpp
Normal file
188
extensions/Particle3D/PU/CCPUAffectorManager.cpp
Normal file
@@ -0,0 +1,188 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCPUAffectorManager.h"
|
||||
#include "extensions/Particle3D/PU/CCPUAlignAffector.h"
|
||||
#include "extensions/Particle3D/PU/CCPUBaseCollider.h"
|
||||
#include "extensions/Particle3D/PU/CCPUBaseForceAffector.h"
|
||||
#include "extensions/Particle3D/PU/CCPUBoxCollider.h"
|
||||
#include "extensions/Particle3D/PU/CCPUCollisionAvoidanceAffector.h"
|
||||
#include "extensions/Particle3D/PU/CCPUColorAffector.h"
|
||||
#include "extensions/Particle3D/PU/CCPUFlockCenteringAffector.h"
|
||||
#include "extensions/Particle3D/PU/CCPUForceFieldAffector.h"
|
||||
#include "extensions/Particle3D/PU/CCPUGeometryRotator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUGravityAffector.h"
|
||||
#include "extensions/Particle3D/PU/CCPUInterParticleCollider.h"
|
||||
#include "extensions/Particle3D/PU/CCPUJetAffector.h"
|
||||
#include "extensions/Particle3D/PU/CCPULineAffector.h"
|
||||
#include "extensions/Particle3D/PU/CCPULinearForceAffector.h"
|
||||
#include "extensions/Particle3D/PU/CCPUParticleFollower.h"
|
||||
#include "extensions/Particle3D/PU/CCPUPathFollower.h"
|
||||
#include "extensions/Particle3D/PU/CCPUPlaneCollider.h"
|
||||
#include "extensions/Particle3D/PU/CCPURandomiser.h"
|
||||
#include "extensions/Particle3D/PU/CCPUScaleAffector.h"
|
||||
#include "extensions/Particle3D/PU/CCPUScaleVelocityAffector.h"
|
||||
#include "extensions/Particle3D/PU/CCPUSineForceAffector.h"
|
||||
#include "extensions/Particle3D/PU/CCPUSphereCollider.h"
|
||||
#include "extensions/Particle3D/PU/CCPUTextureAnimator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUTextureRotator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUVelocityMatchingAffector.h"
|
||||
#include "extensions/Particle3D/PU/CCPUVortexAffector.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
PUAffectorManager::PUAffectorManager()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
PUAffectorManager::~PUAffectorManager()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
PUAffectorManager* PUAffectorManager::Instance()
|
||||
{
|
||||
static PUAffectorManager pam;
|
||||
return &pam;
|
||||
}
|
||||
|
||||
PUScriptTranslator* PUAffectorManager::getTranslator( const std::string &type )
|
||||
{
|
||||
if (type == "Align"){
|
||||
return &_alignAffectorTranslator;
|
||||
}else if (type == "Dummy02"){
|
||||
return &_baseColliderTranslator;
|
||||
}else if (type == "Dummy01"){
|
||||
return &_baseForceAffectorTranslator;
|
||||
}else if (type == "BoxCollider"){
|
||||
return &_boxColliderTranslator;
|
||||
}else if (type == "CollisionAvoidance"){
|
||||
return &_collisionAvoidanceAffectorTranstor;
|
||||
}else if (type == "Colour"){
|
||||
return &_colorAffectorTranslator;
|
||||
}else if (type == "FlockCentering"){
|
||||
return &_flockCenteringAffectorTranslator;
|
||||
}else if (type == "ForceField"){
|
||||
return &_forceFieldAffectorTranslator;
|
||||
}else if (type == "GeometryRotator"){
|
||||
return &_geometryRotatorTranslator;
|
||||
}else if (type == "Gravity"){
|
||||
return &_gravityAffectorTranslator;
|
||||
}else if (type == "InterParticleCollider"){
|
||||
return &_interParticleColliderTranslator;
|
||||
}else if (type == "Jet"){
|
||||
return &_jetAffectorTranslator;
|
||||
}else if (type == "Line"){
|
||||
return &_lineAffectorTranslator;
|
||||
}else if (type == "LinearForce"){
|
||||
return &_linearForceAffectorTranslator;
|
||||
}else if (type == "ParticleFollower"){
|
||||
return &_particleFollowerTranslator;
|
||||
}else if (type == "PathFollower"){
|
||||
return &_pathFollowerTranslator;
|
||||
}else if (type == "PlaneCollider"){
|
||||
return &_planeColliderTranslator;
|
||||
}else if (type == "Randomiser"){
|
||||
return &_randomiserTranslator;
|
||||
}else if (type == "Scale"){
|
||||
return &_scaleAffectorTranslator;
|
||||
}else if (type == "ScaleVelocity"){
|
||||
return &_scaleVelocityAffectorTranslator;
|
||||
}else if (type == "SineForce"){
|
||||
return &_sineForceAffectorTranslator;
|
||||
}else if (type == "SphereCollider"){
|
||||
return &_sphereColliderTranslator;
|
||||
}else if (type == "TextureAnimator"){
|
||||
return &_textureAnimatorTranslator;
|
||||
}else if (type == "TextureRotator"){
|
||||
return &_textureRotatorTranslator;
|
||||
}else if (type == "VelocityMatching"){
|
||||
return &_velocityMatchingAffectorTranslator;
|
||||
}else if (type == "Vortex"){
|
||||
return &_vortexAffectorTranslator;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PUAffector* PUAffectorManager::createAffector( const std::string &type )
|
||||
{
|
||||
if (type == "Align"){
|
||||
return PUAlignAffector::create();
|
||||
}else if (type == "Dummy02"){
|
||||
return nullptr;
|
||||
}else if (type == "Dummy01"){
|
||||
return nullptr;
|
||||
}else if (type == "BoxCollider"){
|
||||
return PUBoxCollider::create();
|
||||
}else if (type == "CollisionAvoidance"){
|
||||
return PUCollisionAvoidanceAffector::create();
|
||||
}else if (type == "Colour"){
|
||||
return PUColorAffector::create();
|
||||
}else if (type == "FlockCentering"){
|
||||
return PUFlockCenteringAffector::create();
|
||||
}else if (type == "ForceField"){
|
||||
return PUForceFieldAffector::create();
|
||||
}else if (type == "GeometryRotator"){
|
||||
return PUGeometryRotator::create();
|
||||
}else if (type == "Gravity"){
|
||||
return PUGravityAffector::create();
|
||||
}else if (type == "InterParticleCollider"){
|
||||
return PUParticle3DInterParticleCollider::create();
|
||||
}else if (type == "Jet"){
|
||||
return PUJetAffector::create();
|
||||
}else if (type == "Line"){
|
||||
return PULineAffector::create();
|
||||
}else if (type == "LinearForce"){
|
||||
return PULinearForceAffector::create();
|
||||
}else if (type == "ParticleFollower"){
|
||||
return PUParticleFollower::create();
|
||||
}else if (type == "PathFollower"){
|
||||
return PUPathFollower::create();
|
||||
}else if (type == "PlaneCollider"){
|
||||
return PUPlaneCollider::create();
|
||||
}else if (type == "Randomiser"){
|
||||
return PURandomiser::create();
|
||||
}else if (type == "Scale"){
|
||||
return PUScaleAffector::create();
|
||||
}else if (type == "ScaleVelocity"){
|
||||
return PUScaleVelocityAffector::create();
|
||||
}else if (type == "SineForce"){
|
||||
return PUSineForceAffector::create();
|
||||
}else if (type == "SphereCollider"){
|
||||
return PUSphereCollider::create();
|
||||
}else if (type == "TextureAnimator"){
|
||||
return PUTextureAnimator::create();
|
||||
}else if (type == "TextureRotator"){
|
||||
return PUTextureRotator::create();
|
||||
}else if (type == "VelocityMatching"){
|
||||
return PUVelocityMatchingAffector::create();
|
||||
}else if (type == "Vortex"){
|
||||
return PUVortexAffector::create();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
111
extensions/Particle3D/PU/CCPUAffectorManager.h
Normal file
111
extensions/Particle3D/PU/CCPUAffectorManager.h
Normal file
@@ -0,0 +1,111 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __CC_PU_PARTICLE_3D_AFFECTOR_MANAGER_H__
|
||||
#define __CC_PU_PARTICLE_3D_AFFECTOR_MANAGER_H__
|
||||
|
||||
#include "base/CCRef.h"
|
||||
#include "extensions/Particle3D/PU/CCPUScriptTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUAffector.h"
|
||||
#include "extensions/Particle3D/PU/CCPUAlignAffectorTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUBaseColliderTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUBaseForceAffectorTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUBoxColliderTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUCollisionAvoidanceAffectorTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUColorAffectorTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUFlockCenteringAffectorTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUForceFieldAffectorTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUGeometryRotatorTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUGravityAffectorTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUInterParticleColliderTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUJetAffectorTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPULineAffectorTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPULinearForceAffectorTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUParticleFollowerTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUPathFollowerTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUPlaneColliderTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPURandomiserTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUScaleAffectorTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUScaleVelocityAffectorTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUSineForceAffectorTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUSphereColliderTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUTextureAnimatorTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUTextureRotatorTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUVelocityMatchingAffectorTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUVortexAffectorTranslator.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class PUAffectorManager
|
||||
{
|
||||
public:
|
||||
|
||||
static PUAffectorManager* Instance();
|
||||
|
||||
/**
|
||||
*/
|
||||
PUScriptTranslator* getTranslator(const std::string &type);
|
||||
PUAffector* createAffector(const std::string &type);
|
||||
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
PUAffectorManager();
|
||||
~PUAffectorManager();
|
||||
|
||||
protected:
|
||||
|
||||
PUAlignAffectorTranslator _alignAffectorTranslator;
|
||||
PUBaseColliderTranslator _baseColliderTranslator;
|
||||
PUBaseForceAffectorTranslator _baseForceAffectorTranslator;
|
||||
PUBoxColliderTranslator _boxColliderTranslator;
|
||||
PUCollisionAvoidanceAffectorTranslator _collisionAvoidanceAffectorTranstor;
|
||||
PUColorAffectorTranslator _colorAffectorTranslator;
|
||||
PUFlockCenteringAffectorTranslator _flockCenteringAffectorTranslator;
|
||||
PUForceFieldAffectorTranslator _forceFieldAffectorTranslator;
|
||||
PUGeometryRotatorTranslator _geometryRotatorTranslator;
|
||||
PUGravityAffectorTranslator _gravityAffectorTranslator;
|
||||
PUInterParticleColliderTranslator _interParticleColliderTranslator;
|
||||
PUJetAffectorTranslator _jetAffectorTranslator;
|
||||
PULineAffectorTranslator _lineAffectorTranslator;
|
||||
PULinearForceAffectorTranslator _linearForceAffectorTranslator;
|
||||
PUParticleFollowerTranslator _particleFollowerTranslator;
|
||||
PUPathFollowerTranslator _pathFollowerTranslator;
|
||||
PUPlaneColliderTranslator _planeColliderTranslator;
|
||||
PURandomiserTranslator _randomiserTranslator;
|
||||
PUScaleAffectorTranslator _scaleAffectorTranslator;
|
||||
PUScaleVelocityAffectorTranslator _scaleVelocityAffectorTranslator;
|
||||
PUSineForceAffectorTranslator _sineForceAffectorTranslator;
|
||||
PUSphereColliderTranslator _sphereColliderTranslator;
|
||||
PUTextureAnimatorTranslator _textureAnimatorTranslator;
|
||||
PUTextureRotatorTranslator _textureRotatorTranslator;
|
||||
PUVelocityMatchingAffectorTranslator _velocityMatchingAffectorTranslator;
|
||||
PUVortexAffectorTranslator _vortexAffectorTranslator;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
|
||||
#endif
|
||||
194
extensions/Particle3D/PU/CCPUAffectorTranslator.cpp
Normal file
194
extensions/Particle3D/PU/CCPUAffectorTranslator.cpp
Normal file
@@ -0,0 +1,194 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCPUAffectorTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUParticleSystem3D.h"
|
||||
#include "extensions/Particle3D/PU/CCPUAffectorManager.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
PUAffectorTranslator::PUAffectorTranslator()
|
||||
:_affector(nullptr)
|
||||
{
|
||||
}
|
||||
//-------------------------------------------------------------------------
|
||||
void PUAffectorTranslator::translate(PUScriptCompiler* compiler, PUAbstractNode *node)
|
||||
{
|
||||
PUObjectAbstractNode* obj = reinterpret_cast<PUObjectAbstractNode*>(node);
|
||||
PUObjectAbstractNode* parent = obj->parent ? reinterpret_cast<PUObjectAbstractNode*>(obj->parent) : 0;
|
||||
|
||||
// The name of the obj is the type of the affector
|
||||
// Remark: This can be solved by using a listener, so that obj->values is filled with type + name. Something for later
|
||||
std::string type;
|
||||
if(!obj->name.empty())
|
||||
{
|
||||
type = obj->name;
|
||||
}
|
||||
|
||||
//// Get the factory
|
||||
//ParticleAffectorFactory* particleAffectorFactory = ParticleSystemManager::getSingletonPtr()->getAffectorFactory(type);
|
||||
//if (!particleAffectorFactory)
|
||||
//{
|
||||
// compiler->addError(ScriptCompiler::CE_INVALIDPARAMETERS, obj->file, obj->line);
|
||||
// return;
|
||||
//}
|
||||
PUScriptTranslator *particleAffectorTranlator = PUAffectorManager::Instance()->getTranslator(type);
|
||||
if (!particleAffectorTranlator) return;
|
||||
//// Create the affector
|
||||
//mAffector = ParticleSystemManager::getSingletonPtr()->createAffector(type);
|
||||
//if (!mAffector)
|
||||
//{
|
||||
// compiler->addError(ScriptCompiler::CE_INVALIDPARAMETERS, obj->file, obj->line);
|
||||
// return;
|
||||
//}
|
||||
_affector = PUAffectorManager::Instance()->createAffector(type);
|
||||
if (!_affector) return;
|
||||
_affector->setAffectorType(type);
|
||||
|
||||
if (parent && parent->context)
|
||||
{
|
||||
PUParticleSystem3D* system = static_cast<PUParticleSystem3D*>(parent->context);
|
||||
system->addAffector(_affector);
|
||||
}
|
||||
|
||||
// The first value is the (optional) name
|
||||
std::string name;
|
||||
if(!obj->values.empty())
|
||||
{
|
||||
getString(*obj->values.front(), &name);
|
||||
_affector->setName(name);
|
||||
}
|
||||
|
||||
// Set it in the context
|
||||
obj->context = _affector;
|
||||
|
||||
// Run through properties
|
||||
for(PUAbstractNodeList::iterator i = obj->children.begin(); i != obj->children.end(); ++i)
|
||||
{
|
||||
if((*i)->type == ANT_PROPERTY)
|
||||
{
|
||||
PUPropertyAbstractNode* prop = reinterpret_cast<PUPropertyAbstractNode*>((*i));
|
||||
if (prop->name == token[TOKEN_ENABLED])
|
||||
{
|
||||
// Property: enabled
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_ENABLED], VAL_BOOL))
|
||||
{
|
||||
bool val;
|
||||
if(getBoolean(*prop->values.front(), &val))
|
||||
{
|
||||
_affector->setEnabled(val);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_POSITION])
|
||||
{
|
||||
// Property: position
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_POSITION], VAL_VECTOR3))
|
||||
{
|
||||
Vec3 val;
|
||||
if(getVector3(prop->values.begin(), prop->values.end(), &val))
|
||||
{
|
||||
//mAffector->position = val;
|
||||
//mAffector->originalPosition = val;
|
||||
_affector->setLocalPosition(val);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_AFFECTOR_MASS])
|
||||
{
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_AFFECTOR_MASS], VAL_REAL))
|
||||
{
|
||||
float val = 0.0f;
|
||||
if(getFloat(*prop->values.front(), &val))
|
||||
{
|
||||
_affector->setMass(val);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_AFFECTOR_SPECIALISATION])
|
||||
{
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_AFFECTOR_SPECIALISATION], VAL_STRING))
|
||||
{
|
||||
std::string val;
|
||||
if(getString(*prop->values.front(), &val))
|
||||
{
|
||||
if (val == token[TOKEN_AFFECTOR_SPEC_DEFAULT])
|
||||
{
|
||||
_affector->setAffectSpecialisation(PUAffector::AFSP_DEFAULT);
|
||||
}
|
||||
else if (val == token[TOKEN_AFFECTOR_SPEC_TTL_INCREASE])
|
||||
{
|
||||
_affector->setAffectSpecialisation(PUAffector::AFSP_TTL_INCREASE);
|
||||
}
|
||||
else if (val == token[TOKEN_AFFECTOR_SPEC_TTL_DECREASE])
|
||||
{
|
||||
_affector->setAffectSpecialisation(PUAffector::AFSP_TTL_DECREASE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_AFFECTOR_EXCLUDE_EMITTER])
|
||||
{
|
||||
if (passValidatePropertyNoValues(compiler, prop, token[TOKEN_AFFECTOR_EXCLUDE_EMITTER]))
|
||||
{
|
||||
for(PUAbstractNodeList::iterator j = prop->values.begin(); j != prop->values.end(); ++j)
|
||||
{
|
||||
std::string val;
|
||||
if(getString(**j, &val))
|
||||
{
|
||||
_affector->addEmitterToExclude(val);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (particleAffectorTranlator->translateChildProperty(compiler, *i))
|
||||
{
|
||||
// Parsed the property by another translator; do nothing
|
||||
}
|
||||
else
|
||||
{
|
||||
errorUnexpectedProperty(compiler, prop);
|
||||
}
|
||||
}
|
||||
else if((*i)->type == ANT_OBJECT)
|
||||
{
|
||||
if (particleAffectorTranlator->translateChildObject(compiler, *i))
|
||||
{
|
||||
// Parsed the object by another translator; do nothing
|
||||
}
|
||||
else
|
||||
{
|
||||
processNode(compiler, *i);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
errorUnexpectedToken(compiler, *i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
50
extensions/Particle3D/PU/CCPUAffectorTranslator.h
Normal file
50
extensions/Particle3D/PU/CCPUAffectorTranslator.h
Normal file
@@ -0,0 +1,50 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __CC_PU_PARTICLE_3D_AFFECTOR_TRANSLATOR_H__
|
||||
#define __CC_PU_PARTICLE_3D_AFFECTOR_TRANSLATOR_H__
|
||||
|
||||
#include "extensions/Particle3D/PU/CCPUScriptTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUScriptCompiler.h"
|
||||
#include "extensions/Particle3D/PU/CCPUAffector.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class PUAffectorTranslator : public PUScriptTranslator
|
||||
{
|
||||
protected:
|
||||
|
||||
PUAffector* _affector;
|
||||
|
||||
public:
|
||||
PUAffectorTranslator();
|
||||
virtual ~PUAffectorTranslator(){};
|
||||
virtual void translate(PUScriptCompiler* compiler, PUAbstractNode *node);
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif /* defined(__cocos2d_libs__CCParticle3DAffectorTranslator__) */
|
||||
99
extensions/Particle3D/PU/CCPUAlignAffector.cpp
Normal file
99
extensions/Particle3D/PU/CCPUAlignAffector.cpp
Normal file
@@ -0,0 +1,99 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCPUAlignAffector.h"
|
||||
#include "extensions/Particle3D/PU/CCPUParticleSystem3D.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
// Constants
|
||||
const bool PUAlignAffector::DEFAULT_RESIZE = false;
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
PUAlignAffector::PUAlignAffector()
|
||||
: PUAffector()
|
||||
, _resize(DEFAULT_RESIZE)
|
||||
{
|
||||
}
|
||||
|
||||
PUAlignAffector::~PUAlignAffector()
|
||||
{
|
||||
}
|
||||
|
||||
bool PUAlignAffector::isResize() const
|
||||
{
|
||||
return _resize;
|
||||
}
|
||||
|
||||
void PUAlignAffector::setResize(bool resize)
|
||||
{
|
||||
_resize = resize;
|
||||
}
|
||||
|
||||
void PUAlignAffector::updatePUAffector( PUParticle3D *particle, float /*deltaTime*/ )
|
||||
{
|
||||
//auto particles = _particleSystem->getParticles();
|
||||
//if (!particles.empty())
|
||||
{
|
||||
//PUParticle3D *preParticle = particles[0];
|
||||
//for (unsigned int i = 1; i < particles.size(); ++i)
|
||||
{
|
||||
//PUParticle3D *particle = particles[i];
|
||||
Vec3 diff = _previousParticle->position - particle->position;
|
||||
if (_resize)
|
||||
{
|
||||
particle->setOwnDimensions(particle->width, diff.length(), particle->depth);
|
||||
}
|
||||
diff.normalize();
|
||||
particle->orientation.x = diff.x;
|
||||
particle->orientation.y = diff.y;
|
||||
particle->orientation.z = diff.z;
|
||||
_previousParticle = particle;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PUAlignAffector::firstParticleUpdate( PUParticle3D *particle, float /*deltaTime*/ )
|
||||
{
|
||||
_previousParticle = particle;
|
||||
}
|
||||
|
||||
PUAlignAffector* PUAlignAffector::create()
|
||||
{
|
||||
auto paa = new (std::nothrow) PUAlignAffector();
|
||||
paa->autorelease();
|
||||
return paa;
|
||||
}
|
||||
|
||||
void PUAlignAffector::copyAttributesTo( PUAffector* affector )
|
||||
{
|
||||
PUAffector::copyAttributesTo(affector);
|
||||
|
||||
PUAlignAffector* alignAffector = static_cast<PUAlignAffector*>(affector);
|
||||
alignAffector->_resize = _resize;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
68
extensions/Particle3D/PU/CCPUAlignAffector.h
Normal file
68
extensions/Particle3D/PU/CCPUAlignAffector.h
Normal file
@@ -0,0 +1,68 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#ifndef __CC_PU_PARTICLE_3D_ALIGN_AFFECTOR_H__
|
||||
#define __CC_PU_PARTICLE_3D_ALIGN_AFFECTOR_H__
|
||||
|
||||
#include "extensions/Particle3D/PU/CCPUAffector.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class CC_DLL PUAlignAffector : public PUAffector
|
||||
{
|
||||
public:
|
||||
// Constants
|
||||
static const bool DEFAULT_RESIZE;
|
||||
|
||||
static PUAlignAffector* create();
|
||||
|
||||
virtual void firstParticleUpdate(PUParticle3D *particle, float deltaTime) override;
|
||||
virtual void updatePUAffector(PUParticle3D *particle, float deltaTime) override;
|
||||
|
||||
/** See setResize().
|
||||
*/
|
||||
bool isResize() const;
|
||||
|
||||
/** Set resize. This attribute determines whether the size of the particle must be changed
|
||||
according to its alignment with the previous particle.
|
||||
*/
|
||||
void setResize(bool resize);
|
||||
|
||||
virtual void copyAttributesTo (PUAffector* affector) override;
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
PUAlignAffector();
|
||||
virtual ~PUAlignAffector();
|
||||
|
||||
protected:
|
||||
|
||||
bool _resize;
|
||||
PUParticle3D* _previousParticle;
|
||||
};
|
||||
NS_CC_END
|
||||
|
||||
#endif
|
||||
78
extensions/Particle3D/PU/CCPUAlignAffectorTranslator.cpp
Normal file
78
extensions/Particle3D/PU/CCPUAlignAffectorTranslator.cpp
Normal file
@@ -0,0 +1,78 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCPUAlignAffectorTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUParticleSystem3D.h"
|
||||
#include "extensions/Particle3D/PU/CCPUDynamicAttribute.h"
|
||||
#include "extensions/Particle3D/PU/CCPUDynamicAttributeTranslator.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
PUAlignAffectorTranslator::PUAlignAffectorTranslator()
|
||||
{
|
||||
}
|
||||
//-------------------------------------------------------------------------
|
||||
bool PUAlignAffectorTranslator::translateChildProperty( PUScriptCompiler* compiler, PUAbstractNode *node )
|
||||
{
|
||||
PUPropertyAbstractNode* prop = reinterpret_cast<PUPropertyAbstractNode*>(node);
|
||||
PUAffector* af = static_cast<PUAffector*>(prop->parent->context);
|
||||
PUAlignAffector* affector = static_cast<PUAlignAffector*>(af);
|
||||
|
||||
if (prop->name == token[TOKEN_RESIZE])
|
||||
{
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_RESIZE], VAL_BOOL))
|
||||
{
|
||||
bool val;
|
||||
if(getBoolean(*prop->values.front(), &val))
|
||||
{
|
||||
affector->setResize(val);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_ALIGN_RESIZE])
|
||||
{
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_ALIGN_RESIZE], VAL_BOOL))
|
||||
{
|
||||
bool val;
|
||||
if(getBoolean(*prop->values.front(), &val))
|
||||
{
|
||||
affector->setResize(val);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool PUAlignAffectorTranslator::translateChildObject( PUScriptCompiler* /*compiler*/, PUAbstractNode* /*node*/ )
|
||||
{
|
||||
// No objects
|
||||
return false;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
48
extensions/Particle3D/PU/CCPUAlignAffectorTranslator.h
Normal file
48
extensions/Particle3D/PU/CCPUAlignAffectorTranslator.h
Normal file
@@ -0,0 +1,48 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __CC_PU_PARTICLE_3D_ALIGN_AFFECTOR_TRANSLATOR_H__
|
||||
#define __CC_PU_PARTICLE_3D_ALIGN_AFFECTOR_TRANSLATOR_H__
|
||||
|
||||
#include "extensions/Particle3D/PU/CCPUScriptTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUScriptCompiler.h"
|
||||
#include "extensions/Particle3D/PU/CCPUAlignAffector.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class PUAlignAffectorTranslator : public PUScriptTranslator
|
||||
{
|
||||
public:
|
||||
PUAlignAffectorTranslator();
|
||||
virtual ~PUAlignAffectorTranslator(){};
|
||||
|
||||
virtual bool translateChildProperty(PUScriptCompiler* compiler, PUAbstractNode *node);
|
||||
virtual bool translateChildObject(PUScriptCompiler* compiler, PUAbstractNode *node);
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif
|
||||
133
extensions/Particle3D/PU/CCPUBaseCollider.cpp
Normal file
133
extensions/Particle3D/PU/CCPUBaseCollider.cpp
Normal file
@@ -0,0 +1,133 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCPUBaseCollider.h"
|
||||
#include "extensions/Particle3D/PU/CCPUParticleSystem3D.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
// Constants
|
||||
const float PUBaseCollider::DEFAULT_BOUNCYNESS = 1.0f;
|
||||
const float PUBaseCollider::DEFAULT_FRICTION = 0.0f;
|
||||
const PUBaseCollider::IntersectionType PUBaseCollider::DEFAULT_INTERSECTION_TYPE = PUBaseCollider::IT_POINT;
|
||||
const PUBaseCollider::CollisionType PUBaseCollider::DEFAULT_COLLISION_TYPE = PUBaseCollider::CT_BOUNCE;
|
||||
//-----------------------------------------------------------------------
|
||||
PUBaseCollider::PUBaseCollider()
|
||||
: PUAffector()
|
||||
, _friction(DEFAULT_FRICTION)
|
||||
, _bouncyness(DEFAULT_BOUNCYNESS)
|
||||
, _intersectionType(DEFAULT_INTERSECTION_TYPE)
|
||||
, _collisionType(DEFAULT_COLLISION_TYPE)
|
||||
, _velocityScale(1.0f)
|
||||
{
|
||||
}
|
||||
|
||||
PUBaseCollider::~PUBaseCollider()
|
||||
{
|
||||
}
|
||||
|
||||
PUBaseCollider::IntersectionType PUBaseCollider::getIntersectionType() const
|
||||
{
|
||||
return _intersectionType;
|
||||
}
|
||||
|
||||
void PUBaseCollider::setIntersectionType( const IntersectionType& intersectionType )
|
||||
{
|
||||
_intersectionType = intersectionType;
|
||||
}
|
||||
|
||||
PUBaseCollider::CollisionType PUBaseCollider::getCollisionType() const
|
||||
{
|
||||
return _collisionType;
|
||||
}
|
||||
|
||||
void PUBaseCollider::setCollisionType( const CollisionType& collisionType )
|
||||
{
|
||||
_collisionType = collisionType;
|
||||
}
|
||||
|
||||
float PUBaseCollider::getFriction() const
|
||||
{
|
||||
return _friction;
|
||||
}
|
||||
|
||||
void PUBaseCollider::setFriction( const float friction )
|
||||
{
|
||||
_friction = friction;
|
||||
}
|
||||
|
||||
float PUBaseCollider::getBouncyness() const
|
||||
{
|
||||
return _bouncyness;
|
||||
}
|
||||
|
||||
void PUBaseCollider::setBouncyness( const float bouncyness )
|
||||
{
|
||||
_bouncyness = bouncyness;
|
||||
}
|
||||
|
||||
void PUBaseCollider::populateAlignedBox( AABB& box, const Vec3& position, const float width, const float height, const float depth )
|
||||
{
|
||||
float halfWidth = 0.5f * width;
|
||||
float halfHeight = 0.5f * height;
|
||||
float halfDepth = 0.5f * depth;
|
||||
box.set(Vec3(position.x - halfWidth,
|
||||
position.y - halfHeight,
|
||||
position.z - halfDepth),
|
||||
Vec3(position.x + halfWidth,
|
||||
position.y + halfHeight,
|
||||
position.z + halfDepth));
|
||||
}
|
||||
|
||||
void PUBaseCollider::calculateRotationSpeedAfterCollision( PUParticle3D* particle )
|
||||
{
|
||||
if (particle->particleType != PUParticle3D::PT_VISUAL)
|
||||
return;
|
||||
|
||||
float signedFriction = CCRANDOM_0_1() > 0.5f ? -(_friction - 1) : (_friction - 1);
|
||||
|
||||
particle->rotationSpeed *= signedFriction;
|
||||
particle->zRotationSpeed *= signedFriction;
|
||||
}
|
||||
|
||||
void PUBaseCollider::preUpdateAffector( float deltaTime )
|
||||
{
|
||||
// Take scaled velocity into account
|
||||
_velocityScale = deltaTime * (static_cast<PUParticleSystem3D *>(_particleSystem))->getParticleSystemScaleVelocity();
|
||||
}
|
||||
|
||||
void PUBaseCollider::copyAttributesTo( PUAffector* affector )
|
||||
{
|
||||
PUAffector::copyAttributesTo(affector);
|
||||
|
||||
PUBaseCollider* baseCollider = static_cast<PUBaseCollider*>(affector);
|
||||
baseCollider->_bouncyness = _bouncyness;
|
||||
baseCollider->_friction = _friction;
|
||||
baseCollider->_intersectionType = _intersectionType;
|
||||
baseCollider->_collisionType = _collisionType;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
137
extensions/Particle3D/PU/CCPUBaseCollider.h
Normal file
137
extensions/Particle3D/PU/CCPUBaseCollider.h
Normal file
@@ -0,0 +1,137 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#ifndef __CC_PU_PARTICLE_3D_BASE_COLLIDER_H__
|
||||
#define __CC_PU_PARTICLE_3D_BASE_COLLIDER_H__
|
||||
|
||||
#include "extensions/Particle3D/PU/CCPUAffector.h"
|
||||
#include "3d/CCAABB.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
struct PUParticle3D;
|
||||
class CC_DLL PUBaseCollider : public PUAffector
|
||||
{
|
||||
public:
|
||||
/** Determines how a particle collision should be determined. IT_POINT means that the position of
|
||||
the particle will be validated against the Colliders' shape. IT_BOX means that the dimensions
|
||||
(width, height and depth) are used to determine whether the particle collides.
|
||||
*/
|
||||
enum IntersectionType
|
||||
{
|
||||
IT_POINT,
|
||||
IT_BOX
|
||||
};
|
||||
|
||||
/** Determines how a particle behaves after collision with this collider. The behaviour of the
|
||||
particle is solved in the collider and only behaviour that needs the colliders?data is taken
|
||||
into account. The fact that a particle expires for example, can be achieved by using an
|
||||
Observer in combination with an EventHandler (DoExpireEventHandler).
|
||||
CT_NONE means that the particle doesn't do anything. This value should be set if the behaviour
|
||||
of the particle is determined outside the collider (for example, expiring the particle).
|
||||
CT_BOUNCE means that the particle bounces off the collider.
|
||||
CT_FLOW means that the particle flows around the contours of the collider.
|
||||
*/
|
||||
enum CollisionType
|
||||
{
|
||||
CT_NONE,
|
||||
CT_BOUNCE,
|
||||
CT_FLOW,
|
||||
};
|
||||
|
||||
// Constants
|
||||
static const float DEFAULT_BOUNCYNESS;
|
||||
static const float DEFAULT_FRICTION;
|
||||
static const IntersectionType DEFAULT_INTERSECTION_TYPE;
|
||||
static const CollisionType DEFAULT_COLLISION_TYPE;
|
||||
|
||||
virtual void preUpdateAffector(float deltaTime) override;
|
||||
|
||||
/** Returns the type of intersection.
|
||||
*/
|
||||
IntersectionType getIntersectionType() const;
|
||||
|
||||
/** Sets the type of intersection.
|
||||
*/
|
||||
void setIntersectionType(const IntersectionType& intersectionType);
|
||||
|
||||
/** Returns the type of collision.
|
||||
*/
|
||||
CollisionType getCollisionType() const;
|
||||
|
||||
/** Sets the type of collision.
|
||||
*/
|
||||
void setCollisionType(const CollisionType& collisionType);
|
||||
|
||||
/** Returns the friction value.
|
||||
*/
|
||||
float getFriction() const;
|
||||
|
||||
/** Sets the friction value.
|
||||
*/
|
||||
void setFriction(const float friction);
|
||||
|
||||
/** Returns the bouncyness value.
|
||||
*/
|
||||
float getBouncyness() const;
|
||||
|
||||
/** Sets the bouncyness value.
|
||||
*/
|
||||
void setBouncyness(const float bouncyness);
|
||||
|
||||
/** Fill the AxisAlignedBox with data derived from the other arguments.
|
||||
*/
|
||||
void populateAlignedBox(AABB& box,
|
||||
const Vec3& position,
|
||||
const float width,
|
||||
const float height,
|
||||
const float depth);
|
||||
|
||||
/** Recalculates the rotation speed after collision.
|
||||
This function must be explicitly called in the updatePUAffector(float deltaTime) function of the class that inherits from
|
||||
BaseCollider.
|
||||
*/
|
||||
void calculateRotationSpeedAfterCollision(PUParticle3D* particle);
|
||||
|
||||
virtual void copyAttributesTo (PUAffector* affector) override;
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
PUBaseCollider();
|
||||
virtual ~PUBaseCollider();
|
||||
|
||||
protected:
|
||||
|
||||
float _friction; // Physics characteristic that influences particle rotation speed.
|
||||
float _bouncyness; // Physics characteristic that influences particle velocity.
|
||||
IntersectionType _intersectionType;
|
||||
CollisionType _collisionType;
|
||||
float _velocityScale; // Value set in the particle system, but stored in the collider for convenience.
|
||||
|
||||
};
|
||||
NS_CC_END
|
||||
|
||||
#endif
|
||||
142
extensions/Particle3D/PU/CCPUBaseColliderTranslator.cpp
Normal file
142
extensions/Particle3D/PU/CCPUBaseColliderTranslator.cpp
Normal file
@@ -0,0 +1,142 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCPUBaseColliderTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUParticleSystem3D.h"
|
||||
#include "extensions/Particle3D/PU/CCPUDynamicAttribute.h"
|
||||
#include "extensions/Particle3D/PU/CCPUDynamicAttributeTranslator.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
PUBaseColliderTranslator::PUBaseColliderTranslator()
|
||||
{
|
||||
}
|
||||
//-------------------------------------------------------------------------
|
||||
bool PUBaseColliderTranslator::translateChildProperty( PUScriptCompiler* compiler, PUAbstractNode *node )
|
||||
{
|
||||
PUPropertyAbstractNode* prop = reinterpret_cast<PUPropertyAbstractNode*>(node);
|
||||
PUAffector* af = static_cast<PUAffector*>(prop->parent->context);
|
||||
PUBaseCollider* affector = static_cast<PUBaseCollider*>(af);
|
||||
|
||||
if (prop->name == token[TOKEN_FRICTION])
|
||||
{
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_FRICTION], VAL_REAL))
|
||||
{
|
||||
float val = 0.0f;
|
||||
if(getFloat(*prop->values.front(), &val))
|
||||
{
|
||||
affector->setFriction(val);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_COLLIDER_FRICTION])
|
||||
{
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_COLLIDER_FRICTION], VAL_REAL))
|
||||
{
|
||||
float val = 0.0f;
|
||||
if(getFloat(*prop->values.front(), &val))
|
||||
{
|
||||
affector->setFriction(val);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_BOUNCYNESS])
|
||||
{
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_BOUNCYNESS], VAL_REAL))
|
||||
{
|
||||
float val = 0.0f;
|
||||
if(getFloat(*prop->values.front(), &val))
|
||||
{
|
||||
affector->setBouncyness(val);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_COLLIDER_BOUNCYNESS])
|
||||
{
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_COLLIDER_BOUNCYNESS], VAL_REAL))
|
||||
{
|
||||
float val = 0.0f;
|
||||
if(getFloat(*prop->values.front(), &val))
|
||||
{
|
||||
affector->setBouncyness(val);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_INTERSECTION] || prop->name == token[TOKEN_COLLIDER_INTERSECTION])
|
||||
{
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_INTERSECTION], VAL_STRING))
|
||||
{
|
||||
std::string val;
|
||||
if(getString(*prop->values.front(), &val))
|
||||
{
|
||||
if (val == token[TOKEN_COLLIDER_INTERSECTION_POINT])
|
||||
{
|
||||
affector->setIntersectionType(PUBaseCollider::IT_POINT);
|
||||
return true;
|
||||
}
|
||||
else if (val == token[TOKEN_COLLIDER_INTERSECTION_BOX])
|
||||
{
|
||||
affector->setIntersectionType(PUBaseCollider::IT_BOX);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_COLLIDER_COLLISION_TYPE])
|
||||
{
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_COLLIDER_COLLISION_TYPE], VAL_STRING))
|
||||
{
|
||||
std::string val;
|
||||
if(getString(*prop->values.front(), &val))
|
||||
{
|
||||
if (val == token[TOKEN_COLLIDER_BOUNCE])
|
||||
{
|
||||
affector->setCollisionType(PUBaseCollider::CT_BOUNCE);
|
||||
return true;
|
||||
}
|
||||
else if (val == token[TOKEN_COLLIDER_FLOW])
|
||||
{
|
||||
affector->setCollisionType(PUBaseCollider::CT_FLOW);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool PUBaseColliderTranslator::translateChildObject( PUScriptCompiler* /*compiler*/, PUAbstractNode* /*node*/ )
|
||||
{
|
||||
// No objects
|
||||
return false;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
48
extensions/Particle3D/PU/CCPUBaseColliderTranslator.h
Normal file
48
extensions/Particle3D/PU/CCPUBaseColliderTranslator.h
Normal file
@@ -0,0 +1,48 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __CC_PU_PARTICLE_3D_BASE_COLLIDER_TRANSLATOR_H__
|
||||
#define __CC_PU_PARTICLE_3D_BASE_COLLIDER_TRANSLATOR_H__
|
||||
|
||||
#include "extensions/Particle3D/PU/CCPUScriptTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUScriptCompiler.h"
|
||||
#include "extensions/Particle3D/PU/CCPUBaseCollider.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class PUBaseColliderTranslator : public PUScriptTranslator
|
||||
{
|
||||
public:
|
||||
PUBaseColliderTranslator();
|
||||
virtual ~PUBaseColliderTranslator(){};
|
||||
|
||||
virtual bool translateChildProperty(PUScriptCompiler* compiler, PUAbstractNode *node);
|
||||
virtual bool translateChildObject(PUScriptCompiler* compiler, PUAbstractNode *node);
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif
|
||||
77
extensions/Particle3D/PU/CCPUBaseForceAffector.cpp
Normal file
77
extensions/Particle3D/PU/CCPUBaseForceAffector.cpp
Normal file
@@ -0,0 +1,77 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCPUBaseForceAffector.h"
|
||||
#include "extensions/Particle3D/PU/CCPUParticleSystem3D.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
// Constants
|
||||
const Vec3 PUBaseForceAffector::DEFAULT_FORCE_VECTOR(0, 0, 0);
|
||||
const PUBaseForceAffector::ForceApplication PUBaseForceAffector::DEFAULT_FORCE_APPL = PUBaseForceAffector::FA_ADD;
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
PUBaseForceAffector::PUBaseForceAffector()
|
||||
: PUAffector()
|
||||
, _forceVector(DEFAULT_FORCE_VECTOR)
|
||||
, _forceApplication(DEFAULT_FORCE_APPL)
|
||||
{
|
||||
}
|
||||
|
||||
PUBaseForceAffector::~PUBaseForceAffector()
|
||||
{
|
||||
}
|
||||
|
||||
const Vec3& PUBaseForceAffector::getForceVector() const
|
||||
{
|
||||
return _forceVector;
|
||||
}
|
||||
|
||||
void PUBaseForceAffector::setForceVector( const Vec3& forceVector )
|
||||
{
|
||||
_forceVector = forceVector;
|
||||
}
|
||||
|
||||
PUBaseForceAffector::ForceApplication PUBaseForceAffector::getForceApplication() const
|
||||
{
|
||||
return _forceApplication;
|
||||
}
|
||||
|
||||
void PUBaseForceAffector::setForceApplication( ForceApplication forceApplication )
|
||||
{
|
||||
_forceApplication = forceApplication;
|
||||
}
|
||||
|
||||
void PUBaseForceAffector::copyAttributesTo( PUAffector* affector )
|
||||
{
|
||||
PUAffector::copyAttributesTo(affector);
|
||||
|
||||
PUBaseForceAffector* baseForceAffector = static_cast<PUBaseForceAffector*>(affector);
|
||||
baseForceAffector->_forceVector = _forceVector;
|
||||
baseForceAffector->_forceApplication = _forceApplication;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
74
extensions/Particle3D/PU/CCPUBaseForceAffector.h
Normal file
74
extensions/Particle3D/PU/CCPUBaseForceAffector.h
Normal file
@@ -0,0 +1,74 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#ifndef __CC_PU_PARTICLE_3D_BASE_FORCE_AFFECTOR_H__
|
||||
#define __CC_PU_PARTICLE_3D_BASE_FORCE_AFFECTOR_H__
|
||||
|
||||
#include "math/CCMath.h"
|
||||
#include "extensions/Particle3D/PU/CCPUAffector.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class CC_DLL PUBaseForceAffector : public PUAffector
|
||||
{
|
||||
public:
|
||||
enum ForceApplication
|
||||
{
|
||||
FA_AVERAGE,
|
||||
FA_ADD
|
||||
};
|
||||
|
||||
// Constants
|
||||
static const Vec3 DEFAULT_FORCE_VECTOR;
|
||||
static const ForceApplication DEFAULT_FORCE_APPL;
|
||||
|
||||
/**
|
||||
*/
|
||||
const Vec3& getForceVector() const;
|
||||
void setForceVector(const Vec3& forceVector);
|
||||
|
||||
/**
|
||||
*/
|
||||
ForceApplication getForceApplication() const;
|
||||
void setForceApplication(ForceApplication forceApplication);
|
||||
|
||||
virtual void copyAttributesTo (PUAffector* affector) override;
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
PUBaseForceAffector();
|
||||
virtual ~PUBaseForceAffector();
|
||||
|
||||
protected:
|
||||
|
||||
Vec3 _forceVector;
|
||||
Vec3 _scaledVector;
|
||||
ForceApplication _forceApplication;
|
||||
|
||||
};
|
||||
NS_CC_END
|
||||
|
||||
#endif
|
||||
118
extensions/Particle3D/PU/CCPUBaseForceAffectorTranslator.cpp
Normal file
118
extensions/Particle3D/PU/CCPUBaseForceAffectorTranslator.cpp
Normal file
@@ -0,0 +1,118 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCPUBaseForceAffectorTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUParticleSystem3D.h"
|
||||
#include "extensions/Particle3D/PU/CCPUDynamicAttribute.h"
|
||||
#include "extensions/Particle3D/PU/CCPUDynamicAttributeTranslator.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
PUBaseForceAffectorTranslator::PUBaseForceAffectorTranslator()
|
||||
{
|
||||
}
|
||||
//-------------------------------------------------------------------------
|
||||
bool PUBaseForceAffectorTranslator::translateChildProperty( PUScriptCompiler* compiler, PUAbstractNode *node )
|
||||
{
|
||||
PUPropertyAbstractNode* prop = reinterpret_cast<PUPropertyAbstractNode*>(node);
|
||||
PUAffector* af = static_cast<PUAffector*>(prop->parent->context);
|
||||
PUBaseForceAffector* affector = static_cast<PUBaseForceAffector*>(af);
|
||||
|
||||
if (prop->name == token[TOKEN_FORCE_VECTOR])
|
||||
{
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_FORCE_VECTOR], VAL_VECTOR3))
|
||||
{
|
||||
Vec3 val;
|
||||
if(getVector3(prop->values.begin(), prop->values.end(), &val))
|
||||
{
|
||||
affector->setForceVector(val);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_FORCE_AFF_VECTOR])
|
||||
{
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_FORCE_AFF_VECTOR], VAL_VECTOR3))
|
||||
{
|
||||
Vec3 val;
|
||||
if(getVector3(prop->values.begin(), prop->values.end(), &val))
|
||||
{
|
||||
affector->setForceVector(val);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_FORCE_APPLICATION])
|
||||
{
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_FORCE_APPLICATION], VAL_STRING))
|
||||
{
|
||||
std::string val;
|
||||
if(getString(*prop->values.front(), &val))
|
||||
{
|
||||
if (val == token[TOKEN_FORCE_ADD])
|
||||
{
|
||||
affector->setForceApplication(PUBaseForceAffector::FA_ADD);
|
||||
return true;
|
||||
}
|
||||
else if (val == token[TOKEN_FORCE_AVERAGE])
|
||||
{
|
||||
affector->setForceApplication(PUBaseForceAffector::FA_AVERAGE);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_FORCE_AFF_APPLICATION])
|
||||
{
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_FORCE_AFF_APPLICATION], VAL_STRING))
|
||||
{
|
||||
std::string val;
|
||||
if(getString(*prop->values.front(), &val))
|
||||
{
|
||||
if (val == token[TOKEN_FORCE_ADD])
|
||||
{
|
||||
affector->setForceApplication(PUBaseForceAffector::FA_ADD);
|
||||
return true;
|
||||
}
|
||||
else if (val == token[TOKEN_FORCE_AVERAGE])
|
||||
{
|
||||
affector->setForceApplication(PUBaseForceAffector::FA_AVERAGE);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool PUBaseForceAffectorTranslator::translateChildObject( PUScriptCompiler* /*compiler*/, PUAbstractNode* /*node*/ )
|
||||
{
|
||||
// No objects
|
||||
return false;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
48
extensions/Particle3D/PU/CCPUBaseForceAffectorTranslator.h
Normal file
48
extensions/Particle3D/PU/CCPUBaseForceAffectorTranslator.h
Normal file
@@ -0,0 +1,48 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __CC_PU_PARTICLE_3D_BASE_FORCE_AFFECT_TRANSLATOR_H__
|
||||
#define __CC_PU_PARTICLE_3D_BASE_FORCE_AFFECT_TRANSLATOR_H__
|
||||
|
||||
#include "extensions/Particle3D/PU/CCPUScriptTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUScriptCompiler.h"
|
||||
#include "extensions/Particle3D/PU/CCPUBaseForceAffector.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class PUBaseForceAffectorTranslator : public PUScriptTranslator
|
||||
{
|
||||
public:
|
||||
PUBaseForceAffectorTranslator();
|
||||
virtual ~PUBaseForceAffectorTranslator(){};
|
||||
|
||||
virtual bool translateChildProperty(PUScriptCompiler* compiler, PUAbstractNode *node);
|
||||
virtual bool translateChildObject(PUScriptCompiler* compiler, PUAbstractNode *node);
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif
|
||||
371
extensions/Particle3D/PU/CCPUBeamRender.cpp
Normal file
371
extensions/Particle3D/PU/CCPUBeamRender.cpp
Normal file
@@ -0,0 +1,371 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "extensions/Particle3D/CCParticleSystem3D.h"
|
||||
#include "extensions/Particle3D/PU/CCPUBeamRender.h"
|
||||
#include "extensions/Particle3D/PU/CCPUParticleSystem3D.h"
|
||||
#include "extensions/Particle3D/PU/CCPUUtil.h"
|
||||
#include "extensions/Particle3D/PU/CCPUSimpleSpline.h"
|
||||
#include "renderer/CCMeshCommand.h"
|
||||
#include "renderer/CCRenderer.h"
|
||||
#include "renderer/CCTextureCache.h"
|
||||
#include "renderer/backend/ProgramState.h"
|
||||
#include "base/CCDirector.h"
|
||||
#include "3d/CCSprite3D.h"
|
||||
#include "3d/CCMesh.h"
|
||||
#include "2d/CCCamera.h"
|
||||
#include <sstream>
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
// Constants
|
||||
const bool PUBeamRender::DEFAULT_USE_VERTEX_COLOURS = false;
|
||||
const size_t PUBeamRender::DEFAULT_MAX_ELEMENTS = 10;
|
||||
const float PUBeamRender::DEFAULT_UPDATE_INTERVAL = 0.1f;
|
||||
const float PUBeamRender::DEFAULT_DEVIATION = 300;
|
||||
const size_t PUBeamRender::DEFAULT_NUMBER_OF_SEGMENTS = 2;
|
||||
const PUBillboardChain::TexCoordDirection PUBeamRender::DEFAULT_TEXTURE_DIRECTION = PUBillboardChain::TCD_V;
|
||||
|
||||
PUBeamRender* PUBeamRender::create( const std::string &texFile )
|
||||
{
|
||||
auto br = new (std::nothrow) PUBeamRender();
|
||||
br->autorelease();
|
||||
br->_texFile = texFile;
|
||||
return br;
|
||||
}
|
||||
|
||||
void PUBeamRender::render( Renderer* renderer, const Mat4 &transform, ParticleSystem3D* particleSystem )
|
||||
{
|
||||
const ParticlePool &particlePool = particleSystem->getParticlePool();
|
||||
if (!_isVisible || particlePool.empty() || !_billboardChain)
|
||||
return;
|
||||
|
||||
Vec3 basePosition = static_cast<PUParticleSystem3D *>(_particleSystem)->getDerivedPosition();
|
||||
for (auto iter : particlePool.getActiveDataList())
|
||||
{
|
||||
auto particle = static_cast<PUParticle3D *>(iter);
|
||||
auto visualData = static_cast<PUParticle3DBeamVisualData*>(particle->visualData);
|
||||
if (visualData){
|
||||
Vec3 end = particle->position - basePosition;
|
||||
PUSimpleSpline spline;
|
||||
|
||||
// Add points
|
||||
spline.addPoint(Vec3::ZERO);
|
||||
for (size_t numDev = 0; numDev < _numberOfSegments; ++numDev)
|
||||
{
|
||||
spline.addPoint(visualData->half[numDev]);
|
||||
}
|
||||
spline.addPoint(end);
|
||||
|
||||
// Loop through all chain elements
|
||||
for (size_t j = 0; j < _maxChainElements; ++j)
|
||||
{
|
||||
PUBillboardChain::Element element = _billboardChain->getChainElement(visualData->chainIndex, j);
|
||||
|
||||
// 1. Set the width of the chain if required
|
||||
if (particle->ownDimensions)
|
||||
{
|
||||
element.width = _rendererScale.x * particle->width;
|
||||
}
|
||||
|
||||
// 2. Set positions of the elements
|
||||
element.position = spline.interpolate((float)j / (float)_maxChainElements);
|
||||
|
||||
// 3. Set the colour
|
||||
element.color = particle->color;
|
||||
|
||||
// 4. Update
|
||||
_billboardChain->updateChainElement(visualData->chainIndex, j, element);
|
||||
}
|
||||
visualData->setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
_billboardChain->render(renderer, transform, particleSystem);
|
||||
}
|
||||
|
||||
PUBeamRender::PUBeamRender() :
|
||||
_billboardChain(0),
|
||||
_quota(0),
|
||||
_useVertexColours(DEFAULT_USE_VERTEX_COLOURS),
|
||||
_maxChainElements(DEFAULT_MAX_ELEMENTS),
|
||||
_updateInterval(DEFAULT_UPDATE_INTERVAL),
|
||||
_deviation(DEFAULT_DEVIATION),
|
||||
_numberOfSegments(DEFAULT_NUMBER_OF_SEGMENTS),
|
||||
_jump(false),
|
||||
_texCoordDirection(DEFAULT_TEXTURE_DIRECTION)
|
||||
{
|
||||
autoRotate = true;
|
||||
}
|
||||
|
||||
PUBeamRender::~PUBeamRender()
|
||||
{
|
||||
if (!_particleSystem)
|
||||
return;
|
||||
|
||||
destroyAll();
|
||||
}
|
||||
|
||||
void PUBeamRender::particleEmitted( PUParticleSystem3D* particleSystem, PUParticle3D* particle )
|
||||
{
|
||||
if (!particle->visualData && !_visualData.empty() && particle->particleType == PUParticle3D::PT_VISUAL)
|
||||
{
|
||||
particle->visualData = _visualData.back();
|
||||
PUParticle3DBeamVisualData* beamRendererVisualData = static_cast<PUParticle3DBeamVisualData*>(particle->visualData);
|
||||
beamRendererVisualData->setVisible(true, _rendererScale.x * particleSystem->getDefaultWidth()); // PU 1.4
|
||||
_visualData.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
void PUBeamRender::particleExpired( PUParticleSystem3D* /*particleSystem*/, PUParticle3D* particle )
|
||||
{
|
||||
if (particle->visualData)
|
||||
{
|
||||
PUParticle3DBeamVisualData* beamRendererVisualData = static_cast<PUParticle3DBeamVisualData*>(particle->visualData);
|
||||
beamRendererVisualData->setVisible(false, 0); // PU 1.4
|
||||
_visualData.push_back(beamRendererVisualData);
|
||||
particle->visualData = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
bool PUBeamRender::isUseVertexColours() const
|
||||
{
|
||||
return _useVertexColours;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUBeamRender::setUseVertexColours(bool useVertexColours)
|
||||
{
|
||||
_useVertexColours = useVertexColours;
|
||||
if (!_billboardChain)
|
||||
return;
|
||||
|
||||
_billboardChain->setUseVertexColours(_useVertexColours);
|
||||
_billboardChain->setUseTextureCoords(!_useVertexColours);
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
size_t PUBeamRender::getMaxChainElements() const
|
||||
{
|
||||
return _maxChainElements;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUBeamRender::setMaxChainElements(size_t maxChainElements)
|
||||
{
|
||||
_maxChainElements = maxChainElements;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
float PUBeamRender::getUpdateInterval() const
|
||||
{
|
||||
return _updateInterval;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUBeamRender::setUpdateInterval(float updateInterval)
|
||||
{
|
||||
_updateInterval = updateInterval;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
float PUBeamRender::getDeviation() const
|
||||
{
|
||||
return _deviation;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUBeamRender::setDeviation(float deviation)
|
||||
{
|
||||
_deviation = deviation;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
size_t PUBeamRender::getNumberOfSegments() const
|
||||
{
|
||||
return _numberOfSegments;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUBeamRender::setNumberOfSegments(size_t numberOfSegments)
|
||||
{
|
||||
_numberOfSegments = numberOfSegments;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
bool PUBeamRender::isJump() const
|
||||
{
|
||||
return _jump;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUBeamRender::setJump(bool jump)
|
||||
{
|
||||
_jump = jump;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
PUBillboardChain::TexCoordDirection PUBeamRender::getTexCoordDirection() const
|
||||
{
|
||||
return _texCoordDirection;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUBeamRender::setTexCoordDirection(PUBillboardChain::TexCoordDirection texCoordDirection)
|
||||
{
|
||||
_texCoordDirection = texCoordDirection;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void PUBeamRender::prepare()
|
||||
{
|
||||
if (!_particleSystem)
|
||||
return;
|
||||
|
||||
// Register itself to the technique
|
||||
if (_particleSystem)
|
||||
{
|
||||
// Although it is safe to assume that technique == mParentTechnique, use the mParentTechnique, because the mParentTechnique is
|
||||
// also used for unregistering.
|
||||
static_cast<PUParticleSystem3D *>(_particleSystem)->addListener(this);
|
||||
}
|
||||
|
||||
_quota = _particleSystem->getParticleQuota();
|
||||
|
||||
// Create BillboardChain
|
||||
std::stringstream ss;
|
||||
ss << this;
|
||||
_billboardChainName = "Beam" + ss.str();
|
||||
_billboardChain = new (std::nothrow) PUBillboardChain(_billboardChainName, _texFile);
|
||||
_billboardChain->setDynamic(true);
|
||||
_billboardChain->setNumberOfChains(_quota);
|
||||
_billboardChain->setMaxChainElements(_maxChainElements);
|
||||
_billboardChain->setTextureCoordDirection(_texCoordDirection);
|
||||
setUseVertexColours(_useVertexColours);
|
||||
_billboardChain->setOtherTextureCoordRange(0.0f, 1.0f);
|
||||
_billboardChain->setDepthTest(_depthTest);
|
||||
_billboardChain->setDepthWrite(_depthWrite);
|
||||
|
||||
// Create number of VisualData objects
|
||||
for (size_t i = 0; i < _quota; i++)
|
||||
{
|
||||
for (size_t j = 0; j < _maxChainElements; j++)
|
||||
{
|
||||
PUBillboardChain::Element element;
|
||||
element = PUBillboardChain::Element(Vec3::ZERO, _rendererScale.x * static_cast<PUParticleSystem3D *>(_particleSystem)->getDefaultWidth(), 0.0f, Vec4::ONE, Quaternion::identity()); // V1.51
|
||||
_billboardChain->addChainElement(i, element);
|
||||
}
|
||||
|
||||
PUParticle3DBeamVisualData* visualData = new (std::nothrow) PUParticle3DBeamVisualData(i, _billboardChain);
|
||||
for (size_t numDev = 0; numDev < _numberOfSegments; ++numDev)
|
||||
{
|
||||
// Initialise the positions
|
||||
visualData->half[numDev].setZero();
|
||||
visualData->destinationHalf[numDev].setZero();
|
||||
}
|
||||
_allVisualData.push_back(visualData); // Managed by this renderer
|
||||
_visualData.push_back(visualData); // Used to assign to a particle
|
||||
}
|
||||
}
|
||||
|
||||
void PUBeamRender::unPrepare()
|
||||
{
|
||||
destroyAll();
|
||||
}
|
||||
|
||||
void PUBeamRender::updateRender( PUParticle3D *particle, float deltaTime, bool /*firstParticle*/ )
|
||||
{
|
||||
if (!particle->visualData)
|
||||
return;
|
||||
|
||||
PUParticle3DBeamVisualData* beamRendererVisualData = static_cast<PUParticle3DBeamVisualData*>(particle->visualData);
|
||||
beamRendererVisualData->timeSinceLastUpdate -= deltaTime;
|
||||
|
||||
if (beamRendererVisualData->timeSinceLastUpdate < 0)
|
||||
{
|
||||
|
||||
Vec3 end = particle->position - static_cast<PUParticleSystem3D *>(_particleSystem)->getDerivedPosition();
|
||||
Vec3 perpendicular;
|
||||
float divide = (float)_numberOfSegments + 1.0f;
|
||||
for (size_t numDev = 0; numDev < _numberOfSegments; ++numDev)
|
||||
{
|
||||
Vec3::cross(end, Vec3(CCRANDOM_MINUS1_1(), CCRANDOM_MINUS1_1(), CCRANDOM_MINUS1_1()), &perpendicular);
|
||||
perpendicular.normalize();
|
||||
beamRendererVisualData->destinationHalf[numDev] = (((float)numDev + 1.0f) / divide) * end
|
||||
+ Vec3(_rendererScale.x * _deviation * perpendicular.x
|
||||
, _rendererScale.y * _deviation * perpendicular.y
|
||||
, _rendererScale.z * _deviation * perpendicular.z);
|
||||
}
|
||||
beamRendererVisualData->timeSinceLastUpdate += _updateInterval;
|
||||
}
|
||||
|
||||
Vec3 diff;
|
||||
for (size_t numDev = 0; numDev < _numberOfSegments; ++numDev)
|
||||
{
|
||||
if (_jump)
|
||||
{
|
||||
beamRendererVisualData->half[numDev] = beamRendererVisualData->destinationHalf[numDev];
|
||||
}
|
||||
else
|
||||
{
|
||||
diff = beamRendererVisualData->destinationHalf[numDev] - beamRendererVisualData->half[numDev];
|
||||
beamRendererVisualData->half[numDev] = beamRendererVisualData->half[numDev] + deltaTime * diff;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
void PUBeamRender::destroyAll()
|
||||
{
|
||||
if (!_particleSystem || !_billboardChain)
|
||||
return;
|
||||
|
||||
// Remove the listener
|
||||
static_cast<PUParticleSystem3D *>(_particleSystem)->removeListener(this);
|
||||
|
||||
// Delete the BillboardChain
|
||||
CC_SAFE_DELETE(_billboardChain);
|
||||
|
||||
// Delete the visual data
|
||||
std::vector<PUParticle3DBeamVisualData*>::const_iterator it;
|
||||
std::vector<PUParticle3DBeamVisualData*>::const_iterator itEnd = _allVisualData.end();
|
||||
for (it = _allVisualData.begin(); it != itEnd; ++it)
|
||||
{
|
||||
delete *it;
|
||||
}
|
||||
|
||||
_allVisualData.clear();
|
||||
_visualData.clear();
|
||||
}
|
||||
|
||||
PUBeamRender* PUBeamRender::clone()
|
||||
{
|
||||
auto br = PUBeamRender::create(_texFile);
|
||||
copyAttributesTo(br);
|
||||
return br;
|
||||
}
|
||||
|
||||
void PUBeamRender::copyAttributesTo(PUBeamRender *beamRender)
|
||||
{
|
||||
PURender::copyAttributesTo(beamRender);
|
||||
beamRender->setUseVertexColours(_useVertexColours);
|
||||
beamRender->setMaxChainElements(_maxChainElements);
|
||||
beamRender->setUpdateInterval(_updateInterval);
|
||||
beamRender->setDeviation(_deviation);
|
||||
beamRender->setNumberOfSegments(_numberOfSegments);
|
||||
beamRender->setJump(_jump);
|
||||
beamRender->setTexCoordDirection(_texCoordDirection);
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
156
extensions/Particle3D/PU/CCPUBeamRender.h
Normal file
156
extensions/Particle3D/PU/CCPUBeamRender.h
Normal file
@@ -0,0 +1,156 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __CC_PU_PARTICLE_3D_BEAM_RENDER_H__
|
||||
#define __CC_PU_PARTICLE_3D_BEAM_RENDER_H__
|
||||
|
||||
#include "base/CCRef.h"
|
||||
#include "math/CCMath.h"
|
||||
#include "extensions/Particle3D/CCParticle3DRender.h"
|
||||
#include "extensions/Particle3D/PU/CCPUListener.h"
|
||||
#include "extensions/Particle3D/PU/CCPUBillboardChain.h"
|
||||
#include "extensions/Particle3D/PU/CCPURender.h"
|
||||
#include <vector>
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class PUParticle3DBeamVisualData : public Ref
|
||||
{
|
||||
public:
|
||||
PUParticle3DBeamVisualData (size_t index, PUBillboardChain* bbChain) :
|
||||
chainIndex(index),
|
||||
timeSinceLastUpdate(0.0f),
|
||||
billboardChain(bbChain){};
|
||||
|
||||
// Set the chain visible or invisible (PU 1.4)
|
||||
void setVisible(bool visible){/* No implementation */};
|
||||
|
||||
/** The is no decent way to make the individual chains/elements invisible. The width of each element is set to 0 to make it invisible.
|
||||
PU 1.4
|
||||
*/
|
||||
void setVisible(bool visible, float width)
|
||||
{
|
||||
if (!billboardChain)
|
||||
return;
|
||||
|
||||
// Set width to 0 if not visible
|
||||
width = visible ? width : 0;
|
||||
|
||||
size_t max = billboardChain->getMaxChainElements();
|
||||
PUBillboardChain::Element element;
|
||||
for (size_t j = 0; j < max; j++)
|
||||
{
|
||||
element = billboardChain->getChainElement(chainIndex, j);
|
||||
element.width = width;
|
||||
billboardChain->updateChainElement(chainIndex, j, element);
|
||||
}
|
||||
}
|
||||
|
||||
// Index of the chain
|
||||
size_t chainIndex;
|
||||
Vec3 half[100];
|
||||
Vec3 destinationHalf[100];
|
||||
float timeSinceLastUpdate;
|
||||
PUBillboardChain* billboardChain;
|
||||
};
|
||||
|
||||
// particle render for quad
|
||||
class CC_DLL PUBeamRender : public PURender, public PUListener
|
||||
{
|
||||
public:
|
||||
|
||||
// Constants
|
||||
static const bool DEFAULT_USE_VERTEX_COLOURS;
|
||||
static const size_t DEFAULT_MAX_ELEMENTS;
|
||||
static const float DEFAULT_UPDATE_INTERVAL;
|
||||
static const float DEFAULT_DEVIATION;
|
||||
static const size_t DEFAULT_NUMBER_OF_SEGMENTS;
|
||||
static const PUBillboardChain::TexCoordDirection DEFAULT_TEXTURE_DIRECTION;
|
||||
|
||||
static PUBeamRender* create(const std::string &texFile = "");
|
||||
|
||||
virtual void prepare() override;
|
||||
virtual void unPrepare() override;
|
||||
virtual void updateRender(PUParticle3D *particle, float deltaTime, bool firstParticle) override;
|
||||
|
||||
virtual void render(Renderer* renderer, const Mat4 &transform, ParticleSystem3D* particleSystem) override;
|
||||
virtual void particleEmitted(PUParticleSystem3D* particleSystem, PUParticle3D* particle) override;
|
||||
virtual void particleExpired(PUParticleSystem3D* particleSystem, PUParticle3D* particle) override;
|
||||
|
||||
/** Getters and Setters
|
||||
*/
|
||||
bool isUseVertexColours() const;
|
||||
void setUseVertexColours(bool useVertexColours);
|
||||
|
||||
size_t getMaxChainElements() const;
|
||||
void setMaxChainElements(size_t maxChainElements);
|
||||
|
||||
float getUpdateInterval() const;
|
||||
void setUpdateInterval(float updateInterval);
|
||||
|
||||
float getDeviation() const;
|
||||
void setDeviation(float deviation);
|
||||
|
||||
size_t getNumberOfSegments() const;
|
||||
void setNumberOfSegments(size_t numberOfSegments);
|
||||
|
||||
bool isJump() const;
|
||||
void setJump(bool jump);
|
||||
|
||||
PUBillboardChain::TexCoordDirection getTexCoordDirection() const;
|
||||
void setTexCoordDirection(PUBillboardChain::TexCoordDirection texCoordDirection);
|
||||
|
||||
/** Destroys the BillboarChain
|
||||
*/
|
||||
void destroyAll();
|
||||
|
||||
virtual PUBeamRender* clone() override;
|
||||
void copyAttributesTo(PUBeamRender *render);
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
PUBeamRender();
|
||||
virtual ~PUBeamRender();
|
||||
|
||||
protected:
|
||||
|
||||
std::string _texFile;
|
||||
std::string _billboardChainName;
|
||||
PUBillboardChain* _billboardChain;
|
||||
std::vector<PUParticle3DBeamVisualData*> _allVisualData;
|
||||
std::vector<PUParticle3DBeamVisualData*> _visualData;
|
||||
size_t _quota;
|
||||
bool _useVertexColours;
|
||||
size_t _maxChainElements;
|
||||
float _updateInterval;
|
||||
float _deviation;
|
||||
size_t _numberOfSegments;
|
||||
bool _jump;
|
||||
PUBillboardChain::TexCoordDirection _texCoordDirection;
|
||||
};
|
||||
|
||||
|
||||
NS_CC_END
|
||||
#endif
|
||||
64
extensions/Particle3D/PU/CCPUBehaviour.cpp
Normal file
64
extensions/Particle3D/PU/CCPUBehaviour.cpp
Normal file
@@ -0,0 +1,64 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "extensions/Particle3D/PU/CCPUBehaviour.h"
|
||||
#include "base/ccMacros.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
PUBehaviour::PUBehaviour( void ):
|
||||
_particleSystem(nullptr),
|
||||
_behaviourScale(Vec3::ONE)
|
||||
{}
|
||||
|
||||
PUBehaviour::~PUBehaviour( void )
|
||||
{}
|
||||
|
||||
void PUBehaviour::updateBehaviour(PUParticle3D* /*particle*/, float /*deltaTime*/)
|
||||
{}
|
||||
|
||||
void PUBehaviour::initParticleForEmission(PUParticle3D* /*particle*/)
|
||||
{}
|
||||
|
||||
void PUBehaviour::initParticleForExpiration(PUParticle3D* /*particle*/, float /*timeElapsed*/)
|
||||
{}
|
||||
|
||||
PUBehaviour* PUBehaviour::clone()
|
||||
{
|
||||
auto pb = new (std::nothrow) PUBehaviour;
|
||||
pb->autorelease();
|
||||
copyAttributesTo(pb);
|
||||
return pb;
|
||||
}
|
||||
|
||||
void PUBehaviour::copyAttributesTo( PUBehaviour* behaviour )
|
||||
{
|
||||
behaviour->_particleSystem = _particleSystem;
|
||||
behaviour->_behaviourType = _behaviourType;
|
||||
behaviour->_behaviourScale = _behaviourScale;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
89
extensions/Particle3D/PU/CCPUBehaviour.h
Normal file
89
extensions/Particle3D/PU/CCPUBehaviour.h
Normal file
@@ -0,0 +1,89 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __CC_PU_PARTICLE_3D_BEHAVIOUR_H__
|
||||
#define __CC_PU_PARTICLE_3D_BEHAVIOUR_H__
|
||||
|
||||
#include "base/CCRef.h"
|
||||
#include "math/CCMath.h"
|
||||
#include "extensions/Particle3D/PU/CCPUParticleSystem3D.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
struct PUParticle3D;
|
||||
class PUParticleSystem3D;
|
||||
|
||||
class CC_DLL PUBehaviour : public Ref
|
||||
{
|
||||
friend class PUParticleSystem3D;
|
||||
public:
|
||||
|
||||
/** Todo
|
||||
*/
|
||||
const std::string& getBehaviourType() const {return _behaviourType;};
|
||||
void setBehaviourType(const std::string& behaviourType) {_behaviourType = behaviourType;};
|
||||
|
||||
/** Notify that the Behaviour is rescaled.
|
||||
*/
|
||||
virtual void notifyRescaled(const Vec3& scale){_behaviourScale = scale;};
|
||||
|
||||
virtual void prepare() {};
|
||||
virtual void unPrepare() {};
|
||||
|
||||
virtual void updateBehaviour(PUParticle3D *particle, float deltaTime);
|
||||
|
||||
/** Perform initialising activities as soon as the particle with which the ParticleBehaviour is
|
||||
associated, is emitted.
|
||||
*/
|
||||
|
||||
virtual void initParticleForEmission(PUParticle3D* particle);
|
||||
/** Perform some action if a particle expires.
|
||||
*/
|
||||
virtual void initParticleForExpiration(PUParticle3D* particle, float timeElapsed);
|
||||
|
||||
virtual PUBehaviour* clone();
|
||||
virtual void copyAttributesTo (PUBehaviour* behaviour);
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
PUBehaviour();
|
||||
virtual ~PUBehaviour();
|
||||
|
||||
protected:
|
||||
PUParticleSystem3D* _particleSystem;
|
||||
|
||||
// Type of behaviour
|
||||
std::string _behaviourType;
|
||||
|
||||
/** Although the scale is on a Particle System level, the behaviour can also be scaled.
|
||||
*/
|
||||
Vec3 _behaviourScale;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif
|
||||
63
extensions/Particle3D/PU/CCPUBehaviourManager.cpp
Normal file
63
extensions/Particle3D/PU/CCPUBehaviourManager.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCPUBehaviourManager.h"
|
||||
#include "extensions/Particle3D/PU/CCPUSlaveBehaviour.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
PUBehaviourManager::PUBehaviourManager()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
PUBehaviourManager::~PUBehaviourManager()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
PUBehaviourManager* PUBehaviourManager::Instance()
|
||||
{
|
||||
static PUBehaviourManager pam;
|
||||
return &pam;
|
||||
}
|
||||
|
||||
PUScriptTranslator* PUBehaviourManager::getTranslator( const std::string &type )
|
||||
{
|
||||
if (type == "Slave"){
|
||||
return &_slaveBehaviourTranslator;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PUBehaviour* PUBehaviourManager::createBehaviour( const std::string &type )
|
||||
{
|
||||
if (type == "Slave"){
|
||||
return PUSlaveBehaviour::create();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
61
extensions/Particle3D/PU/CCPUBehaviourManager.h
Normal file
61
extensions/Particle3D/PU/CCPUBehaviourManager.h
Normal file
@@ -0,0 +1,61 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __CC_PU_PARTICLE_3D_BEHAVIOUR_MANAGER_H__
|
||||
#define __CC_PU_PARTICLE_3D_BEHAVIOUR_MANAGER_H__
|
||||
|
||||
#include "base/CCRef.h"
|
||||
#include "extensions/Particle3D/PU/CCPUScriptTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUBehaviour.h"
|
||||
#include "extensions/Particle3D/PU/CCPUSlaveBehaviourTranslator.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class PUBehaviourManager
|
||||
{
|
||||
public:
|
||||
|
||||
static PUBehaviourManager* Instance();
|
||||
|
||||
/**
|
||||
*/
|
||||
PUScriptTranslator* getTranslator(const std::string &type);
|
||||
PUBehaviour* createBehaviour(const std::string &type);
|
||||
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
PUBehaviourManager();
|
||||
~PUBehaviourManager();
|
||||
|
||||
protected:
|
||||
|
||||
PUSlaveBehaviourTranslator _slaveBehaviourTranslator;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
|
||||
#endif
|
||||
124
extensions/Particle3D/PU/CCPUBehaviourTranslator.cpp
Normal file
124
extensions/Particle3D/PU/CCPUBehaviourTranslator.cpp
Normal file
@@ -0,0 +1,124 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCPUBehaviourTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUParticleSystem3D.h"
|
||||
#include "extensions/Particle3D/PU/CCPUBehaviourManager.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
PUBehaviourTranslator::PUBehaviourTranslator()
|
||||
:_behaviour(nullptr)
|
||||
{
|
||||
}
|
||||
//-------------------------------------------------------------------------
|
||||
void PUBehaviourTranslator::translate(PUScriptCompiler* compiler, PUAbstractNode *node)
|
||||
{
|
||||
PUObjectAbstractNode* obj = reinterpret_cast<PUObjectAbstractNode*>(node);
|
||||
PUObjectAbstractNode* parent = obj->parent ? reinterpret_cast<PUObjectAbstractNode*>(obj->parent) : 0;
|
||||
|
||||
// The name of the obj is the type of the Behaviour
|
||||
std::string type;
|
||||
if(!obj->name.empty())
|
||||
{
|
||||
type = obj->name;
|
||||
}
|
||||
else
|
||||
{
|
||||
//compiler->addError(ScriptCompiler::CE_INVALIDPARAMETERS, obj->file, obj->line);
|
||||
return;
|
||||
}
|
||||
|
||||
//// Get the factory
|
||||
//ParticleBehaviourFactory* behaviourFactory = ParticleSystemManager::getSingletonPtr()->getBehaviourFactory(type);
|
||||
//if (!behaviourFactory)
|
||||
//{
|
||||
// //compiler->addError(ScriptCompiler::CE_INVALIDPARAMETERS, obj->file, obj->line);
|
||||
// return;
|
||||
//}
|
||||
|
||||
PUScriptTranslator *particleBehaviourTranlator = PUBehaviourManager::Instance()->getTranslator(type);
|
||||
if (!particleBehaviourTranlator) return;
|
||||
|
||||
// Create the Behaviour
|
||||
_behaviour = PUBehaviourManager::Instance()->createBehaviour(type);
|
||||
if (!_behaviour)
|
||||
{
|
||||
//compiler->addError(ScriptCompiler::CE_INVALIDPARAMETERS, obj->file, obj->line);
|
||||
return;
|
||||
}
|
||||
|
||||
_behaviour->setBehaviourType(type);
|
||||
if (parent && parent->context)
|
||||
{
|
||||
PUParticleSystem3D* system = static_cast<PUParticleSystem3D*>(parent->context);
|
||||
system->addBehaviourTemplate(_behaviour);
|
||||
}
|
||||
else
|
||||
{
|
||||
//// It is an alias
|
||||
//_behaviour->setAliasName(parent->name);
|
||||
//ParticleSystemManager::getSingletonPtr()->addAlias(mBehaviour);
|
||||
}
|
||||
|
||||
// Set it in the context
|
||||
obj->context = _behaviour;
|
||||
|
||||
// Run through properties
|
||||
for(PUAbstractNodeList::iterator i = obj->children.begin(); i != obj->children.end(); ++i)
|
||||
{
|
||||
// No properties of its own
|
||||
if((*i)->type == ANT_PROPERTY)
|
||||
{
|
||||
PUPropertyAbstractNode* prop = reinterpret_cast<PUPropertyAbstractNode*>((*i));
|
||||
if (particleBehaviourTranlator->translateChildProperty(compiler, *i))
|
||||
{
|
||||
// Parsed the property by another translator; do nothing
|
||||
}
|
||||
else
|
||||
{
|
||||
errorUnexpectedProperty(compiler, prop);
|
||||
}
|
||||
}
|
||||
else if((*i)->type == ANT_OBJECT)
|
||||
{
|
||||
if (particleBehaviourTranlator->translateChildObject(compiler, *i))
|
||||
{
|
||||
// Parsed the object by another translator; do nothing
|
||||
}
|
||||
else
|
||||
{
|
||||
processNode(compiler, *i);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
errorUnexpectedToken(compiler, *i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
51
extensions/Particle3D/PU/CCPUBehaviourTranslator.h
Normal file
51
extensions/Particle3D/PU/CCPUBehaviourTranslator.h
Normal file
@@ -0,0 +1,51 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __CC_PU_PARTICLE_3D_BEHAVIOUR_TRANSLATOR_H__
|
||||
#define __CC_PU_PARTICLE_3D_BEHAVIOUR_TRANSLATOR_H__
|
||||
|
||||
#include "extensions/Particle3D/PU/CCPUScriptTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUScriptCompiler.h"
|
||||
#include "extensions/Particle3D/PU/CCPUBehaviour.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class PUBehaviourTranslator : public PUScriptTranslator
|
||||
{
|
||||
protected:
|
||||
|
||||
PUBehaviour* _behaviour;
|
||||
|
||||
public:
|
||||
PUBehaviourTranslator();
|
||||
virtual ~PUBehaviourTranslator(){};
|
||||
virtual void translate(PUScriptCompiler* compiler, PUAbstractNode *node);
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif /* defined(__cocos2d_libs__CCParticle3DAffectorTranslator__) */
|
||||
|
||||
824
extensions/Particle3D/PU/CCPUBillboardChain.cpp
Normal file
824
extensions/Particle3D/PU/CCPUBillboardChain.cpp
Normal file
@@ -0,0 +1,824 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#include "extensions/Particle3D/PU/CCPUBillboardChain.h"
|
||||
#include <stddef.h> // offsetof
|
||||
#include "base/ccTypes.h"
|
||||
#include "extensions/Particle3D/PU/CCPUParticleSystem3D.h"
|
||||
#include "base/CCDirector.h"
|
||||
#include "renderer/ccShaders.h"
|
||||
#include "renderer/CCMeshCommand.h"
|
||||
#include "renderer/CCRenderer.h"
|
||||
#include "renderer/CCTextureCache.h"
|
||||
#include "renderer/backend/Types.h"
|
||||
#include "renderer/backend/Buffer.h"
|
||||
#include "renderer/backend/Device.h"
|
||||
#include "2d/CCCamera.h"
|
||||
#include "3d/CCSprite3D.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
const size_t PUBillboardChain::SEGMENT_EMPTY = std::numeric_limits<size_t>::max();
|
||||
//-----------------------------------------------------------------------
|
||||
PUBillboardChain::Element::Element()
|
||||
{
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
PUBillboardChain::Element::Element(const Vec3 &pos,
|
||||
float w,
|
||||
float tex,
|
||||
const Vec4 &col,
|
||||
const Quaternion &ori) :
|
||||
position(pos),
|
||||
width(w),
|
||||
texCoord(tex),
|
||||
color(col),
|
||||
orientation(ori)
|
||||
{
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
PUBillboardChain::PUBillboardChain(const std::string& /*name*/, const std::string &texFile, size_t maxElements,
|
||||
size_t numberOfChains, bool useTextureCoords, bool useColours, bool dynamic)
|
||||
:_maxElementsPerChain(maxElements),
|
||||
_chainCount(numberOfChains),
|
||||
_useTexCoords(useTextureCoords),
|
||||
_useVertexColour(useColours),
|
||||
_dynamic(dynamic),
|
||||
_vertexDeclDirty(true),
|
||||
_buffersNeedRecreating(true),
|
||||
_boundsDirty(true),
|
||||
_indexContentDirty(true),
|
||||
_vertexContentDirty(true),
|
||||
_texCoordDir(TCD_U),
|
||||
_faceCamera(true),
|
||||
_normalBase(Vec3::UNIT_X),
|
||||
_texture(nullptr),
|
||||
_programState(nullptr),
|
||||
_indexBuffer(nullptr),
|
||||
_vertexBuffer(nullptr),
|
||||
_texFile(texFile)
|
||||
{
|
||||
|
||||
_stateBlock.setCullFace(false);
|
||||
_stateBlock.setCullFaceSide(backend::CullMode::BACK);
|
||||
_stateBlock.setDepthTest(false);
|
||||
_stateBlock.setDepthWrite(false);
|
||||
_stateBlock.setBlend(true);
|
||||
|
||||
_otherTexCoordRange[0] = 0.0f;
|
||||
_otherTexCoordRange[1] = 1.0f;
|
||||
|
||||
setupChainContainers();
|
||||
|
||||
init(texFile);
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
PUBillboardChain::~PUBillboardChain()
|
||||
{
|
||||
//CC_SAFE_RELEASE(_texture);
|
||||
CC_SAFE_RELEASE(_programState);
|
||||
CC_SAFE_RELEASE(_vertexBuffer);
|
||||
CC_SAFE_RELEASE(_indexBuffer);
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUBillboardChain::setupChainContainers()
|
||||
{
|
||||
// Allocate enough space for everything
|
||||
_chainElementList.resize(_chainCount * _maxElementsPerChain);
|
||||
//_vertexData->vertexCount = _chainElementList.size() * 2;
|
||||
|
||||
// Configure chains
|
||||
_chainSegmentList.resize(_chainCount);
|
||||
for (size_t i = 0; i < _chainCount; ++i)
|
||||
{
|
||||
ChainSegment& seg = _chainSegmentList[i];
|
||||
seg.start = i * _maxElementsPerChain;
|
||||
seg.tail = seg.head = SEGMENT_EMPTY;
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUBillboardChain::setupVertexDeclaration()
|
||||
{
|
||||
//if (_vertexDeclDirty)
|
||||
//{
|
||||
// VertexDeclaration* decl = _vertexData->vertexDeclaration;
|
||||
// decl->removeAllElements();
|
||||
|
||||
// size_t offset = 0;
|
||||
// // Add a description for the buffer of the positions of the vertices
|
||||
// decl->addElement(0, offset, VET_FLOAT3, VES_POSITION);
|
||||
// offset += VertexElement::getTypeSize(VET_FLOAT3);
|
||||
|
||||
// if (_useVertexColour)
|
||||
// {
|
||||
// decl->addElement(0, offset, VET_COLOUR, VES_DIFFUSE);
|
||||
// offset += VertexElement::getTypeSize(VET_COLOUR);
|
||||
// }
|
||||
|
||||
// if (_useTexCoords)
|
||||
// {
|
||||
// decl->addElement(0, offset, VET_FLOAT2, VES_TEXTURE_COORDINATES);
|
||||
// }
|
||||
|
||||
// if (!_useTexCoords && !_useVertexColour)
|
||||
// {
|
||||
// LogManager::getSingleton().logMessage(
|
||||
// "Error - BillboardChain '" + mName + "' is using neither "
|
||||
// "texture coordinates or vertex colours; it will not be "
|
||||
// "visible on some rendering APIs so you should change this "
|
||||
// "so you use one or the other.");
|
||||
// }
|
||||
// _vertexDeclDirty = false;
|
||||
//}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUBillboardChain::setupBuffers()
|
||||
{
|
||||
//setupVertexDeclaration();
|
||||
if (_buffersNeedRecreating)
|
||||
{
|
||||
CC_SAFE_RELEASE_NULL(_vertexBuffer);
|
||||
CC_SAFE_RELEASE_NULL(_indexBuffer);
|
||||
|
||||
size_t stride = sizeof(VertexInfo);
|
||||
_vertexBuffer = backend::Device::getInstance()->newBuffer(stride * _chainElementList.size() * 2, backend::BufferType::VERTEX, backend::BufferUsage::DYNAMIC);
|
||||
VertexInfo vi = {Vec3(0.0f, 0.0f, 0.0f), Vec2(0.0f, 0.0f), Vec4::ONE};
|
||||
_vertices.resize(_chainElementList.size() * 2, vi);
|
||||
|
||||
_indexBuffer = backend::Device::getInstance()->newBuffer(_chainCount * _maxElementsPerChain * 6 * sizeof(uint16_t), backend::BufferType::VERTEX, backend::BufferUsage::DYNAMIC);
|
||||
|
||||
_indices.resize(_chainCount * _maxElementsPerChain * 6, 0);
|
||||
|
||||
//// Create the vertex buffer (always dynamic due to the camera adjust)
|
||||
//HardwareVertexBufferSharedPtr pBuffer =
|
||||
// HardwareBufferManager::getSingleton().createVertexBuffer(
|
||||
// _vertexData->vertexDeclaration->getVertexSize(0),
|
||||
// _vertexData->vertexCount,
|
||||
// HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY_DISCARDABLE);
|
||||
|
||||
//// (re)Bind the buffer
|
||||
//// Any existing buffer will lose its reference count and be destroyed
|
||||
//_vertexData->vertexBufferBinding->setBinding(0, pBuffer);
|
||||
|
||||
//_indexData->indexBuffer =
|
||||
// HardwareBufferManager::getSingleton().createIndexBuffer(
|
||||
// HardwareIndexBuffer::IT_16BIT,
|
||||
// _chainCount * _maxElementsPerChain * 6, // max we can use
|
||||
// _dynamic? HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY : HardwareBuffer::HBU_STATIC_WRITE_ONLY);
|
||||
//// NB we don't set the indexCount on IndexData here since we will
|
||||
//// probably use less than the maximum number of indices
|
||||
|
||||
_buffersNeedRecreating = false;
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUBillboardChain::setMaxChainElements(size_t maxElements)
|
||||
{
|
||||
_maxElementsPerChain = maxElements;
|
||||
setupChainContainers();
|
||||
_buffersNeedRecreating = _indexContentDirty = _vertexContentDirty = true;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUBillboardChain::setNumberOfChains(size_t numChains)
|
||||
{
|
||||
_chainCount = numChains;
|
||||
setupChainContainers();
|
||||
_buffersNeedRecreating = _indexContentDirty = _vertexContentDirty = true;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUBillboardChain::setUseTextureCoords(bool use)
|
||||
{
|
||||
_useTexCoords = use;
|
||||
_vertexDeclDirty = _buffersNeedRecreating = true;
|
||||
_indexContentDirty = _vertexContentDirty = true;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUBillboardChain::setTextureCoordDirection(PUBillboardChain::TexCoordDirection dir)
|
||||
{
|
||||
_texCoordDir = dir;
|
||||
_vertexContentDirty = true;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUBillboardChain::setOtherTextureCoordRange(float start, float end)
|
||||
{
|
||||
_otherTexCoordRange[0] = start;
|
||||
_otherTexCoordRange[1] = end;
|
||||
_vertexContentDirty = true;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUBillboardChain::setUseVertexColours(bool use)
|
||||
{
|
||||
_useVertexColour = use;
|
||||
_vertexDeclDirty = _buffersNeedRecreating = true;
|
||||
_indexContentDirty = _vertexContentDirty = true;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUBillboardChain::setDynamic(bool dyn)
|
||||
{
|
||||
_dynamic = dyn;
|
||||
_buffersNeedRecreating = _indexContentDirty = _vertexContentDirty = true;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUBillboardChain::addChainElement(size_t chainIndex,
|
||||
const PUBillboardChain::Element& dtls)
|
||||
{
|
||||
CCASSERT(chainIndex < _chainCount, "chainIndex out of bounds");
|
||||
ChainSegment& seg = _chainSegmentList[chainIndex];
|
||||
if (seg.head == SEGMENT_EMPTY)
|
||||
{
|
||||
// Tail starts at end, head grows backwards
|
||||
seg.tail = _maxElementsPerChain - 1;
|
||||
seg.head = seg.tail;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (seg.head == 0)
|
||||
{
|
||||
// Wrap backwards
|
||||
seg.head = _maxElementsPerChain - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Just step backward
|
||||
--seg.head;
|
||||
}
|
||||
// Run out of elements?
|
||||
if (seg.head == seg.tail)
|
||||
{
|
||||
// Move tail backwards too, losing the end of the segment and re-using
|
||||
// it in the head
|
||||
if (seg.tail == 0)
|
||||
seg.tail = _maxElementsPerChain - 1;
|
||||
else
|
||||
--seg.tail;
|
||||
}
|
||||
}
|
||||
|
||||
// Set the details
|
||||
_chainElementList[seg.start + seg.head] = dtls;
|
||||
|
||||
_vertexContentDirty = true;
|
||||
_indexContentDirty = true;
|
||||
_boundsDirty = true;
|
||||
//// tell parent node to update bounds
|
||||
//if (mParentNode)
|
||||
// mParentNode->needUpdate();
|
||||
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUBillboardChain::removeChainElement(size_t chainIndex)
|
||||
{
|
||||
CCASSERT(chainIndex < _chainCount, "chainIndex out of bounds");
|
||||
ChainSegment& seg = _chainSegmentList[chainIndex];
|
||||
if (seg.head == SEGMENT_EMPTY)
|
||||
return; // do nothing, nothing to remove
|
||||
|
||||
|
||||
if (seg.tail == seg.head)
|
||||
{
|
||||
// last item
|
||||
seg.head = seg.tail = SEGMENT_EMPTY;
|
||||
}
|
||||
else if (seg.tail == 0)
|
||||
{
|
||||
seg.tail = _maxElementsPerChain - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
--seg.tail;
|
||||
}
|
||||
|
||||
// we removed an entry so indexes need updating
|
||||
_vertexContentDirty = true;
|
||||
_indexContentDirty = true;
|
||||
_boundsDirty = true;
|
||||
//// tell parent node to update bounds
|
||||
//if (mParentNode)
|
||||
// mParentNode->needUpdate();
|
||||
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUBillboardChain::clearChain(size_t chainIndex)
|
||||
{
|
||||
CCASSERT(chainIndex < _chainCount, "chainIndex out of bounds");
|
||||
ChainSegment& seg = _chainSegmentList[chainIndex];
|
||||
|
||||
// Just reset head & tail
|
||||
seg.tail = seg.head = SEGMENT_EMPTY;
|
||||
|
||||
// we removed an entry so indexes need updating
|
||||
_vertexContentDirty = true;
|
||||
_indexContentDirty = true;
|
||||
_boundsDirty = true;
|
||||
//// tell parent node to update bounds
|
||||
//if (mParentNode)
|
||||
// mParentNode->needUpdate();
|
||||
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUBillboardChain::clearAllChains()
|
||||
{
|
||||
for (size_t i = 0; i < _chainCount; ++i)
|
||||
{
|
||||
clearChain(i);
|
||||
}
|
||||
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUBillboardChain::setFaceCamera( bool faceCamera, const Vec3 &normalVector )
|
||||
{
|
||||
_faceCamera = faceCamera;
|
||||
_normalBase = normalVector;
|
||||
_normalBase.normalize();
|
||||
_vertexContentDirty = true;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUBillboardChain::updateChainElement(size_t chainIndex, size_t elementIndex,
|
||||
const PUBillboardChain::Element& dtls)
|
||||
{
|
||||
CCASSERT(chainIndex < _chainCount, "chainIndex out of bounds");
|
||||
ChainSegment& seg = _chainSegmentList[chainIndex];
|
||||
CCASSERT(seg.head != SEGMENT_EMPTY, "Chain segment is empty");
|
||||
|
||||
size_t idx = seg.head + elementIndex;
|
||||
// adjust for the edge and start
|
||||
idx = (idx % _maxElementsPerChain) + seg.start;
|
||||
|
||||
_chainElementList[idx] = dtls;
|
||||
|
||||
_vertexContentDirty = true;
|
||||
_boundsDirty = true;
|
||||
|
||||
//// tell parent node to update bounds
|
||||
//if (mParentNode)
|
||||
// mParentNode->needUpdate();
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
const PUBillboardChain::Element&
|
||||
PUBillboardChain::getChainElement(size_t chainIndex, size_t elementIndex) const
|
||||
{
|
||||
CCASSERT(chainIndex < _chainCount, "chainIndex out of bounds");
|
||||
const ChainSegment& seg = _chainSegmentList[chainIndex];
|
||||
|
||||
size_t idx = seg.head + elementIndex;
|
||||
// adjust for the edge and start
|
||||
idx = (idx % _maxElementsPerChain) + seg.start;
|
||||
|
||||
return _chainElementList[idx];
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
size_t PUBillboardChain::getNumChainElements(size_t chainIndex) const
|
||||
{
|
||||
CCASSERT(chainIndex < _chainCount, "chainIndex out of bounds");
|
||||
const ChainSegment& seg = _chainSegmentList[chainIndex];
|
||||
|
||||
if( seg.tail < seg.head )
|
||||
{
|
||||
return seg.tail - seg.head + _maxElementsPerChain + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return seg.tail - seg.head + 1;
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUBillboardChain::updateVertexBuffer(const Mat4 &camMat)
|
||||
{
|
||||
setupBuffers();
|
||||
|
||||
// The contents of the vertex buffer are correct if they are not dirty
|
||||
// and the camera used to build the vertex buffer is still the current
|
||||
// camera.
|
||||
if (!_vertexContentDirty)
|
||||
return;
|
||||
|
||||
VertexInfo vi = {Vec3(0.0f, 0.0f, 0.0f), Vec2(0.0f, 0.0f), Vec4::ONE};
|
||||
_vertices.assign(_vertices.size(), vi);
|
||||
//HardwareVertexBufferSharedPtr pBuffer =
|
||||
// _vertexData->vertexBufferBinding->getBuffer(0);
|
||||
//void* pBufferStart = pBuffer->lock(HardwareBuffer::HBL_DISCARD);
|
||||
|
||||
//const Vector3& camPos = cam->getDerivedPosition();
|
||||
//Vector3 eyePos = mParentNode->_getDerivedOrientation().Inverse() *
|
||||
// (camPos - mParentNode->_getDerivedPosition()) / mParentNode->_getDerivedScale();
|
||||
|
||||
Vec3 eyePos(camMat.m[12], camMat.m[13], camMat.m[14]);
|
||||
|
||||
Vec3 chainTangent;
|
||||
for (ChainSegmentList::iterator segi = _chainSegmentList.begin();
|
||||
segi != _chainSegmentList.end(); ++segi)
|
||||
{
|
||||
ChainSegment& seg = *segi;
|
||||
|
||||
// Skip 0 or 1 element segment counts
|
||||
if (seg.head != SEGMENT_EMPTY && seg.head != seg.tail)
|
||||
{
|
||||
size_t laste = seg.head;
|
||||
for (size_t e = seg.head; ; ++e) // until break
|
||||
{
|
||||
// Wrap forwards
|
||||
if (e == _maxElementsPerChain)
|
||||
e = 0;
|
||||
|
||||
Element& elem = _chainElementList[e + seg.start];
|
||||
CCASSERT (((e + seg.start) * 2) < 65536, "Too many elements!");
|
||||
unsigned short vertexIndex = static_cast<unsigned short>((e + seg.start) * 2);
|
||||
//// Determine base pointer to vertex #1
|
||||
//void* pBase = static_cast<void*>(
|
||||
// static_cast<char*>(pBufferStart) +
|
||||
// pBuffer->getVertexSize() * baseIdx);
|
||||
|
||||
// Get index of next item
|
||||
size_t nexte = e + 1;
|
||||
if (nexte == _maxElementsPerChain)
|
||||
nexte = 0;
|
||||
|
||||
if (e == seg.head)
|
||||
{
|
||||
// No laste, use next item
|
||||
chainTangent = _chainElementList[nexte + seg.start].position - elem.position;
|
||||
}
|
||||
else if (e == seg.tail)
|
||||
{
|
||||
// No nexte, use only last item
|
||||
chainTangent = elem.position - _chainElementList[laste + seg.start].position;
|
||||
}
|
||||
else
|
||||
{
|
||||
// A mid position, use tangent across both prev and next
|
||||
chainTangent = _chainElementList[nexte + seg.start].position - _chainElementList[laste + seg.start].position;
|
||||
|
||||
}
|
||||
|
||||
Vec3 vP1ToEye;
|
||||
|
||||
//if( _faceCamera )
|
||||
vP1ToEye = eyePos - elem.position;
|
||||
//else
|
||||
// vP1ToEye = elem.orientation * _normalBase;
|
||||
|
||||
Vec3 vPerpendicular;
|
||||
Vec3::cross(chainTangent, vP1ToEye, &vPerpendicular);
|
||||
vPerpendicular.normalize();
|
||||
vPerpendicular *= (elem.width * 0.5f);
|
||||
|
||||
Vec3 pos0 = elem.position - vPerpendicular;
|
||||
Vec3 pos1 = elem.position + vPerpendicular;
|
||||
|
||||
//float* pFloat = static_cast<float*>(pBase);
|
||||
//// pos1
|
||||
//*pFloat++ = pos0.x;
|
||||
//*pFloat++ = pos0.y;
|
||||
//*pFloat++ = pos0.z;
|
||||
_vertices[vertexIndex + 0].position = pos0;
|
||||
|
||||
|
||||
//pBase = static_cast<void*>(pFloat);
|
||||
|
||||
if (_useVertexColour)
|
||||
{
|
||||
//RGBA* pCol = static_cast<RGBA*>(pBase);
|
||||
//Root::getSingleton().convertColourValue(elem.colour, pCol);
|
||||
//pCol++;
|
||||
//pBase = static_cast<void*>(pCol);
|
||||
_vertices[vertexIndex + 0].color = elem.color;
|
||||
}
|
||||
|
||||
if (_useTexCoords)
|
||||
{
|
||||
//pFloat = static_cast<float*>(pBase);
|
||||
if (_texCoordDir == TCD_U)
|
||||
{
|
||||
//*pFloat++ = elem.texCoord;
|
||||
//*pFloat++ = _otherTexCoordRange[0];
|
||||
_vertices[vertexIndex + 0].uv.x = elem.texCoord;
|
||||
_vertices[vertexIndex + 0].uv.y = _otherTexCoordRange[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
//*pFloat++ = _otherTexCoordRange[0];
|
||||
//*pFloat++ = elem.texCoord;
|
||||
_vertices[vertexIndex + 0].uv.x = _otherTexCoordRange[0];
|
||||
_vertices[vertexIndex + 0].uv.y = elem.texCoord;
|
||||
}
|
||||
//pBase = static_cast<void*>(pFloat);
|
||||
}
|
||||
|
||||
// pos2
|
||||
//pFloat = static_cast<float*>(pBase);
|
||||
//*pFloat++ = pos1.x;
|
||||
//*pFloat++ = pos1.y;
|
||||
//*pFloat++ = pos1.z;
|
||||
//pBase = static_cast<void*>(pFloat);
|
||||
_vertices[vertexIndex + 1].position = pos1;
|
||||
|
||||
if (_useVertexColour)
|
||||
{
|
||||
//RGBA* pCol = static_cast<RGBA*>(pBase);
|
||||
//Root::getSingleton().convertColourValue(elem.colour, pCol);
|
||||
//pCol++;
|
||||
//pBase = static_cast<void*>(pCol);
|
||||
_vertices[vertexIndex + 1].color = elem.color;
|
||||
}
|
||||
|
||||
if (_useTexCoords)
|
||||
{
|
||||
//pFloat = static_cast<float*>(pBase);
|
||||
if (_texCoordDir == TCD_U)
|
||||
{
|
||||
//*pFloat++ = elem.texCoord;
|
||||
//*pFloat++ = _otherTexCoordRange[1];
|
||||
_vertices[vertexIndex + 1].uv.x = elem.texCoord;
|
||||
_vertices[vertexIndex + 1].uv.y = _otherTexCoordRange[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
//*pFloat++ = _otherTexCoordRange[1];
|
||||
//*pFloat++ = elem.texCoord;
|
||||
_vertices[vertexIndex + 1].uv.x = _otherTexCoordRange[1];
|
||||
_vertices[vertexIndex + 1].uv.y = elem.texCoord;
|
||||
}
|
||||
}
|
||||
|
||||
if (e == seg.tail)
|
||||
break; // last one
|
||||
|
||||
laste = e;
|
||||
//vertexIndex += 2;
|
||||
} // element
|
||||
} // segment valid?
|
||||
|
||||
} // each segment
|
||||
|
||||
_vertexBuffer->updateData(&_vertices[0], sizeof(_vertices[0]) * _vertices.size());
|
||||
//pBuffer->unlock();
|
||||
//_vertexCameraUsed = cam;
|
||||
_vertexContentDirty = false;
|
||||
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUBillboardChain::updateIndexBuffer()
|
||||
{
|
||||
|
||||
setupBuffers();
|
||||
if (_indexContentDirty)
|
||||
{
|
||||
|
||||
//uint16* pShort = static_cast<uint16*>(
|
||||
// _indexData->indexBuffer->lock(HardwareBuffer::HBL_DISCARD));
|
||||
//_indexData->indexCount = 0;
|
||||
// indexes
|
||||
unsigned short index = 0;
|
||||
for (ChainSegmentList::iterator segi = _chainSegmentList.begin();
|
||||
segi != _chainSegmentList.end(); ++segi)
|
||||
{
|
||||
ChainSegment& seg = *segi;
|
||||
|
||||
// Skip 0 or 1 element segment counts
|
||||
if (seg.head != SEGMENT_EMPTY && seg.head != seg.tail)
|
||||
{
|
||||
// Start from head + 1 since it's only useful in pairs
|
||||
size_t laste = seg.head;
|
||||
while(1) // until break
|
||||
{
|
||||
size_t e = laste + 1;
|
||||
// Wrap forwards
|
||||
if (e == _maxElementsPerChain)
|
||||
e = 0;
|
||||
// indexes of this element are (e * 2) and (e * 2) + 1
|
||||
// indexes of the last element are the same, -2
|
||||
CCASSERT (((e + seg.start) * 2) < 65536, "Too many elements!");
|
||||
unsigned short baseIdx = static_cast<unsigned short>((e + seg.start) * 2);
|
||||
unsigned short lastBaseIdx = static_cast<unsigned short>((laste + seg.start) * 2);
|
||||
|
||||
|
||||
//*pShort++ = lastBaseIdx;
|
||||
//*pShort++ = lastBaseIdx + 1;
|
||||
//*pShort++ = baseIdx;
|
||||
//*pShort++ = lastBaseIdx + 1;
|
||||
//*pShort++ = baseIdx + 1;
|
||||
//*pShort++ = baseIdx;
|
||||
//_indexData->indexCount += 6;
|
||||
|
||||
_indices[index++] = lastBaseIdx;
|
||||
_indices[index++] = lastBaseIdx + 1;
|
||||
_indices[index++] = baseIdx;
|
||||
_indices[index++] = lastBaseIdx + 1;
|
||||
_indices[index++] = baseIdx + 1;
|
||||
_indices[index++] = baseIdx;
|
||||
|
||||
if (e == seg.tail)
|
||||
break; // last one
|
||||
|
||||
laste = e;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
_indexBuffer->updateData(&_indices[0], sizeof(_indices[0]) * _indices.size());
|
||||
//_indexData->indexBuffer->unlock();
|
||||
_indexContentDirty = false;
|
||||
}
|
||||
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUBillboardChain::init( const std::string &texFile )
|
||||
{
|
||||
CC_SAFE_RELEASE_NULL(_programState);
|
||||
|
||||
if (!texFile.empty())
|
||||
{
|
||||
auto tex = Director::getInstance()->getTextureCache()->addImage(texFile);
|
||||
if (tex)
|
||||
{
|
||||
_texture = tex;
|
||||
auto* program = backend::Program::getBuiltinProgram(backend::ProgramType::PARTICLE_TEXTURE_3D);
|
||||
_programState = new backend::ProgramState(program);
|
||||
}
|
||||
}
|
||||
|
||||
if(!_programState)
|
||||
{
|
||||
auto* program = backend::Program::getBuiltinProgram(backend::ProgramType::PARTICLE_COLOR_3D);
|
||||
_programState = new backend::ProgramState(program);
|
||||
}
|
||||
|
||||
auto &pipelineDescriptor = _meshCommand.getPipelineDescriptor();
|
||||
pipelineDescriptor.programState = _programState;
|
||||
auto layout = _programState->getVertexLayout();
|
||||
const auto& attributeInfo = _programState->getProgram()->getActiveAttributes();
|
||||
auto iter = attributeInfo.find("a_position");
|
||||
if(iter != attributeInfo.end())
|
||||
{
|
||||
layout->setAttribute("a_position", iter->second.location, backend::VertexFormat::FLOAT3, offsetof(VertexInfo, position), false);
|
||||
}
|
||||
iter = attributeInfo.find("a_texCoord");
|
||||
if(iter != attributeInfo.end())
|
||||
{
|
||||
layout->setAttribute("a_texCoord", iter->second.location, backend::VertexFormat::FLOAT2, offsetof(VertexInfo, uv), false);
|
||||
}
|
||||
iter = attributeInfo.find("a_color");
|
||||
if(iter != attributeInfo.end())
|
||||
{
|
||||
layout->setAttribute("a_color", iter->second.location, backend::VertexFormat::FLOAT4, offsetof(VertexInfo, color), false);
|
||||
}
|
||||
layout->setLayout(sizeof(VertexInfo));
|
||||
|
||||
_locColor = _programState->getUniformLocation("u_color");
|
||||
_locPMatrix = _programState->getUniformLocation("u_PMatrix");
|
||||
_locTexture = _programState->getUniformLocation("u_texture");
|
||||
|
||||
_meshCommand.setTransparent(true);
|
||||
_meshCommand.setSkipBatching(true);
|
||||
|
||||
_stateBlock.setDepthTest(true);
|
||||
_stateBlock.setDepthWrite(false);
|
||||
_stateBlock.setCullFaceSide(backend::CullMode::BACK);
|
||||
_stateBlock.setCullFace(true);
|
||||
|
||||
_meshCommand.setBeforeCallback(CC_CALLBACK_0(PUBillboardChain::onBeforeDraw, this));
|
||||
_meshCommand.setAfterCallback(CC_CALLBACK_0(PUBillboardChain::onAfterDraw, this));
|
||||
}
|
||||
|
||||
void PUBillboardChain::render( Renderer* renderer, const Mat4 &transform, ParticleSystem3D* particleSystem )
|
||||
{
|
||||
auto camera = Camera::getVisitingCamera();
|
||||
auto cameraMat = camera->getNodeToWorldTransform();
|
||||
|
||||
if (!_chainSegmentList.empty())
|
||||
{
|
||||
updateVertexBuffer(cameraMat);
|
||||
updateIndexBuffer();
|
||||
|
||||
_meshCommand.setVertexBuffer(_vertexBuffer);
|
||||
_meshCommand.setIndexBuffer(_indexBuffer, MeshCommand::IndexFormat::U_SHORT);
|
||||
_meshCommand.setIndexDrawInfo(0, _indices.size());
|
||||
|
||||
if (!_vertices.empty() && !_indices.empty())
|
||||
{
|
||||
_meshCommand.init(0.0);
|
||||
_stateBlock.setBlendFunc(particleSystem->getBlendFunc());
|
||||
|
||||
auto &projectionMatrix = Director::getInstance()->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
|
||||
_programState->setUniform(_locPMatrix, &projectionMatrix.m, sizeof(projectionMatrix.m));
|
||||
|
||||
if (_texture)
|
||||
{
|
||||
_programState->setTexture(_locTexture, 0, _texture->getBackendTexture());
|
||||
}
|
||||
|
||||
auto uColor = Vec4(1, 1, 1, 1);
|
||||
_programState->setUniform(_locColor, &uColor, sizeof(uColor));
|
||||
|
||||
renderer->addCommand(&_meshCommand);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PUBillboardChain::setDepthTest( bool isDepthTest )
|
||||
{
|
||||
_stateBlock.setDepthTest(isDepthTest);
|
||||
}
|
||||
|
||||
void PUBillboardChain::setDepthWrite( bool isDepthWrite )
|
||||
{
|
||||
_stateBlock.setDepthWrite(isDepthWrite);
|
||||
}
|
||||
|
||||
void PUBillboardChain::setBlendFunc(const BlendFunc& blendFunc)
|
||||
{
|
||||
_stateBlock.setBlendFunc(blendFunc);
|
||||
}
|
||||
|
||||
void PUBillboardChain::onBeforeDraw()
|
||||
{
|
||||
auto *renderer = Director::getInstance()->getRenderer();
|
||||
auto &pipelineDescriptor = _meshCommand.getPipelineDescriptor();
|
||||
_rendererDepthTestEnabled = renderer->getDepthTest();
|
||||
_rendererDepthCmpFunc = renderer->getDepthCompareFunction();
|
||||
_rendererCullMode = renderer->getCullMode();
|
||||
_rendererDepthWrite = renderer->getDepthWrite();
|
||||
_rendererWinding = renderer->getWinding();
|
||||
_stateBlock.bind(&pipelineDescriptor);
|
||||
renderer->setDepthTest(true);
|
||||
}
|
||||
|
||||
void PUBillboardChain::onAfterDraw()
|
||||
{
|
||||
auto *renderer = Director::getInstance()->getRenderer();
|
||||
renderer->setDepthTest(_rendererDepthTestEnabled);
|
||||
renderer->setDepthCompareFunction(_rendererDepthCmpFunc);
|
||||
renderer->setCullMode(_rendererCullMode);
|
||||
renderer->setDepthWrite(_rendererDepthWrite);
|
||||
renderer->setWinding(_rendererWinding);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
//void PUBillboardChain::_updateRenderQueue(RenderQueue* queue)
|
||||
//{
|
||||
// updateIndexBuffer();
|
||||
//
|
||||
// if (mIndexData->indexCount > 0)
|
||||
// {
|
||||
// if (mRenderQueuePrioritySet)
|
||||
// queue->addRenderable(this, mRenderQueueID, mRenderQueuePriority);
|
||||
// else if (mRenderQueueIDSet)
|
||||
// queue->addRenderable(this, mRenderQueueID);
|
||||
// else
|
||||
// queue->addRenderable(this);
|
||||
// }
|
||||
//
|
||||
//}
|
||||
//-----------------------------------------------------------------------
|
||||
//void PUBillboardChain::getRenderOperation(RenderOperation& op)
|
||||
//{
|
||||
// op.indexData = mIndexData;
|
||||
// op.operationType = RenderOperation::OT_TRIANGLE_LIST;
|
||||
// op.srcRenderable = this;
|
||||
// op.useIndexes = true;
|
||||
// op.vertexData = mVertexData;
|
||||
//}
|
||||
//-----------------------------------------------------------------------
|
||||
//bool PUBillboardChain::preRender(SceneManager* sm, RenderSystem* rsys)
|
||||
//{
|
||||
// // Retrieve the current viewport from the scene manager.
|
||||
// // The viewport is only valid during a viewport update.
|
||||
// Viewport *currentViewport = sm->getCurrentViewport();
|
||||
// if( !currentViewport )
|
||||
// return false;
|
||||
//
|
||||
// updateVertexBuffer(currentViewport->getCamera());
|
||||
// return true;
|
||||
//}
|
||||
//-----------------------------------------------------------------------
|
||||
//void PUBillboardChain::getWorldTransforms(Matrix4* xform) const
|
||||
//{
|
||||
// *xform = _getParentNodeFullTransform();
|
||||
//}
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
NS_CC_END
|
||||
351
extensions/Particle3D/PU/CCPUBillboardChain.h
Normal file
351
extensions/Particle3D/PU/CCPUBillboardChain.h
Normal file
@@ -0,0 +1,351 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include "renderer/CCRenderState.h"
|
||||
#include "renderer/CCMeshCommand.h"
|
||||
#include "renderer/CCCallbackCommand.h"
|
||||
#include "renderer/backend/Buffer.h"
|
||||
#include "base/CCRef.h"
|
||||
#include "math/CCMath.h"
|
||||
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class MeshCommand;
|
||||
class GLProgramState;
|
||||
class IndexBuffer;
|
||||
class VertexBuffer;
|
||||
class Texture2D;
|
||||
class ParticleSystem3D;
|
||||
class Renderer;
|
||||
|
||||
class PUBillboardChain
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
/** Contains the data of an element of the BillboardChain.
|
||||
*/
|
||||
class Element
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
Element();
|
||||
|
||||
Element(const Vec3& position,
|
||||
float width,
|
||||
float texCoord,
|
||||
const Vec4& colour,
|
||||
const Quaternion& orientation);
|
||||
|
||||
Vec3 position;
|
||||
float width;
|
||||
/// U or V texture coord depending on options
|
||||
float texCoord;
|
||||
Vec4 color;
|
||||
|
||||
//Only used when mFaceCamera == false
|
||||
Quaternion orientation;
|
||||
};
|
||||
typedef std::vector<Element> ElementList;
|
||||
|
||||
/** Constructor
|
||||
@param name The name to give this object
|
||||
@param maxElements The maximum number of elements per chain
|
||||
@param numberOfChains The number of separate chain segments contained in this object
|
||||
@param useTextureCoords If true, use texture coordinates from the chain elements
|
||||
@param useVertexColours If true, use vertex colours from the chain elements
|
||||
@param dynamic If true, buffers are created with the intention of being updated
|
||||
*/
|
||||
PUBillboardChain(const std::string& name, const std::string& texFile = "", size_t maxElements = 20, size_t numberOfChains = 1,
|
||||
bool useTextureCoords = true, bool useColours = true, bool dynamic = true);
|
||||
/// destructor
|
||||
virtual ~PUBillboardChain();
|
||||
|
||||
/** Set the maximum number of chain elements per chain
|
||||
*/
|
||||
virtual void setMaxChainElements(size_t maxElements);
|
||||
/** Get the maximum number of chain elements per chain
|
||||
*/
|
||||
virtual size_t getMaxChainElements() const { return _maxElementsPerChain; }
|
||||
/** Set the number of chain segments (this class can render multiple chains
|
||||
at once using the same material).
|
||||
*/
|
||||
virtual void setNumberOfChains(size_t numChains);
|
||||
/** Get the number of chain segments (this class can render multiple chains
|
||||
at once using the same material).
|
||||
*/
|
||||
virtual size_t getNumberOfChains() const { return _chainCount; }
|
||||
|
||||
/** Sets whether texture coordinate information should be included in the
|
||||
final buffers generated.
|
||||
@note You must use either texture coordinates or vertex colour since the
|
||||
vertices have no normals and without one of these there is no source of
|
||||
colour for the vertices.
|
||||
*/
|
||||
virtual void setUseTextureCoords(bool use);
|
||||
/** Gets whether texture coordinate information should be included in the
|
||||
final buffers generated.
|
||||
*/
|
||||
virtual bool getUseTextureCoords() const { return _useTexCoords; }
|
||||
|
||||
/** The direction in which texture coordinates from elements of the
|
||||
chain are used.
|
||||
*/
|
||||
enum TexCoordDirection
|
||||
{
|
||||
/// Tex coord in elements is treated as the 'u' texture coordinate
|
||||
TCD_U,
|
||||
/// Tex coord in elements is treated as the 'v' texture coordinate
|
||||
TCD_V
|
||||
};
|
||||
/** Sets the direction in which texture coords specified on each element
|
||||
are deemed to run along the length of the chain.
|
||||
@param dir The direction, default is TCD_U.
|
||||
*/
|
||||
virtual void setTextureCoordDirection(TexCoordDirection dir);
|
||||
/** Gets the direction in which texture coords specified on each element
|
||||
are deemed to run.
|
||||
*/
|
||||
virtual TexCoordDirection getTextureCoordDirection() { return _texCoordDir; }
|
||||
|
||||
/** Set the range of the texture coordinates generated across the width of
|
||||
the chain elements.
|
||||
@param start Start coordinate, default 0.0
|
||||
@param end End coordinate, default 1.0
|
||||
*/
|
||||
virtual void setOtherTextureCoordRange(float start, float end);
|
||||
/** Get the range of the texture coordinates generated across the width of
|
||||
the chain elements.
|
||||
*/
|
||||
virtual const float* getOtherTextureCoordRange() const { return _otherTexCoordRange; }
|
||||
|
||||
/** Sets whether vertex colour information should be included in the
|
||||
final buffers generated.
|
||||
@note You must use either texture coordinates or vertex colour since the
|
||||
vertices have no normals and without one of these there is no source of
|
||||
colour for the vertices.
|
||||
*/
|
||||
virtual void setUseVertexColours(bool use);
|
||||
/** Gets whether vertex colour information should be included in the
|
||||
final buffers generated.
|
||||
*/
|
||||
virtual bool getUseVertexColours() const { return _useVertexColour; }
|
||||
|
||||
/** Sets whether or not the buffers created for this object are suitable
|
||||
for dynamic alteration.
|
||||
*/
|
||||
virtual void setDynamic(bool dyn);
|
||||
|
||||
/** Gets whether or not the buffers created for this object are suitable
|
||||
for dynamic alteration.
|
||||
*/
|
||||
virtual bool getDynamic() const { return _dynamic; }
|
||||
|
||||
/** Add an element to the 'head' of a chain.
|
||||
@remarks
|
||||
If this causes the number of elements to exceed the maximum elements
|
||||
per chain, the last element in the chain (the 'tail') will be removed
|
||||
to allow the additional element to be added.
|
||||
@param chainIndex The index of the chain
|
||||
@param billboardChainElement The details to add
|
||||
*/
|
||||
virtual void addChainElement(size_t chainIndex,
|
||||
const Element& billboardChainElement);
|
||||
/** Remove an element from the 'tail' of a chain.
|
||||
@param chainIndex The index of the chain
|
||||
*/
|
||||
virtual void removeChainElement(size_t chainIndex);
|
||||
/** Update the details of an existing chain element.
|
||||
@param chainIndex The index of the chain
|
||||
@param elementIndex The element index within the chain, measured from
|
||||
the 'head' of the chain
|
||||
@param billboardChainElement The details to set
|
||||
*/
|
||||
virtual void updateChainElement(size_t chainIndex, size_t elementIndex,
|
||||
const Element& billboardChainElement);
|
||||
/** Get the detail of a chain element.
|
||||
@param chainIndex The index of the chain
|
||||
@param elementIndex The element index within the chain, measured from
|
||||
the 'head' of the chain
|
||||
*/
|
||||
virtual const Element& getChainElement(size_t chainIndex, size_t elementIndex) const;
|
||||
|
||||
/** Returns the number of chain elements. */
|
||||
virtual size_t getNumChainElements(size_t chainIndex) const;
|
||||
|
||||
/** Remove all elements of a given chain (but leave the chain intact). */
|
||||
virtual void clearChain(size_t chainIndex);
|
||||
/** Remove all elements from all chains (but leave the chains themselves intact). */
|
||||
virtual void clearAllChains();
|
||||
|
||||
/** Sets whether the billboard should always be facing the camera or a custom direction
|
||||
set by each point element.
|
||||
@remarks
|
||||
Billboards facing the camera are useful for smoke trails, light beams, etc by
|
||||
simulating a cylinder. However, because of this property, wide trails can cause
|
||||
several artefacts unless the head is properly covered.
|
||||
Therefore, non-camera-facing billboards are much more convenient for leaving big
|
||||
trails of movement from thin objects, for example a sword swing as seen in many
|
||||
fighting games.
|
||||
@param faceCamera True to be always facing the camera (Default value: True)
|
||||
@param normalVector Only used when faceCamera == false. Must be a non-zero vector.
|
||||
This vector is the "point of reference" for each point orientation. For example,
|
||||
if normalVector is Vector3::UNIT_Z, and the point's orientation is an identity
|
||||
matrix, the segment corresponding to that point will be facing towards UNIT_Z
|
||||
This vector is internally normalized.
|
||||
*/
|
||||
void setFaceCamera( bool faceCamera, const Vec3& normalVector=Vec3::UNIT_X );
|
||||
|
||||
void setDepthTest(bool isDepthTest);
|
||||
void setDepthWrite(bool isDepthWrite);
|
||||
void setBlendFunc(const BlendFunc& blendFunc);
|
||||
|
||||
void render(Renderer* renderer, const Mat4& transform, ParticleSystem3D* particleSystem);
|
||||
|
||||
// Overridden members follow
|
||||
//void _updateRenderQueue(RenderQueue*);
|
||||
//void getRenderOperation(RenderOperation&);
|
||||
//virtual bool preRender(SceneManager* sm, RenderSystem* rsys);
|
||||
//void getWorldTransforms(Matrix4*) const;
|
||||
/// @copydoc MovableObject::visitRenderables
|
||||
|
||||
protected:
|
||||
|
||||
/// Setup the STL collections
|
||||
virtual void setupChainContainers();
|
||||
/// Setup vertex declaration
|
||||
virtual void setupVertexDeclaration();
|
||||
// Setup buffers
|
||||
virtual void setupBuffers();
|
||||
/// Update the contents of the vertex buffer
|
||||
virtual void updateVertexBuffer(const Mat4& camMat);
|
||||
/// Update the contents of the index buffer
|
||||
virtual void updateIndexBuffer();
|
||||
|
||||
void init(const std::string& texFile);
|
||||
|
||||
private:
|
||||
|
||||
void onBeforeDraw();
|
||||
|
||||
void onAfterDraw();
|
||||
|
||||
protected:
|
||||
|
||||
/// Maximum length of each chain
|
||||
size_t _maxElementsPerChain;
|
||||
/// Number of chains
|
||||
size_t _chainCount;
|
||||
/// Use texture coords?
|
||||
bool _useTexCoords;
|
||||
/// Use vertex colour?
|
||||
bool _useVertexColour;
|
||||
/// Dynamic use?
|
||||
bool _dynamic;
|
||||
/// Is the vertex declaration dirty?
|
||||
bool _vertexDeclDirty;
|
||||
/// Do the buffers need recreating?
|
||||
bool _buffersNeedRecreating;
|
||||
/// Do the bounds need redefining?
|
||||
mutable bool _boundsDirty;
|
||||
/// Is the index buffer dirty?
|
||||
bool _indexContentDirty;
|
||||
/// Is the vertex buffer dirty?
|
||||
bool _vertexContentDirty;
|
||||
/// Texture coord direction
|
||||
TexCoordDirection _texCoordDir;
|
||||
/// Other texture coord range
|
||||
float _otherTexCoordRange[2];
|
||||
/// When true, the billboards always face the camera
|
||||
bool _faceCamera;
|
||||
/// Used when mFaceCamera == false; determines the billboard's "normal". i.e.
|
||||
/// when the orientation is identity, the billboard is perpendicular to this
|
||||
/// vector
|
||||
Vec3 _normalBase;
|
||||
|
||||
|
||||
/// The list holding the chain elements
|
||||
ElementList _chainElementList;
|
||||
|
||||
/** Simple struct defining a chain segment by referencing a subset of
|
||||
the preallocated buffer (which will be mMaxElementsPerChain * mChainCount
|
||||
long), by it's chain index, and a head and tail value which describe
|
||||
the current chain. The buffer subset wraps at mMaxElementsPerChain
|
||||
so that head and tail can move freely. head and tail are inclusive,
|
||||
when the chain is empty head and tail are filled with high-values.
|
||||
*/
|
||||
struct ChainSegment
|
||||
{
|
||||
/// The start of this chains subset of the buffer
|
||||
size_t start;
|
||||
/// The 'head' of the chain, relative to start
|
||||
size_t head;
|
||||
/// The 'tail' of the chain, relative to start
|
||||
size_t tail;
|
||||
};
|
||||
typedef std::vector<ChainSegment> ChainSegmentList;
|
||||
ChainSegmentList _chainSegmentList;
|
||||
|
||||
/// Chain segment has no elements
|
||||
static const size_t SEGMENT_EMPTY;
|
||||
|
||||
|
||||
struct VertexInfo
|
||||
{
|
||||
Vec3 position;
|
||||
Vec2 uv;
|
||||
Vec4 color;
|
||||
};
|
||||
MeshCommand _meshCommand;
|
||||
RenderState::StateBlock _stateBlock;
|
||||
Texture2D* _texture = nullptr;
|
||||
backend::ProgramState* _programState = nullptr;
|
||||
backend::Buffer* _indexBuffer = nullptr; //index buffer
|
||||
backend::Buffer* _vertexBuffer = nullptr; //vertex buffer
|
||||
|
||||
std::vector<VertexInfo> _vertices;
|
||||
std::vector<uint16_t> _indices;
|
||||
|
||||
std::string _texFile;
|
||||
|
||||
backend::UniformLocation _locColor;
|
||||
backend::UniformLocation _locTexture;
|
||||
backend::UniformLocation _locPMatrix;
|
||||
|
||||
//renderer state cache variables
|
||||
bool _rendererDepthTestEnabled = true;
|
||||
backend::CompareFunction _rendererDepthCmpFunc = backend::CompareFunction::LESS;
|
||||
backend::CullMode _rendererCullMode = backend::CullMode::BACK;
|
||||
backend::Winding _rendererWinding = backend::Winding::COUNTER_CLOCK_WISE;
|
||||
bool _rendererDepthWrite = false;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
300
extensions/Particle3D/PU/CCPUBoxCollider.cpp
Normal file
300
extensions/Particle3D/PU/CCPUBoxCollider.cpp
Normal file
@@ -0,0 +1,300 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCPUBoxCollider.h"
|
||||
#include "extensions/Particle3D/PU/CCPUParticleSystem3D.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
// Constants
|
||||
const float PUBoxCollider::DEFAULT_WIDTH = 100.0f;
|
||||
const float PUBoxCollider::DEFAULT_HEIGHT = 100.0f;
|
||||
const float PUBoxCollider::DEFAULT_DEPTH = 100.0f;
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
PUBoxCollider::PUBoxCollider() :
|
||||
PUBaseCollider(),
|
||||
_width(DEFAULT_WIDTH),
|
||||
_height(DEFAULT_HEIGHT),
|
||||
_depth(DEFAULT_DEPTH),
|
||||
_xmin(0.0f),
|
||||
_xmax(0.0f),
|
||||
_ymin(0.0f),
|
||||
_ymax(0.0f),
|
||||
_zmin(0.0f),
|
||||
_zmax(0.0f),
|
||||
_innerCollision(false)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
PUBoxCollider::~PUBoxCollider()
|
||||
{
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
float PUBoxCollider::getWidth() const
|
||||
{
|
||||
return _width;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUBoxCollider::setWidth(const float width)
|
||||
{
|
||||
_width = width;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
float PUBoxCollider::getHeight() const
|
||||
{
|
||||
return _height;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUBoxCollider::setHeight(const float height)
|
||||
{
|
||||
_height = height;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
float PUBoxCollider::getDepth() const
|
||||
{
|
||||
return _depth;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUBoxCollider::setDepth(const float depth)
|
||||
{
|
||||
_depth = depth;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
bool PUBoxCollider::isInnerCollision() const
|
||||
{
|
||||
return _innerCollision;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUBoxCollider::setInnerCollision(bool innerCollision)
|
||||
{
|
||||
_innerCollision = innerCollision;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUBoxCollider::calculateDirectionAfterCollision(PUParticle3D* particle)
|
||||
{
|
||||
switch (_collisionType)
|
||||
{
|
||||
case PUBaseCollider::CT_BOUNCE:
|
||||
{
|
||||
// Determine the nearest side and reverse the direction
|
||||
if (isSmallestValue (particle->position.x - _xmin, particle->position))
|
||||
{
|
||||
particle->direction.x *= -1;
|
||||
}
|
||||
else if (isSmallestValue (_xmax - particle->position.x, particle->position))
|
||||
{
|
||||
particle->direction.x *= -1;
|
||||
}
|
||||
else if (isSmallestValue (particle->position.y - _ymin, particle->position))
|
||||
{
|
||||
particle->direction.y *= -1;
|
||||
}
|
||||
else if (isSmallestValue (_ymax - particle->position.y, particle->position))
|
||||
{
|
||||
particle->direction.y *= -1;
|
||||
}
|
||||
else if (isSmallestValue (particle->position.z - _zmin, particle->position))
|
||||
{
|
||||
particle->direction.z *= -1;
|
||||
}
|
||||
else if (isSmallestValue (_zmax - particle->position.z, particle->position))
|
||||
{
|
||||
particle->direction.z *= -1;
|
||||
}
|
||||
particle->direction *= _bouncyness;
|
||||
}
|
||||
break;
|
||||
case PUBaseCollider::CT_FLOW:
|
||||
{
|
||||
if (isSmallestValue (particle->position.x - _xmin, particle->position))
|
||||
{
|
||||
particle->direction.x = 0;
|
||||
}
|
||||
else if (isSmallestValue (_xmax - particle->position.x, particle->position))
|
||||
{
|
||||
particle->direction.x = 0;
|
||||
}
|
||||
else if (isSmallestValue (particle->position.y - _ymin, particle->position))
|
||||
{
|
||||
particle->direction.y = 0;
|
||||
}
|
||||
else if (isSmallestValue (_ymax - particle->position.y, particle->position))
|
||||
{
|
||||
particle->direction.y = 0;
|
||||
}
|
||||
else if (isSmallestValue (particle->position.z - _zmin, particle->position))
|
||||
{
|
||||
particle->direction.z = 0;
|
||||
}
|
||||
else if (isSmallestValue (_zmax - particle->position.z, particle->position))
|
||||
{
|
||||
particle->direction.z = 0;
|
||||
}
|
||||
particle->direction *= -_friction;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUBoxCollider::calculateBounds ()
|
||||
{
|
||||
float scaledWidth = _affectorScale.x * _width;
|
||||
float scaledHeight = _affectorScale.y * _height;
|
||||
float scaledDepth = _affectorScale.z * _depth;
|
||||
|
||||
_xmin = _derivedPosition.x - 0.5f * scaledWidth;
|
||||
_xmax = _derivedPosition.x + 0.5f * scaledWidth;
|
||||
_ymin = _derivedPosition.y - 0.5f * scaledHeight;
|
||||
_ymax = _derivedPosition.y + 0.5f * scaledHeight;
|
||||
_zmin = _derivedPosition.z - 0.5f * scaledDepth;
|
||||
_zmax = _derivedPosition.z + 0.5f * scaledDepth;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
bool PUBoxCollider::isSmallestValue(float value, const Vec3& particlePosition)
|
||||
{
|
||||
float value1 = particlePosition.x - _xmin;
|
||||
float value2 = _xmax - particlePosition.x;
|
||||
float value3 = particlePosition.y - _ymin;
|
||||
float value4 = _ymax - particlePosition.y;
|
||||
float value5 = particlePosition.z - _zmin;
|
||||
float value6 = _zmax - particlePosition.z;
|
||||
|
||||
return (
|
||||
value <= value1 &&
|
||||
value <= value2 &&
|
||||
value <= value3 &&
|
||||
value <= value4 &&
|
||||
value <= value5 &&
|
||||
value <= value6);
|
||||
}
|
||||
|
||||
void PUBoxCollider::updatePUAffector( PUParticle3D *particle, float /*deltaTime*/ )
|
||||
{
|
||||
//for (auto iter : _particleSystem->getParticles())
|
||||
{
|
||||
//PUParticle3D *particle = iter;
|
||||
_predictedPosition = particle->position + _velocityScale * particle->direction;
|
||||
bool collision = false;
|
||||
|
||||
/** Collision detection is a two-step. First, we determine whether the particle is now colliding.
|
||||
If it is, the particle is re-positioned. However, a timeElapsed value is used, which is not the same
|
||||
as the one that was used at the moment before the particle was colliding. Therefore, we rather
|
||||
want to predict particle collision in front. This probably isn't the fastest solution.
|
||||
The same approach was used for the other colliders.
|
||||
*/
|
||||
switch(_intersectionType)
|
||||
{
|
||||
case PUBaseCollider::IT_POINT:
|
||||
{
|
||||
// Validate for a point-box intersection
|
||||
if (_innerCollision != _box.containPoint(particle->position))
|
||||
{
|
||||
// Collision detected (re-position the particle)
|
||||
particle->position -= _velocityScale * particle->direction;
|
||||
collision = true;
|
||||
}
|
||||
else if (_innerCollision != _box.containPoint(_predictedPosition))
|
||||
{
|
||||
// Collision detected
|
||||
collision = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case PUBaseCollider::IT_BOX:
|
||||
{
|
||||
AABB box;
|
||||
populateAlignedBox(box,
|
||||
particle->position,
|
||||
particle->width,
|
||||
particle->height,
|
||||
particle->depth);
|
||||
|
||||
if (_innerCollision != box.intersects(_box))
|
||||
{
|
||||
// Collision detected (re-position the particle)
|
||||
particle->position -= _velocityScale * particle->direction;
|
||||
collision = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
populateAlignedBox(box,
|
||||
_predictedPosition,
|
||||
particle->width,
|
||||
particle->height,
|
||||
particle->depth);
|
||||
if (_innerCollision != box.intersects(_box))
|
||||
{
|
||||
// Collision detected
|
||||
collision = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (collision)
|
||||
{
|
||||
calculateDirectionAfterCollision(particle);
|
||||
calculateRotationSpeedAfterCollision(particle);
|
||||
particle->addEventFlags(PUParticle3D::PEF_COLLIDED);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void PUBoxCollider::preUpdateAffector( float deltaTime )
|
||||
{
|
||||
PUBaseCollider::preUpdateAffector(deltaTime);
|
||||
// Calculate the affectors' center position in worldspace, set the box and calculate the bounds
|
||||
// Applied scaling in V 1.3.1.
|
||||
populateAlignedBox(_box, getDerivedPosition(), _affectorScale.x * _width, _affectorScale.y * _height, _affectorScale.z * _depth);
|
||||
calculateBounds();
|
||||
}
|
||||
|
||||
PUBoxCollider* PUBoxCollider::create()
|
||||
{
|
||||
auto pbc = new (std::nothrow) PUBoxCollider();
|
||||
pbc->autorelease();
|
||||
return pbc;
|
||||
}
|
||||
|
||||
void PUBoxCollider::copyAttributesTo( PUAffector* affector )
|
||||
{
|
||||
PUBaseCollider::copyAttributesTo(affector);
|
||||
|
||||
PUBoxCollider* boxCollider = static_cast<PUBoxCollider*>(affector);
|
||||
boxCollider->_width = _width;
|
||||
boxCollider->_height = _height;
|
||||
boxCollider->_depth = _depth;
|
||||
boxCollider->_innerCollision = _innerCollision;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
118
extensions/Particle3D/PU/CCPUBoxCollider.h
Normal file
118
extensions/Particle3D/PU/CCPUBoxCollider.h
Normal file
@@ -0,0 +1,118 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#ifndef __CC_PU_PARTICLE_3D_BOX_COLLIDER_H__
|
||||
#define __CC_PU_PARTICLE_3D_BOX_COLLIDER_H__
|
||||
|
||||
#include "CCPUBaseCollider.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class CC_DLL PUBoxCollider : public PUBaseCollider
|
||||
{
|
||||
public:
|
||||
static const float DEFAULT_WIDTH;
|
||||
static const float DEFAULT_HEIGHT;
|
||||
static const float DEFAULT_DEPTH;
|
||||
|
||||
static PUBoxCollider* create();
|
||||
|
||||
virtual void preUpdateAffector(float deltaTime) override;
|
||||
virtual void updatePUAffector(PUParticle3D *particle, float deltaTime) override;
|
||||
|
||||
/** Returns the width of the box
|
||||
*/
|
||||
float getWidth() const;
|
||||
|
||||
/** Sets the width of the box
|
||||
*/
|
||||
void setWidth(const float width);
|
||||
|
||||
/** Returns the height of the box
|
||||
*/
|
||||
float getHeight() const;
|
||||
|
||||
/** Sets the height of the box
|
||||
*/
|
||||
void setHeight(const float height);
|
||||
|
||||
/** Returns the depth of the box
|
||||
*/
|
||||
float getDepth() const;
|
||||
|
||||
/** Sets the depth of the box
|
||||
*/
|
||||
void setDepth(const float depth);
|
||||
|
||||
/** Returns indication whether the collision is inside or outside of the box
|
||||
@remarks
|
||||
If value is true, the collision is inside of the box.
|
||||
*/
|
||||
bool isInnerCollision() const;
|
||||
|
||||
/** Set indication whether the collision is inside or outside of the box
|
||||
@remarks
|
||||
If value is set to true, the collision is inside of the box.
|
||||
*/
|
||||
void setInnerCollision(bool innerCollision);
|
||||
|
||||
/**
|
||||
*/
|
||||
void calculateDirectionAfterCollision(PUParticle3D* particle);
|
||||
|
||||
virtual void copyAttributesTo (PUAffector* affector) override;
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
PUBoxCollider();
|
||||
virtual ~PUBoxCollider();
|
||||
|
||||
protected:
|
||||
/**
|
||||
*/
|
||||
void calculateBounds ();
|
||||
/**
|
||||
*/
|
||||
bool isSmallestValue(float value, const Vec3& particlePosition);
|
||||
|
||||
protected:
|
||||
|
||||
float _width;
|
||||
float _height;
|
||||
float _depth;
|
||||
float _xmin;
|
||||
float _xmax;
|
||||
float _ymin;
|
||||
float _ymax;
|
||||
float _zmin;
|
||||
float _zmax;
|
||||
AABB _box;
|
||||
Vec3 _predictedPosition;
|
||||
bool _innerCollision;
|
||||
};
|
||||
NS_CC_END
|
||||
|
||||
#endif
|
||||
152
extensions/Particle3D/PU/CCPUBoxColliderTranslator.cpp
Normal file
152
extensions/Particle3D/PU/CCPUBoxColliderTranslator.cpp
Normal file
@@ -0,0 +1,152 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCPUBoxColliderTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUParticleSystem3D.h"
|
||||
#include "extensions/Particle3D/PU/CCPUDynamicAttribute.h"
|
||||
#include "extensions/Particle3D/PU/CCPUDynamicAttributeTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUBaseColliderTranslator.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
PUBoxColliderTranslator::PUBoxColliderTranslator()
|
||||
{
|
||||
}
|
||||
//-------------------------------------------------------------------------
|
||||
bool PUBoxColliderTranslator::translateChildProperty( PUScriptCompiler* compiler, PUAbstractNode *node )
|
||||
{
|
||||
PUPropertyAbstractNode* prop = reinterpret_cast<PUPropertyAbstractNode*>(node);
|
||||
PUAffector* af = static_cast<PUAffector*>(prop->parent->context);
|
||||
PUBoxCollider* affector = static_cast<PUBoxCollider*>(af);
|
||||
|
||||
if (prop->name == token[TOKEN_BOX_WIDTH])
|
||||
{
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_BOX_WIDTH], VAL_REAL))
|
||||
{
|
||||
// Property: box_width
|
||||
float val = 0.0f;
|
||||
if(getFloat(*prop->values.front(), &val))
|
||||
{
|
||||
affector->setWidth(val);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_BOXCOLL_WIDTH])
|
||||
{
|
||||
// Property: box_collider_width (deprecated and replaced by 'box_width')
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_BOXCOLL_WIDTH], VAL_REAL))
|
||||
{
|
||||
float val = 0.0f;
|
||||
if(getFloat(*prop->values.front(), &val))
|
||||
{
|
||||
affector->setWidth(val);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_BOX_HEIGHT])
|
||||
{
|
||||
// Property: box_height
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_BOX_HEIGHT], VAL_REAL))
|
||||
{
|
||||
float val = 0.0f;
|
||||
if(getFloat(*prop->values.front(), &val))
|
||||
{
|
||||
affector->setHeight(val);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_BOXCOLL_HEIGHT])
|
||||
{
|
||||
// Property: box_collider_height (deprecated and replaced by 'box_height')
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_BOXCOLL_HEIGHT], VAL_REAL))
|
||||
{
|
||||
float val = 0.0f;
|
||||
if(getFloat(*prop->values.front(), &val))
|
||||
{
|
||||
affector->setHeight(val);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_BOX_DEPTH])
|
||||
{
|
||||
// Property: box_depth
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_BOX_DEPTH], VAL_REAL))
|
||||
{
|
||||
float val = 0.0f;
|
||||
if(getFloat(*prop->values.front(), &val))
|
||||
{
|
||||
affector->setDepth(val);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_BOXCOLL_DEPTH])
|
||||
{
|
||||
// Property: box_collider_depth (deprecated and replaced by 'box_depth')
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_BOXCOLL_DEPTH], VAL_REAL))
|
||||
{
|
||||
float val = 0.0f;
|
||||
if(getFloat(*prop->values.front(), &val))
|
||||
{
|
||||
affector->setDepth(val);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_INNER_COLLISION])
|
||||
{
|
||||
// Property: inner_collision
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_INNER_COLLISION], VAL_BOOL))
|
||||
{
|
||||
bool val;
|
||||
if(getBoolean(*prop->values.front(), &val))
|
||||
{
|
||||
affector->setInnerCollision(val);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Parse the BaseCollider
|
||||
PUBaseColliderTranslator baseColliderTranslator;
|
||||
return baseColliderTranslator.translateChildProperty(compiler, node);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool PUBoxColliderTranslator::translateChildObject( PUScriptCompiler* /*compiler*/, PUAbstractNode* /*node*/ )
|
||||
{
|
||||
// No objects
|
||||
return false;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
48
extensions/Particle3D/PU/CCPUBoxColliderTranslator.h
Normal file
48
extensions/Particle3D/PU/CCPUBoxColliderTranslator.h
Normal file
@@ -0,0 +1,48 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __CC_PU_PARTICLE_3D_BOX_COLLIDER_TRANSLATOR_H__
|
||||
#define __CC_PU_PARTICLE_3D_BOX_COLLIDER_TRANSLATOR_H__
|
||||
|
||||
#include "extensions/Particle3D/PU/CCPUScriptTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUScriptCompiler.h"
|
||||
#include "extensions/Particle3D/PU/CCPUBoxCollider.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class PUBoxColliderTranslator : public PUScriptTranslator
|
||||
{
|
||||
public:
|
||||
PUBoxColliderTranslator();
|
||||
virtual ~PUBoxColliderTranslator(){};
|
||||
|
||||
virtual bool translateChildProperty(PUScriptCompiler* compiler, PUAbstractNode *node);
|
||||
virtual bool translateChildObject(PUScriptCompiler* compiler, PUAbstractNode *node);
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif
|
||||
136
extensions/Particle3D/PU/CCPUBoxEmitter.cpp
Normal file
136
extensions/Particle3D/PU/CCPUBoxEmitter.cpp
Normal file
@@ -0,0 +1,136 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCPUBoxEmitter.h"
|
||||
#include "extensions/Particle3D/PU/CCPUParticleSystem3D.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
// Constants
|
||||
const float CCPUBoxEmitter::DEFAULT_WIDTH = 100.0f;
|
||||
const float CCPUBoxEmitter::DEFAULT_HEIGHT = 100.0f;
|
||||
const float CCPUBoxEmitter::DEFAULT_DEPTH = 100.0f;
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
CCPUBoxEmitter::CCPUBoxEmitter() :
|
||||
PUEmitter(),
|
||||
_height(DEFAULT_HEIGHT),
|
||||
_width(DEFAULT_WIDTH),
|
||||
_depth(DEFAULT_DEPTH),
|
||||
_xRange(0.5f * DEFAULT_WIDTH),
|
||||
_yRange(0.5f * DEFAULT_HEIGHT),
|
||||
_zRange(0.5f * DEFAULT_DEPTH)
|
||||
{
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
float CCPUBoxEmitter::getHeight() const
|
||||
{
|
||||
return _height;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void CCPUBoxEmitter::setHeight(const float height)
|
||||
{
|
||||
_height = height;
|
||||
_yRange = 0.5f * height;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
float CCPUBoxEmitter::getWidth() const
|
||||
{
|
||||
return _width;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void CCPUBoxEmitter::setWidth(const float width)
|
||||
{
|
||||
_width = width;
|
||||
_xRange = 0.5f * width;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
float CCPUBoxEmitter::getDepth() const
|
||||
{
|
||||
return _depth;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void CCPUBoxEmitter::setDepth(const float depth)
|
||||
{
|
||||
_depth = depth;
|
||||
_zRange = 0.5f * depth;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void CCPUBoxEmitter::initParticlePosition(PUParticle3D* particle)
|
||||
{
|
||||
//ParticleSystem* sys = mParentTechnique->getParentSystem();
|
||||
|
||||
//if (sys)
|
||||
{
|
||||
Mat4 rotMat;
|
||||
Mat4::createRotation(static_cast<PUParticleSystem3D *>(_particleSystem)->getDerivedOrientation(), &rotMat);
|
||||
particle->position = getDerivedPosition() +
|
||||
rotMat *
|
||||
(/*_emitterScale **/
|
||||
Vec3(CCRANDOM_MINUS1_1() * _xRange * _emitterScale.x,
|
||||
CCRANDOM_MINUS1_1() * _yRange * _emitterScale.y,
|
||||
CCRANDOM_MINUS1_1() * _zRange * _emitterScale.z));
|
||||
}
|
||||
//else
|
||||
//{
|
||||
// particle->position = getDerivedPosition() +
|
||||
// _emitterScale *
|
||||
// Vector3(Math::SymmetricRandom() * _xRange,
|
||||
// Math::SymmetricRandom() * _yRange,
|
||||
// Math::SymmetricRandom() * _zRange);
|
||||
//}
|
||||
|
||||
particle->originalPosition = particle->position;
|
||||
}
|
||||
|
||||
CCPUBoxEmitter* CCPUBoxEmitter::create()
|
||||
{
|
||||
auto pe = new (std::nothrow) CCPUBoxEmitter();
|
||||
pe->autorelease();
|
||||
return pe;
|
||||
}
|
||||
|
||||
void CCPUBoxEmitter::copyAttributesTo( PUEmitter* emitter )
|
||||
{
|
||||
PUEmitter::copyAttributesTo(emitter);
|
||||
|
||||
CCPUBoxEmitter* boxEmitter = static_cast<CCPUBoxEmitter*>(emitter);
|
||||
boxEmitter->_height = _height;
|
||||
boxEmitter->_width = _width;
|
||||
boxEmitter->_depth = _depth;
|
||||
boxEmitter->_xRange = _xRange;
|
||||
boxEmitter->_yRange = _yRange;
|
||||
boxEmitter->_zRange = _zRange;
|
||||
}
|
||||
|
||||
CCPUBoxEmitter* CCPUBoxEmitter::clone()
|
||||
{
|
||||
auto be = CCPUBoxEmitter::create();
|
||||
copyAttributesTo(be);
|
||||
return be;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
86
extensions/Particle3D/PU/CCPUBoxEmitter.h
Normal file
86
extensions/Particle3D/PU/CCPUBoxEmitter.h
Normal file
@@ -0,0 +1,86 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#ifndef __CC_PU_PARTICLE_3D_BOX_EMITTER_H__
|
||||
#define __CC_PU_PARTICLE_3D_BOX_EMITTER_H__
|
||||
|
||||
#include "extensions/Particle3D/PU/CCPUEmitter.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class CC_DLL CCPUBoxEmitter : public PUEmitter
|
||||
{
|
||||
public:
|
||||
// Constants
|
||||
static const float DEFAULT_WIDTH;
|
||||
static const float DEFAULT_HEIGHT;
|
||||
static const float DEFAULT_DEPTH;
|
||||
|
||||
static CCPUBoxEmitter* create();
|
||||
|
||||
/**
|
||||
*/
|
||||
float getHeight() const;
|
||||
void setHeight(const float height);
|
||||
|
||||
/**
|
||||
*/
|
||||
float getWidth() const;
|
||||
void setWidth(const float width);
|
||||
|
||||
/**
|
||||
*/
|
||||
float getDepth() const;
|
||||
void setDepth(const float depth);
|
||||
|
||||
virtual CCPUBoxEmitter* clone() override;
|
||||
virtual void copyAttributesTo (PUEmitter* emitter) override;
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
CCPUBoxEmitter();
|
||||
virtual ~CCPUBoxEmitter() {};
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
*/
|
||||
virtual void initParticlePosition(PUParticle3D* particle) override;
|
||||
|
||||
protected:
|
||||
float _height;
|
||||
float _width;
|
||||
float _depth;
|
||||
|
||||
float _xRange;
|
||||
float _yRange;
|
||||
float _zRange;
|
||||
|
||||
|
||||
};
|
||||
NS_CC_END
|
||||
|
||||
#endif
|
||||
132
extensions/Particle3D/PU/CCPUBoxEmitterTranslator.cpp
Normal file
132
extensions/Particle3D/PU/CCPUBoxEmitterTranslator.cpp
Normal file
@@ -0,0 +1,132 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCPUBoxEmitterTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUParticleSystem3D.h"
|
||||
#include "extensions/Particle3D/PU/CCPUDynamicAttribute.h"
|
||||
#include "extensions/Particle3D/PU/CCPUDynamicAttributeTranslator.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
CCPUBoxEmitterTranslator::CCPUBoxEmitterTranslator()
|
||||
{
|
||||
}
|
||||
//-------------------------------------------------------------------------
|
||||
bool CCPUBoxEmitterTranslator::translateChildProperty( PUScriptCompiler* compiler, PUAbstractNode *node )
|
||||
{
|
||||
PUPropertyAbstractNode* prop = reinterpret_cast<PUPropertyAbstractNode*>(node);
|
||||
PUEmitter* em = static_cast<PUEmitter*>(prop->parent->context);
|
||||
CCPUBoxEmitter* emitter = static_cast<CCPUBoxEmitter*>(em);
|
||||
|
||||
if (prop->name == token[TOKEN_BOX_WIDTH])
|
||||
{
|
||||
// Property: box_width
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_BOX_WIDTH], VAL_REAL))
|
||||
{
|
||||
float val = 0.0f;
|
||||
if(getFloat(*prop->values.front(), &val))
|
||||
{
|
||||
emitter->setWidth(val);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_EMITTER_BOX_WIDTH])
|
||||
{
|
||||
// Property: box_em_width (deprecated and replaced by 'box_width')
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_BOX_WIDTH], VAL_REAL))
|
||||
{
|
||||
float val = 0.0f;
|
||||
if(getFloat(*prop->values.front(), &val))
|
||||
{
|
||||
emitter->setWidth(val);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_BOX_HEIGHT])
|
||||
{
|
||||
// Property: box_height
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_BOX_HEIGHT], VAL_REAL))
|
||||
{
|
||||
float val = 0.0f;
|
||||
if(getFloat(*prop->values.front(), &val))
|
||||
{
|
||||
emitter->setHeight(val);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_EMITTER_BOX_HEIGHT])
|
||||
{
|
||||
// Property: box_em_height (deprecated and replaced by 'box_height')
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_BOX_HEIGHT], VAL_REAL))
|
||||
{
|
||||
float val = 0.0f;
|
||||
if(getFloat(*prop->values.front(), &val))
|
||||
{
|
||||
emitter->setHeight(val);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_BOX_DEPTH])
|
||||
{
|
||||
// Property: box_depth
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_BOX_DEPTH], VAL_REAL))
|
||||
{
|
||||
float val = 0.0f;
|
||||
if(getFloat(*prop->values.front(), &val))
|
||||
{
|
||||
emitter->setDepth(val);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_EMITTER_BOX_DEPTH])
|
||||
{
|
||||
// Property: box_em_depth (deprecated and replaced by 'box_depth')
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_BOX_DEPTH], VAL_REAL))
|
||||
{
|
||||
float val = 0.0f;
|
||||
if(getFloat(*prop->values.front(), &val))
|
||||
{
|
||||
emitter->setDepth(val);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CCPUBoxEmitterTranslator::translateChildObject( PUScriptCompiler* /*compiler*/, PUAbstractNode* /*node*/ )
|
||||
{
|
||||
// No objects
|
||||
return false;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
48
extensions/Particle3D/PU/CCPUBoxEmitterTranslator.h
Normal file
48
extensions/Particle3D/PU/CCPUBoxEmitterTranslator.h
Normal file
@@ -0,0 +1,48 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __CC_PU_PARTICLE_3D_BOX_EMITTER_TRANSLATOR_H__
|
||||
#define __CC_PU_PARTICLE_3D_BOX_EMITTER_TRANSLATOR_H__
|
||||
|
||||
#include "extensions/Particle3D/PU/CCPUScriptTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUScriptCompiler.h"
|
||||
#include "extensions/Particle3D/PU/CCPUBoxEmitter.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class CCPUBoxEmitterTranslator : public PUScriptTranslator
|
||||
{
|
||||
public:
|
||||
CCPUBoxEmitterTranslator();
|
||||
virtual ~CCPUBoxEmitterTranslator(){};
|
||||
|
||||
virtual bool translateChildProperty(PUScriptCompiler* compiler, PUAbstractNode *node);
|
||||
virtual bool translateChildObject(PUScriptCompiler* compiler, PUAbstractNode *node);
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif /* defined(__cocos2d_libs__CCParticle3DAffectorTranslator__) */
|
||||
271
extensions/Particle3D/PU/CCPUCircleEmitter.cpp
Normal file
271
extensions/Particle3D/PU/CCPUCircleEmitter.cpp
Normal file
@@ -0,0 +1,271 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCPUCircleEmitter.h"
|
||||
#include "extensions/Particle3D/PU/CCPUParticleSystem3D.h"
|
||||
#include "extensions/Particle3D/PU/CCPUUtil.h"
|
||||
#include "base/ccRandom.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
// Constants
|
||||
const float PUCircleEmitter::DEFAULT_RADIUS = 100.0f;
|
||||
const float PUCircleEmitter::DEFAULT_STEP = 0.1f;
|
||||
const float PUCircleEmitter::DEFAULT_ANGLE = 0.0f;
|
||||
const bool PUCircleEmitter::DEFAULT_RANDOM = true;
|
||||
const Vec3 PUCircleEmitter::DEFAULT_NORMAL(0, 0, 0);
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
PUCircleEmitter::PUCircleEmitter() :
|
||||
PUEmitter(),
|
||||
_radius(DEFAULT_RADIUS),
|
||||
_circleAngle(DEFAULT_ANGLE),
|
||||
_originalCircleAngle(DEFAULT_ANGLE),
|
||||
_step(DEFAULT_STEP),
|
||||
_x(0.0f),
|
||||
_z(0.0f),
|
||||
_random(DEFAULT_RANDOM),
|
||||
_orientation(),
|
||||
_normal(DEFAULT_NORMAL)
|
||||
{
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
float PUCircleEmitter::getRadius() const
|
||||
{
|
||||
return _radius;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUCircleEmitter::setRadius(const float radius)
|
||||
{
|
||||
_radius = radius;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
float PUCircleEmitter::getCircleAngle() const
|
||||
{
|
||||
return _originalCircleAngle;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUCircleEmitter::setCircleAngle(const float circleAngle)
|
||||
{
|
||||
_originalCircleAngle = circleAngle;
|
||||
_circleAngle = circleAngle;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
float PUCircleEmitter::getStep() const
|
||||
{
|
||||
return _step;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUCircleEmitter::setStep(const float step)
|
||||
{
|
||||
_step = step;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
bool PUCircleEmitter::isRandom() const
|
||||
{
|
||||
return _random;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUCircleEmitter::setRandom(const bool random)
|
||||
{
|
||||
_random = random;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
const Quaternion& PUCircleEmitter::getOrientation() const
|
||||
{
|
||||
return _orientation;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
const Vec3& PUCircleEmitter::getNormal() const
|
||||
{
|
||||
return _normal;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUCircleEmitter::setNormal(const Vec3& normal)
|
||||
{
|
||||
//_orientation = Vec3::UNIT_Y.getRotationTo(normal, Vec3::UNIT_X);
|
||||
_orientation = getRotationTo(Vec3::UNIT_Y, normal, Vec3::UNIT_X);
|
||||
_normal = normal;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUCircleEmitter::notifyStart ()
|
||||
{
|
||||
// Reset the attributes to allow a restart.
|
||||
_circleAngle = _originalCircleAngle;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUCircleEmitter::initParticlePosition(PUParticle3D* particle)
|
||||
{
|
||||
float angle = 0;
|
||||
if (_random)
|
||||
{
|
||||
// Choose a random position on the circle.
|
||||
angle = cocos2d::random(0.0, M_PI * 2.0);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Follow the contour of the circle.
|
||||
_circleAngle += _step;
|
||||
_circleAngle = _circleAngle > M_PI * 2.0f ? _circleAngle - (M_PI * 2.0) : _circleAngle;
|
||||
angle = _circleAngle;
|
||||
}
|
||||
|
||||
_x = cosf(angle);
|
||||
_z = sinf(angle);
|
||||
//ParticleSystem* sys = mParentTechnique->getParentSystem();
|
||||
//if (sys)
|
||||
{
|
||||
// Take both orientation of the node and its own orientation, based on the normal, into account
|
||||
Mat4 rotMat;
|
||||
Mat4::createRotation(static_cast<PUParticleSystem3D *>(_particleSystem)->getDerivedOrientation() * _orientation, &rotMat);
|
||||
particle->position = getDerivedPosition() +
|
||||
/*sys->getDerivedOrientation() * */rotMat * (Vec3(_x * _radius * _emitterScale.x, 0, _z * _radius * _emitterScale.z));
|
||||
}
|
||||
//else
|
||||
//{
|
||||
// particle->position = getDerivedPosition() + _emitterScale * ( mOrientation * Vec3(mX * mRadius, 0, mZ * mRadius) );
|
||||
//}
|
||||
particle->originalPosition = particle->position;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUCircleEmitter::initParticleDirection(PUParticle3D* particle)
|
||||
{
|
||||
if (_autoDirection)
|
||||
{
|
||||
// The value of the direction vector that has been set does not have a meaning for
|
||||
// the circle emitter.
|
||||
float angle = 0.0f;
|
||||
generateAngle(angle);
|
||||
if (angle != 0.0f)
|
||||
{
|
||||
//particle->direction = (mOrientation * Vec3(mX, 0, mZ) ).randomDeviant(angle, mUpVector);
|
||||
Mat4 mat;
|
||||
Mat4::createRotation(_orientation, &mat);
|
||||
Vec3 temp = mat * Vec3(_x, 0, _z);
|
||||
|
||||
particle->direction = PUUtil::randomDeviant(temp, angle, _upVector);
|
||||
|
||||
particle->originalDirection = particle->direction;
|
||||
}
|
||||
else
|
||||
{
|
||||
Mat4 rotMat;
|
||||
Mat4::createRotation(_orientation, &rotMat);
|
||||
particle->direction = rotMat * Vec3(_x, 0, _z);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Use the standard way
|
||||
PUEmitter::initParticleDirection(particle);
|
||||
}
|
||||
}
|
||||
|
||||
PUCircleEmitter* PUCircleEmitter::create()
|
||||
{
|
||||
auto pe = new (std::nothrow) PUCircleEmitter();
|
||||
pe->autorelease();
|
||||
return pe;
|
||||
}
|
||||
|
||||
cocos2d::Quaternion PUCircleEmitter::getRotationTo( const Vec3 &src, const Vec3& dest, const Vec3& fallbackAxis /*= Vec3::ZERO*/ ) const
|
||||
{
|
||||
// Based on Stan Melax's article in Game Programming Gems
|
||||
Quaternion q;
|
||||
// Copy, since cannot modify local
|
||||
Vec3 v0 = src;
|
||||
Vec3 v1 = dest;
|
||||
v0.normalize();
|
||||
v1.normalize();
|
||||
|
||||
float d = v0.dot(v1);
|
||||
// If dot == 1, vectors are the same
|
||||
if (d >= 1.0f)
|
||||
{
|
||||
return Quaternion();
|
||||
}
|
||||
if (d < (1e-6f - 1.0f))
|
||||
{
|
||||
if (fallbackAxis != Vec3::ZERO)
|
||||
{
|
||||
// rotate 180 degrees about the fallback axis
|
||||
q.set(fallbackAxis, (float)M_PI);
|
||||
//q.FromAngleAxis(Radian(Math::PI), fallbackAxis);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Generate an axis
|
||||
Vec3 axis/* = Vec3::UNIT_X.crossProduct(*this)*/;
|
||||
Vec3::cross(Vec3::UNIT_X, src, &axis);
|
||||
if (axis.lengthSquared() < (1e-06 * 1e-06)) // pick another if colinear
|
||||
//axis = Vec3::UNIT_Y.crossProduct(*this);
|
||||
Vec3::cross(Vec3::UNIT_Y, src, &axis);
|
||||
axis.normalize();
|
||||
|
||||
//q.FromAngleAxis(Radian(Math::PI), axis);
|
||||
q.set(axis, (float)M_PI);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/*float s = Math::Sqrt( (1+d)*2 );*/
|
||||
float s = sqrtf( (1+d)*2 );
|
||||
float invs = 1 / s;
|
||||
|
||||
Vec3 c /*= v0.crossProduct(v1)*/;
|
||||
Vec3::cross(v0, v1, &c);
|
||||
|
||||
q.x = c.x * invs;
|
||||
q.y = c.y * invs;
|
||||
q.z = c.z * invs;
|
||||
q.w = s * 0.5f;
|
||||
q.normalize();
|
||||
}
|
||||
return q;
|
||||
}
|
||||
|
||||
void PUCircleEmitter::copyAttributesTo( PUEmitter* emitter )
|
||||
{
|
||||
PUEmitter::copyAttributesTo(emitter);
|
||||
|
||||
PUCircleEmitter* circleEmitter = static_cast<PUCircleEmitter*>(emitter);
|
||||
circleEmitter->_radius = _radius;
|
||||
circleEmitter->_circleAngle = _circleAngle;
|
||||
circleEmitter->_originalCircleAngle = _originalCircleAngle;
|
||||
circleEmitter->_step = _step;
|
||||
circleEmitter->_random = _random;
|
||||
circleEmitter->_normal = _normal;
|
||||
circleEmitter->_orientation = _orientation;
|
||||
}
|
||||
|
||||
PUCircleEmitter* PUCircleEmitter::clone()
|
||||
{
|
||||
auto be = PUCircleEmitter::create();
|
||||
copyAttributesTo(be);
|
||||
return be;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
112
extensions/Particle3D/PU/CCPUCircleEmitter.h
Normal file
112
extensions/Particle3D/PU/CCPUCircleEmitter.h
Normal file
@@ -0,0 +1,112 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#ifndef __CC_PU_PARTICLE_3D_CIRCLE_EMITTER_H__
|
||||
#define __CC_PU_PARTICLE_3D_CIRCLE_EMITTER_H__
|
||||
|
||||
#include "extensions/Particle3D/PU/CCPUEmitter.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class CC_DLL PUCircleEmitter : public PUEmitter
|
||||
{
|
||||
public:
|
||||
// Constants
|
||||
static const float DEFAULT_RADIUS;
|
||||
static const float DEFAULT_STEP;
|
||||
static const float DEFAULT_ANGLE;
|
||||
static const bool DEFAULT_RANDOM;
|
||||
static const Vec3 DEFAULT_NORMAL;
|
||||
|
||||
static PUCircleEmitter* create();
|
||||
|
||||
/**
|
||||
*/
|
||||
float getRadius() const;
|
||||
void setRadius(const float radius);
|
||||
|
||||
/**
|
||||
*/
|
||||
float getCircleAngle() const;
|
||||
void setCircleAngle(const float circleAngle);
|
||||
|
||||
/**
|
||||
*/
|
||||
float getStep() const;
|
||||
void setStep(const float step);
|
||||
|
||||
/**
|
||||
*/
|
||||
bool isRandom() const;
|
||||
void setRandom(const bool random);
|
||||
|
||||
/*
|
||||
*/
|
||||
const Quaternion& getOrientation() const;
|
||||
const Vec3& getNormal() const;
|
||||
void setNormal(const Vec3 &normal);
|
||||
|
||||
/** See ParticleEmiter
|
||||
*/
|
||||
virtual void notifyStart() override;
|
||||
|
||||
virtual PUCircleEmitter* clone() override;
|
||||
virtual void copyAttributesTo (PUEmitter* emitter) override;
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
PUCircleEmitter();
|
||||
virtual ~PUCircleEmitter() {};
|
||||
|
||||
protected:
|
||||
|
||||
/** Determine a particle position on the circle.
|
||||
*/
|
||||
virtual void initParticlePosition(PUParticle3D* particle) override;
|
||||
|
||||
/** Determine the particle direction.
|
||||
*/
|
||||
virtual void initParticleDirection(PUParticle3D* particle) override;
|
||||
|
||||
Quaternion getRotationTo(const Vec3 &src, const Vec3& dest,
|
||||
const Vec3& fallbackAxis = Vec3::ZERO) const;
|
||||
|
||||
protected:
|
||||
float _radius;
|
||||
float _circleAngle;
|
||||
float _originalCircleAngle;
|
||||
float _step;
|
||||
float _x;
|
||||
float _z;
|
||||
bool _random;
|
||||
Quaternion _orientation;
|
||||
Vec3 _normal;
|
||||
|
||||
|
||||
};
|
||||
NS_CC_END
|
||||
|
||||
#endif
|
||||
182
extensions/Particle3D/PU/CCPUCircleEmitterTranslator.cpp
Normal file
182
extensions/Particle3D/PU/CCPUCircleEmitterTranslator.cpp
Normal file
@@ -0,0 +1,182 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCPUCircleEmitterTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUParticleSystem3D.h"
|
||||
#include "extensions/Particle3D/PU/CCPUDynamicAttribute.h"
|
||||
#include "extensions/Particle3D/PU/CCPUDynamicAttributeTranslator.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
PUCircleEmitterTranslator::PUCircleEmitterTranslator()
|
||||
{
|
||||
}
|
||||
//-------------------------------------------------------------------------
|
||||
bool PUCircleEmitterTranslator::translateChildProperty( PUScriptCompiler* compiler, PUAbstractNode *node )
|
||||
{
|
||||
PUPropertyAbstractNode* prop = reinterpret_cast<PUPropertyAbstractNode*>(node);
|
||||
PUEmitter* em = static_cast<PUEmitter*>(prop->parent->context);
|
||||
PUCircleEmitter* emitter = static_cast<PUCircleEmitter*>(em);
|
||||
|
||||
if (prop->name == token[TOKEN_RADIUS])
|
||||
{
|
||||
// Property: radius
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_RADIUS], VAL_REAL))
|
||||
{
|
||||
float val = 0.0f;
|
||||
if(getFloat(*prop->values.front(), &val))
|
||||
{
|
||||
emitter->setRadius(val);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_CIRCLE_RADIUS])
|
||||
{
|
||||
// Property: circle_em_radius (deprecated and replaced by radius)
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_CIRCLE_RADIUS], VAL_REAL))
|
||||
{
|
||||
float val = 0.0f;
|
||||
if(getFloat(*prop->values.front(), &val))
|
||||
{
|
||||
emitter->setRadius(val);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_STEP])
|
||||
{
|
||||
// Property: step
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_STEP], VAL_REAL))
|
||||
{
|
||||
float val = 0.0f;
|
||||
if(getFloat(*prop->values.front(), &val))
|
||||
{
|
||||
emitter->setStep(val);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_CIRCLE_STEP])
|
||||
{
|
||||
// Property: circle_em_step (deprecated and replaced by 'step')
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_CIRCLE_STEP], VAL_REAL))
|
||||
{
|
||||
float val = 0.0f;
|
||||
if(getFloat(*prop->values.front(), &val))
|
||||
{
|
||||
emitter->setStep(val);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_ANGLE])
|
||||
{
|
||||
// Property: angle
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_ANGLE], VAL_REAL))
|
||||
{
|
||||
float val = 0.0f;
|
||||
if(getFloat(*prop->values.front(), &val))
|
||||
{
|
||||
emitter->setCircleAngle(val);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_CIRCLE_ANGLE])
|
||||
{
|
||||
// Property: circle_em_angle
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_CIRCLE_ANGLE], VAL_REAL))
|
||||
{
|
||||
float val = 0.0f;
|
||||
if(getFloat(*prop->values.front(), &val))
|
||||
{
|
||||
emitter->setCircleAngle(val);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_EMIT_RANDOM])
|
||||
{
|
||||
// Property: emit_random
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_EMIT_RANDOM], VAL_BOOL))
|
||||
{
|
||||
bool val;
|
||||
if(getBoolean(*prop->values.front(), &val))
|
||||
{
|
||||
emitter->setRandom(val);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_CIRCLE_RANDOM])
|
||||
{
|
||||
// Property: circle_em_random (deprecated and replaced by 'emit_random'))
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_CIRCLE_RANDOM], VAL_BOOL))
|
||||
{
|
||||
bool val;
|
||||
if(getBoolean(*prop->values.front(), &val))
|
||||
{
|
||||
emitter->setRandom(val);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_NORMAL])
|
||||
{
|
||||
// Property: normal
|
||||
{
|
||||
Vec3 val;
|
||||
if(getVector3(prop->values.begin(), prop->values.end(), &val))
|
||||
{
|
||||
emitter->setNormal(val);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_CIRCLE_NORMAL])
|
||||
{
|
||||
// Property: circle_em_normal (deprecated and replaced by 'normal')
|
||||
{
|
||||
Vec3 val;
|
||||
if(getVector3(prop->values.begin(), prop->values.end(), &val))
|
||||
{
|
||||
emitter->setNormal(val);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool PUCircleEmitterTranslator::translateChildObject( PUScriptCompiler* /*compiler*/, PUAbstractNode* /*node*/ )
|
||||
{
|
||||
// No objects
|
||||
return false;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
48
extensions/Particle3D/PU/CCPUCircleEmitterTranslator.h
Normal file
48
extensions/Particle3D/PU/CCPUCircleEmitterTranslator.h
Normal file
@@ -0,0 +1,48 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __CC_PU_PARTICLE_3D_CIRCLE_EMITTER_TRANSLATOR_H__
|
||||
#define __CC_PU_PARTICLE_3D_CIRCLE_EMITTER_TRANSLATOR_H__
|
||||
|
||||
#include "extensions/Particle3D/PU/CCPUScriptTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUScriptCompiler.h"
|
||||
#include "extensions/Particle3D/PU/CCPUCircleEmitter.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class PUCircleEmitterTranslator : public PUScriptTranslator
|
||||
{
|
||||
public:
|
||||
PUCircleEmitterTranslator();
|
||||
virtual ~PUCircleEmitterTranslator(){};
|
||||
|
||||
virtual bool translateChildProperty(PUScriptCompiler* compiler, PUAbstractNode *node);
|
||||
virtual bool translateChildObject(PUScriptCompiler* compiler, PUAbstractNode *node);
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif /* defined(__cocos2d_libs__CCParticle3DAffectorTranslator__) */
|
||||
113
extensions/Particle3D/PU/CCPUCollisionAvoidanceAffector.cpp
Normal file
113
extensions/Particle3D/PU/CCPUCollisionAvoidanceAffector.cpp
Normal file
@@ -0,0 +1,113 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCPUCollisionAvoidanceAffector.h"
|
||||
#include "extensions/Particle3D/PU/CCPUParticleSystem3D.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
// Constants
|
||||
const float PUCollisionAvoidanceAffector::DEFAULT_RADIUS = 100.0f;
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
PUCollisionAvoidanceAffector::PUCollisionAvoidanceAffector() :
|
||||
PUAffector(),
|
||||
_radius(DEFAULT_RADIUS)
|
||||
{
|
||||
}
|
||||
PUCollisionAvoidanceAffector::~PUCollisionAvoidanceAffector()
|
||||
{
|
||||
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
float PUCollisionAvoidanceAffector::getRadius() const
|
||||
{
|
||||
return _radius;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUCollisionAvoidanceAffector::setRadius(float radius)
|
||||
{
|
||||
_radius = radius;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUCollisionAvoidanceAffector::updatePUAffector( PUParticle3D* /*particle*/, float /*deltaTime*/ )
|
||||
{
|
||||
CCASSERT(0, "nonsupport yet");
|
||||
//for (auto iter : _particleSystem->getParticles())
|
||||
//{
|
||||
// PUParticle3D *particle = iter;
|
||||
// // Activate spatial hashing
|
||||
// particleTechnique->setSpatialHashingUsed(true);
|
||||
|
||||
// // Determine neighbouring particles.
|
||||
// SpatialHashTable<Particle*>* hashtable = particleTechnique->getSpatialHashTable();
|
||||
// if (hashtable)
|
||||
// {
|
||||
// SpatialHashTable<Particle*>::HashTableCell cell = hashtable->getCell(particle->position);
|
||||
// if (cell.empty())
|
||||
// return;
|
||||
|
||||
// unsigned int size = static_cast<unsigned int>(cell.size());
|
||||
// Vector3 displacement = Vector3::ZERO;
|
||||
// Vector3 diff = Vector3::ZERO;
|
||||
// for (unsigned int i = 0; i < size; ++i)
|
||||
// {
|
||||
// Particle* p = cell[i];
|
||||
|
||||
// // Don't check if it is the same particle
|
||||
// if (particle != p)
|
||||
// {
|
||||
// // Validate whether the neighbouring particle is within range
|
||||
// diff = p->position - particle->position;
|
||||
// if (diff.length() < _radius)
|
||||
// {
|
||||
// displacement -= diff;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// particle->direction += displacement * deltaTime;
|
||||
// }
|
||||
|
||||
// // Deactivate spatial hashing
|
||||
// particleTechnique->setSpatialHashingUsed(false);
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
PUCollisionAvoidanceAffector* PUCollisionAvoidanceAffector::create()
|
||||
{
|
||||
auto pcaa = new (std::nothrow) PUCollisionAvoidanceAffector();
|
||||
pcaa->autorelease();
|
||||
return pcaa;
|
||||
}
|
||||
|
||||
void PUCollisionAvoidanceAffector::copyAttributesTo( PUAffector* affector )
|
||||
{
|
||||
PUAffector::copyAttributesTo(affector);
|
||||
PUCollisionAvoidanceAffector* collisionAvoidanceAffector = static_cast<PUCollisionAvoidanceAffector*>(affector);
|
||||
collisionAvoidanceAffector->_radius = _radius;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
65
extensions/Particle3D/PU/CCPUCollisionAvoidanceAffector.h
Normal file
65
extensions/Particle3D/PU/CCPUCollisionAvoidanceAffector.h
Normal file
@@ -0,0 +1,65 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#ifndef __CC_PU_PARTICLE_3D_COLLISION_AVOIDDANCE_AFFECTOR_H__
|
||||
#define __CC_PU_PARTICLE_3D_COLLISION_AVOIDDANCE_AFFECTOR_H__
|
||||
|
||||
#include "extensions/Particle3D/PU/CCPUAffector.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class CC_DLL PUCollisionAvoidanceAffector : public PUAffector
|
||||
{
|
||||
public:
|
||||
// Constants
|
||||
static const float DEFAULT_RADIUS;
|
||||
|
||||
static PUCollisionAvoidanceAffector* create();
|
||||
|
||||
virtual void updatePUAffector(PUParticle3D *particle, float deltaTime) override;
|
||||
|
||||
/** Todo
|
||||
*/
|
||||
float getRadius() const;
|
||||
|
||||
/** Todo
|
||||
*/
|
||||
void setRadius(float radius);
|
||||
|
||||
virtual void copyAttributesTo (PUAffector* affector) override;
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
PUCollisionAvoidanceAffector();
|
||||
virtual ~PUCollisionAvoidanceAffector();
|
||||
|
||||
protected:
|
||||
|
||||
float _radius;
|
||||
};
|
||||
NS_CC_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,66 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCPUCollisionAvoidanceAffectorTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUParticleSystem3D.h"
|
||||
#include "extensions/Particle3D/PU/CCPUDynamicAttribute.h"
|
||||
#include "extensions/Particle3D/PU/CCPUDynamicAttributeTranslator.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
PUCollisionAvoidanceAffectorTranslator::PUCollisionAvoidanceAffectorTranslator()
|
||||
{
|
||||
}
|
||||
//-------------------------------------------------------------------------
|
||||
bool PUCollisionAvoidanceAffectorTranslator::translateChildProperty( PUScriptCompiler* compiler, PUAbstractNode *node )
|
||||
{
|
||||
PUPropertyAbstractNode* prop = reinterpret_cast<PUPropertyAbstractNode*>(node);
|
||||
PUAffector* af = static_cast<PUAffector*>(prop->parent->context);
|
||||
PUCollisionAvoidanceAffector* affector = static_cast<PUCollisionAvoidanceAffector*>(af);
|
||||
|
||||
if (prop->name == token[TOKEN_AVOIDANCE_RADIUS])
|
||||
{
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_AVOIDANCE_RADIUS], VAL_REAL))
|
||||
{
|
||||
float val = 0.0f;
|
||||
if(getFloat(*prop->values.front(), &val))
|
||||
{
|
||||
affector->setRadius(val);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool PUCollisionAvoidanceAffectorTranslator::translateChildObject( PUScriptCompiler* /*compiler*/, PUAbstractNode* /*node*/ )
|
||||
{
|
||||
// No objects
|
||||
return false;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
@@ -0,0 +1,48 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __CC_PU_PARTICLE_3D_COLLISION_AVOIDDANCE_AFFECTOR_TRANSLATOR_H__
|
||||
#define __CC_PU_PARTICLE_3D_COLLISION_AVOIDDANCE_AFFECTOR_TRANSLATOR_H__
|
||||
|
||||
#include "extensions/Particle3D/PU/CCPUScriptTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUScriptCompiler.h"
|
||||
#include "extensions/Particle3D/PU/CCPUCollisionAvoidanceAffector.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class PUCollisionAvoidanceAffectorTranslator : public PUScriptTranslator
|
||||
{
|
||||
public:
|
||||
PUCollisionAvoidanceAffectorTranslator();
|
||||
virtual ~PUCollisionAvoidanceAffectorTranslator(){};
|
||||
|
||||
virtual bool translateChildProperty(PUScriptCompiler* compiler, PUAbstractNode *node);
|
||||
virtual bool translateChildObject(PUScriptCompiler* compiler, PUAbstractNode *node);
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif
|
||||
145
extensions/Particle3D/PU/CCPUColorAffector.cpp
Normal file
145
extensions/Particle3D/PU/CCPUColorAffector.cpp
Normal file
@@ -0,0 +1,145 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCPUColorAffector.h"
|
||||
#include "extensions/Particle3D/PU/CCPUParticleSystem3D.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
// Constants
|
||||
const PUColorAffector::ColorOperation PUColorAffector::DEFAULT_COLOR_OPERATION = PUColorAffector::CAO_SET;
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
PUColorAffector::PUColorAffector() :
|
||||
PUAffector(),
|
||||
_colorOperation(DEFAULT_COLOR_OPERATION)
|
||||
{
|
||||
}
|
||||
|
||||
PUColorAffector::~PUColorAffector()
|
||||
{
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
const PUColorAffector::ColorOperation& PUColorAffector::getColorOperation () const
|
||||
{
|
||||
return _colorOperation;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUColorAffector::setColorOperation (const PUColorAffector::ColorOperation& colorOperation)
|
||||
{
|
||||
_colorOperation = colorOperation;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUColorAffector::addColor (float timeFraction, const Vec4& color)
|
||||
{
|
||||
_colorMap[timeFraction] = color;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
const PUColorAffector::ColorMap& PUColorAffector::getTimeAndColor() const
|
||||
{
|
||||
return _colorMap;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUColorAffector::clearColorMap ()
|
||||
{
|
||||
_colorMap.clear();
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
PUColorAffector::ColorMapIterator PUColorAffector::findNearestColorMapIterator(float timeFraction)
|
||||
{
|
||||
ColorMapIterator it;
|
||||
for (it = _colorMap.begin(); it != _colorMap.end(); ++it)
|
||||
{
|
||||
if (timeFraction < it->first)
|
||||
{
|
||||
if (it == _colorMap.begin())
|
||||
return it;
|
||||
else
|
||||
return --it;
|
||||
}
|
||||
}
|
||||
|
||||
// If not found return the last valid iterator
|
||||
return --it;
|
||||
}
|
||||
|
||||
void PUColorAffector::updatePUAffector( PUParticle3D *particle, float /*deltaTime*/ )
|
||||
{
|
||||
// Fast rejection
|
||||
if (_colorMap.empty())
|
||||
return;
|
||||
|
||||
//for (auto iter : _particleSystem->getParticles())
|
||||
{
|
||||
//PUParticle3D *particle = iter;
|
||||
// Linear interpolation of the colour
|
||||
Vec4 color = Vec4::ONE;
|
||||
float timeFraction = (particle->totalTimeToLive - particle->timeToLive) / particle->totalTimeToLive;
|
||||
ColorMapIterator it1 = findNearestColorMapIterator(timeFraction);
|
||||
ColorMapIterator it2 = it1;
|
||||
++it2;
|
||||
if (it2 != _colorMap.end())
|
||||
{
|
||||
// Interpolate colour
|
||||
|
||||
color = it1->second + ((it2->second - it1->second) * ((timeFraction - it1->first)/(it2->first - it1->first)));
|
||||
}
|
||||
else
|
||||
{
|
||||
color = it1->second;
|
||||
}
|
||||
|
||||
// Determine operation
|
||||
if (_colorOperation == CAO_SET)
|
||||
{
|
||||
// No operation, so just set the colour
|
||||
particle->color = color;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Multiply
|
||||
particle->color = Vec4(color.x * particle->originalColor.x, color.y * particle->originalColor.y, color.z * particle->originalColor.z, color.w * particle->originalColor.w);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PUColorAffector* PUColorAffector::create()
|
||||
{
|
||||
auto pca = new (std::nothrow) PUColorAffector();
|
||||
pca->autorelease();
|
||||
return pca;
|
||||
}
|
||||
|
||||
void PUColorAffector::copyAttributesTo( PUAffector* affector )
|
||||
{
|
||||
PUAffector::copyAttributesTo(affector);
|
||||
|
||||
PUColorAffector* colourAffector = static_cast<PUColorAffector*>(affector);
|
||||
colourAffector->_colorMap = _colorMap;
|
||||
colourAffector->_colorOperation = _colorOperation;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
94
extensions/Particle3D/PU/CCPUColorAffector.h
Normal file
94
extensions/Particle3D/PU/CCPUColorAffector.h
Normal file
@@ -0,0 +1,94 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#ifndef __CC_PU_PARTICLE_3D_COLOR_AFFECTOR_H__
|
||||
#define __CC_PU_PARTICLE_3D_COLOR_AFFECTOR_H__
|
||||
|
||||
#include "extensions/Particle3D/PU/CCPUAffector.h"
|
||||
#include "base/ccTypes.h"
|
||||
#include <map>
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class CC_DLL PUColorAffector : public PUAffector
|
||||
{
|
||||
public:
|
||||
typedef std::map<float, Vec4> ColorMap;
|
||||
typedef std::map<float, Vec4>::iterator ColorMapIterator;
|
||||
enum ColorOperation
|
||||
{
|
||||
CAO_MULTIPLY,
|
||||
CAO_SET
|
||||
};
|
||||
|
||||
// Constants
|
||||
static const ColorOperation DEFAULT_COLOR_OPERATION;
|
||||
|
||||
static PUColorAffector* create();
|
||||
|
||||
virtual void updatePUAffector(PUParticle3D *particle, float deltaTime) override;
|
||||
|
||||
/**
|
||||
*/
|
||||
void addColor(float timeFraction, const Vec4& color);
|
||||
|
||||
/**
|
||||
*/
|
||||
const ColorMap& getTimeAndColor() const;
|
||||
|
||||
/**
|
||||
*/
|
||||
void clearColorMap ();
|
||||
|
||||
/**
|
||||
*/
|
||||
const ColorOperation& getColorOperation () const;
|
||||
|
||||
/**
|
||||
*/
|
||||
void setColorOperation (const ColorOperation& colorOperation);
|
||||
|
||||
virtual void copyAttributesTo (PUAffector* affector) override;
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
PUColorAffector();
|
||||
virtual ~PUColorAffector();
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
*/
|
||||
inline ColorMapIterator findNearestColorMapIterator(float timeFraction);
|
||||
|
||||
protected:
|
||||
|
||||
ColorMap _colorMap;
|
||||
ColorOperation _colorOperation;
|
||||
};
|
||||
NS_CC_END
|
||||
|
||||
#endif
|
||||
114
extensions/Particle3D/PU/CCPUColorAffectorTranslator.cpp
Normal file
114
extensions/Particle3D/PU/CCPUColorAffectorTranslator.cpp
Normal file
@@ -0,0 +1,114 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCPUColorAffectorTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUParticleSystem3D.h"
|
||||
#include "extensions/Particle3D/PU/CCPUDynamicAttribute.h"
|
||||
#include "extensions/Particle3D/PU/CCPUDynamicAttributeTranslator.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
PUColorAffectorTranslator::PUColorAffectorTranslator()
|
||||
{
|
||||
}
|
||||
//-------------------------------------------------------------------------
|
||||
bool PUColorAffectorTranslator::translateChildProperty( PUScriptCompiler* compiler, PUAbstractNode *node )
|
||||
{
|
||||
PUPropertyAbstractNode* prop = reinterpret_cast<PUPropertyAbstractNode*>(node);
|
||||
PUAffector* af = static_cast<PUAffector*>(prop->parent->context);
|
||||
PUColorAffector* affector = static_cast<PUColorAffector*>(af);
|
||||
|
||||
if (prop->name == token[TOKEN_TIME_COLOUR] || prop->name == token[TOKEN_COLOUR_TIME_COLOUR])
|
||||
{
|
||||
if (passValidatePropertyNumberOfValuesRange(compiler, prop, token[TOKEN_TIME_COLOUR], 4, 5))
|
||||
{
|
||||
int n = 0;
|
||||
float time;
|
||||
Vec4 colour;
|
||||
PUAbstractNodeList::const_iterator i = prop->values.begin();
|
||||
PUAbstractNodeList::const_iterator end = prop->values.end();
|
||||
while(i != end)
|
||||
{
|
||||
float v = 0;
|
||||
if(getFloat(**i, &v))
|
||||
{
|
||||
switch(n)
|
||||
{
|
||||
case 0:
|
||||
time = v;
|
||||
break;
|
||||
case 1:
|
||||
colour.x = v;
|
||||
break;
|
||||
case 2:
|
||||
colour.y = v;
|
||||
break;
|
||||
case 3:
|
||||
colour.z = v;
|
||||
break;
|
||||
case 4:
|
||||
colour.w = v;
|
||||
break;
|
||||
}
|
||||
}
|
||||
++n;
|
||||
++i;
|
||||
}
|
||||
affector->addColor(time, colour);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_COLOUR_OPERATION])
|
||||
{
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_COLOUR_OPERATION], VAL_STRING))
|
||||
{
|
||||
std::string val;
|
||||
if(getString(*prop->values.front(), &val))
|
||||
{
|
||||
if (val == token[TOKEN_COLOUR_SET])
|
||||
{
|
||||
affector->setColorOperation(PUColorAffector::CAO_SET);
|
||||
return true;
|
||||
}
|
||||
else if (val == token[TOKEN_COLOUR_MULTIPLY])
|
||||
{
|
||||
affector->setColorOperation(PUColorAffector::CAO_MULTIPLY);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool PUColorAffectorTranslator::translateChildObject( PUScriptCompiler* /*compiler*/, PUAbstractNode* /*node*/ )
|
||||
{
|
||||
// No objects
|
||||
return false;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
48
extensions/Particle3D/PU/CCPUColorAffectorTranslator.h
Normal file
48
extensions/Particle3D/PU/CCPUColorAffectorTranslator.h
Normal file
@@ -0,0 +1,48 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __CC_PU_PARTICLE_3D_COLOR_AFFECTOR_TRANSLATOR_H__
|
||||
#define __CC_PU_PARTICLE_3D_COLOR_AFFECTOR_TRANSLATOR_H__
|
||||
|
||||
#include "extensions/Particle3D/PU/CCPUScriptTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUScriptCompiler.h"
|
||||
#include "extensions/Particle3D/PU/CCPUColorAffector.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class PUColorAffectorTranslator : public PUScriptTranslator
|
||||
{
|
||||
public:
|
||||
PUColorAffectorTranslator();
|
||||
virtual ~PUColorAffectorTranslator(){};
|
||||
|
||||
virtual bool translateChildProperty(PUScriptCompiler* compiler, PUAbstractNode *node);
|
||||
virtual bool translateChildObject(PUScriptCompiler* compiler, PUAbstractNode *node);
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif
|
||||
97
extensions/Particle3D/PU/CCPUDoAffectorEventHandler.cpp
Normal file
97
extensions/Particle3D/PU/CCPUDoAffectorEventHandler.cpp
Normal file
@@ -0,0 +1,97 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "extensions/Particle3D/PU/CCPUDoAffectorEventHandler.h"
|
||||
#include "extensions/Particle3D/PU/CCPUAffector.h"
|
||||
#include "extensions/Particle3D/PU/CCPUParticleSystem3D.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
// Constants
|
||||
const bool PUDoAffectorEventHandler::DEFAULT_PRE_POST = false;
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
PUDoAffectorEventHandler::PUDoAffectorEventHandler() :
|
||||
PUEventHandler(),
|
||||
_prePost(DEFAULT_PRE_POST)
|
||||
{
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUDoAffectorEventHandler::handle (PUParticleSystem3D* particleSystem, PUParticle3D* particle, float timeElapsed)
|
||||
{
|
||||
/** Search for the affector.
|
||||
*/
|
||||
PUParticleSystem3D* technique = 0;
|
||||
PUAffector* affector = particleSystem->getAffector(_affectorName);
|
||||
if (!affector)
|
||||
{
|
||||
// Search all techniques in this ParticleSystem for an affector with the correct name
|
||||
PUParticleSystem3D* system = particleSystem->getParentParticleSystem();
|
||||
auto children = system->getChildren();
|
||||
for(auto iter : children)
|
||||
{
|
||||
technique = dynamic_cast<PUParticleSystem3D *>(iter);
|
||||
if (technique){
|
||||
affector = technique->getAffector(_affectorName);
|
||||
if (affector)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (affector)
|
||||
{
|
||||
// Call the affector even if it has enabled set to 'false'.
|
||||
if (_prePost)
|
||||
{
|
||||
affector->preUpdateAffector(timeElapsed);
|
||||
affector->updatePUAffector(particle, timeElapsed);
|
||||
affector->postUpdateAffector(timeElapsed);
|
||||
}
|
||||
else
|
||||
{
|
||||
affector->updatePUAffector(particle, timeElapsed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PUDoAffectorEventHandler* PUDoAffectorEventHandler::create()
|
||||
{
|
||||
auto peh = new (std::nothrow) PUDoAffectorEventHandler();
|
||||
peh->autorelease();
|
||||
return peh;
|
||||
}
|
||||
|
||||
void PUDoAffectorEventHandler::copyAttributesTo( PUEventHandler* eventHandler )
|
||||
{
|
||||
PUEventHandler::copyAttributesTo(eventHandler);
|
||||
PUDoAffectorEventHandler* doAffectorEventHandler = static_cast<PUDoAffectorEventHandler*>(eventHandler);
|
||||
doAffectorEventHandler->setAffectorName(_affectorName);
|
||||
doAffectorEventHandler->setPrePost(_prePost);
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
90
extensions/Particle3D/PU/CCPUDoAffectorEventHandler.h
Normal file
90
extensions/Particle3D/PU/CCPUDoAffectorEventHandler.h
Normal file
@@ -0,0 +1,90 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __CC_PU_PARTICLE_3D_DO_AFFECTOR_EVENT_HANDLER_H__
|
||||
#define __CC_PU_PARTICLE_3D_DO_AFFECTOR_EVENT_HANDLER_H__
|
||||
|
||||
#include "base/CCRef.h"
|
||||
#include "math/CCMath.h"
|
||||
#include "extensions/Particle3D/PU/CCPUEventHandler.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
struct PUParticle3D;
|
||||
class PUObserver;
|
||||
class PUParticleSystem3D;
|
||||
|
||||
class CC_DLL PUDoAffectorEventHandler : public PUEventHandler
|
||||
{
|
||||
public:
|
||||
// Constants
|
||||
static const bool DEFAULT_PRE_POST;
|
||||
|
||||
static PUDoAffectorEventHandler* create();
|
||||
|
||||
/** Get the indication whether pre- and postprocessing must be done.
|
||||
*/
|
||||
bool getPrePost() const {return _prePost;};
|
||||
|
||||
/** Set the indication whether pre- and postprocessing must be done.
|
||||
*/
|
||||
void setPrePost(const bool prePost){_prePost = prePost;};
|
||||
|
||||
/** Get the name of the affector that must be enabled or disabled.
|
||||
*/
|
||||
const std::string& getAffectorName() const {return _affectorName;};
|
||||
|
||||
/** Set the name of the affector.
|
||||
*/
|
||||
void setAffectorName(const std::string& affectorName){_affectorName = affectorName;};
|
||||
|
||||
/** If the _handle() function of this class is invoked (by an Observer), it searches the
|
||||
ParticleAffector defined by the its name.
|
||||
The ParticleAffector is either part of the ParticleTechnique in which the
|
||||
DoAffectorEventHandler is defined, or if the Affector is not found, other
|
||||
ParticleTechniques are searched.
|
||||
*/
|
||||
virtual void handle (PUParticleSystem3D* particleSystem, PUParticle3D* particle, float timeElapsed) override;
|
||||
|
||||
virtual void copyAttributesTo (PUEventHandler* eventHandler) override;
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
PUDoAffectorEventHandler();
|
||||
virtual ~PUDoAffectorEventHandler() {};
|
||||
|
||||
protected:
|
||||
// Identifies the name of affector
|
||||
std::string _affectorName;
|
||||
|
||||
// Determines whether the pre- and post processing activities must be executed also
|
||||
bool _prePost;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,80 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCPUDoAffectorEventHandlerTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUParticleSystem3D.h"
|
||||
#include "extensions/Particle3D/PU/CCPUDynamicAttribute.h"
|
||||
#include "extensions/Particle3D/PU/CCPUDynamicAttributeTranslator.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
PUDoAffectorEventHandlerTranslator::PUDoAffectorEventHandlerTranslator()
|
||||
{
|
||||
}
|
||||
//-------------------------------------------------------------------------
|
||||
bool PUDoAffectorEventHandlerTranslator::translateChildProperty( PUScriptCompiler* compiler, PUAbstractNode *node )
|
||||
{
|
||||
PUPropertyAbstractNode* prop = reinterpret_cast<PUPropertyAbstractNode*>(node);
|
||||
PUEventHandler* evt = static_cast<PUEventHandler *>(prop->parent->context);
|
||||
PUDoAffectorEventHandler* handler = static_cast<PUDoAffectorEventHandler*>(evt);
|
||||
|
||||
if (prop->name == token[TOKEN_FORCE_AFFECTOR])
|
||||
{
|
||||
// Property: force_affector
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_FORCE_AFFECTOR], VAL_STRING))
|
||||
{
|
||||
std::string val;
|
||||
if(getString(*prop->values.front(), &val))
|
||||
{
|
||||
handler->setAffectorName(val);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_FORCE_AFFECTOR_PRE_POST])
|
||||
{
|
||||
// Property: pre_post
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_FORCE_AFFECTOR_PRE_POST], VAL_BOOL))
|
||||
{
|
||||
bool val;
|
||||
if(getBoolean(*prop->values.front(), &val))
|
||||
{
|
||||
handler->setPrePost(val);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool PUDoAffectorEventHandlerTranslator::translateChildObject( PUScriptCompiler* /*compiler*/, PUAbstractNode* /*node*/ )
|
||||
{
|
||||
// No objects
|
||||
return false;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
@@ -0,0 +1,48 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __CC_PU_PARTICLE_3D_DO_AFFECTOR_EVENT_HANDLER_TRANSLATOR_H__
|
||||
#define __CC_PU_PARTICLE_3D_DO_AFFECTOR_EVENT_HANDLER_TRANSLATOR_H__
|
||||
|
||||
#include "extensions/Particle3D/PU/CCPUScriptTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUScriptCompiler.h"
|
||||
#include "extensions/Particle3D/PU/CCPUDoAffectorEventHandler.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class PUDoAffectorEventHandlerTranslator : public PUScriptTranslator
|
||||
{
|
||||
public:
|
||||
PUDoAffectorEventHandlerTranslator();
|
||||
virtual ~PUDoAffectorEventHandlerTranslator(){};
|
||||
|
||||
virtual bool translateChildProperty(PUScriptCompiler* compiler, PUAbstractNode *node);
|
||||
virtual bool translateChildObject(PUScriptCompiler* compiler, PUAbstractNode *node);
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif
|
||||
172
extensions/Particle3D/PU/CCPUDoEnableComponentEventHandler.cpp
Normal file
172
extensions/Particle3D/PU/CCPUDoEnableComponentEventHandler.cpp
Normal file
@@ -0,0 +1,172 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "extensions/Particle3D/PU/CCPUDoEnableComponentEventHandler.h"
|
||||
#include "extensions/Particle3D/PU/CCPUAffector.h"
|
||||
#include "extensions/Particle3D/PU/CCPUEmitter.h"
|
||||
#include "extensions/Particle3D/PU/CCPUObserver.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
//-----------------------------------------------------------------------
|
||||
PUDoEnableComponentEventHandler::PUDoEnableComponentEventHandler() :
|
||||
PUEventHandler(),
|
||||
_componentType(CT_EMITTER),
|
||||
_componentEnabled(true)
|
||||
{
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUDoEnableComponentEventHandler::handle (PUParticleSystem3D* particleSystem, PUParticle3D* /*particle*/, float /*timeElapsed*/)
|
||||
{
|
||||
/** Search for the component.
|
||||
*/
|
||||
//ParticleTechnique* technique = 0;
|
||||
switch (_componentType)
|
||||
{
|
||||
case CT_EMITTER:
|
||||
{
|
||||
PUEmitter* emitter = particleSystem->getEmitter(_componentName);
|
||||
if (!emitter)
|
||||
{
|
||||
// Search all techniques in this ParticleSystem for an emitter with the correct name
|
||||
PUParticleSystem3D* system = particleSystem->getParentParticleSystem();
|
||||
if (system){
|
||||
auto children = system->getChildren();
|
||||
for(auto iter : children)
|
||||
{
|
||||
PUParticleSystem3D *child = dynamic_cast<PUParticleSystem3D *>(iter);
|
||||
if (child){
|
||||
emitter = child->getEmitter(_componentName);
|
||||
if (emitter)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (emitter)
|
||||
{
|
||||
emitter->setEnabled(_componentEnabled);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case CT_AFFECTOR:
|
||||
{
|
||||
PUAffector* affector = particleSystem->getAffector(_componentName);
|
||||
if (!affector)
|
||||
{
|
||||
// Search all techniques in this ParticleSystem for an emitter with the correct name
|
||||
PUParticleSystem3D* system = particleSystem->getParentParticleSystem();
|
||||
if (system){
|
||||
auto children = system->getChildren();
|
||||
for(auto iter : children)
|
||||
{
|
||||
PUParticleSystem3D *child = dynamic_cast<PUParticleSystem3D *>(iter);
|
||||
if (child){
|
||||
affector = child->getAffector(_componentName);
|
||||
if (affector)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (affector)
|
||||
{
|
||||
affector->setEnabled(_componentEnabled);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case CT_OBSERVER:
|
||||
{
|
||||
PUObserver* observer = particleSystem->getObserver(_componentName);
|
||||
if (!observer)
|
||||
{
|
||||
// Search all techniques in this ParticleSystem for an emitter with the correct name
|
||||
PUParticleSystem3D* system = particleSystem->getParentParticleSystem();
|
||||
if (system){
|
||||
auto children = system->getChildren();
|
||||
for(auto iter : children)
|
||||
{
|
||||
PUParticleSystem3D *child = dynamic_cast<PUParticleSystem3D *>(iter);
|
||||
if (child){
|
||||
observer = child->getObserver(_componentName);
|
||||
if (observer)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (observer)
|
||||
{
|
||||
observer->setEnabled(_componentEnabled);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case CT_TECHNIQUE:
|
||||
{
|
||||
// Search in this ParticleSystem for a technique with the correct name
|
||||
PUParticleSystem3D* system = particleSystem->getParentParticleSystem();
|
||||
if (system){
|
||||
auto children = system->getChildren();
|
||||
for (auto iter : children){
|
||||
PUParticleSystem3D *child = dynamic_cast<PUParticleSystem3D *>(iter);
|
||||
if (child && child->getName() == _componentName){
|
||||
child->setEnabled(_componentEnabled);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
PUDoEnableComponentEventHandler* PUDoEnableComponentEventHandler::create()
|
||||
{
|
||||
auto peh = new (std::nothrow) PUDoEnableComponentEventHandler();
|
||||
peh->autorelease();
|
||||
return peh;
|
||||
}
|
||||
|
||||
void PUDoEnableComponentEventHandler::copyAttributesTo( PUEventHandler* eventHandler )
|
||||
{
|
||||
PUEventHandler::copyAttributesTo(eventHandler);
|
||||
PUDoEnableComponentEventHandler* doEnableComponentEventHandler = static_cast<PUDoEnableComponentEventHandler*>(eventHandler);
|
||||
doEnableComponentEventHandler->setComponentType(_componentType);
|
||||
doEnableComponentEventHandler->setComponentName(_componentName);
|
||||
doEnableComponentEventHandler->setComponentEnabled(_componentEnabled);
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
102
extensions/Particle3D/PU/CCPUDoEnableComponentEventHandler.h
Normal file
102
extensions/Particle3D/PU/CCPUDoEnableComponentEventHandler.h
Normal file
@@ -0,0 +1,102 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __CC_PU_PARTICLE_3D_DO_ENABLE_COMPONENT_EVENT_HANDLER_H__
|
||||
#define __CC_PU_PARTICLE_3D_DO_ENABLE_COMPONENT_EVENT_HANDLER_H__
|
||||
|
||||
#include "base/CCRef.h"
|
||||
#include "math/CCMath.h"
|
||||
#include "extensions/Particle3D/PU/CCPUParticleSystem3D.h"
|
||||
#include "extensions/Particle3D/PU/CCPUEventHandler.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
struct PUParticle3D;
|
||||
class PUObserver;
|
||||
class PUParticleSystem3D;
|
||||
|
||||
class CC_DLL PUDoEnableComponentEventHandler : public PUEventHandler
|
||||
{
|
||||
public:
|
||||
|
||||
static PUDoEnableComponentEventHandler* create();
|
||||
|
||||
/** Get the name of the component that must be enabled or disabled.
|
||||
*/
|
||||
const std::string& getComponentName() const {return _componentName;};
|
||||
|
||||
/** Set the name of the component that must be enabled or disables.
|
||||
*/
|
||||
void setComponentName(const std::string& componentName){_componentName = componentName;};
|
||||
|
||||
/** Get the value that identifies whether the component must be enabled or disabled.
|
||||
*/
|
||||
bool isComponentEnabled() const {return _componentEnabled;};
|
||||
|
||||
/** Set the value that identifies whether the component must be enabled or disabled.
|
||||
*/
|
||||
void setComponentEnabled(bool enabled){_componentEnabled = enabled;};
|
||||
|
||||
/** Get the value that identifies whether the component must be enabled or disabled.
|
||||
*/
|
||||
PUComponentType getComponentType() const {return _componentType;};
|
||||
|
||||
/** Set the value that identifies whether the component must be enabled or disabled.
|
||||
*/
|
||||
void setComponentType(PUComponentType componentType){_componentType = componentType;};
|
||||
|
||||
/** If the _handle() function of this class is invoked (by an Observer), it searches the
|
||||
ParticleEmitter, ParticleAffector or ParticleTechnique defined by the its name.
|
||||
The ParticleEmitter/Affector is either part of the ParticleTechnique in which the
|
||||
DoEnableComponentEventHandler is defined, or if the ParticleEmitter/Affector is not
|
||||
found, other ParticleTechniques are searched.
|
||||
*/
|
||||
virtual void handle (PUParticleSystem3D* particleSystem, PUParticle3D* particle, float timeElapsed) override;
|
||||
|
||||
virtual void copyAttributesTo (PUEventHandler* eventHandler) override;
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
PUDoEnableComponentEventHandler();
|
||||
virtual ~PUDoEnableComponentEventHandler() {};
|
||||
|
||||
protected:
|
||||
// Identifies the name of component
|
||||
std::string _componentName;
|
||||
|
||||
// Identifies the type of component
|
||||
PUComponentType _componentType;
|
||||
|
||||
/** Determines whether the Component must be enabled or disabled.
|
||||
*/
|
||||
bool _componentEnabled;
|
||||
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,95 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCPUDoEnableComponentEventHandlerTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUParticleSystem3D.h"
|
||||
#include "extensions/Particle3D/PU/CCPUDynamicAttribute.h"
|
||||
#include "extensions/Particle3D/PU/CCPUDynamicAttributeTranslator.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
PUDoEnableComponentEventHandlerTranslator::PUDoEnableComponentEventHandlerTranslator()
|
||||
{
|
||||
}
|
||||
//-------------------------------------------------------------------------
|
||||
bool PUDoEnableComponentEventHandlerTranslator::translateChildProperty( PUScriptCompiler* compiler, PUAbstractNode *node )
|
||||
{
|
||||
PUPropertyAbstractNode* prop = reinterpret_cast<PUPropertyAbstractNode*>(node);
|
||||
PUEventHandler* evt = static_cast<PUEventHandler *>(prop->parent->context);
|
||||
PUDoEnableComponentEventHandler* handler = static_cast<PUDoEnableComponentEventHandler*>(evt);
|
||||
|
||||
if (prop->name == token[TOKEN_DOENABLE_COMPONENT])
|
||||
{
|
||||
// Property: enable_component
|
||||
if (passValidatePropertyNumberOfValues(compiler, prop, token[TOKEN_DOENABLE_COMPONENT], 3))
|
||||
{
|
||||
std::string componentType;
|
||||
std::string name;
|
||||
bool enabled = true;
|
||||
PUAbstractNodeList::const_iterator i = prop->values.begin();
|
||||
if(getString(**i, &componentType))
|
||||
{
|
||||
if (componentType == token[TOKEN_DOENABLE_EMITTER_COMPONENT])
|
||||
{
|
||||
handler->setComponentType(CT_EMITTER);
|
||||
}
|
||||
else if (componentType == token[TOKEN_DOENABLE_AFFECTOR_COMPONENT])
|
||||
{
|
||||
handler->setComponentType(CT_AFFECTOR);
|
||||
}
|
||||
else if (componentType == token[TOKEN_DOENABLE_OBSERVER_COMPONENT])
|
||||
{
|
||||
handler->setComponentType(CT_OBSERVER);
|
||||
}
|
||||
else if (componentType == token[TOKEN_DOENABLE_TECHNIQUE_COMPONENT])
|
||||
{
|
||||
handler->setComponentType(CT_TECHNIQUE);
|
||||
}
|
||||
++i;
|
||||
if(getString(**i, &name))
|
||||
{
|
||||
handler->setComponentName(name);
|
||||
++i;
|
||||
if (getBoolean(**i, &enabled))
|
||||
{
|
||||
handler->setComponentEnabled(enabled);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool PUDoEnableComponentEventHandlerTranslator::translateChildObject( PUScriptCompiler* /*compiler*/, PUAbstractNode* /*node*/ )
|
||||
{
|
||||
// No objects
|
||||
return false;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
@@ -0,0 +1,48 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __CC_PU_PARTICLE_3D_DO_ENABLE_COMPONENT_EVENT_HANDLER_TRANSLATOR_H__
|
||||
#define __CC_PU_PARTICLE_3D_DO_ENABLE_COMPONENT_EVENT_HANDLER_TRANSLATOR_H__
|
||||
|
||||
#include "extensions/Particle3D/PU/CCPUScriptTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUScriptCompiler.h"
|
||||
#include "extensions/Particle3D/PU/CCPUDoEnableComponentEventHandler.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class PUDoEnableComponentEventHandlerTranslator : public PUScriptTranslator
|
||||
{
|
||||
public:
|
||||
PUDoEnableComponentEventHandlerTranslator();
|
||||
virtual ~PUDoEnableComponentEventHandlerTranslator(){};
|
||||
|
||||
virtual bool translateChildProperty(PUScriptCompiler* compiler, PUAbstractNode *node);
|
||||
virtual bool translateChildObject(PUScriptCompiler* compiler, PUAbstractNode *node);
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif
|
||||
49
extensions/Particle3D/PU/CCPUDoExpireEventHandler.cpp
Normal file
49
extensions/Particle3D/PU/CCPUDoExpireEventHandler.cpp
Normal file
@@ -0,0 +1,49 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "extensions/Particle3D/PU/CCPUDoExpireEventHandler.h"
|
||||
#include "extensions/Particle3D/PU/CCPUAffector.h"
|
||||
#include "extensions/Particle3D/PU/CCPUParticleSystem3D.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
void PUDoExpireEventHandler::handle (PUParticleSystem3D* /*particleSystem*/, PUParticle3D* particle, float /*timeElapsed*/)
|
||||
{
|
||||
if (!particle)
|
||||
return;
|
||||
|
||||
particle->timeToLive = 0.0f;
|
||||
}
|
||||
|
||||
PUDoExpireEventHandler* PUDoExpireEventHandler::create()
|
||||
{
|
||||
auto peh = new (std::nothrow) PUDoExpireEventHandler();
|
||||
peh->autorelease();
|
||||
return peh;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
69
extensions/Particle3D/PU/CCPUDoExpireEventHandler.h
Normal file
69
extensions/Particle3D/PU/CCPUDoExpireEventHandler.h
Normal file
@@ -0,0 +1,69 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __CC_PU_PARTICLE_3D_DO_EXPIRE_EVENT_HANDLER_H__
|
||||
#define __CC_PU_PARTICLE_3D_DO_EXPIRE_EVENT_HANDLER_H__
|
||||
|
||||
#include "base/CCRef.h"
|
||||
#include "math/CCMath.h"
|
||||
#include "extensions/Particle3D/PU/CCPUEventHandler.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
struct PUParticle3D;
|
||||
class PUObserver;
|
||||
class PUParticleSystem3D;
|
||||
|
||||
class CC_DLL PUDoExpireEventHandler : public PUEventHandler
|
||||
{
|
||||
public:
|
||||
|
||||
static PUDoExpireEventHandler* create();
|
||||
|
||||
///** Get indication that all particles are expired
|
||||
//*/
|
||||
//bool getExpireAll();
|
||||
|
||||
///** Set indication that all particles are expired
|
||||
//*/
|
||||
//void setExpireAll(bool expireAll);
|
||||
|
||||
/**
|
||||
*/
|
||||
virtual void handle (PUParticleSystem3D* particleSystem, PUParticle3D* particle, float timeElapsed) override;
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
PUDoExpireEventHandler() : PUEventHandler()
|
||||
{
|
||||
}
|
||||
virtual ~PUDoExpireEventHandler() {};
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,49 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCPUDoExpireEventHandlerTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUParticleSystem3D.h"
|
||||
#include "extensions/Particle3D/PU/CCPUDynamicAttribute.h"
|
||||
#include "extensions/Particle3D/PU/CCPUDynamicAttributeTranslator.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
PUDoExpireEventHandlerTranslator::PUDoExpireEventHandlerTranslator()
|
||||
{
|
||||
}
|
||||
//-------------------------------------------------------------------------
|
||||
bool PUDoExpireEventHandlerTranslator::translateChildProperty( PUScriptCompiler* /*compiler*/, PUAbstractNode* /*node*/ )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool PUDoExpireEventHandlerTranslator::translateChildObject( PUScriptCompiler* /*compiler*/, PUAbstractNode* /*node*/ )
|
||||
{
|
||||
// No objects
|
||||
return false;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
@@ -0,0 +1,48 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __CC_PU_PARTICLE_3D_DO_EXPIRE_EVENT_HANDLER_TRANSLATOR_H__
|
||||
#define __CC_PU_PARTICLE_3D_DO_EXPIRE_EVENT_HANDLER_TRANSLATOR_H__
|
||||
|
||||
#include "extensions/Particle3D/PU/CCPUScriptTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUScriptCompiler.h"
|
||||
#include "extensions/Particle3D/PU/CCPUDoExpireEventHandler.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class PUDoExpireEventHandlerTranslator : public PUScriptTranslator
|
||||
{
|
||||
public:
|
||||
PUDoExpireEventHandlerTranslator();
|
||||
virtual ~PUDoExpireEventHandlerTranslator(){};
|
||||
|
||||
virtual bool translateChildProperty(PUScriptCompiler* compiler, PUAbstractNode *node);
|
||||
virtual bool translateChildObject(PUScriptCompiler* compiler, PUAbstractNode *node);
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif
|
||||
49
extensions/Particle3D/PU/CCPUDoFreezeEventHandler.cpp
Normal file
49
extensions/Particle3D/PU/CCPUDoFreezeEventHandler.cpp
Normal file
@@ -0,0 +1,49 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "extensions/Particle3D/PU/CCPUDoFreezeEventHandler.h"
|
||||
#include "extensions/Particle3D/PU/CCPUAffector.h"
|
||||
#include "extensions/Particle3D/PU/CCPUParticleSystem3D.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
void PUDoFreezeEventHandler::handle (PUParticleSystem3D* /*particleSystem*/, PUParticle3D* particle, float /*timeElapsed*/)
|
||||
{
|
||||
if (!particle)
|
||||
return;
|
||||
|
||||
particle->setFreezed(true);
|
||||
}
|
||||
|
||||
PUDoFreezeEventHandler* PUDoFreezeEventHandler::create()
|
||||
{
|
||||
auto peh = new (std::nothrow) PUDoFreezeEventHandler();
|
||||
peh->autorelease();
|
||||
return peh;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
61
extensions/Particle3D/PU/CCPUDoFreezeEventHandler.h
Normal file
61
extensions/Particle3D/PU/CCPUDoFreezeEventHandler.h
Normal file
@@ -0,0 +1,61 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __CC_PU_PARTICLE_3D_DO_FREEZE_EVENT_HANDLER_H__
|
||||
#define __CC_PU_PARTICLE_3D_DO_FREEZE_EVENT_HANDLER_H__
|
||||
|
||||
#include "base/CCRef.h"
|
||||
#include "math/CCMath.h"
|
||||
#include "extensions/Particle3D/PU/CCPUEventHandler.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
struct PUParticle3D;
|
||||
class PUObserver;
|
||||
class PUParticleSystem3D;
|
||||
|
||||
class CC_DLL PUDoFreezeEventHandler : public PUEventHandler
|
||||
{
|
||||
public:
|
||||
|
||||
static PUDoFreezeEventHandler* create();
|
||||
|
||||
/**
|
||||
*/
|
||||
virtual void handle (PUParticleSystem3D* particleSystem, PUParticle3D* particle, float timeElapsed) override;
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
PUDoFreezeEventHandler() : PUEventHandler()
|
||||
{
|
||||
}
|
||||
virtual ~PUDoFreezeEventHandler() {};
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,49 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCPUDoFreezeEventHandlerTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUParticleSystem3D.h"
|
||||
#include "extensions/Particle3D/PU/CCPUDynamicAttribute.h"
|
||||
#include "extensions/Particle3D/PU/CCPUDynamicAttributeTranslator.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
PUDoFreezeEventHandlerTranslator::PUDoFreezeEventHandlerTranslator()
|
||||
{
|
||||
}
|
||||
//-------------------------------------------------------------------------
|
||||
bool PUDoFreezeEventHandlerTranslator::translateChildProperty( PUScriptCompiler* /*compiler*/, PUAbstractNode* /*node*/ )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool PUDoFreezeEventHandlerTranslator::translateChildObject( PUScriptCompiler* /*compiler*/, PUAbstractNode* /*node*/ )
|
||||
{
|
||||
// No objects
|
||||
return false;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
@@ -0,0 +1,48 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __CC_PU_PARTICLE_3D_DO_FREEZE_EVENT_HANDLER_TRANSLATOR_H__
|
||||
#define __CC_PU_PARTICLE_3D_DO_FREEZE_EVENT_HANDLER_TRANSLATOR_H__
|
||||
|
||||
#include "extensions/Particle3D/PU/CCPUScriptTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUScriptCompiler.h"
|
||||
#include "extensions/Particle3D/PU/CCPUDoFreezeEventHandler.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class PUDoFreezeEventHandlerTranslator : public PUScriptTranslator
|
||||
{
|
||||
public:
|
||||
PUDoFreezeEventHandlerTranslator();
|
||||
virtual ~PUDoFreezeEventHandlerTranslator(){};
|
||||
|
||||
virtual bool translateChildProperty(PUScriptCompiler* compiler, PUAbstractNode *node);
|
||||
virtual bool translateChildObject(PUScriptCompiler* compiler, PUAbstractNode *node);
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif
|
||||
278
extensions/Particle3D/PU/CCPUDoPlacementParticleEventHandler.cpp
Normal file
278
extensions/Particle3D/PU/CCPUDoPlacementParticleEventHandler.cpp
Normal file
@@ -0,0 +1,278 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "extensions/Particle3D/PU/CCPUDoPlacementParticleEventHandler.h"
|
||||
#include "extensions/Particle3D/PU/CCPUAffector.h"
|
||||
#include "extensions/Particle3D/PU/CCPUParticleSystem3D.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
// Constants
|
||||
const unsigned int PUDoPlacementParticleEventHandler::DEFAULT_NUMBER_OF_PARTICLES = 1;
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
PUDoPlacementParticleEventHandler::PUDoPlacementParticleEventHandler() :
|
||||
PUEventHandler(),
|
||||
PUListener(),
|
||||
_numberOfParticles(DEFAULT_NUMBER_OF_PARTICLES),
|
||||
_system(0),
|
||||
_emitter(0),
|
||||
_found(false),
|
||||
_alwaysUsePosition(true),
|
||||
_baseParticle(0),
|
||||
_inheritPosition(true),
|
||||
_inheritDirection(false),
|
||||
_inheritOrientation(false),
|
||||
_inheritTimeToLive(false),
|
||||
_inheritMass(false),
|
||||
_inheritTextureCoordinate(false),
|
||||
_inheritColour(false),
|
||||
_inheritParticleWidth(false),
|
||||
_inheritParticleHeight(false),
|
||||
_inheritParticleDepth(false)
|
||||
{
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
PUDoPlacementParticleEventHandler::~PUDoPlacementParticleEventHandler()
|
||||
{
|
||||
// We cannot remove this listener from mTechnique, because it is undetermined whether the ParticleTechnique
|
||||
// still exist.
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUDoPlacementParticleEventHandler::handle (PUParticleSystem3D* particleSystem, PUParticle3D* particle, float /*timeElapsed*/)
|
||||
{
|
||||
if (!particle)
|
||||
return;
|
||||
|
||||
if (!_found)
|
||||
{
|
||||
auto system = particleSystem;
|
||||
auto emitter = system->getEmitter(_forceEmitterName);
|
||||
//ParticleTechnique* technique = particleTechnique;
|
||||
//ParticleEmitter* emitter = particleTechnique->getEmitter(_forceEmitterName);
|
||||
if (!emitter)
|
||||
{
|
||||
// Search all techniques in this ParticleSystem for an emitter with the correct name
|
||||
PUParticleSystem3D* parentSystem = particleSystem->getParentParticleSystem();
|
||||
if (parentSystem){
|
||||
auto children = parentSystem->getChildren();
|
||||
for(auto iter : children)
|
||||
{
|
||||
PUParticleSystem3D *child = dynamic_cast<PUParticleSystem3D *>(iter);
|
||||
if (child){
|
||||
system = child;
|
||||
emitter = system->getEmitter(_forceEmitterName);
|
||||
if (emitter)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (emitter)
|
||||
{
|
||||
_system = system;
|
||||
_emitter = emitter;
|
||||
if (_system)
|
||||
{
|
||||
_system->addListener(this);
|
||||
}
|
||||
_found = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Emit 1 or more particles
|
||||
if (_system)
|
||||
{
|
||||
_baseParticle = particle;
|
||||
_system->forceEmission(_emitter, _numberOfParticles);
|
||||
}
|
||||
|
||||
_baseParticle = 0;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUDoPlacementParticleEventHandler::particleEmitted(PUParticleSystem3D* /*particleSystem*/, PUParticle3D* particle)
|
||||
{
|
||||
if (!_baseParticle)
|
||||
return;
|
||||
|
||||
if (particle && _emitter == particle->parentEmitter)
|
||||
{
|
||||
if (_inheritPosition)
|
||||
{
|
||||
#ifdef PU_PHYSICS
|
||||
// Do not assume that the contact point is always used if a physics engine is used.
|
||||
if (!_alwaysUsePosition && particle->physicsActor)
|
||||
{
|
||||
particle->position = _baseParticle->physicsActor->contactPoint; // Store the contact point to spawn new particles on that position.
|
||||
}
|
||||
else
|
||||
{
|
||||
particle->position = _baseParticle->position; // Store the particles' position to spawn new particles on that position.
|
||||
}
|
||||
#else
|
||||
particle->position = _baseParticle->position; // Store the particles' position to spawn new particles on that position.
|
||||
#endif // PU_PHYSICS
|
||||
particle->originalPosition = particle->position;
|
||||
}
|
||||
if (_inheritDirection)
|
||||
{
|
||||
particle->direction = _baseParticle->direction;
|
||||
particle->originalDirection = particle->direction;
|
||||
particle->originalDirectionLength = _baseParticle->originalDirectionLength;
|
||||
particle->originalScaledDirectionLength = _baseParticle->originalScaledDirectionLength;
|
||||
particle->originalVelocity = _baseParticle->originalVelocity;
|
||||
}
|
||||
if (_inheritOrientation)
|
||||
{
|
||||
if (_baseParticle->particleType == PUParticle3D::PT_VISUAL && particle->particleType == PUParticle3D::PT_VISUAL)
|
||||
{
|
||||
//VisualParticle* visualBaseParticle = static_cast<VisualParticle*>(_baseParticle);
|
||||
//VisualParticle* visualParticle = static_cast<VisualParticle*>(particle);
|
||||
particle->orientation = _baseParticle->orientation;
|
||||
particle->originalOrientation = _baseParticle->originalOrientation;
|
||||
}
|
||||
}
|
||||
if (_inheritTimeToLive)
|
||||
{
|
||||
particle->timeToLive = _baseParticle->timeToLive;
|
||||
particle->totalTimeToLive = _baseParticle->totalTimeToLive;
|
||||
particle->timeFraction = _baseParticle->timeFraction;
|
||||
}
|
||||
if (_inheritMass)
|
||||
{
|
||||
particle->mass = _baseParticle->mass;
|
||||
}
|
||||
if (_inheritTextureCoordinate)
|
||||
{
|
||||
if (_baseParticle->particleType == PUParticle3D::PT_VISUAL && particle->particleType == PUParticle3D::PT_VISUAL)
|
||||
{
|
||||
//VisualParticle* visualBaseParticle = static_cast<VisualParticle*>(_baseParticle);
|
||||
//VisualParticle* visualParticle = static_cast<VisualParticle*>(particle);
|
||||
particle->textureAnimationTimeStep = _baseParticle->textureAnimationTimeStep;
|
||||
particle->textureAnimationTimeStepCount = _baseParticle->textureAnimationTimeStepCount;
|
||||
particle->textureCoordsCurrent = _baseParticle->textureCoordsCurrent;
|
||||
particle->textureAnimationDirectionUp = _baseParticle->textureAnimationDirectionUp;
|
||||
}
|
||||
}
|
||||
if (_inheritColour)
|
||||
{
|
||||
if (_baseParticle->particleType == PUParticle3D::PT_VISUAL && particle->particleType == PUParticle3D::PT_VISUAL)
|
||||
{
|
||||
//VisualParticle* visualBaseParticle = static_cast<VisualParticle*>(_baseParticle);
|
||||
//VisualParticle* visualParticle = static_cast<VisualParticle*>(particle);
|
||||
particle->color = _baseParticle->color;
|
||||
particle->originalColor = _baseParticle->originalColor;
|
||||
}
|
||||
}
|
||||
if (_inheritParticleWidth)
|
||||
{
|
||||
if (_baseParticle->particleType == PUParticle3D::PT_VISUAL && particle->particleType == PUParticle3D::PT_VISUAL)
|
||||
{
|
||||
//VisualParticle* visualBaseParticle = static_cast<VisualParticle*>(_baseParticle);
|
||||
//VisualParticle* visualParticle = static_cast<VisualParticle*>(particle);
|
||||
particle->setOwnDimensions(_baseParticle->width, particle->height, particle->depth);
|
||||
}
|
||||
}
|
||||
if (_inheritParticleHeight)
|
||||
{
|
||||
if (_baseParticle->particleType == PUParticle3D::PT_VISUAL && particle->particleType == PUParticle3D::PT_VISUAL)
|
||||
{
|
||||
//VisualParticle* visualBaseParticle = static_cast<VisualParticle*>(_baseParticle);
|
||||
//VisualParticle* visualParticle = static_cast<VisualParticle*>(particle);
|
||||
particle->setOwnDimensions(particle->width, _baseParticle->height, particle->depth);
|
||||
}
|
||||
}
|
||||
if (_inheritParticleDepth)
|
||||
{
|
||||
if (_baseParticle->particleType == PUParticle3D::PT_VISUAL && particle->particleType == PUParticle3D::PT_VISUAL)
|
||||
{
|
||||
//VisualParticle* visualBaseParticle = static_cast<VisualParticle*>(_baseParticle);
|
||||
//VisualParticle* visualParticle = static_cast<VisualParticle*>(particle);
|
||||
particle->setOwnDimensions(particle->width, particle->height, _baseParticle->depth);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PUDoPlacementParticleEventHandler::particleExpired(PUParticleSystem3D* /*particleSystem*/, PUParticle3D* /*particle*/)
|
||||
{}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
void PUDoPlacementParticleEventHandler::setForceEmitterName(const std::string& forceEmitterName)
|
||||
{
|
||||
_forceEmitterName = forceEmitterName;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
PUEmitter* PUDoPlacementParticleEventHandler::getForceEmitter() const
|
||||
{
|
||||
return _emitter;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUDoPlacementParticleEventHandler::removeAsListener()
|
||||
{
|
||||
// Reset some values and remove this as a listener from the old technique.
|
||||
if (_system)
|
||||
{
|
||||
_system->removeListener(this);
|
||||
}
|
||||
_found = false;
|
||||
_emitter = 0;
|
||||
_system = 0;
|
||||
}
|
||||
|
||||
PUDoPlacementParticleEventHandler* PUDoPlacementParticleEventHandler::create()
|
||||
{
|
||||
auto peh = new (std::nothrow) PUDoPlacementParticleEventHandler();
|
||||
peh->autorelease();
|
||||
return peh;
|
||||
}
|
||||
|
||||
void PUDoPlacementParticleEventHandler::copyAttributesTo( PUEventHandler* eventHandler )
|
||||
{
|
||||
PUEventHandler::copyAttributesTo(eventHandler);
|
||||
PUDoPlacementParticleEventHandler* doPlacementParticleEventHandler = static_cast<PUDoPlacementParticleEventHandler*>(eventHandler);
|
||||
doPlacementParticleEventHandler->setForceEmitterName(_forceEmitterName);
|
||||
doPlacementParticleEventHandler->setNumberOfParticles(_numberOfParticles);
|
||||
doPlacementParticleEventHandler->_alwaysUsePosition = _alwaysUsePosition;
|
||||
doPlacementParticleEventHandler->_inheritPosition = _inheritPosition;
|
||||
doPlacementParticleEventHandler->_inheritDirection = _inheritDirection;
|
||||
doPlacementParticleEventHandler->_inheritOrientation = _inheritOrientation;
|
||||
doPlacementParticleEventHandler->_inheritTimeToLive = _inheritTimeToLive;
|
||||
doPlacementParticleEventHandler->_inheritMass = _inheritMass;
|
||||
doPlacementParticleEventHandler->_inheritTextureCoordinate = _inheritTextureCoordinate;
|
||||
doPlacementParticleEventHandler->_inheritColour = _inheritColour;
|
||||
doPlacementParticleEventHandler->_inheritParticleWidth = _inheritParticleWidth;
|
||||
doPlacementParticleEventHandler->_inheritParticleHeight = _inheritParticleHeight;
|
||||
doPlacementParticleEventHandler->_inheritParticleDepth = _inheritParticleDepth;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
190
extensions/Particle3D/PU/CCPUDoPlacementParticleEventHandler.h
Normal file
190
extensions/Particle3D/PU/CCPUDoPlacementParticleEventHandler.h
Normal file
@@ -0,0 +1,190 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __CC_PU_PARTICLE_3D_DO_PLACEMENT_PARTICLE_EVENT_HANDLER_H__
|
||||
#define __CC_PU_PARTICLE_3D_DO_PLACEMENT_PARTICLE_EVENT_HANDLER_H__
|
||||
|
||||
#include "base/CCRef.h"
|
||||
#include "math/CCMath.h"
|
||||
#include "extensions/Particle3D/PU/CCPUListener.h"
|
||||
#include "extensions/Particle3D/PU/CCPUEventHandler.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
struct PUParticle3D;
|
||||
class PUObserver;
|
||||
class PUEmitter;
|
||||
class PUParticleSystem3D;
|
||||
|
||||
class CC_DLL PUDoPlacementParticleEventHandler : public PUEventHandler, public PUListener
|
||||
{
|
||||
public:
|
||||
// Constants
|
||||
static const unsigned int DEFAULT_NUMBER_OF_PARTICLES;
|
||||
|
||||
static PUDoPlacementParticleEventHandler* create();
|
||||
|
||||
/** Getters/Setters
|
||||
*/
|
||||
bool isInheritPosition() const {return _inheritPosition;};
|
||||
bool isInheritDirection() const {return _inheritDirection;};
|
||||
bool isInheritOrientation() const {return _inheritOrientation;};
|
||||
bool isInheritTimeToLive() const {return _inheritTimeToLive;};
|
||||
bool isInheritMass() const {return _inheritMass;};
|
||||
bool isInheritTextureCoordinate() const {return _inheritTextureCoordinate;};
|
||||
bool isInheritColour() const {return _inheritColour;};
|
||||
bool isInheritParticleWidth() const {return _inheritParticleWidth;};
|
||||
bool isInheritParticleHeight() const {return _inheritParticleHeight;};
|
||||
bool isInheritParticleDepth() const {return _inheritParticleDepth;};
|
||||
|
||||
void setInheritPosition(bool inheritPosition) {_inheritPosition = inheritPosition;};
|
||||
void setInheritDirection(bool inheritDirection) {_inheritDirection = inheritDirection;};
|
||||
void setInheritOrientation(bool inheritOrientation) {_inheritOrientation = inheritOrientation;};
|
||||
void setInheritTimeToLive(bool inheritTimeToLive) {_inheritTimeToLive = inheritTimeToLive;};
|
||||
void setInheritMass(bool inheritMass) {_inheritMass = inheritMass;};
|
||||
void setInheritTextureCoordinate(bool inheritTextureCoordinate) {_inheritTextureCoordinate = inheritTextureCoordinate;};
|
||||
void setInheritColour(bool inheritColour) {_inheritColour = inheritColour;};
|
||||
void setInheritParticleWidth(bool inheritParticleWidth) {_inheritParticleWidth = inheritParticleWidth;};
|
||||
void setInheritParticleHeight(bool inheritParticleHeight) {_inheritParticleHeight = inheritParticleHeight;};
|
||||
void setInheritParticleDepth(bool inheritParticleDepth) {_inheritParticleDepth = inheritParticleDepth;};
|
||||
|
||||
/** Get the name of the emitter that is used to emit its particles.
|
||||
*/
|
||||
const std::string& getForceEmitterName() const {return _forceEmitterName;};
|
||||
|
||||
/** Set the name of the emitter that is used to emit its particles.
|
||||
*/
|
||||
void setForceEmitterName(const std::string& forceEmitterName);
|
||||
|
||||
/** Returns a pointer to the emitter that is used as a force emitter.
|
||||
*/
|
||||
PUEmitter* getForceEmitter() const;
|
||||
|
||||
/** Remove this as a listener from the technique.
|
||||
@remarks
|
||||
If a new force-emitter name has been set, the removeAsListener must be called, to remove the DoPlacementParticleEventHandler
|
||||
from the old technique (to which the force-emitter belongs. Only then the new force-emitter is used.
|
||||
The reason why it is not called automatically in the setForceEmitterName() function is to offer some flexibility on
|
||||
the moment the removeAsListener() is called.
|
||||
*/
|
||||
void removeAsListener();
|
||||
|
||||
/** Get the number of particles to emit.
|
||||
*/
|
||||
unsigned int getNumberOfParticles() const {return _numberOfParticles;};
|
||||
|
||||
/** Set the number of particles to emit.
|
||||
*/
|
||||
void setNumberOfParticles(unsigned int numberOfParticles){_numberOfParticles = numberOfParticles;};
|
||||
|
||||
/** Boolean that determines whether always the position of the particle that is handled must be used for emission of
|
||||
the new particle.
|
||||
*/
|
||||
bool alwaysUsePosition() const {return _alwaysUsePosition;};
|
||||
|
||||
/** Set the boolean to indicate whether the position of the particle that is handled must be used for emission of
|
||||
the new particle or whether the contact point of the physics actor must be used. This only applies if a physics engine
|
||||
is used, otherwise the default is used.
|
||||
*/
|
||||
void setAlwaysUsePosition(bool alwaysUsePosition) {_alwaysUsePosition = alwaysUsePosition;};
|
||||
|
||||
/** If the _handle() function of this class is invoked (by an Observer), it searches the
|
||||
ParticleEmitter defined by the mForceEmitterName. This ParticleEmitter is either part of
|
||||
the ParticleTechnique in which the DoPlacementParticleEventHandler is defined, and if the ParticleEmitter
|
||||
is not found, other ParticleTechniques are searched. The ParticleEmitter is 'forced' to emit the
|
||||
requested number of particles.
|
||||
*/
|
||||
virtual void handle (PUParticleSystem3D* particleSystem, PUParticle3D* particle, float timeElapsed) override;
|
||||
|
||||
/** Initialise the emitted particle. This means that its position is set.
|
||||
*/
|
||||
virtual void particleEmitted(PUParticleSystem3D* particleSystem, PUParticle3D* particle) override;
|
||||
|
||||
/** No implementation.
|
||||
*/
|
||||
virtual void particleExpired(PUParticleSystem3D* particleSystem, PUParticle3D* particle) override;
|
||||
|
||||
virtual void copyAttributesTo (PUEventHandler* eventHandler) override;
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
PUDoPlacementParticleEventHandler();
|
||||
virtual ~PUDoPlacementParticleEventHandler();
|
||||
|
||||
protected:
|
||||
// Identifies the name of emitter
|
||||
std::string _forceEmitterName;
|
||||
|
||||
// The number of particles to emit
|
||||
unsigned int _numberOfParticles;
|
||||
|
||||
/** Store the technique value to keep up to speed.
|
||||
@remarks
|
||||
If the ParticleTechnique has been destroyed, the DoPlacementParticleEventHandler isn't automatically
|
||||
notified. Using the pointer causes an exception.
|
||||
*/
|
||||
PUParticleSystem3D* _system;
|
||||
|
||||
/** Store the emitter value to keep up to speed.
|
||||
@remarks
|
||||
If the ParticleEmitter has been destroyed, the DoPlacementParticleEventHandler isn't automatically
|
||||
notified. Using the pointer causes an exception.
|
||||
*/
|
||||
PUEmitter* _emitter;
|
||||
|
||||
/** Used to determine whether the emitter used by the DoPlacementParticleEventHandler, is already found.
|
||||
*/
|
||||
bool _found;
|
||||
|
||||
/** By default the place where to put a new particle is on the position of the particle in the _handle function. If
|
||||
mAlwaysUsePosition is set to false, it tries the contact point of the physics actor that is associated with the
|
||||
particle.
|
||||
*/
|
||||
bool _alwaysUsePosition;
|
||||
|
||||
/** The base particle from which the attributes are inherited
|
||||
*/
|
||||
PUParticle3D* _baseParticle;
|
||||
|
||||
/** These flags are used to determine which attributes must be inherited from the base particle.
|
||||
*/
|
||||
bool _inheritPosition;
|
||||
bool _inheritDirection;
|
||||
bool _inheritOrientation;
|
||||
bool _inheritTimeToLive;
|
||||
bool _inheritMass;
|
||||
bool _inheritTextureCoordinate;
|
||||
bool _inheritColour;
|
||||
bool _inheritParticleWidth;
|
||||
bool _inheritParticleHeight;
|
||||
bool _inheritParticleDepth;
|
||||
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,210 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCPUDoPlacementParticleEventHandlerTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUParticleSystem3D.h"
|
||||
#include "extensions/Particle3D/PU/CCPUDynamicAttribute.h"
|
||||
#include "extensions/Particle3D/PU/CCPUDynamicAttributeTranslator.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
PUDoPlacementParticleEventHandlerTranslator::PUDoPlacementParticleEventHandlerTranslator()
|
||||
{
|
||||
}
|
||||
//-------------------------------------------------------------------------
|
||||
bool PUDoPlacementParticleEventHandlerTranslator::translateChildProperty( PUScriptCompiler* compiler, PUAbstractNode *node )
|
||||
{
|
||||
PUPropertyAbstractNode* prop = reinterpret_cast<PUPropertyAbstractNode*>(node);
|
||||
PUEventHandler* evt = static_cast<PUEventHandler *>(prop->parent->context);
|
||||
PUDoPlacementParticleEventHandler* handler = static_cast<PUDoPlacementParticleEventHandler*>(evt);
|
||||
|
||||
if (prop->name == token[TOKEN_DOPLACE_FORCE_EMITTER])
|
||||
{
|
||||
// Property: force_emitter
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_DOPLACE_FORCE_EMITTER], VAL_STRING))
|
||||
{
|
||||
std::string val;
|
||||
if(getString(*prop->values.front(), &val))
|
||||
{
|
||||
handler->setForceEmitterName(val);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_DOPLACE_NUMBER_OF_PARTICLES])
|
||||
{
|
||||
// Property: number_of_particles
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_DOPLACE_NUMBER_OF_PARTICLES], VAL_UINT))
|
||||
{
|
||||
unsigned int val = 0;
|
||||
if(getUInt(*prop->values.front(), &val))
|
||||
{
|
||||
handler->setNumberOfParticles(val);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_INHERIT_POSITION])
|
||||
{
|
||||
// Property: inherit_position
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_INHERIT_POSITION], VAL_BOOL))
|
||||
{
|
||||
bool val;
|
||||
if(getBoolean(*prop->values.front(), &val))
|
||||
{
|
||||
handler->setInheritPosition(val);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_INHERIT_DIRECTION])
|
||||
{
|
||||
// Property: inherit_direction
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_INHERIT_DIRECTION], VAL_BOOL))
|
||||
{
|
||||
bool val;
|
||||
if(getBoolean(*prop->values.front(), &val))
|
||||
{
|
||||
handler->setInheritDirection(val);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_INHERIT_ORIENTATION])
|
||||
{
|
||||
// Property: inherit_orientation
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_INHERIT_ORIENTATION], VAL_BOOL))
|
||||
{
|
||||
bool val;
|
||||
if(getBoolean(*prop->values.front(), &val))
|
||||
{
|
||||
handler->setInheritOrientation(val);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_INHERIT_TIME_TO_LIVE])
|
||||
{
|
||||
// Property: inherit_time_to_live
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_INHERIT_TIME_TO_LIVE], VAL_BOOL))
|
||||
{
|
||||
bool val;
|
||||
if(getBoolean(*prop->values.front(), &val))
|
||||
{
|
||||
handler->setInheritTimeToLive(val);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_INHERIT_MASS])
|
||||
{
|
||||
// Property: inherit_mass
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_INHERIT_MASS], VAL_BOOL))
|
||||
{
|
||||
bool val;
|
||||
if(getBoolean(*prop->values.front(), &val))
|
||||
{
|
||||
handler->setInheritMass(val);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_INHERIT_TEXTURE_COORDINATE])
|
||||
{
|
||||
// Property: inherit_texture_coord
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_INHERIT_TEXTURE_COORDINATE], VAL_BOOL))
|
||||
{
|
||||
bool val;
|
||||
if(getBoolean(*prop->values.front(), &val))
|
||||
{
|
||||
handler->setInheritTextureCoordinate(val);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_INHERIT_COLOUR])
|
||||
{
|
||||
// Property: inherit_colour
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_INHERIT_COLOUR], VAL_BOOL))
|
||||
{
|
||||
bool val;
|
||||
if(getBoolean(*prop->values.front(), &val))
|
||||
{
|
||||
handler->setInheritColour(val);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_INHERIT_WIDTH])
|
||||
{
|
||||
// Property: inherit_width
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_INHERIT_WIDTH], VAL_BOOL))
|
||||
{
|
||||
bool val;
|
||||
if(getBoolean(*prop->values.front(), &val))
|
||||
{
|
||||
handler->setInheritParticleWidth(val);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_INHERIT_HEIGHT])
|
||||
{
|
||||
// Property: inherit_height
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_INHERIT_HEIGHT], VAL_BOOL))
|
||||
{
|
||||
bool val;
|
||||
if(getBoolean(*prop->values.front(), &val))
|
||||
{
|
||||
handler->setInheritParticleHeight(val);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_INHERIT_DEPTH])
|
||||
{
|
||||
// Property: inherit_depth
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_INHERIT_DEPTH], VAL_BOOL))
|
||||
{
|
||||
bool val;
|
||||
if(getBoolean(*prop->values.front(), &val))
|
||||
{
|
||||
handler->setInheritParticleDepth(val);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool PUDoPlacementParticleEventHandlerTranslator::translateChildObject( PUScriptCompiler* /*compiler*/, PUAbstractNode* /*node*/ )
|
||||
{
|
||||
// No objects
|
||||
return false;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
@@ -0,0 +1,48 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __CC_PU_PARTICLE_3D_DO_PLACEMENT_PARTICLE_EVENT_HANDLER_TRANSLATOR_H__
|
||||
#define __CC_PU_PARTICLE_3D_DO_PLACEMENT_PARTICLE_EVENT_HANDLER_TRANSLATOR_H__
|
||||
|
||||
#include "extensions/Particle3D/PU/CCPUScriptTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUScriptCompiler.h"
|
||||
#include "extensions/Particle3D/PU/CCPUDoPlacementParticleEventHandler.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class PUDoPlacementParticleEventHandlerTranslator : public PUScriptTranslator
|
||||
{
|
||||
public:
|
||||
PUDoPlacementParticleEventHandlerTranslator();
|
||||
virtual ~PUDoPlacementParticleEventHandlerTranslator(){};
|
||||
|
||||
virtual bool translateChildProperty(PUScriptCompiler* compiler, PUAbstractNode *node);
|
||||
virtual bool translateChildObject(PUScriptCompiler* compiler, PUAbstractNode *node);
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif
|
||||
96
extensions/Particle3D/PU/CCPUDoScaleEventHandler.cpp
Normal file
96
extensions/Particle3D/PU/CCPUDoScaleEventHandler.cpp
Normal file
@@ -0,0 +1,96 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "extensions/Particle3D/PU/CCPUDoScaleEventHandler.h"
|
||||
#include "extensions/Particle3D/PU/CCPUParticleSystem3D.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
// Constants
|
||||
const PUDoScaleEventHandler::ScaleType PUDoScaleEventHandler::DEFAULT_SCALE_TYPE = PUDoScaleEventHandler::ST_TIME_TO_LIVE;
|
||||
const float PUDoScaleEventHandler::DEFAULT_SCALE_FRACTION = 0.2f;
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
PUDoScaleEventHandler::PUDoScaleEventHandler() :
|
||||
PUEventHandler(),
|
||||
_scaleFraction(DEFAULT_SCALE_FRACTION),
|
||||
_scaleType(DEFAULT_SCALE_TYPE)
|
||||
{
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
const PUDoScaleEventHandler::ScaleType& PUDoScaleEventHandler::getScaleType() const
|
||||
{
|
||||
return _scaleType;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUDoScaleEventHandler::setScaleType(const PUDoScaleEventHandler::ScaleType& scaleType)
|
||||
{
|
||||
_scaleType = scaleType;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
float PUDoScaleEventHandler::getScaleFraction() const
|
||||
{
|
||||
return _scaleFraction;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUDoScaleEventHandler::setScaleFraction(const float scaleFraction)
|
||||
{
|
||||
_scaleFraction = scaleFraction;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUDoScaleEventHandler::handle (PUParticleSystem3D* /*particleSystem*/, PUParticle3D* particle, float timeElapsed)
|
||||
{
|
||||
if (!particle)
|
||||
return;
|
||||
|
||||
switch (_scaleType)
|
||||
{
|
||||
case ST_TIME_TO_LIVE:
|
||||
particle->timeToLive -= timeElapsed * _scaleFraction * particle->timeToLive;
|
||||
break;
|
||||
|
||||
case ST_VELOCITY:
|
||||
particle->direction += timeElapsed * _scaleFraction * particle->direction;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
PUDoScaleEventHandler* PUDoScaleEventHandler::create()
|
||||
{
|
||||
auto peh = new (std::nothrow) PUDoScaleEventHandler();
|
||||
peh->autorelease();
|
||||
return peh;
|
||||
}
|
||||
|
||||
void PUDoScaleEventHandler::copyAttributesTo( PUEventHandler* eventHandler )
|
||||
{
|
||||
PUEventHandler::copyAttributesTo(eventHandler);
|
||||
PUDoScaleEventHandler* doScaleEventHandler = static_cast<PUDoScaleEventHandler*>(eventHandler);
|
||||
doScaleEventHandler->setScaleFraction(_scaleFraction);
|
||||
doScaleEventHandler->setScaleType(_scaleType);
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
90
extensions/Particle3D/PU/CCPUDoScaleEventHandler.h
Normal file
90
extensions/Particle3D/PU/CCPUDoScaleEventHandler.h
Normal file
@@ -0,0 +1,90 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __CC_PU_PARTICLE_3D_DO_SCALE_EVENT_HANDLER_H__
|
||||
#define __CC_PU_PARTICLE_3D_DO_SCALE_EVENT_HANDLER_H__
|
||||
|
||||
#include "base/CCRef.h"
|
||||
#include "math/CCMath.h"
|
||||
#include "extensions/Particle3D/PU/CCPUEventHandler.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
struct PUParticle3D;
|
||||
class PUParticleSystem3D;
|
||||
|
||||
class CC_DLL PUDoScaleEventHandler : public PUEventHandler
|
||||
{
|
||||
public:
|
||||
enum ScaleType
|
||||
{
|
||||
ST_TIME_TO_LIVE,
|
||||
ST_VELOCITY
|
||||
};
|
||||
|
||||
// Constants
|
||||
static const ScaleType DEFAULT_SCALE_TYPE;
|
||||
static const float DEFAULT_SCALE_FRACTION;
|
||||
|
||||
static PUDoScaleEventHandler* create();
|
||||
|
||||
/** Returns the scale type
|
||||
*/
|
||||
const ScaleType& getScaleType() const;
|
||||
|
||||
/** Set the scale type. This scale type identifies to which attribute the scale factor is applied.
|
||||
*/
|
||||
void setScaleType(const ScaleType& scaleType);
|
||||
|
||||
/** Returns the scale fraction
|
||||
*/
|
||||
float getScaleFraction() const;
|
||||
|
||||
/** Set the scale fraction. This scale fraction value is used to scale different attributes if the
|
||||
event handler is called.
|
||||
*/
|
||||
void setScaleFraction(const float scaleFraction);
|
||||
|
||||
/**
|
||||
*/
|
||||
virtual void handle (PUParticleSystem3D* particleSystem, PUParticle3D* particle, float timeElapsed) override;
|
||||
|
||||
virtual void copyAttributesTo (PUEventHandler* eventHandler) override;
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
PUDoScaleEventHandler();
|
||||
virtual ~PUDoScaleEventHandler() {};
|
||||
|
||||
protected:
|
||||
float _scaleFraction;
|
||||
ScaleType _scaleType;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,88 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCPUDoScaleEventHandlerTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUParticleSystem3D.h"
|
||||
#include "extensions/Particle3D/PU/CCPUDynamicAttribute.h"
|
||||
#include "extensions/Particle3D/PU/CCPUDynamicAttributeTranslator.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
PUDoScaleEventHandlerTranslator::PUDoScaleEventHandlerTranslator()
|
||||
{
|
||||
}
|
||||
//-------------------------------------------------------------------------
|
||||
bool PUDoScaleEventHandlerTranslator::translateChildProperty( PUScriptCompiler* compiler, PUAbstractNode *node )
|
||||
{
|
||||
PUPropertyAbstractNode* prop = reinterpret_cast<PUPropertyAbstractNode*>(node);
|
||||
PUEventHandler* evt = static_cast<PUEventHandler *>(prop->parent->context);
|
||||
PUDoScaleEventHandler* handler = static_cast<PUDoScaleEventHandler*>(evt);
|
||||
|
||||
if (prop->name == token[TOKEN_DOSCALE_FRACTION])
|
||||
{
|
||||
// Property: scale_fraction
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_DOSCALE_FRACTION], VAL_REAL))
|
||||
{
|
||||
float val = 0.0f;
|
||||
if(getFloat(*prop->values.front(), &val))
|
||||
{
|
||||
handler->setScaleFraction(val);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_DOSCALE_TYPE])
|
||||
{
|
||||
// Property: scale_type
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_DOSCALE_TYPE], VAL_STRING))
|
||||
{
|
||||
std::string val;
|
||||
if(getString(*prop->values.front(), &val))
|
||||
{
|
||||
if (val == token[TOKEN_TIME_TO_LIVE] || val == token[TOKEN_DOSCALE_TIME_TO_LIVE])
|
||||
{
|
||||
handler->setScaleType(PUDoScaleEventHandler::ST_TIME_TO_LIVE);
|
||||
return true;
|
||||
}
|
||||
else if (val == token[TOKEN_VELOCITY] || val == token[TOKEN_DOSCALE_VELOCITY])
|
||||
{
|
||||
handler->setScaleType(PUDoScaleEventHandler::ST_VELOCITY);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool PUDoScaleEventHandlerTranslator::translateChildObject( PUScriptCompiler* /*compiler*/, PUAbstractNode* /*node*/ )
|
||||
{
|
||||
// No objects
|
||||
return false;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
48
extensions/Particle3D/PU/CCPUDoScaleEventHandlerTranslator.h
Normal file
48
extensions/Particle3D/PU/CCPUDoScaleEventHandlerTranslator.h
Normal file
@@ -0,0 +1,48 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __CC_PU_PARTICLE_3D_DO_SCALE_EVENT_HANDLER_TRANSLATOR_H__
|
||||
#define __CC_PU_PARTICLE_3D_DO_SCALE_EVENT_HANDLER_TRANSLATOR_H__
|
||||
|
||||
#include "extensions/Particle3D/PU/CCPUScriptTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUScriptCompiler.h"
|
||||
#include "extensions/Particle3D/PU/CCPUDoScaleEventHandler.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class PUDoScaleEventHandlerTranslator : public PUScriptTranslator
|
||||
{
|
||||
public:
|
||||
PUDoScaleEventHandlerTranslator();
|
||||
virtual ~PUDoScaleEventHandlerTranslator(){};
|
||||
|
||||
virtual bool translateChildProperty(PUScriptCompiler* compiler, PUAbstractNode *node);
|
||||
virtual bool translateChildObject(PUScriptCompiler* compiler, PUAbstractNode *node);
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif
|
||||
46
extensions/Particle3D/PU/CCPUDoStopSystemEventHandler.cpp
Normal file
46
extensions/Particle3D/PU/CCPUDoStopSystemEventHandler.cpp
Normal file
@@ -0,0 +1,46 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "extensions/Particle3D/PU/CCPUDoStopSystemEventHandler.h"
|
||||
#include "extensions/Particle3D/PU/CCPUParticleSystem3D.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
//-----------------------------------------------------------------------
|
||||
void PUDoStopSystemEventHandler::handle (PUParticleSystem3D* particleSystem, PUParticle3D* /*particle*/, float /*timeElapsed*/)
|
||||
{
|
||||
ParticleSystem3D *parent = particleSystem->getParentParticleSystem();
|
||||
if (parent)
|
||||
parent->stopParticleSystem();
|
||||
}
|
||||
|
||||
PUDoStopSystemEventHandler* PUDoStopSystemEventHandler::create()
|
||||
{
|
||||
auto peh = new (std::nothrow) PUDoStopSystemEventHandler();
|
||||
peh->autorelease();
|
||||
return peh;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
63
extensions/Particle3D/PU/CCPUDoStopSystemEventHandler.h
Normal file
63
extensions/Particle3D/PU/CCPUDoStopSystemEventHandler.h
Normal file
@@ -0,0 +1,63 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __CC_PU_PARTICLE_3D_DO_STOP_SYSTEM_EVENT_HANDLER_H__
|
||||
#define __CC_PU_PARTICLE_3D_DO_STOP_SYSTEM_EVENT_HANDLER_H__
|
||||
|
||||
#include "base/CCRef.h"
|
||||
#include "math/CCMath.h"
|
||||
#include "extensions/Particle3D/PU/CCPUEventHandler.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
struct PUParticle3D;
|
||||
class PUObserver;
|
||||
class PUParticleSystem3D;
|
||||
|
||||
class CC_DLL PUDoStopSystemEventHandler : public PUEventHandler
|
||||
{
|
||||
protected:
|
||||
|
||||
public:
|
||||
|
||||
static PUDoStopSystemEventHandler* create();
|
||||
|
||||
/**
|
||||
*/
|
||||
virtual void handle(PUParticleSystem3D* particleSystem, PUParticle3D* particle, float timeElapsed) override;
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
PUDoStopSystemEventHandler() : PUEventHandler()
|
||||
{
|
||||
}
|
||||
virtual ~PUDoStopSystemEventHandler() {};
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,49 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCPUDoStopSystemEventHandlerTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUParticleSystem3D.h"
|
||||
#include "extensions/Particle3D/PU/CCPUDynamicAttribute.h"
|
||||
#include "extensions/Particle3D/PU/CCPUDynamicAttributeTranslator.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
PUDoStopSystemEventHandlerTranslator::PUDoStopSystemEventHandlerTranslator()
|
||||
{
|
||||
}
|
||||
//-------------------------------------------------------------------------
|
||||
bool PUDoStopSystemEventHandlerTranslator::translateChildProperty( PUScriptCompiler* /*compiler*/, PUAbstractNode* /*node*/ )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool PUDoStopSystemEventHandlerTranslator::translateChildObject( PUScriptCompiler* /*compiler*/, PUAbstractNode* /*node*/ )
|
||||
{
|
||||
// No objects
|
||||
return false;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
@@ -0,0 +1,48 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __CC_PU_PARTICLE_3D_DO_STOP_EVENT_HANDLER_TRANSLATOR_H__
|
||||
#define __CC_PU_PARTICLE_3D_DO_STOP_EVENT_HANDLER_TRANSLATOR_H__
|
||||
|
||||
#include "extensions/Particle3D/PU/CCPUScriptTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUScriptCompiler.h"
|
||||
#include "extensions/Particle3D/PU/CCPUDoStopSystemEventHandler.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class PUDoStopSystemEventHandlerTranslator : public PUScriptTranslator
|
||||
{
|
||||
public:
|
||||
PUDoStopSystemEventHandlerTranslator();
|
||||
virtual ~PUDoStopSystemEventHandlerTranslator(){};
|
||||
|
||||
virtual bool translateChildProperty(PUScriptCompiler* compiler, PUAbstractNode *node);
|
||||
virtual bool translateChildObject(PUScriptCompiler* compiler, PUAbstractNode *node);
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif
|
||||
466
extensions/Particle3D/PU/CCPUDynamicAttribute.cpp
Normal file
466
extensions/Particle3D/PU/CCPUDynamicAttribute.cpp
Normal file
@@ -0,0 +1,466 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCPUDynamicAttribute.h"
|
||||
#include "base/ccRandom.h"
|
||||
#include "platform/CCStdC.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
//-----------------------------------------------------------------------
|
||||
PUDynamicAttribute::PUDynamicAttribute ()
|
||||
{
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
PUDynamicAttribute::~PUDynamicAttribute ()
|
||||
{
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
PUDynamicAttribute::DynamicAttributeType PUDynamicAttribute::getType () const
|
||||
{
|
||||
return _type;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUDynamicAttribute::setType (PUDynamicAttribute::DynamicAttributeType type)
|
||||
{
|
||||
_type = type;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
PUDynamicAttributeFixed::PUDynamicAttributeFixed () : _value(0)
|
||||
{
|
||||
_type = PUDynamicAttribute::DAT_FIXED;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
PUDynamicAttributeFixed::PUDynamicAttributeFixed (const PUDynamicAttributeFixed& dynamicAttributeFixed)
|
||||
{
|
||||
_type = PUDynamicAttribute::DAT_FIXED;
|
||||
_value = dynamicAttributeFixed._value;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
PUDynamicAttributeFixed::~PUDynamicAttributeFixed ()
|
||||
{
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUDynamicAttributeFixed::setValue (float value)
|
||||
{
|
||||
_value = value;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
float PUDynamicAttributeFixed::getValue (float /*x*/)
|
||||
{
|
||||
return _value;
|
||||
}
|
||||
|
||||
void PUDynamicAttributeFixed::copyAttributesTo( PUDynamicAttribute* dynamicAttribute )
|
||||
{
|
||||
if (!dynamicAttribute || dynamicAttribute->getType() != PUDynamicAttribute::DAT_FIXED)
|
||||
return;
|
||||
|
||||
PUDynamicAttributeFixed* dynAttr = static_cast<PUDynamicAttributeFixed*>(dynamicAttribute);
|
||||
dynAttr->_value = _value;
|
||||
}
|
||||
|
||||
PUDynamicAttributeFixed* PUDynamicAttributeFixed::clone()
|
||||
{
|
||||
auto af = new (std::nothrow) PUDynamicAttributeFixed();
|
||||
this->copyAttributesTo(af);
|
||||
return af;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
PUDynamicAttributeRandom::PUDynamicAttributeRandom () : _min(0), _max(0)
|
||||
{
|
||||
_type = PUDynamicAttribute::DAT_RANDOM;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
PUDynamicAttributeRandom::PUDynamicAttributeRandom (const PUDynamicAttributeRandom& dynamicAttributeRandom)
|
||||
{
|
||||
_type = PUDynamicAttribute::DAT_RANDOM;
|
||||
_min = dynamicAttributeRandom._min;
|
||||
_max = dynamicAttributeRandom._max;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
PUDynamicAttributeRandom::~PUDynamicAttributeRandom ()
|
||||
{
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
float PUDynamicAttributeRandom::getMin () const
|
||||
{
|
||||
return _min;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUDynamicAttributeRandom::setMin (float min)
|
||||
{
|
||||
_min = min;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
float PUDynamicAttributeRandom::getMax () const
|
||||
{
|
||||
return _max;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUDynamicAttributeRandom::setMax (float max)
|
||||
{
|
||||
_max = max;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUDynamicAttributeRandom::setMinMax (float min, float max)
|
||||
{
|
||||
_min = min;
|
||||
_max = max;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
float PUDynamicAttributeRandom::getValue (float /*x*/)
|
||||
{
|
||||
return cocos2d::random(_min, _max);
|
||||
}
|
||||
|
||||
void PUDynamicAttributeRandom::copyAttributesTo( PUDynamicAttribute* dynamicAttribute )
|
||||
{
|
||||
if (!dynamicAttribute || dynamicAttribute->getType() != PUDynamicAttribute::DAT_RANDOM)
|
||||
return;
|
||||
|
||||
PUDynamicAttributeRandom* dynAttr = static_cast<PUDynamicAttributeRandom*>(dynamicAttribute);
|
||||
dynAttr->_min = _min;
|
||||
dynAttr->_max = _max;
|
||||
}
|
||||
|
||||
PUDynamicAttributeRandom* PUDynamicAttributeRandom::clone()
|
||||
{
|
||||
auto ar = new (std::nothrow) PUDynamicAttributeRandom();
|
||||
this->copyAttributesTo(ar);
|
||||
return ar;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
PUDynamicAttributeCurved::PUDynamicAttributeCurved () :
|
||||
_range(0),
|
||||
_interpolationType(IT_LINEAR)
|
||||
{
|
||||
_type = PUDynamicAttribute::DAT_CURVED;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
PUDynamicAttributeCurved::PUDynamicAttributeCurved (PUInterpolationType interpolationType) :
|
||||
_range(0),
|
||||
_interpolationType(interpolationType)
|
||||
{
|
||||
_type = PUDynamicAttribute::DAT_CURVED;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
PUDynamicAttributeCurved::PUDynamicAttributeCurved (const PUDynamicAttributeCurved& dynamicAttributeCurved) :
|
||||
_range(dynamicAttributeCurved._range),
|
||||
_spline(dynamicAttributeCurved._spline),
|
||||
_interpolationType(dynamicAttributeCurved._interpolationType)
|
||||
{
|
||||
_type = PUDynamicAttribute::DAT_CURVED;
|
||||
|
||||
// Copy controlpoints
|
||||
for (const auto& controlPoint : dynamicAttributeCurved._controlPoints)
|
||||
{
|
||||
_controlPoints.push_back (controlPoint);
|
||||
}
|
||||
processControlPoints();
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
PUDynamicAttributeCurved::~PUDynamicAttributeCurved ()
|
||||
{
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUDynamicAttributeCurved::setInterpolationType (PUInterpolationType interpolationType)
|
||||
{
|
||||
if (interpolationType != _interpolationType)
|
||||
{
|
||||
// If switched to another InterpolationType, the already existing ControlPoints will be removed.
|
||||
removeAllControlPoints();
|
||||
_interpolationType = interpolationType;
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
PUInterpolationType PUDynamicAttributeCurved::getInterpolationType () const
|
||||
{
|
||||
return _interpolationType;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
float PUDynamicAttributeCurved::getValue (float x)
|
||||
{
|
||||
switch (_interpolationType)
|
||||
{
|
||||
case IT_LINEAR:
|
||||
{
|
||||
// Search the interval in which 'x' resides and apply linear interpolation
|
||||
if (_controlPoints.empty())
|
||||
return 0;
|
||||
|
||||
ControlPointList::iterator it1 = findNearestControlPointIterator(x);
|
||||
ControlPointList::iterator it2 = it1 + 1;
|
||||
if (it2 != _controlPoints.end())
|
||||
{
|
||||
// Calculate fraction: y = y1 + ((y2 - y1) * (x - x1)/(x2 - x1))
|
||||
return (*it1).y + (((*it2).y - (*it1).y) * (x - (*it1).x)/((*it2).x - (*it1).x));
|
||||
}
|
||||
else
|
||||
{
|
||||
return (*it1).y;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case IT_SPLINE:
|
||||
{
|
||||
// Fit using spline
|
||||
if (_spline.getNumPoints() < 1)
|
||||
return 0;
|
||||
|
||||
float fraction = x / _range;
|
||||
return (_spline.interpolate(fraction < 1.0f ? fraction : 1.0f)).y;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUDynamicAttributeCurved::addControlPoint (float x, float y)
|
||||
{
|
||||
_controlPoints.push_back(Vec2(x, y));
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
const PUDynamicAttributeCurved::ControlPointList& PUDynamicAttributeCurved::getControlPoints () const
|
||||
{
|
||||
return _controlPoints;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUDynamicAttributeCurved::processControlPoints()
|
||||
{
|
||||
if (_controlPoints.empty())
|
||||
return;
|
||||
|
||||
std::sort(_controlPoints.begin(), _controlPoints.end(), PUControlPointSorter());
|
||||
_range = (*getLastValidIterator()).x - (*getFirstValidIterator()).x;
|
||||
|
||||
if (_interpolationType == IT_SPLINE)
|
||||
{
|
||||
// Add all sorted control points to the spline
|
||||
PUDynamicAttributeCurved::ControlPointList::iterator it;
|
||||
_spline.clear();
|
||||
for (it = _controlPoints.begin(); it != _controlPoints.end(); ++it)
|
||||
_spline.addPoint(Vec3((*it).x, (*it).y, 0));
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
size_t PUDynamicAttributeCurved::getNumControlPoints() const
|
||||
{
|
||||
return _controlPoints.size();
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUDynamicAttributeCurved::removeAllControlPoints()
|
||||
{
|
||||
_controlPoints.clear();
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
PUDynamicAttributeCurved::ControlPointList::iterator PUDynamicAttributeCurved::findNearestControlPointIterator(float x)
|
||||
{
|
||||
// Assume that the ControlPointList is not empty
|
||||
ControlPointList::iterator it;
|
||||
ControlPointList::iterator itEnd = _controlPoints.end();
|
||||
for (it = _controlPoints.begin(); it != itEnd; ++it)
|
||||
{
|
||||
if (x < (*it).x)
|
||||
{
|
||||
if (it == _controlPoints.begin())
|
||||
return it;
|
||||
else
|
||||
return --it;
|
||||
}
|
||||
}
|
||||
|
||||
// If not found return the last valid iterator
|
||||
return --it;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
PUDynamicAttributeCurved::ControlPointList::iterator PUDynamicAttributeCurved::getFirstValidIterator()
|
||||
{
|
||||
return _controlPoints.begin();
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
PUDynamicAttributeCurved::ControlPointList::iterator PUDynamicAttributeCurved::getLastValidIterator()
|
||||
{
|
||||
return _controlPoints.end() - 1;
|
||||
}
|
||||
|
||||
void PUDynamicAttributeCurved::copyAttributesTo( PUDynamicAttribute* dynamicAttribute )
|
||||
{
|
||||
if (!dynamicAttribute || dynamicAttribute->getType() != PUDynamicAttribute::DAT_CURVED)
|
||||
return;
|
||||
|
||||
PUDynamicAttributeCurved* dynAttr = static_cast<PUDynamicAttributeCurved*>(dynamicAttribute);
|
||||
dynAttr->_interpolationType = _interpolationType;
|
||||
dynAttr->_spline = _spline;
|
||||
dynAttr->_range = _range;
|
||||
|
||||
// Copy controlpoints
|
||||
PUDynamicAttributeCurved::ControlPointList::const_iterator it; // Need const_iterator here!
|
||||
PUDynamicAttributeCurved::ControlPointList::const_iterator itEnd = _controlPoints.end();
|
||||
for (it = _controlPoints.begin(); it != itEnd; ++it)
|
||||
{
|
||||
Vec2 controlPoint = *it;
|
||||
dynAttr->_controlPoints.push_back(controlPoint);
|
||||
}
|
||||
dynAttr->processControlPoints();
|
||||
}
|
||||
|
||||
PUDynamicAttributeCurved* PUDynamicAttributeCurved::clone()
|
||||
{
|
||||
auto ac = new (std::nothrow) PUDynamicAttributeCurved();
|
||||
this->copyAttributesTo(ac);
|
||||
return ac;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
PUDynamicAttributeOscillate::PUDynamicAttributeOscillate () :
|
||||
_oscillationType(PUDynamicAttributeOscillate::OSCT_SINE),
|
||||
_frequency(1.0f),
|
||||
_phase(0.0f),
|
||||
_base(0.0f),
|
||||
_amplitude(1.0f)
|
||||
{
|
||||
_type = PUDynamicAttribute::DAT_OSCILLATE;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
PUDynamicAttributeOscillate::PUDynamicAttributeOscillate (const PUDynamicAttributeOscillate& /*dynamicAttributeOscillate*/)
|
||||
{
|
||||
_type = PUDynamicAttribute::DAT_OSCILLATE;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
PUDynamicAttributeOscillate::~PUDynamicAttributeOscillate ()
|
||||
{
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
PUDynamicAttributeOscillate::OscillationType PUDynamicAttributeOscillate::getOscillationType () const
|
||||
{
|
||||
return _oscillationType;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUDynamicAttributeOscillate::setOscillationType (PUDynamicAttributeOscillate::OscillationType oscillationType)
|
||||
{
|
||||
_oscillationType = oscillationType;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
float PUDynamicAttributeOscillate::getFrequency () const
|
||||
{
|
||||
return _frequency;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUDynamicAttributeOscillate::setFrequency (float frequency)
|
||||
{
|
||||
_frequency = frequency;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
float PUDynamicAttributeOscillate::getPhase () const
|
||||
{
|
||||
return _phase;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUDynamicAttributeOscillate::setPhase (float phase)
|
||||
{
|
||||
_phase = phase;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
float PUDynamicAttributeOscillate::getBase () const
|
||||
{
|
||||
return _base;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUDynamicAttributeOscillate::setBase (float base)
|
||||
{
|
||||
_base = base;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
float PUDynamicAttributeOscillate::getAmplitude () const
|
||||
{
|
||||
return _amplitude;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUDynamicAttributeOscillate::setAmplitude (float amplitude)
|
||||
{
|
||||
_amplitude = amplitude;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
float PUDynamicAttributeOscillate::getValue (float x)
|
||||
{
|
||||
switch (_oscillationType)
|
||||
{
|
||||
case OSCT_SINE:
|
||||
{
|
||||
return _base + _amplitude * sin(_phase + _frequency * x * M_PI * 2.0f);
|
||||
}
|
||||
break;
|
||||
case OSCT_SQUARE:
|
||||
{
|
||||
float val = sin(_phase + _frequency * x * M_PI * 2.0f);
|
||||
if (std::abs(val) < 0.00001f)
|
||||
val = val >0? 1: -1;
|
||||
return _base + _amplitude * val;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void PUDynamicAttributeOscillate::copyAttributesTo( PUDynamicAttribute* dynamicAttribute )
|
||||
{
|
||||
if (!dynamicAttribute || dynamicAttribute->getType() != PUDynamicAttribute::DAT_OSCILLATE)
|
||||
return;
|
||||
|
||||
PUDynamicAttributeOscillate* dynAttr = static_cast<PUDynamicAttributeOscillate*>(dynamicAttribute);
|
||||
dynAttr->_oscillationType = _oscillationType;
|
||||
dynAttr->_frequency = _frequency;
|
||||
dynAttr->_phase = _phase;
|
||||
dynAttr->_base = _base;
|
||||
dynAttr->_amplitude = _amplitude;
|
||||
}
|
||||
|
||||
PUDynamicAttributeOscillate* PUDynamicAttributeOscillate::clone()
|
||||
{
|
||||
auto ao = new (std::nothrow) PUDynamicAttributeOscillate();
|
||||
this->copyAttributesTo(ao);
|
||||
return ao;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
float PUDynamicAttributeHelper::calculate(PUDynamicAttribute* dyn, float x, float defaultValue)
|
||||
{
|
||||
if (dyn)
|
||||
{
|
||||
return dyn->getValue(x);
|
||||
}
|
||||
|
||||
return defaultValue;
|
||||
}
|
||||
NS_CC_END
|
||||
336
extensions/Particle3D/PU/CCPUDynamicAttribute.h
Normal file
336
extensions/Particle3D/PU/CCPUDynamicAttribute.h
Normal file
@@ -0,0 +1,336 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __CC_PU_PARTICLE_3D_DYNAMIC_ATTRIBUTE_H__
|
||||
#define __CC_PU_PARTICLE_3D_DYNAMIC_ATTRIBUTE_H__
|
||||
|
||||
#include "base/CCRef.h"
|
||||
#include "math/CCMath.h"
|
||||
#include "CCPUSimpleSpline.h"
|
||||
#include <vector>
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
enum PUInterpolationType
|
||||
{
|
||||
IT_LINEAR,
|
||||
IT_SPLINE
|
||||
};
|
||||
|
||||
/** Comparer used for sorting vector in ascending order
|
||||
*/
|
||||
struct PUControlPointSorter
|
||||
{
|
||||
bool operator() (const Vec2& a, const Vec2& b)
|
||||
{
|
||||
return a.x < b.x;
|
||||
}
|
||||
};
|
||||
|
||||
/* The DynamicAttribute class or its child classes encapsulate an attribute with specific (dynamic) behaviour.
|
||||
@remarks
|
||||
This class provides a uniform interface for retrieving the value of an attribute, while the calculation of
|
||||
this value may vary. Each subclass provides its own implementation of the getValue() function and the calling
|
||||
application doesn't need to know about the underlying logic. A subclass could just return a value that has
|
||||
previously been set, but it can also return a value that is randomly generated by a pre-defined min/max interval.
|
||||
The DynamicAttribute class is used in situations where different behaviour of a certain attribute is needed,
|
||||
but where implementation of this behaviour may not be scattered or duplicated within the application that needs
|
||||
it.
|
||||
*/
|
||||
class CC_DLL PUDynamicAttribute : public Ref
|
||||
{
|
||||
public:
|
||||
enum DynamicAttributeType
|
||||
{
|
||||
DAT_FIXED,
|
||||
DAT_RANDOM,
|
||||
DAT_CURVED,
|
||||
DAT_OSCILLATE
|
||||
};
|
||||
|
||||
/** Constructor
|
||||
*/
|
||||
PUDynamicAttribute ();
|
||||
|
||||
/** Destructor
|
||||
*/
|
||||
virtual ~PUDynamicAttribute ();
|
||||
|
||||
/** Virtual function that needs to be implemented by its childs.
|
||||
*/
|
||||
virtual float getValue (float x = 0) = 0;
|
||||
|
||||
/** Todo
|
||||
*/
|
||||
DynamicAttributeType getType () const;
|
||||
|
||||
/** Todo
|
||||
*/
|
||||
void setType (DynamicAttributeType type);
|
||||
|
||||
/** Returns true if one of the attributes was changed by an external source.
|
||||
*/
|
||||
bool isValueChangedExternally() const;
|
||||
|
||||
virtual void copyAttributesTo(PUDynamicAttribute* dynamicAttribute) = 0;
|
||||
virtual PUDynamicAttribute* clone() = 0;
|
||||
|
||||
protected:
|
||||
DynamicAttributeType _type;
|
||||
bool _valueChangedExternally;
|
||||
};
|
||||
|
||||
/* This class is an implementation of the DynamicAttribute class in its most simple form. It just returns a value
|
||||
that has previously been set.
|
||||
@remarks
|
||||
Although use of a regular attribute within the class that needs it is preferred, its benefit is that it makes
|
||||
use of the generic 'getValue' mechanism of a DynamicAttribute.
|
||||
*/
|
||||
class CC_DLL PUDynamicAttributeFixed : public PUDynamicAttribute
|
||||
{
|
||||
public:
|
||||
/** Constructor
|
||||
*/
|
||||
PUDynamicAttributeFixed ();
|
||||
|
||||
/** Copy constructor
|
||||
*/
|
||||
PUDynamicAttributeFixed (const PUDynamicAttributeFixed& dynamicAttributeFixed);
|
||||
|
||||
/** Destructor
|
||||
*/
|
||||
~PUDynamicAttributeFixed ();
|
||||
|
||||
/** Todo
|
||||
*/
|
||||
virtual float getValue (float x = 0) override;
|
||||
|
||||
/** Todo
|
||||
*/
|
||||
virtual void setValue (float value);
|
||||
|
||||
virtual PUDynamicAttributeFixed* clone() override;
|
||||
virtual void copyAttributesTo(PUDynamicAttribute* dynamicAttribute) override;
|
||||
|
||||
protected:
|
||||
float _value;
|
||||
};
|
||||
|
||||
/* This class generates random values within a given minimum and maximum interval.
|
||||
*/
|
||||
class CC_DLL PUDynamicAttributeRandom : public PUDynamicAttribute
|
||||
{
|
||||
public:
|
||||
/** Constructor
|
||||
*/
|
||||
PUDynamicAttributeRandom ();
|
||||
|
||||
/** Copy constructor
|
||||
*/
|
||||
PUDynamicAttributeRandom (const PUDynamicAttributeRandom& dynamicAttributeRandom);
|
||||
|
||||
/** Destructor
|
||||
*/
|
||||
~PUDynamicAttributeRandom ();
|
||||
|
||||
/** Todo
|
||||
*/
|
||||
virtual float getValue (float x = 0) override;
|
||||
|
||||
/** Todo
|
||||
*/
|
||||
void setMin (float min);
|
||||
float getMin () const;
|
||||
void setMax (float max);
|
||||
float getMax () const;
|
||||
void setMinMax (float min, float max);
|
||||
|
||||
virtual PUDynamicAttributeRandom* clone() override;
|
||||
virtual void copyAttributesTo(PUDynamicAttribute* dynamicAttribute) override;
|
||||
|
||||
protected:
|
||||
float _min, _max;
|
||||
};
|
||||
|
||||
/* This is a more complex usage of the DynamicAttribute principle. This class returns a value on an curve.
|
||||
@remarks
|
||||
After setting a number of control points, this class is able to interpolate a point on the curve that is based
|
||||
on these control points. Interpolation is done in different flavours. linear?provides linear interpolation
|
||||
of a value on the curve, while spline?generates a smooth curve and the returns a value that lies on that curve.
|
||||
*/
|
||||
class CC_DLL PUDynamicAttributeCurved : public PUDynamicAttribute
|
||||
{
|
||||
public:
|
||||
typedef std::vector<Vec2> ControlPointList;
|
||||
|
||||
/** Constructor
|
||||
*/
|
||||
PUDynamicAttributeCurved ();
|
||||
PUDynamicAttributeCurved (PUInterpolationType interpolationType);
|
||||
|
||||
/** Copy constructor
|
||||
*/
|
||||
PUDynamicAttributeCurved (const PUDynamicAttributeCurved& dynamicAttributeCurved);
|
||||
|
||||
/** Destructor
|
||||
*/
|
||||
~PUDynamicAttributeCurved ();
|
||||
|
||||
/** Get and set the curve type
|
||||
*/
|
||||
void setInterpolationType (PUInterpolationType interpolationType);
|
||||
PUInterpolationType getInterpolationType () const;
|
||||
|
||||
/** Todo
|
||||
*/
|
||||
virtual float getValue (float x = 0) override;
|
||||
|
||||
/** Todo
|
||||
*/
|
||||
virtual void addControlPoint (float x, float y);
|
||||
|
||||
/** Todo
|
||||
*/
|
||||
const ControlPointList& getControlPoints () const;
|
||||
|
||||
/** Todo
|
||||
*/
|
||||
void processControlPoints ();
|
||||
|
||||
/** Todo
|
||||
*/
|
||||
size_t getNumControlPoints() const;
|
||||
|
||||
/** Todo
|
||||
*/
|
||||
void removeAllControlPoints();
|
||||
|
||||
virtual PUDynamicAttributeCurved* clone() override;
|
||||
virtual void copyAttributesTo(PUDynamicAttribute* dynamicAttribute) override;
|
||||
|
||||
protected:
|
||||
|
||||
/** Todo
|
||||
*/
|
||||
float _range;
|
||||
|
||||
/** Todo
|
||||
*/
|
||||
PUSimpleSpline _spline;
|
||||
|
||||
/** Todo
|
||||
*/
|
||||
PUInterpolationType _interpolationType;
|
||||
|
||||
/** Todo
|
||||
*/
|
||||
ControlPointList _controlPoints;
|
||||
|
||||
/** Find an iterator that forms the low (left) value of the interval where x lies in.
|
||||
*/
|
||||
inline ControlPointList::iterator findNearestControlPointIterator(float x);
|
||||
|
||||
/** Helper functions
|
||||
*/
|
||||
inline ControlPointList::iterator getFirstValidIterator();
|
||||
inline ControlPointList::iterator getLastValidIterator();
|
||||
};
|
||||
|
||||
/* This class generates values based on an oscillating function (i.e. Sine).
|
||||
*/
|
||||
class CC_DLL PUDynamicAttributeOscillate : public PUDynamicAttribute
|
||||
{
|
||||
public:
|
||||
enum OscillationType
|
||||
{
|
||||
OSCT_SINE,
|
||||
OSCT_SQUARE
|
||||
};
|
||||
|
||||
/** Constructor
|
||||
*/
|
||||
PUDynamicAttributeOscillate ();
|
||||
|
||||
/** Copy constructor
|
||||
*/
|
||||
PUDynamicAttributeOscillate (const PUDynamicAttributeOscillate& dynamicAttributeOscillate);
|
||||
|
||||
/** Destructor
|
||||
*/
|
||||
~PUDynamicAttributeOscillate ();
|
||||
|
||||
/** Todo
|
||||
*/
|
||||
virtual float getValue (float x = 0) override;
|
||||
|
||||
/** Get and set the OscillationType
|
||||
*/
|
||||
OscillationType getOscillationType () const;
|
||||
void setOscillationType (OscillationType oscillationType);
|
||||
|
||||
/** Get and set the Frequency
|
||||
*/
|
||||
float getFrequency () const;
|
||||
void setFrequency (float frequency);
|
||||
|
||||
/** Get and set the Phase
|
||||
*/
|
||||
float getPhase () const;
|
||||
void setPhase (float phase);
|
||||
|
||||
/** Get and set the Base
|
||||
*/
|
||||
float getBase () const;
|
||||
void setBase (float base);
|
||||
|
||||
/** Get and set the Amplitude
|
||||
*/
|
||||
float getAmplitude () const;
|
||||
void setAmplitude (float amplitude);
|
||||
|
||||
virtual PUDynamicAttributeOscillate* clone() override;
|
||||
virtual void copyAttributesTo(PUDynamicAttribute* dynamicAttribute) override;
|
||||
|
||||
protected:
|
||||
OscillationType _oscillationType;
|
||||
float _frequency;
|
||||
float _phase;
|
||||
float _base;
|
||||
float _amplitude;
|
||||
};
|
||||
|
||||
/* Helper class to do some generic calculation.
|
||||
*/
|
||||
class PUDynamicAttributeHelper
|
||||
{
|
||||
public:
|
||||
/* Return the value of a DynamicAttribute, given te x value.
|
||||
*/
|
||||
float calculate(PUDynamicAttribute* dyn, float x, float defaultValue = 0.0f);
|
||||
};
|
||||
NS_CC_END
|
||||
|
||||
#endif
|
||||
227
extensions/Particle3D/PU/CCPUDynamicAttributeTranslator.cpp
Normal file
227
extensions/Particle3D/PU/CCPUDynamicAttributeTranslator.cpp
Normal file
@@ -0,0 +1,227 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCPUDynamicAttributeTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUParticleSystem3D.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
PUDynamicAttributeTranslator::PUDynamicAttributeTranslator()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
PUDynamicAttributeTranslator::~PUDynamicAttributeTranslator()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void PUDynamicAttributeTranslator::translate(PUScriptCompiler* compiler, PUAbstractNode *node)
|
||||
{
|
||||
PUObjectAbstractNode* obj = reinterpret_cast<PUObjectAbstractNode*>(node);
|
||||
|
||||
// The first value is the type
|
||||
std::string type = obj->name;
|
||||
|
||||
if (type == token[TOKEN_DYN_RANDOM])
|
||||
{
|
||||
_dynamicAttribute = new (std::nothrow) PUDynamicAttributeRandom();
|
||||
}
|
||||
else if (type == token[TOKEN_DYN_CURVED_LINEAR])
|
||||
{
|
||||
_dynamicAttribute = new (std::nothrow) PUDynamicAttributeCurved();
|
||||
}
|
||||
else if (type == token[TOKEN_DYN_CURVED_SPLINE])
|
||||
{
|
||||
_dynamicAttribute = new (std::nothrow) PUDynamicAttributeCurved();
|
||||
}
|
||||
else if (type == token[TOKEN_DYN_OSCILLATE])
|
||||
{
|
||||
_dynamicAttribute = new (std::nothrow) PUDynamicAttributeOscillate();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Create a fixed one.
|
||||
_dynamicAttribute = new (std::nothrow) PUDynamicAttributeFixed();
|
||||
}
|
||||
|
||||
// Run through properties
|
||||
for(PUAbstractNodeList::iterator i = obj->children.begin(); i != obj->children.end(); ++i)
|
||||
{
|
||||
if((*i)->type == ANT_PROPERTY)
|
||||
{
|
||||
PUPropertyAbstractNode* prop = reinterpret_cast<PUPropertyAbstractNode*>((*i));
|
||||
if (prop->name == token[TOKEN_DYN_MIN])
|
||||
{
|
||||
// Property: min
|
||||
if (_dynamicAttribute->getType() == PUDynamicAttribute::DAT_RANDOM)
|
||||
{
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_DYN_MIN], VAL_REAL))
|
||||
{
|
||||
float val = 0.0f;
|
||||
if(getFloat(*prop->values.front(), &val))
|
||||
{
|
||||
(static_cast<PUDynamicAttributeRandom*>(_dynamicAttribute))->setMin(val);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_DYN_MAX])
|
||||
{
|
||||
// Property: max
|
||||
if (_dynamicAttribute->getType() == PUDynamicAttribute::DAT_RANDOM)
|
||||
{
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_DYN_MAX], VAL_REAL))
|
||||
{
|
||||
float val = 0.0f;
|
||||
if(getFloat(*prop->values.front(), &val))
|
||||
{
|
||||
(static_cast<PUDynamicAttributeRandom*>(_dynamicAttribute))->setMax(val);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_DYN_CONTROL_POINT])
|
||||
{
|
||||
// Property: control_point
|
||||
if (_dynamicAttribute->getType() == PUDynamicAttribute::DAT_CURVED)
|
||||
{
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_DYN_CONTROL_POINT], VAL_VECTOR2))
|
||||
{
|
||||
Vec2 val;
|
||||
if(getVector2(prop->values.begin(), prop->values.end(), &val))
|
||||
{
|
||||
(static_cast<PUDynamicAttributeCurved*>(_dynamicAttribute))->addControlPoint(val.x, val.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_DYN_OSCILLATE_FREQUENCY])
|
||||
{
|
||||
// Property: oscillate_frequency
|
||||
if (_dynamicAttribute->getType() == PUDynamicAttribute::DAT_OSCILLATE)
|
||||
{
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_DYN_OSCILLATE_FREQUENCY], VAL_REAL))
|
||||
{
|
||||
float val = 0.0f;
|
||||
if(getFloat(*prop->values.front(), &val))
|
||||
{
|
||||
(static_cast<PUDynamicAttributeOscillate*>(_dynamicAttribute))->setFrequency(val);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_DYN_OSCILLATE_PHASE])
|
||||
{
|
||||
// Property: oscillate_phase
|
||||
if (_dynamicAttribute->getType() == PUDynamicAttribute::DAT_OSCILLATE)
|
||||
{
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_DYN_OSCILLATE_PHASE], VAL_REAL))
|
||||
{
|
||||
float val = 0.0f;
|
||||
if(getFloat(*prop->values.front(), &val))
|
||||
{
|
||||
(static_cast<PUDynamicAttributeOscillate*>(_dynamicAttribute))->setPhase(val);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_DYN_OSCILLATE_BASE])
|
||||
{
|
||||
// Property: oscillate_base
|
||||
if (_dynamicAttribute->getType() == PUDynamicAttribute::DAT_OSCILLATE)
|
||||
{
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_DYN_OSCILLATE_BASE], VAL_REAL))
|
||||
{
|
||||
float val = 0.0f;
|
||||
if(getFloat(*prop->values.front(), &val))
|
||||
{
|
||||
(static_cast<PUDynamicAttributeOscillate*>(_dynamicAttribute))->setBase(val);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_DYN_OSCILLATE_AMPLITUDE])
|
||||
{
|
||||
// Property: oscillate_amplitude
|
||||
if (_dynamicAttribute->getType() == PUDynamicAttribute::DAT_OSCILLATE)
|
||||
{
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_DYN_OSCILLATE_AMPLITUDE], VAL_REAL))
|
||||
{
|
||||
float val = 0.0f;
|
||||
if(getFloat(*prop->values.front(), &val))
|
||||
{
|
||||
(static_cast<PUDynamicAttributeOscillate*>(_dynamicAttribute))->setAmplitude(val);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_DYN_OSCILLATE_TYPE])
|
||||
{
|
||||
// Property: oscillate_type
|
||||
if (_dynamicAttribute->getType() == PUDynamicAttribute::DAT_OSCILLATE)
|
||||
{
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_DYN_OSCILLATE_TYPE], VAL_STRING))
|
||||
{
|
||||
std::string val;
|
||||
if(getString(*prop->values.front(), &val))
|
||||
{
|
||||
if (val == token[TOKEN_DYN_SINE])
|
||||
{
|
||||
(static_cast<PUDynamicAttributeOscillate*>(_dynamicAttribute))->setOscillationType(
|
||||
PUDynamicAttributeOscillate::OSCT_SINE);
|
||||
}
|
||||
else if (val == token[TOKEN_DYN_SQUARE])
|
||||
{
|
||||
(static_cast<PUDynamicAttributeOscillate*>(_dynamicAttribute))->setOscillationType(
|
||||
PUDynamicAttributeOscillate::OSCT_SQUARE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
errorUnexpectedProperty(compiler, prop);
|
||||
}
|
||||
|
||||
}
|
||||
else if((*i)->type == ANT_OBJECT)
|
||||
{
|
||||
processNode(compiler, *i);
|
||||
}
|
||||
else
|
||||
{
|
||||
errorUnexpectedToken(compiler, *i);
|
||||
}
|
||||
}
|
||||
|
||||
// Set it in the context
|
||||
obj->context = _dynamicAttribute;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_CC_END
|
||||
49
extensions/Particle3D/PU/CCPUDynamicAttributeTranslator.h
Normal file
49
extensions/Particle3D/PU/CCPUDynamicAttributeTranslator.h
Normal file
@@ -0,0 +1,49 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __CC_PU_PARTICLE_3D_DYNAMIC_ATTRIBUTE_TRANSLATOR_H__
|
||||
#define __CC_PU_PARTICLE_3D_DYNAMIC_ATTRIBUTE_TRANSLATOR_H__
|
||||
|
||||
#include "extensions/Particle3D/PU/CCPUDynamicAttribute.h"
|
||||
#include "extensions/Particle3D/PU/CCPUScriptTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUScriptCompiler.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
||||
class PUDynamicAttributeTranslator: public PUScriptTranslator
|
||||
{
|
||||
protected:
|
||||
PUDynamicAttribute* _dynamicAttribute;
|
||||
|
||||
public:
|
||||
PUDynamicAttributeTranslator();
|
||||
virtual ~PUDynamicAttributeTranslator();
|
||||
virtual void translate(PUScriptCompiler* compiler, PUAbstractNode *node);
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
#endif /* defined(__cocos2d_libs__CCParticle3DRendererTranslator__) */
|
||||
970
extensions/Particle3D/PU/CCPUEmitter.cpp
Executable file
970
extensions/Particle3D/PU/CCPUEmitter.cpp
Executable file
@@ -0,0 +1,970 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCPUEmitter.h"
|
||||
#include "extensions/Particle3D/PU/CCPUParticleSystem3D.h"
|
||||
#include "extensions/Particle3D/PU/CCPUUtil.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
// Constants
|
||||
const bool PUEmitter::DEFAULT_ENABLED = true;
|
||||
const Vec3 PUEmitter::DEFAULT_POSITION(0, 0, 0);
|
||||
const bool PUEmitter::DEFAULT_KEEP_LOCAL = false;
|
||||
const Vec3 PUEmitter::DEFAULT_DIRECTION(0, 1, 0);
|
||||
const Quaternion PUEmitter::DEFAULT_ORIENTATION(1, 0, 0, 0);
|
||||
const Quaternion PUEmitter::DEFAULT_ORIENTATION_RANGE_START(1, 0, 0, 0);
|
||||
const Quaternion PUEmitter::DEFAULT_ORIENTATION_RANGE_END(1, 0, 0, 0);
|
||||
//const Particle::ParticleType PUEmitter::DEFAULT_EMITS = VisualParticle::PT_VISUAL;
|
||||
const unsigned short PUEmitter::DEFAULT_START_TEXTURE_COORDS = 0;
|
||||
const unsigned short PUEmitter::DEFAULT_END_TEXTURE_COORDS = 0;
|
||||
const unsigned short PUEmitter::DEFAULT_TEXTURE_COORDS = 0;
|
||||
const Vec4 PUEmitter::DEFAULT_START_COLOUR_RANGE(0, 0, 0, 1);
|
||||
const Vec4 PUEmitter::DEFAULT_END_COLOUR_RANGE(1, 1, 1, 1);
|
||||
const Vec4 PUEmitter::DEFAULT_COLOUR(1, 1, 1, 1);
|
||||
const bool PUEmitter::DEFAULT_AUTO_DIRECTION = false;
|
||||
const bool PUEmitter::DEFAULT_FORCE_EMISSION = false;
|
||||
const float PUEmitter::DEFAULT_EMISSION_RATE = 10.0f;
|
||||
const float PUEmitter::DEFAULT_TIME_TO_LIVE = 3.0f;
|
||||
const float PUEmitter::DEFAULT_MASS = 1.0f;
|
||||
const float PUEmitter::DEFAULT_VELOCITY = 100.0f;
|
||||
const float PUEmitter::DEFAULT_DURATION = 0.0f;
|
||||
const float PUEmitter::DEFAULT_REPEAT_DELAY = 0.0f;
|
||||
const float PUEmitter::DEFAULT_ANGLE = 20.0f;
|
||||
const float PUEmitter::DEFAULT_DIMENSIONS = 0.0f;
|
||||
const float PUEmitter::DEFAULT_WIDTH = 0.0f;
|
||||
const float PUEmitter::DEFAULT_HEIGHT = 0.0f;
|
||||
const float PUEmitter::DEFAULT_DEPTH = 0.0f;
|
||||
|
||||
PUEmitter::PUEmitter()
|
||||
: //mEmitsType(DEFAULT_EMITS),
|
||||
//mEmitsName(StringUtil::BLANK),
|
||||
_emitterScale(Vec3::ONE),
|
||||
_particleDirection(DEFAULT_DIRECTION),
|
||||
_originalParticleDirection(DEFAULT_DIRECTION),
|
||||
//mParticleOrientation(Quaternion::IDENTITY),
|
||||
//mParticleOrientationRangeStart(Quaternion::IDENTITY),
|
||||
//mParticleOrientationRangeEnd(Quaternion::IDENTITY),
|
||||
_particleOrientationRangeSet(false),
|
||||
_dynParticleAllDimensionsSet(false),
|
||||
_dynParticleWidthSet(false),
|
||||
_dynParticleHeightSet(false),
|
||||
_dynParticleDepthSet(false),
|
||||
_remainder(0),
|
||||
_durationRemain(0),
|
||||
_dynDurationSet(false),
|
||||
_repeatDelayRemain(0),
|
||||
_dynRepeatDelaySet(false),
|
||||
_autoDirection(DEFAULT_AUTO_DIRECTION),
|
||||
_forceEmission(DEFAULT_FORCE_EMISSION),
|
||||
_originalForceEmission(false),
|
||||
_forceEmissionExecuted(false),
|
||||
_originalForceEmissionExecuted(false),
|
||||
//mName(StringUtil::BLANK),
|
||||
_particleColor(DEFAULT_COLOUR),
|
||||
_particleColorRangeStart(DEFAULT_START_COLOUR_RANGE),
|
||||
_particleColorRangeEnd(DEFAULT_END_COLOUR_RANGE),
|
||||
_particleColorRangeSet(false),
|
||||
_keepLocal(false),
|
||||
_particleTextureCoords(DEFAULT_TEXTURE_COORDS),
|
||||
_particleTextureCoordsRangeStart(DEFAULT_START_TEXTURE_COORDS),
|
||||
_particleTextureCoordsRangeEnd(DEFAULT_END_TEXTURE_COORDS),
|
||||
_particleTextureCoordsRangeSet(false),
|
||||
_originEnabled(true),
|
||||
_originEnabledSet(false),
|
||||
_emitsType(PUParticle3D::PT_VISUAL),
|
||||
_emitsEntity(nullptr),
|
||||
_isMarkedForEmission(false)
|
||||
{
|
||||
//particleType = PT_EMITTER;
|
||||
//mAliasType = AT_EMITTER;
|
||||
_dynEmissionRate = new (std::nothrow) PUDynamicAttributeFixed();
|
||||
(static_cast<PUDynamicAttributeFixed*>(_dynEmissionRate))->setValue(DEFAULT_EMISSION_RATE);
|
||||
_dynTotalTimeToLive = new (std::nothrow) PUDynamicAttributeFixed();
|
||||
(static_cast<PUDynamicAttributeFixed*>(_dynTotalTimeToLive))->setValue(DEFAULT_TIME_TO_LIVE);
|
||||
_dynParticleMass = new (std::nothrow) PUDynamicAttributeFixed();
|
||||
(static_cast<PUDynamicAttributeFixed*>(_dynParticleMass))->setValue(DEFAULT_MASS);
|
||||
_dynVelocity = new (std::nothrow) PUDynamicAttributeFixed();
|
||||
(static_cast<PUDynamicAttributeFixed*>(_dynVelocity))->setValue(DEFAULT_VELOCITY);
|
||||
_dynDuration = new (std::nothrow) PUDynamicAttributeFixed();
|
||||
(static_cast<PUDynamicAttributeFixed*>(_dynDuration))->setValue(DEFAULT_DURATION);
|
||||
_dynRepeatDelay = new (std::nothrow) PUDynamicAttributeFixed();
|
||||
(static_cast<PUDynamicAttributeFixed*>(_dynRepeatDelay))->setValue(DEFAULT_REPEAT_DELAY);
|
||||
_dynAngle = new (std::nothrow) PUDynamicAttributeFixed();
|
||||
(static_cast<PUDynamicAttributeFixed*>(_dynAngle))->setValue(DEFAULT_ANGLE);
|
||||
|
||||
// Set the dimensions attributes to 0; the default is to use the default dimensions of the ParticleTechnique
|
||||
_dynParticleAllDimensions = new (std::nothrow) PUDynamicAttributeFixed();
|
||||
(static_cast<PUDynamicAttributeFixed*>(_dynParticleAllDimensions))->setValue(DEFAULT_DIMENSIONS);
|
||||
_dynParticleWidth = new (std::nothrow) PUDynamicAttributeFixed();
|
||||
(static_cast<PUDynamicAttributeFixed*>(_dynParticleWidth))->setValue(DEFAULT_WIDTH);
|
||||
_dynParticleHeight = new (std::nothrow) PUDynamicAttributeFixed();
|
||||
(static_cast<PUDynamicAttributeFixed*>(_dynParticleHeight))->setValue(DEFAULT_HEIGHT);
|
||||
_dynParticleDepth = new (std::nothrow) PUDynamicAttributeFixed();
|
||||
(static_cast<PUDynamicAttributeFixed*>(_dynParticleDepth))->setValue(DEFAULT_DEPTH);
|
||||
}
|
||||
|
||||
PUEmitter::~PUEmitter()
|
||||
{
|
||||
_particleSystem = nullptr;
|
||||
|
||||
if (_dynEmissionRate)
|
||||
delete _dynEmissionRate;
|
||||
|
||||
if (_dynTotalTimeToLive)
|
||||
delete _dynTotalTimeToLive;
|
||||
|
||||
if (_dynParticleMass)
|
||||
delete _dynParticleMass;
|
||||
|
||||
if (_dynVelocity)
|
||||
delete _dynVelocity;
|
||||
|
||||
if (_dynDuration)
|
||||
delete _dynDuration;
|
||||
|
||||
if (_dynRepeatDelay)
|
||||
delete _dynRepeatDelay;
|
||||
|
||||
if (_dynParticleAllDimensions)
|
||||
delete _dynParticleAllDimensions;
|
||||
|
||||
if (_dynParticleWidth)
|
||||
delete _dynParticleWidth;
|
||||
|
||||
if (_dynParticleHeight)
|
||||
delete _dynParticleHeight;
|
||||
|
||||
if (_dynParticleDepth)
|
||||
delete _dynParticleDepth;
|
||||
|
||||
//if (mEmissionRateCameraDependency)
|
||||
// mCameraDependencyFactory.destroy(mEmissionRateCameraDependency);
|
||||
|
||||
if (_dynAngle)
|
||||
delete _dynAngle;
|
||||
}
|
||||
|
||||
void PUEmitter::updateEmitter(Particle3D* /*particle*/, float /*deltaTime*/)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void PUEmitter::emit(int /*count*/)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void PUEmitter::initParticlePosition( PUParticle3D* particle )
|
||||
{
|
||||
particle->position = getDerivedPosition();
|
||||
particle->originalPosition = particle->position;
|
||||
particle->latestPosition = particle->position;
|
||||
}
|
||||
|
||||
const Vec3& PUEmitter::getDerivedPosition()
|
||||
{
|
||||
if (_isMarkedForEmission){
|
||||
_derivedPosition = _position;
|
||||
}else {
|
||||
PUParticleSystem3D *ps = static_cast<PUParticleSystem3D *>(_particleSystem);
|
||||
Mat4 rotMat;
|
||||
Mat4::createRotation(ps->getDerivedOrientation(), &rotMat);
|
||||
_derivedPosition = ps->getDerivedPosition() + rotMat * Vec3(_position.x * _emitterScale.x, _position.y * _emitterScale.y, _position.z * _emitterScale.z);
|
||||
//_particleSystem->getNodeToWorldTransform().transformPoint(_position, &_derivedPosition);
|
||||
}
|
||||
return _derivedPosition;
|
||||
}
|
||||
|
||||
void PUEmitter::initParticleOrientation( PUParticle3D* particle )
|
||||
{
|
||||
if (_particleOrientationRangeSet)
|
||||
{
|
||||
// Generate random orientation 'between' start en end.
|
||||
Quaternion::lerp(_particleOrientationRangeStart, _particleOrientationRangeEnd, CCRANDOM_0_1(), &particle->orientation);
|
||||
}
|
||||
else
|
||||
{
|
||||
particle->orientation = _particleOrientation;
|
||||
}
|
||||
|
||||
// Set original orientation
|
||||
particle->originalOrientation = particle->orientation;
|
||||
}
|
||||
|
||||
void PUEmitter::initParticleDirection( PUParticle3D* particle )
|
||||
{
|
||||
// Use the default way of initialising the particle direction
|
||||
float angle = 0.0f;
|
||||
generateAngle(angle);
|
||||
if (angle != 0.0f)
|
||||
{
|
||||
particle->direction = PUUtil::randomDeviant(_particleDirection, angle, _upVector);
|
||||
}
|
||||
else
|
||||
{
|
||||
particle->direction = _particleDirection;
|
||||
}
|
||||
particle->originalDirection = particle->direction;
|
||||
particle->originalDirectionLength = particle->direction.length();
|
||||
}
|
||||
|
||||
void PUEmitter::generateAngle( float &angle )
|
||||
{
|
||||
float a = CC_DEGREES_TO_RADIANS(_dynamicAttributeHelper.calculate(_dynAngle, (static_cast<PUParticleSystem3D *>(_particleSystem))->getTimeElapsedSinceStart()));
|
||||
angle = a;
|
||||
if (_dynAngle->getType() == PUDynamicAttribute::DAT_FIXED)
|
||||
{
|
||||
// Make an exception here and don't use the fixed angle.
|
||||
angle = CCRANDOM_0_1() * angle;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned short PUEmitter::calculateRequestedParticles( float timeElapsed )
|
||||
{
|
||||
unsigned short requestedParticles = 0;
|
||||
|
||||
//FIXME
|
||||
if (_isEnabled)
|
||||
{
|
||||
if (_dynEmissionRate)
|
||||
{
|
||||
float rate = _dynEmissionRate->getValue((static_cast<PUParticleSystem3D *>(_particleSystem))->getTimeElapsedSinceStart());
|
||||
//if (_emissionRateCameraDependency)
|
||||
//{
|
||||
// // Affect the emission rate based on the camera distance
|
||||
// mEmissionRateCameraDependency->affect(rate, mParentTechnique->getCameraSquareDistance());
|
||||
//}
|
||||
if (_forceEmission)
|
||||
{
|
||||
if (_forceEmissionExecuted)
|
||||
{
|
||||
// It is a single-shot system, so there is nothing left anymore.
|
||||
requestedParticles = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Ignore the time. Just emit everything at once (if you absolutely need it).
|
||||
// The emitter cannot be disabled yet, because it needs to emit its particles first.
|
||||
requestedParticles = (unsigned short)rate;
|
||||
_forceEmissionExecuted = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Particle emission is time driven
|
||||
_remainder += rate * timeElapsed;
|
||||
requestedParticles = (unsigned short)_remainder;
|
||||
}
|
||||
|
||||
_remainder -= requestedParticles;
|
||||
}
|
||||
|
||||
// Determine whether the duration period has been exceeded.
|
||||
if (_dynDurationSet)
|
||||
{
|
||||
_durationRemain -= timeElapsed;
|
||||
if (_durationRemain <= 0)
|
||||
{
|
||||
setEnabled(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (_dynRepeatDelaySet)
|
||||
{
|
||||
_repeatDelayRemain -= timeElapsed;
|
||||
if (_repeatDelayRemain <= 0)
|
||||
{
|
||||
//// Initialise again (if stopfade isn't set)
|
||||
//if (mParentTechnique)
|
||||
//{
|
||||
// if (!mParentTechnique->isStopFade())
|
||||
// {
|
||||
// setEnabled(true);
|
||||
// }
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// setEnabled(true);
|
||||
//}
|
||||
|
||||
setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
return requestedParticles;
|
||||
}
|
||||
|
||||
void PUEmitter::setEnabled( bool enabled )
|
||||
{
|
||||
_isEnabled = enabled;
|
||||
if (!_originEnabledSet){
|
||||
_originEnabled = enabled;
|
||||
_originEnabledSet = true;
|
||||
}
|
||||
initTimeBased();
|
||||
}
|
||||
|
||||
bool PUEmitter::isEnabled( void ) const
|
||||
{
|
||||
return _isEnabled;
|
||||
}
|
||||
|
||||
void PUEmitter::notifyStart()
|
||||
{
|
||||
_forceEmission = _originalForceEmission;
|
||||
_forceEmissionExecuted = _originalForceEmissionExecuted;
|
||||
_remainder = 0;
|
||||
_durationRemain = 0;
|
||||
_repeatDelayRemain = 0;
|
||||
setEnabled(_originEnabled); // Also calls _initTimeBased
|
||||
}
|
||||
|
||||
void PUEmitter::notifyRescaled( const Vec3& scale )
|
||||
{
|
||||
_emitterScale = scale;
|
||||
}
|
||||
|
||||
void PUEmitter::notifyStop()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void PUEmitter::notifyPause()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void PUEmitter::notifyResume()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void PUEmitter::prepare()
|
||||
{
|
||||
if (!_emitsEntity){
|
||||
if (_emitsType == PUParticle3D::PT_EMITTER){
|
||||
auto emitter = static_cast<PUParticleSystem3D *>(_particleSystem)->getEmitter(_emitsName);
|
||||
if (emitter){
|
||||
emitter->setMarkedForEmission(true);
|
||||
_emitsEntity = emitter;
|
||||
}
|
||||
}
|
||||
else if (_emitsType == PUParticle3D::PT_TECHNIQUE){
|
||||
PUParticleSystem3D *system = static_cast<PUParticleSystem3D *>(_particleSystem)->getParentParticleSystem();
|
||||
if (system){
|
||||
auto children = system->getChildren();
|
||||
for (auto it : children){
|
||||
if (it->getName() == _emitsName)
|
||||
{
|
||||
static_cast<PUParticleSystem3D *>(it)->setMarkedForEmission(true);
|
||||
_emitsEntity = it;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_latestPosition = getDerivedPosition(); // V1.3.1
|
||||
}
|
||||
|
||||
void PUEmitter::unPrepare()
|
||||
{
|
||||
setForceEmission(_forceEmission);
|
||||
}
|
||||
|
||||
void PUEmitter::preUpdateEmitter( float /*deltaTime*/ )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void PUEmitter::postUpdateEmitter( float /*deltaTime*/ )
|
||||
{
|
||||
Vec3 currentPos = getDerivedPosition();
|
||||
_latestPositionDiff = currentPos - _latestPosition;
|
||||
_latestPosition = currentPos;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
bool PUEmitter::isKeepLocal() const
|
||||
{
|
||||
return _keepLocal;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUEmitter::setKeepLocal(bool keepLocal)
|
||||
{
|
||||
_keepLocal = keepLocal;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
bool PUEmitter::makeParticleLocal(PUParticle3D* particle)
|
||||
{
|
||||
if (!particle)
|
||||
return true;
|
||||
|
||||
if (!_keepLocal/* || hasEventFlags(PUParticle3D::PEF_EXPIRED)*/)
|
||||
return false;
|
||||
|
||||
particle->position += _latestPositionDiff;
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
const Vec4& PUEmitter::getParticleColor() const
|
||||
{
|
||||
return _particleColor;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUEmitter::setParticleColor(const Vec4& particleColor)
|
||||
{
|
||||
_particleColor = particleColor;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
const Vec4& PUEmitter::getParticleColorRangeStart() const
|
||||
{
|
||||
return _particleColorRangeStart;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUEmitter::setParticleColorRangeStart(const Vec4& particleColorRangeStart)
|
||||
{
|
||||
_particleColorRangeStart = particleColorRangeStart;
|
||||
_particleColorRangeSet = true;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
const Vec4& PUEmitter::getParticleColorRangeEnd() const
|
||||
{
|
||||
return _particleColorRangeEnd;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUEmitter::setParticleColorRangeEnd(const Vec4& particleColorRangeEnd)
|
||||
{
|
||||
_particleColorRangeEnd = particleColorRangeEnd;
|
||||
_particleColorRangeSet = true;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
const unsigned short& PUEmitter::getParticleTextureCoords() const
|
||||
{
|
||||
return _particleTextureCoords;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUEmitter::setParticleTextureCoords(const unsigned short& particleTextureCoords)
|
||||
{
|
||||
_particleTextureCoords = particleTextureCoords;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
const unsigned short& PUEmitter::getParticleTextureCoordsRangeStart() const
|
||||
{
|
||||
return _particleTextureCoordsRangeStart;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUEmitter::setParticleTextureCoordsRangeStart(const unsigned short& particleTextureCoordsRangeStart)
|
||||
{
|
||||
_particleTextureCoordsRangeStart = particleTextureCoordsRangeStart;
|
||||
_particleTextureCoordsRangeSet = true;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
const unsigned short& PUEmitter::getParticleTextureCoordsRangeEnd() const
|
||||
{
|
||||
return _particleTextureCoordsRangeEnd;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUEmitter::setParticleTextureCoordsRangeEnd(const unsigned short& particleTextureCoordsRangeEnd)
|
||||
{
|
||||
_particleTextureCoordsRangeEnd = particleTextureCoordsRangeEnd;
|
||||
_particleTextureCoordsRangeSet = true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
void PUEmitter::setEmitsName(const std::string& emitsName)
|
||||
{
|
||||
_emitsName = emitsName;
|
||||
_emitsEntity = nullptr;
|
||||
//if (!_emitsName.empty())
|
||||
//{
|
||||
// markedForEmission = true;
|
||||
// if (mParentTechnique)
|
||||
// {
|
||||
// // Notify the Technique that something changed
|
||||
// mParentTechnique->_notifyEmissionChange();
|
||||
// }
|
||||
//}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
void PUEmitter::setDynEmissionRate(PUDynamicAttribute* dynEmissionRate)
|
||||
{
|
||||
if (_dynEmissionRate)
|
||||
delete _dynEmissionRate;
|
||||
|
||||
_dynEmissionRate = dynEmissionRate;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUEmitter::setDynTotalTimeToLive(PUDynamicAttribute* dynTotalTimeToLive)
|
||||
{
|
||||
if (_dynTotalTimeToLive)
|
||||
delete _dynTotalTimeToLive;
|
||||
|
||||
_dynTotalTimeToLive = dynTotalTimeToLive;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUEmitter::setDynParticleMass(PUDynamicAttribute* dynParticleMass)
|
||||
{
|
||||
if (_dynParticleMass)
|
||||
delete _dynParticleMass;
|
||||
|
||||
_dynParticleMass = dynParticleMass;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUEmitter::setDynAngle(PUDynamicAttribute* dynAngle)
|
||||
{
|
||||
if (_dynAngle)
|
||||
delete _dynAngle;
|
||||
|
||||
_dynAngle = dynAngle;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUEmitter::setDynVelocity(PUDynamicAttribute* dynVelocity)
|
||||
{
|
||||
if (_dynVelocity)
|
||||
delete _dynVelocity;
|
||||
|
||||
_dynVelocity = dynVelocity;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUEmitter::setDynDuration(PUDynamicAttribute* dynDuration)
|
||||
{
|
||||
if (_dynDuration)
|
||||
delete _dynDuration;
|
||||
|
||||
_dynDuration = dynDuration;
|
||||
_dynDurationSet = true;
|
||||
initTimeBased();
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUEmitter::setDynDurationSet(bool durationSet)
|
||||
{
|
||||
_dynDurationSet = durationSet;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUEmitter::setDynRepeatDelay(PUDynamicAttribute* dynRepeatDelay)
|
||||
{
|
||||
if (_dynRepeatDelay)
|
||||
delete _dynRepeatDelay;
|
||||
|
||||
_dynRepeatDelay = dynRepeatDelay;
|
||||
_dynRepeatDelaySet = true;
|
||||
initTimeBased();
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUEmitter::setDynRepeatDelaySet(bool repeatDelaySet)
|
||||
{
|
||||
_dynRepeatDelaySet = repeatDelaySet;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUEmitter::setDynParticleAllDimensions(PUDynamicAttribute* dynParticleAllDimensions)
|
||||
{
|
||||
if (_dynParticleAllDimensions)
|
||||
delete _dynParticleAllDimensions;
|
||||
|
||||
_dynParticleAllDimensions = dynParticleAllDimensions;
|
||||
_dynParticleAllDimensionsSet = true;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUEmitter::setDynParticleAllDimensionsSet(bool particleAllDimensionsSet)
|
||||
{
|
||||
_dynParticleAllDimensionsSet = particleAllDimensionsSet;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUEmitter::setDynParticleWidth(PUDynamicAttribute* dynParticleWidth)
|
||||
{
|
||||
if (_dynParticleWidth)
|
||||
delete _dynParticleWidth;
|
||||
|
||||
_dynParticleWidth = dynParticleWidth;
|
||||
_dynParticleWidthSet = true;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUEmitter::setDynParticleWidthSet(bool particleWidthSet)
|
||||
{
|
||||
_dynParticleWidthSet = particleWidthSet;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUEmitter::setDynParticleHeight(PUDynamicAttribute* dynParticleHeight)
|
||||
{
|
||||
if (_dynParticleHeight)
|
||||
delete _dynParticleHeight;
|
||||
|
||||
_dynParticleHeight = dynParticleHeight;
|
||||
_dynParticleHeightSet = true;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUEmitter::setDynParticleHeightSet(bool particleHeightSet)
|
||||
{
|
||||
_dynParticleHeightSet = particleHeightSet;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUEmitter::setDynParticleDepth(PUDynamicAttribute* dynParticleDepth)
|
||||
{
|
||||
if (_dynParticleDepth)
|
||||
delete _dynParticleDepth;
|
||||
|
||||
_dynParticleDepth = dynParticleDepth;
|
||||
_dynParticleDepthSet = true;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUEmitter::setDynParticleDepthSet(bool particleDepthSet)
|
||||
{
|
||||
_dynParticleDepthSet = particleDepthSet;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
const Vec3& PUEmitter::getParticleDirection()
|
||||
{
|
||||
return _particleDirection;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUEmitter::setParticleDirection(const Vec3& direction)
|
||||
{
|
||||
_particleDirection = direction;
|
||||
_originalParticleDirection = direction;
|
||||
_particleDirection.normalize();
|
||||
|
||||
_upVector = PUUtil::perpendicular(_particleDirection);
|
||||
_upVector.normalize();
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
const Vec3& PUEmitter::getOriginalParticleDirection() const
|
||||
{
|
||||
return _originalParticleDirection;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
const Quaternion& PUEmitter::getParticleOrientation() const
|
||||
{
|
||||
return _particleOrientation;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUEmitter::setParticleOrientation(const Quaternion& orientation)
|
||||
{
|
||||
_particleOrientation = orientation;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
const Quaternion& PUEmitter::getParticleOrientationRangeStart() const
|
||||
{
|
||||
return _particleOrientationRangeStart;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUEmitter::setParticleOrientationRangeStart(const Quaternion& orientationRangeStart)
|
||||
{
|
||||
_particleOrientationRangeStart = orientationRangeStart;
|
||||
_particleOrientationRangeSet = true;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
const Quaternion& PUEmitter::getParticleOrientationRangeEnd() const
|
||||
{
|
||||
return _particleOrientationRangeEnd;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUEmitter::setParticleOrientationRangeEnd(const Quaternion& orientationRangeEnd)
|
||||
{
|
||||
_particleOrientationRangeEnd = orientationRangeEnd;
|
||||
_particleOrientationRangeSet = true;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
bool PUEmitter::isAutoDirection() const
|
||||
{
|
||||
return _autoDirection;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUEmitter::setAutoDirection(bool autoDirection)
|
||||
{
|
||||
_autoDirection = autoDirection;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
bool PUEmitter::isForceEmission() const
|
||||
{
|
||||
return _forceEmission;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
void PUEmitter::setForceEmission(bool forceEmission)
|
||||
{
|
||||
_forceEmission = forceEmission;
|
||||
_originalForceEmission = forceEmission;
|
||||
_forceEmissionExecuted = false;
|
||||
_originalForceEmissionExecuted = false;
|
||||
}
|
||||
|
||||
void PUEmitter::initTimeBased( void )
|
||||
{
|
||||
if (_isEnabled)
|
||||
{
|
||||
if (_dynDurationSet)
|
||||
{
|
||||
_durationRemain = _dynamicAttributeHelper.calculate(_dynDuration, (static_cast<PUParticleSystem3D *>(_particleSystem))->getTimeElapsedSinceStart());
|
||||
}
|
||||
|
||||
/** Determine whether duration must be used. If it is used, the emitter should at least be enabled.
|
||||
@remarks
|
||||
Note, that if the duration has been exceeded, the emitter is disabled. It makes perfect sense to enable
|
||||
the emitter again when the duration is initialised with a valid value (> 0).
|
||||
*/
|
||||
if (_durationRemain > 0)
|
||||
{
|
||||
_isEnabled = true;
|
||||
_repeatDelayRemain = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_dynRepeatDelaySet)
|
||||
{
|
||||
_repeatDelayRemain = _dynamicAttributeHelper.calculate(_dynRepeatDelay, (static_cast<PUParticleSystem3D *>(_particleSystem))->getTimeElapsedSinceStart());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PUEmitter::initParticleForEmission( PUParticle3D* particle )
|
||||
{
|
||||
// Initialise the particle position (localspace)
|
||||
particle->parentEmitter = this;
|
||||
initParticlePosition(particle);
|
||||
initParticleDirection(particle);
|
||||
initParticleVelocity(particle);
|
||||
initParticleOrientation(particle);
|
||||
initParticleMass(particle);
|
||||
initParticleColor(particle);
|
||||
initParticleTextureCoords(particle);
|
||||
particle->totalTimeToLive = initParticleTimeToLive();
|
||||
particle->timeToLive = particle->totalTimeToLive;
|
||||
|
||||
// Generate particles' own dimensions if defined.
|
||||
initParticleDimensions(particle);
|
||||
}
|
||||
|
||||
void PUEmitter::initParticleVelocity( PUParticle3D* particle )
|
||||
{
|
||||
float scalar = _dynamicAttributeHelper.calculate(_dynVelocity, (static_cast<PUParticleSystem3D *>(_particleSystem))->getTimeElapsedSinceStart(), 1.0f);
|
||||
particle->direction *= scalar;
|
||||
particle->originalVelocity = scalar;
|
||||
particle->originalScaledDirectionLength = particle->direction.length();
|
||||
}
|
||||
|
||||
void PUEmitter::initParticleMass( PUParticle3D* particle )
|
||||
{
|
||||
float mass = _dynamicAttributeHelper.calculate(_dynParticleMass, (static_cast<PUParticleSystem3D *>(_particleSystem))->getTimeElapsedSinceStart(), PUParticle3D::DEFAULT_MASS);
|
||||
particle->mass = mass;
|
||||
}
|
||||
|
||||
void PUEmitter::initParticleColor( PUParticle3D* particle )
|
||||
{
|
||||
if (_particleColorRangeSet)
|
||||
{
|
||||
if (_particleColorRangeStart.x < _particleColorRangeEnd.x)
|
||||
particle->color.x = cocos2d::random(_particleColorRangeStart.x, _particleColorRangeEnd.x);
|
||||
else
|
||||
particle->color.x = cocos2d::random(_particleColorRangeEnd.x, _particleColorRangeStart.x);
|
||||
if (_particleColorRangeStart.y < _particleColorRangeEnd.y)
|
||||
particle->color.y = cocos2d::random(_particleColorRangeStart.y, _particleColorRangeEnd.y);
|
||||
else
|
||||
particle->color.y = cocos2d::random(_particleColorRangeEnd.y, _particleColorRangeStart.y);
|
||||
if (_particleColorRangeStart.z < _particleColorRangeEnd.z)
|
||||
particle->color.z = cocos2d::random(_particleColorRangeStart.z, _particleColorRangeEnd.z);
|
||||
else
|
||||
particle->color.z = cocos2d::random(_particleColorRangeEnd.z, _particleColorRangeStart.z);
|
||||
if (_particleColorRangeStart.w < _particleColorRangeEnd.w)
|
||||
particle->color.w = cocos2d::random(_particleColorRangeStart.w, _particleColorRangeEnd.w);
|
||||
else
|
||||
particle->color.w = cocos2d::random(_particleColorRangeEnd.w, _particleColorRangeStart.w);
|
||||
}
|
||||
else
|
||||
{
|
||||
particle->color = _particleColor;
|
||||
}
|
||||
|
||||
// Set original colour
|
||||
particle->originalColor = particle->color;
|
||||
}
|
||||
|
||||
void PUEmitter::initParticleTextureCoords( PUParticle3D* particle )
|
||||
{
|
||||
if (_particleTextureCoordsRangeSet)
|
||||
{
|
||||
particle->textureCoordsCurrent = (unsigned short)cocos2d::random((float)_particleTextureCoordsRangeStart, (float)_particleTextureCoordsRangeEnd + 0.999f);
|
||||
}
|
||||
else
|
||||
{
|
||||
particle->textureCoordsCurrent = _particleTextureCoords;
|
||||
}
|
||||
}
|
||||
|
||||
float PUEmitter::initParticleTimeToLive()
|
||||
{
|
||||
return _dynamicAttributeHelper.calculate(_dynTotalTimeToLive, (static_cast<PUParticleSystem3D *>(_particleSystem))->getTimeElapsedSinceStart(), PUParticle3D::DEFAULT_TTL);
|
||||
}
|
||||
|
||||
void PUEmitter::initParticleDimensions( PUParticle3D* particle )
|
||||
{
|
||||
// Only continue if one of them is set
|
||||
if (_dynParticleAllDimensionsSet || _dynParticleWidthSet || _dynParticleHeightSet || _dynParticleDepthSet)
|
||||
{
|
||||
// Set all dimensions equal ...
|
||||
float extend = 0;
|
||||
if (_dynParticleAllDimensionsSet && _dynParticleAllDimensions)
|
||||
{
|
||||
extend = _dynamicAttributeHelper.calculate(_dynParticleAllDimensions, (static_cast<PUParticleSystem3D *>(_particleSystem))->getTimeElapsedSinceStart());
|
||||
particle->setOwnDimensions(_emitterScale.x * extend, _emitterScale.y * extend, _emitterScale.z * extend);
|
||||
return;
|
||||
}
|
||||
|
||||
// ... or set the dimensions independent from each other
|
||||
float width = 0;
|
||||
float height = 0;
|
||||
float depth = 0;
|
||||
if (_dynParticleWidthSet && _dynParticleWidth)
|
||||
{
|
||||
width = _dynamicAttributeHelper.calculate(_dynParticleWidth, (static_cast<PUParticleSystem3D *>(_particleSystem))->getTimeElapsedSinceStart());
|
||||
}
|
||||
if (_dynParticleHeightSet && _dynParticleHeight)
|
||||
{
|
||||
height = _dynamicAttributeHelper.calculate(_dynParticleHeight, (static_cast<PUParticleSystem3D *>(_particleSystem))->getTimeElapsedSinceStart());
|
||||
}
|
||||
if (_dynParticleDepthSet && _dynParticleDepth)
|
||||
{
|
||||
depth = _dynamicAttributeHelper.calculate(_dynParticleDepth, (static_cast<PUParticleSystem3D *>(_particleSystem))->getTimeElapsedSinceStart());
|
||||
}
|
||||
|
||||
/** Set the width, height and depth if at least one of them is set.
|
||||
@remarks
|
||||
If one of the dimensions is 0, it will be overridden by the default value later on.
|
||||
*/
|
||||
if (_dynParticleWidthSet || _dynParticleHeightSet || _dynParticleDepthSet)
|
||||
{
|
||||
particle->setOwnDimensions(_emitterScale.x * width, _emitterScale.y * height, _emitterScale.z * depth);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Just set the width, height and depth, but these are just the default settings; the particle doesn't
|
||||
// have own dimensions. Recalculate the bounding sphere radius.
|
||||
particle->width = _emitterScale.x * (static_cast<PUParticleSystem3D *>(_particleSystem))->getDefaultWidth();
|
||||
particle->height = _emitterScale.y * (static_cast<PUParticleSystem3D *>(_particleSystem))->getDefaultHeight();
|
||||
particle->depth = _emitterScale.z * (static_cast<PUParticleSystem3D *>(_particleSystem))->getDefaultDepth();
|
||||
particle->calculateBoundingSphereRadius();
|
||||
}
|
||||
}
|
||||
|
||||
bool PUEmitter::isEmitterDone() const
|
||||
{
|
||||
return !(_isEnabled || _dynRepeatDelaySet);
|
||||
}
|
||||
|
||||
Ref* PUEmitter::getEmitsEntityPtr() const
|
||||
{
|
||||
return _emitsEntity;
|
||||
}
|
||||
|
||||
void PUEmitter::copyAttributesTo( PUEmitter* emitter )
|
||||
{
|
||||
emitter->setName(_name);
|
||||
emitter->setEmitterType(_emitterType);
|
||||
emitter->setEmitsName(_emitsName);
|
||||
emitter->setEmitsType(_emitsType);
|
||||
emitter->_position = _position;
|
||||
emitter->_isEnabled = _isEnabled;
|
||||
emitter->_originEnabled = _originEnabled;
|
||||
emitter->_originEnabledSet = _originEnabledSet;
|
||||
emitter->_particleDirection = _particleDirection;
|
||||
emitter->_originalParticleDirection = _originalParticleDirection;
|
||||
emitter->_particleOrientation = _particleOrientation;
|
||||
emitter->_particleOrientationRangeStart = _particleOrientationRangeStart;
|
||||
emitter->_particleOrientationRangeEnd = _particleOrientationRangeEnd;
|
||||
emitter->_particleOrientationRangeSet = _particleOrientationRangeSet;
|
||||
emitter->_isMarkedForEmission = _isMarkedForEmission;
|
||||
emitter->_particleSystem = _particleSystem;
|
||||
emitter->_autoDirection = _autoDirection;
|
||||
emitter->setForceEmission(_forceEmission);
|
||||
emitter->_dynDurationSet = _dynDurationSet;
|
||||
emitter->_dynRepeatDelaySet = _dynRepeatDelaySet;
|
||||
emitter->_dynParticleAllDimensionsSet = _dynParticleAllDimensionsSet;
|
||||
emitter->_dynParticleWidthSet = _dynParticleWidthSet;
|
||||
emitter->_dynParticleHeightSet = _dynParticleHeightSet;
|
||||
emitter->_dynParticleDepthSet = _dynParticleDepthSet;
|
||||
emitter->_emitterScale = _emitterScale;
|
||||
emitter->_particleColor = _particleColor;
|
||||
emitter->_particleColorRangeStart = _particleColorRangeStart;
|
||||
emitter->_particleColorRangeEnd = _particleColorRangeEnd;
|
||||
emitter->_particleColorRangeSet = _particleColorRangeSet;
|
||||
emitter->_particleTextureCoords = _particleTextureCoords;
|
||||
emitter->_particleTextureCoordsRangeStart = _particleTextureCoordsRangeStart;
|
||||
emitter->_particleTextureCoordsRangeEnd = _particleTextureCoordsRangeEnd;
|
||||
emitter->_particleTextureCoordsRangeSet = _particleTextureCoordsRangeSet;
|
||||
emitter->_keepLocal = _keepLocal;
|
||||
|
||||
// Copy Dyn. Emission rate if available
|
||||
emitter->setDynEmissionRate(getDynEmissionRate()->clone());
|
||||
|
||||
// Copy Dyn. Total time to live if available
|
||||
emitter->setDynTotalTimeToLive(getDynTotalTimeToLive()->clone());
|
||||
|
||||
// Copy Dyn. Velocity if available
|
||||
emitter->setDynVelocity(getDynVelocity()->clone());
|
||||
|
||||
// Copy Dyn. Duration if available
|
||||
if (_dynDurationSet)
|
||||
{
|
||||
emitter->setDynDuration(getDynDuration()->clone());
|
||||
}
|
||||
|
||||
// Copy Dyn. RepeatDelay if available
|
||||
if (_dynRepeatDelaySet)
|
||||
{
|
||||
emitter->setDynRepeatDelay(getDynRepeatDelay()->clone());
|
||||
}
|
||||
|
||||
// Copy Dyn. Particle Mass if available
|
||||
emitter->setDynParticleMass(getDynParticleMass()->clone());
|
||||
|
||||
// Copy Dyn. Angle if available
|
||||
emitter->setDynAngle(getDynAngle()->clone());
|
||||
|
||||
// Copy Dyn. own width, height and depth if available
|
||||
if (_dynParticleAllDimensionsSet)
|
||||
{
|
||||
emitter->setDynParticleAllDimensions(getDynParticleAllDimensions()->clone());
|
||||
}
|
||||
if (_dynParticleWidthSet)
|
||||
{
|
||||
emitter->setDynParticleWidth(getDynParticleWidth()->clone());
|
||||
}
|
||||
if (_dynParticleHeightSet)
|
||||
{
|
||||
emitter->setDynParticleHeight(getDynParticleHeight()->clone());
|
||||
}
|
||||
if (_dynParticleDepthSet)
|
||||
{
|
||||
emitter->setDynParticleDepth(getDynParticleDepth()->clone());
|
||||
}
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
581
extensions/Particle3D/PU/CCPUEmitter.h
Normal file
581
extensions/Particle3D/PU/CCPUEmitter.h
Normal file
@@ -0,0 +1,581 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __CC_PU_PARTICLE_3D_EMITTER_H__
|
||||
#define __CC_PU_PARTICLE_3D_EMITTER_H__
|
||||
|
||||
#include "base/CCRef.h"
|
||||
#include "math/CCMath.h"
|
||||
#include "extensions/Particle3D/CCParticle3DEmitter.h"
|
||||
#include "extensions/Particle3D/PU/CCPUDynamicAttribute.h"
|
||||
#include "extensions/Particle3D/PU/CCPUParticleSystem3D.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
NS_CC_BEGIN
|
||||
struct PUParticle3D;
|
||||
class PUParticleSystem3D;
|
||||
/**
|
||||
* 3d particle emitter
|
||||
*/
|
||||
class CC_DLL PUEmitter : public Particle3DEmitter
|
||||
{
|
||||
friend class PUParticleSystem3D;
|
||||
public:
|
||||
|
||||
// Default values
|
||||
static const bool DEFAULT_ENABLED;
|
||||
static const Vec3 DEFAULT_POSITION;
|
||||
static const bool DEFAULT_KEEP_LOCAL;
|
||||
static const Vec3 DEFAULT_DIRECTION;
|
||||
static const Quaternion DEFAULT_ORIENTATION;
|
||||
static const Quaternion DEFAULT_ORIENTATION_RANGE_START;
|
||||
static const Quaternion DEFAULT_ORIENTATION_RANGE_END;
|
||||
//static const Particle::ParticleType DEFAULT_EMITS;
|
||||
static const unsigned short DEFAULT_START_TEXTURE_COORDS;
|
||||
static const unsigned short DEFAULT_END_TEXTURE_COORDS;
|
||||
static const unsigned short DEFAULT_TEXTURE_COORDS;
|
||||
static const Vec4 DEFAULT_START_COLOUR_RANGE;
|
||||
static const Vec4 DEFAULT_END_COLOUR_RANGE;
|
||||
static const Vec4 DEFAULT_COLOUR;
|
||||
static const bool DEFAULT_AUTO_DIRECTION;
|
||||
static const bool DEFAULT_FORCE_EMISSION;
|
||||
static const float DEFAULT_EMISSION_RATE;
|
||||
static const float DEFAULT_TIME_TO_LIVE;
|
||||
static const float DEFAULT_MASS;
|
||||
static const float DEFAULT_VELOCITY;
|
||||
static const float DEFAULT_DURATION;
|
||||
static const float DEFAULT_REPEAT_DELAY;
|
||||
static const float DEFAULT_ANGLE;
|
||||
static const float DEFAULT_DIMENSIONS;
|
||||
static const float DEFAULT_WIDTH;
|
||||
static const float DEFAULT_HEIGHT;
|
||||
static const float DEFAULT_DEPTH;
|
||||
|
||||
PUEmitter();
|
||||
virtual ~PUEmitter();
|
||||
|
||||
virtual void notifyStart();
|
||||
virtual void notifyStop();
|
||||
virtual void notifyPause();
|
||||
virtual void notifyResume();
|
||||
virtual void notifyRescaled(const Vec3& scale);
|
||||
virtual void prepare();
|
||||
virtual void unPrepare();
|
||||
virtual void preUpdateEmitter(float deltaTime);
|
||||
virtual void updateEmitter(Particle3D *particle, float deltaTime) override;
|
||||
virtual void postUpdateEmitter(float deltaTime);
|
||||
virtual unsigned short calculateRequestedParticles(float timeElapsed);
|
||||
|
||||
virtual void emit(int count) override;
|
||||
|
||||
void setLocalPosition(const Vec3 &pos) { _position = pos; };
|
||||
const Vec3 getLocalPosition() const { return _position; };
|
||||
/** Calculate the derived position of the affector.
|
||||
@remarks
|
||||
Note, that in script, the position is set as localspace, while if the affector is
|
||||
emitted, its position is automatically transformed. This function always returns
|
||||
the derived position.
|
||||
*/
|
||||
const Vec3& getDerivedPosition();
|
||||
|
||||
/** Enables or disables the emitter.
|
||||
*/
|
||||
void setEnabled (bool enabled);
|
||||
|
||||
bool isEnabled() const;
|
||||
|
||||
bool isEmitterDone() const;
|
||||
|
||||
/** Todo
|
||||
*/
|
||||
const std::string& getEmitterType() const { return _emitterType; }
|
||||
void setEmitterType(const std::string& emitterType) {_emitterType = emitterType;};
|
||||
|
||||
/** Todo
|
||||
*/
|
||||
const std::string& getName() const { return _name; }
|
||||
void setName(const std::string& name) {_name = name;};
|
||||
|
||||
/** Todo
|
||||
*/
|
||||
PUDynamicAttribute* getDynAngle() const { return _dynAngle; }
|
||||
void setDynAngle(PUDynamicAttribute* dynAngle);
|
||||
|
||||
/** Todo
|
||||
*/
|
||||
PUDynamicAttribute* getDynEmissionRate() const { return _dynEmissionRate; }
|
||||
void setDynEmissionRate(PUDynamicAttribute* dynEmissionRate);
|
||||
|
||||
/** Todo
|
||||
*/
|
||||
PUDynamicAttribute* getDynTotalTimeToLive() const { return _dynTotalTimeToLive; }
|
||||
void setDynTotalTimeToLive(PUDynamicAttribute* dynTotalTimeToLive);
|
||||
|
||||
/** Todo
|
||||
*/
|
||||
PUDynamicAttribute* getDynParticleMass() const { return _dynParticleMass; }
|
||||
void setDynParticleMass(PUDynamicAttribute* dynParticleMass);
|
||||
|
||||
/** Todo
|
||||
*/
|
||||
PUDynamicAttribute* getDynVelocity() const { return _dynVelocity; }
|
||||
void setDynVelocity(PUDynamicAttribute* dynVelocity);
|
||||
|
||||
/** Todo
|
||||
*/
|
||||
PUDynamicAttribute* getDynDuration() const { return _dynDuration; }
|
||||
void setDynDuration(PUDynamicAttribute* dynDuration);
|
||||
void setDynDurationSet(bool durationSet);
|
||||
|
||||
/** Todo
|
||||
*/
|
||||
PUDynamicAttribute* getDynRepeatDelay() const { return _dynRepeatDelay; }
|
||||
void setDynRepeatDelay(PUDynamicAttribute* dynRepeatDelay);
|
||||
void setDynRepeatDelaySet(bool repeatDelaySet);
|
||||
|
||||
/** Todo
|
||||
*/
|
||||
PUDynamicAttribute* getDynParticleAllDimensions() const { return _dynParticleAllDimensions; }
|
||||
void setDynParticleAllDimensions(PUDynamicAttribute* dynParticleAllDimensions);
|
||||
void setDynParticleAllDimensionsSet(bool particleAllDimensionsSet);
|
||||
|
||||
/** Todo
|
||||
*/
|
||||
PUDynamicAttribute* getDynParticleWidth() const { return _dynParticleWidth; }
|
||||
void setDynParticleWidth(PUDynamicAttribute* dynParticleWidth);
|
||||
void setDynParticleWidthSet(bool particleWidthSet);
|
||||
|
||||
/** Todo
|
||||
*/
|
||||
PUDynamicAttribute* getDynParticleHeight() const { return _dynParticleHeight; }
|
||||
void setDynParticleHeight(PUDynamicAttribute* dynParticleHeight);
|
||||
void setDynParticleHeightSet(bool particleHeightSet);
|
||||
|
||||
/** Todo
|
||||
*/
|
||||
PUDynamicAttribute* getDynParticleDepth() const { return _dynParticleDepth; }
|
||||
void setDynParticleDepth(PUDynamicAttribute* dynParticleDepth);
|
||||
void setDynParticleDepthSet(bool particleDepthSet);
|
||||
|
||||
///** Todo
|
||||
//*/
|
||||
//ParticleType getEmitsType() const { return mEmitsType; }
|
||||
//void setEmitsType(ParticleType emitsType) {mEmitsType = emitsType;};
|
||||
|
||||
/** Todo
|
||||
*/
|
||||
const std::string& getEmitsName() const { return _emitsName; }
|
||||
void setEmitsName(const std::string& emitsName);
|
||||
PUParticle3D::ParticleType getEmitsType() const { return _emitsType; }
|
||||
void setEmitsType(PUParticle3D::ParticleType type) {_emitsType = type;};
|
||||
Ref* getEmitsEntityPtr() const;
|
||||
bool isMarkedForEmission() const {return _isMarkedForEmission;};
|
||||
void setMarkedForEmission(bool isMarked) {_isMarkedForEmission = isMarked;};
|
||||
|
||||
/** Returns the base direction of the particle that is going to be emitted.
|
||||
*/
|
||||
const Vec3& getParticleDirection();
|
||||
|
||||
/** Returns the originally set particle direction. This value is not affected by affectors, angle, etc.
|
||||
*/
|
||||
const Vec3& getOriginalParticleDirection() const;
|
||||
|
||||
/** Returns the base orientation of the particle that is going to be emitted.
|
||||
*/
|
||||
const Quaternion& getParticleOrientation() const;
|
||||
|
||||
/** Set the orientation of the particle.
|
||||
*/
|
||||
void setParticleOrientation(const Quaternion& orientation);
|
||||
|
||||
/** Returns the start orientation of the particle that is going to be emitted.
|
||||
@remarks
|
||||
The orientation is generated random between mParticleOrientationRangeStart and mParticleOrientationRangeEnd.
|
||||
*/
|
||||
const Quaternion& getParticleOrientationRangeStart() const;
|
||||
|
||||
/** Set start orientation of the particle that is going to be emitted.
|
||||
@remarks
|
||||
The orientation is generated random between mParticleOrientationRangeStart and mParticleOrientationRangeEnd.
|
||||
*/
|
||||
void setParticleOrientationRangeStart(const Quaternion& orientationRangeStart);
|
||||
|
||||
/** Returns the end orientation of the particle that is going to be emitted.
|
||||
@remarks
|
||||
The orientation is generated random between mParticleOrientationRangeStart and mParticleOrientationRangeEnd.
|
||||
*/
|
||||
const Quaternion& getParticleOrientationRangeEnd() const;
|
||||
|
||||
/** Set end orientation of the particle that is going to be emitted.
|
||||
@remarks
|
||||
The orientation is generated random between mParticleOrientationRangeStart and mParticleOrientationRangeEnd.
|
||||
*/
|
||||
void setParticleOrientationRangeEnd(const Quaternion& orientationRangeEnd);
|
||||
|
||||
/** Sets the direction of the particle that the emitter is emitting.
|
||||
@remarks
|
||||
Don't confuse this with the emitters own direction.
|
||||
@param direction The base direction of emitted particles.
|
||||
*/
|
||||
void setParticleDirection(const Vec3& direction);
|
||||
|
||||
/** Todo
|
||||
*/
|
||||
bool isAutoDirection() const;
|
||||
|
||||
/** Todo
|
||||
*/
|
||||
void setAutoDirection(bool autoDirection);
|
||||
|
||||
/** Todo
|
||||
*/
|
||||
bool isForceEmission() const;
|
||||
|
||||
/** Todo
|
||||
*/
|
||||
void setForceEmission(bool forceEmission);
|
||||
|
||||
/** Get the colour of a particle that will be emitted.
|
||||
*/
|
||||
const Vec4& getParticleColor() const;
|
||||
|
||||
/** Set the colour of an emitted particle.
|
||||
*/
|
||||
void setParticleColor(const Vec4& particleColour);
|
||||
|
||||
/** Get the colour range start of an emitted particle.
|
||||
*/
|
||||
const Vec4& getParticleColorRangeStart() const;
|
||||
|
||||
/** Set the colour range start of an emitted particle. This is the lower value used to generate a random colour.
|
||||
*/
|
||||
void setParticleColorRangeStart(const Vec4& particleColourRangeStart);
|
||||
|
||||
/** Get the colour range end of an emitted particle.
|
||||
*/
|
||||
const Vec4& getParticleColorRangeEnd() const;
|
||||
|
||||
/** Set the colour range end of an emitted particle. This is the upper value used to generate a random colour.
|
||||
*/
|
||||
void setParticleColorRangeEnd(const Vec4& particleColourRangeEnd);
|
||||
|
||||
/** Get the texture coords of an emitted particle.
|
||||
*/
|
||||
const unsigned short& getParticleTextureCoords() const;
|
||||
|
||||
/** Set the texture coords of an emitted particle.
|
||||
*/
|
||||
void setParticleTextureCoords(const unsigned short& particleTextureCoords);
|
||||
|
||||
/** Get the texture coords range start of an emitted particle.
|
||||
*/
|
||||
const unsigned short& getParticleTextureCoordsRangeStart() const;
|
||||
|
||||
/** Set the texture coords range start of an emitted particle. This is the lower value used to set a random texture coords.
|
||||
*/
|
||||
void setParticleTextureCoordsRangeStart(const unsigned short& particleTextureCoordsRangeStart);
|
||||
|
||||
/** Get the texture coords range end of an emitted particle.
|
||||
*/
|
||||
const unsigned short& getParticleTextureCoordsRangeEnd() const;
|
||||
|
||||
/** Set the texture coords range end of an emitted particle. This is the upper value used to set a random texture coords.
|
||||
*/
|
||||
void setParticleTextureCoordsRangeEnd(const unsigned short& particleTextureCoordsRangeEnd);
|
||||
|
||||
/** Todo
|
||||
*/
|
||||
bool isKeepLocal() const;
|
||||
|
||||
/** If this attribute is set to 'true', the particles are emitted relative to the emitter
|
||||
*/
|
||||
void setKeepLocal(bool keepLocal);
|
||||
|
||||
/** Transforms the particle position in a local position relative to the emitter
|
||||
*/
|
||||
bool makeParticleLocal(PUParticle3D* particle);
|
||||
|
||||
virtual PUEmitter* clone() = 0;
|
||||
virtual void copyAttributesTo (PUEmitter* emitter);
|
||||
|
||||
protected:
|
||||
|
||||
/** Todo
|
||||
*/
|
||||
virtual void initParticlePosition(PUParticle3D* particle);
|
||||
|
||||
/** Internal method for generating the particle direction.
|
||||
*/
|
||||
virtual void initParticleDirection(PUParticle3D* particle);
|
||||
|
||||
/** Internal method for generating the particle orientation.
|
||||
*/
|
||||
virtual void initParticleOrientation(PUParticle3D* particle);
|
||||
|
||||
virtual void initParticleVelocity(PUParticle3D* particle);
|
||||
|
||||
virtual void initParticleMass(PUParticle3D* particle);
|
||||
|
||||
virtual void initParticleColor(PUParticle3D* particle);
|
||||
|
||||
virtual void initParticleTextureCoords(PUParticle3D* particle);
|
||||
|
||||
virtual float initParticleTimeToLive();
|
||||
|
||||
virtual void initParticleDimensions(PUParticle3D* particle);
|
||||
|
||||
virtual void initParticleForEmission(PUParticle3D* particle);
|
||||
|
||||
/** Initialise some attributes that are time-based.
|
||||
*/
|
||||
inline void initTimeBased();
|
||||
|
||||
/** Internal method for generating the angle.
|
||||
*/
|
||||
void generateAngle(float &angle);
|
||||
|
||||
protected:
|
||||
|
||||
Vec3 _position;
|
||||
|
||||
Vec3 _latestPosition;
|
||||
Vec3 _latestPositionDiff;
|
||||
|
||||
Vec3 _derivedPosition;
|
||||
/** Although the scale is on a Particle System level, the emitter can also be scaled.
|
||||
*/
|
||||
Vec3 _emitterScale;
|
||||
|
||||
// Type of the emitter
|
||||
std::string _emitterType;
|
||||
|
||||
// Name of the emitter (optional)
|
||||
std::string _name;
|
||||
|
||||
/** Direction (and speed) of the emitted particle
|
||||
@remarks
|
||||
Don't confuse the particle direction with the direction of the emitter itself.
|
||||
The particleDirection is the direction of an emitted particle.
|
||||
*/
|
||||
Vec3 _particleDirection;
|
||||
|
||||
/** The original direction of the emitted particle
|
||||
@remarks
|
||||
Don't confuse this with the particles' originalDirection.
|
||||
*/
|
||||
Vec3 _originalParticleDirection;
|
||||
|
||||
/** Orientation of the particle as soon as it is emitted.
|
||||
@remarks
|
||||
This is only visible if a renderer is used that renders 3D particles.
|
||||
*/
|
||||
Quaternion _particleOrientation;
|
||||
|
||||
/** If set, the range generates a random orientation between start and end.
|
||||
*/
|
||||
Quaternion _particleOrientationRangeStart;
|
||||
Quaternion _particleOrientationRangeEnd;
|
||||
bool _particleOrientationRangeSet;
|
||||
|
||||
// Angle around direction which particles may be emitted
|
||||
PUDynamicAttribute* _dynAngle;
|
||||
|
||||
// Rate of particle emission.
|
||||
PUDynamicAttribute* _dynEmissionRate;
|
||||
|
||||
//// Identifies the type of particle this emitter emits (default is visual particle).
|
||||
//ParticleType mEmitsType;
|
||||
|
||||
// Identifies the name of particle this emitter emits (default is visual particle, so there is no name)
|
||||
std::string _emitsName;
|
||||
|
||||
/** Dynamic attribute used to generate the total time to live.
|
||||
*/
|
||||
PUDynamicAttribute* _dynTotalTimeToLive;
|
||||
|
||||
/** Dynamic attribute used to generate the mass of a particle.
|
||||
*/
|
||||
PUDynamicAttribute* _dynParticleMass;
|
||||
|
||||
/** Dynamic attribute used to generate the velocity of a particle.
|
||||
*/
|
||||
PUDynamicAttribute* _dynVelocity;
|
||||
|
||||
/** Dynamic attribute used to define the duration of the emitter.
|
||||
*/
|
||||
PUDynamicAttribute* _dynDuration;
|
||||
|
||||
/** Dynamic attribute used to define the repeat/delay of the emitter.
|
||||
*/
|
||||
PUDynamicAttribute* _dynRepeatDelay;
|
||||
|
||||
/** Dynamic attribute used to define the (own) dimensions of a particle.
|
||||
@remarks
|
||||
In the Particle Technique it is possible to set the default dimensions for all particles, but it
|
||||
is also possible to set the dimensions per particle. Note, that this only applies to visual particles,
|
||||
of course. This attribute is used to x, y and z dimensions with the value.
|
||||
*/
|
||||
PUDynamicAttribute* _dynParticleAllDimensions;
|
||||
bool _dynParticleAllDimensionsSet;
|
||||
|
||||
/** Dynamic attribute used to define the (own) width of a particle.
|
||||
@remarks
|
||||
In the Particle Technique it is possible to set the default width for all particles, but it
|
||||
is also possible to set the width per particle. Note, that this only applies to visual particles,
|
||||
of course.
|
||||
*/
|
||||
PUDynamicAttribute* _dynParticleWidth;
|
||||
bool _dynParticleWidthSet;
|
||||
|
||||
/** Dynamic attribute used to define the (own) height of a particle.
|
||||
@remarks
|
||||
In the Particle Technique it is possible to set the default height for all particles, but it
|
||||
is also possible to set the height per particle. Note, that this only applies to visual particles,
|
||||
of course.
|
||||
*/
|
||||
PUDynamicAttribute* _dynParticleHeight;
|
||||
bool _dynParticleHeightSet;
|
||||
|
||||
/** Dynamic attribute used to define the (own) depth of a particle.
|
||||
@remarks
|
||||
In the Particle Technique it is possible to set the default depth for all particles, but it
|
||||
is also possible to set the depth per particle. Note, that this only applies to visual particles,
|
||||
of course.
|
||||
*/
|
||||
PUDynamicAttribute* _dynParticleDepth;
|
||||
bool _dynParticleDepthSet;
|
||||
|
||||
/** Notional up vector, just used to speed up generation of variant directions.
|
||||
*/
|
||||
Vec3 _upVector;
|
||||
|
||||
/** Particles that are left to be emitted from the previous time.
|
||||
*/
|
||||
float _remainder;
|
||||
|
||||
///** Helper factory
|
||||
//*/
|
||||
//DynamicAttributeFactory mDynamicAttributeFactory;
|
||||
|
||||
/** Helper class
|
||||
*/
|
||||
PUDynamicAttributeHelper _dynamicAttributeHelper;
|
||||
|
||||
/** Duration remainder.
|
||||
*/
|
||||
float _durationRemain;
|
||||
|
||||
/** Indication to determine whether duration is set.
|
||||
*/
|
||||
bool _dynDurationSet;
|
||||
|
||||
/** Repeat/delay remainder.
|
||||
*/
|
||||
float _repeatDelayRemain;
|
||||
|
||||
/** Indication to determine whether repeat/delay is set.
|
||||
*/
|
||||
bool _dynRepeatDelaySet;
|
||||
|
||||
/** Auto direction means that the direction of a particle is not determined by the
|
||||
direction vector that has been set, but the direction vector is generated based on
|
||||
the shape of the emitter. In most cases this means that the particle direction is
|
||||
perpendicular on the shape of the emitter.
|
||||
@remarks
|
||||
This attribute has only a meaning for certain emitters.
|
||||
*/
|
||||
bool _autoDirection;
|
||||
|
||||
/** In normal cases, emission is regulated by time. This prevents that too much particles are
|
||||
emitted at once, which causes a drop in the framerate. In some cases you just want to emit
|
||||
all particles immediately without any delay. Setting the 'mForceEmission' to true enables this.
|
||||
In that case, the emission rate defines the number of particles that are emitted immediately.
|
||||
If the emission rate is 100, the emitter emits 100 particles at once and then disables.
|
||||
*/
|
||||
bool _forceEmission;
|
||||
|
||||
/** Original value, used to set it back.
|
||||
*/
|
||||
bool _originalForceEmission;
|
||||
|
||||
/** If mForceEmission has been set to true and if all particles are emitted, the mForceEmissionExecuted
|
||||
is also set to true, preventing any further 'forced emission'.
|
||||
*/
|
||||
bool _forceEmissionExecuted;
|
||||
|
||||
/** Original value, used to set it back.
|
||||
*/
|
||||
bool _originalForceEmissionExecuted;
|
||||
|
||||
/** Colour that is assigned to an emitted particle.
|
||||
*/
|
||||
Vec4 _particleColor;
|
||||
|
||||
/** Used to randomize the colour of an emitted particle.
|
||||
*/
|
||||
Vec4 _particleColorRangeStart;
|
||||
|
||||
/** Used to randomize the colour of an emitted particle.
|
||||
*/
|
||||
Vec4 _particleColorRangeEnd;
|
||||
|
||||
/** Used to determine whether the colour range has been set.
|
||||
*/
|
||||
bool _particleColorRangeSet;
|
||||
|
||||
/** Determines whether particle positions should be kept local in relation to the emitter.
|
||||
*/
|
||||
bool _keepLocal;
|
||||
|
||||
/** Texture coords that is assigned to an emitted particle (only works if the renderer uses it)
|
||||
*/
|
||||
unsigned short _particleTextureCoords;
|
||||
|
||||
/** Used to randomize the texture coords of an emitted particle.
|
||||
*/
|
||||
unsigned short _particleTextureCoordsRangeStart;
|
||||
|
||||
/** Used to randomize the texture coords of an emitted particle.
|
||||
*/
|
||||
unsigned short _particleTextureCoordsRangeEnd;
|
||||
|
||||
/** Used to determine whether the texture coords range has been set.
|
||||
*/
|
||||
bool _particleTextureCoordsRangeSet;
|
||||
|
||||
bool _originEnabled;
|
||||
bool _originEnabledSet;
|
||||
|
||||
PUParticle3D::ParticleType _emitsType;
|
||||
Ref *_emitsEntity;
|
||||
|
||||
bool _isMarkedForEmission;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif
|
||||
102
extensions/Particle3D/PU/CCPUEmitterManager.cpp
Normal file
102
extensions/Particle3D/PU/CCPUEmitterManager.cpp
Normal file
@@ -0,0 +1,102 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCPUEmitterManager.h"
|
||||
#include "extensions/Particle3D/PU/CCPUBoxEmitter.h"
|
||||
#include "extensions/Particle3D/PU/CCPUCircleEmitter.h"
|
||||
#include "extensions/Particle3D/PU/CCPULineEmitter.h"
|
||||
#include "extensions/Particle3D/PU/CCPUMeshSurfaceEmitter.h"
|
||||
#include "extensions/Particle3D/PU/CCPUPointEmitter.h"
|
||||
#include "extensions/Particle3D/PU/CCPUPositionEmitter.h"
|
||||
#include "extensions/Particle3D/PU/CCPUSlaveEmitter.h"
|
||||
#include "extensions/Particle3D/PU/CCPUSphereSurfaceEmitter.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
PUEmitterManager::PUEmitterManager()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
PUEmitterManager::~PUEmitterManager()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
PUEmitterManager* PUEmitterManager::Instance()
|
||||
{
|
||||
static PUEmitterManager ptm;
|
||||
return &ptm;
|
||||
}
|
||||
|
||||
PUScriptTranslator* PUEmitterManager::getTranslator( const std::string &type )
|
||||
{
|
||||
if (type == "Box"){
|
||||
return &_boxEmitterTranlator;
|
||||
}else if (type == "Circle"){
|
||||
return &_circleEmitterTranlator;
|
||||
}else if (type == "Line"){
|
||||
return &_lineEmitterTranlator;
|
||||
}else if (type == "MeshSurface"){
|
||||
return &_meshSurfaceEmitterTranlator;
|
||||
}else if (type == "Point"){
|
||||
return &_pointEmitterTranlator;
|
||||
}else if (type == "Position"){
|
||||
return &_positionEmitterTranlator;
|
||||
}else if (type == "Slave"){
|
||||
return &_slaveEmitterTranlator;
|
||||
}else if (type == "SphereSurface"){
|
||||
return &_sphereSurfaceEmitterTranlator;
|
||||
}else if (type == "Vertex"){
|
||||
return nullptr;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PUEmitter* PUEmitterManager::createEmitter( const std::string &type )
|
||||
{
|
||||
if (type == "Box"){
|
||||
return CCPUBoxEmitter::create();
|
||||
}else if (type == "Circle"){
|
||||
return PUCircleEmitter::create();
|
||||
}else if (type == "Line"){
|
||||
return PULineEmitter::create();
|
||||
}else if (type == "MeshSurface"){
|
||||
return PUMeshSurfaceEmitter::create();
|
||||
}else if (type == "Point"){
|
||||
return PUPointEmitter::create();
|
||||
}else if (type == "Position"){
|
||||
return PUPositionEmitter::create();
|
||||
}else if (type == "Slave"){
|
||||
return PUSlaveEmitter::create();
|
||||
}else if (type == "SphereSurface"){
|
||||
return PUSphereSurfaceEmitter::create();
|
||||
}else if (type == "Vertex"){
|
||||
return nullptr;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
75
extensions/Particle3D/PU/CCPUEmitterManager.h
Normal file
75
extensions/Particle3D/PU/CCPUEmitterManager.h
Normal file
@@ -0,0 +1,75 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __CC_PU_PARTICLE_3D_EMITTER_MANAGER_H__
|
||||
#define __CC_PU_PARTICLE_3D_EMITTER_MANAGER_H__
|
||||
|
||||
#include "base/CCRef.h"
|
||||
#include "extensions/Particle3D/PU/CCPUScriptTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUEmitter.h"
|
||||
#include "extensions/Particle3D/PU/CCPUBoxEmitterTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUCircleEmitterTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPULineEmitterTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUMeshSurfaceEmitterTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUPointEmitterTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUPositionEmitterTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUSlaveEmitterTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUSphereSurfaceEmitterTranslator.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class PUEmitterManager
|
||||
{
|
||||
public:
|
||||
|
||||
static PUEmitterManager* Instance();
|
||||
|
||||
/**
|
||||
*/
|
||||
PUScriptTranslator* getTranslator(const std::string &type);
|
||||
PUEmitter* createEmitter(const std::string &type);
|
||||
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
PUEmitterManager();
|
||||
~PUEmitterManager();
|
||||
|
||||
protected:
|
||||
|
||||
CCPUBoxEmitterTranslator _boxEmitterTranlator;
|
||||
PUCircleEmitterTranslator _circleEmitterTranlator;
|
||||
PULineEmitterTranslator _lineEmitterTranlator;
|
||||
PUMeshSurfaceEmitterTranslator _meshSurfaceEmitterTranlator;
|
||||
PUPointEmitterTranslator _pointEmitterTranlator;
|
||||
PUPositionEmitterTranslator _positionEmitterTranlator;
|
||||
PUSlaveEmitterTranslator _slaveEmitterTranlator;
|
||||
PUSphereSurfaceEmitterTranslator _sphereSurfaceEmitterTranlator;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
|
||||
#endif
|
||||
649
extensions/Particle3D/PU/CCPUEmitterTranslator.cpp
Normal file
649
extensions/Particle3D/PU/CCPUEmitterTranslator.cpp
Normal file
@@ -0,0 +1,649 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCPUEmitterTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUParticleSystem3D.h"
|
||||
#include "extensions/Particle3D/PU/CCPUDynamicAttribute.h"
|
||||
#include "extensions/Particle3D/PU/CCPUDynamicAttributeTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUEmitterManager.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
PUEmitterTranslator::PUEmitterTranslator()
|
||||
:_emitter(nullptr)
|
||||
{
|
||||
}
|
||||
//-------------------------------------------------------------------------
|
||||
void PUEmitterTranslator::translate(PUScriptCompiler* compiler, PUAbstractNode *node)
|
||||
{
|
||||
PUObjectAbstractNode* obj = reinterpret_cast<PUObjectAbstractNode*>(node);
|
||||
PUObjectAbstractNode* parent = obj->parent ? reinterpret_cast<PUObjectAbstractNode*>(obj->parent) : 0;
|
||||
|
||||
// The name of the obj is the type of the emitter
|
||||
// Remark: This can be solved by using a listener, so that obj->values is filled with type + name. Something for later
|
||||
std::string type;
|
||||
if(!obj->name.empty())
|
||||
{
|
||||
type = obj->name;
|
||||
}
|
||||
|
||||
|
||||
//// Get the factory
|
||||
//ParticleEmitterFactory* particleEmitterFactory = ParticleSystemManager::getSingletonPtr()->getEmitterFactory(type);
|
||||
//if (!particleEmitterFactory)
|
||||
//{
|
||||
// compiler->addError(ScriptCompiler::CE_INVALIDPARAMETERS, obj->file, obj->line);
|
||||
// return;
|
||||
//}
|
||||
PUScriptTranslator *particleEmitterTranlator = PUEmitterManager::Instance()->getTranslator(type);
|
||||
if (!particleEmitterTranlator) return;
|
||||
|
||||
//// Create the emitter
|
||||
//mEmitter = ParticleSystemManager::getSingletonPtr()->createEmitter(type);
|
||||
//if (!mEmitter)
|
||||
//{
|
||||
// compiler->addError(ScriptCompiler::CE_INVALIDPARAMETERS, obj->file, obj->line);
|
||||
// return;
|
||||
//}
|
||||
_emitter = PUEmitterManager::Instance()->createEmitter(type);
|
||||
if (!_emitter) return;
|
||||
_emitter->setEmitterType(type);
|
||||
|
||||
if (parent && parent->context)
|
||||
{
|
||||
PUParticleSystem3D* system = static_cast<PUParticleSystem3D*>(parent->context);
|
||||
system->addEmitter(_emitter);
|
||||
}
|
||||
|
||||
// The first value is the (optional) name
|
||||
std::string name;
|
||||
if(!obj->values.empty())
|
||||
{
|
||||
getString(*obj->values.front(), &name);
|
||||
_emitter->setName(name);
|
||||
}
|
||||
|
||||
// Set it in the context
|
||||
obj->context = _emitter;
|
||||
|
||||
// Run through properties
|
||||
for(PUAbstractNodeList::iterator i = obj->children.begin(); i != obj->children.end(); ++i)
|
||||
{
|
||||
if((*i)->type == ANT_PROPERTY)
|
||||
{
|
||||
PUPropertyAbstractNode* prop = reinterpret_cast<PUPropertyAbstractNode*>((*i));
|
||||
if (prop->name == token[TOKEN_ENABLED])
|
||||
{
|
||||
// Property: enabled
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_ENABLED], VAL_BOOL))
|
||||
{
|
||||
bool val;
|
||||
if(getBoolean(*prop->values.front(), &val))
|
||||
{
|
||||
_emitter->setEnabled(val);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_POSITION])
|
||||
{
|
||||
// Property: position
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_POSITION], VAL_VECTOR3))
|
||||
{
|
||||
Vec3 val;
|
||||
if(getVector3(prop->values.begin(), prop->values.end(), &val))
|
||||
{
|
||||
//mEmitter->position = val;
|
||||
//mEmitter->originalPosition = val;
|
||||
_emitter->setLocalPosition(val);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_EMITTER_DIRECTION])
|
||||
{
|
||||
// Property: direction
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_DIRECTION], VAL_VECTOR3))
|
||||
{
|
||||
Vec3 val;
|
||||
if(getVector3(prop->values.begin(), prop->values.end(), &val))
|
||||
{
|
||||
_emitter->setParticleDirection(val);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_EMITTER_ORIENTATION])
|
||||
{
|
||||
// Property: orientation
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_ORIENTATION], VAL_QUATERNION))
|
||||
{
|
||||
Quaternion val;
|
||||
if(getQuaternion(prop->values.begin(), prop->values.end(), &val))
|
||||
{
|
||||
_emitter->setParticleOrientation(val);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_EMITTER_START_ORIENTATION_RANGE])
|
||||
{
|
||||
// Property: start_orientation_range
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_START_ORIENTATION_RANGE], VAL_QUATERNION))
|
||||
{
|
||||
Quaternion val;
|
||||
if(getQuaternion(prop->values.begin(), prop->values.end(), &val))
|
||||
{
|
||||
_emitter->setParticleOrientationRangeStart(val);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_EMITTER_ORIENTATION_RANGE_START])
|
||||
{
|
||||
// Property: range_start_orientation (deprecated and replaced by start_orientation_range)
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_ORIENTATION_RANGE_START], VAL_QUATERNION))
|
||||
{
|
||||
Quaternion val;
|
||||
if(getQuaternion(prop->values.begin(), prop->values.end(), &val))
|
||||
{
|
||||
_emitter->setParticleOrientationRangeStart(val);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_EMITTER_END_ORIENTATION_RANGE])
|
||||
{
|
||||
// Property: end_orientation_range
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_END_ORIENTATION_RANGE], VAL_QUATERNION))
|
||||
{
|
||||
Quaternion val;
|
||||
if(getQuaternion(prop->values.begin(), prop->values.end(), &val))
|
||||
{
|
||||
_emitter->setParticleOrientationRangeEnd(val);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_EMITTER_ORIENTATION_RANGE_END])
|
||||
{
|
||||
// Property: range_end_orientation (deprecated and replaced by end_orientation_range)
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_ORIENTATION_RANGE_END], VAL_QUATERNION))
|
||||
{
|
||||
Quaternion val;
|
||||
if(getQuaternion(prop->values.begin(), prop->values.end(), &val))
|
||||
{
|
||||
_emitter->setParticleOrientationRangeEnd(val);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_EMITTER_EMISSION_RATE])
|
||||
{
|
||||
// Property: emission_rate
|
||||
// If it is a property, it is a fixed value
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_EMISSION_RATE], VAL_REAL))
|
||||
{
|
||||
float val = 0.0f;
|
||||
if(getFloat(*prop->values.front(), &val))
|
||||
{
|
||||
PUDynamicAttributeFixed* dynamicAttributeFixed = new (std::nothrow) PUDynamicAttributeFixed();
|
||||
dynamicAttributeFixed->setValue(val);
|
||||
_emitter->setDynEmissionRate(dynamicAttributeFixed);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_TIME_TO_LIVE])
|
||||
{
|
||||
// Property: time_to_live
|
||||
// If it is a property, it is a fixed value
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_TIME_TO_LIVE], VAL_REAL))
|
||||
{
|
||||
float val = 0.0f;
|
||||
if(getFloat(*prop->values.front(), &val))
|
||||
{
|
||||
PUDynamicAttributeFixed* dynamicAttributeFixed = new (std::nothrow) PUDynamicAttributeFixed();
|
||||
dynamicAttributeFixed->setValue(val);
|
||||
_emitter->setDynTotalTimeToLive(dynamicAttributeFixed);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_EMITTER_MASS])
|
||||
{
|
||||
// Property: mass
|
||||
// If it is a property, it is a fixed value
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_MASS], VAL_REAL))
|
||||
{
|
||||
float val = 0.0f;
|
||||
if(getFloat(*prop->values.front(), &val))
|
||||
{
|
||||
PUDynamicAttributeFixed* dynamicAttributeFixed = new (std::nothrow) PUDynamicAttributeFixed();
|
||||
dynamicAttributeFixed->setValue(val);
|
||||
_emitter->setDynParticleMass(dynamicAttributeFixed);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_EMITTER_START_TEXCOORDS_RANGE])
|
||||
{
|
||||
// Property: start_texture_coords_range
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_START_TEXCOORDS_RANGE], VAL_UINT))
|
||||
{
|
||||
unsigned int val = 0;
|
||||
if(getUInt(*prop->values.front(), &val))
|
||||
{
|
||||
_emitter->setParticleTextureCoordsRangeStart(val);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_EMITTER_START_TEXCOORDS])
|
||||
{
|
||||
// Property: start_texture_coords (deprecated and replaced by start_texture_coords_range)
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_START_TEXCOORDS], VAL_UINT))
|
||||
{
|
||||
unsigned int val = 0;
|
||||
if(getUInt(*prop->values.front(), &val))
|
||||
{
|
||||
_emitter->setParticleTextureCoordsRangeStart(val);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_EMITTER_END_TEXCOORDS_RANGE])
|
||||
{
|
||||
// Property: end_texture_coords_range
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_END_TEXCOORDS_RANGE], VAL_UINT))
|
||||
{
|
||||
unsigned int val = 0;
|
||||
if(getUInt(*prop->values.front(), &val))
|
||||
{
|
||||
_emitter->setParticleTextureCoordsRangeEnd(val);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_EMITTER_END_TEXCOORDS])
|
||||
{
|
||||
// Property: end_texture_coords (deprecated and replaced by end_texture_coords_range)
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_END_TEXCOORDS], VAL_UINT))
|
||||
{
|
||||
unsigned int val = 0;
|
||||
if(getUInt(*prop->values.front(), &val))
|
||||
{
|
||||
_emitter->setParticleTextureCoordsRangeEnd(val);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_EMITTER_TEXCOORDS])
|
||||
{
|
||||
// Property: texture_coords
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_TEXCOORDS], VAL_UINT))
|
||||
{
|
||||
unsigned int val = 0;
|
||||
if(getUInt(*prop->values.front(), &val))
|
||||
{
|
||||
_emitter->setParticleTextureCoords(val);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_EMITTER_START_COLOUR_RANGE])
|
||||
{
|
||||
// Property: start_colour_range
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_START_COLOUR_RANGE], VAL_COLOURVALUE))
|
||||
{
|
||||
Vec4 val;
|
||||
if(getVector4(prop->values.begin(), prop->values.end(), &val))
|
||||
{
|
||||
_emitter->setParticleColorRangeStart(val);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_EMITTER_END_COLOUR_RANGE])
|
||||
{
|
||||
// Property: end_colour_range
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_END_COLOUR_RANGE], VAL_COLOURVALUE))
|
||||
{
|
||||
Vec4 val;
|
||||
if(getVector4(prop->values.begin(), prop->values.end(), &val))
|
||||
{
|
||||
_emitter->setParticleColorRangeEnd(val);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_EMITTER_COLOUR])
|
||||
{
|
||||
// Property: colour
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_COLOUR], VAL_COLOURVALUE))
|
||||
{
|
||||
Vec4 val;
|
||||
if(getVector4(prop->values.begin(), prop->values.end(), &val))
|
||||
{
|
||||
_emitter->setParticleColor(val);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_VELOCITY])
|
||||
{
|
||||
// Property: velocity
|
||||
// If it is a property, it is a fixed value
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_VELOCITY], VAL_REAL))
|
||||
{
|
||||
float val = 0.0f;
|
||||
if(getFloat(*prop->values.front(), &val))
|
||||
{
|
||||
PUDynamicAttributeFixed* dynamicAttributeFixed = new (std::nothrow) PUDynamicAttributeFixed();
|
||||
dynamicAttributeFixed->setValue(val);
|
||||
_emitter->setDynVelocity(dynamicAttributeFixed);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_EMITTER_DURATION])
|
||||
{
|
||||
// Property: duration
|
||||
// If it is a property, it is a fixed value
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_DURATION], VAL_REAL))
|
||||
{
|
||||
float val = 0.0f;
|
||||
if(getFloat(*prop->values.front(), &val))
|
||||
{
|
||||
PUDynamicAttributeFixed* dynamicAttributeFixed = new (std::nothrow) PUDynamicAttributeFixed();
|
||||
dynamicAttributeFixed->setValue(val);
|
||||
_emitter->setDynDuration(dynamicAttributeFixed);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_EMITTER_REPEAT_DELAY])
|
||||
{
|
||||
// Property: repeat_delay
|
||||
// If it is a property, it is a fixed value
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_REPEAT_DELAY], VAL_REAL))
|
||||
{
|
||||
float val = 0.0f;
|
||||
if(getFloat(*prop->values.front(), &val))
|
||||
{
|
||||
PUDynamicAttributeFixed* dynamicAttributeFixed = new (std::nothrow) PUDynamicAttributeFixed();
|
||||
dynamicAttributeFixed->setValue(val);
|
||||
_emitter->setDynRepeatDelay(dynamicAttributeFixed);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_EMITTER_EMITS])
|
||||
{
|
||||
// Property: emits
|
||||
if (passValidatePropertyNumberOfValues(compiler, prop, token[TOKEN_EMITTER_EMITS], 2))
|
||||
{
|
||||
std::string particleType;
|
||||
PUAbstractNodeList::const_iterator it = prop->values.begin();
|
||||
if (getString(**it, &particleType))
|
||||
{
|
||||
if (particleType == token[TOKEN_VISUAL_PARTICLE])
|
||||
{
|
||||
_emitter->setEmitsType(PUParticle3D::PT_VISUAL);
|
||||
}
|
||||
else if (particleType == token[TOKEN_EMITTER_PARTICLE])
|
||||
{
|
||||
_emitter->setEmitsType(PUParticle3D::PT_EMITTER);
|
||||
}
|
||||
else if (particleType == token[TOKEN_AFFECTOR_PARTICLE])
|
||||
{
|
||||
_emitter->setEmitsType(PUParticle3D::PT_AFFECTOR);
|
||||
}
|
||||
else if (particleType == token[TOKEN_TECHNIQUE_PARTICLE])
|
||||
{
|
||||
_emitter->setEmitsType(PUParticle3D::PT_TECHNIQUE);
|
||||
}
|
||||
else if (particleType == token[TOKEN_SYSTEM_PARTICLE])
|
||||
{
|
||||
_emitter->setEmitsType(PUParticle3D::PT_SYSTEM);
|
||||
}
|
||||
++it;
|
||||
if (getString(**it, &name))
|
||||
{
|
||||
_emitter->setEmitsName(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_ANGLE])
|
||||
{
|
||||
// Property: angle
|
||||
// If it is a property, it is a fixed value
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_ANGLE], VAL_REAL))
|
||||
{
|
||||
float val = 0.0f;
|
||||
if(getFloat(*prop->values.front(), &val))
|
||||
{
|
||||
PUDynamicAttributeFixed* dynamicAttributeFixed = new (std::nothrow) PUDynamicAttributeFixed();
|
||||
dynamicAttributeFixed->setValue(val);
|
||||
_emitter->setDynAngle(dynamicAttributeFixed);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_EMITTER_ALL_PARTICLE_DIM])
|
||||
{
|
||||
// Property: all_particle_dimensions
|
||||
// If it is a property, it is a fixed value
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_ALL_PARTICLE_DIM], VAL_REAL))
|
||||
{
|
||||
float val = 0.0f;
|
||||
if(getFloat(*prop->values.front(), &val))
|
||||
{
|
||||
PUDynamicAttributeFixed* dynamicAttributeFixed = new (std::nothrow) PUDynamicAttributeFixed();
|
||||
dynamicAttributeFixed->setValue(val);
|
||||
_emitter->setDynParticleAllDimensions(dynamicAttributeFixed);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_EMITTER_PARTICLE_WIDTH])
|
||||
{
|
||||
// Property: particle_width
|
||||
// If it is a property, it is a fixed value
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_PARTICLE_WIDTH], VAL_REAL))
|
||||
{
|
||||
float val = 0.0f;
|
||||
if(getFloat(*prop->values.front(), &val))
|
||||
{
|
||||
PUDynamicAttributeFixed* dynamicAttributeFixed = new (std::nothrow) PUDynamicAttributeFixed();
|
||||
dynamicAttributeFixed->setValue(val);
|
||||
_emitter->setDynParticleWidth(dynamicAttributeFixed);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_EMITTER_PARTICLE_HEIGHT])
|
||||
{
|
||||
// Property: particle_height
|
||||
// If it is a property, it is a fixed value
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_PARTICLE_HEIGHT], VAL_REAL))
|
||||
{
|
||||
float val = 0.0f;
|
||||
if(getFloat(*prop->values.front(), &val))
|
||||
{
|
||||
PUDynamicAttributeFixed* dynamicAttributeFixed = new (std::nothrow) PUDynamicAttributeFixed();
|
||||
dynamicAttributeFixed->setValue(val);
|
||||
_emitter->setDynParticleHeight(dynamicAttributeFixed);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_EMITTER_PARTICLE_DEPTH])
|
||||
{
|
||||
// Property: particle_depth
|
||||
// If it is a property, it is a fixed value
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_PARTICLE_DEPTH], VAL_REAL))
|
||||
{
|
||||
float val = 0.0f;
|
||||
if(getFloat(*prop->values.front(), &val))
|
||||
{
|
||||
PUDynamicAttributeFixed* dynamicAttributeFixed = new (std::nothrow) PUDynamicAttributeFixed();
|
||||
dynamicAttributeFixed->setValue(val);
|
||||
_emitter->setDynParticleDepth(dynamicAttributeFixed);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_EMITTER_AUTO_DIRECTION])
|
||||
{
|
||||
// Property: auto_direction
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_AUTO_DIRECTION], VAL_BOOL))
|
||||
{
|
||||
bool val;
|
||||
if(getBoolean(*prop->values.front(), &val))
|
||||
{
|
||||
_emitter->setAutoDirection(val);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_KEEP_LOCAL])
|
||||
{
|
||||
// Property: keep_local
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_KEEP_LOCAL], VAL_BOOL))
|
||||
{
|
||||
bool val;
|
||||
if(getBoolean(*prop->values.front(), &val))
|
||||
{
|
||||
_emitter->setKeepLocal(val);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (prop->name == token[TOKEN_EMITTER_FORCE_EMISSION])
|
||||
{
|
||||
// Property: force_emission
|
||||
if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_FORCE_EMISSION], VAL_BOOL))
|
||||
{
|
||||
bool val;
|
||||
if(getBoolean(*prop->values.front(), &val))
|
||||
{
|
||||
_emitter->setForceEmission(val);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (particleEmitterTranlator->translateChildProperty(compiler, *i))
|
||||
{
|
||||
// Parsed the property by another translator; do nothing
|
||||
}
|
||||
else
|
||||
{
|
||||
errorUnexpectedProperty(compiler, prop);
|
||||
}
|
||||
}
|
||||
else if((*i)->type == ANT_OBJECT)
|
||||
{
|
||||
PUObjectAbstractNode* child = reinterpret_cast<PUObjectAbstractNode*>((*i));
|
||||
PUDynamicAttributeTranslator dynamicAttributeTranslator;
|
||||
if (child->cls == token[TOKEN_EMITTER_EMISSION_RATE])
|
||||
{
|
||||
// Property: emission_rate
|
||||
dynamicAttributeTranslator.translate(compiler, *i);
|
||||
PUDynamicAttribute* dynamicAttribute = static_cast<PUDynamicAttribute*>(child->context);
|
||||
_emitter->setDynEmissionRate(dynamicAttribute);
|
||||
}
|
||||
else if (child->cls == token[TOKEN_TIME_TO_LIVE])
|
||||
{
|
||||
// Property: time_to_live
|
||||
dynamicAttributeTranslator.translate(compiler, *i);
|
||||
PUDynamicAttribute* dynamicAttribute = static_cast<PUDynamicAttribute*>(child->context);
|
||||
_emitter->setDynTotalTimeToLive(dynamicAttribute);
|
||||
}
|
||||
else if (child->cls == token[TOKEN_EMITTER_MASS])
|
||||
{
|
||||
// Property: mass
|
||||
dynamicAttributeTranslator.translate(compiler, *i);
|
||||
PUDynamicAttribute* dynamicAttribute = static_cast<PUDynamicAttribute*>(child->context);
|
||||
_emitter->setDynParticleMass(dynamicAttribute);
|
||||
}
|
||||
else if (child->cls == token[TOKEN_VELOCITY])
|
||||
{
|
||||
// Property: velocity
|
||||
dynamicAttributeTranslator.translate(compiler, *i);
|
||||
PUDynamicAttribute* dynamicAttribute = static_cast<PUDynamicAttribute*>(child->context);
|
||||
_emitter->setDynVelocity(dynamicAttribute);
|
||||
}
|
||||
else if (child->cls == token[TOKEN_EMITTER_DURATION])
|
||||
{
|
||||
// Property: duration
|
||||
dynamicAttributeTranslator.translate(compiler, *i);
|
||||
PUDynamicAttribute* dynamicAttribute = static_cast<PUDynamicAttribute*>(child->context);
|
||||
_emitter->setDynDuration(dynamicAttribute);
|
||||
}
|
||||
else if (child->cls == token[TOKEN_EMITTER_REPEAT_DELAY])
|
||||
{
|
||||
// Property: repeat_delay
|
||||
dynamicAttributeTranslator.translate(compiler, *i);
|
||||
PUDynamicAttribute* dynamicAttribute = static_cast<PUDynamicAttribute*>(child->context);
|
||||
_emitter->setDynRepeatDelay(dynamicAttribute);
|
||||
}
|
||||
else if (child->cls == token[TOKEN_ANGLE])
|
||||
{
|
||||
// Property: angle
|
||||
dynamicAttributeTranslator.translate(compiler, *i);
|
||||
PUDynamicAttribute* dynamicAttribute = static_cast<PUDynamicAttribute*>(child->context);
|
||||
_emitter->setDynAngle(dynamicAttribute);
|
||||
}
|
||||
else if (child->cls == token[TOKEN_EMITTER_ALL_PARTICLE_DIM])
|
||||
{
|
||||
// Property: all_particle_dimensions
|
||||
dynamicAttributeTranslator.translate(compiler, *i);
|
||||
PUDynamicAttribute* dynamicAttribute = static_cast<PUDynamicAttribute*>(child->context);
|
||||
_emitter->setDynParticleAllDimensions(dynamicAttribute);
|
||||
}
|
||||
else if (child->cls == token[TOKEN_EMITTER_PARTICLE_WIDTH])
|
||||
{
|
||||
// Property: particle_width
|
||||
dynamicAttributeTranslator.translate(compiler, *i);
|
||||
PUDynamicAttribute* dynamicAttribute = static_cast<PUDynamicAttribute*>(child->context);
|
||||
_emitter->setDynParticleWidth(dynamicAttribute);
|
||||
}
|
||||
else if (child->cls == token[TOKEN_EMITTER_PARTICLE_HEIGHT])
|
||||
{
|
||||
// Property: particle_height
|
||||
dynamicAttributeTranslator.translate(compiler, *i);
|
||||
PUDynamicAttribute* dynamicAttribute = static_cast<PUDynamicAttribute*>(child->context);
|
||||
_emitter->setDynParticleHeight(dynamicAttribute);
|
||||
}
|
||||
else if (child->cls == token[TOKEN_EMITTER_PARTICLE_DEPTH])
|
||||
{
|
||||
// Property: particle_depth
|
||||
dynamicAttributeTranslator.translate(compiler, *i);
|
||||
PUDynamicAttribute* dynamicAttribute = static_cast<PUDynamicAttribute*>(child->context);
|
||||
_emitter->setDynParticleDepth(dynamicAttribute);
|
||||
}
|
||||
else if (child->cls == token[TOKEN_CAMERA_DEPENDENCY])
|
||||
{
|
||||
//// Property: it can only be a camera_dependency for emission rate
|
||||
//CameraDependency* cameraDependency = PU_NEW_T(CameraDependency, MEMCATEGORY_SCRIPTING)();
|
||||
//child->context = Any(cameraDependency);
|
||||
//CameraDependencyTranslator cameraDependencyTranslator;
|
||||
//cameraDependencyTranslator.translate(compiler, *i);
|
||||
//Real threshold = cameraDependency->getThreshold();
|
||||
//mEmitter->setEmissionRateCameraDependency(threshold * threshold, cameraDependency->isIncrease());
|
||||
|
||||
//// Delete the camera dependency
|
||||
//PU_DELETE_T(cameraDependency, CameraDependency, MEMCATEGORY_SCRIPTING);
|
||||
}
|
||||
else if (particleEmitterTranlator->translateChildObject(compiler, *i))
|
||||
{
|
||||
// Parsed the object by another translator; do nothing
|
||||
}
|
||||
else
|
||||
{
|
||||
processNode(compiler, *i);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
errorUnexpectedToken(compiler, *i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
50
extensions/Particle3D/PU/CCPUEmitterTranslator.h
Normal file
50
extensions/Particle3D/PU/CCPUEmitterTranslator.h
Normal file
@@ -0,0 +1,50 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __CC_PU_PARTICLE_3D_EMITTER_TRANSLATOR_H__
|
||||
#define __CC_PU_PARTICLE_3D_EMITTER_TRANSLATOR_H__
|
||||
|
||||
#include "extensions/Particle3D/PU/CCPUScriptTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUScriptCompiler.h"
|
||||
#include "extensions/Particle3D/PU/CCPUEmitter.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class PUEmitterTranslator : public PUScriptTranslator
|
||||
{
|
||||
protected:
|
||||
|
||||
PUEmitter* _emitter;
|
||||
|
||||
public:
|
||||
PUEmitterTranslator();
|
||||
virtual ~PUEmitterTranslator(){};
|
||||
virtual void translate(PUScriptCompiler* compiler, PUAbstractNode *node);
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif /* defined(__cocos2d_libs__CCParticle3DAffectorTranslator__) */
|
||||
52
extensions/Particle3D/PU/CCPUEventHandler.cpp
Normal file
52
extensions/Particle3D/PU/CCPUEventHandler.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "extensions/Particle3D/PU/CCPUEventHandler.h"
|
||||
#include "extensions/Particle3D/PU/CCPUParticleSystem3D.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
||||
PUEventHandler::PUEventHandler( ) :
|
||||
_parentObserver(0),
|
||||
_eventHandlerScale(Vec3::ONE)
|
||||
{
|
||||
//mAliasType = AT_HANDLER;
|
||||
};
|
||||
|
||||
PUEventHandler::~PUEventHandler( )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void PUEventHandler::copyAttributesTo( PUEventHandler* eventHandler )
|
||||
{
|
||||
eventHandler->setName(_name);
|
||||
eventHandler->_parentObserver = _parentObserver;
|
||||
eventHandler->_eventHandlerScale = _eventHandlerScale;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
92
extensions/Particle3D/PU/CCPUEventHandler.h
Normal file
92
extensions/Particle3D/PU/CCPUEventHandler.h
Normal file
@@ -0,0 +1,92 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __CC_PU_PARTICLE_3D_EVENT_HANDLER_H__
|
||||
#define __CC_PU_PARTICLE_3D_EVENT_HANDLER_H__
|
||||
|
||||
#include "base/CCRef.h"
|
||||
#include "math/CCMath.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
struct PUParticle3D;
|
||||
class PUObserver;
|
||||
class PUParticleSystem3D;
|
||||
|
||||
class CC_DLL PUEventHandler : public Ref
|
||||
{
|
||||
public:
|
||||
|
||||
/** Todo
|
||||
*/
|
||||
const std::string& getName() const {return _name;};
|
||||
void setName(const std::string& name) {_name = name;};
|
||||
|
||||
/** Todo
|
||||
*/
|
||||
PUObserver* getParentObserver() const {return _parentObserver;};
|
||||
void setParentObserver(PUObserver* parentObserver) {_parentObserver = parentObserver;};
|
||||
|
||||
/** Todo
|
||||
*/
|
||||
const std::string& getEventHandlerType() const {return _eventHandlerType;};
|
||||
void setEventHandlerType(const std::string& eventHandlerType) {_eventHandlerType = eventHandlerType;};
|
||||
|
||||
/** Notify that the event handler is rescaled.
|
||||
*/
|
||||
virtual void notifyRescaled(const Vec3& scale){_eventHandlerScale = scale;};
|
||||
|
||||
/** Todo
|
||||
*/
|
||||
virtual void handle(PUParticleSystem3D* particleSystem, PUParticle3D* particle, float timeElapsed) = 0;
|
||||
|
||||
virtual void copyAttributesTo (PUEventHandler* eventHandler);
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
PUEventHandler();
|
||||
virtual ~PUEventHandler();
|
||||
|
||||
protected:
|
||||
// Observer to which the eventhandler is associated.
|
||||
PUObserver* _parentObserver;
|
||||
|
||||
// Type of event handler
|
||||
std::string _eventHandlerType;
|
||||
|
||||
// Name of the eventHandler (optional)
|
||||
std::string _name;
|
||||
|
||||
/** Although the scale is on a Particle System level, the event handler can also be scaled.
|
||||
*/
|
||||
Vec3 _eventHandlerScale;
|
||||
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif
|
||||
93
extensions/Particle3D/PU/CCPUEventHandlerManager.cpp
Normal file
93
extensions/Particle3D/PU/CCPUEventHandlerManager.cpp
Normal file
@@ -0,0 +1,93 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "extensions/Particle3D/PU/CCPUEventHandlerManager.h"
|
||||
#include "extensions/Particle3D/PU/CCPUDoAffectorEventHandler.h"
|
||||
#include "extensions/Particle3D/PU/CCPUDoEnableComponentEventHandler.h"
|
||||
#include "extensions/Particle3D/PU/CCPUDoExpireEventHandler.h"
|
||||
#include "extensions/Particle3D/PU/CCPUDoFreezeEventHandler.h"
|
||||
#include "extensions/Particle3D/PU/CCPUDoPlacementParticleEventHandler.h"
|
||||
#include "extensions/Particle3D/PU/CCPUDoScaleEventHandler.h"
|
||||
#include "extensions/Particle3D/PU/CCPUDoStopSystemEventHandler.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
PUEventHandlerManager::PUEventHandlerManager()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
PUEventHandlerManager::~PUEventHandlerManager()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
PUEventHandlerManager* PUEventHandlerManager::Instance()
|
||||
{
|
||||
static PUEventHandlerManager pem;
|
||||
return &pem;
|
||||
}
|
||||
|
||||
PUScriptTranslator* PUEventHandlerManager::getTranslator( const std::string &type )
|
||||
{
|
||||
if (type == "DoAffector"){
|
||||
return &_doAffectorEventHandlerTranslator;
|
||||
}else if (type == "DoEnableComponent"){
|
||||
return &_doEnableComponentEventHandlerTranslator;
|
||||
}else if (type == "DoExpire"){
|
||||
return &_doExpireEventHandlerTranslator;
|
||||
}else if (type == "DoFreeze"){
|
||||
return &_doFreezeEventHandlerTranslator;
|
||||
}else if (type == "DoPlacementParticle"){
|
||||
return &_doPlacementParticleEventHandlerTranslator;
|
||||
}else if (type == "DoScale"){
|
||||
return &_doScaleEventHandlerTranslator;
|
||||
}else if (type == "DoStopSystem"){
|
||||
return &_doStopSystemEventHandlerTranslator;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PUEventHandler* PUEventHandlerManager::createEventHandler( const std::string &type )
|
||||
{
|
||||
if (type == "DoAffector"){
|
||||
return PUDoAffectorEventHandler::create();
|
||||
}else if (type == "DoEnableComponent"){
|
||||
return PUDoEnableComponentEventHandler::create();
|
||||
}else if (type == "DoExpire"){
|
||||
return PUDoExpireEventHandler::create();
|
||||
}else if (type == "DoFreeze"){
|
||||
return PUDoFreezeEventHandler::create();
|
||||
}else if (type == "DoPlacementParticle"){
|
||||
return PUDoPlacementParticleEventHandler::create();
|
||||
}else if (type == "DoScale"){
|
||||
return PUDoScaleEventHandler::create();
|
||||
}else if (type == "DoStopSystem"){
|
||||
return PUDoStopSystemEventHandler::create();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
74
extensions/Particle3D/PU/CCPUEventHandlerManager.h
Normal file
74
extensions/Particle3D/PU/CCPUEventHandlerManager.h
Normal file
@@ -0,0 +1,74 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#ifndef __CC_PU_PARTICLE_3D_EVENT_HANDLER_MANAGER_H__
|
||||
#define __CC_PU_PARTICLE_3D_EVENT_HANDLER_MANAGER_H__
|
||||
|
||||
#include "base/CCRef.h"
|
||||
#include "extensions/Particle3D/PU/CCPUScriptTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUEventHandler.h"
|
||||
#include "extensions/Particle3D/PU/CCPUDoAffectorEventHandlerTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUDoEnableComponentEventHandlerTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUDoExpireEventHandlerTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUDoFreezeEventHandlerTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUDoPlacementParticleEventHandlerTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUDoScaleEventHandlerTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUDoStopSystemEventHandlerTranslator.h"
|
||||
|
||||
|
||||
NS_CC_BEGIN
|
||||
class PUEventHandlerManager
|
||||
{
|
||||
public:
|
||||
|
||||
static PUEventHandlerManager* Instance();
|
||||
|
||||
/**
|
||||
*/
|
||||
PUScriptTranslator* getTranslator(const std::string &type);
|
||||
PUEventHandler* createEventHandler(const std::string &type);
|
||||
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
|
||||
PUEventHandlerManager();
|
||||
~PUEventHandlerManager();
|
||||
|
||||
protected:
|
||||
|
||||
PUDoAffectorEventHandlerTranslator _doAffectorEventHandlerTranslator;
|
||||
PUDoEnableComponentEventHandlerTranslator _doEnableComponentEventHandlerTranslator;
|
||||
PUDoExpireEventHandlerTranslator _doExpireEventHandlerTranslator;
|
||||
PUDoFreezeEventHandlerTranslator _doFreezeEventHandlerTranslator;
|
||||
PUDoPlacementParticleEventHandlerTranslator _doPlacementParticleEventHandlerTranslator;
|
||||
PUDoScaleEventHandlerTranslator _doScaleEventHandlerTranslator;
|
||||
PUDoStopSystemEventHandlerTranslator _doStopSystemEventHandlerTranslator;
|
||||
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
|
||||
#endif
|
||||
125
extensions/Particle3D/PU/CCPUEventHandlerTranslator.cpp
Normal file
125
extensions/Particle3D/PU/CCPUEventHandlerTranslator.cpp
Normal file
@@ -0,0 +1,125 @@
|
||||
/****************************************************************************
|
||||
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
||||
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCPUEventHandlerTranslator.h"
|
||||
#include "extensions/Particle3D/PU/CCPUParticleSystem3D.h"
|
||||
#include "extensions/Particle3D/PU/CCPUEventHandlerManager.h"
|
||||
#include "extensions/Particle3D/PU/CCPUObserver.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
PUEventHandlerTranslator::PUEventHandlerTranslator()
|
||||
:_handler(nullptr)
|
||||
{
|
||||
}
|
||||
//-------------------------------------------------------------------------
|
||||
void PUEventHandlerTranslator::translate(PUScriptCompiler* compiler, PUAbstractNode *node)
|
||||
{
|
||||
PUObjectAbstractNode* obj = reinterpret_cast<PUObjectAbstractNode*>(node);
|
||||
PUObjectAbstractNode* parent = obj->parent ? reinterpret_cast<PUObjectAbstractNode*>(obj->parent) : 0;
|
||||
|
||||
// The name of the obj is the type of the ParticleEventHandler
|
||||
// Remark: This can be solved by using a listener, so that obj->values is filled with type + name. Something for later
|
||||
std::string type;
|
||||
if(!obj->name.empty())
|
||||
{
|
||||
type = obj->name;
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
PUScriptTranslator *particleEventHandlerTranlator = PUEventHandlerManager::Instance()->getTranslator(type);
|
||||
if (!particleEventHandlerTranlator) return;
|
||||
|
||||
// Create the ParticleEventHandler
|
||||
//mParticleEventHandler = ParticleSystemManager::getSingletonPtr()->createEventHandler(type);
|
||||
_handler = PUEventHandlerManager::Instance()->createEventHandler(type);
|
||||
if (!_handler)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_handler->setEventHandlerType(type);
|
||||
if (parent && parent->context)
|
||||
{
|
||||
PUObserver* observer = static_cast<PUObserver *>(parent->context);
|
||||
observer->addEventHandler(_handler);
|
||||
}
|
||||
else
|
||||
{
|
||||
//// It is an alias
|
||||
//mParticleEventHandler->setAliasName(parent->name);
|
||||
//ParticleSystemManager::getSingletonPtr()->addAlias(mParticleEventHandler);
|
||||
}
|
||||
|
||||
// The first value is the (optional) name
|
||||
std::string name;
|
||||
if(!obj->values.empty())
|
||||
{
|
||||
getString(*obj->values.front(), &name);
|
||||
_handler->setName(name);
|
||||
}
|
||||
|
||||
// Set it in the context
|
||||
obj->context = _handler;
|
||||
|
||||
// Run through properties
|
||||
for(PUAbstractNodeList::iterator i = obj->children.begin(); i != obj->children.end(); ++i)
|
||||
{
|
||||
// No properties of its own
|
||||
if((*i)->type == ANT_PROPERTY)
|
||||
{
|
||||
PUPropertyAbstractNode* prop = reinterpret_cast<PUPropertyAbstractNode*>((*i));
|
||||
if (particleEventHandlerTranlator->translateChildProperty(compiler, *i))
|
||||
{
|
||||
// Parsed the property by another translator; do nothing
|
||||
}
|
||||
else
|
||||
{
|
||||
errorUnexpectedProperty(compiler, prop);
|
||||
}
|
||||
}
|
||||
else if((*i)->type == ANT_OBJECT)
|
||||
{
|
||||
if (particleEventHandlerTranlator->translateChildObject(compiler, *i))
|
||||
{
|
||||
// Parsed the object by another translator; do nothing
|
||||
}
|
||||
else
|
||||
{
|
||||
processNode(compiler, *i);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
errorUnexpectedToken(compiler, *i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user