Hi all,
This component lets your users add 3D models to their posts using the Google model viewer component. I created this component to let users of my Photogrammetry SaaS Beholder share models that they create on our shiny new Discourse forum and thought I’d also share it here in case it’s of use to other people. I couldn’t see another similar component, but then I only did a very quick search…
Instructions and screenshots showing how to use the component are below.
Any feedback or thoughts on this component are much appreciated. The model viewer component that I use to display the models has quite a lot of functionality so there’s likely quite a bit of scope to expand this component by exposing some of that functionality to users. I created this component by copy, pasting and modifying the insert video and mermaid components so I’d also really appreciate it if someone with more experience of writing Discourse component could cast their eye over the code and let me know what mistakes I’ve made.
Regards
Alan
Usage
When the component is installed users will be able to add 3D models to their
posts by clicking on the new cube icon in the composer.
Currently the 3D viewer will not download and display the 3D model straight away, instead it will display a poster (that can be customised) and will only load the model when the user clicks the ‘Load 3D Model’ button. The thinking behind this is to help users with limited bandwidth.
You’ll also likely need to up the limit for the max attachment size.
This is the probably the main limitation for using this component on hosted Discourse as there, on the lower subscription plans, the max size is limited to 30MB. To be fair though you probably don’t want your users to be uploading massive files and .glb and .gltf files can be greatly reduced in size if they’re generated by a program that supports Draco mesh compression.
Oh no! This is not good. Thank you for letting me know.
The same had happened on my forum. Looking at the post, what I think has happened is that after a few days Discourse has decided that the uploaded poster image and the 3D model are no longer needed so it has deleted them from the server.
I have ‘fixed’ this temporarily on my site by reuploading the model and the poster but I’m now off to read through the Discourse theme docs to see if I can fix it properly. From the quick scan I did when writing the theme component I saw the docs say that as long as an asset is referenced by a post then it will be kept on the server but obviously the URLs that this component puts in the post are not doing that for some reason. If any other plugin writer can offer advice on this it would be much appreciated…
Yeah, my current theory is that when I create the markdown to reference the model viewer, then in some way the URL for the uploaded model is not in the correct form for whatever logic that scans post to recognise used uploads to see.
Currently I’m looking at 2 other places in Discourse where files are uploaded. In the image/file upload modal, a reference is kept to a ‘short_url’ that has the form upload:// rather than the final url that will be used by the browser to download the resource. So perhaps I’ll need to work out how to use that? Alternatively, the GitHub - discourse/discourse-insert-video · GitHub component, which I based my component on uses the resource url directly. Either that component suffers from the same bug (unlikely ) or those urls are recognised because they’re inserted into the markdown message as HTML tags (I can’t do that with the model-viewer tag as it’s not on the HTML tag whitelist).
That’s my current thinking, or it could be something else entirely. Now off to see if I can find the code that identifies orphan uploads on a Discourse site…
어쨌든, 방금 다시 살펴본 결과 업로드 파일이 유지되거나 삭제되는지를 결정하는 코드를 찾은 것 같습니다. 게시글을 처리하는 서버 측 코드에는 'each_upload_url’이라는 루틴이 있으며, 이는 게시글에서 참조된 업로드 파일 목록을 생성합니다.
저는 Ruby 개발자는 아니지만, 파악한 바로는 미리 정의된 HTML 태그 목록에 의해 참조되는 URL을 찾고 있는 것 같습니다. 따라서 제가 복사한 ‘영상 삽입’ 테마 컴포넌트의 경우, <source> HTML 요소의 src 속성과 <video> HTML 요소의 poster 속성은 업로드 파일로 인식됩니다. 하지만 제 ‘3D 모델 삽입’ 컴포넌트의 경우, <model-viewer> HTML 요소가 해당 목록에 포함되어 있지 않아 참조하는 자산이 업로드 파일로 인식되지 않고, 며칠 후 삭제(purged)됩니다.
장기적인 해결책은 서버 측 코드를 변경하여 model-viewer 속성을 업로드 소스로 인식하도록 하는 것일 수 있지만, 현재로서는 업로드를 가리키는 명시적인 HTML <a> 태그를 추가하여 우회할 수도 있다고 생각합니다.
제 이해가 맞는지 확인하기 위해 Contribute > Bug 카테고리에 게시글을 남길 예정입니다. 하지만 만약 제 이해가 맞다면, Insert Model 3D 테마 컴포넌트에 게시글 내에 업로드된 모델과 포스터를 참조하는 숨겨진 <a> 태그를 삽입하는 수정 사항을 제출했습니다. @patrickemin 시간이 되시면 이 수정 사항이 문제를 해결하는지 확인해 주실 수 있을까요? 컴포넌트를 업데이트한 후 삭제된 3D 모델 자산을 다시 업로드해야 합니다.
Alan, not sure if this will solve the riddle, but it has impacted us in the past where there have been bugs in this space.
Orphaned uploads are deleted periodically. As part of an upload, you should end up with an entry in the table uploads. If for any reason that is missing, the upload will be removed eventually.
Might be a line of enquiry.
to check the Upload model you can go into the rails console from Discourse directory and for example:
Ah that’s useful to know, thanks Robert. Do you know if it’s possible to perform that check or something equivalent on hosted Discourse? I’m assuming not so @patrickemin if your server happens to be self hosted then this could be a good thing to check.
Alternatively, I have a docker based local setup of Discourse that I was working on until I gave up and ran to hosted Discourse. This could be a good excuse to return to it.
Hi, me back after a few months… I took the opportunity Microsoft releases its Copilot 2D to 3D model to test and your TC is now working fine, with the code added the model should not disappear, see here.