TArray<FString> UCurveBase::CreateCurveFromCSVString(const FString& InString) { // Array used to store problems about curve import TArray<FString> OutProblems; TArray<FRichCurveEditInfo> Curves = GetCurves(); const int32 NumCurves = Curves.Num(); const FCsvParser Parser(InString); const FCsvParser::FRows& Rows = Parser.GetRows(); if(Rows.Num() == 0) { OutProblems.Add(FString(TEXT("No data."))); return OutProblems; } // First clear out old data. ResetCurve(); // Each row represents a point for(int32 RowIdx=0; RowIdx<Rows.Num(); RowIdx++) { const TArray<const TCHAR*>& Cells = Rows[RowIdx]; const int32 NumCells = Cells.Num(); // Need at least two cell, Time and one Value if(NumCells < 2) { OutProblems.Add(FString::Printf(TEXT("Row '%d' has less than 2 cells."), RowIdx)); continue; } float Time = FCString::Atof(Cells[0]); for(int32 CellIdx=1; CellIdx<NumCells && CellIdx<(NumCurves+1); CellIdx++) { FRichCurve* Curve = Curves[CellIdx-1].CurveToEdit; if(Curve != NULL) { FKeyHandle KeyHandle = Curve->AddKey(Time, FCString::Atof(Cells[CellIdx])); Curve->SetKeyInterpMode(KeyHandle, RCIM_Linear); } } // If we get more cells than curves (+1 for time cell) if(NumCells > (NumCurves + 1)) { OutProblems.Add(FString::Printf(TEXT("Row '%d' has too many cells for the curve(s)."), RowIdx)); } // If we got too few cells else if(NumCells < (NumCurves + 1)) { OutProblems.Add(FString::Printf(TEXT("Row '%d' has too few cells for the curve(s)."), RowIdx)); } } Modify(true); return OutProblems; }
void UCurveBase::ResetCurve() { TArray<FRichCurveEditInfo> Curves = GetCurves(); for(int32 CurveIdx=0; CurveIdx<Curves.Num(); CurveIdx++) { if(Curves[CurveIdx].CurveToEdit != NULL) { Curves[CurveIdx].CurveToEdit->Reset(); } } }
void UCurveBase::GetValueRange(float& MinValue, float& MaxValue) const { TArray<FRichCurveEditInfoConst> Curves = GetCurves(); if(Curves.Num() > 0) { check(Curves[0].CurveToEdit); Curves[0].CurveToEdit->GetValueRange(MinValue, MaxValue); for(int32 i=1; i<Curves.Num(); i++) { float CurveMin, CurveMax; check(Curves[i].CurveToEdit != NULL); Curves[i].CurveToEdit->GetValueRange(CurveMin, CurveMax); MinValue = FMath::Min(CurveMin, MinValue); MaxValue = FMath::Max(CurveMax, MaxValue); } } }
bool HesperisIO::CheckExistingCurves(CurveGroup * geos, MObject &target) { MDagPathArray existing; MDagPath root; MDagPath::getAPathTo(target, root); if(!GetCurves(root, existing)) return false; const unsigned ne = existing.length(); if(ne != geos->numCurves()) return false; unsigned n = 0; unsigned i=0; for(;i<ne;i++) { MFnNurbsCurve fcurve(existing[i].node()); n += fcurve.numCVs(); } if(n!=geos->numPoints()) return false; MGlobal::displayInfo(" existing curves matched"); return true; }