Reputation: 1627
I seem to have a problem in rendering a cubemap image onto a cube in panda3d.It appears that al my images seem to diverge to the bottom right vertex to create an colourful but unfortunately unwanted design:
The code by which I created the cubes and tried to render the cubemap:
from direct.showbase.ShowBase import*
from panda3d.core import*
import random
class myapp(ShowBase):
def __init__(self):
ShowBase.__init__(self)
self.cube=self.loader.loadModel("cube.egg")
self.tex = loader.loadCubeMap('face_#.jpg')
self.cube.setTexture(self.tex)
for i in range(50):
self.placeholder = self.render.attachNewNode("Placeholder")
self.placeholder.setPos(random.randint(1,100), random.randint(1,100),random.randint(1,100))
self.cube.instanceTo(self.placeholder)
self.cube.reparentTo(self.render)
app=myapp()
app.run()
Upvotes: 1
Views: 1129
Reputation: 1582
By default, a cube map will be applied according to the set of U, V, W texture coordinates assigned to the model. Regular U, V coordinates are not suitable for showing cube maps because they lack the W coordinate, and will therefore appear smeared across some of the faces. It is uncommon (but possible) for a model to be assigned cube map coordinates in a modelling program - instead, automatic texture coordinate generation is usually used, where the normal vector or some transformed version thereof is used to generate the appropriate coordinates for cube map sampling.
In Panda3D, this can be done with the setTexGen
function. There are several ways that Panda3D can generate cube map coordinates in, depending on the type of cube map (eg. is it a reflection cube map, or a static one, etc.) One example:
self.cube.setTexGen(TextureStage.getDefault(), TexGenAttrib.MEyeCubeMap)
More information can be found on the respective manual pages: https://www.panda3d.org/manual/index.php/Automatic_Texture_Coordinates https://www.panda3d.org/manual/index.php/Environment_Mapping_with_Cube_Maps
Upvotes: 2