Skip to content

Commit

Permalink
[ADD] : add feature #156 for modify the file infos during scan, here …
Browse files Browse the repository at this point in the history
…for the splitted gltf file format as demo

[UPD] : update of readme ofr feature #156
[UPD] : update of ImGuiFileDialog for feature #156
[ADD] : add some gltf files samples for feature #156
  • Loading branch information
aiekick committed Jan 7, 2024
1 parent b9ffef0 commit 66202bf
Show file tree
Hide file tree
Showing 13 changed files with 535 additions and 9 deletions.
2 changes: 1 addition & 1 deletion ImGuiFileDialog
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,52 @@ you can check the DemoApp who is using an override for the Boost::filesystem

</blockquote></details>

<details open><summary><h2>Modify file infos during scan by a callback</h2></summary><blockquote>

In some case, it can be unsefull to modify file infos during scan
so you can define your callback and attached it in the FileDialogConfig struct in the field userFileAttributes

the callback stamp is :
```cpp
bool (IGFD::FileInfos* vFileInfosPtr, IGFD::UserDatas vUserDatas)
```
if the callback is returning false, the file is ignored, so not displayed by the dialog

example : with the gltf separated files : (see the branch DemoApp for example use)

A gltf file can have data description and datas files separated.
in this case only the file with description will be shown in the dialog, so with not the full size of all attached datas

with this function, you can compose the path of the bin file, get his size, sum it to the desciption file size and use it

syntax :
```cpp
config.userFileAttributes = [](IGFD::FileInfos* vFileInfosPtr, IGFD::UserDatas vUserDatas) -> bool {
if (vFileInfosPtr != nullptr) {
// this demo not take into account .gltf who have data insise. besauce keepd easy just for demo
if (vFileInfosPtr->SearchForExt(".gltf", true)) {
auto bin_file_path_name = vFileInfosPtr->filePath + IGFD::Utils::GetPathSeparator() + vFileInfosPtr->fileNameLevels[0] + ".bin";
struct stat statInfos = {};
char timebuf[100];
int result = stat(bin_file_path_name.c_str(), &statInfos);
if (!result) {
vFileInfosPtr->fileSize += (size_t)statInfos.st_size; // add the size of bin file to the size of the gltf file
} else {
// no bin, so escaped.
// normally we must parse the file and check the uri for get the buffer file
// but here we keep the example as easy for demo.
return false;
}
}
}
return true;
};
```

![user_file_attributes.gif](https://github.com/aiekick/ImGuiFileDialog/blob/DemoApp/doc/user_file_attributes.gif)

</blockquote></details>

<details open><summary><h2>C Api :</h2></summary><blockquote>

this api was sucessfully tested with CImGui
Expand Down
Binary file added doc/user_file_attributes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 32 additions & 8 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
#include <clocale>
#include <string>

#if defined(__WIN32__) || defined(WIN32) || defined(_WIN32) || defined(__WIN64__) || defined(WIN64) || defined(_WIN64) || defined(_MSC_VER)
#define stat _stat
#endif // __WIN32__

// About Desktop OpenGL function loaders:
// Modern desktop OpenGL doesn't have a standard portable header file to load OpenGL function pointers.
// Helper libraries are often used for this purpose! Here we are supporting a few common ones (gl3w, glew, glad).
Expand Down Expand Up @@ -713,14 +717,6 @@ int main(int, char**) {
config.flags = flags;
ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey", ICON_IGFD_FOLDER_OPEN " Choose a File", filters, config);
}
if (ImGui::Button(ICON_IGFD_FOLDER_OPEN " Open File Dialog with custom size according to gltf files")) {
const char* filters = ".gltf";
IGFD::FileDialogConfig config;
config.path = ".";
config.countSelectionMax = 0;
config.flags = flags;
ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey", ICON_IGFD_FOLDER_OPEN " Choose a File", filters, config);
}
if (ImGui::Button(ICON_IGFD_SAVE " Save File Dialog with a custom pane")) {
const char* filters = "C++ File (*.cpp){.cpp}";
IGFD::FileDialogConfig config;
Expand All @@ -732,6 +728,34 @@ int main(int, char**) {
config.flags = flags;
ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey", ICON_IGFD_SAVE " Choose a File", filters, config);
}
if (ImGui::Button(ICON_IGFD_FOLDER_OPEN " Open File Dialog with custom size according to gltf files")) {
const char* filters = ".gltf";
IGFD::FileDialogConfig config;
config.path = ".";
config.countSelectionMax = 0;
config.flags = flags;
config.userFileAttributes = [](IGFD::FileInfos* vFileInfosPtr, IGFD::UserDatas vUserDatas) -> bool {
if (vFileInfosPtr != nullptr) {
// this demo not take into account .gltf who have data insise. besauce keepd easy just for demo
if (vFileInfosPtr->SearchForExt(".gltf", true)) {
auto bin_file_path_name = vFileInfosPtr->filePath + IGFD::Utils::GetPathSeparator() + vFileInfosPtr->fileNameLevels[0] + ".bin";
struct stat statInfos = {};
char timebuf[100];
int result = stat(bin_file_path_name.c_str(), &statInfos);
if (!result) {
vFileInfosPtr->fileSize += (size_t)statInfos.st_size;
} else {
// no bin, so escaped.
// normally we must parse the file and check the uri for get the buffer file
// but here we keep the example as easy for demo.
return false;
}
}
}
return true;
};
ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey", ICON_IGFD_FOLDER_OPEN " Choose a File", filters, config);
}
}

if (ImGui::CollapsingHeader("Open Directories :")) {
Expand Down
Binary file added meshs/cube.bin
Binary file not shown.
88 changes: 88 additions & 0 deletions meshs/cube.gltf
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
{
"asset" : {
"generator" : "Khronos glTF Blender I/O v1.8.19",
"version" : "2.0"
},
"scene" : 0,
"scenes" : [
{
"name" : "Scene",
"nodes" : [
0
]
}
],
"nodes" : [
{
"mesh" : 0,
"name" : "Cube"
}
],
"meshes" : [
{
"name" : "Cube",
"primitives" : [
{
"attributes" : {
"POSITION" : 0,
"NORMAL" : 1
},
"indices" : 2
}
]
}
],
"accessors" : [
{
"bufferView" : 0,
"componentType" : 5126,
"count" : 24578,
"max" : [
1.000000238418579,
1.000000238418579,
1.000000238418579
],
"min" : [
-1.000000238418579,
-1.000000238418579,
-1.000000238418579
],
"type" : "VEC3"
},
{
"bufferView" : 1,
"componentType" : 5126,
"count" : 24578,
"type" : "VEC3"
},
{
"bufferView" : 2,
"componentType" : 5123,
"count" : 147456,
"type" : "SCALAR"
}
],
"bufferViews" : [
{
"buffer" : 0,
"byteLength" : 294936,
"byteOffset" : 0
},
{
"buffer" : 0,
"byteLength" : 294936,
"byteOffset" : 294936
},
{
"buffer" : 0,
"byteLength" : 294912,
"byteOffset" : 589872
}
],
"buffers" : [
{
"byteLength" : 884784,
"uri" : "cube.bin"
}
]
}
88 changes: 88 additions & 0 deletions meshs/file_without_bin.gltf
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
{
"asset" : {
"generator" : "Khronos glTF Blender I/O v1.8.19",
"version" : "2.0"
},
"scene" : 0,
"scenes" : [
{
"name" : "Scene",
"nodes" : [
0
]
}
],
"nodes" : [
{
"mesh" : 0,
"name" : "Icosphere"
}
],
"meshes" : [
{
"name" : "Icosphere.004",
"primitives" : [
{
"attributes" : {
"POSITION" : 0,
"NORMAL" : 1
},
"indices" : 2
}
]
}
],
"accessors" : [
{
"bufferView" : 0,
"componentType" : 5126,
"count" : 40962,
"max" : [
1,
0.9999999403953552,
1
],
"min" : [
-1,
-0.9999999403953552,
-1
],
"type" : "VEC3"
},
{
"bufferView" : 1,
"componentType" : 5126,
"count" : 40962,
"type" : "VEC3"
},
{
"bufferView" : 2,
"componentType" : 5123,
"count" : 245760,
"type" : "SCALAR"
}
],
"bufferViews" : [
{
"buffer" : 0,
"byteLength" : 491544,
"byteOffset" : 0
},
{
"buffer" : 0,
"byteLength" : 491544,
"byteOffset" : 491544
},
{
"buffer" : 0,
"byteLength" : 491520,
"byteOffset" : 983088
}
],
"buffers" : [
{
"byteLength" : 1474608,
"uri" : "sphere.bin"
}
]
}
Binary file added meshs/ico.plane.bin
Binary file not shown.
96 changes: 96 additions & 0 deletions meshs/ico.plane.gltf
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
{
"asset":{
"generator":"Khronos glTF Blender I/O v3.6.27",
"version":"2.0"
},
"scene":0,
"scenes":[
{
"name":"Scene",
"nodes":[
0
]
}
],
"nodes":[
{
"mesh":0,
"name":"Plane",
"translation":[
0,
0.1490543782711029,
0
]
}
],
"meshes":[
{
"name":"Plane.001",
"primitives":[
{
"attributes":{
"POSITION":0,
"NORMAL":1
},
"indices":2
}
]
}
],
"accessors":[
{
"bufferView":0,
"componentType":5126,
"count":201,
"max":[
5,
1.90883207321167,
5
],
"min":[
-5,
-0.9088320732116699,
-5
],
"type":"VEC3"
},
{
"bufferView":1,
"componentType":5126,
"count":201,
"type":"VEC3"
},
{
"bufferView":2,
"componentType":5123,
"count":396,
"type":"SCALAR"
}
],
"bufferViews":[
{
"buffer":0,
"byteLength":2412,
"byteOffset":0,
"target":34962
},
{
"buffer":0,
"byteLength":2412,
"byteOffset":2412,
"target":34962
},
{
"buffer":0,
"byteLength":792,
"byteOffset":4824,
"target":34963
}
],
"buffers":[
{
"byteLength":5616,
"uri":"ico_plane.bin"
}
]
}
Binary file added meshs/ico_plane.bin
Binary file not shown.
Loading

0 comments on commit 66202bf

Please sign in to comment.