0
$\begingroup$

I am having a little confusion here. Some background: the user perspective faces in a direction, I am trying to make a box that faces the user perspective. That I have been able to achieve (pic below)

Side view after creation, arrow shows perspective view:

enter image description here

User perspective on creation:

USER PERSPECTIVE ON CREATION

Where the red arrow is the normal view of the user perspective - all good.

The problem is when I try to resize the box into a rectangle, as you can see the transform coordinate does not align well on creation of the cube. I get something like this:

enter image description here enter image description here

Here is the code I have come up with so far:

world_view = bpy.context.space_data.region_3d.view_rotation
local_view = Model_hollow.matrix_world.inverted().to_quaternion() @ world_view
view3d_rot_matrix = local_view.to_matrix().to_4x4()

bpy.ops.mesh.primitive_cube_add()
cut_box = bpy.context.object
cut_box.name = 'cut_box'
bpy.ops.object.select_all(action="DESELECT")
cut_box.select_set(True)
bpy.context.view_layer.objects.active = cut_box
cut_box.location = Model_hollow.location

bb = Model_hollow.bound_box
dx_local = max(bb[i][0] for i in range(8)) - min(bb[i][0] for i in range(8))
dy_local = max(bb[i][1] for i in range(8)) - min(bb[i][1] for i in range(8))
bpy.ops.transform.resize(value=(dx_local, dy_local, 1), orient_matrix=view3d_rot_matrix.to_3x3())

cut_box.data.transform(view3d_rot_matrix)
cut_box.data.update()

I do supply the orientation matrix.

$\endgroup$

1 Answer 1

0
$\begingroup$

Apply the object scale. Rotating the mesh of the object scaled causes the object to squash.

bpy.ops.transform.resize(value=(dx_local, dy_local, 1), orient_matrix=view3d_rot_matrix.to_3x3())

#=== Appry object scale =====
bpy.ops.object.transform_apply(location=False, rotation=False, scale=True)
#----------------------------

cut_box.data.transform(view3d_rot_matrix)
cut_box.data.update()
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .