MCPcopy Create free account
hub / github.com/KhronosGroup/OpenCOLLADA / exportImage

Method exportImage

COLLADAMax/src/COLLADAMaxEffectTextureExporter.cpp:227–303  ·  view source on GitHub ↗

--------------------------------------------------------------- String EffectTextureExporter::exportImage ( const MObject &texture ) { // Retrieve the texture filename MFnDependencyNode textureNode ( texture ); MString mayaName = textureNode.name(); MPlug filenamePlug = textureNode.findPlug ( ATTR_FILE_TEXTURE_NAME ); // Get the maya image id. S

Source from the content-addressed store, hash-verified

225 */
226 // -------------------------------
227 COLLADASW::Image* EffectTextureExporter::exportImage (
228 const String& mayaImageId,
229 const String& colladaImageId,
230 const COLLADASW::URI& sourceUri )
231 {
232 // Get the file name and the URI
233 COLLADASW::URI fullFileNameURI;
234 bool sourceFileExist = getTextureFileInfos ( sourceUri, fullFileNameURI );
235 String fullFileName = fullFileNameURI.toNativePath ();
236
237 // Have we seen this texture node before?
238 ImageMap::iterator exportedImagesIter = mExportedImageMap.find ( fullFileName );
239 if ( exportedImagesIter != mExportedImageMap.end() )
240 {
241 COLLADASW::Image* colladaImage = ( *exportedImagesIter ).second;
242 return colladaImage;
243 }
244
245 // Check, if we should copy the texture to the destination folder.
246
247 if ( mDocumentExporter->getOptions().getCopyImages() )
248 {
249 // Get the target file from source file.
250 COLLADASW::URI targetUri = createTargetURI ( sourceUri );
251
252 bool exists = COLLADABU::Utils::fileExistsAndIsReadable( sourceUri.toNativePath() );
253 if ( !exists )
254 {
255 String message = "The source texture file doesn't exist! Filename = " + sourceUri.toNativePath();
256 GetCOREInterface()->Log()->LogEntry( SYSLOG_ERROR, DISPLAY_DIALOG, _M( "Image export problem" ),_M( "%s\n" ), message.c_str() );
257 }
258 else
259 {
260 // Copy the texture, if it isn't already there...
261 exists = COLLADABU::Utils::fileExistsAndIsReadable( targetUri.toNativePath() );
262 if ( !exists )
263 {
264 try
265 {
266 // Create the target directory, if necessary.
267 // Note: some systems (window$) requires the string to be
268 // enclosed in quotes when a space is present.
269 COLLADASW::URI targetPathUri ( targetUri.getPathDir() );
270 exists = COLLADABU::Utils::createDirectoryIfNeeded( targetPathUri.toNativePath() );
271
272 if( exists )
273 {
274 // Throws: basic_filesystem_error<Path> if
275 // from_fp.empty() || to_fp.empty() ||!exists(from_fp) || !is_regular(from_fp) || exists(to_fp)
276 exists = COLLADABU::Utils::copyFile ( sourceUri.toNativePath(), targetUri.toNativePath() );
277 }
278 }
279 catch ( std::exception ex )
280 {
281 exists = false;
282 }
283
284 if( !exists )

Callers

nothing calls this directly

Calls 6

toNativePathMethod · 0.80
getCopyImagesMethod · 0.80
c_strMethod · 0.80
getPathDirMethod · 0.80
endMethod · 0.45
LogMethod · 0.45

Tested by

no test coverage detected