MCPcopy Create free account
hub / github.com/ImageEngine/cortex / WriteToFile

Method WriteToFile

contrib/IECoreUSD/src/IECoreUSD/SceneCacheFileFormat.cpp:141–208  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

139}
140
141bool UsdSceneCacheFileFormat::WriteToFile( const SdfLayer& layer, const std::string& filePath, const std::string& comment, const FileFormatArguments& args) const
142{
143 const auto perFrameWriteIt = args.find( "perFrameWrite" );
144 const auto currentFrameIt = args.find( "currentFrame" );
145 const auto firstFrameIt = args.find( "firstFrame" );
146 const auto lastFrameIt = args.find( "lastFrame" );
147
148 auto frames = layer.ListAllTimeSamples();
149 // only write current frame for per frame write
150 if ( perFrameWriteIt != args.end() && args.at( "perFrameWrite" ) == "1" )
151 {
152 frames.clear();
153 frames.insert( std::stof( args.at( "currentFrame" ) ) );
154 }
155 // filter layer time sample inside frame range
156 else if ( firstFrameIt != args.end() && lastFrameIt != args.end() )
157 {
158 std::set<double> filteredFrames;
159 const double firstFrame = std::stof( args.at( "firstFrame" ) );
160 const double lastFrame = std::stof( args.at( "lastFrame" ) );
161 for( const auto& frame : frames )
162 {
163 if ( frame >= firstFrame && frame <= lastFrame )
164 {
165 filteredFrames.insert( frame );
166 }
167 }
168 frames = filteredFrames;
169 }
170
171 UsdStageRefPtr stage = UsdStage::Open( layer.GetIdentifier() );
172 ConstUSDScenePtr usdScene = new USDScene( stage, IndexedIO::Read );
173
174 auto fps = stage->GetTimeCodesPerSecond();
175 SceneInterfacePtr outScene;
176
177 outScene = SdfFileFormatSharedSceneWriters::get( filePath );
178 if ( !outScene )
179 {
180 IECore::msg( IECore::Msg::Error, "UsdSceneCacheFileFormat::WriteToFile", boost::format( "Invalid file path \"%s\" for layer \"%s\"." ) % filePath % layer.GetIdentifier() );
181 return false;
182 }
183
184 SceneInterface::NameList childNames;
185 usdScene->childNames( childNames );
186 for ( auto& childName : childNames )
187 {
188 writeLocation( layer, usdScene, childName, outScene, fps, stage, frames );
189 }
190
191 // if we wrote the last frame of the layer, it's time to close the file
192 if ( currentFrameIt != args.end() &&
193 lastFrameIt != args.end() &&
194 perFrameWriteIt != args.end() &&
195 args.at( "perFrameWrite" ) == "1" &&
196 std::stof( args.at( "currentFrame" ) ) == std::stof( args.at( "lastFrame" ) )
197 )
198 {

Callers

nothing calls this directly

Calls 7

ListAllTimeSamplesMethod · 0.80
insertMethod · 0.80
getFunction · 0.50
findMethod · 0.45
endMethod · 0.45
clearMethod · 0.45
childNamesMethod · 0.45

Tested by

no test coverage detected