import * as React from "react"; import { GlobalState } from '../../globalState'; import { Nullable } from 'babylonjs/types'; import { ButtonLineComponent } from '../../sharedComponents/buttonLineComponent'; import { LineContainerComponent } from '../../sharedComponents/lineContainerComponent'; import { StringTools } from '../../stringTools'; import { FileButtonLineComponent } from '../../sharedComponents/fileButtonLineComponent'; import { Tools } from 'babylonjs/Misc/tools'; import { SerializationTools } from '../../serializationTools'; import { CheckBoxLineComponent } from '../../sharedComponents/checkBoxLineComponent'; import { DataStorage } from '../../dataStorage'; import { GraphNode } from '../../diagram/graphNode'; import { SliderLineComponent } from '../../sharedComponents/sliderLineComponent'; import { GraphFrame } from '../../diagram/graphFrame'; import { TextLineComponent } from '../../sharedComponents/textLineComponent'; import { Engine } from 'babylonjs/Engines/engine'; import { FramePropertyTabComponent } from '../../diagram/properties/framePropertyComponent'; require("./propertyTab.scss"); interface IPropertyTabComponentProps { globalState: GlobalState; } export class PropertyTabComponent extends React.Component, currentFrame: Nullable }> { constructor(props: IPropertyTabComponentProps) { super(props) this.state = { currentNode: null, currentFrame: null }; } componentDidMount() { this.props.globalState.onSelectionChangedObservable.add(selection => { if (selection instanceof GraphNode) { this.setState({ currentNode: selection, currentFrame: null }); } else if (selection instanceof GraphFrame) { this.setState({ currentNode: null, currentFrame: selection }); } else { this.setState({ currentNode: null, currentFrame: null }); } }); } load(file: File) { Tools.ReadFile(file, (data) => { let decoder = new TextDecoder("utf-8"); SerializationTools.Deserialize(JSON.parse(decoder.decode(data)), this.props.globalState); }, undefined, true); } save() { let json = SerializationTools.Serialize(this.props.globalState.nodeMaterial, this.props.globalState); StringTools.DownloadAsFile(this.props.globalState.hostDocument, json, "nodeMaterial.json"); } customSave() { this.props.globalState.onLogRequiredObservable.notifyObservers({message: "Saving your material to Babylon.js snippet server...", isError: false}); this.props.globalState.customSave!.action(SerializationTools.Serialize(this.props.globalState.nodeMaterial, this.props.globalState)).then(() => { this.props.globalState.onLogRequiredObservable.notifyObservers({message: "Material saved successfully", isError: false}); }).catch(err => { this.props.globalState.onLogRequiredObservable.notifyObservers({message: err, isError: true}); }); } render() { if (this.state.currentNode) { return (
{this.state.currentNode.renderProperties()}
); } if (this.state.currentFrame) { return ( ); } let gridSize = DataStorage.ReadNumber("GridSize", 20); return (
window.open('https://doc.babylonjs.com/how_to/node_material', '_blank')}/> { this.props.globalState.nodeMaterial!.setToDefault(); this.props.globalState.onResetRequiredObservable.notifyObservers(); }} /> { this.props.globalState.onZoomToFitRequiredObservable.notifyObservers(); }} /> { this.props.globalState.onReOrganizedRequiredObservable.notifyObservers(); }} /> DataStorage.ReadBoolean("EmbedTextures", true)} onSelect={(value: boolean) => { DataStorage.StoreBoolean("EmbedTextures", value); }} /> { DataStorage.StoreNumber("GridSize", value); this.props.globalState.onGridSizeChanged.notifyObservers(); this.forceUpdate(); }} /> DataStorage.ReadBoolean("ShowGrid", true)} onSelect={(value: boolean) => { DataStorage.StoreBoolean("ShowGrid", value); this.props.globalState.onGridSizeChanged.notifyObservers(); }} /> this.load(file)} accept=".json" /> { this.save(); }} /> { this.props.globalState.customSave && { this.customSave(); }} /> } { StringTools.DownloadAsFile(this.props.globalState.hostDocument, this.props.globalState.nodeMaterial!.generateCode(), "code.txt"); }} /> { StringTools.DownloadAsFile(this.props.globalState.hostDocument, this.props.globalState.nodeMaterial!.compiledShaders, "shaders.txt"); }} />
); } }