Changeset 364
- Timestamp:
- 11/06/02 17:22:05 (6 years ago)
- Files:
-
- trunk/RBFoundation/RBFoundation/Aspects/FlyweightGroup.py (added)
- trunk/RBRapier/RBRapier/Formats/Lightwave/MeshedObject.py (modified) (6 diffs)
- trunk/RBRapier/RBRapier/Tools/Geometry/Analysis/TriangleMesh.py (modified) (4 diffs)
- trunk/RBRapier/RBRapier/Tools/Geometry/Synthesis/VertexNormals.py (added)
- trunk/RBRapier/demo/Lightwave/scene.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/RBRapier/RBRapier/Formats/Lightwave/MeshedObject.py
r363 r364 33 33 from RBRapier.Tools.Geometry.Analysis import TriangleMesh 34 34 from RBRapier.Tools.Geometry.Analysis import LocalityRemapper 35 from RBRapier.Tools.Geometry.Synthesis import VertexNormals 35 36 from RBRapier.Tools.Geometry.ConvexPolygonTesselation import TesselateConvexPolygon 36 37 … … 73 74 self.Load(FileInFormat) 74 75 self.Process(optimizetraversal, optimizemesh) 76 75 77 result = self.GeoObjectFactory() 76 77 78 result.SetVertices(self.Vertices) 78 79 result.SetNormals(self.Normals) … … 152 153 153 154 self.Name = FileInFormat.name 154 self.Vertices = VertexArrays.VertexArray(obj.Vertices) 155 Normals = Numeric.zeros(self.Vertices.data.shape, self.Vertices.data.typecode()) 156 self.Normals = VertexArrays.NormalArray(Normals) 157 155 self.Vertices = obj.Vertices 158 156 self.SurfaceGroups = obj.Surfaces.values() 159 157 … … 168 166 169 167 def TraverseMesh(self, MeshFactory, TraversalMaker): 170 for Group in self.SurfaceGroups: 168 VNSythesisMgr = VertexNormals.VertexNormalSynthesisMgr(self.Vertices) 169 for Group in self.SurfaceGroups: 170 VNSythesisMgr.SetTolerance(getattr(Group, 'SmoothingAngle', None)) 171 171 172 if not Group.Faces: 172 173 Group.Traversals = {} … … 176 177 FaceTraversal = TesselateConvexPolygon(FaceTraversal.IndexList) 177 178 for each in FaceTraversal: 179 each = VNSythesisMgr.VisitTriangle(*each) 178 180 face = mesh.AddFace(*each) 179 if face:180 normal = face.CalculateNormal(self.Vertices.data)181 for v in each:182 self.Normals.data[v] += normal183 181 184 182 if __debug__: … … 200 198 Group.Traversals = TraversalMaker(mesh) 201 199 202 for data in self.Normals.data: 203 data[:] /= Numeric.sqrt(Numeric.sum(data*data)) 200 Vertices, Normals = VNSythesisMgr.GetResultantArrays() 201 self.Vertices = VertexArrays.VertexArray(Vertices) 202 self.Normals = VertexArrays.NormalArray(Normals) 204 203 205 204 def SimpleTraversals(self): trunk/RBRapier/RBRapier/Tools/Geometry/Analysis/TriangleMesh.py
r362 r364 25 25 26 26 import weakref 27 from RBRapier.Tools.Vector import Vector327 from Foundation.AspectOriented.FlyweightGroup import FlyweightGroupObject 28 28 29 29 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 30 30 #~ Definitions 31 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~32 33 class FlyweightGroupObject(object):34 def ClassFlyweightGroup(klass, name, **kw):35 return type(name, (klass,), kw)36 ClassFlyweightGroup = classmethod(ClassFlyweightGroup)37 38 31 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 39 32 … … 103 96 raise KeyError, "Expected one vertex, but found none! (%r, %r, %r)" % (self.v, (pv0, pv1), result) 104 97 105 def CalculateNormal(self, VertexList, KeepNormal=0):106 vectors = [Vector3(VertexList[v]) for v in self.v]107 e01 = (vectors[1] - vectors[0]).Normalize()108 e02 = (vectors[2] - vectors[0]).Normalize()109 normal = e01.Cross3(e02)110 normal = normal.asarray()111 if KeepNormal: self.normal = normal112 return normal113 114 98 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 115 99 … … 150 134 def __init__(self, FaceClass=Face): 151 135 FaceClassName = '%s&%s'%(self.__class__.__name__, FaceClass.__name__) 152 self._FaceClass = FaceClass.ClassFlyweightGroup(FaceClassName , mesh=weakref.proxy(self))136 self._FaceClass = FaceClass.ClassFlyweightGroup(FaceClassName, mesh=weakref.proxy(self)) 153 137 self.Faces = [] 154 138 … … 247 231 print "Testing..." 248 232 import doctest 249 import Mesh as _testmod233 import TriangleMesh as _testmod 250 234 doctest.testmod(_testmod) 251 235 print "Test complete." trunk/RBRapier/demo/Lightwave/scene.py
r363 r364 94 94 GL.glMatrixMode(GL.GL_PROJECTION) 95 95 GL.glLoadIdentity() 96 #GL.glOrtho(-.01,.01,-0.005,.01,-5,5) 97 GL.glOrtho(-.1,.1,-.1,.2,-5,5) 98 #GL.glOrtho(-1,1,-0.5,1,-5,5) 96 # Tiny 97 #GL.glOrtho(-.01,.01,-0.005,.01,-0.1,0.1) 98 99 # Small 100 #GL.glOrtho(-.1,.1,-.1,.2,-1,1) 101 102 GL.glFrustum(-.05,.05,-.025,.075,1,10) 103 GL.glTranslatef(0, 0, -2.5) 104 GL.glRotatef(30, 1, 0, 0) 105 106 # Medium 107 #GL.glOrtho(-0.5,0.5,-0.25,0.75,-1,1) 108 99 109 GL.glMatrixMode(GL.GL_MODELVIEW) 100 110 GL.glRotatef(1., 0, 1, 0)
