Jan 12 2012

Studio Level Managment Of Scripts and Tools in Maya

Today i started to do some online research on what are the current practice for script/and shelf deployment in maya.
the studio I’m currently working for is not a “Maya” house, but we’re getting to the point where often writing tools to convert scenes animated in maya, to something we can use in max. being that this is a somewhat esoteric topic i did not expect that my internet search would return much, but to my surprise i found this article by fellow TD Jonas Avrin.

he really does a great job at introducing the concept of the userSetup.mel as a ways of deploying his personal script from gig to gig.

which seems to me would also make a great starting point along with the mayaEnv.mel to starting the journey into the full time time management of Maya at the studio level.

this might not be anything new to maya TD’s but it was very informative to me 🙂




Jan 10 2012

Singular Value Decomposition (SVD) and object oriented Bounding Boxes

So a continuation of my previous post.. while trying to figure out how to implement SVD (Singular Value Decomposition) algorithm to figure out the best possible aligned bounding box for a set of points.
my friend Ghram Fyffe pointed my to a python library called “numpy” which has great SVD functions that is incredibly easy to use 🙂
seance 3ds max does not support python, i decided i would write the python code to read all the vertex information from a text file, and then overwrite the content of that text file with the resulting alignment matrix.
this method should be eazy to implement into any amp even if it does not have native python support.

i hope this code is helpful to you some one. here it is!

PCA optimized axis generator generator (now threaded)

By Carlos Anguiano
this script will process a text file with point data
and generate and optimized object orient bounding box for the point set
import time
import threading
import sys
import string
import numpy

import os
#this argument feed the script the folder which to parse for pointCloud data files
#PCFld = sys.argv[1]
PCFld = 'C:\Users\SCANLI~2\AppData\Local\Temp\PointCloudData'

def OptmizedTransformAxisFromPointCloadFile (infile):
     lines = open(infile,'r').readlines()
     lCount = len(lines)
     vAr = ""
     for i in range(lCount):
         l = lines[i]
         vector = (l.rstrip())
         vAr += vector

         if i != (lCount-1):
             vAr += ";"
     #once you turn the file content into a string list (look up charArrays) the magic happens
     m = numpy.matrix(vAr)
     USV = numpy.linalg.svd(m)
     return USV[2]

def formatData(data):
     lines = []
     for i in range(3):
         A = numpy.asarray(data[i])
         x = A[0][0]
         y = A[0][1]
         z = A[0][2]
         s = "["+str(x)+","+str(y)+","+str(z)+"]\n"
     return lines

class OptTransAxisFromPCF (threading.Thread):
     def __init__(self,filename):
         self.filename = filename

     def run(self):
         filename = self.filename
         axisData = OptmizedTransformAxisFromPointCloadFile(filename)
         lines = formatData(axisData)
         f = open(filename,'w')

def OptmizedTAxFromPCldFiles (Fldr):
     pcFiles = os.listdir(Fldr)
     if len(pcFiles) == 0:
         print "no files to process in this folder"
         return false

     for f in pcFiles:
         while(threading.activeCount()>=(maxThreads + 1)):
             print 'Waiting for a thread to free up...'
         absF = Fldr+"\\"+f
     while(threading.activeCount() != 1):


Nov 4 2009

The math behind extracting EULER VALUES from a 4×4 transform matrix

This little snippet of code was given to my by my buddy Scott Parrish, who’s a fellow creature TD at ILM.

global proc float[] matrixExtractRot (matrix $aMatrix)
  float $result[3];
  $result[0] = rad_to_deg(atan2($aMatrix[1][2], $aMatrix[2][2]));
  $result[1] = rad_to_deg(-asin ($aMatrix[0][2]));
  $result[2] = rad_to_deg(atan2($aMatrix[0][1], $aMatrix[0][0]));
  return $result;

Aug 18 2009

The math behind rayintersect (closest point on ray)

when i was i first thinking about writing the the rayIntersect function, my plan was to iterate through the entire mesh, and test all the triangles in mesh object with the rayIntersectTriangle function.
the fundamental problem with this is that to run this test on every traingle in a mesh can become very slow.
so i started thinking of running a simpler less expensive test on the faces, figure out which faces are more likely to intersect and only process those. for this i’m thinking i can figure out what the closest point along the ray is to the center of the face, and test the distance between the closet point and the center of the face.
if the this distance is larger than the diameter of the face then this triangle will be ignored.

fn closestPointOnRay ray pos =
    w = pos - ray.pos
    vsq = dot(ray.dir,ray.dir)
    proj = dot(w,ray.dir)
    return  (ray.pos + (proj/vsq)*ray.dir)

i have not tested this function yet. but it should look something like this.
the next thing I’m going to do is test for the for the distance, but use a cool trick that i found in the book “Essential Mathematics for games and interactive applications”.
the most common way for solving the distance between two points is using the good all Pythagorean theory or (x2 + y2 + z2 = d2).
so in order to find the distance of a point from origin we have get the square root of (x2+y2+z2).
being that the square root is one of the heavier math calculations we can avoid it buy just test for the distance squared.

fn sqrDistance pA pB =
    p = pA - pB
    d = (p.x * p.x)+(p.xy* p.y)+(p.z * p.z)
    return d

so we can the test would look something like

fn faceSimpleTest =
    cp = closestPointOnRay ray.pos faceCenter
    sqD = sqrDistance cp faceCenter
    if sqD < faceDiameter then
        return true

Aug 18 2009

The math behind rayintersect (Ray intersect triangle test)

I’m currently working in a 3d package that dosn’t have a rayintersect function available to it’s scripting lenguage. for those who don’t know a ray intersect function is used to test where and if an infinite line in space intersects a triangle. this can be used for many effects in 3d like deforming an object by projecting it’s verts into another surface, or for stoping one object from going through an other 🙂

anyway so i need to write a function in python that will allow me to do this test. i think i have found the math behind it so i figure i write it down here in MAXscript forma, so i can use this a reference to write the python version at work tommorrow

fn RayIntersectTriangle vA vB vC ray =
    //vA vB vC are the positions of the 3 verts that make of the face were testing
    e1 = vB - vA
    e2 = vC - vA
    p = cross(ray.dir e2)
    a = dot(e1,p)
    if a == 0 then return false //no intrsection here the face is parallel to the ray
    //compute denominator
    f = 1.0/a
    //compute barycentric coords
    s = ray.pos - vA
    u = f * dot(s,p)
    if u < 0.0 or u > 1.0 then return false //the u is outside the face
    q = cross(s,e1)
    v = f*dot(ray.dir,q)
    if v < 0.0 or v > 1.0 then return false //the v is outside the face
    t = f*dot(e2,q)
    return (t >= 0)

so the idea is to tweak the function so it return the uv coordinates of the the intersection, which will be easy. then we’ll need to convert does barycentric coordinates to a world space position. which i will look into tomorrow.
this function can then be used to test a ray against all the faces in a geometric mesh.
this might return many intersections of which we would choose the closest one 🙂
this code was translated from the book essential mathematics for games & interactive applications.
i have not tested the code yet so there might be some bugs.