void	SplineData::RotateSelectedCrossSections(Quat q)
{
	Tab<int> selSplines;
	Tab<int> selCrossSections;
	GetSelectedCrossSections(selSplines,selCrossSections);

	//move the cross sections
	for (int i = 0; i < selSplines.Count(); i++)
	{
		int splineIndex = selSplines[i];
		int crossSectionIndex = selCrossSections[i];
		SplineCrossSection *section = GetCrossSection(splineIndex,crossSectionIndex);

		Matrix3 sTM = section->mTM;
		sTM.NoScale();
		sTM.NoTrans();

		Quat tq = TransformQuat(sTM,q);
		//no back into our initial space
		tq = TransformQuat(section->mIBaseTM,tq);

		section->mQuat += tq;


	}

	RecomputeCrossSections();	
}
void     makBoneTrans2(INode* pNode , sBoneTrans_t& boneTrans , Matrix3& mat)
{
	Point3   Trans = mat.GetTrans();
	Matrix3  RotMat = mat;
	Matrix3  ScaleMat = mat;

    RotMat.NoScale();
    ScaleMat = mat * Inverse(RotMat);
    //算出Scale Matrix;

	RotMat.NoTrans();	
	Quat RotQuat(RotMat);

	//ScaleMat.NoRot();
	//ScaleMat.NoTrans();

	boneTrans.m_Rotate    = conv_type<sQuat_t , Quat>(RotQuat);
	boneTrans.m_Trans     = conv_type<sVector_t   ,Point3 >(Trans);
	boneTrans.m_Scale.x   = ScaleMat.GetRow(0).x;
	boneTrans.m_Scale.y   = ScaleMat.GetRow(1).y;
	boneTrans.m_Scale.z   = ScaleMat.GetRow(2).z;
	if( abs(boneTrans.m_Scale.x - boneTrans.m_Scale.y) > 0.000001 ||
		abs(boneTrans.m_Scale.y - boneTrans.m_Scale.z) > 0.000001 ||
		abs(boneTrans.m_Scale.z - boneTrans.m_Scale.x) > 0.000001 )
	{
            std::wstring _NodeName = INodeName(pNode);
            XEVOL_LOG(eXL_DEBUG_HIGH , L"   {警告} :  骨头[ %s ] 的上有NonUniformScale\r\n", _NodeName.c_str() );
	}
}
Exemple #3
0
Matrix3 MshExp::TransformNode(INode* pNode,TimeValue CurTime, int TransformType){
	Matrix3 mat;

	switch((TransformType&0xff))
	{
		case TN_AFTER_WORLD://After World
			mat = pNode->GetObjTMAfterWSM(CurTime);
			break;
		case TN_BEFORE_WORLD://Before World
			mat = pNode->GetObjTMBeforeWSM(CurTime);
			break;
		case TN_TRANSFORM:
			mat = pNode->GetNodeTM(CurTime);
			break;
		default:
			mat = Matrix3(1);
			break;
	}

	if(TransformType&TN_NO_TRANSLATION)
		mat.NoTrans();
	if(TransformType&TN_NO_ROTATION)
		mat.NoRot();
	if(TransformType&TN_NO_SCALE)
		mat.NoScale();

	return mat;
}
Exemple #4
0
std::string LuxMaxUtils::getMaxNodeTransform(INode* node)
{
	LuxMaxUtils *lmutil;
	std::string tmpTrans = "";
	Matrix3 nodeTransformPos = node->GetObjTMAfterWSM(GetCOREInterface()->GetTime());
	Matrix3 nodeTransformRot = nodeTransformPos;
	Matrix3 nodeTransformScale = nodeTransformPos;

	nodeTransformRot.NoTrans();
	nodeTransformScale.NoTrans();
	nodeTransformScale.NoRot();

	nodeTransformRot = nodeTransformRot * nodeTransformScale;

	tmpTrans.append(floatToString(nodeTransformRot.GetColumn(0).x));
	tmpTrans.append(" ");
	tmpTrans.append(floatToString(nodeTransformRot.GetColumn(1).x));
	tmpTrans.append(" ");
	tmpTrans.append(floatToString(nodeTransformRot.GetColumn(2).x));
	tmpTrans.append(" ");
	tmpTrans.append("0 ");

	tmpTrans.append(floatToString(nodeTransformRot.GetColumn(0).y));
	tmpTrans.append(" ");
	tmpTrans.append(floatToString(nodeTransformRot.GetColumn(1).y));
	tmpTrans.append(" ");
	tmpTrans.append(floatToString(nodeTransformRot.GetColumn(2).y));
	tmpTrans.append(" ");
	tmpTrans.append("0 ");

	tmpTrans.append(floatToString(nodeTransformRot.GetColumn(0).z));
	tmpTrans.append(" ");
	tmpTrans.append(floatToString(nodeTransformRot.GetColumn(1).z));
	tmpTrans.append(" ");
	tmpTrans.append(floatToString(nodeTransformRot.GetColumn(2).z));
	tmpTrans.append(" ");
	tmpTrans.append("0 ");

	tmpTrans.append(floatToString(nodeTransformPos.GetTrans().x));
	tmpTrans.append(" ");
	tmpTrans.append(floatToString(nodeTransformPos.GetTrans().y));
	tmpTrans.append(" ");
	tmpTrans.append(floatToString(nodeTransformPos.GetTrans().z));
	tmpTrans.append(" 1.0");

	return tmpTrans;
}
void SplineData::AlignCrossSection(int splineIndex, int crossSectionIndex,Point3 vec)
{
	if ((splineIndex >= 0) && (splineIndex < mSplineElementData.Count()))
	{
		int numCrossSections = NumberOfCrossSections(splineIndex);

		if ((crossSectionIndex >= 0) && (crossSectionIndex < numCrossSections))
		{

			//put the vec in spline space
			SplineCrossSection *crossSection = GetCrossSection(splineIndex,crossSectionIndex);


			Matrix3 crossSectionTM = crossSection->mTM;
			crossSectionTM.NoScale();
			crossSectionTM.NoTrans();
			Matrix3 icrossSectionTM = Inverse(crossSectionTM);


			Point3 crossSectionZVec = crossSection->mTangentNormalized;


			Point3 yvec = Normalize(vec);

			Point3 xvec = Normalize(CrossProd(yvec,crossSectionZVec));
			Point3 zvec = Normalize(CrossProd(xvec,yvec));

			Matrix3 rtm(1);
			rtm.SetRow(0,xvec);
			rtm.SetRow(1,yvec);
			rtm.SetRow(2,zvec);
			rtm.SetRow(3,Point3(0.0f,0.0f,0.0f));

			Matrix3 relativeTM =  crossSection->mIBaseTM * rtm;

			Quat q(relativeTM);


			q = TransformQuat(crossSection->mIBaseTM,q);

			crossSection->mQuat = q;

			return;
		}
	}
	DbgAssert(0);


}
Exemple #6
0
int TapeHelpObject::Display(TimeValue t, INode* inode, ViewExp *vpt, int flags)
{
    if ( ! vpt || ! vpt->IsAlive() )
    {
        // why are we here
        DbgAssert(!_T("Invalid viewport!"));
        return FALSE;
    }


    Matrix3 m;
    GraphicsWindow *gw = vpt->getGW();
    Material *mtl = gw->getMaterial();

    GetMat(t,inode,*vpt,m);
    gw->setTransform(m);
    DWORD rlim = gw->getRndLimits();
    gw->setRndLimits(GW_WIREFRAME|GW_EDGES_ONLY|GW_BACKCULL| (rlim&GW_Z_BUFFER) );
    if (inode->Selected())
        gw->setColor( LINE_COLOR, GetSelColor());
    else if(!inode->IsFrozen() && !inode->Dependent())
        gw->setColor( LINE_COLOR, GetUIColor(COLOR_TAPE_OBJ));
    mesh.render( gw, mtl, NULL, COMP_ALL);
    DrawLine(t,inode,gw,1);
    gw->setRndLimits(rlim);
    if(editting && !specLenState) {
        Point3 pt(0,0,0);
        Matrix3 tm = inode->GetObjectTM(t);
        GetTargetPoint(t,inode,pt);
        float den = Length(tm.GetRow(2));
        float dist = (den!=0)?Length(tm.GetTrans()-pt)/den : 0.0f;
        lengthSpin->SetValue( lastDist = dist, FALSE );
    }
    if(editting) {
        m.NoTrans();
        dirPt = m * Point3(0,0,1);
        float len = Length(dirPt);
        if(len != 0)
            dirPt *= 1.0f/len;
        UpdateUI(iObjParams->GetTime());
    }
    return(0);
}
Matrix3 CActionExporter::get_bone_tm(CSkeletonExporter* pSkeleton,int boneIndex,unsigned int iMaxTime)
{
         sMaxBoneNode_t bone = pSkeleton->m_MaxBones[boneIndex];
         Matrix3        boneInitMTInv;
         if(G_MaxEnv().m_bUseBeforeSkeletonPose)
             boneInitMTInv = bone.m_SkinInitMT;
         else
             boneInitMTInv = bone.m_InitNodeTM0;

         boneInitMTInv.Invert();
         INode* pNode = bone.m_pNode;

         Matrix3 BoneTM = boneInitMTInv * pNode->GetNodeTM(iMaxTime); //>GetNodeTM(iMaxTime);
         Point3 Trans = BoneTM.GetTrans();
         BoneTM.NoTrans();
         //对骨骼进行缩放
         Trans.x *= pSkeleton->m_fScale;
         Trans.y *= pSkeleton->m_fScale;
         Trans.z *= pSkeleton->m_fScale;
         BoneTM.SetTrans(Trans);

         return BoneTM;

}
Exemple #8
0
void Exporter::ExportMesh(INode* node, TimeValue t, int indentLevel)
{
	int i;
	Mtl* nodeMtl = node->GetMtl();
	Matrix3 tm = node->GetObjTMAfterWSM(t);
	BOOL negScale = TMNegParity(tm);
	int vx1, vx2, vx3;
	TSTR indent;
	
	ObjectState os = node->EvalWorldState(t);
	if (!os.obj || os.obj->SuperClassID()!=GEOMOBJECT_CLASS_ID) {
		return; // Safety net. This shouldn't happen.
	}
	
	// Order of the vertices. Get 'em counter clockwise if the objects is
	// negatively scaled.
	if (negScale) {
		vx1 = 2;
		vx2 = 1;
		vx3 = 0;
	}
	else {
		vx1 = 0;
		vx2 = 1;
		vx3 = 2;
	}
	
	BOOL needDel;
	TriObject* tri = GetTriObjectFromNode(node, t, needDel);
	if (!tri) {
		return;
	}
	
	Mesh* mesh = &tri->mesh;
	
	mesh->buildNormals();
	
	{	// make vertices and faces
		rsm->mesh->nV=mesh->getNumVerts();
		rsm->mesh->nF=mesh->getNumFaces();
		rsm->mesh->ver=new rvertex[mesh->getNumVerts()];
		rsm->mesh->face=new rface[mesh->getNumFaces()];
	}
	
	// Export the vertices
	for (i=0; i<mesh->getNumVerts(); i++) {
		Point3 v = tm * mesh->verts[i];
		rsm->mesh->ver[i].coord=rvector(v);
		rsm->mesh->ver[i].normal=rvector(0,0,0);
	}
	
	// To determine visibility of a face, get the vertices in clockwise order.
	// If the objects has a negative scaling, we must compensate for that by
	// taking the vertices counter clockwise
	for (i=0; i<mesh->getNumFaces(); i++) {
		
		rsm->mesh->face[i].a=(WORD)mesh->faces[i].v[vx1];
		rsm->mesh->face[i].c=(WORD)mesh->faces[i].v[vx2];
		rsm->mesh->face[i].b=(WORD)mesh->faces[i].v[vx3];
		rsm->mesh->face[i].nMaterial=mesh->faces[i].getMatID();
	}
	
	// Export face map texcoords if we have them...
	if (!CheckForAndExportFaceMap(nodeMtl, mesh, indentLevel+1)) {
		// If not, export standard tverts
		int numTVx = mesh->getNumTVerts();

		if (numTVx) {
			rface *f=rsm->mesh->face;
			for (i=0; i<mesh->getNumFaces(); i++) {
// dubble added
				TVFace *tvf=&mesh->tvFace[i];
				f->u[0]=mesh->tVerts[tvf->t[vx1]].x;
				f->v[0]=1.0f-mesh->tVerts[tvf->t[vx1]].y;
				f->u[2]=mesh->tVerts[tvf->t[vx2]].x;
				f->v[2]=1.0f-mesh->tVerts[tvf->t[vx2]].y;
				f->u[1]=mesh->tVerts[tvf->t[vx3]].x;
				f->v[1]=1.0f-mesh->tVerts[tvf->t[vx3]].y;  // good
				f++;
// end of dubble added
			}
		}
	}

	{
		// Export mesh (face + vertex) normals
		
		Point3 fn;  // Face normal
		Point3 vn;  // Vertex normal
		int  vert;
		Face* f;
		
		// Face and vertex normals.
		// In MAX a vertex can have more than one normal (but doesn't always have it).
		// This is depending on the face you are accessing the vertex through.
		// To get all information we need to export all three vertex normals
		// for every face.
		Matrix3 pivot = node->GetNodeTM(GetStaticFrame());
		pivot.NoTrans();

		for (i=0; i<mesh->getNumFaces(); i++) {
			f = &mesh->faces[i];
			fn = mesh->getFaceNormal(i);
			rsm->mesh->face[i].normal=fn;
			
			vert = f->getVert(vx1);
			vn = GetVertexNormal(mesh, i, mesh->getRVertPtr(vert));
			rsm->mesh->face[i].vnormals[0]=pivot*vn;
			rsm->mesh->ver[rsm->mesh->face[i].a].normal+=vn;
			
			vert = f->getVert(vx2);
			vn = GetVertexNormal(mesh, i, mesh->getRVertPtr(vert));
			rsm->mesh->face[i].vnormals[2]=pivot*vn;
			rsm->mesh->ver[rsm->mesh->face[i].b].normal+=vn;
			
			vert = f->getVert(vx3);
			vn = GetVertexNormal(mesh, i, mesh->getRVertPtr(vert));
			rsm->mesh->face[i].vnormals[1]=pivot*vn;
			rsm->mesh->ver[rsm->mesh->face[i].c].normal+=vn;
		}
	}
	
	if (needDel) {
		delete tri;
	}
}