def glDrawSplit(this): if not this.projectedTo3D: try: del this.cells except AttributeError: pass Ns3D = [] if this.rot4 != None: Vs4D = [this.rot4 * v for v in this.Vs] # TODO fix Ns.. if needed.. # if this.Ns != []: # Ns4D = [this.rot4*n for n in this.Ns] else: Vs4D = [v for v in this.Vs] Vs3D = this.projectVsTo3D(Vs4D) #if this.Ns != []: # Ns3D = this.projectVsTo3D(Ns4D) this.cells = [] # Add a cell for just the edges: if this.e.draw: cell = Geom3D.SimpleShape( Vs3D, [], this.Es, [], # Vs , Fs, Es, Ns name='%s_Es' % (this.name)) cell.setVertexProperties(radius=this.v.radius, color=this.v.col) cell.setEdgeProperties(radius=this.e.radius, color=this.e.col, drawEdges=this.e.draw) cell.setFaceProperties(drawFaces=False) cell.glInitialised = True this.cells.append(cell) # Add a shape with faces for each cell for i in xrange(len(this.Cs)): if this.c.draw: colors = (this.c.col[0][this.c.col[1][i]], []) else: colors = (this.f.col[0], this.f.col[1][i]) #print colors cell = Geom3D.SimpleShape( Vs3D, this.Cs[i], [], [], # Vs , Fs, Es, Ns colors, name='%s_%d' % (this.name, i)) # The edges and vertices are drawn through a separate shape below. cell.setVertexProperties(radius=-1) cell.setEdgeProperties(drawEdges=False) cell.setFaceProperties(drawFace=this.f.draw) cell.scale(this.c.scale) cell.glInitialised = True this.cells.append(cell) this.projectedTo3D = True
GeomTypes.Vec3([-1, -1, -1]), GeomTypes.Vec3([ 1, -1, -1]), GeomTypes.Vec3([ 1, 1, -2]), GeomTypes.Vec3([.5, 1, 1]), ] Fs = [ [0, 1, 2, 3], [0, 3, 7, 4], [1, 0, 4, 5], [2, 1, 5, 6], [3, 2, 6, 7], [7, 6, 5, 4] ] shape0 = Geom3D.SimpleShape(Vs = Vs, Fs = Fs) Vs = [ GeomTypes.Vec3([ 0, 0, 2]), GeomTypes.Vec3([ 2, 0, 0]), GeomTypes.Vec3([ 0, 2, 0]), GeomTypes.Vec3([-2, 0, 0]), GeomTypes.Vec3([ 0, -2, 0]), GeomTypes.Vec3([ 0, 0, 2]), ] Fs = [ [0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 1],
import Geom3D import GeomTypes import math Vs = [ GeomTypes.Vec3([ 1, 1, 1]), GeomTypes.Vec3([-1, 1, 1]), GeomTypes.Vec3([-1, -1, 1]), GeomTypes.Vec3([ 1, -1, 1]), GeomTypes.Vec3([ 1, 1, -1]), GeomTypes.Vec3([-1, 1, -1]), GeomTypes.Vec3([-1, -1, -1]), GeomTypes.Vec3([ 1, -1, -1]), GeomTypes.Vec3([ 1, 1, -2]), GeomTypes.Vec3([.5, 1, 1]), ] Fs = [ [0, 4, 8], # just a line [0, 9, 1, 2, 3],# first part on line, cannot be used to calc face normal [0, 3, 7, 4], [1, 0, 4, 5], [2, 1, 5, 6], [3, 2, 6, 7], [7, 6, 5, 4] ] shape = Geom3D.SimpleShape(Vs = Vs, Fs = Fs)
import GeomTypes import Geom3D import isometry shape = Geom3D.CompoundShape(simpleShapes=[ Geom3D.SimpleShape(Vs=[ GeomTypes.Vec3([1.0, 1.0, 1.0]), GeomTypes.Vec3([-1.0, 1.0, 1.0]), GeomTypes.Vec3([-1.0, -1.0, 1.0]), GeomTypes.Vec3([1.0, -1.0, 1.0]), GeomTypes.Vec3([1.0, 1.0, -1.0]), GeomTypes.Vec3([-1.0, 1.0, -1.0]), GeomTypes.Vec3([-1.0, -1.0, -1.0]), GeomTypes.Vec3([1.0, -1.0, -1.0]), GeomTypes.Vec3([1.0, 1.0, -2.0]), GeomTypes.Vec3([0.5, 1.0, 1.0]) ], Fs=[[0, 1, 2, 3], [0, 3, 7, 4], [1, 0, 4, 5], [2, 1, 5, 6], [3, 2, 6, 7], [7, 6, 5, 4]], Es=[], colors=([[0.99609400000000003, 0.0, 0.0]], [0, 0, 0, 0, 0, 0]), name="SimpleShape"), Geom3D.SimpleShape(Vs=[ GeomTypes.Vec3([0.0, 0.0, 2.0]), GeomTypes.Vec3([2.0, 0.0, 0.0]), GeomTypes.Vec3([0.0, 2.0, 0.0]), GeomTypes.Vec3([-2.0, 0.0, 0.0]), GeomTypes.Vec3([0.0, -2.0, 0.0]), GeomTypes.Vec3([0.0, 0.0, 2.0]) ], Fs=[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 1],
def glDrawSingleRemoveUnscaledEdges(this): isScaledDown = not Geom3D.eq(this.c.scale, 1.0, margin=0.001) if not this.projectedTo3D: # print 'reprojecting...' try: del this.cell except AttributeError: pass Ns3D = [] if this.rot4 != None: Vs4D = [this.rot4 * v for v in this.Vs] # TODO fix Ns.. if needed.. # if this.Ns != []:cleanUp # Ns4D = [this.rot4*n for n in this.Ns] else: Vs4D = [v for v in this.Vs] Vs3D = this.projectVsTo3D(Vs4D) #for i in range(0, len(this.Es), 2): # v0 = Vs4D[this.Es[i]] # v1 = Vs4D[this.Es[i+1]] # print 'delta v:', v0 - v1 # print 'Edge [%d, %d]; len:' % (this.Es[i], this.Es[i+1]), (v1-v0).length() #if this.Ns != []: # Ns3D = this.projectVsTo3D(Ns4D) # Now project all to one 3D shape. 1 3D shape is chosen, instean of # projecting each cell to one shape because of different reasons: # - when drawing transparent faces all the opaqe fae should be # drawn first. # - if drawing the cells per shape, the glVertexPointer should be # called for each cell. (Currently SimpleShape will not call this # function unless the vertices have been changed... shapeVs = [] shapeEs = [] shapeFs = [] shapeColIndices = [] if this.c.draw: shapeCols = this.c.col[0] else: shapeCols = this.f.col[0] if this.removeTransparency: shapeCols = [c[0:3] for c in shapeCols] if this.e.draw and (not isScaledDown or this.e.showUnscaled): shapeVs = Vs3D shapeEs = this.Es # Add a shape with faces for each cell for i in xrange(len(this.Cs)): # use a copy, since we will filter (v indices will change): cellFs = [f[:] for f in this.Cs[i]] if this.c.draw: shapeColIndices.extend([this.c.col[1][i] for f in cellFs]) else: shapeColIndices.extend(this.f.col[1][i]) # Now cleanup Vs3D # TODO # if this.e.draw and (not isScaledDown or this.e.showUnscaled): # Then shapeVs = Vs3D already, and the code below is all # unecessary. cellVs = Vs3D[:] nrUsed = glue.cleanUpVsFs(cellVs, cellFs) # Now attaching to current Vs, will change index: offset = len(shapeVs) cellFs = [[vIndex + offset for vIndex in f] for f in cellFs] # Now scale from gravitation centre: if isScaledDown: g = GeomTypes.Vec3([0, 0, 0]) sum = 0 for vIndex in range(len(cellVs)): g = g + nrUsed[vIndex] * GeomTypes.Vec3(cellVs[vIndex]) sum = sum + nrUsed[vIndex] if sum != 0: g = g / sum #print this.name, 'g:', g cellVs = [ this.c.scale * (GeomTypes.Vec3(v) - g) + g for v in cellVs ] shapeVs.extend(cellVs) shapeFs.extend(cellFs) # for shapeColIndices.extend() see above this.cell = Geom3D.SimpleShape( shapeVs, shapeFs, shapeEs, [], # Vs , Fs, Es, Ns (shapeCols, shapeColIndices), name='%s_projection' % (this.name)) this.cell.setVertexProperties(radius=this.v.radius, color=this.v.col) this.cell.setEdgeProperties(radius=this.e.radius, color=this.e.col, drawEdges=this.e.draw) this.cell.setFaceProperties(drawFaces=this.f.draw) this.cell.glInitialised = True # done as first step in this func this.projectedTo3D = True this.updateTransparency = False if this.e.draw and isScaledDown: this.cell.recreateEdges() # Don't use, out of performance issues: # cellEs = this.cell.getEdgeProperties()['Es'] # -------------------------- # Bad performance during scaling: # cellEs = this.cell.getEdgeProperties()['Es'] # this.cell.recreateEdges() # cellEs.extend(this.cell.getEdgeProperties()['Es']) # -------end bad perf--------- cellEs = this.cell.Es if this.e.showUnscaled: cellEs.extend(this.Es) this.cell.setEdgeProperties(Es=cellEs) if this.updateTransparency: cellCols = this.cell.getFaceProperties()['colors'] if this.removeTransparency: shapeCols = [c[0:3] for c in cellCols[0]] else: if this.c.draw: shapeCols = this.c.col[0] else: shapeCols = this.f.col[0] cellCols = (shapeCols, cellCols[1]) this.cell.setFaceProperties(colors=cellCols) this.updateTransparency = False