[x3d-public] Strawman C++ example code

John Carlson yottzumm at gmail.com
Mon Aug 16 18:20:30 PDT 2021


Myeong, I appreciate your SAIExample1-4 that you developed for the 
standard, it helped me develop my examples. Your example code has 
something critical that I have not focused on yet.  That is, you can 
read an X3D file.  What I suggest we do next is create some C++ examples 
which can write an X3D XML example file from your C++ SAI library (just 
a few nodes), using toXMLString().  I don't think we should focus on 
rendering at this time, as we already have FreeWRL and perhaps other 
projects (Coin3D) which do a good job of rendering.

So perhaps it would be useful to look at a nearly complete example that 
would approach what I am talking about:

https://github.com/coderextreme/X3DJSONLD/blob/master/src/main/cplusplus/net/coderextreme/data/HelloWorld.cpp

I have looked at the SAI C++ examples you provided and created a 
HelloWorld.cpp which might be used for guiding for how we might develop 
C++ examples. It needs a toXMLString(), I know.

I have some questions:

* Should we use pointers, references or instances for passing to add and 
set methods?  My preference would be pointers.  I would be nervous about 
passing instances, because I don't know how to pass an instance of a 
class hierarchy (but you may know).  I don't know current C++ patterns 
for this. I do note that passing structs used to be a bad idea in C, though.

* Should we concern ourselves with the Builder Pattern, to make 
resultant instances immutable (See Dart Code Builder as an example)?  
This is also known as the Importer/Exporter Pattern.

* Should we try to preserve hand written-code, following Cameron 
Browne's class grammar approach with Ludii?

* Should we provide for method chaining (builder pattern again), so that 
that we reduce code size?  We will need add and set methods which return 
this.

Please review the C++ code provided and consider my questions to create 
library calls where we can programmatically build the example and export 
to XML. Our goal is to provide an XML file and just program enough of 
the library to convert the XML file into a scene+head graph.

First though, let's agree on HelloWorld.cpp example.  I can provide my 
CppSerializer.js or modify the X3dToJava.xslt to produce a C++ 
stylesheet later.  I do feel that I want to program at a higher level of 
abstraction, but that's not the primary purpose.  We already have XML 
Schema for that.

My example does NOT compile yet.  The goal of the example is to provide 
a "coding standard" for C++ SAI.  First off, I don't think we really 
want GL, GLU or GLUT in the example.   We want to make the C++ as 
declarative as we can, probably focusing on the builder pattern. We want 
to spend as little time focusing on webGL, webGPU, Vulkan, openGL, etc. 
as we can.  We will keep your examples though, let's not throw stuff away.

I cannot currently test your SAI Examples, because I am using Kubuntu.

John







More information about the x3d-public mailing list