Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save JokerMartini/b4defcf89709a830d428 to your computer and use it in GitHub Desktop.

Select an option

Save JokerMartini/b4defcf89709a830d428 to your computer and use it in GitHub Desktop.
Maxscript: Takes an array containing X number of point3 values (no less then 3 points) and aligns an object at the center location of those points. Then aligns the object so it's X-axis is pointing at the first item in that point3 array and the Z axis is point outward from those points (like a local axis) We need at least two vectors to make a m…
fn GenerateCircularPoints spaced:true count:10 radius:12 =
(
pts = if spaced then
(
for k=1 to count collect (text size:4 axistripod:off pos:[radius * cos((k-1) * (360.0 / count)), radius * sin((k-1) * (360.0 / count)),0] wirecolor:yellow text:(k as string))
)else(
for k=1 to count collect (text size:4 axistripod:off pos:[radius*cos(a = random 0 360), radius*sin(a),0] wirecolor:yellow text:(k as string))
)
pts
)
fn RandomlyRotate nodes:#() =
(
pos = random [-10,-10,0] [10,10,10]
in coordsys world about pos rotate nodes (eulerangles (random 0 90) (random 0 90) 0)
)
/*
Takes an array containing X number of point3 values (no less then 3 points) and aligns an object at the center location of those points.
Then aligns the object so it's X-axis is pointing at the first item in that point3 array and the Z axis is point outward from those points (like a local axis)
So we need at least two vectors to make a matrix. One vector is from center to the first point, Second could be from center to second point.
*/
fn multipointTM points = if points.count > 1 do
(
center = [0,0,0]
for p in points do center += p.pos
center /= points.count
front = normalize (points[1].pos - center)
side = normalize (points[2].pos - center)
up = normalize (cross front side) -- orthogonalized up
side = normalize (cross up front) -- orthogonalized side
tm = matrix3 front side up center
)
delete objects
-- generate a circlular array of planar points, then randomly rotate them as a group in 3D space
pts = GenerateCircularPoints()
RandomlyRotate nodes:pts
-- now generate a point aligning it to the transform calculated from the points generated above
p = point size:10 axistripod:on transform:(multipointTM pts) wirecolor:green
ptsA = GenerateCircularPoints radius:8
ptsB = GenerateCircularPoints radius:5
for pt in ptsA do
(
pt.wirecolor = blue
pt.pos.z += 5
pt.transform *= p.transform
)
for pt in ptsB do
(
pt.wirecolor = red
pt.pos.z += 10
pt.transform *= p.transform
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment