Using CComAPIHandler with particles

This example shows how to use the CComAPIHandler utility function while writing a particles plug-in with the C++ API.

   Application app;
   Model root = app.GetActiveSceneRoot();

   SIObject siobj((CRef)in_array[0]);
   CString objName(siobj.GetName());
   X3DObject obj = root.FindChild(objName, L"", CStringArray(), true);
   if (obj.GetName() != objName) {
       app.LogMessage(objName + L" not found");
       return CStatus::Fail;
   } else if (obj.GetType() != L"cloud") {
       app.LogMessage(objName + L" not a particle cloud");
       return CStatus::Fail;
   }

   // get the particle type property passed as arguments
   CValue partType(in_array[1]);
   CValue outArg;

   // adds some particles to the cloud primitive
   // note: CComAPIHandler is used as Particle support is not yet available
   // in the C++ API
   CComAPIHandler cloudPrim(CValue(obj.GetActivePrimitive().GetRef()));
   cloudPrim.Call( L"AddParticles", outArg, CValue((long)9), partType );

   // get the particle collection from the cloud object
   CComAPIHandler cloudObj(obj.GetRef());
   CComAPIHandler particleColl(cloudObj.GetProperty( L"Particles" ));

   app.LogMessage( L"number of particles = " +
       particleColl.GetProperty( L"Count" ).GetAsText() );

   // retrieve first particle
   CValueArray argArray;
   argArray.Add( (long)0 );
   particleColl.Invoke( L"Find", CComAPIHandler::PropertyGet, outArg,
       argArray );

   CComAPIHandler particle(outArg);

   // set the particles position via the particle collection
   CValueArray posArray(27);
   CValue v0((double)0);
   CValue v1((double)1);
   CValue v_1((double)-1);

   posArray[0] = v1; posArray[1] = v0;  posArray[2] = v_1;
   posArray[3] = v_1; posArray[4] = v0;  posArray[5] = v0;
   posArray[6] = v_1; posArray[7] = v0;  posArray[8] = v1;
   posArray[9] = v0; posArray[10] = v0;  posArray[11] = v_1;
   posArray[12] = v0; posArray[13] = v0;  posArray[14] = v0;
   posArray[15] = v0; posArray[16] = v0;  posArray[17] = v1;
   posArray[18] = v1; posArray[19] = v0;  posArray[20] = v_1;
   posArray[21] = v1; posArray[22] = v0;  posArray[23] = v0;
   posArray[24] = v1; posArray[25] = v0;  posArray[26] = v1;

   argArray.Clear();
   argArray.Add( CValue() ); // leave it empty
   argArray.Add( posArray ); // position array

   st = comHandler.Invoke( L"PositionArray", CComAPIHandler::PropertyPut,
       outArg, argArray );