Beispiel #1
0
void GR2ImportImpl::ImportPosition(Control* c, TransformTrack& track, float time, GR2Array<granny_real32>& defaultKeys)
{
	// Better use linear for now
	if (Control *subCtrl = MakePositionXYZ(c, Class_ID(HYBRIDINTERP_FLOAT_CLASS_ID,0))) 
	{
		IKeyControl *xkeys = GetKeyControlInterface(subCtrl->GetXController());
		IKeyControl *ykeys = GetKeyControlInterface(subCtrl->GetYController());
		IKeyControl *zkeys = GetKeyControlInterface(subCtrl->GetZController());
		if (xkeys && ykeys && zkeys) 
		{
			if (Point3CurveData* posData = dynamic_cast<Point3CurveData*>(track.PositionCurve.ToPointer()))
			{
				NWArray<float> times = posData->GetKnots();
				NWArray<Point3> points = posData->GetPoint3Data();
				if (times.size() == 0 && points.size() != 0)
					times = defaultKeys;

				xkeys->SetNumKeys(times.size());
				ykeys->SetNumKeys(times.size());
				zkeys->SetNumKeys(times.size());
				for (int i=0; i<times.size(); ++i)
				{
					IBezFloatKey rKey;
					memset(&rKey, 0, sizeof(rKey));
					rKey.time = TimeToFrame(times[i] + time);
					SetInTanType(rKey.flags, BEZKEY_SLOW);
					SetOutTanType(rKey.flags, BEZKEY_SLOW);
					rKey.val = points[i].x;
					xkeys->SetKey(i, &rKey);
					rKey.val = points[i].y;
					ykeys->SetKey(i, &rKey);
					rKey.val = points[i].z;
					zkeys->SetKey(i, &rKey);
				}
				xkeys->SortKeys();
				ykeys->SortKeys();
				zkeys->SortKeys();
			}
		}
	}
}
Beispiel #2
0
// ADJUSTROTKEYS
void AdjustRotKeys(INode *node)
{
    Control *controller = node->GetTMController();
    Control *rotControl = controller->GetRotationController();
    IKeyControl *rotKeyCont = GetKeyControlInterface(rotControl);
    int numKeys = rotKeyCont->GetNumKeys();

    for(int i = 0; i < numKeys; i++)
    {
        ITCBKey key;
        rotKeyCont->GetKey(i, &key);

        key.cont = 0;
        rotKeyCont->SetKey(i, &key);

    }
    
}
Beispiel #3
0
void GR2ImportImpl::ImportRotation(Control* c, TransformTrack& track, float time, GR2Array<granny_real32>& defaultKeys)
{
	if (RotationCurveData* rotData = dynamic_cast<RotationCurveData*>(track.OrientationCurve.ToPointer()))
	{
		if (rotData->GetKeyType() == QUADRATIC_KEY)
		{
			if (Control *subCtrl = MakeRotation(c, Class_ID(HYBRIDINTERP_ROTATION_CLASS_ID,0), Class_ID(HYBRIDINTERP_FLOAT_CLASS_ID,0))) 
			{
				IKeyControl *keys = GetKeyControlInterface(subCtrl);
				if (keys) 
				{
					NWArray<float> times = rotData->GetKnots();
					NWArray<Quat> points = rotData->GetQuatData();
					if (times.size() == 0 && points.size() != 0)
						times = defaultKeys;

					keys->SetNumKeys(times.size());
					for (int i=0; i<times.size(); ++i)
					{
						Quat q = points[i];
						q.w = -q.w;
						IBezQuatKey rKey;
						memset(&rKey, 0, sizeof(rKey));
						rKey.time = TimeToFrame(times[i] + time);
						SetInTanType(rKey.flags, BEZKEY_SLOW);
						SetOutTanType(rKey.flags, BEZKEY_SLOW);
						rKey.val = q;
						keys->SetKey(i, &rKey);
					}
					keys->SortKeys();
				}
			}
		}
		else if (rotData->GetKeyType() == XYZ_ROTATION_KEY)
		{
			if (Control *subCtrl = MakeRotation(c, Class_ID(EULER_CONTROL_CLASS_ID,0), Class_ID(HYBRIDINTERP_FLOAT_CLASS_ID,0)))
			{
				IKeyControl *xkeys = GetKeyControlInterface(subCtrl->GetXController());
				IKeyControl *ykeys = GetKeyControlInterface(subCtrl->GetYController());
				IKeyControl *zkeys = GetKeyControlInterface(subCtrl->GetZController());
				if (xkeys && ykeys && zkeys) 
				{
					NWArray<float> times = rotData->GetKnots();
					NWArray<Point3> points = rotData->GetPoint3Data();
					if (times.size() == 0 && points.size() != 0)
						times = defaultKeys;
					
					xkeys->SetNumKeys(times.size());
					ykeys->SetNumKeys(times.size());
					zkeys->SetNumKeys(times.size());
					for (int i=0; i<times.size(); ++i)
					{
						Point3 &p = points[i];
						//Quat q; Point3 p;
						//EulerToQuat(points[i], q);
						//q = invQ * q;
						//QuatToEuler(q, p);

						IBezFloatKey rKey;
						memset(&rKey, 0, sizeof(rKey));
						rKey.time = TimeToFrame(times[i] + time);
						SetInTanType(rKey.flags, BEZKEY_SLOW);
						SetOutTanType(rKey.flags, BEZKEY_SLOW);
						rKey.val = p.x;
						xkeys->SetKey(i, &rKey);
						rKey.val = p.y;
						ykeys->SetKey(i, &rKey);
						rKey.val = p.z;
						zkeys->SetKey(i, &rKey);
					}
					xkeys->SortKeys();
					ykeys->SortKeys();
					zkeys->SortKeys();
				}
			}
		}
	}
}
Beispiel #4
0
void RandKeysUtil::Apply()
	{
	BOOL timeMode   = iu->GetMajorMode()==TVMODE_EDITTIME;
	BOOL fcurveMode = iu->GetMajorMode()==TVMODE_EDITFCURVE;
	Interval iv = iu->GetTimeSelection();
	if (!doTime && !doVal) return;

	theHold.Begin();

	// Turn animation on
	SuspendAnimate();
	AnimateOn();

	for (int i=0; i<iu->GetNumTracks(); i++) {
		if ((timeMode||fcurveMode) && !iu->IsSelected(i)) continue;
		
		// Get Interfaces
		Animatable *anim   = iu->GetAnim(i);
		Animatable *client = iu->GetClient(i);
		int subNum         = iu->GetSubNum(i);
		Control *cont      = GetControlInterface(anim);
		IKeyControl *ikc   = GetKeyControlInterface(anim);
		IKey *key          = GetKeyPointer(anim->SuperClassID(),anim->ClassID());				
		if (!ikc || !cont || !key) continue;						
		if (fcurveMode && !anim->IsCurveSelected()) continue;

		// Get the param dim
		float min = negVal, max = posVal;
		ParamDimension *dim = client->GetParamDimension(subNum);
		if (dim) {
			min = dim->UnConvert(min);
			max = dim->UnConvert(max);
			}

		for (int j=0; j<ikc->GetNumKeys(); j++) {
			// Get the key data
			ikc->GetKey(j,key);
			
			// Check if it's selected
			if (timeMode && !iv.InInterval(key->time)) continue;
			if (!timeMode && !(key->flags&IKEY_SELECTED)) continue;			

			// Randomize time
			if (doTime) {
				key->time = (int)CompRand(
					float(key->time-negTime),
					float(key->time+posTime));
				ikc->SetKey(j,key);
				}
			}

		if (doTime) ikc->SortKeys();

		for (j=0; j<ikc->GetNumKeys(); j++) {
			// Get the key data
			ikc->GetKey(j,key);
			
			// Check if it's selected
			if (timeMode && !iv.InInterval(key->time)) continue;
			if (!timeMode && !(key->flags&IKEY_SELECTED)) continue;			

			// Randomize value
			if (doVal) {
				Point3 pt, ang;
				Point4 p4;
				float f;
				Quat q;
				ScaleValue s;				
				BOOL doX, doY, doZ, doW;
				doX = doY = doZ = doW = TRUE;
				if (!fcurveMode) {
					if (!(key->flags&IKEY_XSEL)) doX = FALSE;
					if (!(key->flags&IKEY_YSEL)) doY = FALSE;
					if (!(key->flags&IKEY_ZSEL)) doZ = FALSE;
					if (!(key->flags&IKEY_WSEL)) doW = FALSE;
					}

				switch (anim->SuperClassID()) {
					case CTRL_FLOAT_CLASS_ID:			
						cont->GetValue(key->time,&f,FOREVER);
						f = CompRand(f-min,f+max);
						cont->SetValue(key->time,&f);
						break;

					case CTRL_POSITION_CLASS_ID:
					case CTRL_POINT3_CLASS_ID:
						cont->GetValue(key->time,&pt,FOREVER);
						if (doX) pt.x = CompRand(pt.x-min,pt.x+max);
						if (doY) pt.y = CompRand(pt.y-min,pt.y+max);
						if (doZ) pt.z = CompRand(pt.z-min,pt.z+max);
						cont->SetValue(key->time,&pt);
						break;
					
					case CTRL_POINT4_CLASS_ID:
						cont->GetValue(key->time,&p4,FOREVER);
						if (doX) p4.x = CompRand(p4.x-min,p4.x+max);
						if (doY) p4.y = CompRand(p4.y-min,p4.y+max);
						if (doZ) p4.z = CompRand(p4.z-min,p4.z+max);
						if (doW) p4.w = CompRand(p4.w-min,p4.w+max);
						cont->SetValue(key->time,&p4);
						break;

					case CTRL_ROTATION_CLASS_ID:
						cont->GetValue(key->time,&q,FOREVER);
						QuatToEuler(q, ang);
						ang.x = CompRand(ang.x-min,ang.x+max);
						ang.y = CompRand(ang.y-min,ang.y+max);
						ang.z = CompRand(ang.z-min,ang.z+max);
						EulerToQuat(ang,q);
						cont->SetValue(key->time,&q);
						break;

					case CTRL_SCALE_CLASS_ID:
						cont->GetValue(key->time,&s,FOREVER);
						if (doX) s.s.x = CompRand(s.s.x-min,s.s.x+max);
						if (doY) s.s.y = CompRand(s.s.y-min,s.s.y+max);
						if (doZ) s.s.z = CompRand(s.s.z-min,s.s.z+max);
						cont->SetValue(key->time,&s);
						break;
					}
				}
			}

		
		}

	ResumeAnimate();

	theHold.Accept(GetString(IDS_RB_RANDOMIZEKEYS));
	ip->RedrawViews(ip->GetTime());
	}