فهرست منبع

improve texture suport for nme #6012

David Catuhe 5 سال پیش
والد
کامیت
347da2113d

+ 7 - 2
inspector/src/components/actionTabs/lines/textureLinkLineComponent.tsx

@@ -20,6 +20,7 @@ export interface ITextureLinkLineComponentProps {
     onSelectionChangedObservable?: Observable<any>;
     onDebugSelectionChangeObservable?: Observable<BaseTexture>;
     propertyName?: string;
+    onTextureCreated?: (texture: BaseTexture) => void;
     customDebugAction?: (state: boolean) => void
 }
 
@@ -142,7 +143,11 @@ export class TextureLinkLineComponent extends React.Component<ITextureLinkLineCo
 
             let texture = new Texture(url, material.getScene(), false, false);
 
-            (material as any)[this.props.propertyName!] = texture;
+            if (this.props.propertyName) {
+                (material as any)[this.props.propertyName!] = texture;
+            } else if (this.props.onTextureCreated) {
+                this.props.onTextureCreated(texture);
+            }
 
             this.forceUpdate();
 
@@ -153,7 +158,7 @@ export class TextureLinkLineComponent extends React.Component<ITextureLinkLineCo
         const texture = this.props.texture;
 
         if (!texture) {
-            if (this.props.propertyName) {
+            if (this.props.propertyName || this.props.onTextureCreated) {
                 return (
                     <FileButtonLineComponent label={`Add ${this.props.label} texture`} onClick={(file) => this.updateTexture(file)} accept=".jpg, .png, .tga, .dds, .env" />
                 )

+ 7 - 1
inspector/src/components/actionTabs/tabs/propertyGrids/materials/nodeMaterialPropertyGridComponent.tsx

@@ -55,7 +55,13 @@ export class NodeMaterialPropertyGridComponent extends React.Component<INodeMate
                 {
                     textureBlocks.map((textureBlock, i) => {
                         return (
-                            <TextureLinkLineComponent label={textureBlock.name} key={textureBlock.texture!.uniqueId + i} texture={textureBlock.texture} material={material} onSelectionChangedObservable={this.props.onSelectionChangedObservable} onDebugSelectionChangeObservable={onDebugSelectionChangeObservable} />
+                            <TextureLinkLineComponent label={textureBlock.name} 
+                                key={i} 
+                                texture={textureBlock.texture} 
+                                material={material} 
+                                onTextureCreated={texture => textureBlock.texture = texture}
+                                onSelectionChangedObservable={this.props.onSelectionChangedObservable} 
+                                onDebugSelectionChangeObservable={onDebugSelectionChangeObservable} />
                         )
                     })
                 }

+ 19 - 3
nodeEditor/src/components/diagram/texture/texturePropertyTabComponent.tsx

@@ -29,14 +29,14 @@ export class TexturePropertyTabComponent extends React.Component<ITexturePropert
 
         let texture = this.props.node.texture as BaseTexture;
 
-        this.state = {isEmbedded: !texture || texture.name.substring(0, 4) !== "http", loadAsCubeTexture: texture && texture.isCube};
+        this.state = {isEmbedded: !texture || texture.name.substring(0, 4) === "data", loadAsCubeTexture: texture && texture.isCube};
     }
 
     UNSAFE_componentWillUpdate(nextProps: ITexturePropertyTabComponentProps, nextState: {isEmbedded: boolean, loadAsCubeTexture: boolean}) {
         if (nextProps.node !== this.props.node) {
             let texture = nextProps.node.texture as BaseTexture;
 
-            nextState.isEmbedded = !texture || texture.name.substring(0, 4) !== "http";
+            nextState.isEmbedded = !texture || texture.name.substring(0, 4) === "data";
             nextState.loadAsCubeTexture = texture && texture.isCube;
         }
     }
@@ -55,6 +55,18 @@ export class TexturePropertyTabComponent extends React.Component<ITexturePropert
         this.forceUpdate();
     }
 
+    removeTexture() {
+        let texture = this.props.node.texture as BaseTexture;
+
+        if (texture) {
+            texture.dispose();
+            (texture as any) = null;
+            this.props.node.texture = null;
+        }
+
+        this.updateAfterTextureLoad();
+    }
+
 	/**
 	 * Replaces the texture of the node
 	 * @param file the file of the texture to use
@@ -263,7 +275,7 @@ export class TexturePropertyTabComponent extends React.Component<ITexturePropert
                     }
                 </LineContainerComponent>
                 <LineContainerComponent title="SOURCE">
-                    <CheckBoxLineComponent label="Embed texture" isSelected={() => this.state.isEmbedded} onSelect={value => {
+                    <CheckBoxLineComponent label="Embed static texture" isSelected={() => this.state.isEmbedded} onSelect={value => {
                         this.setState({isEmbedded: value});
                         this.props.node.texture = null;
                         this.updateAfterTextureLoad();
@@ -285,6 +297,10 @@ export class TexturePropertyTabComponent extends React.Component<ITexturePropert
                         !this.state.isEmbedded && url &&
                         <ButtonLineComponent label="Refresh" onClick={() => this.replaceTextureWithUrl(url + "?nocache=" + this._generateRandomForCache())}/>
                     }
+                    {
+                        texture &&
+                        <ButtonLineComponent label="Remove" onClick={() => this.removeTexture()}/>
+                    }
                 </LineContainerComponent>
             </div>
         );

+ 2 - 0
src/Materials/Node/Blocks/Dual/textureBlock.ts

@@ -175,6 +175,8 @@ export class TextureBlock extends NodeMaterialBlock {
         }
 
         if (!this.texture || !this.texture.getTextureMatrix) {
+            defines.setValue(this._defineName, false);
+            defines.setValue(this._mainUVDefineName, true);
             return;
         }
 

+ 1 - 1
src/Materials/Node/nodeMaterial.ts

@@ -888,7 +888,7 @@ export class NodeMaterial extends PushMaterial {
             return [];
         }
 
-        return this._sharedData.textureBlocks.filter((tb) => tb.texture);
+        return this._sharedData.textureBlocks;
     }
 
     /**