# Cube In Cube Trimesh to Py5Shape

**URL:** <https://discourse.processing.org/t/cube-in-cube-trimesh-to-py5shape/45615>\
**Category:** Gallery\
**Created:** [January 17, 2025, 3:32am UTC](https://discourse.processing.org/t/cube-in-cube-trimesh-to-py5shape/45615 "2025-01-17T03:32:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)\
**Post date:** [January 17, 2025, 3:32am UTC](https://discourse.processing.org/t/cube-in-cube-trimesh-to-py5shape/45615/1 "2025-01-17T03:32:14Z")

</div>

The following source demonstrates conversion of a trimesh cube in a cube object to a Py5Shape. It was created and run in a Thonny editor.

```python
import trimesh
import math
import py5

one = trimesh.creation.box((150,150,150));
other = trimesh.creation.box((150,150,150))

angle = math.pi / 3
direction = [1, 1, 1]
center = [0, 0, 0]

rot_matrix = trimesh.transformations.rotation_matrix(angle, direction, center)
other.apply_transform(rot_matrix)
mesh = one.union(other)

def setup():
    global cube
    py5.size(600, 600, py5.P3D)
    py5.window_title("Cube In a Cube Trimesh to Py5Shape")
    cube = py5.convert_shape(mesh)
    cube.set_stroke_weight(2)
    cube.set_fills(py5.color(py5.random(255),py5.random(255),py5.random(255)) for _ in range(108))

def draw():
    py5.background(255)
    py5.translate(py5.width/2, py5.height/2)
    py5.scale(1)
    py5.rotate_x(py5.remap(py5.mouse_y, 0, py5.height, py5.PI, -py5.PI))
    py5.rotate_y(py5.remap(py5.mouse_x, 0, py5.width, -py5.PI, py5.PI))
    py5.shape(cube)

py5.run_sketch()

```

**Output:**

 ![CubeInCube](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/a/9/a9c69e8317d8f0ff2a7995eb0aee80782af372cd.png)
