Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Maya sculpt.mel

Keira Wells
Blender Sculptor
Join date: 16 Mar 2008
Posts: 2,371
05-20-2008 12:58
OK, so got Maya. Made a quick teddy to test things out, and exported using the script here:
http://wiki.secondlife.com/w/index.php?action=raw&ctype=text/javascript&dontcountme=s&title=LlSculpt_mel/sculpt.mel

They all exported into what seems to be correct maps, they look right to me. (Haven't tested yet..will soon though). Anywho, now I want to try using the Advanced Sculptie Exporter here:
http://wiki.secondlife.com/wiki/Advanced_Sculptie_Exporter_From_Maya

In the 'Maya Scripts' section, the screenshot is different from the other sculpt.mel script, so I know that this is a different script. However, I can't seem to download or view the linked sculpt.mel from this page. My browser never loads anything when clicked, and if I right click > save as, it tells me it was unable to download because the connection reset.

Am I the only one having this problem? And is there anywhere else I can find this script?

I can read all of the in-world scripts fine, it's just the Maya sculpt.mel script.

Any help would be greatly appreciated, thank you!
_____________________
Tutorials for Sculpties using Blender!
Http://www.youtube.com/user/BlenderSL
2k Suisei
Registered User
Join date: 9 Nov 2006
Posts: 2,150
05-20-2008 13:33
// * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
// * $License$

global string $llPrimScript;

global proc string llFirst(string $list[])
{
return $list[0];
}


global proc string llGetShadingGroup(string $object)
{
string $allNodes[] = (`listHistory -f true $object` );
string $node = "";
for ($node in $allNodes)
{
if(`nodeType $node` == "shadingEngine";)
{
return $node;
}
}

return "";
}



global proc llSculptExport(string $object,
string $file_name, string $file_extension, string $file_format,
int $resolution_x, int $resolution_y,
int $maximize_scale, int $fix_orientation,
int $surface_bake, int $surface_resolution_x, int $surface_resolution_y, int $surface_shadows,
int $generate_primscript)

{
// copy it, because we're going to mutilate it. MUHAHAHAAAaa...
string $object_copy = llFirst(duplicate($object));

// disentangle from groups
string $parents[] = listRelatives("-parent", $object_copy);
if (size($parents) != 0)
$object_copy = llFirst(parent("-world", $object_copy));

// scale it to unit cube
float $bounding_min[3];
float $bounding_max[3];

$bounding_min = getAttr($object_copy + ".boundingBoxMin";);
$bounding_max = getAttr($object_copy + ".boundingBoxMax";);

float $scale[3];
int $i;
for ($i = 0; $i < 3; $i++)
{
$scale[$i] = $bounding_max[$i] - $bounding_min[$i];
if ($scale[$i] < 0.00001)
$scale[$i] = 1;
}

float $scale_max = 0;
for ($i = 0; $i < 3; $i++)
if ($scale[$i] > $scale_max)
$scale_max = $scale[$i];

if ($maximize_scale)
{
print($object + " scale normalized - scale by " +
$scale[0] + " " + $scale[1] + " " + $scale[2] + " inside SL to get original shape\n";);
}
else
{
for ($i = 0; $i < 3; $i++)
$scale[$i] = $scale_max;
}

scale("-relative", 1/$scale[0], 1/$scale[1], 1/$scale[2], $object_copy);

// position it in unit cube
$bounding_min = getAttr($object_copy + ".boundingBoxMin";);
$bounding_max = getAttr($object_copy + ".boundingBoxMax";);

float $center[3];
for ($i = 0; $i < 3; $i++)
$center[$i] = ($bounding_min[$i] + $bounding_max[$i]) / 2.0;

move("-relative", 0.5 - $center[0], 0.5 - $center[1], 0.5 - $center[2], $object_copy);


//
// nurbs surfaces can be adjusted to ensure correct orientation
//

if ($fix_orientation)
{
string $shape = llFirst(listRelatives("-shapes", $object_copy));
if ((nodeType($object_copy) == "nurbsSurface";) ||
(($shape != "";) && (nodeType($shape) == "nurbsSurface";)))
{
// try to determine the "north pole";
float $pole[] = pointOnSurface("-turnOnPercentage", 1,
"-parameterU", 0.5,
"-parameterV", 0,
$object_copy);
float $total_distance = 0;

float $v;
for ($v = 0; $v <= 1; $v += 0.1)
{
float $point[] = pointOnSurface("-turnOnPercentage", 1,
"-parameterU", $v,
"-parameterV", 0,
$object_copy);
float $distance = 0;
int $i;
for ($i = 0; $i < 3; $i++)
$distance += pow($pole[$i] - $point[$i], 2);
$distance = sqrt($distance);

$total_distance += $distance;
}


if ($total_distance > 0.1) // the points don't converge on the pole - swap
{
print("swapping UVs to orient poles for " + $object + "\n";);
reverseSurface("-direction", 3, $object_copy);
}

// now try to ensure the normal points "out"
// note: this could easily fail - but there's no better way (i think.)

float $total_orientation = 0;
float $u;
for ($u = 0; $u <= 1; $u += 0.1)
for ($v = 0; $v <= 1; $v += 0.1)
{
float $point[] = pointOnSurface("-turnOnPercentage", 1,
"-parameterU", $u,
"-parameterV", $v,
$object_copy);

float $normal[] = pointOnSurface("-normal",
"-turnOnPercentage", 1,
"-parameterU", $u,
"-parameterV", $v,
$object_copy);

// check the orientation of the normal w/r/t the direction from center

float $center_dir[];
for ($i = 0; $i < 3; $i++)
$center_dir[$i] = $point[$i] - 0.5;

float $orientation = 0; // dot product
for ($i = 0; $i < 3; $i++)
$orientation += $center_dir[$i] * $normal[$i];

$total_orientation += $orientation;
}

if ($total_orientation < 0) // need to invert
{
print("reversing V for " + $object + "\n";);
reverseSurface("-direction", 1, $object_copy);
}

}

else
{
warning("cannot fix orientation on non-nurbs object: " + $object);
}


}

// create temporary shading network
string $sampler_info = createNode("samplerInfo";);

string $full_file_name = $file_name + "." + $file_extension;

print("exporting sculpt map for " + $object + " into file " + $full_file_name + "\n";);

// bake sculpt texture
string $fileNodes[] = convertSolidTx("-fileImageName", $full_file_name,
"-fileFormat", $file_format,
"-force", 1,
"-resolutionX", $resolution_x,
"-resolutionY", $resolution_y,
$sampler_info + ".pointWorld",
$object_copy);

delete($fileNodes); // we don't want 'em. why do you make 'em?
delete($sampler_info);
delete($object_copy);

//
// bake texture also?
//

if ($surface_bake)
{
string $texture_file_name = $file_name + "-surface." + $file_extension;

string $shading_group = llGetShadingGroup($object);

print("baking texture for " + $object + " into file " + $texture_file_name + "\n";);

// bake sculpt texture
string $fileNodes[] = convertSolidTx("-fileImageName", $texture_file_name,
"-fileFormat", $file_format,
"-force", 1,
"-resolutionX", $surface_resolution_x,
"-resolutionY", $surface_resolution_y,
"-shadows", $surface_shadows,
$shading_group,
$object);

delete($fileNodes); // still don't want 'em.
}


//
// construct primScript
//
if ($generate_primscript)
{
global string $llPrimScript;

// strip dir from filename
string $tokens[];
tokenize($file_name, "/", $tokens);
string $base_name = $tokens[size($tokens)-1];

$llPrimScript += "newPrim\n";

$llPrimScript += "prim -setObjectName " + $object + " -deleteScript\n";

$llPrimScript += "shape -setSculpt " + $base_name + " 1 -deleteScript\n";

$llPrimScript += "texture";
if ($surface_bake)
$llPrimScript += " -setTexture " + $base_name + "-surface -1";
$llPrimScript += " -deleteScript\n";

$llPrimScript += "transform -setScale " +
$scale[0] + " " + $scale[1] + " " +$scale[2] +
" -gotoRelativePos " +
$center[0]*$scale[0] + " " + $center[1]*$scale[1] + " " +$center[2]*$scale[2] +
" -deleteScript \n";
}

}



global proc int llSculptEditorCallback()
{
string $objects[] = ls("-sl";);

if (size($objects) == 0)
{
warning("please select objects to export";);
return 0;
}

string $filename = textFieldButtonGrp("-query", "-fileName", "llSculptEditorFilename";);
int $resolution_x = intSliderGrp("-query", "-value", "llSculptEditorResolutionX";);
int $resolution_y = intSliderGrp("-query", "-value", "llSculptEditorResolutionY";);
int $fix_orientation = checkBoxGrp("-query", "-value1", "llSculptEditorFixOrientation";);
int $maximize_scale = checkBoxGrp("-query", "-value1", "llSculptEditorMaximizeScale";);
int $surface_bake = checkBoxGrp("-query", "-value1", "llSculptEditorSurfaceBake";);
int $surface_resolution_x = intSliderGrp("-query", "-value", "llSculptEditorSurfaceResolutionX";);
int $surface_resolution_y = intSliderGrp("-query", "-value", "llSculptEditorSurfaceResolutionY";);
int $surface_shadows = checkBoxGrp("-query", "-value1", "llSculptEditorSurfaceShadows";);
int $generate_primscript = checkBoxGrp("-query", "-value1", "llSculptEditorGeneratePrimScript";);


// get filetype
string $file_type;
string $file_base;
string $file_extension;

string $tokens[];
tokenize($filename, ".", $tokens);

if (size($tokens) == 1) // no extension, default to bmp
{
$file_base = $filename;
$file_type = "bmp";
$file_extension = "bmp";
}
else
{
$file_extension = $tokens[size($tokens) - 1];
int $i;
for ($i = 0; $i < size($tokens) - 1; $i++)
{
$file_base += $tokens[$i];
if ($i != size($tokens) - 2)
$file_base += ".";
}

if ($file_extension == "bmp";)
$file_type = "bmp";
else if (($file_extension == "jpg";) || ($file_extension == "jpeg";))
$file_type = "jpg";
else if (($file_extension == "tif";) || ($file_extension == "tiff";))
$file_type = "tif";
else if ($file_extension == "tga";)
$file_type = "tga";
else
{
warning("unknown image type (" + $file_extension + ";). switching to bmp";);
$file_type = "bmp";
$file_extension = "bmp";
}
}


global string $llPrimScript;
$llPrimScript = "";

int $multi_file = 0;

if (size($objects) > 1)
$multi_file = 1;

if ($generate_primscript)
$multi_file = 1;

string $object;
for ($object in $objects)
{
string $this_filename = $file_base;
if ($multi_file)
$this_filename += "-" + $object;

llSculptExport($object, $this_filename, $file_extension, $file_type, $resolution_x, $resolution_y,
$maximize_scale, $fix_orientation,
$surface_bake, $surface_resolution_x, $surface_resolution_y, $surface_shadows,
$generate_primscript);
}

if ($generate_primscript)
{
int $file_id=fopen($file_base + ".primscript";);
fwrite($file_id, $llPrimScript);
fclose($file_id);
}

select($objects);

return 1;
}

global proc llSculptEditorSetFilenameCallback(string $filename, string $filetype)
{
textFieldButtonGrp("-edit", "-fileName", $filename, "llSculptEditorFilename";);
}

global proc llSculptEditorBrowseCallback()
{
fileBrowser("llSculptEditorSetFilenameCallback", "Export", "image", 1);
}

global proc llSculptEditorSurfaceBakeCallback()
{
int $surface_bake = checkBoxGrp("-query", "-value1", "llSculptEditorSurfaceBake";);

control("-edit", "-enable", $surface_bake, "llSculptEditorSurfaceResolutionX";);
control("-edit", "-enable", $surface_bake, "llSculptEditorSurfaceResolutionY";);
control("-edit", "-enable", $surface_bake, "llSculptEditorSurfaceShadows";);
}


global proc llSculptEditor()
{
string $commandName = "llSculptExport";

string $layout = getOptionBox();
setParent $layout;

setOptionBoxCommandName($commandName);

setUITemplate -pushTemplate DefaultTemplate;

scrollLayout;

tabLayout -tabsVisible 0 -scrollable 1;

string $parent = `columnLayout -adjustableColumn 1`;

separator -height 10 -style "none";

textFieldButtonGrp
-label "Filename"
-fileName "sculpt.bmp"
-buttonLabel "Browse"
-buttonCommand "llSculptEditorBrowseCallback"
llSculptEditorFilename;

intSliderGrp
-field on
-label "X Resolution"
-minValue 1
-maxValue 512
-fieldMinValue 1
-fieldMaxValue 4096
-value 64
llSculptEditorResolutionX;

intSliderGrp
-field on
-label "Y Resolution"
-minValue 1
-maxValue 512
-fieldMinValue 1
-fieldMaxValue 4096
-value 64
llSculptEditorResolutionY;

checkBoxGrp
-label ""
-label1 "Maximize scale"
-numberOfCheckBoxes 1
-value1 on
llSculptEditorMaximizeScale;

checkBoxGrp
-label ""
-label1 "Correct orientation"
-numberOfCheckBoxes 1
-value1 off
llSculptEditorFixOrientation;

separator;

checkBoxGrp
-label ""
-label1 "Bake surface texture"
-numberOfCheckBoxes 1
-value1 off
-changeCommand llSculptEditorSurfaceBakeCallback
llSculptEditorSurfaceBake;

intSliderGrp
-field on
-label "X Resolution"
-minValue 1
-maxValue 512
-fieldMinValue 1
-fieldMaxValue 4096
-value 128
llSculptEditorSurfaceResolutionX;

intSliderGrp
-field on
-label "Y Resolution"
-minValue 1
-maxValue 512
-fieldMinValue 1
-fieldMaxValue 4096
-value 128
llSculptEditorSurfaceResolutionY;

checkBoxGrp
-label ""
-label1 "Include shadows"
-numberOfCheckBoxes 1
-value1 off
llSculptEditorSurfaceShadows;

separator;

checkBoxGrp
-label ""
-label1 "Generate primscript"
-numberOfCheckBoxes 1
-value1 off
llSculptEditorGeneratePrimScript;



setUITemplate -popTemplate;

string $applyBtn = getOptionBoxApplyBtn();
button -edit
-label "Export"
-command "llSculptEditorCallback"
$applyBtn;

string $applyAndCloseBtn = getOptionBoxApplyAndCloseBtn();
button -edit
-label "Export and Close"
-command "llSculptEditorCallback"
$applyAndCloseBtn;


setOptionBoxTitle("Export Sculpt Texture";);

setOptionBoxHelpTag( "ConvertFileText" );

llSculptEditorSurfaceBakeCallback();

showOptionBox();
}


//

llSculptEditor;
Keira Wells
Blender Sculptor
Join date: 16 Mar 2008
Posts: 2,371
05-20-2008 13:35
Thank you ^____^
_____________________
Tutorials for Sculpties using Blender!
Http://www.youtube.com/user/BlenderSL
Keira Wells
Blender Sculptor
Join date: 16 Mar 2008
Posts: 2,371
05-20-2008 13:53
New question!

That script loaded fine and all.. but I have no 'Generate primscript' toggle box. After the 'include shadows' one is a small scroll bar (Left to right) and then just blank gray box.

>.> Now what?

XD
_____________________
Tutorials for Sculpties using Blender!
Http://www.youtube.com/user/BlenderSL
Keira Wells
Blender Sculptor
Join date: 16 Mar 2008
Posts: 2,371
05-20-2008 14:05
I just went through the script in the editor in Maya, and where the buttons are defined, it does have an entry for the checkbox for generate primscript, and it seems to be pointing to the right bit of code, but I still don't see it. Blargh



Also, I'm not a coder. I did a search for 'primscript' and found various entries that meant nothing to me, and then a line that looked to be defining a checkbox, with that name and pointing to that function. It happened to be in a small block of code that looked to be defining sliders and checkboxes, so I'm assuming that's where the button-thingies are defined in the script.
_____________________
Tutorials for Sculpties using Blender!
Http://www.youtube.com/user/BlenderSL
2k Suisei
Registered User
Join date: 9 Nov 2006
Posts: 2,150
05-20-2008 14:06
Search for "scrollable" and you'll find this line:

From: someone
tabLayout -tabsVisible 0 -scrollable 1;


Change the 1 to 0:

From: someone
tabLayout -tabsVisible 0 -scrollable 0;


It's a well known bug.
Keira Wells
Blender Sculptor
Join date: 16 Mar 2008
Posts: 2,371
05-20-2008 14:12
yay thank you!

ETA:: The sculpt is now posted in the show us your sculpties thread ^_^

Thankies again for the help!
_____________________
Tutorials for Sculpties using Blender!
Http://www.youtube.com/user/BlenderSL
Fiona Branagh
... or her equivalent.
Join date: 1 Feb 2007
Posts: 156
05-22-2008 08:07
I'd really like a copy of the old script that doesn't fix the inversion problem.

The reason for this is I have a lot of old sculpty files in Maya that I can't tweak for animations anymore with the new sculpty MEL, because it's not going through the same inversion step - it screws with the shape and UV.

Anyone still have it?
_____________________
Fiona Branagh
... or her equivalent.
Join date: 1 Feb 2007
Posts: 156
05-22-2008 10:35
Or, if anyone has a good notion on how to fiddle with the output of the new one in Photoshop so as to get the same effect... great.

I don't have the time these days to fiddle with countless exports and uploads to see if it's even possible, which is why I figured the easiest way would be to get the old exporter - but I'll take any solution.

Yes, I know I could re-export all the maps of all my sculpties, and then refigure the textures and recode all my critters to reorient all the sculpts... but I would vastly prefer to just be able to finish off my old projects without redoing them, and then use the new exporter on new projects.

Help, anyone?
_____________________
Zena Juran
Registered User
Join date: 21 Jul 2007
Posts: 473
06-16-2008 20:35
HIyas Everyone, I just found the wiki page with the Maya exporter by Qarl. When I type in "sculpt" in the MEL command line (after installing the script), it seems to generate something but I don't get a popup window or anything for the Export Sculpt Texture. I searched the menus but didn't dind anything there either. I have Maya 2008 and running .Net 2.0. Also running MONO. Also can't seem to keep the window open for Importprimscript (flashes open and then closes right out). What am I missing here? All help greatly appreciated. :-)
Chosen Few
Alpha Channel Slave
Join date: 16 Jan 2004
Posts: 7,496
06-16-2008 23:35
From: Zena Juran
When I type in "sculpt" in the MEL command line (after installing the script), it seems to generate something but I don't get a popup window or anything for the Export Sculpt Texture.

I'd suggest you park the script on your shelf as a button and run it from there. I've posted detailed instructions for how to do that at /8/fe/236258/1.html and /8/06/257778/1.html and several other threads.

I wasn't even aware that the "sculpt" text command even existed.

From: Zena Juran
I have Maya 2008 and running .Net 2.0. Also running MONO.

You don't need .Net or MONO for MEL scripts, just Maya. MEL, true to its name, is embedded directly in Maya.

From: Zena Juran
Also can't seem to keep the window open for Importprimscript (flashes open and then closes right out). What am I missing here?

What do you mean by "window for Importpriscript"? It's a command line program. The only window you need is your Windows command prompt.

In any case, I'm sorry to have to tell you Importprimscript is broken right now, thanks to recent changes to the SL server code. Depending on what version of Importprimscript you have, it will either upload the textures and then fail to rez the objects, or else it will fail right at the upload stage. Qarl's Qlab Assembler is the better choice right now. You'll find that it fails to place the objects in the right positions, but the sizes and rotations at least will be correct, and then you can position the objects by hand. It's a pain, but it's the only viable option at the moment.
_____________________
.

Land now available for rent in Indigo. Low rates. Quiet, low-lag mainland sim with good neighbors. IM me in-world if you're interested.
Zena Juran
Registered User
Join date: 21 Jul 2007
Posts: 473
06-17-2008 04:14
Thanx Chosen! All is well now. What a roundabout way to get a decent sculpt into SL... lol