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

Joe D Williams joedwil at earthlink.net
Mon Oct 16 20:25:36 PDT 2023


> How can I add one Coordinate to both skin coord (in IFS, etc) and skinCoord in SAI?    Check the spec. I think you can't add just one SF at the beginning, end, or middle of MF. For MF fields you must get or set the complete field. SAI Field services.
https://www.web3d.org/documents/specifications/19777-1/V3.0/index.html

https://www.web3d.org/documents/specifications/19775-2/V3.0/index.html

https://www.web3d.org/documents/specifications/19775-2/V3.0/Part02/servRef.html


Joe
-----Original Message-----
From: John Carlson <yottzumm at gmail.com>
Sent: Oct 16, 2023 7:50 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

We didn’t invent append.  Just like addChild was added to X3DJSAIL, there are features in Python to support the real programming.  There are differences between encodings and bindings.  I would have written a different example than Doug, but using his was facile.
 
If you’re just converting from XML, you can play tricks like producing a whole scene in one variable.  Regular programming involves stuff like append and addChild.  Normally, to satisfy x3d.py, I collect all children in a list, and set children.  I can provide an example of that, if you wish, but would it help the situation?
 
How do i add the same Transform to two Groups in SAI?   Not in an encoding.
 
Ignoring all that,
 
How can I add one Coordinate to both skin coord (in IFS, etc) and skinCoord in SAI?  Not in an encoding.
 
John

On Mon, Oct 16, 2023 at 8:52 PM John Carlson <yottzumm at gmail.com (mailto:yottzumm at gmail.com)> wrote:
Joe, we have been discussing X3DPSAIL (x3d.py).
 
I don’t know if it’s SAI or not because there’s no Python SAI that I know of.
 
John

On Mon, Oct 16, 2023 at 8:27 PM Joe D Williams <joedwil at earthlink.net (mailto:joedwil at earthlink.net)> wrote:
> Is the author doing the wrong thing?How can you tell right or wrong from that example? If building a scene, why not use X3D SAI features. If you are simply inventing away to build good user code, then this should fail. In general, why invent an append, and what is this supposed to append. Please check x3d SAI for this type of functionality.trans = Transform(DEF='C')  # probably need to set other fields
grpb.children.append(Transform(DEF='D' USE='C')
grpa.children.append(Transform(DEF='E' USE='C')

or something, but look at SAI for this kind of stuff

Joe-----Original Message-----
From: John Carlson <yottzumm at gmail.com (mailto:yottzumm at gmail.com)>
Sent: Oct 16, 2023 5:41 PM
To: Joe D Williams <joedwil at earthlink.net (mailto:joedwil at earthlink.net)>
Cc: Brutzman Donald (Don) (CIV) <brutzman at nps.edu (mailto:brutzman at nps.edu)>, GPU Group <gpugroup at gmail.com (mailto:gpugroup at gmail.com)>, Peitso Loren (CIV) <lepeitso at nps.edu (mailto:lepeitso at nps.edu)>, X3D Graphics public mailing list <x3d-public at web3d.org (mailto:x3d-public at web3d.org)>
Subject: Re: Thoughts for x3d.py str() calls

Here’s a python example from Doug:
 
 
trans = Transform(DEF='C')
grpb.children.append(trans)
grpa.children.append(trans)


Is the author doing the wrong thing?
 
John 

On Mon, Oct 16, 2023 at 7:37 PM John Carlson <yottzumm at gmail.com (mailto:yottzumm at gmail.com)> wrote:
If we keep a reference around to place in both skin coordinate and skinCoord, will x3d.py be smart enough to output DEF in the first case and USE in the second case, or will it just output whatever DEF or USE is currently stored for the node?  Will it gladly print out both USE and DEF plus all the fields along with USE and DEF?  A simple python example would use a a reference more than once.  I don’t have that yet, but it should be easy to create one.
 
No, I don’t want to override the str function, because my new function will use it.

On Mon, Oct 16, 2023 at 5:32 PM Joe D Williams <joedwil at earthlink.net (mailto:joedwil at earthlink.net)> wrote:
I don't know if this helps, but just from memory, every loader I have ever seen that deep into will assign a unique def if a DEFable field does not have a DEF. I think a DEF always helps the runtime. The SAI can discover the assignment if you need it.   

Joe


-----Original Message-----
From: GPU Group <gpugroup at gmail.com (mailto:gpugroup at gmail.com)>
Sent: Oct 16, 2023 2:36 PM
To: Brutzman, Donald (Don) (CIV) <brutzman at nps.edu (mailto:brutzman at nps.edu)>
Cc: John Carlson <yottzumm at gmail.com (mailto:yottzumm at gmail.com)>, Joe D Williams <joedwil at earthlink.net (mailto:joedwil at earthlink.net)>, Peitso, Loren (CIV) <lepeitso at nps.edu (mailto:lepeitso at nps.edu)>, X3D Graphics public mailing list <x3d-public at web3d.org (mailto:x3d-public at web3d.org)>
Subject: Re: Thoughts for x3d.py str() calls

Don,Q1. Do you acknowledge x3d.py makes no attempt to conjugate DEF and USE of the same name?
Q2. Do you acknowledge some nodes in x3d can have multiple fields using the same node?
Q3. Do you acknowledge x3d.py controls the order fields of a node are exported?
Q4. Do you acknowledge there may be use-cases when a script using x3d.py will instance DEF and USE x3d.py nodes of the same name in a different order than x3d.py may export?
In HAnimHumanoid 2 fields take the same Coordinate node: a) .coordinate b) .skin (in descendent nodes)
The blender exporter traverses the blender scenegraph in a systematic order convenient to that script. The first time it encounters the Coordinate node it instances an x3d.py Coordinate node with a DEF. The subsequent times it encounters the same node it instances an x3d.py node with a USE of the same name.
x3d.py exports the HAnimHumanoid.coordinate field before .skin. That's a different order than the user script visits blender nodes.
That 2-field-same-node scenario may not occur frequently in web3d, or a using-script may be lucky in its case to instance the DEF and USE in the same order as x3d.py happens to export. So many successful Examples don't help this case.
-Doug
 


On Mon, Oct 16, 2023 at 2:47 PM Brutzman, Donald (Don) (CIV) <brutzman at nps.edu (mailto: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 (mailto: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 (mailto:gpugroup at gmail.com)> 
Sent: Monday, October 16, 2023 9:49 AM
To: John Carlson <yottzumm at gmail.com (mailto:yottzumm at gmail.com)>
Cc: Brutzman, Donald (Don) (CIV) <brutzman at nps.edu (mailto:brutzman at nps.edu)>; Joe D Williams <joedwil at earthlink.net (mailto:joedwil at earthlink.net)>; Peitso, Loren (CIV) <lepeitso at nps.edu (mailto:lepeitso at nps.edu)>; X3D Graphics public mailing list <x3d-public at web3d.org (mailto: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 (mailto: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='' xsd:noNamespaceSchemaLocation='https://www.web3d.org/specifications/x3d-4.0.xsd (https://nam10.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.w3.org%2F2001%2FXMLSchema-instance&data=05%7C01%7Cbrutzman%40nps.edu%7C5c09532fc6784acf636108dbce67ceb2%7C6d936231a51740ea9199f7578963378e%7C0%7C0%7C638330717470356414%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=yglIKBZsT6BoJS9%2BDnaKptd%2FEdy4pnjHp4KFFEuFFLQ%3D&reserved=0)'>

  <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='' xsd:noNamespaceSchemaLocation='https://www.web3d.org/specifications/x3d-4.0.xsd (https://nam10.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.w3.org%2F2001%2FXMLSchema-instance&data=05%7C01%7Cbrutzman%40nps.edu%7C5c09532fc6784acf636108dbce67ceb2%7C6d936231a51740ea9199f7578963378e%7C0%7C0%7C638330717470512654%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=C1CiwnRN22BrRL7097t92ojvanIkKyb8xlQeolJXaGc%3D&reserved=0)'>

  <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 (mailto: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 (mailto: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/ab01909b/attachment-0001.html>


More information about the x3d-public mailing list