// ===== Create Ogre menu namespace -add "GTPSceneExporter"; namespace -set "GTPSceneExporter"; setParent "MayaWindow"; menu -label "GTP" -tearOff false; menuItem -label "Export Scene" -command "GTPSceneExporter"; menuItem -label "Path Map" -subMenu true; menuItem -label "Add Path Map attributes" -command "GTPAddPathMapAttr"; //GTPSceneExporter(); global proc runGTPSceneExport() { string $outputDir = (`textField -query -text OutputDirectory`); if (!endsWith($outputDir,"\\") && !endsWith($outputDir,"/") && (size($outputDir)>0)) $outputDir += "/"; string $sceneFile = (`textField -query -text SceneFileName`); $sceneFileName = $outputDir + $sceneFile; $fileId = `fopen $sceneFileName "w"`; string $options; string $shapes[]; $shapes=`ls -geometry`; string $commandFile = $outputDir + "GTP_SceneExport.bat"; int $comandFileID; string $commands = ""; if (`checkBox -query -value CreateBinary`) { $comandFileID = `fopen $commandFile "w"`; string $OgreDir = (`textField -query -text OgrePath`); $OgreDir = toNativePath($OgreDir); $commands += "path=" + $OgreDir + "\n"; } //geometry for($index=0;$index0)) $PMTexturePath += "/"; fprint $fileId("\tpathmapfile " + toNativePath($PMTexturePath) + $entityName + "\n"); } fprint $fileId "}\n\n"; } } if (`checkBox -query -value CreateBinary`) { fprint $comandFileID $commands; fclose $comandFileID; system("\"" + `toNativePath $commandFile` + "\""); } //material export int $exportMaterials = `checkBox -query -value ExportMaterials`; if($exportMaterials) { string $materialFile = (`textField -query -text MaterialFilename`); string $materialFileName = encodeString(toNativePath($outputDir + $materialFile)); $options = "-all"; $options += " -mat \"" + $materialFileName + "\""; string $matPrefix = `textField -query -text MaterialPrefix`; if ($matPrefix != "") { $options += " -matPrefix \"" + $matPrefix + "\""; } eval ("ogreExport" + $options); } fclose $fileId; int $exportPathMapMaterials = `checkBox -query -value ExportPMMat`; if($exportPathMapMaterials) { string $materialFile = (`textField -query -text PMMatFile`); string $materialFileName = encodeString(toNativePath($outputDir + $materialFile)); $PMMatfileId = `fopen $materialFileName "w"`; fprint $PMMatfileId "\n"; string $materials[] = `ls -type lambert`; for($i = 0; $i < size($materials); $i++) { select $materials[$i]; fprint $PMMatfileId (" 0) { select $textureFiles[0]; $textureName = `getAttr .fileTextureName`; fprint $PMMatfileId ("texture=\"" + basename($textureName, "") + "\" "); } else { float $baseColor[] = `getAttr .color`; string $colorString = $baseColor[0] + " " + $baseColor[1] + " " + $baseColor[2]; fprint $PMMatfileId ("color=\"" + $colorString + "\" "); } fprint $PMMatfileId "/>\n"; } fprint $PMMatfileId "\n"; fclose $PMMatfileId; } } // ===== Launch exporter UI global proc GTPSceneExporter() { defineGTPExportUIView(); } global proc formatGTPExportUI() { int $exportMaterials = `checkBox -q -v ExportMaterials`; text -edit -enable $exportMaterials MaterialFilenameLabel; textField -edit -enable $exportMaterials MaterialFilename; text -edit -enable $exportMaterials MaterialPrefixLabel; textField -edit -enable $exportMaterials MaterialPrefix; int $exportMeshes = `checkBox -q -v ExportMeshes`; checkBox -edit -enable $exportMeshes CreateBinary; checkBox -edit -enable $exportMeshes BuildEdgeList; checkBox -edit -enable $exportMeshes BuildTangents; if (!$exportMeshes) checkBox -edit -value false CreateBinary; int $createBinary = `checkBox -q -v CreateBinary`; checkBox -edit -enable $createBinary BuildEdgeList; checkBox -edit -enable $createBinary BuildTangents; text -edit -enable $createBinary OgrePathLabel; textField -edit -enable $createBinary OgrePath; int $exportPM = `checkBox -q -v ExportPMAttr`; text -edit -enable $exportPM PMPathLabel; textField -edit -enable $exportPM PMPath; int $exportPMMat = `checkBox -q -v ExportPMMat`; text -edit -enable $exportPMMat PMMatFileLabel; textField -edit -enable $exportPMMat PMMatFile; } global proc defineGTPExportUIView() { string $sceneFile = `file -query -sceneName`; string $sceneDir = dirname($sceneFile); string $mayaFile = basename($sceneFile, "." + fileExtension($sceneFile)); if($mayaFile == "") $mayaFile = "untitled"; // --- Main window for Ogre exporter if (`window -exists GTPSceneExportWindow`) { deleteUI GTPSceneExportWindow; } window -title "GTP Scene Exporter" -widthHeight 305 300 GTPSceneExportWindow; scrollLayout GTPSceneExportScrollLayout; columnLayout GTPSceneExportMainLayout; frameLayout -parent GTPSceneExportMainLayout -label "General" -collapsable true GeneralControls; columnLayout GTPGeneralControlsLayout; text -parent GTPGeneralControlsLayout -label "Output Directory" OutputDirectoryLabel; textField -parent GTPGeneralControlsLayout -width 305 -text $sceneDir OutputDirectory; text -parent GTPGeneralControlsLayout -label "Scene File Name" SceneFileNameLabel; textField -parent GTPGeneralControlsLayout -width 305 -text ($mayaFile + ".level") SceneFileName; frameLayout -parent GTPSceneExportMainLayout -label "Materials" -collapsable true MaterialControls; columnLayout MaterialControlsLayout; checkBox -parent MaterialControlsLayout -value false -changeCommand "formatGTPExportUI" -label "Export Materials" ExportMaterials; text -parent MaterialControlsLayout -label "Material File Name" -enable false MaterialFilenameLabel; textField -parent MaterialControlsLayout -width 305 -enable false -text ($mayaFile + ".material") MaterialFilename; text -parent MaterialControlsLayout -label "Material name prefix" -enable false MaterialPrefixLabel; textField -parent MaterialControlsLayout -width 305 -enable false -text $mayaFile MaterialPrefix; frameLayout -parent GTPSceneExportMainLayout -label "Meshes" -collapsable true -width 309 MeshControls; columnLayout MeshControlsLayout; checkBox -parent MeshControlsLayout -value true -changeCommand "formatGTPExportUI" -label "Export Meshes" ExportMeshes; checkBox -parent MeshControlsLayout -value true -changeCommand "formatGTPExportUI" -label "Create Binary Mesh Files" CreateBinary; checkBox -parent MeshControlsLayout -value false -changeCommand "formatGTPExportUI" -label "Build Edge List" BuildEdgeList; checkBox -parent MeshControlsLayout -value false -changeCommand "formatGTPExportUI" -label "Build Tangent Vectors" BuildTangents; text -parent MeshControlsLayout -label "Ogre Dir(where dlls and OgreXMLConverter.exe are located)" -enable true OgrePathLabel; textField -parent MeshControlsLayout -width 305 -enable true -text "%OGRE_PATH%/Samples/Common/bin/Release" OgrePath; frameLayout -parent GTPSceneExportMainLayout -label "Path Map Options" -collapsable true -width 309 PathMapControls; columnLayout PathMapControlsLayout; checkBox -parent PathMapControlsLayout -value false -changeCommand "formatGTPExportUI" -label "Export Path Map Attributes" ExportPMAttr; text -parent PathMapControlsLayout -label "Path Map Texture Directory" -enable false PMPathLabel; textField -parent PathMapControlsLayout -width 305 -enable false -text "prm" PMPath; checkBox -parent PathMapControlsLayout -value false -changeCommand "formatGTPExportUI" -label "Export Path Map Materials" ExportPMMat; text -parent PathMapControlsLayout -label "Path Map Material File" -enable false PMMatFileLabel; textField -parent PathMapControlsLayout -width 305 -enable false -text ($mayaFile + ".materials") PMMatFile; button -parent GTPSceneExportMainLayout -label "EXPORT" -command "runGTPSceneExport" -width 305 ButtonExport; showWindow GTPSceneExportWindow; } global proc GTPAddPathMapAttr() { string $selected[] = `selectedNodes`; for($i = 0; $i < size($selected); $i++ ) { select $selected[$i]; $isGeometry = `objectType -isType mesh $selected[$i]`; if($isGeometry) { if(!attributeExists("PhotonMapResolution", $selected[$i])) addAttr -at short -ln PhotonMapResolution -sn prmRes -min 16 -max 1024 -dv 64; if(!attributeExists("PhotonMapSubdivision", $selected[$i])) addAttr -at short -ln PhotonMapSubdivision -sn prmDiv -min 1 -dv 1; string $transforms[] = `listRelatives -ap $selected[$i]`; for($j = 0; $j