inputNodePropertyComponent.tsx 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. switch (this.props.inputNode.outputType) {
  48. case NodeMaterialBlockConnectionPointTypes.Float:
  49. return (
  50. <FloatPropertyTabComponent globalState={globalState} connection={connection} />
  51. );
  52. case NodeMaterialBlockConnectionPointTypes.Vector2:
  53. return (
  54. <Vector2PropertyTabComponent globalState={globalState} connection={connection} />
  55. );
  56. case NodeMaterialBlockConnectionPointTypes.Color3:
  57. case NodeMaterialBlockConnectionPointTypes.Color3OrColor4:
  58. case NodeMaterialBlockConnectionPointTypes.Color4:
  59. return (
  60. <Color3PropertyTabComponent globalState={globalState} connection={connection} />
  61. );
  62. case NodeMaterialBlockConnectionPointTypes.Vector3:
  63. case NodeMaterialBlockConnectionPointTypes.Vector3OrColor3:
  64. return (
  65. <Vector3PropertyTabComponent globalState={globalState} connection={connection} />
  66. );
  67. }
  68. return null;
  69. }
  70. setDefaultValue() {
  71. let connection = this.props.inputNode.connection!;
  72. switch (connection.type) {
  73. case NodeMaterialBlockConnectionPointTypes.Float:
  74. connection.value = 0;
  75. break;
  76. case NodeMaterialBlockConnectionPointTypes.Vector2:
  77. connection.value = Vector2.Zero();
  78. break;
  79. case NodeMaterialBlockConnectionPointTypes.Vector3:
  80. case NodeMaterialBlockConnectionPointTypes.Color3:
  81. case NodeMaterialBlockConnectionPointTypes.Vector3OrColor3:
  82. connection.value = Vector3.Zero();
  83. break;
  84. case NodeMaterialBlockConnectionPointTypes.Matrix:
  85. connection.value = Matrix.Identity();
  86. break;
  87. }
  88. }
  89. render() {
  90. let connection = this.props.inputNode.connection!;
  91. var wellKnownOptions = [
  92. { label: "World", value: NodeMaterialWellKnownValues.World },
  93. { label: "WorldxView", value: NodeMaterialWellKnownValues.WorldView },
  94. { label: "WorldxViewxProjection", value: NodeMaterialWellKnownValues.WorldViewProjection },
  95. { label: "View", value: NodeMaterialWellKnownValues.View },
  96. { label: "ViewxProjection", value: NodeMaterialWellKnownValues.ViewProjection },
  97. { label: "Projection", value: NodeMaterialWellKnownValues.Projection },
  98. { label: "Camera position", value: NodeMaterialWellKnownValues.CameraPosition },
  99. { label: "Automatic", value: NodeMaterialWellKnownValues.Automatic },
  100. ];
  101. var attributeOptions = [
  102. { label: "position", value: "position" },
  103. { label: "normal", value: "normal" },
  104. { label: "tangent", value: "tangent" },
  105. { label: "color", value: "color" },
  106. { label: "uv", value: "uv" },
  107. { label: "uv2", value: "uv2" },
  108. ];
  109. return (
  110. <div>
  111. <LineContainerComponent title="GENERAL">
  112. <TextLineComponent label="Type" value={StringTools.GetBaseType(this.props.inputNode.outputType)} />
  113. </LineContainerComponent>
  114. <LineContainerComponent title="PROPERTIES">
  115. <CheckBoxLineComponent label="Is mesh attribute" onSelect={value => {
  116. if (!value) {
  117. connection.isUniform = true;
  118. this.setDefaultValue();
  119. } else {
  120. connection.isAttribute = true;
  121. }
  122. this.props.globalState.onRebuildRequiredObservable.notifyObservers();
  123. this.forceUpdate();
  124. }} isSelected={() => connection!.isAttribute} />
  125. {
  126. connection.isAttribute &&
  127. <OptionsLineComponent label="Attribute" valuesAreStrings={true} options={attributeOptions} target={connection} propertyName="name" onSelect={(value: any) => {
  128. connection.setAsAttribute(value);
  129. this.forceUpdate();
  130. this.props.globalState.onRebuildRequiredObservable.notifyObservers();
  131. }} />
  132. }
  133. {
  134. connection.isUniform &&
  135. <CheckBoxLineComponent label="Is well known value" onSelect={value => {
  136. if (value) {
  137. connection!.setAsWellKnownValue(NodeMaterialWellKnownValues.World);
  138. } else {
  139. connection!.setAsWellKnownValue(null);
  140. this.setDefaultValue();
  141. }
  142. this.props.globalState.onRebuildRequiredObservable.notifyObservers();
  143. this.forceUpdate();
  144. }} isSelected={() => connection!.isWellKnownValue} />
  145. }
  146. {
  147. connection.isUniform && !connection.isWellKnownValue &&
  148. this.renderValue(this.props.globalState)
  149. }
  150. {
  151. connection.isUniform && connection.isWellKnownValue &&
  152. <OptionsLineComponent label="Well known value" options={wellKnownOptions} target={connection} propertyName="wellKnownValue" onSelect={(value: any) => {
  153. connection.setAsWellKnownValue(value);
  154. this.forceUpdate();
  155. this.props.globalState.onRebuildRequiredObservable.notifyObservers();
  156. }} />
  157. }
  158. </LineContainerComponent>
  159. </div>
  160. );
  161. }
  162. }