Problems with cubes, cubemaps and rotations

Hi;

I have some problems using the panda3d tool.
I’d like to rotate a cube, which has a cubemap, around the x axis and I have two issues:

• When I rotate the cube, for about 45°, using setP, it changes its texture
• The cube rotates on its edge and not around its centre as I need
Any suggestions ?
• If rotating the cube changes its texture, it means that the texture coordinates must not be part of the cube model, but are perhaps being generated externally (for instance, via model.setTexGen()). If this is the case, then you need to choose an appropriate TexGen mode that does not move the texture when you move the cube. The manual has examples of this. If you need further assistance, we will need to know precisely what calls you are making now to generate the texture coordinates.

• All models rotate about their (0, 0, 0) point. If the cube is rotating about its corner, it means that corner is at (0, 0, 0). You want a cube whose center is at (0, 0, 0) instead. You can either change the source model, or you can create an intervening node with the appropriate offset, or you can apply the appropriate offset to the model and then flatten it down to the vertices:

``````cube.setPos(-0.5, -0.5, -0.5)
cube.flattenLight()``````

David

drwr, thanks a lot!

• Sorry, I’m new of panda3d. I’m using the simple model “box” of panda3d and the cubemap generated by six png pictures.
I tried looking for an appropriate TexGen mode reading in the manual or surfing the internet but I didn’t find anything that seemed useful. Maybe the problem is that I’m using a cubemap.
Or maybe the solution is simply change textures coordinates, but I don’t know how to do it. What’s are your suggestions?

• To solve the second issue, I think I’ll apply a different offset to the cube to make it turning around its point (0.5,0.5,0.5). Is it possible? How can I do this?

The word “cubemap” means different things in different contexts. In Panda3D, it usually means a single Texture object loaded with an explicit loader.loadCubemap() call, from a series of images named something like image_1.png, image_2.png, and so on. It might also mean such an object loaded by a particular construct within the egg file, but the “box.egg” model that ships with Panda3D contains no such construct.

So, let’s get on the same page: what exactly do you mean when you say you are applying a cubemap to panda’s box.egg file? Can you show me the code you are using?

I say it again: all nodes always rotate about their (0, 0, 0) point, never around any other point. But you can move the model so that the (0, 0, 0) point is anywhere in the model you like, for instance where the (0.5,0.5,0.5) point used to be. The flattenLight() call I illustrated above demonstrates exactly this.

David

-For sure, the code is:

``````cbox=loader.loadModel('box')
cbox.setScale(32,32,32)
cbox.setPos(0,0,0)
cbox.reparentTo(render)                        cbox.setTexGen(TextureStage.getDefault(),TexGenAttrib.MWorldNormal) #In my opinion here I have to change something
cbox.setTexture(texture,1)``````
• I can’t change the cube position. What can I do?

Thanks David

Replace this:

``cbox.setTexGen(TextureStage.getDefault(),TexGenAttrib.MWorldNormal)``

With this:

``````cbox.setTexGen(TextureStage.getDefault(), TexGenAttrib.MWorldNormal)
cbox.setTexProjector(TextureStage.getDefault(), render, cbox);``````

This is described in the manual page entitled “Automatic Texture Coordinates”.

I don’t know what you mean by “can’t”–couldn’t you do this?

``````cbox.setPos(-0.5, -0.5, -0.5)
cbox.flattenLight()
cbox.setPos(0.5, 0.5, 0.5)``````

The first call moves the box, the middle call resets the origin there, and the third call puts the box back where it was. Now you can rotate the box around its center without moving its position.

David

It’s a good idea to change the center of the cube to its (0,0,0) point, but is possible to find the coordinates in the space of cubes’ (0,0,0)point?

Thank you very much; with your suggestions I have solved the second issue in this way:
1- I set cube’s pos(0,0,0);
2- then I moved it to (-.5,-.5,-.5);
3- I called flattenLight();
4- I put again the cube in (+.5,+.5,+.5);
5- finally I set moved it in the position I wanted.

But the first issue is yet unsolved, setTexProjector doesn’t work rightly,
I think I have to set textures coordinates equal to cube coordinates.
How can I do it? Do I have to use a best TexGen?

Please, drwr, help me for the last time.
To solve the first issue I simple need to texture a cube choosing the colour of each face. Maybe there is a simple solution to do this, pheraps using a normal texture and then painting it with different colour as you suggested in other topics.
I’m new in panda3d, so I ask you: which is the simpliest way to do what I wish?

Try MWorldPosition, then, instead of MWorldNormal. The following code works fine for me:

``````cbox=loader.loadModel('box.egg')
cbox.setPos(-0.5, -0.5, -0.5)
cbox.flattenLight()
cbox.setPos(0.5, 0.5, 0.5)
cbox.setScale(32,32,32)

cbox.reparentTo(render)
cbox.setTexGen(TextureStage.getDefault(),TexGenAttrib.MWorldPosition)
cbox.setTexProjector(TextureStage.getDefault(), render, cbox)

cbox.setTexture(texture,1)``````

But, you are certainly using the wrong approach here, if all you really want is a cube with a different color on each face. Despite its name, a cubemap isn’t really intended for being mapped onto a cube. You’re going about it the hard way.

The simple solution to this is to model the cube the way you want it, with the textures you want on each face, in the modeling package that creates the cube in the first place. Note that Panda3D is not a modeling tool. You should use a tool like Blender to create the cube that you desire, then export it to Panda for rendering. Blender makes it easy to assign a different texture to each face of the cube.

If you cannot use a modeling package for some reason, you can hand-edit the egg file. Add a new group at the top of the egg file for each different texture you want, naming each one differently, then change the line in each polygon to reference the appropriate texture for that face.

David

Good idea, drwr.
Now I solved the first issue!: I’m editing textures on the .egg file, using a program in python.
In this way the textures are as I want and I modified the cube rotation center, too.
Thank you David!

I’m using cube maps for texturing my skyboxes, mainly for retexturing on the fly using one call for 6 images. Is there anything bad with that approach? From practice it works just fine, but I’d consider changing it if it’s known to cause some problems or bottlenecks.

Neme

Nothing wrong with that approach (at least, not much wrong with it). It’s just that cubemaps are really designed to solve a much more general problem, for applying 360-degree textures onto arbitrary surfaces. If you just applying it onto a cube, which already has a separate face for each texture, you’re not really taking advantage of the full functionality of a cubemap.

Some very, very old drivers don’t support cubemaps at all, or support them at a high performance cost. Panda’s tinydisplay doesn’t support them. Other than that, they’re pretty universal, and there’s no reason to avoid it, even for simple tasks. There may even be a performance gain for using them, since you can render the skybox in one Geom call, rather than six.

But in this case, I was recommending against its use due to its complexity, based on the OP’s experience level.

David

Ok, thanks.