mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-10-12 10:21:17 +00:00
Importing a model that already carries colours was broken for texture displacement in two ways: the UV layout it was authored against was thrown away and re-unwrapped, and a bake overwrote the colours it arrived with. A model's own UV channel is now kept. ModelVolume::texture_uv holds three uvs per triangle, in the mesh's own triangle order and with V flipped to the convention DecodedHeightTexture samples in. It is filled from a textured OBJ's vt data on import and carried across every stage that replaces the mesh - the colour import's painted mesh, the gizmo's remesh and subdivide, the default pipeline's rebuild - by transfer_uv_channel(), which gives each new corner the uv of its closest point on the surface it came from. A new mapping, TextureProjectionMethod::ModelUV, samples that channel instead of solving an unwrap, and a new layer on a volume that has one starts there. Its uv is already normalized, so it keeps the layer's rotation and offset but not the millimetre tile size (the slider is disabled) or the non-square aspect correction; with no channel it falls back to Triplanar, as LSCM does when a patch will not flatten. A bake with colour off on every layer now leaves the model's colours where they were. The default pipeline rebuilds the topology, which left mmu_segmentation_facets describing a triangle set that no longer existed. ModelVolume::restore_painting() cannot carry it: its remap wants a target triangle overlapping the source paint to within 0.01 mm, and a baked surface has moved by the relief depth. transfer_facet_paint() gives each new facet the state at its own foot point on the pre-bake surface instead, and the bake commit runs it over all four paint channels. The classic path is untouched, since there triangle i is still triangle i. Blend gains an Override entry next to Add: the layer replaces the displacement under it rather than combining with it, which is what the stack's colour already does where two layers overlap. The combo's order is the panel's, not the enum's, so stored blend modes are unaffected. Measured on a textured OBJ of 85224 triangles (uv_color_probe in the bake harness): the channel survives import intact, the relief follows the model's own uv on 98.7% of vertices against 51.3% for a re-unwrap, and a colour-off bake through the default pipeline keeps the colours on 99.8% of the baked surface where it previously kept none. Through a coloured 3mf, 100%.
OrcaSlicer tests
Building, running and writing tests is documented on the wiki, under How to Test.
Two files here rather than there, because coding agents only read what is in the repository: