Closed pamtbaau closed 3 years ago
So, do you have a javascript error in your browser's console ?
As I said in the other issue, the node <div class="online..."
is written with 2 children node at once. From there, you should also have 3 javascript files added to your page (three.min.js
, o3dv.min.js
and 3dviewer.js
). If they aren't loaded or if they fails, it should appear in the Javascript console or the network tab.
(Sorry for misreading your description)
Do you have jquery on your website ? The plugin requires jquery, but since it's loaded by default in my Grav installation, I haven't included it in the required resources. I suspect it would fail to load if you don't have it in your default installation.
Said differently, does it work when you go here ?
The viewer isn't created because assets are never being loaded: onTwigSiteVariables
is fired before onMarkdownInitialized
. See https://learn.getgrav.org/17/plugins/grav-lifecycle
That's not what written here and it works on my site.
In the referred page, onMarkdownInitialized
is 19.2th and onTwigSiteVariables
is 25th.
In your referred page, onTwigSiteVariables
(do not confuse with onTwigInitialized
) seems to happen after running the page processor. The page processor must render markdown (althrough there is no description as to when page.content() is called), I suppose it's done after onTwigInitialized
but before onTwigSiteVariables
You can put a var_dump("markdown")
in onMarkdownInitialized
and var_dump("twig")
in onTwigSiteVariables
to check in which order they are called. On my website, I'm getting:
string(8) "markdown"
string(16) "twigsitevariable"
So it's clearly behaving like expected for me.
Yes, I believe it is working in your env...
Would you mind taking a step back and pretend to be a new user:
user/plugins
viewer3-d
user/pages/03.viewer/default.md
https://blog.cyril.by/en/documentation/3d%20models/filament-detector/SupportFilDet.stl
into folder```3dv SupportFilDet.stl ```
localhost/grav/viewer
If I perform above steps:
<div class="online_3d_viewer"...>
is being created.onTwigSiteVariables
is run before onMarkdownInitialized
onTwigSiteVariables
is run.That's strange. I've started a website like you said and it behaves differently as you said. I don't understand why, but clearly the documentation is wrong here. In the documentation page here it says that onMarkdownInitialized
happens in onPageInitialized
(unconditionally off the cached state of the page) before onTwigSiteVariables
. This is also what's stated in your linked documentation page: onPageInitialized
happens in the page processor (position 10.3), while onTwigSiteVariables
should happen later in position 12.3.1.
I think it's a bug with grav or its documentation. Else, no one can load additional assets required by markdown extensions conditionally (short code or markdown, I don't think it would make a change here).
Obviously I could force loading the assets anywhere (replace the line that read if (isset($this->used) && $this->used)
by if (true)
and it'll work, but that's poor solution since it forces loading threejs library that's huge for all the website's pages.
So, I guess I'll have to fill a bug in Grav's repository here or maybe you know why it's not following the documented lifecycle ?
BTW, it's also requiring to add a media type for STL files in your site, typically like this (in Configuration / Media tab):
Glad you've done the test... I wanted you see for your self which 3 issues (js assets, images, media) were blocking the display of the viewer.
Yes, page Event hooks is misleading and I'm currently in the process of rewriting it. Grav lifecycle is correct and more clear.
You may be misconceiving the aspect of caching used by Grav. Read the bottom of Grav lifecycle
Meaning:
onMarkdownInitialized
, is only called once, when the page has not yet been cached, or the cache has been invalidated. That means that after the first run, your extension won't run again and $this->used
will not be set again.cache_enable: false
in the page on which the viewer needs to be shown.
Because your extension will now be fired every time the page with the viewer is being requested, you can use any event after onMarkdownInitialized
, but before onOutputGenerated
.
Of course, this defies Grav's strength of caching. See below on Shortcodes.Besides the loading of javascript, two other roadblocks were preventing the viewer to be shown:
media.yaml
filemodel='" .$slug . '/' .$Block['src']
to the path of the file e.g. /user/pages/03.viewer/SupportFilDet.stl
. In this case, the file is loaded without intervention of Grav and no media.yaml
change is needed.Final suggestion: Have a look at the Shortcode Core plugin. That is the Grav way of doing it. When using Shortcodes, the cache_enable
trick is no longer needed and the page's content can be efficiently cached. Also, assets are being cached. Quite more efficient...
Thanks for your hints, it's much appreciated!
I think changing the media.yaml
is the only way that would work, since the plugin allows to download the model and as such, the correct mime-type must be set for downloading it. So if I link to the file directly, I think (not tested), that the http server will not send the correct mime-type by itself (I don't think nginx or apache have the mime-type for all supported 3d model file).
Can I change it automatically in my plugin (instead of asking the user to do it manually) ?
How can I specify in my plugin that it depends on the Shortcode Core plugin ?
How can I specify in my plugin that it depends on the Shortcode Core plugin ?
Inside blueprint.yaml
, add something like the following to the dependencies
section:
- { name: shortcode-core, version: '>=5.0.0' }
So if I link to the file directly, I think (not tested)
Test it and you'll know it. "The proof is in the pudding..." (not the mind)
Test it and you'll know it
Tested and it does not work. Got Content-Type: application/vnd.ms-pki.stl
and not model/stl
as expected. I don't know where the former is coming from (I don't manage the http server on my test server), but it's clearly incorrect.
I'm closing this now, since I'll remove this repository in favor of shortcode's version here
@X-Ryl669, I've taken the liberty to test-run your plugin. In short: I cannot get it to work...
I proceeded as follows:
$ cd user/plugins
$ mkdir viewer3-d
$ cd viewer3-d
$ git clone https://github.com/X-Ryl669/grav-plugin-viewer3-d .
user/pages/03.viewer/default.md
https://blog.cyril.by/en/documentation/3d%20models/filament-detector/SupportFilDet.stl
into folderlocalhost/grav/viewer
<div class="online_3d_viewer"...>
is being created, containing two other divs but all are empty.Other remarks:
```3dv
to generate the code to view the 3D model. IMHO adding a 3D viewer to the page is not really what block code fences are meant to be used for.