Search code examples
pythonscaleopen3d

Scaling along a single axis in open3d


Is there a function to scale a mesh along y-axis only (left) after its creation?

I tried the open3d.geometry.Geometry3D.scale function, but it scales along the 3-axis (right).

import open3d as o3d
cylinder = o3d.geometry.create_mesh_cylinder(radius=1, height=3)
cylinder_scaled.scale(2) # I got the cylinder on the left.

open3d scaling

Thanks in advance!


Solution

  • Convert mesh vertices to numpy array first. Convert back after scaling.

    cylinder.vertices = o3d.utility.Vector3dVector(
        np.asarray(cylinder.vertices) * np.array([1., 1., 2.]) )