I am revisiting some old alembic code I wrote a while back and noticed that OPoints is only writing out position and ids but not other custom attributes

69 views
Skip to first unread message

Nicholas Yue

unread,
Sep 5, 2020, 8:20:18 PM9/5/20
to alembic-discussion
I loaded it in houdini to verify and only see IDs

Any idea ?

void single_time_sample(Alembic::Util::uint32_t i_num_points, const std::string& i_abc_fileName)
{

    Alembic::Abc::OArchive archive(Alembic::Abc::CreateArchiveWithInfo(Alembic::AbcCoreHDF5::WriteArchive(),
                                                                       std::string(i_abc_fileName.c_str()),
                                                                       std::string("Procedural Insight Pty. Ltd."),
                                                                       std::string("Single Sample Random points"),
                                                                       Alembic::Abc::ErrorHandler::kThrowPolicy));

    Alembic::AbcGeom::OObject iParent( archive, Alembic::AbcGeom::kTop );
    Alembic::AbcGeom::OXform xform = addXform(iParent,"Xform");

    // Frames per second
    Alembic::AbcCoreAbstract::chrono_t iFps = 24.0;

    // Create the time sampling type.
    Alembic::AbcCoreAbstract::TimeSampling ts(iFps, 0.0);
    Alembic::Util::uint32_t tsidx = iParent.getArchive().addTimeSampling(ts);

    // Create our object.
    Alembic::AbcGeom::OPoints partsOut( xform, "simpleParticles", tsidx );
    std::cout << "Created Simple Particles" << std::endl;

    // Add attributes
    Alembic::AbcGeom::OPointsSchema &pSchema = partsOut.getSchema();
    Alembic::AbcGeom::MetaData mdata;
    SetGeometryScope( mdata, Alembic::AbcGeom::kVaryingScope );
    Alembic::AbcGeom::OV3fArrayProperty velOut( pSchema, "velocity", mdata, tsidx );
    Alembic::AbcGeom::OC3fArrayProperty rgbOut( pSchema, "Cs", tsidx );
    Alembic::AbcGeom::OFloatArrayProperty ageOut( pSchema, "age", tsidx );

    // Seconds per frame
    Alembic::AbcCoreAbstract::chrono_t iSpf = 1.0 / iFps;

// Create a specific type of random number generator
const unsigned seed = 0u;
base_generator_type generator(seed);
// Define a uniform random number distribution which produces "double"
// values between 0 and 1 (0 inclusive, 1 exclusive).
boost::uniform_01<> uniform_distribution;
boost::variate_generator<base_generator_type&, boost::uniform_01<> > uniform_random_number_generator(generator, uniform_distribution);

    // const size_t num_particles = 16;
    std::vector<Alembic::Util::uint64_t> m_id(i_num_points);
    std::vector<Alembic::AbcGeom::V3f> m_position(i_num_points);
    std::vector<Alembic::AbcGeom::C3f> m_color(i_num_points);
    std::vector<Alembic::AbcGeom::V3f> m_velocity(i_num_points);
    std::vector<Alembic::Util::float32_t> m_age(i_num_points);
    for (size_t index=0;index<i_num_points;index++)
    {
        m_id[index] = index;
        m_position[index] = Alembic::AbcGeom::V3f(uniform_random_number_generator() - 0.5, uniform_random_number_generator() - 0.5, uniform_random_number_generator() - 0.5); //  Subtract 0.5 to center it
        m_color[index] = Alembic::AbcGeom::C3f(uniform_random_number_generator(), uniform_random_number_generator(), uniform_random_number_generator());
        m_velocity[index] = Alembic::AbcGeom::V3f(uniform_random_number_generator(), uniform_random_number_generator(), uniform_random_number_generator());
        m_age[index] = uniform_random_number_generator();
    }

    // First, write the sample.
    Alembic::AbcGeom::V3fArraySample position_data ( m_position );
    Alembic::AbcGeom::UInt64ArraySample id_data ( m_id );
    Alembic::AbcGeom::OPointsSchema::Sample psamp(position_data,
            id_data);
    pSchema.set( psamp );
    velOut.set( Alembic::AbcGeom::V3fArraySample( m_velocity ) );
    rgbOut.set( Alembic::AbcGeom::C3fArraySample( m_color ) );
    ageOut.set( Alembic::AbcGeom::FloatArraySample( m_age ) );

}

single_sample_random_points.abc

Nicholas Yue

unread,
Sep 5, 2020, 9:15:27 PM9/5/20
to alembic-discussion
Ah. I think I should be using ArbGeomParams

    void AddPointAttributes(Alembic::AbcGeom::OPointsSchema &pSchema,uint32_t tsidx)
    {
        Alembic::AbcGeom::MetaData mdata;
        Alembic::AbcGeom::SetGeometryScope(mdata, _geometry_parameter_scope);

        Alembic::AbcGeom::OCompoundProperty arbParams = pSchema.getArbGeomParams();
        bool is_param_indexed = false;
        color_geom_param.reset(new Alembic::AbcGeom::OV3fGeomParam ( arbParams, "Cd", is_param_indexed, _geometry_parameter_scope, 1, tsidx ));
        normal_geom_param.reset(new Alembic::AbcGeom::OV3fGeomParam ( arbParams, "N", is_param_indexed, _geometry_parameter_scope, 1, tsidx ));
        density_geom_param.reset(new Alembic::AbcGeom::OFloatGeomParam ( arbParams, "density", is_param_indexed, _geometry_parameter_scope, 1, tsidx ));
    }


Reply all
Reply to author
Forward
0 new messages