From 16e81a6aef164b11e84599498255679813061ae8 Mon Sep 17 00:00:00 2001 From: Tom Wojciechowski Date: Wed, 16 Oct 2024 15:53:55 +0100 Subject: [PATCH] Fix crash on select particle when its null Adjust velocity over time in attached/non attached modes --- .../ParticleComponentProvider.java | 1 + .../render/ParticleRenderPassSystem.java | 17 +++++++++-------- .../talosvfx/talos/runtime/vfx/Particle.java | 2 +- .../vfx/render/SpriteBatchParticleRenderer.java | 15 +++++++++++++++ 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/editor/src/com/talosvfx/talos/editor/addons/scene/logic/componentwrappers/ParticleComponentProvider.java b/editor/src/com/talosvfx/talos/editor/addons/scene/logic/componentwrappers/ParticleComponentProvider.java index 045ff38e6..f3978db9d 100644 --- a/editor/src/com/talosvfx/talos/editor/addons/scene/logic/componentwrappers/ParticleComponentProvider.java +++ b/editor/src/com/talosvfx/talos/editor/addons/scene/logic/componentwrappers/ParticleComponentProvider.java @@ -66,6 +66,7 @@ public void report(String value) { ButtonPropertyWidget playButton = new ButtonPropertyWidget("Play", new ButtonPropertyWidget.ButtonListener() { @Override public void clicked (ButtonPropertyWidget widget) { + if (component == null || component.getEffectRef() == null) return; component.getEffectRef().restart(); } }); diff --git a/runtimes/talos-bongo/src/main/java/com/talosvfx/talos/runtime/systems/render/ParticleRenderPassSystem.java b/runtimes/talos-bongo/src/main/java/com/talosvfx/talos/runtime/systems/render/ParticleRenderPassSystem.java index ab62ca16e..74b24e553 100644 --- a/runtimes/talos-bongo/src/main/java/com/talosvfx/talos/runtime/systems/render/ParticleRenderPassSystem.java +++ b/runtimes/talos-bongo/src/main/java/com/talosvfx/talos/runtime/systems/render/ParticleRenderPassSystem.java @@ -5,10 +5,7 @@ import com.artemis.utils.IntBag; import com.badlogic.gdx.Files; import com.badlogic.gdx.Gdx; -import com.badlogic.gdx.graphics.Camera; -import com.badlogic.gdx.graphics.GL20; -import com.badlogic.gdx.graphics.VertexAttribute; -import com.badlogic.gdx.graphics.VertexAttributes; +import com.badlogic.gdx.graphics.*; import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.graphics.g3d.utils.RenderContext; import com.badlogic.gdx.graphics.glutils.ShaderProgram; @@ -182,21 +179,25 @@ public void render (ParticleEffectInstance particleEffectInstance) { meshGenerator.render(this, drawableModule.getMaterialModule(), particleEmitter.pointData()); +// simple3DBatch.end(); // ShapeRenderer shapeRenderer = new ShapeRenderer(); // shapeRenderer.setProjectionMatrix(cameras.getGameCamera().combined); // shapeRenderer.begin(ShapeRenderer.ShapeType.Line); -// Array pointData = particlePointDataGeneratorModule.pointData; +// Array pointData = particleEmitter.pointData(); // for (ParticlePointGroup group : pointData) { // shapeRenderer.setColor(1f, 0, 0, 1f); // for (ParticlePointData particlePointData : group.pointDataArray) { -// shapeRenderer.circle(particlePointData.x, particlePointData.y, 0.25f, 20); -// } +// shapeRenderer.setColor(Color.RED); +// shapeRenderer.circle(particlePointData.x, particlePointData.y, 0.15f, 20); +// } // } // shapeRenderer.end(); - +// particleEmitter.getScope().setCurrentRequestMode(cachedMode); particleEmitter.getScope().setCurrentRequesterID(cachedRequesterID); + +// simple3DBatch.begin(cameras.getGameCamera(), shaderProgram.getShaderProgram()); } simple3DBatch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); diff --git a/runtimes/talos/src/main/java/com/talosvfx/talos/runtime/vfx/Particle.java b/runtimes/talos/src/main/java/com/talosvfx/talos/runtime/vfx/Particle.java index 4e303b2c7..5285d9cd0 100644 --- a/runtimes/talos/src/main/java/com/talosvfx/talos/runtime/vfx/Particle.java +++ b/runtimes/talos/src/main/java/com/talosvfx/talos/runtime/vfx/Particle.java @@ -185,8 +185,8 @@ public void applyAlpha (float alpha, float delta) { //Velocity is driven by velocity over time final Vector3 velocityOverTime = particleModule.getVelocityOverTime(); velocity.set(velocityOverTime); - velocity.rotate(initialWorldRotation, 0, 0, 1); if (!emitterReference.getEmitterModule().isAttached()) { + velocity.rotate(initialWorldRotation, 0, 0, 1); //not attached rotate it velocity.scl(worldScale.x, worldScale.y, 0); } } else { diff --git a/runtimes/talos/src/main/java/com/talosvfx/talos/runtime/vfx/render/SpriteBatchParticleRenderer.java b/runtimes/talos/src/main/java/com/talosvfx/talos/runtime/vfx/render/SpriteBatchParticleRenderer.java index 2a312ef38..1fb257e7a 100644 --- a/runtimes/talos/src/main/java/com/talosvfx/talos/runtime/vfx/render/SpriteBatchParticleRenderer.java +++ b/runtimes/talos/src/main/java/com/talosvfx/talos/runtime/vfx/render/SpriteBatchParticleRenderer.java @@ -115,6 +115,21 @@ public void render (ParticleEffectInstance particleEffectInstance) { particleEmitter.getScope().setCurrentRequestMode(ScopePayload.SUB_PARTICLE_ALPHA); meshGenerator.render(this, drawableModule.getMaterialModule(), particleEmitter.pointData()); +// batch.end(); +// ShapeRenderer shapeRenderer = new ShapeRenderer(); +// shapeRenderer.setProjectionMatrix(camera.combined); +// shapeRenderer.begin(ShapeRenderer.ShapeType.Line); +// Array pointData = particleEmitter.pointData(); +// for (ParticlePointGroup group : pointData) { +// shapeRenderer.setColor(1f, 0, 0, 1f); +// for (ParticlePointData particlePointData : group.pointDataArray) { +// shapeRenderer.circle(particlePointData.x, particlePointData.y, 10.15f, 20); +// } +// } +// shapeRenderer.end(); +// shapeRenderer.dispose(); +// batch.begin(); + particleEmitter.getScope().setCurrentRequestMode(cachedMode); particleEmitter.getScope().setCurrentRequesterID(cachedRequesterID);