Skip to content

Commit

Permalink
Sync with 70b0464
Browse files Browse the repository at this point in the history
  • Loading branch information
qnzhou committed Jul 23, 2021
1 parent 8ed20cd commit e02a4f6
Show file tree
Hide file tree
Showing 19 changed files with 262 additions and 80 deletions.
2 changes: 1 addition & 1 deletion cmake/recipes/external/imgui.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ include(FetchContent)
FetchContent_Declare(
imgui
GIT_REPOSITORY https://github.com/adobe/imgui.git
GIT_TAG 3f1593b28346da2ad34edbab9432b93deb305f42
GIT_TAG docking_v1.83
)
FetchContent_MakeAvailable(imgui)

Expand Down
5 changes: 5 additions & 0 deletions modules/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ if(LAGRANGE_KEEP_TRANSITION_CODE)
target_compile_definitions(lagrange_core PUBLIC -DLA_KEEP_TRANSITION_CODE)
endif()

option(LAGRANGE_DISABLE_FPE "Disable floating point exception code" OFF)
if(LAGRANGE_DISABLE_FPE)
target_compile_definitions(lagrange_core PRIVATE -DLA_DISABLE_FPE)
endif()

# 2. target sources
file(GLOB_RECURSE INC_FILES "include/*.h")
file(GLOB_RECURSE SRC_FILES "src/*.cpp")
Expand Down
5 changes: 3 additions & 2 deletions modules/core/include/lagrange/compute_vertex_normal.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ template <typename MeshType>
void compute_vertex_normal(
MeshType& mesh,
const igl::PerVertexNormalsWeightingType weighting =
igl::PER_VERTEX_NORMALS_WEIGHTING_TYPE_ANGLE)
igl::PER_VERTEX_NORMALS_WEIGHTING_TYPE_ANGLE,
bool recompute_facet_normals = false)
{
static_assert(MeshTrait<MeshType>::is_mesh(), "Input type is not Mesh");
using Index = IndexOf<MeshType>;
Expand All @@ -40,7 +41,7 @@ void compute_vertex_normal(
throw std::runtime_error("Input mesh is not triangle mesh.");
}

if (!mesh.has_facet_attribute("normal")) {
if (!mesh.has_facet_attribute("normal") || recompute_facet_normals) {
compute_triangle_normal(mesh);
LA_ASSERT(mesh.has_facet_attribute("normal"));
}
Expand Down
7 changes: 4 additions & 3 deletions modules/core/src/fpe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
#ifdef _WIN32
#if defined(_WIN32) || defined(LA_DISABLE_FPE)

namespace {

Expand All @@ -29,18 +29,19 @@ inline int fedisableexcept(unsigned int excepts)

} // namespace

#elif __linux__
#elif defined(__linux__)

#include <fenv.h>

#elif __APPLE__
#elif defined(__APPLE__)

#include <fenv.h>

// Public domain polyfill for feenableexcept on OS X
// http://www-personal.umich.edu/~williams/archive/computation/fe-handling-example.c

namespace {

inline int feenableexcept(unsigned int excepts)
{
static fenv_t fenv;
Expand Down
2 changes: 1 addition & 1 deletion modules/core/src/predicates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4251,6 +4251,6 @@ REAL insphere(const REAL* pa, const REAL* pb, const REAL* pc, const REAL* pd, co
}

} // namespace lagrange
#if defined(__GNUC__)
#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic pop
#endif
7 changes: 0 additions & 7 deletions modules/ui/include/lagrange/ui/components/GLMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,6 @@ struct DefaultShaderIndicesNames
constexpr static const entt::id_type TriangleIndices = entt::hashed_string{"_triangle_indices"};
};

struct GLOcclusionQuery
{
GLuint id;
GLenum type;
GLint last_result;
};

struct GLMesh
{
std::shared_ptr<GPUBuffer> get_attribute_buffer(entt::id_type id) const
Expand Down
23 changes: 11 additions & 12 deletions modules/ui/include/lagrange/ui/utils/mesh.impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
#include <lagrange/compute_vertex_normal.h>
#include <lagrange/select_facets_in_frustum.h>
#include <lagrange/ui/Entity.h>
#include <lagrange/ui/types/Camera.h>
#include <lagrange/ui/types/Color.h>
#include <lagrange/ui/types/Frustum.h>
#include <lagrange/ui/types/RayFacetHit.h>
#include <lagrange/ui/types/VertexBuffer.h>
#include <lagrange/ui/types/Camera.h>
#include <lagrange/ui/utils/math.h>
#include <lagrange/ui/utils/objectid_viewport.h>

Expand Down Expand Up @@ -161,6 +161,8 @@ template <typename MeshType>
AABB get_mesh_bounds(const MeshBase* mesh_base)
{
const auto& mesh = reinterpret_cast<const MeshType&>(*mesh_base);
if (mesh.get_num_vertices() == 0) return AABB();

const auto& V = mesh.get_vertices();
return AABB(
V.colwise().minCoeff().template cast<float>(),
Expand Down Expand Up @@ -248,7 +250,9 @@ void ensure_is_selected_attribute(MeshBase* d)

if (mesh.is_edge_data_initialized_new() && !mesh.has_edge_attribute_new(attrib_name)) {
mesh.add_edge_attribute_new(attrib_name);
mesh.import_edge_attribute_new(attrib_name, AttributeArray::Zero(mesh.get_num_edges_new(), 1));
mesh.import_edge_attribute_new(
attrib_name,
AttributeArray::Zero(mesh.get_num_edges_new(), 1));
}

if (!mesh.has_vertex_attribute(attrib_name)) {
Expand Down Expand Up @@ -552,7 +556,7 @@ void select_vertices_in_frustum(
using Index = typename MeshType::Index;

const auto num_vertices = mesh.get_num_vertices();
const auto& vertices = mesh.get_vertices();
const auto& vertices = mesh.get_vertices();

AttributeArray attr;

Expand Down Expand Up @@ -891,7 +895,6 @@ void select_facets(
}



template <typename MeshType>
void filter_closest_vertex(
MeshBase* mesh_base,
Expand All @@ -900,7 +903,6 @@ void filter_closest_vertex(
const Camera& camera,
const Eigen::Vector2i& viewport_pos)
{

auto& mesh = reinterpret_cast<MeshType&>(*mesh_base);
using AttribArray = typename MeshType::AttributeArray;

Expand Down Expand Up @@ -936,7 +938,8 @@ void filter_closest_vertex(

if (vertex_attrib(vi) == 0.0f) continue;

const auto proj = camera.project_with_depth(vertices.row(vi).template cast<float>());
const auto proj =
camera.project_with_depth(vertices.row(vi).template cast<float>());
const auto diff =
(Eigen::Vector2i(int(proj.x()), int(camera.get_window_height() - proj.y())) -
viewport_pos)
Expand Down Expand Up @@ -984,7 +987,6 @@ void filter_closest_vertex(
const auto value = (sel_behavior != SelectionBehavior::ERASE) ? Scalar(1) : Scalar(0);

if (final_buffer.min_vi != lagrange::INVALID<Index>()) {

vertex_attrib(final_buffer.min_vi, 0) = value;
for (auto equiv_vi : final_buffer.equivalence) {
vertex_attrib(equiv_vi, 0) = value;
Expand Down Expand Up @@ -1038,8 +1040,7 @@ void register_mesh_type(const std::string& display_name = entt::type_id<MeshType
entt::meta<MeshType>().template func<&detail::get_mesh_attribute_range<MeshType>>(
"get_mesh_attribute_range"_hs);

entt::meta<MeshType>().template func<&detail::get_mesh_bounds<MeshType>>(
"get_mesh_bounds"_hs);
entt::meta<MeshType>().template func<&detail::get_mesh_bounds<MeshType>>("get_mesh_bounds"_hs);


// Ensure attribs
Expand Down Expand Up @@ -1112,11 +1113,9 @@ void register_mesh_type(const std::string& display_name = entt::type_id<MeshType
entt::meta<MeshType>().template func<&detail::select_vertices_by_color<MeshType>>(
"select_vertices_by_color"_hs);

entt::meta<MeshType>().template func<&detail::select_facets<MeshType>>(
"select_facets"_hs);
entt::meta<MeshType>().template func<&detail::select_facets<MeshType>>("select_facets"_hs);
entt::meta<MeshType>().template func<&detail::filter_closest_vertex<MeshType>>(
"filter_closest_vertex"_hs);

}


Expand Down
8 changes: 3 additions & 5 deletions modules/ui/src/Viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,9 @@ bool Viewer::run(const std::function<bool(Registry&)>& main_loop)

m_systems.run(Systems::Stage::Interface, registry());

if (main_loop) {
if (!main_loop(registry())) glfwSetWindowShouldClose(m_window, true);
}

show_last_shader_error();
end_dockspace();
Expand All @@ -405,11 +408,6 @@ bool Viewer::run(const std::function<bool(Registry&)>& main_loop)
end_imgui_frame();


if (main_loop) {
if (!main_loop(registry())) glfwSetWindowShouldClose(m_window, true);
}


m_systems.run(Systems::Stage::Simulation, registry());


Expand Down
43 changes: 35 additions & 8 deletions modules/ui/src/default_components.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,31 @@ void show_mesh_geometry(Registry* rptr, Entity orig_e)
}
ImGui::Text("MeshType: %s", typeinfo.name().data());

const size_t num_vertices = get_num_vertices(mesh_data);
if (num_vertices == 0) ImGui::PushStyleColor(ImGuiCol_Text, ImGui::Spectrum::RED400);
ImGui::Text("Vertices: %zu", num_vertices);
if (num_vertices == 0) ImGui::PopStyleColor();

const size_t num_facets = get_num_facets(mesh_data);
if (num_facets == 0) ImGui::PushStyleColor(ImGuiCol_Text, ImGui::Spectrum::RED400);
ImGui::Text("Facets: %zu", num_facets);
if (num_facets == 0) ImGui::PopStyleColor();

int sub_id = m.submesh_index;
if (m.submesh_index == entt::null) {
ImGui::Text("Submesh/Material ID not set");
ImGui::SameLine();

if (ImGui::InputInt("Submesh/Material ID", &sub_id)) {
if (sub_id >= 0) m.submesh_index = entt::id_type(sub_id);
if (ImGui::Button("Set")) {
m.submesh_index = 0;
}
} else {
if (ImGui::InputInt("Submesh/Material ID", &sub_id) && sub_id >= 0) {
m.submesh_index = entt::id_type(sub_id);
}
if (ImGui::Button("Unset Submesh/Material ID")) {
m.submesh_index = entt::null;
}
}

if (has_accelerated_picking(r, m.entity)) {
Expand Down Expand Up @@ -1034,12 +1055,18 @@ void show_bounds(Registry* rptr, Entity e)
const auto& bounds = rptr->get<Bounds>(e);

const auto show_bb = [](const AABB& bb) {
Eigen::Vector3f tmp_min = bb.min(), tmp_max = bb.max(), tmp_extent = bb.diagonal(),
tmp_center = bb.center();
ImGui::DragFloat3("Min", tmp_min.data());
ImGui::DragFloat3("Max", tmp_max.data());
ImGui::DragFloat3("Extent", tmp_extent.data());
ImGui::DragFloat3("Center", tmp_center.data());
if (bb.isEmpty()) {
ImGui::PushStyleColor(ImGuiCol_Text, ImGui::Spectrum::RED400);
ImGui::Text("Empty");
ImGui::PopStyleColor();
} else {
Eigen::Vector3f tmp_min = bb.min(), tmp_max = bb.max(), tmp_extent = bb.diagonal(),
tmp_center = bb.center();
ImGui::DragFloat3("Min", tmp_min.data());
ImGui::DragFloat3("Max", tmp_max.data());
ImGui::DragFloat3("Extent", tmp_extent.data());
ImGui::DragFloat3("Center", tmp_center.data());
}
};

ImGui::Text("Local");
Expand Down
7 changes: 7 additions & 0 deletions modules/ui/src/panels/ViewportPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,13 @@ void draw_framebuffer_popup(Registry& registry, ViewportPanel& data)
ImGui::InputInt("Width", &v.width);
ImGui::InputInt("Height", &v.height);
ImGui::Checkbox("Auto near/far", &v.auto_nearfar);

if (v.auto_nearfar) {
auto n = v.computed_camera.get_near();
auto f = v.computed_camera.get_far();
ImGui::InputFloat("Computed near", &n);
ImGui::InputFloat("Computed far", &f);
}
}

if (ImGui::CollapsingHeader("Layer visibility")) {
Expand Down
6 changes: 3 additions & 3 deletions modules/ui/src/systems/camera_systems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ void camera_focusfit_system(Registry& registry)
} else {
const float dist = (radius * 2.0f) / std::tan(cam.get_fov() / 2.0f);
const auto dir = cam.get_direction().normalized().eval();
const auto new_pos = cam.get_lookat() - dir * dist;
const auto old_pos = cam.get_position();
const Eigen::Vector3f new_pos = cam.get_lookat() - dir * dist;
const Eigen::Vector3f old_pos = cam.get_position();

fit_reached = (old_pos - new_pos).squaredNorm() < eps;
cam.set_position(t * new_pos + (1.0f - t) * cam.get_position());
Expand Down Expand Up @@ -240,4 +240,4 @@ void camera_focusfit_system(Registry& registry)
}

} // namespace ui
} // namespace lagrange
} // namespace lagrange
1 change: 0 additions & 1 deletion modules/ui/src/systems/render_background.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ struct SkyboxCubeVertexData

void render_background(Registry& r)
{
auto& rctx = get_render_context(r);
auto& viewport = get_render_context_viewport(r);

// Grab and bind fbo if set
Expand Down
2 changes: 0 additions & 2 deletions modules/ui/src/systems/render_geometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,6 @@ void render_gl_render_queue(Registry& r)
auto& cam = viewport.computed_camera;
const auto P = cam.get_perspective();
const auto V = cam.get_view();
const auto PV = cam.get_PV();
const auto PVinv = cam.get_PV().inverse().eval();
const auto cameraPos = cam.get_position();
const auto screen_size = cam.get_window_size();

Expand Down
6 changes: 3 additions & 3 deletions modules/ui/src/systems/render_viewports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ void adjust_camera(Registry& registry, ViewportComponent& viewport, Camera& cam)
auto near_plane = cam.get_near();
auto far_plane = cam.get_far();

if (furthest != std::numeric_limits<float>::min()) {
if (furthest > 0) {
far_plane = 1.01f * furthest;
}
if (nearest != std::numeric_limits<float>::max()) {
near_plane = std::max(0.99f * nearest, near_plane);
if (nearest > 0) {
near_plane = 0.99f * nearest;
}
cam.set_planes(near_plane, far_plane);
}
Expand Down
22 changes: 8 additions & 14 deletions modules/ui/src/systems/update_scene_bounds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ void update_scene_bounds_system(Registry& registry)
auto view = registry.view<Transform, Bounds>();
for (auto e : view) {
auto& b = view.get<Bounds>(e);
b.global = b.local.transformed(view.get<Transform>(e).global);
if (!b.local.isEmpty()) {
b.global = b.local.transformed(view.get<Transform>(e).global);
}
}
}

Expand Down Expand Up @@ -87,22 +89,14 @@ void update_scene_bounds_system(Registry& registry)
}



// If parent does not have bounds component yet
if (!registry.has<Bounds>(parent)) {
auto& parent_bounds = registry.emplace<Bounds>(parent);
if (registry.has<Transform>(parent)) {
const auto& t = registry.get<Transform>(parent);
const auto local_pos = t.local.matrix().block<3, 1>(0, 3).eval();
const auto global_pos = t.global.matrix().block<3, 1>(0, 3).eval();
parent_bounds.local = AABB(local_pos, local_pos);
parent_bounds.global = AABB(global_pos, global_pos);
parent_bounds.bvh_node = parent_bounds.global; //Init with empty box at global position
} else {
parent_bounds.local = AABB();
parent_bounds.global = AABB();
parent_bounds.bvh_node = bvh_node; //Init with child
}
// Empty bounds
parent_bounds.local = AABB();
parent_bounds.global = AABB();
// Init with child's bvh
parent_bounds.bvh_node = bvh_node;
}

// Update parent and mark as dirty
Expand Down
Loading

0 comments on commit e02a4f6

Please sign in to comment.