|
| 1 | +import { Component, ReactNode } from "react"; |
| 2 | + |
| 3 | +import { AbstractMesh } from "babylonjs"; |
| 4 | +import { WaterMaterial } from "babylonjs-materials"; |
| 5 | + |
| 6 | +import { EditorInspectorColorField } from "../fields/color"; |
| 7 | +import { EditorInspectorStringField } from "../fields/string"; |
| 8 | +import { EditorInspectorSwitchField } from "../fields/switch"; |
| 9 | +import { EditorInspectorNumberField } from "../fields/number"; |
| 10 | +import { EditorInspectorSectionField } from "../fields/section"; |
| 11 | +import { EditorInspectorTextureField } from "../fields/texture"; |
| 12 | + |
| 13 | +import { EditorMaterialInspectorUtilsComponent } from "./components/utils"; |
| 14 | +import { Switch } from "../../../../ui/shadcn/ui/switch"; |
| 15 | +import { EditorInspectorVectorField } from "../fields/vector"; |
| 16 | + |
| 17 | +export interface IEditorWaterMaterialInspectorProps { |
| 18 | + mesh?: AbstractMesh; |
| 19 | + material: WaterMaterial; |
| 20 | +} |
| 21 | + |
| 22 | +export interface IEditorWaterMaterialInspectorState { |
| 23 | + renderListSearch: string; |
| 24 | +} |
| 25 | + |
| 26 | +export class EditorWaterMaterialInspector extends Component<IEditorWaterMaterialInspectorProps, IEditorWaterMaterialInspectorState> { |
| 27 | + public constructor(props: IEditorWaterMaterialInspectorProps) { |
| 28 | + super(props); |
| 29 | + |
| 30 | + this.state = { |
| 31 | + renderListSearch: "", |
| 32 | + }; |
| 33 | + } |
| 34 | + |
| 35 | + public render(): ReactNode { |
| 36 | + return ( |
| 37 | + <> |
| 38 | + <EditorInspectorSectionField title="Material" label={this.props.material.getClassName()}> |
| 39 | + <EditorInspectorStringField label="Name" object={this.props.material} property="name" /> |
| 40 | + <EditorInspectorSwitchField label="Back Face Culling" object={this.props.material} property="backFaceCulling" /> |
| 41 | + |
| 42 | + <EditorMaterialInspectorUtilsComponent mesh={this.props.mesh} material={this.props.material} /> |
| 43 | + </EditorInspectorSectionField> |
| 44 | + |
| 45 | + <EditorInspectorSectionField title="Water"> |
| 46 | + <EditorInspectorTextureField hideLevel object={this.props.material} title="Normal Texture" property="bumpTexture" onChange={() => this.forceUpdate()}> |
| 47 | + <EditorInspectorNumberField label="Bump Height" object={this.props.material} property="bumpHeight" /> |
| 48 | + </EditorInspectorTextureField> |
| 49 | + </EditorInspectorSectionField> |
| 50 | + |
| 51 | + {this.props.material.bumpTexture && ( |
| 52 | + <> |
| 53 | + <EditorInspectorSectionField title="Colors"> |
| 54 | + <EditorInspectorColorField label={<div className="w-14">Color 1</div>} object={this.props.material} property="waterColor" /> |
| 55 | + <EditorInspectorColorField label={<div className="w-14">Color 2</div>} object={this.props.material} property="waterColor2" /> |
| 56 | + <EditorInspectorNumberField label="Color Blend Factor" object={this.props.material} property="colorBlendFactor" min={0} max={1} /> |
| 57 | + <EditorInspectorNumberField label="Color Blend Factor 2" object={this.props.material} property="colorBlendFactor2" min={0} max={1} /> |
| 58 | + |
| 59 | + <EditorInspectorColorField label={<div className="w-14">Diffuse</div>} object={this.props.material} property="diffuseColor" /> |
| 60 | + <EditorInspectorColorField label={<div className="w-14">Specular</div>} object={this.props.material} property="specularColor" /> |
| 61 | + </EditorInspectorSectionField> |
| 62 | + |
| 63 | + <EditorInspectorSectionField title="Reflection"> |
| 64 | + <input |
| 65 | + type="text" |
| 66 | + placeholder="Search..." |
| 67 | + value={this.state.renderListSearch} |
| 68 | + onChange={(e) => this.setState({ renderListSearch: e.currentTarget.value })} |
| 69 | + className="px-5 py-2 rounded-lg bg-primary-foreground outline-none w-full" |
| 70 | + /> |
| 71 | + |
| 72 | + <div className="flex flex-col w-full max-h-96 p-2 rounded-lg bg-card overflow-x-hidden overflow-y-auto"> |
| 73 | + {this.props.material |
| 74 | + .getScene() |
| 75 | + .meshes.filter((mesh) => mesh.name.toLowerCase().includes(this.state.renderListSearch.toLowerCase())) |
| 76 | + .map((mesh) => this._getRenderListItem(mesh))} |
| 77 | + </div> |
| 78 | + </EditorInspectorSectionField> |
| 79 | + </> |
| 80 | + )} |
| 81 | + |
| 82 | + <EditorInspectorSectionField title="Options"> |
| 83 | + <EditorInspectorNumberField label="Wave Length" object={this.props.material} property="waveLength" /> |
| 84 | + |
| 85 | + <EditorInspectorNumberField label="Wind Force" object={this.props.material} property="windForce" /> |
| 86 | + <EditorInspectorVectorField label="Wind Direction" object={this.props.material} property="windDirection" step={0.1} /> |
| 87 | + |
| 88 | + <EditorInspectorSwitchField label="Bump Super Impose" object={this.props.material} property="bumpSuperimpose" /> |
| 89 | + <EditorInspectorSwitchField label="Fresnel Separate" object={this.props.material} property="fresnelSeparate" /> |
| 90 | + <EditorInspectorSwitchField label="Bump Affects Reflection" object={this.props.material} property="bumpAffectsReflection" /> |
| 91 | + </EditorInspectorSectionField> |
| 92 | + |
| 93 | + <EditorInspectorSectionField title="Misc"> |
| 94 | + <EditorInspectorSwitchField label="Disable Lighting" object={this.props.material} property="disableLighting" /> |
| 95 | + <EditorInspectorSwitchField label="Separate Culling Pass" object={this.props.material} property="separateCullingPass" /> |
| 96 | + <EditorInspectorNumberField label="Z Offset" object={this.props.material} property="zOffset" /> |
| 97 | + <EditorInspectorNumberField label="Z Offset Units" object={this.props.material} property="zOffsetUnits" /> |
| 98 | + <EditorInspectorSwitchField label="Fog Enabled" object={this.props.material} property="fogEnabled" /> |
| 99 | + </EditorInspectorSectionField> |
| 100 | + </> |
| 101 | + ); |
| 102 | + } |
| 103 | + |
| 104 | + private _getRenderListItem(mesh: AbstractMesh): ReactNode { |
| 105 | + if (mesh === this.props.mesh) { |
| 106 | + return undefined; |
| 107 | + } |
| 108 | + |
| 109 | + return ( |
| 110 | + <div key={mesh.id} className="flex items-center gap-2 hover:bg-muted transition-all duration-300 ease-in-out p-2 rounded-lg"> |
| 111 | + <Switch |
| 112 | + defaultChecked={this.props.material.reflectionTexture?.renderList?.includes(mesh)} |
| 113 | + onCheckedChange={(checked) => { |
| 114 | + if (checked) { |
| 115 | + this.props.material.addToRenderList(mesh); |
| 116 | + } else { |
| 117 | + this.props.material.removeFromRenderList(mesh); |
| 118 | + } |
| 119 | + }} |
| 120 | + /> |
| 121 | + <div>{mesh.name}</div> |
| 122 | + </div> |
| 123 | + ); |
| 124 | + } |
| 125 | +} |
0 commit comments