Realistic texture render and create 3D objects in code

I have a quick question before I commit to a major learning curve on this library. I wish to do a more realistic render (maybe at least 60-80% of Blender’s quality) to render objects.

Can I know is it possible to create the 3D objects totally from code? These are mainly simple cuboids (some with one open face and hollow inside) or cylinders with one end open (and hollow inside). I want to create these objects totally from code,
and then apply a texture to it from code too, and also lighting from code.

In other words, I want to skip the CGE studio, and just be able to do this from Delphi pascal code entirely. Is it possible?

If someone happens to have a small code sample to share, would deeply appreciate it. I’ll be using Delphi 12 with FMX.

PS: the \examples\viewport_and_scenes\build_3d_object_by_code\ is missing the *_standalone.dpr files

You can build everything in code. You can use the CGE geometric primitives or go below them to to build x3d nodes. Then you use TTriangleSetNode or TIndexedSetNode or TTriangleStripNode or TIndexedTriangleStripNode or other primitives. You add a TPhysicalMaterialNode to the set properties like the texture and shininess. And then can load your your model into a TCastleScene. Blender has more material properties, but you should still be able to get results that meets your goal.

I find it helpful to made a ‘builder’ class that will build the rootnode for the x3dscene and encapsulate complexities.

Look for my icosphere code on the CGE site. It is an example of building this way.

Here is my public repo. You would want to look at the icosphere.pas and the x3dtools.pas.

ok thanks so much. will digest it. I’m new to 3D, so many terms are really alien. hoping to find a really simple example on how to build a cube or rectangular block (with a hollow) to start with.

Indeed, you can build anything using code.

See :

I will still absolutely recommend to go through the manual and use CGE editor, play with it, design some 3D stuff there :slight_smile: If you really need to use X3D nodes, then also see about writing your own X3D files, you can load them into TCastleScene (see docs above). In most practical cases, you want to do some stuff from code, but still some stuff in the editor, so combine their strengths :slight_smile: And even for cases when you really need to generate something from code, it is often nice to experiment first – before writing Pascal code, it’s often nice to first play with components in CGE editor or X3D nodes in X3D files, and see can you “do by hand” the thing that you will later want to automate.

The editor is the best way to find what all the settings are and do. Even if you ultimately build it all in code.

1 Like

Geometry3D component | Castle Game Engine Section 3 is the example code I found simplest starting point to figuring out how build x3d scenes. A box with faces and a texture.

https://castle-engine.io/code-samples/orthographic_cube_sheared_test.lpr

Oh, I forgot to answer this – that’s OK, i.e. not every example has DPR/DPROJ with _standalone suffix. That example has just

  • DPR in build_3d_object_by_code.dpr and
  • DPROJ in build_3d_object_by_code.dproj.

Open the DPROJ to build and run it.

Hi Michalis & all,
thanks so much for providing such a clear guide to getting started! I’ll try it out.

hi Edj, thanks. I got to try this today. yes, you are right. this one is relatively straight forward compared to the rest. thank you once again!

1 Like

From that face demo, I got to here with my parametric buildings in about 1.5 years (after implementing drawable roads, flowing water and growing trees). This building made of 4 ‘blocks’ is all built in code into one scene using the x3d nodes. I plan to then have each face be able to be built with varying level of paramtric detail (this would be the lowest).

1 Like

Please share a render here, if it’s allowed. will be curious to see what you have produce.

Here are a bunch in no particular order from the past 1.5 years.










3 Likes