View Full Version : Data conversion weirdness...

11-06-2003, 09:01 AM
Please please please can someone put me out of my misery here. I've written a script which takes a head a user may have made, which consists of RightEye, LeftEye, lowergums, uppergums, tongue, Head2 and Eyelashes. These bits of geometry are skinned to a skeleton whose root joint is called Root. As this data is originallt taken from some 3d scans, sometimes its scale is slightly wrong, so we need to be able to scale these heads. Now if I were to just scale the root joint, the meshes distort horribly, so what my tool does is groups the root node, via the following mel;

select -r Root ;
group -n HeadGroup; xform -os -piv 0 0 0;
I then get the user to scale this to correct size then do the following mel;

select -r HeadGroup ;
duplicate -rr;


select -r RightEye LeftEye lowergums uppergums tongue Eyelashes Head2 ;
duplicate -rr;

select -add HeadGroup1|Root ;

newSkinCluster "-mi 3 -dr 8";

Then I have several procedures setup to copy the skinning vertex by vertex from the original mesh piece to the scaled duplicate mesh piece, as shown below;

global proc string findSkinCluster(string $shape)
// Description:
// Returns the skinCluster (if any) that is in the history
// of the given shape
string $histNodes[] = `listHistory -pdo true $shape`;
string $node;
for($node in $histNodes)
if (`nodeType $node` == "skinCluster")
return $node;
return "";

global proc Head(){

string $copyFromObj = "Head2";
string $copyFromSkinCluster = findSkinCluster($copyFromObj);
string $copyToObj = "Head3";
string $copyToSkinCluster = findSkinCluster($copyToObj);
int $polycountCopyFromObj[] = `polyEvaluate -v $copyFromObj`;
int $polycountCopyToObj[] = `polyEvaluate -v $copyToObj`;
string $jointNames[] = `skinPercent -q -t $copyToSkinCluster ($copyToObj + ".vtx[0]")`;
string $jointWeightsArray[];
string $jointWeightsString;
string $skinPercentCommand;

if ($polycountCopyToObj[0] != $polycountCopyFromObj[0])
error "objects have different polycount";
waitCursor -state on;
//loops through all the mesh vertices int $x is the vtx number
for ($x=0; $x < $polycountCopyToObj[0]; $x++)
//reads the weights of the loop vtx in the imp_obj
string $weightsCopyFromObjCommand = "skinPercent -q -v " + $copyFromSkinCluster + " " + $copyFromObj + ".vtx[" + $x + "]";
float $weightsCopyFromObj[] = eval($weightsCopyFromObjCommand);
//assings those weights to cur_obj in that vtx
for ($y=0; $y < size($jointNames); $y++)
$jointWeightsArray[$y] = "-tv " + $jointNames[$y] + " " + $weightsCopyFromObj[$y] + " ";
$jointWeightsString = $jointWeightsString + $jointWeightsArray[$y];
$skinPercentCommand = "skinPercent " + $jointWeightsString + " " + $copyToSkinCluster + " " + $copyToObj + ".vtx[" + $x + "]";
float $z= (($x*100)/$polycountCopyToObj[0]);
text -edit -label ($z + "%") displayPercent;
//clear everything before leaving the loop for this vertex
clear $weightsCopyFromObj;
clear $jointWeightsArray;
$jointWeightsString = "";
$skinPercentCommand = "";
text -edit -label "" displayPercent;
waitCursor -state off;
print "\nHead skinned";
clear $jointNames;
//waitCursor -state off;

This global Proc Head is repeated for each piece of geometry, changing the $copyFromObj and $copyToObj to the relevant mesh pieces. Unfortunately, for some strange reason I always seem to be getting errors saying;

Cannot convert data of type string to type int[].

I'm absolutely buggered if I can understand whats going on - has anyone out there got any ideas? One of the mel gurus here has said he's had problems with polyEvaluate before - maybe its that?

the error is definately occuring on the following;

int $polycountCopyToObj[] = `polyEvaluate -v $copyToObj`;

however, this only happens on one piece of geometry specifically. However, I have no idea why it is only being a problem on this piece of geometry - it works fine on the other up until this point.

With this in mind, I got a different head in a different scene and tried running the script on that. This one worked fine, on the piece of geometry in question (the eyelashes) so I exported these out on their own and replace the eyes in the other scene with these ones, but lo and behold having done this, these one also cause the script to error! (hope that makes sense!)

I hope someone can help me out here, cos I need to get this script finished soon ....

11-08-2003, 05:06 PM
1) you need to find out what that returnvalue is PRECISELY when the error occurs, e.g. include a temporary "print"-statement

if the iteration ends, and the last symbol returns as "" - it oftentimes constitutes a string!

2) try making your procedures error-proof: check for the right type of data on crucial lines of code.
try a "catch"-statement on the line that causes the exithalt.


CGTalk Moderation
01-16-2006, 02:00 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.