我想使用 libigl 查看器来显示 3d 模型和一个点。3d 模型将始终保持不变,但点会四处移动。我目前的做法基本上是:
但是,它很慢,尤其是当 3d 模型有很多顶点时,因为每次清除后都需要重新加载所有内容。最好,我想要么只清除那个点,要么将该点移动到一个新坐标。有没有办法做到这一点?
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();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
570 次 |
| 最近记录: |