Fixed coding errors

This commit is contained in:
Perfare 2019-07-16 05:32:54 +08:00
parent 50c17c2ec4
commit eb4981808b
3 changed files with 21 additions and 28 deletions

View File

@ -2,9 +2,14 @@
namespace AssetStudio
{
char* Fbx::StringToCharArray(String^ s)
char* Fbx::StringToUTF8(String^ s)
{
return (char*)(void*)Marshal::StringToHGlobalAnsi(s);
auto bytes = Text::Encoding::UTF8->GetBytes(s);
auto chars = new char[bytes->Length + 1];
pin_ptr<unsigned char> ptr = &bytes[0];
memcpy(chars, ptr, bytes->Length);
chars[bytes->Length] = '\0';
return chars;
}
void Fbx::Init(FbxManager** pSdkManager, FbxScene** pScene)

View File

@ -10,19 +10,18 @@
using namespace System;
using namespace System::Collections::Generic;
using namespace System::IO;
using namespace System::Runtime::InteropServices;
#define WITH_MARSHALLED_STRING(name,str,block)\
{ \
char* name; \
try \
{ \
name = StringToCharArray(str); \
name = StringToUTF8(str); \
block \
} \
finally \
{ \
Marshal::FreeHGlobal((IntPtr)name); \
delete name; \
} \
}
@ -43,13 +42,13 @@ namespace AssetStudio {
public:
static Vector3 QuaternionToEuler(Quaternion q);
static Quaternion EulerToQuaternion(Vector3 v);
static char* StringToCharArray(String^ s);
static char* StringToUTF8(String^ s);
static void Init(FbxManager** pSdkManager, FbxScene** pScene);
ref class Exporter
{
public:
static void Export(String^ path, IImported^ imported, bool eulerFilter, float filterPrecision, bool allFrames, bool allBones, bool skins, float boneSize, float scaleFactor, bool flatInbetween, int versionIndex, bool isAscii);
static void Export(String^ name, IImported^ imported, bool eulerFilter, float filterPrecision, bool allFrames, bool allBones, bool skins, float boneSize, float scaleFactor, bool flatInbetween, int versionIndex, bool isAscii);
private:
bool exportSkins;

View File

@ -12,9 +12,8 @@ namespace AssetStudio
}
String^ currentDir = Directory::GetCurrentDirectory();
Directory::SetCurrentDirectory(dir->FullName);
path = Path::GetFileName(path);
Exporter^ exporter = gcnew Exporter(path, imported, allFrames, allBones, skins, boneSize, scaleFactor, versionIndex, isAscii);
auto name = Path::GetFileName(path);
Exporter^ exporter = gcnew Exporter(name, imported, allFrames, allBones, skins, boneSize, scaleFactor, versionIndex, isAscii);
//TODO exporter->ExportMorphs(false, flatInbetween);
exporter->ExportAnimations(eulerFilter, filterPrecision, flatInbetween);
exporter->pExporter->Export(exporter->pScene);
@ -23,7 +22,7 @@ namespace AssetStudio
Directory::SetCurrentDirectory(currentDir);
}
Fbx::Exporter::Exporter(String^ path, IImported^ imported, bool allFrames, bool allBones, bool skins, float boneSize, float scaleFactor, int versionIndex, bool isAscii)
Fbx::Exporter::Exporter(String^ name, IImported^ imported, bool allFrames, bool allBones, bool skins, float boneSize, float scaleFactor, int versionIndex, bool isAscii)
{
this->imported = imported;
exportSkins = skins;
@ -51,7 +50,7 @@ namespace AssetStudio
FbxGlobalSettings& globalSettings = pScene->GetGlobalSettings();
globalSettings.SetSystemUnit(FbxSystemUnit(scaleFactor));
cDest = StringToCharArray(path);
cDest = StringToUTF8(name);
pExporter = FbxExporter::Create(pScene, "");
int pFileFormat = 0;
@ -155,7 +154,7 @@ namespace AssetStudio
}
if (cDest != NULL)
{
Marshal::FreeHGlobal((IntPtr)cDest);
delete cDest;
}
}
@ -387,7 +386,7 @@ namespace AssetStudio
char* pMatName = NULL;
try
{
pMatName = StringToCharArray(mat->Name);
pMatName = StringToUTF8(mat->Name);
int foundMat = -1;
for (int j = 0; j < pMaterials->GetCount(); j++)
{
@ -467,7 +466,7 @@ namespace AssetStudio
}
finally
{
Marshal::FreeHGlobal((IntPtr)pMatName);
delete pMatName;
}
}
@ -579,7 +578,7 @@ namespace AssetStudio
char* pTexName = NULL;
try
{
pTexName = StringToCharArray(matTexName);
pTexName = StringToUTF8(matTexName);
int foundTex = -1;
for (int i = 0; i < pTextures->GetCount(); i++)
{
@ -608,17 +607,7 @@ namespace AssetStudio
pTex->SetRotation(0.0, 0.0);
pTextures->Add(pTex);
String^ path = Path::GetDirectoryName(gcnew String(pExporter->GetFileName().Buffer()));
if (path == String::Empty)
{
path = ".";
}
FileInfo^ file = gcnew FileInfo(path + Path::DirectorySeparatorChar + Path::GetFileName(matTex->Name));
DirectoryInfo^ dir = file->Directory;
if (!dir->Exists)
{
dir->Create();
}
FileInfo^ file = gcnew FileInfo(matTex->Name);
BinaryWriter^ writer = gcnew BinaryWriter(file->Create());
writer->Write(matTex->Data);
writer->Close();
@ -626,7 +615,7 @@ namespace AssetStudio
}
finally
{
Marshal::FreeHGlobal((IntPtr)pTexName);
delete pTexName;
}
}