FBXSDK201701_fbxproj_ConvertScene00400main.cxx
/**************************************************************************************** | |
Copyright (C) 2015 Autodesk, Inc. | |
All rights reserved. | |
Use of this software is subject to the terms of the Autodesk license agreement | |
provided at the time of installation or download, or which otherwise accompanies | |
this software in either electronic or hard copy form. | |
****************************************************************************************/ | |
///////////////////////////////////////////////////////////////////////// | |
// | |
// This program converts any file in a format supported by the FBX SDK | |
// into DAE, FBX, 3DS, OBJ and DXF files. | |
// | |
// Steps: | |
// 1. Initialize SDK objects. | |
// 2. Load a file(fbx, obj,...) to a FBX scene. | |
// 3. Create a exporter. | |
// 4. Retrieve the writer ID according to the description of file format. | |
// 5. Initialize exporter with specified file format | |
// 6. Export. | |
// 7. Destroy the exporter | |
// 8. Destroy the FBX SDK manager | |
// | |
///////////////////////////////////////////////////////////////////////// | |
#include <fbxsdk.h> | |
#include "../Common/Common.h" | |
#define SAMPLE_FILENAME "box.fbx" | |
///////////////////////////////////////////////////////////////////////////////// | |
/* | |
const char* lFileTypes[] = | |
{ | |
"_dae.dae", "Collada DAE (*.dae)", | |
"_fbx7binary.fbx", "FBX binary (*.fbx)", | |
"_fbx7ascii.fbx", "FBX ascii (*.fbx)", | |
"_fbx6binary.fbx", "FBX 6.0 binary (*.fbx)", | |
"_fbx6ascii.fbx", "FBX 6.0 ascii (*.fbx)", | |
"_obj.obj", "Alias OBJ (*.obj)", | |
"_dxf.dxf", "AutoCAD DXF (*.dxf)" | |
}; | |
*/ | |
const char* lFileTypes[] = | |
{ | |
"_fbx7ascii.fbx", "FBX ascii (*.fbx)" | |
}; | |
//おまじない: | |
#include <shlwapi.h> | |
#pragma comment(lib, "ShLwApi.Lib") | |
int OutFileExistCheck(char* ShiftJis_Path) | |
{ | |
int int_PathFileExists_ = 0; | |
//関数: | |
int_PathFileExists_ = PathFileExists(ShiftJis_Path); | |
if (int_PathFileExists_ == 1) | |
{ | |
FBXSDK_printf("ファイルすでにあるから iN Out 実行できません ShiftJis_Path= "); FBXSDK_printf(ShiftJis_Path); FBXSDK_printf("\n"); | |
} | |
else | |
{ | |
FBXSDK_printf("ファイルないから iN Out 実行できます。 ShiftJis_Path= "); FBXSDK_printf(ShiftJis_Path); FBXSDK_printf("\n"); | |
} | |
return int_PathFileExists_; | |
} | |
//////////////////////////////////////////////////////////////////////////////////////// | |
//時間でファイル名を変動させたい。 | |
#include <windows.h> | |
#include <string.h> | |
char* showNowTime() | |
{ | |
char* pNowTimeNameName="aaaaa.fbx"; | |
//char* pNewFileNameNowTimeNameName = "2017/01/30 16:05:55 853.fbx"; | |
char* pNewFileNameNowTimeNameName = "box_fbx7ascii_20170130160555853.fbx"; | |
char* pNewFileName00100 = "box_fbx7ascii_20170130160555853.fbx"; | |
SYSTEMTIME st; | |
GetSystemTime(&st); | |
//char *pstr[5]; の宣言は、pstrが5個の要素を持つ配列であり、 その各要素がchar型のデータを指し示すポインタであることを意味します。 | |
char szTime[25] = { 0 }; | |
// wHourを9時間足して、日本時間にする | |
//wsprintf(szTime, "%04d/%02d/%02d %02d:%02d:%02d %03d", | |
// st.wYear, st.wMonth, st.wDay, | |
// st.wHour + 9, st.wMinute, st.wSecond, st.wMilliseconds); | |
wsprintf(szTime, "box_fbx7ascii_%04d_%02d_%02d_%02d_%02d_%02d_%03d_.fbx", | |
st.wYear, st.wMonth, st.wDay, | |
st.wHour + 9, st.wMinute, st.wSecond, st.wMilliseconds); | |
FBXSDK_printf("87行目の時間だす関数 szTime = %s \n ", szTime); | |
// 余裕のある文字列を strに与えておく | |
/* | |
char *x= "AB"; | |
char *y= "CD"; | |
char *str = " "; | |
char *p = str; | |
char *w; | |
FBXSDK_printf("100行目 \n "); | |
for (w = x; *w != NULL; w++) { | |
FBXSDK_printf("102行目 \n "); | |
*p = *w; | |
FBXSDK_printf("104行目 \n "); | |
p++; | |
FBXSDK_printf("106行目 \n "); | |
} | |
FBXSDK_printf("105行目 \n "); | |
w = y; | |
while (*w != NULL) { | |
*p = *w; | |
p++; | |
w++; | |
}*/ | |
//FBXSDK_printf("110行目の時間だす関数 str = %s \n ", str); | |
//const size_t length = 60; | |
FBXSDK_printf("120行目 \n "); | |
//const char* plongLongName = "box_fbx7ascii_20170130160555853.fbx";///////////////// | |
FBXSDK_printf("122行目 plongLongName \n "); | |
FBXSDK_printf("142行目 おわり \n "); | |
return pNewFileNameNowTimeNameName; | |
} | |
//////////////////////////quita edo_m18 [C言語] 時間を扱う////////////////////////////////////// | |
#include <time.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include "GlobalTimeSec_To_UnderScoreString.h" | |
//const char* GlobalTimeSec_To_UnderScoreString() { | |
std::string GlobalTimeSec_To_UnderScoreStringFunc(){ | |
GlobalTimeSec_To_UnderScoreString GlobalTimeSec_To_UnderScoreString_intance; | |
//GlobalTimeSec_To_UnderScoreString_intance. | |
std::string GlobalTimeSec_To_UnderScoreString_method_Str = GlobalTimeSec_To_UnderScoreString_intance.GlobalTimeSec_To_UnderScoreString_method(); | |
printf("クラスからの文字列 GlobalTimeSec_To_UnderScoreString_method_Str ======= "); printf(GlobalTimeSec_To_UnderScoreString_method_Str.c_str()); printf("\n"); | |
std::string str_return = "box_fbx7ascii_2017_1_30_19_1_56_916______.fbx"; | |
const char *pNewFileNameNowTimeNameName = "box_fbx7ascii_2017_1_30_19_1_56_916______.fbx"; | |
SYSTEMTIME st; | |
GetSystemTime(&st); | |
char *sample = "2015年04月15日00時43分"; | |
int year; | |
int month; | |
int hour; | |
int day; | |
int wMinute; | |
int wSecond; | |
int wMilliseconds; | |
//int型からchar型への変換 | |
int i_decimal; | |
char buffer[33]; char year_buffer1[33]; char month_buffer2[33]; char day_buffer3[33]; char hour_buffer4[33]; char wMinute_buffer5[33]; char wSecond_buffer6[33]; char wMilliseconds_buffer7[33]; char buffer8[33]; | |
i_decimal = 12654; | |
itoa(i_decimal, buffer, 10); printf("i_decimal: %s \n", buffer); | |
year = st.wYear; | |
month = st.wMonth, | |
day = st.wDay, | |
hour = st.wHour + 9, | |
wMinute = st.wMinute ; | |
wSecond = st.wSecond; | |
wMilliseconds = st.wMilliseconds; | |
itoa(year, year_buffer1, 10); printf("year: %s \n", year_buffer1); | |
itoa(month, month_buffer2, 10); printf("month: %s \n", month_buffer2); | |
itoa(day, day_buffer3, 10); printf("day: %s \n", day_buffer3); | |
itoa(hour, hour_buffer4, 10); printf("hour: %s \n", hour_buffer4); | |
itoa(wMinute, wMinute_buffer5, 10); printf("wMinute: %s \n", wMinute_buffer5); | |
itoa(wSecond, wSecond_buffer6, 10); printf("wSecond: %s \n", wSecond_buffer6); | |
itoa(wMilliseconds, wMilliseconds_buffer7, 10); | |
printf("wMilliseconds: %s \n", wMilliseconds_buffer7); | |
printf("wMilliseconds: %s \n", wMilliseconds_buffer7); | |
std::string str_year = year_buffer1; printf("str_year %s \n", str_year.c_str() ); | |
std::string str_month = month_buffer2; printf("str_month %s \n", str_month.c_str()); | |
std::string str_day = day_buffer3; printf("str_day %s \n", str_day.c_str()); | |
std::string str_hour = hour_buffer4; printf("str_hour %s \n", str_hour.c_str()); | |
std::string str_Minute = wMinute_buffer5; printf("str_Minute %s \n", str_Minute.c_str()); | |
std::string str_Second = wSecond_buffer6; printf("str_Second %s \n", str_Second.c_str()); | |
std::string str_Milliseconds = wMilliseconds_buffer7; printf("str_Milliseconds %s \n", str_Milliseconds.c_str()); | |
std::string str_ALL = str_year +"_"+ str_month + "_" + str_day + "_" + str_hour + "_" + str_Minute + "_" + str_Second + "_" + str_Milliseconds; printf("str_ALL %s \n", str_ALL.c_str()); | |
str_return = str_ALL; | |
return str_return; | |
} | |
/////////////////////////////////////////////////////////////////////////////////////// | |
//////////////////////////////////////////////////////////////////////////////////////////////// | |
int main(int argc, char** argv) | |
{ | |
FbxString lFilePath(""); | |
for( int i = 1, c = argc; i < c; ++i ) | |
{ | |
if( FbxString(argv[i]) == "-test" ) continue; | |
else if( lFilePath.IsEmpty() ) lFilePath = argv[i]; | |
} | |
if( lFilePath.IsEmpty() ) lFilePath = SAMPLE_FILENAME; | |
FbxManager* lSdkManager = NULL; | |
FbxScene* lScene = NULL; | |
// Prepare the FBX SDK. | |
InitializeSdkObjects(lSdkManager, lScene); | |
bool lResult_Load; bool lResult_Init; bool lResult_Export; | |
//ロードできたかをブールでとる | |
bool lResult = LoadScene(lSdkManager, lScene, lFilePath.Buffer()); lResult_Load = lResult; | |
if( lResult ) | |
{ | |
const size_t lFileNameLength = strlen((argc>=3)?argv[2]:lFilePath.Buffer()); | |
char* lNewFileName = new char[lFileNameLength+64]; | |
FBXSDK_strcpy(lNewFileName,lFileNameLength+64,(argc>=3)?argv[2]:lFilePath.Buffer()); | |
////////////////////////////////////////////////// | |
//strcpy関数を使うと、文字列のコピーを行うことが出来ます。 | |
FBXSDK_printf("100行目の lNewFileName= "); FBXSDK_printf(lNewFileName); FBXSDK_printf("\n"); | |
////////////////////////////////////////////////// | |
const size_t lFileTypeCount = sizeof(lFileTypes)/sizeof(lFileTypes[0])/2; | |
for(size_t i=0; i<lFileTypeCount; ++i) | |
{ | |
// Retrieve the writer ID according to the description of file format. | |
int lFormat = lSdkManager->GetIOPluginRegistry()->FindWriterIDByDescription(lFileTypes[i*2+1]); | |
// Construct the output file name. | |
FBXSDK_strcpy(lNewFileName+lFileNameLength-4,60, lFileTypes[i*2]); | |
////////////////////////////////////////////////// | |
//strcpy関数を使うと、文字列のコピーを行うことが出来ます。 | |
FBXSDK_printf("113行目の 入力 lNewFileName= "); FBXSDK_printf(lNewFileName); FBXSDK_printf("\n"); | |
int boolOutFileExistCheck = OutFileExistCheck(lNewFileName); | |
////////////////////////////////////////////////// | |
if(boolOutFileExistCheck==1) | |
{ | |
FBXSDK_printf("142 行 出力 ファイルすでにあるから iN Out 実行できません lNewFileName= "); FBXSDK_printf(lNewFileName); FBXSDK_printf("\n"); | |
//FBXSDK_strcpy(dst, size, src) strcpy_s(dst, size, src) | |
FBXSDK_printf("142 終わり \n"); | |
char* pNewFileNameNowTimeNameName = "box_fbx7ascii_20170130160555853.fbx"; | |
std::string strNowTime= "box_fbx7ascii_"+GlobalTimeSec_To_UnderScoreStringFunc()+"_.fbx"; | |
const char* pNewFileNameNowTimeNameFile = strNowTime.c_str(); | |
printf("269 戻り値 pNewFileNameNowTimeNameFile: %s \n", pNewFileNameNowTimeNameFile); | |
FBXSDK_printf("146 char* pNowTimeNameName = showNowTime(); 終わり \n"); | |
//char* pNewFileNameNowTimeNameName; | |
FBXSDK_printf("147 char* pNewFileNameNowTimeNameName; 終わり \n"); | |
//strcpy_s(char* out, rsize_t型 _SizeInBytes, char const*型 _Source); | |
//FBXSDK_strcpy(pNewFileNameNowTimeNameName, 60, pNowTimeNameName); | |
FBXSDK_printf("149 FBXSDK_strcpy(pNewFileNameNowTimeNameName, 60, pNowTimeNameName); 終わり \n"); | |
FBXSDK_printf("141 行 出力 pNewFileNameNowTimeNameName= "); FBXSDK_printf(pNewFileNameNowTimeNameName); FBXSDK_printf("\n"); | |
//FBXSDK_strcpy(lNewFileName, 60, pNewFileNameNowTimeNameName); | |
FBXSDK_strcpy(lNewFileName, 60, pNewFileNameNowTimeNameFile); | |
FBXSDK_printf("144 行 ファイルすでにあるから iN Out 実行できません ファイルの名前変えました lNewFileName= "); FBXSDK_printf(lNewFileName); FBXSDK_printf("\n"); | |
} | |
// Create an exporter. | |
FbxExporter* lExporter = FbxExporter::Create(lSdkManager, ""); | |
////lExporterの初期化できたかをブールでとる Initialize the exporter. | |
lResult = lExporter->Initialize(lNewFileName, lFormat, lSdkManager->GetIOSettings()); lResult_Init = lResult; | |
if( !lResult ) | |
{ | |
FBXSDK_printf("%s:\tCall to FbxExporter::Initialize() failed.\n", lFileTypes[i*2+1]); | |
FBXSDK_printf("Error returned: %s\n\n", lExporter->GetStatus().GetErrorString()); | |
} | |
else | |
{ | |
////lExporterエクスポート シーンできたかをブールでとる Export the scene. | |
lResult = lExporter->Export(lScene); lResult_Export = lResult; | |
if( !lResult ) | |
{ | |
FBXSDK_printf("Call to FbxExporter::Export() failed.\n"); | |
} | |
} | |
// Destroy the exporter. | |
lExporter->Destroy(); | |
} | |
delete[] lNewFileName; | |
} | |
else | |
{ | |
FBXSDK_printf("Call to LoadScene() failed.\n"); | |
} | |
// Delete the FBX SDK manager. All the objects that have been allocated | |
// using the FBX SDK manager and that haven't been explicitly destroyed | |
// are automatically destroyed at the same time. | |
DestroySdkObjects(lSdkManager, lResult); | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
c++
FbxIOPluginRegistry クラス
int FindWriterIDByDescription (const char *pDesc) const
https://whaison.github.io/FBXpythonSDK201701/FBXcppSDKdoxygen01200/html/class_fbx_i_o_plugin_registry.html#afb8a3db5c0234b9a275be784b75e5748
https://whaison.github.io/FBXpythonSDK201701/FBXcppSDKdoxygen01200/html/class_fbx_i_o_plugin_registry-members.html
python
FbxIOPluginRegistry.GetNativeWriterFormat;
FbxIOPluginRegistry.GetNativeWriterFormat;
https://whaison.github.io/FBXpythonSDK201701/FBXpythonSDKdoxygen01200/html/class_fbx_i_o_plugin_registry.html
https://github.com/whaison/FBXpythonSDK201701/blob/master/FBXpythonSDKdoxygen01200/html/class_fbx_i_o_plugin_registry-members.html