Kaydet (Commit) 0bd49edc authored tarafından Matúš Kukan's avatar Matúš Kukan

Use collada2gltf to open .dae files and convert them to .json.

Change-Id: Idb70da1db2516eeb6d518b39eb732a7e7d0a14ab
üst d5759170
...@@ -46,6 +46,21 @@ $(eval $(call gb_Library_use_libraries,avmedia,\ ...@@ -46,6 +46,21 @@ $(eval $(call gb_Library_use_libraries,avmedia,\
$(gb_UWINAPI) \ $(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,\ $(eval $(call gb_Library_add_exception_objects,avmedia,\
avmedia/source/framework/mediacontrol \ avmedia/source/framework/mediacontrol \
avmedia/source/framework/mediaitem \ avmedia/source/framework/mediaitem \
......
...@@ -19,11 +19,18 @@ ...@@ -19,11 +19,18 @@
#include <comphelper/processfactory.hxx> #include <comphelper/processfactory.hxx>
#include <tools/urlobj.hxx> #include <tools/urlobj.hxx>
#include <ucbhelper/content.hxx> #include <ucbhelper/content.hxx>
#include <unotools/localfilehelper.hxx>
#include <unotools/tempfile.hxx>
#include <boost/property_tree/ptree.hpp> #include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp> #include <boost/property_tree/json_parser.hpp>
#include <boost/foreach.hpp> #include <boost/foreach.hpp>
#ifdef ENABLE_COLLADA2GLTF
#include <COLLADA2GLTFWriter.h>
#include <GLTFAsset.h>
#endif
#include <string> #include <string>
#include <vector> #include <vector>
...@@ -130,9 +137,29 @@ static void lcl_EmbedExternals(const OUString& rSourceURL, uno::Reference<embed: ...@@ -130,9 +137,29 @@ static void lcl_EmbedExternals(const OUString& rSourceURL, uno::Reference<embed:
bool Embed3DModel( const uno::Reference<frame::XModel>& xModel, bool Embed3DModel( const uno::Reference<frame::XModel>& xModel,
const OUString& rSourceURL, OUString& o_rEmbeddedURL) 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 try
{ {
::ucbhelper::Content aSourceContent(rSourceURL, ::ucbhelper::Content aSourceContent(sSource,
uno::Reference<ucb::XCommandEnvironment>(), uno::Reference<ucb::XCommandEnvironment>(),
comphelper::getProcessComponentContext()); comphelper::getProcessComponentContext());
...@@ -148,13 +175,13 @@ bool Embed3DModel( const uno::Reference<frame::XModel>& xModel, ...@@ -148,13 +175,13 @@ bool Embed3DModel( const uno::Reference<frame::XModel>& xModel,
xStorage->openStorageElement(sModel, embed::ElementModes::WRITE)); xStorage->openStorageElement(sModel, embed::ElementModes::WRITE));
// Own storage of the corresponding model // Own storage of the corresponding model
const OUString sFilename(GetFilename(rSourceURL)); const OUString sFilename(GetFilename(sSource));
const OUString sGLTFDir(sFilename.copy(0,sFilename.lastIndexOf('.'))); const OUString sGLTFDir(sFilename.copy(0,sFilename.lastIndexOf('.')));
uno::Reference<embed::XStorage> const xSubStorage( uno::Reference<embed::XStorage> const xSubStorage(
xModelStorage->openStorageElement(sGLTFDir, embed::ElementModes::WRITE)); xModelStorage->openStorageElement(sGLTFDir, embed::ElementModes::WRITE));
// Embed external resources // Embed external resources
lcl_EmbedExternals(rSourceURL, xSubStorage, aSourceContent); lcl_EmbedExternals(sSource, xSubStorage, aSourceContent);
// Save model file (.json) // Save model file (.json)
uno::Reference<io::XStream> const xStream( uno::Reference<io::XStream> const xStream(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment