Changeset 379
- Timestamp:
- 11/18/02 12:12:19 (6 years ago)
- Files:
-
- trunk/RBRapier/RBRapier/Formats/Lightwave/Loader.py (modified) (1 diff)
- trunk/RBRapier/RBRapier/Formats/Lightwave/MeshedObject.py (modified) (3 diffs)
- trunk/RBRapier/RBRapier/Formats/Wavefront/MeshedObject.py (modified) (1 diff)
- trunk/RBRapier/RBRapier/Renderer/SequenceMgr.py (modified) (1 diff)
- trunk/RBRapier/RBRapier/Renderer/View/Transformations.py (modified) (16 diffs)
- trunk/RBRapier/RBRapier/Tools/Geometry/Analysis/LocalityRemapper.py (modified) (2 diffs)
- trunk/RBRapier/RBRapier/Tools/Geometry/Synthesis/VertexNormals.py (modified) (4 diffs)
- trunk/RBRapier/RBRapier/Tools/Visualizers/AxisSets.py (modified) (1 diff)
- trunk/RBRapier/RBRapier/Tools/Visualizers/Grids.py (modified) (1 diff)
- trunk/RBRapier/RBRapier/Tools/Visualizers/ProjectionBoxes.py (modified) (3 diffs)
- trunk/RBRapier/demo/Lightwave/scene.py (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/RBRapier/RBRapier/Formats/Lightwave/Loader.py
r374 r379 151 151 if name: 152 152 setattr(self, name, value) 153 print name, value153 #print name, value 154 154 except EOFError: 155 155 pass # end of chunk 156 #print vars(self).keys() 156 157 Flag = getattr(self, 'Flag', 0) 158 self.Luminous = Flag & 1; Flag >>= 1 159 self.Outline = Flag & 1; Flag >>= 1 160 self.Smoothing = Flag & 1; Flag >>= 1 161 self.ColorHighlights = Flag & 1; Flag >>= 1 162 self.ColorFilter = Flag & 1; Flag >>= 1 163 self.OpaqueEdge = Flag & 1; Flag >>= 1 164 self.TransparentEdge = Flag & 1; Flag >>= 1 165 self.SharpTerminator = Flag & 1; Flag >>= 1 166 self.DoubleSided = Flag & 1; Flag >>= 1 167 self.Additive = Flag & 1; Flag >>= 1 168 self.ShadowAlpha = Flag & 1; Flag >>= 1 157 169 158 170 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ trunk/RBRapier/RBRapier/Formats/Lightwave/MeshedObject.py
r368 r379 211 211 VNSythesisMgr = VertexNormals.VertexNormalSynthesisMgr(self.Vertices) 212 212 for Group in self.SurfaceGroups: 213 VNSythesisMgr.SetTolerance(getattr(Group, 'SmoothingAngle', None)) 213 if Group.Smoothing: 214 VNSythesisMgr.SetTolerance(getattr(Group, 'SmoothingAngle', None)) 215 else: 216 VNSythesisMgr.SetTolerance(None) 214 217 215 218 if Group.SurfaceTask: … … 283 286 else: OptimizingSubtask = 0 284 287 285 optimizer = LocalityRemapper.LocalityRemapper( )288 optimizer = LocalityRemapper.LocalityRemapper(len(self.Vertices.data)) 286 289 287 290 for Group in self.SurfaceGroups: … … 330 333 print "Testing..." 331 334 import doctest 332 #import MODULE as _testmod333 #doctest.testmod(_testmod)334 335 335 test = MeshedObjectBuilder() 336 336 obj = test.Build(open('data/ki162a.lwo', 'rb'), 1, 0) trunk/RBRapier/RBRapier/Formats/Wavefront/MeshedObject.py
r370 r379 202 202 203 203 def OptimizeTraversals(self, level): 204 optimizer = LocalityRemapper.LocalityRemapper( )204 optimizer = LocalityRemapper.LocalityRemapper(len(self.Vertices.data)) 205 205 206 206 for Group in self.FormatGroups: trunk/RBRapier/RBRapier/Renderer/SequenceMgr.py
r369 r379 75 75 priority = self.GeneralPhase 76 76 self._AddElement(Element, priority) 77 78 def AddElements(self, *args): 79 for each in args: 80 if isinstance(each, (tuple, list)): 81 self.AddElement(*each) 82 else: self.AddElement(each) 77 83 78 84 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ trunk/RBRapier/RBRapier/Renderer/View/Transformations.py
r369 r379 76 76 Draw = Execute 77 77 78 class ManagedComposite(ManagedTransformationMixin, Composite): 79 pass 78 class CompositeMgd(ManagedTransformationMixin, Composite): 79 pass 80 ManagedComposite = CompositeMgd 80 81 81 82 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ … … 86 87 Draw = Execute 87 88 89 class MatrixMgd(ManagedTransformationMixin, Matrix): 90 pass 91 88 92 class LoadMatrix(Transformations.Matrix): 89 93 def Execute(self, context): … … 91 95 Draw = Execute 92 96 97 class LoadMatrixMgd(ManagedTransformationMixin, LoadMatrix): 98 pass 99 93 100 class Identity(Transformations.Identity): 94 101 def Execute(self, context): … … 96 103 Draw = Execute 97 104 105 class IdentityMgd(ManagedTransformationMixin, Identity): 106 pass 107 98 108 class LoadIdentity(Transformations.Identity): 99 109 def Execute(self, context): … … 101 111 Draw = Execute 102 112 113 class LoadIdentityMgd(ManagedTransformationMixin, LoadIdentity): 114 pass 115 103 116 class Translate(Transformations.Translate): 104 117 def Execute(self, context): … … 106 119 Draw = Execute 107 120 121 class TranslateMgd(ManagedTransformationMixin, Translate): 122 pass 123 108 124 class Scale(Transformations.Scale): 109 125 def Execute(self, context): … … 111 127 Draw = Execute 112 128 129 class ScaleMgd(ManagedTransformationMixin, Scale): 130 pass 131 113 132 class Rotate(Transformations.Rotate): 114 133 def Execute(self, context): … … 116 135 Draw = Execute 117 136 137 class RotateMgd(ManagedTransformationMixin, Rotate): 138 pass 139 118 140 class Quaternion(Quaternion.Quaternion): 119 141 def Execute(self, context): … … 121 143 Draw = Execute 122 144 145 class QuaternionMgd(ManagedTransformationMixin, Quaternion): 146 pass 147 123 148 class LinearMappingMatrix(Transformations.LinearMappingMatrix): 124 149 def Execute(self, context): 125 150 GL.glMultMatrixd(transpose(self.asArray4x4()).tolist()) 126 151 Draw = Execute 152 153 class LinearMappingMatrixMgd(ManagedTransformationMixin, LinearMappingMatrix): 154 pass 127 155 128 156 class LookAt(Transformations.LookAt): … … 132 160 Draw = Execute 133 161 162 class LookAtMgd(ManagedTransformationMixin, LookAt): 163 pass 164 134 165 class SphericalLookAt(Transformations.SphericalLookAt): 135 166 def Execute(self, context): … … 138 169 Draw = Execute 139 170 171 class SphericalLookAtMgd(ManagedTransformationMixin, SphericalLookAt): 172 pass 173 140 174 class Shear(Transformations.Shear): 141 175 def Execute(self, context): … … 143 177 Draw = Execute 144 178 179 class ShearMgd(ManagedTransformationMixin, Shear): 180 pass 181 145 182 class Skew(Transformations.Skew): 146 183 def Execute(self, context): … … 148 185 Draw = Execute 149 186 150 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 151 #~ Title 187 class SkewMgd(ManagedTransformationMixin, Skew): 188 pass 189 190 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 191 #~ Projections 152 192 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 153 193 … … 157 197 Draw = Execute 158 198 199 class OrthographicMgd(ManagedTransformationMixin, Orthographic): 200 pass 201 159 202 class Frustum(Projections.Frustum): 160 203 def Execute(self, context): … … 162 205 Draw = Execute 163 206 207 class FrustumMgd(ManagedTransformationMixin, Frustum): 208 pass 209 164 210 class Perspective(Projections.Perspective): 165 211 def Execute(self, context): … … 167 213 Draw = Execute 168 214 215 class PerspectiveMgd(ManagedTransformationMixin, Perspective): 216 pass 217 trunk/RBRapier/RBRapier/Tools/Geometry/Analysis/LocalityRemapper.py
r345 r379 24 24 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 25 25 26 from __future__ import generators 27 import Numeric 28 26 29 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 27 30 #~ Definitions … … 29 32 30 33 class LocalityRemapper(object): 31 def __init__(self): 32 print 33 print "TODO: Write LocalityRemapper" 34 print 34 def __init__(self, NumberOfIndices): 35 if NumberOfIndices < 1<<7: 36 format = Numeric.Int8 37 elif NumberOfIndices < 1<<15: 38 format = Numeric.Int16 39 elif NumberOfIndices < 1<<31: 40 format = Numeric.Int32 41 else: format = Numeric.Int64 42 43 self.RemapIdx = -1 * Numeric.ones(NumberOfIndices, format) 44 self.Remapping = Numeric.zeros(NumberOfIndices, format) 45 self.RemappingIdx = self._RemappingIndices() 46 47 def _RemappingIndices(self): 48 idx = 0 49 while 1: 50 yield idx 51 idx += 1 35 52 36 53 def Visit(self, indexreferences): 37 pass 54 for i in xrange(len(indexreferences)): 55 idx = indexreferences[i] 56 current = self.RemapIdx[idx] 57 if current < 0: 58 current = self.RemappingIdx.next() 59 self.RemapIdx[idx] = current 60 self.Remapping[current] = idx 61 indexreferences[i] = current 38 62 39 def RemapIndices(self, indexcollections):40 pass63 def RemapIndices(self, datacollections): 64 datacollections[:] = Numeric.take(datacollections, self.Remapping) 41 65 trunk/RBRapier/RBRapier/Tools/Geometry/Synthesis/VertexNormals.py
r374 r379 38 38 self.Normals = {} 39 39 40 def IntegrateNormal(self, normal, cosToler=0.): 41 for idx, value in self.Normals.iteritems(): 42 if normal.Dot(value) < cosToler: 43 # Found one within tolerance... average them 44 self.Normals[idx] = normal + value 45 break 46 else: 47 # Well, let's make a new normal then 48 if not self.Normals: 49 idx = self.idx 50 else: 51 idx = self.owner._GetNextValue() 52 self.Normals[idx] = normal 40 def IntegrateNormal(self, normal, cosToler=2.): 41 if cosToler is not None: 42 for idx, (value, blendable) in self.Normals.iteritems(): 43 if not blendable: continue 44 cosAngle = normal.Dot(value) 45 #if not (-1.000001 <= cosAngle <= 1.000001): 46 # print cosAngle 47 assert -1.000001 <= cosAngle <= 1.000001 48 #divisor = abs(value) * abs(normal) 49 #cosAngle = normal.Dot(value) / divisor 50 #try: 51 # print 180./Numeric.pi * Numeric.arccos(cosAngle) 52 #except ValueError: 53 # print "ValueError", cosAngle 54 if cosAngle >= cosToler: 55 # Found one within tolerance... average them 56 self.Normals[idx] = ((normal + value).Normalize(), blendable) 57 return idx 58 blendable = 1 59 else: blendable = 0 60 61 # Well, let's make a new normal then 62 if not self.Normals: idx = self.idx 63 else: idx = self.owner._GetNextValue() 64 self.Normals[idx] = normal.Normalize(), blendable 53 65 return idx 54 66 55 67 def SetResults(self, VertexData, NormalData): 56 68 srcVertex = self.owner.VertexData[self.idx] 57 for idx, normalin self.Normals.iteritems():69 for idx, (normal, blendable) in self.Normals.iteritems(): 58 70 VertexData[idx] = srcVertex 59 71 NormalData[idx] = normal.Normalize().asarray() … … 74 86 75 87 def SetTolerance(self, tolerance): 76 if tolerance is None: tolerance = Numeric.pi/877 self._cosToler = Numeric.cos(tolerance)88 if tolerance is None: self._cosToler = None 89 else: self._cosToler = Numeric.cos(tolerance) 78 90 79 91 def GetResultantArrays(self): 80 #print len(self.VertexData), self.NextVertexIdx81 92 defval = (0.,0.,0.) 82 93 self.NormalData = [defval for i in xrange(self.NextVertexIdx)] … … 91 102 return None 92 103 normal = self._CalculateNormal(vi0, vi1, vi2) 93 vi0 = self.Vertices[vi0].IntegrateNormal(normal) 94 vi1 = self.Vertices[vi1].IntegrateNormal(normal) 95 vi2 = self.Vertices[vi2].IntegrateNormal(normal) 96 return vi0, vi1, vi2 104 if normal is None: 105 return None 106 else: 107 vi0 = self.Vertices[vi0].IntegrateNormal(normal, self._cosToler) 108 vi1 = self.Vertices[vi1].IntegrateNormal(normal, self._cosToler) 109 vi2 = self.Vertices[vi2].IntegrateNormal(normal, self._cosToler) 110 return vi0, vi1, vi2 97 111 98 112 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ … … 109 123 e01 = (Vector3(self.VertexData[vi1]) - vector0).Normalize() 110 124 e02 = (Vector3(self.VertexData[vi2]) - vector0).Normalize() 111 normal = e01.Cross3(e02)#.Normalize() 112 return normal 125 normal = e01.Cross3(e02) 126 if normal.Magnitude(0) <= 1e-9: 127 return e01 128 else: 129 return normal.Normalize() 113 130 114 131 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ trunk/RBRapier/RBRapier/Tools/Visualizers/AxisSets.py
r371 r379 24 24 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 25 25 26 from OpenGL import GL 27 from RBRapier.Renderer.AttributeMgr import AttributeChangeElement 28 26 29 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 27 30 #~ Definitions 28 31 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 29 32 33 class AxisLineSet(object): 34 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 35 #~ Constants / Variables / Etc. 36 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 30 37 38 AttributeChange = AttributeChangeElement(GL.GL_LINE_BIT) 39 LineWidth = 4. 40 AxisLength = 1. 41 xColor = (1., 0., 0., 1.) 42 yColor = (0., 1., 0., 1.) 43 zColor = (0., 0., 1., 1.) 44 45 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 46 #~ Public Methods 47 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 48 49 def __init__(self, AxisLength=None, **kw): 50 if AxisLength is not None: 51 self.AxisLength = AxisLength 52 for name, value in kw.iteritems(): 53 setattr(self, name, value) 54 55 def Execute(self, context): 56 AxisLength = self.AxisLength 57 58 GL.glLineWidth(self.LineWidth) 59 GL.glNormal3f(0.577,0.577,0.577) 60 GL.glBegin(GL.GL_LINES) 61 62 # X Axis 63 GL.glColor4f(*self.xColor) 64 GL.glVertex3f(0., 0., 0.) 65 GL.glVertex3f(AxisLength, 0., 0.) 66 # Y Axis 67 GL.glColor4f(*self.yColor) 68 GL.glVertex3f(0., 0., 0.) 69 GL.glVertex3f(0., AxisLength, 0.) 70 # Z Axis 71 GL.glColor4f(*self.zColor) 72 GL.glVertex3f(0., 0., 0.) 73 GL.glVertex3f(0., 0., AxisLength) 74 75 GL.glEnd() 76 GL.glLineWidth(1.) 77 78 context.Statistics['lines'] = context.Statistics.get('lines', 0) + 3 79 trunk/RBRapier/RBRapier/Tools/Visualizers/Grids.py
r372 r379 92 92 GL.glBindTexture(GL.GL_TEXTURE_2D, self.TextureID) 93 93 GL.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1) 94 #GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, 3, w, h, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, self.imagedata)95 GLU.gluBuild2DMipmaps(GL.GL_TEXTURE_2D, 3, w, h, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, self.imagedata)94 GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, 3, w, h, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, self.imagedata) 95 #GLU.gluBuild2DMipmaps(GL.GL_TEXTURE_2D, 3, w, h, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, self.imagedata) 96 96 97 97 GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_REPEAT) 98 98 GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_REPEAT) 99 99 GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR) 100 #GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR)101 GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR_MIPMAP_NEAREST)100 GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR) 101 #GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR_MIPMAP_NEAREST) 102 102 103 103 def Execute(self, context): trunk/RBRapier/RBRapier/Tools/Visualizers/ProjectionBoxes.py
r378 r379 26 26 import Numeric 27 27 from OpenGL import GL 28 from RBRapier.Renderer.AttributeMgr import AttributeChangeElement 28 29 from RBRapier.Renderer.Geometry.VertexArrays import VertexArray 29 30 from RBRapier.Renderer.Geometry.ArrayTraversal import IndexedCollectionTraversal … … 51 52 52 53 Projection = None 54 LineWidth = 4. 55 AttributeChange = AttributeChangeElement(GL.GL_LINE_BIT) 53 56 _BoxTraversal = IndexedCollectionTraversal(GL.GL_LINES, [[0,1, 1,2, 2,3, 3,0, 0,4, 1,5, 2,6, 3,7, 4,5, 5,6, 6,7, 7,4]], Numeric.UInt8) 54 57 … … 62 65 63 66 def Execute(self, context): 67 GL.glLineWidth(self.LineWidth) 68 GL.glColor4f(*self.color) 64 69 self._UpdateBoxVertices() 65 70 self._Vertices.Select(context) 66 71 self._BoxTraversal.Execute(context) 67 72 self._Vertices.Deselect(context) 73 GL.glLineWidth(1.) 68 74 69 75 def _UpdateBoxVertices(self): trunk/RBRapier/demo/Lightwave/scene.py
r376 r379 43 43 44 44 from RBRapier.Tools.Visualizers import Grids 45 from RBRapier.Tools.Visualizers import AxisSets 46 #from RBRapier.Tools.Visualizers import ProjectionBoxes 45 47 import Numeric 46 48 … … 71 73 72 74 self.Lighting = Lighting.LightingModel() 75 self.Lighting.Active = 1 73 76 self.Sequence.AddElement(self.Lighting.Select) 74 77 self.Lights = [] … … 126 129 self.Sequence.AddElement(self.Grid) 127 130 128 self.GeoObj = self.LigthwaveLWO('data/RBText.lwo', 1, 3) 129 #self.GeoObj = self.LigthwaveLWO('data/dodecahedron.lwo', 1, 3) 130 #self.GeoObj = self.LigthwaveLWO('data/ki162a.lwo', 1, 3) 131 #self.GeoObj = self.LigthwaveLWO('data/fi110a.lwo', 1, 3) 132 #self.GeoObj = self.LigthwaveLWO('data/ga102a.lwo', 1, 0) 133 #self.GeoObj = self.LigthwaveLWO('data/CHIP.LWO', 1, 0) 134 #self.GeoObj = self.LigthwaveLWO('data/SIM.LWO', 1, 3) 131 #self.Sequence.AddElement(AxisSets.AxisLineSet()) 132 133 args = 1,3 134 #self.GeoObj = self.LigthwaveLWO('data/RBText.lwo', *args) 135 self.GeoObj = self.LigthwaveLWO('data/dodecahedron.lwo', *args) 136 #self.GeoObj = self.LigthwaveLWO('data/ki162a.lwo', *args) 137 #self.GeoObj = self.LigthwaveLWO('data/fi110a.lwo', *args) 138 #self.GeoObj = self.LigthwaveLWO('data/ga102a.lwo', *args) 139 #self.GeoObj = self.LigthwaveLWO('data/CHIP.LWO', *args) 140 #self.GeoObj = self.LigthwaveLWO('data/SIM.LWO', *args) 141 142 #self.Sequence.AddElements(self.GeoObj.Vertices.Select, self.GeoObj.Normals.Select) 143 self.Sequence.AddElement(self.GeoObj) 135 144 136 145 def StripColoredLigthwaveLWO(self, name, *args, **kw): … … 140 149 builder.IndexedTraversal = ArrayTraversal.ColoredIndexedCollectionTraversal 141 150 GeoObj = builder.Build(open(name, 'rb'), *args, **kw) 142 self.Sequence.AddElement(GeoObj)151 #self.Sequence.AddElement(GeoObj) 143 152 return GeoObj 144 153 … … 147 156 builder.GeoObjectFactory = GeoObject.DefaultGeoObject 148 157 GeoObj = builder.Build(open(name, 'rb'), *args, **kw) 149 self.Sequence.AddElement(GeoObj)158 #self.Sequence.AddElement(GeoObj) 150 159 return GeoObj 151 160
