diff --git a/toonz/sources/include/tools/track.h b/toonz/sources/include/tools/track.h index aee3ae5..c9268d4 100644 --- a/toonz/sources/include/tools/track.h +++ b/toonz/sources/include/tools/track.h @@ -396,9 +396,9 @@ public: return TTrackPoint( interpolationSpline(p0.position , p1.position , t0.position , t1.position , l), interpolationLinear(p0.pressure , p1.pressure , l), - //interpolationSpline(p0.pressure , p1.pressure , t0.pressure , t1.pressure , l), + //interpolationSpline(p0.pressure , p1.pressure , t0.pressure , t1.pressure , l), interpolationLinear(p0.tilt , p1.tilt , l), - //interpolationSpline(p0.tilt , p1.tilt , t0.tilt , t1.tilt , l), + //interpolationSpline(p0.tilt , p1.tilt , t0.tilt , t1.tilt , l), interpolationLinear(p0.originalIndex , p1.originalIndex , l), interpolationLinear(p0.time , p1.time , l), interpolationLinear(p0.length , p1.length , l), diff --git a/toonz/sources/tnztools/inputmanager.cpp b/toonz/sources/tnztools/inputmanager.cpp index efc0754..06b7f8d 100644 --- a/toonz/sources/tnztools/inputmanager.cpp +++ b/toonz/sources/tnztools/inputmanager.cpp @@ -1,5 +1,6 @@ +#include #include // TnzCore includes @@ -574,12 +575,10 @@ TInputManager::calcDrawBounds() { for(int i = 0; i < (int)m_modifiers.size(); ++i) bounds += m_modifiers[i]->calcDrawBounds(m_tracks[i], m_hovers[i]); - if ( debugInputManager || drawPreview ) { + if (drawPreview) { for(TTrackList::const_iterator ti = getOutputTracks().begin(); ti != getOutputTracks().end(); ++ti) { TTrack &track = **ti; - int painted = track.fixedSize() - track.fixedPointsAdded; - if (painted < 0) painted = 0; - int start = debugInputManager ? 0 : painted; + int start = std::max(0, track.fixedSize() - track.fixedPointsAdded); if (start + 1 < track.size()) for(int i = start + 1; i < track.size(); ++i) bounds += boundingBox(track[i-1].position, track[i].position); @@ -599,50 +598,69 @@ TInputManager::draw() { m_nextBounds = TRectD(); // paint not fixed parts of tracks - if ( debugInputManager || drawPreview ) { + if (drawPreview) { glPushAttrib(GL_ALL_ATTRIB_BITS); tglEnableBlending(); tglEnableLineSmooth(true, 1.0); double pixelSize = sqrt(tglGetPixelSize2()); - double colorBlack[4] = { 0.0, 0.0, 0.0, 1.0 }; - double colorWhite[4] = { 1.0, 1.0, 1.0, 1.0 }; + double colorBlack[4] = { 0.0, 0.0, 0.0, 0.5 }; + double colorWhite[4] = { 1.0, 1.0, 1.0, 0.5 }; for(TTrackList::const_iterator ti = getOutputTracks().begin(); ti != getOutputTracks().end(); ++ti) { TTrack &track = **ti; - int painted = track.fixedSize() - track.fixedPointsAdded; - if (painted < 0) painted = 0; - int start = debugInputManager ? 0 : painted; - if (start + 1 < track.size()) { - double radius = 2.0; - for(int i = start + 1; i < track.size(); ++i) { - //if (i >= painted) - // colorBlack[3] = colorWhite[3] = 0.8; - - const TPointD &a = track[i-1].position; - const TPointD &b = track[i].position; - TPointD d = b - a; - - double k = norm2(d); - if (k > TConsts::epsilon*TConsts::epsilon) { - k = 0.5*pixelSize/sqrt(k); - d = TPointD(-k*d.y, k*d.x); - glColor4dv(colorWhite); - tglDrawSegment(a - d, b - d); - glColor4dv(colorBlack); - tglDrawSegment(a + d, b + d); - radius = 2.0; - } else { - radius += 2.0; - } - - if (debugInputManager) { - glColor4d(0.0, 0.0, 0.0, 0.25); - tglDrawCircle(b, radius*pixelSize); - } + int start = std::max(0, track.fixedSize() - track.fixedPointsAdded); + const TPointD *a = &track[start].position; + for(int i = start + 1; i < track.size(); ++i) { + const TPointD *b = &track[i].position; + TPointD d = *b - *a; + double k = norm2(d); + if (k > TConsts::epsilon*TConsts::epsilon) { + k = 0.5*pixelSize/sqrt(k); + d = TPointD(-k*d.y, k*d.x); + glColor4dv(colorWhite); + tglDrawSegment(*a - d, *b - d); + glColor4dv(colorBlack); + tglDrawSegment(*a + d, *b + d); + a = b; } } } glPopAttrib(); } + + // paint all tracks modifications for debug + if (debugInputManager) { + double pixelSize = sqrt(tglGetPixelSize2()); + double color[4] = { 0.0, 0.0, 0.0, 0.5 }; + int cnt = m_tracks.size(); + for(int li = 0; li < cnt; ++li) { + HSV2RGB(240 + li*120.0/(cnt-1), 1, 1, &color[0], &color[1], &color[2]); + glColor4dv(color); + for(TTrackList::const_iterator ti = m_tracks[li].begin(); ti != m_tracks[li].end(); ++ti) { + assert(*ti); + const TTrack &track = **ti; + int radius = 0; + const TPointD *a = &track[0].position; + for(int i = 0; i < track.size(); ++i) { + const TPointD *b = &track[i].position; + + if (i) { + TPointD d = *b - *a; + double k = norm2(d); + if (k > 4*pixelSize*pixelSize) { + tglDrawSegment(*a, *b); + radius = 0; + a = b; + } else { + ++radius; + } + } + + if (radius && li == 0) + tglDrawCircle(*b, radius*pixelSize*3); + } + } + } + } // paint modifiers for(int i = 0; i < (int)m_modifiers.size(); ++i) diff --git a/toonz/sources/tnztools/modifiers/modifiertangents.cpp b/toonz/sources/tnztools/modifiers/modifiertangents.cpp index 531778c..7f6c533 100644 --- a/toonz/sources/tnztools/modifiers/modifiertangents.cpp +++ b/toonz/sources/tnztools/modifiers/modifiertangents.cpp @@ -12,32 +12,31 @@ TTrackPoint TModifierTangents::Modifier::calcPoint(double originalIndex) { double frac; int i0 = original.floorIndex(originalIndex, &frac); - int i1 = original.ceilIndex(originalIndex); + int i1 = i0 + 1; TTrackPoint p; - if (i0 >= 0) { - // calculate tangent length to make monotonic subdivisions, - // (because we don't have valid input time) - const TTrackPoint &p0 = original[i0]; - const TTrackPoint &p1 = original[i1]; - TTrackTangent t0 = i0 < (int)tangents.size() ? tangents[i0] : TTrackTangent(); - TTrackTangent t1 = i1 < (int)tangents.size() ? tangents[i1] : TTrackTangent(); - double l = p1.length - p0.length; - - t0.position.x *= l; - t0.position.y *= l; - t0.pressure *= l; - t0.tilt.x *= l; - t0.tilt.y *= l; - - t1.position.x *= l; - t1.position.y *= l; - t1.pressure *= l; - t1.tilt.x *= l; - t1.tilt.y *= l; - - p = TTrack::interpolationSpline(p0, p1, t0, t1, frac); - } + + // calculate tangent length to make monotonic subdivisions, + // (because we don't have valid input time) + const TTrackPoint &p0 = original[i0]; + const TTrackPoint &p1 = original[i1]; + TTrackTangent t0 = i0 >= 0 && i0 < (int)tangents.size() ? tangents[i0] : TTrackTangent(); + TTrackTangent t1 = i1 >= 0 && i1 < (int)tangents.size() ? tangents[i1] : TTrackTangent(); + double l = p1.length - p0.length; + + t0.position.x *= l; + t0.position.y *= l; + t0.pressure *= l; + t0.tilt.x *= l; + t0.tilt.y *= l; + + t1.position.x *= l; + t1.position.y *= l; + t1.pressure *= l; + t1.tilt.x *= l; + t1.tilt.y *= l; + + p = TTrack::interpolationSpline(p0, p1, t0, t1, frac); p.originalIndex = originalIndex; return p; } @@ -50,26 +49,25 @@ TModifierTangents::Modifier::calcPoint(double originalIndex) { TTrackTangent TModifierTangents::calcTangent(const TTrack &track, int index) const { - if (track.size() < 2) return TTrackTangent(); + if (index <= 0 || index >= track.size() - 1) + return TTrackTangent(); + const TTrackPoint &p0 = track[index-1]; - const TTrackPoint &p1 = track[index]; const TTrackPoint &p2 = track[index+1]; // calculate tangent length by time // for that we need know time of actual user input // instead of time when message dispatched - //double dt = p2.time - p0.time; - //double k = dt > TConsts::epsilon ? (p1.time - p0.time)/dt : 0.0; - ////if (&p0 == &p1 || &p1 == &p2) k *= 2.0; + //double k = p2.time - p0.time; - // calculate tangent without time (based on length) + // calculate tangent based on length, util we have no valid times double k = p2.length - p0.length; - k = k > TConsts::epsilon ? 1/k : 0; + k = k > TConsts::epsilon ? 1/k : 0; return TTrackTangent( (p2.position - p0.position)*k, (p2.pressure - p0.pressure)*k, - (p2.tilt - p0.tilt)*k ); + (p2.tilt - p0.tilt )*k ); } @@ -98,25 +96,23 @@ TModifierTangents::modifyTrack( return; // update subTrack - int start = track.size() - track.pointsAdded; + int start = track.size() - track.pointsAdded - 1; if (start < 0) start = 0; subTrack.truncate(start); for(int i = start; i < track.size(); ++i) subTrack.push_back(track[i], false); // update tangents - int tangentsStart = start - 1; - if (tangentsStart < 0) tangentsStart = 0; - modifier->tangents.resize(tangentsStart); - for(int i = tangentsStart; i < subTrack.size(); ++i) - modifier->tangents.push_back(calcTangent(subTrack, i)); + modifier->tangents.resize(start); + for(int i = start; i < track.size(); ++i) + modifier->tangents.push_back(calcTangent(track, i)); // fix points if (track.fixedFinished()) { subTrack.fix_all(); } else if (track.fixedSize()) { - subTrack.fix_to(std::max(track.fixedSize() - 1, 1)); + subTrack.fix_to(std::max(track.fixedSize() - 1, 0)); } track.resetChanges(); diff --git a/toonz/sources/tnztools/toonzrasterbrushtool.cpp b/toonz/sources/tnztools/toonzrasterbrushtool.cpp index 218aea2..42d784f 100644 --- a/toonz/sources/tnztools/toonzrasterbrushtool.cpp +++ b/toonz/sources/tnztools/toonzrasterbrushtool.cpp @@ -1175,7 +1175,7 @@ bool ToonzRasterBrushTool::askWrite(const TRect &rect) { bool ToonzRasterBrushTool::preLeftButtonDown() { int smoothRadius = (int)round(m_smooth.getValue()); m_modifierAssistants->drawOnly = true; - m_inputmanager.drawPreview = true;//bwtodo: false; //! m_modifierAssistants->drawOnly; + m_inputmanager.drawPreview = !m_modifierAssistants->drawOnly; m_inputmanager.clearModifiers(); m_inputmanager.addModifier(TInputModifierP(m_modifierTangents.getPointer())); @@ -1188,7 +1188,7 @@ bool ToonzRasterBrushTool::preLeftButtonDown() { } m_inputmanager.addModifier(TInputModifierP(m_modifierAssistants.getPointer())); #ifndef NDEBUG - //m_inputmanager.addModifier(TInputModifierP(m_modifierTest.getPointer())); + m_inputmanager.addModifier(TInputModifierP(m_modifierTest.getPointer())); #endif m_inputmanager.addModifier(TInputModifierP(m_modifierSegmentation.getPointer()));