OpenDroneMap / Obj2Tiles

Converts OBJ files to OGC 3D tiles by performing splitting, decimation and conversion
GNU Affero General Public License v3.0
196 stars 58 forks source link

Consider remapping uv range [0, 1] to image pixel range [0, w-1] (or [0, h-1]) in MeshT.BinPackTextures #57

Closed EzioHelios closed 6 months ago

EzioHelios commented 7 months ago

In case where I have u = 1.0 or v 1.0 of vt {u} {v} in my obj file, the following line in Obj2Tiles.Library.Common.CopyImage will throw index out of range exception.

targetRow[x + destX] = sourceRow[x + sourceX];

I traced back and found that when clusterBoundary.Left (u) is exactly 1.0, clusterX will be equal to textureWidth and cause this problem.

Maybe we should consider remapping uv range [0, 1] to image pixel range [0, w-1] (or [0, h-1])?

          var clusterX = (int)Math.Floor(clusterBoundary.Left * (textureWidth - 1));
          var clusterY = (int)Math.Floor(clusterBoundary.Top * (textureHeight - 1));

As for uv out of range [0, 1], it might not be necessary to handle repetition.

pierotofy commented 6 months ago

Hey @EzioHelios thanks for looking into this and for the fix !