API bug? Mirroring via occurrence.transform results in reversed normals

API bug? Mirroring via occurrence.transform results in reversed normals

JesusFreke
Advocate Advocate
717 Views
4 Replies
Message 1 of 5

API bug? Mirroring via occurrence.transform results in reversed normals

JesusFreke
Advocate
Advocate

I was playing around with doing a mirror operation by tweaking an occurrence's transformation matrix. If you mirror by

1 axis or 3 axes, you end up with a body that looks like it has reversed normals. Although, if you modify the object (e.g. do a combine operation on it), the normals seem to get fixed.

 

Mirroring by 2 axes does not exhibit the bug -- likely 2 normal inversions cancelling each other out? 🙂

 

mirror_normal_bug.png

 

code:

 

import adsk.core
import adsk.fusion

app = adsk.core.Application.get()
root = app.activeProduct.rootComponent


def box(x, y, z, *, name="Box"):
    brep = adsk.fusion.TemporaryBRepManager.get()
    box_body = brep.createBox(adsk.core.OrientedBoundingBox3D.create(
        adsk.core.Point3D.create(x/2, y/2, z/2),
        adsk.core.Vector3D.create(1, 0, 0),
        adsk.core.Vector3D.create(0, 1, 0),
        x, y, z))
    occurrence = root.occurrences.addNewComponent(adsk.core.Matrix3D.create())
    occurrence.component.name = name
    base_feature = occurrence.component.features.baseFeatures.add()
    base_feature.startEdit()
    occurrence.component.bRepBodies.add(box_body, base_feature)
    base_feature.finishEdit()
    return occurrence


def run(context):
    original = box(1, 1, 1, name="original")
    mirrored = box(1, 1, 1, name="mirror")

    transform = mirrored.transform
    transform.setCell(0, 0, -1)
    transform.setCell(1, 1, 1)
    transform.setCell(2, 2, 1)
    mirrored.transform = transform
0 Likes
718 Views
4 Replies
Replies (4)
Message 2 of 5

JesusFreke
Advocate
Advocate

And yes, I know the usual way to mirror is via a mirror feature 🙂

0 Likes
Message 3 of 5

BrianEkins
Mentor
Mentor

It is a bug in the API, but the bug is that it's allowing you to set the transform with a matrix that defines a mirror.  Fusion doesn't expect this internally and the API shouldn't let you do it.  There's supposed to be a check in the API when setting the transform to verify that the matrix is only defining translation and rotation.  Any scaling, mirroring, or other non-standard transforms should fail.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes
Message 4 of 5

JesusFreke
Advocate
Advocate

Fair enough :). As far as I can tell, there is a check to disallow non-uniform scaling at least. But uniform scaling does seem to work.

0 Likes
Message 5 of 5

goyals
Autodesk
Autodesk

UP-40767 is created to track this. Thank you for reporting it.



Shyam Goyal
Sr. Software Dev. Manager
0 Likes