Any idea to reader a Rubiks cub with six photo instead of six color?

From current examples i can find from internet, they always give a rubiks cube with six color. This is done by just put every single cube with six color. But i am trying to find a way to set six photo to a rubiks cube, so that every sinlge cube will only take different part of those photo.
Any good suggestion to achieve that?

Thank you very much!

Well, how are your cubes modelled?

If you’re making them yourself, then you can potentially add the images as part of the modelling process–give the cubes an appopriate UV-map and assign a texture to them.

If you’re getting the cubes from someone else, then the approaches available depend on what properties the model has: If it has UV maps, then you might be able to set a texture on the object (perhaps with some adjustment). If it doesn’t, then you might be left with looking into Panda-generated UV-mapping, or a shader.

Hi Thaumatuge:
I create a single cube entity. with below code:
def create_god_cube(self):
combine_parent = Entity(enabled=False)
for i in range(3):
dir = Vec3(0,0,0)
dir[i] = 1

		e = Entity(parent=combine_parent, model='plane', origin_y=-0.5, texture='sky_sunset', color=self.cube_colors[i*2])
		e.look_at(dir, 'up')

		e_flipped = Entity(parent=combine_parent, model='plane', origin_y=-0.5, texture='white_cube', color=self.cube_colors[(i*2)+1])
		e_flipped.look_at(-dir, 'up')

	self.god_cube = combine_parent

then instancing to 26 pathnodes. I’ve successfully add a cubemap to any of those instances or that cube entity, six images in sixe faces.
But the rubiks cube is composited with 26 cube instaces, each of this rubik cube face have 9 small cube faces. Shall I create 26 static cubemaps and them assign each of them to different small cubes?


Hmm… I’m not familiar with the “Entity” class, or what it does or provides–is it a class of your own making?

You could, I daresay. Not knowing your intended program or requirements, it’s hard to say whether this is a good approach, but it should I think work. (As long as you have the texture memory for all of those images, of course.)

Under most circumstances I might be inclined rather to have just six images, and to use UV-mapping to apply the relevant parts of them to the relevant faces.


Sorry, I missed another very import information. I am actually using ursina. Entity is a concept from ursina. ursina engine is build ontop of panda3d.
My purpose is just to create a rubik’s cube game. Normaly, this game have six colors, problem is solved when every single faces of this rubik’s cube only have same colors. Now i want to use a photo repalce color, which means in every face, the game is solved (complete) only when six photoes are all correctly displayed.

Ah, yeah–I’ve heard of Ursina, but don’t use it myself.

(Indeed, it might be worth asking of Ursina’s developers, as they’re likely to be more familiar with how their components work.)

Hmm… Looking again at your code, I see that you provide a reference to a model named “plane”–is that a 3D model that you’ve created? Or something that Ursina provides?

Yes, “plane” is a ursina model. ursina was starting up from 2019. Very poor document. I use it is just because of some convience. All panda3d model, texture… can be working well from my current experience.
For my current problem, actually, i am thinking of creating 26 (maybe only 9 ) different dynamic CubeMap Texture from given six photoes by TexturePool.setupCubeMap (then use setRamImage). It’s a bit complex.

Yeah, unfortunately, I don’t know how many people here are familiar with Ursina. I don’t know how it sets up its “plane” model, I’m afraid, and thus what features it might provide. :/

What you describe should work, I do think.

I do caution you that it’s likely not an efficient approach, and for larger projects is perhaps not a good idea–but if you’re just making a single Rubik’s Cube, and if your textures aren’t massive, then it seems like it might be okay.

Yep, this kind of possiblity of performance issue cause me here to find a better solution. Let’s forget about the ursina. How panda3d can achieve same target, for example, 100 Rubik Cubes?


Well, with 100 Rubik’s Cubes, one would presumably have 100 x 26 = 2600 sub-cubes. That’s an awful lot of nodes in the scene-graph, which could cause problems!

So, I might suggest that each Rubik’s Cube be a single object–perhaps made in a 3D modelling package and controlled by a skeletal armature. That would allow the Rubik’s Cube to be rearranged without introducing lots and lots of nodes. (Another approach might be to handle it procedurally, using something like Panda’s “MeshDrawer” class.)

Either way, this would also allow us to specify UV maps for the Rubik’s Cubes, allowing us to have a minimal number of textures, with each sub-cube only using a portion of the texture appropriate to it.

That, I think, is how I might recommend going about it.

I am a new comer on panda3d, the approaches you’ve mentioned here, I didnt know them yet. But I’ve found them by keywords searching from the mannual page. I will study them.

Thank you very much, Thaumaturge!

It’s not a problem!

That’s fair! Good luck with your studies, then! :slight_smile:

(And of course, if you have further questions, do post them here on the forums!)

Let me add: If you want to make your own models, I might suggest getting a free 3D modelling tool (such as Blender), and looking up some tutorials for it.


1 Like

From current my study progress, i can NOT find a correct way to load a pieces (read by cv2 or PIL’s Image) of image to a Texture. The read or load members functions are all read contents from a filename.

That’s means, to implement my previous ideas, i have to save each of six photoes into another 9 files.
Can you help me?

It’s less a matter of loading a piece of a texture than of showing a piece of a texture.

Have you yet studied “UV mapping”? In short, a model can have coordinates associate with each vertex that correspond to positions in the texture. This allows the modeller to define which regions of the texture appear on which parts of the model, thus allowing them to have different parts of the texture appear on different parts of the model–even though the texture is entirely loaded.

This “UV map” can generally be applied during the 3D modelling process. (Or during procedural construction of geometry, if you build your model that way.)

If you do want to go this way–and, as noted above, it’s not the only approach–you would presumably have to construct and load your 9 files as you did your original 1 file.

Where in the process are you currently stuck?

I skipped UV Mapping section, because I was understanding that only applys to 2D model. Now, seems i was wrong.

For this way, i’ve alreay split each of six photoes into 9 pieces, I don’t want to save them to disk and load them to CubeMap by reading files. I am now trying to use Texture’s setupCubeMap member function, then use setRamImage. But I the issue here, i don’t know what shall be the image format of setRamImage and how to translate PIL’s Image to that data format.

Ah, fair enough! I’m glad that we caught that error, then, as UV-mapping is a very useful tool, I do feel!

Ah, I think that I see. Unfortunately, that’s not a process that I’m terribly familiar with, so I’m going to bow out for now, in the hopes that another forum-member will know better than I about these things!

No problem. I will study UV mapping carefully from now on.
BTW, I just figure out aworkaround for that.

  1. Save the photo to a well designed size.
  2. load those six photoes to six PNMImage.
  3. for each of PNMImage, create another PNMImage, then copy desired size to those small PNMImage by copySubImage memember function.
1 Like

It’s a slow approach, but it should work, indeed. Well done on finding it! :slight_smile:

You reply me so quickly!