Primitive representing a triangle solid mesh.
| 477 | |
| 478 | # === Triangle Primitive === |
| 479 | class TrianglePrim(Primitive): |
| 480 | """ |
| 481 | Primitive representing a triangle solid mesh. |
| 482 | """ |
| 483 | def __init__(self, points=None, colors=None): |
| 484 | super(TrianglePrim, self).__init__() |
| 485 | self._points = list() # control points |
| 486 | self._drawPoints = list() # drawable points |
| 487 | self._prePoints = list() # pre-transform points |
| 488 | self._colors = None |
| 489 | if points: |
| 490 | self.points = points |
| 491 | self.colors = colors or COLOR_BLACK |
| 492 | |
| 493 | @property |
| 494 | def points(self): |
| 495 | if self.isDirty: |
| 496 | self.update() |
| 497 | return self._points |
| 498 | |
| 499 | @points.setter |
| 500 | def points(self, value): |
| 501 | self._prePoints = list(value) |
| 502 | self._drawPoints = list(value) |
| 503 | self.isDirty = True |
| 504 | |
| 505 | @property |
| 506 | def colors(self): |
| 507 | if self.isDirty: |
| 508 | self.update() |
| 509 | return self._colors |
| 510 | |
| 511 | @colors.setter |
| 512 | def colors(self, value): |
| 513 | if isinstance(value, (list, tuple)): |
| 514 | self._colors = value |
| 515 | self.isDirty = True |
| 516 | return True |
| 517 | logger.error('Unable to set colors: ' + value) |
| 518 | return False |
| 519 | |
| 520 | def _is_color_list(self): |
| 521 | for each in self.colors: |
| 522 | if isinstance(each, (list, tuple)) and len(each) == 3: |
| 523 | return True |
| 524 | return False |
| 525 | |
| 526 | def update(self): |
| 527 | super(TrianglePrim, self).update() |
| 528 | self._points = [] |
| 529 | matrix = self.transform.asMatrix() |
| 530 | for i in xrange(len(self._prePoints)): |
| 531 | point = om2.MPoint(self._prePoints[i]) |
| 532 | point *= matrix |
| 533 | self._points.append(point) |
| 534 | |
| 535 | def draw(self, view, renderer): |
| 536 | super(TrianglePrim, self).draw(view, renderer) |