Particle collision with multiple primitives and changing to 1 colour value upon hit

   2259   2   1
User Avatar
Member
7 posts
Joined: March 2016
Offline
Hi there,

I'm trying to change the colour of a primitive once a particle collides with it….but i don't want to use an attribute transfer because that gives me a gradient of colour on the primitive and i want to change the colour back after it's been hit and have it be a solid colour.
So hit == green (0,1,0)
not hit == red(1,0,0)
Another problem i'm having is when i don't use an attribute transfer and write it in a python sop(code below) i change all the primitives colours in one go rather than individually where the the particle collides with each primitive.

Not sure how to go about this, but here is the file attached.Any help would be much appreciated.

CODE FOR HIT COUNTER AND PRIMITIVE CHANGE COLOUR
node = hou.pwd()
geo = node.geometry()
from hou.session import *

inputs = node.inputs() # bring in city searcher data

pointcolliders = inputs.geometry().points()


ship = geo.prims()
if hou.frame() == 1:
hitCount = 0


for p in pointcolliders:

store = p.attribValue(“hittotal”) # get hittotal attribute from the pop solver
hitCount += store # hitcount += store (to add number of hits to hou.session)
hits = store


green = (0.0,1.0,0.0)
red = (1.0,0.0,0.0)

#change colour of second input so object

for s in ship:

if hits == 1:
s.setAttribValue('Cd', green)
else:
s.setAttribValue('Cd', red)
Edited by 212AA - Aug. 17, 2017 11:59:16

Attachments:
particles hit each prim.hipnc (310.8 KB)

User Avatar
Member
1391 posts
Joined: Dec. 2010
Offline
Never use Python for such these things ,Because it is so slow !

However you can do same thing very easily with hitprim attrbute.

1.Turn on Add Hit Prim Attribute on the POPCollisionDetect
2.Connect a Point Wrangle SOP to your all_ships and use this simple expression for wrangle node :

i@hitprim = @primnum;

3.Append an attribute Copy SOP and connect Point Wrangle SOP to the first input and your particles to the second input
4.Turn on Match by Attribute in the attribute Copy SOP
5. use hitprim as a Attribute to Match

Now you can see the color of each particle will copy to the primitive with exact same hitprim attribute
Edited by Sadjad Rabiee - Aug. 16, 2017 05:23:04
https://www.youtube.com/c/sadjadrabiee [www.youtube.com]
Rabiee.Sadjad@Gmail.Com
User Avatar
Member
7 posts
Joined: March 2016
Offline
thanks so much, that worked Sadjad
  • Quick Links