[x3d-public] Thoughts for x3d.py str() calls

John Carlson yottzumm at gmail.com
Mon Oct 16 22:46:11 PDT 2023


Note USE = 'C' totally disappeared! Where did it go? This is one reason why
I say that USE and DEF can't be used together in the same node.

John

On Tue, Oct 17, 2023 at 12:42 AM John Carlson <yottzumm at gmail.com> wrote:

> Sure, no need to read the python source code. Just look at the XML output,
> that's what we're complaining about. I can export VRML, just a second.
> Think of imperative source code like reading a recipe and combining
> things.  You have to follow the order of things.
>
>
>
>
> Here's another try:
>
> from x3d import *
>
> x3d = X3D()
> trans = Transform(DEF='C')
> grpa = Group(DEF='A', children=[trans])
> trans.USE = 'C'
> trans.DEF = 'WTF'
> grpb = Group(DEF='B', children=[trans])
> scene = Scene(children=[grpa, grpb])
> x3d.Scene = scene
> blob = x3d.XML()
> print(blob)
>
> Output:
>
> x3d.py package 4.0.64.4 loaded, have fun with X3D Graphics!
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 4.0//EN" "
> https://www.web3d.org/specifications/x3d-4.0.dtd">
> <X3D profile='Full' version='4.0' xmlns:xsd='
> http://www.w3.org/2001/XMLSchema-instance' xsd:noNamespaceSchemaLocation='
> https://www.web3d.org/specifications/x3d-4.0.xsd'>
>   <Scene>
>     <Group DEF='A'>
>       <Transform DEF='WTF'/>
>     </Group>
>     <Group DEF='B'>
>       <Transform DEF='WTF'/>
>     </Group>
>   </Scene>
> </X3D>
>
>
> On Mon, Oct 16, 2023 at 10:29 PM Joe D Williams <joedwil at earthlink.net>
> wrote:
>
>> Sorry, I have no interest in trying to read and understand that listing.
>> Regular user code is hard enough for me.
>>
>> What are you trying to do,anyway? Is the intent to generate x3d user
>> code?
>>
>> Joe
>>
>> -----Original Message-----
>> From: John Carlson <yottzumm at gmail.com>
>> Sent: Oct 16, 2023 8:21 PM
>> To: Joe D Williams <joedwil at earthlink.net>
>> Cc: Brutzman Donald (Don) (CIV) <brutzman at nps.edu>, GPU Group <
>> gpugroup at gmail.com>, Peitso Loren (CIV) <lepeitso at nps.edu>, X3D Graphics
>> public mailing list <x3d-public at web3d.org>
>> Subject: Re: Thoughts for x3d.py str() calls
>>
>>
>> Okay, to be more "SAI"-like, and not use append, I present the
>> following python, which admittedly, is more complicated than Doug's initial
>> example.
>>
>>
>> from x3d import *
>>
>> x3d = X3D()
>> trans = Transform(DEF='C')
>> grpa = Group(DEF='A', children=[trans])
>> trans.DEF = None
>> trans.USE = 'C'
>> grpb = Group(DEF='B', children=[trans])
>> scene = Scene(children=[grpa, grpb])
>> x3d.Scene = scene
>> blob = x3d.XML()
>> print(blob)
>>
>>
>>
>> Output:
>>
>> x3d.py package 4.0.64.4 loaded, have fun with X3D Graphics!
>> <?xml version="1.0" encoding="UTF-8"?>
>> <!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 4.0//EN" "
>> https://www.web3d.org/specifications/x3d-4.0.dtd">
>> <X3D profile='Full' version='4.0' xmlns:xsd='
>> http://www.w3.org/2001/XMLSchema-instance'
>> xsd:noNamespaceSchemaLocation='
>> https://www.web3d.org/specifications/x3d-4.0.xsd'>
>>   <Scene>
>>     <Group DEF='A'>
>>       <Transform USE='C'/>
>>     </Group>
>>     <Group DEF='B'>
>>       <Transform USE='C'/>
>>     </Group>
>>   </Scene>
>> </X3D>
>>
>> If you suggest that I change trans.DEF to something beside None, we can
>> try that. I'll do that in my next message.
>>
>> Remember that the goal is to to produce fields which are order
>> independent as output from x3d.py
>>
>> John
>>
>> On Mon, Oct 16, 2023 at 10:00 PM Joe D Williams <joedwil at earthlink.net>
>> wrote:
>>
>>> Joeminion asks: So what is this other people's change thing.
>>>
>>> Is there somebody who knows the spec and wants to change something?
>>>
>>> What is to change?
>>>
>>> All any contributor has to do is show a better way.
>>>
>>>
>>>
>>> > Part of open source is accepting and incorporating other people’s
>>> changes.
>>>  Please think about how to improve x3d. The open part means you can read
>>> the stuff, build tools around and in the stuff, experiment with it, and
>>> maybe contribute. Hey, all it takes is a good idea that improves the
>>> package.
>>>
>>> Joe
>>>
>>>
>>>
>>>
>>>
>>> -----Original Message-----
>>> From: John Carlson <yottzumm at gmail.com>
>>> Sent: Oct 16, 2023 7:13 PM
>>> To: Brutzman, Donald (Don) (CIV) <brutzman at nps.edu>
>>> Cc: GPU Group <gpugroup at gmail.com>, Joe D Williams <
>>> joedwil at earthlink.net>, Peitso, Loren (CIV) <lepeitso at nps.edu>, X3D
>>> Graphics public mailing list <x3d-public at web3d.org>
>>> Subject: Re: Thoughts for x3d.py str() calls
>>>
>>>
>>> Part of open source is accepting and incorporating other people’s
>>> changes.  If you don’t do that, you’re not doing open source.
>>>
>>> John
>>>
>>> On Mon, Oct 16, 2023 at 8:28 PM Brutzman, Donald (Don) (CIV) <
>>> brutzman at nps.edu> wrote:
>>>
>>>> Back to you guys… please use your friendly neighborhood python
>>>> implementation to answer all these questions relating to code correctness
>>>> and effectiveness.
>>>>
>>>>
>>>>
>>>>    - Wikipedia: Small matter of programming
>>>>    - https://en.wikipedia.org/wiki/Small_matter_of_programming
>>>>
>>>>
>>>>
>>>> all the best, Don
>>>>
>>>> --
>>>>
>>>> Don Brutzman  Naval Postgraduate School, Code USW/Br
>>>> brutzman at nps.edu
>>>>
>>>> Watkins 270,  MOVES Institute, Monterey CA 93943-5000 USA
>>>> +1.831.656.2149
>>>>
>>>> X3D graphics, virtual worlds, navy robotics
>>>> https://faculty.nps.edu/brutzman
>>>>
>>>>
>>>>
>>>> *From:* John Carlson <yottzumm at gmail.com>
>>>> *Sent:* Monday, October 16, 2023 6:13 PM
>>>> *To:* Brutzman, Donald (Don) (CIV) <brutzman at nps.edu>
>>>> *Cc:* GPU Group <gpugroup at gmail.com>; Joe D Williams <
>>>> joedwil at earthlink.net>; Peitso, Loren (CIV) <lepeitso at nps.edu>; X3D
>>>> Graphics public mailing list <x3d-public at web3d.org>
>>>> *Subject:* Re: Thoughts for x3d.py str() calls
>>>>
>>>>
>>>>
>>>> Don, there is no error in Doug’s python example.  We’re back to the
>>>> multiple parent problem previously discussed.
>>>>
>>>>
>>>>
>>>> It is possible to set a flag in nodes that have been output and clear
>>>> it afterwards.  It’s also possible to keep a map of DEFed outputted nodes
>>>> and put in USE if the node has multiple parents discard the map afterwards.
>>>> The latter may be preferred.
>>>>
>>>>
>>>>
>>>> Consider the case of a script handling several outputs from the same
>>>> model.
>>>>
>>>>
>>>>
>>>> John
>>>>
>>>>
>>>>
>>>> On Mon, Oct 16, 2023 at 3:47 PM Brutzman, Donald (Don) (CIV) <
>>>> brutzman at nps.edu> wrote:
>>>>
>>>> The x3d.py makes no effort to correct author errors.  That is up to the
>>>> author.  Trying to “fix” things further can lead to further problems and a
>>>> corrupted model.
>>>>
>>>>
>>>>
>>>> There are a great many models in X3D Examples with DEF and USE which
>>>> run properly in unit tests.
>>>>
>>>>
>>>>
>>>> There are several diagnostics built in for reporting errors.  Have you
>>>> tested your erroneous scene to see what you get?  If a further error
>>>> diagnostic is needed, we can add it to the  X3DPSAIL TODO list.  If you
>>>> write a python method to do that, we can test it further and possibly
>>>> integrate it.
>>>>
>>>>
>>>>
>>>>    - X3D Python Scene Access Interface Library (X3DPSAIL), TODO
>>>>    - https://www.web3d.org/x3d/stylesheets/python/python.html#TODO
>>>>
>>>>
>>>>
>>>> If a correct model is getting exported into another form incorrectly,
>>>> then we can diagnose and fix the conversion.  As ever, use-case examples of
>>>> such errors are essential to continuing progress.
>>>>
>>>>
>>>>
>>>> Thanks for all efforts with X3D Python.
>>>>
>>>>
>>>>
>>>> all the best, Don
>>>>
>>>> --
>>>>
>>>> Don Brutzman  Naval Postgraduate School, Code USW/Br
>>>> brutzman at nps.edu
>>>>
>>>> Watkins 270,  MOVES Institute, Monterey CA 93943-5000 USA
>>>> +1.831.656.2149
>>>>
>>>> X3D graphics, virtual worlds, navy robotics
>>>> https://faculty.nps.edu/brutzman
>>>>
>>>>
>>>>
>>>> *From:* GPU Group <gpugroup at gmail.com>
>>>> *Sent:* Monday, October 16, 2023 9:49 AM
>>>> *To:* John Carlson <yottzumm at gmail.com>
>>>> *Cc:* Brutzman, Donald (Don) (CIV) <brutzman at nps.edu>; Joe D Williams <
>>>> joedwil at earthlink.net>; Peitso, Loren (CIV) <lepeitso at nps.edu>; X3D
>>>> Graphics public mailing list <x3d-public at web3d.org>
>>>> *Subject:* Re: Thoughts for x3d.py str() calls
>>>>
>>>>
>>>>
>>>> correction first output is
>>>>
>>>>   <Scene>
>>>>
>>>>     <Group DEF='A'>
>>>>
>>>>       <Transform DEF='C'/>
>>>>
>>>>     </Group>
>>>>
>>>>     <Group DEF='B'>
>>>>
>>>>       <Transform DEF='C'/>
>>>>
>>>>     </Group>
>>>>
>>>>
>>>>
>>>> On Mon, Oct 16, 2023 at 10:32 AM GPU Group <gpugroup at gmail.com> wrote:
>>>>
>>>> That may relate to the DEF USE issue with X3D.py:
>>>>
>>>> x x3d.py makes no effort to conjugate DEF and USE and properly order
>>>> DEF before USE in its export stream
>>>>
>>>> - not a common problem unless a node has 2 fields that take the same
>>>> node (directly SF or indirectly in MFNode descendent field)
>>>>
>>>> x it's a problem with HAnimHumanoid which has coordinate and skin
>>>> fields, which typically involve the same Coordinate node
>>>>
>>>> - tinkering can be done in the blender exporter, to do a USE before a
>>>> DEF,  but with inconvenience and messy code
>>>>
>>>> If a call can be made in x3d.py before exporting a DEF or USE, then
>>>> that function can be over-ridden to take responsibility for DEF USE
>>>> conjugation and correct output ordering something like this:
>>>>
>>>> node = getDefOrUse(node, node.DEF, node.USE)
>>>>
>>>> and for the x3d.py default it would just return the same element (or
>>>> node), and overrides can do something more sophisticated.
>>>>
>>>>
>>>>
>>>> more..
>>>>
>>>> DEF USE NON-CONJUGATION IN X3D.PY
>>>>
>>>> test_def.py
>>>>
>>>> x3d = X3D()
>>>>
>>>> scene = Scene()
>>>>
>>>> x3d.Scene = scene
>>>>
>>>> grpa = Group(DEF='A')
>>>>
>>>> grpb = Group(DEF='B')
>>>>
>>>> scene.children.append(grpa)
>>>>
>>>> scene.children.append(grpb)
>>>>
>>>> trans = Transform(DEF='C')
>>>>
>>>> grpb.children.append(trans)
>>>>
>>>> grpa.children.append(trans)
>>>>
>>>> blob = x3d.XML()
>>>>
>>>> fp = open("dump.x3d","w+")
>>>>
>>>> fp.write(blob)
>>>>
>>>> fp.close()
>>>>
>>>>
>>>>
>>>> output:
>>>>
>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>>
>>>> <!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 4.0//EN" "
>>>> https://www.web3d.org/specifications/x3d-4.0.dtd">
>>>>
>>>> <X3D profile='Full' version='4.0' xmlns:xsd='
>>>> http://www.w3.org/2001/XMLSchema-instance
>>>> <https://nam10.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.w3.org%2F2001%2FXMLSchema-instance&data=05%7C01%7Cbrutzman%40nps.edu%7C4181f75f38a24696882b08dbceae41c5%7C6d936231a51740ea9199f7578963378e%7C0%7C0%7C638331020060039666%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=MhoqazQK%2FlPhDhc%2BNJs6uMa7kFTpfKnJ1oGWwgxtakQ%3D&reserved=0>'
>>>> xsd:noNamespaceSchemaLocation='
>>>> https://www.web3d.org/specifications/x3d-4.0.xsd'>
>>>>
>>>>   <Scene>
>>>>
>>>>     <Group DEF='A'>
>>>>
>>>>       <Transform USE='C'/>
>>>>
>>>>     </Group>
>>>>
>>>>     <Group DEF='B'>
>>>>
>>>>       <Transform DEF='C'/>
>>>>
>>>>     </Group>
>>>>
>>>>   </Scene>
>>>>
>>>> </X3D>
>>>>
>>>>
>>>>
>>>> test_def_use.py
>>>>
>>>> from x3d import *
>>>>
>>>>
>>>>
>>>> x3d = X3D()
>>>>
>>>> scene = Scene()
>>>>
>>>> x3d.Scene = scene
>>>>
>>>> grpa = Group(DEF='A')
>>>>
>>>> grpb = Group(DEF='B')
>>>>
>>>> scene.children.append(grpa)
>>>>
>>>> scene.children.append(grpb)
>>>>
>>>> trans = Transform(DEF='C')
>>>>
>>>> grpb.children.append(trans)
>>>>
>>>> grpa.children.append(trans)
>>>>
>>>> blob = x3d.XML()
>>>>
>>>> fp = open("dump.x3d","w+")
>>>>
>>>> fp.write(blob)
>>>>
>>>> fp.close()
>>>>
>>>>
>>>>
>>>> output:
>>>>
>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>>
>>>> <!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 4.0//EN" "
>>>> https://www.web3d.org/specifications/x3d-4.0.dtd">
>>>>
>>>> <X3D profile='Full' version='4.0' xmlns:xsd='
>>>> http://www.w3.org/2001/XMLSchema-instance
>>>> <https://nam10.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.w3.org%2F2001%2FXMLSchema-instance&data=05%7C01%7Cbrutzman%40nps.edu%7C4181f75f38a24696882b08dbceae41c5%7C6d936231a51740ea9199f7578963378e%7C0%7C0%7C638331020060039666%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=MhoqazQK%2FlPhDhc%2BNJs6uMa7kFTpfKnJ1oGWwgxtakQ%3D&reserved=0>'
>>>> xsd:noNamespaceSchemaLocation='
>>>> https://www.web3d.org/specifications/x3d-4.0.xsd'>
>>>>
>>>>   <Scene>
>>>>
>>>>     <Group DEF='A'>
>>>>
>>>>       <Transform USE='C'/>
>>>>
>>>>     </Group>
>>>>
>>>>     <Group DEF='B'>
>>>>
>>>>       <Transform DEF='C'/>
>>>>
>>>>     </Group>
>>>>
>>>>   </Scene>
>>>>
>>>> </X3D>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> On Mon, Oct 16, 2023 at 10:09 AM GPU Group <gpugroup at gmail.com> wrote:
>>>>
>>>> It seems possible to override functions in python, if there are just a
>>>> few to override.
>>>>
>>>> And one suggestion for x3d.py imperfections is to apply fixes at
>>>> runtime in some initialization function.
>>>>
>>>> - that assumes/requires just a few target functions, not 480 functions
>>>> that need to be repaired
>>>>
>>>> - so for some fixes it may be helpful to change the upstream x3d.py to
>>>> call a function that can be easily replaced.
>>>>
>>>> -Doug
>>>>
>>>> Example:
>>>>
>>>> file myclass.py
>>>>
>>>> class Wonky:
>>>>
>>>>   def __init__(self):
>>>>
>>>>     self.color = "Red"
>>>>
>>>>   def func1(self, color :str) -> bool:
>>>>
>>>>     if color == self.color:
>>>>
>>>>       return True
>>>>
>>>>     return False
>>>>
>>>>
>>>>
>>>> file override.py
>>>>
>>>> from myclass import *
>>>>
>>>>
>>>>
>>>> mc = Wonky()
>>>>
>>>> print("match with Blue? "+str(mc.func1("Blue")))
>>>>
>>>>
>>>>
>>>> def func2(self, color: str) -> bool:
>>>>
>>>>   if self.color != color:
>>>>
>>>>     return True
>>>>
>>>>   return False
>>>>
>>>> Wonky.func1 = func2 # <<<<<<<<<<<< OVERRIDE
>>>>
>>>> print("don't match with Blue? "+str(mc.func1("Blue")))
>>>>
>>>>
>>>>
>>>> output:
>>>>
>>>> match with Blue? False
>>>>
>>>> don't match with Blue? True
>>>>
>>>> -Doug
>>>>
>>>>
>>>>
>>>> On Mon, Oct 16, 2023 at 9:55 AM John Carlson <yottzumm at gmail.com>
>>>> wrote:
>>>>
>>>> Instead of calling str() to print out a value, call a function that
>>>> does precision floating point formatting on floats according to a user’s
>>>> wishes.  If the value is a list, call the function recursively with a list
>>>> comprehension, otherwise, call str.
>>>>
>>>>
>>>>
>>>> I think this is doable by mere humans.
>>>>
>>>>
>>>>
>>>> Thanks,
>>>>
>>>>
>>>>
>>>> John
>>>>
>>>>
>>>
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20231017/e45e3d4d/attachment-0001.html>


More information about the x3d-public mailing list