# How to obtain the size of texture in TCastleScene

**URL:** <https://forum.castle-engine.io/t/how-to-obtain-the-size-of-texture-in-tcastlescene/1251>\
**Category:** 2D\
**Created:** [June 28, 2024, 9:57am UTC](https://forum.castle-engine.io/t/how-to-obtain-the-size-of-texture-in-tcastlescene/1251 "2024-06-28T09:57:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![a493203176](https://forum.castle-engine.io/letter_avatar_proxy/v4/letter/a/cc9497/32.png) [@a493203176](https://forum.castle-engine.io/u/a493203176)\
**Post date:** [June 28, 2024, 9:57am UTC](https://forum.castle-engine.io/t/how-to-obtain-the-size-of-texture-in-tcastlescene/1251/1 "2024-06-28T09:57:22Z")

</div>

How to obtain the height and width of textures in TCastleScene

---

<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:** [June 28, 2024, 6:19pm UTC](https://forum.castle-engine.io/t/how-to-obtain-the-size-of-texture-in-tcastlescene/1251/2 "2024-06-28T18:19:38Z")

</div>

Note: I give an answer below, but it will be helpful if you can describe in more detail what do you want to achieve in the end. I.e. _why_ do you want to know texture size, how it’s loaded in TCastleScene. Then we can maybe advise better :), there are maybe more direct ways of doing what you need.

The answer: the Scene has `RootNode` which contains a graph of nodes, see [Scene graph (X3D) | Castle Game Engine](https://castle-engine.io/vrml_x3d.php) . You can search it for `TImageTextureNode` nodes, e.g. using

```auto
Scene.RootNode.EnumerateNodes(TImageTextureNode, @MyProc, false);

```

See e.g. how `examples/animations/animate_bones_by_code/` is using `EnumerateNodes`. It’s using `EnumerateNodes` for different purpose, but the idea remains. See [castle-engine/examples/animations/animate\_bones\_by\_code/code/gameviewmain.pas at master · castle-engine/castle-engine · GitHub](https://github.com/castle-engine/castle-engine/blob/master/examples/animations/animate_bones_by_code/code/gameviewmain.pas) .

In `MyProc`, you get a node, `Node: TX3DNode`. You can cast it to `TImageTextureNode` and access properties, like this:

```auto
procedure TViewMain.MyProc(Node: TX3DNode);
var
  TextureNode: TImageTextureNode;
begin
  TextureNode := Node as TImageTextureNode; // safe to cast, as EnumerateNodes only chooses TImageTextureNode
  // Possible URLs from which to load texture are in TextureNode.FdUrl.Items .
  // The URL which was actually used to load the texture, if any, is in TextureNode.TextureUsedFullUrl .
  TextureNode.IsTextureLoaded := true; // load the texture now, if not loaded yet
  if TextureNode.IsTextureImage then
  begin
    WritelnLog('loaded from %s', [TextureNode.TextureUsedFullUrl]);
    WritelnLog('loaded size %d %d', [TextureNode.TextureImage.Width, TextureNode.TextureImage.Height]);
  end else
  begin
    WritelnLog('not loaded, no valid URLs');
  end;
end;

```

^ I did not actually test the above code, but hopefully it will get you started 🙂

The API docs of TImageTextureNode and ancestor classes:

- [Castle Game Engine: X3DNodes: Class TImageTextureNode](https://castle-engine.io/apidoc/html/X3DNodes.TImageTextureNode.html)
- [Castle Game Engine: X3DNodes: Class TAbstractTexture2DNode](https://castle-engine.io/apidoc/html/X3DNodes.TAbstractTexture2DNode.html)
- [Castle Game Engine: X3DNodes: Class TAbstractSingleTextureNode](https://castle-engine.io/apidoc/html/X3DNodes.TAbstractSingleTextureNode.html)
- [Castle Game Engine: X3DNodes: Class TAbstractTextureNode](https://castle-engine.io/apidoc/html/X3DNodes.TAbstractTextureNode.html)
