diff --git a/@here/harp-datasource-protocol/lib/TechniqueDescriptors.ts b/@here/harp-datasource-protocol/lib/TechniqueDescriptors.ts index 0bc6b225bd..b5ff8d5d10 100644 --- a/@here/harp-datasource-protocol/lib/TechniqueDescriptors.ts +++ b/@here/harp-datasource-protocol/lib/TechniqueDescriptors.ts @@ -235,7 +235,8 @@ const fillTechniqueDescriptor = mergeTechniqueDescriptor( color: { scope: AttrScope.TechniqueRendering, automatic: true }, opacity: { scope: AttrScope.TechniqueRendering, automatic: true }, transparent: { scope: AttrScope.TechniqueRendering, automatic: true }, - lineWidth: AttrScope.TechniqueRendering + lineWidth: AttrScope.TechniqueRendering, + map: { scope: AttrScope.TechniqueRendering, automatic: true } } } ); diff --git a/@here/harp-datasource-protocol/lib/TechniqueParams.ts b/@here/harp-datasource-protocol/lib/TechniqueParams.ts index a5039cb172..b692dc3952 100644 --- a/@here/harp-datasource-protocol/lib/TechniqueParams.ts +++ b/@here/harp-datasource-protocol/lib/TechniqueParams.ts @@ -1199,6 +1199,20 @@ export interface FillTechniqueParams extends BaseTechniqueParams, PolygonalTechn * Width of the lines. Currently limited to the [0, 1] range. */ lineWidth?: DynamicProperty; + + /* + * URL or texture buffer that should be used as color map. See: + * https://threejs.org/docs/#api/en/materials/MeshBasicMaterial.map + */ + map?: DynamicProperty; + mapProperties?: DynamicProperty; + + /** + * Whether and how texture coordinates should be generated. No texture coordinates are + * generated if `undefined`. + * Should be set if a `map` is assigned. + */ + textureCoordinateType?: TextureCoordinateType; } /** diff --git a/@here/harp-datasource-protocol/lib/Techniques.ts b/@here/harp-datasource-protocol/lib/Techniques.ts index 7b35d69799..af7eda52d1 100644 --- a/@here/harp-datasource-protocol/lib/Techniques.ts +++ b/@here/harp-datasource-protocol/lib/Techniques.ts @@ -429,21 +429,27 @@ export function needsVertexNormals(technique: Technique): boolean { ); } +/** + * Type guard to check if an object is an instance of a technique with textures. + */ +export function supportsTextures( + technique: Technique +): technique is FillTechnique | StandardTechnique | ExtrudedPolygonTechnique | TerrainTechnique { + return ( + isFillTechnique(technique) || + isStandardTechnique(technique) || + isExtrudedPolygonTechnique(technique) || + isTerrainTechnique(technique) + ); +} + /** * Get the texture coordinate type if the technique supports it. */ export function textureCoordinateType(technique: Technique): TextureCoordinateType | undefined { - if (isStandardTechnique(technique)) { - return technique.textureCoordinateType; - } else if (isExtrudedPolygonTechnique(technique)) { - return technique.textureCoordinateType; - } else if (isTerrainTechnique(technique)) { - return technique.textureCoordinateType; - } else if (isShaderTechnique(technique)) { - return technique.textureCoordinateType; - } else { - return undefined; - } + return supportsTextures(technique) || isShaderTechnique(technique) + ? technique.textureCoordinateType + : undefined; } /** diff --git a/@here/harp-mapview/lib/DecodedTileHelpers.ts b/@here/harp-mapview/lib/DecodedTileHelpers.ts index cf8ec730fd..bcb7bf102e 100644 --- a/@here/harp-mapview/lib/DecodedTileHelpers.ts +++ b/@here/harp-mapview/lib/DecodedTileHelpers.ts @@ -13,11 +13,10 @@ import { isExtrudedLineTechnique, isExtrudedPolygonTechnique, isShaderTechnique, - isStandardTechnique, - isTerrainTechnique, isTextureBuffer, parseStringEncodedColor, ShaderTechnique, + supportsTextures, Technique, TEXTURE_PROPERTY_KEYS, TextureBuffer, @@ -260,11 +259,7 @@ export function createMaterial( material.depthTest = isExtrudedPolygonTechnique(technique) && technique.depthTest !== false; - if ( - isStandardTechnique(technique) || - isTerrainTechnique(technique) || - isExtrudedPolygonTechnique(technique) - ) { + if (supportsTextures(technique)) { TEXTURE_PROPERTY_KEYS.forEach((texturePropertyName: string) => createTexture(material, texturePropertyName, options, textureReadyCallback) ); diff --git a/@here/harp-mapview/lib/MapMaterialAdapter.ts b/@here/harp-mapview/lib/MapMaterialAdapter.ts index 158bacfdc4..8e2e55f1d7 100644 --- a/@here/harp-mapview/lib/MapMaterialAdapter.ts +++ b/@here/harp-mapview/lib/MapMaterialAdapter.ts @@ -4,7 +4,13 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { ColorUtils, Expr, getPropertyValue, Value } from "@here/harp-datasource-protocol"; +import { + ColorUtils, + Expr, + getPropertyValue, + TEXTURE_PROPERTY_KEYS, + Value +} from "@here/harp-datasource-protocol"; import { disableBlending, enableBlending, RawShaderMaterial } from "@here/harp-materials"; import * as THREE from "three"; @@ -36,7 +42,7 @@ export interface StyledProperties { } function isTextureProperty(propertyName: string): boolean { - return propertyName === "map" || propertyName.endsWith("Map"); + return TEXTURE_PROPERTY_KEYS.includes(propertyName); } /**