void getXformTimeSpan(IXform iXf, chrono_t& first, chrono_t& last, bool inherits) { IXformSchema xf = iXf.getSchema(); TimeSamplingPtr ts = xf.getTimeSampling(); first = std::min(first, ts->getSampleTime(0) ); if (xf.isConstant()) { last = first; } else { last = std::max(last, ts->getSampleTime(xf.getNumSamples()-1) ); } if (inherits && xf.getInheritsXforms()) { IObject parent = iXf.getParent(); // Once the Archive's Top Object is reached, IObject::getParent() will // return an invalid IObject, and that will evaluate to False. while ( parent ) { if ( Alembic::AbcGeom::IXform::matches(parent.getHeader()) ) { IXform x( parent, kWrapExisting ); getXformTimeSpan(x, first, last, inherits); } } } }
//-***************************************************************************** void ProcessXform( IXform &xform, ProcArgs &args ) { IXformSchema &xs = xform.getSchema(); TimeSamplingPtr ts = xs.getTimeSampling(); size_t xformSamps = xs.getNumSamples(); SampleTimeSet sampleTimes; GetRelevantSampleTimes( args, ts, xformSamps, sampleTimes ); bool multiSample = sampleTimes.size() > 1; std::vector<XformSample> sampleVectors; sampleVectors.resize( sampleTimes.size() ); //fetch all operators at each sample time first size_t sampleTimeIndex = 0; for ( SampleTimeSet::iterator I = sampleTimes.begin(); I != sampleTimes.end(); ++I, ++sampleTimeIndex ) { ISampleSelector sampleSelector( *I ); xs.get( sampleVectors[sampleTimeIndex], sampleSelector ); } if (xs.getInheritsXforms () == false) { RiIdentity (); } //loop through the operators individually since a MotionBegin block //can enclose only homogenous statements for ( size_t i = 0, e = xs.getNumOps(); i < e; ++i ) { if ( multiSample ) { WriteMotionBegin(args, sampleTimes); } for ( size_t j = 0; j < sampleVectors.size(); ++j ) { XformOp &op = sampleVectors[j][i]; switch ( op.getType() ) { case kScaleOperation: { V3d value = op.getScale(); RiScale( value.x, value.y, value.z ); break; } case kTranslateOperation: { V3d value = op.getTranslate(); RiTranslate( value.x, value.y, value.z ); break; } case kRotateOperation: case kRotateXOperation: case kRotateYOperation: case kRotateZOperation: { V3d axis = op.getAxis(); float degrees = op.getAngle(); RiRotate( degrees, axis.x, axis.y, axis.z ); break; } case kMatrixOperation: { WriteConcatTransform( op.getMatrix() ); break; } } } if ( multiSample ) { RiMotionEnd(); } } }