Sentence. 2D image in 3D


Add the function of opening images 2D extensions to PNG, BMP … as 3D objects, but with a very thin thickness. HTTPS://Castle-Engine.IO/manual_load_3d.php here I can only download 3D model, and I would like to 2D model with the extension. PNG

As well as for my project is very necessary.



ildus03, hi!

You cannot add an image directly to 3D world, as the image must be “rendered onto something” to be visible. 2D image is a “texture” and 3D object is a “shape/mesh” - those are two inherently different objects. You can mix 3D and 2D objects by creating a 3D Quad (this is exactly a “very thin thickness” shape).

Check this example: The only difference will be that you would need to load the image, not to render it from an existing 3D object.

1 Like


As a demo, I implemented it :slight_smile: See the example code on in the section Example in Pascal (build a textured rectangle) .

This loads an image as a rectangle into TCastleScene.

1 Like


Many thanks! You really helped!



I used this example already quite a long time ago, but found the error only now: when creating a 2d image 3d, alpha channel of the primary image remains and when two objects collide, they crash into their alpha channels. (Sorry for my English Nai)



The only solution to this is to artificially make the bounding boxes (TBox3D, TFloatRectangle) smaller, by an amount that depends on your assets. Or construct your objects from more complicated geometry, that fits the underlying objects tighter, without leaving too large invisible margins around.

Short explanation:
All collision routines (2D or 3D, in CGE or Kraft) operate looking at geometry. A geometry using a texture with alpha channel is no different – we do not analyze the alpha channel when detecting collisions (this would be slow, and in general case could be complicated).