void collisionShapeNode::computeCollisionShape(const MPlug& plug, MDataBlock& data)
{
	//std::cout << collisionShapeNode::collisionMarginOffset << std::endl;

	MObject thisObject(thisMObject());

	MPlug plgInShape(thisObject, ia_shape);


	if (isCompound(plgInShape))
	{
		m_collision_shape = createCompositeShape(plgInShape);
	} else
	{

		MObject thisObject(thisMObject());
		MPlug plgType(thisObject, ia_type);
		int type;
		plgType.getValue(type);

		switch(type)
		{
		case 4:
			//box
			m_collision_shape = solver_t::create_box_shape();
			break;
		case 5:
			//sphere
			m_collision_shape = solver_t::create_sphere_shape();
			break;
		case 6:
			//plane
			m_collision_shape = solver_t::create_plane_shape();
			break;

		default:
			{
				MPlugArray plgaConnectedTo;
				plgInShape.connectedTo(plgaConnectedTo, true, true);
				int numSelectedShapes = plgaConnectedTo.length();

				if(numSelectedShapes > 0) 
				{
					MObject node = plgaConnectedTo[0].node();
					m_collision_shape = createCollisionShape(node);
				}
			}
		}
	}



	//btAssert(m_collision_shape);

	data.setClean(plug);
}
// Cache the plug arrays for use in setDependentsDirty
bool AlembicCurvesDeformNode::setInternalValueInContext(const MPlug & plug,
    const MDataHandle & dataHandle,
    MDGContext &)
{
  if (plug == mGeomParamsList) {
    MString geomParamsStr = dataHandle.asString();
    getPlugArrayFromAttrList(geomParamsStr, thisMObject(), mGeomParamPlugs);
  }
  else if (plug == mUserAttrsList) {
    MString userAttrsStr = dataHandle.asString();
    getPlugArrayFromAttrList(userAttrsStr, thisMObject(), mUserAttrPlugs);
  }

  return false;
}
MBoundingBox AlembicCurvesLocatorNode::boundingBox() const
{
  MPlug SentinelPlug(thisMObject(), AlembicCurvesLocatorNode::mSentinelAttr);
  int sent = 0;
  SentinelPlug.getValue(sent);
  return mBoundingBox;
}
Exemple #4
0
// function to mark the output dirty once one of the dynamic attributes changes
MStatus puttyNode::setDependentsDirty( const MPlug &plugBeingDirtied,	MPlugArray &affectedPlugs )
{
	if ( plugBeingDirtied.isDynamic()) 
    {
		MStatus	status;
		MObject thisNode = thisMObject();

		// there is a dynamic attribute that is is dirty, so mark 
        // the outputGeometry dirty

		if ( MStatus::kSuccess == status ) 
		{
//			cerr << "\n###" << plugBeingDirtied.name() <<" "<<output.name();

//			MPlug pB( thisNode, puttyNode::outputGeom );
//           affectedPlugs.append( pB );

			MPlug pD( thisNode, puttyNode::aDynDirty );
			pD.setValue(true);
    
//			affectedPlugs.append( output );

		}

	}
	return( MS::kSuccess );
}
Exemple #5
0
void SoftBodyNode::computeSoftBodyParam(const MPlug &plug, MDataBlock &data)
{

	MObject thisObject(thisMObject());
	MObject update;

	// update mass
	MPlug(thisObject, ca_softBody).getValue(update);
	float mass = static_cast<float>( data.inputValue(ia_mass).asDouble() );
	this->m_soft_body->set_mass(mass);

	// update dynamic friction coefficient
	float dynFrictionCoeff = static_cast<float>( data.inputValue(ia_dynamicFrictionCoeff).asDouble() );	
	this->m_soft_body->set_dynamic_friction_coeff(dynFrictionCoeff);
	data.outputValue(ca_softBodyParam).set(true);

	// update collision margin
	float collisionMargin = data.inputValue(ia_collisionMargin).asFloat();
	this->m_soft_body->set_collision_margin(collisionMargin);
	data.setClean(plug);

	// number of collision clusters
	int numClust = data.inputValue(ia_numClusters).asInt();
	// this->m_soft_body->set_
}
Exemple #6
0
void rigidBodyNode::clearContactInfo()
{
	MObject thisObject(thisMObject());

	// contactCount
	m_contactCount = 0;
	MPlug plugContactCount(thisObject, rigidBodyNode::oa_contactCount);
	plugContactCount.setValue(m_contactCount);
	
	// contactName
	MStringArray stringArray;
	stringArray.clear();
	MFnStringArrayData stringArrayData;
	MObject strArrObject = stringArrayData.create(stringArray);

	MPlug plugContactName(thisObject, rigidBodyNode::oa_contactName);

	if ( !plugContactName.isNull() )
		plugContactName.setValue(strArrObject);

	// contactPosition
	MPlug plugContactPosition(thisObject, rigidBodyNode::oa_contactPosition);
	bool isArray = plugContactPosition.isArray();
				
	MVectorArray vectorArray;
	vectorArray.clear();

	MFnVectorArrayData vectorArrayData;
	MObject arrObject = vectorArrayData.create(vectorArray);		

	if ( !plugContactPosition.isNull() )
		plugContactPosition.setValue(arrObject);
}
Exemple #7
0
void rigidBodyNode::updateShape(const MPlug& plug, MDataBlock& data, float& collisionMarginOffset)
{
	MObject thisObject(thisMObject());
    MPlug plgCollisionShape(thisObject, ia_collisionShape);
    MObject update;
    //force evaluation of the shape
    plgCollisionShape.getValue(update);

   /* vec3f prevCenter(0, 0, 0);
    quatf prevRotation(qidentity<float>());
    if(m_rigid_body) {
        prevCenter = m_rigid_body->collision_shape()->center();
        prevRotation = m_rigid_body->collision_shape()->rotation();
    }*/

    collision_shape_t::pointer  collision_shape;
	
    if(plgCollisionShape.isConnected()) {
        MPlugArray connections;
        plgCollisionShape.connectedTo(connections, true, true);
        if(connections.length() != 0) {
            MFnDependencyNode fnNode(connections[0].node());
            if(fnNode.typeId() == collisionShapeNode::typeId) {
				collisionShapeNode *pCollisionShapeNode = static_cast<collisionShapeNode*>(fnNode.userNode());
				pCollisionShapeNode->setCollisionMarginOffset(collisionMarginOffset); //mb
                collision_shape = pCollisionShapeNode->collisionShape();
            } else {
                std::cout << "rigidBodyNode connected to a non-collision shape node!" << std::endl;
            }
        }
    }

	data.outputValue(ca_rigidBody).set(true);
    data.setClean(plug);
}
Exemple #8
0
void rigidBodyNode::computeRigidBodyParam(const MPlug& plug, MDataBlock& data)
{
	// std::cout << "(rigidBodyNode::computeRigidBodyParam) | " << std::endl;
	if (!m_rigid_body)
		return;

    MObject thisObject(thisMObject());
    MObject update;
    
    MPlug(thisObject, ca_rigidBody).getValue(update);
    double mass = data.inputValue(ia_mass).asDouble();

	bool changedMassStatus= false;
	float curMass = m_rigid_body->get_mass();
	if ((curMass > 0.f) != (mass > 0.f))
	{
		changedMassStatus = true;
	}
	if (changedMassStatus)
		solver_t::remove_rigid_body(m_rigid_body);

	m_rigid_body->set_mass((float)mass);
	m_rigid_body->set_inertia((float)mass * m_rigid_body->collision_shape()->local_inertia());

	if (changedMassStatus)
		solver_t::add_rigid_body(m_rigid_body,name().asChar());

	m_rigid_body->set_restitution((float)data.inputValue(ia_restitution).asDouble());
    m_rigid_body->set_friction((float)data.inputValue(ia_friction).asDouble());
    m_rigid_body->set_linear_damping((float)data.inputValue(ia_linearDamping).asDouble());
    m_rigid_body->set_angular_damping((float)data.inputValue(ia_angularDamping).asDouble());

    data.outputValue(ca_rigidBodyParam).set(true);
    data.setClean(plug);
}
void kgLocator::draw( M3dView & view, const MDagPath & path, 
					 M3dView::DisplayStyle style, M3dView::DisplayStatus status )
{
	MStatus stat;

	//First get the value of the height attribute
	//of the assocuated locator
	MObject thisNode = thisMObject();
	MFnDagNode dagFn( thisNode  );  	
	MPlug heightPlug = dagFn.findPlug( height, &stat );
	float heightValue;
	heightPlug.getValue( heightValue );
		
	view.beginGL();
	glPushAttrib( GL_CURRENT_BIT );
	
	
	glBegin( GL_LINES );
	//Draw a cross
	for(unsigned int i=0; i < pts.length(); i+= 2 )
	{
		glVertex3f(pts[i].x, pts[i].y, pts[i].z );
		glVertex3f(pts[i+1].x, pts[i+1].y, pts[i+1].z );
	}
	//And a vertical spindle
	//of the same height as 
	//the height attribute
	glVertex3f( 0.0f, 0.0f, 0.0f );
	glVertex3f( 0.0f, heightValue, 0.0f );
	
	glEnd();
	
	glPopAttrib();
	view.endGL();
}
Exemple #10
0
MBoundingBox kgLocator::boundingBox() const
{
	MBoundingBox bbox;
	MPoint pt;
	MStatus stat;
	
	MObject thisNode = thisMObject();
	MFnDagNode dagFn( thisNode  );  
	
	MPlug heightPlug = dagFn.findPlug( height, &stat );
	float heightValue;
	heightPlug.getValue( heightValue );
	
	for(unsigned int i=0; i < pts.length(); ++i )
	{
		pt.x = pts[i].x; pt.y = pts[i].y; pt.z = pts[i].z;
		bbox.expand( pt );
	}
	//account for the vertical spindle
	pt.x=0.0; pt.y = 0.0f; pt.z = 0.0f;
	bbox.expand( pt );
	pt.x=0.0; pt.y = heightValue; pt.z = 0.0f;
	bbox.expand( pt );

	return bbox;
}
//
//	This method allows the custom transform to apply its own locking
//	mechanism to rotation. Standard dependency graph attribute locking
//	happens automatically and cannot be modified by custom nodes.
//	If the plug should not be changed, then the value from the passed savedR
//	argument should be return to be used in the transformation matrix.
//
MEulerRotation rockingTransformCheckNode::applyRotationLocks(const MEulerRotation &toTest,
									const MEulerRotation &savedRotation,
									MStatus *ReturnStatus )
{
#ifdef ALLOW_DG_TO_HANDLE_LOCKS
	// Allow the DG to handle locking.
	return toTest;
#else
	//
	// Implement a simple lock by checking for an existing attribute
	// Use the following MEL to add the attribute:
	//	addAttr -ln "rotateLockPlug"
	//
	MStatus status;
	MObject object = thisMObject();
	MFnDependencyNode depNode( object );
	MObject rotateLockPlug = depNode.findPlug( "rotateLockPlug", &status );

	// If the lock does not exist that we return the updated value that has
	// been passed in
	if ( rotateLockPlug.isNull() )
		return toTest;
	
	// We have a lock.  Returned the original saved value of the
	// rotation.
	return savedRotation;
#endif
}
void NuiMayaDeviceGrabber::addCallbacks()
{
	MStatus status;
	
	MObject node = thisMObject();
	fCallbackIds.append( MNodeMessage::addAttributeChangedCallback(node, attrChangedCB, (void*)this) );
}
// The compute() method does the actual work of the node using the inputs
// of the node to generate its output.
//
// Compute takes two parameters: plug and data.
// - Plug is the the data value that needs to be recomputed
// - Data provides handles to all of the nodes attributes, only these
//   handles should be used when performing computations.
//
MStatus affects::compute( const MPlug& plug, MDataBlock& data )
{
    MStatus status;
    MObject thisNode = thisMObject();
    MFnDependencyNode fnThisNode( thisNode );
    fprintf(stderr,"affects::compute(), plug being computed is \"%s\"\n",
            plug.name().asChar());

    if ( plug.partialName() == "B" ) {
        // Plug "B" is being computed. Assign it the value on plug "A"
        // if "A" exists.
        //
        MPlug pA = fnThisNode.findPlug( "A", &status );
        if ( MStatus::kSuccess == status ) {
            fprintf(stderr,"\t\t... found dynamic attribute \"A\", copying its value to \"B\"\n");
            MDataHandle inputData = data.inputValue( pA, &status );
            CHECK_MSTATUS( status );
            int value = inputData.asInt();

            MDataHandle outputHandle = data.outputValue( plug );
            outputHandle.set( value );
            data.setClean(plug);
        }
    } else {
        return MS::kUnknownParameter;
    }
    return( MS::kSuccess );
}
Exemple #14
0
// returns the list of files to archive.
MStringArray AlembicNode::getFilesToArchive(
    bool /* shortName */,
    bool unresolvedName,
    bool /* markCouldBeImageSequence */) const
{
    MStringArray files;
    MStatus status = MS::kSuccess;

    MPlug fileNamePlug(thisMObject(), mAbcFileNameAttr);
    MString fileName = fileNamePlug.asString(MDGContext::fsNormal, &status);

    if (status == MS::kSuccess && fileName.length() > 0) {
        if(unresolvedName)
        {
            files.append(fileName);
        }
        else
        {
            //unresolvedName is false, resolve the path via MFileObject.
            MFileObject fileObject;
            fileObject.setRawFullName(fileName);
            files.append(fileObject.resolvedFullName());
        }
    }

    return files;
}
sgBLocator_fromGeo::sgBLocator_fromGeo()
{
	m_pointArr.setLength(6);

 	m_pointArr[0] = MFloatPoint(  1,  0, 0 );
	m_pointArr[1] = MFloatPoint( -1,  0, 0 );
	m_pointArr[2] = MFloatPoint(  0, -1, 0 );
	m_pointArr[3] = MFloatPoint(  0,  1, 0 );
	m_pointArr[4] = MFloatPoint(  0,  0, 1 );
	m_pointArr[5] = MFloatPoint(  0,  0, -1 );

	m_boundingBox.clear();
    m_boundingBox.expand( MVector( 1.0, 1.0, 1.0 ) );
    m_boundingBox.expand( MVector( -1.0, -1.0, -1.0 ) );

	m_colorActive =  MColor( 1.0f, 1.0f, 1.0f );
	m_colorLead   =	 MColor( .26f, 1.0f, .64f );
	m_colorDefault = MColor( 1.0f, 1.0f, 0.0f );

	m_lineWidth = 1;

	MFnDependencyNode fnNode( thisMObject() );
	MPlug plugOutput = fnNode.findPlug( aOutputValue );
	MPlug plugVis    =fnNode.findPlug( "v" );

	MDGModifier dgModifier;
	dgModifier.connect( plugOutput, plugVis );
}
Exemple #16
0
void ProxyViz::processPickInView(const int & plantTyp)
{
	useActiveView();
/// not needed?
//  _viewport.refresh();
	
	MObject node = thisMObject();
	
	MPlug gateHighPlg(node, alodgatehigh);
	float gateHigh = gateHighPlg.asFloat();
	
	MPlug gateLowPlg(node, alodgatelow);
	float gateLow = gateLowPlg.asFloat();
	
//	MPlug gcPlg(node, agroupcount);
//	int groupCount = gcPlg.asInt();
	
//	MPlug giPlg(node, ainstanceId);
//	int groupId = giPlg.asInt();
	
	MPlug perPlg(node, aconvertPercentage);
	double percentage = perPlg.asDouble();
	pickVisiblePlants(gateLow, gateHigh, percentage, plantTyp);
	AHelper::Info<int>("proxyviz picks up n visible plants", numActivePlants() );
}
Exemple #17
0
MStatus pnTriangles::getFloat3(MObject attr, float value[3])
{
	MStatus status;
	// Get the attr to use
	//
	MPlug	plug(thisMObject(), attr);

	MObject object;

	status = plug.getValue(object);
	if (!status)
	{
		status.perror("pnTrianglesNode::bind plug.getValue.");
		return status;
	}


	MFnNumericData data(object, &status);
	if (!status)
	{
		status.perror("pnTrianglesNode::bind construct data.");
		return status;
	}

	status = data.getData(value[0], value[1], value[2]);
	if (!status)
	{
		status.perror("pnTrianglesNode::bind get values.");
		return status;
	}

	return MS::kSuccess;
}
Exemple #18
0
// returns the list of files to archive.
MStringArray AlembicNode::getFilesToArchive(
    bool /* shortName */,
    bool unresolvedName,
    bool /* markCouldBeImageSequence */) const
{
    MStringArray files;
    MStatus status = MS::kSuccess;

    MPlug layerFilenamesPlug(thisMObject(), mAbcLayerFileNamesAttr);

    MFnStringArrayData fnSAD( layerFilenamesPlug.asMObject() );
	MStringArray layerFilenames = fnSAD.array();

	for( unsigned int i = 0; i < layerFilenames.length(); i++ )
	{
		MString fileName = layerFilenames[i];

		if (status == MS::kSuccess && fileName.length() > 0) {
			if(unresolvedName)
			{
				files.append(fileName);
			}
			else
			{
				//unresolvedName is false, resolve the path via MFileObject.
				MFileObject fileObject;
				fileObject.setRawFullName(fileName);
				files.append(fileObject.resolvedFullName());
			}
		}
	}

    return files;
}
void hingeConstraintNode::computeConstraintParam(const MPlug& plug, MDataBlock& data)
{
    //std::cout << "hingeConstraintNode::computeRigidBodyParam data.className=" << std::endl;

    MObject thisObject(thisMObject());
    MObject update;
    
    MPlug(thisObject, ca_constraint).getValue(update);
    if(m_constraint) {
		float damping = (float) data.inputValue(ia_damping).asDouble();
		m_constraint->set_damping(damping);
		float lower = (float) data.inputValue(ia_lowerLimit).asDouble();
		float upper = (float) data.inputValue(ia_upperLimit).asDouble();
		float limit_softness = (float) data.inputValue(ia_limitSoftness).asDouble();
		float bias_factor = (float) data.inputValue(ia_biasFactor).asDouble();
		float relaxation_factor = (float) data.inputValue(ia_relaxationFactor).asDouble();

		m_constraint->set_limit(lower, upper, limit_softness, bias_factor, relaxation_factor);

		float* axis = data.inputValue(ia_hingeAxis).asFloat3();
		m_constraint->set_axis(vec3f(axis[0], axis[1], axis[2]));

		bool enable_motor = data.inputValue(ia_enableAngularMotor).asBool();
		float motorTargetVelocity = (float) data.inputValue(ia_motorTargetVelocity).asDouble();
		float maxMotorImpulse = (float) data.inputValue(ia_maxMotorImpulse).asDouble();
		m_constraint->enable_motor(enable_motor, motorTargetVelocity, maxMotorImpulse);
    }

    data.outputValue(ca_constraintParam).set(true);
    data.setClean(plug);
}
void sixdofConstraintNode::computeConstraintParam(const MPlug& plug, MDataBlock& data)
{
   // std::cout << "sixdofConstraintNode::computeRigidBodyParam" << std::endl;

    MObject thisObject(thisMObject());
    MObject update;
    
    MPlug(thisObject, ca_constraint).getValue(update);
    if(m_constraint) {
        m_constraint->set_damping((float) data.inputValue(ia_damping).asDouble());
		m_constraint->set_breakThreshold((float) data.inputValue(ia_breakThreshold).asDouble());

		vec3f lowLin, uppLin, lowAng, uppAng;
		float3& mLowLin = data.inputValue(ia_lowerLinLimit).asFloat3();
		float3& mUppLin = data.inputValue(ia_upperLinLimit).asFloat3();
		float3& mLowAng = data.inputValue(ia_lowerAngLimit).asFloat3();
		float3& mUppAng = data.inputValue(ia_upperAngLimit).asFloat3();
		for(int j = 0; j < 3; j++) 
		{
			lowLin[j] = mLowLin[j];
			uppLin[j] = mUppLin[j];
			lowAng[j] = deg2rad(mLowAng[j]);
			uppAng[j] = deg2rad(mUppAng[j]);
		}
		m_constraint->set_LinLimit(lowLin, uppLin);
		m_constraint->set_AngLimit(lowAng, uppAng);
    }

    data.outputValue(ca_constraintParam).set(true);
    data.setClean(plug);
}
void curvedArrows::draw( M3dView & view, const MDagPath & /*path*/, 
							 M3dView::DisplayStyle style,
							 M3dView::DisplayStatus status )
{ 
	// Get the size
	//
	MObject thisNode = thisMObject();
	MPlug tPlug = MPlug( thisNode, aTransparency ); 
	MPlug cPlug = MPlug( thisNode, aTheColor ); 

	float r, g, b, a; 
	MObject color; 

	cPlug.getValue( color ); 
	MFnNumericData data( color ); 
	data.getData( r, g, b ); 
	tPlug.getValue( a ); 

	view.beginGL(); 

	if( (style == M3dView::kFlatShaded) ||
	    (style == M3dView::kGouraudShaded) ) {
		// Push the color settings
		// 
		glPushAttrib( GL_COLOR_BUFFER_BIT | GL_CURRENT_BIT | GL_ENABLE_BIT | 
					  GL_PIXEL_MODE_BIT ); 
	
		if ( a < 1.0f ) { 
			glEnable( GL_BLEND );
			glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
		}
		
		glColor4f( r, g, b, a );			
	
		glBegin( GL_TRIANGLES ); 
		unsigned int i;
		for ( i = 0; i < fsFaceListSize; i ++ ) { 
			unsigned int *vid = fsFaceList[i];
			unsigned int *nid = fsFaceVertexNormalList[i]; 
			for ( unsigned int j = 0; j < 3; j ++ ) { 
				glNormal3d( fsNormalList[nid[j]-1][0], 
							fsNormalList[nid[j]-1][1], 
							fsNormalList[nid[j]-1][2] );
				glVertex3d( fsVertexList[vid[j]-1][0], 
							fsVertexList[vid[j]-1][1],
							fsVertexList[vid[j]-1][2] ); 
			}
		}
		glEnd(); 
	
		glPopAttrib(); 

		drawEdgeLoop( view, status ); 
	} else { 
		drawEdgeLoop( view, status ); 
	}

	view.endGL(); 
}
Exemple #22
0
void BasicLocator::postConstructor()
{
	//rename the locator shape post construction
	MObject oThis = thisMObject();
	MFnDependencyNode fnNode(oThis);
	fnNode.setName("basicLocator#");

}
collision_shape_t::pointer collisionShapeNode::collisionShape()
{
	MObject thisObject(thisMObject());
	MObject update;
	MPlug(thisObject, oa_collisionShape).getValue(update);
	MPlug(thisObject, ca_collisionShapeParam).getValue(update);
	return m_collision_shape;
}
bool curvedArrows::drawLast() const
{
    MObject thisNode = thisMObject();
    MPlug plug( thisNode, aEnableDrawLast );
    bool value;
    plug.getValue( value );
    return value;
}
Exemple #25
0
bool BasicLocator::isTransparent() const
{
	MPlug plug(thisMObject(), aIsTransparent);
	bool value;
	plug.getValue(value);
	return value;

}
bool curvedArrows::isTransparent( ) const
{
	MObject thisNode = thisMObject(); 
	MPlug plug( thisNode, aEnableTransparencySort ); 
	bool value; 
	plug.getValue( value ); 
	return value; 
}
Exemple #27
0
void nailConstraintNode::update()
{
    MObject thisObject(thisMObject());

    MObject update;
    MPlug(thisObject, ca_constraint).getValue(update);
    MPlug(thisObject, ca_constraintParam).getValue(update);
    MPlug(thisObject, worldMatrix).elementByLogicalIndex(0).getValue(update);
}
Exemple #28
0
soft_body_t::pointer SoftBodyNode::soft_body()
{
	MObject thisObject(thisMObject());
	MObject update;
	MPlug(thisObject, ca_softBody).getValue(update);
	MPlug(thisObject, ca_softBodyParam).getValue(update);

	return this->m_soft_body;
}
Exemple #29
0
void ProxyViz::pressToLoad()
{
	MObject thisNode = thisMObject();
	MPlug plugc( thisNode, acachename );
	const MString filename = plugc.asString();
	if(filename != "")
		loadExternal(replaceEnvVar(filename).c_str());
	else 
		AHelper::Info<int>("ProxyViz error empty external cache filename", 0);
}
Exemple #30
0
MBoundingBox nailConstraintNode::boundingBox() const
{
    // std::cout << "nailConstraintNode::boundingBox()" << std::endl;
    //load the pdbs
    MObject node = thisMObject();

    MPoint corner1(-1, -1, -1);
    MPoint corner2(1, 1, 1);
    return MBoundingBox(corner1, corner2);
}