Interacting with the mouse with an OpenSCAD model

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

Interacting with the mouse with an OpenSCAD model

Peter Falke
How to do it:

The lexer adds to every call of a primitive a token with a index number and the line number of the editor. They act as a pseudo-color. When drawing the preview (F5) a second (non-visibale) view is drawn, where every primitive is drawn with its pseudo-color. Now, when you click on the model with the mouse, simply look up the color under the pointer in the pseudo-view, and decode the editor line number from it.
Now you could:
- jumb in the file to the selected line number
- open a new window with the parameter of that primitive and change them right there

TakeItAndRun






_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Interacting with the mouse with an OpenSCAD model

wmartin
Yes! That would be useful, to tweak interactively.

On 03/24/2015 10:34 AM, Peter Falke wrote:
How to do it:

The lexer adds to every call of a primitive a token with a index number and the line number of the editor. They act as a pseudo-color. When drawing the preview (F5) a second (non-visibale) view is drawn, where every primitive is drawn with its pseudo-color. Now, when you click on the model with the mouse, simply look up the color under the pointer in the pseudo-view, and decode the editor line number from it.
Now you could:
- jumb in the file to the selected line number
- open a new window with the parameter of that primitive and change them right there

TakeItAndRun







_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Interacting with the mouse with an OpenSCAD model

clothbot
In reply to this post by Peter Falke
I forget if it's an OpenGL GLU or GLUT API feature, but there's one (set) that lets you "tag" objects with an integer number. When a collision/mouse click is detected, the integer is returned.

It'll get moderately complicated when multiple files are involved via include, but not insurmountable.

Andrew

Sent from myBrain

> On Mar 24, 2015, at 13:34, Peter Falke <[hidden email]> wrote:
>
> How to do it:
>
> The lexer adds to every call of a primitive a token with a index number and the line number of the editor. They act as a pseudo-color. When drawing the preview (F5) a second (non-visibale) view is drawn, where every primitive is drawn with its pseudo-color. Now, when you click on the model with the mouse, simply look up the color under the pointer in the pseudo-view, and decode the editor line number from it.
> Now you could:
> - jumb in the file to the selected line number
> - open a new window with the parameter of that primitive and change them right there
>
> TakeItAndRun
>
>
>
>
>
> _______________________________________________
> OpenSCAD mailing list
> [hidden email]
> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Interacting with the mouse with an OpenSCAD model

Peter Falke
I asked on the IRC channel of #opengl:

Pete____ Is there a command in opengl that lets me tag every drawn object with a number, so that a mouseover would return this number?
<a href="ircs://freenode/Bloodust,isnick" class="">Bloodustno but you can do this yourselfPete____how?<a href="ircs://freenode/Bloodust,isnick" class="">Bloodustdraw your scene to FBO and dedicate one texture as 'id' texture<a href="ircs://freenode/Bloodust,isnick" class="">Bloodustthen in fragment shader write the id to it<a href="ircs://freenode/Bloodust,isnick" class="">BloodustPete____ you have no idea what I just said, do you?Pete____Im reading what a fbo is ...<a href="ircs://freenode/Bloodust,isnick" class="">Bloodustframebuffer object<a href="ircs://freenode/Bloodust,isnick" class="">Bloodustused when RTT AKA render to texturePete____So I basically draw a second view that is colored with the id number?<a href="ircs://freenode/kyle1320,isnick" class="">kyle1320Just checking, would it work to multiply a vector in worldspace by my perspective matrix, then check if it's within -1, 1 on each axis to determine whether it would be on-screen?<a href="ircs://freenode/sillesta,isnick" class="">sillestaPete____: each object would be drawn with a unique color, yes<a href="ircs://freenode/Bloodust,isnick" class="">BloodustPete____ sillesta no you dont have to draw a second time/view<a href="ircs://freenode/Bloodust,isnick" class="">Bloodust"normally" you would have a single RGBA texture attached to your FBO to save color<a href="ircs://freenode/sillesta,isnick" class="">sillestaBloodust: how would you separate different objects?<a href="ircs://freenode/Bloodust,isnick" class="">Bloodustand in this case you would have another texture, possibly a single R8 or R16 texture that stores the object IDPete____This doesnt sound to comlicated<a href="ircs://freenode/Bloodust,isnick" class="">Bloodustits very easy if you know how to use FBOsPete____I`ll have a look at the code (OpenSCAD) and see if I can find the RGBA texture ...<a href="ircs://freenode/Bloodust,isnick" class="">Bloodustits possible your code doesnt use an FBO especially if its older softwarePete____It does color and alpha, so it propably needs to have it.<a href="ircs://freenode/Bloodust,isnick" class="">Bloodustnope, doesnt need itPete____Ok, I´ll have a look. Thanks for your help!




2015-03-24 19:58 GMT+01:00 Andrew Plumb <[hidden email]>:
I forget if it's an OpenGL GLU or GLUT API feature, but there's one (set) that lets you "tag" objects with an integer number. When a collision/mouse click is detected, the integer is returned.

It'll get moderately complicated when multiple files are involved via include, but not insurmountable.

Andrew

Sent from myBrain

> On Mar 24, 2015, at 13:34, Peter Falke <[hidden email]> wrote:
>
> How to do it:
>
> The lexer adds to every call of a primitive a token with a index number and the line number of the editor. They act as a pseudo-color. When drawing the preview (F5) a second (non-visibale) view is drawn, where every primitive is drawn with its pseudo-color. Now, when you click on the model with the mouse, simply look up the color under the pointer in the pseudo-view, and decode the editor line number from it.
> Now you could:
> - jumb in the file to the selected line number
> - open a new window with the parameter of that primitive and change them right there
>
> TakeItAndRun
>
>
>
>
>
> _______________________________________________
> OpenSCAD mailing list
> [hidden email]
> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org



--
[hidden email]

P.S. Falls meine E-Mail kürzer ausfällt als Dir angenehm ist:
Ich probiere gerade aus kurze Antworten statt gar keine Antworten zu schreiben.
Wenn Du gerne mehr lesen möchtest, dann lass es mich bitte wissen.

P.S. In case my e-mail is shorter than you enjoy:
I am currently trying short replies instead of no replies at all.
Please let me know, if you like to read more.

Enjoy!

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Interacting with the mouse with an OpenSCAD model

Peter Falke
cut and paste didnt work that great:

draw your scene to FBO and dedicate one texture as 'id' texture

then in fragment shader write the id to it

"normally" you would have a single RGBA texture attached to your FBO to save color

and in this case you would have another texture, possibly a single R8 or R16 texture that stores the object ID

2015-03-24 20:28 GMT+01:00 Peter Falke <[hidden email]>:
I asked on the IRC channel of #opengl:

Pete____ Is there a command in opengl that lets me tag every drawn object with a number, so that a mouseover would return this number?
Bloodustno but you can do this yourselfPete____how?Bloodustdraw your scene to FBO and dedicate one texture as 'id' textureBloodustthen in fragment shader write the id to itBloodustPete____ you have no idea what I just said, do you?Pete____Im reading what a fbo is ...Bloodustframebuffer objectBloodustused when RTT AKA render to texturePete____So I basically draw a second view that is colored with the id number?kyle1320Just checking, would it work to multiply a vector in worldspace by my perspective matrix, then check if it's within -1, 1 on each axis to determine whether it would be on-screen?sillestaPete____: each object would be drawn with a unique color, yesBloodustPete____ sillesta no you dont have to draw a second time/viewBloodust"normally" you would have a single RGBA texture attached to your FBO to save colorsillestaBloodust: how would you separate different objects?Bloodustand in this case you would have another texture, possibly a single R8 or R16 texture that stores the object IDPete____This doesnt sound to comlicatedBloodustits very easy if you know how to use FBOsPete____I`ll have a look at the code (OpenSCAD) and see if I can find the RGBA texture ...Bloodustits possible your code doesnt use an FBO especially if its older softwarePete____It does color and alpha, so it propably needs to have it.Bloodustnope, doesnt need itPete____Ok, I´ll have a look. Thanks for your help!




2015-03-24 19:58 GMT+01:00 Andrew Plumb <[hidden email]>:
I forget if it's an OpenGL GLU or GLUT API feature, but there's one (set) that lets you "tag" objects with an integer number. When a collision/mouse click is detected, the integer is returned.

It'll get moderately complicated when multiple files are involved via include, but not insurmountable.

Andrew

Sent from myBrain

> On Mar 24, 2015, at 13:34, Peter Falke <[hidden email]> wrote:
>
> How to do it:
>
> The lexer adds to every call of a primitive a token with a index number and the line number of the editor. They act as a pseudo-color. When drawing the preview (F5) a second (non-visibale) view is drawn, where every primitive is drawn with its pseudo-color. Now, when you click on the model with the mouse, simply look up the color under the pointer in the pseudo-view, and decode the editor line number from it.
> Now you could:
> - jumb in the file to the selected line number
> - open a new window with the parameter of that primitive and change them right there
>
> TakeItAndRun
>
>
>
>
>
> _______________________________________________
> OpenSCAD mailing list
> [hidden email]
> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org



--
[hidden email]

P.S. Falls meine E-Mail kürzer ausfällt als Dir angenehm ist:
Ich probiere gerade aus kurze Antworten statt gar keine Antworten zu schreiben.
Wenn Du gerne mehr lesen möchtest, dann lass es mich bitte wissen.

P.S. In case my e-mail is shorter than you enjoy:
I am currently trying short replies instead of no replies at all.
Please let me know, if you like to read more.

Enjoy!



--
[hidden email]

P.S. Falls meine E-Mail kürzer ausfällt als Dir angenehm ist:
Ich probiere gerade aus kurze Antworten statt gar keine Antworten zu schreiben.
Wenn Du gerne mehr lesen möchtest, dann lass es mich bitte wissen.

P.S. In case my e-mail is shorter than you enjoy:
I am currently trying short replies instead of no replies at all.
Please let me know, if you like to read more.

Enjoy!

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Interacting with the mouse with an OpenSCAD model

kintel
Administrator
On Mar 24, 2015, at 15:31 PM, Peter Falke <[hidden email]> wrote:

> draw your scene to FBO and dedicate one texture as 'id' texture
>
> then in fragment shader write the id to it
>
> "normally" you would have a single RGBA texture attached to your FBO to save color
>
> and in this case you would have another texture, possibly a single R8 or R16 texture that stores the object ID
>
That looks like the modern way of doing it.
The question is: What is the minimum version of OpenGL we should require?
What you describe above is available only on OpenGL 3-class hardware.
OpenGL 2 extensions for this exists, depending on drivers and hardware capability, see e.g. https://www.opengl.org/registry/specs/ARB/framebuffer_object.txt

For OpenGL <=2, there is glSelectBuffer, which offers something similar, see e.g. https://www.opengl.org/registry/specs/ARB/framebuffer_object.txt

 -Marius


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Interacting with the mouse with an OpenSCAD model

xenomachina
On Tue, Mar 24, 2015 at 12:44 PM, Marius Kintel <[hidden email]> wrote:
For OpenGL <=2, there is glSelectBuffer, which offers something similar, see e.g. https://www.opengl.org/registry/specs/ARB/framebuffer_object.txt

I think you had a copy-paste error there? You posted the same link twice.

Here's a page with some info about the "classic" way of picking/selecting in OpenGL:


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Interacting with the mouse with an OpenSCAD model

kintel
Administrator
On Mar 24, 2015, at 16:02 PM, Laurence Gonsalves <[hidden email]> wrote:

> I think you had a copy-paste error there? You posted the same link twice.
>
> Here's a page with some info about the "classic" way of picking/selecting in OpenGL:
>
>      https://www.opengl.org/archives/resources/faq/technical/selection.htm

Wops, I meant http://www.glprogramming.com/red/chapter13.html

 -Marius


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Interacting with the mouse with an OpenSCAD model

Greg Frost
Would this mean that you could only select positive objects? Wouldn't we also want to manipulate negative objects (I.e parts difference()ed from others?). Also, which object would be selected when hovering over the result of an intersection()?

> On 25 Mar 2015, at 6:34 am, Marius Kintel <[hidden email]> wrote:
>
>> On Mar 24, 2015, at 16:02 PM, Laurence Gonsalves <[hidden email]> wrote:
>>
>> I think you had a copy-paste error there? You posted the same link twice.
>>
>> Here's a page with some info about the "classic" way of picking/selecting in OpenGL:
>>
>>     https://www.opengl.org/archives/resources/faq/technical/selection.htm
>
> Wops, I meant http://www.glprogramming.com/red/chapter13.html
>
> -Marius
>
>
> _______________________________________________
> OpenSCAD mailing list
> [hidden email]
> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Interacting with the mouse with an OpenSCAD model

kintel
Administrator

On Mar 24, 2015, at 16:12 PM, Greg Frost <[hidden email]> wrote:

> Would this mean that you could only select positive objects? Wouldn't we also want to manipulate negative objects (I.e parts difference()ed from others?). Also, which object would be selected when hovering over the result of an intersection()?
>
All negative objects are rendered as well, so this is mostly a UI issue in terms of how to guide selection.

 -Marius


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Interacting with the mouse with an OpenSCAD model

MichaelAtOz
Administrator
Just make sure you don't limit 'material' handling for future multi-material/colour production.
Sounds like additional id's can be used tho, so probably OK?

It would also be really good to be able to drag (with a modifier key or maybe middle button) a discrete object and have the translate() modified. Maybe rotate too?? But that is maybe to trad-CAD...
Admin - email* me if you need anything,
or if I've done something stupid...
* click on my MichaelAtOz label, there is a link to email me.

Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work.
Obviously inclusion of works of previous authors is not included in the above.


The TPP is no simple “trade agreement.” Fight it! http://www.ourfairdeal.org/ time is running out!