[X3D-Ecosystem] Fixing DEF/USE in Python(Serializer)
John Carlson
yottzumm at gmail.com
Mon Aug 25 16:38:58 PDT 2025
I am primarily concerned with A) at this point.
I will look into the kwargs solution, I don’t recall looking at before.
On Mon, Aug 25, 2025 at 5:24 PM Andreas Plesch <andreasplesch at gmail.com>
wrote:
> Personally, I do not have updates and would have to look up the discussion
> at the time.
>
> I believe there were two sources of USE before DEF x3d code using x3d.py:
>
> A) - x3d.py assembling result output in some fixed order, for example the
> Metadataset.metadata field is output before the MetadataSet.value field,
> regardless of parameter order.
> B) - explicitly appending DEF nodes after USE nodes in python by user,
> perhaps by accident
>
> I tried to first address A) by modifying x3d.py generation to process the
> field arrays in order (using the python **kwargs feature to get access to
> the parameter) since array parameters are the default python x3d style.
> I think this works but leads to harder to understand code. (Run
> test/MetadataNodeExampleV4.py).
>
> I then tried to address B) although it is mostly user error but realizing
> a solution should also address A). This is done through postprocessing the
> x3d.py generated python scene structure and just building up dictionaries
> of encountered DEF and USE nodes, and then swapping them as necessary. I
> could get it to work for the most common situations but it will need a lot
> more work. It should be doable and would be probably a preferred solution.
> (Run test/swap_USEbeforeDEF.py).
>
> -Andreas
>
> On Mon, Aug 25, 2025 at 3:34 PM John Carlson <yottzumm at gmail.com> wrote:
>
>> Let me know of any updates, my brain is back 2+ years ago. I’m working
>> on a Python based renderer (no X3D encodings), and sometimes, I want to
>> output XML and VRML from Python to check the scene, and potentially others
>> will too. I have 2 struggles, containerFields (another message) and
>> DEF/USE ordering on output.
>>
>> Most likely, the best approach is to remove USE, and use variables
>> instead in my python. But yes, we also need logic in x3d.py output to add
>> USE and possibly different containerFields appropriately. Maybe using
>> Andreas’s kwargs branch is best???
>> https://github.com/andreasplesch/x3d-python-mod/tree/kwargs
>>
>> Using variables is not common in X3dToPython.xslt output (yes, it uses
>> parameters), but it’s extremely common in my PythonSerializer.js output, so
>> I’m guessing that X3dToPython.xslt restructures the scenegraph output to
>> conform to x3d.py output. That seems extremely messy, but perhaps that’s
>> the power of XSLT.
>>
>> How do we propagate solutions in x3d-tidy and Castle to other systems?
>> I’m hearing that Castle is working on a Python solution? Will it work with
>> the x3d.py API?
>>
>> Who else wants to write python that generates good VRML and XML? Do we
>> have to design our Python (or possibly source JSON and XML) according to
>> how x3d.py outputs fields? That would be okay, perhaps?
>>
>> How dow we attach different containerFields to the same scenegraph node?
>>
>> John
>>
>>>
>
> --
> Andreas Plesch
> Waltham, MA 02453
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://web3d.org/pipermail/x3d-ecosystem_web3d.org/attachments/20250825/86838461/attachment-0001.html>
More information about the X3D-Ecosystem
mailing list