use of com.talosvfx.talos.runtime.serialization.ConnectionData in project talos by rockbite.
the class TalosProject method setToExportData.
private void setToExportData(ExportData data, ModuleBoardWidget moduleBoardWidget) {
final ObjectMap<ParticleEmitterWrapper, Array<ModuleWrapper>> moduleWrappers = moduleBoardWidget.moduleWrappers;
final ObjectMap<ParticleEmitterWrapper, Array<ModuleBoardWidget.NodeConnection>> nodeConnections = moduleBoardWidget.nodeConnections;
for (ParticleEmitterWrapper key : moduleWrappers.keys()) {
final ExportData.EmitterExportData emitterData = new ExportData.EmitterExportData();
emitterData.name = key.getName();
for (ModuleWrapper wrapper : moduleWrappers.get(key)) {
emitterData.modules.add(wrapper.getModule());
if (wrapper.getModule() instanceof TextureModule) {
TextureModule textureModule = (TextureModule) wrapper.getModule();
String name = textureModule.regionName;
if (name == null)
name = "fire";
if (!data.metadata.resources.contains(name, false)) {
data.metadata.resources.add(name);
}
}
if (wrapper.getModule() instanceof PolylineModule) {
PolylineModule module = (PolylineModule) wrapper.getModule();
String name = module.regionName;
if (name == null)
name = "fire";
if (!data.metadata.resources.contains(name, false)) {
data.metadata.resources.add(name);
}
}
if (wrapper.getModule() instanceof VectorFieldModule) {
VectorFieldModule vectorFieldModule = (VectorFieldModule) wrapper.getModule();
String fgaFileName = vectorFieldModule.fgaFileName;
if (fgaFileName == null) {
return;
}
fgaFileName = fgaFileName + ".fga";
if (!data.metadata.resources.contains(fgaFileName, false)) {
data.metadata.resources.add(fgaFileName);
}
}
}
final Array<ModuleBoardWidget.NodeConnection> nodeConns = nodeConnections.get(key);
if (nodeConns != null) {
for (ModuleBoardWidget.NodeConnection nodeConn : nodeConns) {
emitterData.connections.add(new ConnectionData(nodeConn.fromModule.getModule().getIndex(), nodeConn.toModule.getModule().getIndex(), nodeConn.fromSlot, nodeConn.toSlot));
}
}
data.emitters.add(emitterData);
}
}
use of com.talosvfx.talos.runtime.serialization.ConnectionData in project talos by rockbite.
the class ModuleBoardWidget method loadEmitterToBoard.
public void loadEmitterToBoard(ParticleEmitterWrapper emitterWrapper, EmitterData emitterData) {
IntMap<ModuleWrapper> map = new IntMap<>();
if (!moduleWrappers.containsKey(emitterWrapper)) {
moduleWrappers.put(emitterWrapper, new Array<ModuleWrapper>());
}
for (ModuleWrapper wrapper : emitterData.modules) {
moduleWrappers.get(emitterWrapper).add(wrapper);
wrapper.setModule(wrapper.getModule());
wrapper.setBoard(this);
map.put(wrapper.getId(), wrapper);
}
for (ConnectionData connectionData : emitterData.connections) {
// make connections based on ids
makeConnection(map.get(connectionData.moduleFrom), map.get(connectionData.moduleTo), connectionData.slotFrom, connectionData.slotTo);
}
}
use of com.talosvfx.talos.runtime.serialization.ConnectionData in project talos by rockbite.
the class ProjectData method setFrom.
public void setFrom(ModuleBoardWidget moduleBoardWidget) {
final ObjectMap<ParticleEmitterWrapper, Array<ModuleWrapper>> moduleWrappers = moduleBoardWidget.moduleWrappers;
final ObjectMap<ParticleEmitterWrapper, Array<ModuleBoardWidget.NodeConnection>> nodeConnections = moduleBoardWidget.nodeConnections;
emitters.clear();
for (ParticleEmitterWrapper key : moduleWrappers.keys()) {
final EmitterData emitterData = new EmitterData();
emitterData.name = key.getName();
emitterData.sortPosition = key.getEmitter().getSortPosition();
emitterData.modules.addAll(moduleWrappers.get(key));
emitterData.isMuted = key.isMuted;
final Array<ModuleBoardWidget.NodeConnection> nodeConns = nodeConnections.get(key);
if (nodeConns != null) {
for (ModuleBoardWidget.NodeConnection nodeConn : nodeConns) {
emitterData.connections.add(new ConnectionData(nodeConn.fromModule.getId(), nodeConn.toModule.getId(), nodeConn.fromSlot, nodeConn.toSlot));
}
}
// add groups
for (ModuleWrapperGroup group : moduleBoardWidget.getGroups(key)) {
GroupData groupData = new GroupData();
groupData.text = group.getText();
groupData.modules = new Array<>();
groupData.color = group.getFrameColor().toFloatBits();
for (ModuleWrapper wrapper : group.getModuleWrappers()) {
groupData.modules.add(wrapper.getId());
}
emitterData.groups.add(groupData);
}
emitters.add(emitterData);
}
}
use of com.talosvfx.talos.runtime.serialization.ConnectionData 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