meshlab: pymeshlab颜色化物体顶点坐标(vertex coordinate)并颜色化后的物体模型

 一、关于环境

 请参考:pymeshlab遍历文件夹中模型、缩放并导出指定格式-CSDN博客

二、关于代码

本文所给出代码仅为参考,禁止转载和引用,仅供个人学习。本文所给出的例子是https://download.csdn.net/download/weixin_42605076/89233917中的obj_000001.ply。

运行代码后的颜色化物体模型





# pymeshlab需要导入,其一般被命名为ml
import pymeshlab as ml

# numpy需要导入,其一般被命名为np
import numpy as np

# 本案例所使用的3D模型为压缩包中的obj_000001.ply,请将其与本脚本放置在同一文件夹内。
input_file = 'obj_000001.ply'

# 首先需要创建一个空的容器
mesh = ml.MeshSet()

# 然后,加载物体模型
mesh.load_new_mesh(input_file)

# 获取顶点坐标和面片索引
mesh_c = mesh.current_mesh()
vertex_matrix = mesh_c.vertex_matrix().copy()
face_matrix = mesh_c.face_matrix().copy()

# 获取坐标下限
min_vertex_matrix = np.min(vertex_matrix, axis=0)

# 获取坐标范围
range_vertex_matrix = np.max(vertex_matrix, axis=0) - np.min(vertex_matrix, axis=0)

# 将坐标转换为颜色
color_vertex_matrix = ((vertex_matrix - min_vertex_matrix) / range_vertex_matrix)
v_color_matrix = np.ones((color_vertex_matrix.shape[0], 4))
v_color_matrix[:,:3] = color_vertex_matrix

# 创建一个新的容器
mesh = ml.MeshSet()

# 创建一个新的模型
mesh_c = ml.Mesh(vertex_matrix = vertex_matrix,
                 face_matrix = face_matrix,
                 v_color_matrix = v_color_matrix,
                 )

# 然后,将新的模型放入MeshSet中
mesh.add_mesh(mesh_c)

# 保存颜色化坐标
mesh.save_current_mesh(input_file.replace('.ply', '_color.ply'))

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值