Exemple #1
0
void SargassoNode::updateSpace(MDataBlock& block, unsigned idx)
{
	MStatus stat;
	/* // jump to elm is slow
	MArrayDataHandle hparentspaces = block.inputArrayValue(aconstraintParentInverseMatrix, &stat);
	// if(!stat) MGlobal::displayInfo("cannot input array");
	stat = hparentspaces.jumpToElement(idx);
	//if(!stat) AHelper::Info<unsigned>("cannot jump to elm", iobject);
	MDataHandle hspace = hparentspaces.inputValue(&stat);
	// if(!stat) MGlobal::displayInfo("cannot input single");
	const MMatrix parentSpace = hspace.asMatrix();
	*/
	const unsigned itri = objectTriangleInd()[idx];
         
	Matrix33F q = m_diff->Q()[itri];
	q.orthoNormalize();
	const Vector3F t = m_mesh->triangleCenter(itri);
	Matrix44F sp(q, t);

    AHelper::ConvertToMMatrix(m_currentSpace, sp);
	// m_currentSpace *= parentSpace;
	// AHelper::PrintMatrix("parent inv", m_currentSpace);
	
	const Vector3F objectP = localP()[idx];
	m_solvedT = MPoint(objectP.x, objectP.y, objectP.z) * m_currentSpace;
         
	MTransformationMatrix mtm(m_currentSpace);
	MTransformationMatrix::RotationOrder rotorder =  MTransformationMatrix::kXYZ;
	mtm.getRotation(m_rot, rotorder);
}
	bool getSamplePosition(const PositionSamplingRecord &pRec,
			const DirectionSamplingRecord &dRec, Point2 &samplePosition) const {
		Transform invTrafo = m_worldTransform->eval(pRec.time).inverse();
		Point localP(invTrafo.transformAffine(pRec.p));
		Point localD(invTrafo(dRec.d));

		if (localD.z <= 0)
			return false;

		Point intersection = localP + localD * (m_focusDistance / localD.z);

		Point screenSample = m_cameraToSample(intersection);
		if (screenSample.x < 0 || screenSample.x > 1 ||
			screenSample.y < 0 || screenSample.y > 1)
			return false;

		samplePosition = Point2(
				screenSample.x * m_resolution.x,
				screenSample.y * m_resolution.y);

		return true;
	}
Exemple #3
0
bool SargassoNode::creatRestShape(const MObject & m)
{
    MStatus stat;
    MFnMesh fmesh(m, &stat);
    if(!stat) {
        MGlobal::displayInfo("val is not mesh");
        return false;
    }
    MObject thisObj = thisMObject();
    MPlug pnv(thisObj, atargetNv);
    const int restNv = pnv.asInt();
    
    if(restNv != fmesh.numVertices()) {
        MGlobal::displayInfo("target nv not match");
        return false;
    }
    
    MPlug pntriv(thisObj, atargetNt);
    const int restNtriv = pntriv.asInt();
    
    MIntArray triangleCounts, triangleVertices;
	fmesh.getTriangles(triangleCounts, triangleVertices);
	
    if(restNtriv != triangleVertices.length()) {
        MGlobal::displayInfo("target ntri not match");
        return false;
    }
    
    m_mesh->create(restNv, restNtriv/3);
    
    MPlug prestp(thisObj, atargetRestP);
    MObject orestp;
    prestp.getValue(orestp);
    MFnPointArrayData frestp(orestp);
    MPointArray restPArray = frestp.array();	
    
    if(restPArray.length() != restNv) {
        MGlobal::displayInfo("cached target nv not match");
        return false;
    }
    
    Vector3F * p = m_mesh->points();
    unsigned i=0;
    for(;i<restNv;i++) p[i].set(restPArray[i].x, restPArray[i].y, restPArray[i].z);
    
    MPlug presttri(thisObj, atargetTri);
    MObject oresttri;
    presttri.getValue(oresttri);
    MFnIntArrayData fresttri(oresttri);
    MIntArray restTriArray = fresttri.array();	
    
    if(restTriArray.length() != restNtriv) {
        MGlobal::displayInfo("cached target ntri not match");
        return false;
    }
    
    unsigned * ind = m_mesh->indices();
    for(i=0;i<restNtriv;i++) ind[i] = restTriArray[i];
    
    const BoundingBox box = ((AGenericMesh *)m_mesh)->calculateBBox();
    AHelper::Info<BoundingBox>("target mesh box", box);
    
    m_diff = new TriangleDifference(m_mesh);
    
    MPlug ptargetbind(thisObj, atargetBind);
    MObject otargetbind;
    ptargetbind.getValue(otargetbind);
    MFnIntArrayData ftargetbind(otargetbind);
    MIntArray targetBindArray = ftargetbind.array();
    const unsigned nbind = targetBindArray.length();
    AHelper::Info<unsigned>("n binded triangles", nbind);
    
    std::vector<unsigned> vbind;
    for(i=0;i<nbind;i++) vbind.push_back(targetBindArray[i]);
    m_diff->requireQ(vbind);
    vbind.clear();
    
    MPlug pobjLocal(thisObj, aobjLocal);
    MObject oobjLocal;
    pobjLocal.getValue(oobjLocal);
    MFnVectorArrayData fobjLocal(oobjLocal);
    MVectorArray localPArray = fobjLocal.array();
    m_numObjects = localPArray.length();
    AHelper::Info<unsigned>("n constrained objects", m_numObjects);
    
    m_localP->create(m_numObjects * 12);
    
    Vector3F * lp = localP();
    for(i=0;i<m_numObjects;i++) lp[i].set(localPArray[i].x, localPArray[i].y, localPArray[i].z);
    
    m_triId->create(m_numObjects * 4);
    
    MPlug pobjtri(thisObj, aobjTri);
    MObject oobjtri;
    pobjtri.getValue(oobjtri);
    MFnIntArrayData fobjtri(oobjtri);
    MIntArray objtriArray = fobjtri.array();
    
    unsigned * tri = objectTriangleInd();
    for(i=0;i<m_numObjects;i++) tri[i] = objtriArray[i];
        
    return true;
}