# HG changeset patch
# User glarrain
# Date 1368148952 14400
# Branch dev
# Node ID 7e82277e482104b2fcb34fb2e01c3658d9d39724
# Parent 17e0d3162fb2cc7a2ce2b1b3f130cb820a888fe0
collison.base: created HeightfieldTrimesh by splitting Trimesh, renaming
function 'get_heightfield_faces' to 'calc_faces'.
diff git a/ars/model/collision/base.py b/ars/model/collision/base.py
 a/ars/model/collision/base.py
+++ b/ars/model/collision/base.py
@@ 273,10 +273,30 @@
super(Trimesh, self).__init__()
@staticmethod
 def get_heightfield_faces(num_x, num_z):
 """Creates the faces corresponding to a heightfield size 'num_x' by
 'num_z'. Faces are triangular, so each is composed by 3 vertices."""
+ def swap_faces_indices(faces):
+ """Faces had to change their indices to work with ODE. With the initial
+ get_faces, the normal to the triangle defined by the 3 vertices pointed
+ (following the righthand rule) downwards. Swapping the third with the
+ first index, now the triangle normal pointed upwards."""
+ new_faces = []
+ for face in faces:
+ new_faces.append((face[2], face[1], face[0]))
+ return new_faces
+
+
+class HeightfieldTrimesh(Trimesh):
+
+ def __init__(self, space, num_x, num_z, vertices):
+ faces = self.calc_faces(num_x, num_z)
+ super(HeightfieldTrimesh, self).__init__(space, vertices, faces)
+
+ @staticmethod
+ def calc_faces(num_x, num_z):
+ """Create the faces corresponding to a heightfield size 'num_x' by
+ 'num_z'. Faces are triangular, so each is composed by 3 vertices.
+
+ """
# index of each square is calculated because it is needed to define faces
indices = []
@@ 316,18 +336,6 @@
return faces
 @staticmethod
 def swap_faces_indices(faces):
 """Faces had to change their indices to work with ODE. With the initial
 get_faces, the normal to the triangle defined by the 3 vertices pointed
 (following the righthand rule) downwards. Swapping the third with the
 first index, now the triangle normal pointed upwards."""

 new_faces = []
 for face in faces:
 new_faces.append((face[2], face[1], face[0]))
 return new_faces

#==============================================================================
# Basic Shapes
#==============================================================================