inputNodePropertyComponent.tsx 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. interface IInputPropertyTabComponentProps {
  13. globalState: GlobalState;
  14. inputNode: InputNodeModel;
  15. }
  16. export class InputPropertyTabComponentProps extends React.Component<IInputPropertyTabComponentProps> {
  17. constructor(props: IInputPropertyTabComponentProps) {
  18. super(props)
  19. }
  20. renderValue(globalState: GlobalState) {
  21. let connection = this.props.inputNode.connection!;
  22. switch (connection.type) {
  23. case NodeMaterialBlockConnectionPointTypes.Vector2:
  24. return (
  25. <Vector2PropertyTabComponent globalState={globalState} connection={connection} />
  26. );
  27. case NodeMaterialBlockConnectionPointTypes.Vector3:
  28. case NodeMaterialBlockConnectionPointTypes.Color3:
  29. case NodeMaterialBlockConnectionPointTypes.Vector3OrColor3:
  30. return (
  31. <Vector3PropertyTabComponent globalState={globalState} connection={connection} />
  32. );
  33. }
  34. return null;
  35. }
  36. setDefaultValue() {
  37. let connection = this.props.inputNode.connection!;
  38. switch (connection.type) {
  39. case NodeMaterialBlockConnectionPointTypes.Vector2:
  40. connection.value = Vector2.Zero();
  41. break;
  42. case NodeMaterialBlockConnectionPointTypes.Vector3:
  43. case NodeMaterialBlockConnectionPointTypes.Color3:
  44. case NodeMaterialBlockConnectionPointTypes.Vector3OrColor3:
  45. connection.value = Vector3.Zero();
  46. break;
  47. case NodeMaterialBlockConnectionPointTypes.Matrix:
  48. connection.value = Matrix.Identity();
  49. break;
  50. }
  51. }
  52. render() {
  53. let connection = this.props.inputNode.connection!;
  54. var wellKnownOptions = [
  55. { label: "World", value: NodeMaterialWellKnownValues.World },
  56. { label: "WorldxView", value: NodeMaterialWellKnownValues.WorldView },
  57. { label: "WorldxViewxProjection", value: NodeMaterialWellKnownValues.WorldViewProjection },
  58. { label: "View", value: NodeMaterialWellKnownValues.View },
  59. { label: "ViewxProjection", value: NodeMaterialWellKnownValues.ViewProjection },
  60. { label: "Projection", value: NodeMaterialWellKnownValues.Projection },
  61. { label: "Automatic", value: NodeMaterialWellKnownValues.Automatic },
  62. ];
  63. /**
  64. * Gets the base math type of node material block connection point.
  65. * @param type Type to parse.
  66. */
  67. function getBaseType(type: NodeMaterialBlockConnectionPointTypes): string {
  68. switch (type) {
  69. case NodeMaterialBlockConnectionPointTypes.Vector3OrColor3:
  70. case NodeMaterialBlockConnectionPointTypes.Color3: {
  71. return NodeMaterialBlockConnectionPointTypes[NodeMaterialBlockConnectionPointTypes.Vector3];
  72. }
  73. case NodeMaterialBlockConnectionPointTypes.Vector4OrColor4:
  74. case NodeMaterialBlockConnectionPointTypes.Vector3OrVector4:
  75. case NodeMaterialBlockConnectionPointTypes.Color3OrColor4:
  76. case NodeMaterialBlockConnectionPointTypes.Vector3OrColor3OrVector4OrColor4:
  77. case NodeMaterialBlockConnectionPointTypes.Color4: {
  78. return NodeMaterialBlockConnectionPointTypes[NodeMaterialBlockConnectionPointTypes.Vector4];
  79. }
  80. default: {
  81. return NodeMaterialBlockConnectionPointTypes[type];
  82. }
  83. }
  84. }
  85. return (
  86. <div>
  87. <TextLineComponent label="Type" value={getBaseType(connection.type)} />
  88. <CheckBoxLineComponent label="Is mesh attribute" onSelect={value => {
  89. connection!.isAttribute = value;
  90. this.props.globalState.onRebuildRequiredObservable.notifyObservers();
  91. this.forceUpdate();
  92. }} isSelected={() => connection!.isAttribute} />
  93. {
  94. connection.isUniform &&
  95. <CheckBoxLineComponent label="Is well known value" onSelect={value => {
  96. if (value) {
  97. connection!.setAsWellKnownValue(NodeMaterialWellKnownValues.World);
  98. } else {
  99. connection!.setAsWellKnownValue(null);
  100. this.setDefaultValue();
  101. }
  102. this.props.globalState.onRebuildRequiredObservable.notifyObservers();
  103. this.forceUpdate();
  104. }} isSelected={() => connection!.isWellKnownValue} />
  105. }
  106. {
  107. connection.isUniform && !connection.isWellKnownValue &&
  108. this.renderValue(this.props.globalState)
  109. }
  110. {
  111. connection.isUniform && connection.isWellKnownValue &&
  112. <OptionsLineComponent label="Well known value" options={wellKnownOptions} target={connection} propertyName="wellKnownValue" onSelect={(value: any) => {
  113. connection.setAsWellKnownValue(value);
  114. this.forceUpdate();
  115. this.props.globalState.onRebuildRequiredObservable.notifyObservers();
  116. }} />
  117. }
  118. </div>
  119. );
  120. }
  121. }