import * as React from "react"; import { Texture, BaseTexture, CubeTexture, Observable, Nullable, Tools } from "babylonjs"; import { PropertyChangedEvent } from "../../../../propertyChangedEvent"; import { LineContainerComponent } from "../../../lineContainerComponent"; import { SliderLineComponent } from "../../../lines/sliderLineComponent"; import { TextLineComponent } from "../../../lines/textLineComponent"; import { CheckBoxLineComponent } from "../../../lines/checkBoxLineComponent"; import { TextureLineComponent } from "../../../lines/textureLineComponent"; import { FloatLineComponent } from "../../../lines/floatLineComponent"; import { OptionsLineComponent } from "../../../lines/optionsLineComponent"; import { FileButtonLineComponent } from "../../../lines/fileButtonLineComponent"; import { LockObject } from "../lockObject"; import { ValueLineComponent } from "../../../lines/valueLineComponent"; import { GlobalState } from "components/globalState"; import { AdvancedDynamicTextureInstrumentation, AdvancedDynamicTexture } from "babylonjs-gui"; interface ITexturePropertyGridComponentProps { texture: BaseTexture, lockObject: LockObject, globalState: GlobalState, onPropertyChangedObservable?: Observable } export class TexturePropertyGridComponent extends React.Component { private _adtInstrumentation: Nullable; constructor(props: ITexturePropertyGridComponentProps) { super(props); } componentWillMount() { const texture = this.props.texture; if (!texture || !(texture as any).rootContainer) { return; } const adt = texture as AdvancedDynamicTexture; this._adtInstrumentation = new AdvancedDynamicTextureInstrumentation(adt); this._adtInstrumentation!.captureRenderTime = true; this._adtInstrumentation!.captureLayoutTime = true; } componentWillUnmount() { if (this._adtInstrumentation) { this._adtInstrumentation.dispose(); this._adtInstrumentation = null; } } updateTexture(file: File) { const texture = this.props.texture; Tools.ReadFile(file, (data) => { var blob = new Blob([data], { type: "octet/stream" }); var url = URL.createObjectURL(blob); if (texture.isCube) { let extension: string | undefined = undefined; if (file.name.toLowerCase().indexOf(".dds") > 0) { extension = ".dds"; } else if (file.name.toLowerCase().indexOf(".env") > 0) { extension = ".env"; } (texture as CubeTexture).updateURL(url, extension, () => this.forceUpdate()); } else { (texture as Texture).updateURL(url, null, () => this.forceUpdate()); } }, undefined, true); } render() { const texture = this.props.texture; var samplingMode = [ { label: "Nearest", value: Texture.NEAREST_NEAREST }, { label: "Nearest & linear mip", value: Texture.NEAREST_LINEAR }, { label: "Linear", value: Texture.LINEAR_LINEAR_MIPLINEAR }, ]; return (
this.updateTexture(file)} accept=".jpg, .png, .tga, .dds, .env" /> { texture.updateSamplingMode && texture.updateSamplingMode(value)} /> } { (texture as any).rootContainer && } { !texture.isCube &&
texture.wrapU === Texture.CLAMP_ADDRESSMODE} onSelect={(value) => texture.wrapU = value ? Texture.CLAMP_ADDRESSMODE : Texture.WRAP_ADDRESSMODE} /> texture.wrapV === Texture.CLAMP_ADDRESSMODE} onSelect={(value) => texture.wrapV = value ? Texture.CLAMP_ADDRESSMODE : Texture.WRAP_ADDRESSMODE} />
} { texture.isCube &&
}
); } }