Skip to content

Onion Skin Management (Do not merge) #774

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/lib/ip/IPBaseNodes/IPBaseNodes/PaintIPNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@ namespace IPCore
struct LocalPolyLine : public Paint::PolyLine
{
int eye;
Color baseColor;
};

struct LocalText : public Paint::Text
{
int eye;
Color baseColor;
};

typedef TwkMath::Vec4f Vec4;
Expand Down
134 changes: 106 additions & 28 deletions src/lib/ip/IPBaseNodes/PaintIPNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ namespace IPCore
declareProperty<IntProperty>("paint.show", 1);
declareProperty<StringProperty>("paint.exclude");
declareProperty<StringProperty>("paint.include");
declareProperty<IntProperty>("paint.onionShow", 0);
declareProperty<IntProperty>("paint.onionBeforeFrame", 5);
declareProperty<IntProperty>("paint.onionAfterFrame", 5);
declareProperty<Vec4fProperty>("paint.onionBeforeColor",
Vec4f(1, 0, 0, 1));
declareProperty<Vec4fProperty>("paint.onionAfterColor",
Vec4f(0, 1, 0, 1));

m_tag = createComponent("tag");
}
Expand Down Expand Up @@ -80,6 +87,7 @@ namespace IPCore
const int eye = eyeP && eyeP->size() ? eyeP->front() : 2;

p.width = width;
p.baseColor = color;
p.color = color;
p.brush = brush;
p.debug = debug;
Expand Down Expand Up @@ -148,6 +156,7 @@ namespace IPCore
p.scale = 1.0 / 80.0 / 10.0 * scale;
p.pos = pos;
p.spacing = space;
p.baseColor = color;
p.color = color;
p.font = font;
p.text = text;
Expand Down Expand Up @@ -342,6 +351,29 @@ namespace IPCore
IPNode::readCompleted(typeName, version);
}

static Vec4f onionSkinColor(const Vec4f& colorIn, const Vec4f& colorBase,
const Vec4f& colorBefore,
const Vec4f& colorAfter, float alpha, int i,
int frame)
{
Vec4f color;
if (i < frame)
{
color = colorBefore;
color[3] = color[3] * alpha * colorBase[3];
}
else if (i > frame)
{
color = colorAfter;
color[3] = color[3] * alpha * colorBase[3];
}
else
{
color = colorBase;
}
return color;
}

IPImage* PaintIPNode::evaluate(const Context& context)
{
IPImage* head = 0;
Expand All @@ -356,50 +388,96 @@ namespace IPCore
IntProperty* showP = property<IntProperty>("paint", "show");
StringProperty* incP = property<StringProperty>("paint", "include");
StringProperty* excP = property<StringProperty>("paint", "exclude");
IntProperty* onionShowP = property<IntProperty>("paint", "onionShow");
IntProperty* onionBFP =
property<IntProperty>("paint", "onionBeforeFrame");
IntProperty* onionAFP =
property<IntProperty>("paint", "onionAfterFrame");
Vec4fProperty* onionBCP =
property<Vec4fProperty>("paint", "onionBeforeColor");
Vec4fProperty* onionACP =
property<Vec4fProperty>("paint", "onionAfterColor");

bool showPaint = !showP || showP->empty() || showP->front() == 1;

if (showPaint)
{
if (m_frameMap.count(frame) != 0)
bool onionShow =
onionShowP && !onionShowP->empty() && onionShowP->front() == 1;
int rb, ra;
Vec4f cb, ca;
if (onionShow)
{
Components& comps = m_frameMap[frame];
size_t s = comps.size();
rb = onionBFP && !onionBFP->empty() ? onionBFP->front() : 0;
ra = onionAFP && !onionAFP->empty() ? onionAFP->front() : 0;
rb = std::max(0, rb + 1);
ra = std::max(0, ra + 1);
cb = onionBCP && onionBCP->size() ? onionBCP->front()
: Vec4f(1, 0, 0, 1);
ca = onionACP && onionACP->size() ? onionACP->front()
: Vec4f(0, 1, 0, 1);
}
else
{
rb = 0;
ra = 0;
cb = Vec4f(1, 0, 0, 1);
ca = Vec4f(0, 1, 0, 1);
}

for (size_t q = 0; q < s; q++)
for (size_t i = frame - rb; i <= frame + ra; i++)
{
if (m_frameMap.count(i) != 0)
{
Component* c = comps[q];
int numProps = c->properties().size();
float alpha =
i < frame
? (rb > 0 ? 1.0f - (frame - i) / float(rb) : 1.0f)
: (ra > 0 ? 1.0f - (i - frame) / float(ra) : 1.0f);

if (m_penStrokes.count(c) >= 1)
Components& comps = m_frameMap[i];
size_t s = comps.size();

for (size_t q = 0; q < s; q++)
{
if (numProps == 0)
{
m_penStrokes.erase(c);
}
else
{
LocalPolyLine& pl = m_penStrokes[c];
Component* c = comps[q];
int numProps = c->properties().size();

if (pl.eye == 2 || (pl.eye == context.eye))
if (m_penStrokes.count(c) >= 1)
{
if (numProps == 0)
{
head->commands.push_back(&pl);
m_penStrokes.erase(c);
}
else
{
LocalPolyLine& pl = m_penStrokes[c];

if (pl.eye == 2 || (pl.eye == context.eye))
{
pl.color =
onionSkinColor(pl.color, pl.baseColor,
cb, ca, alpha, i, frame);
head->commands.push_back(&pl);
}
}
}
}
else if (m_texts.count(c) >= 1)
{
if (numProps == 0)
{
m_texts.erase(c);
}
else
else if (m_texts.count(c) >= 1)
{
LocalText& t = m_texts[c];

if (t.eye == 2 || (t.eye == context.eye))
if (numProps == 0)
{
m_texts.erase(c);
}
else
{
head->commands.push_back(&t);
LocalText& t = m_texts[c];

if (t.eye == 2 || (t.eye == context.eye))
{
t.color =
onionSkinColor(t.color, t.baseColor, cb,
ca, alpha, i, frame);
head->commands.push_back(&t);
}
}
}
}
Expand Down
Loading
Loading