-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sampler.py
57 lines (40 loc) · 1.53 KB
/
Sampler.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
import maya.cmds as cmds
import maya.mel as mel
import random
import itertools as itools
import numpy as np
import sys
# TO DO:
# - Get angle of vertex normals to surrounding face normals
# - How to find best????
class VertexSampler:
def __init__(self, object):
self.object = object
cmds.select(object + ".vtx[*]", r=True)
vertPosTemp = cmds.xform(object + '.vtx[*]', q=True, ws=True, t=True)
self.vertexPositions = zip(*[iter(vertPosTemp)] * 3)
self.vertexNames = self.getVertexNames(object)
def getVertexNames(self,object):
cmds.select(object)
mel.eval("PolySelectConvert 3")
vertList = cmds.ls(sl=1, fl=1)
cmds.select(cl=True)
return vertList
def getVertexWeights(self):
weights = []
for v in self.vertexNames:
# get vertex normal
angle = 360
# get surrounding face normals
# for n in normals:
# faceAngle = angle between vertex normal and n
# if faceAngle < angle:
# angle = faceAngle
weights.append(angle / 360)
def randomSamples(self,numberOfSamples):
return random.sample(set(self.vertexPositions), numberOfSamples)
def randomPercent(self,samplePercent):
numberOfSamples = len(self.vertexPositions) * (samplePercent / 100.0)
return self.randomSamples(int(round(numberOfSamples)))
def uniformSamples(self,numberOfSamples):
return np.random.choice(self.vertexPositions,numberOfSamples)