// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 //////////////////////////////////////////////////////////// //KRAKATOA MAGMA EDITOR FOR MAYA //Started: 2013/09/23 //Edited: 2014/01/17 //Code by Conrad Wiebe, Matthew Yu, Borislav "Bobo" Petrov //Thinkbox Software Inc. // //////////////////////////////////////////////////////////// global proc string GetMagmaFluxDialogName (string $prtNode) { string $nodelist[]; string $nodename; tokenize $prtNode "|" $nodelist; for ($i in $nodelist) $nodename+="_"+$i; return ("magmaFLUXEditorWindow" + $nodename); } global proc OpenMagmaFLUXDialog (string $prtNode ) { string $windowName = `GetMagmaFluxDialogName $prtNode`; if( `window -exists $windowName` ) deleteUI -window $windowName; window $windowName; PopulateMagmaFLUXDialog $prtNode $windowName; showWindow $windowName; } global proc ResetMagmaFLUXDialog ( string $prtNode ) { string $ret = `confirmDialog -title "Reset Magma Flow?" -message "Are you sure you want to RESET the content of the Magma Editor?" -button "Yes" -button "No" -defaultButton "Yes" -cancelButton "No"`; if ($ret == "Yes") { checkBox -e -v false ($prtNode+"_chk_enableUpdatesAndReoderCalls"); apply_magma_description -prt $prtNode -n {} -e {} -v {} -rn true ; checkBox -e -v true ($prtNode+"_chk_enableUpdatesAndReoderCalls"); MagmaFLUX_resetSelection $prtNode {}; MagmaEditor_CreateUndoRecord $prtNode ("File > Reset Flow"); } } global proc AboutMagmaFLUXDialog () { string $ret = `confirmDialog -title "About Krakatoa MY Magma" -message "Krakatoa MY Magma Channel Editor\n� 2013 by Thinkbox Software, Inc.\nAll Rights Reserved." -button "OK" -defaultButton "OK" -cancelButton "OK"`; } global proc int MagmaEditor_GetNodeHeight (string $prtNode, int $id) { string $type = `retrieve_magma_node_instance_info -id $id -prt $prtNode -type true`; string $insockets[] = `retrieve_magma_node_instance_info -id $id -prt $prtNode -is true`; int $insocketsCount = `size $insockets`; string $outsockets[] = `retrieve_magma_node_instance_info -id $id -prt $prtNode -os true`; int $outsocketsCount = `size $outsockets`; int $nodeheight = 60 + ($insocketsCount + $outsocketsCount)*22; if ($type == "NearestPoint") $nodeheight = 260; return $nodeheight; } global proc int MagmaSetNodePositionRecursive (int $parentNode, int $lastX, string $prtNode, int $raster[], int $processednodes[], int $reordermode, int $maxcolumns, int $outtype ) { int $nodeheight = `MagmaEditor_GetNodeHeight $prtNode $parentNode`; float $snapsize = 20; int $posX = 500 - $lastX*200; int $posY = (($raster[$lastX]*$snapsize)-500); if ($processednodes[$parentNode] == 0 ) //if not processed or not first pass modes || ($reordermode != 2 && $reordermode != 4 && $reordermode != 6) { if ($reordermode == 2 ) // branch mode || $reordermode == 3 { if ($raster[$lastX]> $raster[$lastX+1]) { $raster[$lastX+1] = $raster[$lastX]; } } $raster[$lastX] = $raster[$lastX] + (int)(($nodeheight/$snapsize)); //print ("$raster[$lastX]="+$raster[$lastX]+"\n"); if ($reordermode > 1) // if not manual mode, move the node to new position { //print ("ID:"+$parentNode +" PosX: "+$posX +" PosY: "+ $posY+"\n"); set_magma_node_instance_info -id $parentNode -prt $prtNode -x $posX -y $posY; } $processednodes[$parentNode] = 1; } $lastX++; int $connection[] = `get_magma_connections -prt $prtNode -id $parentNode`; int $i = 0; for ($i = 0; $i < `size $connection`; $i=$i+2) { if ($connection[$i] > -1 && $processednodes[$connection[$i]] == 0) //if connected and the connection is unprocessed { //MagmaSwitchInputSocketDefaults $connection[$i] $prtNode $outtype; int $returnvalue = `MagmaSetNodePositionRecursive $connection[$i] $lastX $prtNode $raster $processednodes $reordermode $maxcolumns $outtype`; if ($returnvalue > $maxcolumns) $maxcolumns = $returnvalue; } } if ($lastX > $maxcolumns) $maxcolumns = $lastX; return $maxcolumns; } global proc MagmaEditor_UpdateNodeColors ( int $aNode, string $prtNode, string $bgcolor, string $colorscheme, float $color[], float $dimFactor, float $enabledFloat, float $drawOutline, float $drawTitle, string $colorOutline, string $titleColors, string $headerColors) { if ($colorOutline == "dark") //outline colors set_magma_node_instance_info -prt $prtNode -id $aNode -r 0 -g 0 -b 0 -a $drawOutline -o true; else set_magma_node_instance_info -prt $prtNode -id $aNode -r ((int)($color[0]*$dimFactor)) -g ((int)($color[1]*$dimFactor)) -b ((int)($color[2]*$dimFactor)) -a ((int)($drawOutline*$dimFactor)) -o true; //*$enabledFloat if ($titleColors == "dark") set_magma_node_instance_info -prt $prtNode -id $aNode -r 0 -g 0 -b 0 -a $drawTitle -t true; // Set the title text color else set_magma_node_instance_info -prt $prtNode -id $aNode -r ((int)($color[0]*$dimFactor)) -g ((int)($color[1]*$dimFactor)) -b ((int)($color[2]*$dimFactor)) -a ((int)($drawTitle*$dimFactor*$enabledFloat)) -t true; // title text color if ($headerColors == "dark") set_magma_node_instance_info -prt $prtNode -id $aNode -r ((int)(40*$dimFactor)) -g ((int)(40*$dimFactor)) -b ((int)(40*$dimFactor)) -a ((int)(220*$dimFactor)) -h true; // header color //*$enabledFloat else set_magma_node_instance_info -prt $prtNode -id $aNode -r ((int)($color[0]*0.75*$dimFactor)) -g ((int)($color[1]*0.75*$dimFactor)) -b ((int)($color[2]*0.75*$dimFactor)) -a ((int)(220*$enabledFloat)) -h true; // Set the title bar color //*$enabledFloat if ($colorscheme== "light") set_magma_node_instance_info -prt $prtNode -id $aNode -r ((int)($color[0]*$dimFactor)) -g ((int)($color[1]*$dimFactor)) -b ((int)($color[2]*$dimFactor)) -a ((int)(200*$enabledFloat)); //node fill color else set_magma_node_instance_info -prt $prtNode -id $aNode -r ((int)(65*$dimFactor)) -g ((int)(65*$dimFactor)) -b ((int)(68*$dimFactor)) -a ((int)(200*$dimFactor*$enabledFloat)); //node fill color } global proc MagmaNodesReorderGrid (string $prtNode) { if (`checkBox -q -v ($prtNode+"_chk_enableUpdatesAndReoderCalls")`) { //print "//MagmaNodesReorderGrid called\n"; string $bgcolor = "light"; if (`menuItem -q-cb ($prtNode+"_mnu_useDarkBackgroundColor")`) $bgcolor = "dark"; string $colorscheme = "light"; if (`menuItem -q-cb ($prtNode+"_mnu_useDarkNodeBackgroundColors")`) $colorscheme = "dark"; string $colorOutline = "light"; if (`menuItem -q -cb ($prtNode+"_mnu_useDarkNodeOutlineColors")`) $colorOutline = "dark"; string $titleColors = "light"; if (`menuItem -q -cb ($prtNode+"_mnu_useDarkNodeTitleColors")`) $titleColors = "dark"; string $headerColors = "light"; if (`menuItem -q -cb ($prtNode+"_mnu_useDarkNodeHeaderColors")`) $headerColors = "dark"; int $drawOutline = 100; if (`menuItem -q-cb ($prtNode+"_mnu_drawHighContrastNodeOutlines")`) $drawOutline = 255; int $drawTitle = 150; if (`menuItem -q -cb ($prtNode+"_mnu_drawHighContrastNodeTitles")`) $drawTitle = 255; int $maxColumns = 0; int $snapsize = 20; int $reordermode = `optionMenu -q -select ($prtNode+"_ddl_MagmaAutoReorderControl")`; int $allNodes[] = `retrieve_magma_node_ids -prt $prtNode`; int $processednodes[]; int $raster[]; //for ($aNode in $allNodes) $processednodes[$aNode] = 0; //for ($i=0; $i < `size $allNodes`; $i++) $raster[$i] = 0; for ($aNode in $allNodes) { string $type = `retrieve_magma_node_instance_info -id $aNode -prt $prtNode -type true`; if ($processednodes[$aNode] == 0 && $type == "Output") // if unprocessed output node, { int $maxRaster = 0; if ($reordermode != 4) //not compact modes { for ($i=0; $i < `size $allNodes`; $i++) { if ($raster[$i] > $maxRaster) $maxRaster =$raster[$i]; } $maxRaster -= 1; for ($i=0; $i < `size $allNodes`; $i++) { if ($raster[$i] < $maxRaster) $raster[$i] = $maxRaster; } } string $channelType = eval ("getAttr "+$prtNode + "." + $type +"_"+ $aNode +"_Property2_channelType_MagmaDataType;"); //print ("$channelType ="+$channelType +"\n"); int $outtype = 0; if ($channelType== "Float") $outtype = 2; if ($channelType== "Vec3") $outtype = 4; int $returnvalue = `MagmaSetNodePositionRecursive $aNode 0 $prtNode $raster $processednodes $reordermode $maxColumns $outtype`; if ($returnvalue > $maxColumns ) $maxColumns = $returnvalue; $processednodes[$aNode] = 1; } } float $dimmer = 0.8; int $unconnectedplacement = `menuItem -q -cb ($prtNode+"_mnu_unconnectedNodesAtBottom")`; if ($unconnectedplacement == 1) // unconnected bottom { int $maxRaster = 0; int $maxY = 0; for ($i=0; $i < `size $allNodes`; $i++) if ($raster[$i] > $maxRaster) $maxRaster =$raster[$i]; if ($maxColumns < 4) $maxColumns = 4; int $posX = 500; int $posY = ($maxRaster*$snapsize); int $cnt = 0; for ($nodeIndex=((`size $allNodes`)-1); $nodeIndex > -1; $nodeIndex = $nodeIndex-1) { int $aNode = $allNodes[$nodeIndex]; string $type = `retrieve_magma_node_instance_info -id $aNode -prt $prtNode -type true`; int $newValue = eval ("getAttr "+$prtNode + "." + $type +"_"+ $aNode +"_Property0_enabled_Bool;"); float $enabledFloat = 1.0; if ($newValue==0) $enabledFloat = 0.4; float $color[] = `MagmaGetOperatorColor $aNode $prtNode`; float $dimFactor = 1.0; if ($processednodes[$aNode] == 0) // unprocessed means unconnected! { $dimFactor = $dimmer; if ($reordermode > 1) { set_magma_node_instance_info -id $aNode -prt $prtNode -x $posX -y $posY; int $nodeheight = `MagmaEditor_GetNodeHeight $prtNode $aNode`; if ($nodeheight > $maxY) $maxY = $nodeheight; $posX = $posX - 200; $cnt++; if ($cnt == $maxColumns) { $cnt = 0; $posY = $posY+$maxY; $maxY = 0; $posX = 500; } } } MagmaEditor_UpdateNodeColors $aNode $prtNode $bgcolor $colorscheme $color $dimFactor $enabledFloat $drawOutline $drawTitle $colorOutline $titleColors $headerColors; } } else // unconnected left { int $maxRaster = 500; for ($aNode in $allNodes) { if ($processednodes[$aNode] == 1) { int $sourcepoint[] = `retrieve_magma_node_instance_info -id $aNode -prt $prtNode -xy true`; if ($sourcepoint[0] < $maxRaster) $maxRaster = $sourcepoint[0]; } } $maxRaster -= 200; int $posX = $maxRaster; int $posY = 0; int $cnt = 0; for ($aNode in $allNodes) { string $type = `retrieve_magma_node_instance_info -id $aNode -prt $prtNode -type true`; int $newValue = eval ("getAttr "+$prtNode + "." + $type +"_"+ $aNode +"_Property0_enabled_Bool;"); float $enabledFloat = 1.0; if ($newValue==0) $enabledFloat = 0.4; float $color[] = `MagmaGetOperatorColor $aNode $prtNode`; float $dimFactor = 1.0; if ($processednodes[$aNode] == 0) { $dimFactor = $dimmer; if ($reordermode > 1) { set_magma_node_instance_info -id $aNode -prt $prtNode -x $posX -y $posY; int $nodeheight = `MagmaEditor_GetNodeHeight $prtNode $aNode`; $posY += $nodeheight; $cnt++; if ($cnt == 6 ) { $cnt = 0; $posX = $posX-200; $posY = 0; } } } MagmaEditor_UpdateNodeColors $aNode $prtNode $bgcolor $colorscheme $color $dimFactor $enabledFloat $drawOutline $drawTitle $colorOutline $titleColors $headerColors; } } //print "//MagmaNodesReorderGrid ended\n"; } } global proc int MagmaSetNodePositionRecursive (int $parentNode, int $lastX, string $prtNode, int $raster[], int $processednodes[], int $reordermode, int $maxcolumns, int $outtype ) { int $nodeheight = `MagmaEditor_GetNodeHeight $prtNode $parentNode`; float $snapsize = 20; int $posX = 500 - $lastX*200; int $posY = ($raster[$lastX]*$snapsize); if ($processednodes[$parentNode] == 0 ) //if not processed or not first pass modes || ($reordermode != 2 && $reordermode != 4 && $reordermode != 6) { if ($reordermode == 2 ) // branch mode || $reordermode == 3 { if ($raster[$lastX]> $raster[$lastX+1]) { $raster[$lastX+1] = $raster[$lastX]; } } $raster[$lastX] = $raster[$lastX] + (int)(($nodeheight/$snapsize)); //print ("$raster[$lastX]="+$raster[$lastX]+"\n"); if ($reordermode > 1) // if not manual mode, move the node to new position { //print ("ID:"+$parentNode +" PosX: "+$posX +" PosY: "+ $posY+"\n"); set_magma_node_instance_info -id $parentNode -prt $prtNode -x $posX -y $posY; } $processednodes[$parentNode] = 1; } $lastX++; int $connection[] = `get_magma_connections -prt $prtNode -id $parentNode`; for ($i = 0; $i < `size $connection`; $i=$i+2) { if ($connection[$i] > -1 && $processednodes[$connection[$i]] == 0) //if connected and the connection is unprocessed { //MagmaSwitchInputSocketDefaults $connection[$i] $prtNode $outtype; int $returnvalue = `MagmaSetNodePositionRecursive $connection[$i] $lastX $prtNode $raster $processednodes $reordermode $maxcolumns $outtype`; if ($returnvalue > $maxcolumns) $maxcolumns = $returnvalue; } } if ($lastX > $maxcolumns) $maxcolumns = $lastX; return $maxcolumns; } global proc MagmaSetOperatorDefaultTypesRecursive (int $aNode, int $newNode, string $prtNode, int $processednodes[], int $outtype) { if ($aNode == $newNode) { MagmaSwitchInputSocketDefaults $newNode $prtNode $outtype; } else { int $connection[] = `get_magma_connections -prt $prtNode -id $aNode`; for ($i = 0; $i < `size $connection`; $i=$i+2) { if ($connection[$i] > -1 && $processednodes[$connection[$i]] == 0) //if connected and the connection is unprocessed { $processednodes[$connection[$i]] = 1; MagmaSetOperatorDefaultTypesRecursive $connection[$i] $newNode $prtNode $processednodes $outtype; } } } } global proc MagmaEditor_SetOperatorDefaultTypesByOutputConnection (int $newNode, string $prtNode ) { int $allNodes[] = `retrieve_magma_node_ids -prt $prtNode`; int $processednodes[]; for ($aNode in $allNodes) { string $type = `retrieve_magma_node_instance_info -id $aNode -prt $prtNode -type true`; if ($processednodes[$aNode] == 0 && $type == "Output") // if unprocessed output node, { string $channelType = eval ("getAttr "+$prtNode + "." + $type +"_"+ $aNode +"_Property2_channelType_MagmaDataType;"); int $outtype = 0; if ($channelType== "Float") $outtype = 2; if ($channelType== "Vec3") $outtype = 4; MagmaSetOperatorDefaultTypesRecursive $aNode $newNode $prtNode $processednodes $outtype; $processednodes[$aNode] = 1; } } } global proc SetMagmaNodeAttributeValue ( string $prtNode, string $nodeName, string $attr, string $attrType, string $value ) { string $command = "setAttr \""+$prtNode + "." + $nodeName + "_" + $attr; if ($attrType == "String" ) $command = $command + "_" + $attrType + "\" -type \"string\" \"" + $value + "\";"; if ($attrType == "MagmaDataType") $command = $command + "_" + $attrType + "\" -type \"string\" \""+ $value + "\";"; if ($attrType == "Int" || $attrType == "Float") $command = $command + "_" + $attrType + "\" " + $value + ";"; if ($attrType == "Vector3f") $command = $command + "_Vector3f\" -type float3 " + $value+ ";"; /*print ($command); print ("\n"); */ eval ($command); } global proc int[] GetOutputConnections ( string $prtNode, int $currentNode, int $socket ) { int $connectedNodes[] = `get_magma_connections -prt $prtNode -i $currentNode -ss $socket`; /* int $allNodes[] = `retrieve_magma_node_ids -prt $prtNode`; int $connectedNodes[] = {}; for ($aNode in $allNodes) { int $connection[] = `get_magma_connections -prt $prtNode -id $aNode`; for ($i = 0; $i < `size $connection`; $i=$i+2) { if ($connection[$i] == $currentNode && $connection[$i+1] == $socket) { $connectedNodes[`size $connectedNodes`] = $aNode; $connectedNodes[`size $connectedNodes`] = ($i/2); } } }*/ return $connectedNodes; } global proc int[] GetOutputConnectionsMap (string $prtNode) { int $allNodes[] = `retrieve_magma_node_ids -prt $prtNode`; int $connectedNodes[] = {}; for ($aNode in $allNodes) { int $connection[] = `get_magma_connections -prt $prtNode -id $aNode`; for ($i = 0; $i < `size $connection`; $i=$i+2) { if ($connection[$i] != -1) { $connectedNodes[$connection[$i]*20+$connection[$i+1]] = 1; } } } return $connectedNodes; } global proc MagmaEditor_UpdateColorScheme ( string $prtNode, int $save ) { //print ("MagmaEditor_UpdateColorScheme called\n"); MagmaEditor_SetupEditorBackground $prtNode; MagmaNodesReorderGrid $prtNode ; MagmaEditor_RepaintSockets $prtNode 0; MagmaEditor_SetWireColors $prtNode ; if ($save) MagmaEditor_SaveColorScheme $prtNode ""; } global proc MagmaEditor_ToggleSnapToGrid ( string $prtNode ) { int $snap = `menuItem -q -cb ($prtNode+"_mnu_toggleSnapToGrid")`; magma_flux_window_set -prt $prtNode -s $snap; int $grid = `menuItem -q -cb ($prtNode+"_mnu_toggleShowGrid")`; magma_flux_window_set -prt $prtNode -g $grid; } global proc MagmaEditor_SetupEditorBackground ( string $prtNode ) { string $colorscheme = "light"; if (`menuItem -q-cb ($prtNode+"_mnu_useDarkBackgroundColor")`) $colorscheme = "dark"; if ($colorscheme == "light") { /* magma_flux_window_set -prt $prtNode -bgr 192 -bgg 192 -bgb 192; magma_flux_window_set -prt $prtNode -gr 160 -gg 160 -gb 160; */ magma_flux_window_set -prt $prtNode -bgr 140 -bgg 140 -bgb 140; magma_flux_window_set -prt $prtNode -gr 120 -gg 120 -gb 120; } else { magma_flux_window_set -prt $prtNode -bgr 45 -bgg 45 -bgb 45; magma_flux_window_set -prt $prtNode -gr 60 -gg 60 -gb 60; } magma_flux_window_set -prt $prtNode -g on; // show/hide grid (true to show) magma_flux_window_set -prt $prtNode -gs 20; // grid size magma_flux_window_set -prt $prtNode -s on; // snap on/off to grid (true to snap) } // SOCKET COLORS global proc MagmaEditor_SetSocketColors ( int $aNode, string $prtNode, int $connectionsMap[] ) { string $bgcolor = "light"; if (`menuItem -q-cb ($prtNode+"_mnu_useDarkBackgroundColor")`) $bgcolor = "dark"; string $colorscheme = "light"; if (`menuItem -q-cb ($prtNode+"_mnu_useDarkNodeBackgroundColors")`) $colorscheme = "dark"; string $socketcolors = "gray"; if (`menuItem -q-cb ($prtNode+"_mnu_useSaturatedSocketColors")`) $socketcolors = "color"; string $socketoutlines = "light"; if (`menuItem -q-cb ($prtNode+"_mnu_useDarkSocketOutlineColors")`) $socketoutlines = "dark"; string $type = `retrieve_magma_node_instance_info -id $aNode -prt $prtNode -type true`; string $insockets[] = `retrieve_magma_node_instance_info -id $aNode -prt $prtNode -is true`; int $insocketsCount = `size $insockets`; string $outsockets[] = `retrieve_magma_node_instance_info -id $aNode -prt $prtNode -os true`; int $outsocketsCount = `size $outsockets`; /* if ($type == "ParticleSumCount" || $type == "ParticleSumRadius" || $type == "ParticleQuery") { $customOutputChannels = eval ("getAttr "+$prtNode + "." + $type +"_"+ $aNode +"_Property1_channels_StringList;"); $outsocketsCount += `size $customOutputChannels`; } */ int $connection[] = `get_magma_connections -prt $prtNode -id $aNode`; int $newValue = eval ("getAttr "+$prtNode + "." + $type +"_"+ $aNode +"_Property0_enabled_Bool;"); float $enabledFloat = 1.0; if ($newValue==0) $enabledFloat = 0.5; //Collect info about socket defaults int $socketState[]; string $category = MagmaGetNodeCategoryFromType($type); if( $category != "Input" ) // if not an input node, it has input sockets { string $inInfoBuffer[] = $insockets; for( $currentInfo in $inInfoBuffer ) { string $attr; string $currentInfoBuffer[] = `MagmaFLUX_PropertyTokenizer $currentInfo`; string $socketNameBuffer[]; tokenize $currentInfoBuffer[0] "#:" $socketNameBuffer; string $socketNumber = $socketNameBuffer[1]; //string $socketName = $socketNameBuffer[2]; string $attributeTypes = $currentInfoBuffer[2]; $socketState[(int)$socketNumber] = 0; // Check if there are any options for the socket string $attributeTypesBuffer[]; tokenize $attributeTypes " " $attributeTypesBuffer; if( `size $attributeTypesBuffer` <= 0 ) continue; if( `size $attributeTypesBuffer` == 1 && `size $attributeTypesBuffer[0]` <= 0) continue; $socketState[(int)$socketNumber] = 1; } } for ($i = 0; $i < `size $connection`; $i=$i+2) { if ($connection[$i+1] == -1) //unconnected input socket { if ($socketState[$i/2] == 1) // if the socket has a default, draw it in green { if ($bgcolor=="light") { if ($socketcolors == "gray") set_magma_node_instance_info -prt $prtNode -id $aNode -r (170*$enabledFloat) -g (220*$enabledFloat) -b (200*$enabledFloat) -a 255 -si ($i/2) -st 0 ; else set_magma_node_instance_info -prt $prtNode -id $aNode -r (120*$enabledFloat) -g (230*$enabledFloat) -b (190*$enabledFloat) -a 255 -si ($i/2) -st 0 ; } else { if ($socketcolors == "gray") set_magma_node_instance_info -prt $prtNode -id $aNode -r (140*$enabledFloat) -g (180*$enabledFloat) -b (160*$enabledFloat) -a 255 -si ($i/2) -st 0 ; else set_magma_node_instance_info -prt $prtNode -id $aNode -r (120*$enabledFloat) -g (200*$enabledFloat) -b (150*$enabledFloat) -a 255 -si ($i/2) -st 0 ; } //text and outline if ($colorscheme== "light") { set_magma_node_instance_info -prt $prtNode -id $aNode -r 0 -g 50 -b 0 -a 200 -si ($i/2) -st 0 -t true; if ($socketoutlines == "light") set_magma_node_instance_info -prt $prtNode -id $aNode -r 100 -g 150 -b 100 -a 255 -si ($i/2) -st 0 -o true; else set_magma_node_instance_info -prt $prtNode -id $aNode -r 0 -g 50 -b 0 -a 255 -si ($i/2) -st 0 -o true; } else { set_magma_node_instance_info -prt $prtNode -id $aNode -r 200 -g 255 -b 200 -a 200 -si ($i/2) -st 0 -t true; if ($socketoutlines == "light") set_magma_node_instance_info -prt $prtNode -id $aNode -r 80 -g 160 -b 80 -a 255 -si ($i/2) -st 0 -o true; else set_magma_node_instance_info -prt $prtNode -id $aNode -r 40 -g 80 -b 40 -a 255 -si ($i/2) -st 0 -o true; } } else // if unconnected without a default, draw it in red { if ($bgcolor=="light") { if ($socketcolors == "gray") set_magma_node_instance_info -prt $prtNode -id $aNode -r 180 -g 150 -b 150 -a 255 -si ($i/2) -st 0 ; else set_magma_node_instance_info -prt $prtNode -id $aNode -r 200 -g 120 -b 120 -a 255 -si ($i/2) -st 0 ; } else { if ($socketcolors == "gray") set_magma_node_instance_info -prt $prtNode -id $aNode -r 140 -g 120 -b 120 -a 255 -si ($i/2) -st 0 ; else set_magma_node_instance_info -prt $prtNode -id $aNode -r 180 -g 100 -b 100 -a 255 -si ($i/2) -st 0 ; } if ($colorscheme== "light") { set_magma_node_instance_info -prt $prtNode -id $aNode -r 50 -g 0 -b 0 -a 200 -si ($i/2) -st 0 -t true; if ($socketoutlines == "light") set_magma_node_instance_info -prt $prtNode -id $aNode -r 255 -g 80 -b 80 -a 255 -si ($i/2) -st 0 -o true; else set_magma_node_instance_info -prt $prtNode -id $aNode -r 255 -g 0 -b 0 -a 255 -si ($i/2) -st 0 -o true; } else { set_magma_node_instance_info -prt $prtNode -id $aNode -r 230 -g 200 -b 200 -a 200 -si ($i/2) -st 0 -t true; if ($socketoutlines == "light") set_magma_node_instance_info -prt $prtNode -id $aNode -r 255 -g 80 -b 80 -a 255 -si ($i/2) -st 0 -o true; else set_magma_node_instance_info -prt $prtNode -id $aNode -r 255 -g 0 -b 0 -a 255 -si ($i/2) -st 0 -o true; } } } else //if connected, draw it in blue { if ($bgcolor=="light") { if ($i == 0) { if ($socketcolors == "gray") set_magma_node_instance_info -prt $prtNode -id $aNode -r 170 -g 200 -b 210 -a 255 -si ($i/2) -st 0 ; else set_magma_node_instance_info -prt $prtNode -id $aNode -r 140 -g 200 -b 220 -a 255 -si ($i/2) -st 0 ; } else { if ($socketcolors == "gray") set_magma_node_instance_info -prt $prtNode -id $aNode -r (170*$enabledFloat) -g (200*$enabledFloat) -b (210*$enabledFloat) -a 255 -si ($i/2) -st 0 ; else set_magma_node_instance_info -prt $prtNode -id $aNode -r (140*$enabledFloat) -g (200*$enabledFloat) -b (220*$enabledFloat) -a 255 -si ($i/2) -st 0 ; } } else // dark { if ($i == 0) { if ($socketcolors == "gray") set_magma_node_instance_info -prt $prtNode -id $aNode -r 140 -g 150 -b 170 -a 255 -si ($i/2) -st 0 ; else set_magma_node_instance_info -prt $prtNode -id $aNode -r 120 -g 150 -b 200 -a 255 -si ($i/2) -st 0 ; } else { if ($socketcolors == "gray") set_magma_node_instance_info -prt $prtNode -id $aNode -r (140*$enabledFloat) -g (150*$enabledFloat) -b (170*$enabledFloat) -a 255 -si ($i/2) -st 0 ; else set_magma_node_instance_info -prt $prtNode -id $aNode -r (120*$enabledFloat) -g (150*$enabledFloat) -b (200*$enabledFloat) -a 255 -si ($i/2) -st 0 ; } } if ($colorscheme== "light") { set_magma_node_instance_info -prt $prtNode -id $aNode -r 0 -g 0 -b 50 -a 200 -si ($i/2) -st 0 -t true; if ($socketoutlines == "light") set_magma_node_instance_info -prt $prtNode -id $aNode -r 100 -g 100 -b 150 -a 255 -si ($i/2) -st 0 -o true; else set_magma_node_instance_info -prt $prtNode -id $aNode -r 0 -g 0 -b 50 -a 255 -si ($i/2) -st 0 -o true; } else { set_magma_node_instance_info -prt $prtNode -id $aNode -r 200 -g 200 -b 230 -a 225 -si ($i/2) -st 0 -t true; if ($socketoutlines == "light") set_magma_node_instance_info -prt $prtNode -id $aNode -r 80 -g 80 -b 160 -a 255 -si ($i/2) -st 0 -o true; else set_magma_node_instance_info -prt $prtNode -id $aNode -r 40 -g 40 -b 80 -a 255 -si ($i/2) -st 0 -o true; } } } //OUTPUT SOCKETS for ($i = 0; $i < $outsocketsCount; $i++) { if ($connectionsMap[$aNode*20+$i] > 0) // connected { if ($bgcolor=="light") { if ($i == 0) // first socket { if ($socketcolors == "gray") set_magma_node_instance_info -prt $prtNode -id $aNode -r 170 -g 200 -b 210 -a 255 -si $i -st 1 ; else set_magma_node_instance_info -prt $prtNode -id $aNode -r 140 -g 200 -b 220 -a 255 -si $i -st 1 ; } else { if ($socketcolors == "gray") set_magma_node_instance_info -prt $prtNode -id $aNode -r (170*$enabledFloat) -g (200*$enabledFloat) -b (210*$enabledFloat) -a 255 -si $i -st 1 ; else set_magma_node_instance_info -prt $prtNode -id $aNode -r (140*$enabledFloat) -g (200*$enabledFloat) -b (220*$enabledFloat) -a 255 -si $i -st 1 ; } } else { if ($i == 0) // first socket { if ($socketcolors == "gray") set_magma_node_instance_info -prt $prtNode -id $aNode -r 140 -g 150 -b 170 -a 255 -si $i -st 1 ; else set_magma_node_instance_info -prt $prtNode -id $aNode -r 120 -g 150 -b 200 -a 255 -si $i -st 1 ; } else { if ($socketcolors == "gray") set_magma_node_instance_info -prt $prtNode -id $aNode -r (140*$enabledFloat) -g (150*$enabledFloat) -b (170*$enabledFloat) -a 255 -si $i -st 1 ; else set_magma_node_instance_info -prt $prtNode -id $aNode -r (120*$enabledFloat) -g (150*$enabledFloat) -b (200*$enabledFloat) -a 255 -si $i -st 1 ; } } if ($colorscheme== "light") { set_magma_node_instance_info -prt $prtNode -id $aNode -r 0 -g 0 -b 50 -a 200 -si $i -st 1 -t true; if ($socketoutlines == "light") set_magma_node_instance_info -prt $prtNode -id $aNode -r 100 -g 100 -b 150 -a 255 -si $i -st 1 -o true; else set_magma_node_instance_info -prt $prtNode -id $aNode -r 0 -g 0 -b 50 -a 255 -si $i -st 1 -o true; } else { set_magma_node_instance_info -prt $prtNode -id $aNode -r 200 -g 200 -b 230 -a 225 -si $i -st 1 -t true; if ($socketoutlines == "light") set_magma_node_instance_info -prt $prtNode -id $aNode -r 80 -g 80 -b 160 -a 255 -si $i -st 1 -o true; else set_magma_node_instance_info -prt $prtNode -id $aNode -r 40 -g 40 -b 80 -a 255 -si $i -st 1 -o true; } } else // not connected, draw in green { if ($bgcolor=="light") { if ($i == 0) { if ($socketcolors == "gray") set_magma_node_instance_info -prt $prtNode -id $aNode -r 170 -g 220 -b 200 -a 255 -si $i -st 1 ; else set_magma_node_instance_info -prt $prtNode -id $aNode -r 120 -g 230 -b 190 -a 255 -si $i -st 1 ; } else { if ($socketcolors == "gray") set_magma_node_instance_info -prt $prtNode -id $aNode -r (170*$enabledFloat) -g (220*$enabledFloat) -b (200*$enabledFloat) -a 255 -si $i -st 1 ; else set_magma_node_instance_info -prt $prtNode -id $aNode -r (120*$enabledFloat) -g (230*$enabledFloat) -b (190*$enabledFloat) -a 255 -si $i -st 1 ; } } else { if ($i == 0) { if ($socketcolors == "gray") set_magma_node_instance_info -prt $prtNode -id $aNode -r 140 -g 180 -b 160 -a 255 -si $i -st 1 ; else set_magma_node_instance_info -prt $prtNode -id $aNode -r 120 -g 200 -b 150 -a 255 -si $i -st 1 ; } else { if ($socketcolors == "gray") set_magma_node_instance_info -prt $prtNode -id $aNode -r (140*$enabledFloat) -g (180*$enabledFloat) -b (156*$enabledFloat) -a 255 -si $i -st 1 ; else set_magma_node_instance_info -prt $prtNode -id $aNode -r (120*$enabledFloat) -g (200*$enabledFloat) -b (150*$enabledFloat) -a 255 -si $i -st 1 ; } } if ($colorscheme== "light") { set_magma_node_instance_info -prt $prtNode -id $aNode -r 0 -g 50 -b 0 -a 200 -si $i -st 1 -t true; if ($socketoutlines == "light") set_magma_node_instance_info -prt $prtNode -id $aNode -r 100 -g 150 -b 100 -a 255 -si $i -st 1 -o true; else set_magma_node_instance_info -prt $prtNode -id $aNode -r 0 -g 50 -b 0 -a 255 -si $i -st 1 -o true; } else { set_magma_node_instance_info -prt $prtNode -id $aNode -r 200 -g 230 -b 200 -a 225 -si $i -st 1 -t true; if ($socketoutlines == "light") set_magma_node_instance_info -prt $prtNode -id $aNode -r 140 -g 180 -b 140 -a 255 -si $i -st 1 -o true; else set_magma_node_instance_info -prt $prtNode -id $aNode -r 40 -g 80 -b 40 -a 255 -si $i -st 1 -o true; } } } if ($type == "InputValue") { int $valuetype = eval ("getAttr "+$prtNode + "." + $type +"_"+ $aNode +"_Property1_enumValue_Int;"); if ($valuetype == 3) { float $red = 255*(eval ("getAttr "+$prtNode+"."+$type +"_"+$aNode+"_Property4_vec3Value_Vector3f0")); float $green = 255*(eval ("getAttr "+$prtNode+"."+$type +"_"+$aNode+"_Property4_vec3Value_Vector3f1")); float $blue = 255*(eval ("getAttr "+$prtNode+"."+$type +"_"+$aNode+"_Property4_vec3Value_Vector3f2")); set_magma_node_instance_info -prt $prtNode -id $aNode -r ((int)$red) -g ((int)$green) -b ((int)$blue) -a 255 -si 0 -st 1 ; set_magma_node_instance_info -prt $prtNode -id $aNode -r ((int)(255-$red)) -g ((int)(255-$green)) -b ((int)(255-$blue)) -a 255 -o true -si 0 -st 1 ; } } } global proc MagmaEditor_RepaintSockets ( string $prtNode, int $selectedonly ) { //print "//MagmaEditor_RepaintSockets called\n"; int $nodes[]; if ($selectedonly==1) { //print "Repaint Selection Only\n"; $nodes = `magma_flux_window_query -n true -prt $prtNode`; } else $nodes = `retrieve_magma_node_ids -prt $prtNode`; int $connectionsMap[] = `GetOutputConnectionsMap $prtNode`; for ($aNode in $nodes) { MagmaEditor_SetSocketColors $aNode $prtNode $connectionsMap; } //print "//MagmaEditor_RepaintSockets ended\n"; } global proc MagmaEditor_SetWireColors (string $prtNode) { string $bgcolor = "light"; if (`menuItem -q-cb ($prtNode+"_mnu_useDarkBackgroundColor")`) $bgcolor = "dark"; int $red = 70; int $green = 70; int $blue = 90; int $alpha = 255; if ($bgcolor == "dark") { $red = 160; $green = 160; $blue = 180; $alpha = 255; } int $edges[] = `get_magma_description -prt $prtNode -e true`; for ($i = 0; $i < `size $edges`; $i+=4) { set_magma_connection -prt $prtNode -si $edges[$i] -ss $edges[$i+1] -di $edges[$i+2] -ds $edges[$i+3] -r $red -g $green -b $blue -a $alpha; } } global proc float[] MagmaGetOperatorColor (int $node, string $prtNode ) { string $nodeType = `retrieve_magma_node_instance_info -id $node -prt $prtNode -type true`; string $infoBuffer[] = `retrieve_magma_node_info -t $nodeType -a true`; string $tokens[]; tokenize($infoBuffer[0], ",:", $tokens); string $category = $tokens[1]; float $redColor = 255; float $greenColor = 225; float $blueColor = 200; if ($category == "Convert") { $redColor = 255; $greenColor = 235; $blueColor = 200; }else if ($category == "Transform") { $redColor = 255; $greenColor = 240; $blueColor = 210; }else if ($category == "Function") { $redColor = 255; $greenColor = 235; $blueColor = 225; }else if ($category == "Logic") { $redColor = 255; $greenColor = 240; $blueColor = 200; }else if ($category == "Object") { $redColor = 255; $greenColor = 200; $blueColor = 200; }else if ($nodeType == "Output") { $redColor = 200; $greenColor = 255; $blueColor = 200; }else if ($nodeType == "InputGeometry") { $redColor = 255; $greenColor = 220; $blueColor = 220; }else if ($nodeType == "InputParticles") { $redColor = 255; $greenColor = 255; $blueColor = 200; }else if ($nodeType == "InputChannel") { $redColor = 200; $greenColor = 225; $blueColor = 255; }else if ($nodeType == "InputObject") { $redColor = 255; $greenColor = 200; $blueColor = 225; }else if ($nodeType == "InputValue") { $redColor = 200; $greenColor = 240; $blueColor = 220; int $valuetype = eval ("getAttr "+$prtNode + "." + $nodeType +"_"+ $node +"_Property1_enumValue_Int;"); if ($valuetype == 1) { $redColor = 200; $greenColor = 240; $blueColor = 220; } else if ($valuetype == 2) { $redColor = 230; $greenColor = 220; $blueColor = 240; } else if ($valuetype == 3) { $redColor = 200; $greenColor = 240; $blueColor = 255; } } return {$redColor, $greenColor, $blueColor}; } global proc MagmaAdjustInputSocketDefaults (int $newNode, string $type, string $prtNode) { //Input Socket Properties string $category = MagmaGetNodeCategoryFromType($type); if( $category != "Input" ) { string $inInfoBuffer[] = `retrieve_magma_node_info -t $type -is true`; int $socketindex = 0; int $existingConnection[] = `get_magma_connections -prt $prtNode -id $newNode`; for( $currentInfo in $inInfoBuffer ) { if ($existingConnection[$socketindex] == -1) { string $attr; string $currentInfoBuffer[] = `MagmaFLUX_PropertyTokenizer $currentInfo`; string $socketNameBuffer[]; tokenize $currentInfoBuffer[0] "#:" $socketNameBuffer; string $socketNumber = $socketNameBuffer[1]; string $socketName = $socketNameBuffer[2]; string $attributeTypes = $currentInfoBuffer[2]; // Check if there are any options for the socket string $attributeTypesBuffer[]; tokenize $attributeTypes " " $attributeTypesBuffer; if( `size $attributeTypesBuffer` <= 0 ) continue; if( `size $attributeTypesBuffer` == 1 && `size $attributeTypesBuffer[0]` <= 0) continue; string $signature = $prtNode + "." + $type + "_" + $newNode + "_" + "InputSocket" + $socketNumber; if ($type == "Multiply" || $type == "Divide" || $type == "Modulo") { eval ("setAttr "+$signature + "_float 1.0;"); eval ("setAttr "+$signature + "_int 1;"); eval ("setAttr "+$signature + "_vector3f0 1;"); eval ("setAttr "+$signature + "_vector3f1 1;"); eval ("setAttr "+$signature + "_vector3f2 1;"); } if ($type == "Power" ) { eval ("setAttr "+$signature + "_float 2.0;"); eval ("setAttr "+$signature + "_int 2;"); } if ($type == "Clamp" && $socketNumber == 2) { eval ("setAttr "+$signature + "_float 1.0;"); eval ("setAttr "+$signature + "_int 1;"); } if ($type == "Blend" && $socketNumber == 1) { eval ("setAttr "+$signature + "_float 1.0;"); eval ("setAttr "+$signature + "_vector3f0 1;"); eval ("setAttr "+$signature + "_vector3f1 1;"); eval ("setAttr "+$signature + "_vector3f2 1;"); } if ($type == "Subtract" && $socketNumber == 0) { eval ("setAttr "+$signature + "_float 1.0;"); eval ("setAttr "+$signature + "_vector3f0 1;"); eval ("setAttr "+$signature + "_vector3f1 1;"); eval ("setAttr "+$signature + "_vector3f2 1;"); } if ($type == "AngleAxisToQuat" && $socketNumber == 1) { eval ("setAttr "+$signature + "_vector3f0 0;"); eval ("setAttr "+$signature + "_vector3f1 1;"); eval ("setAttr "+$signature + "_vector3f2 0;"); } if ($type == "VectorsToQuat") { if ($socketNumber == 0) { eval ("setAttr "+$signature + "_vector3f0 1;"); eval ("setAttr "+$signature + "_vector3f1 0;"); eval ("setAttr "+$signature + "_vector3f2 0;"); } if ($socketNumber == 1) { eval ("setAttr "+$signature + "_vector3f0 0;"); eval ("setAttr "+$signature + "_vector3f1 1;"); eval ("setAttr "+$signature + "_vector3f2 0;"); } if ($socketNumber == 2) { eval ("setAttr "+$signature + "_vector3f0 0;"); eval ("setAttr "+$signature + "_vector3f1 0;"); eval ("setAttr "+$signature + "_vector3f2 1;"); } } if ($type == "UniformRandom" || $type == "VecUniformRandom") { if ($socketNumber == 1) { eval ("setAttr "+$signature + "_float 0.0;"); } if ($socketNumber == 2) { eval ("setAttr "+$signature + "_float 1.0;"); } } if ($type == "ExponentialRandom") { if ($socketNumber == 1) { eval ("setAttr "+$signature + "_float 1.0;"); } } if ($type == "WeibullRandom") { if ($socketNumber == 1) { eval ("setAttr "+$signature + "_float 1.0;"); } if ($socketNumber == 2) { eval ("setAttr "+$signature + "_float 1.0;"); } } if ($type == "GaussianRandom") { if ($socketNumber == 1) { eval ("setAttr "+$signature + "_float 0.0;"); } if ($socketNumber == 2) { eval ("setAttr "+$signature + "_float 1.0;"); } } if ($type == "TriangleRandom") { if ($socketNumber == 1) { eval ("setAttr "+$signature + "_float 0.0;"); } if ($socketNumber == 2) { eval ("setAttr "+$signature + "_float 0.5;"); } if ($socketNumber == 3) { eval ("setAttr "+$signature + "_float 1.0;"); } } if ($type == "UniformOnSphere") { if ($socketNumber == 1) { eval ("setAttr "+$signature + "_int 2;"); } } if ($type == "Noise" || $type == "VecNoise") { if ($socketNumber == 1) { eval ("setAttr "+$signature + "_float 0.0;"); } } if ($type == "NearestPoint") { if ($socketNumber == 2) { eval ("setAttr "+$signature + "_int 0;"); } } if ($type == "IntersectRay") { if ($socketNumber == 3) { eval ("setAttr "+$signature + "_int 0;"); } } } $socketindex += 2; } } } global proc AddNewMagmaOperatorToFlow ( string $type, string $prtNode, int $x, int $y, int $redraw, int $undorecord ) { int $enableupdates = `checkBox -q -v ($prtNode+"_chk_enableUpdatesAndReoderCalls")`; //remember whether updates were on checkBox -e -v false ($prtNode+"_chk_enableUpdatesAndReoderCalls"); int $selnodes[] = `magma_flux_window_query -n true -prt $prtNode`; int $position[] = `magma_flux_window_query -lxy true -prt $prtNode `; int $XOffset = 200; int $isOutput = 0; if (`size $selnodes` == 1) { string $type = `retrieve_magma_node_instance_info -id $selnodes[0] -prt $prtNode -type true`; if ($type == "Output") { $XOffset = -200; $isOutput = 1; } } /*int $newpointX = ($position[0] + $XOffset); int $newpointY = $position[1];*/ if ($x == 0 && $y == 0) { $x = $position[0]+$XOffset; $y = $position[1]; } else { //$x = $x-50;+ $y = $y-40; } int $newNode = `create_magma_node -t $type -x ($y) -y ($y) -prt $prtNode`; /* float $color[] = `MagmaGetOperatorColor $newNode $prtNode`; set_magma_node_instance_info -id $newNode -r $color[0] -g $color[1] -b $color[2] -a 180 -prt $prtNode; set_magma_node_instance_info -id $newNode -r $color[0] -g $color[1] -b $color[2] -a 235 -h true -prt $prtNode; */ int $connectionsMap[] = `GetOutputConnectionsMap $prtNode`; MagmaEditor_SetSocketColors $newNode $prtNode $connectionsMap; // set default values for some attributes if ($type == "Noise" || $type == "VecNoise") { eval ("setAttr "+$prtNode + "." + $type +"_"+ $newNode +"_Property1_numOctaves_Int 4;"); eval ("setAttr "+$prtNode + "." + $type +"_"+ $newNode +"_Property2_lacunarity_Float 0.5;"); } if ($type == "ParticleSumCount") { eval ("setAttr "+$prtNode + "." + $type +"_"+ $newNode +"_InputSocket2_int 2;"); eval ("setAttr "+$prtNode + "." + $type +"_"+ $newNode +"_InputSocket3_float 0.0;"); } if ($type == "ParticleSumRadius") { eval ("setAttr "+$prtNode + "." + $type +"_"+ $newNode +"_InputSocket2_float 0.1;"); eval ("setAttr "+$prtNode + "." + $type +"_"+ $newNode +"_InputSocket3_float 1.0;"); } if ($type == "FaceQuery") { float $onethird = 1.0/3.0; string $onethirdvec = $onethird + " " + $onethird + " " + $onethird; eval("setAttr "+$prtNode + "." + $type +"_"+ $newNode +"_InputSocket3_vector3f " + $onethirdvec); } if ($type == "PropertyQuery") { string $nodeattr = ($prtNode + "." + $type +"_"+ $newNode +"_Property1_properties_StringList"); string $code = ( "string $nodeattr = \"" + $nodeattr + "\";\n" + "string $pqItems[]; \n" + "$pqItems[0] = \"translate\";\n" + "string $setAttrArgs = `MagmaFLUX_ListToStringSetAttr $pqItems`;\n" + "eval(\"setAttr $nodeattr -type \\\"stringArray\\\" \" + $setAttrArgs + \"\");\n" ); eval ($code); } if ($type == "NearestPoint") { eval ("setAttr "+$prtNode + "." + $type +"_"+ $newNode + "_InputSocket2_int 0" ); } if ($type == "IntersectRay") { eval ("setAttr "+$prtNode + "." + $type +"_"+ $newNode + "_InputSocket3_int 0" ); } if ($type == "UniformRandom" || $type == "VecUniformRandom") { eval ("setAttr "+$prtNode + "." + $type +"_"+ $newNode + "_InputSocket1_float 0.0" ); eval ("setAttr "+$prtNode + "." + $type +"_"+ $newNode + "_InputSocket2_float 1.0" ); } if ($type == "ExponentialRandom") { eval ("setAttr "+$prtNode + "." + $type +"_"+ $newNode + "_InputSocket1_float 1.0" ); } if ($type == "WeibullRandom") { eval ("setAttr "+$prtNode + "." + $type +"_"+ $newNode + "_InputSocket1_float 1.0" ); eval ("setAttr "+$prtNode + "." + $type +"_"+ $newNode + "_InputSocket2_float 1.0" ); } if ($type == "GaussianRandom") { eval ("setAttr "+$prtNode + "." + $type +"_"+ $newNode + "_InputSocket1_float 0.0" ); eval ("setAttr "+$prtNode + "." + $type +"_"+ $newNode + "_InputSocket2_float 1.0" ); } if ($type == "TriangleRandom") { eval ("setAttr "+$prtNode + "." + $type +"_"+ $newNode + "_InputSocket1_float 0.0" ); eval ("setAttr "+$prtNode + "." + $type +"_"+ $newNode + "_InputSocket2_float 0.5" ); eval ("setAttr "+$prtNode + "." + $type +"_"+ $newNode + "_InputSocket3_float 1.0" ); } if ($type == "UniformOnSphere") { eval ("setAttr "+$prtNode + "." + $type +"_"+ $newNode + "_InputSocket1_int 2" ); } if ($type == "Noise" || $type == "VecNoise") { eval ("setAttr "+$prtNode + "." + $type +"_"+ $newNode + "_InputSocket1_float 0.0" ); } // set default values for some inputs MagmaAdjustInputSocketDefaults $newNode $type $prtNode ; string $insertbranch = `optionMenu -q -v ($prtNode+"_ddl_MagmaInsertBranchControl")`; string $edges[] = `magma_flux_window_query -e true -prt $prtNode`; if (`size $edges` == 1) { string $edgesTokens[]; tokenize($edges[0], ",", $edgesTokens); int $src = $edgesTokens[0]; int $srcSock = $edgesTokens[1]; int $dst = $edgesTokens[2]; int $dstSock = $edgesTokens[3]; delete_magma_connection -si $src -ss $srcSock -di $dst -ds $dstSock -prt $prtNode; create_magma_connection -si $src -ss $srcSock -di $newNode -ds 0 -prt $prtNode; create_magma_connection -si $newNode -ss 0 -di $dst -ds $dstSock -prt $prtNode; int $sourcepoint[] = `retrieve_magma_node_instance_info -id $src -prt $prtNode -xy true`; int $destpoint[] = `retrieve_magma_node_instance_info -id $dst -prt $prtNode -xy true`; $x = ($destpoint[0]+$sourcepoint[0])/2; $y = ($destpoint[1]+$sourcepoint[1])/2; } if (`size $selnodes` == 1) //Insert node after selected object { string $seltype = `retrieve_magma_node_instance_info -id $selnodes[0] -prt $prtNode -type true`; if ($seltype != "Output") { if ($insertbranch == "Insert") { int $connections[] = `get_magma_connections -prt $prtNode -i $selnodes[0] -ss 0`; create_magma_connection -si $selnodes[0] -ss 0 -di $newNode -ds 0 -prt $prtNode; int $i = 0; for ($i = 0; $i < `size $connections`; $i=$i+2) { create_magma_connection -si $newNode -ss 0 -di $connections[$i] -ds $connections[$i+1] -prt $prtNode; } int $sourcepoint[] = `retrieve_magma_node_instance_info -id $selnodes[0] -prt $prtNode -xy true`; int $destpoint[] = `retrieve_magma_node_instance_info -id $connections[0] -prt $prtNode -xy true`; $x = ($destpoint[0]+$sourcepoint[0])/2; $y = ($destpoint[1]+$sourcepoint[1])/2; } else { create_magma_connection -si $selnodes[0] -ss 0 -di $newNode -ds 0 -prt $prtNode; } } } if ($isOutput == 1 && $insertbranch == "Insert") // if the one selected node was an Output, insert into its connection... { int $existingConnection[] = `get_magma_connections -prt $prtNode -id $selnodes[0]`; create_magma_connection -si $newNode -ss 0 -di $selnodes[0] -ds 0 -prt $prtNode; if ($existingConnection[0] > -1) { create_magma_connection -si $existingConnection[0] -ss $existingConnection[1] -di $newNode -ds 0 -prt $prtNode; } } MagmaEditor_SetOperatorDefaultTypesByOutputConnection $newNode $prtNode ; //switch the inputs according to connection's Outout node, if any checkBox -e -v true ($prtNode+"_chk_enableUpdatesAndReoderCalls"); magma_flux_window_set -n $newNode -prt $prtNode; set_magma_node_instance_info -id $newNode -prt $prtNode -x $x -y $y; if ($redraw) MagmaNodesReorderGrid $prtNode; optionMenu -e -select 1 ($prtNode+"_ddl_MagmaInsertBranchControl"); MagmaFLUX_resetSelection $prtNode {$newNode}; MagmaEditor_SetWireColors $prtNode; checkBox -e -v ($enableupdates) ($prtNode+"_chk_enableUpdatesAndReoderCalls"); //back to original state if ($undorecord) MagmaEditor_CreateUndoRecord $prtNode ("Create Node ["+$type+"_"+$newNode+"]"); if ($enableupdates) MagmaEditor_ForceUpdate $prtNode ; } global proc MagmaSwitchInputSocketDefaults (int $node, string $prtNode, int $enum) { string $type = `retrieve_magma_node_instance_info -id $node -prt $prtNode -type true`; string $category = MagmaGetNodeCategoryFromType($type); if( $category != "Input" ) { string $inInfoBuffer[] = `retrieve_magma_node_info -t $type -is true`; // string $inInfoBuffer[] = `retrieve_magma_node_instance_info -id $node -is true`; // <-- THIS CHANGE WAS CAUSING AN ERROR! for( $currentInfo in $inInfoBuffer ) { string $attr; string $currentInfoBuffer[] = `MagmaFLUX_PropertyTokenizer $currentInfo`; string $socketNameBuffer[]; tokenize $currentInfoBuffer[0] "#:" $socketNameBuffer; string $socketNumber = $socketNameBuffer[1]; string $socketName = $socketNameBuffer[2]; string $attributeTypes = $currentInfoBuffer[2]; // Check if there are any options for the socket string $attributeTypesBuffer[]; tokenize $attributeTypes " " $attributeTypesBuffer; if( `size $attributeTypesBuffer` <= 0 ) continue; if( `size $attributeTypesBuffer` == 1 && `size $attributeTypesBuffer[0]` <= 0) continue; string $signature = $prtNode + "." + $type + "_" + $node + "_" + "InputSocket" + $socketNumber; if ( ($type == "Blend" || $type == "Subtract"|| $type == "Add") && ($socketNumber == 0 || $socketNumber == 1)) // { eval ("setAttr "+$signature + "_enum "+$enum+";"); } if ( ($type == "Multiply") && $socketNumber == 0) // { eval ("setAttr "+$signature + "_enum "+$enum+";"); } } } } global proc MagmaInsertAndConnectQueryNode (string $prtNode, int $currentNode, string $nodeType) { int $enableupdates = `checkBox -q -v ($prtNode+"_chk_enableUpdatesAndReoderCalls")`; //remember whether updates were on checkBox -e -v false ($prtNode+"_chk_enableUpdatesAndReoderCalls"); int $pos[] = `retrieve_magma_node_instance_info -id $currentNode -prt $prtNode -xy true`; int $newNode = `create_magma_node -t $nodeType -prt $prtNode -x ($pos[0]+200) -y ($pos[1])`; int $connections[] = `get_magma_connections -prt $prtNode -i $currentNode`; create_magma_connection -si $currentNode -ss 2 -di $newNode -ds 1 -prt $prtNode; if ($nodeType == "FaceQuery") { create_magma_connection -si $currentNode -ss 3 -di $newNode -ds 2 -prt $prtNode; create_magma_connection -si $currentNode -ss 6 -di $newNode -ds 3 -prt $prtNode; float $onethird = 1.0/3.0; string $onethirdvec = $onethird + " " + $onethird + " " + $onethird; eval("setAttr "+$prtNode + "." + $nodeType +"_"+ $newNode +"_InputSocket3_vector3f " + $onethirdvec); } int $connection[] = `get_magma_connections -prt $prtNode -id $currentNode`; if ($connection[0] > -1) { create_magma_connection -si $connection[0] -ss $connection[1] -di $newNode -ds 0 -prt $prtNode; } checkBox -e -v true ($prtNode+"_chk_enableUpdatesAndReoderCalls"); int $connectionsMap[] = `GetOutputConnectionsMap $prtNode`; MagmaEditor_SetSocketColors $newNode $prtNode $connectionsMap; MagmaEditor_SetWireColors $prtNode; MagmaNodesReorderGrid $prtNode; optionMenu -e -select 1 ($prtNode+"_ddl_MagmaInsertBranchControl"); checkBox -e -v ($enableupdates) ($prtNode+"_chk_enableUpdatesAndReoderCalls"); //back to original state MagmaEditor_CreateUndoRecord $prtNode ("Create And Connect "+$nodeType); } global proc MagmaInsertConversionNode (string $prtNode, int $x, int $y, int $currentNode, string $newNodeType, int $sourceoutput, int $targetinput, int $axis, int $selectIt, int $undorecord ) { //print "// MagmaInsertConversionNode called\n"; int $enableupdates = `checkBox -q -v ($prtNode+"_chk_enableUpdatesAndReoderCalls")`; //remember whether updates were on checkBox -e -v false ($prtNode+"_chk_enableUpdatesAndReoderCalls"); int $position[] = `magma_flux_window_query -lxy true -prt $prtNode `; string $oldNodeType = `retrieve_magma_node_instance_info -id $currentNode -prt $prtNode -type true`; int $connections[] = `get_magma_connections -prt $prtNode -i $currentNode -ss $sourceoutput`; $newNode = `create_magma_node -t $newNodeType -prt $prtNode`; if ($x == 0 && $y == 0) { set_magma_node_instance_info -id $newNode -prt $prtNode -x ($position[0]+200) -y $position[1]; } else { set_magma_node_instance_info -id $newNode -prt $prtNode -x $x -y $y; } if ($newNodeType == "FaceQuery") { float $onethird = 1.0/3.0; string $onethirdvec = $onethird + " " + $onethird + " " + $onethird; eval("setAttr "+$prtNode + "." + $newNodeType +"_"+ $newNode +"_InputSocket3_vector3f " + $onethirdvec); } if ($newNodeType == "PropertyQuery") { string $nodeattr = ($prtNode + "." + $newNodeType +"_"+ $newNode +"_Property1_properties_StringList"); string $code = ( "string $nodeattr = \"" + $nodeattr + "\";\n" + "string $pqItems[]; \n" + "$pqItems[0] = \"translate\";\n" + "string $setAttrArgs = `MagmaFLUX_ListToStringSetAttr $pqItems`;\n" + "eval(\"setAttr $nodeattr -type \\\"stringArray\\\" \" + $setAttrArgs + \"\");\n" ); eval ($code); } if ($newNodeType == "ToVector" && $oldNodeType == "Breakout") { for ($i = 0; $i < 3; $i++) { create_magma_connection -si $currentNode -ss $i -di $newNode -ds $i -prt $prtNode; } } else { create_magma_connection -si $currentNode -ss $sourceoutput -di $newNode -ds $targetinput -prt $prtNode; } for ($i = 0; $i < `size $connections`; $i=$i+2) { create_magma_connection -si $newNode -ss $axis -di $connections[$i] -ds $connections[$i+1] -prt $prtNode; } if ($newNodeType == "ToWorld" || $newNodeType == "FromWorld" || $newNodeType == "ToCamera" || $newNodeType == "FromCamera" || $newNodeType == "ToSpace" || $newNodeType == "FromSpace" ) { string $type = `retrieve_magma_node_instance_info -id $currentNode -prt $prtNode -type true`; if ($type == "InputChannel" ) { string $usedChannel = eval ("getAttr "+$prtNode + "." + $type +"_"+ $currentNode +"_Property1_channelName_String;"); if ($usedChannel == "Normal") SetMagmaNodeAttributeValue $prtNode ($newNodeType+"_"+$newNode) "Property1_inputType" "String" "Normal"; else if ($usedChannel == "Position") SetMagmaNodeAttributeValue $prtNode ($newNodeType+"_"+$newNode) "Property1_inputType" "String" "Point"; else SetMagmaNodeAttributeValue $prtNode ($newNodeType+"_"+$newNode) "Property1_inputType" "String" "Vector"; } if ($type == "IntersectRay" && $sourceoutput == 5 ) { SetMagmaNodeAttributeValue $prtNode ($newNodeType+"_"+$newNode) "Property1_inputType" "String" "Normal"; } } MagmaAdjustInputSocketDefaults $newNode $newNodeType $prtNode; MagmaEditor_SetOperatorDefaultTypesByOutputConnection $newNode $prtNode; //switch the inputs according to connection's Outout node, if any checkBox -e -v true ($prtNode+"_chk_enableUpdatesAndReoderCalls"); int $connectionsMap[] = `GetOutputConnectionsMap $prtNode`; MagmaEditor_SetSocketColors $newNode $prtNode $connectionsMap; MagmaEditor_SetWireColors $prtNode; MagmaNodesReorderGrid $prtNode; optionMenu -e -select 1 ($prtNode+"_ddl_MagmaInsertBranchControl"); if ($selectIt) magma_flux_window_set -n $newNode -prt $prtNode; if ($undorecord) MagmaEditor_CreateUndoRecord $prtNode ("Insert Conversion Node ["+$newNodeType+"_"+$newNode+"]"); checkBox -e -v ($enableupdates) ($prtNode+"_chk_enableUpdatesAndReoderCalls"); //back to original state //print "// MagmaInsertConversionNode ended\n"; } global proc AddNewMagmaInputGeometryToFlow (string $prtNode, int $x, int $y, int $redraw, int $undorecord ) { int $enableupdates = `checkBox -q -v ($prtNode+"_chk_enableUpdatesAndReoderCalls")`; //remember whether updates were on int $position[] = `magma_flux_window_query -lxy true -prt $prtNode`; int $selnodes[] = `magma_flux_window_query -n true -prt $prtNode`; $newNode = `create_magma_node -t "InputGeometry" -x ($position[0] - 200) -y ($position[1]) -prt $prtNode`; for ($aNode in $selnodes) { string $type = `retrieve_magma_node_instance_info -id $aNode -prt $prtNode -type true`; int $index = stringArrayFindWrapper( $type, 0, {"IntersectRay", "NearestPoint", "MeshQuery", "ElementQuery", "InVolume"} ); if ( $index > -1 ) { int $connection[] = `get_magma_connections -prt $prtNode -id $aNode`; if ($connection[0] == -1) { create_magma_connection -si $newNode -ss 0 -di $aNode -ds 0 -prt $prtNode; } } } checkBox -e -v true ($prtNode+"_chk_enableUpdatesAndReoderCalls"); magma_flux_window_set -n $newNode -prt $prtNode; int $connectionsMap[] = `GetOutputConnectionsMap $prtNode`; MagmaEditor_SetSocketColors $newNode $prtNode $connectionsMap; MagmaEditor_SetWireColors $prtNode; if ($redraw) MagmaNodesReorderGrid $prtNode; optionMenu -e -select 1 ($prtNode+"_ddl_MagmaInsertBranchControl"); if ($undorecord) MagmaEditor_CreateUndoRecord $prtNode ("Add Node [InputGeometry_"+$newNode+"]"); checkBox -e -v ($enableupdates) ($prtNode+"_chk_enableUpdatesAndReoderCalls"); //back to original state } global proc AddNewMagmaInputParticlesToFlow (string $prtNode, int $x, int $y, int $redraw, int $undorecord ) { int $enableupdates = `checkBox -q -v ($prtNode+"_chk_enableUpdatesAndReoderCalls")`; //remember whether updates were on int $position[] = `magma_flux_window_query -lxy true -prt $prtNode`; int $selnodes[] = `magma_flux_window_query -n true -prt $prtNode`; $newNode = `create_magma_node -t "InputParticles" -x ($position[0] - 200) -y ($position[1]) -prt $prtNode`; for ($aNode in $selnodes) { string $type = `retrieve_magma_node_instance_info -id $aNode -prt $prtNode -type true`; if ( $type == "NearestParticle" || $type == "ParticleSumCount" || $type == "ParticleSumRadius" || $type == "ParticleQuery" ) { int $connection[] = `get_magma_connections -prt $prtNode -id $aNode`; if ($connection[0] == -1) { create_magma_connection -si $newNode -ss 0 -di $aNode -ds 0 -prt $prtNode; } } } checkBox -e -v true ($prtNode+"_chk_enableUpdatesAndReoderCalls"); magma_flux_window_set -n $newNode -prt $prtNode; //set_magma_node_instance_info -id $newNode -r 255 -g 220 -b 220 -a 210 -prt $prtNode; int $connectionsMap[] = `GetOutputConnectionsMap $prtNode`; MagmaEditor_SetSocketColors $newNode $prtNode $connectionsMap; MagmaEditor_SetWireColors $prtNode; if ($redraw) MagmaNodesReorderGrid $prtNode; optionMenu -e -select 1 ($prtNode+"_ddl_MagmaInsertBranchControl"); if ($undorecord) MagmaEditor_CreateUndoRecord $prtNode ("Add Node [InputParticles_"+$newNode+"]"); checkBox -e -v ($enableupdates) ($prtNode+"_chk_enableUpdatesAndReoderCalls"); //back to original state } global proc AddNewMagmaInputObjectToFlow (string $prtNode, int $x, int $y, int $redraw, int $undorecord ) { int $enableupdates = `checkBox -q -v ($prtNode+"_chk_enableUpdatesAndReoderCalls")`; //remember whether updates were on int $position[] = `magma_flux_window_query -lxy true -prt $prtNode`; int $selnodes[] = `magma_flux_window_query -n true -prt $prtNode`; $newNode = `create_magma_node -t "InputObject" -x ($position[0] - 200) -y ($position[1]) -prt $prtNode`; for ($aNode in $selnodes) { string $type = `retrieve_magma_node_instance_info -id $aNode -prt $prtNode -type true`; if ( $type == "PropertyQuery" ) { int $connection[] = `get_magma_connections -prt $prtNode -id $aNode`; if ($connection[0] == -1) { create_magma_connection -si $newNode -ss 0 -di $aNode -ds 0 -prt $prtNode; } } } string $sceneSelection[] = `ls -sl`; if (`size $sceneSelection` == 1) { eval ("setAttr "+$prtNode+".InputObject_" + $newNode + "_Property1_objectName_String -type \"string\" " + $sceneSelection[0]); } checkBox -e -v true ($prtNode+"_chk_enableUpdatesAndReoderCalls"); magma_flux_window_set -n $newNode -prt $prtNode; int $connectionsMap[] = `GetOutputConnectionsMap $prtNode`; MagmaEditor_SetSocketColors $newNode $prtNode $connectionsMap; MagmaEditor_SetWireColors $prtNode; if ($redraw) MagmaNodesReorderGrid $prtNode; optionMenu -e -select 1 ($prtNode+"_ddl_MagmaInsertBranchControl"); if ($undorecord) MagmaEditor_CreateUndoRecord $prtNode ("Add Node [InputObject_"+$newNode+"]"); checkBox -e -v ($enableupdates) ($prtNode+"_chk_enableUpdatesAndReoderCalls"); //back to original state } //Auto-connect to any selected nodes' first empty socket global proc AutoConnectMagmaInputNodeToSelected (string $prtNode, int $newNode) { int $selnodes[] = `magma_flux_window_query -n true -prt $prtNode`; for ($aNode in $selnodes) { int $isConnected = 0; int $connection[] = `get_magma_connections -prt $prtNode -id $aNode`; int $i = 0; for ($i = 0; $i< `size $connection`; $i=$i+2) { if ($connection[$i] == -1 && $isConnected == 0) { $isConnected = 1; create_magma_connection -si $newNode -ss 0 -di $aNode -ds ($i/2) -prt $prtNode; } } } } global proc int GetMagmaNodeYOffset (string $prtNode) { int $isConnected = 0; int $selnodes[] = `magma_flux_window_query -n true -prt $prtNode`; if (`size $selnodes` == 1) { int $aNode = $selnodes[0]; int $connection[] = `get_magma_connections -prt $prtNode -id $aNode`; int $done = 0; for ($i = 0; $i< `size $connection`; $i=$i+2) { if ($connection[$i] == -1) $done = 1; if ($connection[$i] > -1 && $done == 0) $isConnected++; } } return ($isConnected*100); } global proc AddNewMagmaInputChannelToFlow (string $channelName, string $channelType, string $prtNode, int $x, int $y, int $xoffsetmulti, int $update, int $undorecord, int $node, int $socket) { int $enableupdates = `checkBox -q -v ($prtNode+"_chk_enableUpdatesAndReoderCalls")`; //remember whether updates were on checkBox -e -v false ($prtNode+"_chk_enableUpdatesAndReoderCalls"); int $YOffset = `GetMagmaNodeYOffset $prtNode`; int $position[] = `magma_flux_window_query -lxy true -prt $prtNode`; if ($x == 0 && $y == 0) { $x = $position[0] - 200*$xoffsetmulti; $y = $position[1]+$YOffset; } else { $y = $y-40; } int $newNode = `create_magma_node -t "InputChannel" -x ($x) -y ($y) -prt $prtNode`; if ($socket == -1) AutoConnectMagmaInputNodeToSelected $prtNode $newNode; else { create_magma_connection -si $newNode -ss 0 -di $node -ds $socket -prt $prtNode; } int $connectionsMap[] = `GetOutputConnectionsMap $prtNode`; MagmaEditor_SetSocketColors $newNode $prtNode $connectionsMap; MagmaEditor_SetWireColors $prtNode; SetMagmaNodeAttributeValue $prtNode ("InputChannel_"+$newNode) "Property1_channelName" "String" $channelName; SetMagmaNodeAttributeValue $prtNode ("InputChannel_"+$newNode) "Property2_channelType" "MagmaDataType" $channelType; checkBox -e -v true ($prtNode+"_chk_enableUpdatesAndReoderCalls"); magma_flux_window_set -n $newNode -prt $prtNode; if ($update) MagmaNodesReorderGrid $prtNode; if ($undorecord) MagmaEditor_CreateUndoRecord $prtNode ("Add Node [InputChannel_"+$newNode+"]"); checkBox -e -v ($enableupdates) ($prtNode+"_chk_enableUpdatesAndReoderCalls"); //back to original state if ($enableupdates) MagmaEditor_ForceUpdate $prtNode ; } global proc AddNewMagmaOutputChannelToFlow (string $channelName, string $channelType, string $prtNode, int $x, int $y) { int $enableupdates = `checkBox -q -v ($prtNode+"_chk_enableUpdatesAndReoderCalls")`; //remember whether updates were on checkBox -e -v false ($prtNode+"_chk_enableUpdatesAndReoderCalls"); int $selnodes[] = `magma_flux_window_query -n true -prt $prtNode`; int $allNodes[] = `retrieve_magma_node_ids -prt $prtNode`; int $outCount = 0; string $usedChannels[] = {""}; for ($aNode in $allNodes) { string $type = `retrieve_magma_node_instance_info -id $aNode -prt $prtNode -type true`; if ($type == "Output") { string $usedChannel = eval ("getAttr "+$prtNode + "." + $type +"_"+ $aNode +"_Property1_channelName_String;"); appendStringArray $usedChannels {$usedChannel} 1; $outCount++; } } string $allowedChannels[] = MagmaFLUX_getChannelTypes(); if ($channelName == "") { int $i = 0; int $isAssigned = 0; for ($i =0; $i < `size $allowedChannels` && $isAssigned == 0; $i++) { int $index = stringArrayFindWrapper( $allowedChannels[$i], 0, $usedChannels ); if ($index == -1) { $channelName = $allowedChannels[$i]; $channelType = `MagmaFLUX_getChannelTypesDataType $i`; $isAssigned = 1; } } } if ($channelName == "") //if no valid channel was found... { $channelName = "Color"; $channelType = "Vec3"; } $newNode = `create_magma_node -t "Output" -x (500) -y ($outCount*80) -prt $prtNode`; if ($x == 0 && $y == 0) { } else { set_magma_node_instance_info -id $newNode -x $x -y $y -prt $prtNode; } SetMagmaNodeAttributeValue $prtNode ("Output_"+$newNode) "Property1_channelName" "String" $channelName; SetMagmaNodeAttributeValue $prtNode ("Output_"+$newNode) "Property2_channelType" "MagmaDataType" $channelType; if (`size $selnodes` == 1) { string $type = `retrieve_magma_node_instance_info -id $selnodes[0] -prt $prtNode -type true`; if ($type != "Output") { create_magma_connection -si $selnodes[0] -ss 0 -di $newNode -ds 0 -prt $prtNode; } } checkBox -e -v true ($prtNode+"_chk_enableUpdatesAndReoderCalls"); MagmaNodesReorderGrid $prtNode; int $connectionsMap[] = `GetOutputConnectionsMap $prtNode`; MagmaEditor_SetSocketColors $newNode $prtNode $connectionsMap; MagmaEditor_SetWireColors $prtNode; optionMenu -e -select 1 ($prtNode+"_ddl_MagmaInsertBranchControl"); magma_flux_window_set -n $newNode -prt $prtNode; MagmaEditor_CreateUndoRecord $prtNode ("Add Node [Output_"+$newNode+"]"); checkBox -e -v ($enableupdates) ($prtNode+"_chk_enableUpdatesAndReoderCalls"); //back to original state if ($enableupdates) MagmaEditor_ForceUpdate $prtNode ; } global proc AddNewMagmaInputValueVectorToFlow (float $red, float $green, float $blue, string $prtNode, int $x, int $y, int $redraw, int $undorecord, int $node, int $socket) { int $enableupdates = `checkBox -q -v ($prtNode+"_chk_enableUpdatesAndReoderCalls")`; //remember whether updates were on checkBox -e -v false ($prtNode+"_chk_enableUpdatesAndReoderCalls"); int $selnodes[] = `magma_flux_window_query -n true -prt $prtNode`; int $YOffset = `GetMagmaNodeYOffset $prtNode`; int $position[] = `magma_flux_window_query -lxy true -prt $prtNode`; if ($x == 0 && $y == 0) { $x = $position[0] - 200; $y = $position[1]+$YOffset; } else { $y = $y-40; } int $newNode = `create_magma_node -t "InputValue" -x ($x) -y ($y) -prt $prtNode`; if ($node == -1 || $socket == -1) AutoConnectMagmaInputNodeToSelected $prtNode $newNode; else { create_magma_connection -si $newNode -ss 0 -di $node -ds $socket -prt $prtNode; } SetMagmaNodeAttributeValue $prtNode ("InputValue_"+$newNode) "Property1_enumValue" "Int" 3; string $vvalue = "" + $red +" "+ $green + " " + $blue; SetMagmaNodeAttributeValue $prtNode ("InputValue_"+$newNode) "Property4_vec3Value" "Vector3f" $vvalue; checkBox -e -v true ($prtNode+"_chk_enableUpdatesAndReoderCalls"); int $inputConnectionsCheck = 0; if(`size $selnodes` == 1) { int $existingConnection[] = `get_magma_connections -prt $prtNode -id $selnodes[0]`; for ($i=0; $i < `size $existingConnection`; $i+=2) { if ($existingConnection[$i] == -1) $inputConnectionsCheck++; } } if(`size $selnodes` != 1 || $inputConnectionsCheck == 0 ) { magma_flux_window_set -n $newNode -prt $prtNode; //select the new node if there wasn't a single node selected, or if all its sockets were filled } else { MagmaFLUX_resetSelection $prtNode $selnodes; } if ($redraw) MagmaNodesReorderGrid $prtNode; int $connectionsMap[] = `GetOutputConnectionsMap $prtNode`; MagmaEditor_SetSocketColors $newNode $prtNode $connectionsMap; MagmaEditor_SetWireColors $prtNode; if ($undorecord) MagmaEditor_CreateUndoRecord $prtNode ("Add Vector [InputValue_"+$newNode+"]"); checkBox -e -v ($enableupdates) ($prtNode+"_chk_enableUpdatesAndReoderCalls"); //back to original state if ($enableupdates) MagmaEditor_ForceUpdate $prtNode ; } global proc AddNewMagmaInputValueIntToFlow (int $value, string $prtNode, int $x, int $y, int $redraw, int $undorecord, int $node, int $socket) { int $enableupdates = `checkBox -q -v ($prtNode+"_chk_enableUpdatesAndReoderCalls")`; //remember whether updates were on checkBox -e -v false ($prtNode+"_chk_enableUpdatesAndReoderCalls"); int $selnodes[] = `magma_flux_window_query -n true -prt $prtNode`; int $YOffset = `GetMagmaNodeYOffset $prtNode`; int $position[] = `magma_flux_window_query -lxy true -prt $prtNode`; if ($x == 0 && $y == 0) { $x = $position[0] - 200; $y = $position[1]+$YOffset; } else { $y = $y-40; } $newNode = `create_magma_node -t "InputValue" -x ($x) -y ($y) -prt $prtNode`; if ($node == -1 || $socket == -1) AutoConnectMagmaInputNodeToSelected $prtNode $newNode; else { create_magma_connection -si $newNode -ss 0 -di $node -ds $socket -prt $prtNode; } checkBox -e -v true ($prtNode+"_chk_enableUpdatesAndReoderCalls"); int $connectionsMap[] = `GetOutputConnectionsMap $prtNode`; MagmaEditor_SetSocketColors $newNode $prtNode $connectionsMap; MagmaEditor_SetWireColors $prtNode; SetMagmaNodeAttributeValue $prtNode ("InputValue_"+$newNode) "Property1_enumValue" "Int" 2; SetMagmaNodeAttributeValue $prtNode ("InputValue_"+$newNode) "Property3_iValue" "Int" $value; int $inputConnectionsCheck = 0; if(`size $selnodes` == 1) { int $existingConnection[] = `get_magma_connections -prt $prtNode -id $selnodes[0]`; for ($i=0; $i < `size $existingConnection`; $i+=2) { if ($existingConnection[$i] == -1) $inputConnectionsCheck++; } } if(`size $selnodes` != 1 || $inputConnectionsCheck == 0 ) { magma_flux_window_set -n $newNode -prt $prtNode; } else { MagmaFLUX_resetSelection $prtNode $selnodes; } if ($redraw) MagmaNodesReorderGrid $prtNode; if ($undorecord) MagmaEditor_CreateUndoRecord $prtNode ("Add Integer [InputValue_"+$newNode+"]"); checkBox -e -v ($enableupdates) ($prtNode+"_chk_enableUpdatesAndReoderCalls"); //back to original state if ($enableupdates) MagmaEditor_ForceUpdate $prtNode ; } global proc AddNewMagmaInputValueFloatToFlow (float $value, string $prtNode, int $x, int $y, int $redraw, int $undorecord, int $node, int $socket ) { int $enableupdates = `checkBox -q -v ($prtNode+"_chk_enableUpdatesAndReoderCalls")`; //remember whether updates were on checkBox -e -v false ($prtNode+"_chk_enableUpdatesAndReoderCalls"); int $selnodes[] = `magma_flux_window_query -n true -prt $prtNode`; int $YOffset = `GetMagmaNodeYOffset $prtNode`; int $position[] = `magma_flux_window_query -lxy true -prt $prtNode`; if ($x == 0 && $y == 0) { $x = $position[0] - 200; $y = $position[1]+$YOffset; } else { $y = $y-40; } $newNode = `create_magma_node -t "InputValue" -x ($x) -y ($y) -prt $prtNode`; if ($node == -1 || $socket == -1) AutoConnectMagmaInputNodeToSelected $prtNode $newNode; else { create_magma_connection -si $newNode -ss 0 -di $node -ds $socket -prt $prtNode; } SetMagmaNodeAttributeValue $prtNode ("InputValue_"+$newNode) "Property1_enumValue" "Int" 1; SetMagmaNodeAttributeValue $prtNode ("InputValue_"+$newNode) "Property2_fValue" "Float" $value; checkBox -e -v true ($prtNode+"_chk_enableUpdatesAndReoderCalls"); int $inputConnectionsCheck = 0; if(`size $selnodes` == 1) { int $existingConnection[] = `get_magma_connections -prt $prtNode -id $selnodes[0]`; for ($i=0; $i < `size $existingConnection`; $i+=2) { if ($existingConnection[$i] == -1) $inputConnectionsCheck++; } } if(`size $selnodes` != 1 || $inputConnectionsCheck == 0 ) { magma_flux_window_set -n $newNode -prt $prtNode; } else { MagmaFLUX_resetSelection $prtNode $selnodes; } int $connectionsMap[] = `GetOutputConnectionsMap $prtNode`; MagmaEditor_SetSocketColors $newNode $prtNode $connectionsMap; MagmaEditor_SetWireColors $prtNode; if ($redraw) MagmaNodesReorderGrid $prtNode; if ($undorecord) MagmaEditor_CreateUndoRecord $prtNode ("Add Float [InputValue_"+$newNode+"]"); checkBox -e -v ($enableupdates) ($prtNode+"_chk_enableUpdatesAndReoderCalls"); //back to original state if ($enableupdates) MagmaEditor_ForceUpdate $prtNode ; } global proc MagmaEditor_SaveColorScheme (string $prtNode, string $savepath) { string $filePath = $savepath; if ($savepath == "") { string $userprefs = (`internalVar -userPrefDir`); $userprefs+= "Krakatoa/Magma/"; sysFile -md $userprefs; $filePath = ($userprefs+"magma_current_color_scheme.cfg"); } $fileId = `fopen $filePath "w"`; fprint $fileId ("//Krakatoa MY - Magma Editor Current Color Scheme\n"); fprint $fileId (`menuItem -q -cb ($prtNode+"_mnu_useDarkBackgroundColor")`+"\n"); fprint $fileId (`menuItem -q -cb ($prtNode+"_mnu_useDarkNodeBackgroundColors")`+"\n"); fprint $fileId (`menuItem -q -cb ($prtNode+"_mnu_useDarkNodeOutlineColors")`+"\n"); fprint $fileId (`menuItem -q -cb ($prtNode+"_mnu_drawHighContrastNodeOutlines")`+"\n"); fprint $fileId (`menuItem -q -cb ($prtNode+"_mnu_useDarkNodeHeaderColors")`+"\n"); fprint $fileId (`menuItem -q -cb ($prtNode+"_mnu_useDarkNodeTitleColors")`+"\n"); fprint $fileId (`menuItem -q -cb ($prtNode+"_mnu_drawHighContrastNodeTitles")`+"\n"); fprint $fileId (`menuItem -q -cb ($prtNode+"_mnu_useSaturatedSocketColors")`+"\n"); fprint $fileId (`menuItem -q -cb ($prtNode+"_mnu_useDarkSocketOutlineColors")`+"\n"); fclose $fileId; } global proc MagmaEditor_SaveNamedColorScheme (string $prtNode) { string $userprefs = (`internalVar -userPrefDir`); $userprefs+= "Krakatoa/Magma/"; string $filePath[] = `fileDialog2 -fileMode 0 -dir $userprefs -caption "SAVE A Magma Color Scheme Preset..." -fileFilter ("Krakatoa MY Magma Color Scheme (*.MagmaColors)")`; if (`size $filePath[0]`) { MagmaEditor_SaveColorScheme $prtNode $filePath[0]; } } global proc MagmaEditor_LoadColorScheme (string $prtNode, string $loadpath) { string $filePath = $loadpath; if ($loadpath == "") { string $userprefs = (`internalVar -userPrefDir`); $userprefs+= "Krakatoa/Magma/"; sysFile -md $userprefs; $filePath = ($userprefs+"magma_current_color_scheme.cfg"); } if (`filetest -r $filePath`) { $fileId = `fopen $filePath "r"`; string $comment = `fgetline $fileId`; int $value1 = `fgetline $fileId`; int $value2 = `fgetline $fileId`; int $value3 = `fgetline $fileId`; int $value4 = `fgetline $fileId`; int $value5 = `fgetline $fileId`; int $value6 = `fgetline $fileId`; int $value7 = `fgetline $fileId`; int $value8 = `fgetline $fileId`; int $value9 = `fgetline $fileId`; fclose $fileId; menuItem -e -cb $value1 ($prtNode+"_mnu_useDarkBackgroundColor"); menuItem -e -cb $value2 ($prtNode+"_mnu_useDarkNodeBackgroundColors"); menuItem -e -cb $value3 ($prtNode+"_mnu_useDarkNodeOutlineColors"); menuItem -e -cb $value4 ($prtNode+"_mnu_drawHighContrastNodeOutlines"); menuItem -e -cb $value5 ($prtNode+"_mnu_useDarkNodeHeaderColors"); menuItem -e -cb $value6 ($prtNode+"_mnu_useDarkNodeTitleColors"); menuItem -e -cb $value7 ($prtNode+"_mnu_drawHighContrastNodeTitles"); menuItem -e -cb $value8 ($prtNode+"_mnu_useSaturatedSocketColors"); menuItem -e -cb $value9 ($prtNode+"_mnu_useDarkSocketOutlineColors"); } } global proc MagmaEditor_LoadNamedColorScheme (string $prtNode) { string $userprefs = (`internalVar -userPrefDir`); $userprefs+= "Krakatoa/Magma/"; string $filePath[] = `fileDialog2 -fileMode 1 -dir $userprefs -caption "LOAD A Magma Color Scheme Preset..." -fileFilter ("Krakatoa MY Magma Color Scheme (*.MagmaColors)")`; if (`size $filePath[0]`) { MagmaEditor_LoadColorScheme $prtNode $filePath[0]; MagmaEditor_UpdateColorScheme $prtNode 1; } } global proc MagmaEditor_SetSelectionModeWindowCrossing (string $prtNode) { int $newState = `menuItem -q -cb ($prtNode+"_selectionModeCrossing")`; magma_flux_window_set -prt $prtNode -sm ($newState); MagmaEditor_setIniKey "KrakatoaMagmaSettings" "SelectionModeCrossing" ($newState); } global proc MagmaEditor_setIniKey (string $settingsfile, string $key, string $value) { int $keylength = `size $key`; string $record = $key + "=" + $value+"\n"; string $tmpDir = `internalVar -userPrefDir`; $tmpDir += "Krakatoa/Magma/"; sysFile -md $tmpDir; string $IniFile = ($tmpDir+$settingsfile+".cfg"); string $dataArray[]; if (`filetest -r $IniFile`) { $fileId = `fopen $IniFile "r"`; string $line; do { $line = `fgetline $fileId`; if ($line != "" && (`substring $line 1 $keylength`) != $key) $dataArray[`size $dataArray`] = $line; } while ( $line != ""); fclose $fileId ; } $dataArray[`size $dataArray`] = $record; string $IniFile2 = ($tmpDir+$settingsfile +".tmp"); $fileId2 = `fopen $IniFile2 "w"`; for ($i in $dataArray) fprint $fileId2 ($i); fclose $fileId2 ; sysFile -delete $IniFile; sysFile -rename $IniFile $IniFile2; } global proc string MagmaEditor_getIniKey (string $settingsfile, string $key, string $default) { string $value = $default; //initialize the return value to the default, in case there is no file or data in the file int $keylength = `size $key`; string $tmpDir = `internalVar -userPrefDir`; $tmpDir += "Krakatoa/Magma/"; string $IniFile = ($tmpDir+$settingsfile+".cfg"); if (`filetest -r $IniFile`) //if the file exists, read from it { $fileId = `fopen $IniFile "r"`; string $line; do { $line = `fgetline $fileId`; int $linelength = `size $line`; if ($line != "" && (`substring $line 1 $keylength`) == $key) $value = `substring $line ($keylength+2) $linelength`; //if the key is found, read its value } while ( $line != ""); fclose $fileId ; } return $value; } global proc MagmaEditor_SetColorTheme (string $prtNode, int $offset) { string $menuNames[] = {"_mnu_useDarkBackgroundColor", "_mnu_useDarkNodeBackgroundColors", "_mnu_useDarkNodeOutlineColors", "_mnu_useDarkNodeTitleColors", "_mnu_useDarkNodeHeaderColors", "_mnu_drawHighContrastNodeOutlines", "_mnu_drawHighContrastNodeTitles", "_mnu_useSaturatedSocketColors", "_mnu_useDarkSocketOutlineColors" }; int $themeList[] = { 1,0,0,0,1,0,1,1,1, // Default Dark 1,1,0,0,1,1,1,1,1, // Neon Dark 1,1,1,1,0,1,1,0,1, // Dark Monopoly 0,0,1,1,0,1,1,1,1, // KMX Light 0,0,0,1,0,0,0,0,0 // Light Low Contrast }; for ($i = 0; $i < `size $menuNames`; $i++) { menuItem -e -cb $themeList[$i+($offset*9)] ($prtNode+$menuNames[$i]); } MagmaEditor_UpdateColorScheme $prtNode 1; } global proc PopulateMagmaFLUXDialog ( string $prtNode, string $windowName ) { string $InputItems[] = { "InputChannel", "InputGeometry", "InputObject", "InputParticles", /*"InputScript", "InputTexmap",*/ "InputValue" }; string $SystemItems[] = { "Elbow", "Output" }; //string $LoopsItems[] = { "Loop" }; string $ArithmeticItems[] = { "Abs","A&bs","B", "Add","A&dd","D", "Ceil","&Ceil","C", "Divide","Di&vide","V", "Floor","&Floor","F", "Log","&Log","L", "Modulo","M&odulo","O", "Multiply","&Multiply","M", "Negate","&Negate","N", "Power","&Power","P", "Sqrt","&Sqrt","S", "Subtract","S&ubtract","U"}; string $BLOP_BLOPItems[] = { "BLOP" }; //string $BLOP_GeometryItems[] = { "BaryFromRnd", "FaceArea" }; //string $BLOP_LogarithmsItems[] = { "Log10", "LogBase" }; //string $BLOP_StandardItems[] = { "GizmoBlend", "GizmoBlendExp", "GizmoGrad" }; //string $BLOP_VectorsItems[] = { "ColorGradient", "ClampVector", "MakeCircle", "ReflectVector", "XFormVbyNxT" }; string $ConvertItems[] = { "AngleAxisToQuat","&AngleAxisToQuat","A", "Breakout","&Breakout","B", "EulerAnglesToQuat","&EulerAnglesToQuat","E", "QuatToVectors","&QuatToVectors","Q", "ToFloat","To&Float","F", "ToInt","To&Int","I", "ToVector","To&Vector","V", "VectorsToQuat","Vectors&ToQuat","T"}; string $FunctionItems[] = { "Blend","&Blend","B", "Clamp","&Clamp","C", /*"Curve","Curve",*/ "Noise","&Noise","N", "VecNoise","&VecNoise","V", "ExponentialRandom", "&ExponentialRandom", "E", "GaussianRandom", "&GaussianRandom", "G", "TriangleRandom", "&TriangleRandom", "T", "UniformOnSphere", "Uniform&OnSphere", "O", "UniformRandom", "&UniformRandom", "U", "VecUniformRandom", "VecR&andom", "A", "WeibullRandom", "&WeibullRandom", "W" }; string $LogicItems[] = { "Equal","&Equal","E", "Greater","&Greater","G", "GreaterOrEqual","G&reaterOrEqual","R", "Less","&Less","L", "LessOrEqual","LessOrE&qual","Q", "LogicalAnd","Logical&And","A", "LogicalNot","Logical&Not","N", "LogicalOr","Logical&Or","O", "LogicalXor","Logical&Xor","X", "Mux", "&Mux", "M", "NotEqual","No&tEqual","T", "Switch","&Switch","S"}; string $ObjectItems[] = { "ElementQuery","&ElementQuery","E", "FaceQuery","&FaceQuery","F", "IntersectRay","&IntersectRay","I", "InVolume","In&Volume","V", "MeshQuery","&MeshQuery","M", "NearestParticle","Nearest&Particle","P", "NearestPoint","&NearestPoint","N", "ParticleQuery","P&articleQuery", "A", "ParticleSumCount","ParticleSum&Count","C", "ParticleSumRadius","ParticleSum&Radius","R", "PropertyQuery","Property&Query","Q", "VertexQuery","Verte&xQuery","X"}; string $TransformItems[] = { "FromCamera","From&Camera","C", "FromSpace", "From&Space", "S", "FromWorld","From&World","W", "ToCamera","ToCamera","T", "ToSpace", "To&Space", "A", "ToWorld","ToWo&rld","R", "TransformByQuat","TransformBy&Quat","Q" }; string $TrigonometryItems[] = { "ACos","AC&os","O", "ASin","AS&in","I", "ATan","&ATan","A", "ATan2","ATan&2","N", "Cos","&Cos","C", "Sin","&Sin","S", "Tan","&Tan","T" }; string $VectorsItems[] = { "ComponentSum","Component&Sum","S", "Magnitude","&Magnitude","M", "MatrixMulVec","MatrixMul&Vec","V", "Normalize","&Normalize","N", "VectorCross","Vector&Cross","C", "VectorDot","Vector&Dot","D" }; string $windowLayout = ($prtNode + "_windowLayout"); formLayout $windowLayout; rowLayout -nc 2 buttonPanel4; intField -v 0 -w 1 -visible false ($prtNode+"_int_NodeID"); intField -v 0 -w 1 -visible false ($prtNode+"_int_SocketID"); //intField -v 0 -w 1 -visible false ($prtNode+"_int_TargetNode"); //intField -v 0 -w 1 -visible false ($prtNode+"_int_TargetSocket"); setParent ..; menuBarLayout -w 250 -h 16; menu -label "File"; menuItem -label "New..." -command ("ResetMagmaFLUXDialog " + $prtNode + ";"); menuItem -divider true; menuItem -label "Open Flow..." -enable true -command ("MagmaEditor_LoadMagmaFlowFromDisk "+$prtNode+" true 0;"); menuItem -label "Merge Flow..." -enable true -command ("MagmaEditor_LoadMagmaFlowFromDisk "+$prtNode+" false 200;"); menuItem -divider true; menuItem -label "Save Flow As..." -enable true -command ("MagmaEditor_SaveMagmaFlowToDisk "+$prtNode+" 0;"); menuItem -label "Save Selected Nodes As..." -enable true -command ("MagmaEditor_SaveMagmaFlowToDisk "+$prtNode+" 1;"); //menuItem -label "Save Flow As..." -enable false; menuItem -divider true; menuItem -label "Export to Krakatoa MX..." -enable true -command ("MagmaEditor_ExportToKrakatoaMXMagma "+ $prtNode +";"); menuItem -divider true; //menuItem -label "Re-Select &Host Object" -command ("select -r " + $prtNode + ";"); //menuItem -divider true; menuItem -label "Close Magma Editor" -command ("deleteUI -window "+$windowName+" ;"); menu -label "Edit"; menuItem -label "Undo" -ke "Z" -ctl true -command ("MagmaEditor_UndoRecord "+$prtNode +";") mnu_undoCommand; menuItem -label "Redo" -ke "Y" -ctl true -command ("MagmaEditor_RedoRecord "+$prtNode +";") mnu_redoCommand; //menuItem -label "Cut" -enable false -ke "X" -ctl true; menuItem -label "Copy" -enable false -ke "C" -ctl true -command ("MagmaEditor_CopyToClipboardFile "+$prtNode +";") ($prtNode+"_copyToClipboard"); menuItem -label "Paste" -enable true -ke "V" -ctl true -command ("MagmaEditor_PasteFromClipboardFile "+$prtNode +";") ($prtNode+"_pasteFromClipboard"); menuItem -divider true; menuItem -label "Select All" -ke "A" -ctl true -command ("MagmaEditor_SelectAllNodes "+$prtNode+";"); menuItem -label "Invert Selection" -ke "I" -ctl true -command ("MagmaEditor_SelectInvert "+$prtNode+";"); menuItem -label "Select Unconnected" -ke "U" -ctl true -command ("MagmaEditor_SelectUnconnectedNodes "+$prtNode+";"); menuItem -label "Select All Inputs" -ke "I" -alt true -ctl true -command ("MagmaEditor_SelectInputNodes "+$prtNode+";"); menuItem -label "Select All Outputs" -ke "O" -alt true -ctl true -command ("MagmaEditor_SelectOutpuNodes "+$prtNode+";"); menuItem -divider true; menuItem -label "Swap 1st and 2nd Input Sockets" -ke "W" -ctl true -command ("MagmaSwapInputSockets "+$prtNode+" 0;"); menuItem -label "Swap 2nd and 3rd Input Sockets" -ke "W" -ctl true -sh true -command ("MagmaSwapInputSockets "+$prtNode+" 1;"); menuItem -divider true; menuItem -label "Use Crossing Selection Method" -cb false -command ("MagmaEditor_SetSelectionModeWindowCrossing "+$prtNode+";") ($prtNode+"_selectionModeCrossing"); menu -label "View"; menuItem -label "Cycle Reorder Mode" -ctl true -ke "R" -command ("MagmaEditor_CycleReorderMode "+$prtNode +" 1;"); menuItem -label "Order Unconnected Nodes at the Bottom" -cb true -command ("MagmaNodesReorderGrid "+$prtNode + ";") ($prtNode+"_mnu_unconnectedNodesAtBottom"); menuItem -divider true; menuItem -label "Show Grid" -cb true -command ("MagmaEditor_ToggleSnapToGrid "+$prtNode + ";") ($prtNode+"_mnu_toggleShowGrid"); menuItem -label "Snap To Grid" -cb true -command ("MagmaEditor_ToggleSnapToGrid "+$prtNode + ";") ($prtNode+"_mnu_toggleSnapToGrid"); menuItem -divider true; menuItem -label "Reset Pan And Zoom" -ke "Z" -ctl true -sh true -enable true -command ("magma_flux_window_set -prt "+$prtNode+" -cx 0.0 -cy 0.0;magma_flux_window_set -prt "+$prtNode+" -z 1.0;"); menuItem -label "Reset Pan" -ke "P" -command ("magma_flux_window_set -prt "+$prtNode+" -cx 0.0 -cy 0.0;"); menuItem -label "Reset Zoom" -ke "Z" -command ("magma_flux_window_set -prt "+$prtNode+" -z 1.0;"); /*menuItem -divider true; menuItem -label "Zoom Extents" -enable false; menuItem -label "Zoom Selected" -enable false;*/ menu -label "Colors"; menuItem -label "'Default Dark' Theme" -command ("MagmaEditor_SetColorTheme "+$prtNode + " 0;"); menuItem -label "'Neon In The Dark' Theme" -command ("MagmaEditor_SetColorTheme "+$prtNode + " 1;"); menuItem -label "'Dark Monopoly' Theme" -command ("MagmaEditor_SetColorTheme "+$prtNode + " 2;"); menuItem -label "'Krakatoa MX' Light Theme" -command ("MagmaEditor_SetColorTheme "+$prtNode + " 3;"); menuItem -label "'Low Contrast' Light Theme" -command ("MagmaEditor_SetColorTheme "+$prtNode + " 4;"); menuItem -divider true; //menuItem -label "Color Theme Options" -subMenu true; menuItem -label "Dark Background Colors" -cb true -command ("MagmaEditor_UpdateColorScheme "+$prtNode + " 1;") ($prtNode+"_mnu_useDarkBackgroundColor"); menuItem -divider true; menuItem -label "Dark Node Colors" -cb false -command ("MagmaEditor_UpdateColorScheme "+$prtNode +" 1;") ($prtNode+"_mnu_useDarkNodeBackgroundColors"); menuItem -label "Dark Node Outline Colors" -cb false -command ("MagmaEditor_UpdateColorScheme "+$prtNode +" 1;") ($prtNode+"_mnu_useDarkNodeOutlineColors"); menuItem -label "High Contrast Node Outlines" -cb false -command ("MagmaEditor_UpdateColorScheme "+$prtNode +" 1;") ($prtNode+"_mnu_drawHighContrastNodeOutlines"); menuItem -divider true; menuItem -label "Dark Node Header Colors" -cb true -command ("MagmaEditor_UpdateColorScheme "+$prtNode +" 1;") ($prtNode+"_mnu_useDarkNodeHeaderColors"); menuItem -label "Dark Node Title Colors" -cb false -command ("MagmaEditor_UpdateColorScheme "+$prtNode +" 1;") ($prtNode+"_mnu_useDarkNodeTitleColors"); menuItem -label "High Contrast Node Titles" -cb true -command ("MagmaEditor_UpdateColorScheme "+$prtNode +" 1;") ($prtNode+"_mnu_drawHighContrastNodeTitles"); menuItem -divider true; menuItem -label "Saturated Socket Colors" -cb true -command ("MagmaEditor_UpdateColorScheme "+$prtNode +" 1;") ($prtNode+"_mnu_useSaturatedSocketColors"); menuItem -label "Dark Socket Outline Colors" -cb true -command ("MagmaEditor_UpdateColorScheme "+$prtNode +" 1;") ($prtNode+"_mnu_useDarkSocketOutlineColors"); menuItem -divider true -subMenu false; menuItem -label "SAVE Color Scheme..." -command ("MagmaEditor_SaveNamedColorScheme "+$prtNode+";"); menuItem -label "LOAD Color Scheme..." -command ("MagmaEditor_LoadNamedColorScheme "+$prtNode+";"); menu -label "Help"; menuItem -label "Online Help..." -command ("launch -webPage \"https://docs.thinkboxsoftware.com/products/krakatoa/2.12/1_Documentation/manual/kmy/magma/kmy_magma_editor.html\";"); menuItem -divider true; menuItem -label "About..." -command ("AboutMagmaFLUXDialog();"); setParent ..; rowLayout -nc 2 buttonPanel2; //-w 300 checkBox -label "" -v 1 -cc ("MagmaEditor_ForceUpdate "+$prtNode+";") chk_autoUpdate; button -label "&U P D A T E" -h 20 -command ("KMY_forceObjectReevaluate " + $prtNode + ";"); setParent ..; formLayout -e -attachForm buttonPanel2 "right" 425 $windowLayout; rowLayout -nc 4 insertReorderPanel; //text -label " " -visible false; checkBox -label "" -width 1 -visible false -value true ($prtNode+"_chk_enableUpdatesAndReoderCalls"); //this is a hidden control which holds the state of internal flag whether to update and reorder or not (speed up hack) checkBox -label "" -width 1 -visible false -value true ($prtNode+"_chk_enableCallbacks"); //this is a hidden control which holds the state of internal flag whether to run callback functions (prevents errors during file loading) optionMenu -label "" -cc "" ($prtNode+"_ddl_MagmaInsertBranchControl"); menuItem -label "Insert"; menuItem -label "Branch"; optionMenu -label "" -cc ("MagmaNodesReorderGrid "+$prtNode +";") ($prtNode+"_ddl_MagmaAutoReorderControl"); menuItem -label "Manual"; menuItem -label "Branches"; menuItem -label "Blocks"; menuItem -label "Compact"; setParent ..; // Set up control panel //rowLayout -nc 14 buttonPanel; int $menuwidth = 700; string $osName = `about -os`; if( `substring $osName 1 3` == "win" ) $menuwidth = 610; //slightly hacky, but this allows Windows' Magma Editor to be a bit smaller if desired. Linux/OSX fonts are wider... menuBarLayout -w $menuwidth -h 20 nodesmenubar; menu -label "&INPUT"; menuItem -label "Input&Channel" -ke "C" -command ("AddNewMagmaInputChannelToFlow \"Color\" \"Vec3\" "+$prtNode + " 0 0 1 on on -1 -1;") -subMenu true; menuItem -label "A&bsorption" -ke "B" -command ("AddNewMagmaInputChannelToFlow \"Absorption\" \"Vec3\" "+$prtNode + " 0 0 1 on on -1 -1;"); menuItem -label "&Age" -ke "A" -command ("AddNewMagmaInputChannelToFlow \"Age\" \"Float\" "+$prtNode + " 0 0 1 on on -1 -1;"); menuItem -label "&Color" -ke "C" -command ("AddNewMagmaInputChannelToFlow \"Color\" \"Vec3\" "+$prtNode + " 0 0 1 on on -1 -1;"); menuItem -label "&Density" -ke "D" -command ("AddNewMagmaInputChannelToFlow \"Density\" \"Float\" "+$prtNode + " 0 0 1 on on -1 -1;"); menuItem -label "&Emission" -ke "E" -command ("AddNewMagmaInputChannelToFlow \"Emission\" \"Vec3\" "+$prtNode + " 0 0 1 on on -1 -1;"); menuItem -label "&ID" -ke "I" -command ("AddNewMagmaInputChannelToFlow \"ID\" \"Int\" "+$prtNode + " 0 0 1 on on -1 -1;"); menuItem -label "Inde&x" -ke "X" -command ("AddNewMagmaInputChannelToFlow \"Index\" \"Int\" "+$prtNode + " 0 0 1 on on -1 -1;"); menuItem -label "&LifeSpan" -ke "L" -command ("AddNewMagmaInputChannelToFlow \"LifeSpan\" \"Float\" "+$prtNode + " 0 0 1 on on -1 -1;"); menuItem -label "&Normal" -ke "N" -command ("AddNewMagmaInputChannelToFlow \"Normal\" \"Vec3\" "+$prtNode + " 0 0 1 on on -1 -1;"); menuItem -label "&Orientation" -ke "O" -command ("AddNewMagmaInputChannelToFlow \"Orientation\" \"Quat\" "+$prtNode + " 0 0 1 on on -1 -1;"); menuItem -label "&Position" -ke "P" -command ("AddNewMagmaInputChannelToFlow \"Position\" \"Vec3\" "+$prtNode + " 0 0 1 on on -1 -1;"); menuItem -label "&TextureCoord" -ke "T" -command ("AddNewMagmaInputChannelToFlow \"TextureCoord\" \"Vec3\" "+$prtNode + " 0 0 1 on on -1 -1;"); menuItem -label "&Velocity" -ke "V" -command ("AddNewMagmaInputChannelToFlow \"Velocity\" \"Vec3\" "+$prtNode + " 0 0 1 on on -1 -1;"); setParent -menu ..; menuItem -divider true; menuItem -label "Input&Geometry" -ke "G" -command ("AddNewMagmaInputGeometryToFlow " + $prtNode + " 0 0 on on;"); menuItem -divider true; menuItem -label "Input&Particles" -ke "P" -command ("AddNewMagmaInputParticlesToFlow " + $prtNode + " 0 0 on on;"); menuItem -divider true; menuItem -label "Input&Object" -ke "O" -command ("AddNewMagmaInputObjectToFlow " + $prtNode + " 0 0 on on;"); menuItem -divider true; menuItem -label "Input&Value" -ke "V" -command ("AddNewMagmaInputValueFloatToFlow 0.0 "+$prtNode + " 0 0 on on -1 -1;") -subMenu true; menuItem -label "&Float" -ke "F" -command ("AddNewMagmaInputValueFloatToFlow 0.0 "+$prtNode + " 0 0 on on -1 -1;"); menuItem -label "&Integer" -ke "I" -command ("AddNewMagmaInputValueIntToFlow 0 "+$prtNode + " 0 0 on on -1 -1;"); menuItem -label "&Vector" -ke "V" -command ("AddNewMagmaInputValueVectorToFlow 0.0 0.0 0.0 "+$prtNode + " 0 0 on on -1 -1;"); setParent -menu ..; menu -label "&Arithmetic"; for( $i = 0; $i < `size $ArithmeticItems`; $i+=3 ) menuItem -label $ArithmeticItems[$i+1] -ke $ArithmeticItems[$i+2] -command ("AddNewMagmaOperatorToFlow \"" + $ArithmeticItems[$i] + "\" " + $prtNode + " 0 0 on on;"); menu -label "&Convert"; for( $i = 0; $i < `size $ConvertItems`; $i+=3 ) menuItem -label $ConvertItems[$i+1] -ke $ConvertItems[$i+2] -command ("AddNewMagmaOperatorToFlow \"" + $ConvertItems[$i] + "\" " + $prtNode + " 0 0 on on;"); menu -label "&Function"; for( $i = 0; $i < `size $FunctionItems`; $i+=3 ) menuItem -label $FunctionItems[$i+1] -ke $FunctionItems[$i+2] -command ("AddNewMagmaOperatorToFlow \"" + $FunctionItems[$i] + "\" " + $prtNode + " 0 0 on on;"); menu -label "&Logic"; for( $i = 0; $i < `size $LogicItems`; $i+=3 ) menuItem -label $LogicItems[$i+1] -ke $LogicItems[$i+2] -command ("AddNewMagmaOperatorToFlow \"" + $LogicItems[$i] + "\" " + $prtNode + " 0 0 on on;"); /* button -label "Loops"; popupMenu -button 1; for( $item in $LoopsItems ) menuItem -label $item -command ("AddNewMagmaOperatorToFlow \"" + $item + "\" " + $prtNode + " on on;"); */ menu -label "&Object"; for( $i = 0; $i < `size $ObjectItems`; $i+=3 ) menuItem -label $ObjectItems[$i+1] -ke $ObjectItems[$i+2] -command ("AddNewMagmaOperatorToFlow \"" + $ObjectItems[$i] + "\" " + $prtNode + " 0 0 on on;"); /* button -label "System"; popupMenu -button 1; for( $item in $SystemItems ) menuItem -label $item -command ("AddNewMagmaOperatorToFlow \"" + $item + "\" " + $prtNode + " on on;"); */ menu -label "&Transform"; for( $i = 0; $i < `size $TransformItems`; $i+=3 ) menuItem -label $TransformItems[$i+1] -ke $TransformItems[$i+2] -command ("AddNewMagmaOperatorToFlow \"" + $TransformItems[$i] + "\" " + $prtNode + " 0 0 on on;"); menu -label "T&rigonometry"; for( $i = 0; $i < `size $TrigonometryItems`; $i+=3 ) menuItem -label $TrigonometryItems[$i+1] -ke $TrigonometryItems[$i+2] -command ("AddNewMagmaOperatorToFlow \"" + $TrigonometryItems[$i] + "\" " + $prtNode + " 0 0 on on;"); menu -label "&Vector"; for( $i = 0; $i < `size $VectorsItems`; $i+=3 ) menuItem -label $VectorsItems[$i+1] -ke $VectorsItems[$i+2] -command ("AddNewMagmaOperatorToFlow \"" + $VectorsItems[$i] + "\" " + $prtNode + " 0 0 on on;"); menu -label "OUT&PUT"; menuItem -label "A&bsorption" -ke "B" -command ("AddNewMagmaOutputChannelToFlow \"Absorption\" \"Vec3\" "+$prtNode + " 0 0;"); menuItem -label "&Age" -ke "A" -command ("AddNewMagmaOutputChannelToFlow \"Age\" \"Float\" "+$prtNode + " 0 0;"); menuItem -label "&Color" -ke "C" -command ("AddNewMagmaOutputChannelToFlow \"Color\" \"Vec3\" "+$prtNode + " 0 0;"); menuItem -label "&Density" -ke "D" -command ("AddNewMagmaOutputChannelToFlow \"Density\" \"Float\" "+$prtNode + " 0 0;"); menuItem -label "&Emission" -ke "E" -command ("AddNewMagmaOutputChannelToFlow \"Emission\" \"Vec3\" "+$prtNode + " 0 0;"); menuItem -label "&ID" -ke "I" -command ("AddNewMagmaOutputChannelToFlow \"ID\" \"Int\" "+$prtNode + " 0 0;"); menuItem -label "&LifeSpan" -ke "L" -command ("AddNewMagmaOutputChannelToFlow \"LifeSpan\" \"Float\" "+$prtNode + " 0 0;"); menuItem -label "&Normal" -ke "N" -command ("AddNewMagmaOutputChannelToFlow \"Normal\" \"Vec3\" "+$prtNode + " 0 0;"); menuItem -label "&Orientation" -ke "O" -command ("AddNewMagmaOutputChannelToFlow \"Orientation\" \"Quat\" "+$prtNode + " 0 0;"); menuItem -label "&Position" -ke "P" -command ("AddNewMagmaOutputChannelToFlow \"Position\" \"Vec3\" "+$prtNode + " 0 0;"); menuItem -label "&TextureCoord" -ke "T" -command ("AddNewMagmaOutputChannelToFlow \"TextureCoord\" \"Vec3\" "+$prtNode + " 0 0;"); menuItem -label "&Velocity" -ke "V" -command ("AddNewMagmaOutputChannelToFlow \"Velocity\" \"Vec3\" "+$prtNode + " 0 0;"); setParent ..; formLayout -e -attachForm nodesmenubar "bottom" 0 -attachForm nodesmenubar "left" 0 -attachForm insertReorderPanel "bottom" 0 -attachForm insertReorderPanel "right" 425 $windowLayout; // Set up the magmaFLUX gui paneLayout fluxForm; // paneLayout lets the window auto stretch add_magma_flux_window -ln fluxForm -prt $prtNode -wn $windowName; setParent ..; //attach all 4 sides of the MagmaFLUX form to the windowLayout formLayout -e -attachForm fluxForm "top" 20 -attachForm fluxForm "left" 0 -attachForm fluxForm "right" 425 -attachForm fluxForm "bottom" 20 $windowLayout; setParent ..; global string $gMainWindow; int $mainTopLeft[] = `window -q -tlc $gMainWindow`; window -e -resizeToFitChildren true -sizeable true -title ("Krakatoa Magma Editor (" + $prtNode + ")") -tlc ( $mainTopLeft[0] + 50 ) ( $mainTopLeft[1] + 50 ) $windowName; MagmaEditor_LoadColorScheme $prtNode ""; MagmaFLUX_resetSelection $prtNode {}; MagmaEditor_ClearUndoRecords $prtNode ; MagmaEditor_CreateUndoRecord $prtNode ("New Magma Editor Session"); MagmaEditor_UpdateUndoRedoInfo $prtNode ; MagmaEditor_UpdateColorScheme $prtNode 0; MagmaEditor_DefineRightClickMenu $prtNode "All" "MagmaEditor_AllNodesPopupMenu"; // Set Selection mode from CFG file: int $value = (`MagmaEditor_getIniKey "KrakatoaMagmaSettings" "SelectionModeCrossing" "1"`); menuItem -e -cb ((int)$value) ($prtNode+"_selectionModeCrossing"); magma_flux_window_set -prt $prtNode -sm ((int)$value); // EVENT CALLBACK SCRIPTS: scriptJob -parent $windowName -kws -e "timeChanged" ("MagmaEditor_ForceUpdate " + $prtNode); //auto-update when time slider changed. scriptJob -parent $windowName -e "NewSceneOpened" ("deleteUI -window "+$windowName); //close Editor on File>New or Open. } global proc MagmaEditor_CycleInsertBranchMode (string $prtNode) { int $insertbranch = `optionMenu -q -select ($prtNode+"_ddl_MagmaInsertBranchControl")`; if ($insertbranch == 1) { optionMenu -e -select 2 ($prtNode+"_ddl_MagmaInsertBranchControl"); } else { optionMenu -e -select 1 ($prtNode+"_ddl_MagmaInsertBranchControl"); } } global proc MagmaEditor_CycleReorderMode (string $prtNode, int $increment) { checkBox -e -v true ($prtNode+"_chk_enableUpdatesAndReoderCalls"); //make sure updates are enabled in case something got stuck... if ($increment == 0) { optionMenu -e -select 1 ($prtNode+"_ddl_MagmaAutoReorderControl"); } else { int $reordermode = `optionMenu -q -select ($prtNode+"_ddl_MagmaAutoReorderControl")`; int $numitems = `optionMenu -q -ni ($prtNode+"_ddl_MagmaAutoReorderControl")`; $reordermode = $reordermode + $increment ; if ($reordermode > $numitems) $reordermode = 1; if ($reordermode < 1) $reordermode = $numitems; optionMenu -e -select $reordermode ($prtNode+"_ddl_MagmaAutoReorderControl"); MagmaNodesReorderGrid $prtNode; } } global proc MagmaEditor_ForceUpdate (string $prtNode) { int $autoOn = `checkBox -q -v chk_autoUpdate`; int $enableupdates = `checkBox -q -v ($prtNode+"_chk_enableUpdatesAndReoderCalls")`; if ($autoOn && $enableupdates) { KMY_forceObjectReevaluate $prtNode; MagmaEditor_RepaintSockets $prtNode 1; //repaint selected only } } global proc string MagmaFLUX_ListToString(string $val[]) { string $result = ""; int $first = 1; for ( $v in $val ) { if ( $first ) $first = 0; else $result += ","; $result += $v; } return $result; } global proc string MagmaFLUX_ListToStringSetAttr(string $val[]) { string $result = `size $val`; for ( $v in $val ) { $result += " "; $result += ("\"" + $v + "\""); } return $result; } global proc string[] MagmaFLUX_StringToList(string $val) { string $result[]; tokenize $val ", " $result; // If the string contains nothing of interest, return an empty array if ( `size $result` == 1 ) if( $result[0] == "" ) return {}; return $result; } global proc MagmaFLUX_addAttributeOption(string $prtNode, string $spinner, string $attr, string $attrName, string $attrType, int $showLabel, string $type, int $id ) { $attrType = `tolower $attrType`; int $rowWidth = 425; int $inputWidth = $rowWidth - 110; rowLayout -width $rowWidth -nc 3 -cw 20 1; if( $showLabel ) { text -label (`interToUI ($attrName)`) -width 85 -h 20 -al "right" ; } if( $attrType == "bool" ) { /*print $attrName; print "BOOL\n";*/ checkBox -w $inputWidth -label "" -enable on -cc ("MagmaEditor_ForceUpdate "+$prtNode+"; MagmaEditor_UpdateColorScheme "+$prtNode+" 0;") $spinner; connectControl $spinner ($prtNode + "." + $attr); } else if( $attrType == "int" ) { intField -w ($inputWidth - 10) -value 0 -cc ("MagmaEditor_ForceUpdate "+$prtNode+";") $spinner; connectControl $spinner ($prtNode + "." + $attr); } else if( $attrType == "float" ) { if ( `getApplicationVersionAsFloat` > 2012 ) floatField -w ($inputWidth - 10) -value 0 -cc ("MagmaEditor_ForceUpdate "+$prtNode+";") -s 0.1 $spinner ; else floatField -w ($inputWidth - 10) -value 0 -cc ("MagmaEditor_ForceUpdate "+$prtNode+";") $spinner ; connectControl $spinner ($prtNode + "." + $attr); } else if( $attrType == "string" ) //Add "magmadatatype" as well? { textField -w $inputWidth -text "" $spinner; connectControl $spinner ($prtNode + "." + $attr); } else if( $attrType == "vector3f" || $attrType == "vec3" ) { if ( `getApplicationVersionAsFloat` > 2012 ) floatFieldGrp -w ($inputWidth - 70) -numberOfFields 3 -value1 0 -value2 0 -value3 0 -pre 3 -cc ("MagmaEditor_ForceUpdate "+$prtNode+";") -s 0.1 $spinner; else floatFieldGrp -w ($inputWidth - 70) -numberOfFields 3 -value1 0 -value2 0 -value3 0 -pre 3 -cc ("MagmaEditor_ForceUpdate "+$prtNode+";") $spinner; connectControl $spinner -index 1 ($prtNode + "." + $attr + "0"); connectControl $spinner -index 2 ($prtNode + "." + $attr + "1"); connectControl $spinner -index 3 ($prtNode + "." + $attr + "2"); //attrColorSliderGrp -w $inputWidth -rgbValue 0 0 0 ($spinner+"_Color"); button -label "As Color..." -command ( "$prtNode = \"" + $prtNode + "\";" + "$attr = \"" + $attr + "\";" + "$v0 = `getAttr ($prtNode + \".\" + $attr + \"0\")`;" + "$v1 = `getAttr ($prtNode + \".\" + $attr + \"1\")`;" + "$v2 = `getAttr ($prtNode + \".\" + $attr + \"2\")`;" + "colorEditor -rgb $v0 $v1 $v2;" + "if ( `colorEditor -query -result` ) {" + "float $values[] = `colorEditor -query -rgb`;" + "setAttr ($prtNode + \".\" + $attr + \"0\") $values[0];" + "setAttr ($prtNode + \".\" + $attr + \"1\") $values[1];" + "setAttr ($prtNode + \".\" + $attr + \"2\") $values[2];" + "MagmaEditor_ForceUpdate $prtNode;\n" + "}" ); } else if( $attrType == "quat" ) { floatFieldGrp -w $inputWidth -numberOfFields 4 -value1 0 -value2 0 -value3 0 -value4 0 $spinner; connectControl $spinner -index 1 ($prtNode + "." + $attr + "_real"); connectControl $spinner -index 2 ($prtNode + "." + $attr + "_imaginary0"); connectControl $spinner -index 3 ($prtNode + "." + $attr + "_imaginary1"); connectControl $spinner -index 4 ($prtNode + "." + $attr + "_imaginary2"); } else if( ( $type == "FaceQuery" || $type == "VertexQuery" || $type == "ParticleQuery" || $type == "ParticleSumCount" || $type == "ParticleSumRadius" ) && $attrType == "stringlist" ) { //columnLayout -width 390 -cw 1; string $nodeattr = ($prtNode + "." + $attr); string $fieldchangecmd = ( "string $prtNode = \"" + $prtNode + "\";\n" + "string $nodeattr = \"" + $nodeattr + "\";\n" + "string $text = \"#1\";\n" + "string $resultArray[] = `getAttr $nodeattr`;\n" + "if ((`stringArrayFindWrapper $text 0 $resultArray`)==-1){\n" + " $resultArray[`size $resultArray`] = $text ;\n" + " textScrollList -e -ra $spinner;\n" + " for ($i=0; $i<`size $resultArray`;$i++) textScrollList -e -append $resultArray[$i] $spinner;\n"+ " string $setAttrArgs = `MagmaFLUX_ListToStringSetAttr $resultArray`;\n" + " eval(\"setAttr $nodeattr -type \\\"stringArray\\\" \" + $setAttrArgs + \"\");\n" + " MagmaEditor_ForceUpdate $prtNode;\n" + " MagmaEditor_RepaintSockets $prtNode 0;\n" + "textField -e -text \"\" (\"txt_\"+$spinner);\n}\n" ); string $possibleChannels; if ($type == "FaceQuery" ) $possibleChannels = "{\"FaceNormal\",\"Normal\",\"TextureCoord\",\"map1\"}"; if ($type == "VertexQuery" ) $possibleChannels = "{\"Normal\",\"TextureCoord\",\"map1\"}"; if ($type == "ParticleQuery" || $type == "ParticleSumCount" || $type == "ParticleSumRadius" ) $possibleChannels = "{\"Position\",\"Velocity\",\"Density\",\"Normal\",\"Tangent\",\"Color\",\"Emission\",\"Absorption\",\"Age\",\"LifeSpan\"}"; string $attrchangecmd = ( "string $nodeattr = \"" + $nodeattr + "\";\n" + "string $spinner = \"" + $spinner + "\";\n" + "string $resultArray[] = `getAttr $nodeattr`;\n" + "textScrollList -e -ra $spinner;\n" + "for ($i=0; $i<`size $resultArray`;$i++) textScrollList -e -append $resultArray[$i] $spinner;\n"+ "string $possibleChannels[] = "+ $possibleChannels + "; \n" + "for ($i=0; $i<`size $possibleChannels`;$i++) if ((`stringArrayFindWrapper $possibleChannels[$i] 0 $resultArray`)==-1) textScrollList -e -append $possibleChannels[$i] (\"lst_\"+$spinner);\n" + "textScrollList -e -sii 1 $spinner;\n" + "textScrollList -e -sii 1 (\"lst_\"+$spinner);\n" ); string $exposechannelcmd = ( "string $prtNode = \"" + $prtNode + "\";\n" + "string $spinner = \"" + $spinner + "\";\n" + "string $nodeattr = \"" + $nodeattr + "\";\n" + "string $currentchannelname[] = `textScrollList -q -si (\"lst_\"+$spinner)`; \n" + "int $currentchannelindex[] = `textScrollList -q -sii (\"lst_\"+$spinner)`; \n" + "string $allItems[] = `textScrollList -q -ai $spinner`;\n" + "if ($currentchannelindex[0] > 0 && (`stringArrayFindWrapper $currentchannelname[0] 0 $allItems`)==-1){\n" + " textScrollList -e -rii $currentchannelindex[0] (\"lst_\"+$spinner); \n" + " $allItems[`size $allItems`] = $currentchannelname[0];\n" + " string $setAttrArgs = `MagmaFLUX_ListToStringSetAttr $allItems`;\n" + " eval(\"setAttr $nodeattr -type \\\"stringArray\\\" \" + $setAttrArgs + \"\");\n" + " textScrollList -e -ra $spinner;\n" + " for ($i=0; $i<`size $allItems`;$i++) textScrollList -e -append $allItems[$i] $spinner;\n" + " textScrollList -e -sii (`textScrollList -q -ni $spinner`) $spinner;\n" + " MagmaEditor_ForceUpdate $prtNode;\n" + " MagmaEditor_RepaintSockets $prtNode 0;\n }\n" ); string $removechannelcmd = ( "$prtNode = \"" + $prtNode + "\";\n" + "string $spinner = \"" + $spinner + "\";\n" + "string $nodeattr = \"" + $nodeattr + "\";\n" + "string $currentchannelname[] = `textScrollList -q -si $spinner`; \n" + "int $currentchannelindex[] = `textScrollList -q -sii $spinner`; \n" + "if ($currentchannelindex[0] > 0) {\n" + " textScrollList -e -rii $currentchannelindex[0] $spinner;\n" + " string $allItems[] = `textScrollList -q -ai $spinner`;\n" + " string $setAttrArgs = `MagmaFLUX_ListToStringSetAttr $allItems`;\n" + " eval(\"setAttr $nodeattr -type \\\"stringArray\\\" \" + $setAttrArgs + \"\");\n" + " textScrollList -e -append $currentchannelname[0] (\"lst_\"+$spinner); \n" + " textScrollList -e -sii (`textScrollList -q -ni (\"lst_\"+$spinner)`) (\"lst_\"+$spinner);\n" + " MagmaEditor_ForceUpdate $prtNode;\n" + " MagmaEditor_RepaintSockets $prtNode 0;\n}\n" ); columnLayout -width 390 -cw 1; rowLayout -width 390 -nc 2 -cw 160 1 ; //text -label "Custom Channel:" -w 160; textField -text "Enter Custom Channel:" -w 150 -enable false; textField -text "" -w 150 -cc $fieldchangecmd ("txt_"+$spinner); setParent ..; rowLayout -width 390 -nc 2 -cw 160 1 ; textScrollList -w 150 -h 82 -numberOfRows 4 -allowMultiSelection false -dcc $exposechannelcmd ("lst_"+$spinner); textScrollList -w 150 -h 82 -numberOfRows 4 -allowMultiSelection false -dcc $removechannelcmd $spinner; setParent ..; rowLayout -width 390 -nc 2 -cw 150 1; button -label "EXPOSE Channel >>" -w 150 -command $exposechannelcmd; button -label "<< REMOVE Channel" -w 150 -command $removechannelcmd; setParent ..; setParent ..; //scriptJob -parent $spinner -attributeChange $nodeattr ( $attrchangecmd ); eval $attrchangecmd; //Update the current value } else if( $type == "PropertyQuery" && $attrType == "stringlist" ) { //columnLayout -width 390 -cw 1; string $nodeattr = ($prtNode + "." + $attr); string $fieldchangecmd = ( "string $prtNode = \"" + $prtNode + "\";\n" + "string $nodeattr = \"" + $nodeattr + "\";\n" + "string $text = \"#1\";\n" + "string $resultArray[] = `getAttr $nodeattr`;\n" + "if ((`stringArrayFindWrapper $text 0 $resultArray`)==-1){\n" + " $resultArray[`size $resultArray`] = $text ;\n" + " textScrollList -e -ra $spinner;\n" + " for ($i=0; $i<`size $resultArray`;$i++) textScrollList -e -append $resultArray[$i] $spinner;\n"+ " string $setAttrArgs = `MagmaFLUX_ListToStringSetAttr $resultArray`;\n" + " eval(\"setAttr $nodeattr -type \\\"stringArray\\\" \" + $setAttrArgs + \"\");\n" + " MagmaEditor_ForceUpdate $prtNode;\n" + " MagmaEditor_RepaintSockets $prtNode 0;\n" + "textField -e -text \"\" (\"txt_\"+$spinner);\n}\n" ); string $possibleProperties = "{}"; int $existingConnection[] = `get_magma_connections -prt $prtNode -id $id`; if ($existingConnection[0] > -1) { string $sourceType = `retrieve_magma_node_instance_info -id $existingConnection[0] -prt $prtNode -type true`; if ($sourceType == "InputObject" || $sourceType == "InputGeometry") { string $sourceObject[] = {}; int $objIndex = -1; if($sourceType == "InputObject") { string $sourceObjTemp = `getAttr ($prtNode+".InputObject_"+$existingConnection[0]+"_Property1_objectName_String")`; $sourceObject[0] = $sourceObjTemp; $objIndex = 0; } else { $sourceObject = `getAttr ($prtNode+".InputGeometry_"+$existingConnection[0]+"_Property1_geometryNames_StringList")`; if ($existingConnection[1] > -1) { $objIndex = 0; } } if (`size $sourceObject` > 0 && $sourceObject[0] != "") { string $attrList[] = `listAttr $sourceObject[0]`; $possibleProperties = "{"; int $notFirst = 0; for ($i=0; $i < `size $attrList`; $i++) { if (eval ("objExists "+$sourceObject[0]+"."+$attrList[$i]) ) { string $valueType = ""; if (catch($valueType= eval ("getAttr -type "+$sourceObject[0]+"."+$attrList[$i]))) { print "// MAGMA: Failed to access attribute type of ["; print $attrList[$i]; print "]\n"; } // print ($attrList[$i] + " = " + $valueType + "\n"); if ($valueType != "message" && $valueType != "string" && $valueType != "enum" && $valueType != "mesh") { if ($notFirst) $possibleProperties += ","; $possibleProperties += "\""+ $attrList[$i] +"\""; $notFirst = 1; } } } $possibleProperties += "}"; } } } string $attrchangecmd = ( "string $nodeattr = \"" + $nodeattr + "\";\n" + "string $spinner = \"" + $spinner + "\";\n" + "string $resultArray[] = `getAttr $nodeattr`;\n" + "textScrollList -e -ra $spinner;\n" + "for ($i=0; $i<`size $resultArray`;$i++) textScrollList -e -append $resultArray[$i] $spinner;\n"+ "string $possibleProperties[] = "+ $possibleProperties + "; \n" + "for ($i=0; $i<`size $possibleProperties`;$i++) if ((`stringArrayFindWrapper $possibleProperties[$i] 0 $resultArray`)==-1) textScrollList -e -append $possibleProperties[$i] (\"lst_\"+$spinner);\n" + "textScrollList -e -sii 1 $spinner;\n" + "textScrollList -e -sii 1 (\"lst_\"+$spinner);\n" ); string $exposechannelcmd = ( "string $prtNode = \"" + $prtNode + "\";\n" + "string $spinner = \"" + $spinner + "\";\n" + "string $nodeattr = \"" + $nodeattr + "\";\n" + "string $currentchannelname[] = `textScrollList -q -si (\"lst_\"+$spinner)`; \n" + "int $currentchannelindex[] = `textScrollList -q -sii (\"lst_\"+$spinner)`; \n" + "string $allItems[] = `textScrollList -q -ai $spinner`;\n" + "if ($currentchannelindex[0] > 0 && (`stringArrayFindWrapper $currentchannelname[0] 0 $allItems`)==-1){\n" + " textScrollList -e -rii $currentchannelindex[0] (\"lst_\"+$spinner); \n" + " $allItems[`size $allItems`] = $currentchannelname[0];\n" + " string $setAttrArgs = `MagmaFLUX_ListToStringSetAttr $allItems`;\n" + " eval(\"setAttr $nodeattr -type \\\"stringArray\\\" \" + $setAttrArgs + \"\");\n" + " textScrollList -e -ra $spinner;\n" + " for ($i=0; $i<`size $allItems`;$i++) textScrollList -e -append $allItems[$i] $spinner;\n" + " textScrollList -e -sii (`textScrollList -q -ni $spinner`) $spinner;\n" + " MagmaEditor_ForceUpdate $prtNode;\n" + " MagmaEditor_RepaintSockets $prtNode 0;\n }\n" ); string $removechannelcmd = ( "$prtNode = \"" + $prtNode + "\";\n" + "string $spinner = \"" + $spinner + "\";\n" + "string $nodeattr = \"" + $nodeattr + "\";\n" + "string $currentchannelname[] = `textScrollList -q -si $spinner`; \n" + "int $currentchannelindex[] = `textScrollList -q -sii $spinner`; \n" + "if ($currentchannelindex[0] > 0) {\n" + " textScrollList -e -rii $currentchannelindex[0] $spinner;\n" + " string $allItems[] = `textScrollList -q -ai $spinner`;\n" + " string $setAttrArgs = `MagmaFLUX_ListToStringSetAttr $allItems`;\n" + " eval(\"setAttr $nodeattr -type \\\"stringArray\\\" \" + $setAttrArgs + \"\");\n" + " textScrollList -e -append $currentchannelname[0] (\"lst_\"+$spinner); \n" + " textScrollList -e -sii (`textScrollList -q -ni (\"lst_\"+$spinner)`) (\"lst_\"+$spinner);\n" + " MagmaEditor_ForceUpdate $prtNode;\n" + " MagmaEditor_RepaintSockets $prtNode 0;\n}\n" ); columnLayout -width 390 -cw 1; rowLayout -width 390 -nc 2 -cw 160 1 ; textField -text "Enter Property:" -w 150 -enable false; textField -text "" -w 150 -cc $fieldchangecmd ("txt_"+$spinner); setParent ..; rowLayout -width 390 -nc 2 -cw 160 1 ; textScrollList -w 150 -h 182 -numberOfRows 4 -allowMultiSelection false -dcc $exposechannelcmd ("lst_"+$spinner); textScrollList -w 150 -h 182 -numberOfRows 4 -allowMultiSelection false -dcc $removechannelcmd $spinner; setParent ..; rowLayout -width 390 -nc 2 -cw 150 1; button -label "EXPOSE Property >>" -w 150 -command $exposechannelcmd; button -label "<< REMOVE Property" -w 150 -command $removechannelcmd; setParent ..; setParent ..; //scriptJob -parent $spinner -attributeChange $nodeattr ( $attrchangecmd ); eval $attrchangecmd; //Update the current value } else if( $attrType == "stringlist" ) { //TODO: make this prettier string $nodeattr = ($prtNode + "." + $attr); string $fieldchangecmd = ( "$prtNode = \"" + $prtNode + "\";\n" + "string $nodeattr = \"" + $nodeattr + "\";\n" + "string $text = \"#1\";\n" + "string $resultArray[] = `MagmaFLUX_StringToList $text`;\n" + "string $setAttrArgs = `MagmaFLUX_ListToStringSetAttr $resultArray`;\n" + "eval(\"setAttr $nodeattr -type \\\"stringArray\\\" \" + $setAttrArgs + \"\");\n" + "MagmaEditor_ForceUpdate $prtNode;\n" + "MagmaEditor_RepaintSockets "+$prtNode +" 0\n" ); string $attrchangecmd = ( "string $nodeattr = \"" + $nodeattr + "\";\n" + "string $spinner = \"" + $spinner + "\";\n" + "string $resultArray[] = `getAttr $nodeattr`;\n" + "string $text = `MagmaFLUX_ListToString $resultArray`;\n" + "textField -e -text $text $spinner;\n" ); textField -w $inputWidth -text "" -cc $fieldchangecmd $spinner; scriptJob -parent $spinner -attributeChange $nodeattr ( $attrchangecmd ); eval $attrchangecmd; //Update the current value } else { textField -w $inputWidth -text "" $spinner; connectControl $spinner ($prtNode + "." + $attr); print("//Node Property Unknown type " + $attrType +"\n"); } setParent ..; } global proc int MagmaFLUX_addTypeEnumAttributeOption( string $prtNode, string $spinner, string $attr, string $attrName, string $attributeChoices[], string $enumTabsName ) { int $isCreateEnumTabs = (`size $enumTabsName` > 0); string $tabCmd = ""; // Set up the enum selection changed command int $tabIndex = 1; for( $item in $attributeChoices ) { $tabCmd += "if( \"#1\" == \"" + $item + "\") " + " tabLayout -e -selectTabIndex " + $tabIndex + " " + $enumTabsName + ";\n" + "else "; $tabIndex++; } $tabCmd += ("MagmaEditor_ForceUpdate "+$prtNode+";\n"); $tabCmd += ";\n"; int $currentSelection = -1; int $currentEnum = `getAttr ($prtNode + "." + $attr)`; //Set up the enum choices and combo box rowLayout -width 425 -nc 2 -cw 20 1; if( !$isCreateEnumTabs ) { text -label (`interToUI ($attrName)`) -width 85 -al "right" ; optionMenu -label "" -cc $tabCmd $spinner; } else { optionMenu -label "" -cc $tabCmd -width 85 $spinner; } int $index; int $itemIndex = 1; for( $item in $attributeChoices ) { string $name = `tolower $item`; if( $name == "none" ) $index = 0; else if( $name == "bool" ) $index = 1; else if( $name == "float" ) $index = 2; else if( $name == "int" ) $index = 3; else if( $name == "vec3" ) $index = 4; else if( $name == "quat" ) $index = 5; else { print("//Enum Selection Unknown type " + $item +"\n"); $index = 0; } menuItem -label $item -data $index; if( $currentEnum == $index ) { $currentSelection = $itemIndex; } $itemIndex++; } connectControl $spinner ($prtNode + "." + $attr); //setParent ..; //Ommitted. It is assumed the next properties will be stacked onto this layout return $currentSelection; } global proc string[] MagmaFLUX_getTransformTypes() { //allowed inputType return { "Point", "Vector", "Normal" }; } global proc string[] MagmaFLUX_getChannelTypes() { //allowed channelName return { "", "Position", "Color", "Density", "Emission", "Absorption", "Velocity", "Normal", "Tangent", "TextureCoord", "ID", "Index", "Orientation", "SpecularLevel", "SpecularPower", "Eccentricity", "SpecularGlossiness", "SpecularShift", "Specular2Level", "Specular2Glossiness", "Specular2Shift", "GlintLevel", "GlintSize","GlintGlossiness","DiffuseLevel", "Age", "LifeSpan", "ColorScalar", "RandomValue" }; } global proc string MagmaFLUX_getChannelTypesDataType ( int $index ) { //allowed types per channelName string $types[] = { "Vec3", "Vec3", "Vec3", "Float","Vec3", "Vec3", "Vec3", "Vec3", "Vec3", "Vec3", "Int", "Int", "Quat", "Float", "Float", "Float", "Float", "Float", "Float", "Float", "Float", "Float", "Float", "Float", "Float", "Float", "Float", "Float", "Float" }; return $types[$index]; } global proc string[] MagmaFLUX_getDataTypes() { //allowed channelType return { "Float", "Int", "Vec3", "IVec3", "Quat", "Bool" }; } global proc MagmaEditor_UpdateChannelAttributeList ( string $spinner, string $textfield, string $attr ) { string $attributeChoices[] = MagmaFLUX_getChannelTypes(); string $currentChoice = `textField -q -text $textfield`; int $itemIndex = 1; int $currentChoiceInList = 1; for( $item in $attributeChoices ) { if( $item == $currentChoice ) $currentChoiceInList = $itemIndex; $itemIndex++; } optionMenu -e -select $currentChoiceInList $spinner; eval ("setAttr \"" + $attr + "\" -type \"string\" \""+ $currentChoice +"\";\n"); } global proc MagmaFLUX_addStringEnumAttributeOption( string $prtNode, string $spinner, string $attr, string $attrName, string $attributeChoices[], string $annotation ) { // This is meant to be a work around. Enums are actually for ints but we need to treat strings as an enum // Thus we need to manually set up the attribute connection string $enumCommand = ("setAttr \"" + $prtNode + "." + $attr + "\" -type \"string\" \"#1\";\n"); if ($attrName == "channelName") { string $attr2 = substituteAllString ( $attr, "Property1_channelName_String", "Property2_channelType_MagmaDataType"); //$attr2 = substituteAllString ( $attr2, "_Property1_", "_Property2_"); $enumCommand += ("textField -e -text \"#1\" "+$spinner+"_text;\n"); $enumCommand += ( "string $s[] =`MagmaFLUX_getChannelTypes`;\n"); $enumCommand += ( "int $index = `stringArrayFindWrapper \"#1\" 0 $s`;\n"); $enumCommand += ( "string $newType = `MagmaFLUX_getChannelTypesDataType $index`;\n"); $enumCommand += ( "if ($index > -1) setAttr \"" + $prtNode+"."+ $attr2+"\" -type \"string\" ($newType);\n"); $enumCommand += ( "int $currentChannelType = 4;\n"); $enumCommand += ( "if ($newType == \"Float\") $currentChannelType = 1;\n"); $enumCommand += ( "if ($newType == \"Int\") $currentChannelType = 2;\n"); $enumCommand += ( "if ($newType == \"Vec3\") $currentChannelType = 3;\n"); $enumCommand += ( "tabLayout -e -selectTabIndex ($currentChannelType) (\"spin_"+$attr2 +"_channel_converter\"); \n"); } if ($attrName == "channelType") { $enumCommand += ( "int $currentChannelType = 4;\n"); $enumCommand += ( "if (\"#1\" == \"Float\") $currentChannelType = 1;\n"); $enumCommand += ( "if (\"#1\" == \"Int\") $currentChannelType = 2;\n"); $enumCommand += ( "if (\"#1\" == \"Vec3\") $currentChannelType = 3;\n"); $enumCommand += ( "tabLayout -e -selectTabIndex ($currentChannelType) (\""+$spinner +"_channel_converter\"); \n"); } $enumCommand += ("MagmaEditor_ForceUpdate "+$prtNode+";\n"); string $currentChoice = `getAttr ($prtNode + "." + $attr)`; int $currentChoiceInList = 1; //Set up the enum choices and combo box rowLayout -width 425 -nc 3 -cw 20 1; text -label (`interToUI ($attrName)`) -width 85 -al "right" ; optionMenu -label "" -cc $enumCommand -width 135 -ann $annotation $spinner; int $itemIndex = 1; for( $item in $attributeChoices ) { menuItem -label $item -data $itemIndex; if( $item == $currentChoice ) $currentChoiceInList = $itemIndex; $itemIndex++; } optionMenu -e -select $currentChoiceInList $spinner; if ($attrName == "channelName") { textField -w 170 -text $currentChoice -cc ("MagmaEditor_UpdateChannelAttributeList "+$spinner+" "+$spinner+"_text \""+ ($prtNode+"."+$attr) +"\";") ($spinner+"_text") ; } if ($attrName == "channelType") { textField -w 170 -text $currentChoice -visible false ($spinner+"_text"); } string $jobstring = ("int $itemIndex = 1;" + "string $spinner = \"" + $spinner + "\";" + "string $currentChoice = `getAttr " + ($prtNode + "." + $attr) + "`;" ); if ($attrName == "channelName") $jobstring += "textField -e -text $currentChoice ($spinner+\"_text\"); \n" ; $jobstring += ( "for( $item in `optionMenu -q -ils $spinner` )" + "{" + "$itemName = `menuItem -q -label $item $spinner`;" + "if( $itemName == $currentChoice )" + "{" + "if( `optionMenu -q -select $spinner` != $itemIndex ) {" + "optionMenu -e -select $itemIndex $spinner; \n" + "break;}" + "}" + "$itemIndex++;" + "}" ); scriptJob -parent $spinner -attributeChange ($prtNode + "." + $attr) ( $jobstring ); setParent ..; } global proc MagmaFLUX_addSocketTypeEnumAttributeOption(string $prtNode, string $basename, string $spinner_enum, string $attr_enum, string $attrName_enum, string $socketNumber, string $attributeChoices[], string $type, int $id ) { string $enumChoices[] = $attributeChoices; string $enumTab = ($spinner_enum + "_" + "layout"); int $currentSelection = `MagmaFLUX_addTypeEnumAttributeOption $prtNode $spinner_enum $attr_enum $attrName_enum $enumChoices $enumTab`; tabLayout -tabsVisible false $enumTab; for( $currentType in $attributeChoices ) { if( $currentType == "Vec3" ) $currentType = "Vector3f"; $currentType = `tolower $currentType`; $attr = ($basename + "_" + "InputSocket" + $socketNumber + "_" + $currentType); $spinner = "spin_" + $attr; MagmaFLUX_addAttributeOption($prtNode, $spinner, $attr, $currentType, $currentType, 0, $type, $id ); } // Exit tab form tabLayout -e -selectTabIndex ($currentSelection) $enumTab; setParent ..; // Get out of sub tab setParent ..; // Get out of tab } global proc string[] MagmaFLUX_PropertyTokenizer( string $value ) { string $result[] = {}; string $currentText = ""; int $bracketBalance = 0; for( $i = 1; $i <= `size $value`; $i++ ) { string $currentChar = `substring $value $i $i`; if( $bracketBalance == 0 && $currentChar == "," ) { appendStringArray $result {$currentText} 1; $currentText = ""; } else { if( $currentChar == "[" ) { $bracketBalance++; } else if( $currentChar == "]" ) { $bracketBalance--; } $currentText = ($currentText + $currentChar); } } appendStringArray $result {$currentText} 1; return $result; } global proc MagmaEditor_buildParticleObjectsList (string $prtNode, string $control) { KMY_wrapMayaParticles(); textScrollList -edit -ra $control; // find the particle system the Magma is attached to, so we can skip it string $objType = objectType( $prtNode ); string $list[] = `listConnections -p true -s true -d false ( $prtNode + "." + "inParticleStream" )`; string $entry[]; tokenize $list[0] "." $entry; string $allObjects[] = `ls -typ "PRTFractal" -typ "PRTLoader" -typ "PRTVolume" -typ "PRTSurface" /*-typ "PRTMayaParticle"*/ -typ "particle" -type "nParticle"`; string $anObject; for ($anObject in $allObjects) { // If a node contains a deformed version, skip it if ( `nodeType $anObject` == "particle" || `nodeType $anObject` == "nParticle" ) { string $isDeformed = `KMY_mayaParticleGetDeformed $anObject`; if ( $isDeformed != "" ) continue; } if ($anObject != $entry[0]) textScrollList -edit -append $anObject $control; } } global proc MagmaEditor_buildAllObjectsList (string $prtNode, string $control) { //KMY_wrapMayaParticles(); textScrollList -edit -ra $control; // find the particle system the Magma is attached to, so we can skip it string $objType = objectType( $prtNode ); string $list[] = `listConnections -p true -s true -d false ( $prtNode + "." + "inParticleStream" )`; string $entry[]; tokenize $list[0] "." $entry; string $allObjects[] = `ls -o`; string $anObject; for ($anObject in $allObjects) { textScrollList -edit -append $anObject $control; } } global proc MagmaEditor_updateParticleObjectsListSelection (string $control, string $text) { textScrollList -e -da $control; string $allItems[] = `textScrollList -q -ai $control`; int $index = stringArrayFindWrapper( $text, 0, $allItems ); if ($index > -1) { textScrollList -e -si $text $control; if ($index > 0) textScrollList -e -showIndexedItem $index $control; } } global proc int MagmaFLUX_parseMagmaNodeInfoProperty( string $infoBuffer[], string $basename, string $out_attributeNames[], string $out_attributeFullNames[], string $out_attributeTypes[] ) { int $count = 0; for( $currentInfo in $infoBuffer ) { string $currentInfoBuffer[] = `MagmaFLUX_PropertyTokenizer $currentInfo`; string $attributeNameBuffer[]; tokenize $currentInfoBuffer[0] ":" $attributeNameBuffer; string $attributeNumber = $attributeNameBuffer[0]; string $attributeName = $attributeNameBuffer[1]; string $attributeType = $currentInfoBuffer[1]; //// Ignore Enabled/Disabled attribute //if( $attributeNumber == 0 ) continue; //// Convert "MagmaDataType" //string $attributeTypeName; //if( $attributeType == "MagmaDataType" ) // $attributeTypeName = "String_String"; //else // $attributeTypeName = $attributeType; string $attributeTypeName = $attributeType; string $attr = ($basename + "_" + "Property" + $attributeNumber + "_" + $attributeName + "_" + $attributeTypeName); appendStringArray $out_attributeNames {$attributeName} 1; appendStringArray $out_attributeFullNames {$attr} 1; appendStringArray $out_attributeTypes {$attributeType} 1; $count++; } return $count; } global proc MagmaFLUX_resetSelection( string $prtNode, int $selected[] ) { if (`checkBox -q -v ($prtNode+"_chk_enableUpdatesAndReoderCalls")`) { string $windowName = `GetMagmaFluxDialogName $prtNode`; window -e $windowName; string $MagmaFLUXAttributesFormLayout = $prtNode + "_MagmaFLUXAttributesFormLayout"; string $MagmaFLUXAttributesMainLayout = $prtNode + "_MagmaFLUXAttributesMainLayout"; string $windowLayout = ($prtNode + "_windowLayout"); int $nodes[] = $selected; if( !`scrollLayout -exists $MagmaFLUXAttributesFormLayout` ) { scrollLayout -width 425 $MagmaFLUXAttributesFormLayout; formLayout -e -attachForm $MagmaFLUXAttributesFormLayout "right" 0 $windowLayout; formLayout -e -attachForm $MagmaFLUXAttributesFormLayout "top" 0 $windowLayout; formLayout -e -attachForm $MagmaFLUXAttributesFormLayout "bottom" 0 $windowLayout; } else { scrollLayout -e $MagmaFLUXAttributesFormLayout; setParent $MagmaFLUXAttributesFormLayout; } if( `columnLayout -exists $MagmaFLUXAttributesMainLayout` ) { deleteUI -lay $MagmaFLUXAttributesMainLayout; } columnLayout -adj true -columnAttach "both" 4 -rowSpacing 4 $MagmaFLUXAttributesMainLayout; //main layout begin for ( $id in $nodes ) { //NOTE: This code generates the attribute editor inside the MagmaFLUX window. // Customize here to suit your needs string $type = `retrieve_magma_node_instance_info -id $id -prt $prtNode -type true`; //Type of node here string $basename = ($type + "_" + $id); string $nodename = `retrieve_magma_node_instance_info -prt $prtNode -id $id -name true`; string $nametextname = "edt_name_"+$id; float $color[] = `MagmaGetOperatorColor $id $prtNode`; frameLayout -label $basename -width 405 -bgc ($color[0]/600.0) ($color[1]/600.0) ($color[1]/600.0) ; //frame layout current node begin rowLayout -width 425 -height 22 -nc 3 -cw 20 1; text -label "Description" -w 85 -h 21 -al "right" ; textField -w 285 -h 21 -text $nodename -cc ("set_magma_node_instance_info -prt "+$prtNode+" -id "+$id+" -name (`textField -q -text "+$nametextname+"`);") $nametextname; button -label "X" -w 18 -h 21 -ann ("Reset the Description to '"+$type+"'") -command ("set_magma_node_instance_info -prt "+$prtNode+" -id "+$id+" -name \""+ $type +"\"; textField -e -text \"" +$type +"\" "+$nametextname+";"); setParent ..; columnLayout -width 425 -cw 1; //column layout begin string $attributeFullName_list[] = {}; string $attributeName_list[] = {}; string $attributeType_list[] = {}; //Base Properties string $infoBuffer[] = `retrieve_magma_node_info -t $type -p true`; int $count = MagmaFLUX_parseMagmaNodeInfoProperty( $infoBuffer, $basename, $attributeName_list, $attributeFullName_list, $attributeType_list ); int $requireSetParent = 0; string $enumTabsName = ""; string $converterTabsName = ""; int $currentEnum = -1; for( $i = 0; $i < $count; $i++ ) { string $attributeName = $attributeName_list[$i]; string $attributeType = $attributeType_list[$i]; string $attr = $attributeFullName_list[$i]; string $spinner = "spin_" + $attr; string $channelConverterTabsName = ($spinner + "_channel_converter"); if( $type == "InputValue" && $attributeName_list[$i] == "enumValue" ) // For InputValue, create a combo box to select input type and tab control { $requireSetParent = 1; // Set up list of choices int $choicesCount = 1 + ($count - $i); string $choices[] = { }; int $j; for( $j = $i + 1; $j < $count; $j++ ) { string $itemName; if( $attributeName_list[$j] == "iValue" ) $itemName = "Int"; else if( $attributeName_list[$j] == "fValue" ) $itemName = "Float"; else if( $attributeName_list[$j] == "vec3Value" ) $itemName = "Vec3"; else if( $attributeName_list[$j] == "quatValue" ) $itemName = "Quat"; else $itemName = $attributeName_list[$j]; appendStringArray $choices {$itemName} 1; } // Set up the choice change command $enumTabsName = ($spinner + "_layout"); $converterTabsName = ($spinner + "_converter"); int $tabIndex = 1; string $tabCmd = ""; for( $item in $choices ) { $tabCmd += "if( \"#1\" == \"" + $item + "\") " + " {tabLayout -e -selectTabIndex " + $tabIndex + " " + $converterTabsName + ";\n" + " tabLayout -e -selectTabIndex " + $tabIndex + " " + $enumTabsName + ";}\n" + "else "; $tabIndex++; } $tabCmd += ";\n"; $tabCmd += ("MagmaEditor_ForceUpdate "+$prtNode+";\n"); $tabCmd += ("MagmaNodesReorderGrid "+$prtNode +";\n"); // Add the combo box enum selector rowLayout -width 425 -nc 2 -cw 20 1; optionMenu -label "" -width 85 -cc $tabCmd $spinner; $tabIndex = 1; for( $item in $choices ) { menuItem -label $item -data $tabIndex; $tabIndex++; } connectControl $spinner ($prtNode + "." + $attr); $currentEnum = `getAttr ($prtNode + "." + $attr)`; //Start the tab control tabLayout -tabsVisible false $enumTabsName; continue; } if( $attributeName_list[$i] == "inputType" ) { MagmaFLUX_addStringEnumAttributeOption $prtNode $spinner $attr $attributeName `MagmaFLUX_getTransformTypes` "Point - use to transform points in 3D space like the Position channel.\nVector - use to transform Vector channels.\nNormal - use to transform unit Vectors like Normals and Tangents."; } else if( $attributeName_list[$i] == "channelName" ) { MagmaFLUX_addStringEnumAttributeOption $prtNode $spinner $attr $attributeName `MagmaFLUX_getChannelTypes` "Select a pre-defined channel name from the list,\nor enter an existing name in the list to the right."; } else if( $attributeName_list[$i] == "channelType" ) { MagmaFLUX_addStringEnumAttributeOption $prtNode $spinner $attr $attributeName `MagmaFLUX_getDataTypes` "Specify the Data Type of the Channel."; string $channelType = eval ("getAttr "+$prtNode + "." + $type +"_"+ $id +"_Property2_channelType_MagmaDataType;"); if ($type != "Output") //$channelType == "Vec3" { int $currentChannelType = 4; if ($channelType == "Float") $currentChannelType = 1; if ($channelType == "Int") $currentChannelType = 2; if ($channelType == "Vec3") $currentChannelType = 3; frameLayout -label ($basename+" - Conversion Shortcuts") -width 425 -h 80 -fn "plainLabelFont" -li 20; tabLayout -tabsVisible false $channelConverterTabsName; gridLayout -width 425 -nc 3 -nr 1 -cw 130 -ch 25 ; //rowLayout -width 425 -nc 3 -cw 10 1; button -label "To Vector" -w 130 -command ("MagmaInsertConversionNode "+$prtNode+" 0 0 "+$id+" \"ToVector\" 0 0 0 1 1;"); button -label "To Integer" -w 130 -command ("MagmaInsertConversionNode "+$prtNode+" 0 0 "+$id+" \"ToInt\" 0 0 0 1 1;"); button -label "Clamp Value" -w 130 -command ("MagmaInsertConversionNode "+$prtNode+" 0 0 "+$id+" \"Clamp\" 0 0 0 1 1;"); setParent ..; //rowLayout -width 425 -nc 2 -cw 10 1; gridLayout -width 425 -nc 2 -nr 1 -cw 192 -ch 25 ; button -label "To Float" -w 192 -command ("MagmaInsertConversionNode "+$prtNode+" 0 0 "+$id+" \"ToFloat\" 0 0 0 1 1;"); button -label "Clamp Value" -w 192 -command ("MagmaInsertConversionNode "+$prtNode+" 0 0 "+$id+" \"Clamp\" 0 0 0 1 1;"); setParent ..; gridLayout -width 425 -nc 3 -nr 2 -cw 130 -ch 25 ; button -label "Breakout X" -w 130 -command ("MagmaInsertConversionNode "+$prtNode+" 0 0 "+$id+" \"Breakout\" 0 0 0 1 1;"); button -label "Breakout Y" -w 130 -command ("MagmaInsertConversionNode "+$prtNode+" 0 0 "+$id+" \"Breakout\" 0 0 1 1 1;"); button -label "Breakout Z" -w 130 -command ("MagmaInsertConversionNode "+$prtNode+" 0 0 "+$id+" \"Breakout\" 0 0 2 11;"); button -label "Magnitude" -w 130 -command ("MagmaInsertConversionNode "+$prtNode+" 0 0 "+$id+" \"Magnitude\" 0 0 0 1 1;"); button -label "To World" -w 130 -command ("MagmaInsertConversionNode "+$prtNode+" 0 0 "+$id+" \"ToWorld\" 0 0 0 1 1;"); button -label "To Camera" -w 130 -command ("MagmaInsertConversionNode "+$prtNode+" 0 0 "+$id+" \"ToCamera\" 0 0 0 1 1;"); setParent ..; rowLayout -width 425 -nc 2 -cw 10 1; button -label "To Float" -w 384 -visible false -command ("MagmaInsertConversionNode "+$prtNode+" 0 0 "+$id+" \"ToFloat\" 0 0 0 1 1;"); setParent ..; setParent ..; setParent ..; tabLayout -e -selectTabIndex ($currentChannelType) $channelConverterTabsName; } else { frameLayout -label ($basename+" - Conversion Shortcuts") -width 425 -h 80 -visible false -fn "plainLabelFont" -li 20; tabLayout -tabsVisible false -visible false $channelConverterTabsName; rowLayout -width 425 -nc 2 -cw 10 1; setParent ..; rowLayout -width 425 -nc 2 -cw 10 1; setParent ..; rowLayout -width 425 -nc 2 -cw 10 1; setParent ..; rowLayout -width 425 -nc 2 -cw 10 1; setParent ..; setParent ..; setParent ..; } } else if( $attributeName_list[$i] == "geometryNames" ) { string $listcontrol = ($spinner+"_lbx_geometryObjects"); string $nodeattr = ($prtNode + "." + $attr); string $attrchangecmd = ( //populates list with object names from string array attribute "int $firstSel = `textScrollList -q -ni "+$listcontrol+"`+1;\n" + "string $nodeattr = \"" + $nodeattr + "\";\n" + "string $listcontrol = \"" + $listcontrol + "\";\n" + "string $resultArray[] = `getAttr $nodeattr`;\n" + "textScrollList -e -ra $listcontrol;\n"+ "for ($anItem in $resultArray)\n"+ "textScrollList -e -append $anItem $listcontrol;\n" + "for ($i = $firstSel; $i <= `size $resultArray`; $i++)\n " + "textScrollList -e -sii $i "+$listcontrol+";\n" ); columnLayout -width 425 -h 165 ; //-cw 1 text -label " Geometry Objects:"; textScrollList -w 390 -numberOfRows 10 -allowMultiSelection true $listcontrol; setParent ..; rowLayout -width 425 -nc 2 -cw 20 1; button -label "Get From Scene Selection" -w 195 -command ("KMYMAGMAED_getCurrentSceneSelectionGeometry " + $prtNode + " " + $attr + " "+ $listcontrol + ";"); button -label "Remove Highlighted Items" -w 195 -command ("KMYMAGMAED_removeHighlightedGeometryFromList " + $prtNode + " " + $attr + " "+ $listcontrol + ";"); setParent ..; eval $attrchangecmd; scriptJob -parent $listcontrol -attributeChange $nodeattr ( $attrchangecmd ); } else if ( $attributeName_list[$i] == "particleName" ) { string $listcontrol = ($spinner+"_lbx_particleSelector"); columnLayout -width 425 -h 200 -cw 1; string $nodeattr = ($prtNode + "." + $attr); string $text = eval ( "getAttr "+$nodeattr+";"); string $fieldchangecmd = ( "string $nodeattr = \"" + $nodeattr + "\";\n" + "string $text = \"#1\";\n" + "eval(\"setAttr $nodeattr -type \\\"string\\\" \" + $text + \"\");\n" + "MagmaEditor_updateParticleObjectsListSelection "+$listcontrol +" $text;\n" ); string $listchangecmd = ( "string $nodeattr = \"" + $nodeattr + "\";\n" + "string $selectedItem[] = `textScrollList -q -si "+ $listcontrol+"`;\n" + "textField -e -text $selectedItem[0] "+$spinner +";\n" + "eval(\"setAttr $nodeattr -type \\\"string\\\" \" + $selectedItem[0] + \"\");\n" ); text -label " Particle Name:"; textField -w 400 -text $text -cc $fieldchangecmd $spinner; textScrollList -w 400 -numberOfRows 11 -allowMultiSelection false -sc $listchangecmd $listcontrol; MagmaEditor_buildParticleObjectsList $prtNode $listcontrol ; MagmaEditor_updateParticleObjectsListSelection $listcontrol $text; string $attrchangecmd = ( "string $nodeattr = \"" + $nodeattr + "\";\n" + "string $spinner = \"" + $spinner + "\";\n" + "string $text = `getAttr $nodeattr`;\n" + "textField -e -text $text $spinner;\n" ); scriptJob -parent $spinner -attributeChange $nodeattr ( $attrchangecmd ); setParent ..; } else if ( $attributeName_list[$i] == "objectName" ) { string $listcontrol = ($spinner+"_lbx_objectSelector"); columnLayout -width 425 -h 250 -cw 1; string $nodeattr = ($prtNode + "." + $attr); string $text = eval ( "getAttr "+$nodeattr+";"); string $fieldchangecmd = ( "string $nodeattr = \"" + $nodeattr + "\";\n" + "string $text = \"#1\";\n" + "eval(\"setAttr $nodeattr -type \\\"string\\\" \" + $text + \"\");\n" + "MagmaEditor_updateParticleObjectsListSelection "+$listcontrol +" $text;\n" ); string $listchangecmd = ( "string $nodeattr = \"" + $nodeattr + "\";\n" + "string $selectedItem[] = `textScrollList -q -si "+ $listcontrol+"`;\n" + "textField -e -text $selectedItem[0] "+$spinner +";\n" + "eval(\"setAttr $nodeattr -type \\\"string\\\" \" + $selectedItem[0] + \"\");\n" ); text -label " Object Name:"; textField -w 400 -text $text -cc $fieldchangecmd $spinner; textScrollList -w 400 -numberOfRows 14 -allowMultiSelection false -sc $listchangecmd $listcontrol; MagmaEditor_buildAllObjectsList $prtNode $listcontrol ; MagmaEditor_updateParticleObjectsListSelection $listcontrol $text; string $attrchangecmd = ( "string $nodeattr = \"" + $nodeattr + "\";\n" + "string $spinner = \"" + $spinner + "\";\n" + "string $text = `getAttr $nodeattr`;\n" + "textField -e -text $text $spinner;\n" ); scriptJob -parent $spinner -attributeChange $nodeattr ( $attrchangecmd ); setParent ..; } else { if (`tolower $attributeName_list[$i]` == "enabled") { if (`MagmaNodeSupportsPassThrough $type`) MagmaFLUX_addAttributeOption($prtNode, $spinner, $attr, $attributeName, $attributeType, !$requireSetParent, $type, $id ); else { rowLayout -width 425 -nc 3 -cw 20 1; text -label "Enabled" -al "right" -width 85 -h 20 -enable off -ann "This node cannot be disabled."; //This node cannot be disabled. checkBox -w 315 -label "" -v on -enable off; setParent ..; } } else MagmaFLUX_addAttributeOption($prtNode, $spinner, $attr, $attributeName, $attributeType, !$requireSetParent, $type, $id ); } } if( $type == "InputValue" ) // For InputValue, exit out of the input type selection tab form { if( $requireSetParent ) { tabLayout -e -selectTabIndex ($currentEnum) $enumTabsName; setParent ..; setParent ..; //setParent ..; } frameLayout -label ($basename+" - Conversion Shortcuts") -width 425 -fn "plainLabelFont" -li 20; tabLayout -tabsVisible false $converterTabsName; gridLayout -width 425 -nc 3 -nr 1 -cw 130 -ch 25 ; //rowLayout -width 425 -nc 3 -cw 10 1; button -label "To Vector" -w 130 -command ("MagmaInsertConversionNode "+$prtNode+" 0 0 "+$id+" \"ToVector\" 0 0 0 1 1;"); button -label "To Integer" -w 130 -command ("MagmaInsertConversionNode "+$prtNode+" 0 0 "+$id+" \"ToInt\" 0 0 0 1 1;"); button -label "Clamp Value" -w 130 -command ("MagmaInsertConversionNode "+$prtNode+" 0 0 "+$id+" \"Clamp\" 0 0 0 1 1;"); setParent ..; rowLayout -width 425 -nc 2 -cw 10 1; button -label "To Float" -w 192 -command ("MagmaInsertConversionNode "+$prtNode+" 0 0 "+$id+" \"ToFloat\" 0 0 0 1 1;"); button -label "Clamp Value" -w 192 -command ("MagmaInsertConversionNode "+$prtNode+" 0 0 "+$id+" \"Clamp\" 0 0 0 1 1;"); setParent ..; rowLayout -width 425 -nc 4 -cw 10 1; button -label "Breakout X" -w 95 -command ("MagmaInsertConversionNode "+$prtNode+" 0 0 "+$id+" \"Breakout\" 0 0 0 1 1;"); button -label "Breakout Y" -w 95 -command ("MagmaInsertConversionNode "+$prtNode+" 0 0 "+$id+" \"Breakout\" 0 0 1 1 1;"); button -label "Breakout Z" -w 95 -command ("MagmaInsertConversionNode "+$prtNode+" 0 0 "+$id+" \"Breakout\" 0 0 2 1 1;"); button -label "Magnitude" -w 95 -command ("MagmaInsertConversionNode "+$prtNode+" 0 0 "+$id+" \"Magnitude\" 0 0 0 1 1;"); setParent ..; setParent ..; setParent ..; tabLayout -e -selectTabIndex ($currentEnum) $converterTabsName; } if ($type == "IntersectRay" || $type == "NearestPoint") { frameLayout -label ($basename+" - Vector Channel - Conversion Shortcuts") -width 425 -fn "plainLabelFont" -li 20; //rowLayout -width 425 -nc 2 -cw 10 1; gridLayout -width 425 -nc 2 -nr 1 -cw 192 -ch 25 ; button -label "\"Position\" Output To Object Space" -w 192 -command ("MagmaInsertConversionNode "+$prtNode+" 0 0 "+$id+" \"FromWorld\" 0 0 0 0 1;"); button -label "\"Normal\" Output To Object Space" -w 192 -command ("MagmaInsertConversionNode "+$prtNode+" 0 0 "+$id+" \"FromWorld\" 5 0 0 0 1;"); setParent ..; //rowLayout -width 425 -nc 4 -cw 10 1; gridLayout -width 425 -nc 2 -nr 1 -cw 192 -ch 25 ; button -label "Add 'FaceQuery'" -w 192 -command ("MagmaInsertAndConnectQueryNode "+$prtNode+" "+$id+" \"FaceQuery\";"); button -label "Add 'VertexQuery'" -w 192 -command ("MagmaInsertAndConnectQueryNode "+$prtNode+" "+$id+" \"VertexQuery\";"); button -label "Add 'MeshQuery'" -w 192 -command ("MagmaInsertAndConnectQueryNode "+$prtNode+" "+$id+" \"MeshQuery\";"); button -label "Add 'ElementQuery'" -w 192 -command ("MagmaInsertAndConnectQueryNode "+$prtNode+" "+$id+" \"ElementQuery\";"); setParent ..; } if ($type == "NearestParticle") { frameLayout -label ($basename+" - Vector Channel - Conversion Shortcuts") -width 425 -fn "plainLabelFont" -li 20; rowLayout -width 425 -nc 2 -cw 10 1; button -label "\"Position\" To Object Space" -w 192 -command ("MagmaInsertConversionNode "+$prtNode+" 0 0 "+$id+" \"FromWorld\" 0 0 0 0 1;"); button -label "Add 'ParticleQuery'" -w 192 -command ("MagmaInsertAndConnectQueryNode "+$prtNode+" "+$id+" \"ParticleQuery\";"); setParent ..; } if ($type == "Magnitude" || $type == "Breakout") { frameLayout -label ($basename+" - Conversion Shortcuts") -width 425 -fn "plainLabelFont" -li 20; rowLayout -width 425 -nc 1 -cw 10 1; button -label "Convert To Vector" -w 400 -command ("MagmaInsertConversionNode "+$prtNode+" 0 0 "+$id+" \"ToVector\" 0 0 0 1 1;"); setParent ..; } if ($type == "ToVector") { frameLayout -label ($basename+" - Conversion Shortcuts") -width 425 -fn "plainLabelFont" -li 20; rowLayout -width 425 -nc 1 -cw 10 1; button -label "Vector Magnitude" -w 400 -command ("MagmaInsertConversionNode "+$prtNode+" 0 0 "+$id+" \"Magnitude\" 0 0 0 1 1;"); setParent ..; } if ($type == "InputObject") { frameLayout -label ($basename+" - Conversion Shortcuts") -width 425 -fn "plainLabelFont" -li 20; rowLayout -width 425 -nc 1 -cw 10 1; button -label "Add Property Query" -w 400 -command ("MagmaInsertConversionNode "+$prtNode+" 0 0 "+$id+" \"PropertyQuery\" 0 0 0 1 1;"); setParent ..; } if ($type == "ToFloat") { frameLayout -label ($basename+" - Conversion Shortcuts") -width 425 -fn "plainLabelFont" -li 20; rowLayout -width 425 -nc 3 -cw 10 1; button -label "To Vector" -w 130 -command ("MagmaInsertConversionNode "+$prtNode+" 0 0 "+$id+" \"ToVector\" 0 0 0 1 1;"); button -label "To Integer" -w 130 -command ("MagmaInsertConversionNode "+$prtNode+" 0 0 "+$id+" \"ToInt\" 0 0 0 1 1;"); button -label "Clamp Value" -w 130 -command ("MagmaInsertConversionNode "+$prtNode+" 0 0 "+$id+" \"Clamp\" 0 0 0 1 1;"); setParent ..; } string $category = MagmaGetNodeCategoryFromType($type); if ($category == "Logic" && $type != "Mux" && $type != "Switch" ) { frameLayout -label ($basename+" - Logic - Conversion Shortcuts") -width 425 -fn "plainLabelFont" -li 20; rowLayout -width 425 -nc 1 -cw 10 1; button -label "Convert Integer Output To Float" -w 390 -command ("MagmaInsertConversionNode "+$prtNode+" 0 0 "+$id+" \"ToFloat\" 0 0 0 1 1;"); setParent ..; } //Input Socket Properties if( $type != "InputValue" && $type != "InputChannel" ) { string $inInfoBuffer[] = `retrieve_magma_node_info -t $type -is true`; int $socketindex = 0; int $existingConnection[] = `get_magma_connections -prt $prtNode -id $id`; for( $currentInfo in $inInfoBuffer ) { if ($existingConnection[$socketindex] == -1) { string $attr; string $spinner; string $currentInfoBuffer[] = `MagmaFLUX_PropertyTokenizer $currentInfo`; string $socketNameBuffer[]; tokenize $currentInfoBuffer[0] "#:" $socketNameBuffer; string $socketNumber = $socketNameBuffer[1]; string $socketName = $socketNameBuffer[2]; string $attributeTypes = $currentInfoBuffer[2]; // Check if there are any options for the socket string $attributeTypesBuffer[]; tokenize $attributeTypes " " $attributeTypesBuffer; if( `size $attributeTypesBuffer` <= 0 ) continue; if( `size $attributeTypesBuffer` == 1 && `size $attributeTypesBuffer[0]` <= 0) continue; frameLayout -label ($socketName + " - Default Value") -li 10 -fn "obliqueLabelFont"; //-bgc 0.2 0.2 0.2 columnLayout -width 425 -cw 1; $attributeType = "enum"; $attr = ($basename + "_" + "InputSocket" + $socketNumber + "_" + $attributeType); $spinner = "spin_" + $attr; MagmaFLUX_addSocketTypeEnumAttributeOption( $prtNode, $basename, $spinner, $attr, "Default", $socketNumber, $attributeTypesBuffer, $type, $id ); setParent ..; setParent ..; } $socketindex += 2; } } setParent ..; //column layout end setParent ..; //frame layout current node begin } setParent ..; //main layout end } } global proc MagmaEditor_SelectAllNodes (string $prtNode ) { checkBox -e -v false ($prtNode+"_chk_enableUpdatesAndReoderCalls"); int $selected[] = `retrieve_magma_node_ids -prt $prtNode`; magma_flux_window_set -n $selected -prt $prtNode; checkBox -e -v true ($prtNode+"_chk_enableUpdatesAndReoderCalls"); //MagmaFLUX_resetSelection $prtNode {}; MagmaFLUX_resetSelection $prtNode $selected; } global proc MagmaEditor_SelectUnconnectedRecursive (int $aNode, string $prtNode, int $processednodes[]) { $processednodes[$aNode] = 1; int $connection[] = `get_magma_connections -prt $prtNode -id $aNode`; int $i = 0; for ($i = 0; $i < `size $connection`; $i=$i+2) { if ($connection[$i] > -1) { MagmaEditor_SelectUnconnectedRecursive $connection[$i] $prtNode $processednodes ; } } } global proc MagmaEditor_SelectUnconnectedNodes (string $prtNode ) { int $allNodes[] = `retrieve_magma_node_ids -prt $prtNode`; int $processednodes[]; for ($aNode in $allNodes) $processednodes[$aNode] = 0; for ($aNode in $allNodes) { string $type = `retrieve_magma_node_instance_info -id $aNode -prt $prtNode -type true`; if ($processednodes[$aNode] == 0 && $type == "Output") { MagmaEditor_SelectUnconnectedRecursive $aNode $prtNode $processednodes; } } int $unconnectedNodes[] = {}; for ($aNode in $allNodes) { if ($processednodes[$aNode] == 0) $unconnectedNodes[`size $unconnectedNodes`] = $aNode; } checkBox -e -v false ($prtNode+"_chk_enableUpdatesAndReoderCalls"); magma_flux_window_set -n $unconnectedNodes -prt $prtNode; checkBox -e -v true ($prtNode+"_chk_enableUpdatesAndReoderCalls"); MagmaFLUX_resetSelection $prtNode $unconnectedNodes; } global proc MagmaEditor_SelectInputNodes (string $prtNode ) { int $nodes[] = `retrieve_magma_node_ids -prt $prtNode`; int $toSelect[] = {}; for ($aNode in $nodes) { string $type = `retrieve_magma_node_instance_info -id $aNode -prt $prtNode -type true`; if ($type == "InputValue" || $type == "InputChannel" || $type == "InputGeometry") $toSelect[`size $toSelect`] = $aNode; } checkBox -e -v false ($prtNode+"_chk_enableUpdatesAndReoderCalls"); magma_flux_window_set -n $toSelect -prt $prtNode; checkBox -e -v true ($prtNode+"_chk_enableUpdatesAndReoderCalls"); MagmaFLUX_resetSelection $prtNode $toSelect; } global proc MagmaEditor_SelectOutpuNodes (string $prtNode ) { int $nodes[] = `retrieve_magma_node_ids -prt $prtNode`; int $toSelect[] = {}; for ($aNode in $nodes) { string $type = `retrieve_magma_node_instance_info -id $aNode -prt $prtNode -type true`; if ($type == "Output") $toSelect[`size $toSelect`] = $aNode; } checkBox -e -v false ($prtNode+"_chk_enableUpdatesAndReoderCalls"); magma_flux_window_set -n $toSelect -prt $prtNode; checkBox -e -v true ($prtNode+"_chk_enableUpdatesAndReoderCalls"); MagmaFLUX_resetSelection $prtNode $toSelect; } global proc MagmaEditor_SelectInvert (string $prtNode ) { int $nodes[] = `retrieve_magma_node_ids -prt $prtNode`; int $sel[] = `magma_flux_window_query -n true -prt $prtNode`; int $toSelectMap[] = {}; int $toSelect[] = {}; for ($aNode in $nodes) $toSelectMap[$aNode] = 1; for ($aNode in $sel) $toSelectMap[$aNode] = 0; for ($aNode in $nodes) { if ($toSelectMap[$aNode]==1) $toSelect[`size $toSelect`] = $aNode; } checkBox -e -v false ($prtNode+"_chk_enableUpdatesAndReoderCalls"); magma_flux_window_set -n $toSelect -prt $prtNode; checkBox -e -v true ($prtNode+"_chk_enableUpdatesAndReoderCalls"); MagmaFLUX_resetSelection $prtNode $toSelect; } ////////////////////////////////////// // EVENT HANDLER FUNCTIONS:// ///////////////////////////////////// global proc MagmaFLUX_nodeSelectionChanged( string $prtNode, int $selectedID[] ) { if (`checkBox -q -v ($prtNode+"_chk_enableCallbacks")`) { //print "MagmaFLUX_nodeSelectionChanged called\n"; MagmaFLUX_resetSelection $prtNode $selectedID; int $isSelected = `size $selectedID`; menuItem -e -enable $isSelected ($prtNode+"_copyToClipboard"); } } global proc MagmaFLUX_connectionSelectionChanged( string $prtNode, string $selectedConnection[] ) { //print( $prtNode + ": Connections: \n"); /* for( $edge in $selectedConnection ) { string $edgesTokens[]; tokenize($edge, ",", $edgesTokens); int $src = $edgesTokens[0]; int $srcSock = $edgesTokens[1]; int $dst = $edgesTokens[2]; int $dstSock = $edgesTokens[3]; // print( $src + ":" + $srcSock + " to " + $dst + ":" + $dstSock + "\n"); } */ } global proc MagmaFLUX_connectionCreated( string $prtNode, int $src, int $srcSock, int $dst, int $dstSock ) { if (`checkBox -q -v ($prtNode+"_chk_enableCallbacks")`) { //print( $prtNode + ": Create: " + $src + ":" + $srcSock + " to " + $dst + ":" + $dstSock + "\n"); int $selnodes[] = `magma_flux_window_query -n true -prt $prtNode`; MagmaEditor_ForceUpdate $prtNode ; MagmaNodesReorderGrid $prtNode ; MagmaFLUX_resetSelection $prtNode $selnodes; MagmaEditor_RepaintSockets $prtNode 0; /* int $connectionsMap[] = `GetOutputConnectionsMap $prtNode`; MagmaEditor_SetSocketColors $dst $prtNode $connectionsMap; MagmaEditor_SetSocketColors $src $prtNode $connectionsMap; */ MagmaEditor_SetWireColors $prtNode; int $enableupdates = `checkBox -q -v ($prtNode+"_chk_enableUpdatesAndReoderCalls")`; if ($enableupdates) MagmaEditor_CreateUndoRecord $prtNode ("Created Connection From "+$src + ":" + $srcSock + " To " + $dst + ":" + $dstSock); } } global proc MagmaFLUX_connectionDeleted( string $prtNode, int $src, int $srcSock, int $dst, int $dstSock ) { if (`checkBox -q -v ($prtNode+"_chk_enableCallbacks")`) { //print( $prtNode + ": Delete: " + $src + ":" + $srcSock + " to " + $dst + ":" + $dstSock + "\n"); int $selnodes[] = `magma_flux_window_query -n true -prt $prtNode`; MagmaEditor_ForceUpdate $prtNode ; MagmaNodesReorderGrid $prtNode ; MagmaFLUX_resetSelection $prtNode $selnodes; int $connectionsMap[] = `GetOutputConnectionsMap $prtNode`; MagmaEditor_SetSocketColors $dst $prtNode $connectionsMap; MagmaEditor_SetSocketColors $src $prtNode $connectionsMap; MagmaEditor_SetWireColors $prtNode; //if (`size $selnodes` > 0) //MagmaEditor_CreateUndoRecord $prtNode ("Deleted Connection From "+$src + ":" + $srcSock + " To " + $dst + ":" + $dstSock); } } global proc MagmaSwapInputSockets ( string $prtNode, int $mode ) { checkBox -e -v false ($prtNode+"_chk_enableUpdatesAndReoderCalls"); int $nodes[] = `magma_flux_window_query -n true -prt $prtNode`; for( $node in $nodes ) { int $connection[] = `get_magma_connections -prt $prtNode -id $node`; if (`size $connection` > ($mode+1)*2) { delete_magma_connection -si $connection[0+$mode*2] -ss $connection[1+$mode*2] -di $node -ds ($mode) -prt $prtNode; delete_magma_connection -si $connection[2+$mode*2] -ss $connection[3+$mode*2] -di $node -ds (1+$mode) -prt $prtNode; if ($connection[2+$mode*2] != -1) { create_magma_connection -si $connection[2+$mode*2] -ss $connection[3+$mode*2] -di $node -ds ($mode) -prt $prtNode; } if ($connection[$mode*2] != -1) { create_magma_connection -si $connection[0+$mode*2] -ss $connection[1+$mode*2] -di $node -ds (1+$mode) -prt $prtNode; } //int $connectionsMap[] = `GetOutputConnectionsMap $prtNode`; //MagmaEditor_SetSocketColors $node $prtNode $connectionsMap; //MagmaEditor_SetSocketColors $connection[0+$mode*2] $prtNode $connectionsMap; //MagmaEditor_SetSocketColors $connection[2+$mode*2] $prtNode $connectionsMap; } } checkBox -e -v true ($prtNode+"_chk_enableUpdatesAndReoderCalls"); MagmaEditor_SetWireColors $prtNode; int $nodecount =`size $nodes`; if ($nodecount > 0) { MagmaFLUX_resetSelection $prtNode $nodes; MagmaEditor_ForceUpdate $prtNode; MagmaNodesReorderGrid $prtNode; string $undostring = $nodecount+" Nodes"; if ($nodecount==1) { string $type = `retrieve_magma_node_instance_info -id $nodes[0] -prt $prtNode -type true`; $undostring = $type+"_"+$nodes[0]; } string $modestring = " First And Second "; if ($mode==2) $modestring = " Second And Third "; MagmaEditor_CreateUndoRecord $prtNode ("Swap"+$modestring+"Input Sockets Of "+$undostring); } } global proc MagmaEditor_RemoveNodeFromConnection ( string $prtNode, int $remove ) { checkBox -e -v false ($prtNode+"_chk_enableUpdatesAndReoderCalls"); int $selnodes[] = `magma_flux_window_query -n true -prt $prtNode`; int $nodestoremove[] = {}; for ( $node in $selnodes ) { string $type = `retrieve_magma_node_instance_info -id $node -prt $prtNode -type true`; string $category = MagmaGetNodeCategoryFromType($type); int $connection[]; if ($category != "Input") { $connection = `get_magma_connections -prt $prtNode -id $node`; if ($connection[0] > -1) { delete_magma_connection -si $connection[0] -ss $connection[1] -di $node -ds 0 -prt $prtNode; } } else $connection[0] = -1; int $nodes[] = `retrieve_magma_node_ids -prt $prtNode`; for ($aNode in $nodes) { int $upconnection[] = `get_magma_connections -prt $prtNode -id $aNode`; for ($i = 0; $i < `size $upconnection`; $i=$i+2) { if ($upconnection[$i] == $node && $upconnection[$i+1] == 0) { delete_magma_connection -si $node -ss 0 -di $aNode -ds ($i/2) -prt $prtNode; if ($connection[0] > -1) { create_magma_connection -si $connection[0] -ss $connection[1] -di $aNode -ds ($i/2) -prt $prtNode; } } } } if ($remove) { $nodestoremove[`size $nodestoremove`] = $node; } } for ($aNode in $nodestoremove) // delete any remaining connections from the other sockets, then delete the node { int $connection[] = `get_magma_connections -prt $prtNode -id $aNode`; for ($i = 0; $i < `size $connection`; $i=$i+2) { if ($connection[$i] != -1) { delete_magma_connection -si $connection[$i] -ss $connection[$i+1] -di $aNode -ds ($i/2) -prt $prtNode; } } delete_magma_node -i $aNode -prt $prtNode; } checkBox -e -v true ($prtNode+"_chk_enableUpdatesAndReoderCalls"); if ($remove) MagmaFLUX_resetSelection $prtNode {}; MagmaEditor_ForceUpdate $prtNode; MagmaNodesReorderGrid $prtNode; string $modestring = " "; if ($remove) $modestring = " And Delete "; MagmaEditor_CreateUndoRecord $prtNode ("Remove"+$modestring+`size $nodestoremove`+" Nodes"); } global proc MagmaEditor_InsertNodeIntoConnection ( string $prtNode ) { //print "//MagmaEditor_InsertNodeIntoConnection called\n"; checkBox -e -v false ($prtNode+"_chk_enableUpdatesAndReoderCalls"); int $selnodes[] = `magma_flux_window_query -n true -prt $prtNode`; string $edges[] = `magma_flux_window_query -e true -prt $prtNode`; if ((`size $selnodes` == 1) && (`size $edges` == 1)) { int $connection[] = `get_magma_connections -prt $prtNode -id $selnodes[0]`; if ($connection[0] == -1) { string $edgesTokens[]; tokenize($edges[0], ",", $edgesTokens); int $src = $edgesTokens[0]; int $srcSock = $edgesTokens[1]; int $dst = $edgesTokens[2]; int $dstSock = $edgesTokens[3]; create_magma_connection -si $src -ss $srcSock -di $selnodes[0] -ds 0 -prt $prtNode; create_magma_connection -si $selnodes[0] -ss 0 -di $dst -ds $dstSock -prt $prtNode; } } if ((`size $selnodes` == 2) && (`size $edges` == 0)) { int $node1 = $selnodes[0]; int $node2 = $selnodes[1]; string $sockets[] = `retrieve_magma_node_instance_info -prt $prtNode -id $node1 -is true`; int $insocketsCount1 = `size $sockets`; $sockets = `retrieve_magma_node_instance_info -prt $prtNode -id $node2 -is true`; int $insocketsCount2 = `size $sockets`; $sockets = `retrieve_magma_node_instance_info -prt $prtNode -id $node1 -os true`; int $outsocketsCount1 = `size $sockets`; $sockets = `retrieve_magma_node_instance_info -prt $prtNode -id $node2 -os true`; int $outsocketsCount2 = `size $sockets`; int $pos1[] = `retrieve_magma_node_instance_info -id $node1 -prt $prtNode -xy true`; int $pos2[] = `retrieve_magma_node_instance_info -id $node2 -prt $prtNode -xy true`; if ($insocketsCount2 > 0 && $insocketsCount1 == 0 && $outsocketsCount1 > 0) // if node 1 is an Input node and node 2 has inputs (Operator or Output node) { //connect the first output of node 1 to the first empty input of node 2 int $connections[] = `get_magma_connections -prt $prtNode -id $node2`; int $done = 0; for ($i = 0; $i < `size $connections`; $i=$i+2) { if ($connections[$i] == -1 && $done == 0) { $done = 1; create_magma_connection -si $node1 -ss 0 -di $node2 -ds ($i/2) -prt $prtNode; } } } if ($insocketsCount1 > 0 && $insocketsCount2 == 0 && $outsocketsCount2 > 0) // if node 2 is an Input node and node 1 has inputs (Operator or Output node) { //connect the first output of node 2 to the first empty input of node 1 int $connections[] = `get_magma_connections -prt $prtNode -id $node1`; int $done = 0; for ($i = 0; $i < `size $connections`; $i=$i+2) { if ($connections[$i] == -1 && $done == 0) { $done = 1; create_magma_connection -si $node2 -ss 0 -di $node1 -ds ($i/2) -prt $prtNode; } } } if ($insocketsCount2 > 0 && $insocketsCount1 > 0 && $outsocketsCount1 > 0 && $outsocketsCount2 > 0) // Both nodes are operators { if ($pos2[0] > $pos1[0]) //connect the first output of node 1 to the first empty input of node 2 { int $connections[] = `get_magma_connections -prt $prtNode -id $node2`; int $done = 0; for ($i = 0; $i < `size $connections`; $i=$i+2) { if ($connections[$i] == -1 && $done == 0) { $done = 1; create_magma_connection -si $node1 -ss 0 -di $node2 -ds ($i/2) -prt $prtNode; } } } else //connect the first output of node 2 to the first empty input of node 1 { int $connections[] = `get_magma_connections -prt $prtNode -id $node1`; int $done = 0; for ($i = 0; $i < `size $connections`; $i=$i+2) { if ($connections[$i] == -1 && $done == 0) { $done = 1; create_magma_connection -si $node2 -ss 0 -di $node1 -ds ($i/2) -prt $prtNode; } } } } if ($insocketsCount2 > 0 && $outsocketsCount2 == 0 && $outsocketsCount1 > 0 ) // if Node 2 is an Output node and the other is anything but Output { //connect the first output of node 1 to the first input of node 2 create_magma_connection -si $node1 -ss 0 -di $node2 -ds 0 -prt $prtNode; } if ($insocketsCount1 > 0 && $outsocketsCount1 == 0 && $outsocketsCount2 > 0 ) // if Node 1 is an Output node and the other is anything but Output { //connect the first output of node 1 to the first input of node 2 create_magma_connection -si $node2 -ss 0 -di $node1 -ds 0 -prt $prtNode; } } checkBox -e -v true ($prtNode+"_chk_enableUpdatesAndReoderCalls"); MagmaEditor_ForceUpdate $prtNode; MagmaNodesReorderGrid $prtNode; MagmaEditor_CreateUndoRecord $prtNode ("Insert Node Into Connection"); //print "//MagmaEditor_InsertNodeIntoConnection ended\n"; } global proc string MagmaGetNodeCategoryFromType (string $type) { string $infoBuffer[] = `retrieve_magma_node_info -t $type -a true`; string $tokens[]; tokenize($infoBuffer[0], ",:", $tokens); return $tokens[1]; } global proc int MagmaNodeSupportsPassThrough (string $type) { string $category = MagmaGetNodeCategoryFromType($type); int $index = stringArrayFindWrapper( $type, 0, {"Blend"} ); if ($index >= 0 || $category == "Convert" || $category == "Input" || $category == "Object" ) return 0; else return 1; } global proc MagmaToggleNodeEnabled ( string $prtNode ) { int $processed = 0; string $lastnode = ""; int $newValue = 0; checkBox -e -v false ($prtNode+"_chk_enableUpdatesAndReoderCalls"); int $nodes[] = `magma_flux_window_query -n true -prt $prtNode`; for( $node in $nodes ) { string $type = `retrieve_magma_node_instance_info -id $node -prt $prtNode -type true`; if (`MagmaNodeSupportsPassThrough $type`) { $processed++; $lastnode = $type+"_"+$node; $newValue = eval ("getAttr "+$prtNode + "." + $type +"_"+ $node +"_Property0_enabled_Bool;"); $newValue = 1 - $newValue; eval ("setAttr "+$prtNode + "." + $type +"_"+ $node +"_Property0_enabled_Bool " + $newValue+";"); } } checkBox -e -v true ($prtNode+"_chk_enableUpdatesAndReoderCalls"); MagmaEditor_ForceUpdate $prtNode; MagmaNodesReorderGrid $prtNode; if ($processed > 0) { if ($processed > 1) MagmaEditor_CreateUndoRecord $prtNode ("Toggle Enabled Attribute of "+ $processed +" Nodes"); else { if ($newValue) MagmaEditor_CreateUndoRecord $prtNode ("Enable Node ["+ $lastnode +"]"); else MagmaEditor_CreateUndoRecord $prtNode ("Disable Node ["+ $lastnode +"]"); } } } global proc MagmaEditor_DeleteSelection ( string $prtNode ) { //conrad??? int $selnodes[] = `magma_flux_window_query -n true -prt $prtNode`; string $seledges[] = `magma_flux_window_query -e true -prt $prtNode`; /* if (`size $selnodes` > 1 ) { string $msg = ("Are you sure you want to DELETE "+ `size $selnodes`+" Nodes And/Or "+`size $seledges`+" Connections?\nCurrently there is no Undo!"); string $ret = `confirmDialog -title "Delete Multiple?" -message ($msg) -button "Yes" -button "No" -defaultButton "Yes" -cancelButton "No"`; if ($ret == "No") { return; } } */ int $enableupdates = `checkBox -q -v ($prtNode+"_chk_enableUpdatesAndReoderCalls")`; //remember whether updates were on checkBox -e -v false ($prtNode+"_chk_enableUpdatesAndReoderCalls"); //turn updates and reordering off for ($anEdge in $seledges) { string $edgesTokens[]; tokenize($anEdge, ",", $edgesTokens); int $src = $edgesTokens[0]; int $srcSock = $edgesTokens[1]; int $dst = $edgesTokens[2]; int $dstSock = $edgesTokens[3]; delete_magma_connection -si $src -ss $srcSock -di $dst -ds $dstSock -prt $prtNode; } for ( $node in $selnodes ) { int $connection[] = `get_magma_connections -prt $prtNode -id $node`; for ($i = 0; $i < `size $connection`; $i=$i+2) { if ($connection[$i] > -1) //delete input connections, if any { delete_magma_connection -si $connection[$i] -ss $connection[$i+1] -di $node -ds ($i/2) -prt $prtNode; } } int $nodes[] = `retrieve_magma_node_ids -prt $prtNode`; for ($aNode in $nodes) { int $upconnection[] = `get_magma_connections -prt $prtNode -id $aNode`; for ($i = 0; $i < `size $upconnection`; $i=$i+2) { if ($upconnection[$i] == $node) { delete_magma_connection -si $upconnection[$i] -ss $upconnection[$i+1] -di $aNode -ds ($i/2) -prt $prtNode; } } } } for ($aNode in $selnodes) { delete_magma_node -i $aNode -prt $prtNode; } if ($enableupdates) //if the updates were originally enabled, make sure they are reenabled again and undo records are created. { checkBox -e -v true ($prtNode+"_chk_enableUpdatesAndReoderCalls"); MagmaFLUX_resetSelection $prtNode {}; if (`size $selnodes` > 0) { string $plural = ""; if (`size $selnodes` > 1) $plural = "s"; MagmaEditor_CreateUndoRecord $prtNode ("Delete "+`size $selnodes`+" Node"+$plural); } else { string $plural = ""; if (`size $seledges` > 1 ) $plural = "s"; MagmaEditor_CreateUndoRecord $prtNode ("Delete "+`size $seledges`+" Connection"+$plural); } } } global proc MagmaFLUX_keyPressed( string $prtNode, int $key, int $shift, int $ctrl, int $alt) { // print( $prtNode + ": " + $key + "(" + $shift + "," + $ctrl + "," + $alt + ")" + "\n"); if ($key == 33 && $shift == 1 && $ctrl == 0 && $alt == 0) AddNewMagmaInputValueVectorToFlow 1.0 0.0 0.0 $prtNode 0 0 on on -1 -1; // ! if ($key == 64 && $shift == 1 && $ctrl == 0 && $alt == 0) AddNewMagmaInputValueVectorToFlow 0.0 1.0 0.0 $prtNode 0 0 on on -1 -1; // @ if ($key == 35 && $shift == 1 && $ctrl == 0 && $alt == 0) AddNewMagmaInputValueVectorToFlow 0.0 0.0 1.0 $prtNode 0 0 on on -1 -1; // # if ($key == 36 && $shift == 1 && $ctrl == 0 && $alt == 0) AddNewMagmaInputValueVectorToFlow 0.0 1.0 1.0 $prtNode 0 0 on on -1 -1; // $ if ($key == 37 && $shift == 1 && $ctrl == 0 && $alt == 0) AddNewMagmaInputValueVectorToFlow 1.0 0.0 1.0 $prtNode 0 0 on on -1 -1; // % if ($key == 94 && $shift == 1 && $ctrl == 0 && $alt == 0) AddNewMagmaInputValueVectorToFlow 1.0 1.0 0.0 $prtNode 0 0 on on -1 -1; // ^ if ($key == 38 && $shift == 1 && $ctrl == 0 && $alt == 0) AddNewMagmaInputValueVectorToFlow 1.0 1.0 1.0 $prtNode 0 0 on on -1 -1; // & if ($key == 41 && $shift == 1 && $ctrl == 0 && $alt == 0) AddNewMagmaInputValueVectorToFlow 0.0 0.0 0.0 $prtNode 0 0 on on -1 -1; // ) if ($key == 49 && $shift == 1 && $ctrl == 1 && $alt == 0) AddNewMagmaInputValueVectorToFlow -1.0 0.0 0.0 $prtNode 0 0 on on -1 -1; // -1,0,0 if ($key == 64 && $shift == 1 && $ctrl == 1 && $alt == 0) AddNewMagmaInputValueVectorToFlow 0.0 -1.0 0.0 $prtNode 0 0 on on -1 -1; // 0,-1,0 if ($key == 51 && $shift == 1 && $ctrl == 1 && $alt == 0) AddNewMagmaInputValueVectorToFlow 0.0 0.0 -1.0 $prtNode 0 0 on on -1 -1; // 0,0,-1 if ($key == 49 && $shift == 0 && $ctrl == 0 && $alt == 0) AddNewMagmaInputValueIntToFlow 1 $prtNode 0 0 on on -1 -1; // 1 if ($key == 50 && $shift == 0 && $ctrl == 0 && $alt == 0) AddNewMagmaInputValueIntToFlow 2 $prtNode 0 0 on on -1 -1; // 2 if ($key == 51 && $shift == 0 && $ctrl == 0 && $alt == 0) AddNewMagmaInputValueIntToFlow 3 $prtNode 0 0 on on -1 -1; // 3 if ($key == 52 && $shift == 0 && $ctrl == 0 && $alt == 0) AddNewMagmaInputValueIntToFlow 4 $prtNode 0 0 on on -1 -1; // 4 if ($key == 53 && $shift == 0 && $ctrl == 0 && $alt == 0) AddNewMagmaInputValueIntToFlow 5 $prtNode 0 0 on on -1 -1; // 5 if ($key == 48 && $shift == 0 && $ctrl == 0 && $alt == 0) AddNewMagmaInputValueIntToFlow 0 $prtNode 0 0 on on -1 -1; // 0 if ($key == 49 && $shift == 0 && $ctrl == 1 && $alt == 0) AddNewMagmaInputValueFloatToFlow 1 $prtNode 0 0 on on -1 -1; // 1.0 if ($key == 50 && $shift == 0 && $ctrl == 1 && $alt == 0) AddNewMagmaInputValueFloatToFlow 2 $prtNode 0 0 on on -1 -1; // 2.0 if ($key == 51 && $shift == 0 && $ctrl == 1 && $alt == 0) AddNewMagmaInputValueFloatToFlow 3 $prtNode 0 0 on on -1 -1; // 3.0 if ($key == 52 && $shift == 0 && $ctrl == 1 && $alt == 0) AddNewMagmaInputValueFloatToFlow 4 $prtNode 0 0 on on -1 -1; // 4.0 if ($key == 53 && $shift == 0 && $ctrl == 1 && $alt == 0) AddNewMagmaInputValueFloatToFlow 5 $prtNode 0 0 on on -1 -1; // 5.0 if ($key == 54 && $shift == 0 && $ctrl == 1 && $alt == 0) AddNewMagmaInputValueFloatToFlow 6 $prtNode 0 0 on on -1 -1; // 6.0 if ($key == 55 && $shift == 0 && $ctrl == 1 && $alt == 0) AddNewMagmaInputValueFloatToFlow 7 $prtNode 0 0 on on -1 -1; // 7.0 if ($key == 56 && $shift == 0 && $ctrl == 1 && $alt == 0) AddNewMagmaInputValueFloatToFlow 8 $prtNode 0 0 on on -1 -1; // 8.0 if ($key == 57 && $shift == 0 && $ctrl == 1 && $alt == 0) AddNewMagmaInputValueFloatToFlow 9 $prtNode 0 0 on on -1 -1; // 9.0 if ($key == 48 && $shift == 0 && $ctrl == 1 && $alt == 0) AddNewMagmaInputValueFloatToFlow 0 $prtNode 0 0 on on -1 -1; // 0.0 if ($key == 42 && $shift == 0 && $ctrl == 0 && $alt == 0) AddNewMagmaOperatorToFlow "Multiply" $prtNode 0 0 on on; // * if ($key == 43 && $shift == 0 && $ctrl == 0 && $alt == 0) AddNewMagmaOperatorToFlow "Add" $prtNode 0 0 on on; // + if ($key == 44 && $shift == 0 && $ctrl == 0 && $alt == 0) AddNewMagmaOperatorToFlow "VectorCross" $prtNode 0 0 on on; // , if ($key == 45 && $shift == 0 && $ctrl == 0 && $alt == 0) AddNewMagmaOperatorToFlow "Subtract" $prtNode 0 0 on on; // - if ($key == 46 && $shift == 0 && $ctrl == 0 && $alt == 0) AddNewMagmaOperatorToFlow "VectorDot" $prtNode 0 0 on on; // Period. if ($key == 47 && $shift == 0 && $ctrl == 0 && $alt == 0) AddNewMagmaOperatorToFlow "Divide" $prtNode 0 0 on on; // / if ($key == 54 && $shift == 0 && $ctrl == 0 && $alt == 0) AddNewMagmaOperatorToFlow "Power" $prtNode 0 0 on on; // 6 if ($key == 79 && $shift == 0 && $ctrl == 1 && $alt == 0) AddNewMagmaOutputChannelToFlow "" "" $prtNode 0 0; // Ctrl+O if ($key == 95 && $shift == 1 && $ctrl == 0 && $alt == 0) AddNewMagmaOperatorToFlow "Negate" $prtNode 0 0 on on; // SHIFT + _ if ($key == 60 && $shift == 1 && $ctrl == 0 && $alt == 0) AddNewMagmaOperatorToFlow "Less" $prtNode 0 0 on on; // SHIFT + < if ($key == 61 && $shift == 0 && $ctrl == 0 && $alt == 0) AddNewMagmaOperatorToFlow "Equal" $prtNode 0 0 on on; // = if ($key == 62 && $shift == 1 && $ctrl == 0 && $alt == 0) AddNewMagmaOperatorToFlow "Greater" $prtNode 0 0 on on; // SHIFT + > if ($key == 63 && $shift == 1 && $ctrl == 0 && $alt == 0) AddNewMagmaOperatorToFlow "Switch" $prtNode 0 0 on on; // SHIFT+/ ? if ($key == 47 && $shift == 1 && $ctrl == 1 && $alt == 0) AddNewMagmaOperatorToFlow "Mux" $prtNode 0 0 on on; // SHIFT+CTRL+/ if ($key == 91 && $shift == 0 && $ctrl == 0 && $alt == 0) AddNewMagmaOperatorToFlow "Sin" $prtNode 0 0 on on; // [ if ($key == 92 && $shift == 1 && $ctrl == 0 && $alt == 0) AddNewMagmaOperatorToFlow "Tan" $prtNode 0 0 on on; // \ if ($key == 92 && $shift == 1 && $ctrl == 1 && $alt == 0) AddNewMagmaOperatorToFlow "ATan2" $prtNode 0 0 on on; // SHIFT+CTRL+\ if ($key == 93 && $shift == 0 && $ctrl == 0 && $alt == 0) AddNewMagmaOperatorToFlow "Cos" $prtNode 0 0 on on; // ] if ($key == 124 && $shift == 1 && $ctrl == 0 && $alt == 0) AddNewMagmaOperatorToFlow "ATan" $prtNode 0 0 on on; // SHIFT+[ if ($key == 123 && $shift == 1 && $ctrl == 0 && $alt == 0) AddNewMagmaOperatorToFlow "ASin" $prtNode 0 0 on on; // SHIFT+\ if ($key == 125 && $shift == 1 && $ctrl == 0 && $alt == 0) AddNewMagmaOperatorToFlow "ACos" $prtNode 0 0 on on; // SHIFT+] if ($key == 65 && $shift == 0 && $ctrl == 1 && $alt == 0) MagmaEditor_SelectAllNodes $prtNode; //CTRL+A if ($key == 73 && $shift == 0 && $ctrl == 1 && $alt == 0) MagmaEditor_SelectInvert $prtNode; //CTRL+I if ($key == 73 && $shift == 0 && $ctrl == 1 && $alt == 1) MagmaEditor_SelectInputNodes $prtNode; //ALT+CTRL+I if ($key == 79 && $shift == 0 && $ctrl == 1 && $alt == 1) MagmaEditor_SelectOutpuNodes $prtNode; //ALT+CTRL+O if ($key == 85 && $shift == 0 && $ctrl == 1 && $alt == 0) MagmaEditor_SelectUnconnectedNodes $prtNode; //CTRL+U if ($key == 65 && $shift == 1 && $ctrl == 0 && $alt == 0) AddNewMagmaInputChannelToFlow "Age" "Float" $prtNode 0 0 1 on on -1 -1; //SHIFT+A if ($key == 66 && $shift == 0 && $ctrl == 1 && $alt == 0) AddNewMagmaOperatorToFlow "Blend" $prtNode 0 0 on on; //CTRL+B if ($key == 67 && $shift == 0 && $ctrl == 1 && $alt == 1) AddNewMagmaOperatorToFlow "Clamp" $prtNode 0 0 on on; //CTRL+C if ($key == 66 && $shift == 1 && $ctrl == 0 && $alt == 0) AddNewMagmaInputChannelToFlow "Absorption" "Vec3" $prtNode 0 0 1 on on -1 -1; //SHIFT+B if ($key == 67 && $shift == 1 && $ctrl == 0 && $alt == 0) AddNewMagmaInputChannelToFlow "Color" "Vec3" $prtNode 0 0 1 on on -1 -1; //SHIFT+C if ($key == 68 && $shift == 1 && $ctrl == 0 && $alt == 0) AddNewMagmaInputChannelToFlow "Density" "Float" $prtNode 0 0 1 on on -1 -1; //SHIFT+D if ($key == 69 && $shift == 1 && $ctrl == 0 && $alt == 0) AddNewMagmaInputChannelToFlow "Emission" "Vec3" $prtNode 0 0 1 on on -1 -1; //SHIFT+E if ($key == 71 && $shift == 0 && $ctrl == 1 && $alt == 0) AddNewMagmaInputGeometryToFlow $prtNode 0 0 on on; //CTRL+G if ($key == 73 && $shift == 1 && $ctrl == 0 && $alt == 0) AddNewMagmaInputChannelToFlow "ID" "Int" $prtNode 0 0 1 on on -1 -1; //SHIFT+I if ($key == 76 && $shift == 1 && $ctrl == 0 && $alt == 0) AddNewMagmaInputChannelToFlow "LifeSpan" "Float" $prtNode 0 0 1 on on -1 -1; //SHIFT+L if ($key == 78 && $shift == 0 && $ctrl == 1 && $alt == 0) AddNewMagmaOperatorToFlow "Noise" $prtNode 0 0 on on; //CTRL+N if ($key == 78 && $shift == 0 && $ctrl == 1 && $alt == 1) AddNewMagmaOperatorToFlow "VecNoise" $prtNode 0 0 on on; //CTRL+N if ($key == 78 && $shift == 1 && $ctrl == 0 && $alt == 0) AddNewMagmaInputChannelToFlow "Normal" "Vec3" $prtNode 0 0 1 on on -1 -1; //SHIFT+N if ($key == 80 && $shift == 1 && $ctrl == 0 && $alt == 0) AddNewMagmaInputChannelToFlow "Position" "Vec3" $prtNode 0 0 1 on on -1 -1; //SHIFT+P if ($key == 65 && $shift == 1 && $ctrl == 1 && $alt == 0) AddNewMagmaOutputChannelToFlow "Age" "Float" $prtNode 0 0; //CTRL+SHIFT+A if ($key == 66 && $shift == 1 && $ctrl == 1 && $alt == 0) AddNewMagmaOutputChannelToFlow "Absorption" "Vec3" $prtNode 0 0; //CTRL+SHIFT+B if ($key == 67 && $shift == 1 && $ctrl == 1 && $alt == 0) AddNewMagmaOutputChannelToFlow "Color" "Vec3" $prtNode 0 0; //CTRL+SHIFT+C if ($key == 68 && $shift == 1 && $ctrl == 1 && $alt == 0) AddNewMagmaOutputChannelToFlow "Density" "Float" $prtNode 0 0; //CTRL+SHIFT+D if ($key == 69 && $shift == 1 && $ctrl == 1 && $alt == 0) AddNewMagmaOutputChannelToFlow "Emission" "Vec3" $prtNode 0 0; //CTRL+SHIFT+E if ($key == 73 && $shift == 1 && $ctrl == 1 && $alt == 0) AddNewMagmaOutputChannelToFlow "ID" "Int" $prtNode 0 0; //CTRL+SHIFT+I if ($key == 76 && $shift == 1 && $ctrl == 1 && $alt == 0) AddNewMagmaOutputChannelToFlow "LifeSpan" "Float" $prtNode 0 0; //CTRL+SHIFT+L if ($key == 78 && $shift == 1 && $ctrl == 1 && $alt == 0) AddNewMagmaOutputChannelToFlow "Normal" "Vec3" $prtNode 0 0; //CTRL+SHIFT+N if ($key == 80 && $shift == 1 && $ctrl == 1 && $alt == 0) AddNewMagmaOutputChannelToFlow "Position" "Vec3" $prtNode 0 0; //CTRL+SHIFT+P if ($key == 86 && $shift == 1 && $ctrl == 1 && $alt == 0) AddNewMagmaOutputChannelToFlow "Velocity" "Vec3" $prtNode 0 0; // SHIFT+CTRL+V if ($key == 80 && $shift == 0 && $ctrl == 1 && $alt == 0) MagmaToggleNodeEnabled $prtNode; //CTRL+P if ($key == 86 && $shift == 1 && $ctrl == 0 && $alt == 0) AddNewMagmaInputChannelToFlow "Velocity" "Vec3" $prtNode 0 0 1 on on -1 -1; //SHIFT+V if ($key == 87 && $shift == 0 && $ctrl == 1 && $alt == 0) MagmaSwapInputSockets $prtNode 0; //CTRL+W if ($key == 87 && $shift == 1 && $ctrl == 1 && $alt == 0) MagmaSwapInputSockets $prtNode 1; //SHIFT+CTRL+W if ($key == 89 && $shift == 0 && $ctrl == 1 && $alt == 0) MagmaEditor_RedoRecord $prtNode; //CTRL+Y if ($key == 90 && $shift == 0 && $ctrl == 1 && $alt == 0) MagmaEditor_UndoRecord $prtNode; //CTRL+Z if ($key == 80 && $shift == 0 && $ctrl == 0 && $alt == 0) magma_flux_window_set -prt $prtNode -cx 0.0 -cy 0.0; //P if ($key == 90 && $shift == 0 && $ctrl == 0 && $alt == 0) magma_flux_window_set -prt $prtNode -z 1.0; //Z if ($key == 90 && $shift == 0 && $ctrl == 1 && $alt == 1) magma_flux_window_set -prt $prtNode -z 0.65; //CTRL+ALT+Z if ($key == 90 && $shift == 1 && $ctrl == 1 && $alt == 0) { magma_flux_window_set -prt $prtNode -cx 0.0 -cy 0.0; magma_flux_window_set -prt $prtNode -z 1.0; //CTRL+SHIFT+Z } if ($key == 32 && $shift == 0 && $ctrl == 0 && $alt == 0) MagmaEditor_InsertNodeIntoConnection $prtNode; // SPACE = INSERT NODE INTO SELECTED WIRE if ($key == 32 && $shift == 0 && $ctrl == 1 && $alt == 0) MagmaEditor_RemoveNodeFromConnection $prtNode 0; // CTRL+SPACE = REMOVE NODE AND PRESERVE if ($key == 16777222 && $shift == 0 && $ctrl == 0 && $alt == 0) MagmaEditor_CycleInsertBranchMode $prtNode; if ($key == 16777223 && $shift == 0 && $ctrl == 0 && $alt == 0) // Del { MagmaEditor_DeleteSelection $prtNode; MagmaEditor_ForceUpdate $prtNode; MagmaNodesReorderGrid $prtNode; } if ($key == 16777219 && $shift == 0 && $ctrl == 0 && $alt == 0) // Backspace { MagmaEditor_RemoveNodeFromConnection $prtNode 1; MagmaEditor_ForceUpdate $prtNode; } if ($key == 16777219 && $shift == 1 && $ctrl == 0 && $alt == 0) // SHIFT+Backspace { MagmaEditor_RemoveNodeFromConnection $prtNode 0; MagmaEditor_ForceUpdate $prtNode; } if ($key == 67 && $shift == 0 && $ctrl == 1 && $alt == 0) MagmaEditor_CopyToClipboardFile $prtNode; //CTRL+C if ($key == 86 && $shift == 0 && $ctrl == 1 && $alt == 0) MagmaEditor_PasteFromClipboardFile $prtNode; //CTRL+V //if ($key == 82 && $shift == 0 && $ctrl == 1 && $alt == 0) MagmaNodesReorderGrid $prtNode; // Ctrl+R if ($key == 82 && $shift == 0 && $ctrl == 1 && $alt == 0) MagmaEditor_CycleReorderMode $prtNode 1; // Ctrl+R if ($key == 82 && $shift == 1 && $ctrl == 1 && $alt == 0) MagmaEditor_CycleReorderMode $prtNode 0; // Shift+Ctrl+R } global proc MagmaFLUX_connectToEmpty(string $prtNode, int $dropX, int $dropY, int $sourceID, int $nodeIsSource, int $socketIndex ) { //print "MagmaFLUX_connectToEmpty called\n"; int $needsupdate = 0; checkBox -e -v false ($prtNode+"_chk_enableUpdatesAndReoderCalls"); //print "Disabling redraws...\n"; intField -e -v $sourceID ($prtNode+"_int_NodeID"); intField -e -v $socketIndex ($prtNode+"_int_SocketID"); string $type = `retrieve_magma_node_instance_info -id $sourceID -prt $prtNode -type true`; if ( $nodeIsSource ) { //print( $prtNode + ": " + $sourceID + ":" + $socketIndex + " goes to " + "(" + $dropX + "," + $dropY + ")" + "\n"); if ($type == "InVolume") { magma_flux_window_set -n $sourceID -prt $prtNode; if ($socketIndex == 0) { /*AddNewMagmaOperatorToFlow "Switch" $prtNode 0 0 on on; $needsupdate = 1;*/ MagmaEditor_DefineRightClickMenu $prtNode "IsValidSwitch" "MagmaEditor_IsValidSwitchMenu"; magma_flux_window_menu -prt $prtNode -s {$dropX,$dropY}; MagmaEditor_DefineRightClickMenu $prtNode "All" "MagmaEditor_AllNodesPopupMenu"; } else { MagmaEditor_DefineRightClickMenu $prtNode "Source" "MagmaEditor_AllNodesFromEmptySourceMenu"; magma_flux_window_menu -prt $prtNode -s {$dropX,$dropY}; MagmaEditor_DefineRightClickMenu $prtNode "All" "MagmaEditor_AllNodesPopupMenu"; } } else if ($type == "NearestParticle") { if ($socketIndex == 2) { MagmaEditor_DefineRightClickMenu $prtNode "ParticleQuery" "MagmaEditor_ParticleQueryMenu"; magma_flux_window_menu -prt $prtNode -s {$dropX,$dropY}; MagmaEditor_DefineRightClickMenu $prtNode "All" "MagmaEditor_AllNodesPopupMenu"; } else { MagmaEditor_DefineRightClickMenu $prtNode "Source" "MagmaEditor_AllNodesFromEmptySourceMenu"; magma_flux_window_menu -prt $prtNode -s {$dropX,$dropY}; MagmaEditor_DefineRightClickMenu $prtNode "All" "MagmaEditor_AllNodesPopupMenu"; } } else if ($type == "IntersectRay" || $type == "NearestPoint" || $type == "InVolume") { magma_flux_window_set -n $sourceID -prt $prtNode; if ($socketIndex == 1) { /* MagmaInsertConversionNode $prtNode 0 0 $sourceID "Switch" 1 2 0 1; $needsupdate = 1; */ MagmaEditor_DefineRightClickMenu $prtNode "IsValidSwitch" "MagmaEditor_IsValidSwitchMenu"; magma_flux_window_menu -prt $prtNode -s {$dropX,$dropY}; MagmaEditor_DefineRightClickMenu $prtNode "All" "MagmaEditor_AllNodesPopupMenu"; } else { MagmaEditor_DefineRightClickMenu $prtNode "Source" "MagmaEditor_AllNodesFromEmptySourceMenu"; magma_flux_window_menu -prt $prtNode -s {$dropX,$dropY}; MagmaEditor_DefineRightClickMenu $prtNode "All" "MagmaEditor_AllNodesPopupMenu"; } } else if ($type == "InputGeometry" && $socketIndex == 0) { MagmaEditor_DefineRightClickMenu $prtNode "Geometry" "MagmaEditor_GeometryNodesMenu"; magma_flux_window_menu -prt $prtNode -s {$dropX,$dropY}; MagmaEditor_DefineRightClickMenu $prtNode "All" "MagmaEditor_AllNodesPopupMenu"; } else if ($type == "InputParticles") { if ($socketIndex == 0) { MagmaEditor_DefineRightClickMenu $prtNode "Particles" "MagmaEditor_GeometryNodesMenu"; magma_flux_window_menu -prt $prtNode -s {$dropX,$dropY}; MagmaEditor_DefineRightClickMenu $prtNode "All" "MagmaEditor_AllNodesPopupMenu"; } else { MagmaEditor_DefineRightClickMenu $prtNode "Source" "MagmaEditor_AllNodesFromEmptySourceMenu"; magma_flux_window_menu -prt $prtNode -s {$dropX,$dropY}; MagmaEditor_DefineRightClickMenu $prtNode "All" "MagmaEditor_AllNodesPopupMenu"; } } else if ($type == "InputObject" && $socketIndex == 0) { MagmaEditor_DefineRightClickMenu $prtNode "Object" "MagmaEditor_ObjectNodesMenu"; magma_flux_window_menu -prt $prtNode -s {$dropX,$dropY}; MagmaEditor_DefineRightClickMenu $prtNode "All" "MagmaEditor_AllNodesPopupMenu"; } else { MagmaEditor_DefineRightClickMenu $prtNode "Source" "MagmaEditor_AllNodesFromEmptySourceMenu"; magma_flux_window_menu -prt $prtNode -s {$dropX,$dropY}; MagmaEditor_DefineRightClickMenu $prtNode "All" "MagmaEditor_AllNodesPopupMenu"; } } else { if ($type == "IntersectRay" || $type == "NearestPoint" || $type == "InVolume") { magma_flux_window_set -n $sourceID -prt $prtNode; if ($socketIndex == 0) { MagmaEditor_DefineRightClickMenu $prtNode "InputGeometry" "MagmaEditor_InputGeometryMenu"; magma_flux_window_menu -prt $prtNode -s {$dropX,$dropY}; MagmaEditor_DefineRightClickMenu $prtNode "All" "MagmaEditor_AllNodesPopupMenu"; } else if ($socketIndex == 1) { MagmaEditor_DefineRightClickMenu $prtNode "WorldPosition" "MagmaEditor_WorldPositionMenu"; magma_flux_window_menu -prt $prtNode -s {$dropX,$dropY}; MagmaEditor_DefineRightClickMenu $prtNode "All" "MagmaEditor_AllNodesPopupMenu"; } else if ($socketIndex == 2) { MagmaEditor_DefineRightClickMenu $prtNode "RayDirection" "MagmaEditor_RayDirectionMenu"; magma_flux_window_menu -prt $prtNode -s {$dropX,$dropY}; MagmaEditor_DefineRightClickMenu $prtNode "All" "MagmaEditor_AllNodesPopupMenu"; } } else if ($type == "ElementQuery" || $type == "MeshQuery" || $type == "FaceQuery" || $type == "VertexQuery") { magma_flux_window_set -n $sourceID -prt $prtNode; if ($socketIndex == 0) { MagmaEditor_DefineRightClickMenu $prtNode "InputGeometry" "MagmaEditor_InputGeometryMenu"; magma_flux_window_menu -prt $prtNode -s {$dropX,$dropY}; MagmaEditor_DefineRightClickMenu $prtNode "All" "MagmaEditor_AllNodesPopupMenu"; } else { MagmaEditor_DefineRightClickMenu $prtNode "Target" "MagmaEditor_AllNodesPopupMenu"; magma_flux_window_menu -prt $prtNode -s {$dropX,$dropY}; MagmaEditor_DefineRightClickMenu $prtNode "All" "MagmaEditor_AllNodesPopupMenu"; } } else if ($type == "NearestParticle" || $type == "ParticleSumCount" || $type == "ParticleSumRadius" || $type == "ParticleQuery" ) { magma_flux_window_set -n $sourceID -prt $prtNode; if ($socketIndex == 0) { MagmaEditor_DefineRightClickMenu $prtNode "InputParticles" "MagmaEditor_InputParticlesMenu"; magma_flux_window_menu -prt $prtNode -s {$dropX,$dropY}; MagmaEditor_DefineRightClickMenu $prtNode "All" "MagmaEditor_AllNodesPopupMenu"; } else if ($socketIndex == 1) { MagmaEditor_DefineRightClickMenu $prtNode "WorldPosition" "MagmaEditor_WorldPositionMenu"; magma_flux_window_menu -prt $prtNode -s {$dropX,$dropY}; MagmaEditor_DefineRightClickMenu $prtNode "All" "MagmaEditor_AllNodesPopupMenu"; } else { MagmaEditor_DefineRightClickMenu $prtNode "Target" "MagmaEditor_AllNodesPopupMenu"; magma_flux_window_menu -prt $prtNode -s {$dropX,$dropY}; MagmaEditor_DefineRightClickMenu $prtNode "All" "MagmaEditor_AllNodesPopupMenu"; } } else if ($type == "PropertyQuery") { magma_flux_window_set -n $sourceID -prt $prtNode; if ($socketIndex == 0) { MagmaEditor_DefineRightClickMenu $prtNode "InputObject" "MagmaEditor_InputObjectMenu"; magma_flux_window_menu -prt $prtNode -s {$dropX,$dropY}; MagmaEditor_DefineRightClickMenu $prtNode "All" "MagmaEditor_AllNodesPopupMenu"; } } else { MagmaEditor_DefineRightClickMenu $prtNode "Target" "MagmaEditor_AllNodesFromEmptyTarget"; magma_flux_window_menu -prt $prtNode -s {$dropX,$dropY}; MagmaEditor_DefineRightClickMenu $prtNode "All" "MagmaEditor_AllNodesPopupMenu"; } //print( $prtNode + ": " + "(" + $dropX + "," + $dropY + ")" + " goes to " + $sourceID + ":" + $socketIndex + "\n"); } checkBox -e -v true ($prtNode+"_chk_enableUpdatesAndReoderCalls"); int $selNodes[] = `magma_flux_window_query -n true -prt $prtNode`; MagmaFLUX_resetSelection $prtNode $selNodes; //print "Enabling redraws...\n"; if ($needsupdate) { MagmaEditor_ForceUpdate $prtNode; MagmaNodesReorderGrid $prtNode; } } global proc KMYMAGMAED_selectCurrentObject () { string $selectedItemMultSelect[] = `textScrollList -q -si lbx_MagmaPRTObjects`; if (size($selectedItemMultSelect) > 0) { string $selectedItem = $selectedItemMultSelect[0]; select -r $selectedItem; } } global proc KMYMAGMAED_OpenMagmaForCurrentObject () { string $baseSelectionObjects[] = `ls -l -sl`; if( size($baseSelectionObjects) == 1 ) { OpenMagmaFLUXDialog $baseSelectionObjects[0]; } } //Required because stringArrayFind is not available in 2012 global proc int stringArrayFindWrapper( string $item, int $index, string $list[] ) { if ( `getApplicationVersionAsFloat` > 2012 ) return stringArrayFind( $item, $index, $list ); else { int $i; for ( $i = $index; $i < `size $list`; $i++ ) { if ( $list[$i] == $item ) return $i; } return -1; } } global proc OpenKrakatoaMagmaEditor () { string $allObjects[] = `ls -l -v -typ "PRTFractal" -typ "PRTLoader" -typ "PRTVolume" -typ "PRTSurface" -typ "particle" -typ "nParticle"`; string $baseSelectionObjects[] = `ls -l -sl`; if( size($baseSelectionObjects) == 1 ) { // Get to the actual particle object string $objectName = $baseSelectionObjects[0]; int $index = stringArrayFindWrapper( $objectName, 0, $allObjects ); if ( $index < 0 ) { string $newSelection[] = `listRelatives -shapes $baseSelectionObjects[0]`; string $newFullName[] =`ls -l $newSelection[0]`; $objectName = $newFullName[0]; $index = stringArrayFindWrapper( $objectName, 0, $allObjects ); if ( $index < 0 ) { string $ret = `confirmDialog -title "Krakatoa MY Magma" -message "Selected object does not support Magma." -button "OK" -defaultButton "OK" -cancelButton "OK"`; return; } } // Get the last object string $lastObject = `KMYMODED_getObjectToConnectModifierTo $objectName`; if ( `objectType $lastObject` != "PRTMagma" ) { // If it's not there, add it $lastObject = KMYMOD_addMagmaMod( $lastObject ); } // Open it OpenMagmaFLUXDialog $lastObject; } else { string $ret = `confirmDialog -title "Krakatoa MY Magma" -message "No object or multiple objects selected." -button "OK" -defaultButton "OK" -cancelButton "OK"`; } } // Geometry Selection // global proc KMYMAGMAED_getCurrentSceneSelectionGeometry (string $nodeName, string $attribute, string $listcontrol) { string $selected[] = `ls -sl`; string $allObjects[] = `ls -g -l`; string $particleObjects[] = `ls -v -l -typ "PRTFractal" -typ "PRTLoader" -typ "PRTVolume" -typ "PRTSurface" -typ "particle" -type "nParticle"`; string $nodeattr = ($nodeName + "." + $attribute); string $currentList[] = `getAttr $nodeattr`; for ($anObject in $selected) { string $theShape = `AttachSelectedMesh {$anObject}`; if (stringArrayFindWrapper( $theShape, 0, $particleObjects) > -1) continue; if (stringArrayFindWrapper( $theShape, 0, $currentList) > -1) continue; if (stringArrayFindWrapper( $theShape, 0, $allObjects) > -1) $currentList[`size $currentList`] = $theShape; } string $setAttrArgs = `MagmaFLUX_ListToStringSetAttr $currentList`; eval("setAttr \""+$nodeattr+"\" -type \"stringArray\" " + $setAttrArgs + ";"); MagmaEditor_ForceUpdate $nodeName; MagmaEditor_CreateUndoRecord $nodeName ("Add Geometry Objects"); } global proc KMYMAGMAED_removeHighlightedGeometryFromList (string $nodeName, string $attribute, string $listcontrol) { string $selectedItems[] = `textScrollList -q -si $listcontrol`; string $nodeattr = ($nodeName + "." + $attribute); string $currentList[] = `getAttr $nodeattr`; string $newList[]; for ($i = 0; $i < `size $currentList`; $i++) if (stringArrayFindWrapper( $currentList[$i], 0, $selectedItems) == -1) $newList[`size $newList`]= $currentList[$i]; string $setAttrArgs = `MagmaFLUX_ListToStringSetAttr $newList`; eval("setAttr \""+$nodeattr+"\" -type \"stringArray\" " + $setAttrArgs + ";"); MagmaEditor_ForceUpdate $nodeName; MagmaEditor_CreateUndoRecord $nodeName ("Remove Geometry Objects"); } global proc KMYMAGMAED_assignMeshDoIt(string $selectedNodes[], string $nodeName, string $attribute) { //print "test\n"; string $targetNode = `AttachSelectedMesh $selectedNodes`; if ( $targetNode == "" ) { warning "Not assigning geometry: no suitable mesh was found under the current scene selection\n"; } else { string $nodeattr = ($nodeName + "." + $attribute); string $datatype = `getAttr -type $nodeattr`; if ( $datatype == "stringArray" ) { // Append result string $currentResults[] = `getAttr $nodeattr`; // Ignore duplicates int $insert = 1; for( $element in $currentResults ) { if ( $element == $targetNode ) { $insert = 0; break; } } appendStringArray $currentResults {$targetNode} 1; if ( $insert ) { string $setAttrArgs = `MagmaFLUX_ListToStringSetAttr $currentResults`; print ( $setAttrArgs + "\n" ); eval("setAttr $nodeattr -type \"stringArray\" " + $setAttrArgs + ";"); } } else { setAttr $nodeattr -type "string" $targetNode; } } } global proc KMYMAGMAED_assignMeshEnd(string $meshSelectContext) { if ( `contextInfo -ex $meshSelectContext` ) { deleteUI $meshSelectContext; } } global proc KMYMAGMAED_assignMeshBegin(string $nodeName, string $attribute) { select -r $nodeName; string $meshSelectContext = "meshSelectContext"; KMYMAGMAED_assignMeshEnd $meshSelectContext; scriptCtx -title "Magma Mesh Select" -totalSelectionSets 1 -setSelectionCount 1 -setAutoComplete true -setAllowExcessCount true -setNoSelectionPrompt "Please select a mesh to use for this magma node" -toolFinish ("evalDeferred(\"KMYMAGMAED_assignMeshEnd " + $meshSelectContext + ";\")") -finalCommandScript ("KMYMAGMAED_assignMeshDoIt $Selection1 \"" + $nodeName + "\" \"" + $attribute + "\";") $meshSelectContext; setToolTo $meshSelectContext; } global proc MagmaEditor_ExportToKrakatoaMXMagma ( string $prtNode) { string $filePath[] = `fileDialog2 -fileMode 0 -caption "SAVE The Magma Flow To Krakatoa MX File..." -fileFilter ("Krakatoa MX Magma Flow (*.MagmaScript)")`; if (`size $filePath[0]`) { $fileId = `fopen $filePath[0] "w"`; fprint $fileId ("(--MAGMAFLOW2-- \n"); int $allNodes[] = `retrieve_magma_node_ids -prt $prtNode`; int $selNodes[] = `magma_flux_window_query -n true -prt $prtNode`; for ($aNode in $allNodes) { string $type = `retrieve_magma_node_instance_info -id $aNode -prt $prtNode -type true`; string $aNodeSig = "node"+$aNode; fprint $fileId ($aNodeSig+" = magmaNode.createNode \""+$type+"\" \n"); string $infoBuffer[] = `retrieve_magma_node_info -t $type -p true`; string $tokens[]; int $valueType = 1; for ($anInfo in $infoBuffer) { tokenize($anInfo, ",:", $tokens); string $propValue; if ($tokens[2] =="Vector3f") { float $propValueF[] = `getAttr ($prtNode+"."+$type+"_"+$aNode+"_Property"+$tokens[0] + "_"+ $tokens[1]+"_" + $tokens[2])`; $propValue = "["+$propValueF[0]+","+$propValueF[1]+","+$propValueF[2]+"]"; } else { $propValue = `getAttr ($prtNode+"."+$type+"_"+$aNode+"_Property"+$tokens[0] + "_"+ $tokens[1]+"_" + $tokens[2])`; if ($propValue == "Vec3") $propValue = "float32[3]"; if ($type == "InputValue" && $tokens[1] == "enumValue") { $valueType = $propValue; $tokens[1] = "forceInteger"; $propValue = "False"; string $controllerType = "Bezier_Float"; if ($valueType == "2") $propValue = "True"; if ($valueType == "3") $controllerType = "Point3_XYZ"; fprint $fileId ("ctrl="+$controllerType+"()\n"); fprint $fileId ("magmaNode.setNodeProperty "+$aNodeSig+" \"controller\" ctrl\n"); } } if ($tokens[1] == "vec3Value") { if ($valueType == 3) fprint $fileId ("ctrl.value = "+ $propValue +"\n"); continue; } if ($tokens[1] == "iValue") { if ($valueType == 2) fprint $fileId ("ctrl.value = "+ $propValue +"\n"); continue; } if ($tokens[1] == "fValue") { if ($valueType == 1) fprint $fileId ("ctrl.value = "+ $propValue +"\n"); continue; } string $printline = "magmaNode.setNodeProperty "+$aNodeSig+" \""+$tokens[1]+"\" "; if ($tokens[2] == "String" || $tokens[2] == "MagmaDataType") { $printline += "\"" + $propValue +"\""; } else if ($tokens[2] == "Bool") { string $boolValue = "True"; if ($propValue == 0) $boolValue = "False"; $printline += $boolValue; } else { $printline += $propValue; } fprint $fileId ($printline+"\n"); } //Export node Position fprint $fileId ("magmaNode.DeclareExtensionProperty "+$aNodeSig+" \"Position\"\n"); int $pos[] = `retrieve_magma_node_instance_info -id $aNode -prt $prtNode -xy true`; fprint $fileId ("magmaNode.SetNodeProperty "+$aNodeSig+" \"Position\" ["+ $pos[0]*0.7 +","+ ($pos[1]+1)*0.7 +"]\n"); // Export selected state of the node for ($i in $selNodes) { if ($i == $aNode) { fprint $fileId ("magmaNode.DeclareExtensionProperty "+$aNodeSig+" \"Selected\" \n"); fprint $fileId ("magmaNode.SetNodeProperty "+$aNodeSig+" \"Selected\" true \n"); } } //Export Input Socket Defaults, if any string $category = MagmaGetNodeCategoryFromType($type); if( $category != "Input" ) { string $inInfoBuffer[] = `retrieve_magma_node_info -t $type -is true`; for( $currentInfo in $inInfoBuffer ) { string $attr; string $currentInfoBuffer[] = `MagmaFLUX_PropertyTokenizer $currentInfo`; string $socketNameBuffer[]; tokenize $currentInfoBuffer[0] "#:" $socketNameBuffer; string $socketNumber = $socketNameBuffer[1]; string $socketName = $socketNameBuffer[2]; string $attributeTypes = $currentInfoBuffer[2]; // Check if there are any options for the socket string $attributeTypesBuffer[]; tokenize $attributeTypes " " $attributeTypesBuffer; if( `size $attributeTypesBuffer` <= 0 ) continue; if( `size $attributeTypesBuffer` == 1 && `size $attributeTypesBuffer[0]` <= 0) continue; string $signature = $prtNode + "." + $type + "_" + $aNode + "_" + "InputSocket" + $socketNumber; // eval ("setAttr "+$signature + "_enum "+$enum+";"); //$socketValue = ; //fprint $fileId ("magmaNode.setNodeInputDefaultValue "+ $aNodeSig +" "+($socketNumber+1)+" "+$socketValue+"\n"); } } fprint $fileId ("--------------------------------------------\n"); } for ($aNode in $allNodes) { int $connection[] = `get_magma_connections -prt $prtNode -id $aNode`; for ($i = 0; $i < `size $connection`; $i=$i+2) { if ($connection[$i] != -1) { fprint $fileId ("try(magmaNode.setNodeInput node"+$aNode+" "+($i/2+1)+" node"+$connection[$i]+" "+($connection[$i+1]+1)+" )catch()\n"); } } } fprint $fileId ")\n"; fclose $fileId; } } global proc MagmaEditor_SaveFlowToPath (string $prtNode, string $filePath, string $comment, int $selected) { string $nodes[] = `get_magma_description -prt $prtNode -n true -s $selected`; // get all the nodes and their color, position, and type int $edges[] = `get_magma_description -prt $prtNode -e true -s $selected`; // get all the edges string $props[] = `get_magma_description -prt $prtNode -v true -s $selected`; // get all the magma properties string $defaults[] = `get_magma_description -prt $prtNode -iv true -s $selected`; // get all the magma defaults string $propsAnim[] = `get_magma_description -prt $prtNode -va true -s $selected`; // get all the magma properties that are animated string $defaultsAnim[] = `get_magma_description -prt $prtNode -iva true -s $selected`; // get all the magma socket inputs that are animated $fileId = `fopen $filePath "w"`; fprint $fileId ("//"+$comment+"\n"); fprint $fileId ("global proc _MagmaEditor_LoadFlowFromDisk ( string $prtNode, int $replace, int $offset )\n{\n"); int $first; $first = 1; fprint $fileId ("string $nodes[] = {"); for ($i in $nodes) { if ( $first ) $first = 0; else fprint $fileId (","); fprint $fileId ( "\"" + $i + "\"" ); } fprint $fileId ("};\n") ; fprint $fileId ("int $edges[] = {"); int $cnt = 0; for ($i in $edges) { fprint $fileId ($i); if ($cnt < `size $edges`-1) fprint $fileId (", "); $cnt++; } fprint $fileId ("};\n") ; $first = 1; fprint $fileId ("string $props[] = {"); for ($i in $props) { if ( $first ) $first = 0; else fprint $fileId (","); //TODO: should we account for unprintable/special chars like double quotes? fprint $fileId ( "\"" + $i + "\"" ); } fprint $fileId ("};\n") ; $first = 1; fprint $fileId ("string $defaults[] = {"); for ($i in $defaults) { if ( $first ) $first = 0; else fprint $fileId (","); fprint $fileId ( "\"" + $i + "\"" ); } fprint $fileId ("};\n") ; $first = 1; fprint $fileId ("string $propsAnim[] = {"); for ($i in $propsAnim) { if ( $first ) $first = 0; else fprint $fileId (","); fprint $fileId ( "\"" + $i + "\"" ); } fprint $fileId ("};\n") ; $first = 1; fprint $fileId ("string $defaultsAnim[] = {"); for ($i in $defaultsAnim) { if ( $first ) $first = 0; else fprint $fileId (","); fprint $fileId ( "\"" + $i + "\"" ); } fprint $fileId ("};\n") ; fprint $fileId ("apply_magma_description -prt $prtNode -n $nodes -e $edges -v $props -iv $defaults -va $propsAnim -iva $defaultsAnim -rn $replace -y $offset;\n"); fprint $fileId ("}\n"); fclose $fileId ; } global proc MagmaEditor_ClearUndoRecords (string $prtNode) { string $tmpDir = `internalVar -userTmpDir`; $tmpDir += "KMY_Magma/"; sysFile -md $tmpDir; string $undofiles[] = `getFileList -folder $tmpDir -filespec ("_"+$prtNode+"_magmaundo.*")`; for ($aFile in $undofiles) { sysFile -delete ($tmpDir +$aFile); } sysFile -delete ($tmpDir+"_"+$prtNode+"_magmaundoinfo.txt"); } global proc string MagmaEditor_GetUndoNameFromRecord (string $prtNode, int $offset) { string $tmpDir = `internalVar -userTmpDir`; $tmpDir += "KMY_Magma/"; sysFile -md $tmpDir; int $recordNumber = 0; $fileId1 = `fopen ($tmpDir+"_"+$prtNode+"_magmaundoinfo.txt") "r"`; string $word = `fgetword $fileId1`; fclose $fileId1 ; if (`size $word`) $recordNumber = (int)$word; string $comment = ""; string $undoFileToLoad = ($tmpDir+"_"+$prtNode+"_magmaundo."+($recordNumber+$offset)); if (`filetest -r $undoFileToLoad`) { $fileId2 = `fopen $undoFileToLoad "r"`; $comment =`fgetline $fileId2`; fclose $fileId2 ; if (`size $comment`==0 || ($recordNumber+$offset) == 1) $comment = ""; } string $commentArray[]; tokenize $comment "//" $commentArray; return $commentArray[0]; } global proc MagmaEditor_UpdateUndoRedoInfo (string $prtNode) { string $previousRecord = `MagmaEditor_GetUndoNameFromRecord $prtNode 0`; string $nextRecord = `MagmaEditor_GetUndoNameFromRecord $prtNode 1`; int $undoOn = true; if ($previousRecord == "") $undoOn = false; else $previousRecord = "'"+$previousRecord+"'"; int $redoOn = true; if ($nextRecord == "") $redoOn = false; else $nextRecord = "'"+$nextRecord+"'"; menuItem -e -label ("Undo "+$previousRecord) -enable $undoOn mnu_undoCommand; menuItem -e -label ("Redo "+$nextRecord) -enable $redoOn mnu_redoCommand; } global proc MagmaEditor_CreateUndoRecord (string $prtNode, string $undoName) { string $tmpDir = `internalVar -userTmpDir`; $tmpDir += "KMY_Magma/"; sysFile -md $tmpDir; //figure out the current undo record int $recordNumber = 0; string $undoInfoFile = ($tmpDir+"_"+$prtNode+"_magmaundoinfo.txt"); if (`filetest -r $undoInfoFile`) { $fileId = `fopen $undoInfoFile "r"`; string $word = `fgetword $fileId`; fclose $fileId ; if (`size $word`) $recordNumber = (int)$word; } //figure out the last record index int $lastrecord = 0; string $undofiles[] = `getFileList -folder $tmpDir -filespec ("_"+$prtNode+"_magmaundo.*")`; if (`size $undofiles`) $lastrecord = (int)fileExtension($undofiles[`size $undofiles`-1]); //if the current record is less than the last one, we have to delete all records after it! for ($aFile in $undofiles) { string $ext = fileExtension($aFile); int $extAsInt = (int)$ext; if ($extAsInt > $recordNumber) { sysFile -delete ($tmpDir +$aFile); } } $recordNumber++; string $undofile = $tmpDir+"_"+$prtNode+"_magmaundo."+$recordNumber; MagmaEditor_SaveFlowToPath $prtNode $undofile $undoName 0; //store the current record number on disk $fileId = `fopen ($tmpDir+"_"+$prtNode+"_magmaundoinfo.txt") "w"`; fprint $fileId ($recordNumber+"\n") ; fclose $fileId ; MagmaEditor_UpdateUndoRedoInfo $prtNode; } global proc MagmaEditor_UndoRecord (string $prtNode) { string $tmpDir = `internalVar -userTmpDir`; $tmpDir += "KMY_Magma/"; sysFile -md $tmpDir; //figure out the current undo record int $recordNumber = 0; string $undoInfoFile = ($tmpDir+"_"+$prtNode+"_magmaundoinfo.txt"); if (`filetest -r $undoInfoFile`) { $fileId = `fopen $undoInfoFile "r"`; string $word = `fgetword $fileId`; fclose $fileId ; if (`size $word`) $recordNumber = (int)$word; } //print ("Current Record is "+$recordNumber+"\n"); //if the record is greater than 1, step back by one and restore the previous undo record if ($recordNumber > 1) { //print ("Undo Record \n"); $recordNumber--; string $undofile = $tmpDir+"_"+$prtNode+"_magmaundo."+$recordNumber; eval ("source \""+$undofile+"\";"); checkBox -e -v false ($prtNode+"_chk_enableUpdatesAndReoderCalls"); checkBox -e -v false ($prtNode+"_chk_enableCallbacks"); _MagmaEditor_LoadFlowFromDisk $prtNode true 0 ; checkBox -e -v true ($prtNode+"_chk_enableCallbacks"); checkBox -e -v true ($prtNode+"_chk_enableUpdatesAndReoderCalls"); MagmaNodesReorderGrid $prtNode; MagmaEditor_RepaintSockets $prtNode 0; //store the updated number $fileId = `fopen ($tmpDir+"_"+$prtNode+"_magmaundoinfo.txt") "w"`; fprint $fileId ($recordNumber+"\n") ; fclose $fileId ; MagmaEditor_UpdateUndoRedoInfo $prtNode; } int $selnodes[] = `magma_flux_window_query -n true -prt $prtNode`; MagmaFLUX_resetSelection $prtNode $selnodes; } global proc MagmaEditor_RedoRecord (string $prtNode) { string $tmpDir = `internalVar -userTmpDir`; $tmpDir += "KMY_Magma/"; sysFile -md $tmpDir; //figure out the current undo record int $recordNumber = 0; string $undoInfoFile = ($tmpDir+"_"+$prtNode+"_magmaundoinfo.txt"); if (`filetest -r $undoInfoFile`) { $fileId = `fopen $undoInfoFile "r"`; string $word = `fgetword $fileId`; fclose $fileId ; if (`size $word`) $recordNumber = (int)$word; } //print ("Current Record is "+$recordNumber+"\n"); //print ("Redo Record \n"); $recordNumber++; string $undofile = $tmpDir+"_"+$prtNode+"_magmaundo."+$recordNumber; if (`filetest -r $undofile`) { eval ("source \""+$undofile+"\";"); checkBox -e -v false ($prtNode+"_chk_enableUpdatesAndReoderCalls"); checkBox -e -v false ($prtNode+"_chk_enableCallbacks"); _MagmaEditor_LoadFlowFromDisk $prtNode true 0 ; checkBox -e -v true ($prtNode+"_chk_enableCallbacks"); checkBox -e -v true ($prtNode+"_chk_enableUpdatesAndReoderCalls"); MagmaNodesReorderGrid $prtNode; MagmaEditor_RepaintSockets $prtNode 0; //store the updated number $fileId = `fopen ($tmpDir+"_"+$prtNode+"_magmaundoinfo.txt") "w"`; fprint $fileId ($recordNumber+"\n") ; fclose $fileId ; MagmaEditor_UpdateUndoRedoInfo $prtNode; } int $selnodes[] = `magma_flux_window_query -n true -prt $prtNode`; MagmaFLUX_resetSelection $prtNode $selnodes; } global proc MagmaEditor_SaveMagmaFlowToDisk ( string $prtNode, int $saveSelected ) { string $caption = "SAVE The Krakatoa MY Magma Flow To File..."; if ($saveSelected) $caption = "SAVE SELECTED Magma Nodes To File..."; string $filePath[] = `fileDialog2 -fileMode 0 -caption $caption -fileFilter ("Magma Flow Scripts (*.magmamel)")`; if (`size $filePath[0]`) { MagmaEditor_SaveFlowToPath $prtNode $filePath[0] "Magma File Save" $saveSelected; } } global proc MagmaEditor_LoadMagmaFlowFromDisk ( string $prtNode, int $replace, int $offset ) { string $cap = "Select a Krakatoa MY Magma Flow File To "; string $mode = "MERGE"; if ($replace) $mode = "LOAD"; $cap+= $mode; string $filePath[] = `fileDialog2 -fileMode 1 -caption $cap -fileFilter ("Magma Flow Scripts (*.magmamel)")`; if (`size $filePath[0]` && `filetest -r $filePath[0]`) { eval ("source \""+$filePath[0]+"\";"); checkBox -e -v false ($prtNode+"_chk_enableUpdatesAndReoderCalls"); checkBox -e -v false ($prtNode+"_chk_enableCallbacks"); _MagmaEditor_LoadFlowFromDisk $prtNode $replace $offset ; checkBox -e -v true ($prtNode+"_chk_enableCallbacks"); checkBox -e -v true ($prtNode+"_chk_enableUpdatesAndReoderCalls"); MagmaNodesReorderGrid $prtNode; MagmaEditor_RepaintSockets $prtNode 0; MagmaEditor_UpdateColorScheme $prtNode 0; MagmaEditor_ForceUpdate $prtNode; MagmaEditor_CreateUndoRecord $prtNode ($mode+" File `"+basename( $filePath[0], "" ) +"'"); int $selNodes[] = `magma_flux_window_query -n true -prt $prtNode`; MagmaFLUX_resetSelection $prtNode $selNodes; } } global proc MagmaEditor_CopyToClipboardFile (string $prtNode) { string $tmpDir = `internalVar -userTmpDir`; $tmpDir += "KMY_Magma/"; sysFile -md $tmpDir; string $clipboard = $tmpDir+"_Magma_Clipboard.magmamel"; MagmaEditor_SaveFlowToPath $prtNode $clipboard "Clipboard" 1; } global proc MagmaEditor_PasteFromClipboardFile (string $prtNode) { string $tmpDir = `internalVar -userTmpDir`; $tmpDir += "KMY_Magma/"; sysFile -md $tmpDir; string $undofile = $tmpDir+"_Magma_Clipboard.magmamel"; if (`filetest -r $undofile`) { eval ("source \""+$undofile+"\";"); checkBox -e -v false ($prtNode+"_chk_enableUpdatesAndReoderCalls"); checkBox -e -v false ($prtNode+"_chk_enableCallbacks"); _MagmaEditor_LoadFlowFromDisk $prtNode false 0 ; checkBox -e -v true ($prtNode+"_chk_enableCallbacks"); checkBox -e -v true ($prtNode+"_chk_enableUpdatesAndReoderCalls"); MagmaNodesReorderGrid $prtNode; MagmaEditor_RepaintSockets $prtNode 0; MagmaEditor_CreateUndoRecord $prtNode ("Paste From Clipboard"); } } global proc int[] MagmaEditor_CollectAllToWorldPositionNodes (string $prtNode) { int $array[]; int $allNodes[] = `retrieve_magma_node_ids -prt $prtNode`; for ($aNode in $allNodes) { string $type = `retrieve_magma_node_instance_info -id $aNode -prt $prtNode -type true`; if ($type == "ToWorld") { int $connection[] = `get_magma_connections -prt $prtNode -id $aNode`; if ($connection[0] != -1) { string $type2 = `retrieve_magma_node_instance_info -id $connection[0] -prt $prtNode -type true`; if ($type2 == "InputChannel") { string $channelName = eval ("getAttr "+$prtNode + "." + $type2 +"_"+ $connection[0] +"_Property1_channelName_String;"); if ($channelName == "Position") $array[`size $array`] = $aNode; } } } } return $array; } global proc int[] MagmaEditor_CollectAllNodesOfType (string $prtNode, string $type) { int $array[]; int $allNodes[] = `retrieve_magma_node_ids -prt $prtNode`; for ($aNode in $allNodes) { string $type2 = `retrieve_magma_node_instance_info -id $aNode -prt $prtNode -type true`; if ($type2 == $type) { $array[`size $array`] = $aNode; } } return $array; } global proc MagmaEditor_DefineRightClickMenu (string $prtNode, string $mode, string $popupMenuName) { magma_flux_window_menu -prt $prtNode -c true; string $channels[] = MagmaFLUX_getChannelTypes(); if ($mode == "Geometry") { string $ObjectItems[] = { "ElementQuery","FaceQuery","IntersectRay","InVolume","MeshQuery","NearestPoint","VertexQuery"}; for ($i=0; $i <`size $ObjectItems`; $i++) magma_flux_window_menu -prt $prtNode -m {$ObjectItems[$i]} -a $popupMenuName; } else if ($mode == "Particles") { string $ObjectItems[] = { "NearestParticle","ParticleQuery","ParticleSumCount","ParticleSumRadius"}; for ($i=0; $i <`size $ObjectItems`; $i++) magma_flux_window_menu -prt $prtNode -m {$ObjectItems[$i]} -a $popupMenuName; } else if ($mode == "Object") { magma_flux_window_menu -prt $prtNode -m {"PropertyQuery"} -a $popupMenuName; } else if ($mode == "WorldPosition") { int $worldPosNodes[] = `MagmaEditor_CollectAllToWorldPositionNodes $prtNode`; int $nodeID = `intField -q -v ($prtNode+"_int_NodeID")`; int $connection[] = `get_magma_connections -prt $prtNode -id $nodeID`; for ($i=0; $i<`size $worldPosNodes`; $i++) { if ($connection[0] != $worldPosNodes[$i]) magma_flux_window_menu -prt $prtNode -m {"Connect To Existing ToWorld_"+$worldPosNodes[$i] } -a $popupMenuName; } magma_flux_window_menu -prt $prtNode -m {"New InputChannel Position->ToWorld"} -a $popupMenuName; magma_flux_window_menu -prt $prtNode -m {"All Nodes Menu..."} -a $popupMenuName; } else if ($mode == "RayDirection") { magma_flux_window_menu -prt $prtNode -m {"Down Vector (0,-1,0)"} -a $popupMenuName; magma_flux_window_menu -prt $prtNode -m {"Up Vector (0,1,0)"} -a $popupMenuName; magma_flux_window_menu -prt $prtNode -m {"All Nodes Menu..."} -a $popupMenuName; } else if ($mode == "IsValidSwitch") { magma_flux_window_menu -prt $prtNode -m {"Create Logical Switch"} -a $popupMenuName; magma_flux_window_menu -prt $prtNode -m {"All Nodes Menu..."} -a $popupMenuName; } else if ($mode == "ParticleQuery") { magma_flux_window_menu -prt $prtNode -m {"Create And Connect ParticleQuery"} -a $popupMenuName; magma_flux_window_menu -prt $prtNode -m {"All Nodes Menu..."} -a $popupMenuName; } else if ($mode == "InputParticles") { int $possibleNodes[] = `MagmaEditor_CollectAllNodesOfType $prtNode "InputParticles"`; int $nodeID = `intField -q -v ($prtNode+"_int_NodeID")`; int $connection[] = `get_magma_connections -prt $prtNode -id $nodeID`; for ($i=0; $i<`size $possibleNodes`; $i++) { if ($connection[0] != $possibleNodes[$i]) magma_flux_window_menu -prt $prtNode -m {"Connect To Existing InputParticles_"+$possibleNodes[$i] } -a $popupMenuName; } magma_flux_window_menu -prt $prtNode -m {"New InputParticles Node"} -a $popupMenuName; } else if ($mode == "InputGeometry") { int $possibleNodes[] = `MagmaEditor_CollectAllNodesOfType $prtNode "InputGeometry"`; int $nodeID = `intField -q -v ($prtNode+"_int_NodeID")`; int $connection[] = `get_magma_connections -prt $prtNode -id $nodeID`; for ($i=0; $i<`size $possibleNodes`; $i++) { if ($connection[0] != $possibleNodes[$i]) magma_flux_window_menu -prt $prtNode -m {"Connect To Existing InputGeometry_"+$possibleNodes[$i] } -a $popupMenuName; } magma_flux_window_menu -prt $prtNode -m {"New InputGeometry Node"} -a $popupMenuName; } else if ($mode == "InputObject") { int $possibleNodes[] = `MagmaEditor_CollectAllNodesOfType $prtNode "InputObject"`; int $nodeID = `intField -q -v ($prtNode+"_int_NodeID")`; int $connection[] = `get_magma_connections -prt $prtNode -id $nodeID`; for ($i=0; $i<`size $possibleNodes`; $i++) { if ($connection[0] != $possibleNodes[$i]) magma_flux_window_menu -prt $prtNode -m {"Connect To Existing InputObject_"+$possibleNodes[$i] } -a $popupMenuName; } magma_flux_window_menu -prt $prtNode -m {"New InputObject Node"} -a $popupMenuName; } else { if ($mode != "Source") { for ($i=1; $i <`size $channels`; $i++) magma_flux_window_menu -prt $prtNode -m {"INPUT","InputChannel", $channels[$i]} -a $popupMenuName; magma_flux_window_menu -prt $prtNode -m {"INPUT","InputGeometry"} -a $popupMenuName; magma_flux_window_menu -prt $prtNode -m {"INPUT","InputParticles"} -a $popupMenuName; magma_flux_window_menu -prt $prtNode -m {"INPUT","InputObject"} -a $popupMenuName; magma_flux_window_menu -prt $prtNode -m {"INPUT","InputValue","Integer"} -a $popupMenuName; magma_flux_window_menu -prt $prtNode -m {"INPUT","InputValue","Float"} -a $popupMenuName; magma_flux_window_menu -prt $prtNode -m {"INPUT","InputValue","Vector"} -a $popupMenuName; } string $ArithmeticItems[] = { "Abs","Add","Ceil","Divide","Floor","Log","Modulo","Multiply","Negate","Power","Sqrt","Subtract"}; for ($i=0; $i <`size $ArithmeticItems`; $i++) magma_flux_window_menu -prt $prtNode -m {"Arithmetic",$ArithmeticItems[$i]} -a $popupMenuName; string $ConvertItems[] = { "AngleAxisToQuat","Breakout","EulerAnglesToQuat","QuatToVectors","ToFloat","ToInt","ToVector","VectorsToQuat"}; for ($i=0; $i <`size $ConvertItems`; $i++) magma_flux_window_menu -prt $prtNode -m {"Convert",$ConvertItems[$i]} -a $popupMenuName; string $FunctionItems[] = { "Blend","Clamp","Noise","VecNoise","ExponentialRandom","GaussianRandom","TriangleRandom","UniformOnSphere","UniformRandom","VecUniformRandom","WeibullRandom"}; for ($i=0; $i <`size $FunctionItems`; $i++) magma_flux_window_menu -prt $prtNode -m {"Function",$FunctionItems[$i]} -a $popupMenuName; string $LogicItems[] = { "Equal","Greater","GreaterOrEqual","Less","LessOrEqual","LogicalAnd","LogicalNot","LogicalOr","LogicalXor","Mux","NotEqual","Switch"}; for ($i=0; $i <`size $LogicItems`; $i++) magma_flux_window_menu -prt $prtNode -m {"Logic",$LogicItems[$i]} -a $popupMenuName; string $ObjectItems[] = { "ElementQuery","FaceQuery","IntersectRay","InVolume","MeshQuery","NearestParticle","NearestPoint","ParticleQuery","ParticleSumCount","ParticleSumRadius","PropertyQuery","VertexQuery"}; for ($i=0; $i <`size $ObjectItems`; $i++) magma_flux_window_menu -prt $prtNode -m {"Object",$ObjectItems[$i]} -a $popupMenuName; string $TransformItems[] = { "FromCamera","FromWorld","ToCamera","ToWorld", "FromSpace", "ToSpace", "TransformByQuat"}; for ($i=0; $i <`size $TransformItems`; $i++) magma_flux_window_menu -prt $prtNode -m {"Transform",$TransformItems[$i]} -a $popupMenuName; string $TrigonometryItems[] = { "ACos","ASin","ATan","ATan2","Cos","Sin","Tan"}; for ($i=0; $i <`size $TrigonometryItems`; $i++) magma_flux_window_menu -prt $prtNode -m {"Trigonometry",$TrigonometryItems[$i]} -a $popupMenuName; string $VectorsItems[] = { "ComponentSum","Magnitude","MatrixMulVec","Normalize","VectorCross","VectorDot"}; for ($i=0; $i <`size $VectorsItems`; $i++) magma_flux_window_menu -prt $prtNode -m {"Vectors",$VectorsItems[$i]} -a $popupMenuName; if ($mode != "Target") { for ($i=1; $i <`size $channels`; $i++) magma_flux_window_menu -prt $prtNode -m {"OUTPUT",$channels[$i]} -a $popupMenuName; } } } global proc MagmaEditor_AllNodesPopupMenu( int $x, int $y, string $menuPath[], string $prtNode ) { checkBox -e -v true ($prtNode+"_chk_enableUpdatesAndReoderCalls"); if ($menuPath[0] == "INPUT") { if ($menuPath[1] == "InputChannel") { string $channelType = "Vec3"; string $channels[] = MagmaFLUX_getChannelTypes(); int $index = stringArrayFindWrapper( $menuPath[2], 0, $channels); if ($index > -1) $channelType = `MagmaFLUX_getChannelTypesDataType $index`; AddNewMagmaInputChannelToFlow $menuPath[2] $channelType $prtNode $x $y 1 on on -1 -1; } else if ($menuPath[1] == "InputValue") { if ($menuPath[2] == "Integer") AddNewMagmaInputValueIntToFlow 1 $prtNode $x $y on on -1 -1; if ($menuPath[2] == "Float") AddNewMagmaInputValueFloatToFlow 1.0 $prtNode $x $y on on -1 -1; if ($menuPath[2] == "Vector") AddNewMagmaInputValueVectorToFlow 0 0 0 $prtNode $x $y on on -1 -1; } else { if ($menuPath[1] == "InputGeometry") AddNewMagmaInputGeometryToFlow $prtNode $x $y on on; if ($menuPath[1] == "InputParticles") AddNewMagmaInputParticlesToFlow $prtNode $x $y on on; if ($menuPath[1] == "InputObject") AddNewMagmaInputObjectToFlow $prtNode $x $y on on; } } else if ($menuPath[0] == "OUTPUT") { string $channelType = "Vec3"; string $channels[] = MagmaFLUX_getChannelTypes(); int $index = stringArrayFindWrapper( $menuPath[1], 0, $channels); if ($index > -1) $channelType = `MagmaFLUX_getChannelTypesDataType $index`; AddNewMagmaOutputChannelToFlow $menuPath[1] $channelType $prtNode $x $y; // on on -1 -1; } else if (`size $menuPath` == 2) AddNewMagmaOperatorToFlow $menuPath[1] $prtNode $x $y on on; MagmaNodesReorderGrid $prtNode; } global proc MagmaEditor_AllNodesFromEmptySourceMenu ( int $x, int $y, string $menuPath[], string $prtNode ) { checkBox -e -v true ($prtNode+"_chk_enableUpdatesAndReoderCalls"); int $sourceID = `intField -q -v ($prtNode+"_int_NodeID")`; int $socketIndex = `intField -q -v ($prtNode+"_int_SocketID")`; magma_flux_window_set -n {} -prt $prtNode; magma_flux_window_set -e {} -prt $prtNode; if ($menuPath[0] == "OUTPUT") { string $channelType = "Vec3"; string $channels[] = MagmaFLUX_getChannelTypes(); int $index = stringArrayFindWrapper( $menuPath[1], 0, $channels); if ($index > -1) $channelType = `MagmaFLUX_getChannelTypesDataType $index`; AddNewMagmaOutputChannelToFlow $menuPath[1] $channelType $prtNode $x ($y-30); // on on -1 -1; int $selnodes[] = `magma_flux_window_query -n true -prt $prtNode`; create_magma_connection -si $sourceID -ss $socketIndex -di $selnodes[0] -ds 0 -prt $prtNode; MagmaEditor_CreateUndoRecord $prtNode ("Create and Connect Output ["+$menuPath[1] +"]"); } else if (`size $menuPath` == 2) // all operators //MagmaInsertConversionNode $prtNode $x $y $sourceID $menuPath[1] $socketIndex 0 0; { AddNewMagmaOperatorToFlow $menuPath[1] $prtNode $x ($y-30) on off; int $selnodes[] = `magma_flux_window_query -n true -prt $prtNode`; create_magma_connection -si $sourceID -ss $socketIndex -di $selnodes[0] -ds 0 -prt $prtNode; MagmaEditor_CreateUndoRecord $prtNode ("Create and Connect ["+$menuPath[1] +"]"); } MagmaNodesReorderGrid $prtNode; } global proc MagmaEditor_GeometryNodesMenu ( int $x, int $y, string $menuPath[], string $prtNode ) { checkBox -e -v true ($prtNode+"_chk_enableUpdatesAndReoderCalls"); int $sourceID = `intField -q -v ($prtNode+"_int_NodeID")`; int $socketIndex = `intField -q -v ($prtNode+"_int_SocketID")`; AddNewMagmaOperatorToFlow $menuPath[0] $prtNode $x ($y-30) on off; int $selnodes[] = `magma_flux_window_query -n true -prt $prtNode`; create_magma_connection -si $sourceID -ss $socketIndex -di $selnodes[0] -ds 0 -prt $prtNode; MagmaEditor_CreateUndoRecord $prtNode ("Create and Connect "+$menuPath[0]); MagmaNodesReorderGrid $prtNode; } global proc MagmaEditor_ObjectNodesMenu ( int $x, int $y, string $menuPath[], string $prtNode ) { checkBox -e -v true ($prtNode+"_chk_enableUpdatesAndReoderCalls"); int $sourceID = `intField -q -v ($prtNode+"_int_NodeID")`; int $socketIndex = `intField -q -v ($prtNode+"_int_SocketID")`; AddNewMagmaOperatorToFlow $menuPath[0] $prtNode $x ($y-30) on off; int $selnodes[] = `magma_flux_window_query -n true -prt $prtNode`; create_magma_connection -si $sourceID -ss $socketIndex -di $selnodes[0] -ds 0 -prt $prtNode; MagmaEditor_CreateUndoRecord $prtNode ("Create and Connect "+$menuPath[0]); MagmaNodesReorderGrid $prtNode; } global proc MagmaEditor_RayDirectionMenu ( int $x, int $y, string $menuPath[], string $prtNode ) { checkBox -e -v true ($prtNode+"_chk_enableUpdatesAndReoderCalls"); int $sourceID = `intField -q -v ($prtNode+"_int_NodeID")`; int $socketIndex = `intField -q -v ($prtNode+"_int_SocketID")`; if ($menuPath[0] == "All Nodes Menu...") { MagmaEditor_DefineRightClickMenu $prtNode "Target" "MagmaEditor_AllNodesFromEmptyTarget"; magma_flux_window_menu -prt $prtNode -s {$x,$y}; } else { if ($menuPath[0] == "Up Vector (0,1,0)") AddNewMagmaInputValueVectorToFlow 0.0 1.0 0.0 $prtNode 0 0 on on $sourceID $socketIndex; if ($menuPath[0] == "Down Vector (0,-1,0)") AddNewMagmaInputValueVectorToFlow 0.0 -1.0 0.0 $prtNode 0 0 on on $sourceID $socketIndex; } } global proc MagmaEditor_InputParticlesMenu (int $x, int $y, string $menuPath[], string $prtNode ) { checkBox -e -v false ($prtNode+"_chk_enableUpdatesAndReoderCalls"); int $nodeID = `intField -q -v ($prtNode+"_int_NodeID")`; if ($menuPath[0] == "New InputParticles Node") { AddNewMagmaInputParticlesToFlow $prtNode 0 0 on off; int $selnodes[] = `magma_flux_window_query -n true -prt $prtNode`; create_magma_connection -si $selnodes[0] -ss 0 -di $nodeID -ds 0 -prt $prtNode; MagmaEditor_CreateUndoRecord $prtNode ($menuPath[0]); } else { string $nodeToConnectTo[]; tokenize $menuPath[0] "_" $nodeToConnectTo; int $selnodes[] = `magma_flux_window_query -n true -prt $prtNode`; create_magma_connection -si ((int)$nodeToConnectTo[1]) -ss 0 -di $nodeID -ds 0 -prt $prtNode; MagmaEditor_CreateUndoRecord $prtNode ($menuPath[0]); } checkBox -e -v true ($prtNode+"_chk_enableUpdatesAndReoderCalls"); } global proc MagmaEditor_InputGeometryMenu (int $x, int $y, string $menuPath[], string $prtNode ) { checkBox -e -v false ($prtNode+"_chk_enableUpdatesAndReoderCalls"); int $nodeID = `intField -q -v ($prtNode+"_int_NodeID")`; if ($menuPath[0] == "New InputGeometry Node") { AddNewMagmaInputGeometryToFlow $prtNode 0 0 on off; int $selnodes[] = `magma_flux_window_query -n true -prt $prtNode`; create_magma_connection -si $selnodes[0] -ss 0 -di $nodeID -ds 0 -prt $prtNode; MagmaEditor_CreateUndoRecord $prtNode ($menuPath[0]); } else { string $nodeToConnectTo[]; tokenize $menuPath[0] "_" $nodeToConnectTo; int $selnodes[] = `magma_flux_window_query -n true -prt $prtNode`; create_magma_connection -si ((int)$nodeToConnectTo[1]) -ss 0 -di $nodeID -ds 0 -prt $prtNode; MagmaEditor_CreateUndoRecord $prtNode ($menuPath[0]); } checkBox -e -v true ($prtNode+"_chk_enableUpdatesAndReoderCalls"); } global proc MagmaEditor_InputObjectMenu (int $x, int $y, string $menuPath[], string $prtNode ) { checkBox -e -v false ($prtNode+"_chk_enableUpdatesAndReoderCalls"); int $nodeID = `intField -q -v ($prtNode+"_int_NodeID")`; if ($menuPath[0] == "New InputObject Node") { AddNewMagmaInputObjectToFlow $prtNode 0 0 on off; int $selnodes[] = `magma_flux_window_query -n true -prt $prtNode`; create_magma_connection -si $selnodes[0] -ss 0 -di $nodeID -ds 0 -prt $prtNode; MagmaEditor_CreateUndoRecord $prtNode ($menuPath[0]); } else { string $nodeToConnectTo[]; tokenize $menuPath[0] "_" $nodeToConnectTo; int $selnodes[] = `magma_flux_window_query -n true -prt $prtNode`; create_magma_connection -si ((int)$nodeToConnectTo[1]) -ss 0 -di $nodeID -ds 0 -prt $prtNode; MagmaEditor_CreateUndoRecord $prtNode ($menuPath[0]); } } global proc MagmaEditor_IsValidSwitchMenu ( int $x, int $y, string $menuPath[], string $prtNode ) { int $sourceID = `intField -q -v ($prtNode+"_int_NodeID")`; int $socketID = `intField -q -v ($prtNode+"_int_SocketID")`; if ($menuPath[0] == "All Nodes Menu...") { MagmaEditor_DefineRightClickMenu $prtNode "Source" "MagmaEditor_AllNodesFromEmptySourceMenu"; magma_flux_window_menu -prt $prtNode -s {$x,$y}; } else { checkBox -e -v false ($prtNode+"_chk_enableUpdatesAndReoderCalls"); magma_flux_window_set -n {} -prt $prtNode; AddNewMagmaOperatorToFlow "Switch" $prtNode $x $y on off; int $selnodes[] = `magma_flux_window_query -n true -prt $prtNode`; create_magma_connection -si $sourceID -ss $socketID -di $selnodes[0] -ds 2 -prt $prtNode; checkBox -e -v true ($prtNode+"_chk_enableUpdatesAndReoderCalls"); MagmaEditor_CreateUndoRecord $prtNode ($menuPath[0]); } } global proc MagmaEditor_ParticleQueryMenu ( int $x, int $y, string $menuPath[], string $prtNode ) { int $sourceID = `intField -q -v ($prtNode+"_int_NodeID")`; if ($menuPath[0] == "All Nodes Menu...") { MagmaEditor_DefineRightClickMenu $prtNode "Source" "MagmaEditor_AllNodesFromEmptySourceMenu"; magma_flux_window_menu -prt $prtNode -s {$x,$y}; } else { checkBox -e -v false ($prtNode+"_chk_enableUpdatesAndReoderCalls"); magma_flux_window_set -n $sourceID -prt $prtNode; MagmaInsertConversionNode $prtNode $x $y $sourceID "ParticleQuery" 2 1 0 1 0; int $selnodes[] = `magma_flux_window_query -n true -prt $prtNode`; int $connection[] = `get_magma_connections -prt $prtNode -id $sourceID`; if ($connection[0] > -1) { create_magma_connection -si $connection[0] -ss 0 -di $selnodes[0] -ds 0 -prt $prtNode; } checkBox -e -v true ($prtNode+"_chk_enableUpdatesAndReoderCalls"); MagmaEditor_CreateUndoRecord $prtNode ($menuPath[0]); } } global proc MagmaEditor_WorldPositionMenu ( int $x, int $y, string $menuPath[], string $prtNode ) { checkBox -e -v true ($prtNode+"_chk_enableUpdatesAndReoderCalls"); int $nodeID = `intField -q -v ($prtNode+"_int_NodeID")`; int $socketIndex = `intField -q -v ($prtNode+"_int_SocketID")`; if ($menuPath[0] == "New InputChannel Position->ToWorld") { AddNewMagmaInputChannelToFlow "Position" "Vec3" $prtNode 0 0 2 off off $nodeID 1; int $selnodes[] = `magma_flux_window_query -n true -prt $prtNode`; MagmaInsertConversionNode $prtNode 0 0 $selnodes[(`size $selnodes`)-1] "ToWorld" 0 0 0 0 0; //AddNewMagmaOperatorToFlow "ToWorld" $prtNode 0 0 off off; MagmaEditor_CreateUndoRecord $prtNode ("Create World Space Position Nodes"); } else if ($menuPath[0] == "All Nodes Menu...") { MagmaEditor_DefineRightClickMenu $prtNode "Target" "MagmaEditor_AllNodesFromEmptyTarget"; magma_flux_window_menu -prt $prtNode -s {$x,$y}; } else { string $nodeToConnectTo[]; tokenize $menuPath[0] "_" $nodeToConnectTo; int $selnodes[] = `magma_flux_window_query -n true -prt $prtNode`; create_magma_connection -si ((int)$nodeToConnectTo[1]) -ss 0 -di $nodeID -ds $socketIndex -prt $prtNode; } } global proc MagmaEditor_AllNodesFromEmptyTarget ( int $x, int $y, string $menuPath[], string $prtNode ) { checkBox -e -v true ($prtNode+"_chk_enableUpdatesAndReoderCalls"); int $tagetID = `intField -q -v ($prtNode+"_int_NodeID")`; int $targetIndex = `intField -q -v ($prtNode+"_int_SocketID")`; magma_flux_window_set -n {} -prt $prtNode; magma_flux_window_set -e {} -prt $prtNode; if ($menuPath[0] == "INPUT") { if ($menuPath[1] == "InputChannel") { string $channelType = "Vec3"; string $channels[] = MagmaFLUX_getChannelTypes(); int $index = stringArrayFindWrapper( $menuPath[2], 0, $channels); if ($index > -1) $channelType = `MagmaFLUX_getChannelTypesDataType $index`; AddNewMagmaInputChannelToFlow $menuPath[2] $channelType $prtNode ($x-160) ($y-5) 1 on off -1 -1; int $selnodes[] = `magma_flux_window_query -n true -prt $prtNode`; create_magma_connection -si $selnodes[0] -ss 0 -di $tagetID -ds $targetIndex -prt $prtNode; MagmaEditor_CreateUndoRecord $prtNode ("Create and Connect InputChannel ["+$menuPath[2] +"]"); } else if ($menuPath[1] == "InputValue") { if ($menuPath[2] == "Integer") AddNewMagmaInputValueIntToFlow 1 $prtNode $x $y on off -1 -1; if ($menuPath[2] == "Float") AddNewMagmaInputValueFloatToFlow 1.0 $prtNode $x $y on off -1 -1; if ($menuPath[2] == "Vector") AddNewMagmaInputValueVectorToFlow 0 0 0 $prtNode $x $y on off -1 -1; int $selnodes[] = `magma_flux_window_query -n true -prt $prtNode`; create_magma_connection -si $selnodes[0] -ss 0 -di $tagetID -ds $targetIndex -prt $prtNode; MagmaEditor_CreateUndoRecord $prtNode ("Create and Connect "+$menuPath[2] +" " +$menuPath[1]); } else { if ($menuPath[1] == "InputGeometry") { AddNewMagmaInputGeometryToFlow $prtNode $x $y on off; int $selnodes[] = `magma_flux_window_query -n true -prt $prtNode`; create_magma_connection -si $selnodes[0] -ss 0 -di $tagetID -ds $targetIndex -prt $prtNode; MagmaEditor_CreateUndoRecord $prtNode ("Create and Connect "+$menuPath[1]); } if ($menuPath[1] == "InputParticles") { AddNewMagmaInputParticlesToFlow $prtNode $x $y on on; int $selnodes[] = `magma_flux_window_query -n true -prt $prtNode`; create_magma_connection -si $selnodes[0] -ss 0 -di $tagetID -ds $targetIndex -prt $prtNode; MagmaEditor_CreateUndoRecord $prtNode ("Create and Connect "+$menuPath[1]); } if ($menuPath[1] == "InputObject") { AddNewMagmaInputParticlesToFlow $prtNode $x $y on on; int $selnodes[] = `magma_flux_window_query -n true -prt $prtNode`; create_magma_connection -si $selnodes[0] -ss 0 -di $tagetID -ds $targetIndex -prt $prtNode; MagmaEditor_CreateUndoRecord $prtNode ("Create and Connect "+$menuPath[1]); } } } else if (`size $menuPath` == 2) { AddNewMagmaOperatorToFlow $menuPath[1] $prtNode ($x-160) ($y-5) on off; int $selnodes[] = `magma_flux_window_query -n true -prt $prtNode`; create_magma_connection -si $selnodes[0] -ss 0 -di $tagetID -ds $targetIndex -prt $prtNode; MagmaEditor_CreateUndoRecord $prtNode ("Create and Connect "+$menuPath[1]); } } /* \\fs-01\public\users\conrad.wiebe\for_bobo\KrakatoaMY_with_magma_v2.zip -nodes are enabled by default -added the ability to set the color of a node: for example, this mel (id is the node id that gets returned when a node is created). in this case, it is the first node created): set_magma_node_instance_info -id 0 -r 0.5 -g 0.5 -b 0.5; -The "None" option has been removed, and it now defaults to float (you can change this if you'd like) -added an enum dropdown for the channel names (to modify it, change the line in KrakatoaMagma.mel) -same thing (dropdown) for data types -magma now reports an error message of the actual node that produced the error (rather than stating just "Magma Error") however, it just gets displayed as a maya error. i will have to make a MEL callback for it, so you can perform the "red" coloring on the node. ...or sorry, for that "color the node" example, the rgb values are actually between 0-255 currently i'm working on MEL callbacks when attributes change... which will allow you to do auto-update, and anything else you could desire. so, for the coloring of specific types, one way to do it is: on create node in MEL: i believe you can get the category of a node type via MEL. then based on that, you can call the "set color" code. the MEL function to get node info is: retrieve_magma_node_info and its arguments are: -t nodeType -a (on-print all infos; off -p property (on, off) -is inputsocket (on, off) -os outputSocket (on, off) -i index (either the index in inputSocket, or the index in outputSocket, or the index in property ...we may have to change that to return a value rather than print and just for reference, these are all the MEL functions we currently expose: create_magma_connection delete_magma_connection debug_magma create_magma_node delete_magma_node retrieve_magma_node_instance_info set_magma_node_instance_info retrieve_magma_node_ids retrieve_magma_node_info add_magma_flux_window magma_flux_window_query \\fs-01\public\users\conrad.wiebe\for_bobo\KrakatoaMY_with_magma_v3.zip Release notes: -disabled nodes appear transparent -added a "-prt NodeName" option to set_magma_node_instance_info MEL command. -highlights the nodes that are in error, and the border colors gets highlighted. -options for retireving current node color. -added the ability to query nodes and connections in MEL script -get_magma_connection -id MagmaNodeId +added the ability to set transparency: (set_magma_node_instance_info -prt -id -a ;) is from 0 to 255. -fixed a bug that was causing loading a previously saved scene to mess up the magma graph. -added color selector alongside Vec3 attributes. You can change this in script if you don't like how it works. -reduced the curvature of the graph lines -MEL events for connection created, selected, and deleted. See KrakatoaMagma.MEL: MagmaFLUX_nodeSelectionChanged, MagmaFLUX_connectionSelectionChanged, MagmaFLUX_connectionCreated -To traverse the graph, you can use the "get nodes" like last time, and you can find their input connections using: get_magma_connections -prt -id ; it will return an array for example: [4,6] << if two connections, one is connected to node id 4, and the other to 6. or if something is unconnected, it's -1 Get x and y positions of a node: int $point[] = `retrieve_magma_node_instance_info -id -prt -xy true`; point[0] will contain the x position and point[1] will contain the y position Set x and y positions of a node: set_magma_node_instance_info -id -prt -x -y ; // string $nodes[] = `get_magma_description -prt -n true`; // get all the nodes and their color, position, and type int $edges[] = `get_magma_description -prt -e true`; // get all the edges string $props[] = `get_magma_description -prt -v true`; // get all the magma properties apply_magma_description -prt -n $nodes -e $edges -v $props [-x ] [-y ] [-rn true]; // add the given nodes/connections/properties to the current node $nodes is an array that follows the pattern: [, , , , , , , , , , , , , , , , ... ]. The size will be a multiple of 8 $edges is an array that follows the pattern: [, , , , , , , , ... ]. The size will be a multiple of 4 $props is an array the follows the pattern: [, , , , , , ... ]. The size will be a multiple of 3. is either an int/bool, float, string, vector3 (of the form ",,"), string list (of the form ",,..."). apply_magma_description will either overwrite (if "-rn true" is given), or append the description to the magma setup of the given node. -x and -y are optional and will translate all the nodes to be added before placing them. magma_flux_window_set -i -prt -bgr -bgg -bgb ; // set background color (0-255) magma_flux_window_set -i -prt -gr -gg -gb ; // set grid color (0-255) magma_flux_window_set -i -prt -g ; // show/hide grid (true to show) magma_flux_window_set -i -prt -gs ; // grid size magma_flux_window_set -i -prt -s ; // snap on/off to grid (true to snap) magma_flux_window_set -i -prt -cx -cy ; // center view on position magma_flux_window_set -i -prt -z ; // scale the current view by this amount set_magma_node_instance_info -prt -id -r -g -b -a ; // Set the body node color (unchanged from before) set_magma_node_instance_info -prt -id -r -g -b -a -h true; // Set the title bar color set_magma_node_instance_info -prt -id -r -g -b -a -o true; // Set the outline color set_magma_node_instance_info -prt -id -r -g -b -a -t true; // Set the title text color set_magma_node_instance_info -prt -id -r -g -b -a -si -st ; // Set the socket fill set_magma_node_instance_info -prt -id -r -g -b -a -si -st -o true; // Set the socket outline color set_magma_node_instance_info -prt -id -r -g -b -a -si -st -t true; // Set the socket label text color set_magma_connection -prt -si -ss -di -ds -r -g -b -a ; A method to get all connections of a given output socket would speed things up" working. The command is: get_magma_connections -prt -i -ss ; This returns an int array of the form [, , , , ...] retrieve_magma_node_instance_info -id -prt -os true; -Same thing as "retrieve_magma_node_info -t $type -os true" except it includes the variable output sockets for the instance. Return value is the same format as well. retrieve_magma_node_instance_info -id -prt -is true; -Exactly the same as "retrieve_magma_node_info -t $type -is true". This is a placeholder until we implement mux. The rcmenu commands: magma_flux_window_menu -prt -m {, , , ..., } -a ; //Creates a pop up menu item or overwrites a pop up menu item command. It will create the menu item and submenu , and so on. The function is the mel script function that is run when the option is selected. and the s are strings magma_flux_window_menu -prt -c true; //Deletes all the menu items magma_flux_window_menu -prt -s {,}; //Pops up the menu at the given position in the flux window. This will return whatever the result the clicked option's function returns. This is to help implement popping up the action for "connectToEmpty" just in case should have the following prototype: global proc string ( int $x, int $y, string $path[], string $prtnode) Pan and Zoom: magma_flux_window_set -prt "PRTMagma1" -cx -cy ; // Center on (x,y) magma_flux_window_set -prt "PRTMagma1" -z ; // Set zoom factor to z Selection Mode: magma_flux_window_set -prt "PRTMagma1" -sm 0; // Select all excluding crossing magma_flux_window_set -prt "PRTMagma1" -sm 1; // Select all including crossing */