createMaterialPropertyDescriptor.js 1.1 KB

123456789101112131415161718192021222324252627282930
  1. import Color from '../Core/Color.js';
  2. import DeveloperError from '../Core/DeveloperError.js';
  3. import Resource from '../Core/Resource.js';
  4. import ColorMaterialProperty from './ColorMaterialProperty.js';
  5. import createPropertyDescriptor from './createPropertyDescriptor.js';
  6. import ImageMaterialProperty from './ImageMaterialProperty.js';
  7. function createMaterialProperty(value) {
  8. if (value instanceof Color) {
  9. return new ColorMaterialProperty(value);
  10. }
  11. if (typeof value === 'string' || value instanceof Resource || value instanceof HTMLCanvasElement || value instanceof HTMLVideoElement) {
  12. var result = new ImageMaterialProperty();
  13. result.image = value;
  14. return result;
  15. }
  16. //>>includeStart('debug', pragmas.debug);
  17. throw new DeveloperError('Unable to infer material type: ' + value);
  18. //>>includeEnd('debug');
  19. }
  20. /**
  21. * @private
  22. */
  23. function createMaterialPropertyDescriptor(name, configurable) {
  24. return createPropertyDescriptor(name, configurable, createMaterialProperty);
  25. }
  26. export default createMaterialPropertyDescriptor;