forgejo/templates/repo
Alex Smith 690532efb8 add model viewer for .glb (GLTF) model in file view (#8111)
## Motivation

The GLTF (`.gltf`, `.glb`) 3D model format is very popular for game development and visual productions.

For an indie game studio, it would be convenient for a team to view textured 3D models directly from the Forgejo interface (otherwise they need to be downloaded and opened). [Perforce](https://www.perforce.com/products/helix-dam), [Diversion](https://www.diversion.dev/), and GitHub all have this capability to differing extents.

Some discussion on 3D file support here: https://codeberg.org/forgejo/forgejo/issues/5188

## Changes

Adds a model viewer similar to [GitHub STL viewer](https://github.com/assimp/assimp/blob/master/test/models/STL/Spider_ascii.stl) for `.glb` model files, and lays some groundwork to support future files. Uses the [model-viewer](https://modelviewer.dev/) library by Google and three.js. The model viewer is interactive and can be rotated and scaled.

![Screen Recording 2025-06-08 at 15.27.15](/attachments/84c63dea-a0ce-45f9-b48b-c80867636639)

## How to Test

1) Create a new repository or use an existing one.
2) Upload a `.glb` file such as `tests/testdata/data/viewer/Unicode❤♻Test.glb` (CC0 1.0 Universal)
3) View the file in the repository.
    - Similar to image files, the 3D model should be rendered in a viewer.
    - Use mouse clicks to turn and zoom.

## Licenses

Libraries used for this change include three.js and @google/model-viewer, which are MIT and Apache-2.0 licenses respectively. Both of these are compatible with Forgejo's GPL3.0 license.

## Future Plans

1) `.gltf` was not attempted because it is a multiple file format, referencing other files in the same directory. Still need to experiment with this to see if it can work. `.glb` is a single file containing a `.gltf` and all of its other file/texture dependencies so was easier to implement.
2) The PR diff still shows the model as an unviewable bin file, but clicking the "View File" button takes you to a view screen where this model viewer is used. It would be nice to view the before and after of the model in two side-by-side model viewers, akin to reviewing a change in an image.
3) Also inserted stubs for adding contexts for GLTF, STL, OBJ, and 3MF. These ultimately don't do anything yet as only `.glb` files can be detected by the type sniffer of all of these.

## Checklist

The [contributor guide](https://forgejo.org/docs/next/contributor/) contains information that will be helpful to first time contributors. There also are a few [conditions for merging Pull Requests in Forgejo repositories](https://codeberg.org/forgejo/governance/src/branch/main/PullRequestsAgreement.md). You are also welcome to join the [Forgejo development chatroom](https://matrix.to/#/#forgejo-development:matrix.org).

### Tests

- I added test coverage for checking GLB file content using the first few bytes.
  - [x] in their respective `typesniffer_test.go` for unit tests.

### Documentation

- [ ] I created a pull request [to the documentation](https://codeberg.org/forgejo/docs) to explain to Forgejo users how to use this change.
- [x] I did not document these changes and I do not expect someone else to do it.

### Release notes

- [ ] I do not want this change to show in the release notes.
- [ ] I want the title to show in the release notes with a link to this pull request.
- [ ] I want the content of the `release-notes/<pull request number>.md` to be be used for the release notes instead of the title.

<!--start release-notes-assistant-->

## Release notes
<!--URL:https://codeberg.org/forgejo/forgejo-->
- User Interface features
  - [PR](https://codeberg.org/forgejo/forgejo/pulls/8111): <!--number 8111 --><!--line 0 --><!--description YWRkIG1vZGVsIHZpZXdlciBmb3IgYC5nbGJgIChHTFRGKSBtb2RlbCBpbiBmaWxlIHZpZXc=-->add model viewer for `.glb` (GLTF) model in file view<!--description-->
<!--end release-notes-assistant-->

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8111
Reviewed-by: oliverpool <oliverpool@noreply.codeberg.org>
Co-authored-by: Alex Smith <amsmith.pro@pm.me>
Co-committed-by: Alex Smith <amsmith.pro@pm.me>
2025-06-21 14:42:35 +02:00
..
actions feat(ui): Automatically refresh workflows in the "Actions" list (#7361) 2025-04-04 14:38:54 +00:00
branch fix: Remove "create branch" button on mirrored repos (#7640) 2025-05-14 23:26:12 +00:00
cite ui: fix go to citation button url (#4597) 2024-08-22 15:36:12 +00:00
code fix(ui): multiple fixes of sync fork UI (#7740) 2025-05-02 14:25:05 +00:00
diff Implement single-commit PR review flow (#7155) 2025-06-17 09:31:50 +02:00
editor chore(ui): clean up hashbox CSS, small design changes (#7822) 2025-05-25 12:51:27 +02:00
find Migrate gt-hidden to tw-hidden (#30046) 2024-03-30 07:17:29 +01:00
graph Show if commit is signed in activity feed and unify sha box (#6933) 2025-05-03 10:54:52 +00:00
issue [gitea] week 2025-22 cherry pick (gitea/main -> forgejo) (#8198) 2025-06-17 18:28:07 +02:00
migrate feat(ui): redesign migration selection screen (#6795) 2025-04-19 13:51:35 +00:00
projects Migrate margin and padding helpers to tailwind (#30043) 2024-03-30 07:17:29 +01:00
pulls Improve diff stats bar (#30669) 2024-04-28 15:39:01 +02:00
release fix: remove download attribute from external assets (#8112) 2025-06-09 10:48:35 +02:00
settings add model viewer for .glb (GLTF) model in file view (#8111) 2025-06-21 14:42:35 +02:00
tag fix: add missing bottom margin for verification-button in release view (#8044) 2025-06-03 08:55:22 +02:00
wiki Fix two missed null value checks on the wiki page. (#34205) 2025-04-22 10:04:41 +02:00
activity.tmpl Show repo activities even if only code unit active or git repo is empty but issue is active (#3455) 2024-04-28 13:47:52 +00:00
admin_flags.tmpl [FEAT] Repository flags 2024-02-05 16:09:42 +01:00
blame.tmpl ui(blame): remove broken padding (#4318) 2024-07-04 11:46:31 +00:00
branch_dropdown.tmpl fix(ui): show commit icon in branch dropdown button when viewing a commit (#7571) 2025-04-19 04:33:07 +00:00
clone_buttons.tmpl Refactor clone-panel styles (#29861) 2024-03-26 19:04:24 +01:00
clone_script.tmpl Customizable "Open with" applications for repository clone (#29320) 2024-03-23 11:58:54 +01:00
code_frequency.tmpl Implement code frequency graph (#29191) 2024-02-26 22:30:26 +01:00
commit_header.tmpl Implement single-commit PR review flow (#7155) 2025-06-17 09:31:50 +02:00
commit_load_branches_and_tags.tmpl Implement single-commit PR review flow (#7155) 2025-06-17 09:31:50 +02:00
commit_page.tmpl chore: extract commit header template (#8061) 2025-06-05 11:35:08 +02:00
commit_status.tmpl Restore warning commit status (#27504) 2023-10-08 22:16:06 +00:00
commit_statuses.tmpl Replace 10 more gt- classes with tw- (#29945) 2024-03-26 19:04:27 +01:00
commits.tmpl Migrate margin and padding helpers to tailwind (#30043) 2024-03-30 07:17:29 +01:00
commits_list.tmpl Implement single-commit PR review flow (#7155) 2025-06-17 09:31:50 +02:00
commits_list_small.tmpl Implement single-commit PR review flow (#7155) 2025-06-17 09:31:50 +02:00
commits_search_dropdown.tmpl Unify search boxes (#29530) 2024-03-20 12:31:05 +00:00
commits_table.tmpl chore(ui): clean up hashbox CSS, small design changes (#7822) 2025-05-25 12:51:27 +02:00
contributors.tmpl Add "n commits" link to contributors in contributors graph page (#32799) 2024-12-15 13:21:02 +01:00
create.tmpl fix(ui): make limits clearer in create repo form (#7402) 2025-05-20 16:37:15 +02:00
create_advanced.tmpl New repo: Rework advanced and template sections 2024-12-28 22:32:19 +01:00
create_basic.tmpl fix(ui): make limits clearer in create repo form (#7402) 2025-05-20 16:37:15 +02:00
create_from_template.tmpl New repo: Rework advanced and template sections 2024-12-28 22:32:19 +01:00
create_helper.tmpl Remove incorrect and unnecessary Escape from templates (#29394) 2024-02-26 22:30:27 +01:00
create_init.tmpl New repo: Rework initialization 2024-12-29 13:05:30 +01:00
empty.tmpl fix(ui): clarify repo init instruction for sha256 (#7394) 2025-03-30 18:08:05 +00:00
file_info.tmpl [UI] Adjust trailing EOL behavior for empty file 2024-08-19 20:23:15 +02:00
flags.tmpl Migrate margin and padding helpers to tailwind (#30043) 2024-03-30 07:17:29 +01:00
forks.tmpl Migrate margin and padding helpers to tailwind (#30043) 2024-03-30 07:17:29 +01:00
graph.tmpl fix(ui): use gap in switch items (#7581) 2025-04-21 04:25:08 +00:00
header.tmpl feat!: Abusive content reporting (#6977) 2025-05-18 08:05:16 +00:00
header_fork.tmpl Migrate margin and padding helpers to tailwind (#30043) 2024-03-30 07:17:29 +01:00
home.tmpl feat(ui): make fork related banners more consistent (#7577) 2025-04-23 16:48:26 +00:00
icon.tmpl Replace 10 more gt- classes with tw- (#29945) 2024-03-26 19:04:27 +01:00
latest_commit.tmpl Show if commit is signed in activity feed and unify sha box (#6933) 2025-05-03 10:54:52 +00:00
navbar.tmpl Hide activity contributors, recent commits and code frequrency left tabs if there is no code permission (#34053) 2025-04-01 02:28:02 +02:00
packages.tmpl Fix inconsistent user profile layout across tabs (#25625) 2023-07-06 18:59:24 +00:00
pulse.tmpl chore(ui): cleanup unused color CSS (#7898) 2025-05-19 14:04:28 +02:00
recent_commits.tmpl Implement recent commits graph (#29210) 2024-02-26 22:30:26 +01:00
release_tag_header.tmpl feat: Add Search to Releases Page 2024-11-02 10:24:35 +01:00
search.tmpl ui(code-search): fix to use CodeSearchMode 2024-09-16 16:20:55 +02:00
search_name.tmpl Clean template/helper.go (#23922) 2023-04-07 03:31:41 -04:00
shabox.tmpl chore(ui): clean up hashbox CSS, small design changes (#7822) 2025-05-25 12:51:27 +02:00
shabox_badge.tmpl chore(ui): clean up hashbox CSS, small design changes (#7822) 2025-05-25 12:51:27 +02:00
star_unstar.tmpl Further consistency in the repo header 2024-03-27 09:33:06 +01:00
sub_menu.tmpl ui: update language stats layout and click behavior (#6700) 2025-01-29 16:55:10 +00:00
unicode_escape_prompt.tmpl templates: remove superfluous SanitizeHTML 2024-03-11 23:36:58 +07:00
upload.tmpl Always use ctx.Locale.Tr inside templates (#27231) 2023-09-25 08:56:50 +00:00
user_cards.tmpl fix(ui): ensure same width of usercards in grid (#6799) 2025-05-25 13:31:53 +02:00
view_file.tmpl add model viewer for .glb (GLTF) model in file view (#8111) 2025-06-21 14:42:35 +02:00
view_list.tmpl [PORT] Refactor DateUtils and merge TimeSince (gitea#32409) 2024-11-10 22:23:27 +01:00
watch_unwatch.tmpl Further consistency in the repo header 2024-03-27 09:33:06 +01:00
watchers.tmpl Fix user-cards format (#24428) 2023-04-29 15:43:01 -04:00