| 1 |
#!/usr/bin/env python |
|---|
| 2 |
##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 3 |
##~ License |
|---|
| 4 |
##~ |
|---|
| 5 |
##- The RuneBlade Foundation library is intended to ease some |
|---|
| 6 |
##- aspects of writing intricate Jabber, XML, and User Interface (wxPython, etc.) |
|---|
| 7 |
##- applications, while providing the flexibility to modularly change the |
|---|
| 8 |
##- architecture. Enjoy. |
|---|
| 9 |
##~ |
|---|
| 10 |
##~ Copyright (C) 2002 TechGame Networks, LLC. |
|---|
| 11 |
##~ |
|---|
| 12 |
##~ This library is free software; you can redistribute it and/or |
|---|
| 13 |
##~ modify it under the terms of the BSD style License as found in the |
|---|
| 14 |
##~ LICENSE file included with this distribution. |
|---|
| 15 |
##~ |
|---|
| 16 |
##~ TechGame Networks, LLC can be reached at: |
|---|
| 17 |
##~ 3578 E. Hartsel Drive #211 |
|---|
| 18 |
##~ Colorado Springs, Colorado, USA, 80920 |
|---|
| 19 |
##~ |
|---|
| 20 |
##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 21 |
|
|---|
| 22 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 23 |
#~ Imports |
|---|
| 24 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 25 |
|
|---|
| 26 |
import weakref |
|---|
| 27 |
from RBRapier.Renderer import SequenceMgr |
|---|
| 28 |
|
|---|
| 29 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 30 |
#~ Definitions |
|---|
| 31 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 32 |
|
|---|
| 33 |
class GeoObject(SequenceMgr.Sequence): |
|---|
| 34 |
class GeoSubGroup(object): |
|---|
| 35 |
def __init__(self, geoobj, name): |
|---|
| 36 |
self.Traversals = [] |
|---|
| 37 |
self.Materials = [] |
|---|
| 38 |
self.geoobj = weakref.proxy(geoobj) |
|---|
| 39 |
self.name = name |
|---|
| 40 |
|
|---|
| 41 |
def AddTraversal(self, traversal): |
|---|
| 42 |
self.Traversals.append(traversal) |
|---|
| 43 |
|
|---|
| 44 |
def AddMaterial(self, material): |
|---|
| 45 |
self.Materials.append(material) |
|---|
| 46 |
|
|---|
| 47 |
def LoadFinalized(self): |
|---|
| 48 |
pass |
|---|
| 49 |
GeoSubGroupFactory = GeoSubGroup |
|---|
| 50 |
|
|---|
| 51 |
def SetVertices(self, Vertices): |
|---|
| 52 |
try: self.RemoveElement(self.Vertices) |
|---|
| 53 |
except AttributeError: pass |
|---|
| 54 |
self.Vertices = Vertices |
|---|
| 55 |
|
|---|
| 56 |
def SetNormals(self, Normals): |
|---|
| 57 |
try: self.RemoveElement(self.Normals) |
|---|
| 58 |
except AttributeError: pass |
|---|
| 59 |
self.Normals = Normals |
|---|
| 60 |
|
|---|
| 61 |
def SetTextureCoords(self, TexCoords): |
|---|
| 62 |
try: self.RemoveElement(self.TexCoords) |
|---|
| 63 |
except AttributeError: pass |
|---|
| 64 |
self.TexCoords = TexCoords |
|---|
| 65 |
|
|---|
| 66 |
def AddGroup(self, name): |
|---|
| 67 |
group = self.GeoSubGroupFactory(self, name) |
|---|
| 68 |
try: self.Groups.append(group) |
|---|
| 69 |
except AttributeError: |
|---|
| 70 |
self.Groups = [group] |
|---|
| 71 |
return group |
|---|
| 72 |
|
|---|
| 73 |
def LoadFinalized(self): |
|---|
| 74 |
pass |
|---|
| 75 |
|
|---|
| 76 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 77 |
|
|---|
| 78 |
class DefaultGeoObject(GeoObject): |
|---|
| 79 |
class DefaultGeoSubGroup(GeoObject.GeoSubGroup): |
|---|
| 80 |
def AddTraversal(self, traversal): |
|---|
| 81 |
GeoObject.GeoSubGroup.AddTraversal(self, traversal) |
|---|
| 82 |
self.geoobj.AddElement(traversal.GLExecute) |
|---|
| 83 |
|
|---|
| 84 |
def AddMaterial(self, material): |
|---|
| 85 |
GeoObject.GeoSubGroup.AddMaterial(self, material) |
|---|
| 86 |
self.geoobj.AddElement(material.GLSelect) |
|---|
| 87 |
GeoSubGroupFactory = DefaultGeoSubGroup |
|---|
| 88 |
|
|---|
| 89 |
def SetVertices(self, Vertices): |
|---|
| 90 |
super(DefaultGeoObject, self).SetVertices(Vertices) |
|---|
| 91 |
self.AddElement(self.Vertices.GLSelect, -1) |
|---|
| 92 |
|
|---|
| 93 |
def SetNormals(self, Normals): |
|---|
| 94 |
super(DefaultGeoObject, self).SetNormals(Normals) |
|---|
| 95 |
self.AddElement(self.Normals.GLSelect, -1) |
|---|
| 96 |
|
|---|
| 97 |
def SetTextureCoords(self, TexCoords): |
|---|
| 98 |
super(DefaultGeoObject, self).SetTextureCoords(TexCoords) |
|---|
| 99 |
self.AddElement(self.TexCoords.GLSelect, -1) |
|---|
| 100 |
|
|---|
| 101 |
_BoundingBox = None |
|---|
| 102 |
def _getBoundingBox(self): |
|---|
| 103 |
if self._BoundingBox is None: |
|---|
| 104 |
import Numeric |
|---|
| 105 |
lenItem = len(self.Vertices.data[0]) |
|---|
| 106 |
vmin = self.Vertices.data[0].copy() |
|---|
| 107 |
vmax = self.Vertices.data[0].copy() |
|---|
| 108 |
for v in self.Vertices.data[1:]: |
|---|
| 109 |
for i in range(lenItem): |
|---|
| 110 |
vi, vmini, vmaxi = v[i], vmin[i], vmax[i] |
|---|
| 111 |
vmin[i] = Numeric.minimum(vmini, vi) |
|---|
| 112 |
vmax[i] = Numeric.maximum(vmaxi, vi) |
|---|
| 113 |
self._BoundingBox = vmin, vmax |
|---|
| 114 |
return self._BoundingBox |
|---|
| 115 |
|
|---|
| 116 |
BoundingBox = property(_getBoundingBox) |
|---|
| 117 |
|
|---|