| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- // Copyright (C) 2009-2021, Panagiotis Christopoulos Charitos and contributors.
- // All rights reserved.
- // Code licensed under the BSD License.
- // http://www.anki3d.org/LICENSE
- #include <AnKi/Scene/GpuParticleEmitterNode.h>
- #include <AnKi/Scene/Components/MoveComponent.h>
- #include <AnKi/Scene/Components/SpatialComponent.h>
- #include <AnKi/Scene/Components/GenericGpuComputeJobComponent.h>
- #include <AnKi/Scene/Components/RenderComponent.h>
- #include <AnKi/Scene/Components/GpuParticleEmitterComponent.h>
- namespace anki
- {
- /// Feedback component
- class GpuParticleEmitterNode::MoveFeedbackComponent : public SceneComponent
- {
- ANKI_SCENE_COMPONENT(GpuParticleEmitterNode::MoveFeedbackComponent)
- public:
- MoveFeedbackComponent(SceneNode* node)
- : SceneComponent(node, getStaticClassId(), true)
- {
- }
- ANKI_USE_RESULT Error update(SceneNode& node, Second prevTime, Second crntTime, Bool& updated) override
- {
- updated = false;
- const MoveComponent& move = node.getFirstComponentOfType<MoveComponent>();
- if(move.getTimestamp() == node.getGlobalTimestamp())
- {
- GpuParticleEmitterNode& mnode = static_cast<GpuParticleEmitterNode&>(node);
- mnode.onMoveComponentUpdate(move);
- }
- return Error::NONE;
- }
- };
- ANKI_SCENE_COMPONENT_STATICS(GpuParticleEmitterNode::MoveFeedbackComponent)
- /// Feedback component
- class GpuParticleEmitterNode::ShapeFeedbackComponent : public SceneComponent
- {
- ANKI_SCENE_COMPONENT(GpuParticleEmitterNode::ShapeFeedbackComponent)
- public:
- ShapeFeedbackComponent(SceneNode* node)
- : SceneComponent(node, getStaticClassId(), true)
- {
- }
- ANKI_USE_RESULT Error update(SceneNode& node, Second prevTime, Second crntTime, Bool& updated) override
- {
- updated = false;
- const GpuParticleEmitterComponent& pec = node.getFirstComponentOfType<GpuParticleEmitterComponent>();
- if(pec.getTimestamp() == node.getGlobalTimestamp())
- {
- GpuParticleEmitterNode& mnode = static_cast<GpuParticleEmitterNode&>(node);
- mnode.onShapeUpdate(pec);
- }
- return Error::NONE;
- }
- };
- ANKI_SCENE_COMPONENT_STATICS(GpuParticleEmitterNode::ShapeFeedbackComponent)
- GpuParticleEmitterNode::GpuParticleEmitterNode(SceneGraph* scene, CString name)
- : SceneNode(scene, name)
- {
- // Create the components
- newComponent<MoveComponent>();
- newComponent<MoveFeedbackComponent>();
- GpuParticleEmitterComponent* pec = newComponent<GpuParticleEmitterComponent>();
- newComponent<ShapeFeedbackComponent>();
- newComponent<SpatialComponent>();
- GenericGpuComputeJobComponent* gpuComp = newComponent<GenericGpuComputeJobComponent>();
- gpuComp->setCallback(GpuParticleEmitterComponent::simulateCallback, pec);
- RenderComponent* rcomp = newComponent<RenderComponent>();
- const U64 noMerging = 0;
- rcomp->initRaster(GpuParticleEmitterComponent::drawCallback, pec, noMerging);
- }
- GpuParticleEmitterNode::~GpuParticleEmitterNode()
- {
- }
- Error GpuParticleEmitterNode::frameUpdate(Second prevUpdateTime, Second crntTime)
- {
- const GpuParticleEmitterComponent& pec = getFirstComponentOfType<GpuParticleEmitterComponent>();
- if(pec.isEnabled())
- {
- RenderComponent& rc = getFirstComponentOfType<RenderComponent>();
- rc.setFlagsFromMaterial(pec.getParticleEmitterResource()->getMaterial());
- }
- return Error::NONE;
- }
- void GpuParticleEmitterNode::onMoveComponentUpdate(const MoveComponent& movec)
- {
- getFirstComponentOfType<SpatialComponent>().setSpatialOrigin(movec.getWorldTransform().getOrigin().xyz());
- getFirstComponentOfType<GpuParticleEmitterComponent>().setWorldTransform(movec.getWorldTransform());
- }
- void GpuParticleEmitterNode::onShapeUpdate(const GpuParticleEmitterComponent& pec)
- {
- getFirstComponentOfType<SpatialComponent>().setAabbWorldSpace(pec.getBoundingVolumeWorldSpace());
- }
- } // end namespace anki
|