Search in sources :

Example 1 with SingleInputsPipelineNode

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

the class SingleParamMathFunctionPipelineNodeProducerImpl method createNodeForSingleInputs.

@Override
public PipelineNode createNodeForSingleInputs(JsonValue data, ObjectMap<String, String> inputTypes, ObjectMap<String, String> outputTypes) {
    final String resultType = inputTypes.get(inputName);
    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) {
            Object value = inputs.get(inputName).getValue();
            Object returnValue;
            if (resultType.equals(PipelineFieldType.Float)) {
                returnValue = executeFunction(value, 0);
            } else if (resultType.equals(PipelineFieldType.Vector2)) {
                returnValue = ((Vector2) resultValue).set(executeFunction(value, 0), executeFunction(value, 1));
            } else if (resultType.equals(PipelineFieldType.Vector3)) {
                returnValue = ((Vector3) resultValue).set(executeFunction(value, 0), executeFunction(value, 1), executeFunction(value, 2));
            } else {
                returnValue = ((Color) resultValue).set(executeFunction(value, 0), executeFunction(value, 1), executeFunction(value, 2), executeFunction(value, 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 2 with SingleInputsPipelineNode

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

the class RenderSizePipelineNodeProducer method createNodeForSingleInputs.

@Override
public PipelineNode createNodeForSingleInputs(JsonValue data, ObjectMap<String, String> inputTypes, ObjectMap<String, String> outputTypes) {
    final Vector2 size = new Vector2();
    final DefaultFieldOutput<Vector2> sizeOutput = new DefaultFieldOutput<>(PipelineFieldType.Vector2);
    sizeOutput.setValue(size);
    final DefaultFieldOutput<Float> widthOutput = new DefaultFieldOutput<>(PipelineFieldType.Float);
    final DefaultFieldOutput<Float> heightOutput = new DefaultFieldOutput<>(PipelineFieldType.Float);
    final ObjectMap<String, PipelineNode.FieldOutput<?>> result = new ObjectMap<>();
    result.put("size", sizeOutput);
    result.put("width", widthOutput);
    result.put("height", heightOutput);
    return new SingleInputsPipelineNode(result) {

        @Override
        public void executeNode(PipelineRenderingContext pipelineRenderingContext, PipelineRequirementsCallback pipelineRequirementsCallback) {
            int width = pipelineRenderingContext.getRenderWidth();
            int height = pipelineRenderingContext.getRenderHeight();
            size.set(width, height);
            widthOutput.setValue(width * 1f);
            heightOutput.setValue(height * 1f);
        }
    };
}
Also used : 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 3 with SingleInputsPipelineNode

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

the class CrossProductPipelineNodeProducer method createNodeForSingleInputs.

@Override
public PipelineNode createNodeForSingleInputs(JsonValue data, ObjectMap<String, String> inputTypes, ObjectMap<String, String> outputTypes) {
    final Vector3 tmpVector = new Vector3();
    final ObjectMap<String, PipelineNode.FieldOutput<?>> result = new ObjectMap<>();
    final DefaultFieldOutput resultOutput = new DefaultFieldOutput(PipelineFieldType.Vector3);
    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");
            Vector3 a = (Vector3) aFunction.getValue();
            Vector3 b = (Vector3) bFunction.getValue();
            Vector3 returnValue = tmpVector.set(a).crs(b);
            resultOutput.setValue(returnValue);
        }
    };
}
Also used : ObjectMap(com.badlogic.gdx.utils.ObjectMap) DefaultFieldOutput(com.gempukku.libgdx.graph.pipeline.producer.node.DefaultFieldOutput) SingleInputsPipelineNode(com.gempukku.libgdx.graph.pipeline.producer.node.SingleInputsPipelineNode) Vector3(com.badlogic.gdx.math.Vector3) PipelineRenderingContext(com.gempukku.libgdx.graph.pipeline.producer.PipelineRenderingContext) DefaultFieldOutput(com.gempukku.libgdx.graph.pipeline.producer.node.DefaultFieldOutput)

Example 4 with SingleInputsPipelineNode

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

the class NormalizePipelineNodeProducer method createNodeForSingleInputs.

@Override
public PipelineNode createNodeForSingleInputs(JsonValue data, ObjectMap<String, String> inputTypes, ObjectMap<String, String> outputTypes) {
    final String resultType = inputTypes.get("input");
    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) {

        private FieldOutput<?> aFunction;

        @Override
        public void executeNode(PipelineRenderingContext pipelineRenderingContext, PipelineRequirementsCallback pipelineRequirementsCallback) {
            aFunction = inputs.get("input");
            Object a = aFunction.getValue();
            Object returnValue;
            if (a instanceof Float) {
                returnValue = Math.signum((float) a);
            } else if (a instanceof Vector2) {
                returnValue = ((Vector2) resultValue).set((Vector2) a).nor();
            } else if (a instanceof Vector3) {
                returnValue = ((Vector3) resultValue).set((Vector3) a).nor();
            } else {
                Color aColor = (Color) a;
                float length = (float) Math.sqrt(aColor.r * aColor.r + aColor.g * aColor.g + aColor.b * aColor.b + aColor.a * aColor.a);
                returnValue = ((Color) resultValue).set(aColor.r / length, aColor.b / length, aColor.b / length, aColor.a / length);
            }
            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 5 with SingleInputsPipelineNode

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

the class DistancePipelineNodeProducer method createNodeForSingleInputs.

@Override
public PipelineNode createNodeForSingleInputs(JsonValue data, ObjectMap<String, String> inputTypes, ObjectMap<String, String> outputTypes) {
    final String resultType = inputTypes.get("p0");
    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("p0");
            FieldOutput<?> bFunction = inputs.get("p1");
            Object a = aFunction.getValue();
            Object b = bFunction.getValue();
            Object returnValue;
            if (a instanceof Float) {
                returnValue = Math.abs(((float) a) - ((float) b));
            } else if (a instanceof Vector2) {
                returnValue = ((Vector2) resultValue).dst((Vector2) b);
            } else if (a instanceof Vector3) {
                returnValue = ((Vector3) resultValue).dst((Vector3) b);
            } else if (a instanceof Color) {
                Color aColor = (Color) a;
                Color bColor = (Color) b;
                final float p1 = aColor.r - bColor.r;
                final float p2 = aColor.g - bColor.g;
                final float p3 = aColor.b - bColor.b;
                final float p4 = aColor.a - bColor.a;
                returnValue = (float) Math.sqrt(p1 * p1 + p2 * p2 + p3 * p3 + p4 * p4);
            } 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)

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