浏览代码

Merge branch 'master' into add-setColor4Array-to-shaderMaterial

David Catuhe 6 年之前
父节点
当前提交
440e5ff2db
共有 2 个文件被更改,包括 31 次插入0 次删除
  1. 1 0
      dist/preview release/what's new.md
  2. 30 0
      src/Materials/shaderMaterial.ts

+ 1 - 0
dist/preview release/what's new.md

@@ -55,6 +55,7 @@
 
 ### Materials
 - Added `ShaderMaterial.setColor4Array` ([JonathanTron](https://github.com/JonathanTron/))
+- Added `ShaderMaterial.setArray4` ([JonathanTron](https://github.com/JonathanTron/))
 
 ## Bug fixes
 - Added support for `AnimationGroup` serialization ([Drigax](https://github.com/drigax/))

+ 30 - 0
src/Materials/shaderMaterial.ts

@@ -79,6 +79,7 @@ export class ShaderMaterial extends Material {
     private _matrices2x2: { [name: string]: Float32Array } = {};
     private _vectors2Arrays: { [name: string]: number[] } = {};
     private _vectors3Arrays: { [name: string]: number[] } = {};
+    private _vectors4Arrays: { [name: string]: number[] } = {};
     private _cachedWorldViewMatrix = new Matrix();
     private _cachedWorldViewProjectionMatrix = new Matrix();
     private _renderId: number;
@@ -383,6 +384,19 @@ export class ShaderMaterial extends Material {
         return this;
     }
 
+    /**
+     * Set a vec4 array in the shader from a number array.
+     * @param name Define the name of the uniform as defined in the shader
+     * @param value Define the value to give to the uniform
+     * @return the material itself allowing "fluent" like uniform updates
+     */
+    public setArray4(name: string, value: number[]): ShaderMaterial {
+        this._checkUniform(name);
+        this._vectors4Arrays[name] = value;
+
+        return this;
+    }
+
     private _checkCache(mesh?: AbstractMesh, useInstances?: boolean): boolean {
         if (!mesh) {
             return true;
@@ -660,6 +674,11 @@ export class ShaderMaterial extends Material {
             for (name in this._vectors3Arrays) {
                 this._effect.setArray3(name, this._vectors3Arrays[name]);
             }
+
+            // Vector4Array
+            for (name in this._vectors4Arrays) {
+                this._effect.setArray4(name, this._vectors4Arrays[name]);
+            }
         }
 
         this._afterBind(mesh);
@@ -865,6 +884,12 @@ export class ShaderMaterial extends Material {
             serializationObject.vectors3Arrays[name] = this._vectors3Arrays[name];
         }
 
+        // Vector4Array
+        serializationObject.vectors4Arrays = {};
+        for (name in this._vectors4Arrays) {
+            serializationObject.vectors4Arrays[name] = this._vectors4Arrays[name];
+        }
+
         return serializationObject;
     }
 
@@ -982,6 +1007,11 @@ export class ShaderMaterial extends Material {
             material.setArray3(name, source.vectors3Arrays[name]);
         }
 
+        // Vector4Array
+        for (name in source.vectors4Arrays) {
+            material.setArray4(name, source.vectors4Arrays[name]);
+        }
+
         return material;
     }
 }