Skip to content

Instantly share code, notes, and snippets.

View JokerMartini's full-sized avatar
😀

John Martini JokerMartini

😀
View GitHub Profile
@JokerMartini
JokerMartini / Wave Expressions | .ms
Last active July 5, 2017 14:19
Maxscript: There are two functions here which create a single wave in maxscript using point helps to display the wave.
-- http://cameroncarson.com/nuke-wave-expressions/
-- https://davemne.wordpress.com/2011/05/16/nuke-wave-expressions-to-copy-and-paste/
fn BuildBounceArc =
(
waveWidth = 10
minVal = 0
maxVal = 10
numSamples = 20
@JokerMartini
JokerMartini / Bias Expression | .ms
Created July 31, 2015 17:55
Maxscript: This function demonstrates how to implement a simple 'bias' control to weight values towards one direction versus the other.
-- biasStrength : range:[-1,1,0]
-- biasPower : range:[1,100,0]
fn CalculateBias val:0.0 bias:0.0 biasPower:1 =
(
if bias < 0 then 1 - (pow (1 - val) (1 - biasPower*bias)) else (pow val (1 + biasPower * bias))
)
fn BiasTest =
(
count = 20
@JokerMartini
JokerMartini / Smooth Curve Expression | .ms
Created August 1, 2015 20:19
Maxscript: This function demonstrates how to control a blend between a 'linear curve' - 'round curve' - 'inverted round curve'. This is useful when creating a fillet on an object.
numSteps = 20
height = 15.0 --radius
width = 30.0 --radius
smoothness = .5
delete objects
for i = 0 to numSteps do
(
ang = (180.0 / numSteps) * i
@JokerMartini
JokerMartini / Radial Sorting | .ms
Created August 3, 2015 14:45
Maxscript: Radial sorts objects using the average center position to determine sort.
(
local theObjects = objects as array
local count = theObjects.count
local center = [0, 0, 0]
for obj in theObjects do center += obj.pos
center /= count
fn radialSort obj1 obj2 =
in coordSys (transMatrix center) (cross obj2.pos obj1.pos).z
@JokerMartini
JokerMartini / How to rotate a vector around another vector x degrees | .ms
Last active September 18, 2023 09:11
Maxscript: How to rotate a vector around another vector x degrees.
/* How to rotate a vector around another vector x degrees? */
staticVector = normalize (point3 1 1 1)
rotatingVector = normalize (point3 0 1 1)
centerOfRotatoin = [0,0,0]
x = 30
--use static vector and rotating vector to derive a 3rd axis.
finalVector= cross staticVector rotatingVector
--contruct a matrix 3
@JokerMartini
JokerMartini / Finding Angle Between Two Vectors | .ms
Created August 3, 2015 22:06
Maxscript: finds the angle between two vectors
-- Option 1
fn GetVectorsAngle v1 v2 =
(
theAngle = acos(dot (normalize v1) (normalize v2))
)
vA = obj2.pos - obj1.pos -- vector between two objects
vA = obj3.pos - obj1.pos -- vector between two objects
GetVectorsAngle vA vB
@JokerMartini
JokerMartini / Rotate an object on it's local axis so that y axis faces towards another object | .ms
Last active June 9, 2022 19:06
Maxscript: This function demonstrates how to rotate an object on it's local axis so that y axis faces towards another object
delete objects
target = sphere pos:[20,20,20] radius:2
n = teapot radius:2 pos:[6,35,0]
rotate n (angleaxis -68.2351 [0.808965,0.587747,0.0113632])
-- rotate teapot on local z axis so it points towards the vector (sphere position)
theDir = normalize (target.pos - n.pos) --a vector pointing from teapot to sphere position
theZ = normalize (n.transform.row3) --the local Z axis
theCross = cross theDir theZ --a vector perpendicular to both the Z and the direction vector
theDir2 = normalize (cross theZ theCross) --a vector perpendicular to the Z and the cross product = projection of the direction in local XY
@JokerMartini
JokerMartini / Finding Right Angle Point | .ms
Created August 13, 2015 22:18
Maxscript: This snippet demonstrates how to calculate the corner point for a right angle when knowing 2 points and a normal.
fn GetVectorsAngle v1 v2 =
(
theAngle = acos(dot (normalize v1) (normalize v2))
)
fn PlaceAlongVector pos:[0,0,0] vec:[0,0,1] offset:0 =
(
pos + (normalize (vec)) * offset
)
@JokerMartini
JokerMartini / Smooth-Linear Blend Curve | .ms
Last active July 5, 2017 14:18
Maxscript: This code demonstrates how to create a curve both inward and outward, allowing users to transition between the outer curve - linear - inner curve.
try(destroyDialog rlTest)catch()
rollout rlTest "test"
(
spinner uiWidth "Width" range:[-1e6,1e6,15.0] type:#worldUnits
spinner uiHeight "Height" range:[-1e6,1e6,5.0] type:#worldUnits
spinner uiSmoothness "Smoothness" range:[-1e3,1e3,0] type:#float
spinner uiSamples "Samples" range:[1,1e4,6] type:#integer
spinner uiDegrees "Degrees" range:[0,180,180] type:#float
fn BuildArc =
@JokerMartini
JokerMartini / Rotate Node Around Vector X Degrees | .ms
Created August 14, 2015 16:52
Maxscript: This snippet demonstrates how to rotate a node around a given vector, 'X' degrees. This example rotates a sphere so it aligns with another objects vector based on the same origin.
fn GetVectorsAngle v1 v2 =
(
theAngle = acos(dot (normalize v1) (normalize v2))
)
fn PlaceAlongVector pos:[0,0,0] vec:[0,0,1] offset:0 =
(
pos + (normalize (vec)) * offset
)