Kaydet (Commit) 436f2aa8 authored tarafından Matúš Kukan's avatar Matúš Kukan

Add kmz support to collada2gltf and use it.

Change-Id: I37cda0e326af00ef369c4415bcec1e03c91ce401
üst 969df2a0
......@@ -29,6 +29,7 @@
#ifdef ENABLE_COLLADA2GLTF
#include <COLLADA2GLTFWriter.h>
#include <GLTFAsset.h>
#include <KMZ2Collada.h>
#endif
#include <string>
......@@ -139,7 +140,7 @@ bool Embed3DModel( const uno::Reference<frame::XModel>& xModel,
{
OUString sSource = rSourceURL;
#ifdef ENABLE_COLLADA2GLTF
if (rSourceURL.endsWith("dae"))
if (rSourceURL.endsWith(".dae") || rSourceURL.endsWith(".kmz"))
{
OUString sName = ::utl::TempFile::CreateTempName();
// remove .tmp extension
......@@ -149,6 +150,14 @@ bool Embed3DModel( const uno::Reference<frame::XModel>& xModel,
std::shared_ptr <GLTF::GLTFAsset> asset(new GLTF::GLTFAsset());
asset->setInputFilePath(sSourcePath);
if (rSourceURL.endsWith(".kmz"))
{
std::string strDaeFilePath = GLTF::Kmz2Collada()(asset->getInputFilePath());
if (strDaeFilePath == "")
return false;
asset->setInputFilePath(strDaeFilePath);
}
asset->setBundleOutputPath(OUStringToOString( sName, RTL_TEXTENCODING_UTF8 ).getStr());
GLTF::COLLADA2GLTFWriter writer(asset);
writer.write();
......
......@@ -50,6 +50,7 @@ $(eval $(call gb_StaticLibrary_add_generated_exception_objects,collada2gltf,\
UnpackedTarball/collada2gltf/COLLADA2GLTFWriter \
UnpackedTarball/collada2gltf/GitSHA1 \
UnpackedTarball/collada2gltf/GLTFOpenCOLLADAUtils \
UnpackedTarball/collada2gltf/KMZ2Collada \
UnpackedTarball/collada2gltf/assetModifiers/GLTFFlipUVModifier \
UnpackedTarball/collada2gltf/convert/meshConverter \
UnpackedTarball/collada2gltf/convert/animationConverter \
......@@ -81,6 +82,11 @@ $(eval $(call gb_StaticLibrary_add_generated_exception_objects,collada2gltf,\
UnpackedTarball/collada2gltf/shaders/commonProfileShaders \
))
$(eval $(call gb_StaticLibrary_add_generated_cobjects,collada2gltf,\
UnpackedTarball/collada2gltf/kmz/ioapi \
UnpackedTarball/collada2gltf/kmz/unzip \
))
# o3dgc external library compiled from collada2gltf
$(eval $(call gb_StaticLibrary_set_include,collada2gltf,\
-I$(call gb_UnpackedTarball_get_dir,collada2gltf)/dependencies/o3dgc/src/o3dgc_common_lib/inc \
......
......@@ -13,4 +13,9 @@ $(eval $(call gb_UnpackedTarball_set_tarball,collada2gltf,$(COLLADA2GLTF_TARBALL
$(eval $(call gb_UnpackedTarball_add_file,collada2gltf,.,external/collada2gltf/GitSHA1.cpp))
$(eval $(call gb_UnpackedTarball_add_patches,collada2gltf,\
external/collada2gltf/add-unzip-kmz-files-to-collada-files-module.patch.3 \
external/collada2gltf/write-only-.dae-file-which-we-need.patch.0 \
))
# vim: set noet sw=4 ts=4:
diff --git KMZ2Collada.cpp KMZ2Collada.cpp
index d193784..3b5bdfc 100644
--- KMZ2Collada.cpp
+++ KMZ2Collada.cpp
@@ -2,7 +2,7 @@
#include "kmz/unzip.h"
#include "kmz/ioapi.h"
-#include <direct.h>
+#include <string.h>
using namespace std;
@@ -14,39 +14,19 @@ namespace GLTF{
}
- void Kmz2Collada::setFileFolder(std::string& strSrc) {
- std::string strFolderPath = "";
- char *pFolderName = new char[strSrc.size()];
-
- for (unsigned int i = 0; i < strSrc.size(); i++) {
- if (strSrc[i] == '\\' || strSrc[i] == '/') {
- pFolderName[i] = '\0';
- strFolderPath = strKmzPath + pFolderName;
- _mkdir(strFolderPath.c_str());
- }
- pFolderName[i] = strSrc[i];
- }
- strSrc = strKmzPath +strSrc;
-
- delete[] pFolderName;
- }
- void Kmz2Collada::getFilePath(std::string& strSrc) {
+ void Kmz2Collada::getFilePath(const std::string& strSrc) {
char *pTemporaryContent = new char[strSrc.size()+1];
std::string strFilePath;
for (unsigned int ipos = 0; ipos < strSrc.size(); ipos ++) {
+ pTemporaryContent[ipos] = strSrc[ipos];
if (strSrc[ipos] == '\\' || strSrc[ipos] == '/') {
- pTemporaryContent[ipos] = '\0';
+ pTemporaryContent[ipos+1] = '\0';
strFilePath = pTemporaryContent;
- _mkdir(strFilePath.c_str());
}
- pTemporaryContent[ipos] = strSrc[ipos];
}
- if (strFilePath != "")
- strFilePath += '\\';
- strSrc = strFilePath;
- strKmzPath = strSrc;
+ strKmzPath = strFilePath;
delete[] pTemporaryContent;
}
@@ -72,18 +52,24 @@ namespace GLTF{
return "";
}
- for (int i = 0; i < zGlobalInfo.number_entry; i++) {
+ for (int i = 0; i < zGlobalInfo.number_entry; i++, unzGoToNextFile(zFile)) {
if (UNZ_OK != unzGetCurrentFileInfo64(zFile, &zFileInfo,
pFileName, num, NULL, 0, NULL, 0)) {
printf("Read file error\n");
return "";
}
- std::string strFilePath = pFileName;
- setFileFolder(strFilePath);
- if (strstr(strFilePath.c_str(), ".dae"))
- strDaePath = strFilePath;
+ if (!strstr(pFileName, ".dae"))
+ continue;
- FILE *fp = fopen(strFilePath.c_str(),"wb");
+ unsigned int pos = strlen(pFileName) - 1;
+ while (pos >= 0) {
+ if (pFileName[pos] == '\\' || pFileName[pos] == '/')
+ break;
+ pos--;
+ }
+ strDaePath = strKmzPath + std::string(&pFileName[pos + 1]);
+
+ FILE *fp = fopen(strDaePath.c_str(),"wb");
if (UNZ_OK != unzOpenCurrentFile(zFile)) {
printf("Open current file error");
@@ -107,8 +93,6 @@ namespace GLTF{
fclose(fp);
delete[] pFileData;
pFileData = NULL;
-
- unzGoToNextFile(zFile);
}
unzCloseCurrentFile(zFile);
@@ -118,4 +102,4 @@ namespace GLTF{
return strDaePath;
}
-}
\ No newline at end of file
+}
diff --git KMZ2Collada.h KMZ2Collada.h
index 5e8bdef..df7e92f 100644
--- KMZ2Collada.h
+++ KMZ2Collada.h
@@ -10,11 +10,8 @@ namespace GLTF{
Kmz2Collada();
~Kmz2Collada();
- /** get the kmz file path and set folder.*/
- void setFileFolder(std::string& strSrc);
-
/** get kmz file path.*/
- void getFilePath(std::string& strSrc);
+ void getFilePath(const std::string& strSrc);
/** copy function.*/
std::string operator()(std::string strInputFile);
@@ -25,4 +22,4 @@ namespace GLTF{
};
}
-#endif
\ No newline at end of file
+#endif
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