From 0f20bffd37dd45994bf6ae56189be1f93a9fe3fe Mon Sep 17 00:00:00 2001 From: Claus Nagel Date: Sat, 14 Sep 2024 11:35:44 +0200 Subject: [PATCH] fixed import of texture images shared by implicit and normal geometries --- .../adapter/appearance/TextureAdapter.java | 44 +++++++------------ .../io/citygml/reader/ModelBuilderHelper.java | 7 ++- 2 files changed, 21 insertions(+), 30 deletions(-) diff --git a/citydb-io-citygml/src/main/java/org/citydb/io/citygml/adapter/appearance/TextureAdapter.java b/citydb-io-citygml/src/main/java/org/citydb/io/citygml/adapter/appearance/TextureAdapter.java index 292eef4a..54c6f5af 100644 --- a/citydb-io-citygml/src/main/java/org/citydb/io/citygml/adapter/appearance/TextureAdapter.java +++ b/citydb-io-citygml/src/main/java/org/citydb/io/citygml/adapter/appearance/TextureAdapter.java @@ -31,6 +31,7 @@ import org.citydb.model.common.Reference; import org.citygml4j.core.model.appearance.AbstractTexture; import org.citygml4j.core.model.appearance.ColorPlusOpacity; +import org.citygml4j.core.model.core.ImplicitGeometry; import java.io.IOException; @@ -41,37 +42,21 @@ public void build(R source, T target, ModelBuilderHelper helper) throws ModelBui super.build(source, target, helper); if (source.getTextureType() != null) { - switch (source.getTextureType()) { - case SPECIFIC: - target.setTextureType(TextureType.SPECIFIC); - break; - case TYPICAL: - target.setTextureType(TextureType.TYPICAL); - break; - case UNKNOWN: - target.setTextureType(TextureType.UNKNOWN); - break; - } + target.setTextureType(switch (source.getTextureType()) { + case SPECIFIC -> TextureType.SPECIFIC; + case TYPICAL -> TextureType.TYPICAL; + case UNKNOWN -> TextureType.UNKNOWN; + }); } if (source.getWrapMode() != null) { - switch (source.getWrapMode()) { - case NONE: - target.setWrapMode(WrapMode.NONE); - break; - case WRAP: - target.setWrapMode(WrapMode.WRAP); - break; - case CLAMP: - target.setWrapMode(WrapMode.CLAMP); - break; - case BORDER: - target.setWrapMode(WrapMode.BORDER); - break; - case MIRROR: - target.setWrapMode(WrapMode.MIRROR); - break; - } + target.setWrapMode(switch (source.getWrapMode()) { + case NONE -> WrapMode.NONE; + case WRAP -> WrapMode.WRAP; + case CLAMP -> WrapMode.CLAMP; + case BORDER -> WrapMode.BORDER; + case MIRROR -> WrapMode.MIRROR; + }); } if (source.getBorderColor() != null) { @@ -84,7 +69,8 @@ public void build(R source, T target, ModelBuilderHelper helper) throws ModelBui if (source.getImageURI() != null) { try { ExternalFile textureImage = helper.getExternalFile(source.getImageURI()); - if (helper.lookupAndPut(textureImage)) { + String token = source.getParent(ImplicitGeometry.class) != null ? "[template]" : null; + if (helper.lookupAndPut(textureImage, token)) { target.setTextureImageProperty(TextureImageProperty.of(Reference.of( textureImage.getOrCreateObjectId()))); } else { diff --git a/citydb-io-citygml/src/main/java/org/citydb/io/citygml/reader/ModelBuilderHelper.java b/citydb-io-citygml/src/main/java/org/citydb/io/citygml/reader/ModelBuilderHelper.java index f4f663d3..c1bfe351 100644 --- a/citydb-io-citygml/src/main/java/org/citydb/io/citygml/reader/ModelBuilderHelper.java +++ b/citydb-io-citygml/src/main/java/org/citydb/io/citygml/reader/ModelBuilderHelper.java @@ -182,8 +182,13 @@ public ExternalFile getExternalFile(String location) throws IOException { } public boolean lookupAndPut(ExternalFile file) { + return lookupAndPut(file, null); + } + + public boolean lookupAndPut(ExternalFile file, String token) { String id = file != null ? file.getObjectId().orElse(null) : null; - return id != null && getOrCreatePersistentMap("external-files").putIfAbsent(id, Boolean.TRUE) != null; + return id != null && getOrCreatePersistentMap("external-files") + .putIfAbsent(token == null ? id : token + id, Boolean.TRUE) != null; } @SuppressWarnings("unchecked")