I created one circle SOP connected to a null SOP which is connected to a geometry COMP. A camera, light and the geometry COMP are connected to a render TOP.
There is also a noise CHOP with three channels tx, ty, tz. This noise is connected to a math chop, which is connected the geometry comp under instances under default instance OP and the channels tx, ty, tz are assigned to translate x, translate y and translate z. The circles are floating on the screen.
There is also a table DAT with the following values:
rgb 001 001 001 001 001 100 100 100 100 100
This table is connected to a datto CHOP, which is connected to the geometry COMP under colour OP with the channels r, g, b. The output is five red and five blue circles that are floating on the screen.
Now, I would like that when I click on the blue circles, they disappear, but not when I click on the red circles. I tried it with a Constant CHOP to control the visibility. I also used a Render Pick CHOP to pick the circles. But it didn’t work. I also tried it with a mousein CHOP, but it didn’t work too.
How can it be made that when a person clicks with the mouse on the blue circles, they disappear, but not when he clicks on the red circles?
The Instancing parameters for translation have an Active parameter which can be driven by values in the same operator as the translate channels.
Also the Render Pick CHOP has a parameter on the “Options” page called Fetch Point Color. and Fetch Instance ID
The Point Color and Instance ID are now reported in the Render Pick CHOP’s callback and here you could check if the color of the picked instance is red and via the Instance ID change values in a Table DAT that are converted to the active channel used on the instancing page.
I found the parameters and set them accordingly as you suggested and also created an active table with the active values and connected it to a datto CHOP. But whenever I try to assign the datto2 to the geometry COMP under instances in the parameter Active, I get an error message that it cannot be found.
the Active parameter, just like the Translate parameters doesn’t take a operator reference but a channel, column, color, or attribute (depending on the op used for instancing).
In my example above I convert the DAT to a CHOP where a channel is expressed by a column in the DAT - same as your conversion for the color. Then the CHOP is merged with the CHOP you use to drive the position (with the tx, ty, and tz channels)
How can it be made that when the blue circles are clicked, they disappear and when the red circles are clicked, they remain (i.e. they do not disappear) ?
surprised that the blue circles don’t disappear when you set alpha to 0. But generally you can work with the active channel instead of changing the color of the picked element. This way they are truly not rendered instead of them just being made transparent.
Some other pointers:
The callback has 3 arguments that are being passed in of which 2 are:
the Render Pick CHOP which you can already access as renderPickOp
so there is no need to set rp = op('renderpick1')
the full event which contains amongst other things instanceId and color
both can be accessed by calling event.instanceId or event.color
Knowing this your callback can look like this:
"""
Render Pick CHOP Callbacks
me - this DAT
renderPickOp - the connected Render Pick CHOP
event - a named tuple with the fields listed below.
eventPrev - a event holding the previous values.
u - The selection u coordinate. (float)
v - The selection v coordinate. (float)
select - True when a selection is ongoing. (bool)
selectStart - True at the start of a selection. (bool)
selectEnd - True at the end of a selection. (bool)
pickOp - Currently picked operator. (OP)
pos - 3D position of picked point. (Position)
texture - Texture coordinate of picked point. (Position)
color - Color of picked point. (4-tuple)
normal - Geometry normal of picked point. (Vector)
depth - Post projection space depth. (float)
instanceId - Instance ID of the object. (int)
"""
from typing import Any
def onEvent(renderPickOp: renderpickCHOP, event: Any, eventPrev: Any):
"""
Called when any passed values have changed.
Turn on the related parameter in the CHOP to retrieve these values.
Args:
renderPickOp: The connected Render Pick CHOP
event: Named tuple with current event values
eventPrev: Named tuple with previous event values
"""
if event.selectStart:
color = event.color
instanceId = event.instanceId
if color == (0,0,1,1):
op('table2')[instanceId+1, 'active'] = 0
return
thank you for the explanation and the new code. I tried several more things, like changing certain parameters and settings of some OPs. Unfortunately, nothing helped. When I click on the blue circles, they still do not disappear.
Do you mind, having a look at my file and checking what the cause might be? I would appreciate it.
ah - there was a sample rate mismatch between the noise with it’s transform channels and the other CHOP with the active channel. You could work around it by setting the Align parameter of the Merge CHOP to “Stretch to First Interval” or just keep the original sample rate on the noise and instead change the Start and End parameter units to samples (it’s the little dropdown menu behind the sliders). Having two different sample rates merging is something that should be avoided if possible as it’s hard to debug.
What was happening:
the Noise CHOP was set to a length of 10 seconds at a sample rate of 1 sample per second resulting in 10 samples but 600 frames (the CHOP’s length at the main timeline’s framerate)
the active channel created via the DAT uses by default the main timeline’s samplerate (60fps) resulting in 10 samples, in 10 frames, in 0.17s
merging the two CHOPs you had correctly chosen to “Resample At First Input Rate” but then the Merge CHOP with it’s default “Automatic” Align parameter setting, most likely first extended the second input to 600 frames (adding 590 values to the end) and then down sampled it to 1 fps in effect collapsing the 600 values down to 10 resulting only in the first sample to ever go down to 0.
Also a slight change but doesn’t change functionality: Instancing can accept CHOPs, DATs, TOPs, SOPs, and POPs as sources, so for the table that saves the colors, the conversion to a CHOP was unnecessary.
thank you for looking through it and your explanation. I appreciate it.
I have changed the materials and adapted the project slightly and everything still works.
I also tried to include audio with an audiofilein CHOP connected to a audiodevout CHOP. Then I tried to write a code so that when the circle instances of geo1 COMP are clicked a short error sound is heard (but they do not disappear as the other circle instances of geo2).
Unfortunately, this doesn’t work. Do you know how this can be accomplished so that when the banana circles are clicked they disappear (this works) but when the butterfly circles are clicked, a short error sound is heard.
I also tried to add a background image behind the circles, but it never worked. Do you know how to add a background image behind the circles in a 3D environment ?
as you are instancing 2 different geometry components, the instancing IDs for each component will restart at 0. Instead of checking for the instance ID, rather differentiate by looking at the event.pickOp member which will tell you if you clicked on a operator in the “geo1” COMP or the “geo2” COMP.
To track these things, you can make use of the debug or print statement and check the output in the Textport. (something like debug(event.pickOp))