| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499 |
- //
- // Copyright (c) 2014-2016 THUNDERBEAST GAMES LLC
- //
- // Permission is hereby granted, free of charge, to any person obtaining a copy
- // of this software and associated documentation files (the "Software"), to deal
- // in the Software without restriction, including without limitation the rights
- // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- // copies of the Software, and to permit persons to whom the Software is
- // furnished to do so, subject to the following conditions:
- //
- // The above copyright notice and this permission notice shall be included in
- // all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- // THE SOFTWARE.
- //
- import EditorUI = require("ui/EditorUI");
- import InspectorUtils = require("./InspectorUtils");
- import AttributeInfoEdit = require("./AttributeInfoEdit");
- import SerializableEditType = require("./SerializableEditType");
- import EditorEvents = require("editor/EditorEvents");
- class LightCascadeAttributeEdit extends AttributeInfoEdit {
- splitFields: Atomic.UIEditField[] = [];
- createEditWidget() {
- var panel = new Atomic.UILayout();
- panel.axis = Atomic.UI_AXIS_Y;
- panel.layoutSize = Atomic.UI_LAYOUT_SIZE_PREFERRED;
- panel.layoutPosition = Atomic.UI_LAYOUT_POSITION_LEFT_TOP;
- var lp = new Atomic.UILayoutParams();
- lp.width = 180;
- panel.layoutParams = lp;
- this.editWidget = panel;
- var _this = this;
- function createHandler(index, field) {
- return function(ev: Atomic.UIWidgetEditCompleteEvent) {
- for (var i in _this.editType.objects) {
- var o = <Atomic.Light>_this.editType.objects[i];
- o.setShadowCascadeParameter(this.index, Number(this.field.text));
- }
- o.scene.sendEvent("SceneEditEnd");
- _this.refresh();
- }.bind({ index: index, field: field });
- }
- var flp = new Atomic.UILayoutParams();
- flp.width = 60;
- for (var i = 0; i < 4; i++) {
- var field = InspectorUtils.createAttrEditField("Split " + i, panel);
- field.layoutParams = flp;
- field.subscribeToEvent(field, "UIWidgetEditComplete", createHandler(i, field));
- this.splitFields.push(field);
- }
- }
- refresh() {
- // Vector 4 internally
- for (var i = 0; i < 4; i++) {
- var uniform = this.editType.getUniformValue(this.attrInfo, i);
- var field = this.splitFields[i];
- if (uniform) {
- var object = this.editType.getFirstObject();
- if (object) {
- var value = object.getAttribute(this.attrInfo.name);
- field.text = parseFloat(value[i].toFixed(5)).toString();
- }
- else {
- field.text = "???";
- }
- }
- else {
- field.text = "--";
- }
- }
- }
- handleWidgetEvent(ev: Atomic.UIWidgetEvent): boolean {
- if (ev.type == Atomic.UI_EVENT_TYPE_CHANGED) {
- return true;
- }
- return false;
- }
- }
- interface MaterialEdit {
- index: number;
- pathReference: string;
- editField: Atomic.UIEditField;
- selectButton: Atomic.UIButton;
- }
- class SubmeshAttributeEdit extends AttributeInfoEdit {
- materialIndexes: number[] = [];
- materialEdits: { [index: number]: MaterialEdit } = {};
- mainLayout: Atomic.UILayout;
- enabledCheckBox: Atomic.UICheckBox;
- nameField: Atomic.UITextField;
- name: string;
- matIndex: number;
- constructor(name: string) {
- super();
- this.name = name;
- this.hideName = true;
- this.subscribeToEvent(EditorEvents.RemoveCurrentAssetAssigned, (ev: EditorEvents.RemoveCurrentAssetAssignedEvent) => {
- this.editType.onAttributeInfoEdited(this.attrInfo, null, this.matIndex);
- this.refresh();
- });
- }
- openResourceSelectionBox(materialIndex: number, resourceTypeName: string, importerName: string) {
- this.matIndex = materialIndex;
- EditorUI.getModelOps().showResourceSelection("Select " + resourceTypeName + " Resource", importerName, resourceTypeName, function (retObject: any) {
- var resource: Atomic.Resource = null;
- if (retObject instanceof ToolCore.Asset) {
- resource = (<ToolCore.Asset>retObject).getResource(resourceTypeName);
- } else if (retObject instanceof Atomic.Resource) {
- resource = <Atomic.Resource>retObject;
- }
- this.sendEvent(EditorEvents.InspectorProjectReference, { "path": resource.name });
- this.editType.onAttributeInfoEdited(this.attrInfo, resource, materialIndex);
- this.refresh();
- }.bind(this));
- }
- createMaterialEdit(materialIndex: number) {
- var o = InspectorUtils.createAttrEditFieldWithSelectButton("Material", this.mainLayout);
- var lp = new Atomic.UILayoutParams();
- lp.width = 140;
- lp.height = 24;
- o.editField.layoutParams = lp;
- o.editField.readOnly = true;
- var selectButton = o.selectButton;
- var materialEdit: MaterialEdit = { index: materialIndex, pathReference: "" , editField: o.editField, selectButton: selectButton };
- this.materialEdits[materialIndex] = materialEdit;
- var resourceTypeName = "Material";
- var importerName = ToolCore.assetDatabase.getResourceImporterName(resourceTypeName);
- selectButton.onClick = () => {
- this.openResourceSelectionBox(materialIndex, resourceTypeName, importerName);
- // this.sendEvent(EditorEvents.InspectorProjectReference, { "path": pathName });
- };
- // handle dropping of component on field
- o.editField.subscribeToEvent(o.editField, "DragEnded", (ev: Atomic.DragEndedEvent) => {
- if (ev.target == o.editField) {
- var dragObject = ev.dragObject;
- var importer;
- if (dragObject.object && dragObject.object.typeName == "Asset") {
- var asset = <ToolCore.Asset>dragObject.object;
- if (asset.importerTypeName == importerName) {
- importer = asset.importer;
- }
- }
- if (importer) {
- var resource = asset.getResource(resourceTypeName);
- this.sendEvent(EditorEvents.InspectorProjectReference, { "path": resource.name });
- this.editType.onAttributeInfoEdited(this.attrInfo, resource, materialIndex);
- this.refresh();
- }
- }
- });
- o.editField.subscribeToEvent(o.editField, "WidgetEvent", (ev: Atomic.UIWidgetEvent) => {
- if (ev.type == Atomic.UI_EVENT_TYPE_POINTER_DOWN && o.editField.text != "") {
- var pathName = materialEdit.pathReference;
- this.sendEvent(EditorEvents.InspectorProjectReference, { "path": pathName });
- } else if (o.editField.text == "") {
- this.openResourceSelectionBox(materialIndex, resourceTypeName, importerName);
- }
- });
- }
- createEditWidget() {
- var mainLayout = this.mainLayout = new Atomic.UILayout();
- mainLayout.axis = Atomic.UI_AXIS_Y;
- mainLayout.layoutSize = Atomic.UI_LAYOUT_SIZE_AVAILABLE;
- mainLayout.layoutPosition = Atomic.UI_LAYOUT_POSITION_LEFT_TOP;
- mainLayout.gravity = Atomic.UI_GRAVITY_LEFT_RIGHT;
- mainLayout.layoutDistribution = Atomic.UI_LAYOUT_DISTRIBUTION_GRAVITY;
- var cb = InspectorUtils.createAttrCheckBox(this.name, mainLayout);
- this.enabledCheckBox = cb.checkBox;
- cb.checkBox.subscribeToEvent(cb.checkBox, "WidgetEvent", (ev: Atomic.UIWidgetEvent) => {
- if (ev.type == Atomic.UI_EVENT_TYPE_CHANGED) {
- var scene: Atomic.Scene;
- for (var i in this.editType.objects) {
- var staticModel = <Atomic.StaticModel>this.editType.objects[i];
- scene = staticModel.scene;
- if (cb.checkBox.value) {
- staticModel.showGeometry(this.name);
- } else {
- staticModel.hideGeometry(this.name);
- }
- }
- scene.sendEvent("SceneEditEnd");
- return true;
- }
- return false;
- });
- this.nameField = cb.textField;
- this.editWidget = mainLayout;
- }
- refresh() {
- var editType = this.editType;
- var object = this.editType.getFirstObject();
- if (!object) {
- this.visibility = Atomic.UI_WIDGET_VISIBILITY_GONE;
- return;
- }
- this.visibility = Atomic.UI_WIDGET_VISIBILITY_VISIBLE;
- var enabled = (<Atomic.StaticModel>object).getGeometryVisible(this.name);
- var mixed = false;
- for (var i in editType.objects) {
- object = editType.objects[i];
- var _enabled = (<Atomic.StaticModel>object).getGeometryVisible(this.name);
- if (_enabled != enabled) {
- mixed = true;
- break;
- }
- }
- if (mixed) {
- this.enabledCheckBox.skinBg = "TBGreyCheckBoxNonUniform";
- this.enabledCheckBox.value = 1;
- } else {
- this.enabledCheckBox.skinBg = "TBGreyCheckBox";
- this.enabledCheckBox.value = enabled ? 1 : 0;
- }
- for (var i in this.materialIndexes) {
- var idx = this.materialIndexes[i];
- if (!this.materialEdits[idx]) {
- this.createMaterialEdit(idx);
- }
- var matEdit = this.materialEdits[idx];
- var uniform = editType.getUniformValue(this.attrInfo, matEdit.index);
- if (uniform) {
- var object = editType.getFirstObject();
- if (object) {
- // for cached resources, use the asset name, otherwise use the resource path name
- var resource: Atomic.Resource;
- if (matEdit.index != -1) {
- resource = object.getAttribute(this.attrInfo.name).resources[matEdit.index];
- } else {
- resource = <Atomic.Resource>object.getAttribute(this.attrInfo.name);
- }
- var text = "";
- if (resource) {
- if (resource instanceof Atomic.Material) {
- text = (<Atomic.Material>resource).name;
- } else {
- text = "???";
- }
- }
- var pathinfo = Atomic.splitPath(text);
- matEdit.editField.text = pathinfo.fileName;
- matEdit.pathReference = text;
- }
- } else {
- matEdit.editField.text = "--";
- }
- }
- }
- }
- class SubmeshListAttributeEdit extends AttributeInfoEdit {
- layout: Atomic.UILayout;
- submeshEdits: { [name: string]: SubmeshAttributeEdit } = {};
- constructor() {
- super();
- this.hideName = true;
- }
- createEditWidget() {
- this.spacing = 0;
- var layout = this.layout = new Atomic.UILayout();
- layout.axis = Atomic.UI_AXIS_Y;
- layout.spacing = 2;
- layout.layoutSize = Atomic.UI_LAYOUT_SIZE_AVAILABLE;
- layout.layoutPosition = Atomic.UI_LAYOUT_POSITION_LEFT_TOP;
- layout.gravity = Atomic.UI_GRAVITY_LEFT_RIGHT;
- layout.layoutDistribution = Atomic.UI_LAYOUT_DISTRIBUTION_GRAVITY;
- var lp = new Atomic.UILayoutParams();
- lp.width = 304;
- layout.layoutParams = lp;
- var name = new Atomic.UITextField();
- name.textAlign = Atomic.UI_TEXT_ALIGN_LEFT;
- name.skinBg = "InspectorTextAttrName";
- name.layoutParams = AttributeInfoEdit.attrNameLP;
- name.text = "Submeshes";
- layout.addChild(name);
- InspectorUtils.createSeparator(layout);
- this.editWidget = layout;
- }
- refresh() {
- var editType = this.editType;
- var object = this.editType.getFirstObject();
- if (!object) {
- this.visibility = Atomic.UI_WIDGET_VISIBILITY_GONE;
- return;
- }
- this.visibility = Atomic.UI_WIDGET_VISIBILITY_VISIBLE;
- var name: string;
- for (var i in editType.objects) {
- // TODO: check for multiple selection with different models and display multiple selection info box
- var staticModel = <Atomic.StaticModel>editType.objects[i];
- var model = staticModel.model;
- if (!model)
- continue;
- for (var j = 0; j < model.numGeometries; j++) {
- name = model.getGeometryName(j);
- if (!name)
- name = "Mesh";
- if (!this.submeshEdits.hasOwnProperty(name)) {
- var submeshEdit = new SubmeshAttributeEdit(name);
- submeshEdit.initialize(this.editType, this.attrInfo);
- this.layout.addChild(submeshEdit);
- this.submeshEdits[name] = submeshEdit;
- InspectorUtils.createSeparator(this.layout);
- }
- this.submeshEdits[name].materialIndexes.push(j);
- }
- }
- for (name in this.submeshEdits)
- this.submeshEdits[name].refresh();
- }
- }
- AttributeInfoEdit.registerCustomAttr("AnimatedModel", "Material", SubmeshListAttributeEdit);
- AttributeInfoEdit.registerCustomAttr("StaticModel", "Material", SubmeshListAttributeEdit);
- AttributeInfoEdit.registerCustomAttr("Light", "CSM Splits", LightCascadeAttributeEdit);
|