From 7ca83e6bd9d616835402ae963363ef31e4c67139 Mon Sep 17 00:00:00 2001 From: Robert Dorn Date: Wed, 11 Dec 2024 12:44:32 +0100 Subject: [PATCH] added missing saturate node registry implementation --- src/BasicBehaveEngine/BasicBehaveEngine.ts | 2 ++ src/authoring/AuthoringNodeSpecs.ts | 35 ++++++++++++++++++++++ tst/nodes.test.ts | 23 ++++++++++++++ 3 files changed, 60 insertions(+) diff --git a/src/BasicBehaveEngine/BasicBehaveEngine.ts b/src/BasicBehaveEngine/BasicBehaveEngine.ts index 57fceff..9cf81f8 100644 --- a/src/BasicBehaveEngine/BasicBehaveEngine.ts +++ b/src/BasicBehaveEngine/BasicBehaveEngine.ts @@ -35,6 +35,7 @@ import {Remainder} from "./nodes/math/arithmetic/Remainder"; import {Min} from "./nodes/math/arithmetic/Min"; import {Max} from "./nodes/math/arithmetic/Max"; import {Mix} from "./nodes/math/arithmetic/Mix"; +import {Saturate} from "./nodes/math/arithmetic/Saturate"; import {Clamp} from "./nodes/math/arithmetic/Clamp"; import {DegreeToRadians} from "./nodes/math/trigonometry/DegreeToRadians"; import {RadiansToDegrees} from "./nodes/math/trigonometry/RadiansToDegrees"; @@ -354,6 +355,7 @@ export class BasicBehaveEngine implements IBehaveEngine { this.registerBehaveEngineNode("math/min", Min); this.registerBehaveEngineNode("math/max", Max); this.registerBehaveEngineNode("math/mix", Mix); + this.registerBehaveEngineNode("math/saturate", Saturate); this.registerBehaveEngineNode("math/clamp", Clamp); this.registerBehaveEngineNode("math/rad", DegreeToRadians); this.registerBehaveEngineNode("math/deg", RadiansToDegrees); diff --git a/src/authoring/AuthoringNodeSpecs.ts b/src/authoring/AuthoringNodeSpecs.ts index 45b9384..0468bab 100644 --- a/src/authoring/AuthoringNodeSpecs.ts +++ b/src/authoring/AuthoringNodeSpecs.ts @@ -2117,6 +2117,41 @@ export const arithmeticNodes = [ ] } }, + { + type: "math/saturate", + description: "Saturate operation", + configuration: [], + input: { + flows: [], + values: [ + { + id: "a", + description: "First Arg", + types: [ + "float", + "float2", + "float3", + "float4" + ] + } + ] + }, + output: { + flows: [], + values: [ + { + id: "value", + description: "Clamps between 0 and 1", + types: [ + "float", + "float2", + "float3", + "float4" + ] + } + ] + } + }, { type: "math/max", description: "Maximum operation", diff --git a/tst/nodes.test.ts b/tst/nodes.test.ts index f92b799..93b8e44 100644 --- a/tst/nodes.test.ts +++ b/tst/nodes.test.ts @@ -1114,7 +1114,30 @@ describe('nodes', () => { expect(val['value'].value[0]).toBe(-0); expect(val['value'].value[1]).toBe(4); expect(val['value'].value[2]).toBe(9); + }); + + it("math/saturate", () => { + let sat: Saturate = new Saturate({ + ...defaultProps, + values: [ + { id: 'a', value: [2], type: 2 }, + ] + }); + + let val = sat.processNode(); + expect(val['value'].value[0]).toBe(1); + + sat = new Saturate({ + ...defaultProps, + values: [ + { id: 'a', value: [2, 0.5, -2], type: 3 } + ] + }); + val = sat.processNode(); + expect(val['value'].value[0]).toBe(1); + expect(val['value'].value[1]).toBe(0.5); + expect(val['value'].value[2]).toBe(0); }); it("math/max", () => {