OVisibilityProperty CreateVisibilityProperty( OObject & iObject, AbcA::TimeSamplingPtr iTimeSampling ) { OVisibilityProperty emptyProperty; if ( iTimeSampling ) { uint32_t iTimeSamplingID; iTimeSamplingID = iObject.getArchive().addTimeSampling( *iTimeSampling ); return CreateVisibilityProperty( iObject, iTimeSamplingID ); } return emptyProperty; }
//-***************************************************************************** //-***************************************************************************** //-***************************************************************************** // PARTICLES WRITER //-***************************************************************************** //-***************************************************************************** //-***************************************************************************** void RunAndWriteParticles ( OObject &iParent, const ParticleSystem::Parameters &iParams, size_t iNumFrames, chrono_t iFps ) { // Make the particle system. ParticleSystem parts( iParams ); // Create the time sampling type. TimeSampling ts(iFps, 0.0); Alembic::Util::uint32_t tsidx = iParent.getArchive().addTimeSampling(ts); // Create our object. OPoints partsOut( iParent, "simpleParticles", tsidx ); std::cout << "Created Simple Particles" << std::endl; // Add attributes OPointsSchema &pSchema = partsOut.getSchema(); MetaData mdata; SetGeometryScope( mdata, kVaryingScope ); OV3fArrayProperty velOut( pSchema, "velocity", mdata, tsidx ); OC3fArrayProperty rgbOut( pSchema, "Cs", tsidx ); OFloatArrayProperty ageOut( pSchema, "age", tsidx ); // Get seconds per frame. chrono_t iSpf = 1.0 / iFps; // CJH: Until we fix zero-array-property bug, loop a few frames. for ( int preRoll = 0; preRoll < 100; ++preRoll ) { parts.timeStep( iSpf ); if ( parts.numParticles() > 0 ) { break; } } ABCA_ASSERT( parts.numParticles() > 0, "Degenerate particle system" ); // Loop over the frames. for ( index_t sampIndex = 0; sampIndex < ( index_t )iNumFrames; ++sampIndex ) { // First, write the sample. OPointsSchema::Sample psamp( V3fArraySample( parts.positionVec() ), UInt64ArraySample( parts.idVec() ) ); pSchema.set( psamp ); velOut.set( V3fArraySample( parts.velocityVec() ) ); rgbOut.set( C3fArraySample( parts.colorVec() ) ); ageOut.set( FloatArraySample( parts.ageVec() ) ); // Now time step. parts.timeStep( iSpf ); // Print! std::cout << "Wrote " << parts.numParticles() << " particles to frame: " << sampIndex << std::endl; } // End it. std::cout << "Finished Sim, About to finish writing" << std::endl; }