Exemple #1
0
//-*****************************************************************************
void lightTest()
{
    std::string fileName = "light1.abc";

    {
        OArchive archive( Alembic::AbcCoreHDF5::WriteArchive(), fileName );
        OLight emptyLightObj( OObject( archive, kTop ), "emptyLight" );
        OLight lightObj( OObject( archive, kTop ), "myLight" );

        CameraSample samp;
        lightObj.getSchema().setCameraSample( samp );
        samp = CameraSample( -0.35, 0.75, 0.1, 0.5 );
        samp.setChildBounds( Abc::Box3d(
            Abc::V3d( 0.0, 0.1, 0.2), Abc::V3d( 0.3, 0.4, 0.5 ) ) );
        lightObj.getSchema().setCameraSample( samp );

        Abc::OCompoundProperty arb = lightObj.getSchema().getArbGeomParams();
        OFloatGeomParam param(arb, "test", false,
            Alembic::AbcGeom::kConstantScope, 1);
        Abc::OCompoundProperty user = lightObj.getSchema().getUserProperties();
        OFloatProperty(user, "test");
    }

    {
        CameraSample samp;
        double top, bottom, left, right;

        IArchive archive( Alembic::AbcCoreHDF5::ReadArchive(), fileName );
        ILight emptyLightObj( IObject( archive, kTop ), "emptyLight" );
        ILight lightObj( IObject( archive, kTop ), "myLight" );

        TESTING_ASSERT( ! emptyLightObj.getSchema().getArbGeomParams() );
        TESTING_ASSERT( ! emptyLightObj.getSchema().getUserProperties() );
        TESTING_ASSERT( ! emptyLightObj.getSchema().getCameraSchema().valid() );
        TESTING_ASSERT(
            lightObj.getSchema().getArbGeomParams().getNumProperties() == 1 );
        TESTING_ASSERT(
            lightObj.getSchema().getUserProperties().getNumProperties() == 1 );

        lightObj.getSchema().getCameraSchema().get( samp, 0 );
        samp.getScreenWindow( top, bottom, left, right );
        TESTING_ASSERT( almostEqual( top, 0.666666666666667 ) );
        TESTING_ASSERT( almostEqual( bottom, -0.666666666666667 ) );
        TESTING_ASSERT( almostEqual( left, -1.0 ) );
        TESTING_ASSERT( almostEqual( right, 1.0 ) );

        lightObj.getSchema().getCameraSchema().get( samp, 1 );
        samp.getScreenWindow( top, bottom, left, right );
        TESTING_ASSERT( almostEqual( top, -0.35 ) );
        TESTING_ASSERT( almostEqual( bottom, 0.75 ) );
        TESTING_ASSERT( almostEqual( left, 0.1 ) );
        TESTING_ASSERT( almostEqual( right, 0.5 ) );

        TESTING_ASSERT(
            ! lightObj.getSchema().getCameraSchema().getChildBoundsProperty() );
    }
}
IECore::ObjectPtr FromAlembicCameraConverter::doAlembicConversion( const Alembic::Abc::IObject &iObject, const Alembic::Abc::ISampleSelector &sampleSelector, const IECore::CompoundObject *operands ) const
{
	ICamera iCamera( iObject, kWrapExisting );
	ICameraSchema &iCameraSchema = iCamera.getSchema();
	CameraSample sample;
	iCameraSchema.get( sample, sampleSelector );
	
	CameraPtr result = new Camera;
	result->parameters()["projection"] = new StringData( "perspective" );
	
	double top, bottom, left, right;
	sample.getScreenWindow( top, bottom, left, right );
	result->parameters()["screenWindow"] = new Box2fData( Box2f( V2f( left, bottom ), V2f( right, top ) ) );
	result->parameters()["projection:fov"] = new FloatData( sample.getFieldOfView() );
	
	return result;
}