# Archimedean spiral in maxScript

Hi everyone,  i was going through some files on my HDD and found short script that i wrote while researching few topics. this was rather to understand what Spirals were, math behind them and so on. I came about a number of code examples that helped me understand it much better. Here is more about Spirals -> Archimedean spiral

Below is a snippet of 3d MaxScript that i made:

```--Basic start point,
pCenter = Dummy()
pCenter.scale = point3 0.05 0.05 0.05
pCenter.pos = point3 0 0 0
centerX = pCenter.position.x
centerY = pCenter.position.y
centerZ = pcenter.position.z

/*
HINT: convert to and from

*/

--initial vars from formula:r=a+b*theta
a = 0.0  --this will be replaced in params via centerX and centerY
b = 1.0  -- this is distance for offset
t = 0.0  -- this is start angle
theta = t * (pi/180)

end = 1440.0 -- specify max degrees

for theta =0 to end do
(
r = a + theta * b
r *=0.1
x = centerX + cos(theta) * r
y = centerY + sin(theta) * r

pt = Dummy()
pt.scale = point3 0.1 0.1 0.1
pt.pos = point3 x y centerZ

)
```

# MaxScript – bake animation to vertex

Okay, so this was an attempt to transfer some animation into vertex positions and set key-frames on each vertex . Remove the animation at the end from the object itself, so that we  are left with “baked” vertices.  If you try to copy/paste and run this – probably a ton of errors will take place, but if you study this -> a lot of good can come out ( now this is mainly a personal note 😉 )

```fn collectVertPosition geometryNode VertexList  =
(
for v=1 to (polyop.getNumVerts geometryNode) do
(
vertex = polyop.getVert geometryNode v
append VertexList vertex
)
)

fn getXYZlocation vertexList axis =
(
for v = 1 to vertexList.count do
(
if (axis == "x" or axis == "X") then
(
vertX = vertexList[v].x
return vertX
)
if (axis == "y" or axis == "Y") then
(
vertY = vertexList[v].y
return vertY
)
if (axis == "z" or axis == "Z") then
(
vertZ = vertexList[v].z
return vertZ
)
)
)

fn updateXYZlocation vertList axis location =
(
for v = 1 to vertexList.count do
(
if (axis == "x" or axis == "X") then
(
vertexList[v].x = location
)
if (axis == "y" or axis == "Y") then
(
vertexList[v].y = location
)
if (axis == "z" or axis == "Z") then
(
vertexList[v].z = location
)
)
)

-------------------------
sliderTime = 0
--animateVertex \$ #all
originalModel = \$

------------------------------------------------------------
--Create TMP model and append to TMP Layer
targetMeshModel = copy originalModel
targetMeshModel.name = "baked_" + originalModel.name
targetAnimation = LayerManager.newLayer()
targetAnimation.setname "Baked_Animation"
----------------------------------------------------------
targetMeshModel = convertToMesh targetMeshModel
--targetMeshModel = convertToPoly targetMeshModel

sourceVertexList = #()
targetVertexList = #()

collectVertPosition originalModel sourceVertexList
collectVertPosition targetMeshModel targetVertexList

format "source Verts Count: %" sourceVertexList.count
format "target Verts Count: %" targetVertexList.count

--enable animation of the Vertex for Target Node
animateVertex targetMeshModel #all

--set keys to Target Node
with animate on
(
for frame=0 to 120 do
(
for v = 1 to meshop.getNumVerts targetMeshModel do
(
with animate on at time frame meshop.setVert targetMeshModel v sourceVertexList[v]
x = getXYZlocation sourceVertexList "x"
y = getXYZlocation sourceVertexList "y"
z = getXYZlocation sourceVertexList "z"
updateXYZlocation targetVertexList "x" x
updateXYZlocation targetVertexList "y" y
updateXYZlocation targetVertexList "z" z
)
sliderTime = frame
sourceVertexList = #()
collectVertPosition originalModel sourceVertexList

)

)
```

# MaxScript – Zero-out those controls

So for some time at the studio i was doing some coding for rigging, and had to experiment with a few things here and there.
Most of the controls in rigs, for those that don’t know, require relative transformation control, so that component, could look twisted, but is actually at Zero values on all axis in Local space, Often in rig you get this level of control using parenting and some Dummy() objects or Point() objects.
So here is a snipped from a bigger code that takes care of this in maxscript.

```fn getParentRoot theNode =
(
theParent = theNode
while (isValidNode theParent.parent) do
( theParent = theParent.parent )
return theParent
)

fn childildExists obj =
(
if obj.childildren.count != undefined then
( return True )
)

my_obj = getNodeByName "Box002"
root_bone = getParentRoot my_obj

if (childildExists root_bone) then
(
root_point = Point()
root_point.pos = root_bone.pos
for child in root_bone.childildren do
(
if (childildExists child) then (
print child.name )
else
(
point_ = Point()
point_.pos = child.pos
point_.parent = root_point
)
)
)
```

# MaxScript – Standard Material Ops

This is a short code snippet that shows how to create and set material instance for an object using maxscript. this can be wrapped into a function or struct-method. i thought i would post it here so that i can get to this later when or if i will ever need this.

```--Making dummy object
b=box()
--creating material instance
b.material = Standardmaterial()
--assigning BitmapTextures to specific channels
b.material.diffuseMap = Bitmaptexture()
b.material.specularMap = Bitmaptexture()
b.material.bumpmap = Bitmaptexture()
--specify files for bitmaps
b.material.diffuseMap.filename = @"D:\Diffuse_D.bmp"
b.material.specularMap.filename  = @"D:\Specular_M.bmp"
b.material.bumpmap.filename = @"D:\Normal_N.bmp"
--let material be visible in viewport
b.material.showinViewport = True
```