1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2025-06-27 16:35:57 +00:00
forgejo/routers/web/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 chore(cleanup): replaces unnecessary calls to formatting functions by non-formatting equivalents (#7994) 2025-05-29 17:34:29 +02:00
badges chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
flags chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
setting add model viewer for .glb (GLTF) model in file view (#8111) 2025-06-21 14:42:35 +02:00
action_aggregator_test.go fix: aggregate deleted team as ghost team (#7987) 2025-05-29 17:45:18 +02:00
activity.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
attachment.go Update module github.com/golangci/golangci-lint/cmd/golangci-lint to v2 (forgejo) (#7367) 2025-03-28 22:22:21 +00:00
blame.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
branch.go feat: always publish the link to the commit status (#8177) 2025-06-13 12:41:34 +02:00
card.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
cherry_pick.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
code_frequency.go 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
commit.go feat: always publish the link to the commit status (#8177) 2025-06-13 12:41:34 +02:00
compare.go feat: always publish the link to the commit status (#8177) 2025-06-13 12:41:34 +02:00
contributors.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
download.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
editor.go fix(i18n): fix several usages of i18n (#7422) 2025-04-02 14:50:02 +00:00
editor_test.go Update module github.com/golangci/golangci-lint/cmd/golangci-lint to v2 (forgejo) (#7367) 2025-03-28 22:22:21 +00:00
find.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
githttp.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
githttp_test.go Update module github.com/golangci/golangci-lint/cmd/golangci-lint to v2 (forgejo) (#7367) 2025-03-28 22:22:21 +00:00
helper.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
helper_test.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
issue.go fix: only send Forgejo Actions notifications to one user (#8227) 2025-06-21 12:15:38 +02:00
issue_content_history.go Update module github.com/golangci/golangci-lint/cmd/golangci-lint to v2 (forgejo) (#7367) 2025-03-28 22:22:21 +00:00
issue_dependency.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
issue_label.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
issue_label_test.go Update module github.com/golangci/golangci-lint/cmd/golangci-lint to v2 (forgejo) (#7367) 2025-03-28 22:22:21 +00:00
issue_lock.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
issue_pin.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
issue_stopwatch.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
issue_timetrack.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
issue_watch.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
main_test.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
middlewares.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
migrate.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
milestone.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
packages.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
patch.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
projects.go Update module github.com/golangci/golangci-lint/cmd/golangci-lint to v2 (forgejo) (#7367) 2025-03-28 22:22:21 +00:00
projects_test.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
pull.go fix: git_model.CommitStatusesHideActionsURL is obsolete (#8209) 2025-06-17 10:15:48 +02:00
pull_review.go Update module github.com/golangci/golangci-lint/cmd/golangci-lint to v2 (forgejo) (#7367) 2025-03-28 22:22:21 +00:00
pull_review_test.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
recent_commits.go 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
release.go Show if commit is signed in activity feed and unify sha box (#6933) 2025-05-03 10:54:52 +00:00
release_test.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
render.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
repo.go feat: always publish the link to the commit status (#8177) 2025-06-13 12:41:34 +02:00
search.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
topic.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
treelist.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
view.go add model viewer for .glb (GLTF) model in file view (#8111) 2025-06-21 14:42:35 +02:00
view_test.go Implement FSFE REUSE for golang files (#21840) 2022-11-27 18:20:29 +00:00
wiki.go feat: always publish the link to the commit status (#8177) 2025-06-13 12:41:34 +02:00
wiki_test.go Update module github.com/golangci/golangci-lint/cmd/golangci-lint to v2 (forgejo) (#7367) 2025-03-28 22:22:21 +00:00