UE4 button插件,简单的把Max Transform 转换 然后在关卡中生成模型

来源:互联网 发布:生产工艺过程演示软件 编辑:程序博客网 时间:2024/06/08 17:42

代码 糙的一比。。实在太菜了。
使用了 csv,txt读入,windows 剪贴板api,UE4plugin。自己简单的记录下,美术需求的插件。
不负责任的代码,为什么用英文标注? 因为显得比较厉害啊。

void FCopyMeshModule::PluginButtonClicked(){    // Read file from the root.    IDesktopPlatform *DesktopPlatform = FDesktopPlatformModule::Get();    FString RootDir;    DesktopPlatform->GetDefaultEngineRootDir(RootDir);    TArray<FString> SelectedFiles;    DesktopPlatform->OpenFileDialog(nullptr, TEXT("Open File"), RootDir, TEXT(""), TEXT("Text file|*.txt"), EFileDialogFlags::None, SelectedFiles);    // Choose the first txt file     std::string CurrentFile(TCHAR_TO_UTF8(*SelectedFiles[0]));    // Ifstream read     ifstream readfile(CurrentFile);    // Must use "std::" about vector    std::string str;    std::vector <string> TotalString;    // Char ","  used to separate    char * dou = ",";    std::vector<string>ShowStr;    // Read the entire line, stop by "\n"    while (getline(readfile, str))    {        ShowStr.clear();        stringstream Splitstr(str);        string tempstr;        // In the loop, read and separated by commas        while (getline(Splitstr, tempstr, *dou))        {            // Pressed the result into the vector showstr.            ShowStr.push_back(tempstr);        }        string duanStr1 = "Begin Actor Class=StaticMeshActor Name=" + ShowStr[0];        string duanStr2 = " Archetype=StaticMeshActor'/Script/Engine.Default__StaticMeshActor' \n\            Begin Object Class=StaticMeshComponent Name=StaticMeshComponent0 ObjName=StaticMeshComponent0 \n\            Archetype=StaticMeshComponent'/Script/Engine.Default__StaticMeshActor:StaticMeshComponent0'\n\            End Object\n\            Begin Object Name=StaticMeshComponent0\n\            StaticMesh=StaticMesh'/Engine/EditorMeshes/EditorCube.EditorCube'\n\            RelativeLocation=(X=";        string duanStr2_1 = ShowStr[1];        string duanStr3 = ",Y=" + ShowStr[2];        string duanStr4 = ",Z=" + ShowStr[3];        string duanStr5 = ")\n\            RelativeScale3D=(X=";        string duanStr5_1 = ShowStr[7];        string duanStr6 = ",Y=" + ShowStr[8];        string duanStr7 = ",Z=" + ShowStr[9];        string duanStr8 = ")\n\            RelativeRotation=(Pitch=";        string duanStr8_1 = ShowStr[4];        string duanStr9 = ",Yaw=" + ShowStr[5];        string duanStr10 = ",Roll=" + ShowStr[6];        string duanStr11 = ")\n\            CustomProperties \n\            End Object\n\            StaticMeshComponent=StaticMeshComponent0\n\            Components(0)=StaticMeshComponent0\n\            RootComponent=StaticMeshComponent0\n\            ActorLabel=";        string duanStr11_1 = ShowStr[0];        string duanStr12 = "\n\            End Actor\n";        string total = duanStr1 + duanStr2 + duanStr2_1 + duanStr3 + duanStr4 + duanStr5 + duanStr5_1 + duanStr6 + duanStr7 + duanStr8 + duanStr8_1 + duanStr9 + duanStr10 + duanStr11 + duanStr11_1 + duanStr12;        TotalString.push_back(total);    }    string beg = "Begin Map\n BeginLevel\n";    string end = "End Level\n Begin Surface\n End Surface\n End Map\n";    string res;    // I have no idea about "TotalString.size()-1"    for (int i = 0; i < TotalString.size() - 1; i++)    {        res += TotalString[i];    }    res = beg + res + end;    // string to char    const char * mystr = res.c_str();    // Open the Chipboard    if (!OpenClipboard(NULL) || !EmptyClipboard())    {        return;    }    // window api Memory block    HGLOBAL hMen;    // Allocate global memory    hMen = GlobalAlloc(GMEM_MOVEABLE, ((strlen(mystr) + 1) * sizeof(char)));    if (!hMen)    {        CloseClipboard();        return;    }    // copy the data into the global memory test    // lock the memory area    LPSTR lpstr = (LPSTR)GlobalLock(hMen);    // Memory copy    memcpy(lpstr, mystr, ((strlen(mystr)) * sizeof(char)));    // Character terminator    lpstr[strlen(mystr)] = (char)0;    // Release the lock    GlobalLock(hMen);    // Put the data in memory on the clipboard    SetClipboardData(CF_TEXT, hMen);    CloseClipboard();    return;    // Reference, ClipboardData: http://blog.csdn.net/ycc892009/article/details/6521565}

阅读全文
0 0
原创粉丝点击