UniformsUtils.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /**
  2. * Uniform Utilities
  3. */
  4. var UniformsUtils = {
  5. merge: function ( uniforms ) {
  6. var merged = {};
  7. for ( var u = 0; u < uniforms.length; u ++ ) {
  8. var tmp = this.clone( uniforms[ u ] );
  9. for ( var p in tmp ) {
  10. merged[ p ] = tmp[ p ];
  11. }
  12. }
  13. return merged;
  14. },
  15. clone: function ( uniforms_src ) {
  16. var uniforms_dst = {};
  17. for ( var u in uniforms_src ) {
  18. uniforms_dst[ u ] = {};
  19. for ( var p in uniforms_src[ u ] ) {
  20. var parameter_src = uniforms_src[ u ][ p ];
  21. if ( parameter_src && ( parameter_src.isColor ||
  22. parameter_src.isMatrix3 || parameter_src.isMatrix4 ||
  23. parameter_src.isVector2 || parameter_src.isVector3 || parameter_src.isVector4 ||
  24. parameter_src.isTexture ) ) {
  25. uniforms_dst[ u ][ p ] = parameter_src.clone();
  26. } else if ( Array.isArray( parameter_src ) ) {
  27. uniforms_dst[ u ][ p ] = parameter_src.slice();
  28. } else {
  29. uniforms_dst[ u ][ p ] = parameter_src;
  30. }
  31. }
  32. }
  33. return uniforms_dst;
  34. }
  35. };
  36. export { UniformsUtils };