// we first define an assembly which contains the world assembly. This "uberMaster" contains the global transformation.
void defineMasterAssembly(renderer::Project* project)
{
    MMatrix conversionMatrix;
    conversionMatrix.setToIdentity();
    World* world = getWorldPtr();
    if (world != 0)
    {
        RenderGlobals* rg = world->mRenderGlobals.get();
        if (rg != 0)
            conversionMatrix = rg->globalConversionMatrix;
    }
    if (getSceneFromProject(project)->assemblies().get_by_name("world") == 0)
    {
        foundation::auto_release_ptr<renderer::Assembly> assembly(renderer::AssemblyFactory().create("world", renderer::ParamArray()));
        getSceneFromProject(project)->assemblies().insert(assembly);
        foundation::Matrix4d appMatrix;
        MMatrix transformMatrix;
        transformMatrix.setToIdentity();
        transformMatrix *= conversionMatrix;
        foundation::auto_release_ptr<renderer::AssemblyInstance> assemblyInstance = renderer::AssemblyInstanceFactory::create("world_Inst", renderer::ParamArray(), "world");
        MMatrixToAMatrix(transformMatrix, appMatrix);
        assemblyInstance->transform_sequence().set_transform(0.0, foundation::Transformd::from_local_to_parent(appMatrix));
        getSceneFromProject(project)->assembly_instances().insert(assemblyInstance);
    }
}
Beispiel #2
0
MMatrix GetGlobalMMatrix(const MObject & in_Ref)
{
   MMatrix result;
   result.setToIdentity();

   MFnDagNode node(in_Ref);
   MDagPathArray paths;
   node.getAllPaths(paths);
   MDagPath path = paths[0];

   MString typeStr = in_Ref.apiTypeStr();
   if(typeStr == "kTransform")
   {
      result = path.inclusiveMatrix();
   }
   else
   {
      for(unsigned int i=0;i<node.parentCount();i++)
      {
         MObject parent = node.parent(i);
         typeStr = parent.apiTypeStr();
         if(typeStr == "kTransform")
         {
            result = GetGlobalMMatrix(parent);
            //break;
         }
      }
   }

   return result;
}
Beispiel #3
0
void AppleseedRenderer::fillTransformMatices(mtap_MayaObject *obj, asr::Camera *assInstance)
{
	assInstance->transform_sequence().clear();
	size_t numSteps =  obj->transformMatrices.size();
	size_t divSteps = numSteps;
	if( divSteps > 1)
		divSteps -= 1;
	float stepSize = 1.0f / (float)divSteps;
	float start = 0.0f;

	// here only the transform will be scaled because a scaled camera will result in different renderings (e.g. dof)

	asf::Matrix4d appMatrix;
	MMatrix transformMatrix;
	for( size_t matrixId = 0; matrixId < numSteps; matrixId++)
	{
		transformMatrix.setToIdentity();
		transformMatrix.matrix[3][0] = obj->transformMatrices[matrixId].matrix[3][0];
		transformMatrix.matrix[3][1] = obj->transformMatrices[matrixId].matrix[3][1];
		transformMatrix.matrix[3][2] = obj->transformMatrices[matrixId].matrix[3][2];
		transformMatrix *= this->renderGlobals->globalConversionMatrix;
		MMatrix colMatrix = obj->transformMatrices[matrixId];
		colMatrix.matrix[3][0] = transformMatrix.matrix[3][0];
		colMatrix.matrix[3][1] = transformMatrix.matrix[3][1];
		colMatrix.matrix[3][2] = transformMatrix.matrix[3][2];
		this->MMatrixToAMatrix(colMatrix, appMatrix);
		logger.trace(MString("cam mat ") + colMatrix.matrix[3][0] + " " + colMatrix.matrix[3][1] + " " + colMatrix.matrix[3][2]);
		assInstance->transform_sequence().set_transform(
			start + stepSize * matrixId,
			asf::Transformd::from_local_to_parent(appMatrix));
	}
}
void AbcWriteJob::perFrameCallback(double iFrame)
{
    MBoundingBox bbox;

    util::ShapeSet::iterator it = mArgs.dagPaths.begin();
    const util::ShapeSet::iterator end = mArgs.dagPaths.end();
    for (; it != end; it ++)
    {
        mCurDag = *it;

        MMatrix eMInvMat;
        if (mArgs.worldSpace)
        {
            eMInvMat.setToIdentity();
        }
        else
        {
            eMInvMat = mCurDag.exclusiveMatrixInverse();
        }

        bbox.expand(getBoundingBox(iFrame, eMInvMat));
    }

    Alembic::Abc::V3d min(bbox.min().x, bbox.min().y, bbox.min().z);
    Alembic::Abc::V3d max(bbox.max().x, bbox.max().y, bbox.max().z);
    Alembic::Abc::Box3d b(min, max);
    mBoxProp.set(b);

    processCallback(mArgs.melPerFrameCallback, true, iFrame, bbox);
    processCallback(mArgs.pythonPerFrameCallback, false, iFrame, bbox);
}
Beispiel #5
0
MMatrix getMatrix(const char *plugName, MFnDependencyNode& dn)
{
	MMatrix m;
	m.setToIdentity();
	MStatus stat;
	MPlug p = dn.findPlug(plugName, &stat);
	if (stat)
	{
		MObject matrixObject;
		p.getValue(matrixObject);
		MFnMatrixData fnMat(matrixObject);
		MMatrix mat = fnMat.matrix();
		m = mat;
	}
	return m;
}
Beispiel #6
0
void getUVFromConnectedTexturePlacementNode(MObject fileTextureNode, float inU, float inV, float& outU, float& outV)
{
	MObject texPlaceObj = getConnectedInNode(fileTextureNode, "uvCoord");
	outU = inU;
	outV = outV;
	if( texPlaceObj == MObject::kNullObj )
		return;

	double offsetU = 0.0;
	double offsetV = 0.0;

	MFnDependencyNode texPlaceNode(texPlaceObj);
	getDouble(MString("offsetU"), texPlaceNode, offsetU);
	getDouble(MString("offsetV"), texPlaceNode, offsetV);
	float repeatU = 1.0f, repeatV = 1.0f, rotateUV = 0.0f;
	getFloat("repeatU",  texPlaceNode, repeatU);
	getFloat("repeatV",  texPlaceNode, repeatV);
	getFloat("rotateUV",  texPlaceNode, rotateUV);

	MMatrix rotationMatrix;
	rotationMatrix.setToIdentity();
	rotationMatrix[0][0] =  cos(rotateUV) * repeatU;
	rotationMatrix[1][0] = -sin(rotateUV) * repeatU;
	rotationMatrix[0][1] =  sin(rotateUV) * repeatV;
	rotationMatrix[1][1] =  cos(rotateUV) * repeatV;

	MVector uv(inU - 0.5, inV - 0.5, 0.0);
	uv = uv * rotationMatrix;
	uv.x += 0.5;
	uv.y += 0.5;

	uv.x *= repeatU;
	uv.y *= repeatV;

	uv.x += offsetU;
	uv.y += offsetV;

	outU = uv.x;
	outV = uv.y;
}
Beispiel #7
0
void FujiRenderer::setTransform(mtfu_MayaObject *obj)
{
	if( obj->objectID == SI_BADID)
	{
		logger.error(MString("Object ") + obj->shortName + " has bad ID");
		return;
	}


	MMatrix rotMatrix;
	rotMatrix.setToIdentity();

	if( obj->mobject.hasFn(MFn::kAreaLight))
	{
		MTransformationMatrix tm(rotMatrix);
		double areaScale[3] = {2,2,2};
		tm.setScale(areaScale, MSpace::kWorld);
		MEulerRotation e(-90.0, 0.0, 0.0);
		tm.rotateBy(e, MSpace::kWorld);
		rotMatrix = tm.asMatrix();
	}
	
	MMatrix transformMatrix = rotMatrix * obj->dagPath.inclusiveMatrix();
	MTransformationMatrix objTMatrix(transformMatrix);
	double rot[3];
	double scale[3];

	MTransformationMatrix::RotationOrder rotOrder =  MTransformationMatrix::kXYZ;
	objTMatrix.getRotation(rot, rotOrder, MSpace::kWorld);
	MVector pos = objTMatrix.getTranslation(MSpace::kWorld);
	objTMatrix.getScale(scale, MSpace::kWorld);
	SiSetProperty3(obj->objectID, "translate", pos[0], pos[1], pos[2]);
	SiSetProperty3(obj->objectID, "rotate", RadToDeg(rot[0]), RadToDeg(rot[1]), RadToDeg(rot[2]));
	SiSetProperty3(obj->objectID, "scale", scale[0], scale[1], scale[2]);

	//logger.debug(MString("SetProperty3 ") + obj->shortName + " translate " + pos[0] + " " + pos[1] + " " + pos[2]);
	//logger.debug(MString("SetProperty3 ") + obj->shortName + " rotate " + RadToDeg(rot[0]) + " " + RadToDeg(rot[1]) + " " + RadToDeg(rot[2]));

}
MStatus geometrySurfaceConstraint::compute( const MPlug& plug, MDataBlock& block )
{	
	MStatus returnStatus;
 
    if(plug == constraintTranslateX || plug == constraintTranslateY || plug == constraintTranslateZ) {
        if(!m_isInitd) {
// read rest position
            MDataHandle htgo = block.inputValue(targetRestP);
            double3 & tgo = htgo.asDouble3();
            MGlobal::displayInfo(MString("target rest p ")+tgo[0]+" "+tgo[1]+" "+tgo[2]);
            m_restPos = MPoint(tgo[0],tgo[1],tgo[2]);
			m_isInitd = true;
		}
		
		MArrayDataHandle targetArray = block.inputArrayValue( compoundTarget );
		const unsigned int targetArrayCount = targetArray.elementCount();
        MMatrix tm;
        tm.setToIdentity();
        unsigned int i;
		for ( i = 0; i < targetArrayCount; i++ ) {
            MDataHandle targetElement = targetArray.inputValue(&returnStatus);
            if(!returnStatus) {
                MGlobal::displayInfo("failed to get input value target element");
            }
            MDataHandle htm = targetElement.child(targetTransform);
            MFnMatrixData ftm(htm.data(), &returnStatus);
            if(!returnStatus) {
                MGlobal::displayInfo("failed to get matrix data");
            }
            tm = ftm.matrix();
            targetArray.next();
        }
		
		MDataHandle hparentInvMat = block.inputValue(constraintParentInverseMatrix);
		MMatrix parentInvMat = hparentInvMat.asMatrix();

// world position
        MPoint curPos(tm(3,0), tm(3,1), tm(3,2));
// offset in local space
		m_offsetToRest = m_restPos - curPos;
// object position in world space
		MPoint localP = m_offsetToRest * tm + curPos;
// in local space
		localP *= parentInvMat;

        MDataHandle hout;
        if(plug == constraintTranslateX) {
            hout = block.outputValue(constraintTranslateX);
			hout.set(localP.x);
        }
        else if(plug == constraintTranslateY) {
            hout = block.outputValue(constraintTranslateY);
			hout.set(localP.y);
        }
        else if(plug == constraintTranslateZ) {
            hout = block.outputValue(constraintTranslateZ);
			hout.set(localP.z);
        }
		
		//MPlug pgTx(thisMObject(), constraintTargetX);
		//pgTx.setValue(m_lastPos.x);
		//MPlug pgTy(thisMObject(), constraintTargetY);
		//pgTy.setValue(m_lastPos.y);
		//MPlug pgTz(thisMObject(), constraintTargetZ);
		//pgTz.setValue(m_lastPos.z);
		
		MPlug pgOx(thisMObject(), constraintObjectX);
		pgOx.setValue(m_offsetToRest.x);
		MPlug pgOy(thisMObject(), constraintObjectY);
		pgOy.setValue(m_offsetToRest.y);
		MPlug pgOz(thisMObject(), constraintObjectZ);
		pgOz.setValue(m_offsetToRest.z);
        
       // MFnNumericData nd;
		//MObject offsetData = nd.create( MFnNumericData::k3Double);
        //nd.setData3Double(m_lastPos.x, m_lastPos.y, m_lastPos.z);
        //MPlug pgTgo(thisMObject(), targetOffset);
        //pgTgo.setValue(offsetData); 
    }
	else
		return MS::kUnknownParameter;

	return MS::kSuccess;
}
	bool gpuCacheIsectUtil::getClosestPointOnTri(const MPoint &toThisPoint, const MPoint &pt1, const MPoint &pt2, const MPoint &pt3, MPoint &theClosestPoint, double &currDist) 
	{
		double		sum, a, b, c, len, dist;
		MMatrix mat;
		mat.setToIdentity();
		mat[2][0] = mat[2][1] = mat[2][2] = 1.;

		MVector v = toThisPoint - pt1;
		MVector v12 = pt2 - pt1;
		MVector v13 = pt3 - pt1;
		MVector norm = v12 ^ v13;
		len = norm * norm;
		if (len < 1.175494351e-38F) return false;
		len = ( norm * v ) / len;

		MPoint pnt = toThisPoint - len * norm;

		// Do a quick test first
		if (pnt.distanceTo(toThisPoint) >= currDist)
			return false;

		int i, j;				// Find best plane to project to
		if (fabs(norm[0]) > fabs(norm[1]))
		{
			if (fabs(norm[0]) > fabs(norm[2]))
			{
				i = 1; j = 2;
			}
			else
			{
				i = 0; j = 1;
			}
		}
		else
		{
			if (fabs(norm[1]) > fabs(norm[2]))
			{
				i = 0; j = 2;
				// i = 2; j = 0;
			}
			else
			{
				i = 0; j = 1;
			}
		}

		mat[0][0] = pt1[i]; mat[0][1] = pt2[i]; mat[0][2] = pt3[i]; 
		mat[1][0] = pt1[j]; mat[1][1] = pt2[j]; mat[1][2] = pt3[j]; 

		MMatrix	matInv = mat.inverse();
		MPoint abc(pnt[i], pnt[j], 1, 0);

		abc = matInv * abc;
		// Now abc is the barycentric coordinates of pnt
		// clip to inside triangle

		if (abc[0]<0) { // a < 0
			if (abc[1]<0) { // b < 0
				a = b = 0;
				c = 1;
			} else if (abc[2]<0) { // c < 0
				a = c = 0;
				b = 1;
			} else {
				a = 0;
				// c = BP dot BC / BC square;
				MVector v23 = pt3 - pt2; // BC
				MVector vp =  toThisPoint - pt2;  // BP

				c = ( vp * v23 ) / ( v23[0]*v23[0] + v23[1]*v23[1] + v23[2]*v23[2] );
				if (c<0) c = 0; else if (c>1) c = 1;
				b = 1 - c;
			}
		} else if (abc[1]<0) { // b < 0
			if (abc[2]<0) { // c < 0
				b = c = 0;
				a = 1;
				//} else if (abc[0]<0) { // a < 0
				//	b = a = 0;	// commented-code for optimization
				//	c = 1;		// leaving it in for readability (cyclic variations)
			} else {
				b = 0;
				// a = CP dot CA / CA square;
				MVector v31 = pt1 - pt3; // CA
				MVector vp =  toThisPoint - pt3;  // CP

				a = ( vp * v31 ) / ( v31[0]*v31[0] + v31[1]*v31[1] +v31[2]*v31[2] );
				if (a<0) a = 0; else if (a>1) a = 1;
				c = 1 - a;
			} 
		} else if (abc[2]<0) { // c < 0
			//if (abc[1]<0) { // b < 0
			//	c = b = 0;
			//	a = 1;
			//} else if (abc[0]<0) { // a < 0
			//	c = a = 0;
			//	b = 1;	// commented-code for optimization
			//} else {	// leaving it in for readability (cyclic variations)
			c = 0;
			// b = AP dot AB / AB square;
			//DIFF(v23, pt3, pt2); // AB
			MVector vp =  toThisPoint - pt1;  // AP

			b = ( vp * v12 ) / ( v12[0]*v12[0] + v12[1]*v12[1] + v12[2]*v12[2] );
			if (b<0) b = 0; else if (b>1) b = 1;
			a = 1 - b;
			//}
		} else {
			if (abc[0]>0) a = abc[0]; else a = 0;
			if (abc[1]>0) b = abc[1]; else b = 0;
			if (abc[2]>0) c = abc[2]; else c = 0;
		}
		sum = a+b+c;
		a /= sum ; b /= sum ; c /= sum ; 
		pnt = a * pt1 + b * pt2 + c * pt3;
		dist = pnt.distanceTo(toThisPoint);
		if ( dist < currDist)
		{			
			// Now it's really closer, keep it
			currDist = dist;
			theClosestPoint = pnt;
			return true;
		}
		return false;
	}
// write the frame ranges and statistic string on the root
// Also call the post callbacks
void AbcWriteJob::postCallback(double iFrame)
{
    std::string statsStr = "";

    addToString(statsStr, "SubDStaticNum", mStats.mSubDStaticNum);
    addToString(statsStr, "SubDAnimNum", mStats.mSubDAnimNum);
    addToString(statsStr, "SubDStaticCVs", mStats.mSubDStaticCVs);
    addToString(statsStr, "SubDAnimCVs", mStats.mSubDAnimCVs);
    addToString(statsStr, "SubDStaticFaces", mStats.mSubDStaticFaces);
    addToString(statsStr, "SubDAnimFaces", mStats.mSubDAnimFaces);

    addToString(statsStr, "PolyStaticNum", mStats.mPolyStaticNum);
    addToString(statsStr, "PolyAnimNum", mStats.mPolyAnimNum);
    addToString(statsStr, "PolyStaticCVs", mStats.mPolyStaticCVs);
    addToString(statsStr, "PolyAnimCVs", mStats.mPolyAnimCVs);
    addToString(statsStr, "PolyStaticFaces", mStats.mPolyStaticFaces);
    addToString(statsStr, "PolyAnimFaces", mStats.mPolyAnimFaces);

    addToString(statsStr, "CurveStaticNum", mStats.mCurveStaticNum);
    addToString(statsStr, "CurveStaticCurves", mStats.mCurveStaticCurves);
    addToString(statsStr, "CurveAnimNum", mStats.mCurveAnimNum);
    addToString(statsStr, "CurveAnimCurves", mStats.mCurveAnimCurves);
    addToString(statsStr, "CurveStaticCVs", mStats.mCurveStaticCVs);
    addToString(statsStr, "CurveAnimCVs", mStats.mCurveAnimCVs);

    addToString(statsStr, "PointStaticNum", mStats.mPointStaticNum);
    addToString(statsStr, "PointAnimNum", mStats.mPointAnimNum);
    addToString(statsStr, "PointStaticCVs", mStats.mPointStaticCVs);
    addToString(statsStr, "PointAnimCVs", mStats.mPointAnimCVs);

    addToString(statsStr, "NurbsStaticNum", mStats.mNurbsStaticNum);
    addToString(statsStr, "NurbsAnimNum", mStats.mNurbsAnimNum);
    addToString(statsStr, "NurbsStaticCVs", mStats.mNurbsStaticCVs);
    addToString(statsStr, "NurbsAnimCVs", mStats.mNurbsAnimCVs);

    addToString(statsStr, "TransStaticNum", mStats.mTransStaticNum);
    addToString(statsStr, "TransAnimNum", mStats.mTransAnimNum);

    addToString(statsStr, "LocatorStaticNum", mStats.mLocatorStaticNum);
    addToString(statsStr, "LocatorAnimNum", mStats.mLocatorAnimNum);

    addToString(statsStr, "CameraStaticNum", mStats.mCameraStaticNum);
    addToString(statsStr, "CameraAnimNum", mStats.mCameraAnimNum);

    if (statsStr.length() > 0)
    {
        Alembic::Abc::OStringProperty stats(mRoot.getTop().getProperties(),
            "statistics");
        stats.set(statsStr);
    }

    if (mTransTimeIndex != 0)
    {
        MString propName;
        propName += static_cast<int>(mTransTimeIndex);
        propName += ".samples";
        Alembic::Abc::OUInt32Property samp(mRoot.getTop().getProperties(),
            propName.asChar());
        samp.set(mTransSamples);
    }

    if (mShapeTimeIndex != 0 && mShapeTimeIndex != mTransTimeIndex)
    {
        MString propName;
        propName += static_cast<int>(mShapeTimeIndex);
        propName += ".samples";
        Alembic::Abc::OUInt32Property samp(mRoot.getTop().getProperties(),
            propName.asChar());
        samp.set(mShapeSamples);
    }

    MBoundingBox bbox;

    if (mArgs.melPostCallback.find("#BOUNDS#") != std::string::npos ||
        mArgs.pythonPostCallback.find("#BOUNDS#") != std::string::npos ||
        mArgs.melPostCallback.find("#BOUNDSARRAY#") != std::string::npos ||
        mArgs.pythonPostCallback.find("#BOUNDSARRAY#") != std::string::npos)
    {
        util::ShapeSet::const_iterator it = mArgs.dagPaths.begin();
        const util::ShapeSet::const_iterator end = mArgs.dagPaths.end();
        for (; it != end; it ++)
        {
            mCurDag = *it;

            MMatrix eMInvMat;
            if (mArgs.worldSpace)
            {
                eMInvMat.setToIdentity();
            }
            else
            {
                eMInvMat = mCurDag.exclusiveMatrixInverse();
            }

            bbox.expand(getBoundingBox(iFrame, eMInvMat));
        }
    }

    processCallback(mArgs.melPostCallback, true, iFrame, bbox);
    processCallback(mArgs.pythonPostCallback, false, iFrame, bbox);
}
Beispiel #11
0
MStatus CXRayCameraExport::ExportCamera(const MFileObject& file)
{
	MDagPath            node; 
    MObject             component; 
    MSelectionList      list; 
    MFnDagNode          nodeFn; 
	MFnCamera			C;
	MStatus		st ;
    
	MGlobal::getActiveSelectionList( list ); 
    for ( u32 index = 0; index < list.length(); ++index ) 
    { 
        list.getDagPath			( index, node, component ); 
        nodeFn.setObject		( node ); 
		st = C.setObject		(node);
		if(st!=MStatus::kSuccess)
		{
			Msg		("Selected object is not a camera");
			return	MStatus::kInvalidParameter;
		}

    } 

	Msg("exporting camera named [%s]",	C.name().asChar());

	MTime				tmTemp,tmTemp2;
	MTime				tmQuant;

	// Remember the frame the scene was at so we can restore it later.
	MTime storedFrame	= MAnimControl::currentTime();
	MTime startFrame	= MAnimControl::minTime();
	MTime endFrame		= MAnimControl::maxTime();

	tmTemp.setUnit		(MTime::uiUnit());
	tmTemp2.setUnit		(MTime::uiUnit());
	tmQuant.setUnit		(MTime::uiUnit());
	tmQuant				= 10.0; //3 time in sec. temporary
	
	COMotion			M;
	M.SetParam			(0, (int)(endFrame-startFrame).as(MTime::uiUnit()), 30);
	
	Fvector				P,R;
	tmTemp				= startFrame;

	MObject cam_parent	= C.parent(0);
	MFnTransform		parentTransform(cam_parent);
	

	MDistance			dist;
	while(tmTemp <= endFrame)
	{
		MAnimControl::setCurrentTime( tmTemp );

		MMatrix parentMatrix	=	parentTransform.transformation().asMatrix();
		MMatrix					cv;
		cv.setToIdentity		();
		cv[2][2]				= -1.0;
		MMatrix					TM;
		TM						=  (cv*parentMatrix)*cv;
		TM						= cv*TM;
		parentMatrix			= TM;

		Msg				("frame[%d]",(int)tmTemp.as(MTime::uiUnit()));
		
		dist.setValue	(parentMatrix[3][0]);
		P.x				= (float)dist.asMeters();
		dist.setValue	(parentMatrix[3][1]);
		P.y				= (float)dist.asMeters();
		dist.setValue	(parentMatrix[3][2]);
		P.z				= (float)dist.asMeters();

		Msg				("P %3.3f,%3.3f,%3.3f",P.x,P.y,P.z);

		double			rot[3];
		MTransformationMatrix::RotationOrder rot_order = MTransformationMatrix::kXYZ;

		st 				= parentTransform.getRotation( rot, rot_order );
                             
		R.x				= -(float)rot[0];
		R.y				= -(float)rot[1];
		R.z				= -(float)rot[2];
//.		Msg				("rt %3.3f,%3.3f,%3.3f kWorld",R.x,R.y,R.z);

		tmTemp2			= tmTemp-startFrame;
		M.CreateKey		(float(tmTemp2.as(MTime::uiUnit()))/30.0f,P,R);

		if(tmTemp==endFrame)
			break;

		tmTemp			+= tmQuant;

		if(tmTemp>endFrame)
			tmTemp=endFrame;
	};


	MString 			fn_save_to = file.fullName();
	fn_save_to			+= ".anm";

	Msg("file full name [%s]", fn_save_to);
	M.SaveMotion		(fn_save_to.asChar());

	MAnimControl::setCurrentTime( storedFrame );

	return MS::kSuccess;
}
Beispiel #12
0
MStatus MG_nurbsRivet::initialize()
	{ 

		//This is the nurbs input attribute
		MFnTypedAttribute typedFn;
		MFnCompoundAttribute compund;
		MFnNumericAttribute numFn;
		MFnMatrixAttribute    matrixFn;

		inputNurbSurface  = typedFn.create("inputNurbSurface","in",MFnData::kNurbsSurface);
		typedFn.setStorable(true);
		addAttribute(inputNurbSurface);
		

		//This is the input point   attribute
		
		
		inputPointX = numFn.create("inputPointX","ipx",MFnNumericData::kDouble,0);
		numFn.setStorable(true);
		numFn.setKeyable(true);
		addAttribute(inputPointX);

		inputPointY = numFn.create("inputPointY","ipy",MFnNumericData::kDouble,0);
		numFn.setStorable(true);
		numFn.setKeyable(true);
		addAttribute(inputPointY);
		

		inputPointZ = numFn.create("inputPointZ","ipz",MFnNumericData::kDouble,0);
		numFn.setStorable(true);
		numFn.setKeyable(true);
		addAttribute(inputPointZ);




		
		inputPoint= compund.create("inputPoint","ip");
		compund.addChild(inputPointX);
		compund.addChild(inputPointY);
		compund.addChild(inputPointZ);
		addAttribute(inputPoint);
	

		//This is the recompute point checkbox
	
		recompute = numFn.create("recompute","r",MFnNumericData::kBoolean,1);
		numFn.setKeyable(true);
		numFn.setStorable(true);
		addAttribute(recompute);

		//This is U attribute
	
		uValue = numFn.create("uValue","u",MFnNumericData::kFloat , 0);
		numFn.setKeyable(true);
		numFn.setStorable(true);
		addAttribute(uValue);


		//This is V attribute
	
		vValue = numFn.create("vValue","v",MFnNumericData::kFloat , 0 );
		numFn.setKeyable(true);
		numFn.setStorable(true);
		addAttribute(vValue);



		//This is the output translate attribute 

		outputX = numFn.create("outputTranslateX","otx",MFnNumericData::kDouble,0);
		numFn.setStorable(true);
		numFn.setKeyable(true);
		addAttribute(outputX);

		outputY = numFn.create("outputTranslateY","oty",MFnNumericData::kDouble,0);
		numFn.setStorable(true);
		numFn.setKeyable(true);
		addAttribute(outputY);
		

		outputZ = numFn.create("outputTranslateZ","otz",MFnNumericData::kDouble,0);
		numFn.setStorable(true);
		numFn.setKeyable(true);
		addAttribute(outputZ);




		
		output= compund.create("outputTranslate","ot");
		compund.addChild(outputX);
		compund.addChild(outputY);
		compund.addChild(outputZ);
		compund.setKeyable(false);
		compund.setStorable(false);
		compund.setWritable(false);
		addAttribute(output);


		//output = numFn.createPoint("outputTranslate","ot");
		//numFn.setKeyable(false);
		//numFn.setStorable(false);
		//numFn.setWritable(false);
		//addAttribute(output);


		//This is the output rotate attribute 
		outputRotateX = numFn.create("outputRotateX","orx",MFnNumericData::kDouble,0);
		numFn.setStorable(true);
		numFn.setKeyable(true);
		addAttribute(outputRotateX);

		outputRotateY = numFn.create("outputRotateY","ory",MFnNumericData::kDouble,0);
		numFn.setStorable(true);
		numFn.setKeyable(true);
		addAttribute(outputRotateY);

		outputRotateZ = numFn.create("outputRotateZ","orz",MFnNumericData::kDouble,0);
		numFn.setStorable(true);
		numFn.setKeyable(true);
		addAttribute(outputRotateZ);


		outputRotate= compund.create("outputRotate","oro");
		compund.addChild(outputRotateX);
		compund.addChild(outputRotateY);
		compund.addChild(outputRotateZ);
		compund.setKeyable(false);
		compund.setStorable(false);
		compund.setWritable(false);
		addAttribute(outputRotate);

 
		//Those are all the matrix input 

		
		outputMatrix =matrixFn.create("outputMatrix","om");
		matrixFn.setKeyable(false);
		matrixFn.setStorable(false);
		matrixFn.setWritable(false);
		addAttribute(outputMatrix); 


		//offset matrix 

		offsetMatrix =matrixFn.create("offsetMatrix","ofm");
		MMatrix defMatrix;
		defMatrix.setToIdentity();
		matrixFn.setDefault(defMatrix);
		matrixFn.setKeyable(false);
		matrixFn.setStorable(true);
		matrixFn.setWritable(true);
		addAttribute(offsetMatrix); 

		//all the attr affects

		attributeAffects (recompute,output);
		attributeAffects (inputPoint,output);
		attributeAffects (inputNurbSurface,output);
		attributeAffects (uValue,output);
		attributeAffects (vValue,output);
		attributeAffects (offsetMatrix,output);

		attributeAffects (recompute,outputRotate);
		attributeAffects (inputPoint,outputRotate);
		attributeAffects (inputNurbSurface,outputRotate);
		attributeAffects (uValue,outputRotate);
		attributeAffects (vValue,outputRotate);
		attributeAffects (offsetMatrix,outputRotate);

		attributeAffects (recompute,outputMatrix);
		attributeAffects (inputPoint,outputMatrix);
		attributeAffects (inputNurbSurface,outputMatrix);
		attributeAffects (uValue,outputMatrix);
		attributeAffects (vValue,outputMatrix);
		attributeAffects (offsetMatrix,outputMatrix);

		return MS::kSuccess;
	}
Beispiel #13
0
void RenderGlobals::defineGlobalConversionMatrix()
{
	globalConversionMatrix.setToIdentity();
	MMatrix scaleMatrix;
	scaleMatrix.setToIdentity();

	internalScaleFactor = 1.0f; // internal in mm
	rendererScaleFactor = 1.0f; // external in mm

	this->scaleFactor = 1.0f;

	switch( this->internalUnit )
	{
	case MDistance::kCentimeters:
		internalScaleFactor = 10.0f;
		break;
	case MDistance::kFeet:
		internalScaleFactor = 304.8f;
		break;
	case MDistance::kInches:
		internalScaleFactor = 25.4f;
		break;
	case MDistance::kKilometers:
		internalScaleFactor = 1000000.f;
		break;
	case MDistance::kMeters:
		internalScaleFactor = 1000.f;
		break;
	case MDistance::kMillimeters:
		internalScaleFactor = 1.f;
		break;
	case MDistance::kMiles:
		internalScaleFactor = 1609344.f;
		break;
	case MDistance::kYards:
		internalScaleFactor = 914.4f;
		break;
	};

	switch( this->rendererUnit )
	{
	case MDistance::kCentimeters:
		rendererScaleFactor = 10.0f;
		break;
	case MDistance::kFeet:
		rendererScaleFactor = 304.8f;
		break;
	case MDistance::kInches:
		rendererScaleFactor = 25.4f;
		break;
	case MDistance::kKilometers:
		rendererScaleFactor = 1000000.f;
		break;
	case MDistance::kMeters:
		rendererScaleFactor = 1000.f;
		break;
	case MDistance::kMillimeters:
		rendererScaleFactor = 1.f;
		break;
	case MDistance::kMiles:
		rendererScaleFactor = 1609344.f;
		break;
	case MDistance::kYards:
		rendererScaleFactor = 914.4f;
		break;
	};

	scaleFactor = internalScaleFactor/rendererScaleFactor * sceneScale;
	scaleMatrix[0][0] = scaleMatrix[1][1] = scaleMatrix[2][2] = scaleFactor;

	scaleMatrix = scaleMatrix * sceneScaleMatrix;

	MMatrix YtoZ;
	YtoZ.setToIdentity();
	YtoZ[0][0] = 1;
	YtoZ[0][1] = 0;
	YtoZ[0][2] = 0;
	YtoZ[0][3] = 0;
	
	YtoZ[1][0] = 0;
	YtoZ[1][1] = 0;
	YtoZ[1][2] = 1;
	YtoZ[1][3] = 0;
	
	YtoZ[2][0] = 0;
	YtoZ[2][1] = -1;
	YtoZ[2][2] = 0;
	YtoZ[2][3] = 0;
	
	YtoZ[3][0] = 0;
	YtoZ[3][1] = 0;
	YtoZ[3][2] = 0;
	YtoZ[3][3] = 1;	


	if ((this->internalAxis == YUp) && (this->rendererAxis == ZUp) )
	{
		globalConversionMatrix = YtoZ;
	}

	globalConversionMatrix *= scaleMatrix;
}
void sphericalBlendShapeVisualizerDrawOverride::addUIDrawables(
								const MDagPath& objPath,
								MHWRender::MUIDrawManager& drawManager,
								const MHWRender::MFrameContext& frameContext,
								const MUserData* data)
{
	sphericalBlendShapeVisualizerData* pLocatorData = (sphericalBlendShapeVisualizerData*)data;
	if (!pLocatorData)
	{
		return;
	}

	MMatrix spaceMatrix    = pLocatorData->fSpaceMatrix;
	MMatrix spaceInvMatrix = spaceMatrix.inverse();

	short poleAxis      = pLocatorData->fPoleAxis;
	short seamAxis      = pLocatorData->fSeamAxis;

	drawManager.beginDrawable();

	MColor lineColor, vertexColor, poleAxisColor, seamAxisColor;
	lineColor		= MColor(0.7294f, .239216f, 0.2980f, 1.0f);
	vertexColor		= MColor(0.5843f, 0.78824f, .17255f, 1.0f);
	poleAxisColor   = MColor(1.0f, 0.0f, 0.f, 1.0f);
	seamAxisColor   = MColor(0.0f, 1.0f, 0.0f, 1.0f);

	MMatrix identity;
	identity.setToIdentity();

	double radius   = 1.0;
	int numRings    = 20;
	int numSections = 20;

	MPoint sphericalPoint, xyzPoint;
	MPoint startPoint, endPoint, firstPoint;
	MPointArray points;

	drawManager.setDepthPriority(5);

	drawManager.setColor(lineColor);

	bboxPoints.clear();
	bboxPoints.setLength(numRings*numSections);

	for(int ring=0; ring<=numRings; ring++) {
		double azimuth = (double)ring / numRings * M_PI * 2;

		for(int section=0; section<=numSections; section++) {
			double zenith = (double)section / (numSections) * M_PI;

			sphericalPoint.x = radius;
			sphericalPoint.y = zenith;
			sphericalPoint.z = azimuth;
			
			if (section==0) {
				sphericalToCartesian(sphericalPoint, poleAxis, seamAxis, startPoint);
				startPoint = startPoint * spaceMatrix;
				firstPoint = startPoint;
				bboxPoints.append(firstPoint);
				continue;
			} else {
				sphericalToCartesian(sphericalPoint, poleAxis, seamAxis, endPoint);
				endPoint = endPoint * spaceMatrix;
				drawManager.line(startPoint, endPoint);
				bboxPoints.append(endPoint);
				startPoint = endPoint;
			}
		}
	}

	for(int ring=0; ring<=numRings; ring++) {
		double azimuth = (double)ring / numRings * M_PI * 2;

		for(int section=0; section<=numSections; section++) {
			double zenith = (double)section / (numSections) * M_PI;

			sphericalPoint.x = radius;
			sphericalPoint.y = azimuth;
			sphericalPoint.z = zenith;
			
			if (section==0) {
				sphericalToCartesian(sphericalPoint, poleAxis, seamAxis, startPoint);
				startPoint = startPoint * spaceMatrix;
				firstPoint = startPoint;
				continue;
			} else {
				sphericalToCartesian(sphericalPoint, poleAxis, seamAxis, endPoint);
				endPoint = endPoint * spaceMatrix;
				drawManager.line(startPoint, endPoint);
				startPoint = endPoint;
			}
		}
	}

	drawManager.setLineWidth(3.0);
	drawManager.setLineStyle(MHWRender::MUIDrawManager::kDashed);
	
	startPoint = MPoint(0, 0, 0) * spaceMatrix;


	MVector endVector(0, 0, 0);
	setAxis(endVector, poleAxis, radius);
	endPoint = MPoint(endVector) * spaceMatrix;

	drawManager.setColor(poleAxisColor);
	drawManager.line(startPoint, endPoint);

	endVector = MVector(0, 0, 0);
	setAxis(endVector, seamAxis, radius);
	endPoint = MPoint(endVector) * spaceMatrix;

	drawManager.setColor(seamAxisColor);
	drawManager.line(startPoint, endPoint);
	drawManager.endDrawable();
}