Ejemplo n.º 1
0
int CreateSubTreeWithNopCubes( CRef& parentNode, CString& nodeName, CString& path, CString& identifier, int subLevels, int childrenPerLevel, int operatorsPerNode )
{
	X3DObject parentX3DObject(parentNode);
	X3DObject meshObj;

	parentX3DObject.AddGeometry(L"Cube",L"MeshSurface",nodeName,meshObj);
	CRef newNode = meshObj.GetRef();

	CRef realTarget = meshObj.GetActivePrimitive().GetRef();

	for( int i = 0; i < operatorsPerNode; i ++ ) {
		CustomOperator op = Application().GetFactory().CreateObject("exocortex_nop");
		op.AddOutputPort(realTarget);
		op.AddInputPort(realTarget);

		siConstructionMode consMode = siConstructionModeModeling;
		op.Connect(consMode);

		op.PutParameterValue(L"path",path);
		op.PutParameterValue(L"identifier",identifier);
	}

	int numNodes = 1;

	if( subLevels > 0 ) {
		for( int i = 0; i < childrenPerLevel; i ++ ) {
			std::stringstream s;
			s << "node_level" << subLevels << "_child" << i;
			CString childNodeName( s.str().c_str() );
			numNodes += CreateSubTreeWithNopCubes( newNode, childNodeName, path, identifier, subLevels - 1, childrenPerLevel, operatorsPerNode );
		}
	}

	return numNodes ;
}
Ejemplo n.º 2
0
XSIPLUGINCALLBACK CStatus apply_MomentumConsBallSocket_Execute( CRef& in_ctxt )

{

   Context ctxt( in_ctxt );

   Selection l_pSelection = Application().GetSelection();

   // you need to select TWO objects
   if(l_pSelection.GetCount() != 2)
   {
      Application().LogMessage(L"[MOMENTUM] You need to select TWO rigid bodies.",siErrorMsg);
      return CStatus::Abort;
   }

   X3DObject obj1(l_pSelection.GetItem(0));

   X3DObject obj2(l_pSelection.GetItem(1));
   CRef opRef1,opRef2;
   opRef1.Set(obj1.GetFullName()+L".kine.global.MomentumKinematics");
   if(!opRef1.IsValid())

      opRef1.Set(obj1.GetFullName()+L".polymsh.MomentumDeform");
   opRef2.Set(obj2.GetFullName()+L".kine.global.MomentumKinematics");
   if(!opRef2.IsValid())

      opRef2.Set(obj2.GetFullName()+L".polymsh.MomentumDeform");
   if(!opRef1.IsValid())
   {
      Application().LogMessage(L"[MOMENTUM] Object "+obj1.GetFullName()+L" is not a bullet rigid body.",siErrorMsg);
      return CStatus::Abort;

   }
   if(!opRef2.IsValid())
   {
      Application().LogMessage(L"[MOMENTUM] Object "+obj1.GetFullName()+L" is not a bullet rigid body.",siErrorMsg);
      return CStatus::Abort;

   }

   // get the transform for the cons
   CTransformation xfA = obj1.GetKinematics().GetGlobal().GetTransform();
   CTransformation xfB = obj2.GetKinematics().GetGlobal().GetTransform();
   CVector3 trans;
   trans.LinearlyInterpolate(xfA.GetTranslation(),xfB.GetTranslation(),0.5);
   xfA.SetTranslation(trans);

   // create the constraint object
   Null consNull1;
   obj1.AddNull(L"BallSocket_pivot",consNull1);
   consNull1.GetKinematics().GetGlobal().PutTransform(xfA);
   consNull1.GetActivePrimitive().PutParameterValue(L"primary_icon", (LONG)2);

   // create the operator

   CustomOperator newOp = Application().GetFactory().CreateObject(L"MomentumConsBallSocket");

   newOp.AddOutputPort(consNull1.GetKinematics().GetGlobal().GetRef());

   newOp.AddInputPort(consNull1.GetKinematics().GetGlobal().GetRef());

   newOp.AddInputPort(obj1.GetKinematics().GetGlobal().GetRef());

   newOp.AddInputPort(obj2.GetKinematics().GetGlobal().GetRef());

   newOp.AddInputPort(opRef1);

   newOp.AddInputPort(opRef2);

   newOp.Connect();

   // set the expression for the frame!
   CValueArray args(2);
   CValue returnVal;
   args[0] = newOp.GetFullName()+L".frame";
   args[1] = L"fc";
   Application().ExecuteCommand(L"SetExpr",args,returnVal);

   return CStatus::OK;

}