asf::auto_release_ptr<asr::Object> IECoreAppleseed::BatchPrimitiveConverter::doConvertPrimitive( PrimitivePtr primitive, const string &name ) { MurmurHash primitiveHash; primitiveHash.append( name ); primitive->hash( primitiveHash ); if( primitive->typeId() == MeshPrimitiveTypeId ) { // Check if we already have a mesh saved for this object. string fileName = string( "_geometry/" ) + primitiveHash.toString() + m_meshGeomExtension; filesystem::path p = m_projectPath / fileName; if( !filesystem::exists( p ) ) { ToAppleseedConverterPtr converter = ToAppleseedConverter::create( primitive.get() ); if( !converter ) { msg( Msg::Warning, "IECoreAppleseed::BatchPrimitiveConverter", "Couldn't convert primitive." ); return asf::auto_release_ptr<asr::Object>(); } asf::auto_release_ptr<asr::Object> entity; entity.reset( static_cast<asr::Object*>( converter->convert() ) ); if( entity.get() == 0 ) { msg( Msg::Warning, "IECoreAppleseed::BatchPrimitiveConverter", "Couldn't convert primitive." ); return asf::auto_release_ptr<asr::Object>(); } // Write the mesh to a file. p = m_projectPath / fileName; if( !asr::MeshObjectWriter::write( static_cast<const asr::MeshObject&>( *entity ), name.c_str(), p.string().c_str() ) ) { msg( Msg::Warning, "IECoreAppleseed::BatchPrimitiveConverter", "Couldn't save mesh primitive." ); return asf::auto_release_ptr<asr::Object>(); } } asf::auto_release_ptr<asr::MeshObject> meshObj( asr::MeshObjectFactory().create( name.c_str(), asr::ParamArray().insert( "filename", fileName.c_str() ) ) ); return asf::auto_release_ptr<asr::Object>( meshObj.release() ); } return asf::auto_release_ptr<asr::Object>(); }
asf::auto_release_ptr<asr::Object> IECoreAppleseed::InteractivePrimitiveConverter::doConvertPrimitive( PrimitivePtr primitive, const string &name ) { if( primitive->typeId() == MeshPrimitiveTypeId ) { MeshPrimitive *meshPrimitive = static_cast<MeshPrimitive *>( primitive.get() ); asf::auto_release_ptr<asr::MeshObject> entity( MeshAlgo::convert( meshPrimitive ) ); if( entity.get() ) { entity->set_name( name.c_str() ); } else { msg( Msg::Warning, "IECoreAppleseed::PrimitiveConverter", "Couldn't convert object" ); } return asf::auto_release_ptr<asr::Object>( entity.release() ); } return asf::auto_release_ptr<asr::Object>(); }