-
Notifications
You must be signed in to change notification settings - Fork 2
/
positionToVelocity.py
69 lines (60 loc) · 2.08 KB
/
positionToVelocity.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
'''..................................................................................................
Author: Diego Inácio
GitHub: github.com/diegoinacio
Date: JULY/29/2013
.....................................................................................................
This is a very simple tool to creates a velocity point attribute from position differentiation.
To create this tool just follow the next steps:
1 - Create new operator... (File/New Operator Type...);
2 - Put a operator name and a operator label as you want;
3 - Select "Python Type" on Operator Style;
4 - On Network Type, select "Geometry Operator"(this is a very important step!!! pay attention =));
5 - Save where you want; (do not forget to put ".otl" extension, not ".py")
6 - On Type Properties window, in Basic tab, set to 2 a minimum and maximum inputs
6 - In Code tab, paste the code below.
If you have any comments send to: diegodci@gmail.com
Thank you! :D
..................................................................................................'''
###################
# Node initiation #
###################
node = hou.pwd()
geoA = node.geometry()
geoB = node.inputs()[1].geometry()
#############
# Functions #
#############
def makeTemplate():
'''
Create node parameters
'''
pGroup = hou.ParmTemplateGroup()
mult = hou.FloatParmTemplate('mult', 'Multiply', 1, (1.0, 0.0, 0.0), 0.0, 4.0)
pGroup.append(mult)
node.setParmTemplateGroup(pGroup)
def difference(v1, v2):
'''
Calculates a derivative differentiation between two vectors
'''
dx = (v2[0] - v1[0])*mult
dy = (v2[1] - v1[1])*mult
dz = (v2[2] - v1[2])*mult
d = (dx, dy, dz)
return d
########
# Main #
########
makeTemplate()
pointsA = geoA.points()
pointsB = geoB.points()
mult = node.parm('mult').eval()
if not geoA.findPointAttrib('v'):
try:
geoA.addAttrib(hou.attribType.Point, 'v', (0.0, 0.0, 0.0))
except:
None
for i in range(len(pointsA)):
pa = pointsA[i].attribValue('P')
pb = pointsB[i].attribValue('P')
v = difference(pa, pb)
pointsA[i].setAttribValue('v', v)