use of com.talosvfx.talos.runtime.modules.ParticleModule in project talos by rockbite.
the class Particle method notifyKill.
public void notifyKill() {
ParticleModule particleModule = emitterReference.getParticleModule();
if (particleModule == null)
return;
particleModule.updateScopeData(this);
drawable = particleModule.getDrawable();
if (drawable != null) {
drawable.notifyDispose(this);
}
}
use of com.talosvfx.talos.runtime.modules.ParticleModule in project talos by rockbite.
the class Particle method applyAlpha.
public void applyAlpha(float alpha, float delta) {
ParticleModule particleModule = emitterReference.getParticleModule();
if (particleModule == null)
return;
particleModule.updateScopeData(this);
// update variable values
Vector2 target = particleModule.getTarget();
float angle = 0;
if (target == null) {
// do we take angle or target
angle = particleModule.getAngle();
} else {
angle = target.sub(position).angle();
}
float velocity = particleModule.getVelocity();
transparency = particleModule.getTransparency();
if (emitterReference.getEmitterModule().isAligned()) {
rotation = angle + particleModule.getRotation();
} else {
rotation = particleModule.getRotation();
}
pivot.set(particleModule.getPivot());
// important to get drawable before size
drawable = particleModule.getDrawable();
if (drawable != null) {
emitterReference.getScope().set(ScopePayload.DRAWABLE_ASPECT_RATIO, drawable.getAspectRatio());
} else {
emitterReference.getScope().set(ScopePayload.DRAWABLE_ASPECT_RATIO, 1f);
}
size.set(particleModule.getSize());
Vector2 positionOverride = particleModule.getPosition();
color.set(particleModule.getColor());
// perform inner operations
if (positionOverride != null) {
position.set(positionOverride);
} else {
position.x += MathUtils.cosDeg(angle) * velocity * delta;
position.y += MathUtils.sinDeg(angle) * velocity * delta;
}
}
use of com.talosvfx.talos.runtime.modules.ParticleModule in project talos by rockbite.
the class Particle method update.
public void update(float delta) {
if (alpha == 1f)
return;
if (emitterReference == null)
return;
// scope data
ParticleModule particleModule = emitterReference.getParticleModule();
if (particleModule == null)
return;
// maybe should remove this
life = particleModule.getLife();
alpha += delta / life;
if (alpha > 1f)
alpha = 1f;
applyAlpha(alpha, delta);
}
use of com.talosvfx.talos.runtime.modules.ParticleModule in project talos by rockbite.
the class Particle method init.
public void init(IEmitter emitterReference, float seed) {
this.emitterReference = emitterReference;
ParticleModule particleModule = emitterReference.getParticleModule();
this.seed = seed;
// inner variable defaults
alpha = 0f;
particleModule.updateScopeData(this);
// really makes more sense like this, for deterministic purposes
life = particleModule.getLife();
// offset
position.set(particleModule.getStartPosition());
spawnPosition.set(emitterReference.getEffectPosition());
durationAtInit = emitterReference.getAlpha();
}
use of com.talosvfx.talos.runtime.modules.ParticleModule in project talos by rockbite.
the class ParticleEffectDescriptor method load.
public void load(FileHandle fileHandle) {
Json json = new Json();
ParticleEmitterDescriptor.registerModules();
for (Class clazz : ParticleEmitterDescriptor.registeredModules) {
json.addClassTag(clazz.getSimpleName(), clazz);
}
final ExportData exportData = json.fromJson(ExportData.class, fileHandle.readString());
for (ExportData.EmitterExportData emitter : exportData.emitters) {
ParticleEmitterDescriptor emitterDescriptor = new ParticleEmitterDescriptor(this);
IntMap<AbstractModule> idMap = new IntMap<>();
for (AbstractModule module : emitter.modules) {
module.setModuleGraph(emitterDescriptor);
if (module instanceof ParticleModule) {
emitterDescriptor.particleModule = (ParticleModule) module;
}
if (module instanceof EmitterModule) {
emitterDescriptor.emitterModule = (EmitterModule) module;
}
idMap.put(module.getIndex(), module);
// I cannot understand how this was working before. This is needed so that it can later reset requesters.
emitterDescriptor.modules.add(module);
}
for (ConnectionData connection : emitter.connections) {
final int moduleFromId = connection.moduleFrom;
final int moduleToId = connection.moduleTo;
final int slotFrom = connection.slotFrom;
final int slotTo = connection.slotTo;
AbstractModule moduleFrom = idMap.get(moduleFromId);
AbstractModule moduleTo = idMap.get(moduleToId);
if (moduleFrom == null) {
throw new GdxRuntimeException("No module from found for id: " + moduleFromId);
}
if (moduleTo == null) {
throw new GdxRuntimeException("No module to found for id: " + moduleToId);
}
emitterDescriptor.connectNode(moduleFrom, moduleTo, slotFrom, slotTo);
}
emitterModuleGraphs.add(emitterDescriptor);
}
}
Aggregations