-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsampleShadingNetwork.py
77 lines (59 loc) · 1.85 KB
/
sampleShadingNetwork.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
70
71
72
73
74
75
76
77
# http://mayastation.typepad.com/maya-station/2011/03/how-to-sample-a-3d-texture.html
# getMeshData.py
if 'includeScript' not in locals():
def includeScript(path, cwd=''):
exec (open(cwd + path, 'r').read(), globals())
# includes
includeScript('laserMayaImports.py', '/Users/laserstorm/MayaUsefulScripts/')
includeScript('laserOpenMayaImports.py', '/Users/laserstorm/MayaUsefulScripts/')
# example that samples a 3D marble texture at the location of a sphere
import maya.OpenMaya as OpenMaya
import maya.OpenMayaRender as OpenMayaRender
#
#
def sampleShadingNetworkAtPoints(nodeAttr, points):
numSamples = len(points)
pointArray = points;
pointArray = OpenMaya.MFloatPointArray()
pointArray.setLength(numSamples)
refPoints = OpenMaya.MFloatPointArray()
refPoints.setLength(numSamples)
for i, point in enumerate(points):
location = OpenMaya.MFloatPoint(point[0], point[1], point[2])
pointArray.set(location, i)
refPoints.set(location, i)
# but we don't need these
useShadowMap = False
reuseMaps = False
cameraMatrix= OpenMaya.MFloatMatrix()
uCoords= None
vCoords= None
normals= None
tangentUs= None
tangentVs= None
filterSizes= None
# and the return arguments are empty....
resultColors = OpenMaya.MFloatVectorArray()
resultTransparencies = OpenMaya.MFloatVectorArray()
# sample the node network
OpenMayaRender.MRenderUtil.sampleShadingNetwork(
nodeAttr,
numSamples,
useShadowMap,
reuseMaps,
cameraMatrix,
pointArray,
uCoords,
vCoords,
normals,
refPoints,
tangentUs,
tangentVs,
filterSizes,
resultColors,
resultTransparencies )
# return formatted sampled colours
return resultColors
def sampleShadingNetwork(nodeAttr, points):
c = sampleShadingNetworkAtPoints(nodeAttr, points)
return [om.MVector(c[i].x, c[i].y, c[i].z) for i in range(c.length())]