-
Notifications
You must be signed in to change notification settings - Fork 15
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
Visualize 3D models locally without relying on sketchfab iframe #2091
Visualize 3D models locally without relying on sketchfab iframe #2091
Conversation
Hi @luistoptal, prasie: Was able to associate this https://sketchfab.com/3d-models/beet-03-c63d100fb76042ecab2ec87f73da323e stl file to dataset 100006, and display it on Chrome browser. ![]() question: The 3D image cannot be shown in Safari nor Firefox browsers, can you help further look into it? SafariFirefox |
@kencho51 looking at the images, it looks as if the CSS is not loaded. Because not only the 3D model is not shown but the buttons look as if the custom styles applied to them were not working. Can you try:
|
Hi @luistoptal,
After hard refresh/empty the cache in safari and firefox, the 3D image can be displayed now. |
Hi @luistoptal, question: Would it be better to have acceptance tests/accessibility tests as there is an extra
@rija, @pli888 , what do you think? praise: I was able to deploy this PR to my staging, and display the 3D images from the above files stored in the s3 bucket. |
@kencho51 that would work since the viewer simply loads and displays files accessible via public links, thanks for adding these files, now they can be used to update the tests there is one test for the 3D models tab already present, it hadn't been updated |
I extended the test that checks for the 3D Model tab |
The 3D model viewer functionality works on my |
Hi @luistoptal praise: I saw that the 3D models tab is now in the style guide (My pipeline is still building, I'll let you know the results from my AWS deployment later) issue: However the contextual help and full screen callbacks still appear inline on Safari (including the example one from the style guide) |
HI @rija
Can you plase add screenshots so I understand better what you see? |
Hi @luistoptal I'll let you know when I get your PR deployed on AWS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @luistoptal,
issue: Having deployed your PR to AWS, I'm now seeing the same problem as @pli888:
CException:
The asset "/gigadb/app/client/js/model-viewer" to be published does not exist.
Neither the web server nor the application server knows about that path, and they probably shouldn't anyway.
suggestion: can you pre-compile the model-viewer code into the top-level js/
directory (it is effectly our dist
directory), so that is can be copied into both the web and application containers?
You would need to load the javascript in the page from that directory.
That's the approach we took for the File Upload Wizard. (that's why you can see fuw-1.0.0.js
in the js
directory, while the javascript source is under gigadb/app/client/web
)
Hi @rija So if I understand correctly, the folder /gigadb/app/client/js/model-viewer is not available in the dockerized production app? will the following work? $jsDir = Yii::getAlias('js/model-viewer'); // using the js folder instead of the gigadb folder
$jsUrl = Yii::app()->assetManager->publish($jsDir); // this will create a dir under the assets folder
Yii::app()->clientScript->registerScriptFile($jsUrl . '/index.js', CClientScript::POS_END, ['type' => 'module']);
?>
<script type="module">
import { modelViewer } from "<?php echo $jsUrl; ?>/index.js";
// code
</script> or must I call the script directly from the js folder without using the php helpers? in which case, I do not understand how the assets folder works |
Hi @luistoptal, I understand your confusion, sorry about that. First, do not use the You are right in realising that the problem is that the path So, given that you are using Yii assets, the correct fix is to make that path available to the dockerized production app. We do so by copying the path into the Dockerfile for the production Web and application container by adding the following line:
into in the same section were the other |
Hi @rija I added the copy command to the docker files as per your suggestion, thanks |
@luistoptal Seems like there are conflicts with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @luistoptal,
praise: Your last change to the dockerfiles fixed the asset publishing error, thanks.
issue: when loading the '.las' model (on any browser) I get the following CSP error the js console:
Content-Security-Policy: The page's settings blocked a worker script (worker-src) at blob:https://rija-staging.gigadb.host/ff12fa1f-6144-4fa4-a046-e14c8902478c from being executed because it violates the following directive: "child-src <https://www.protocols.io>](https://www.protocols.io) <https://hypothes.is>](https://hypothes.is) <https://www.rosaceae.org>](https://www.rosaceae.org) <https://sketchfab.com>](https://sketchfab.com) <https://codeocean.com>](https://codeocean.com) <https://tumormap.ucsc.edu>](https://tumormap.ucsc.edu)"
and the model-viewer shows that error:
Error: Failed to load worker las (#1 of 3) from https://unpkg.com/@loaders.gl/[email protected]/dist/las-worker.js.
suggestion: It sounds like there is a missing directive, maybe you could add a
; worker-src 'self' blob:
at the end (but within the double-quote) of the two lines starting with add_header Content-Security-Policy
and add_header Content-Security-Policy-Report-Only
respectively.
and I think we may also need to add https://unpkg.com
to the script-src
directive on both lines as it is not listed there.
Hi @rija I updated the nginx server config as you suggested |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @luistoptal,
praise: the functionality now works for me in all web browsers
praise: I can see how ops/scripts/set_env_vars.sh
can be useful and it's great a mention of it has been added in the docs
nitpick: I feel like the .gitlab-env-vars.example
example file should go in ops/configuration/variables
with the other variables related example/sample files
Hi @rija I relocated the example file as you suggested |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @luistoptal,
based on the latest change, I'm happy to approve this PR
Hi @luis,
Regarding this script which aims to set up variables for staging and live deployment:
suggestion:(non-blocking) For var |
@kencho51 I applied your suggestions, thanks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
praise: Functionality is now working on my staging and dev environments.
praise: New code looks good including new set_env_vars.sh
script.
Happy to approve.
when deploying, will need to run the following query:
|
Pull request for issue: #2054
This is a pull request for the following functionalities:
How to test?
The following steps describe how I test this widget locally (if you know of a better way, please be my guest and I would love to know 🙂):
You can test error states if you repeat the above process by adding a file that is not a valid 3d model or not a LAS, STL, PLY or OBJ file (or you can just add a
throw new Error('Ooops')
in the line beforeawait loadModel(file);
)Example of error message:
How have functionalities been implemented?
3D models were previously visualized within an iframe taking a sketchfab url as input. This PR gets rid of the sketchfab iframe and replaces it with a JS widget that makes use of the three.js library to load and display an interactive 3D model
The main requirement is to load STL and OBJ file formats, and also (less common) PLY and LAS
Different options to locally load the model were considered (refer to the original ticket for some). I decided to use three.js because:
Other options I checked had very low or null adoption and / or did not fully cover the use case. I opted for the widely adopted solution.
The changes can be grouped as follows:
protected/js/model-viewer
protected/views/shared/_model_viewer.php
renders the html for the widget, and loads the necessary scripts;head
as a import map. That way, the three.js library can be imported as a module in the widget scriptsYii::app()->assetManager->forceCopy = YII_DEBUG;
makes sure the assets are rebuilt and not cached in development (NOTE: I am unclear on whether this targets specifically local dev, is this the correct solution? If this is a blocker, this line can be removed, but I found it necessary to add this line during local dev)protected/views/dataset/view.php
. This page contains a switch statement that renders elements such an iframe depending on the external link types. In the switch statement, the links are handled one by one. In the case of 3D models, I deleted that case from the switch statement, and passed them to the partial asdata
property. Note that I had to do this because the partial, rather than handling individual links one by one, takes them all to build a select input from which to select the model to loadless/modules/model-viewer.less
takes care of all the styles related to the viewerThat covers all the changes outside of the
protected/js/model-viewer
folder, now related to the widget itselfmodelViewer
function and dig deeper only if curious about implementation detailsmodelViewer
connects the two modules and initializes themAny issues with implementation?
isProduction
value inprotected/js/model-viewer/helpers/logger.js
Any changes to automated tests?
All tests pass