[X3D-Ecosystem] Stumbling over importing JSON into a scenegraph

John Carlson yottzumm at gmail.com
Wed Aug 6 10:15:40 PDT 2025


Michalis, I am not mentally capable of doing what you outlined.  I can
generate DOM and XML fairly successfully, if CGE works with that.   I might
need to download that again, because I can’t even get the template model
viewer working with .x3d files, just replacing car.x3d with:


https://github.com/coderextreme/X3DJSONLD/blob/master/src/main/data/rubikPly.x3d

I can’t get car.x3d working either, just knight.gltf.

My current approach is to get my .x3d file working under the template model
viewer project, and then add a .x3dj loader.

John
On Wed, Aug 6, 2025 at 7:13 AM Michalis Kamburelis <michalis.kambi at gmail.com>
wrote:

> John:
>
> I explained what I propose and why in Discord,
>
> https://discord.com/channels/389676745957310465/1168902964228931656/1400918074630340629
> . This email thread somewhat repeats your notions, forcing me to
> repeat my answers.. this is not optimal :) Please let's keep the
> communication on this topic on Discord (where also others familiar
> with Castle Game Engine are, and can help, or learn from
> developments).
>
> To summarize for others now, so they have the context :
>
> Ultimately, you can go with any solution you like naturally, it's your
> code and your choice.
>
> My advises aim to help you make what you want easier. Repeating what I
> said from Discord thread and why:
>
> 1. I advise to implement X3D JSON reader just like all other readers
> in Castle Game Engine. So you read X3D file (using FpJson) and in turn
> you construct a graph of X3D nodes, represented by Castle Game Engine
> classes, like TSphereNode, TX3DRootNode etc.
>
>     - It means you make a unit that implements a function like
> "function X3DJson(const Stream: TStream; const BaseUrl: String):
> TX3DRootNode;" and register it using RegisterModelFormat .
>
>     - There's documentation of it, we have CGE manual, API reference
> and it's all open-source.
>
>     - The requirement for this is that you need to learn CGE API to
> use X3D, naturally.
>
>     - On the upside, if you follow this way, you are integrated with
> CGE on every level. So e.g. castle-model-viewer will be able to
> automatically view X3D JSON. And castle-model-converter will be able
> to read (and validate, and convert to other encodings like X3D
> classic,xml) X3D JSON. And you can use existing infrastructure of CGE,
> where all X3D nodes, with all their fields, are already defined, and
> can be accessed in various ways (also by just knowing their name as a
> string). All the existing loading, from glTF, from X3D classic, from
> X3D XML, goes this route.
>
> 2. In contrast, if you just convert X3D JSON -> X3D XML, then you need
> to reinvent things which already exist in CGE. You will need to deal
> with DOM, you will need to invent knowledge about X3D nodes and
> fields. And in the end you do a specific conversion that will have to
> be "chained" with e.g castle-model-converter to get e.g. X3D classic
> output.
>
> Again, in the end you can follow any approach you like in the end.
> Note that for AD 2, you don't really CGE. FPC includes already JSON
> and XML support (FpJson, DOM units).
>
> Regards,
> Michalis
>
> śr., 6 sie 2025 o 00:34 John Carlson <yottzumm at gmail.com> napisał(a):
> >
> > I am again stumbling over importing X3D JSON into a scenegraph, this
> time with Castle Game Engine.  How is this beast crackable?  I don’t seem
> to have the skill, but perhaps persistence pays off?
> >
> > My wiser self says I should just go with converting DOM or  XML, which
> worked well with X_ITE, X3DOM and X3DJSAIL.   I will still apparently have
> to register classes, which shouldn’t be a problem.   I don’t know how to
> register Proto stuff yet.
> > I am having better luck translating to XML. I’ll go that route for now.
> I’m thinking Michalis knows something I don’t, which might complicate
> things.
> >
> > There’s a choice between fpjson/jsonparser, and CastlePasJson units, I’m
> not clear on advantages of one over the other.
> >
> > John
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://web3d.org/pipermail/x3d-ecosystem_web3d.org/attachments/20250806/47c74e18/attachment-0001.html>


More information about the X3D-Ecosystem mailing list