void MayaPointPrimitiveWriter::write(double iFrame) { MStatus status; std::vector<float> position; std::vector<float> velocity; std::vector< Alembic::Util::uint64_t > particleIds; std::vector<float> width; bool runupFromStart = false; MTime to(iFrame, MTime::kSeconds); // need to force re-evaluation MFnParticleSystem particle(mDagPath); particle.evaluateDynamics(to, runupFromStart); unsigned int size = particle.count(); Alembic::AbcGeom::OPointsSchema::Sample samp; if (size == 0) { samp.setPositions(Alembic::Abc::V3fArraySample(NULL, 0)); samp.setVelocities(Alembic::Abc::V3fArraySample(NULL, 0)); samp.setIds(Alembic::Abc::UInt64ArraySample(NULL, 0)); mSchema.set(samp); return; } position.reserve(size*3); velocity.reserve(size*3); particleIds.reserve(size); width.reserve(size); // get particle position MVectorArray posArray; particle.position(posArray); for (unsigned int i = 0; i < size; i++) { MVector vec = posArray[i]; position.push_back(static_cast<float>(vec.x)); position.push_back(static_cast<float>(vec.y)); position.push_back(static_cast<float>(vec.z)); } samp.setPositions( Alembic::Abc::P3fArraySample((const Imath::V3f *) &position.front(), position.size() / 3) ); // get particle velocity MVectorArray vecArray; particle.velocity(vecArray); for (unsigned int i = 0; i < size; i++) { MVector vec = vecArray[i]; velocity.push_back(static_cast<float>(vec.x)); velocity.push_back(static_cast<float>(vec.y)); velocity.push_back(static_cast<float>(vec.z)); } if (!velocity.empty()) { samp.setVelocities( Alembic::Abc::V3fArraySample((const Imath::V3f *) &velocity.front(), velocity.size() / 3) ); } // get particleIds MIntArray idArray; particle.particleIds(idArray); for (unsigned int i = 0; i < size; i++) { particleIds.push_back(idArray[i]); } samp.setIds( Alembic::Abc::UInt64ArraySample(&(particleIds.front()), particleIds.size()) ); // assume radius is width MDoubleArray radiusArray; MPlug radius = particle.findPlug("radiusPP", true, &status); AbcGeom::GeometryScope widthScope = AbcGeom::kUnknownScope; if ( status == MS::kSuccess) { // RadiusPP exists, get all particles value widthScope = AbcGeom::kVaryingScope; particle.radius(radiusArray); for (unsigned int i = 0; i < size; i++) { float radius = static_cast<float>(radiusArray[i]); width.push_back(radius); } } else { // Get the value of the radius attribute widthScope = AbcGeom::kUniformScope; width.push_back( particle.findPlug("radius").asDouble() ); } if (!width.empty()) { Alembic::AbcGeom::OFloatGeomParam::Sample widthSamp; widthSamp.setVals(width); widthSamp.setScope(widthScope); samp.setWidths( widthSamp ); } mSchema.set(samp); }
void MayaPointPrimitiveWriter::write(double iFrame) { std::vector<float> position; std::vector<float> velocity; std::vector< Alembic::Util::uint64_t > particleIds; std::vector<float> width; bool runupFromStart = false; MTime to(iFrame, MTime::kSeconds); // need to force re-evaluation MFnParticleSystem particle(mDagPath); particle.evaluateDynamics(to, runupFromStart); unsigned int size = particle.count(); Alembic::AbcGeom::OPointsSchema::Sample samp; if (size == 0) { samp.setPositions(Alembic::Abc::V3fArraySample(NULL, 0)); samp.setVelocities(Alembic::Abc::V3fArraySample(NULL, 0)); samp.setIds(Alembic::Abc::UInt64ArraySample(NULL, 0)); mSchema.set(samp); return; } position.reserve(size*3); velocity.reserve(size*3); particleIds.reserve(size); width.reserve(size); // get particle position MVectorArray posArray; particle.position(posArray); for (unsigned int i = 0; i < size; i++) { MVector vec = posArray[i]; position.push_back(static_cast<float>(vec.x)); position.push_back(static_cast<float>(vec.y)); position.push_back(static_cast<float>(vec.z)); } samp.setPositions( Alembic::Abc::V3fArraySample((const Imath::V3f *) &position.front(), position.size() / 3) ); // get particle velocity MVectorArray vecArray; particle.velocity(vecArray); for (unsigned int i = 0; i < size; i++) { MVector vec = vecArray[i]; velocity.push_back(static_cast<float>(vec.x)); velocity.push_back(static_cast<float>(vec.y)); velocity.push_back(static_cast<float>(vec.z)); } if (!velocity.empty()) { samp.setVelocities( Alembic::Abc::V3fArraySample((const Imath::V3f *) &velocity.front(), velocity.size() / 3) ); } // get particleIds MIntArray idArray; particle.particleIds(idArray); for (unsigned int i = 0; i < size; i++) { particleIds.push_back(idArray[i]); } samp.setIds( Alembic::Abc::UInt64ArraySample(&(particleIds.front()), particleIds.size()) ); // assume radius is width MDoubleArray radiusArray; particle.radius(radiusArray); for (unsigned int i = 0; i < size; i++) { float radius = static_cast<float>(radiusArray[i]); width.push_back(radius); } // ignoring width and the velocity vectors for now mSchema.set(samp); }