Closed abudden closed 5 years ago
@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 ! It is true that the current 'pre-built's are not really thought out for customisation: this will change in the very near future: we are currently working on a set of 'reusable/embeddable' pieces namely:
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 ?
2 - PixelRatio use is necessary, and normally webgl resolution tends to be off if it is not used, but it should still be user settable , so I'll add that to the new viewer
3 - As opts.js is a prebuilt file, it is not possible to patch it directly, but it should be possible to insert such functions outside the browserify
scope .
- broken out 'core' of openjscad to convert scripts to CSG/CAG
Hi Mark - @kaosat-dev - can you give more details about this conversion? Specifically, what is the export of the module? And how will getParameterDefinitions()
be exported?
@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?
@z3dev - yes that's what I'm thinking. But now that I'm re-reading this I think I had it confused with something else. I was thinking of "conversion" of jscad to commonjs. Which I suppose is already being discussed in #245 ?
@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 loads either jscad code as common.js modules OR creates a virtual common.js module for jscad scripts which are not using it explicitly :)
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: package.json
and index.js
. The index.js is created from a template. All of the jscad code is in one file thanks to Includify :)
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 :) ok so this is very interesting, if I get this right it converts a current 'vanilla' jscad file into a common.js module : that could be very handy as a tool to make it easier for people to publish their current script to github/npm as common.js :)
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