Does panda have a feature to generate a simple wireframe cube? Im totally new to 3d in general, but have a bit of python experience. The manual is very good, and covers texturing the cube but not making one.
Any help would be much appreciated.
It is not recommended to generate models procedurally, except in very special cases (e.g. terrain). You are better off modeling a simple cube in a modeling program, and exporting it to Panda3D.
Though, if you still want to create a cube procedurally, there is a sample program which describes how to do that, the Procedural Cube sample.
To set the render mode to wireframe on a particular NodePath object, use the setRenderModeWireframe() function, or, if you want to toggle wireframe mode for your entire scene, you can use base.wireframeOn().
Hmm, ok it would probably be better if I just explained what I want to do. I want to make a 3D cube that can rotate and each side can change color. If I make a wireframe cube in maya, can I import it and then color the sides?
Ah. You can do either, whatever you think is best. If you want each face to be able to change color, the procedural cube thing might be easier, since you have full control about the vertex colors. The other way is also possible, though.
Note that there is no difference between a filled cube and a wireframe cube – you model it the same way, just a cube. The only difference is that you give it a different render mode (using setRenderModeWireframe() or setRenderModeFilled()).
EDIT: Now I think of it, there is also a third way, using CardMakers which is even easier, actually. Just place 6 cardmakers in a way so they make a cube. You can give each card a different color very easily. Downside of this approach is that they can’t share the same vertices. Whatever you think is easier though, all three approaches will work fine.
Ok, il do the procedural cube, especially as im making a kinda rubik’s cube thing, it will be a lot easier to control the color of the individual squares on any one side.
Thanks for that link
Im really struggling to understand all this vertex stuff, I have started with the procedural cube base, and understand roughly whats going on, I now have it stripped down to just the wireframe cube, and can see its made with 12 triangles (2 on each side). My problem is I have no idea how to add more vertex points to make it 9 smaller squares per side. Can anyone help me at all im totally stuck
Look at the makeSquare function. It creates one face for the cube. Why not substitute the calls for a makeFace function, which just calls makeSquare nine times with correct coordinates.
I recommend reading the “Advanced operations with Panda’s internal structures” section of the manual.
I had been reading that, but it seemed so complex for something that should be (imho) pretty simple. Ive just had a look in the manual and the reference for the makeSquare command, and found none, where do you learn about functions like this? It sounds like what I was trying to write myself, but I cant find the parameters it accepts.
Must be somewhere in the reference surely…
Really appreciate the help (so does my sanity )
Ah man this stuff is making me go crazy, I realize what you mean now, procedural cube’s make square function. The problem is its creating cubes out of triangles, and I need them out of cubes. Il try writing a makeface() function and let you know how it goes.
Ok, ive got a single square to come out, so I can now write a makeface function, but it just occured to me, how will I fill this ‘square’ with color, after all its just 4 lines and 4 verticies. There doesnt seem to be a way to refer to the space in between to change its color.
You have to set the vertex color, how to do that is described in that manual section.
Wait, I just got a better idea that doesn’t require you to do anything with procedural stuff.
You’re creating a rubik’s cube simulation, right? So, wouldn’t it be sensible just to have 26 (3x3x3 - 1) cubes with each their own color? That way, you can just rotate a row or column of those cubes like a real rubik’s cube. That’s much easier, and, you can keep each cube it’s own color, instead of having to deal with procedural stuff.
You can just work with setColor() then.
but wouldn’t the cubes overlap at the edges? And the problem remains, how do I make a square without using the verticies?
Im not quite doing a rubiks cube sim, but I want to end up with something that looks like a 5x5 rubiks cube, which I can rotate (as a whole) and change the color of individual tiles.
Well, at this procedural cube sample, (I just noticed) they don’t share the same vertices either, so they overlap same as they would using cubes.
In your case, I’d suggest creating 5x5x5 cubes where you can use setColor on each of them.
You can model your own cube or use the one that panda has in it’s models directory. Try this little program:
from direct.directbase import DirectStart
from random import random
cube = loader.loadModel("misc/rgbCube")
for x in range(5):
for y in range(5):
for z in range(5):
instance = cube.copyTo(render)
instance.setPos(x, y, z)
instance.setColor(random(), random(), random(), 1)
Ah, that makes a mockery of all that I was trying. That code is absolutely perfect apart from the fact that the cubes at the edges are the same color, I need them to be different on different faces. But thank you so much for this massive step!
BTW i had a look at your vikings game and it looks amazing! Might get the milestone and have a go later.
edit - Also, is there any way to show the verticies between the cubes, so they appear as a 5x5 grid not one large cube? Would that require changing the model?