CadQuery / sphinxcadquery

An extension to visualize CadQuery 3D files in your Sphinx documentation
BSD 3-Clause "New" or "Revised" License
13 stars 4 forks source link

Automatically resize grid according to the model size #12

Open Peque opened 4 years ago

Peque commented 4 years ago

Right now the grid is defined with its size and number of divisions.

While this is fine and should be kept as a possibility, the default should set a grid with a size double the longest dimension of the displayed model.

garrlker commented 4 years ago

I'd like to try my hand at this!

Peque commented 4 years ago

Great! :blush:

shimwell commented 3 years ago

Perhaps it would also be nice to have the option to not include the grid at all

Peque commented 3 years ago

@Shimwell Yeah! :+1:

shimwell commented 3 years ago

Does this approach sound ok to you @Peque ?

make another variable called raw_gridless_html_template which is the same as raw_html_template but misses the parent.gridsize and griddivisions parts

then add an if statement to the run function and if gridsize and griddivisions are not specified in the user options then make use of the raw_gridless_html_template

Peque commented 3 years ago

@Shimwell So I guess you are suggesting that, by default, no grid should be displayed (unless the user defines gridsize).

I think I would rather leave the default behavior as-is (i.e.: show a grid).

So, how could we disable the grid? Instead of adding a new parameter, I'd say gridsize=0 should disable the grid. Maybe an if in the main.js:init() function to check if gridsize is greater than 0?

shimwell commented 3 years ago

That sounds better

shimwell commented 3 years ago

Changing this

https://github.com/Peque/sphinxcadquery/blob/917dedfe0dd7a4aae092922b1a3c0f323c099dc4/sphinxcadquery/sphinxcadquerystatic/main.js#L143

to this appears to work for me

        if ( gsize > 0 ){
            var grid = new TranslucentGrid( gsize, gdivs, 0x888888, 0xdddddd, 0.6, );
        }
Peque commented 3 years ago

@Shimwell What about the references to grid just bellow? Don't they throw an error?

https://github.com/Peque/sphinxcadquery/blob/917dedfe0dd7a4aae092922b1a3c0f323c099dc4/sphinxcadquery/sphinxcadquerystatic/main.js#L145-L147

Maybe put all those lines inside the if clause? (from the var grid declaration to the scene.add(grid) call).

shimwell commented 3 years ago

Yep you are right. I was just testing it worked with out the grid

I can make a PR for your consideration

shimwell commented 3 years ago

Just to get this issue back on track I wanted to mention that Cadquery has a bounding box that can be used to find the shape size in x,y,z https://cadquery.readthedocs.io/en/latest/classreference.html?highlight=boundingbox#cadquery.Shape.BoundingBox