[x3d-public] Thoughts for x3d.py str() calls
GPU Group
gpugroup at gmail.com
Mon Oct 16 09:48:52 PDT 2023
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' 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' 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/20231016/f4ef94a2/attachment.html>
More information about the x3d-public
mailing list