# Commits

committed 5387dda

model.geometry.shapes.Trimesh: new swap_faces_indices method; get_faces returned faces indices are no lorger composed randomly, because it didn't help in any way

• Participants
• Parent commits 3d1de89
• Branches trimesh-floor

# File ars/model/geometry/shapes.py

` 		self._inner_object = ode.GeomTriMesh(tm_data, space.get_inner_object())`
` `
` 	@staticmethod`
`-	def get_faces(num_x, num_y):`
`+	def get_faces(num_x, num_z):`
` 		"""`
`-		Copied from:`
`+		Based on:`
` 		Edward Dale - Snowballs: An experiment in Winter frivolity (2006).`
` 		http://scompt.com/files/cg2/final.pdf`
` 		`
` 		method chooses 3 vertices out of each 4 to make a face and the other set to make`
` 		another triangular face. This is done randomly to eliminate artifacts.`
` 		"""`
`-		faces=[]`
`-		for y in range(num_y-1):`
`-			for x in range(num_x-1):`
`-				one = (num_x*y)+x`
`-				two = (num_x*y)+x+1`
`-				three = (num_x*(y+1))+x`
`-				four = (num_x*(y+1))+x+1`
`-				faces += choice( ( [( three,two,one ),( three,four,two )],`
`-								[( four,two,one ), ( three,four,one )] ) )`
`+		#TODO: make it work OK when num_x != num_z`
`+		faces = []`
`+		for z in range(num_z - 1):`
`+			for x in range(num_x - 1):`
`+				one = (num_x * z) + x`
`+				two = (num_x * z) + x + 1`
`+				three = (num_x * (z + 1)) + x`
`+				four = (num_x * (z + 1)) + x + 1`
`+				#===============================================================`
`+				# faces += choice((`
`+				#				[(three,two,one), (three,four,two)],`
`+				#				[(four,two,one), (three,four,one)]`
`+				#				))`
`+				#===============================================================`
`+				# randomness does not seem to help in any way`
`+				faces += [( three,two,one ),( three,four,two )] #( three,two,one )`
` 		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 `
`+		right-hand 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`
`+`
` 	#===========================================================================`
` 	# def attach_body(self, body):`
` 	#	raise Exception('Trimesh shapes are not yet allowed to have a body attached')`