Changeset 364

Show
Ignore:
Timestamp:
11/06/02 17:22:05 (6 years ago)
Author:
sholloway
Message:

*** empty log message ***

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/RBRapier/RBRapier/Formats/Lightwave/MeshedObject.py

    r363 r364  
    3333from RBRapier.Tools.Geometry.Analysis import TriangleMesh 
    3434from RBRapier.Tools.Geometry.Analysis import LocalityRemapper 
     35from RBRapier.Tools.Geometry.Synthesis import VertexNormals 
    3536from RBRapier.Tools.Geometry.ConvexPolygonTesselation import TesselateConvexPolygon 
    3637 
     
    7374        self.Load(FileInFormat) 
    7475        self.Process(optimizetraversal, optimizemesh) 
     76 
    7577        result = self.GeoObjectFactory() 
    76  
    7778        result.SetVertices(self.Vertices) 
    7879        result.SetNormals(self.Normals) 
     
    152153 
    153154        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 
    158156        self.SurfaceGroups = obj.Surfaces.values() 
    159157 
     
    168166 
    169167    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 
    171172            if not Group.Faces: 
    172173                Group.Traversals = {} 
     
    176177                    FaceTraversal = TesselateConvexPolygon(FaceTraversal.IndexList) 
    177178                    for each in FaceTraversal: 
     179                        each = VNSythesisMgr.VisitTriangle(*each) 
    178180                        face = mesh.AddFace(*each) 
    179                         if face:  
    180                             normal = face.CalculateNormal(self.Vertices.data) 
    181                             for v in each: 
    182                                 self.Normals.data[v] += normal 
    183181 
    184182                if __debug__:  
     
    200198                    Group.Traversals = TraversalMaker(mesh) 
    201199 
    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) 
    204203 
    205204    def SimpleTraversals(self): 
  • trunk/RBRapier/RBRapier/Tools/Geometry/Analysis/TriangleMesh.py

    r362 r364  
    2525 
    2626import weakref 
    27 from RBRapier.Tools.Vector import Vector3 
     27from Foundation.AspectOriented.FlyweightGroup import FlyweightGroupObject 
    2828 
    2929#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    3030#~ Definitions  
    31 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    32  
    33 class FlyweightGroupObject(object): 
    34     def ClassFlyweightGroup(klass, name, **kw): 
    35         return type(name, (klass,), kw) 
    36     ClassFlyweightGroup = classmethod(ClassFlyweightGroup) 
    37  
    3831#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    3932 
     
    10396            raise KeyError, "Expected one vertex, but found none! (%r, %r, %r)" % (self.v, (pv0, pv1), result) 
    10497 
    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 = normal 
    112         return normal 
    113  
    11498#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    11599 
     
    150134    def __init__(self, FaceClass=Face): 
    151135        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)) 
    153137        self.Faces = [] 
    154138 
     
    247231    print "Testing..." 
    248232    import doctest 
    249     import Mesh as _testmod 
     233    import TriangleMesh as _testmod 
    250234    doctest.testmod(_testmod) 
    251235    print "Test complete." 
  • trunk/RBRapier/demo/Lightwave/scene.py

    r363 r364  
    9494        GL.glMatrixMode(GL.GL_PROJECTION) 
    9595        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 
    99109        GL.glMatrixMode(GL.GL_MODELVIEW) 
    100110        GL.glRotatef(1., 0, 1, 0)