[x3d-public] x3d.py roundtrip for Metadata nodes in v.3.3 and v.4.0
Andreas Plesch
andreasplesch at gmail.com
Tue Oct 31 12:49:50 PDT 2023
Notes:
x3d.py is autogenerated from X3DUOM:
https://www.web3d.org/x3d/stylesheets/python/python.html#autogeneration
https://sourceforge.net/p/x3d/code/HEAD/tree/www.web3d.org/x3d/stylesheets/X3duomToX3dPythonPackage.xslt
X3DUOM has all necessary containerField default value information.
But the first step may be to modify the stylesheet to generate
containerField attributes for all nodes, for simplicity. It looks like
the .XML() function would have to have an additional parameter 'field'
X3D(indentLevel, syntax, field) for each node.
Postprocessing the generated XML is not possible since information was
irretrievably lost. But postprocessing the autogenerated x3d.py python
code may be possible since xslt is not for everyone.
-Andreas
On Tue, Oct 31, 2023 at 2:10 PM John Carlson <yottzumm at gmail.com> wrote:
>
> Thank you Andreas for bringing this up. x3d.py as of last night, did not output any containerFields.
>
> I don’t think that putting containerFields everywhere is the right solution. It would be great if x3d.py could figure out what containerField field to use, like for HAnimHumanoid's skeleton, skin fields, and joints/segments/sites fields. Right now, x3d.py prevents the user from specifying any containerFields, because x3d.py controls pretty much all output. My idea was to pass an optional containerField to an XML method, but since ix3d.py is created with a stylesheet, this will affect many XML methods potentially, so this will need to be controlled carefully.
>
> I have a lot of related experience trying to get containerField right for X3DJSONLD/X3DJSAIL when creating DOM from JSON in https://github.com/coderextreme/x3dschema/blob/main/X3DJSONLD.java. Here's my current results. More logic probably needs to be added for the skin fields
>
> public Element CreateElement(Document document, String key, String containerField) {
> Element child = document.createElement(key);
> if (containerField != null &&
> ((containerField.equals("geometry") && key.equals("IndexedFaceSet")) ||
> (containerField.equals("geometry") && key.equals("Text")) ||
> (containerField.equals("geometry") && key.equals("IndexedTriangleSet")) ||
> (containerField.equals("geometry") && key.equals("Sphere")) ||
> (containerField.equals("geometry") && key.equals("Cylinder")) ||
> (containerField.equals("geometry") && key.equals("Cone")) ||
> (containerField.equals("geometry") && key.equals("LineSet")) ||
> (containerField.equals("geometry") && key.equals("IndexedLineSet")) ||
> (containerField.equals("geometry") && key.equals("Box")) ||
> (containerField.equals("geometry") && key.equals("Extrusion")) ||
> (containerField.equals("geometry") && key.equals("GeoElevationGrid")) ||
> (containerField.equals("shape") && key.equals("Shape")) ||
> (containerField.equals("skin") && key.equals("Shape")) ||
> (containerField.endsWith("exture") && key.equals("ImageTexture")) ||
> (key.equals("HAnimSegment")) ||
> (key.equals("HAnimSite")) ||
> (key.equals("HAnimMotion")) ||
> (containerField.equals("skinCoord") && key.equals("Coordinate")) || // overwrite coord with skinCoord, if set
> (containerField.equals("skin") && key.equals("IndexedFaceSet")) ||
> ((containerField.equals("skinBindingCoords") || containerField.equals("skinCoord")) && key.equals("Coordinate")) ||
> ((containerField.equals("normal") || containerField.equals("skinBindingNormals") || containerField.equals("skinNormal")) && key.equals("Normal")) ||
> ((containerField.equals("skeleton") || containerField.equals("children") || containerField.equals("joints")) && key.equals("HAnimJoint"))
> )) {
> elementSetAttribute(child, "containerField", containerField);
> }
> return child;
> }
>
> if ((containerField == null || containerField.equals("children")) && parentkey.equals("HAnimJoint") && element.getTagName().equals("HAnimHumanoid")) {
> containerField = "joints";
> }
> if ((containerField == null || containerField.equals("coord")) && parentkey.equals("Coordinate") && element.getTagName().equals("HAnimHumanoid")) {
> containerField = "skinCoord";
> }
> child = CreateElement(document, parentkey, containerField);
>
>
> I don't know if something similar could be added for x3d.py or whether x3d.py can be sufficiently tested. I am willing to put in effort to run code output from X3dToPython.xslt in the archive, which I know no one else wants to do. But someone else will have to go through possibly the tons of output from tovrmlx3d that is created. My recommendation is to do onesies-twosies as Don suggested and likes. I will try to set up a testing framework with a modified X3dToPython.xslt. This will take away from my WS work.
>
> On Tue, Oct 31, 2023 at 12:21 PM Andreas Plesch <andreasplesch at gmail.com> wrote:
>>
>> x3d.py may not quite manage a roundtrip back to XML for MetadataSet.
>>
>> https://www.web3d.org/x3d/content/examples/X3dForWebAuthors/Chapter01TechnicalOverview/EmptySceneCoreProfileIndex.html
>>
>> has the model in XML encoding:
>>
>> ..
>> <Scene>
>> <!-- Core profile can only contain WorldInfo and Metadata nodes. here!!! -->
>> <WorldInfo title='EmptySceneCoreProfile.x3d'/>
>> <WorldInfo title='EmptySceneCoreProfile.x3d'>
>> <MetadataSet name='NodeSet' containerField='metadata'>
>> <MetadataBoolean containerField='value' name='BooleanData'
>> value='true false'/>
>> <MetadataDouble containerField='value' name='DoubleData' value='1 2 3'/>
>> <MetadataFloat containerField='value' name='FloatData' value='4 5 6'/>
>> <MetadataInteger containerField='value' name='IntegerData' value='7 8 9'/>
>> <MetadataString containerField='value' name='StringData'
>> value='"Empty Scene" "Core Profile"'/>
>> </MetadataSet>
>> </WorldInfo>
>> </Scene>
>> ...
>>
>> Running https://www.web3d.org/x3d/content/examples/X3dForWebAuthors/Chapter01TechnicalOverview/EmptySceneCoreProfile.py
>>
>> with the latest x3d.py confirms well formedness of the .XML() output.
>>
>> Uncommenting the diagnostic line to print the XML output gives this XML:
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.3//EN"
>> "https://www.web3d.org/specifications/x3d-3.3.dtd">
>> <X3D profile='Core' version='3.3'
>> xmlns:xsd='http://www.w3.org/2001/XMLSchema-instance'
>> xsd:noNamespaceSchemaLocation='https://www.web3d.org/specifications/x3d-3.3.xsd'>
>> <head>
>> ...
>> </head>
>> <Scene>
>> <WorldInfo title='EmptySceneCoreProfile.x3d'/>
>> <WorldInfo title='EmptySceneCoreProfile.x3d'>
>> <MetadataSet name='NodeSet'>
>> <MetadataBoolean name='BooleanData' value='true false'/>
>> <MetadataDouble name='DoubleData' value='1 2 3'/>
>> <MetadataFloat name='FloatData' value='4 5 6'/>
>> <MetadataInteger name='IntegerData' value='7 8 9'/>
>> <MetadataString name='StringData' value='"Empty Scene" "Core Profile"'/>
>> </MetadataSet>
>> </WorldInfo>
>> </Scene>
>> </X3D>
>>
>> The Metadata containerField attributes of the original XML encoding
>> were omitted. This is ok for most Metadata nodes since the default
>> containerField value is 'value'.
>>
>> https://www.web3d.org/specifications/X3dSchemaDocumentation4.0/x3d-4.0_MetadataSet.html#Link561
>> defines the default value for the MetadataSet containerField attribute
>> also as 'value'. However, in the example the containerField attribute
>> value for the MetadataSet node needs to be 'metadata' and not 'value',
>> in the x3d.py generated XML.
>>
>> I believe this may be an example of what John encountered.
>>
>> One option for x3d.py may be to generate containerField attributes for
>> all nodes since x3d.py will know the field name for which a node is
>> the value. Perhaps it suffices to do this for all nodes where the
>> containerField attribute value would not be 'children'. It may not be
>> practical to embed the containerField default values for all nodes in
>> the x3d.py source.
>>
>> I just noticed that x3d.py explicitly generates X3D 3.3 xml output.
>> The above only applies to X3D 4.0. However, the same issue persists in
>> a flipped way with X3D 3.3 which has 'metadata' as default
>> containerField value for Metadata nodes. This means in the x3d.py
>> generated output all Metadata nodes except for MetadataSet would need
>> an explicit containerField value of 'value'.
>>
>> -Andreas
>> --
>> Andreas Plesch
>> Waltham, MA 02453
>>
>> _______________________________________________
>> x3d-public mailing list
>> x3d-public at web3d.org
>> http://web3d.org/mailman/listinfo/x3d-public_web3d.org
--
Andreas Plesch
Waltham, MA 02453
More information about the x3d-public
mailing list