[x3d-public] file converter based on pythonocc: x3d.py toXML()

Don Brutzman brutzman at nps.edu
Sun Apr 19 11:33:45 PDT 2020


John thanks for checking that x3d.py includes preliminary toXML() support.

I will update the TODO status as we progress.
* https://www.web3d.org/x3d/stylesheets/python/python.html#TODO

On 4/18/2020 6:47 PM, John Carlson wrote:
> [...]
> Otherwise, you probably have to wait for enhancements to x3d.py.  It looks like toXML is supported in x3d.py currently.  One could use a stylesheet X3dToPython.xslt to convert XML to Python.
> [...]

> On Sat, Apr 18, 2020 at 5:20 PM Andreas Plesch <andreasplesch at gmail.com <mailto:andreasplesch at gmail.com>> wrote:
> 
>     Thanks for the interest. I initialized a project at
> 
>     https://github.com/andreasplesch/OCCToX3D
> 
>     The wiki has some collected info and a short outline. The wiki is
>     editable by anyone.
> 
>     pythonocc has a method to generate X3D xml. It is a simple Shape with
>     a TriangleSet, nothing sophisticated. If x3d.py would have  a
>     createX3DFromString() function, it would be possible to use x3d.py to
>     enhance the generated X3D. But I do not think x3d.py has that. But
>     x3d.py may come in handy in other ways.

Super.  There is an ultra-simple example in the current build tests:

[3] X3DPSAIL build examples output

===================================================================
https://www.web3d.org/x3d/stylesheets/python/build.examples.log.txt
[...]
     modelTest     = X3D(head=head(children=[component(level=2,name='Grouping'), meta(content='name-value pair',name='description'), meta(content='diagnostic test 1',name='info'), meta(content='diagnostic test 2',name='hint'), meta(content='diagnostic test 3',name='warning'), meta(content='diagnostic test 4',name='error')]),Scene=Scene(children=[WorldInfo(title='modelTest sample scene'), Group()]))
str(modelTest)    = X3D(head=head(children=[component(level=2,name='Grouping'), meta(content='name-value pair',name='description'), meta(content='diagnostic test 1',name='info'), meta(content='diagnostic test 2',name='hint'), meta(content='diagnostic test 3',name='warning'), meta(content='diagnostic test 4',name='error')]),Scene=Scene(children=[WorldInfo(title='modelTest sample scene'), Group()])) (should match)
     modelTest.toXML() =
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 4.0//EN" "http://www.web3d.org/specifications/x3d-4.0.dtd">
<X3D profile='Immersive' version='4.0' xmlns:xsd='http://www.w3.org/2001/XMLSchema-instance' xsd:noNamespaceSchemaLocation='http://www.web3d.org/specifications/x3d-4.0.xsd'>
   <head>
     <component level='2' name='Grouping'/>
     <meta content='name-value pair' name='description'/>
     <meta content='diagnostic test 1' name='info'/>
     <meta content='diagnostic test 2' name='hint'/>
     <meta content='diagnostic test 3' name='warning'/>
     <meta content='diagnostic test 4' name='error'/>
   </head>
   <Scene>
     <WorldInfo title='modelTest sample scene'/>
     <Group/>
   </Scene>
</X3D>

Current work:
DONE value range checks for simple types
TEST save toXML() .x3d recursive serializer
TODO save toClassicVRML() .x3dv
TODO check node types when building scene graph
TODO add and invoke validation methods that walk model tree
===================================================================

Key status message there is "TEST save toXML() .x3d recursive serializer"

Just inspected a number of classes in x3d.py and indeed it looks like the pattern is place.

Suggest someone tries it, given the preceding simple example it should work.  Hope so!

Bug reports are typically fixed easily since these are autogeneration code patterns that get tuned, not the x3d.py source itself.

When I have a day or two available for dedicated work on this, I will add
- round-trip unit testing of toXML() in X3D Examples testing
- add toClassicVRML() toVRML97() toJSON() and related utility methods

Recommendation: you can count on x3d.py providing these kinds of capabilities (just as X3DJSAIL does) in concert with X3DUOM rigor.  No need to reinvent a class hierarchy for conversion.

Please also be aware that there are thousands of example models in X3D Example Archives showing x3d.py syntax.  John Carlson, Loren Peitso and I worked for a long time to make them as Pythonic as possible.

[4]	X3D Resources, Examples: Scene Archives for X3D
	https://www.web3d.org/x3d/content/examples/X3dResources.html#Examples

for instance

[5]	Hello World
	https://x3dgraphics.com/examples/X3dForWebAuthors/Chapter01TechnicalOverview/HelloWorldIndex.html
	https://x3dgraphics.com/examples/X3dForWebAuthors/Chapter01TechnicalOverview/HelloWorld.py

>     The first goal is to add a simple jupyter notebook to the repo based
>     on the available pythonocc docker image which demonstrate how to load
>     step and output X3D.

sounds useful, thanks!

>     Any feedback or ideas welcome, using Issues on the project or here,
> 
>     -Andreas
> 
> 
>     On Sat, Apr 18, 2020 at 1:27 PM Don Brutzman <brutzman at nps.edu <mailto:brutzman at nps.edu>> wrote:
>      >
>      > Hi Andreas, sounds like a great idea to me.  Here are some peripheral points of support.
>      >
>      > Last weekend i updated and deployed the x3d.py package (sometimes called X3DPSAIL) at
>      >
>      > [1]     Python Package Index (PyPi) x3d 0.0.25
>      >         Package support for Extensible 3D (X3D) Graphics International Standard (IS)
>      > https://pypi.org/project/x3d/
>      >
>      > [2]     Python X3D Package x3d.py,X3D Python Scene Access Interface Library (X3DPSAIL)
>      > https://www.web3d.org/x3d/stylesheets/python/python.html
>      >
>      > "The x3d.py Python X3D Package supports programmers with Python interfaces and objects for standards-based X3D programming, all as open source.
>      > The presentation *Python X3D Package Implementation* provides an overview and shows examples."
>      >
>      > [2.1]   Python X3D Package Implementation
>      > https://www.web3d.org/x3d/stylesheets/python/documents/PythonX3dPackageImplementation.pdf
>      >
>      > So you would use this library for model creation and data-driven improvement, no need to reinvent X3D data structures or methods.
>      >
>      > This is autogenerated from X3DUOM so it will always stay in sync with latest/greatest X3D4.
>      >
>      > We've done some preliminary work with Jupyter notebook, listed there.  Lots of potential projects in TODO section.
>      >
>      > [2.2]   X3DPSAIL: Jupyter notebook, TODO
>      > https://www.web3d.org/x3d/stylesheets/python/python.html#Jupyter
>      > https://www.web3d.org/x3d/stylesheets/python/python.html#TODO
>      >
>      > For pythonocc conversion efforts, will be happy to ensure that
>      > a. all improvements to API are applied,
>      > b. ensure that validation of all scene-graph inputs remains rigorous,
>      > b. utility methods are added for easy use together,
>      > d. examplar conversion models are properly saved in X3D Examples Archive,
>      > e. Whatever else!
>      >
>      > Looks like there is vast potential here.  Hoping folks start picking it up and applying capabilities.
>      >
>      > Have fun with X3D Python!  8)
>      >
>      >
>      > On 4/17/2020 5:15 PM, Andreas Plesch wrote:
>      > > Did somebody put together an x3d converter based on pythonocc ?
>      > >
>      > > Here is an example:
>      > >
>      > > https://senties-martinelli.com/software/cad-viewer
>      > >
>      > > It could convert  step, stp, igs, iges, obj and stl formats. Format
>      > > import and export is only a small subset of pythonocc
>      > > (https://github.com/tpaviot/pythonocc-core) but I think just making
>      > > this functionality easy to use with a dedicated converter could be
>      > > really valuable.
>      > >
>      > > In the end, I think a  web service just for conversion would be most useful.
>      > >
>      > > I played with the Jupyter notebook and could generate with only a few lines x3d.
>      > >
>      > > And there are ways to generate a standalone webapp from a notebook:
>      > > https://discourse.jupyter.org/t/how-to-transform-a-jupyter-notebook-into-a-webapp/758/6
>      > >
>      > > That could be quick way to offer a web service.
>      > >
>      > > Have there been attempts of this kind ? Would there be interest in a
>      > > open source github hosted project ?
>      > >
>      > > -Andreas
>      >
>      > 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 http://faculty.nps.edu/brutzman
> 
> 
> 
>     -- 
>     Andreas Plesch
>     Waltham, MA 02453
> 
>     _______________________________________________
>     x3d-public mailing list
>     x3d-public at web3d.org <mailto:x3d-public at web3d.org>
>     http://web3d.org/mailman/listinfo/x3d-public_web3d.org
> 

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 http://faculty.nps.edu/brutzman



More information about the x3d-public mailing list