createMaterialPropertyDescriptor.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  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 (
  12. typeof value === "string" ||
  13. value instanceof Resource ||
  14. value instanceof HTMLCanvasElement ||
  15. value instanceof HTMLVideoElement
  16. ) {
  17. const result = new ImageMaterialProperty();
  18. result.image = value;
  19. return result;
  20. }
  21. //>>includeStart('debug', pragmas.debug);
  22. throw new DeveloperError(`Unable to infer material type: ${value}`);
  23. //>>includeEnd('debug');
  24. }
  25. /**
  26. * @private
  27. */
  28. function createMaterialPropertyDescriptor(name, configurable) {
  29. return createPropertyDescriptor(name, configurable, createMaterialProperty);
  30. }
  31. export default createMaterialPropertyDescriptor;