Search in sources :

Example 1 with PropertyLocation

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;
}
Also used : PropertyBox(com.gempukku.libgdx.graph.ui.graph.property.PropertyBox) PropertyLocation(com.gempukku.libgdx.graph.shader.property.PropertyLocation) JsonValue(com.badlogic.gdx.utils.JsonValue) NodeGroup(com.gempukku.libgdx.graph.data.NodeGroup)

Example 2 with PropertyLocation

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();
}
Also used : PropertyLocation(com.gempukku.libgdx.graph.shader.property.PropertyLocation) JsonValue(com.badlogic.gdx.utils.JsonValue) ObjectSet(com.badlogic.gdx.utils.ObjectSet)

Example 3 with PropertyLocation

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());
}
Also used : VertexAttributes(com.badlogic.gdx.graphics.VertexAttributes) PropertySource(com.gempukku.libgdx.graph.shader.property.PropertySource) GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) Array(com.badlogic.gdx.utils.Array) IntArray(com.badlogic.gdx.utils.IntArray) ObjectMap(com.badlogic.gdx.utils.ObjectMap) PropertyLocation(com.gempukku.libgdx.graph.shader.property.PropertyLocation) VertexAttribute(com.badlogic.gdx.graphics.VertexAttribute) ArrayShaderFieldType(com.gempukku.libgdx.graph.shader.field.ArrayShaderFieldType) ArrayShaderFieldType(com.gempukku.libgdx.graph.shader.field.ArrayShaderFieldType) ShaderFieldType(com.gempukku.libgdx.graph.shader.field.ShaderFieldType)

Aggregations

PropertyLocation (com.gempukku.libgdx.graph.shader.property.PropertyLocation)3 JsonValue (com.badlogic.gdx.utils.JsonValue)2 VertexAttribute (com.badlogic.gdx.graphics.VertexAttribute)1 VertexAttributes (com.badlogic.gdx.graphics.VertexAttributes)1 Array (com.badlogic.gdx.utils.Array)1 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)1 IntArray (com.badlogic.gdx.utils.IntArray)1 ObjectMap (com.badlogic.gdx.utils.ObjectMap)1 ObjectSet (com.badlogic.gdx.utils.ObjectSet)1 NodeGroup (com.gempukku.libgdx.graph.data.NodeGroup)1 ArrayShaderFieldType (com.gempukku.libgdx.graph.shader.field.ArrayShaderFieldType)1 ShaderFieldType (com.gempukku.libgdx.graph.shader.field.ShaderFieldType)1 PropertySource (com.gempukku.libgdx.graph.shader.property.PropertySource)1 PropertyBox (com.gempukku.libgdx.graph.ui.graph.property.PropertyBox)1