Sentence. 2D image in 3D

#1

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
image

As well as for my project is very necessary.

0 Likes

#2

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: https://github.com/castle-engine/castle-engine/blob/master/examples/3d_rendering_processing/render_3d_to_texture_and_use_as_quad.lpr#L116. The only difference will be that you would need to load the image, not to render it from an existing 3D object.

1 Like

#3

As a demo, I implemented it :slight_smile: See the example code on https://castle-engine.io/x3d_implementation_geometry3d.php in the section Example in Pascal (build a textured rectangle) .

This loads an image as a rectangle into TCastleScene.

1 Like

#4

Many thanks! You really helped!

0 Likes

#5

I used this example https://castle-engine.io/x3d_implementation_geometry3d.php 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)

0 Likes

#6

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).

0 Likes