diff --git a/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/mesh/texturemodel/Material.kt b/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/mesh/texturemodel/Material.kt index c520c538..1edd95da 100644 --- a/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/mesh/texturemodel/Material.kt +++ b/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/mesh/texturemodel/Material.kt @@ -44,6 +44,26 @@ class Material : JavaSerializable { val EMPTY = Material() } + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (other !is Material) return false + + return materialMeshes == other.materialMeshes && + materialTexture == other.materialTexture && + materialDiffuseColor == other.materialDiffuseColor + } + + override fun hashCode(): Int { + var result = materialMeshes.hashCode() + result = 31 * result + (materialTexture?.hashCode() ?: 0) + result = 31 * result + materialDiffuseColor.hashCode() + return result + } + + override fun toString(): String { + return "Material(materialMeshes=$materialMeshes, materialTexture=$materialTexture, materialDiffuseColor=$materialDiffuseColor)" + } + /** * @return A MinimalBoundingBox which encloses all MinimalBoundingBoxes from containing meshes. */ diff --git a/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/mesh/texturemodel/Mesh.kt b/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/mesh/texturemodel/Mesh.kt index 4c5b2b0c..7b519ea8 100644 --- a/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/mesh/texturemodel/Mesh.kt +++ b/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/mesh/texturemodel/Mesh.kt @@ -51,6 +51,26 @@ class Mesh( private val LOGGER: Logger = LogManager.getLogger() } + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (other !is Mesh) return false + + if (!positions.contentEquals(other.positions)) return false + if (!normals.contentEquals(other.normals)) return false + if (!textureCoords.contentEquals(other.textureCoords)) return false + if (!idx.contentEquals(other.idx)) return false + + return true + } + + override fun hashCode(): Int { + var result = positions.contentHashCode() + result = 31 * result + (normals?.contentHashCode() ?: 0) + result = 31 * result + textureCoords.contentHashCode() + result = 31 * result + idx.contentHashCode() + return result + } + /** * Number of all vertices in the mesh. */ diff --git a/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/mesh/texturemodel/Texture.kt b/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/mesh/texturemodel/Texture.kt index c257c9dc..c4f3516a 100644 --- a/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/mesh/texturemodel/Texture.kt +++ b/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/mesh/texturemodel/Texture.kt @@ -35,6 +35,40 @@ data class Texture( } } + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (other !is Texture) return false + + if (texturePath != other.texturePath) return false + if (!compareBufferedImages(textureImage, other.textureImage)) return false + + return true + } + + override fun hashCode(): Int { + var result = texturePath?.hashCode() ?: 0 + result = 31 * result + (textureImage?.let { it.hashCode() } ?: 0) + return result + } + + /** + * Compares two BufferedImages pixel by pixel. + */ + private fun compareBufferedImages(img1: BufferedImage?, img2: BufferedImage?): Boolean { + if (img1 == null || img2 == null) return img1 == img2 + if (img1.width != img2.width || img1.height != img2.height) return false + + for (y in 0 until img1.height) { + for (x in 0 until img1.width) { + if (img1.getRGB(x, y) != img2.getRGB(x, y)) { + return false + } + } + } + + return true + } + constructor(texturePath: String) : this(texturePath, null) constructor(textureImage: BufferedImage) : this(null, textureImage)