All files / engine/Source/DataSources createMaterialPropertyDescriptor.js

100% Statements 8/8
100% Branches 8/8
100% Functions 2/2
100% Lines 8/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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