nodeMaterialDecorator.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /**
  2. * Enum defining the type of properties that can be edited in the property pages in the NME
  3. */
  4. export enum PropertyTypeForEdition {
  5. /** property is a boolean */
  6. Boolean,
  7. /** property is a float */
  8. Float,
  9. /** property is a Vector2 */
  10. Vector2,
  11. /** property is a list of values */
  12. List,
  13. }
  14. /**
  15. * Interface that defines an option in a variable of type list
  16. */
  17. export interface IEditablePropertyListOption {
  18. /** label of the option */
  19. "label": string;
  20. /** value of the option */
  21. "value": number;
  22. }
  23. /**
  24. * Interface that defines the options available for an editable property
  25. */
  26. export interface IEditablePropertyOption {
  27. /** min value */
  28. "min"?: number;
  29. /** max value */
  30. "max"?: number;
  31. /** notifiers: indicates which actions to take when the property is changed */
  32. "notifiers"?: {
  33. /** the material should be rebuilt */
  34. "rebuild"?: boolean;
  35. /** the preview should be updated */
  36. "update"?: boolean;
  37. };
  38. /** list of the options for a variable of type list */
  39. "options"?: IEditablePropertyListOption[];
  40. }
  41. /**
  42. * Interface that describes an editable property
  43. */
  44. export interface IPropertyDescriptionForEdition {
  45. /** name of the property */
  46. "propertyName": string;
  47. /** display name of the property */
  48. "displayName": string;
  49. /** type of the property */
  50. "type": PropertyTypeForEdition;
  51. /** group of the property - all properties with the same group value will be displayed in a specific section */
  52. "groupName": string;
  53. /** options for the property */
  54. "options": IEditablePropertyOption;
  55. }
  56. /**
  57. * Decorator that flags a property in a node material block as being editable
  58. */
  59. export function editableInPropertyPage(displayName: string, propertyType: PropertyTypeForEdition = PropertyTypeForEdition.Boolean, groupName: string = "PROPERTIES", options?: IEditablePropertyOption) {
  60. return (target: any, propertyKey: string) => {
  61. let propStore: IPropertyDescriptionForEdition[] = target._propStore;
  62. if (!propStore) {
  63. propStore = [];
  64. target._propStore = propStore;
  65. }
  66. propStore.push({
  67. "propertyName": propertyKey,
  68. "displayName": displayName,
  69. "type": propertyType,
  70. "groupName": groupName,
  71. "options": options ?? {}
  72. });
  73. };
  74. }