void DifferentialGeometry::ComputeDifferentials( const RayDifferential &ray) const { if (ray.hasDifferentials) { // Estimate screen space change in $\pt{}$ and $(u,v)$ // Compute auxiliary intersection points with plane float d = -Dot(nn, Vector(p.x, p.y, p.z)); Vector rxv(ray.rxOrigin.x, ray.rxOrigin.y, ray.rxOrigin.z); float tx = -(Dot(nn, rxv) + d) / Dot(nn, ray.rxDirection); if (isnan(tx)) goto fail; Point px = ray.rxOrigin + tx * ray.rxDirection; Vector ryv(ray.ryOrigin.x, ray.ryOrigin.y, ray.ryOrigin.z); float ty = -(Dot(nn, ryv) + d) / Dot(nn, ray.ryDirection); if (isnan(ty)) goto fail; Point py = ray.ryOrigin + ty * ray.ryDirection; dpdx = px - p; dpdy = py - p; // Compute $(u,v)$ offsets at auxiliary points // Initialize _A_, _Bx_, and _By_ matrices for offset computation float A[2][2], Bx[2], By[2]; int axes[2]; if (fabsf(nn.x) > fabsf(nn.y) && fabsf(nn.x) > fabsf(nn.z)) { axes[0] = 1; axes[1] = 2; } else if (fabsf(nn.y) > fabsf(nn.z)) { axes[0] = 0; axes[1] = 2; } else { axes[0] = 0; axes[1] = 1; } // Initialize matrices for chosen projection plane A[0][0] = dpdu[axes[0]]; A[0][1] = dpdv[axes[0]]; A[1][0] = dpdu[axes[1]]; A[1][1] = dpdv[axes[1]]; Bx[0] = px[axes[0]] - p[axes[0]]; Bx[1] = px[axes[1]] - p[axes[1]]; By[0] = py[axes[0]] - p[axes[0]]; By[1] = py[axes[1]] - p[axes[1]]; if (!SolveLinearSystem2x2(A, Bx, &dudx, &dvdx)) { dudx = 0.; dvdx = 0.; } if (!SolveLinearSystem2x2(A, By, &dudy, &dvdy)) { dudy = 0.; dvdy = 0.; } } else { fail: dudx = dvdx = 0.; dudy = dvdy = 0.; dpdx = dpdy = Vector(0,0,0); } }
void SMDImporter::CreateAnimationSource() { XSI::ActionSource actionSource; float animStart = 9999; float animEnd = -9999; XSI::CString animatedObjects; for (int c=0;c<m_pNodes.GetUsed();c++) { SMDNode* node = m_pNodes[c]; if ( node->m_pKeys.GetUsed() > 1 ) { if ( !actionSource.IsValid() ) { LPWSTR l_wszActionName; DSA2W(&l_wszActionName,m_szActionName); actionSource = m_pModel.AddActionSource( l_wszActionName ); } XSI::Parameter x = node->m_x3d.GetParameters().GetItem( L"posx" ); XSI::Parameter y = node->m_x3d.GetParameters().GetItem( L"posy" ); XSI::Parameter z = node->m_x3d.GetParameters().GetItem( L"posz" ); XSI::Parameter rx = node->m_x3d.GetParameters().GetItem( L"rotx" ); XSI::Parameter ry = node->m_x3d.GetParameters().GetItem( L"roty" ); XSI::Parameter rz = node->m_x3d.GetParameters().GetItem( L"rotz" ); node->m_fOldX = x.GetValue(); node->m_fOldY = y.GetValue(); node->m_fOldZ = z.GetValue(); node->m_fOldRX = rx.GetValue(); node->m_fOldRY = ry.GetValue(); node->m_fOldRZ = rz.GetValue(); XSI::FCurve fcrvx; x.AddFCurve( XSI::siStandardFCurve, fcrvx ); XSI::FCurve fcrvy; y.AddFCurve( XSI::siStandardFCurve, fcrvy ); XSI::FCurve fcrvz; z.AddFCurve( XSI::siStandardFCurve, fcrvz ); XSI::FCurve fcrvrx; rx.AddFCurve( XSI::siStandardFCurve, fcrvrx ); XSI::FCurve fcrvry; ry.AddFCurve( XSI::siStandardFCurve, fcrvry ); XSI::FCurve fcrvrz; rz.AddFCurve( XSI::siStandardFCurve, fcrvrz ); XSI::CTimeArray time(node->m_pKeys.GetUsed()); XSI::CValueArray xv(node->m_pKeys.GetUsed()); XSI::CValueArray yv(node->m_pKeys.GetUsed()); XSI::CValueArray zv(node->m_pKeys.GetUsed()); XSI::CValueArray rxv(node->m_pKeys.GetUsed()); XSI::CValueArray ryv(node->m_pKeys.GetUsed()); XSI::CValueArray rzv(node->m_pKeys.GetUsed()); if ( node->m_pParent ==NULL ) { for (int k=0;k<node->m_pKeys.GetUsed();k++) { if ( node->GetKey(k)->m_fTime < animStart ) { animStart = node->GetKey(k)->m_fTime; } if ( node->GetKey(k)->m_fTime > animEnd ) { animEnd = node->GetKey(k)->m_fTime; } XSI::MATH::CTransformation xfo1; XSI::MATH::CTransformation xfo2; xfo1.SetRotationFromXYZAnglesValues ( node->GetKey(k)->m_vRotation.GetX(), node->GetKey(k)->m_vRotation.GetY(), node->GetKey(k)->m_vRotation.GetZ() ); xfo1.SetTranslationFromValues ( node->GetKey(k)->m_vPosition.GetX(), node->GetKey(k)->m_vPosition.GetY(), node->GetKey(k)->m_vPosition.GetZ() ); xfo2.SetRotationFromXYZAnglesValues ( -1.570796, 0.0, 0.0 ); xfo1.MulInPlace(xfo2); double dx,dy,dz; double drx, dry, drz; xfo1.GetTranslationValues ( dx, dy, dz); xfo1.GetRotationFromXYZAnglesValues(drx, dry, drz); time[k] = k; xv[k] = dx; yv[k] = dy; zv[k] = dz; rxv[k] = drx * 57.29577951308232286465; ryv[k] = dry * 57.29577951308232286465; rzv[k] = drz * 57.29577951308232286465; } } else { for (int k=0;k<node->m_pKeys.GetUsed();k++) { if ( node->GetKey(k)->m_fTime < animStart ) { animStart = node->GetKey(k)->m_fTime; } if ( node->GetKey(k)->m_fTime > animEnd ) { animEnd = node->GetKey(k)->m_fTime; } time[k] = k; xv[k] = node->GetKey(k)->m_vPosition.GetX(); yv[k] = node->GetKey(k)->m_vPosition.GetY(); zv[k] = node->GetKey(k)->m_vPosition.GetZ(); rxv[k] = node->GetKey(k)->m_vRotation.GetX() * 57.29577951308232286465; ryv[k] = node->GetKey(k)->m_vRotation.GetY() * 57.29577951308232286465; rzv[k] = node->GetKey(k)->m_vRotation.GetZ() * 57.29577951308232286465; } } fcrvx.SetKeys ( time, xv ); fcrvy.SetKeys ( time, yv ); fcrvz.SetKeys ( time, zv ); fcrvrx.SetKeys ( time, rxv ); fcrvry.SetKeys ( time, ryv ); fcrvrz.SetKeys ( time, rzv ); LPWSTR l_wszModelName; DSA2W(&l_wszModelName,FixName(node->m_szName)); XSI::CString cname = l_wszModelName; actionSource.AddSourceItem ( cname + L".kine.local.posx", fcrvx, true ); actionSource.AddSourceItem ( cname + L".kine.local.posy", fcrvy, true ); actionSource.AddSourceItem ( cname + L".kine.local.posz", fcrvz, true ); actionSource.AddSourceItem ( cname + L".kine.local.rotx", fcrvrx, true ); actionSource.AddSourceItem ( cname + L".kine.local.roty", fcrvry, true ); actionSource.AddSourceItem ( cname + L".kine.local.rotz", fcrvrz, true ); // build up the string list of objects that we want to remove animation from if (animatedObjects.IsEmpty() == false) { animatedObjects += L", "; } animatedObjects += node->m_x3d.GetFullName(); } } if ( actionSource.IsValid() ) { actionSource.PutParameterValue(L"FrameStart", (double)animStart); actionSource.PutParameterValue(L"FrameEnd", (double)animEnd); } // remove animation on all objects that were imported // and animated if (animatedObjects.IsEmpty() == false) { XSI::Application app; XSI::CValue out; XSI::CValueArray args(4); args[0] = animatedObjects; args[1] = XSI::CValue(); args[2] = (long)XSI::siBranch; args[3] = (long)(XSI::siFCurveSource); app.ExecuteCommand(L"RemoveAllAnimation", args, out); } }