Search in sources :

Example 6 with SingleInputsPipelineNode

use of com.gempukku.libgdx.graph.pipeline.producer.node.SingleInputsPipelineNode in project gdx-graph by MarcinSc.

the class LengthPipelineNodeProducer method createNodeForSingleInputs.

@Override
public PipelineNode createNodeForSingleInputs(JsonValue data, ObjectMap<String, String> inputTypes, ObjectMap<String, String> outputTypes) {
    final ObjectMap<String, PipelineNode.FieldOutput<?>> result = new ObjectMap<>();
    final DefaultFieldOutput resultOutput = new DefaultFieldOutput(PipelineFieldType.Float);
    result.put("output", resultOutput);
    return new SingleInputsPipelineNode(result) {

        @Override
        public void executeNode(PipelineRenderingContext pipelineRenderingContext, PipelineRequirementsCallback pipelineRequirementsCallback) {
            FieldOutput<?> aFunction = inputs.get("input");
            Object a = aFunction.getValue();
            float resultValue;
            if (a instanceof Float) {
                resultValue = (Float) a;
            } else if (a instanceof Vector2) {
                resultValue = ((Vector2) a).len();
            } else if (a instanceof Vector3) {
                resultValue = ((Vector3) a).len();
            } else if (a instanceof Color) {
                Color aColor = (Color) a;
                resultValue = (float) Math.sqrt(aColor.r * aColor.r + aColor.g * aColor.g + aColor.b * aColor.b + aColor.a * aColor.a);
            } else {
                throw new IllegalArgumentException("Not matching type for function");
            }
            resultOutput.setValue(resultValue);
        }
    };
}
Also used : Color(com.badlogic.gdx.graphics.Color) Vector3(com.badlogic.gdx.math.Vector3) PipelineRenderingContext(com.gempukku.libgdx.graph.pipeline.producer.PipelineRenderingContext) DefaultFieldOutput(com.gempukku.libgdx.graph.pipeline.producer.node.DefaultFieldOutput) ObjectMap(com.badlogic.gdx.utils.ObjectMap) Vector2(com.badlogic.gdx.math.Vector2) DefaultFieldOutput(com.gempukku.libgdx.graph.pipeline.producer.node.DefaultFieldOutput) SingleInputsPipelineNode(com.gempukku.libgdx.graph.pipeline.producer.node.SingleInputsPipelineNode)

Example 7 with SingleInputsPipelineNode

use of com.gempukku.libgdx.graph.pipeline.producer.node.SingleInputsPipelineNode in project gdx-graph by MarcinSc.

the class MergePipelineNodeProducer method createNodeForSingleInputs.

@Override
public PipelineNode createNodeForSingleInputs(JsonValue data, ObjectMap<String, String> inputTypes, ObjectMap<String, String> outputTypes) {
    final Vector2 v2 = new Vector2();
    final Vector3 v3 = new Vector3();
    final Color color = new Color();
    DefaultFieldOutput<Vector2> v2Output = new DefaultFieldOutput<>(PipelineFieldType.Vector2);
    v2Output.setValue(v2);
    DefaultFieldOutput<Vector3> v3Output = new DefaultFieldOutput<>(PipelineFieldType.Vector3);
    v3Output.setValue(v3);
    DefaultFieldOutput<Color> colorOutput = new DefaultFieldOutput<>(PipelineFieldType.Color);
    colorOutput.setValue(color);
    final ObjectMap<String, PipelineNode.FieldOutput<?>> result = new ObjectMap<>();
    result.put("v2", v2Output);
    result.put("v3", v3Output);
    result.put("color", colorOutput);
    return new SingleInputsPipelineNode(result) {

        @Override
        public void executeNode(PipelineRenderingContext pipelineRenderingContext, PipelineRequirementsCallback pipelineRequirementsCallback) {
            float xValue = getInputValue("x", 0f);
            float yValue = getInputValue("y", 0f);
            float zValue = getInputValue("z", 0f);
            float wValue = getInputValue("w", 0f);
            v2.set(xValue, yValue);
            v3.set(xValue, yValue, zValue);
            color.set(xValue, yValue, zValue, wValue);
        }
    };
}
Also used : Color(com.badlogic.gdx.graphics.Color) Vector3(com.badlogic.gdx.math.Vector3) PipelineRenderingContext(com.gempukku.libgdx.graph.pipeline.producer.PipelineRenderingContext) DefaultFieldOutput(com.gempukku.libgdx.graph.pipeline.producer.node.DefaultFieldOutput) Vector2(com.badlogic.gdx.math.Vector2) ObjectMap(com.badlogic.gdx.utils.ObjectMap) DefaultFieldOutput(com.gempukku.libgdx.graph.pipeline.producer.node.DefaultFieldOutput) SingleInputsPipelineNode(com.gempukku.libgdx.graph.pipeline.producer.node.SingleInputsPipelineNode)

Example 8 with SingleInputsPipelineNode

use of com.gempukku.libgdx.graph.pipeline.producer.node.SingleInputsPipelineNode in project gdx-graph by MarcinSc.

the class DotProductPipelineNodeProducer method createNodeForSingleInputs.

@Override
public PipelineNode createNodeForSingleInputs(JsonValue data, ObjectMap<String, String> inputTypes, ObjectMap<String, String> outputTypes) {
    final String resultType = inputTypes.get("a");
    final Object resultValue = createResult(resultType);
    final ObjectMap<String, PipelineNode.FieldOutput<?>> result = new ObjectMap<>();
    final DefaultFieldOutput resultOutput = new DefaultFieldOutput(resultType);
    result.put("output", resultOutput);
    return new SingleInputsPipelineNode(result) {

        @Override
        public void executeNode(PipelineRenderingContext pipelineRenderingContext, PipelineRequirementsCallback pipelineRequirementsCallback) {
            FieldOutput<?> aFunction = inputs.get("a");
            FieldOutput<?> bFunction = inputs.get("b");
            Object a = aFunction.getValue();
            Object b = bFunction.getValue();
            Object returnValue;
            if (a instanceof Float) {
                returnValue = ((float) a) * ((float) b);
            } else if (a instanceof Vector2) {
                returnValue = ((Vector2) resultValue).dot((Vector2) b);
            } else if (a instanceof Vector3) {
                returnValue = ((Vector3) resultValue).dot((Vector3) b);
            } else if (a instanceof Color) {
                Color aColor = (Color) a;
                Color bColor = (Color) b;
                returnValue = aColor.r * bColor.r + aColor.g * bColor.g + aColor.b * bColor.b + aColor.a * bColor.a;
            } else {
                throw new IllegalArgumentException("Not matching type for function");
            }
            resultOutput.setValue(returnValue);
        }
    };
}
Also used : Color(com.badlogic.gdx.graphics.Color) Vector3(com.badlogic.gdx.math.Vector3) PipelineRenderingContext(com.gempukku.libgdx.graph.pipeline.producer.PipelineRenderingContext) DefaultFieldOutput(com.gempukku.libgdx.graph.pipeline.producer.node.DefaultFieldOutput) ObjectMap(com.badlogic.gdx.utils.ObjectMap) Vector2(com.badlogic.gdx.math.Vector2) DefaultFieldOutput(com.gempukku.libgdx.graph.pipeline.producer.node.DefaultFieldOutput) SingleInputsPipelineNode(com.gempukku.libgdx.graph.pipeline.producer.node.SingleInputsPipelineNode)

Example 9 with SingleInputsPipelineNode

use of com.gempukku.libgdx.graph.pipeline.producer.node.SingleInputsPipelineNode in project gdx-graph by MarcinSc.

the class ThreeParamMathFunctionPipelineNodeProducer method createNodeForSingleInputs.

@Override
public PipelineNode createNodeForSingleInputs(JsonValue data, ObjectMap<String, String> inputTypes, ObjectMap<String, String> outputTypes) {
    final String resultType = inputTypes.get(param1);
    final Object resultValue = createResult(resultType);
    final ObjectMap<String, PipelineNode.FieldOutput<?>> result = new ObjectMap<>();
    final DefaultFieldOutput resultOutput = new DefaultFieldOutput(resultType);
    result.put(outputName, resultOutput);
    return new SingleInputsPipelineNode(result) {

        @Override
        public void executeNode(PipelineRenderingContext pipelineRenderingContext, PipelineRequirementsCallback pipelineRequirementsCallback) {
            FieldOutput<?> aFunction = inputs.get(param1);
            FieldOutput<?> bFunction = inputs.get(param2);
            FieldOutput<?> cFunction = inputs.get(param3);
            Object a = aFunction.getValue();
            Object b = bFunction.getValue();
            Object c = cFunction.getValue();
            Object returnValue;
            if (resultType.equals(PipelineFieldType.Float)) {
                returnValue = executeFunction(a, b, c, 0);
            } else if (resultType.equals(PipelineFieldType.Vector2)) {
                returnValue = ((Vector2) resultValue).set(executeFunction(a, b, c, 0), executeFunction(a, b, c, 1));
            } else if (resultType.equals(PipelineFieldType.Vector3)) {
                returnValue = ((Vector3) resultValue).set(executeFunction(a, b, c, 0), executeFunction(a, b, c, 1), executeFunction(a, b, c, 2));
            } else {
                returnValue = ((Color) resultValue).set(executeFunction(a, b, c, 0), executeFunction(a, b, c, 1), executeFunction(a, b, c, 2), executeFunction(a, b, c, 3));
            }
            resultOutput.setValue(returnValue);
        }
    };
}
Also used : ObjectMap(com.badlogic.gdx.utils.ObjectMap) Vector2(com.badlogic.gdx.math.Vector2) DefaultFieldOutput(com.gempukku.libgdx.graph.pipeline.producer.node.DefaultFieldOutput) SingleInputsPipelineNode(com.gempukku.libgdx.graph.pipeline.producer.node.SingleInputsPipelineNode) PipelineRenderingContext(com.gempukku.libgdx.graph.pipeline.producer.PipelineRenderingContext) DefaultFieldOutput(com.gempukku.libgdx.graph.pipeline.producer.node.DefaultFieldOutput)

Example 10 with SingleInputsPipelineNode

use of com.gempukku.libgdx.graph.pipeline.producer.node.SingleInputsPipelineNode in project gdx-graph by MarcinSc.

the class TwoParamMathFunctionPipelineNodeProducer method createNodeForSingleInputs.

@Override
public PipelineNode createNodeForSingleInputs(JsonValue data, ObjectMap<String, String> inputTypes, ObjectMap<String, String> outputTypes) {
    final String resultType = inputTypes.get(param1);
    final Object resultValue = createResult(resultType);
    final ObjectMap<String, PipelineNode.FieldOutput<?>> result = new ObjectMap<>();
    final DefaultFieldOutput resultOutput = new DefaultFieldOutput(resultType);
    result.put(outputName, resultOutput);
    return new SingleInputsPipelineNode(result) {

        @Override
        public void executeNode(PipelineRenderingContext pipelineRenderingContext, PipelineRequirementsCallback pipelineRequirementsCallback) {
            FieldOutput<?> aFunction = inputs.get(param1);
            FieldOutput<?> bFunction = inputs.get(param2);
            Object a = aFunction.getValue();
            Object b = bFunction.getValue();
            Object returnValue;
            if (resultType.equals(PipelineFieldType.Float)) {
                returnValue = executeFunction(a, b, 0);
            } else if (resultType.equals(PipelineFieldType.Vector2)) {
                returnValue = ((Vector2) resultValue).set(executeFunction(a, b, 0), executeFunction(a, b, 1));
            } else if (resultType.equals(PipelineFieldType.Vector3)) {
                returnValue = ((Vector3) resultValue).set(executeFunction(a, b, 0), executeFunction(a, b, 1), executeFunction(a, b, 2));
            } else {
                returnValue = ((Color) resultValue).set(executeFunction(a, b, 0), executeFunction(a, b, 1), executeFunction(a, b, 2), executeFunction(a, b, 3));
            }
            resultOutput.setValue(returnValue);
        }
    };
}
Also used : ObjectMap(com.badlogic.gdx.utils.ObjectMap) Vector2(com.badlogic.gdx.math.Vector2) DefaultFieldOutput(com.gempukku.libgdx.graph.pipeline.producer.node.DefaultFieldOutput) SingleInputsPipelineNode(com.gempukku.libgdx.graph.pipeline.producer.node.SingleInputsPipelineNode) PipelineRenderingContext(com.gempukku.libgdx.graph.pipeline.producer.PipelineRenderingContext) DefaultFieldOutput(com.gempukku.libgdx.graph.pipeline.producer.node.DefaultFieldOutput)

Aggregations

ObjectMap (com.badlogic.gdx.utils.ObjectMap)10 PipelineRenderingContext (com.gempukku.libgdx.graph.pipeline.producer.PipelineRenderingContext)10 DefaultFieldOutput (com.gempukku.libgdx.graph.pipeline.producer.node.DefaultFieldOutput)10 SingleInputsPipelineNode (com.gempukku.libgdx.graph.pipeline.producer.node.SingleInputsPipelineNode)10 Vector2 (com.badlogic.gdx.math.Vector2)9 Vector3 (com.badlogic.gdx.math.Vector3)6 Color (com.badlogic.gdx.graphics.Color)5