summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZolnai Tamás <tamas.zolnai@collabora.com>2014-06-13 00:20:36 +0200
committerZolnai Tamás <tamas.zolnai@collabora.com>2014-06-13 00:33:44 +0200
commit31f386caa16413c7751855d491b4421441bfd758 (patch)
tree2c8657f914f8dffe604ff07dd2f25d50b038dbf4
parenta25a461b213450d797bfeed1fc4d4169841e35bd (diff)
Extract kmz and collada converter code to a seperate function
Plus fix some problems related to temp files. e.g. kmz converter was creating temp files next to the input file. Change-Id: Ib3f367fe1c4ef3cb25f5ca1c3d06b2dde78c5e45 (cherry picked from commit 573ced4087f46788a8596fb89c657d3427be4bf8)
-rw-r--r--avmedia/source/framework/modeltools.cxx140
-rw-r--r--include/avmedia/modeltools.hxx2
2 files changed, 82 insertions, 60 deletions
diff --git a/avmedia/source/framework/modeltools.cxx b/avmedia/source/framework/modeltools.cxx
index 7de35f7855ab..490db487efa1 100644
--- a/avmedia/source/framework/modeltools.cxx
+++ b/avmedia/source/framework/modeltools.cxx
@@ -41,6 +41,84 @@ using namespace boost::property_tree;
namespace avmedia {
+#ifdef ENABLE_COLLADA2GLTF
+bool KmzDae2Gltf(const OUString& rSourceURL, OUString& o_rOutput)
+{
+ o_rOutput = OUString();
+ const bool bIsDAE = rSourceURL.endsWithIgnoreAsciiCase(".dae");
+ const bool bIsKMZ = rSourceURL.endsWithIgnoreAsciiCase(".kmz");
+ if( !bIsDAE && !bIsKMZ )
+ {
+ SAL_WARN("avmedia.opengl", "KmzDae2Gltf converter got a file with wrong extension\n" << rSourceURL);
+ return false;
+ }
+
+ // Create a temporary folder for conversion
+ OUString sOutput;
+ ::utl::LocalFileHelper::ConvertPhysicalNameToURL(::utl::TempFile::CreateTempName(), sOutput);
+ // remove .tmp extension
+ sOutput = sOutput.copy(0, sOutput.getLength()-4);
+
+ std::shared_ptr <GLTF::GLTFAsset> asset(new GLTF::GLTFAsset());
+ asset->setBundleOutputPath(OUStringToOString( sOutput, RTL_TEXTENCODING_UTF8 ).getStr());
+
+ // If *.dae file is not in the local file system, then copy it to a temp folder for the conversion
+ // KMZ covnerter need a temp folder in all case, because it creates temp files next to the source file
+ OUString sInput = rSourceURL;
+ const INetURLObject aSourceURLObj(rSourceURL);
+ if( bIsKMZ || aSourceURLObj.GetProtocol() != INET_PROT_FILE )
+ {
+ try
+ {
+ ::ucbhelper::Content aSourceContent(rSourceURL,
+ uno::Reference<ucb::XCommandEnvironment>(),
+ comphelper::getProcessComponentContext());
+
+ const OUString sTarget = sOutput + "/" + GetFilename(rSourceURL);
+ ::ucbhelper::Content aTempContent(sTarget,
+ uno::Reference<ucb::XCommandEnvironment>(),
+ comphelper::getProcessComponentContext());
+
+ aTempContent.writeStream(aSourceContent.openStream(), true);
+ sInput = sTarget;
+ }
+ catch (const uno::Exception&)
+ {
+ SAL_WARN("avmedia.opengl", "Exception while trying to copy source file to the temp folder for conversion:\n" << sInput);
+ return false;
+ }
+ }
+
+ asset->setInputFilePath(OUStringToOString( sInput, RTL_TEXTENCODING_UTF8 ).getStr());
+
+ if (bIsKMZ)
+ {
+ // KMZ converter needs a system path
+ const std::string sSourcePath =
+ OUStringToOString( INetURLObject(sInput).getFSysPath(INetURLObject::FSYS_DETECT), RTL_TEXTENCODING_UTF8 ).getStr();
+ const std::string strDaeFilePath = GLTF::Kmz2Collada()(sSourcePath);
+ if (strDaeFilePath == "")
+ {
+ SAL_WARN("avmedia.opengl", "Kmz2Collada converter return with an empty URL\n" << rSourceURL);
+ return false;
+ }
+
+ // DAE converter needs URL
+ OUString sDaeFilePath;
+ ::utl::LocalFileHelper::ConvertPhysicalNameToURL(
+ OStringToOUString(OString(strDaeFilePath.c_str()), RTL_TEXTENCODING_UTF8 ), sDaeFilePath);
+ asset->setInputFilePath(OUStringToOString( sDaeFilePath, RTL_TEXTENCODING_UTF8 ).getStr());
+ }
+
+ GLTF::COLLADA2GLTFWriter writer(asset);
+ writer.write();
+ // Path to the .json file created by COLLADA2GLTFWriter
+ o_rOutput = sOutput + "/" + GetFilename(sOutput) + ".json";
+
+ return true;
+}
+#endif
+
static void lcl_EmbedExternals(const OUString& rSourceURL, uno::Reference<embed::XStorage> xSubStorage, ::ucbhelper::Content& rContent)
{
// Create a temp file with which json parser can work.
@@ -148,66 +226,8 @@ bool Embed3DModel( const uno::Reference<frame::XModel>& xModel,
{
OUString sSource = rSourceURL;
#ifdef ENABLE_COLLADA2GLTF
- const bool bIsDAE = rSourceURL.endsWithIgnoreAsciiCase(".dae");
- const bool bIsKMZ = rSourceURL.endsWithIgnoreAsciiCase(".kmz");
- if (bIsDAE || bIsKMZ)
- {
- std::shared_ptr <GLTF::GLTFAsset> asset(new GLTF::GLTFAsset());
-
- OUString sOutput;
- ::utl::LocalFileHelper::ConvertPhysicalNameToURL(::utl::TempFile::CreateTempName(), sOutput);
- // remove .tmp extension
- sOutput = sOutput.copy(0, sOutput.getLength()-4);
- asset->setBundleOutputPath(OUStringToOString( sOutput, RTL_TEXTENCODING_UTF8 ).getStr());
-
- const INetURLObject aSourceURLObj(sSource);
- // If *.dae or *.kmz file is not in the local file system, then copy them to a temp folder for the conversion
- if(aSourceURLObj.GetProtocol() != INET_PROT_FILE )
- {
- try
- {
- ::ucbhelper::Content aSourceContent(sSource,
- uno::Reference<ucb::XCommandEnvironment>(),
- comphelper::getProcessComponentContext());
-
- const OUString sTarget = sOutput + GetFilename(sSource);
- ::ucbhelper::Content aTempContent(sTarget,
- uno::Reference<ucb::XCommandEnvironment>(),
- comphelper::getProcessComponentContext());
-
- aTempContent.writeStream(aSourceContent.openStream(), true);
- sSource = sTarget;
- }
- catch (const uno::Exception&)
- {
- SAL_WARN("avmedia.opengl", "Exception while trying to copy source file to the temp folder for conversion:\n" << sSource);
- return false;
- }
- }
-
- asset->setInputFilePath(OUStringToOString( sSource, RTL_TEXTENCODING_UTF8 ).getStr());
-
- if (bIsKMZ)
- {
- // KMZ converter needs a system path
- const std::string sSourcePath =
- OUStringToOString( aSourceURLObj.getFSysPath(INetURLObject::FSYS_DETECT), RTL_TEXTENCODING_UTF8 ).getStr();
- const std::string strDaeFilePath = GLTF::Kmz2Collada()(sSourcePath);
- if (strDaeFilePath == "")
- return false;
-
- // DAE converter needs URL
- OUString sDaeFilePath;
- ::utl::LocalFileHelper::ConvertPhysicalNameToURL(
- OStringToOUString(OString(strDaeFilePath.c_str()), RTL_TEXTENCODING_UTF8 ), sDaeFilePath);
- asset->setInputFilePath(OUStringToOString( sDaeFilePath, RTL_TEXTENCODING_UTF8 ).getStr());
- }
-
- GLTF::COLLADA2GLTFWriter writer(asset);
- writer.write();
- // Path to the .json file created by COLLADA2GLTFWriter
- sSource = sOutput + "/" + GetFilename(sOutput) + ".json";
- }
+ if( !rSourceURL.endsWithIgnoreAsciiCase(".json") )
+ KmzDae2Gltf(rSourceURL, sSource);
#endif
try
diff --git a/include/avmedia/modeltools.hxx b/include/avmedia/modeltools.hxx
index 3de866dd7f52..ed2de44cf64b 100644
--- a/include/avmedia/modeltools.hxx
+++ b/include/avmedia/modeltools.hxx
@@ -13,6 +13,8 @@
namespace avmedia {
+bool KmzDae2Gltf(const OUString& rSourceURL, OUString& o_rOutput);
+
bool AVMEDIA_DLLPUBLIC Embed3DModel(
const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel>& xModel,
const OUString& rSourceURL, OUString& o_rEmbeddedURL);