SICALLBACK VDB_Node_VolumeToMesh_BeginEvaluate(ICENodeContext& ctxt)
{
   Application().LogMessage(L"[VDB_Node_VolumeToMesh] BeginEvaluate");

   CValue userData = ctxt.GetUserData();
   VDB_Node_VolumeToMesh* vdbNode;
   if (userData.IsEmpty())
   {
      vdbNode = new VDB_Node_VolumeToMesh;
   }
   else
   {
      vdbNode = (VDB_Node_VolumeToMesh*)(CValue::siPtrType)userData;
   }

   CICEPortState vdbGridPortState(ctxt, kVDBGrid);
   CICEPortState isoPortState(ctxt, kIsoValue);
   CICEPortState adaptPortState(ctxt, kAdaptivity);

   bool vdbGridDirty = vdbGridPortState.IsDirty(CICEPortState::siAnyDirtyState);
   bool isoDirty = isoPortState.IsDirty(CICEPortState::siAnyDirtyState);
   bool adaptDirty = adaptPortState.IsDirty(CICEPortState::siAnyDirtyState);

   vdbGridPortState.ClearState();
   isoPortState.ClearState();
   adaptPortState.ClearState();

   if (vdbGridDirty || isoDirty || adaptDirty)
   {
      vdbNode->Cache(ctxt);
   }

   ctxt.PutUserData((CValue::siPtrType)vdbNode);
   return CStatus::OK;
}
SICALLBACK VDB_Node_VolumeToMesh_EndEvaluate(ICENodeContext& ctxt)
{
   CValue userData = ctxt.GetUserData();
   VDB_Node_VolumeToMesh* vdbNode;
   vdbNode = (VDB_Node_VolumeToMesh*)(CValue::siPtrType)userData;
	
	if(!vdbNode->IsValid())
	{
      delete vdbNode;
		ctxt.PutUserData(CValue());
	}

	return CStatus::OK;
}
Ejemplo n.º 3
0
XSIPLUGINCALLBACK CStatus ToonixGetData_BeginEvaluate( ICENodeContext& in_ctxt )
{
	// Get User Data
	TXData* data = (TXData*)(CValue::siPtrType)in_ctxt.GetUserData( );
	CDataArrayBool cullingData(in_ctxt, ID_IN_CameraCulling);
	int dirtyState = GetToonixDataDirtyState(in_ctxt,cullingData[0]);
	
	if(!dirtyState)return CStatus::OK;

	// Get geometry object from the input port
	CICEGeometry geom( in_ctxt, ID_IN_Geometry );

	// Get Camera Datas
	CDataArrayMatrix4f matrixData(in_ctxt, ID_IN_CameraGlobal);
	CDataArrayFloat fovData(in_ctxt, ID_IN_CameraFov);
	CDataArrayFloat aspectData(in_ctxt, ID_IN_CameraAspect);
	CDataArrayFloat nearData(in_ctxt, ID_IN_CameraNear);
	CDataArrayFloat farData(in_ctxt, ID_IN_CameraFar);
	CDataArrayBool octreeData(in_ctxt, ID_IN_UseOctree);

	data->SetCulling(cullingData[0]);
	data->SetCamera(matrixData[0],fovData[0],aspectData[0],nearData[0],farData[0]);

	if(dirtyState == 1)
	{
		bool bTopologyDirtyState = geom.IsDirty( CICEGeometry::siTopologyDirtyState );
		geom.ClearState();

		data->Init(geom, bTopologyDirtyState);
	}

	data->Update(geom, octreeData[0]);

	return CStatus::OK;
}
Ejemplo n.º 4
0
XSIPLUGINCALLBACK CStatus nest_GetPositionArray_Evaluate( ICENodeContext& in_ctxt )
{
   // The current output port being evaluated...
   ULONG out_portID = in_ctxt.GetEvaluatedOutputPortID( );

   switch( out_portID )
   {
      case Array_ID_OUT_Result:
      {
         // Get the output port array ...
         CDataArray2DVector3f outData( in_ctxt );

         // Get the input data buffers for each port
         CDataArrayVector3f InData( in_ctxt, Array_ID_IN_Vector );

         // We need a CIndexSet to iterate over the data
         LONG count = InData.GetCount();
         outData.Resize(0,InData.GetCount());

         for(LONG i=0;i<count;i++)
            outData[0][i] = InData[i];
      }
      break;

      // Other output ports...

   };

   return CStatus::OK;
}
Ejemplo n.º 5
0
SICALLBACK ToonixLighter_Evaluate( ICENodeContext& in_ctxt )
{
	// Get User Data
	TXLight* light = (TXLight*)(CValue::siPtrType)in_ctxt.GetUserData( );

	// The current output port being evaluated...
	LONG out_portID = in_ctxt.GetEvaluatedOutputPortID( );

	switch( out_portID )
	{	
		case ID_OUT_Vertices:
		{
			// Get the output port array ...			
			CDataArray2DVector3f outData( in_ctxt );

			CDataArray2DVector3f::Accessor outDataSubArray = outData.Resize(0,light->_nbv);
			for(ULONG n=0;n<light->_nbv;n++)
			{
				outDataSubArray[n].Set(light->_vertices[n].GetX(),light->_vertices[n].GetY(),light->_vertices[n].GetZ());
			}
			
		}
		break;

		case ID_OUT_Polygons:
		{
			// Get the output port array ...			
			CDataArray2DLong outData( in_ctxt );	

			CDataArray2DLong::Accessor outDataSubArray = outData.Resize(0,light->_nbp);
			for(ULONG n=0;n<light->_nbp;n++)
			{
				outDataSubArray[n] = light->_polygons[n];
			}
		}
		break;
	}
	return CStatus::OK;
}
Ejemplo n.º 6
0
SICALLBACK ToonixCurve_Evaluate(ICENodeContext& in_ctxt)
{
	// Get User Data
	TXLine* line = (TXLine*)(CValue::siPtrType)in_ctxt.GetUserData();

	// Get the output port array ...			
	CDataArrayCustomType outData(in_ctxt);

	XSI::CDataArrayCustomType::TData* pOutData = outData.Resize(0, sizeof(TXLine));
	::memcpy(pOutData, line, sizeof(TXLine));

	return CStatus::OK;
}
Ejemplo n.º 7
0
XSIPLUGINCALLBACK CStatus ToonixGetData_Evaluate( ICENodeContext& in_ctxt )
{
	// Get User Data
	TXData* data = (TXData*)(CValue::siPtrType)in_ctxt.GetUserData( );

	// The current output port being evaluated...
	LONG out_portID = in_ctxt.GetEvaluatedOutputPortID( );

	switch( out_portID )
	{	
		case ID_OUT_ToonixData :
		{
			//Application().LogMessage(L"Toonix Get Data :: Nb Crease Edges : "+(CString)(ULONG)data->_geom->_creases.size());
			// Get the output port array ...			
			CDataArrayCustomType outData( in_ctxt );
			
			XSI::CDataArrayCustomType::TData* pOutData = outData.Resize(0,sizeof(TXData));
			::memcpy( pOutData, data, sizeof(TXData) );   

		}break;
	}

	return CStatus::OK;
}
Ejemplo n.º 8
0
SICALLBACK MOM_GetContactPoints_Evaluate( ICENodeContext& in_ctxt )
{
	// The current output port being evaluated...
	ULONG out_portID = in_ctxt.GetEvaluatedOutputPortID( );

	switch( out_portID )
	{
		case ID_OUT_Contacts :
		{
			// Get the output port array ...
			CDataArray2DMatrix3f outData( in_ctxt );

         // see if we have a simulation
         if(gSimulation == NULL)
         {
            // we will need to resize to nothing
            outData.Resize(0,0);
            return CStatus::OK;
         }

 			// Get the input data buffers for each port
			CDataArrayLong modeData( in_ctxt, ID_IN_mode );
			CDataArrayFloat minImpulseData( in_ctxt, ID_IN_minImpulse_id );


         // ask the dynamics world for the contact points
         btAlignedObjectArray<btVector3> pos,vel;
         gSimulation->GetContactPoints(&pos,&vel,(int)modeData[0],minImpulseData[0]);

         // resize the output and fill out the matrices
         outData.Resize(0,pos.size());
         for(size_t i=0;i<pos.size();i++)
         {
            outData[0][i].Set(pos[i].getX(),pos[i].getY(),pos[i].getZ(),
                              vel[i].getX(),vel[i].getY(),vel[i].getZ(),
                              0,0,0);

         }
		}
		break;

		// Other output ports...
	};

	return CStatus::OK;
}
Ejemplo n.º 9
0
SICALLBACK aaOcean_BeginEvaluate( ICENodeContext& in_ctxt )
{
    // get ocean pointer from user-data
    aaOcean *pOcean = (aaOcean *)(CValue::siPtrType)in_ctxt.GetUserData();

    // get ICE node input port arrays
    CDataArrayLong PointID( in_ctxt, ID_IN_PointID);
    CDataArrayLong resolution( in_ctxt, ID_IN_RESOLUTION);      
    CDataArrayLong seed( in_ctxt, ID_IN_SEED);
    CDataArrayFloat waveHeight( in_ctxt, ID_IN_WAVE_HEIGHT);
    CDataArrayFloat waveSpeed( in_ctxt, ID_IN_WAVESPEED);
    CDataArrayFloat chop( in_ctxt, ID_IN_CHOP);
    CDataArrayFloat oceanScale( in_ctxt, ID_IN_OCEAN_SCALE );
    CDataArrayFloat oceanDepth( in_ctxt, ID_IN_OCEAN_DEPTH );
    CDataArrayFloat windDir( in_ctxt, ID_IN_WINDDIR );
    CDataArrayFloat cutoff( in_ctxt, ID_IN_CUTOFF);
    CDataArrayFloat velocity( in_ctxt, ID_IN_WINDVELOCITY);
    CDataArrayLong  windAlign( in_ctxt, ID_IN_WINDALIGN );
    CDataArrayFloat damp( in_ctxt, ID_IN_DAMP);
    CDataArrayBool enableFoam( in_ctxt, ID_IN_ENABLEFOAM);
    CDataArrayFloat time( in_ctxt, ID_IN_TIME);
    CDataArrayFloat loopTime( in_ctxt, ID_IN_REPEAT_TIME);
    CDataArrayFloat surfaceTension( in_ctxt, ID_IN_SURFACE_TENSION);
    CDataArrayFloat randWeight( in_ctxt, ID_IN_RAND_WEIGHT);

    pOcean->input(resolution[0], 
        seed[0],
        oceanScale[0], 
        oceanDepth[0],
        surfaceTension[0],
        velocity[0], 
        cutoff[0], 
        windDir[0], 
        windAlign[0], 
        damp[0], 
        waveSpeed[0], 
        waveHeight[0],
        chop[0], 
        time[0],
        loopTime[0],
        enableFoam[0],
        randWeight[0]);

    return CStatus::OK;
}
Ejemplo n.º 10
0
SICALLBACK MOM_AddToCluster_Evaluate( ICENodeContext& in_ctxt )
{
	// The current output port being evaluated...
   ULONG out_portID = in_ctxt.GetEvaluatedOutputPortID( );

   if(gSimulation == NULL)
      return CStatus::OK;

	switch( out_portID )
	{
		case ID_OUT_base:
		{
         CDataArrayLong baseData( in_ctxt, ID_IN_base );
         CDataArrayLong idData( in_ctxt, ID_IN_id );
         CDataArrayLong clusterData( in_ctxt, ID_IN_cluster );
         rbdID rbd_ID,cluster_ID;
         CIndexSet indexSet( in_ctxt );

			// Get the output port array ...
			CDataArrayLong outData( in_ctxt );

			for(CIndexSet::Iterator it = indexSet.Begin(); it.HasNext(); it.Next())
			{
            rbd_ID.primary = (int)(baseData.IsConstant() ? baseData[0] : baseData[it]);
            rbd_ID.secondary = (int)(idData.IsConstant() ? idData[0] : idData[it]);
            cluster_ID.primary = rbd_ID.primary;
            cluster_ID.secondary = (int)(clusterData.IsConstant() ? clusterData[0] : clusterData[it]);
            btRigidBodyReference * bodyRef = gSimulation->GetRigidBody(rbd_ID);
            btRigidBodyReference * clusterRef = gSimulation->GetRigidBody(cluster_ID);

            if(bodyRef != NULL && clusterRef != NULL)
            {
               bodyRef->AddToCluster(clusterRef);
            }
            outData[it] = rbd_ID.primary;
			}
         break;
		}
	};

	return CStatus::OK;
}
Ejemplo n.º 11
0
SICALLBACK ToonixLighter_BeginEvaluate( ICENodeContext& in_ctxt )
{
	TXLight* light = NULL;
	CValue userData = in_ctxt.GetUserData();

	if(userData.IsEmpty())
	{
		// Build a new Light Object
		light = new TXLight();

		// Get the input TXGeometry
		CDataArrayCustomType ToonixData( in_ctxt, ID_IN_ToonixData );

		CDataArrayCustomType::TData* pBufferToonixData;
		ULONG nSizeToonixData;
		ToonixData.GetData( 0,(const CDataArrayCustomType::TData**)&pBufferToonixData, nSizeToonixData );
		TXData* data = (TXData*)pBufferToonixData;
		light->_geom = data->_geom;


		in_ctxt.PutUserData((CValue::siPtrType)light);
	}
	else
	{
		light = (TXLight*)(CValue::siPtrType)in_ctxt.GetUserData( );
	}

	if(GetLighterDirtyState(in_ctxt))
	{
		//Application().LogMessage(L"Toonix Lighter >State Dirty...");
		// Get lights positions used for light detection
		light->_lights.clear();
		
		siICENodeDataType inPortType;
		siICENodeStructureType inPortStruct;
		siICENodeContextType inPortContext;

		in_ctxt.GetPortInfo( ID_IN_LightPosition, inPortType, inPortStruct, inPortContext );
		if ( inPortStruct == XSI::siICENodeStructureSingle )
		{
			//Application().LogMessage(L"ONE Light");
			CDataArrayVector3f lightPointData( in_ctxt, ID_IN_LightPosition );
			light->_lights.push_back(lightPointData[0]);
			light->_nbl = 1;
		}
		else if ( inPortStruct == XSI::siICENodeStructureArray )
		{
			//Application().LogMessage(L"MULTI Lights");
			CDataArray2DVector3f lightPointsData( in_ctxt, ID_IN_LightPosition );
			CDataArray2DVector3f::Accessor lightPointData = lightPointsData[0];
			light->_nbl = lightPointData.GetCount();

			for(LONG l=0;l<light->_nbl;l++)
			{
				light->_lights.push_back(lightPointData[l]);
			}
		}

		light->_bias.resize(light->_nbl);

		in_ctxt.GetPortInfo( ID_IN_LightBias, inPortType, inPortStruct, inPortContext );
		if ( inPortStruct == XSI::siICENodeStructureSingle )
		{
			CDataArrayFloat lightBiasData( in_ctxt, ID_IN_LightBias );
			light->_bias[0] = lightBiasData[0];
		}
		else if ( inPortStruct == XSI::siICENodeStructureArray )
		{
			CDataArray2DFloat lightPointsData( in_ctxt, ID_IN_LightBias );
			CDataArray2DFloat::Accessor lightPointData = lightPointsData[0];
			ULONG nbl = lightPointData.GetCount();

			for(LONG l=0;l<nbl&&l<light->_nbl;l++)
			{
				light->_bias[l] = lightPointData[l];
			}
		}

		light->_distance.resize(light->_nbl);

		in_ctxt.GetPortInfo( ID_IN_LightDistance, inPortType, inPortStruct, inPortContext );
		if ( inPortStruct == XSI::siICENodeStructureSingle )
		{
			CDataArrayFloat lightDistanceData( in_ctxt, ID_IN_LightDistance );
			light->_distance[0] = lightDistanceData[0];
		}
		else if ( inPortStruct == XSI::siICENodeStructureArray )
		{
			CDataArray2DFloat lightDistancesData( in_ctxt, ID_IN_LightDistance );
			CDataArray2DFloat::Accessor lightDistanceData = lightDistancesData[0];
			ULONG nbl = lightDistanceData.GetCount();

			for(LONG l=0;l<nbl&&l<light->_nbl;l++)
			{
				light->_distance[l] = lightDistanceData[l];
			}
		}

		CDataArrayBool revertData( in_ctxt, ID_IN_Revert );
		light->_reverse = revertData[0];
		CDataArrayFloat pushData( in_ctxt, ID_IN_Push );
		light->_push = pushData[0];

		CDataArrayVector3f viewData( in_ctxt, ID_IN_ViewPosition );
		light->_view = viewData[0];

		light->Build();

		in_ctxt.PutUserData((CValue::siPtrType)light);
	}
	return CStatus::OK;
}
Ejemplo n.º 12
0
SICALLBACK MOM_GetAttributes_Evaluate( ICENodeContext& in_ctxt )
{
	// The current output port being evaluated...
   ULONG out_portID = in_ctxt.GetEvaluatedOutputPortID( );
   CDataArrayLong baseData( in_ctxt, ID_IN_base );
   CDataArrayLong idData( in_ctxt, ID_IN_id );
   rbdID rbd_ID;
   CIndexSet indexSet( in_ctxt );

   if(gSimulation == NULL)
      return CStatus::OK;

	switch( out_portID )
	{
		case ID_OUT_position :
		{
			// Get the output port array ...
			CDataArrayVector3f outData( in_ctxt );

         // get the index set iterator
         btTransform bodyTransform;
         btVector3 bodyPos;
			for(CIndexSet::Iterator it = indexSet.Begin(); it.HasNext(); it.Next())
			{
            rbd_ID.primary = (int)(baseData.IsConstant() ? baseData[0] : baseData[it]);
            rbd_ID.secondary = (int)(idData.IsConstant() ? idData[0] : idData[it]);
            btRigidBodyReference * bodyRef = gSimulation->GetRigidBody(rbd_ID);
            if(bodyRef != NULL)
            {
               bodyRef->body->getMotionState()->getWorldTransform(bodyTransform);
               bodyPos = bodyTransform.getOrigin();
               outData[it] = CVector3f(bodyPos.getX(),bodyPos.getY(),bodyPos.getZ());
            }
			}
         break;
		}
		case ID_OUT_orientation :
		{
			// Get the output port array ...
			CDataArrayVector3f outData( in_ctxt );

         // get the index set iterator
         btTransform bodyTransform;
         btQuaternion bodyRot;
			CRotation rot;
			CVector3 angles;
			for(CIndexSet::Iterator it = indexSet.Begin(); it.HasNext(); it.Next())
			{
            rbd_ID.primary = (int)(baseData.IsConstant() ? baseData[0] : baseData[it]);
            rbd_ID.secondary = (int)(idData.IsConstant() ? idData[0] : idData[it]);
            btRigidBodyReference * bodyRef = gSimulation->GetRigidBody(rbd_ID);
            if(bodyRef != NULL)
            {
               bodyTransform = bodyRef->GetWorldTransform();
               bodyRot = bodyTransform.getRotation();
               rot.SetFromQuaternion(CQuaternion(bodyRot.getW(),bodyRot.getX(),bodyRot.getY(),bodyRot.getZ()));
               angles = rot.GetXYZAngles();
               outData[it].Set(RadiansToDegrees(angles.GetX()),RadiansToDegrees(angles.GetY()),RadiansToDegrees(angles.GetZ()));
            }
			}
         break;
		}
		case ID_OUT_linvelocity:
		{
			// Get the output port array ...
			CDataArrayVector3f outData( in_ctxt );

         // get the index set iterator
         btVector3 linvel;
			for(CIndexSet::Iterator it = indexSet.Begin(); it.HasNext(); it.Next())
			{
            rbd_ID.primary = (int)(baseData.IsConstant() ? baseData[0] : baseData[it]);
            rbd_ID.secondary = (int)(idData.IsConstant() ? idData[0] : idData[it]);
            btRigidBodyReference * bodyRef = gSimulation->GetRigidBody(rbd_ID);
            if(bodyRef != NULL)
            {
               linvel = bodyRef->body->getLinearVelocity();
               outData[it].Set(linvel.getX(),linvel.getY(),linvel.getZ());
            }
			}
         break;
		}
		case ID_OUT_angvelocity:
		{
			// Get the output port array ...
			CDataArrayVector3f outData( in_ctxt );

         // get the index set iterator
         btVector3 angvel;
			for(CIndexSet::Iterator it = indexSet.Begin(); it.HasNext(); it.Next())
			{
            rbd_ID.primary = (int)(baseData.IsConstant() ? baseData[0] : baseData[it]);
            rbd_ID.secondary = (int)(idData.IsConstant() ? idData[0] : idData[it]);
            btRigidBodyReference * bodyRef = gSimulation->GetRigidBody(rbd_ID);
            if(bodyRef != NULL)
            {
               angvel = bodyRef->body->getAngularVelocity();
               outData[it].Set(angvel.getX(),angvel.getY(),angvel.getZ());
            }
			}
         break;
		}
		case ID_OUT_state:
		{
			// Get the output port array ...
			CDataArrayLong outData( in_ctxt );

         // get the index set iterator
			for(CIndexSet::Iterator it = indexSet.Begin(); it.HasNext(); it.Next())
			{
            rbd_ID.primary = (int)(baseData.IsConstant() ? baseData[0] : baseData[it]);
            rbd_ID.secondary = (int)(idData.IsConstant() ? idData[0] : idData[it]);
            btRigidBodyReference * bodyRef = gSimulation->GetRigidBody(rbd_ID);
            if(bodyRef != NULL)
            {
               outData[it] = 0;
               if(bodyRef->body->getActivationState() == WANTS_DEACTIVATION)
                  outData[it] = 1;
               else if(bodyRef->body->getActivationState() == DISABLE_SIMULATION)
                  outData[it] = 2;
            }
			}
         break;
		}
		case ID_OUT_mass:
		{
			// Get the output port array ...
			CDataArrayFloat outData( in_ctxt );

         // get the index set iterator
			for(CIndexSet::Iterator it = indexSet.Begin(); it.HasNext(); it.Next())
			{
            rbd_ID.primary = (int)(baseData.IsConstant() ? baseData[0] : baseData[it]);
            rbd_ID.secondary = (int)(idData.IsConstant() ? idData[0] : idData[it]);
            btRigidBodyReference * bodyRef = gSimulation->GetRigidBody(rbd_ID);
            if(bodyRef != NULL)
               outData[it] = 1.0f / bodyRef->body->getInvMass();
			}
         break;
		}
		case ID_OUT_bounce:
		{
			// Get the output port array ...
			CDataArrayFloat outData( in_ctxt );

         // get the index set iterator
			for(CIndexSet::Iterator it = indexSet.Begin(); it.HasNext(); it.Next())
			{
            rbd_ID.primary = (int)(baseData.IsConstant() ? baseData[0] : baseData[it]);
            rbd_ID.secondary = (int)(idData.IsConstant() ? idData[0] : idData[it]);
            btRigidBodyReference * bodyRef = gSimulation->GetRigidBody(rbd_ID);
            if(bodyRef != NULL)
               outData[it] = bodyRef->body->getRestitution();
			}
         break;
		}
		case ID_OUT_friction:
		{
			// Get the output port array ...
			CDataArrayFloat outData( in_ctxt );

         // get the index set iterator
			for(CIndexSet::Iterator it = indexSet.Begin(); it.HasNext(); it.Next())
			{
            rbd_ID.primary = (int)(baseData.IsConstant() ? baseData[0] : baseData[it]);
            rbd_ID.secondary = (int)(idData.IsConstant() ? idData[0] : idData[it]);
            btRigidBodyReference * bodyRef = gSimulation->GetRigidBody(rbd_ID);
            if(bodyRef != NULL)
               outData[it] = bodyRef->body->getFriction();
			}
         break;
		}
		case ID_OUT_lindamping:
		{
			// Get the output port array ...
			CDataArrayFloat outData( in_ctxt );

         // get the index set iterator
			for(CIndexSet::Iterator it = indexSet.Begin(); it.HasNext(); it.Next())
			{
            rbd_ID.primary = (int)(baseData.IsConstant() ? baseData[0] : baseData[it]);
            rbd_ID.secondary = (int)(idData.IsConstant() ? idData[0] : idData[it]);
            btRigidBodyReference * bodyRef = gSimulation->GetRigidBody(rbd_ID);
            if(bodyRef != NULL)
               outData[it] = bodyRef->body->getLinearDamping();
			}
         break;
		}
		case ID_OUT_angdamping:
		{
			// Get the output port array ...
			CDataArrayFloat outData( in_ctxt );

         // get the index set iterator
			for(CIndexSet::Iterator it = indexSet.Begin(); it.HasNext(); it.Next())
			{
            rbd_ID.primary = (int)(baseData.IsConstant() ? baseData[0] : baseData[it]);
            rbd_ID.secondary = (int)(idData.IsConstant() ? idData[0] : idData[it]);
            btRigidBodyReference * bodyRef = gSimulation->GetRigidBody(rbd_ID);
            if(bodyRef != NULL)
               outData[it] = bodyRef->body->getAngularDamping();
			}
         break;
		}
		case ID_OUT_lintreshold:
		{
			// Get the output port array ...
			CDataArrayFloat outData( in_ctxt );

         // get the index set iterator
			for(CIndexSet::Iterator it = indexSet.Begin(); it.HasNext(); it.Next())
			{
            rbd_ID.primary = (int)(baseData.IsConstant() ? baseData[0] : baseData[it]);
            rbd_ID.secondary = (int)(idData.IsConstant() ? idData[0] : idData[it]);
            btRigidBodyReference * bodyRef = gSimulation->GetRigidBody(rbd_ID);
            if(bodyRef != NULL)
               outData[it] = bodyRef->body->getLinearSleepingThreshold();
			}
         break;
		}
		case ID_OUT_angtreshold:
		{
			// Get the output port array ...
			CDataArrayFloat outData( in_ctxt );

         // get the index set iterator
			for(CIndexSet::Iterator it = indexSet.Begin(); it.HasNext(); it.Next())
			{
            rbd_ID.primary = (int)(baseData.IsConstant() ? baseData[0] : baseData[it]);
            rbd_ID.secondary = (int)(idData.IsConstant() ? idData[0] : idData[it]);
            btRigidBodyReference * bodyRef = gSimulation->GetRigidBody(rbd_ID);
            if(bodyRef != NULL)
               outData[it] = bodyRef->body->getAngularSleepingThreshold();
			}
         break;
		}
	};

	return CStatus::OK;
}
Ejemplo n.º 13
0
SICALLBACK aaOcean_Evaluate( ICENodeContext& in_ctxt )
{
    aaOcean *pOcean = (aaOcean *)(CValue::siPtrType)in_ctxt.GetUserData();

    CIndexSet indexSet(in_ctxt, ID_IN_PointID );
    CDataArrayLong PointID(in_ctxt, ID_IN_PointID );
    CDataArrayBool bEnable(in_ctxt, ID_IN_ENABLE);
    CDataArrayFloat uCoord(in_ctxt, ID_IN_U);
    CDataArrayFloat vCoord(in_ctxt, ID_IN_V);
    CDataArrayBool enableFoam( in_ctxt, ID_IN_ENABLEFOAM);
    CDataArrayMatrix4f transform(in_ctxt, ID_IN_TRANSFORM);

    const int count = PointID.GetCount();

    float worldSpaceVec[3] = {0.0f, 0.0f, 0.0f};
    float localSpaceVec[3] = {0.0f, 0.0f, 0.0f};

    int transformArraySize = 0;
    bool transformSingleton = TRUE;

    if(transform.GetCount() > 1)
        transformSingleton = FALSE;

    ULONG out_portID = in_ctxt.GetEvaluatedOutputPortID( ); 
    switch( out_portID )
    {
        case ID_OUT_OCEAN:
        {
            CDataArrayVector3f outData( in_ctxt );
            if(bEnable[0])
            {
                #pragma omp parallel for private(worldSpaceVec, localSpaceVec)
                for(int i = 0; i<count; ++i)
                {
                    // get ocean displacement vector
                    worldSpaceVec[1] = pOcean->getOceanData(uCoord[i], vCoord[i], aaOcean::eHEIGHTFIELD);
                    if(pOcean->isChoppy())
                    {
                        worldSpaceVec[0] = pOcean->getOceanData(uCoord[i], vCoord[i], aaOcean::eCHOPX);
                        worldSpaceVec[2] = pOcean->getOceanData(uCoord[i], vCoord[i], aaOcean::eCHOPZ);
                    }

                    // multiply displacement vector by input transform matrix
                    if(!transformSingleton)
                        transformArraySize = i;

                    multiplyMatrix(&worldSpaceVec[0], &localSpaceVec[0], transform, transformArraySize);

                    outData[i].PutX(localSpaceVec[0]);
                    outData[i].PutY(localSpaceVec[1]);
                    outData[i].PutZ(localSpaceVec[2]);

                    outData[i].PutX(worldSpaceVec[0]);
                    outData[i].PutY(worldSpaceVec[1]);
                    outData[i].PutZ(worldSpaceVec[2]);
                }
            }
            else
            {
                #pragma omp parallel for
                for(int i = 0; i<count; ++i)
                {
                    outData[i].PutX(0.f); 
                    outData[i].PutY(0.f); 
                    outData[i].PutZ(0.f);
                }
            }
        }
        break;

        case ID_OUT_FOAM:
        {
            if(pOcean->isChoppy() && bEnable[0] && enableFoam[0])
            {               
                CDataArrayFloat outData( in_ctxt );

                // output raw (unscaled) foam in ICE deformer
                #pragma omp parallel for
                for(int i = 0; i<count; ++i)
                    outData[i] = pOcean->getOceanData(uCoord[i], vCoord[i], aaOcean::eFOAM);
            }
        }
        break;

        case ID_OUT_EIGEN_MINUS:
        {
            CDataArrayVector3f outData( in_ctxt );
            if(pOcean->isChoppy() && bEnable[0] && enableFoam[0])
            {
                #pragma omp parallel for private(worldSpaceVec, localSpaceVec)
                for(int i = 0; i<count; ++i)
                {
                    worldSpaceVec[0] = pOcean->getOceanData(uCoord[i], vCoord[i], aaOcean::eEIGENMINUSX);
                    worldSpaceVec[2] = pOcean->getOceanData(uCoord[i], vCoord[i], aaOcean::eEIGENMINUSZ);

                    multiplyMatrix(&worldSpaceVec[0], &localSpaceVec[0], transform, transformArraySize);

                    outData[i].PutX(localSpaceVec[0]);
                    outData[i].PutY(0.0f);
                    outData[i].PutZ(localSpaceVec[2]);
                }
            }
            else
            {
                #pragma omp parallel for
                for(int i = 0; i<count; ++i){
                    outData[i].PutX(0);outData[i].PutY(0);outData[i].PutZ(0);}
            }
        }
        break;

        case ID_OUT_EIGEN_PLUS:
        {
            CDataArrayVector3f outData( in_ctxt );
            if(pOcean->isChoppy() && bEnable[0] && enableFoam[0])
            {
                #pragma omp parallel for private(worldSpaceVec, localSpaceVec)
                for(int i = 0; i<count; ++i)
                {
                    worldSpaceVec[0] = pOcean->getOceanData(uCoord[i], vCoord[i], aaOcean::eEIGENPLUSX);
                    worldSpaceVec[2] = pOcean->getOceanData(uCoord[i], vCoord[i], aaOcean::eEIGENPLUSZ);

                    multiplyMatrix(&worldSpaceVec[0], &localSpaceVec[0], transform, transformArraySize);

                    outData[i].PutX(localSpaceVec[0]);
                    outData[i].PutY(0.0f);
                    outData[i].PutZ(localSpaceVec[2]);
                }
            }
            else
            {
                #pragma omp parallel for
                for(int i = 0; i<count; ++i){
                    outData[i].PutX(0); outData[i].PutY(0); outData[i].PutZ(0);}
            }
        }
        break;
    }

    return CStatus::OK;
}
Ejemplo n.º 14
0
SICALLBACK ToonixMesher_Evaluate( ICENodeContext& in_ctxt )
{
	TXMesh* mesh = (TXMesh*)(CValue::siPtrType)in_ctxt.GetUserData( );

	if(!mesh->_valid || GetMesherDirtyState(in_ctxt))
	{
		// Get the input TXLine
		CDataArrayCustomType ToonixLine( in_ctxt, ID_IN_ToonixLine );

		CDataArrayCustomType::TData* pBufferToonixLine;
		ULONG nSizeToonixLine;
		ToonixLine.GetData( 0,(const CDataArrayCustomType::TData**)&pBufferToonixLine, nSizeToonixLine );
		TXLine* line = (TXLine*)pBufferToonixLine;
		if(!line)
		{
			mesh->_nbv = mesh->_nbp = 0;
		}
		else
		{
			mesh->_line = line;

			CDataArrayLong subdivData(in_ctxt, ID_IN_Subdiv);
			mesh->_subdiv = subdivData[0];
			CDataArrayVector3f viewData(in_ctxt, ID_IN_ViewPosition);
			mesh->_view = viewData[0];
			mesh->Build();
		}
		mesh->_valid = true;
	}

	// The current output port being evaluated...
	LONG out_portID = in_ctxt.GetEvaluatedOutputPortID( );

	switch( out_portID )
	{	
		case ID_OUT_Vertices:
		{
			// Get the output port array ...			
			CDataArray2DVector3f outData( in_ctxt );

			CDataArray2DVector3f::Accessor outDataSubArray = outData.Resize(0,mesh->_nbv);
			for(ULONG n=0;n<mesh->_nbv;n++)
			{
				outDataSubArray[n].Set(mesh->_vertices[n].GetX(),mesh->_vertices[n].GetY(),mesh->_vertices[n].GetZ());
			}
			
		}
		break;

		case ID_OUT_Polygons:
		{
			// Get the output port array ...			
			CDataArray2DLong outData( in_ctxt );	

			CDataArray2DLong::Accessor outDataSubArray = outData.Resize(0,mesh->_nbp);
			for(ULONG n=0;n<mesh->_nbp;n++)
			{
				outDataSubArray[n] = mesh->_polygons[n];
			}
		}
		break;
	}
	return CStatus::OK;
}
Ejemplo n.º 15
0
XSIPLUGINCALLBACK CStatus nest_LatticeDeform_Evaluate( ICENodeContext& in_ctxt )
{
   // The current output port being evaluated...
   ULONG out_portID = in_ctxt.GetEvaluatedOutputPortID( );

   switch( out_portID )
   {
      case Array_ID_OUT_Result:
      {
         siICENodeDataType dataType;
         siICENodeStructureType struType;
         siICENodeContextType contType;
         in_ctxt.GetPortInfo(Lattice_ID_IN_Point,dataType,struType,contType);
			
         // get all of the data that is the same for any structure
         CDataArrayVector3f SubdivData( in_ctxt, Lattice_ID_IN_Subdivision );
         CDataArrayVector3f StepData( in_ctxt, Lattice_ID_IN_Step );
         CDataArray2DVector3f ReferenceData( in_ctxt, Lattice_ID_IN_Reference );
         CDataArray2DVector3f CurrentData( in_ctxt, Lattice_ID_IN_Current );
         CDataArray2DVector3f::Accessor ReferenceDataSub = ReferenceData[0];
         CDataArray2DVector3f::Accessor CurrentDataSub = CurrentData[0];

         // define the things we need to calculate
         long subdiv[3];
         subdiv[0] = long(floor(SubdivData[0].GetX()));
         subdiv[1] = long(floor(SubdivData[0].GetY()));
         subdiv[2] = long(floor(SubdivData[0].GetZ()));
         long subdiv1[3];
         subdiv1[0] = subdiv[0]+1;
         subdiv1[1] = subdiv[1]+1;
         subdiv1[2] = subdiv[2]+1;
         float step[3];
         step[0] = 1.0f / StepData[0].GetX();
         step[1] = 1.0f / StepData[0].GetY();
         step[2] = 1.0f / StepData[0].GetZ();
			float steplength = StepData[0].GetLength();
         long indexX[8];
         long indexY[8];
         long indexZ[8];
         long index[8];
         long lastIndex[3];
			lastIndex[0] = -1;
			lastIndex[1] = -1;
			lastIndex[2] = -1;
			CVector3f posCp;
			CVector3f pos;
         CVector3f diff[8];
         CVector3f motion[8];
         CVector3f motionScl[8];
			CVector3f deform;
         float weight[8];
			float xyz0[3];
			float xyz1[3];
			float weightSum;
         
         if(struType == siICENodeStructureSingle)
         {
            // two behaviours based on the datatype...
            // Get the output port array ...
            CDataArrayVector3f outData( in_ctxt );
   
            // Get the input data buffers for each port
            CDataArrayVector3f PointData( in_ctxt, Lattice_ID_IN_Point );

            // iterate each subset!
            CIndexSet IndexSet( in_ctxt );
            for(CIndexSet::Iterator it = IndexSet.Begin(); it.HasNext(); it.Next())
            {
               // first let's find the index inside the box!
					posCp.Set(PointData[it].GetX(),PointData[it].GetY(),PointData[it].GetZ());
					
					// substract the lowest corner
					pos.Sub(posCp,ReferenceDataSub[0]);
					pos.Set(pos.GetX() * step[0], pos.GetY() * step[1], pos.GetZ() * step[2]);
					xyz0[0] = pos.GetX() - floor(pos.GetX());
					xyz0[1] = pos.GetY() - floor(pos.GetY());
					xyz0[2] = pos.GetZ() - floor(pos.GetZ());

					xyz1[0] = 1.0 - xyz0[0];
					xyz1[1] = 1.0 - xyz0[1];
					xyz1[2] = 1.0 - xyz0[2];
					
					// calculate the indices (decomposed)
					indexX[0] = clampl(long(floor(pos.GetX())),0,subdiv[0]);
					indexY[0] = clampl(long(floor(pos.GetY())),0,subdiv[1]);
					indexZ[0] = clampl(long(floor(pos.GetZ())),0,subdiv[2]);
					
					if(lastIndex[0] != indexX[0] || lastIndex[1] != indexY[0] || lastIndex[2] != indexZ[0])
					{
						indexX[1] = clampl(indexX[0]+1	,0,subdiv[0]);
						indexY[1] = clampl(indexY[0]	,0,subdiv[1]);
						indexZ[1] = clampl(indexZ[0]	,0,subdiv[2]);
	
						indexX[2] = clampl(indexX[0]+1	,0,subdiv[0]);
						indexY[2] = clampl(indexY[0]+1	,0,subdiv[1]);
						indexZ[2] = clampl(indexZ[0]	,0,subdiv[2]);
	
						indexX[3] = clampl(indexX[0]+1	,0,subdiv[0]);
						indexY[3] = clampl(indexY[0]	,0,subdiv[1]);
						indexZ[3] = clampl(indexZ[0]+1	,0,subdiv[2]);
	
						indexX[4] = clampl(indexX[0]+1	,0,subdiv[0]);
						indexY[4] = clampl(indexY[0]+1	,0,subdiv[1]);
						indexZ[4] = clampl(indexZ[0]+1	,0,subdiv[2]);
						
						indexX[5] = clampl(indexX[0]	,0,subdiv[0]);
						indexY[5] = clampl(indexY[0]+1	,0,subdiv[1]);
						indexZ[5] = clampl(indexZ[0]	,0,subdiv[2]);
	
						indexX[6] = clampl(indexX[0]	,0,subdiv[0]);
						indexY[6] = clampl(indexY[0]	,0,subdiv[1]);
						indexZ[6] = clampl(indexZ[0]+1	,0,subdiv[2]);
	
						indexX[7] = clampl(indexX[0]	,0,subdiv[0]);
						indexY[7] = clampl(indexY[0]+1	,0,subdiv[1]);
						indexZ[7] = clampl(indexZ[0]+1	,0,subdiv[2]);
						
						for(int i=0;i<8;i++)
						{
							// compose the indices!
							index[i] = compose(indexX[i],indexY[i],indexZ[i],subdiv1[1],subdiv1[2]);
							
							// calculate the motions
							motion[i].Sub(CurrentDataSub[index[i]],ReferenceDataSub[index[i]]);
						}
					}
					else
					{
						// for performance, remember the last used index
						lastIndex[0] = indexX[0];
						lastIndex[1] = indexY[0];
						lastIndex[2] = indexZ[0];
					}

					// compute the weights
					weight[0] = xyz1[0] * xyz1[1] * xyz1[2];
					weight[1] = xyz0[0] * xyz1[1] * xyz1[2];
					weight[2] = xyz0[0] * xyz0[1] * xyz1[2];
					weight[3] = xyz0[0] * xyz1[1] * xyz0[2];
					weight[4] = xyz0[0] * xyz0[1] * xyz0[2];
					weight[5] = xyz1[0] * xyz0[1] * xyz1[2];
					weight[6] = xyz1[0] * xyz1[1] * xyz0[2];
					weight[7] = xyz1[0] * xyz0[1] * xyz0[2];

					// sum up all weighted motions
					deform.SetNull();
					for(int i=0;i<8;i++)
					{
						motionScl[i].Scale(weight[i],motion[i]);
						deform.AddInPlace(motionScl[i]);
					}
					
					// output the deformed position
					outData[it] = deform;
            }
         }
			else
         {
            // two behaviours based on the datatype...
            // Get the output port array ...
            CDataArray2DVector3f outData( in_ctxt );
   
            // Get the input data buffers for each port
            CDataArray2DVector3f PointData( in_ctxt, Lattice_ID_IN_Point );

            // iterate each subset!
            CIndexSet IndexSet( in_ctxt );
            for(CIndexSet::Iterator it = IndexSet.Begin(); it.HasNext(); it.Next())
            {
		         CDataArray2DVector3f::Accessor PointDataSub = PointData[it];
					long subCount = PointDataSub.GetCount();
					Application().LogMessage(CString((LONG)subCount));
					outData.Resize(it,subCount);
					for(long k=0;k<subCount;k++)
					{
						// first let's find the index inside the box!
						posCp.Set(PointDataSub[k].GetX(),PointDataSub[k].GetY(),PointDataSub[k].GetZ());
						
						// substract the lowest corner
						pos.Sub(posCp,ReferenceDataSub[0]);
						pos.Set(pos.GetX() * step[0], pos.GetY() * step[1], pos.GetZ() * step[2]);
						xyz0[0] = pos.GetX() - floor(pos.GetX());
						xyz0[1] = pos.GetY() - floor(pos.GetY());
						xyz0[2] = pos.GetZ() - floor(pos.GetZ());
	
						xyz1[0] = 1.0 - xyz0[0];
						xyz1[1] = 1.0 - xyz0[1];
						xyz1[2] = 1.0 - xyz0[2];
						
						// calculate the indices (decomposed)
						indexX[0] = clampl(long(floor(pos.GetX())),0,subdiv[0]);
						indexY[0] = clampl(long(floor(pos.GetY())),0,subdiv[1]);
						indexZ[0] = clampl(long(floor(pos.GetZ())),0,subdiv[2]);
						
						if(lastIndex[0] != indexX[0] || lastIndex[1] != indexY[0] || lastIndex[2] != indexZ[0])
						{
							indexX[1] = clampl(indexX[0]+1	,0,subdiv[0]);
							indexY[1] = clampl(indexY[0]	,0,subdiv[1]);
							indexZ[1] = clampl(indexZ[0]	,0,subdiv[2]);
		
							indexX[2] = clampl(indexX[0]+1	,0,subdiv[0]);
							indexY[2] = clampl(indexY[0]+1	,0,subdiv[1]);
							indexZ[2] = clampl(indexZ[0]	,0,subdiv[2]);
		
							indexX[3] = clampl(indexX[0]+1	,0,subdiv[0]);
							indexY[3] = clampl(indexY[0]	,0,subdiv[1]);
							indexZ[3] = clampl(indexZ[0]+1	,0,subdiv[2]);
		
							indexX[4] = clampl(indexX[0]+1	,0,subdiv[0]);
							indexY[4] = clampl(indexY[0]+1	,0,subdiv[1]);
							indexZ[4] = clampl(indexZ[0]+1	,0,subdiv[2]);
							
							indexX[5] = clampl(indexX[0]	,0,subdiv[0]);
							indexY[5] = clampl(indexY[0]+1	,0,subdiv[1]);
							indexZ[5] = clampl(indexZ[0]	,0,subdiv[2]);
		
							indexX[6] = clampl(indexX[0]	,0,subdiv[0]);
							indexY[6] = clampl(indexY[0]	,0,subdiv[1]);
							indexZ[6] = clampl(indexZ[0]+1	,0,subdiv[2]);
		
							indexX[7] = clampl(indexX[0]	,0,subdiv[0]);
							indexY[7] = clampl(indexY[0]+1	,0,subdiv[1]);
							indexZ[7] = clampl(indexZ[0]+1	,0,subdiv[2]);
							
							for(int i=0;i<8;i++)
							{
								// compose the indices!
								index[i] = compose(indexX[i],indexY[i],indexZ[i],subdiv1[1],subdiv1[2]);
								
								// calculate the motions
								motion[i].Sub(CurrentDataSub[index[i]],ReferenceDataSub[index[i]]);
							}
						}
						else
						{
							// for performance, remember the last used index
							lastIndex[0] = indexX[0];
							lastIndex[1] = indexY[0];
							lastIndex[2] = indexZ[0];
						}
	
						// compute the weights
						weight[0] = xyz1[0] * xyz1[1] * xyz1[2];
						weight[1] = xyz0[0] * xyz1[1] * xyz1[2];
						weight[2] = xyz0[0] * xyz0[1] * xyz1[2];
						weight[3] = xyz0[0] * xyz1[1] * xyz0[2];
						weight[4] = xyz0[0] * xyz0[1] * xyz0[2];
						weight[5] = xyz1[0] * xyz0[1] * xyz1[2];
						weight[6] = xyz1[0] * xyz1[1] * xyz0[2];
						weight[7] = xyz1[0] * xyz0[1] * xyz0[2];
	
						// sum up all weighted motions
						deform.SetNull();
						for(int i=0;i<8;i++)
						{
							motionScl[i].Scale(weight[i],motion[i]);
							deform.AddInPlace(motionScl[i]);
						}
						
						// output the deformed position
						outData[it][k] = deform;
					}
				}
         }
      }
      break;

      // Other output ports...

   };

   return CStatus::OK;
}
CStatus VDB_Node_VolumeToMesh::Evaluate(ICENodeContext& ctxt)
{
   Application().LogMessage(L"[VDB_Node_VolumeToMesh] Evaluate");

   if (!m_isValid) return CStatus::OK;

   // The current output port being evaluated...
   ULONG evaluatedPort = ctxt.GetEvaluatedOutputPortID();
   
   switch (evaluatedPort)
   {
      case kPointArray:
      {
         CDataArray2DVector3f output(ctxt);
         CDataArray2DVector3f::Accessor iter;
         iter = output.Resize(0, (ULONG)m_points.size());
         CIndexSet::Iterator index = CIndexSet(ctxt).Begin();

         for (size_t i=0; i<m_points.size(); ++i, index.Next())
         {
            openvdb::math::Vec3s pnt = m_points[i];
            iter[index] = CVector3f(pnt.x(), pnt.y(), pnt.z());
         }
         break;
      }
      case kPolygonArray:
      {
         CDataArray2DLong output(ctxt);
         CDataArray2DLong::Accessor iter = output.Resize(0, m_polygonArraySize);
         CIndexSet::Iterator index = CIndexSet(ctxt).Begin();
         
         // quads
         for (size_t q=0; q<m_quads.size(); ++q)
         {
            const openvdb::Vec4I& quad = m_quads[q];
            iter[index] = quad.w(); index.Next();
            iter[index] = quad.z(); index.Next();
            iter[index] = quad.y(); index.Next();
            iter[index] = quad.x(); index.Next();
            // end of quad
            iter[index] = -1; index.Next();
         }

         // triangles
         for (size_t t=0; t<m_triangles.size(); ++t)
         {
            const openvdb::Vec3I& triangle = m_triangles[t];
            iter[index] = triangle.z(); index.Next();
            iter[index] = triangle.y(); index.Next();
            iter[index] = triangle.x(); index.Next();
            // end of triangle
            iter[index] = -1; index.Next();
         }
         break;
      }
      default:
         break;
   };
   
   return CStatus::OK;
}
Ejemplo n.º 17
0
SICALLBACK ToonixCurve_BeginEvaluate(ICENodeContext& in_ctxt)
{
	CValue userData = in_ctxt.GetUserData();
	TXLine* line = (TXLine*)(CValue::siPtrType)in_ctxt.GetUserData();

	// Get geometry object from the input port
	CICEGeometry curve(in_ctxt, ID_IN_Curves);
	if (!curve.GetGeometryType() != CICEGeometry::siNurbsCurveType)
		LOGWITHSEVERITY("TOONIXCURVE : ONLY CURVE INPUT VALID", XSI::siSeverityType::siErrorMsg);

	// Get num sub curves
	ULONG subCurvesCount = curve.GetSubGeometryCount();
	LOG("NUM CURVES : " + CString(subCurvesCount));

	for (ULONG i = 0; i < subCurvesCount; i++) {
		CICEGeometry subCurve = curve.GetSubGeometry(i);
		LOG("SUB CURVE : " + CString(i));
	}
	
	/*
	//CDataArrayCustomType ToonixData(in_ctxt, ID_IN_ToonixData);

	CDataArrayCustomType::TData* pBufferToonixData;
	ULONG nSizeToonixData;
	ToonixData.GetData(0, (const CDataArrayCustomType::TData**)&pBufferToonixData, nSizeToonixData);
	TXData* data = (TXData*)pBufferToonixData;

	//Empty Out if input is invalid
	if (!data) { line->EmptyData(); return CStatus::OK; }

	// Get underlying TXGeometry
	line->m_geom = data->m_geom;

	// Get View Position and optionnal lights positions used for silhouette detection
	line->m_eye.clear();

	siICENodeDataType inPortType;
	siICENodeStructureType inPortStruct;
	siICENodeContextType inPortContext;

	in_ctxt.GetPortInfo(ID_IN_ViewPosition, inPortType, inPortStruct, inPortContext);
	if (inPortStruct == XSI::siICENodeStructureSingle)
	{
		CDataArrayVector3f viewPointData(in_ctxt, ID_IN_ViewPosition);
		line->m_eye.push_back(viewPointData[0]);
		line->m_nbv = 1;
	}
	else if (inPortStruct == XSI::siICENodeStructureArray)
	{
		CDataArray2DVector3f viewPointsData(in_ctxt, ID_IN_ViewPosition);
		CDataArray2DVector3f::Accessor viewPointData = viewPointsData[0];
		line->m_nbv = viewPointData.GetCount();

		for (ULONG v = 0; v<line->m_nbv; v++)
		{
			line->m_eye.push_back(viewPointData[v]);
		}
	}

	// Get View Bias used for silhouette detection
	line->m_bias.Resize(line->m_nbv);
	in_ctxt.GetPortInfo(ID_IN_ViewBias, inPortType, inPortStruct, inPortContext);
	if (inPortStruct == XSI::siICENodeStructureSingle)
	{
		CDataArrayFloat viewBias(in_ctxt, ID_IN_ViewBias);
		for (ULONG v = 0; v<line->m_nbv; v++)
		{
			line->m_bias[v] = viewBias[0];
		}

	}
	else if (inPortStruct == XSI::siICENodeStructureArray)
	{
		CDataArray2DFloat viewBiasData(in_ctxt, ID_IN_ViewBias);
		CDataArray2DFloat::Accessor viewBias = viewBiasData[0];
		for (ULONG v = 0; v<line->m_nbv; v++)
		{
			line->m_bias[v] = viewBias[v];
		}
	}
	// Get the parameters value
	CDataArrayFloat widthData(in_ctxt, ID_IN_Width);
	CDataArrayFloat breakData(in_ctxt, ID_IN_BreakAngle);
	CDataArrayFloat filterData(in_ctxt, ID_IN_FilterPoints);
	CDataArrayFloat extendData(in_ctxt, ID_IN_Extend);
	CDataArrayBool smoothData(in_ctxt, ID_IN_SmoothSilhouette);
	CDataArrayBool ogldrawData(in_ctxt, ID_IN_OGLDraw);

	// Pass them to line object
	line->m_width = widthData[0];
	line->m_break = (float)DegreesToRadians(breakData[0]);
	line->m_filterpoints = filterData[0];
	line->m_extend = extendData[0];
	line->m_smoothsilhouette = smoothData[0];
	line->m_ogldraw = ogldrawData[0];

	line->ClearChains();
	
	bool dual = data->_useoctree;
	if(dual)
	{
	line->SetDualMesh(data->_dualmesh);
	for(int v=0;v<line->_eye.size();v++)
	{
	line->GetDualSilhouettes((LONG)v);
	line->Build(v);
	}
	}

	else
	{
	
	for (int v = 0; v<line->m_eye.size(); v++)
	{
		line->GetSilhouettes(v);
		line->Build(v);
		//Application().LogMessage(L"Nb Chains : "+(CString)(ULONG)line->_chains.size());
	}
	//}
	*/
	return CStatus::OK;
}
Ejemplo n.º 18
0
CStatus VDB_Node_FBM::Evaluate(ICENodeContext& ctxt)
{
   Application().LogMessage(L"[VDB_Node_FBM] Evaluate");

   CDataArrayCustomType inVDBGridPort(ctxt, kInVDBGrid);

   // The current output port being evaluated...
   ULONG evaluatedPort = ctxt.GetEvaluatedOutputPortID();

   switch (evaluatedPort)
   {
      case kOutVDBGrid:
      {
         CDataArrayCustomType output(ctxt);
         CIndexSet indexSet(ctxt);

         for(CIndexSet::Iterator it = indexSet.Begin(); it.HasNext(); it.Next())
         {
            //Application().LogMessage(L"[VDB_Node_FBM] iterator index = " + CValue(it.GetIndex()).GetAsText());

            ULONG inDataSize;
            VDB_Primitive* inVDBPrim;
            inVDBGridPort.GetData(it, (const CDataArrayCustomType::TData**)&inVDBPrim, inDataSize);
            if (!inDataSize)
            {
               Application().LogMessage(L"[VDB_Node_FBM] data size is invalid!", siErrorMsg);
               return CStatus::OK;
            }
            Application().LogMessage(L"[VDB_Node_FBM] previous data size = " + CValue(inDataSize).GetAsText());

            openvdb::GridBase::Ptr grid = inVDBPrim->GetGridPtr();
            openvdb::FloatGrid::Ptr outputGrid;
            outputGrid = openvdb::gridPtrCast<openvdb::FloatGrid>(grid);
            //openvdb::math::Transform::Ptr transform = outputGrid->getTransform();
            
            CDataArrayLong octaves(ctxt, kOctaves);
            CDataArrayFloat lacunarity(ctxt, kLacunarity);
            CDataArrayFloat gain(ctxt, kGain);

            for (openvdb::FloatGrid::ValueOnIter iter = outputGrid->beginValueOn(); iter; ++iter)
            {
               if (iter.isVoxelValue())
               {
                  openvdb::Coord coord = iter.getCoord();
                  openvdb::Vec3d vec = outputGrid->indexToWorld(coord);
                  double result;
                  double p[3] = {vec.x(), vec.y(), vec.z()};
                  SeExpr::FBM<3,1,false>(p, &result, double(octaves[0]), double(lacunarity[0]), double(gain[0]));
                  Application().LogMessage(CValue(vec.x()).GetAsText() + "," + CValue(vec.y()).GetAsText() + "," + CValue(vec.z()).GetAsText(), siVerboseMsg);
                  Application().LogMessage(CValue(.5*result+.5).GetAsText(), siVerboseMsg);
                  iter.setValue(*iter + 1.0f * result);
               }
            }

            VDB_Primitive* outVDBPrim = (VDB_Primitive*)output.Resize(it, sizeof(VDB_Primitive));
            ::memcpy(outVDBPrim, inVDBPrim, inDataSize);

            Application().LogMessage(L"[VDB_Node_FBM] memcpy succeeded");
            Application().LogMessage(L"[VDB_Node_FBM] grid type is " + CString(inVDBPrim->GetTypeName()));
         }
         break;
      }
      default:
         break;
   };

   return CStatus::OK;
}
Ejemplo n.º 19
0
SICALLBACK MOM_SetAttributes_Evaluate( ICENodeContext& in_ctxt )
{
	// The current output port being evaluated...
   ULONG out_portID = in_ctxt.GetEvaluatedOutputPortID( );

   if(gSimulation == NULL)
      return CStatus::OK;

	switch( out_portID )
	{
		case ID_OUT_base:
		{
         CDataArrayLong baseData( in_ctxt, ID_IN_base );
         CDataArrayLong idData( in_ctxt, ID_IN_id );
         rbdID rbd_ID;
         CIndexSet indexSet( in_ctxt );

			// Get the output port array ...
			CDataArrayLong outData( in_ctxt );

			// get all of the input SET data!
			CDataArrayBool setPosData( in_ctxt, ID_IN_set_position);
			CDataArrayBool setRotData( in_ctxt, ID_IN_set_orientation);
			CDataArrayBool setLinvelData( in_ctxt, ID_IN_set_linvelocity);
			CDataArrayBool setAngvelData( in_ctxt, ID_IN_set_angvelocity);
			CDataArrayBool setStateData( in_ctxt, ID_IN_set_state);
			CDataArrayBool setMassData( in_ctxt, ID_IN_set_mass);
			CDataArrayBool setBounceData( in_ctxt, ID_IN_set_bounce);
			CDataArrayBool setFrictionData( in_ctxt, ID_IN_set_friction);
			CDataArrayBool setLindampData( in_ctxt, ID_IN_set_lindamping);
			CDataArrayBool setAngdampData( in_ctxt, ID_IN_set_angdamping);
			CDataArrayBool setLintreshData( in_ctxt, ID_IN_set_lintreshold);
			CDataArrayBool setAngtreshData( in_ctxt, ID_IN_set_angtreshold);

			// get all of the input data!
			CDataArrayVector3f posData( in_ctxt, ID_IN_position);
			CDataArrayVector3f rotData( in_ctxt, ID_IN_orientation);
			CDataArrayVector3f linvelData( in_ctxt, ID_IN_linvelocity);
			CDataArrayVector3f angvelData( in_ctxt, ID_IN_angvelocity);
			CDataArrayLong stateData( in_ctxt, ID_IN_state);
			CDataArrayFloat massData( in_ctxt, ID_IN_mass);
			CDataArrayFloat bounceData( in_ctxt, ID_IN_bounce);
			CDataArrayFloat frictionData( in_ctxt, ID_IN_friction);
			CDataArrayFloat lindampData( in_ctxt, ID_IN_lindamping);
			CDataArrayFloat angdampData( in_ctxt, ID_IN_angdamping);
			CDataArrayFloat lintreshData( in_ctxt, ID_IN_lintreshold);
			CDataArrayFloat angtreshData( in_ctxt, ID_IN_angtreshold);

         // get the index set iterator
         btTransform bodyTransform;
         CVector3f bodyPos,linvel,angvel;
         btQuaternion bodyRot;
			CRotation rot;
			CQuaternion quat;
			CVector3f anglesf;
			CVector3 angles;

			for(CIndexSet::Iterator it = indexSet.Begin(); it.HasNext(); it.Next())
			{
            rbd_ID.primary = (int)(baseData.IsConstant() ? baseData[0] : baseData[it]);
            rbd_ID.secondary = (int)(idData.IsConstant() ? idData[0] : idData[it]);
            btRigidBodyReference * bodyRef = gSimulation->GetRigidBody(rbd_ID);
            if(bodyRef != NULL)
            {
               // take care of the positions
               if((setPosData.IsConstant() ? setPosData[0] : setPosData[it]) == true)
               {
                  bodyPos = posData.IsConstant() ? posData[0] : posData[it];
                  bodyTransform = bodyRef->GetWorldTransform();
                  bodyTransform.setOrigin(btVector3(bodyPos.GetX(),bodyPos.GetY(),bodyPos.GetZ()));
                  bodyRef->SetWorldTransform(bodyTransform);
               }
               // take care of the orientations
               if((setRotData.IsConstant() ? setRotData[0] : setRotData[it]) == true)
               {
                  anglesf = rotData.IsConstant() ? rotData[0] : rotData[it];
                  rot.SetFromXYZAngles(DegreesToRadians(anglesf.GetX()),DegreesToRadians(anglesf.GetY()),DegreesToRadians(anglesf.GetZ()));
                  quat = rot.GetQuaternion();
                  bodyTransform = bodyRef->GetWorldTransform();
                  bodyTransform.setRotation(btQuaternion(quat.GetX(),quat.GetY(),quat.GetZ(),quat.GetW()));
                  bodyRef->SetWorldTransform(bodyTransform);
               }
               // take care of the linear velocity
               if((setLinvelData.IsConstant() ? setLinvelData[0] : setLinvelData[it]) == true)
               {
                  linvel = linvelData.IsConstant() ? linvelData[0] : linvelData[it];
                  bodyRef->body->setLinearVelocity(btVector3(linvel.GetX(),linvel.GetY(),linvel.GetZ()));
               }
               // take care of the angular velocity
               if((setAngvelData.IsConstant() ? setAngvelData[0] : setAngvelData[it]) == true)
               {
                  angvel = angvelData.IsConstant() ? angvelData[0] : angvelData[it];
                  bodyRef->body->setAngularVelocity(btVector3(angvel.GetX(),angvel.GetY(),angvel.GetZ()));
               }
               // take care of the state
               if((setStateData.IsConstant() ? setStateData[0] : setStateData[it]) == true)
               {
                  int state = stateData.IsConstant() ? stateData[0] : stateData[it];
                  if(state == 0)
                     bodyRef->body->forceActivationState(ACTIVE_TAG);
                  else if(state == 1)
                     bodyRef->body->forceActivationState(ISLAND_SLEEPING);
                  else if(state == 2)
                     bodyRef->body->forceActivationState(DISABLE_SIMULATION);
               }
               // take care of the mass
               if((setMassData.IsConstant() ? setMassData[0] : setMassData[it]) == true)
               {
                  // compute the inertia
                  bodyRef->mass = massData.IsConstant() ? massData[0] : massData[it];
                  btVector3 inertia(0,0,0);
                  if(bodyRef->mass > 0.0f)
                     bodyRef->body->getCollisionShape()->calculateLocalInertia(bodyRef->mass,inertia);
                  bodyRef->body->setMassProps(bodyRef->mass,inertia);
               }
               // take care of the bounce
               if((setBounceData.IsConstant() ? setBounceData[0] : setBounceData[it]) == true)
               {
                  bodyRef->body->setRestitution(bounceData.IsConstant() ? bounceData[0] : bounceData[it]);
               }
               // take care of the friction
               if((setFrictionData.IsConstant() ? setFrictionData[0] : setFrictionData[it]) == true)
               {
                  bodyRef->body->setFriction(frictionData.IsConstant() ? frictionData[0] : frictionData[it]);
               }
               // take care of the linear damping
               if((setLindampData.IsConstant() ? setLindampData[0] : setLindampData[it]) == true)
               {
                  float angdamp = bodyRef->body->getAngularDamping();
                  bodyRef->body->setDamping(lindampData.IsConstant() ? lindampData[0] : lindampData[it],angdamp);
               }
               // take care of the angular damping
               if((setAngdampData.IsConstant() ? setAngdampData[0] : setAngdampData[it]) == true)
               {
                  float lindamp = bodyRef->body->getLinearDamping();
                  bodyRef->body->setDamping(lindamp,angdampData.IsConstant() ? angdampData[0] : angdampData[it]);
               }
               // take care of the linear treshold
               if((setLintreshData.IsConstant() ? setLintreshData[0] : setLintreshData[it]) == true)
               {
                  float angtresh = bodyRef->body->getAngularSleepingThreshold();
                  bodyRef->body->setSleepingThresholds(lintreshData.IsConstant() ? lintreshData[0] : lintreshData[it],angtresh);
               }
               // take care of the angular treshold
               if((setAngtreshData.IsConstant() ? setAngtreshData[0] : setAngtreshData[it]) == true)
               {
                  float lintresh = bodyRef->body->getLinearSleepingThreshold();
                  bodyRef->body->setSleepingThresholds(lintresh,angtreshData.IsConstant() ? angtreshData[0] : angtreshData[it]);
               }
            }
            outData[it] = rbd_ID.primary;
			}
         break;
		}
	};

	return CStatus::OK;
}