taribo
29-07-2006 14:37:02
I'd like to do a textured background for my scene that is "aligned" with the camera... in the sense that this texture will be behind the objects and when i move the camera i could see all the texture.
Like "target" of this example...
http://www.ogre3d.org/phpBB2addons/viewtopic.php?t=733&highlight=mouse
but target will be behind the objects
how could i do? with cegui?
pls help me
taribo
30-07-2006 09:58:40
this is the example:
the background is a texture and the pawns are 3d spheres
taribo
31-07-2006 10:51:39
I've thought to use getViewport function but is possible to give to him a texture? and how can i do?
the code that i'm thinking is something like this:
material = ogre.MaterialPointer(ogre.MaterialManager.getSingleton().create("Background", "General"))
material.getTechnique(0).getPass(0).createTextureUnitState("Chinese_Cam1_B.bmp")
self.renderWindow.getViewport(0).backgroundTexture = material
is there something to do this?
help me pls
viblo2
31-07-2006 12:11:51
Why not just place a big box or a plane in the back with the texture on it?
dermont
31-07-2006 13:21:51
Try using a default plane (or manually created one) as a childnode of your camera node and manipulate the camera node instead of the camera as suggested here:
http://www.ogre3d.org/phpBB2/viewtopic. ... background
Also read up on material settings:
http://www.ogre3d.org/docs/manual/manual_14.html#SEC23
e.g., progre1.2 (but shouldn't be many changes):
# This code is in the Public Domain
import pyogre.ogre as ogre
import SampleFramework as sf
import math
class ColourCubeApplication(sf.Application):
def ManualPlane(self, name = "planeMesh", size=(620,480), axis=(1,1,0),w=1,h=1 ):
meshMgr = ogre.MeshManager.getSingleton()
mesh = meshMgr.createManual(name, ogre.ResourceManager.DEFAULT_RESOURCE_GROUP_NAME)
subMesh = mesh.createSubMesh()
x,y = size
x /= 2.0
y /= 2.0
vert_pos = [
(-x * axis[0], -y * axis[1], -y* axis[2]),
(x * axis[0], -y * axis[1], -y* axis[2]),
(x * axis[0], y * axis[1], y* axis[2]),
(-x * axis[0], y * axis[1], y* axis[2])
]
vert_norm = [
(0,1,0),
(0,1,0),
(0,1,0),
(0,1,0)
]
tex_coords = [
(0,h),
(w,h),
(w,0),
(0,0)
]
faces = [
0,1,2,
0,2,3
]
POSITION_ELEMENT = 0
NORMAL_ELEMENT = 1
TEXTURE_ELEMENT = 2
mesh.get().sharedVertexData = ogre.VertexData()
mesh.sharedVertexData.vertexCount = len(vert_pos)
#work-around to prevent destruction
self.sharedVertexData = mesh.sharedVertexData
decl = mesh.sharedVertexData.vertexDeclaration
offset = 0
decl.addElement(0, offset, ogre.VET_FLOAT3, ogre.VES_POSITION)
offset += ogre.VertexElement.getTypeSize(ogre.VET_FLOAT3)
decl.addElement(0, offset, ogre.VET_FLOAT3, ogre.VES_NORMAL)
offset += ogre.VertexElement.getTypeSize(ogre.VET_FLOAT3)
decl.addElement(0, offset, ogre.VET_FLOAT2, ogre.VES_TEXTURE_COORDINATES)
offset += ogre.VertexElement.getTypeSize(ogre.VET_FLOAT2)
hBuffMgr = ogre.HardwareBufferManager.getSingleton()
vbuf = hBuffMgr.createVertexBuffer(offset, mesh.sharedVertexData.vertexCount, ogre.HardwareBuffer.HBU_STATIC_WRITE_ONLY)
pVertex = vbuf.lock(decl, ogre.HardwareBuffer.HBL_DISCARD)
#loop through the vert_pos array
for i in range(0, len(vert_pos)):
vx, vy, vz = vert_pos[i]
nx, ny, nz = vert_norm[i]
tu, tv = tex_coords [i]
pVertex.setFloat(i, POSITION_ELEMENT, vx, vy, vz)
pVertex.setFloat(i, NORMAL_ELEMENT, nx, ny, nz)
pVertex.setFloat(i, TEXTURE_ELEMENT, tu, tv)
bind = mesh.sharedVertexData.vertexBufferBinding
bind.setBinding(0,vbuf)
vbuf.unlock()
# faces
subMesh.indexData.indexCount = len(faces)
subMesh.indexData.indexBuffer = hBuffMgr.createIndexBuffer(ogre.HardwareIndexBuffer.IT_16BIT, len(faces), ogre.HardwareBuffer.HBU_STATIC_WRITE_ONLY)
ibuf = subMesh.indexData.indexBuffer
subMesh.indexData.indexBuffer.writeIndexes(0, faces)
subMesh.useSharedVertices = True
subMesh.indexData.indexBuffer = ibuf
subMesh.indexData.indexCount = len(faces)
subMesh.indexData.indexStart = 0
p = 100000.0
mesh._setBounds(ogre.AxisAlignedBox(-p,-p,-p,p,p,p))
mesh._setBoundingSphereRadius(p)
self.indexData = subMesh.indexData
mesh.load()
def _planeBackGround(self):
# create background plane
plane = ogre.Plane()
plane.normal = ogre.Vector3.UNIT_Y
plane.d = 200
mm = ogre.MeshManager.getSingleton()
mm.createPlane('FloorPlane', 'General', plane, 800.0, 600.0,
5, 5, True, 1, 5.0, 5.0, (0, 0, 1))
backEntity = self.sceneManager.createEntity('floor', 'FloorPlane')
backEntity.setMaterialName('Examples/OgreLogo')
return backEntity
def _manualPlaneBackGround(self):
self.ManualPlane(name = "planeMesh", size=(800,640), axis=[1,0,-1],w=1,h=1)
self.planeEntity = self.sceneManager.createEntity("myPlaneEntity", "planeMesh")
material = ogre.MaterialPointer(ogre.MaterialManager.getSingleton().create("Background", "General"))
material.getTechnique(0).getPass(0).createTextureUnitState("rockwall.tga")
# these should be false but onlt tusks are shown ??
material.getTechnique(0).getPass(0).depthCheckEnabled = True
material.getTechnique(0).getPass(0).depthWriteEnabled = True
material.getTechnique(0).getPass(0).lightingEnabled = True
material.getTechnique(0).getPass(0).manualCullingMode = ogre.CULL_NONE
material.getTechnique(0).ambient = (0.8 ,0.8 ,0.8)
#material.getTechnique(0).getPass(0).depthCheckEnabled = False
#material.getTechnique(0).getPass(0).depthWriteEnabled = False
#material.getTechnique(0).getPass(0).lightingEnabled = False
self.planeEntity.setMaterialName("Background")
return self.planeEntity
def _createScene(self):
sceneManager = self.sceneManager
#sceneManager.ambientLight = 0.7, 0.7, 0.7
light = sceneManager.createLight('MainLight')
light.position = 20, 80, 50
# create head entity
headNode = sceneManager.rootSceneNode.createChildSceneNode()
entity = sceneManager.createEntity('head', 'ogrehead.mesh')
headNode.attachObject(entity)
headNode.showBoundingBox = True
#backEntity = self._planeBackGround()
backEntity = self._manualPlaneBackGround()
lookatpos = (1.023376522e-016, 0.8356779456, -0.5492197841)
self.camera.position = (0, 1013, 0)
self.camera.lookAt(lookatpos)
# create camera node
cameraNode = sceneManager.rootSceneNode.createChildSceneNode()
cameraNode.attachObject(self.camera)
# create child node for cameras node and attach background
#self.nd2=sceneManager.rootSceneNode.createChildSceneNode()
self.nd2=cameraNode.createChildSceneNode()
self.nd2.attachObject(backEntity)
self.nd2.showBoundingBox = True
# remove for manual plane / and/or set for cameras fovy
#self.nd2.translate(0,0,-400)
self.nd2.renderQueueGroup = ogre.RENDER_QUEUE_BACKGROUND
# moving this will increase rotation arc
headNode.translate(0, 0, 15)
self.cameraNode = cameraNode
def _createFrameListener(self):
self.frameListener = GeneralListener(self.renderWindow, self.camera, self.cameraNode)
self.root.addFrameListener(self.frameListener)
class GeneralListener(sf.FrameListener):
def __init__(self, renderWindow, camera, cameraNode):
self.cameraNode = cameraNode
sf.FrameListener.__init__(self, renderWindow, camera)
def frameStarted(self, frameEvent):
return sf.FrameListener.frameStarted(self, frameEvent)
def _moveCamera(self):
# move our camera node instead of the camera
# 1.2 typemap problem
#self.cameraNode.yaw(self.rotationX.valueRadians())
#self.cameraNode.pitch(self.rotationY.valueRadians())
self.cameraNode.yaw(self.rotationX)
self.cameraNode.pitch(self.rotationY)
#self.cameraNode.translate(self.translateVector)
if __name__ == '__main__':
try:
application = ColourCubeApplication()
application.go()
except ogre.OgreException, e:
print e
Edited code to include camera lookat.
taribo
01-08-2006 10:29:53
Try using a default plane (or manually created one) as a childnode of your camera node and manipulate the camera node instead of the camera as suggested here:
http://www.ogre3d.org/phpBB2/viewtopic. ... background
Also read up on material settings:
http://www.ogre3d.org/docs/manual/manual_14.html#SEC23
e.g., progre1.2 (but shouldn't be many changes):
# This code is in the Public Domain
import pyogre.ogre as ogre
import SampleFramework as sf
import math
class ColourCubeApplication(sf.Application):
def ManualPlane(self, name = "planeMesh", size=(620,480,0),w=1,h=1 ):
meshMgr = ogre.MeshManager.getSingleton()
mesh = meshMgr.createManual(name, ogre.ResourceManager.DEFAULT_RESOURCE_GROUP_NAME)
subMesh = mesh.createSubMesh()
x,y,z = size
x /= 2.0
y /= 2.0
z /= 2.0
vert_pos = [
(-x,-y,0),
(x,-y,0),
(x,y,0),
(-x,y,0)
]
vert_norm = [
(0,0,1),
(0,0,1),
(0,0,1),
(0,0,1)
]
tex_coords = [
(0,h),
(w,h),
(w,0),
(0,0)
]
print tex_coords
faces = [
0,1,2,
0,2,3
]
POSITION_ELEMENT = 0
NORMAL_ELEMENT = 1
TEXTURE_ELEMENT = 2
mesh.get().sharedVertexData = ogre.VertexData()
mesh.sharedVertexData.vertexCount = len(vert_pos)
#work-around to prevent destruction
self.sharedVertexData = mesh.sharedVertexData
decl = mesh.sharedVertexData.vertexDeclaration
offset = 0
decl.addElement(0, offset, ogre.VET_FLOAT3, ogre.VES_POSITION)
offset += ogre.VertexElement.getTypeSize(ogre.VET_FLOAT3)
decl.addElement(0, offset, ogre.VET_FLOAT3, ogre.VES_NORMAL)
offset += ogre.VertexElement.getTypeSize(ogre.VET_FLOAT3)
decl.addElement(0, offset, ogre.VET_FLOAT2, ogre.VES_TEXTURE_COORDINATES)
offset += ogre.VertexElement.getTypeSize(ogre.VET_FLOAT2)
hBuffMgr = ogre.HardwareBufferManager.getSingleton()
vbuf = hBuffMgr.createVertexBuffer(offset, mesh.sharedVertexData.vertexCount, ogre.HardwareBuffer.HBU_STATIC_WRITE_ONLY)
pVertex = vbuf.lock(decl, ogre.HardwareBuffer.HBL_DISCARD)
#loop through the vert_pos array
for i in range(0, len(vert_pos)):
vx, vy, vz = vert_pos[i]
nx, ny, nz = vert_norm[i]
tu, tv = tex_coords [i]
pVertex.setFloat(i, POSITION_ELEMENT, vx, vy, vz)
pVertex.setFloat(i, NORMAL_ELEMENT, nx, ny, nz)
pVertex.setFloat(i, TEXTURE_ELEMENT, tu, tv)
bind = mesh.sharedVertexData.vertexBufferBinding
bind.setBinding(0,vbuf)
vbuf.unlock()
# faces
subMesh.indexData.indexCount = len(faces)
subMesh.indexData.indexBuffer = hBuffMgr.createIndexBuffer(ogre.HardwareIndexBuffer.IT_16BIT, len(faces), ogre.HardwareBuffer.HBU_STATIC_WRITE_ONLY)
ibuf = subMesh.indexData.indexBuffer
subMesh.indexData.indexBuffer.writeIndexes(0, faces)
subMesh.useSharedVertices = True
subMesh.indexData.indexBuffer = ibuf
subMesh.indexData.indexCount = len(faces)
subMesh.indexData.indexStart = 0
mesh._setBounds(ogre.AxisAlignedBox(-100000.0,-100000.0,-100000.0,100000.0,100000.0,100000.0))
mesh._setBoundingSphereRadius(1000000)
self.indexData = subMesh.indexData
mesh.load()
def _planeBackGround(self):
# create background plane
plane = ogre.Plane()
plane.normal = ogre.Vector3.UNIT_Z
plane.d = 200
mm = ogre.MeshManager.getSingleton()
mm.createPlane('FloorPlane', 'General', plane, 800.0, 600.0,
5, 5, True, 1, 5.0, 5.0, (0, 1, 0))
backEntity = self.sceneManager.createEntity('floor', 'FloorPlane')
backEntity.setMaterialName('Examples/OgreSkyPlane')
return backEntity
def _manualPlaneBackGround(self):
self.ManualPlane(name = "planeMesh", size=(800,640,0),w=1,h=1)
self.planeEntity = self.sceneManager.createEntity("myPlaneEntity", "planeMesh")
material = ogre.MaterialPointer(ogre.MaterialManager.getSingleton().create("Background", "General"))
material.getTechnique(0).getPass(0).createTextureUnitState("rockwall.tga")
# these should be false but onlt tusks are shown ??
material.getTechnique(0).getPass(0).depthCheckEnabled = True
material.getTechnique(0).getPass(0).depthWriteEnabled = True
material.getTechnique(0).getPass(0).lightingEnabled = True
#material.getTechnique(0).getPass(0).depthCheckEnabled = False
#material.getTechnique(0).getPass(0).depthWriteEnabled = False
#material.getTechnique(0).getPass(0).lightingEnabled = False
self.planeEntity.setMaterialName("Background")
return self.planeEntity
def _createScene(self):
sceneManager = self.sceneManager
#sceneManager.ambientLight = 0.7, 0.7, 0.7
light = sceneManager.createLight('MainLight')
light.position = 20, 80, 50
# create head entity
headNode = sceneManager.rootSceneNode.createChildSceneNode()
entity = sceneManager.createEntity('head', 'ogrehead.mesh')
headNode.attachObject(entity)
backEntity = self._planeBackGround()
#backEntity = self._manualPlaneBackGround()
# create camera node
cameraNode = sceneManager.rootSceneNode.createChildSceneNode()
cameraNode.attachObject(self.camera)
# create child node for cameras node and attach background
self.nd2=cameraNode.createChildSceneNode()
self.nd2.attachObject(backEntity)
# remove for manual plane / and/or set for cameras fovy
#self.nd2.translate(0,0,-400)
self.nd2.renderQueueGroup = ogre.RENDER_QUEUE_BACKGROUND
# moving this will increase rotation arc
headNode.translate(0, 0, 15)
self.cameraNode = cameraNode
def _createFrameListener(self):
self.frameListener = GeneralListener(self.renderWindow, self.camera, self.cameraNode)
self.root.addFrameListener(self.frameListener)
class GeneralListener(sf.FrameListener):
def __init__(self, renderWindow, camera, cameraNode):
self.cameraNode = cameraNode
sf.FrameListener.__init__(self, renderWindow, camera)
def frameStarted(self, frameEvent):
return sf.FrameListener.frameStarted(self, frameEvent)
def _moveCamera(self):
# move our camera node instead of the camera
self.cameraNode.yaw(self.rotationX)
self.cameraNode.pitch(self.rotationY)
#self.cameraNode.translate(self.translateVector)
if __name__ == '__main__':
try:
application = ColourCubeApplication()
application.go()
except ogre.OgreException, e:
print e
the manualPlaneBackGround seems to be what i need but i'd tried put the background on the Y axis but i don't see the plane, i thougt this:
vert_pos = [
(-x,0,-z),
(x,0,-z),
(x,0,z),
(-x,0,z)
]
vert_norm = [
(1,0,0),
(1,0,0),
(1,0,0),
(1,0,0)
]
camera.position = (0, 1013, 0)
camera.lookAt(1.023376522e-016, 0.8356779456, -0.5492197841)
where's wrong? sorry for newbie questions
dermont
01-08-2006 20:50:30
The vert_pos z value is 0. and the vert_norm should be (0,1,0).
I've updated it the original code for your camera scenario passing the axis plane. For a more generic solution you'll retrieve that based on the direction/distance of your camera and scale/move the mesh appropriately..
The vertex normals aren't updated and probably not needed so you can try:
POSITION_ELEMENT = 0
#NORMAL_ELEMENT = 1
TEXTURE_ELEMENT = 1
#decl.addElement(0, offset, ogre.VET_FLOAT3, ogre.VES_NORMAL)
#offset += ogre.VertexElement.getTypeSize(ogre.VET_FLOAT3)
#pVertex.setFloat(i, NORMAL_ELEMENT, nx, ny, nz)
The ordinary planeBackGround appears easier to use. You should check/ask on the main forum for alternative approaches.
taribo
03-08-2006 12:24:53
The vert_pos z value is 0. and the vert_norm should be (0,1,0).
I've updated it the original code for your camera scenario passing the axis plane. For a more generic solution you'll retrieve that based on the direction/distance of your camera and scale/move the mesh appropriately..
The vertex normals aren't updated and probably not needed so you can try:
POSITION_ELEMENT = 0
#NORMAL_ELEMENT = 1
TEXTURE_ELEMENT = 1
#decl.addElement(0, offset, ogre.VET_FLOAT3, ogre.VES_NORMAL)
#offset += ogre.VertexElement.getTypeSize(ogre.VET_FLOAT3)
#pVertex.setFloat(i, NORMAL_ELEMENT, nx, ny, nz)
The ordinary planeBackGround appears easier to use. You should check/ask on the main forum for alternative approaches.
thank you
and for this 3 cameras? how to do for view the panel center and not rotated?
camera 1:
position -0.08516539685, 12.77812866, -0.8938062806
lookat 1.023376522e-016, 0.8356779456, -0.5492197841
camera2:
position -0.08516539685 14.84778873 -2.738573204e-015
lookat 1.224606354e-016 1.0 -2.220446049e-016
camera3:
position 8.681944053e-014 12.66216741 -0.7996193057
lookat -0.4717418824 0.7449289851 -0.4717418824