f3d-app / f3d

Fast and minimalist 3D viewer.
https://f3d.app
BSD 3-Clause "New" or "Revised" License
2.76k stars 199 forks source link

Implements texture transforms #1643

Open Meakk opened 1 day ago

Meakk commented 1 day ago

It's already possible to specify custom textures in both F3D and libf3d --texture-XXX options.
Some file formats are expecting textures to be Y-flipped like GLTF for example (Flipping the texture is already done in the GLTF importer, but not the reader).
It could be useful to allow the user to transform the texture coordinates to do take that into account.
VTK supports texture coordinates transform, by setting a specific key on the actor, like the code below:

  double mat[] = { 1, 0, 0, 0, 0, -1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1 };
  actor->GetPropertyKeys()->Set(vtkProp::GeneralTextureTransform(), mat, 16);

VTK expects a 4x4 matrix, but in our case we only support 2D texture coordinates, so we should expose the option as a 3x3 matrix.
Suggested F3D option is --textures-transform, suggested libf3d option is model.textures_transform.
Ideally, the option should be a new type transform2d_t defined in types.h storing 9 float values, and parsing methods should support things like:

Yogesh9000 commented 14 hours ago

Is anyone working on this issue? If not I would like to work on it.

mwestphal commented 4 hours ago

you can start looking at it but it may conflicts with my ongoing work: https://github.com/f3d-app/f3d/pull/1609, so you may want to wait for this to be merged before actually implementting this.