John Jepson
John Jepson

Reputation: 21

How can I import a 3d model/mesh with python

want to do some 3d model processing using Python.

I was told 3d models are made up of 4d matrices. Is it possible to import a 3d model from meshlab or blender or some other software and convert it into a matrix or something of the sort so I could do some processing?

Upvotes: 2

Views: 9137

Answers (3)

Parth Mahakal
Parth Mahakal

Reputation: 181

pip install pyvista
import pyvista as pv

# Load a 3D file (e.g., .stl)
mesh = pv.read('file.obj')

# Plot the 3D mesh
mesh.plot()

Upvotes: 0

sambler
sambler

Reputation: 7079

While you can use a 4D matrix to apply multiple transformations in one step, for the most part I would say it is more common to access each property either as an array of three or four values or to directly access each element.

import bpy
obj = bpy.context.active_object
obj.location.x += 1.0
obj.location.y -= 0.2
obj.location.z += 0.8
obj.rotation_euler = (radians(45.0),radians(15.8), radians(0.0))

Blender includes a full python interpreter, so you should be able to do most of what you want using blender without having to export any data.

If you want to try blender, you can get more blender specific help at blender.stackexchange.

Upvotes: 0

troymyname00
troymyname00

Reputation: 702

Yes it is possible. You need the plyfile library. Since it's Meshlab, I am assuming the file format that you're trying to import is .ply. Use the code below.

from plyfile import PlyData

data = PlyData.read('my_data.ply')

Upvotes: 1

Related Questions