use of com.gempukku.libgdx.graph.shader.property.PropertyLocation in project gdx-graph by MarcinSc.
the class GraphDesignTab method serializeGraph.
public JsonValue serializeGraph() {
JsonValue graph = new JsonValue(JsonValue.ValueType.object);
graph.addChild("version", new JsonValue(GraphLoader.VERSION));
graph.addChild("type", new JsonValue(type.getType()));
JsonValue objects = new JsonValue(JsonValue.ValueType.array);
for (JsonValue jsonValue : getSortedNodesAsJson()) {
objects.addChild(jsonValue);
}
graph.addChild("nodes", objects);
List<JsonValue> connectionJsonValues = getSortedConnectionsAsJson();
JsonValue connections = new JsonValue(JsonValue.ValueType.array);
for (JsonValue connection : connectionJsonValues) {
connections.addChild(connection);
}
graph.addChild("connections", connections);
JsonValue properties = new JsonValue(JsonValue.ValueType.array);
for (PropertyBox propertyBox : propertyBoxes) {
JsonValue property = new JsonValue(JsonValue.ValueType.object);
property.addChild("name", new JsonValue(propertyBox.getName()));
property.addChild("type", new JsonValue(propertyBox.getType()));
PropertyLocation location = propertyBox.getLocation();
if (location != null)
property.addChild("location", new JsonValue(location.name()));
JsonValue data = propertyBox.getData();
if (data != null)
property.addChild("data", data);
properties.addChild(property);
}
graph.addChild("properties", properties);
JsonValue groups = new JsonValue(JsonValue.ValueType.array);
for (NodeGroup nodeGroup : graphContainer.getNodeGroups()) {
JsonValue group = new JsonValue(JsonValue.ValueType.object);
group.addChild("name", new JsonValue(nodeGroup.getName()));
JsonValue nodes = new JsonValue(JsonValue.ValueType.array);
for (String nodeId : nodeGroup.getNodeIds()) {
nodes.addChild(new JsonValue(nodeId));
}
group.addChild("nodes", nodes);
groups.addChild(group);
}
graph.addChild("groups", groups);
return graph;
}
use of com.gempukku.libgdx.graph.shader.property.PropertyLocation in project gdx-graph by MarcinSc.
the class GraphLoader method loadGraph.
public static <T> T loadGraph(JsonValue graph, GraphLoaderCallback<T> graphLoaderCallback, PropertyLocation defaultPropertyLocation) {
// Assuming default
String version = graph.has("version") ? graph.getString("version") : "0.1.0";
if (!canReadVersion(version)) {
throw new IllegalArgumentException("Unable to read a graph of version " + version);
}
if (!VERSION.equals(version))
Gdx.app.debug("GraphLoader", "Reading a graph from different version " + VERSION + " != " + version);
graphLoaderCallback.start();
for (JsonValue object : graph.get("nodes")) {
String type = object.getString("type");
String id = object.getString("id");
float x = object.getFloat("x");
float y = object.getFloat("y");
JsonValue data = object.get("data");
if (data == null)
data = emptyData;
graphLoaderCallback.addPipelineNode(id, type, x, y, data);
}
for (JsonValue connection : graph.get("connections")) {
String fromNode = connection.getString("fromNode");
String fromField = connection.getString("fromField");
String toNode = connection.getString("toNode");
String toField = connection.getString("toField");
graphLoaderCallback.addPipelineVertex(fromNode, fromField, toNode, toField);
}
for (JsonValue property : graph.get("properties")) {
String type = property.getString("type");
String name = property.getString("name");
JsonValue data = property.get("data");
if (data == null)
data = emptyData;
String location = property.getString("location", null);
PropertyLocation propertyLocation = (location != null) ? PropertyLocation.valueOf(location) : defaultPropertyLocation;
graphLoaderCallback.addPipelineProperty(type, name, propertyLocation, data);
}
JsonValue groups = graph.get("groups");
if (groups != null) {
for (JsonValue group : groups) {
String name = group.getString("name");
JsonValue nodes = group.get("nodes");
ObjectSet<String> nodeIds = new ObjectSet<>();
for (JsonValue node : nodes) {
nodeIds.add(node.asString());
}
graphLoaderCallback.addNodeGroup(name, nodeIds);
}
}
return graphLoaderCallback.end();
}
use of com.gempukku.libgdx.graph.shader.property.PropertyLocation in project gdx-graph by MarcinSc.
the class GraphModelUtil method getShaderVertexAttributes.
public static VertexAttributes getShaderVertexAttributes(GraphModels graphModels, String tag) {
ObjectMap<String, PropertySource> shaderProperties = graphModels.getShaderProperties(tag);
if (shaderProperties == null)
throw new GdxRuntimeException("Unable to locate shader with tag: " + tag);
Array<VertexAttribute> vertexAttributeArray = new Array<>(VertexAttribute.class);
for (ObjectMap.Entry<String, PropertySource> shaderProperty : shaderProperties) {
PropertySource propertySource = shaderProperty.value;
PropertyLocation propertyLocation = propertySource.getPropertyLocation();
if (propertyLocation == PropertyLocation.Attribute) {
ShaderFieldType shaderFieldType = propertySource.getShaderFieldType();
if (shaderFieldType instanceof ArrayShaderFieldType) {
int arraySize = ((ArrayShaderFieldType) shaderFieldType).getArrayLength();
for (int i = 0; i < arraySize; i++) {
vertexAttributeArray.add(new VertexAttribute(1024, shaderFieldType.getNumberOfComponents(), propertySource.getAttributeName(i)));
}
} else {
vertexAttributeArray.add(new VertexAttribute(1024, shaderFieldType.getNumberOfComponents(), propertySource.getAttributeName()));
}
}
}
return new VertexAttributes(vertexAttributeArray.toArray());
}
Aggregations