#include "util.h"
#include "NurbsCurveHelper.h"
#include <maya/MString.h>
#include <maya/MPoint.h>
#include <maya/MPointArray.h>
#include <maya/MDoubleArray.h>
#include <maya/MFnNurbsCurve.h>
#include <maya/MFnNurbsCurveData.h>
#include <maya/MFnTransform.h>
#include <maya/MFnNumericAttribute.h>
#include <maya/MFnNumericData.h>
#include <maya/MFnDoubleArrayData.h>
#include <maya/MFnGenericAttribute.h>
#include <maya/MPlug.h>
MStatus readCurves(
double iFrame,
const Alembic::AbcGeom::ICurves & iNode,
std::size_t iExpectedCurves, std::vector<MObject> & ioCurveObjects)
{
Alembic::AbcGeom::ICurvesSchema schema = iNode.getSchema();
Alembic::AbcCoreAbstract::index_t index, ceilIndex;
double alpha = getWeightAndIndex(iFrame, schema.getTimeSampling(),
schema.getNumSamples(), index, ceilIndex);
Alembic::AbcGeom::ICurvesSchema::Sample samp, ceilSamp;
schema.get(samp, index);
unsigned int numCurves = static_cast<unsigned int>(samp.getNumCurves());
bool interp = false;
if (alpha != 0.0 && index != ceilIndex)
{
schema.get(ceilSamp, ceilIndex);
if (ceilSamp.getNumCurves() == numCurves)
{
interp = true;
}
}
Alembic::Abc::P3fArraySamplePtr sampPoints = samp.getPositions();
Alembic::Abc::P3fArraySamplePtr ceilPoints = ceilSamp.getPositions();
Alembic::Abc::FloatArraySamplePtr sampKnots = samp.getKnots();
Alembic::Abc::FloatArraySamplePtr ceilKnots = ceilSamp.getKnots();
Alembic::Abc::UcharArraySamplePtr orders = samp.getOrders();
Alembic::Abc::Int32ArraySamplePtr numVertices =
samp.getCurvesNumVertices();
Alembic::Abc::Int32ArraySamplePtr ceilNumVertices =
ceilSamp.getCurvesNumVertices();
if (interp && sampPoints->size() != ceilPoints->size())
{
interp = false;
}
std::size_t curVert = 0;
std::size_t curKnot = 0;
for (std::size_t i = 0; i < iExpectedCurves && i < numCurves; ++i)
{
unsigned int degree = 1;
if (samp.getType() == Alembic::AbcGeom::kCubic)
{
degree = 3;
}
else if (samp.getType() == Alembic::AbcGeom::kVariableOrder &&
orders->size() > i)
{
degree = (unsigned int)((*orders)[i] - 1);
}
int numVerts = (*numVertices)[i];
int j;
for (j = 0; j < numVerts; ++j, ++curVert)
{
Alembic::Abc::V3f pos = (*sampPoints)[curVert];
if (interp)
{
Alembic::Abc::V3f ceilPos = (*ceilPoints)[curVert];
cvs.
append(simpleLerp<float>(alpha, pos.x, ceilPos.x),
simpleLerp<float>(alpha, pos.y, ceilPos.y),
simpleLerp<float>(alpha, pos.z, ceilPos.z));
}
else
{
cvs.
append(pos.x, pos.y, pos.z);
}
}
if (samp.getWrap() == Alembic::AbcGeom::kPeriodic)
{
if (degree > 1 && numVerts > (int)(degree * 2))
{
for (unsigned int j = 0; j < degree; ++j)
{
if (cvs[j] != cvs[numVerts-degree+j])
{
break;
}
}
}
else
{
}
cvs[0] == cvs[numVerts-1])
{
}
}
if (!sampKnots)
{
int numKnots = numVerts + degree - 1;
for (j = 0; j < numKnots; ++j)
{
knots.
append(j/(
double)(numKnots-1));
}
{
knots[1] = knots[0];
knots[2] = knots[0];
knots[numKnots-2] = knots[numKnots-1];
knots[numKnots-3] = knots[numKnots-1];
}
}
else if (numVerts > 0)
{
int numKnots = numVerts + degree + 1;
for (j = 1; j < numKnots - 1; ++j)
{
float knot = (*sampKnots)[curKnot + j];
if (interp)
{
float ceilKnot = (*ceilKnots)[curKnot + j];
knots.
append(simpleLerp<float>(alpha, knot, ceilKnot));
}
else
{
}
}
curKnot += numKnots;
}
ioCurveObjects.push_back(curveDataObj);
curve.
create(cvs, knots, degree, form,
false,
true,
curveDataObj);
}
for (std::size_t i = numCurves; i < iExpectedCurves; ++i)
{
ioCurveObjects.push_back(curveDataObj);
}
return status;
}
MObject createCurves(
const std::string & iName,
Alembic::AbcGeom::ICurvesSchema::Sample & iSample,
Alembic::AbcGeom::IFloatGeomParam::Sample & iWidths,
MObject & iParent, std::vector< MObject > & ioCurves,
bool isAnimated)
{
std::size_t numCurves = iSample.getNumCurves();
Alembic::Abc::FloatArraySamplePtr widths = iWidths.getVals();
Alembic::Abc::Int32ArraySamplePtr curvesNumVertices =
iSample.getCurvesNumVertices();
Alembic::Abc::P3fArraySamplePtr positions = iSample.getPositions();
Alembic::Abc::FloatArraySamplePtr knotsSamp = iSample.getKnots();
Alembic::Abc::UcharArraySamplePtr ordersSamp = iSample.getOrders();
if (numCurves > 1)
{
parent = fnTrans.
create(iParent);
returnObj = parent;
if (parent.isNull())
{
MString theError(
"Failed to create curves group parent node: ");
theError += iName.c_str();
printError(theError);
return returnObj;
}
if (widths && widths->size() == 1)
{
attrObj = widthAttr.
create(
"width",
"width",
}
}
std::size_t curVert = 0;
std::size_t curKnot = 0;
for (std::size_t i = 0; i < numCurves; ++i)
{
unsigned int degree = 1;
if (iSample.getType() == Alembic::AbcGeom::kCubic)
{
degree = 3;
}
else if (iSample.getType() == Alembic::AbcGeom::kVariableOrder &&
ordersSamp->size() > i)
{
degree = (unsigned int)((*ordersSamp)[i] - 1);
}
int numVerts = (*curvesNumVertices)[i];
int j;
for (j = 0; j < numVerts; ++j, ++curVert)
{
Alembic::Abc::V3f pos = (*positions)[curVert];
cvs.
append(pos.x, pos.y, pos.z);
}
if (iSample.getWrap() == Alembic::AbcGeom::kPeriodic)
{
if (degree > 1 && numVerts > (int)(degree * 2))
{
for (unsigned int j = 0; j < degree; ++j)
{
if (cvs[j] != cvs[numVerts-degree+j])
{
break;
}
}
}
else
{
}
cvs[0] == cvs[numVerts-1])
{
}
}
if (!knotsSamp)
{
int numKnots = numVerts + degree - 1;
for (j = 0; j < numKnots; ++j)
{
knots.
append(j/(
double)(numKnots-1));
}
{
knots[1] = knots[0];
knots[2] = knots[0];
knots[numKnots-2] = knots[numKnots-1];
knots[numKnots-3] = knots[numKnots-1];
}
}
else if (numVerts > 0)
{
int numKnots = numVerts + degree + 1;
for (j = 1; j < numKnots - 1; ++j)
{
float knot = (*knotsSamp)[curKnot + j];
}
curKnot += numKnots;
}
MObject curveObj = curve.
create(cvs, knots, degree, form,
false,
true,
parent);
if (isAnimated)
{
ioCurves.push_back(curveObj);
}
if (numCurves == 1)
{
returnObj = curveObj;
}
if (numCurves == 1 && widths && widths->size() == 1 &&
iWidths.getScope() == Alembic::AbcGeom::kConstantScope)
{
}
else if (widths && widths->size() >= curVert && numVerts > 0 &&
iWidths.getScope() == Alembic::AbcGeom::kVertexScope)
{
&(*widths)[curVert-numVerts]), numVerts);
MPlug plug(curveObj, attrObj);
plug.setValue(attrObject);
}
}
return returnObj;
}