diff --git a/include/polyscope/surface_parameterization_quantity.h b/include/polyscope/surface_parameterization_quantity.h index 6d3f69a5..8e90c47d 100644 --- a/include/polyscope/surface_parameterization_quantity.h +++ b/include/polyscope/surface_parameterization_quantity.h @@ -25,12 +25,14 @@ class SurfaceParameterizationQuantity : public SurfaceMeshQuantity, public: SurfaceParameterizationQuantity(std::string name, SurfaceMesh& mesh_, const std::vector& coords_, - ParamCoordsType type_, ParamVizStyle style_); + MeshElement definedOn, ParamCoordsType type_, ParamVizStyle style_); virtual void draw() override; virtual void refresh() override; virtual void buildCustomUI() override; + const MeshElement definedOn; + // Set islands labels. Technically, this data is just any categorical integer labels per-face of the mesh. // The intended use is to label islands (connected components in parameterization space) of the UV map. // When style == CHECKER_ISLANDS, these will be use to visualize the islands with different colors. diff --git a/src/surface_color_quantity.cpp b/src/surface_color_quantity.cpp index 2b2a5207..ecd2518a 100644 --- a/src/surface_color_quantity.cpp +++ b/src/surface_color_quantity.cpp @@ -145,7 +145,20 @@ void SurfaceTextureColorQuantity::createProgram() { // clang-format on parent.setMeshGeometryAttributes(*program); - program->setAttribute("a_tCoord", param.coords.getIndexedRenderAttributeBuffer(parent.triangleCornerInds)); + + // the indexing into the parameterization varies based on whether it is a corner or vertex quantity + switch (param.definedOn) { + case MeshElement::VERTEX: + program->setAttribute("a_tCoord", param.coords.getIndexedRenderAttributeBuffer(parent.triangleVertexInds)); + break; + case MeshElement::CORNER: + program->setAttribute("a_tCoord", param.coords.getIndexedRenderAttributeBuffer(parent.triangleCornerInds)); + break; + default: + // nothing + break; + } + program->setTextureFromBuffer("t_color", colors.getRenderTextureBuffer().get()); render::engine->setMaterial(*program, parent.getMaterial()); diff --git a/src/surface_parameterization_quantity.cpp b/src/surface_parameterization_quantity.cpp index ce9de526..fc7b8a44 100644 --- a/src/surface_parameterization_quantity.cpp +++ b/src/surface_parameterization_quantity.cpp @@ -20,8 +20,10 @@ namespace polyscope { SurfaceParameterizationQuantity::SurfaceParameterizationQuantity(std::string name, SurfaceMesh& mesh_, const std::vector& coords_, - ParamCoordsType type_, ParamVizStyle style_) - : SurfaceMeshQuantity(name, mesh_, true), ParameterizationQuantity(*this, coords_, type_, style_) { + MeshElement definedOn_, ParamCoordsType type_, + ParamVizStyle style_) + : SurfaceMeshQuantity(name, mesh_, true), ParameterizationQuantity(*this, coords_, type_, style_), + definedOn(definedOn_) { // sanity check, this should basically never happen, but this guards against weird edge cases such // as persistent values restoring the style, device updates, etc @@ -216,7 +218,7 @@ SurfaceCornerParameterizationQuantity::SurfaceCornerParameterizationQuantity(std const std::vector& coords_, ParamCoordsType type_, ParamVizStyle style_) - : SurfaceParameterizationQuantity(name, mesh_, coords_, type_, style_) {} + : SurfaceParameterizationQuantity(name, mesh_, coords_, MeshElement::CORNER, type_, style_) {} std::string SurfaceCornerParameterizationQuantity::niceName() { return name + " (corner parameterization)"; } @@ -244,7 +246,7 @@ SurfaceVertexParameterizationQuantity::SurfaceVertexParameterizationQuantity(std const std::vector& coords_, ParamCoordsType type_, ParamVizStyle style_) - : SurfaceParameterizationQuantity(name, mesh_, coords_, type_, style_) {} + : SurfaceParameterizationQuantity(name, mesh_, coords_, MeshElement::VERTEX, type_, style_) {} std::string SurfaceVertexParameterizationQuantity::niceName() { return name + " (vertex parameterization)"; } diff --git a/src/surface_scalar_quantity.cpp b/src/surface_scalar_quantity.cpp index a9e2983f..d3d47681 100644 --- a/src/surface_scalar_quantity.cpp +++ b/src/surface_scalar_quantity.cpp @@ -275,7 +275,7 @@ SurfaceTextureScalarQuantity::SurfaceTextureScalarQuantity(std::string name, Sur SurfaceParameterizationQuantity& param_, size_t dimX_, size_t dimY_, const std::vector& values_, ImageOrigin origin_, DataType dataType_) - : SurfaceScalarQuantity(name, mesh_, "texture", values_, dataType_), param(param_), dimX(dimX_), dimY(dimY_), + : SurfaceScalarQuantity(name, mesh_, "vertex", values_, dataType_), param(param_), dimX(dimX_), dimY(dimY_), imageOrigin(origin_) { values.setTextureSize(dimX, dimY); values.ensureHostBufferPopulated(); @@ -298,7 +298,20 @@ void SurfaceTextureScalarQuantity::createProgram() { // clang-format on parent.setMeshGeometryAttributes(*program); - program->setAttribute("a_tCoord", param.coords.getIndexedRenderAttributeBuffer(parent.triangleCornerInds)); + + // the indexing into the parameterization varies based on whether it is a corner or vertex quantity + switch (param.definedOn) { + case MeshElement::VERTEX: + program->setAttribute("a_tCoord", param.coords.getIndexedRenderAttributeBuffer(parent.triangleVertexInds)); + break; + case MeshElement::CORNER: + program->setAttribute("a_tCoord", param.coords.getIndexedRenderAttributeBuffer(parent.triangleCornerInds)); + break; + default: + // nothing + break; + } + program->setTextureFromBuffer("t_scalar", values.getRenderTextureBuffer().get()); render::engine->setMaterial(*program, parent.getMaterial()); program->setTextureFromColormap("t_colormap", cMap.get());