David Catuhe 5 years ago
parent
commit
fe9c572275

+ 3 - 3
inspector/src/components/actionTabs/lines/textInputLineComponent.tsx

@@ -19,7 +19,7 @@ export class TextInputLineComponent extends React.Component<ITextInputLineCompon
     constructor(props: ITextInputLineComponentProps) {
         super(props);
 
-        this.state = { value: this.props.value || this.props.target[this.props.propertyName!] || "" }
+        this.state = { value: (this.props.value !== undefined ? this.props.value : this.props.target[this.props.propertyName!]) || "" }
     }
 
     componentWillUnmount() {
@@ -32,7 +32,7 @@ export class TextInputLineComponent extends React.Component<ITextInputLineCompon
             return true;
         }
 
-        const newValue = nextProps.value || nextProps.target[nextProps.propertyName!];
+        const newValue = nextProps.value  !== undefined  ? nextProps.value : nextProps.target[nextProps.propertyName!];
         if (newValue !== nextState.value) {
             nextState.value = newValue || "";
             return true;
@@ -61,7 +61,7 @@ export class TextInputLineComponent extends React.Component<ITextInputLineCompon
     updateValue(value: string) {
 
         this._localChange = true;
-        const store = this.props.value || this.props.target[this.props.propertyName!];
+        const store = this.props.value !== undefined ? this.props.value : this.props.target[this.props.propertyName!];
         this.setState({ value: value });
 
         this.raiseOnPropertyChanged(value, store);

+ 18 - 4
inspector/src/components/actionTabs/tabs/propertyGrids/materials/texturePropertyGridComponent.tsx

@@ -24,6 +24,7 @@ import { AdvancedDynamicTextureInstrumentation } from "babylonjs-gui/2D/adtInstr
 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,
@@ -73,12 +74,17 @@ export class TexturePropertyGridComponent extends React.Component<ITextureProper
                     extension = ".env";
                 }
 
-                (texture as CubeTexture).updateURL(url, extension, () => this.forceUpdate());
+                (texture as CubeTexture).updateURL(url, extension, () => this.foreceRefresh());
             } else {
-                (texture as Texture).updateURL(url, null, () => this.forceUpdate());
+                (texture as Texture).updateURL(url, null, () => this.foreceRefresh());
             }
 
         }, undefined, true);
+    }    
+
+    foreceRefresh() {
+        this.forceUpdate();
+        (this.refs["textureLine"] as TextureLineComponent).updatePreview();
     }
 
     render() {
@@ -113,13 +119,21 @@ export class TexturePropertyGridComponent extends React.Component<ITextureProper
                 }
                 extension = url[index] + extension;
             }
+        } else {
+            url = "";
         }
 
+        let textureUrl = (url.substring(0, 4) === "data" || url.substring(0, 4) === "blob") ? "" : url;
+
         return (
             <div className="pane">
                 <LineContainerComponent globalState={this.props.globalState} title="PREVIEW">
-                    <TextureLineComponent texture={texture} width={256} height={256} globalState={this.props.globalState} />
-                    <FileButtonLineComponent label="Replace texture" onClick={(file) => this.updateTexture(file)} accept=".jpg, .png, .tga, .dds, .env" />
+                    <TextureLineComponent ref="textureLine" texture={texture} width={256} height={256} globalState={this.props.globalState} />
+                    <FileButtonLineComponent label="Load texture from file" onClick={(file) => this.updateTexture(file)} accept=".jpg, .png, .tga, .dds, .env" />
+                    <TextInputLineComponent label="URL" value={textureUrl} lockObject={this.props.lockObject} onChange={url => {
+                        (texture as Texture).updateURL(url);
+                        this.foreceRefresh();
+                    }} />
                 </LineContainerComponent>
                 <CustomPropertyGridComponent globalState={this.props.globalState} target={texture}
                     lockObject={this.props.lockObject}

+ 0 - 1
src/Materials/Textures/cubeTexture.ts

@@ -250,7 +250,6 @@ export class CubeTexture extends BaseTexture {
             this.getScene()!.markAllMaterialsAsDirty(Constants.MATERIAL_TextureDirtyFlag);
         }
 
-        this.name = url;
         this.url = url;
         this.delayLoadState = Constants.DELAYLOADSTATE_NOTLOADED;
         this._prefiltered = false;

+ 0 - 1
src/Materials/Textures/texture.ts

@@ -376,7 +376,6 @@ export class Texture extends BaseTexture {
             this.getScene()!.markAllMaterialsAsDirty(Constants.MATERIAL_TextureDirtyFlag);
         }
 
-        this.name = url;
         this.url = url;
         this._buffer = buffer;
         this.delayLoadState = Constants.DELAYLOADSTATE_NOTLOADED;