summaryrefslogtreecommitdiff
path: root/avmedia
diff options
context:
space:
mode:
authorMatúš Kukan <matus.kukan@collabora.com>2014-05-12 18:01:38 +0200
committerMatúš Kukan <matus.kukan@collabora.com>2014-05-13 16:34:49 +0200
commit0bd49edc1ffd3717a75952bb8512110a5503d74b (patch)
tree78b099b6c3d00435f3d215ae2453bc8d4a4e9c14 /avmedia
parentd575917016f65a7322817a8e13ec25c52d18a600 (diff)
Use collada2gltf to open .dae files and convert them to .json.
Change-Id: Idb70da1db2516eeb6d518b39eb732a7e7d0a14ab
Diffstat (limited to 'avmedia')
-rw-r--r--avmedia/Library_avmedia.mk15
-rw-r--r--avmedia/source/framework/modeltools.cxx33
2 files changed, 45 insertions, 3 deletions
diff --git a/avmedia/Library_avmedia.mk b/avmedia/Library_avmedia.mk
index a77fb2908c93..fcd4a07c713a 100644
--- a/avmedia/Library_avmedia.mk
+++ b/avmedia/Library_avmedia.mk
@@ -46,6 +46,21 @@ $(eval $(call gb_Library_use_libraries,avmedia,\
$(gb_UWINAPI) \
))
+ifneq (,$(filter COLLADA2GLTF,$(BUILD_TYPE)))
+$(eval $(call gb_Library_set_warnings_not_errors,avmedia))
+
+$(eval $(call gb_Library_use_externals,avmedia,\
+ collada2gltf \
+ libxml2 \
+ opencollada_parser \
+ png \
+))
+
+$(eval $(call gb_Library_add_defs,avmedia,\
+ -DENABLE_COLLADA2GLTF \
+))
+endif
+
$(eval $(call gb_Library_add_exception_objects,avmedia,\
avmedia/source/framework/mediacontrol \
avmedia/source/framework/mediaitem \
diff --git a/avmedia/source/framework/modeltools.cxx b/avmedia/source/framework/modeltools.cxx
index 6dff44bd1a92..0d517441a3ca 100644
--- a/avmedia/source/framework/modeltools.cxx
+++ b/avmedia/source/framework/modeltools.cxx
@@ -19,11 +19,18 @@
#include <comphelper/processfactory.hxx>
#include <tools/urlobj.hxx>
#include <ucbhelper/content.hxx>
+#include <unotools/localfilehelper.hxx>
+#include <unotools/tempfile.hxx>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <boost/foreach.hpp>
+#ifdef ENABLE_COLLADA2GLTF
+#include <COLLADA2GLTFWriter.h>
+#include <GLTFAsset.h>
+#endif
+
#include <string>
#include <vector>
@@ -130,9 +137,29 @@ static void lcl_EmbedExternals(const OUString& rSourceURL, uno::Reference<embed:
bool Embed3DModel( const uno::Reference<frame::XModel>& xModel,
const OUString& rSourceURL, OUString& o_rEmbeddedURL)
{
+ OUString sSource = rSourceURL;
+#ifdef ENABLE_COLLADA2GLTF
+ if (rSourceURL.endsWith("dae"))
+ {
+ OUString sName = ::utl::TempFile::CreateTempName();
+ // remove .tmp extension
+ sName = sName.copy(0, sName.getLength() - 4);
+ const INetURLObject aSourceURLObj(rSourceURL);
+ std::string sSourcePath = OUStringToOString( aSourceURLObj.getFSysPath(INetURLObject::FSYS_DETECT), RTL_TEXTENCODING_UTF8 ).getStr();
+
+ std::shared_ptr <GLTF::GLTFAsset> asset(new GLTF::GLTFAsset());
+ asset->setInputFilePath(sSourcePath);
+ asset->setBundleOutputPath(OUStringToOString( sName, RTL_TEXTENCODING_UTF8 ).getStr());
+ GLTF::COLLADA2GLTFWriter writer(asset);
+ writer.write();
+ // Path to the .json file created by COLLADA2GLTFWriter
+ ::utl::LocalFileHelper::ConvertPhysicalNameToURL(sName + "/" + GetFilename(sName) + ".json", sSource);
+ }
+#endif
+
try
{
- ::ucbhelper::Content aSourceContent(rSourceURL,
+ ::ucbhelper::Content aSourceContent(sSource,
uno::Reference<ucb::XCommandEnvironment>(),
comphelper::getProcessComponentContext());
@@ -148,13 +175,13 @@ bool Embed3DModel( const uno::Reference<frame::XModel>& xModel,
xStorage->openStorageElement(sModel, embed::ElementModes::WRITE));
// Own storage of the corresponding model
- const OUString sFilename(GetFilename(rSourceURL));
+ const OUString sFilename(GetFilename(sSource));
const OUString sGLTFDir(sFilename.copy(0,sFilename.lastIndexOf('.')));
uno::Reference<embed::XStorage> const xSubStorage(
xModelStorage->openStorageElement(sGLTFDir, embed::ElementModes::WRITE));
// Embed external resources
- lcl_EmbedExternals(rSourceURL, xSubStorage, aSourceContent);
+ lcl_EmbedExternals(sSource, xSubStorage, aSourceContent);
// Save model file (.json)
uno::Reference<io::XStream> const xStream(