[x3d-public] WIP: JSON document to X3D SAI scenegraph in Python.

John Carlson yottzumm at gmail.com
Tue Sep 19 18:41:40 PDT 2023


Re: x3d.py for X3D JSON plugin import into Blender and X3DJSONLD for
x3d.py.  WIP.

For X3D Python geeks.  If you’re not a Python geek, the following will be
meaningless.

What I need:  Status report of using x3d.py for importing anything into
Blender.

Desired: Python app code generation from x3d.py, to replace x3djsonld.py,
here:
https://github.com/coderextreme/X3DJSONLD/blob/master/src/main/python/x3djsonld.py
 I want to provide Python code export from Blender.

For X3D JSON, I am using standard Python’s getattr/setattr techniques on
x3d.py with lookup structures for classes, methods, field types and
accessTypes (so I won’t try to call setattr on a outputOnly field and for
finding constructors, etc).  This is done to “simplify” JSON import into a
few methods, instead of spreading import stuff across a whole new class
hierarchy parallel to x3d.py.

My current idea is to provide lookup structures (dicts) which converts
class name strings and field name strings into classes, field types, setter
methods and access types.  At least I don’t use eval.  This kind of lookup
may be in x3d.py for some things already, like field metadata, Don has
shown me.  I’m pretty sure i need hashes/maps/structures for fast access,
instead of looping through all the fields.  I do not know if Python/x3d.py
provides a hashes/maps based on the field metadata array for each class or
not.  I do know that this would lead to code bloat in x3d.py, so I’m not
asking for updates for this.  What I will eventually do is move my hash
generation code from looking at X3DUOM to looking at x3d.py.  I’m just
trying to prove the pattern works.  I already had a lot of similar Python
code for similar purposes.

One thing I found while using pydantic was to use import typing’s ClassVar
to give a type to class variable constants.

Like:

from typing import ClassVar

[snip]
XML_HEADER: ClassVar[str] = ‘<?xml …

I’m not sure what’s pythonic or standard.  I know python 3.12 probably
updates this, when available.

I’ve been working with a JSON import adapter which identifies the class to
invoke for meta, unit, and component statements (I will add others) by
adding a new property, “tag.”  It’s slow going.  At least the coding is
more decent than generating python so far.  It’s rough debugging from the
command line.  This will be an X3DJSONLD product in addition to being used
with Blender.

Someone should think about “rendering” x3d.py structures to Blender bpy, if
not already done.  I desire information on this if it exists.

If lookup/dispatch/hash structures are patented, please let me know, and I
will switch to switch/match or if/elif/else code structures.

Another idea is to provide JSON validation with x3d.py.   We already have
something for Java and JavaScript, why not Python?

John

On Mon, Sep 18, 2023 at 12:21 PM John Carlson <yottzumm at gmail.com> wrote:

> Does anyone have a DOM document or python dict to scenegraph converter we
can use with a blender plugin and x3d.py?

Thanks for any info you can provide.   I believe this is the best path
forward.  Python dict is preferred over DOM.

>
> John
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20230919/ce8ff5ed/attachment.html>


More information about the x3d-public mailing list