Skip to content
Snippets Groups Projects
Commit 8601eb82 authored by Joshua Steer's avatar Joshua Steer
Browse files

Functionality to fix normals through flipping

parent a0a23105
No related branches found
No related tags found
No related merge requests found
......@@ -100,6 +100,7 @@ class AmpObject(trimMixin, smoothMixin, analyseMixin, visMixin):
if unify is True:
self.unifyVert()
# Call function to calculate the edges array
# self.fixNorm()
if struc is True:
self.calcStruct()
self.values = np.zeros([len(self.vert)])
......@@ -243,6 +244,18 @@ class AmpObject(trimMixin, smoothMixin, analyseMixin, visMixin):
mag = np.linalg.norm(norms, axis=1)
self.norm = np.divide(norms, mag[:,None])
def fixNorm(self):
r"""
Fix normals of faces so they all face outwards
"""
fC = self.vert[self.faces].mean(axis=1)
cent = self.vert.mean(axis=0)
polarity = np.sum(self.norm * (fC-cent), axis=1) < 0
if polarity.mean() > 0.5:
self.faces[:, [1,2]] = self.faces[:, [2,1]]
self.calcNorm()
if hasattr(self, 'vNorm'): self.calcVNorm()
def calcVNorm(self):
"""
Function to compute the vertex normals based upon the mean of the
......@@ -372,7 +385,6 @@ class AmpObject(trimMixin, smoothMixin, analyseMixin, visMixin):
self.translate(T)
@staticmethod
def rotMatrix(rot, ang='rad'):
r"""
......@@ -406,3 +418,19 @@ class AmpObject(trimMixin, smoothMixin, analyseMixin, visMixin):
[0, 0, 1]])
R = np.dot(np.dot(Rz, Ry), Rx)
return R
def flip(self, axis=1):
r"""
Flip the mesh in a plane
Parameters
----------
axis: int, default 1
The axis in which to flip the mesh
"""
self.vert[:, axis] *= -1.0
# Switch face order to normals face same direction
self.faces[:, [1, 2]] = self.faces[:, [2, 1]]
self.calcNorm()
self.calcVNorm()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment