Bläddra i källkod

Fix that upsetting texture offset issue

David Catuhe 6 år sedan
förälder
incheckning
4bce2c5ea1

+ 3 - 2
src/Materials/Node/Blocks/Fragment/textureBlock.ts

@@ -73,7 +73,7 @@ export class TextureBlock extends NodeMaterialBlock {
         if (!defines._areTexturesDirty) {
             return;
         }
-        
+
         defines.setValue(this._mainUVDefineName, false);
     }
 
@@ -81,7 +81,7 @@ export class TextureBlock extends NodeMaterialBlock {
         if (!defines._areTexturesDirty) {
             return;
         }
-    
+
         if (!this.texture || !this.texture.getTextureMatrix) {
             return;
         }
@@ -147,6 +147,7 @@ export class TextureBlock extends NodeMaterialBlock {
         }
 
         state.sharedData.blockingBlocks.push(this);
+        state.sharedData.textureBlocks.push(this);
 
         this._samplerName = state._getFreeVariableName(this.name + "Sampler");
         state.samplers.push(this._samplerName);

+ 4 - 7
src/Materials/Node/nodeMaterial.ts

@@ -101,7 +101,6 @@ export class NodeMaterial extends PushMaterial {
     private _buildWasSuccessful = false;
     private _cachedWorldViewMatrix = new Matrix();
     private _cachedWorldViewProjectionMatrix = new Matrix();
-    private _textures: BaseTexture[];
     private _optimizers = new Array<NodeMaterialOptimizer>();
 
     /** Define the URl to load node editor script */
@@ -469,7 +468,6 @@ export class NodeMaterial extends PushMaterial {
         this._vertexCompilationState.finalize(this._vertexCompilationState);
         this._fragmentCompilationState.finalize(this._fragmentCompilationState);
 
-        this._textures = this._sharedData.textureBlocks.filter((tb) => tb.texture).map((tb) => tb.texture);
         this._buildId++;
 
         // Errors
@@ -726,7 +724,7 @@ export class NodeMaterial extends PushMaterial {
     public getActiveTextures(): BaseTexture[] {
         var activeTextures = super.getActiveTextures();
 
-        activeTextures.push(...this._textures);
+        activeTextures.push(...this._sharedData.textureBlocks.filter((tb) => tb.texture).map((tb) => tb.texture));
 
         return activeTextures;
     }
@@ -741,8 +739,8 @@ export class NodeMaterial extends PushMaterial {
             return true;
         }
 
-        for (var t of this._textures) {
-            if (t === texture) {
+        for (var t of this._sharedData.textureBlocks) {
+            if (t.texture === texture) {
                 return true;
             }
         }
@@ -759,12 +757,11 @@ export class NodeMaterial extends PushMaterial {
     public dispose(forceDisposeEffect?: boolean, forceDisposeTextures?: boolean, notBoundToMesh?: boolean): void {
 
         if (forceDisposeTextures) {
-            for (var texture of this._textures) {
+            for (var texture of this._sharedData.textureBlocks.filter((tb) => tb.texture).map((tb) => tb.texture)) {
                 texture.dispose();
             }
         }
 
-        this._textures = [];
         this.onBuildObservable.clear();
 
         super.dispose(forceDisposeEffect, forceDisposeTextures, notBoundToMesh);