在libigl Viewer上清除,移动,动画点?

问题描述 投票:1回答:1

我想使用libigl查看器来显示一个3d模型和一个点。 3D模型将始终保持不变,但该点将会移动。我目前的做法基本上是:

  1. 加载3d模型和点
  2. viewer.data()。clear()清除查看器
  3. 再次转到第1步

但是,它很慢,特别是当3d模型有很多顶点时,因为它需要在每次清除后重新加载所有内容。优选地,我想要仅清除该单个点或将该点移动到新坐标。有没有办法做到这一点?

ros eigen3 libigl
1个回答
1
投票

viewer.data().set_points(...)将清除与点相关的数据,并将其替换为输入位置和颜色。不会修改或清除网格。因此,只需更改积分就无需调用viewer.data().clear()

这是一个基于libigl-example-project的简约示例:

#include <igl/opengl/glfw/Viewer.h>
int main(int argc, char *argv[])
{
  // Inline mesh of a cube
  const Eigen::MatrixXd V= (Eigen::MatrixXd(8,3)<< -1.0,-1.0,-1.0, -1.0,-1.0, 1.0, -1.0, 1.0,-1.0, -1.0, 1.0, 1.0, 1.0,-1.0,-1.0, 1.0,-1.0, 1.0, 1.0, 1.0,-1.0, 1.0, 1.0, 1.0).finished();
  const Eigen::MatrixXi F = (Eigen::MatrixXi(12,3)<< 1,7,5, 1,3,7, 1,4,3, 1,2,4, 3,8,7, 3,4,8, 5,7,8, 5,8,6, 1,5,6, 1,6,2, 2,6,8, 2,8,4).finished().array()-1;
  igl::opengl::glfw::Viewer viewer;
  // Set mesh
  viewer.data().set_mesh(V, F);
  viewer.data().set_face_based(true);
  viewer.core().is_animating = true;
  // Initialize point
  Eigen::MatrixXd P = (Eigen::MatrixXd(1,3)<<1.42,0,0).finished();
  // function will be  called before every draw
  viewer.callback_pre_draw = [&](igl::opengl::glfw::Viewer & )->bool
  {
    // Create orbiting animation
    P = (1.42*(P+Eigen::RowVector3d(P(1),-P(0),P(2))*0.1).normalized()).eval();
    // update point location. no .clear() necessary
    viewer.data().set_points(P,Eigen::RowVector3d(1,1,1));
    return false;
  };
  viewer.launch();
}

animation of point in libigl viewer

© www.soinside.com 2019 - 2024. All rights reserved.