Skip to content

Add support for 3D/CAD file formats preview #34794

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 24 commits into from
Jun 30, 2025

Conversation

kerwin612
Copy link
Member

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jun 20, 2025
@github-actions github-actions bot added modifies/go Pull requests that update Go code modifies/templates This PR modifies the template files modifies/dependencies modifies/frontend labels Jun 20, 2025
@wxiaoguang
Copy link
Contributor

wxiaoguang commented Jun 20, 2025

I think we need a pure frontend "render plugin" mechanism

  1. Register "fronend render plugin"
  2. Plugin read page information (for example: file name)
  3. If the plugin is able to render it, read the "raw" content, then replace the "fileview" element.

I don't think we should hard-code too many file types in backend.

@kerwin612 kerwin612 force-pushed the feat/support-preview-3d-file branch from eba2b22 to 057ee0e Compare June 21, 2025 06:16
@github-actions github-actions bot removed the modifies/go Pull requests that update Go code label Jun 21, 2025
@kerwin612 kerwin612 requested review from delvh, lunny and wxiaoguang June 21, 2025 06:17
@kerwin612 kerwin612 force-pushed the feat/support-preview-3d-file branch from 057ee0e to 448effb Compare June 21, 2025 06:22
@github-actions github-actions bot added the modifies/go Pull requests that update Go code label Jun 21, 2025
@lunny lunny added this to the 1.25.0 milestone Jun 23, 2025
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Jun 26, 2025
@wxiaoguang
Copy link
Contributor

Can we merge "initPdfViewer" into the new framework? I think it can also benefit from the new design.

@wxiaoguang wxiaoguang added the type/feature Completely new functionality. Can only be merged if feature freeze is not active. label Jun 29, 2025
@lunny
Copy link
Member

lunny commented Jun 29, 2025

When viewing .3ds file, there is a View Rendered icon. But when viewing .mp4 or other binary files, there is no such icon. Is that normal?
image
image

@kerwin612
Copy link
Member Author

b89f6858-a480-4b20-82ee-0651913a2d6a
058a8aa9-63b7-4104-a901-5aa378689a77
My suggestions:

  1. When there are no tabs to switch (as shown in Figure 2 above), this tab switch can be directly hidden, because an isolated button seems to have no meaning and may also cause users to guess and misunderstand.
  2. Is it necessary to skip the click event for the selected tab?

@wxiaoguang
Copy link
Contributor

Feel free to make more improvements.

@hiifong
Copy link
Member

hiifong commented Jun 30, 2025

I think a full screen preview of the 3d file is missing.

@kerwin612
Copy link
Member Author

Feel free to make more improvements.

OK, I'll find time to improve it.

@kerwin612
Copy link
Member Author

I think a full screen preview of the 3d file is missing.

Yeah, this is already in the plan.

@hiifong
Copy link
Member

hiifong commented Jun 30, 2025

bim, dae,brep,igs,stp,ply,off,wrl,ifc,3mf file extensions are rendered as plain text.

Please make it as draft.

@wxiaoguang
Copy link
Contributor

wxiaoguang commented Jun 30, 2025

bim, dae,brep,igs,stp,ply,off,wrl,ifc,3mf file extensions are rendered as plain text.

Please make it as draft.

It is already supported. Including STL, see my comment.

This PR can't auto render them because there is no accurate detection yet.

In the future, if we have a better detection, then we can auto render them.

image

@wxiaoguang
Copy link
Contributor

Feel free to make more improvements.

OK, I'll find time to improve it.

Merge this as-is and propose following up PRs, or switch to WIP to wait for more changes?

@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Jun 30, 2025
@kerwin612
Copy link
Member Author

Feel free to make more improvements.

OK, I'll find time to improve it.

Merge this as-is and propose following up PRs, or switch to WIP to wait for more changes?

Merge it first. I'll submit a PR for other optimizations or adjustments later.

@wxiaoguang
Copy link
Contributor

It is already supported. Including STL, see my comment.

This PR can't auto render them because there is no accurate detection yet.

In the future, if we have a better detection, then we can auto render them.

More details about the problem:

It needs more logic to make it overall right, we need to distinguish the ambiguous filename extensions. For example: "*.obj, *.off, *.step" might be or not be a 3D model file. So when it is a text file, we can't assume that "we only render it by 3D plugin", otherwise the end users would be impossible to view its real content when the file is not a 3D model.

@hiifong
Copy link
Member

hiifong commented Jun 30, 2025

ref: https://www.spatial.com/glossary/what-is-an-stp-file

I've just checked for information on this, and the .step and .stp files are standard ISO file formats (ISO 10303-242:2014), and I think we can check from the contents of the file.

$ cat as1_pe_203.stp
ISO-10303-21;
HEADER;
FILE_DESCRIPTION((''),'2;1');
FILE_NAME('AS1_PE_ASM','2008-09-04T',('mmeadows'),(''),
'PRO/ENGINEER BY PARAMETRIC TECHNOLOGY CORPORATION, 2008340',
'PRO/ENGINEER BY PARAMETRIC TECHNOLOGY CORPORATION, 2008340','');
FILE_SCHEMA((
'AP203_CONFIGURATION_CONTROLLED_3D_DESIGN_OF_MECHANICAL_PARTS_AND_ASSEMBLIES_MIM_LF'));
ENDSEC;
DATA;
#16=DIRECTION('',(0.E0,1.E0,0.E0));
#17=VECTOR('',#16,2.E1);
#18=CARTESIAN_POINT('',(4.E1,-2.E1,-7.5E1));
#19=LINE('',#18,#17);
...
#2874=REPRESENTATION('centroid',(#2872),#2841);
#2875=PROPERTY_DEFINITION_REPRESENTATION(#2873,#2874);
ENDSEC;
END-ISO-10303-21;

@hiifong
Copy link
Member

hiifong commented Jun 30, 2025

ref: https://www.spatial.com/glossary/what-is-an-stp-file

I've just checked for information on this, and the .step and .stp files are standard ISO file formats (ISO 10303-242:2014), and I think we can check from the contents of the file.

$ cat as1_pe_203.stp
ISO-10303-21;
HEADER;
FILE_DESCRIPTION((''),'2;1');
FILE_NAME('AS1_PE_ASM','2008-09-04T',('mmeadows'),(''),
'PRO/ENGINEER BY PARAMETRIC TECHNOLOGY CORPORATION, 2008340',
'PRO/ENGINEER BY PARAMETRIC TECHNOLOGY CORPORATION, 2008340','');
FILE_SCHEMA((
'AP203_CONFIGURATION_CONTROLLED_3D_DESIGN_OF_MECHANICAL_PARTS_AND_ASSEMBLIES_MIM_LF'));
ENDSEC;
DATA;
#16=DIRECTION('',(0.E0,1.E0,0.E0));
#17=VECTOR('',#16,2.E1);
#18=CARTESIAN_POINT('',(4.E1,-2.E1,-7.5E1));
#19=LINE('',#18,#17);
...
#2874=REPRESENTATION('centroid',(#2872),#2841);
#2875=PROPERTY_DEFINITION_REPRESENTATION(#2873,#2874);
ENDSEC;
END-ISO-10303-21;

I don't want you to implement it in this pull request, but I want to provide some clues about it

@wxiaoguang
Copy link
Contributor

And we can also use AI:

image

@wxiaoguang wxiaoguang merged commit 176962c into go-gitea:main Jun 30, 2025
26 checks passed
@wxiaoguang wxiaoguang deleted the feat/support-preview-3d-file branch June 30, 2025 08:12
const viewer = new OV.EmbeddedViewer(container, {
backgroundColor: new OV.RGBAColor(59, 68, 76, 0),
defaultColor: new OV.RGBColor(65, 131, 196),
edgeSettings: new OV.EdgeSettings(false, new OV.RGBColor(0, 0, 0), 1),
Copy link
Member

@silverwind silverwind Jun 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this will look good on dark theme, you need different colors on dark theme, e.g. use getColor() from web_src/js/features/codeeditor.ts to get the color values from CSS variables. Likely declare new color variables.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for pointing it out. I will improve it later.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the background, you can likely re-use --color-code-bg, e.g. getColor('--color-code-bg'), converting to this OV.RGBAColor of course.

This comment was marked as off-topic.

zjjhot added a commit to zjjhot/gitea that referenced this pull request Jul 1, 2025
* giteaofficial/main:
  Fix modal + form abuse (go-gitea#34921)
  [skip ci] Updated translations via Crowdin
  Follow file symlinks in the UI to their target (go-gitea#28835)
  Fix issue filter (go-gitea#34914)
  Fix: RPM package download routing & missing package version count (go-gitea#34909)
  Add support for 3D/CAD file formats preview (go-gitea#34794)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. modifies/dependencies modifies/frontend modifies/go Pull requests that update Go code modifies/templates This PR modifies the template files type/feature Completely new functionality. Can only be merged if feature freeze is not active.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants