Logarithmic spiral – 3DS MaxScript

Okay, so i remember getting deeper into this spiral RnD, and had been working on understanding different types of spirals.

Here is a result of my RnD that i did a while ago, using MaxScript:

--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

/*
Thank you:
https://swiftcoder.wordpress.com/2010/06/21/logarithmic-spiral-distance-field/

HINT: convert to and from

radians = degrees * (pi/180)

degrees = radians * (180/pi)

*/


--initial vars from formula:r = ae^{b*theta}\,
a = 0.0  -- controls the starting angle
b = 0.1  -- controls how tightly the spiral is wound.
t = 0.0  -- this is start angle

theta = t * (pi/180)

across = atan(1/b)
end = 180.0 -- specify max degrees

for theta = 0 to end do 
(
	r = pow e (b*theta)
	r *=0.01
	
	print r
	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
	
)

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

radians = degrees * (pi/180)

degrees = radians * (180/pi)

*/


--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
	
)

python and IDE-Editors – Few things to remember

for daily work i use some more or less suitable IDE’s for python development, like PyCharm, or Eclipce with pydev.

but i cannot go without my sublime editor

sublime already packaged with default python interpreter, which is what makes it super powerful out of the box python programming tool for quick scripts that do not require any custom modules or what not.

but when there is a need to switch to system-default or alternative version of python,

you can create a simple configuration.

more about this is described here

few python quickies

this is a snippet from an data-audit application i made for work.

i often have to convert between file sizes and these are just quick and handy functions to keep around.

def _printDict(d):
    for key, value in d.items():
        print '%s = %s' % (key, value)

def _formatSize(s):
    if s > 1024 * 1024:
        return '%10s (~%s Mb)' % (s, s / (1024 * 1024))
    if s > 1024:
        return '%10s (~%s Kb)' % (s, s / 1024)
    else:
        return '%10s' % s

def _formatSizeInMb(s):
    sizemb = float(s) / (1024 * 1024)
    return '%0.2f' % sizemb

About that GDC talk i did while working in New Zealand

Okay, so at the time it was all calm and everything was just fine, i had been doing some routine work at the studio, making sure our deliverables were on time and that artists could talk to programmers 😉

When our PR had sent out email asking for volunteers to present at an upcoming New Zealand GDC… No real alarms had been going off in my head, and i safely ignored this email and carried on with my duties.

A little time later, i had to take a several interviews for Technical Artists positions that we had opened at the time, and most of the interviews where via Skype.  While being all confident with my skills and that my bosses recognized a TRUE ME in ME 🙂 (lol) , i made a huge list of tech-questions that i was using to “filter” the right candidate. To my surprise, most of the candidates failed… Very few were able to even come close to some of the tech questions i had. And as for me, those were quite standard, considering that position for a Senior Level too.

Now, let me get that email from PR-Lady again… and Listen – i want to do this talk, I have a great topic, is what i replied.

Here it is…

Go from Student to Technical Artist

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
			)
		)
)

Open and add text to image in Python

Here i found an oldrer code snipped that served as my RnD for a thumbnail application that i made for my studio. This code snipped uses very simple.  here is what this snippet does:

We create a new Canvas 512×512, and open another image from our HDD, Resizing the image to desired size, in my case it was 128×128, and i am sure i had a good reason for all these sizes :), we also set the Font that we want to use, here i explicitly copied font file to so opened location, just to avoid some security troubles with Windows folder and all that, we combine our canvas and image together and add text at some location, in red, and as a last step – save this new image somewhere on the disk.

Now, why is this here, often , in production i come about really frequently repeated actions, of assembling some sort of Daily report or something similar, so, if this code is adapted into a very simple structure, you can have a pretty powerful application that allows to save a lot of time in assembly of these assets… really up to your imagination how one could use it.

i want to have this code here for my own reference, and for anyone who is after some ideas for automation.. or what not 🙂
 

from PIL import Image, ImageFont, ImageDraw
font = ImageFont.truetype("C:/arial.ttf", 22)
im = Image.new("RGB", (512, 512), "black")
im2 = Image.open("c:/1.png")
im2 = im2.resize((128,128))
draw = ImageDraw.Draw(im)
im.paste(im2, (10,10))
draw.text((100,100), "Hello", font=font, fill=(255,0,0))
im.save("C:/test.jpg")