Hi!
I want to write an expression for drawing an edge between a point and its nearest neighbor using the Add SOP.
I have a POPnet as input.
Any help would be most welcome!
Thanks!
Gon
edge between nearest pairs
4830 5 0- gonzifroni
- Member
- 29 posts
- Joined: 9月 2007
- Offline
- Soothsayer
- Member
- 874 posts
- Joined: 10月 2008
- Offline
Substract position vector of point one from point two. That gives you the line. To find the closest neighbor, there is a proximity attribute node in the popnet.
Edit: Sorry I didn't read your question carefully. I think you figured out what I said already. I'll see if I can come up with something that can group pairs of points.
Edit: Sorry I didn't read your question carefully. I think you figured out what I said already. I'll see if I can come up with something that can group pairs of points.
--
Jobless
Jobless
- Soothsayer
- Member
- 874 posts
- Joined: 10月 2008
- Offline
Haven't tested it fully but how about something like this:
# This code is called when instances of this SOP cook.
geo = hou.pwd().geometry()
points = geo.points()
# Add code to modify the contents of geo.
lst =
for i in points:
p1 = i.number()
p2 = i.attribValue(“nearest”)
pairs = (p1,p2)
curve = geo.createPolygon()
for j in pairs:
point = geo.createPoint()
point.setPosition(points.position())
curve.addVertex(point)
# This code is called when instances of this SOP cook.
geo = hou.pwd().geometry()
points = geo.points()
# Add code to modify the contents of geo.
lst =
for i in points:
p1 = i.number()
p2 = i.attribValue(“nearest”)
pairs = (p1,p2)
curve = geo.createPolygon()
for j in pairs:
point = geo.createPoint()
point.setPosition(points.position())
curve.addVertex(point)
--
Jobless
Jobless
- gonzifroni
- Member
- 29 posts
- Joined: 9月 2007
- Offline
- Soothsayer
- Member
- 874 posts
- Joined: 10月 2008
- Offline
Try this. I wanted to save the python sop in the file but I always forget how to do it. So you need to copy paste the code into it yourself (red node, right-click>TypeProperties>Code)
# Macha/Soothsayer June, 3, 2010
# drawing lines between pairs of neighbours
# This code is called when instances of this SOP cook.
geo = hou.pwd().geometry()
points = geo.points()
# Add code to modify the contents of geo.
pairs =
for i in points:
p1 = i.number()
p2 = i.attribValue(“nearest”)
pair =
pairs.append(pair)
riap = [ pair, pair ]
if (riap in pairs) != 1:
curve = geo.createPolygon()
for j in pair:
point = geo.createPoint()
point.setPosition(points.position())
curve.addVertex(point)
# Macha/Soothsayer June, 3, 2010
# drawing lines between pairs of neighbours
# This code is called when instances of this SOP cook.
geo = hou.pwd().geometry()
points = geo.points()
# Add code to modify the contents of geo.
pairs =
for i in points:
p1 = i.number()
p2 = i.attribValue(“nearest”)
pair =
pairs.append(pair)
riap = [ pair, pair ]
if (riap in pairs) != 1:
curve = geo.createPolygon()
for j in pair:
point = geo.createPoint()
point.setPosition(points.position())
curve.addVertex(point)
--
Jobless
Jobless
- gonzifroni
- Member
- 29 posts
- Joined: 9月 2007
- Offline
-
- Quick Links