Skip to content

Commit edbde59

Browse files
o2b3dpixar-oss
authored andcommitted
Remove Maya style tangents from time splines and add tangent
conversion functions. Remove Maya style tangent values from the time spline (and related) code. Tangents are now only stored in "standard" format which is a typed slope and a TsTime (aka doule) width. Maya style tangent values which have a height instead of width, stored values scaled by 3, and which invert the height of the pre-tangent are no longer used internally. To continue to support Maya we have added TsConvertToStandardTangent and TsConvertFromStandardTangent. These functions take standard slope and width values and perform optional conversions on them that can convert between slope and height values, scale by 3, and/or negate the slope or height value. Note that Hermite curves do not have an explicit tangent width value. Instead, the value used is 1/3 the width of the segment to which they belong. The conversion functions, however, require a width in order to convert between slope and height values. It is up to the caller to provide a width value to the conversion routines, even when working with Hermite curves. (Internal change: 2343223) (Internal change: 2343286)
1 parent 4033978 commit edbde59

25 files changed

Lines changed: 949 additions & 768 deletions

pxr/base/ts/CMakeLists.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ set(classes
2222
regressionPreventer
2323
spline
2424
splineData
25+
tangentConversions
2526
typeHelpers
2627
types
2728
)
@@ -42,6 +43,7 @@ set(pycpp
4243
wrapRaii.cpp
4344
wrapRegressionPreventer.cpp
4445
wrapSpline.cpp
46+
wrapTangentConversions.cpp
4547
wrapTypes.cpp
4648
)
4749

@@ -165,6 +167,16 @@ pxr_build_test(
165167
tf
166168
)
167169

170+
pxr_build_test(
171+
testTsTangentConversion
172+
CPPFILES
173+
testenv/testTsTangentConversion.cpp
174+
LIBRARIES
175+
ts
176+
vt
177+
tf
178+
)
179+
168180
pxr_test_scripts(
169181
testenv/testTsDerivatives.py
170182
testenv/testTsRegressionPreventer.py
@@ -204,6 +216,11 @@ pxr_register_test(
204216
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testTsSplineAPI"
205217
)
206218

219+
pxr_register_test(
220+
testTsTangentConversion
221+
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testTsTangentConversion"
222+
)
223+
207224
pxr_register_test(
208225
tsTest_TsFramework
209226
PYTHON

pxr/base/ts/binary.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,9 @@ namespace
9595
// Bit 0: whether dual-valued.
9696
// Bits 1-2: next segment interpolation mode.
9797
// Bit 3: curve type.
98-
// Bit 4: whether pre-tangent is in Maya form.
99-
// Bit 5: whether post-tangent is in Maya form.
10098
uint8_t flagByte = knot.dualValued;
10199
flagByte |= static_cast<uint8_t>(knot.nextInterp) << 1;
102100
flagByte |= static_cast<uint8_t>(knot.curveType) << 3;
103-
flagByte |= knot.preTanMayaForm << 4;
104-
flagByte |= knot.postTanMayaForm << 5;
105101
_WriteBytes<uint8_t>(buf, flagByte);
106102

107103
// Knot time and value.
@@ -121,8 +117,7 @@ namespace
121117
_WriteBytes<double>(buf, knot.postTanWidth);
122118
}
123119

124-
// Tangent slopes or heights.
125-
// Interpretation will be governed by the Maya-form flags.
120+
// Tangent slopes.
126121
_WriteBytes<T>(buf, knot.preTanSlope);
127122
_WriteBytes<T>(buf, knot.postTanSlope);
128123
}
@@ -273,8 +268,6 @@ namespace
273268
static_cast<TsInterpMode>((flagByte & 0x06) >> 1);
274269
knot.curveType =
275270
static_cast<TsCurveType>((flagByte & 0x08) >> 3);
276-
knot.preTanMayaForm = flagByte & 0x10;
277-
knot.postTanMayaForm = flagByte & 0x20;
278271

279272
// Knot time and value.
280273
READ(&knot.time);
@@ -293,8 +286,7 @@ namespace
293286
READ(&knot.postTanWidth);
294287
}
295288

296-
// Tangent slopes or heights.
297-
// Interpretation will be governed by the Maya-form flags.
289+
// Tangent slopes
298290
READ(&knot.preTanSlope);
299291
READ(&knot.postTanSlope);
300292

pxr/base/ts/eval.cpp

Lines changed: 4 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -307,50 +307,6 @@ _EvalHermite(
307307
////////////////////////////////////////////////////////////////////////////////
308308
// EVAL HELPERS
309309

310-
// Find the slope at a knot, facing into a curved segment.
311-
//
312-
// Accounts for Maya vs. standard tangent forms, and forced tangent widths for
313-
// Hermite curves.
314-
//
315-
static double
316-
_GetCurveKnotSlope(
317-
const Ts_TypedKnotData<double> &knotData,
318-
const TsTime adjacentTime,
319-
const TsCurveType curveType,
320-
const Ts_EvalLocation location)
321-
{
322-
if (location == Ts_EvalPre)
323-
{
324-
if (!knotData.preTanMayaForm)
325-
{
326-
return knotData.preTanSlope;
327-
}
328-
else if (curveType == TsCurveTypeHermite)
329-
{
330-
return -knotData.preTanMayaHeight / (knotData.time - adjacentTime);
331-
}
332-
else
333-
{
334-
return -knotData.preTanMayaHeight / knotData.preTanWidth;
335-
}
336-
}
337-
else
338-
{
339-
if (!knotData.postTanMayaForm)
340-
{
341-
return knotData.postTanSlope;
342-
}
343-
else if (curveType == TsCurveTypeHermite)
344-
{
345-
return knotData.postTanMayaHeight / (adjacentTime - knotData.time);
346-
}
347-
else
348-
{
349-
return knotData.postTanMayaHeight / knotData.postTanWidth;
350-
}
351-
}
352-
}
353-
354310
// Find the slope from one knot to another in a linear segment. Such slopes are
355311
// implicit: based on times and values, not tangents.
356312
//
@@ -424,8 +380,7 @@ _GetExtrapolationSlope(
424380

425381
// Otherwise the first segment is curved. The slope is continued from
426382
// the inward-facing side of the first knot.
427-
return _GetCurveKnotSlope(
428-
endKnotData, adjacentData.time, curveType, Ts_EvalPost);
383+
return endKnotData.postTanSlope;
429384
}
430385
else
431386
{
@@ -444,8 +399,7 @@ _GetExtrapolationSlope(
444399

445400
// Otherwise the last segment is curved. The slope is continued from
446401
// the inward-facing side of the last knot.
447-
return _GetCurveKnotSlope(
448-
endKnotData, adjacentData.time, curveType, Ts_EvalPre);
402+
return endKnotData.preTanSlope;
449403
}
450404
}
451405

@@ -1248,8 +1202,7 @@ _EvalMain(
12481202
}
12491203

12501204
// Not a special case. Return what's stored in the knot.
1251-
return _GetCurveKnotSlope(
1252-
knotData, prevData.time, data->curveType, Ts_EvalPre);
1205+
return knotData.preTanSlope;
12531206
}
12541207
else
12551208
{
@@ -1275,8 +1228,7 @@ _EvalMain(
12751228
}
12761229

12771230
// Not a special case. Return what's stored in the knot.
1278-
return _GetCurveKnotSlope(
1279-
knotData, nextData.time, data->curveType, Ts_EvalPost);
1231+
return knotData.postTanSlope;
12801232
}
12811233
}
12821234
}

0 commit comments

Comments
 (0)