Changeset 379

Show
Ignore:
Timestamp:
11/18/02 12:12:19 (6 years ago)
Author:
sholloway
Message:

*** empty log message ***

Files:

Legend:

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

    r374 r379  
    151151                if name:  
    152152                    setattr(self, name, value) 
    153                     print name, value 
     153                    #print name, value 
    154154        except EOFError: 
    155155            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 
    157169 
    158170#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
  • trunk/RBRapier/RBRapier/Formats/Lightwave/MeshedObject.py

    r368 r379  
    211211        VNSythesisMgr = VertexNormals.VertexNormalSynthesisMgr(self.Vertices) 
    212212        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) 
    214217 
    215218            if Group.SurfaceTask: 
     
    283286        else: OptimizingSubtask = 0 
    284287 
    285         optimizer = LocalityRemapper.LocalityRemapper(
     288        optimizer = LocalityRemapper.LocalityRemapper(len(self.Vertices.data)
    286289 
    287290        for Group in self.SurfaceGroups: 
     
    330333    print "Testing..." 
    331334    import doctest 
    332     #import MODULE as _testmod 
    333     #doctest.testmod(_testmod) 
    334  
    335335    test = MeshedObjectBuilder() 
    336336    obj = test.Build(open('data/ki162a.lwo', 'rb'), 1, 0) 
  • trunk/RBRapier/RBRapier/Formats/Wavefront/MeshedObject.py

    r370 r379  
    202202 
    203203    def OptimizeTraversals(self, level): 
    204         optimizer = LocalityRemapper.LocalityRemapper(
     204        optimizer = LocalityRemapper.LocalityRemapper(len(self.Vertices.data)
    205205 
    206206        for Group in self.FormatGroups: 
  • trunk/RBRapier/RBRapier/Renderer/SequenceMgr.py

    r369 r379  
    7575            priority = self.GeneralPhase 
    7676        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) 
    7783 
    7884    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
  • trunk/RBRapier/RBRapier/Renderer/View/Transformations.py

    r369 r379  
    7676    Draw = Execute 
    7777 
    78 class ManagedComposite(ManagedTransformationMixin, Composite): 
    79     pass 
     78class CompositeMgd(ManagedTransformationMixin, Composite): 
     79    pass 
     80ManagedComposite = CompositeMgd 
    8081 
    8182#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     
    8687    Draw = Execute 
    8788 
     89class MatrixMgd(ManagedTransformationMixin, Matrix): 
     90    pass 
     91 
    8892class LoadMatrix(Transformations.Matrix): 
    8993    def Execute(self, context): 
     
    9195    Draw = Execute 
    9296 
     97class LoadMatrixMgd(ManagedTransformationMixin, LoadMatrix): 
     98    pass 
     99 
    93100class Identity(Transformations.Identity): 
    94101    def Execute(self, context): 
     
    96103    Draw = Execute 
    97104 
     105class IdentityMgd(ManagedTransformationMixin, Identity): 
     106    pass 
     107 
    98108class LoadIdentity(Transformations.Identity): 
    99109    def Execute(self, context): 
     
    101111    Draw = Execute 
    102112 
     113class LoadIdentityMgd(ManagedTransformationMixin, LoadIdentity): 
     114    pass 
     115 
    103116class Translate(Transformations.Translate): 
    104117    def Execute(self, context): 
     
    106119    Draw = Execute 
    107120 
     121class TranslateMgd(ManagedTransformationMixin, Translate): 
     122    pass 
     123 
    108124class Scale(Transformations.Scale): 
    109125    def Execute(self, context): 
     
    111127    Draw = Execute 
    112128 
     129class ScaleMgd(ManagedTransformationMixin, Scale): 
     130    pass 
     131 
    113132class Rotate(Transformations.Rotate): 
    114133    def Execute(self, context): 
     
    116135    Draw = Execute 
    117136 
     137class RotateMgd(ManagedTransformationMixin, Rotate): 
     138    pass 
     139 
    118140class Quaternion(Quaternion.Quaternion): 
    119141    def Execute(self, context): 
     
    121143    Draw = Execute 
    122144 
     145class QuaternionMgd(ManagedTransformationMixin, Quaternion): 
     146    pass 
     147 
    123148class LinearMappingMatrix(Transformations.LinearMappingMatrix): 
    124149    def Execute(self, context): 
    125150        GL.glMultMatrixd(transpose(self.asArray4x4()).tolist()) 
    126151    Draw = Execute 
     152 
     153class LinearMappingMatrixMgd(ManagedTransformationMixin, LinearMappingMatrix): 
     154    pass 
    127155 
    128156class LookAt(Transformations.LookAt): 
     
    132160    Draw = Execute 
    133161 
     162class LookAtMgd(ManagedTransformationMixin, LookAt): 
     163    pass 
     164 
    134165class SphericalLookAt(Transformations.SphericalLookAt): 
    135166    def Execute(self, context): 
     
    138169    Draw = Execute 
    139170 
     171class SphericalLookAtMgd(ManagedTransformationMixin, SphericalLookAt): 
     172    pass 
     173 
    140174class Shear(Transformations.Shear): 
    141175    def Execute(self, context): 
     
    143177    Draw = Execute 
    144178 
     179class ShearMgd(ManagedTransformationMixin, Shear): 
     180    pass 
     181 
    145182class Skew(Transformations.Skew): 
    146183    def Execute(self, context): 
     
    148185    Draw = Execute 
    149186 
    150 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    151 #~ Title  
     187class SkewMgd(ManagedTransformationMixin, Skew): 
     188    pass 
     189 
     190#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     191#~ Projections 
    152192#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    153193 
     
    157197    Draw = Execute 
    158198 
     199class OrthographicMgd(ManagedTransformationMixin, Orthographic): 
     200    pass 
     201 
    159202class Frustum(Projections.Frustum): 
    160203    def Execute(self, context): 
     
    162205    Draw = Execute 
    163206 
     207class FrustumMgd(ManagedTransformationMixin, Frustum): 
     208    pass 
     209 
    164210class Perspective(Projections.Perspective): 
    165211    def Execute(self, context): 
     
    167213    Draw = Execute 
    168214 
     215class PerspectiveMgd(ManagedTransformationMixin, Perspective): 
     216    pass 
     217 
  • trunk/RBRapier/RBRapier/Tools/Geometry/Analysis/LocalityRemapper.py

    r345 r379  
    2424#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    2525 
     26from __future__ import generators 
     27import Numeric 
     28 
    2629#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    2730#~ Definitions  
     
    2932 
    3033class 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 
    3552 
    3653    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 
    3862 
    39     def RemapIndices(self, indexcollections): 
    40         pass 
     63    def RemapIndices(self, datacollections): 
     64        datacollections[:] = Numeric.take(datacollections, self.Remapping) 
    4165 
  • trunk/RBRapier/RBRapier/Tools/Geometry/Synthesis/VertexNormals.py

    r374 r379  
    3838        self.Normals = {} 
    3939 
    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 
    5365        return idx 
    5466 
    5567    def SetResults(self, VertexData, NormalData): 
    5668        srcVertex = self.owner.VertexData[self.idx] 
    57         for idx, normal in self.Normals.iteritems(): 
     69        for idx, (normal, blendable) in self.Normals.iteritems(): 
    5870            VertexData[idx] = srcVertex 
    5971            NormalData[idx] = normal.Normalize().asarray() 
     
    7486 
    7587    def SetTolerance(self, tolerance): 
    76         if tolerance is None: tolerance = Numeric.pi/8 
    77         self._cosToler = Numeric.cos(tolerance) 
     88        if tolerance is None: self._cosToler = None 
     89        else: self._cosToler = Numeric.cos(tolerance) 
    7890         
    7991    def GetResultantArrays(self): 
    80         #print len(self.VertexData), self.NextVertexIdx 
    8192        defval = (0.,0.,0.) 
    8293        self.NormalData = [defval for i in xrange(self.NextVertexIdx)] 
     
    91102            return None 
    92103        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 
    97111 
    98112    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     
    109123        e01 = (Vector3(self.VertexData[vi1]) - vector0).Normalize() 
    110124        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() 
    113130 
    114131#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
  • trunk/RBRapier/RBRapier/Tools/Visualizers/AxisSets.py

    r371 r379  
    2424#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    2525 
     26from OpenGL import GL 
     27from RBRapier.Renderer.AttributeMgr import AttributeChangeElement 
     28 
    2629#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    2730#~ Definitions  
    2831#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    2932 
     33class AxisLineSet(object): 
     34    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     35    #~ Constants / Variables / Etc.  
     36    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    3037 
     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  
    9292        GL.glBindTexture(GL.GL_TEXTURE_2D, self.TextureID) 
    9393        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) 
    9696 
    9797        GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_REPEAT) 
    9898        GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_REPEAT) 
    9999        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) 
    102102 
    103103    def Execute(self, context): 
  • trunk/RBRapier/RBRapier/Tools/Visualizers/ProjectionBoxes.py

    r378 r379  
    2626import Numeric 
    2727from OpenGL import GL 
     28from RBRapier.Renderer.AttributeMgr import AttributeChangeElement 
    2829from RBRapier.Renderer.Geometry.VertexArrays import VertexArray  
    2930from RBRapier.Renderer.Geometry.ArrayTraversal import IndexedCollectionTraversal  
     
    5152 
    5253    Projection = None 
     54    LineWidth = 4. 
     55    AttributeChange = AttributeChangeElement(GL.GL_LINE_BIT) 
    5356    _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) 
    5457 
     
    6265 
    6366    def Execute(self, context): 
     67        GL.glLineWidth(self.LineWidth) 
     68        GL.glColor4f(*self.color) 
    6469        self._UpdateBoxVertices() 
    6570        self._Vertices.Select(context) 
    6671        self._BoxTraversal.Execute(context) 
    6772        self._Vertices.Deselect(context) 
     73        GL.glLineWidth(1.) 
    6874 
    6975    def _UpdateBoxVertices(self): 
  • trunk/RBRapier/demo/Lightwave/scene.py

    r376 r379  
    4343 
    4444from RBRapier.Tools.Visualizers import Grids 
     45from RBRapier.Tools.Visualizers import AxisSets 
     46#from RBRapier.Tools.Visualizers import ProjectionBoxes 
    4547import Numeric 
    4648 
     
    7173 
    7274        self.Lighting = Lighting.LightingModel() 
     75        self.Lighting.Active = 1 
    7376        self.Sequence.AddElement(self.Lighting.Select) 
    7477        self.Lights = [] 
     
    126129        self.Sequence.AddElement(self.Grid) 
    127130 
    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) 
    135144 
    136145    def StripColoredLigthwaveLWO(self, name, *args, **kw): 
     
    140149        builder.IndexedTraversal = ArrayTraversal.ColoredIndexedCollectionTraversal 
    141150        GeoObj = builder.Build(open(name, 'rb'), *args, **kw) 
    142         self.Sequence.AddElement(GeoObj) 
     151        #self.Sequence.AddElement(GeoObj) 
    143152        return GeoObj 
    144153 
     
    147156        builder.GeoObjectFactory = GeoObject.DefaultGeoObject 
    148157        GeoObj = builder.Build(open(name, 'rb'), *args, **kw) 
    149         self.Sequence.AddElement(GeoObj) 
     158        #self.Sequence.AddElement(GeoObj) 
    150159        return GeoObj 
    151160