Align object to PLA polygon

Lately I have worked a lot with alembic files that have point level animated geometry and once I had to attach objects to that PLA geometry. I figured out a couple different ways to do this (e.g. MoGraph Cloner or Contraint Tag) but my favorite solution is to use Xpresso and Python.

In this setup I’m taking three points from selected polygon. Then I’m creating vectors v1 and v2 from those points’ positions. Then vectors are used to generate orthogonal axes by using cross product.

import c4d
import math

def main():
    global Matrix

    v1 = Point1 - Point0
    v2 = Point2 - Point0

    m = c4d.Matrix()
    m.v1 = v1.GetNormalized()
    m.v3 = v1.Cross(v2).GetNormalized()
    m.v2 = m.v3.Cross(v1).GetNormalized()
    m.off = Position

    Matrix = m

align_object_to_pla_polygon.c4d

Cinema 4D, Python, Xpresso