Skip to content

Commit

Permalink
add data binding blend states support
Browse files Browse the repository at this point in the history
add support for data binding blend animations.
There's a lot of boilerplate code, but I have commented the most relevant parts

Diffs=
f9355c5d84 add data binding blend states support (#7731)

Co-authored-by: hernan <hernan@rive.app>
  • Loading branch information
bodymovin and bodymovin committed Dec 11, 2024
1 parent b6b3a3e commit 79ad25c
Show file tree
Hide file tree
Showing 25 changed files with 377 additions and 122 deletions.
2 changes: 1 addition & 1 deletion .rive_head
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1a8c1621517e961a2e7e04b51d1a0e2c0b0d049a
f9355c5d844b041f7ea6475ef99be7288f74404c
12 changes: 11 additions & 1 deletion dev/defs/animation/blend_animation_direct.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,24 @@
},
"description": "Direct mix value for this animation."
},
"bindablePropertyId": {
"type": "Id",
"initialValue": "Core.missingId",
"key": {
"int": 736,
"string": "bindablepropertyid"
},
"description": "Direct mix value for this animation.",
"runtime": false
},
"blendSource": {
"type": "uint",
"initialValue": "0",
"key": {
"int": 298,
"string": "blendsource"
},
"description": "Source to use when establishing the mix value for the animation. 0 means look at the input, 1 look at the mixValue."
"description": "Source to use when establishing the mix value for the animation. 0 means look at the input, 1 look at the mixValue, 2 look at the bindableProperty."
}
}
}
18 changes: 3 additions & 15 deletions dev/defs/animation/blend_state_1d.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@
{
"name": "BlendState1D",
"key": {
"int": 76,
"int": 527,
"string": "blendstate1d"
},
"abstract": true,
"extends": "animation/blend_state.json",
"generic": "animation/blend_animation_1d.json",
"properties": {
"inputId": {
"type": "Id",
"typeRuntime": "uint",
"initialValue": "Core.missingId",
"initialValueRuntime": "-1",
"key": {
"int": 167,
"string": "inputid"
},
"description": "Id of the input that drives the mix value for this blend state."
}
}
"generic": "animation/blend_animation_1d.json"
}
21 changes: 21 additions & 0 deletions dev/defs/animation/blend_state_1d_input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "BlendState1DInput",
"key": {
"int": 76,
"string": "blendstate1dinput"
},
"extends": "animation/blend_state_1d.json",
"properties": {
"inputId": {
"type": "Id",
"typeRuntime": "uint",
"initialValue": "Core.missingId",
"initialValueRuntime": "-1",
"key": {
"int": 167,
"string": "inputid"
},
"description": "Id of the input that drives the mix value for this blend state."
}
}
}
20 changes: 20 additions & 0 deletions dev/defs/animation/blend_state_1d_viewmodel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "BlendState1DViewModel",
"key": {
"int": 528,
"string": "blendstate1dviewmodel"
},
"extends": "animation/blend_state_1d.json",
"properties": {
"bindablePropertyId": {
"type": "Id",
"initialValue": "Core.missingId",
"key": {
"int": 737,
"string": "bindablepropertyid"
},
"description": "Id of the bindable property that drives the mix value for this blend state.",
"runtime": false
}
}
}
12 changes: 11 additions & 1 deletion include/rive/animation/blend_animation_direct.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
#include <stdio.h>
namespace rive
{

class BindableProperty;
enum class DirectBlendSource : unsigned int
{
inputId = 0,
mixValue = 1,
dataBindId = 2,
};

class BlendAnimationDirect : public BlendAnimationDirectBase
Expand All @@ -17,7 +18,16 @@ class BlendAnimationDirect : public BlendAnimationDirectBase
StatusCode onAddedDirty(CoreContext* context) override;
StatusCode onAddedClean(CoreContext* context) override;
StatusCode import(ImportStack& importStack) override;
void bindableProperty(BindableProperty* value)
{
m_bindableProperty = value;
};
BindableProperty* bindableProperty() const { return m_bindableProperty; };

private:
BindableProperty* m_bindableProperty;
};

} // namespace rive

#endif
4 changes: 0 additions & 4 deletions include/rive/animation/blend_state_1d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ namespace rive
class BlendState1D : public BlendState1DBase
{
public:
bool hasValidInputId() const { return inputId() != Core::emptyId; }

StatusCode import(ImportStack& importStack) override;

std::unique_ptr<StateInstance> makeInstance(
ArtboardInstance*) const override;
};
Expand Down
16 changes: 16 additions & 0 deletions include/rive/animation/blend_state_1d_input.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef _RIVE_BLEND_STATE1_DINPUT_HPP_
#define _RIVE_BLEND_STATE1_DINPUT_HPP_
#include "rive/generated/animation/blend_state_1d_input_base.hpp"
#include <stdio.h>
namespace rive
{
class BlendState1DInput : public BlendState1DInputBase
{
public:
bool hasValidInputId() const { return inputId() != Core::emptyId; }

StatusCode import(ImportStack& importStack) override;
};
} // namespace rive

#endif
20 changes: 20 additions & 0 deletions include/rive/animation/blend_state_1d_viewmodel.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef _RIVE_BLEND_STATE1_DVIEW_MODEL_HPP_
#define _RIVE_BLEND_STATE1_DVIEW_MODEL_HPP_
#include "rive/generated/animation/blend_state_1d_viewmodel_base.hpp"
#include "rive/data_bind/bindable_property.hpp"
#include <stdio.h>
namespace rive
{
class BlendState1DViewModel : public BlendState1DViewModelBase
{
public:
StatusCode import(ImportStack& importStack) override;

BindableProperty* bindableProperty() const { return m_bindableProperty; };

protected:
BindableProperty* m_bindableProperty;
};
} // namespace rive

#endif
39 changes: 1 addition & 38 deletions include/rive/generated/animation/blend_state_1d_base.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#ifndef _RIVE_BLEND_STATE1_DBASE_HPP_
#define _RIVE_BLEND_STATE1_DBASE_HPP_
#include "rive/animation/blend_state.hpp"
#include "rive/core/field_types/core_uint_type.hpp"
namespace rive
{
class BlendState1DBase : public BlendState
Expand All @@ -10,7 +9,7 @@ class BlendState1DBase : public BlendState
typedef BlendState Super;

public:
static const uint16_t typeKey = 76;
static const uint16_t typeKey = 527;

/// Helper to quickly determine if a core object extends another without
/// RTTI at runtime.
Expand All @@ -30,43 +29,7 @@ class BlendState1DBase : public BlendState

uint16_t coreType() const override { return typeKey; }

static const uint16_t inputIdPropertyKey = 167;

protected:
uint32_t m_InputId = -1;

public:
inline uint32_t inputId() const { return m_InputId; }
void inputId(uint32_t value)
{
if (m_InputId == value)
{
return;
}
m_InputId = value;
inputIdChanged();
}

Core* clone() const override;
void copy(const BlendState1DBase& object)
{
m_InputId = object.m_InputId;
BlendState::copy(object);
}

bool deserialize(uint16_t propertyKey, BinaryReader& reader) override
{
switch (propertyKey)
{
case inputIdPropertyKey:
m_InputId = CoreUintType::deserialize(reader);
return true;
}
return BlendState::deserialize(propertyKey, reader);
}

protected:
virtual void inputIdChanged() {}
};
} // namespace rive

Expand Down
74 changes: 74 additions & 0 deletions include/rive/generated/animation/blend_state_1d_input_base.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#ifndef _RIVE_BLEND_STATE1_DINPUT_BASE_HPP_
#define _RIVE_BLEND_STATE1_DINPUT_BASE_HPP_
#include "rive/animation/blend_state_1d.hpp"
#include "rive/core/field_types/core_uint_type.hpp"
namespace rive
{
class BlendState1DInputBase : public BlendState1D
{
protected:
typedef BlendState1D Super;

public:
static const uint16_t typeKey = 76;

/// Helper to quickly determine if a core object extends another without
/// RTTI at runtime.
bool isTypeOf(uint16_t typeKey) const override
{
switch (typeKey)
{
case BlendState1DInputBase::typeKey:
case BlendState1DBase::typeKey:
case BlendStateBase::typeKey:
case LayerStateBase::typeKey:
case StateMachineLayerComponentBase::typeKey:
return true;
default:
return false;
}
}

uint16_t coreType() const override { return typeKey; }

static const uint16_t inputIdPropertyKey = 167;

protected:
uint32_t m_InputId = -1;

public:
inline uint32_t inputId() const { return m_InputId; }
void inputId(uint32_t value)
{
if (m_InputId == value)
{
return;
}
m_InputId = value;
inputIdChanged();
}

Core* clone() const override;
void copy(const BlendState1DInputBase& object)
{
m_InputId = object.m_InputId;
BlendState1D::copy(object);
}

bool deserialize(uint16_t propertyKey, BinaryReader& reader) override
{
switch (propertyKey)
{
case inputIdPropertyKey:
m_InputId = CoreUintType::deserialize(reader);
return true;
}
return BlendState1D::deserialize(propertyKey, reader);
}

protected:
virtual void inputIdChanged() {}
};
} // namespace rive

#endif
39 changes: 39 additions & 0 deletions include/rive/generated/animation/blend_state_1d_viewmodel_base.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#ifndef _RIVE_BLEND_STATE1_DVIEW_MODEL_BASE_HPP_
#define _RIVE_BLEND_STATE1_DVIEW_MODEL_BASE_HPP_
#include "rive/animation/blend_state_1d.hpp"
namespace rive
{
class BlendState1DViewModelBase : public BlendState1D
{
protected:
typedef BlendState1D Super;

public:
static const uint16_t typeKey = 528;

/// Helper to quickly determine if a core object extends another without
/// RTTI at runtime.
bool isTypeOf(uint16_t typeKey) const override
{
switch (typeKey)
{
case BlendState1DViewModelBase::typeKey:
case BlendState1DBase::typeKey:
case BlendStateBase::typeKey:
case LayerStateBase::typeKey:
case StateMachineLayerComponentBase::typeKey:
return true;
default:
return false;
}
}

uint16_t coreType() const override { return typeKey; }

Core* clone() const override;

protected:
};
} // namespace rive

#endif
Loading

0 comments on commit 79ad25c

Please sign in to comment.