<div><div dir="auto">Re: x3d.py for X3D JSON plugin import into Blender and X3DJSONLD for x3d.py.  WIP.</div><div dir="auto"><br></div><div dir="auto">For X3D Python geeks.  If you’re not a Python geek, the following will be meaningless.</div><div dir="auto"><br></div><div dir="auto">What I need:  Status report of using x3d.py for importing anything into Blender.</div><div dir="auto"><br></div><div dir="auto">Desired: Python app code generation from x3d.py, to replace x3djsonld.py, here:  <div dir="auto"><a href="https://github.com/coderextreme/X3DJSONLD/blob/master/src/main/python/x3djsonld.py">https://github.com/coderextreme/X3DJSONLD/blob/master/src/main/python/x3djsonld.py</a>  I want to provide Python code export from Blender.</div></div><div dir="auto"><br></div><div dir="auto">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.<br></div><div dir="auto"><br></div><div dir="auto">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.</div><div dir="auto"><br></div><div dir="auto"><div><meta charset="UTF-8"><div dir="auto" style="font-size:19px;font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;color:rgb(0,0,0)">One thing I found while using pydantic was to use import typing’s ClassVar to give a type to class variable constants.</div><div dir="auto" style="font-size:19px;font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;color:rgb(0,0,0)"><br></div><div dir="auto" style="font-size:19px;font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;color:rgb(0,0,0)">Like:</div><div dir="auto" style="font-size:19px;font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;color:rgb(0,0,0)"><br></div><div dir="auto" style="font-size:19px;font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;color:rgb(0,0,0)">from typing import ClassVar</div><div dir="auto" style="font-size:19px;font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;color:rgb(0,0,0)"><br></div><div dir="auto" style="font-size:19px;font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;color:rgb(0,0,0)">[snip]</div><div dir="auto" style="font-size:19px;font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;color:rgb(0,0,0)">XML_HEADER: ClassVar[str] = ‘<?xml …</div><div dir="auto" style="font-size:19px;font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;color:rgb(0,0,0)"><br></div><div dir="auto" style="font-size:19px;font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;color:rgb(0,0,0)">I’m not sure what’s pythonic or standard.  I know python 3.12 probably updates this, when available.</div></div><div dir="auto" style="font-size:19px;font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;color:rgb(0,0,0)"><br></div><div dir="auto" style="font-size:19px;font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;color:rgb(0,0,0)">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.</div><div dir="auto" style="font-size:19px;font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;color:rgb(0,0,0)"><br></div><div dir="auto" style="font-size:19px;font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;color:rgb(0,0,0)">Someone should think about “rendering” x3d.py structures to Blender bpy, if not already done.  I desire information on this if it exists.</div><div dir="auto" style="font-size:19px;font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;color:rgb(0,0,0)"><br></div><div dir="auto" style="font-size:19px;font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;color:rgb(0,0,0)">If lookup/dispatch/hash structures are patented, please let me know, and I will switch to switch/match or if/elif/else code structures.</div><div dir="auto" style="font-size:19px;font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;color:rgb(0,0,0)"><br></div><div dir="auto" style="font-size:19px;font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;color:rgb(0,0,0)">Another idea is to provide JSON validation with x3d.py.   We already have something for Java and JavaScript, why not Python?</div></div><div dir="auto"><br></div><div dir="auto">John</div><div><br><div class="gmail_quote"></div></div></div><div><div><div><div dir="ltr" class="gmail_attr">On Mon, Sep 18, 2023 at 12:21 PM John Carlson <<a href="mailto:yottzumm@gmail.com" target="_blank">yottzumm@gmail.com</a>> wrote:<br></div></div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;padding-left:1ex;border-left-color:rgb(204,204,204)"></blockquote></div><div>Does anyone have a DOM document or python dict to scenegraph converter we can use with a blender plugin and x3d.py?<div dir="auto"><br></div></div></div></div><div><div><div><div dir="auto">Thanks for any info you can provide.   I believe this is the best path forward.  Python dict is preferred over DOM.</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;padding-left:1ex;border-left-color:rgb(204,204,204)"><div dir="auto"><br></div><div dir="auto">John </div>
</blockquote>
</div>
</div>
</div>