Integration/Tracking Demo Reel 2018 on Youtube
MJ VFX
Personal Blog, VFX, News, Discussion, Tools, Technology, Some Python & Mel Scripting, howto's and random stuff
Wednesday, December 19, 2018
Wednesday, August 14, 2013
Integration / Tracking Reel 2013 from Montu Jariwala on Vimeo.
Show reel of my latest tracking and environments work featuring shots from Real Steel, Tron, Jack The Giant Slayer, G.I.Joe: The Rise of Cobra, The Watch, Transformers and The Seeker: The Dark Is Rising.
Skill set: camera tracking, matchmoving, object tracking, stereoscopic tracking, Environments, HDR prep, python scripting for Maya and Nuke
Software used: PFTrack, SynthEyes, Maya, Nuke, Image Modeler and proprietary tracking software
Monday, December 19, 2011
Python Looping Techniques
looping thru list
li = ['cube', 'sphere', 'reactangle' ]
for i, v in enumerate(li):
print i,v
print i,v
1 sphere
2 reactangle
Looping thru Dictionary
a = {'translate': '25', 'rotate': '4'}
for k, v in a.iteritems():
print k, v
translate 25
rotate 4
rotate 4
List Comprehension
squares = [x**2 for x in range(10)]
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
squares = map(lambda x: x**2, range(10))
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
Thursday, December 15, 2011
Python: list objects to string
Python tips - How to easily convert a list to a string for display
if it is a list of strings, you may simply use join this way:
>>> mylist = ['spam', 'ham', 'eggs'] >>> print ', '.join(mylist) spam, ham, eggs
Using the same method, you might also do this:
>>> print '\n'.join(mylist)
spam
ham
eggsspam
ham
eggs
u can store the result in string variable. this time its and empty space between list objects
>>> c = ' '.join(mylist)
spam ham eggs
for non-string objects, such as integers.
If you just want to obtain a comma-separated string, you may use this shortcut:
>>> list_of_ints = [820, 547, 8080, 8081] >>> print str(list_of_ints).strip('[]')
820, 547, 8080, 8081
Or this one, if your objects contain square brackets:
>>> print str(list_of_ints)[1:-1]
820, 547, 8080, 8081
Finally, you may use map() to convert each item in the list to a string, and then join them:
>>> print ', '.join(map(str, list_of_ints)) 820, 547, 8080, 8081
>>> print '\n'.join(map(str, list_of_ints))
820 547
8080
8081
Tuesday, July 19, 2011
Randomize selected vertex in Maya
def moveRandom(input):
import random
import maya.cmds as cmds
s = cmds.ls(sl=True, fl =True)
num = len(s)
for i in range(num):
cmds.select(s[i])
r = random.random()
h =r*input
cmds.move( h, h, h, s[i], relative=True )
Monday, December 6, 2010
Intersection between Line and the Plane
A and B are the 2 known points on the line and t is the parameter which will allow us to find a point P on the line.
lets assume that P is the point of intersection between a line and a plane
in order to find point P we will need to find value of the parameter t.
to find t, we plug equation of line into the equation of plane, where we have everything we need to calculate t.
once we have t, we plug into our equation of line back to find P.
The equation of a line is:
P = A + t(B – A) ------------------------------------------------------------------ (1)
- P is any arbitrary point on the line. In this case, P is the point of intersection of the ray and the plane
- A is the starting point of the line
- B is the end point of our line segment
- t is the parameter. Values between 0 and 1 represent points on our line.
- Po and Co are position vector for P and C.
- Po-Co will lie completely in the plane. hence dot product of this to planes normal will be zero.
The equation of a plane is:
N dot (P – C) = 0 ------------------------------------------------------------------ (2)
- N is the normal of the plane
- P and C are known points on the plane. In this case, P will represent the point of intersection. If our plane was represented by a triangle, C could be one of the vertices.
Plug the equation of the ray from ---(1) into our intersection pt of the equation of the plane ---(2).
N dot ( (A + tV) – C) = 0
Solve for t:
(N dot (A + tV)) – (N dot C) = 0
(N dot (A + tV)) = (N dot C)
(N dot A) + (N dot tV) = (N dot C)
N dot tV = (N dot C) - (N dot A)
t = N dot (C – A) /N dot V ------------------------------------------------------------------ (3)
so we calculated the value of t. we can use this value in the line equation to find the co-ordinates of the intersection point
we have all the information on the right side of equal sign mean we can find P.
puting t in equation of line
P = A + t(B – A) ------------------------------------------------------------------ (4)
If:
t > 0 and t < 1 : The intersection occurs between the two points
t = 0 : The intersection falls on the first point
t = 1 : Intersection falls on the second point
t > 1 : Intersection occurs beyond second Point
t < 0 : Intersection happens before 1st point.
Tuesday, November 30, 2010
Mel : How to find center of 2 selected vertex
so if we know 2 points out in 3d space and if you want to shoot a point along the line anywhere in 3d space you can achieve this using vector equation of a line.you can also find center of 2 Selected vertex.
using vector equation of line
r = ro + a
a = t*(v)
r = ro + t*(v)
t*(v) will be a vector that lines along the line and it tells us how far from the original point that we should move. if t is positive we move away from the original point in direction of vector v and if t is negative we move away from the original point in the opposite direction of vector v. note vector v can be anywhere in 3D as long as it is parallal to a.
string $verts[] = `ls -sl -fl`;
vector $ro = `pointPosition $verts[0]`;
vector $r = `pointPosition $verts[1]`;
vector $v = $r - $ro;
float $result[] = $ro + (0.5*$v);
$sl = `spaceLocator`;
move $result[0] $result[1] $result[2] $sl;
above script will create a locator in the center of 2 selected vertex as i used t as 0.5 here.
imagine your first point is camera position and second point is 2d pattern looking thru camera. if you want to extend the ray from these 2 points far enough you can use above script with the t value whatever you like. you can go t over 1 so the third point goes beyond your second point.
Mel : How to return multiple values in procedure?
you can do this using string array
global proc string[] myproc() {
string $r[];
string $sel[] = `ls -sl`;
float $pos[] = `xform -q -ws -t $sel[0]`;
$r[0] = $sel[0];
$r[1] = $pos[0];
$r[2] = $pos[1];
$r[3] = $pos[2];
return $r;
}
myproc();
so for example if you want to store selected object's transform node and shape node name along with translate x,y,z in a string array, you can plug all of them in string array inside the proc.
here i am forcing my script to store values only if shape node is camera.
global proc string[] camtr(string $myselection[]) {
string $return[];
string $shp[] = `listRelatives -s $myselection[0]`;
for ( $s in $shp )
{
string $cam = `nodeType $s`;
if ($cam == "camera")
{
print ( "\n YES " + $s + " is camera\n");
$pos =`xform -q -ws -t $myselection[0]`;
$return[0] = $myselection[0];
$return[1] = $shp[0];
$return[2] = $pos[0];
$return[3] = $pos[1];
$return[4] = $pos[2];
}
else
{
print ( "\n No " + $s + " is not a camera. It is a " + $cam +"\n");
}
}
return $return;
}
string $sel[] = `ls -sl -fl`;
string $b[] =camtr($sel);
global proc string[] myproc() {
string $r[];
string $sel[] = `ls -sl`;
float $pos[] = `xform -q -ws -t $sel[0]`;
$r[0] = $sel[0];
$r[1] = $pos[0];
$r[2] = $pos[1];
$r[3] = $pos[2];
return $r;
}
myproc();
here i am forcing my script to store values only if shape node is camera.
global proc string[] camtr(string $myselection[]) {
string $return[];
string $shp[] = `listRelatives -s $myselection[0]`;
for ( $s in $shp )
{
string $cam = `nodeType $s`;
if ($cam == "camera")
{
print ( "\n YES " + $s + " is camera\n");
$pos =`xform -q -ws -t $myselection[0]`;
$return[0] = $myselection[0];
$return[1] = $shp[0];
$return[2] = $pos[0];
$return[3] = $pos[1];
$return[4] = $pos[2];
}
else
{
print ( "\n No " + $s + " is not a camera. It is a " + $cam +"\n");
}
}
return $return;
}
to see result of above proc
string $b[] =camtr($sel);
Sunday, May 23, 2010
Mel : useful Maya file commands
some handy Maya file commands
some basic file and directory path operation commands
How to query currently opened scene name?
file -q -sceneName;
How to find directory path of the currently opened scene?
dirname(`file -q -sceneName`);
How to find path to your default projects directory?
string $path[]= `internalVar -uwd`;
uwd flag is short for user work directory
How to make directory thru mel?
depends on where you want to make first line can vary.
i will illustrate how to make folder in maya/scene folder
$currentFilePath = dirname(`file -q -sceneName`);
$folder = $currentFilePath + "/my_folder";
sysFile -makeDir $folder ;
How to export obj using file command?
for example i will use above location to create another folder name my_obj_folder
$sel = `ls -sl`;
$currentFilePath = dirname(`file -q -sceneName`);
$objfolder = $currentFilePath + "/my_obj_folder";
sysFile -makeDir $objfolder ;
string $objpath = $objfolder + "/" + $sel[0] + ".obj";
file -typ "OBJ" -pr -es $objpath;
if you want to make folder name as selected object name in maya then replace line 3 in above script with this $objfolder = $currentFilePath + "/" + $sel[0];
$sel = `ls -sl`;
$currentFilePath = dirname(`file -q -sceneName`);
$objfolder = $currentFilePath + "/" + $sel[0];
sysFile -makeDir $objfolder ;
string $objpath = $objfolder + "/" + $sel[0] + ".obj";
file -typ "OBJ" -pr -es $objpath;
How to open a file using fileDialog mel command?
string $filename = `fileDialog -m 0 -directoryMask "/home/username/maya/scenes/*.ma"`;
file -o $filename;
i have used fileDialog and file mel command here
you can replace path with whatever path you are working on.
m flag in the first line stands for mode. 0 is for opening the file.
note: if u have unsaved file opened when you run the script it will give u error.
Monday, March 15, 2010
Mel : Matchmover's Handy Tool
with camera offset x y and overscan attribute you can pan left right and zoom on to the imageplane without affecting camera transform node. this is really handy specially for matchmoving when you are trying to lineup camera to the track geometry or fixing camera and you want to zoom into the imageplane really close without affecting camera.
To test these procedures i am going to add these to the my custom maya shelf. if you want you can make hotkey for these to make it even quicker. its your choice. i personally use hotkeys for these. dig in thru my earlier post to see how to make hotkey thru mel.
but just for testing purpose i am adding them to shelf.
Select a camera and look thru that camera in current model panel. load any image in the imageplane so that we can test these procedures better to see whats happening. test them one at a time using middle mouse drag screen left-right. hold control key while dragging middle mouse will make the drag slower and once you done you can reset them to default value.
hope this is helpful. please make any suggestion if you have any.
global proc drag_Xpan(){
string $camName[] = `ls -sl`;
string $camShapeName[] = `listRelatives -s $camName[0]`;
dragAttrContext dxpan;
dragAttrContext -edit -ct ($camShapeName[0] +".horizontalFilmOffset") dxpan;
setToolTo dxpan;
}
global proc drag_Ypan(){
string $camName[] = `ls -sl`;
string $camShapeName[] = `listRelatives -s $camName[0]`;
dragAttrContext dypan;
dragAttrContext -edit -ct ($camShapeName[0] +".verticalFilmOffset") dypan;
setToolTo dypan;
}
global proc drag_Zoom(){
string $camName[] = `ls -sl`;
string $camShapeName[] = `listRelatives -s $camName[0]`;
dragAttrContext dzoom;
dragAttrContext -edit -ct ($camShapeName[0] +".overscan") dzoom;
setToolTo dzoom;
}
global proc resetCam(){
string $camName[] = `ls -sl`;
string $camShapeName[] = `listRelatives -s $camName[0]`;
setAttr ($camShapeName[0] +".horizontalFilmOffset") 0;
setAttr ($camShapeName[0] +".verticalFilmOffset") 0;
setAttr ($camShapeName[0] +".overscan") 1;
}
To test these procedures i am going to add these to the my custom maya shelf. if you want you can make hotkey for these to make it even quicker. its your choice. i personally use hotkeys for these. dig in thru my earlier post to see how to make hotkey thru mel.
but just for testing purpose i am adding them to shelf.
scriptToShelf "X" "drag_Xpan;" "1";
scriptToShelf "Y" "drag_Ypan;" "1";
scriptToShelf "Y" "drag_Zoom;" "1";
scriptToShelf "reset" "resetCam;" "1";
Select a camera and look thru that camera in current model panel. load any image in the imageplane so that we can test these procedures better to see whats happening. test them one at a time using middle mouse drag screen left-right. hold control key while dragging middle mouse will make the drag slower and once you done you can reset them to default value.
hope this is helpful. please make any suggestion if you have any.
Mel: Measure Distance
Maya has this Measure tool which pretty much does the job but i always felt lazy to go thru Create Menu / Measure tool and click on vertices one after other with snap on. too many things to do to get simple distance between two points. i made this script handy for myself for quick checks specially when i have survey information and measurement from set. you can simply make this global procedure in your user/maya/script path and assign hotkey to even make it quicker. it saves time when you want to query lots of measurements and cross check track data scale from tracking software in 3D. pretty sure this can be handy even for modelers, animator and fx guys. script currently works for transform, mesh, nurbsCurve type of nodes. you can modify it further to include different nodes based on your needs.
script is self explanatory. also if you have any suggestion to make this script better please share.
global proc getdistance(){
string $currentsel[] = `ls -sl -fl`;
if ($currentsel[0] == "") error "You must select two nodes or vertex to measure the distance";
else {
int $numofvertex = size($currentsel);
if($numofvertex > 2) error "More than 2 nodes selected. Make selection again with only two nodes to measure distance between them";
else {
if(`objectType -isType "mesh" $currentsel[0]` || `objectType -isType "nurbsCurve" $currentsel[0]`)
{
vector $va = `pointPosition $currentsel[0]`;
vector $vb = `pointPosition $currentsel[1]`;
vector $distpos = $va - $vb;
float $d = `mag <<$distpos.x, $distpos.y, $distpos.z>>`;
string $unit= `currentUnit -query -linear`;
print ($d + "\t" + $unit);
}
else if (`objectType -isType "transform" $currentsel[0]`)
{
vector $va = `xform -q -ws -a -rp $currentsel[0]`;
vector $vb = `xform -q -ws -a -rp $currentsel[1]`;
vector $distpos = $va - $vb;
float $d = `mag <<$distpos.x, $distpos.y, $distpos.z>>`;
string $unit= `currentUnit -query -linear`;
print ($d + "\t" + $unit);
}
}
}
}
script is self explanatory. also if you have any suggestion to make this script better please share.
global proc getdistance(){
string $currentsel[] = `ls -sl -fl`;
if ($currentsel[0] == "") error "You must select two nodes or vertex to measure the distance";
else {
int $numofvertex = size($currentsel);
if($numofvertex > 2) error "More than 2 nodes selected. Make selection again with only two nodes to measure distance between them";
else {
if(`objectType -isType "mesh" $currentsel[0]` || `objectType -isType "nurbsCurve" $currentsel[0]`)
{
vector $va = `pointPosition $currentsel[0]`;
vector $vb = `pointPosition $currentsel[1]`;
vector $distpos = $va - $vb;
float $d = `mag <<$distpos.x, $distpos.y, $distpos.z>>`;
string $unit= `currentUnit -query -linear`;
print ($d + "\t" + $unit);
}
else if (`objectType -isType "transform" $currentsel[0]`)
{
vector $va = `xform -q -ws -a -rp $currentsel[0]`;
vector $vb = `xform -q -ws -a -rp $currentsel[1]`;
vector $distpos = $va - $vb;
float $d = `mag <<$distpos.x, $distpos.y, $distpos.z>>`;
string $unit= `currentUnit -query -linear`;
print ($d + "\t" + $unit);
}
}
}
}
Subscribe to:
Posts (Atom)
Integration/Tracking Demo Reel 2018 on Youtube
-
you can do this using string array global proc string[] myproc() { string $r[]; string $sel[] = `ls -sl`; float $pos[] = `x...
-
some handy Maya file commands some basic file and directory path operation commands How to query currently opened scene name? fil...