Skip to content

Commit

Permalink
Introduce gltf_baker tool.
Browse files Browse the repository at this point in the history
  • Loading branch information
prideout committed May 13, 2019
1 parent f5b47dc commit 3291fb6
Show file tree
Hide file tree
Showing 9 changed files with 663 additions and 18 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ dist-*
toolchains
filament/docs/html/**
.vscode
gltf_baker.ini
3 changes: 3 additions & 0 deletions libs/filagui/include/filagui/ImGuiHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ class ImGuiHelper {
// Helper method called after resolving fontPath; public so fonts can be added by caller.
void createAtlasTexture(filament::Engine* engine);

// Return the ImGui view, useful for drawing 2D overlays.
filament::View* getView() const { return mView; }

private:
void renderDrawData(ImDrawData* imguiData);
void createBuffers(int numRequiredBuffers);
Expand Down
47 changes: 29 additions & 18 deletions libs/gltfio/include/gltfio/SimpleViewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,17 @@ namespace gltfio {
*/
class SimpleViewer {
public:

static constexpr uint32_t FLAG_COLLAPSED = (1 << 0);

/**
* Constructs a SimpleViewer that has a fixed association with the given Filament objects.
*
* Upon construction, the simple viewer may create some additional Filament objects (such as
* light sources) that it owns.
*/
SimpleViewer(filament::Engine* engine, filament::Scene* scene, filament::View* view);
SimpleViewer(filament::Engine* engine, filament::Scene* scene, filament::View* view,
uint32_t flags = 0);

/**
* Destroys the SimpleViewer and any Filament entities that it owns.
Expand Down Expand Up @@ -145,6 +149,7 @@ class SimpleViewer {
bool mEnableMsaa = true;
bool mEnableSsao = true;
int mSidebarWidth = INITIAL_SIDEBAR_WIDTH;
uint32_t mFlags;
};

filament::math::mat4f fitIntoUnitCube(const filament::Aabb& bounds);
Expand Down Expand Up @@ -181,10 +186,12 @@ filament::math::mat4f fitIntoUnitCube(const filament::Aabb& bounds) {
return mat4f::scaling(float3(scaleFactor)) * mat4f::translation(-center);
}

SimpleViewer::SimpleViewer(filament::Engine* engine, filament::Scene* scene, filament::View* view) :
SimpleViewer::SimpleViewer(filament::Engine* engine, filament::Scene* scene, filament::View* view,
uint32_t flags) :
mEngine(engine), mScene(scene), mView(view),
mNames(new utils::NameComponentManager(utils::EntityManager::get())),
mSunlight(utils::EntityManager::get().create()) {
mSunlight(utils::EntityManager::get().create()),
mFlags(flags) {
using namespace filament;
LightManager::Builder(LightManager::Type::SUN)
.color(Color::toLinear<ACCURATE>({0.98, 0.92, 0.89}))
Expand Down Expand Up @@ -260,6 +267,8 @@ void SimpleViewer::applyAnimation(double currentTime) {
void SimpleViewer::updateUserInterface() {
using namespace filament;

ImGuiTreeNodeFlags headerFlags = (mFlags & FLAG_COLLAPSED) ? 0 : ImGuiTreeNodeFlags_DefaultOpen;

auto& tm = mEngine->getTransformManager();
auto& rm = mEngine->getRenderableManager();
auto& lm = mEngine->getLightManager();
Expand Down Expand Up @@ -361,7 +370,7 @@ void SimpleViewer::updateUserInterface() {
mView->setAmbientOcclusion(
mEnableSsao ? View::AmbientOcclusion::SSAO : View::AmbientOcclusion::NONE);

if (ImGui::CollapsingHeader("Light", ImGuiTreeNodeFlags_DefaultOpen)) {
if (ImGui::CollapsingHeader("Light", headerFlags)) {
ImGui::SliderFloat("IBL intensity", &mIblIntensity, 0.0f, 100000.0f);
ImGui::SliderAngle("IBL rotation", &mIblRotation);
ImGui::SliderFloat("Sun intensity", &mSunlightIntensity, 50000.0, 150000.0f);
Expand All @@ -378,23 +387,25 @@ void SimpleViewer::updateUserInterface() {
mScene->remove(mSunlight);
}

if (ImGui::CollapsingHeader("Model", ImGuiTreeNodeFlags_DefaultOpen)) {
if (mAnimator->getAnimationCount() > 0) {
intptr_t animationsNodeId = -1;
ImGuiTreeNodeFlags flags = ImGuiTreeNodeFlags_DefaultOpen;
if (ImGui::TreeNodeEx((const void*) animationsNodeId, flags, "Animations")) {
animationsTreeItem();
ImGui::TreePop();
if (mAsset != nullptr) {
if (ImGui::CollapsingHeader("Model", headerFlags)) {
if (mAnimator->getAnimationCount() > 0) {
intptr_t animationsNodeId = -1;
ImGuiTreeNodeFlags flags = ImGuiTreeNodeFlags_DefaultOpen;
if (ImGui::TreeNodeEx((const void*) animationsNodeId, flags, "Animations")) {
animationsTreeItem();
ImGui::TreePop();
}
}
ImGui::Checkbox("Wireframe", &mShowWireframe);
treeNode(mAsset->getRoot());
}
ImGui::Checkbox("Wireframe", &mShowWireframe);
treeNode(mAsset->getRoot());
}

if (mShowWireframe) {
mScene->addEntity(mAsset->getWireframe());
} else {
mScene->remove(mAsset->getWireframe());
if (mShowWireframe) {
mScene->addEntity(mAsset->getWireframe());
} else {
mScene->remove(mAsset->getWireframe());
}
}

mSidebarWidth = ImGui::GetWindowWidth();
Expand Down
1 change: 1 addition & 0 deletions libs/image/include/image/LinearImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class LinearImage {
* Creates an empty (invalid) image.
*/
LinearImage() : mDataRef(nullptr), mData(nullptr), mWidth(0), mHeight(0), mChannels(0) {}
operator bool() const { return mData != nullptr; }

/**
* Gets a pointer to the underlying pixel data.
Expand Down
3 changes: 3 additions & 0 deletions samples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ add_mesh("assets/models/monkey/monkey.obj" "suzanne.filamesh")
set(MATERIAL_SRCS
materials/bakedColor.mat
materials/bakedTexture.mat
materials/aoPreview.mat
materials/aiDefaultMat.mat
materials/aiDefaultTrans.mat
materials/depthVisualizer.mat
Expand Down Expand Up @@ -256,11 +257,13 @@ if (NOT ANDROID)
add_filamesh_demo(sample_normal_map)
add_filamesh_demo(suzanne)
add_filamesh_demo(gltf_viewer)
add_filamesh_demo(gltf_baker)

# Sample app specific
target_link_libraries(frame_generator PRIVATE imageio)
target_link_libraries(suzanne PRIVATE suzanne-resources)
target_link_libraries(gltf_viewer PRIVATE gltf-resources gltfio)
target_link_libraries(gltf_baker PRIVATE gltf-resources gltfio)
endif()

# ==================================================================================================
Expand Down
6 changes: 6 additions & 0 deletions samples/app/FilamentApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ FilamentApp::~FilamentApp() {
SDL_Quit();
}

View* FilamentApp::getGuiView() const noexcept {
return mImGuiHelper->getView();
}

void FilamentApp::run(const Config& config, SetupCallback setupCallback,
CleanupCallback cleanupCallback, ImGuiCallback imguiCallback,
PreRenderCallback preRender, PostRenderCallback postRender,
Expand Down Expand Up @@ -515,6 +519,8 @@ FilamentApp::Window::Window(FilamentApp* filamentApp,
mMainCameraMan.lookAt(at + double3{ 0, 0, 4 }, at);
mDebugCameraMan.lookAt(at + double3{ 0, 0, 4 }, at);
mOrthoCameraMan.lookAt(at + double3{ 0, 0, 4 }, at);

mMainCamera->lookAt({4, 0, -4}, {0, 0, -4}, {0, 1, 0});
}

FilamentApp::Window::~Window() {
Expand Down
1 change: 1 addition & 0 deletions samples/app/FilamentApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class FilamentApp {
filament::Material const* getDefaultMaterial() const noexcept { return mDefaultMaterial; }
filament::Material const* getTransparentMaterial() const noexcept { return mTransparentMaterial; }
IBL* getIBL() const noexcept { return mIBL.get(); }
filament::View* getGuiView() const noexcept;

void close() { mClosed = true; }

Expand Down
Loading

0 comments on commit 3291fb6

Please sign in to comment.