ModelInspector.ts 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. //
  2. // Copyright (c) 2014-2016 THUNDERBEAST GAMES LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. import InspectorWidget = require("./InspectorWidget");
  23. import ArrayEditWidget = require("./ArrayEditWidget");
  24. import InspectorUtils = require("./InspectorUtils");
  25. class ModelInspector extends InspectorWidget {
  26. constructor() {
  27. super();
  28. this.subscribeToEvent(this, Atomic.UIWidgetEvent((data) => this.handleWidgetEvent(data)));
  29. }
  30. handleWidgetEvent(ev: Atomic.UIWidgetEvent):boolean {
  31. return false;
  32. }
  33. onApply() {
  34. this.importer.scale = Number(this.scaleEdit.text);
  35. this.importer.generateLightmapUV = this.genLightmapUVBox.value ? true : false;
  36. this.importer.importAnimations = this.importAnimationBox.value ? true : false;
  37. this.importer.setImportMaterials(this.importMaterials.value ? true : false);
  38. for (var i = 0; i < this.importer.animationCount; i++) {
  39. var info = this.importer.getAnimationInfo(i);
  40. var nameEdit = this.nameEdits[i];
  41. var startEdit = this.startEdits[i];
  42. var endEdit = this.endEdits[i];
  43. info.name = nameEdit.text;
  44. // guard against NAN
  45. var _startTime = Number(startEdit.text);
  46. var _endTime = Number(endEdit.text);
  47. if (isNaN(_startTime)) _startTime = 0;
  48. if (isNaN(_endTime)) _endTime = 0;
  49. info.startTime = _startTime;
  50. info.endTime = _endTime;
  51. }
  52. this.asset.import();
  53. this.asset.save();
  54. }
  55. inspect(asset: ToolCore.Asset) {
  56. this.asset = asset;
  57. this.importer = <ToolCore.ModelImporter> asset.importer;
  58. // node attr layout
  59. var rootLayout = this.rootLayout;
  60. // Model Section
  61. var modelLayout = this.createSection(rootLayout, "Model", 1);
  62. var editField = InspectorUtils.createAttrEditField("Name", modelLayout);
  63. var lp = new Atomic.UILayoutParams();
  64. editField.readOnly = true;
  65. editField.text = asset.name;
  66. //This should preferably be onClick
  67. editField.subscribeToEvent(editField, Atomic.UIWidgetFocusChangedEvent((ev: Atomic.UIWidgetFocusChangedEvent) => {
  68. if (ev.widget == editField && editField.focus) {
  69. this.sendEvent(Editor.InspectorProjectReferenceEventData({ "path": asset.getRelativePath() }));
  70. }
  71. }));
  72. this.scaleEdit = InspectorUtils.createAttrEditField("Scale", modelLayout);
  73. this.scaleEdit.text = this.importer.scale.toString();
  74. this.importMaterials = this.createAttrCheckBox("Import Materials", modelLayout);
  75. this.importMaterials.value = this.importer.getImportMaterials() ? 1 : 0;
  76. this.genLightmapUVBox = this.createAttrCheckBox("Generate Lightmap UV", modelLayout);
  77. this.genLightmapUVBox.value = this.importer.generateLightmapUV ? 1 : 0;
  78. // Animations Section
  79. var animationLayout = this.createSection(rootLayout, "Animation", 1);
  80. this.importAnimationBox = this.createAttrCheckBox("Import Animations", animationLayout);
  81. this.importAnimationBox.value = this.importer.importAnimations ? 1 : 0;
  82. this.importAnimationArray = new ArrayEditWidget("Animation Count");
  83. animationLayout.addChild(this.importAnimationArray);
  84. this.importAnimationArray.onCountChanged = (count) => this.onAnimationCountChanged(count);
  85. var nlp = new Atomic.UILayoutParams();
  86. nlp.width = 310;
  87. var animLayout = this.animationInfoLayout = new Atomic.UILayout();
  88. animLayout.spacing = 4;
  89. animLayout.layoutDistribution = Atomic.UI_LAYOUT_DISTRIBUTION.UI_LAYOUT_DISTRIBUTION_GRAVITY;
  90. animLayout.layoutPosition = Atomic.UI_LAYOUT_POSITION.UI_LAYOUT_POSITION_LEFT_TOP;
  91. animLayout.layoutParams = nlp;
  92. animLayout.axis = Atomic.UI_AXIS.UI_AXIS_Y;
  93. animLayout.gravity = Atomic.UI_GRAVITY.UI_GRAVITY_ALL;
  94. animationLayout.addChild(animLayout);
  95. this.createAnimationEntries();
  96. // Animation preview button
  97. rootLayout.addChild(this.createPreviewAnimationButton(this.asset));
  98. // apply button
  99. rootLayout.addChild(this.createApplyButton());
  100. }
  101. createAnimationEntries() {
  102. var layout = this.animationInfoLayout;
  103. layout.deleteAllChildren();
  104. var count = this.importer.animationCount;
  105. this.importAnimationArray.countEdit.text = count.toString();
  106. this.nameEdits = [];
  107. this.startEdits = [];
  108. this.endEdits = [];
  109. for (var i = 0; i < count; i++) {
  110. var animInfo = this.importer.getAnimationInfo(i);
  111. var name = InspectorUtils.createAttrName("Animation " + i.toString() + ":");
  112. layout.addChild(name);
  113. var nameEdit = InspectorUtils.createAttrEditField("Name", layout);
  114. nameEdit.text = animInfo.name;
  115. var startEdit = InspectorUtils.createAttrEditField("Start", layout);
  116. startEdit.text = animInfo.startTime.toString();
  117. var endEdit = InspectorUtils.createAttrEditField("End", layout);
  118. endEdit.text = animInfo.endTime.toString();
  119. this.nameEdits.push(nameEdit);
  120. this.startEdits.push(startEdit);
  121. this.endEdits.push(endEdit);
  122. InspectorUtils.createSeparator(layout);
  123. }
  124. }
  125. onAnimationCountChanged(count: number) {
  126. if (this.importer.animationCount == count) {
  127. return;
  128. }
  129. this.importer.animationCount = count;
  130. this.createAnimationEntries();
  131. }
  132. // model
  133. scaleEdit: Atomic.UIEditField;
  134. genLightmapUVBox: Atomic.UICheckBox;
  135. // animation
  136. importAnimationBox: Atomic.UICheckBox;
  137. importMaterials: Atomic.UICheckBox;
  138. importAnimationArray: ArrayEditWidget;
  139. animationInfoLayout: Atomic.UILayout;
  140. nameEdits: Atomic.UIEditField[];
  141. startEdits: Atomic.UIEditField[];
  142. endEdits: Atomic.UIEditField[];
  143. asset: ToolCore.Asset;
  144. importer: ToolCore.ModelImporter;
  145. }
  146. export = ModelInspector;