# \[solved\] General question before learn more

**URL:** https://forum.castle-engine.io/t/solved-general-question-before-learn-more/2054
**Category:** 3D
**Created:** [November 29, 2025, 3:34pm UTC](https://forum.castle-engine.io/t/solved-general-question-before-learn-more/2054 "2025-11-29T15:34:08Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![aboisrame](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/aboisrame/32/2709_2.png) [@aboisrame](https://forum.castle-engine.io/u/aboisrame)
#### Post date: [November 29, 2025, 3:34pm UTC](https://forum.castle-engine.io/t/solved-general-question-before-learn-more/2054/1 "2025-11-29T15:34:08Z")

</div>

Hello,

I’m discovering CGE and I would like to use it to program a viewer for polyhedron. But I don’t want to load a external file. It is possible to build by code a 3D object if I have all the vertices coordinnates and if I also know which vextices connect to build each face ? I would like to control by code the color of each face and be able to draw or not a line for each visible edge ?

I don’t ask detail code just know if it seems possible. I can more or less do it for a test with Lazarus and OpenGL but OpenGL is not always easy to use so I imagine that CGE classes are great to do that much more easily.

Thank you for your answer

Have a good day

Alexandre

---

<div class="post-metadata">

### Author: ![michalis](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/michalis/32/3_2.png) [@michalis](https://forum.castle-engine.io/u/michalis)
#### Post date: [November 29, 2025, 5:39pm UTC](https://forum.castle-engine.io/t/solved-general-question-before-learn-more/2054/2 "2025-11-29T17:39:58Z")

</div>

Hello!

Yes, everything that can be displayed in Castle Game Engine can be also built by code.

Our manual page [Writing code to modify scenes and transformations](https://castle-engine.io/viewport_and_scenes_from_code) documents it in details, in particular the section there _“11. Building a mesh using code”_ exactly shows a code that builds a mesh using Pascal code. You define yourself the vertexes, and how they are connected to display polygons.

In the end, you will have [TCastleScene](https://castle-engine.io/apidoc/html/CastleScene.TCastleScene.html) instance with the nodes that define the mesh, and you can use it just like any other `TCastleScene` instance where contents would be loaded from 3D file (like X3D or glTF).

So I advise to follow the [manual](https://castle-engine.io/manual_intro.php) from start, at least up to this chapter 🙂

The “nodes” that are used to define it, like `TIndexedFaceSetNode`, are [X3D nodes](https://castle-engine.io/x3d). So for many questions like “how to display X” an answer will be like “use X3D node like Y” 🙂

- Each X3D node is a Pascal class and is documented (briefly) in our docs and in depth in the [X3D specification](https://www.web3d.org/documents/specifications/19775-1/V4.0/Part01/Architecture.html). For example, TIndexedFaceSetNode is here: [in Pascal](https://castle-engine.io/apidoc/html/X3DNodes.TIndexedFaceSetNode.html), [in X3D spec](https://www.web3d.org/documents/specifications/19775-1/V4.0/Part01/components/geometry3D.html#IndexedFaceSet). Reading this shows you the full capabilities – all of these X3D things can be created/modified by Pascal code.

- To display edges, you would create [TIndexedLineSetNode](https://www.web3d.org/documents/specifications/19775-1/V4.0/Part01/components/rendering.html#IndexedLineSet).

- To determine colors per face you would set `TIndexedFaceSetNode.Color` to an instance of `TColorNode` and set `TIndexedFaceSetNode.ColorPerVertex` to `false`. Similar approach can be used to modify colors for lines.

I hope this is good to get you started 🙂

---

<div class="post-metadata">

### Author: ![aboisrame](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/aboisrame/32/2709_2.png) [@aboisrame](https://forum.castle-engine.io/u/aboisrame)
#### Post date: [November 30, 2025, 7:44am UTC](https://forum.castle-engine.io/t/solved-general-question-before-learn-more/2054/3 "2025-11-30T07:44:07Z")

</div>

Thank you very for your detailed answer, it’s very kind.

Have a good day

Alexandre

---

<div class="post-metadata">

### Author: ![aboisrame](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/aboisrame/32/2709_2.png) [@aboisrame](https://forum.castle-engine.io/u/aboisrame)
#### Post date: [December 1, 2025, 9:50am UTC](https://forum.castle-engine.io/t/solved-general-question-before-learn-more/2054/4 "2025-12-01T09:50:42Z")

</div>

Hello,

I need a small more information 🙂

I saw that the Gtlf file format absolutly need triangle faces and I understood why. Obj file format doesn’t have this" “limitation”. When I load a .obj file in castle-model-view, with for example pentagonal faces, and I choose “solid wireframe” I see that every face is in fact transformed in a set of triangles …and it’s not what I want to be able to do.

So here is my essential question 🙂 …. by code is it possible to define a no triangle face and see edge of this face ? If I read the example to gace me to read in the previous message; I guess that the answer is yes ?

```auto
IndexedFaceSet.SetCoordIndex([0, 1, 3, 2, -1, 2, 3, 4, 5, -1, 5, 4, 6, 7, -1]);

```

Here there are 4 points faces between -1 value, that’s it ?

Thank you again for your answer.

Have a good day and hello from France 🙂

Alexandre

---

<div class="post-metadata">

### Author: ![michalis](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/michalis/32/3_2.png) [@michalis](https://forum.castle-engine.io/u/michalis)
#### Post date: [December 1, 2025, 1:32pm UTC](https://forum.castle-engine.io/t/solved-general-question-before-learn-more/2054/5 "2025-12-01T13:32:40Z")

</div>

For rendering, the polygons (anything with more than 3 vertexes) are transformed into triangles. (Some OpenGL versions supported also natively quads, but not OpenGLES.)

If you choose to display the wireframe using `TCastleScene.RenderOptions.WireframeEffect` and you look at mesh with polygons (like `TIndexedFaceSetNode`) then indeed you will see this (somewhat internal) fact. We have a TODO to improve the wireframe look, to not show these “internal edges” effectively, see [roadmap item](https://castle-engine.io/roadmap#opengles_wirefame), [related news a few months ago](https://castle-engine.io/wp/2025/03/09/new-class-for-zip-handling-tcastlezip-progress-on-new-pretty-wireframe-approach-woff-fonts-support-lod-usage-demo/). But, long story short, it’s not finished – so by using `TCastleScene.RenderOptions.WireframeEffect` , you will see these internal edges.

The way to avoid them:

1. Build the `TIndexedLineSetNode` or `TLineSetNode` yourself. From your original description, if you want to e.g. selectively change edges colors, I guessed yo will want to do it anyway 🙂 So this means you have 2 geometry nodes for one mesh: one with faces, one with edges. If the edges have sufficient thickness (which you can influence e.g. using [MyScene.RenderOptions.LineWidth](https://castle-engine.io/apidoc/html/CastleRenderOptions.TCastleRenderOptions.html#LineWidth) ), then they will be visible “on top” of the mesh.

2. A little easier: duplicate the mesh (like `TIndexedFaceSetNode`) but set the [TAbstractShapeNode.Shading](https://castle-engine.io/apidoc/html/X3DNodes.TAbstractShapeNode.html#Shading) to `shWireframe` on the mesh’s copy. This internally does something similar to above: it builds an `TIndexedLineSetNode` or `TLineSetNode` to display the wireframe, and it’s intelligent to avoid showing the internal edges.

---

<div class="post-metadata">

### Author: ![aboisrame](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/aboisrame/32/2709_2.png) [@aboisrame](https://forum.castle-engine.io/u/aboisrame)
#### Post date: [December 1, 2025, 2:38pm UTC](https://forum.castle-engine.io/t/solved-general-question-before-learn-more/2054/6 "2025-12-01T14:38:47Z")

</div>

Thanks again for your second precious answer. I can now read the coordinnates from a text file, build the mesh and have only the edges I want with the “duplicate the mesh” solution.

It seem’s that CGE will be able to deeply help me to create this little program about polyhedra I want to do since a long time now. Because polyhedra are just beautiful to look at and to build 🙂

Thank you again for your genius work.

Alexandre
