Skip to content

Commit a8832d4

Browse files
committed
feat: add support of decal map in standard and pbr material inspectors
1 parent 9b99df0 commit a8832d4

5 files changed

Lines changed: 76 additions & 18 deletions

File tree

editor/src/editor/layout/graph/remove.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ export function removeNodes(editor: Editor) {
207207
});
208208
},
209209
});
210+
211+
editor.layout.preview.selectionOutlineLayer.clearSelection();
210212
}
211213

212214
function restoreNodeData(editor: Editor, data: _RemoveNodeData, scene: Scene) {
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { Component, ReactNode } from "react";
2+
3+
import { PBRMaterial, StandardMaterial } from "babylonjs";
4+
5+
import { EditorInspectorSwitchField } from "../../fields/switch";
6+
import { EditorInspectorNumberField } from "../../fields/number";
7+
import { EditorInspectorSectionField } from "../../fields/section";
8+
import { EditorInspectorTextureField } from "../../fields/texture";
9+
10+
export interface IEditorDetailMapInspectorProps {
11+
material: StandardMaterial | PBRMaterial;
12+
}
13+
14+
export interface IEditorDetailMapInspectorState {}
15+
16+
export class EditorDetailMapInspector extends Component<IEditorDetailMapInspectorProps, IEditorDetailMapInspectorState> {
17+
public constructor(props: IEditorDetailMapInspectorProps) {
18+
super(props);
19+
20+
this.state = {};
21+
}
22+
23+
public render(): ReactNode {
24+
return (
25+
<EditorInspectorSectionField title="Detail Map">
26+
<EditorInspectorSwitchField object={this.props.material.detailMap} property="isEnabled" label="Enabled" onChange={() => this.forceUpdate()} />
27+
28+
{this.props.material.detailMap.isEnabled && (
29+
<>
30+
<EditorInspectorTextureField hideLevel scene={this.props.material.getScene()} object={this.props.material.detailMap} property="texture" title="Texture" />
31+
<EditorInspectorNumberField object={this.props.material.detailMap} property="diffuseBlendLevel" label="Diffuse Blend Level" step={0.01} min={0} max={1} />
32+
<EditorInspectorNumberField object={this.props.material.detailMap} property="bumpLevel" label="Bump Level" step={0.01} min={0} max={1} />
33+
<EditorInspectorNumberField
34+
object={this.props.material.detailMap}
35+
property="roughnessBlendLevel"
36+
label="Roughness Blend Level"
37+
step={0.01}
38+
min={0}
39+
max={1}
40+
/>
41+
</>
42+
)}
43+
</EditorInspectorSectionField>
44+
);
45+
}
46+
}

editor/src/editor/layout/inspector/material/pbr.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { EditorInspectorTextureField } from "../fields/texture";
1313
import { EditorInspectorSectionField } from "../fields/section";
1414

1515
import { EditorAlphaModeField } from "./components/alpha";
16+
import { EditorDetailMapInspector } from "./components/detail";
1617
import { EditorTransparencyModeField } from "./components/transparency";
1718
import { EditorMaterialInspectorUtilsComponent } from "./components/utils";
1819

@@ -245,6 +246,8 @@ export class EditorPBRMaterialInspector extends Component<IEditorPBRMaterialInsp
245246
</EditorInspectorSectionField>
246247
)}
247248

249+
<EditorDetailMapInspector material={this.props.material} />
250+
248251
<EditorInspectorSectionField title="Sub Surface">
249252
<EditorInspectorSwitchField
250253
noUndoRedo

editor/src/editor/layout/inspector/material/standard.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { EditorInspectorTextureField } from "../fields/texture";
1010
import { EditorInspectorSectionField } from "../fields/section";
1111

1212
import { EditorAlphaModeField } from "./components/alpha";
13+
import { EditorDetailMapInspector } from "./components/detail";
1314
import { EditorTransparencyModeField } from "./components/transparency";
1415
import { EditorMaterialInspectorUtilsComponent } from "./components/utils";
1516

@@ -80,6 +81,8 @@ export function EditorStandardMaterialInspector(props: IEditorStandardMaterialIn
8081
<EditorInspectorNumberField label="Specular Intensity" object={props.material} property="specularIntensity" min={0} />
8182
</EditorInspectorSectionField>
8283

84+
<EditorDetailMapInspector material={props.material} />
85+
8386
<EditorInspectorSectionField title="Misc">
8487
<EditorInspectorSwitchField label="Disable Lighting" object={props.material} property="disableLighting" />
8588
<EditorInspectorSwitchField label="Use Specular Over Alpha" object={props.material} property="useSpecularOverAlpha" />

editor/src/editor/layout/preview.tsx

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ export class EditorPreview extends Component<IEditorPreviewProps, IEditorPreview
189189
private _renderScene: boolean = true;
190190
private _mouseDownPosition: Vector2 = Vector2.Zero();
191191

192+
private _lastPickedDecal: AbstractMesh | null = null;
192193
private _objectUnderPointer: AbstractMesh | Sprite | null = null;
193194

194195
private _workingCanvas: HTMLCanvasElement | null = null;
@@ -767,34 +768,37 @@ export class EditorPreview extends Component<IEditorPreviewProps, IEditorPreview
767768
}
768769
}
769770

770-
private _getPickingInfo(x: number, y: number): PickingInfo {
771-
const decalPick = this.scene.pick(
772-
x,
773-
y,
774-
(m) => {
775-
return m.metadata?.decal && m.isVisible && m.isEnabled();
776-
},
777-
false
778-
);
771+
private _decalMeshPredicate(m: AbstractMesh): boolean {
772+
if (!m.isVisible || !m.isEnabled() || !m.metadata?.decal) {
773+
return false;
774+
}
779775

780-
const meshPick = this.scene.pick(
781-
x,
782-
y,
783-
(m) => {
784-
return !m._masterMesh && !isCollisionMesh(m) && !isCollisionInstancedMesh(m) && m.isVisible && m.isEnabled();
785-
},
786-
false
787-
);
776+
if (this._lastPickedDecal) {
777+
return m !== this._lastPickedDecal;
778+
}
788779

780+
return true;
781+
}
782+
783+
private _meshPredicate(m: AbstractMesh): boolean {
784+
return !m._masterMesh && !isCollisionMesh(m) && !isCollisionInstancedMesh(m) && m.isVisible && m.isEnabled();
785+
}
786+
787+
private _getPickingInfo(x: number, y: number): PickingInfo {
788+
const decalPick = this.scene.pick(x, y, (m) => this._decalMeshPredicate(m), false);
789+
const meshPick = this.scene.pick(x, y, (m) => this._meshPredicate(m), false);
789790
const spritePick = this.scene.pickSprite(x, y, (s) => isSprite(s), false);
790791

792+
this._lastPickedDecal = null;
793+
791794
let pickingInfo = meshPick;
792795
if (decalPick?.pickedPoint && meshPick?.pickedPoint) {
793796
const distance = Vector3.Distance(decalPick.pickedPoint, meshPick.pickedPoint);
794797
const zOffset = decalPick.pickedMesh?.material?.zOffset ?? 0;
795798

796-
if (distance <= zOffset + 0.01) {
799+
if (distance <= zOffset + 1) {
797800
pickingInfo = decalPick;
801+
this._lastPickedDecal = decalPick.pickedMesh;
798802
}
799803
}
800804

0 commit comments

Comments
 (0)