Changeset 356

Show
Ignore:
Timestamp:
11/04/02 15:46:23 (6 years ago)
Author:
sholloway
Message:

*** empty log message ***

Files:

Legend:

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

    r354 r356  
    2727 
    2828import weakref 
    29  
    3029import Loader 
     30import Numeric 
    3131 
    3232from RBRapier.Tools.Geometry.Analysis import TriangleLister 
     
    105105 
    106106        result.SetVertices(self.Vertices) 
     107        result.SetNormals(self.Normals) 
    107108 
    108109        if self.SurfaceGroups: 
     
    125126        elif optimizemesh == 0:  
    126127            self.SimpleMesh() 
     128 
    127129        if optimizetraversal > 0: 
    128130            self.OptimizeTraversals(optimizetraversal) 
     
    135137 
    136138        self.Name = FileInFormat.name 
    137         self.Vertices = obj.Vertices and VertexArrays.VertexArray(obj.Vertices) or None 
     139        self.Vertices = VertexArrays.VertexArray(obj.Vertices) 
     140        Normals = Numeric.zeros(self.Vertices.data.shape, self.Vertices.data.typecode()) 
     141        self.Normals = VertexArrays.NormalArray(Normals) 
     142 
     143        self.NormalDivide = Numeric.zeros(self.Vertices.data.shape[0], Numeric.UInt16) 
    138144        self.SurfaceGroups = obj.Surfaces.values() 
    139145 
     
    162168                    v0,v1 = FaceTraversal[:2] 
    163169                    for v2 in FaceTraversal[2:]: 
    164                         mesh.AddFace(v0,v1,v2) 
     170                        face = mesh.AddFace(v0,v1,v2) 
     171                        if face:  
     172                            normal = face.CalculateNormal(self.Vertices.data) 
     173                            self.Normals.data[v0] += normal 
     174                            self.NormalDivide[v0] += 1 
     175                            self.Normals.data[v1] += normal 
     176                            self.NormalDivide[v1] += 1 
     177                            self.Normals.data[v2] += normal 
     178                            self.NormalDivide[v2] += 1 
     179                        else:  
     180                            assert v0==v1 or v1==v2 or v2==v0 
    165181                        v1 = v2 
     182 
    166183                if __debug__:  
    167184                    print '%-20s[%6d]: ' % (Group.Name, len(mesh.Faces)*3), 
     
    182199                    Group.Traversals = TraversalMaker(mesh) 
    183200 
     201        for data, divisor in zip(self.Normals.data, self.NormalDivide): 
     202            if divisor: data = data/float(divisor) 
     203            else: print "Unreferenced index", data, divisor 
     204        del self.NormalDivide 
     205 
    184206    def SimpleTraversals(self): 
    185207        for Group in self.SurfaceGroups: 
     
    236258 
    237259    test = MeshedObjectBuilder() 
    238     obj = test.Build(open('data/ki162a.lwo', 'rb'), 0, 0) 
     260    obj = test.Build(open('data/ki162a.lwo', 'rb'), 1, 0) 
    239261    print "Test complete." 
    240262 
  • trunk/RBRapier/RBRapier/Tools/Geometry/Analysis/TriangleMesh.py

    r345 r356  
    2525 
    2626import weakref 
     27from RBRapier.Tools.Vector import Vector3 
    2728 
    2829#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     
    102103            raise KeyError, "Expected one vertex, but found none! (%r, %r, %r)" % (self.v, (pv0, pv1), result) 
    103104 
     105    def CalculateNormal(self, VertexList, KeepNormal=0): 
     106        vectors = [Vector3(VertexList[v]) for v in self.v] 
     107        e01 = vectors[1] - vectors[0] 
     108        e02 = vectors[2] - vectors[0] 
     109        normal = e01.Cross3(e02).Normalize().asarray() 
     110        if KeepNormal: self.normal = normal 
     111        return normal 
     112 
    104113#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    105114 
     
    128137 
    129138class FaceMesh(FlyweightGroupObject): 
     139    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     140    #~ Constants / Variables / Etc.  
     141    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     142 
     143    WarnOnOddities = 0 
     144 
     145    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     146    #~ Public Methods  
     147    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     148 
    130149    def __init__(self, FaceClass=Face): 
    131150        FaceClassName = '%s&%s'%(self.__class__.__name__, FaceClass.__name__) 
     
    138157    def AddFace(self, v0,v1,v2): 
    139158        if v0 == v1 or v1 == v2 or v2 == v0: 
    140             #print "DEGENERATE face", (v0,v1,v2) 
     159            if self.WarnOnOddities: 
     160                print "DEGENERATE face", (v0,v1,v2) 
    141161            return None 
    142162        else: 
     
    194214 
    195215        edge.Faces.append(face) 
    196         #if len(edge.Faces) > 2: 
    197         #    print "ABNORMAL Edge:", edge, edge.Faces 
     216        if self.WarnOnOddities: 
     217            if len(edge.Faces) > 2: 
     218                print "ABNORMAL Edge:", edge, edge.Faces 
    198219        return edge 
    199220 
    200221    def AddFace(self, v0,v1,v2): 
    201222        if v0 == v1 or v1 == v2 or v2 == v0: 
    202             #print "DEGENERATE face", (v0,v1,v2) 
     223            if self.WarnOnOddities: 
     224                print "DEGENERATE face", (v0,v1,v2) 
    203225            return None 
    204226        else: 
  • trunk/RBRapier/RBRapier/Tools/Projections.py

    r337 r356  
    154154            [0., 0., -2./deprojh, zoff], 
    155155            [0., 0., 0., 1.]], 
    156             Numeric.Float
     156            Numeric.Float32
    157157        return result 
    158158 
     
    256256            [0., 0., -zoff, ugly], 
    257257            [0., 0., -1., 0.]], 
    258             Numeric.Float
     258            Numeric.Float32
    259259        return result 
    260260 
  • trunk/RBRapier/RBRapier/Tools/Quaternion.py

    r340 r356  
    109109    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    110110 
    111     NumericType = Numeric.Float 
     111    NumericType = Numeric.Float32 
    112112     
    113113    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
  • trunk/RBRapier/RBRapier/Tools/Transformations.py

    r337 r356  
    136136    def asArray4x4(self): 
    137137        """Returns the transformation in 4x4 Numeric array form""" 
    138         r = Numeric.identity(4, Numeric.Float
     138        r = Numeric.identity(4, Numeric.Float32
    139139        for xform in self.collection: 
    140140            r = Numeric.dot(r, xform.asArray4x4()) 
     
    169169 
    170170    def __init__(self, matrix=None): 
    171         if matrix: self.matrix = Numeric.asarray(matrix, Numeric.Float
    172         else: self.matrix = Numeric.identity(4, Numeric.Float
     171        if matrix: self.matrix = Numeric.asarray(matrix, Numeric.Float32
     172        else: self.matrix = Numeric.identity(4, Numeric.Float32
    173173        assert self.matrix.shape == (4,4) 
    174174 
     
    208208 
    209209    def asArray4x4(self): 
    210         return Numeric.identity(4, Numeric.Float
     210        return Numeric.identity(4, Numeric.Float32
    211211 
    212212    def asInverse4x4(self): 
    213         return Numeric.identity(4, Numeric.Float
     213        return Numeric.identity(4, Numeric.Float32
    214214 
    215215    def Inverse(self): 
     
    244244 
    245245    def asArray4x4(self): 
    246         result = Numeric.identity(4, Numeric.Float
     246        result = Numeric.identity(4, Numeric.Float32
    247247        result[:, 3] = self.Direction 
    248248        return result 
    249249 
    250250    def asInverse4x4(self): 
    251         result = Numeric.identity(4, Numeric.Float
     251        result = Numeric.identity(4, Numeric.Float32
    252252        result[:, 3] = -self.Direction 
    253253        return result 
     
    289289 
    290290    def asArray4x4(self): 
    291         result = Numeric.identity(4, Numeric.Float
     291        result = Numeric.identity(4, Numeric.Float32
    292292        for idx in range(4): result[idx,idx] = self.Scale[idx] 
    293293        return result 
    294294 
    295295    def asInverse4x4(self): 
    296         result = Numeric.identity(4, Numeric.Float
     296        result = Numeric.identity(4, Numeric.Float32
    297297        for idx in range(4): result[idx,idx] = 1./self.Scale[idx] 
    298298        return result 
     
    377377        u = self.Axis[:-1] 
    378378        uut = Numeric.outerproduct(u, u) 
    379         M = Numeric.identity(3, Numeric.Float) - uut 
    380         S = Numeric.asarray([[0., -u[2], u[1]], [u[2], 0., -u[0]], [-u[1], u[0], 0.]], Numeric.Float
     379        M = Numeric.identity(3, Numeric.Float32) - uut 
     380        S = Numeric.asarray([[0., -u[2], u[1]], [u[2], 0., -u[0]], [-u[1], u[0], 0.]], Numeric.Float32
    381381        radians = self.Radians 
    382382        R = uut + math.cos(radians) * M + math.sin(radians) * S 
    383         result = Numeric.identity(4, Numeric.Float
     383        result = Numeric.identity(4, Numeric.Float32
    384384        result[:3,:3] = R 
    385385        return result 
     
    432432        U_ = S.Cross3(L) 
    433433 
    434         result = Numeric.identity(4, Numeric.Float
     434        result = Numeric.identity(4, Numeric.Float32
    435435        result[0,:-1] = S 
    436436        result[1,:-1] = U_ 
    437437        result[2,:-1] = -L 
    438         xlate = Numeric.identity(4, Numeric.Float
     438        xlate = Numeric.identity(4, Numeric.Float32
    439439        xlate[:-1,3] = -E 
    440440        return Numeric.dot(result, xlate) 
     
    622622            [0, 0, Zs, Zt], 
    623623            [0, 0, 0, 1]],  
    624             Numeric.Float
     624            Numeric.Float32
    625625        return result 
    626626 
     
    634634            [0, 0, Zs, Zt], 
    635635            [0, 0, 0, 1]],  
    636             Numeric.Float
     636            Numeric.Float32
    637637        return result 
    638638 
  • trunk/RBRapier/RBRapier/Tools/Vector.py

    r340 r356  
    133133    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    134134 
    135     NumericType = Numeric.Float 
     135    NumericType = Numeric.Float32 
    136136    Default = Numeric.asarray((0.,0.,0.), NumericType) 
    137137 
     
    377377    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    378378 
    379     NumericType = Numeric.Float 
     379    NumericType = Numeric.Float32 
    380380    Default = Numeric.asarray((0.,0.,0.,1.), NumericType) 
    381381 
  • trunk/RBRapier/demo/Wavefront/scene.py

    r351 r356  
    5959        self.Sequence.AddElement(self.Viewport, -2) 
    6060 
    61         self.GeoObj = self.WavefrontOBJ('data/oldtree.obj'
     61        self.GeoObj = self.WavefrontOBJ('data/oldtree.obj', 0, 0
    6262        #self.GeoObj = self.WavefrontOBJ('data/x29.obj') 
    6363