inputNodePropertyComponent.tsx 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. import * as React from "react";
  2. import { Vector2PropertyTabComponent } from '../../propertyTab/properties/vector2PropertyTabComponent';
  3. import { Vector3PropertyTabComponent } from '../../propertyTab/properties/vector3PropertyTabComponent';
  4. import { CheckBoxLineComponent } from '../../../sharedComponents/checkBoxLineComponent';
  5. import { GlobalState } from '../../../globalState';
  6. import { InputNodeModel } from './inputNodeModel';
  7. import { NodeMaterialBlockConnectionPointTypes } from 'babylonjs/Materials/Node/nodeMaterialBlockConnectionPointTypes';
  8. import { OptionsLineComponent } from '../../../sharedComponents/optionsLineComponent';
  9. import { NodeMaterialWellKnownValues } from 'babylonjs/Materials/Node/nodeMaterialWellKnownValues';
  10. import { Vector2, Vector3, Matrix } from 'babylonjs/Maths/math';
  11. import { TextLineComponent } from '../../../sharedComponents/textLineComponent';
  12. import { Color3PropertyTabComponent } from '../../propertyTab/properties/color3PropertyTabComponent';
  13. import { FloatPropertyTabComponent } from '../../propertyTab/properties/floatPropertyTabComponent';
  14. import { LineContainerComponent } from '../../../sharedComponents/lineContainerComponent';
  15. import { StringTools } from '../../../stringTools';
  16. interface IInputPropertyTabComponentProps {
  17. globalState: GlobalState;
  18. inputNode: InputNodeModel;
  19. }
  20. export class InputPropertyTabComponentProps extends React.Component<IInputPropertyTabComponentProps> {
  21. constructor(props: IInputPropertyTabComponentProps) {
  22. super(props)
  23. }
  24. renderValue(globalState: GlobalState) {
  25. let connection = this.props.inputNode.connection!;
  26. switch (connection.type) {
  27. case NodeMaterialBlockConnectionPointTypes.Float:
  28. return (
  29. <FloatPropertyTabComponent globalState={globalState} connection={connection} />
  30. );
  31. case NodeMaterialBlockConnectionPointTypes.Vector2:
  32. return (
  33. <Vector2PropertyTabComponent globalState={globalState} connection={connection} />
  34. );
  35. case NodeMaterialBlockConnectionPointTypes.Color3:
  36. case NodeMaterialBlockConnectionPointTypes.Color3OrColor4:
  37. case NodeMaterialBlockConnectionPointTypes.Color4:
  38. return (
  39. <Color3PropertyTabComponent globalState={globalState} connection={connection} />
  40. );
  41. case NodeMaterialBlockConnectionPointTypes.Vector3:
  42. case NodeMaterialBlockConnectionPointTypes.Vector3OrColor3:
  43. return (
  44. <Vector3PropertyTabComponent globalState={globalState} connection={connection} />
  45. );
  46. }
  47. return null;
  48. }
  49. setDefaultValue() {
  50. let connection = this.props.inputNode.connection!;
  51. switch (connection.type) {
  52. case NodeMaterialBlockConnectionPointTypes.Float:
  53. connection.value = 0;
  54. break;
  55. case NodeMaterialBlockConnectionPointTypes.Vector2:
  56. connection.value = Vector2.Zero();
  57. break;
  58. case NodeMaterialBlockConnectionPointTypes.Vector3:
  59. case NodeMaterialBlockConnectionPointTypes.Color3:
  60. case NodeMaterialBlockConnectionPointTypes.Vector3OrColor3:
  61. connection.value = Vector3.Zero();
  62. break;
  63. case NodeMaterialBlockConnectionPointTypes.Matrix:
  64. connection.value = Matrix.Identity();
  65. break;
  66. }
  67. }
  68. render() {
  69. let connection = this.props.inputNode.connection!;
  70. var wellKnownOptions = [
  71. { label: "World", value: NodeMaterialWellKnownValues.World },
  72. { label: "WorldxView", value: NodeMaterialWellKnownValues.WorldView },
  73. { label: "WorldxViewxProjection", value: NodeMaterialWellKnownValues.WorldViewProjection },
  74. { label: "View", value: NodeMaterialWellKnownValues.View },
  75. { label: "ViewxProjection", value: NodeMaterialWellKnownValues.ViewProjection },
  76. { label: "Projection", value: NodeMaterialWellKnownValues.Projection },
  77. { label: "Camera position", value: NodeMaterialWellKnownValues.CameraPosition },
  78. { label: "Automatic", value: NodeMaterialWellKnownValues.Automatic },
  79. ];
  80. var attributeOptions = [
  81. { label: "position", value: "position" },
  82. { label: "normal", value: "normal" },
  83. { label: "tangent", value: "tangent" },
  84. { label: "color", value: "color" },
  85. { label: "uv", value: "uv" },
  86. { label: "uv2", value: "uv2" },
  87. ];
  88. return (
  89. <div>
  90. <LineContainerComponent title="GENERAL">
  91. <TextLineComponent label="Type" value={StringTools.GetBaseType(connection.type)} />
  92. </LineContainerComponent>
  93. <LineContainerComponent title="PROPERTIES">
  94. <CheckBoxLineComponent label="Is mesh attribute" onSelect={value => {
  95. if (!value) {
  96. connection.isUniform = true;
  97. this.setDefaultValue();
  98. } else {
  99. connection.isAttribute = true;
  100. }
  101. this.props.globalState.onRebuildRequiredObservable.notifyObservers();
  102. this.forceUpdate();
  103. }} isSelected={() => connection!.isAttribute} />
  104. {
  105. connection.isAttribute &&
  106. <OptionsLineComponent label="Attribute" valuesAreStrings={true} options={attributeOptions} target={connection} propertyName="name" onSelect={(value: any) => {
  107. connection.setAsAttribute(value);
  108. this.forceUpdate();
  109. this.props.globalState.onRebuildRequiredObservable.notifyObservers();
  110. }} />
  111. }
  112. {
  113. connection.isUniform &&
  114. <CheckBoxLineComponent label="Is well known value" onSelect={value => {
  115. if (value) {
  116. connection!.setAsWellKnownValue(NodeMaterialWellKnownValues.World);
  117. } else {
  118. connection!.setAsWellKnownValue(null);
  119. this.setDefaultValue();
  120. }
  121. this.props.globalState.onRebuildRequiredObservable.notifyObservers();
  122. this.forceUpdate();
  123. }} isSelected={() => connection!.isWellKnownValue} />
  124. }
  125. {
  126. connection.isUniform && !connection.isWellKnownValue &&
  127. this.renderValue(this.props.globalState)
  128. }
  129. {
  130. connection.isUniform && connection.isWellKnownValue &&
  131. <OptionsLineComponent label="Well known value" options={wellKnownOptions} target={connection} propertyName="wellKnownValue" onSelect={(value: any) => {
  132. connection.setAsWellKnownValue(value);
  133. this.forceUpdate();
  134. this.props.globalState.onRebuildRequiredObservable.notifyObservers();
  135. }} />
  136. }
  137. </LineContainerComponent>
  138. </div>
  139. );
  140. }
  141. }