compositeTextureEditor.tscript 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. function CompositeTextureEditor::buildComposite(%this, %sourceTex0, %sourceTex1, %sourceTex2, %sourceTex3, %sourceChan0, %sourceChan1, %sourceChan2, %sourceChan3, %callback)
  2. {
  3. Canvas.pushDialog(%this);
  4. CompTextureEd_RedChan.setChannelData(%sourceTex0, %sourceChan0);
  5. CompTextureEd_GreenChan.setChannelData(%sourceTex1, %sourceChan1);
  6. CompTextureEd_BlueChan.setChannelData(%sourceTex2, %sourceChan2);
  7. CompTextureEd_AlphaChan.setChannelData(%sourceTex3, %sourceChan3);
  8. %this.callbackFunc = %callback;
  9. }
  10. function CompositeTextureSlotContainer::onWake(%this)
  11. {
  12. %this-->InputMode.clear();
  13. %this-->InputMode.add("Raw Value");
  14. %this-->InputMode.add("Texture");
  15. %this-->InputMode.setSelected(1);
  16. %this-->InputMode.active = false;
  17. %this-->sourceChannel.clear();
  18. %this-->sourceChannel.add("Red");
  19. %this-->sourceChannel.add("Green");
  20. %this-->sourceChannel.add("Blue");
  21. %this-->sourceChannel.add("Alpha");
  22. }
  23. function CompositeTextureSlotContainer::setChannelData(%this, %sourceValue, %sourceChannel)
  24. {
  25. //for now, hard-force Texture mode
  26. %this-->InputMode.setSelected(1);
  27. if(AssetDatabase.isDeclaredAsset(%sourceValue))
  28. {
  29. %this-->InputMode.setSelected(1);
  30. %this-->bitmap.setBitmap(%sourceValue);
  31. if(%sourceChannel $= "")
  32. %sourceChannel = "Red";
  33. %this-->sourceChannel.setText(%sourceChannel);
  34. }
  35. /*else
  36. {
  37. %this-->InputMode.setSelected(0);
  38. %value = 0;
  39. if(%sourceValue !$= "" && (isFloat(%sourceValue) || isFloat(%sourceValue)))
  40. {
  41. %value = %sourceValue;
  42. }
  43. %this-->RawValueTxtEdit.setText(%value);
  44. %this-->RawValueSlider.setValue(%value);
  45. }*/
  46. }
  47. function CompositeTextureSlotContainer::getChannelData(%this)
  48. {
  49. return "";
  50. }
  51. function CompositeTextureChannelMode::onSelect(%this, %id, %text)
  52. {
  53. %isRawValueMode = %text $= "Raw Value";
  54. %this.getParent()-->RawValueContainer.setVisible(%isRawValueMode);
  55. %this.getParent()-->TextureContainer.setVisible(!%isRawValueMode);
  56. }
  57. function CompositeTextureEditor::setSourceTex(%this, %assetId)
  58. {
  59. if($CompTexSourceChannel $= "")
  60. $CompTexSourceChannel = 0;
  61. %channelContainer = CompositeTextureEditorWindow.getObject($CompTexSourceChannel);
  62. %channelContainer-->bitmap.setBitmap(%assetId);
  63. }
  64. function CompositeTextureEditor::saveComposite(%this)
  65. {
  66. %cubemap = CubemapEditor.currentCubemap;
  67. %aoMap = CompTextureEd_RedChan-->Bitmap.getBitmap();
  68. %roughMap = CompTextureEd_GreenChan-->Bitmap.getBitmap();
  69. %metalMap = CompTextureEd_BlueChan-->Bitmap.getBitmap();
  70. if(%aoMap $= "ToolsModule:unknownImage_image")
  71. %aoMap = "";
  72. if(%roughMap $= "ToolsModule:unknownImage_image")
  73. %roughMap = "";
  74. if(%metalMap $= "ToolsModule:unknownImage_image")
  75. %metalMap = "";
  76. if(%aoMap $= "" && %roughMap $= "" && %metalMap $= "")
  77. {
  78. toolsMessageBoxOK("Error", "Saving a composite map requires at least one channel slot to have source data!");
  79. return;
  80. }
  81. AssetBrowser.setupCreateNewAsset("ImageAsset", AssetBrowser.selectedModule, "CompositeEditorDoSaveComposite");
  82. }
  83. function CompositeEditorDoSaveComposite(%assetId)
  84. {
  85. %assetDef = AssetDatabase.acquireAsset(%assetId);
  86. if(!isObject(%assetDef))
  87. {
  88. toolsMessageBoxOK("Error", "We somehow failed to successfully create a new ImageAsset!");
  89. return;
  90. }
  91. %targetFilePath = %assetDef.getImagePath();
  92. %aoMapAsset = CompTextureEd_RedChan-->Bitmap.getBitmap();
  93. %roughMapAsset = CompTextureEd_GreenChan-->Bitmap.getBitmap();
  94. %metalMapAsset = CompTextureEd_BlueChan-->Bitmap.getBitmap();
  95. if(%aoMapAsset $= "ToolsModule:unknownImage_image")
  96. {
  97. %aoMap = "";
  98. }
  99. else
  100. {
  101. %aoAssetDef = AssetDatabase.acquireAsset(%aoMapAsset);
  102. %aoMap = %aoAssetDef.getImagePath();
  103. }
  104. if(%roughMapAsset $= "ToolsModule:unknownImage_image")
  105. {
  106. %roughMap = "";
  107. }
  108. else
  109. {
  110. %roughAssetDef = AssetDatabase.acquireAsset(%roughMapAsset);
  111. %roughMap = %roughAssetDef.getImagePath();
  112. }
  113. if(%metalMapAsset $= "ToolsModule:unknownImage_image")
  114. {
  115. %metalMap = "";
  116. }
  117. else
  118. {
  119. %metalAssetDef = AssetDatabase.acquireAsset(%metalMapAsset);
  120. %metalMap = %roughAssetDef.getImagePath();
  121. }
  122. if(%aoMap $= "" && %roughMap $= "" && %metalMap $= "")
  123. {
  124. toolsMessageBoxOK("Error", "Attempted to create a composite texture but all three source textures are blank or invalid!");
  125. return;
  126. }
  127. %redChanSource = CompTextureEd_RedChan-->sourceChannel;
  128. %greenChanSource = CompTextureEd_GreenChan-->sourceChannel;
  129. %blueChanSource = CompTextureEd_BlueChan-->sourceChannel;
  130. %aoChan = %redChanSource.findText(%redChanSource.getText());
  131. %aoChan = %aoChan == -1 ? 0 : %aoChan;
  132. %roughChan = %greenChanSource.findText(%greenChanSource.getText());
  133. %roughChan = %roughChan == -1 ? 1 : %roughChan;
  134. %metalChan = %blueChanSource.findText(%blueChanSource.getText());
  135. %metalChan = %metalChan == -1 ? 2 : %metalChan;
  136. %channelKey = %aoChan SPC %roughChan SPC %metalChan SPC 3;
  137. error("Storing: \"" @ %aoMap @"\" \""@ %roughMap @"\" \""@ %metalMap @"\" \""@ %channelKey @"\" \""@ %targetFilePath @"\"");
  138. saveCompositeTexture(%aoMap, %roughMap, %metalMap, "", %channelKey, %targetFilePath);
  139. %assetDef.refreshAsset();
  140. %command = CompositeTextureEditor.callbackFunc @ "(\"" @ %assetId @ "\");";
  141. if(CompositeTextureEditor.callbackFunc !$= "")
  142. {
  143. eval(%command);
  144. CompositeTextureEditor.callbackFunc = "";
  145. }
  146. Canvas.popDialog(CompositeTextureEditor);
  147. }
  148. function CompositeTextureRawValueEdit::onReturn(%this)
  149. {
  150. %this.getParent()-->RawValueSlider.setValue(%this.getText());
  151. }
  152. function CompositeTextureRawValueSlider::onDragComplete(%this)
  153. {
  154. %value = %this.getValue();
  155. %this.getParent()-->RawValueTxtEdit.setText(%value);
  156. }