Код
from panda3d.core import *
import direct.directbase.DirectStart
import random
class Water():
def __init__(self):
cm = CardMaker("water")
cm.setFrame(-1, 1, -1, 1)
self.water = render.attachNewNode(cm.generate())
self.water.setScale(4096)
self.water.lookAt(0, 0, -1)
self.water.setZ(1)
self.water.setShaderOff(1)
self.water.setLightOff(1)
self.water.setAlphaScale(0.5)
self.water.setTransparency(TransparencyAttrib.MAlpha)
wbuffer = base.win.makeTextureBuffer("water", 512, 512)
wbuffer.setClearColorActive(True)
wbuffer.setClearColor(base.win.getClearColor())
self.wcamera = base.makeCamera(wbuffer)
self.wcamera.reparentTo(render)
self.wcamera.node().setLens(base.camLens)
self.wcamera.node().setCameraMask(BitMask32.bit(1))
self.water.hide(BitMask32.bit(1))
#fir.hide(BitMask32.bit(1))
wtexture = wbuffer.getTexture()
wtexture.setWrapU(Texture.WMClamp)
wtexture.setWrapV(Texture.WMClamp)
wtexture.setMinfilter(Texture.FTLinearMipmapLinear)
self.wplane = Plane(Vec3(0, 0, 1), Point3(0, 0, self.water.getZ()))
wplanenp = render.attachNewNode(PlaneNode("water", self.wplane))
tmpnp = NodePath("StateInitializer")
tmpnp.setClipPlane(wplanenp)
tmpnp.setAttrib(CullFaceAttrib.makeReverse())
self.wcamera.node().setInitialState(tmpnp.getState())
self.water.projectTexture(TextureStage("reflection"), wtexture, self.wcamera)
base.bufferViewer.toggleEnable()
taskMgr.add(self.update, 'water cam update')
def update(self, task):
self.wcamera.setMat(base.cam.getMat(render) * self.wplane.getReflectionMat())
return task.cont
w = Water()
box = loader.loadModel('box')
for i in xrange(50):
newbox = box.copyTo(render)
newbox.setPos(random.randrange(-20, 20), random.randrange(-20, 20), random.randrange(0, 20))
for i in xrange(6):
newbox = box.copyTo(render)
newbox.setScale(random.randrange(10, 25))
newbox.setPos(random.randrange(-100, 100), random.randrange(-100, 100), random.randrange(-15, -5))
newbox.setHpr(random.randrange(360), random.randrange(360), random.randrange(360))
run()