import * as React from "react"; import { Mesh, Observable } from "babylonjs"; import { PropertyChangedEvent } from "../../../../propertyChangedEvent"; import { LineContainerComponent } from "../../../lineContainerComponent"; import { TextLineComponent } from "../../../lines/textLineComponent"; import { CheckBoxLineComponent } from "../../../lines/checkBoxLineComponent"; import { Vector3LineComponent } from "../../../lines/vector3LineComponent"; import { SliderLineComponent } from "../../../lines/sliderLineComponent"; interface IMeshPropertyGridComponentProps { mesh: Mesh, onSelectionChangeObservable?: Observable, onPropertyChangedObservable?: Observable } export class MeshPropertyGridComponent extends React.Component { constructor(props: IMeshPropertyGridComponentProps) { super(props); this.state = { paintNormals: false } } paintNormals() { const mesh = this.props.mesh; const scene = mesh.getScene(); if (!mesh.material) { return; } if (mesh.material.getClassName() === "NormalMaterial") { mesh.material.dispose(); mesh.material = mesh.metadata.originalMaterial; mesh.metadata.originalMaterial = null; this.setState({ paintNormals: false }); } else { if (!(BABYLON as any).NormalMaterial) { this.setState({ paintNormals: true }); BABYLON.Tools.LoadScript("https://preview.babylonjs.com/materialsLibrary/babylonjs.materials.js", () => { this.paintNormals(); }); return; } if (!mesh.metadata) { mesh.metadata = {}; } mesh.metadata.originalMaterial = mesh.material; const normalMaterial = new (BABYLON as any).NormalMaterial("normalMaterial", scene); normalMaterial.disableLighting = true; normalMaterial.sideOrientation = mesh.material.sideOrientation; normalMaterial.metadata = { hidden: true }; mesh.material = normalMaterial; this.setState({ paintNormals: true }); } } onMaterialLink() { if (!this.props.onSelectionChangeObservable) { return; } const mesh = this.props.mesh; this.props.onSelectionChangeObservable.notifyObservers(mesh.material) } render() { const mesh = this.props.mesh; const scene = mesh.getScene(); const paintNormals = mesh.material != null && mesh.material.getClassName() === "NormalMaterial"; return (
mesh.isEnabled()} onSelect={(value) => mesh.setEnabled(value)} /> { mesh.material && this.onMaterialLink()} /> } { mesh.isVerticesDataPresent(BABYLON.VertexBuffer.ColorKind) && } { scene.fogMode !== BABYLON.Scene.FOGMODE_NONE && } { !mesh.parent && } { mesh.useBones && } paintNormals} onSelect={() => this.paintNormals()} />
); } }