Skip to content

Commit

Permalink
fixed import of texture images shared by implicit and normal geometries
Browse files Browse the repository at this point in the history
  • Loading branch information
clausnagel committed Sep 14, 2024
1 parent 7e008be commit 0f20bff
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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) {
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 0f20bff

Please sign in to comment.