Skip to content

Instantly share code, notes, and snippets.

@JokerMartini
Created March 22, 2016 14:32
Show Gist options
  • Save JokerMartini/26ff420914ecd01af6c9 to your computer and use it in GitHub Desktop.
Save JokerMartini/26ff420914ecd01af6c9 to your computer and use it in GitHub Desktop.
Maxscript: Demonstrates how to flip/mirror a transform around another transform.
delete objects
tp = Teapot radius:5 pos:[40,0,0]
pt = Point pos:[20,0,0] size:5 wirecolor:red
fn mirrorMatrixFn
axis:"x" --Axis to mirror over
flip:"x" --Axis to flip
tm:(matrix3 1) --Matrix to mirror
pivotTm:(matrix3 1) --Matrix to mirror around
=
(
fn FetchReflection a =
(
case a of (
"x": [-1,1,1] -- reflect in YZ plane
"y": [1,-1,1] -- in ZX plane
"z": [1,1,-1] -- in XY plane
)
)
aReflection = scalematrix (FetchReflection axis)
fReflection = scalematrix (FetchReflection flip)
--calculate the mirroredTM
fReflection * (tm * (inverse pivotTm)) * aReflection * pivotTm
)
flippedTM = mirrorMatrixFn pivotTm:pt.transform tm:tp.transform
dup = copy tp
dup.transform = flippedTM
@Hoek67
Copy link

Hoek67 commented Apr 24, 2023

Thanks, works great.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment