-
Notifications
You must be signed in to change notification settings - Fork 520
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
Embedding 1.6.1 #343
Comments
@abudden Thanks for the information. Things have changed over the last few years so issues during reintegration should be expected. For issue #1, the canvas for LightGL is set to the size of the HTML element. I would guess that the element name has changed, and the HTML of your page needs to adjust. You might try this again. For issue #2, the code is interesting. I didn’t know the pixel ratio was used. I’m not sure it would be necessary but maybe Mark knows a little more. For issue #3, this code change might be a better solution. How about submitting a patch to opt.js? |
Hello @abudden , very sorry for the inconveniences !
1 - this is sadly a generic issue with canvas elements + webgl, (implicit size vs container vs px size) , it tends to be heavily dependent on the wrapper element : does it have an absolute or relative size ? |
Hi Mark - @kaosat-dev - can you give more details about this conversion? Specifically, what is the export of the module? And how will |
@danmarshall not 100% sure yet, but there will not be breaking changes, it will likely be something like exposing the various sub folders here in src/ (like cli, core, etc) as independant packages that will be used by the main UI |
@danmarshall Are you thinking of a similar functionality for your library/web? If so, how would you like to use it? |
@danmarshall yes that is the correct topic ... annd you might be interested in this here : https://github.com/jscad/jscad-desktop/blob/master/src/core/scripLoading.js#L75 I think there might be a way to do something very similar in the browser, stay tuned! |
@kaosat-dev that is really cool - you are loading a module from a string ??? Nice! I have a conversion script that takes a .jscad file from the disk, and creates a module on the disk. The module is just a folder with 2 files in it: Once it is a module on the disk it can be browserified or, checked into GitHub, published to NPM etc. I could generalize this script if you might find it useful. |
Very cool @danmarshall ! My brain is completely fried right now, but I'll take it for a spin first thing tomorrow :) |
@danmarshall we really need to talk, pinged you on hangouts :) |
I've used openjscad as an embedded feature on my website for a number of years, but the version I was using was very old (I'm not sure which one, but here's a link to the source - it has a couple of small modifications for viewer size control). Examples of the embedded versions using the old openjscad are Grinder Gauges and Lathe Threading Gauges.
I'm now using 1.6.1 on this page, but getting it working took me quite a lot of hours and was very frustrating.
Expected Behaviour
I expected to be able to embed openjscad 1.6.1 on a website and customise settings such as whether the "plate" or the axes are shown. I also expected the size of the
viewerContext
to affect the size of the canvas and not for it to be made about 25% wider and only 13 pixels high.Actual Behaviour - First Problem
When I set up the openjscad 1.6.1 viewer (
dist/opt.js
) on my web server, the canvas wasn't viewable. After a lot of hacking around, I found thatLightGLEngine.prototype
'sinit()
declaration wasn't doing what I would expect it to do. This is the patch I applied - the originalthis.containerEl.width
was returningundefined
. I initially changed it tothis.containerEl.style.width
but this didn't seem to work (maybe something to do withcontainerEl
having it's width set to100%
rather than apx
value inProcessor.createElements
?)Actual Behaviour - Second Problem
I also had a problem with the
resizeCanvas
function as it was taking my fixed pixel size (690 pixels in this case) and multiplying it by 1.25 as that was what Chrome was returning as thedevicePixelRatio
. I fixed this by forcingdevicePixelRatio
to be 1. Now I must admit that this was done at the same time as the above, so it could be that fixing the one above makes the following unnecessary, but I'm happy with it at the moment and don't want to break my working version!Actual Behaviour - Third Problem
As I was reading
opts.js
, I saw a comment in the Viewer function: "see the defaults method on how to change these". As I was looking to change the settings, I went to the defaults method, but was none the wiser as it wasn't at all clear. I'm sure I could hack the code and change the defaults, but I hoped this would be more of a library and I could have a single instance ofopts.js
on my web server and adjust the settings on each page that has a model. After many hours of searching, I gave up in this and did the following hacks in order to make it possible:Then in my main html file, I added:
I'm sure there must be a better way of doing this, but
Viewer
isn't accessible outside the script (due to thebrowserify
magic) and I couldn't find any documentation anywhere on how to do this.Please accept my apologies if I've been missing a really obvious wiki page that explains all of this.
Specifications
The text was updated successfully, but these errors were encountered: