Skip to content

Commit

Permalink
Nnnn range data converter
Browse files Browse the repository at this point in the history
added a new data converter by request from Duo.
It defines an input range and maps it to an output range.
It includes some extra features like clamping the value, applying a modulo in order to make it loop, and reversing it.
And it also takes an interpolator such that the mapping doesn't need to be lineal.
@

https://github.com/user-attachments/assets/d18b1269-8b5e-4aad-9504-9f5f3dcdaad9

Diffs=
88543fa792 Nnnn range data converter (#8585)

Co-authored-by: hernan <hernan@rive.app>
  • Loading branch information
bodymovin and bodymovin committed Nov 18, 2024
1 parent 95187c3 commit e1c546d
Show file tree
Hide file tree
Showing 23 changed files with 661 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .rive_head
Original file line number Diff line number Diff line change
@@ -1 +1 @@
a2b0cb230ae3f3834d13096d7dc7688ef908c1d3
88543fa79295566065b700bfcf66130f327ff562
39 changes: 39 additions & 0 deletions dev/defs/data_bind/converters/data_converter_range_mapper.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "DataConverterRangeMapper",
"key": {
"int": 518,
"string": "dataconverterrangemapper"
},
"abstract": true,
"extends": "data_bind/converters/data_converter.json",
"properties": {
"interpolationType": {
"type": "uint",
"initialValue": "0",
"key": {
"int": 713,
"string": "interpolationtype"
},
"description": "The type of interpolation index in KeyframeInterpolation applied to this layout."
},
"interpolatorId": {
"type": "Id",
"typeRuntime": "uint",
"initialValue": "Core.missingId",
"initialValueRuntime": "-1",
"key": {
"int": 714,
"string": "interpolatorid"
},
"description": "The id of the custom interpolator used when interpolation is Cubic."
},
"flags": {
"type": "uint",
"initialValue": "0",
"key": {
"int": 715,
"string": "flags"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"name": "DataConverterRangeMapperValues",
"key": {
"int": 519,
"string": "dataconverterrangemappervalues"
},
"extends": "data_bind/converters/data_converter_range_mapper.json",
"properties": {
"minInput": {
"type": "double",
"initialValue": "1",
"key": {
"int": 716,
"string": "mininput"
},
"description": "Min value the input will map from"
},
"maxInput": {
"type": "double",
"initialValue": "1",
"key": {
"int": 717,
"string": "maxinput"
},
"description": "Max value the input will map from"
},
"minOutput": {
"type": "double",
"initialValue": "1",
"key": {
"int": 718,
"string": "minoutput"
},
"description": "Min value the output will map to"
},
"maxOutput": {
"type": "double",
"initialValue": "1",
"key": {
"int": 719,
"string": "maxoutput"
},
"description": "Max value the output will map to"
}
}
}
1 change: 1 addition & 0 deletions include/rive/animation/cubic_interpolator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class CubicInterpolator : public CubicInterpolatorBase
{
public:
StatusCode onAddedDirty(CoreContext* context) override;
void initialize() override;

protected:
CubicInterpolatorSolver m_solver;
Expand Down
27 changes: 27 additions & 0 deletions include/rive/animation/data_converter_range_mapper_flags.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#ifndef _RIVE_DATA_CONVERTER_RANGE_MAPPER_FLAGS_HPP_
#define _RIVE_DATA_CONVERTER_RANGE_MAPPER_FLAGS_HPP_

#include "rive/enum_bitset.hpp"

namespace rive
{
enum class DataConverterRangeMapperFlags : unsigned short
{

/// Whether the lower bound should be clamped
ClampLower = 1 << 0,

/// Whether the upper bound should be clamped
ClampUpper = 1 << 1,

/// Whether the value should wrap if it exceeds the range
Modulo = 1 << 2,

/// Whether to reverse the mapping
Reverse = 1 << 3,

};

RIVE_MAKE_ENUM_BITSET(DataConverterRangeMapperFlags)
} // namespace rive
#endif
1 change: 1 addition & 0 deletions include/rive/animation/elastic_interpolator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class ElasticInterpolator : public ElasticInterpolatorBase
float transform(float factor) const override;

Easing easing() const { return (Easing)easingValue(); }
void initialize() override;

private:
ElasticEase m_elastic;
Expand Down
2 changes: 2 additions & 0 deletions include/rive/animation/keyframe_interpolator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class KeyFrameInterpolator : public KeyFrameInterpolatorBase
virtual float transform(float factor) const = 0;

StatusCode import(ImportStack& importStack) override;

virtual void initialize(){};
};
} // namespace rive

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class DataConverterGroupItem : public DataConverterGroupItemBase
void converter(DataConverter* value) { m_dataConverter = value; };

protected:
DataConverter* m_dataConverter;
DataConverter* m_dataConverter = nullptr;
};
} // namespace rive

Expand Down
31 changes: 31 additions & 0 deletions include/rive/data_bind/converters/data_converter_range_mapper.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#ifndef _RIVE_DATA_CONVERTER_RANGE_MAPPER_HPP_
#define _RIVE_DATA_CONVERTER_RANGE_MAPPER_HPP_
#include "rive/generated/data_bind/converters/data_converter_range_mapper_base.hpp"
#include "rive/data_bind/data_values/data_value_number.hpp"
#include "rive/data_bind/data_values/data_value.hpp"
#include "rive/animation/keyframe_interpolator.hpp"
#include <stdio.h>
namespace rive
{
class DataConverterRangeMapper : public DataConverterRangeMapperBase
{
protected:
KeyFrameInterpolator* m_interpolator;
DataValueNumber* calculateRange(DataValue* input,
float minInput,
float maxInput,
float minOutput,
float maxOutput);
DataValueNumber* calculateReverseRange(DataValue* input,
float minInput,
float maxInput,
float minOutput,
float maxOutput);

public:
void interpolator(KeyFrameInterpolator* interpolator);
DataType outputType() override { return DataType::number; };
};
} // namespace rive

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef _RIVE_DATA_CONVERTER_RANGE_MAPPER_VALUES_HPP_
#define _RIVE_DATA_CONVERTER_RANGE_MAPPER_VALUES_HPP_
#include "rive/generated/data_bind/converters/data_converter_range_mapper_values_base.hpp"
#include <stdio.h>
namespace rive
{
class DataConverterRangeMapperValues : public DataConverterRangeMapperValuesBase
{
public:
DataValue* convert(DataValue* value, DataBind* dataBind) override;
DataValue* reverseConvert(DataValue* value, DataBind* dataBind) override;
};
} // namespace rive

#endif
72 changes: 72 additions & 0 deletions include/rive/generated/core_registry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@
#include "rive/data_bind/converters/data_converter_operation.hpp"
#include "rive/data_bind/converters/data_converter_operation_value.hpp"
#include "rive/data_bind/converters/data_converter_operation_viewmodel.hpp"
#include "rive/data_bind/converters/data_converter_range_mapper.hpp"
#include "rive/data_bind/converters/data_converter_range_mapper_values.hpp"
#include "rive/data_bind/converters/data_converter_rounder.hpp"
#include "rive/data_bind/converters/data_converter_system_degs_to_rads.hpp"
#include "rive/data_bind/converters/data_converter_system_normalizer.hpp"
Expand Down Expand Up @@ -532,6 +534,8 @@ class CoreRegistry
return new DataConverterRounder();
case DataConverterTriggerBase::typeKey:
return new DataConverterTrigger();
case DataConverterRangeMapperValuesBase::typeKey:
return new DataConverterRangeMapperValues();
case DataConverterOperationViewModelBase::typeKey:
return new DataConverterOperationViewModel();
case DataConverterToStringBase::typeKey:
Expand Down Expand Up @@ -1195,6 +1199,17 @@ class CoreRegistry
case DataConverterOperationBase::operationTypePropertyKey:
object->as<DataConverterOperationBase>()->operationType(value);
break;
case DataConverterRangeMapperBase::interpolationTypePropertyKey:
object->as<DataConverterRangeMapperBase>()->interpolationType(
value);
break;
case DataConverterRangeMapperBase::interpolatorIdPropertyKey:
object->as<DataConverterRangeMapperBase>()->interpolatorId(
value);
break;
case DataConverterRangeMapperBase::flagsPropertyKey:
object->as<DataConverterRangeMapperBase>()->flags(value);
break;
case DataConverterGroupItemBase::converterIdPropertyKey:
object->as<DataConverterGroupItemBase>()->converterId(value);
break;
Expand Down Expand Up @@ -1781,6 +1796,22 @@ class CoreRegistry
case DataConverterOperationValueBase::valuePropertyKey:
object->as<DataConverterOperationValueBase>()->value(value);
break;
case DataConverterRangeMapperValuesBase::minInputPropertyKey:
object->as<DataConverterRangeMapperValuesBase>()->minInput(
value);
break;
case DataConverterRangeMapperValuesBase::maxInputPropertyKey:
object->as<DataConverterRangeMapperValuesBase>()->maxInput(
value);
break;
case DataConverterRangeMapperValuesBase::minOutputPropertyKey:
object->as<DataConverterRangeMapperValuesBase>()->minOutput(
value);
break;
case DataConverterRangeMapperValuesBase::maxOutputPropertyKey:
object->as<DataConverterRangeMapperValuesBase>()->maxOutput(
value);
break;
case BindablePropertyNumberBase::propertyValuePropertyKey:
object->as<BindablePropertyNumberBase>()->propertyValue(value);
break;
Expand Down Expand Up @@ -2368,6 +2399,14 @@ class CoreRegistry
case DataConverterOperationBase::operationTypePropertyKey:
return object->as<DataConverterOperationBase>()
->operationType();
case DataConverterRangeMapperBase::interpolationTypePropertyKey:
return object->as<DataConverterRangeMapperBase>()
->interpolationType();
case DataConverterRangeMapperBase::interpolatorIdPropertyKey:
return object->as<DataConverterRangeMapperBase>()
->interpolatorId();
case DataConverterRangeMapperBase::flagsPropertyKey:
return object->as<DataConverterRangeMapperBase>()->flags();
case DataConverterGroupItemBase::converterIdPropertyKey:
return object->as<DataConverterGroupItemBase>()->converterId();
case DataConverterRounderBase::decimalsPropertyKey:
Expand Down Expand Up @@ -2779,6 +2818,18 @@ class CoreRegistry
return object->as<JoystickBase>()->height();
case DataConverterOperationValueBase::valuePropertyKey:
return object->as<DataConverterOperationValueBase>()->value();
case DataConverterRangeMapperValuesBase::minInputPropertyKey:
return object->as<DataConverterRangeMapperValuesBase>()
->minInput();
case DataConverterRangeMapperValuesBase::maxInputPropertyKey:
return object->as<DataConverterRangeMapperValuesBase>()
->maxInput();
case DataConverterRangeMapperValuesBase::minOutputPropertyKey:
return object->as<DataConverterRangeMapperValuesBase>()
->minOutput();
case DataConverterRangeMapperValuesBase::maxOutputPropertyKey:
return object->as<DataConverterRangeMapperValuesBase>()
->maxOutput();
case BindablePropertyNumberBase::propertyValuePropertyKey:
return object->as<BindablePropertyNumberBase>()
->propertyValue();
Expand Down Expand Up @@ -3058,6 +3109,9 @@ class CoreRegistry
case DataBindBase::flagsPropertyKey:
case DataBindBase::converterIdPropertyKey:
case DataConverterOperationBase::operationTypePropertyKey:
case DataConverterRangeMapperBase::interpolationTypePropertyKey:
case DataConverterRangeMapperBase::interpolatorIdPropertyKey:
case DataConverterRangeMapperBase::flagsPropertyKey:
case DataConverterGroupItemBase::converterIdPropertyKey:
case DataConverterRounderBase::decimalsPropertyKey:
case BindablePropertyEnumBase::propertyValuePropertyKey:
Expand Down Expand Up @@ -3250,6 +3304,10 @@ class CoreRegistry
case JoystickBase::widthPropertyKey:
case JoystickBase::heightPropertyKey:
case DataConverterOperationValueBase::valuePropertyKey:
case DataConverterRangeMapperValuesBase::minInputPropertyKey:
case DataConverterRangeMapperValuesBase::maxInputPropertyKey:
case DataConverterRangeMapperValuesBase::minOutputPropertyKey:
case DataConverterRangeMapperValuesBase::maxOutputPropertyKey:
case BindablePropertyNumberBase::propertyValuePropertyKey:
case NestedArtboardLeafBase::alignmentXPropertyKey:
case NestedArtboardLeafBase::alignmentYPropertyKey:
Expand Down Expand Up @@ -3680,6 +3738,12 @@ class CoreRegistry
return object->is<DataBindBase>();
case DataConverterOperationBase::operationTypePropertyKey:
return object->is<DataConverterOperationBase>();
case DataConverterRangeMapperBase::interpolationTypePropertyKey:
return object->is<DataConverterRangeMapperBase>();
case DataConverterRangeMapperBase::interpolatorIdPropertyKey:
return object->is<DataConverterRangeMapperBase>();
case DataConverterRangeMapperBase::flagsPropertyKey:
return object->is<DataConverterRangeMapperBase>();
case DataConverterGroupItemBase::converterIdPropertyKey:
return object->is<DataConverterGroupItemBase>();
case DataConverterRounderBase::decimalsPropertyKey:
Expand Down Expand Up @@ -4056,6 +4120,14 @@ class CoreRegistry
return object->is<JoystickBase>();
case DataConverterOperationValueBase::valuePropertyKey:
return object->is<DataConverterOperationValueBase>();
case DataConverterRangeMapperValuesBase::minInputPropertyKey:
return object->is<DataConverterRangeMapperValuesBase>();
case DataConverterRangeMapperValuesBase::maxInputPropertyKey:
return object->is<DataConverterRangeMapperValuesBase>();
case DataConverterRangeMapperValuesBase::minOutputPropertyKey:
return object->is<DataConverterRangeMapperValuesBase>();
case DataConverterRangeMapperValuesBase::maxOutputPropertyKey:
return object->is<DataConverterRangeMapperValuesBase>();
case BindablePropertyNumberBase::propertyValuePropertyKey:
return object->is<BindablePropertyNumberBase>();
case NestedArtboardLeafBase::alignmentXPropertyKey:
Expand Down
Loading

0 comments on commit e1c546d

Please sign in to comment.