@hrgdavor said in Click to item for Callback/Event functionality:
Said like that it is not too hard but it opens a pandora box and a can of worms.
You call them worms, somebody else calls it Pasta.
who receives the callback,
The name of the callback-function would be passed into the dictionary. So specifically, it has to be supplied by the Creator.
Eg:
return [
[colorize([0.65, 0.25, 0.8], outer),{'onclick':outerclick}],
colorize([0.7, 0.7, 0.1], inner),
]
do you need also moseover event
Probably. Somebody is going to ask for it. It might look like this:
[ [colorize([0.7, 0.7, 0.1], inner],{'mouseover':'innerhover'}]),
how do you highlight the selected element ?
The caller can do it in the callback. For example with the built in method 'colorise'. A reference to the object is passed to the callback.
what types of highlights would you need
Only existing JSCAD CSG (modelling) methods such as Transform (make it bigger), colorize (change color) etc.
what would you do with the selected item afterwards
Nothing - leave the object changed. Konva is another 2D JS framework and they have all the events worked out. If the item needs to be deselected if another item is clicked, that can be done in the callback code.
index is fragile, objects should have a unique id for callback
Most callbacks (for eg on Konva) give a pointer/reference to the object for the callback. ie
function outerclick(obj) {
return(colorize([0.15, 0.35, 0.33], obj))
}
script is in the worker, renderer is on main thread
ok
how to send granular updates instead of re-render whole script (exponentional complication)
Just update the single object, and then do a refresh. On Konva for example, you have to update the Frame-Buffer yourself to see the change. But their use case is complex.
function outerclick(ref) {
return(colorize([0.15, 0.35, 0.33], ref))
}
@z3dev said in Click to item for Callback/Event functionality:
@DavidLyon66 The design is assembled via a call to main(), which can accept a single dictionary of parameters (This is what happens for the parameters). The interactive parameters are converted to a dictionary.
That makes it easier to specify the name of a callback function. Just add it to the dictionary.
It might be worth looking at the Solidworks Animator. I was shown it by a CAD Operator at a place that I worked at once where they used it to show a machine design to a client to help motivate them to pay for the job.
https://www.youtube.com/watch?v=CwklwnqzbVU
Adding a Timeline isn't as hard as it seems. I'm not asking for it. I'm only mentioning it as this is the complete use-case. To be able to watch some sort of CAD Design in operation or action. Which is often what the client wants.
i don't need the animation in my use case.