如何在Mayavi放大3D模型

2024-05-31 23:36:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我是python的Mayavi模块的新手,有些事情我还不清楚。我目前已经成功地显示了一个模型使用三角形网格函数。问题是,我想放大模型,使它看起来大5倍,我不知道怎么做。我试图更新顶点数组V,但一切看起来都一样。代码如下。不知怎么的,我想我需要转换包含顶点的V数组,但我不知道如何对它进行变换,使模型看起来更大5倍。在

import math
import numpy  as np
import mayavi.mlab as mlab  
import pickle

    # The following three lines will load the "pickled" arrays V and F from the
    # pickle file dino.pkl. V represents the vertices of the model as Nx3 matrix,
    # while N is the number of vertices the model consists of. F represent the
    # faces (here triangles of the model). F is also a Nx3 matrix, while here N
    # represents the number of the faces the model.
    fid = open('dino.pkl', 'rb')
    (V, F) = pickle.load(fid)
    fid.close()

    # a small wrapper function around mlab's triangular_mesh 
    # input are the face-vertex indices inside an (M x 3) array F
    # and the vertices in a (N x 3) array V
    def trimesh(F, V, new_figure=True):
        if new_figure:
            mlab.figure()
            mlab.triangular_mesh(V[:,0], V[:,1] , V[:,2] , F)
            mlab.show()


    # small helper function that is used to visualize the coordinate axes
    def draw_axes():
        mlab.points3d(1, 0, 0, 1, scale_factor=0.1, color=(1, 0, 0))
        mlab.points3d(0, 1, 0, 1, scale_factor=0.1, color=(0, 1, 0))
        mlab.points3d(0, 0, 1, 1, scale_factor=0.1, color=(0, 0, 1))
        mlab.plot3d([0, 1], [0, 0], [0, 0])
        mlab.plot3d([0, 0], [0, 1], [0, 0])
        mlab.plot3d([0, 0], [0, 0], [0, 1])


    # show dino triangle mesh
    draw_axes()
    trimesh(F, V)

Tags: ofthe模型importmodelisaspickle
1条回答
网友
1楼 · 发布于 2024-05-31 23:36:17

我不熟悉Mayavi,但是根据docsscale_factor参数会影响为每个点绘制的glyph的大小;如果要更改绘图的总体大小,可以指定extent。在

相关问题 更多 >