import * as React from "react"; import { Nullable } from "babylonjs/types"; import { Tools } from "babylonjs/Misc/tools"; import { Observable } from "babylonjs/Misc/observable"; import { BaseTexture } from "babylonjs/Materials/Textures/baseTexture"; import { Texture } from "babylonjs/Materials/Textures/texture"; import { CubeTexture } from "babylonjs/Materials/Textures/cubeTexture"; 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 } from "babylonjs-gui/2D/adtInstrumentation"; import { AdvancedDynamicTexture } from "babylonjs-gui/2D/advancedDynamicTexture"; import { CustomPropertyGridComponent } from '../customPropertyGridComponent'; import { ButtonLineComponent } from '../../../lines/buttonLineComponent'; import { TextInputLineComponent } from '../../../lines/textInputLineComponent'; interface ITexturePropertyGridComponentProps { texture: BaseTexture, lockObject: LockObject, globalState: GlobalState, onPropertyChangedObservable?: Observable } export class TexturePropertyGridComponent extends React.Component { private _adtInstrumentation: Nullable; constructor(props: ITexturePropertyGridComponentProps) { super(props); 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.foreceRefresh()); } else { (texture as Texture).updateURL(url, null, () => this.foreceRefresh()); } }, undefined, true); } foreceRefresh() { this.forceUpdate(); (this.refs["textureLine"] as TextureLineComponent).updatePreview(); } 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 }, ]; var coordinatesMode = [ { label: "Explicit", value: Texture.EXPLICIT_MODE }, { label: "Cubic", value: Texture.CUBIC_MODE }, { label: "Inverse cubic", value: Texture.INVCUBIC_MODE }, { label: "Equirectangular", value: Texture.EQUIRECTANGULAR_MODE }, { label: "Fixed equirectangular", value: Texture.FIXED_EQUIRECTANGULAR_MODE }, { label: "Fixed equirectangular mirrored", value: Texture.FIXED_EQUIRECTANGULAR_MIRRORED_MODE }, { label: "Planar", value: Texture.PLANAR_MODE }, { label: "Projection", value: Texture.PROJECTION_MODE }, { label: "Skybox", value: Texture.SKYBOX_MODE }, { label: "Spherical", value: Texture.SPHERICAL_MODE }, ]; let extension = ""; let url = (texture as Texture).url; if (url) { for (var index = url.length - 1; index >= 0; index--) { if (url[index] === ".") { break; } extension = url[index] + extension; } } else { url = ""; } let textureUrl = (url.substring(0, 4) === "data" || url.substring(0, 4) === "blob") ? "" : url; return (
this.updateTexture(file)} accept=".jpg, .png, .tga, .dds, .env" /> { (texture as Texture).updateURL(url); this.foreceRefresh(); }} /> { texture.isRenderTarget && { let scene = texture.getScene()!; texture.scale(2); setTimeout(() => { this.props.globalState.onSelectionChangedObservable.notifyObservers(scene.getTextureByUniqueID(texture.uniqueId)); }); }} /> } { texture.isRenderTarget && { let scene = texture.getScene()!; texture.scale(0.5); setTimeout(() => { this.props.globalState.onSelectionChangedObservable.notifyObservers(scene.getTextureByUniqueID(texture.uniqueId)); }); }} /> } { extension && } { (texture instanceof Texture) && } texture.updateSamplingMode(value)} /> { 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 &&
}
); } }