Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to create a rectangle with trimesh.path.Path3D? #1243

Closed
xleEmesent opened this issue May 10, 2021 · 4 comments
Closed

How to create a rectangle with trimesh.path.Path3D? #1243

xleEmesent opened this issue May 10, 2021 · 4 comments

Comments

@xleEmesent
Copy link

xleEmesent commented May 10, 2021

Hi, All:

I am trying to create a 3D rectangle using trimesh.path.Path3D. But I am how to use trimesh.path.Path3D here?
The purpose is to cut a mesh with a polygon.
For example, if I have list of vertices as following:

    center = [0,0,0]
    width = 1
    depth = 2
    vs = np.array([
                    [center[0]-width/2, center[1], center[2]+depth/4], #left from the back
                    [center[0],center[1],center[2]+depth/4], #right from the back
                    [center[0],center[1]+height/2, center[2]+depth/4], #front right
                    [center[0]-width/2, center[1]+height/2, center[2]+depth/4]
                    ], #front left
                    dtype=np.float32)

    es = [[0, 1], [1, 2], [2, 3],[3,0]]

How could I create a trimesh.path.Path3D with above vertices and edges?
trimesh.path.Path3D(entities=None, vertices=None)

What is the "entities" here?
Thanks in advance.

@mikedh
Copy link
Owner

mikedh commented May 10, 2021

Hey, if you're using booleans you might want to do it with a trimesh.creation.box. But you can also create the outline of a box pretty easily:

In [1]: import trimesh

In [2]: trimesh.path.creation.box_outline?
Signature: trimesh.path.creation.box_outline(extents=None, transform=None, **kwargs)
Docstring:
Return a cuboid.

Parameters
------------
extents : float, or (3,) float
  Edge lengths
transform: (4, 4) float
  Transformation matrix
**kwargs:
    passed to Trimesh to create box

Returns
------------
geometry : trimesh.Path3D
  Path outline of a cuboid geometry
File:      ~/trimesh/trimesh/path/creation.py
Type:      function

In [3]: p = trimesh.path.creation.box_outline(extents=[10,4,3])

In [4]: p
Out[4]: <trimesh.Path3D(vertices.shape=(8, 3), len(entities)=1)>

In [5]: p.show()
Out[5]: SceneViewer(width=1800, height=1350)

Screenshot from 2021-05-10 01-29-33

@xleEmesent
Copy link
Author

xleEmesent commented May 10, 2021

@mikedh , Many thanks for you reply.

However, I am a bit lost about your answer. I am intending to create a polygon using trimesh.path.Path3D. For example, a rectangle. So later on, I can use it to cut a mesh.

However, I am not sure how can use trimesh.path.Path3D here given edges and vetices here.

@mikedh , can you further clarify it? Thanks. (The polygon is actually in a plane)

@xleEmesent
Copy link
Author

Also; the following error appeared when I did this:


es = np.array([0,1,2,3,0])
trimesh.path.Path3D(entities=es, vertices=vs)

lib/python3.7/site-packages/trimesh/path/path.py", line 228, in <genexpr>
    e._bytes() for e in self.entities))
AttributeError: 'numpy.int64' object has no attribute '_bytes'

@xleEmesent
Copy link
Author

I think the solution is as following:
The parameter entities for Path3D requires a list of trimesh.path.entities.Line object instead of a single one.


el = trimesh.path.entities.Line([0,1,2,3,0])
trimesh.path.Path3D(entities=[el], vertices=vs)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants