Esempio n. 1
0
    tri2.closePrimitive()

    square = Geom(vdata)
    square.addPrimitive(tri1)
    square.addPrimitive(tri2)

    return square


square0 = makeSquare(-1, -1, -1, 1, -1, 1)
square1 = makeSquare(-1, 1, -1, 1, 1, 1)
square2 = makeSquare(-1, 1, 1, 1, -1, 1)
square3 = makeSquare(-1, 1, -1, 1, -1, -1)
square4 = makeSquare(-1, -1, -1, -1, 1, 1)
square5 = makeSquare(1, -1, -1, 1, 1, 1)
snode = GeomNode('square')
snode.addGeom(square0)
snode.addGeom(square1)
snode.addGeom(square2)
snode.addGeom(square3)
snode.addGeom(square4)
snode.addGeom(square5)

cube = render.attachNewNode(snode)
cube.hprInterval(1.5, Point3(360, 360, 360)).loop()

#OpenGl by default only draws "front faces" (polygons whose vertices are specified CCW).
cube.setTwoSided(True)


class MyTapper(DirectObject):
Esempio n. 2
0
def drawBody(nodePath, vdata, pos, vecList, radius=1, keepDrawing=True,numVertices=8):

  circleGeom=Geom(vdata)

  vertWriter=GeomVertexWriter(vdata, "vertex")
  colorWriter=GeomVertexWriter(vdata, "color")
  normalWriter=GeomVertexWriter(vdata, "normal")
  drawReWriter=GeomVertexRewriter(vdata, "drawFlag")
  texReWriter=GeomVertexRewriter(vdata, "texcoord")


  startRow=vdata.getNumRows()
  vertWriter.setRow(startRow)
  colorWriter.setRow(startRow)
  normalWriter.setRow(startRow)

  sCoord=0

  if (startRow!=0):
    texReWriter.setRow(startRow-numVertices)
    sCoord=texReWriter.getData2f().getX()+1

    drawReWriter.setRow(startRow-numVertices)
    if(drawReWriter.getData1f()==False):
      sCoord-=1

  drawReWriter.setRow(startRow)
  texReWriter.setRow(startRow)

  angleSlice=2*math.pi/numVertices
  currAngle=0

  #axisAdj=Mat4.rotateMat(45, axis)*Mat4.scaleMat(radius)*Mat4.translateMat(pos)

  perp1=vecList[1]
  perp2=vecList[2]

  #vertex information is written here
  for i in range(numVertices):
    adjCircle=pos+(perp1*math.cos(currAngle)+perp2*math.sin(currAngle))*radius
    normal=perp1*math.cos(currAngle)+perp2*math.sin(currAngle)
    normalWriter.addData3f(normal)
    vertWriter.addData3f(adjCircle)
    texReWriter.addData2f(sCoord,(i+0.001)/(numVertices-1))
    colorWriter.addData4f(0.5,0.5,0.5,1)
    drawReWriter.addData1f(keepDrawing)
    currAngle+=angleSlice


  drawReader=GeomVertexReader(vdata, "drawFlag")
  drawReader.setRow(startRow-numVertices)

  #we cant draw quads directly so we use Tristrips
  if (startRow!=0) & (drawReader.getData1f()!=False):
    lines=GeomTristrips(Geom.UHStatic)
    half=int(numVertices*0.5)
    for i in range(numVertices):
      lines.addVertex(i+startRow)
      if i< half:
        lines.addVertex(i+startRow-half)
      else:
        lines.addVertex(i+startRow-half-numVertices)

    lines.addVertex(startRow)
    lines.addVertex(startRow-half)
    lines.closePrimitive()
    lines.decompose()
    circleGeom.addPrimitive(lines)


    circleGeomNode=GeomNode("Debug")
    circleGeomNode.addGeom(circleGeom)

    #I accidentally made the front-face face inwards. Make reverse makes the tree render properly and
      #should cause any surprises to any poor programmer that tries to use this code
    circleGeomNode.setAttrib(CullFaceAttrib.makeReverse(),1)
    global numPrimitives
    numPrimitives+=numVertices*2

    nodePath.attachNewNode(circleGeomNode)
Esempio n. 3
0
	tri2.closePrimitive()


	square=Geom(vdata)
	square.addPrimitive(tri1)
	square.addPrimitive(tri2)
	
	return square

square0=makeSquare(-1,-1,-1, 1,-1, 1)
square1=makeSquare(-1, 1,-1, 1, 1, 1)
square2=makeSquare(-1, 1, 1, 1,-1, 1)
square3=makeSquare(-1, 1,-1, 1,-1,-1)
square4=makeSquare(-1,-1,-1,-1, 1, 1)
square5=makeSquare( 1,-1,-1, 1, 1, 1)
snode=GeomNode('square')
snode.addGeom(square0)
snode.addGeom(square1)
snode.addGeom(square2)
snode.addGeom(square3)
snode.addGeom(square4)
snode.addGeom(square5)

cube=render.attachNewNode(snode)
cube.hprInterval(1.5,Point3(360,360,360)).loop()

#OpenGl by default only draws "front faces" (polygons whose vertices are specified CCW).
cube.setTwoSided(True)

class MyTapper(DirectObject):
	def __init__(self):