示例#1
0
  def __init__(self,manager,xml):
    self.surface = getWaterSurface(manager)
    self.surface.reparentTo(render)
    self.surface.hide(BitMask32.bit(1)) # Invisible to reflection camera (speedup)
    self.surface.hide(BitMask32.bit(2)) # Invisible to volumetric lighting camera (speedup)
    self.surface.hide(BitMask32.bit(3)) # Invisible to shadow cameras (speedup)
    self.surface.setShader(loader.loadShader(manager.get('paths').getConfig().find('shaders').get('path')+'/water.cg'))
    self.surface.setShaderInput('time', 0.0, 0.0, 0.0, 0.0)
    ntex = loader.loadTexture(manager.get('paths').getConfig().find('textures').get('path')+'/water-normal.png')
    ntex.setMinfilter(Texture.FTLinearMipmapLinear)
    self.surface.setShaderInput('normal', ntex)
    self.surface.setShaderInput('camera', base.cam)
    self.surface.setTransparency(TransparencyAttrib.MDual, 10)
    self.surface.setTwoSided(True)

    self.surface.setShaderInput('waveInfo', Vec4(0.4, 0.4, 0.4, 0))
    self.surface.setShaderInput('param2', Vec4(-0.015,0.005, 0.05, 0.05))
    self.surface.setShaderInput('param3', Vec4(0.7, 0.3, 0, 0))
    self.surface.setShaderInput('param4', Vec4(2.0, 0.5, 0.5, 0.0))
    #self.surface.setShaderInput('speed', Vec4(-.8, -.4, -.9, .3))
    self.surface.setShaderInput('speed', Vec4(0.2, -1.2, -0.2, -0.7))
    self.surface.setShaderInput('deepcolor', Vec4(0.0,0.3,0.5,1.0))
    self.surface.setShaderInput('shallowcolor', Vec4(0.0,1.0,1.0,1.0))
    self.surface.setShaderInput('reflectioncolor', Vec4(0.95,1.0,1.0,1.0))
    self.surface.hide()

    self.wbuffer = base.win.makeTextureBuffer('water', 512, 512)
    self.wbuffer.setClearColorActive(True)
    self.wbuffer.setClearColor(base.win.getClearColor())
    self.wcamera = base.makeCamera(self.wbuffer)
    if manager.get('sky') != None and manager.get('sky').model != None:
      self.sky = manager.get('sky').model.copyTo(self.wcamera)
      self.sky.setTwoSided(True)
      self.sky.setSz(self.sky, -1)
      self.sky.setClipPlaneOff(1)
      self.sky.show()
      self.sky.hide(BitMask32.bit(0)) # Hide for normal camera
      self.sky.hide(BitMask32.bit(2)) # Hide for volumetric lighting camera
      self.sky.hide(BitMask32.bit(3)) # Hide for shadow camera(s), if any
    else:
      self.sky = None
    self.wcamera.reparentTo(render)
    self.wcamera.node().setLens(base.camLens)
    self.wcamera.node().setCameraMask(BitMask32.bit(1))
    self.surface.hide(BitMask32.bit(1))
    wtexture = self.wbuffer.getTexture()
    wtexture.setWrapU(Texture.WMClamp)
    wtexture.setWrapV(Texture.WMClamp)
    wtexture.setMinfilter(Texture.FTLinearMipmapLinear)
    self.surface.setShaderInput('reflection', wtexture)
    self.wplane = Plane(Vec3(0, 0, 1), Point3(0, 0, 0))
    self.wplanenp = render.attachNewNode(PlaneNode('water', self.wplane))
    tmpnp = NodePath('StateInitializer')
    tmpnp.setClipPlane(self.wplanenp)
    tmpnp.setAttrib(CullFaceAttrib.makeReverse())
    self.wcamera.node().setInitialState(tmpnp.getState())

    #self.fog = Fog('UnderwaterFog')
    #self.fog.setColor(0.0,0.3,0.5)
    self.fogEnabled = False
示例#2
0
    def __init__(self, x1, y1, x2, y2, z):
        Att_base.__init__(self, False, "Water1")
        # Water surface
        maker = CardMaker( 'water' )
        maker.setFrame( x1, x2, y1, y2 )

        self.waterNP = render.attachNewNode(maker.generate())
        self.waterNP.setHpr(0,-90,0)
        self.waterNP.setPos(0,0,z)
        self.waterNP.setTransparency(TransparencyAttrib.MAlpha )
        self.waterNP.setShader(loader.loadShader( 'Shaders/water1.sha' ))

        # Reflection plane
        self.waterPlane = Plane( Vec3( 0, 0, z+1 ), Point3( 0, 0, z ) )

        planeNode = PlaneNode( 'waterPlane' )
        planeNode.setPlane( self.waterPlane )

        # Buffer and reflection camera
        self.buffer = base.win.makeTextureBuffer( 'waterBuffer', 512, 512 )
        self.buffer.setClearColor( Vec4( 0, 0, 0, 1 ) )

        cfa = CullFaceAttrib.makeReverse( )
        rs = RenderState.make(cfa)

        self.watercamNP = base.makeCamera( self.buffer )
        self.watercamNP.reparentTo(render)

        sa = ShaderAttrib.make()
        sa = sa.setShader(loader.loadShader('Shaders/splut3Clipped.sha') )

        self.cam = self.watercamNP.node()
        self.cam.getLens( ).setFov( base.camLens.getFov( ) )
        self.cam.getLens().setNear(1)
        self.cam.getLens().setFar(5000)
        self.cam.setInitialState( rs )
        self.cam.setTagStateKey('Clipped')
        self.cam.setTagState('True', RenderState.make(sa))


        # ---- water textures ---------------------------------------------

        # reflection texture, created in realtime by the 'water camera'
        tex0 = self.buffer.getTexture( )
        tex0.setWrapU(Texture.WMClamp)
        tex0.setWrapV(Texture.WMClamp)
        ts0 = TextureStage( 'reflection' )
        self.waterNP.setTexture( ts0, tex0 )

        # distortion texture
        tex1 = loader.loadTexture('Textures/water.png')
        ts1 = TextureStage('distortion')
        self.waterNP.setTexture(ts1, tex1)
示例#3
0
  def draw_body(self, position, vector_list, radius = 1, keep_drawing = True, num_vertices = 8):
    circle_geom = Geom(self.vdata)

    vertex_writer = GeomVertexWriter(self.vdata, "vertex")
    color_writer = GeomVertexWriter(self.vdata, "color")
    normal_writer = GeomVertexWriter(self.vdata, "normal")
    draw_rewriter = GeomVertexRewriter(self.vdata, "drawFlag")
    tex_rewriter = GeomVertexRewriter(self.vdata, "texcoord")

    start_row = self.vdata.getNumRows()
    vertex_writer.setRow(start_row)
    color_writer.setRow(start_row)
    normal_writer.setRow(start_row)

    sCoord = 0

    if start_row != 0:
      tex_rewriter.setRow(start_row - num_vertices)
      sCoord = tex_rewriter.getData2f().getX() + 1

      draw_rewriter.setRow(start_row - num_vertices)
      if draw_rewriter.getData1f() == False:
        sCoord -= 1

    draw_rewriter.setRow(start_row)
    tex_rewriter.setRow(start_row)

    angle_slice = 2 * math.pi / num_vertices
    current_angle = 0

    perp1 = vector_list[1]
    perp2 = vector_list[2]

    # write vertex information
    for i in range(num_vertices):
      adjacent_circle = position + (perp1 * math.cos(current_angle) + perp2 * math.sin(current_angle)) * radius
      normal = perp1 * math.cos(current_angle) + perp2 * math.sin(current_angle)
      normal_writer.addData3f(normal)
      vertex_writer.addData3f(adjacent_circle)
      tex_rewriter.addData2f(sCoord, (i + 0.001) / (num_vertices - 1))
      color_writer.addData4f(0.5, 0.5, 0.5, 1.0)
      draw_rewriter.addData1f(keep_drawing)
      current_angle += angle_slice

    draw_reader = GeomVertexReader(self.vdata, "drawFlag")
    draw_reader.setRow(start_row - num_vertices)

    # we can't draw quads directly so use Tristrips
    if start_row != 0 and draw_reader.getData1f() != False:
      lines = GeomTristrips(Geom.UHStatic)
      half = int(num_vertices * 0.5)
      for i in range(num_vertices):
        lines.addVertex(i + start_row)
        if i < half:
          lines.addVertex(i + start_row - half)
        else:
          lines.addVertex(i + start_row - half - num_vertices)

      lines.addVertex(start_row)
      lines.addVertex(start_row - half)
      lines.closePrimitive()
      lines.decompose()
      circle_geom.addPrimitive(lines)

      circle_geom_node = GeomNode("Debug")
      circle_geom_node.addGeom(circle_geom)

      circle_geom_node.setAttrib(CullFaceAttrib.makeReverse(), 1)

      self.get_model().attachNewNode(circle_geom_node)
示例#4
0
    def __init__(self, parent):
        self.parent = parent
        self.baseNode = self.parent.attachNewNode(self.__class__.__name__)

        x1 = -200
        y1 = -200
        x2 = 200
        y2 = 200
        z = 0.0

        #waterNP = NodePath("Water Node Parent")
        #waterNP.reparentTo(parent)

        #sn = self.drawSquare(-100, -100, 0, 100, 100, 0);
        #sn.reparentTo(self.baseNode)
        water = Square(self.baseNode, Point3(x1, y1, 0.2), Point3(x2, y2, 0.2),
                       Vec4(0.0, 0.0, 0.5, 0.5))
        wNp = water.draw()
        t1 = loader.loadTexture('assets/textures/wave.png')
        t1.setWrapU(Texture.WMRepeat)
        t1.setWrapV(Texture.WMRepeat)
        wNp.setTexture(t1)

        # Water Shader from
        # http://www.panda3d.org/forums/viewtopic.php?p=70853&sid=53d92b5ae1683bd9458f21d6026ad36e
        # anim: vx, vy, scale, skip
        # distort: offset, strength, refraction factor (0 = perfect mirror,
        #   1 = total refraction), refractivity
        anim = (.022, -.012, 2.5, 0)
        distort = (.1, 2, .5, .45)

        self.buffer = base.win.makeTextureBuffer('waterBuffer', 512, 512)
        self.watercamNP = base.makeCamera(self.buffer)

        # Create water surface using a card
        # The surface will be centered and
        maker = CardMaker('water')  # Water surface
        maker.setFrame(x1, x2, y1, y2)
        self.waterNP = self.baseNode.attachNewNode(maker.generate())
        self.waterNP.setPosHpr((0, 0, z), (0, -90, 0))
        self.waterNP.setTransparency(TransparencyAttrib.MAlpha)
        self.waterNP.setTwoSided(True)

        # Attach the water shader to the water shader surface
        waterShader = Shader.load("shaders/water.sha")
        self.waterNP.setShader(waterShader)
        self.waterNP.setShaderInput('wateranim', anim)
        self.waterNP.setShaderInput('waterdistort', distort)
        self.waterNP.setShaderInput('time', 0)

        self.waterPlane = Plane((0, 0, z + 1), (0, 0, z))  # Reflection plane
        PlaneNode('waterPlane').setPlane(self.waterPlane)

        self.buffer.setClearColor((0, 0, 0.5, 1))  # buffer

        self.watercamNP.reparentTo(self.baseNode)  # reflection camera
        cam = self.watercamNP.node()
        cam.getLens().setFov(base.camLens.getFov())
        cam.getLens().setNearFar(1, 5000)
        cam.setInitialState(RenderState.make(CullFaceAttrib.makeReverse()))
        cam.setTagStateKey('Clipped')
        cam.setTagState(
            'True',
            RenderState.make(ShaderAttrib.make().setShader(
                loader.loadShader('shaders/splut3Clipped.sha'))))

        tex0 = self.buffer.getTexture()  # reflection texture, created in
        # realtime by the 'water camera'
        tex0.setWrapU(Texture.WMClamp)
        tex0.setWrapV(Texture.WMClamp)
        self.waterNP.setTexture(TextureStage('reflection'), tex0)
        self.waterNP.setTexture(
            TextureStage('distortion'),
            loader.loadTexture(
                'assets/textures/water.png'))  # distortion texture

        self.task = taskMgr.add(self.update, 'waterUpdate', sort=50)
示例#5
0
文件: water.py 项目: figo-sh/naith
    def __init__(self, manager, xml):
        self.surface = getWaterSurface(manager)
        self.surface.reparentTo(render)
        self.surface.hide(BitMask32.bit(1))  # Invisible to reflection camera (speedup)
        self.surface.hide(BitMask32.bit(2))  # Invisible to volumetric lighting camera (speedup)
        self.surface.hide(BitMask32.bit(3))  # Invisible to shadow cameras (speedup)
        self.surface.setShader(
            loader.loadShader(manager.get("paths").getConfig().find("shaders").get("path") + "/water.cg")
        )
        self.surface.setShaderInput("time", 0.0, 0.0, 0.0, 0.0)
        ntex = loader.loadTexture(manager.get("paths").getConfig().find("textures").get("path") + "/water-normal.png")
        ntex.setMinfilter(Texture.FTLinearMipmapLinear)
        self.surface.setShaderInput("normal", ntex)
        self.surface.setShaderInput("camera", base.cam)
        self.surface.setTransparency(TransparencyAttrib.MDual, 10)
        self.surface.setTwoSided(True)

        self.surface.setShaderInput("waveInfo", Vec4(0.4, 0.4, 0.4, 0))
        self.surface.setShaderInput("param2", Vec4(-0.015, 0.005, 0.05, 0.05))
        self.surface.setShaderInput("param3", Vec4(0.7, 0.3, 0, 0))
        self.surface.setShaderInput("param4", Vec4(2.0, 0.5, 0.5, 0.0))
        # self.surface.setShaderInput('speed', Vec4(-.8, -.4, -.9, .3))
        self.surface.setShaderInput("speed", Vec4(0.2, -1.2, -0.2, -0.7))
        self.surface.setShaderInput("deepcolor", Vec4(0.0, 0.3, 0.5, 1.0))
        self.surface.setShaderInput("shallowcolor", Vec4(0.0, 1.0, 1.0, 1.0))
        self.surface.setShaderInput("reflectioncolor", Vec4(0.95, 1.0, 1.0, 1.0))
        self.surface.hide()

        self.wbuffer = base.win.makeTextureBuffer("water", 512, 512)
        self.wbuffer.setClearColorActive(True)
        self.wbuffer.setClearColor(base.win.getClearColor())
        self.wcamera = base.makeCamera(self.wbuffer)
        if manager.get("sky") != None and manager.get("sky").model != None:
            self.sky = manager.get("sky").model.copyTo(self.wcamera)
            self.sky.setTwoSided(True)
            self.sky.setSz(self.sky, -1)
            self.sky.setClipPlaneOff(1)
            self.sky.show()
            self.sky.hide(BitMask32.bit(0))  # Hide for normal camera
            self.sky.hide(BitMask32.bit(2))  # Hide for volumetric lighting camera
            self.sky.hide(BitMask32.bit(3))  # Hide for shadow camera(s), if any
        else:
            self.sky = None
        self.wcamera.reparentTo(render)
        self.wcamera.node().setLens(base.camLens)
        self.wcamera.node().setCameraMask(BitMask32.bit(1))
        self.surface.hide(BitMask32.bit(1))
        wtexture = self.wbuffer.getTexture()
        wtexture.setWrapU(Texture.WMClamp)
        wtexture.setWrapV(Texture.WMClamp)
        wtexture.setMinfilter(Texture.FTLinearMipmapLinear)
        self.surface.setShaderInput("reflection", wtexture)
        self.wplane = Plane(Vec3(0, 0, 1), Point3(0, 0, 0))
        self.wplanenp = render.attachNewNode(PlaneNode("water", self.wplane))
        tmpnp = NodePath("StateInitializer")
        tmpnp.setClipPlane(self.wplanenp)
        tmpnp.setAttrib(CullFaceAttrib.makeReverse())
        self.wcamera.node().setInitialState(tmpnp.getState())

        # self.fog = Fog('UnderwaterFog')
        # self.fog.setColor(0.0,0.3,0.5)
        self.fogEnabled = False
示例#6
0
	def __init__(self, world, x1, y1, x2, y2, z):
		self.world = world
		logging.info(('setting up water plane at z=' + str(z)))
		
		# Water surface
		maker = CardMaker('water')
		maker.setFrame(x1, x2, y1, y2)
		
		self.waterNP = render.attachNewNode(maker.generate())
		self.waterNP.setHpr(0, -90, 0)
		self.waterNP.setPos(0, 0, z)
		self.waterNP.setTransparency(TransparencyAttrib.MAlpha)
		self.waterNP.setShader(loader.loadShader('shaders/water.sha'))
		self.waterNP.setShaderInput('wateranim', Vec4(0.03, -0.015, 64.0, 0)) # vx, vy, scale, skip
		# offset, strength, refraction factor (0=perfect mirror, 1=total refraction), refractivity
		self.waterNP.setShaderInput('waterdistort', Vec4(0.4, 4.0, 0.25, 0.45))
		self.waterNP.setShaderInput('time', 0)
		
		# Reflection plane	
		self.waterPlane = Plane(Vec3(0, 0, z + 1), Point3(0, 0, z))
		planeNode = PlaneNode('waterPlane')
		planeNode.setPlane(self.waterPlane)
		
		# Buffer and reflection camera
		buffer = base.win.makeTextureBuffer('waterBuffer', 512, 512)
		buffer.setClearColor(Vec4(0, 0, 0, 1))
		
		cfa = CullFaceAttrib.makeReverse()
		rs = RenderState.make(cfa)
		
		self.watercamNP = base.makeCamera(buffer)
		self.watercamNP.reparentTo(render)
		
		#sa = ShaderAttrib.make()
		#sa = sa.setShader(loader.loadShader('shaders/splut3Clipped.sha') )
		
		cam = self.watercamNP.node()
		cam.getLens().setFov(base.camLens.getFov())
		cam.getLens().setNear(1)
		cam.getLens().setFar(5000)
		cam.setInitialState(rs)
		cam.setTagStateKey('Clipped')
		#cam.setTagState('True', RenderState.make(sa))
		
		# ---- water textures -----------------------------------------------
		
		#reflection texture, created in realtime by the 'water camera'
		tex0 = buffer.getTexture()
		tex0.setWrapU(Texture.WMClamp)
		tex0.setWrapV(Texture.WMClamp)
		ts0 = TextureStage('reflection')
		self.waterNP.setTexture(ts0, tex0)
		
		# distortion texture
		tex1 = loader.loadTexture('textures/water.png')
		ts1 = TextureStage('distortion')
		self.waterNP.setTexture(ts1, tex1)
		
		# ---- Fog --- broken
		min = Point3(x1, y1, -999.0)
		max = Point3(x2, y2, z)
		boundry = BoundingBox(min, max
		self.waterFog = Fog('waterFog')
		self.waterFog.setBounds(boundry)
		colour = (0.2, 0.5, 0.8)
		self.waterFog.setColor(*colour)
		self.waterFog.setExpDensity(0.05)
		render.attachNewNode(self.waterFog)
		#render.setFog(world.waterFog)
		taskMgr.add(self.update, "waterTask")
		
	def update(self, task):
		# update matrix of the reflection camera
		mc = base.camera.getMat()
		mf = self.waterPlane.getReflectionMat()
		self.watercamNP.setMat(mc * mf)
		self.waterNP.setShaderInput('time', task.time)
		self.waterNP.setX(self.world.ralph.getX())
		self.waterNP.setY(self.world.ralph.getY())
		return task.cont
示例#7
0
    def __init__(self, world, x1, y1, x2, y2, z):
        self.world = world
        logging.info(('setting up water plane at z=' + str(z)))

        # Water surface
        maker = CardMaker('water')
        maker.setFrame(x1, x2, y1, y2)

        self.waterNP = render.attachNewNode(maker.generate())
        self.waterNP.setHpr(0, -90, 0)
        self.waterNP.setPos(0, 0, z)
        self.waterNP.setTransparency(TransparencyAttrib.MAlpha)
        self.waterNP.setShader(loader.loadShader('shaders/water.sha'))
        self.waterNP.setShaderInput('wateranim',
                                    Vec4(0.03, -0.015, 64.0,
                                         0))  # vx, vy, scale, skip
        # offset, strength, refraction factor (0=perfect mirror, 1=total refraction), refractivity
        self.waterNP.setShaderInput('waterdistort', Vec4(0.4, 4.0, 0.25, 0.45))
        self.waterNP.setShaderInput('time', 0)

        # Reflection plane
        self.waterPlane = Plane(Vec3(0, 0, z + 1), Point3(0, 0, z))
        planeNode = PlaneNode('waterPlane')
        planeNode.setPlane(self.waterPlane)

        # Buffer and reflection camera
        buffer = base.win.makeTextureBuffer('waterBuffer', 512, 512)
        buffer.setClearColor(Vec4(0, 0, 0, 1))

        cfa = CullFaceAttrib.makeReverse()
        rs = RenderState.make(cfa)

        self.watercamNP = base.makeCamera(buffer)
        self.watercamNP.reparentTo(render)

        #sa = ShaderAttrib.make()
        #sa = sa.setShader(loader.loadShader('shaders/splut3Clipped.sha') )

        cam = self.watercamNP.node()
        cam.getLens().setFov(base.camLens.getFov())
        cam.getLens().setNear(1)
        cam.getLens().setFar(5000)
        cam.setInitialState(rs)
        cam.setTagStateKey('Clipped')
        #cam.setTagState('True', RenderState.make(sa))

        # ---- water textures ---------------------------------------------

        # reflection texture, created in realtime by the 'water camera'
        tex0 = buffer.getTexture()
        tex0.setWrapU(Texture.WMClamp)
        tex0.setWrapV(Texture.WMClamp)
        ts0 = TextureStage('reflection')
        self.waterNP.setTexture(ts0, tex0)

        # distortion texture
        tex1 = loader.loadTexture('textures/water.png')
        ts1 = TextureStage('distortion')
        self.waterNP.setTexture(ts1, tex1)

        # ---- Fog --- broken
        min = Point3(x1, y1, -999.0)
        max = Point3(x2, y2, z)
        boundry = BoundingBox(min, max)
        self.waterFog = Fog('waterFog')
        self.waterFog.setBounds(boundry)
        colour = (0.2, 0.5, 0.8)
        self.waterFog.setColor(*colour)
        self.waterFog.setExpDensity(0.05)
        render.attachNewNode(self.waterFog)
        #render.setFog(world.waterFog)
        taskMgr.add(self.update, "waterTask")
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)
示例#9
0
    def __init__(self, parent):
        self.parent = parent
        self.baseNode = self.parent.attachNewNode(self.__class__.__name__)
        
        x1 = -200
        y1 = -200
        x2 =  200
        y2 =  200
        z  =  0.0
        
        #waterNP = NodePath("Water Node Parent")
        #waterNP.reparentTo(parent)
        
        #sn = self.drawSquare(-100, -100, 0, 100, 100, 0);
        #sn.reparentTo(self.baseNode)
        water = Square(self.baseNode,
                       Point3(x1, y1, 0.2),
                       Point3(x2, y2, 0.2),
                       Vec4(0.0,0.0,0.5,0.5))
        wNp = water.draw()
        t1 = loader.loadTexture( 'assets/textures/wave.png' )
        t1.setWrapU(Texture.WMRepeat)
        t1.setWrapV(Texture.WMRepeat)
        wNp.setTexture(t1)
        
        # Water Shader from
        # http://www.panda3d.org/forums/viewtopic.php?p=70853&sid=53d92b5ae1683bd9458f21d6026ad36e
        # anim: vx, vy, scale, skip
        # distort: offset, strength, refraction factor (0 = perfect mirror,
        #   1 = total refraction), refractivity
        anim = ( .022, -.012, 2.5, 0 )
        distort = ( .1, 2, .5, .45 )
        
        self.buffer = base.win.makeTextureBuffer( 'waterBuffer', 512, 512 )
        self.watercamNP = base.makeCamera( self.buffer )
        
        # Create water surface using a card
        # The surface will be centered and 
        maker = CardMaker( 'water' ) # Water surface
        maker.setFrame( x1, x2, y1, y2 )
        self.waterNP = self.baseNode.attachNewNode( maker.generate() )
        self.waterNP.setPosHpr( ( 0, 0, z ), ( 0, -90, 0 ) )
        self.waterNP.setTransparency( TransparencyAttrib.MAlpha )
        self.waterNP.setTwoSided(True)
        
        # Attach the water shader to the water shader surface
        waterShader = Shader.load("shaders/water.sha")
        self.waterNP.setShader(waterShader)
        self.waterNP.setShaderInput('wateranim',    anim )
        self.waterNP.setShaderInput('waterdistort', distort )
        self.waterNP.setShaderInput('time',         0 )
        
        self.waterPlane = Plane( ( 0, 0, z + 1 ), ( 0, 0, z ) ) # Reflection plane
        PlaneNode( 'waterPlane' ).setPlane( self.waterPlane )
        
        self.buffer.setClearColor( ( 0, 0, 0.5, 1 ) ) # buffer

        self.watercamNP.reparentTo( self.baseNode ) # reflection camera
        cam = self.watercamNP.node()
        cam.getLens().setFov( base.camLens.getFov() )
        cam.getLens().setNearFar( 1, 5000 )
        cam.setInitialState( RenderState.make( CullFaceAttrib.makeReverse() ) )
        cam.setTagStateKey( 'Clipped' )
        cam.setTagState('True', RenderState.make(
          ShaderAttrib.make().setShader(
            loader.loadShader( 'shaders/splut3Clipped.sha' ) ) ) )
        
        tex0 = self.buffer.getTexture() # reflection texture, created in
                                             # realtime by the 'water camera'
        tex0.setWrapU( Texture.WMClamp ); tex0.setWrapV( Texture.WMClamp )
        self.waterNP.setTexture( TextureStage( 'reflection' ), tex0 )
        self.waterNP.setTexture( TextureStage( 'distortion' ),
          loader.loadTexture( 'assets/textures/water.png' ) ) # distortion texture
        
        self.task = taskMgr.add( self.update, 'waterUpdate', sort = 50 )