[x3d-public] Simple example of X3DConcreteNode/addChild problem

John Carlson yottzumm at gmail.com
Sat May 18 06:25:34 PDT 2019

Repost.  Sorry for the duplicate.

We may choose just to change the JavaMethod setIS, since that may limit the damage, but if want, we can also do setDEF

See italicized text below for next thing we can do.


Sent from Mail for Windows 10

From: John Carlson
Sent: Friday, May 17, 2019 1:06 AM
To: Brutzman, Donald (Don) (CIV); X3D Graphics public mailing list; aono at tut.jp
Subject: RE: Simple example of X3DConcreteNode/addChild problem


is the simplest example that throws an error. Simpler examples succeed.

I didn’t run the code with the nested transform.  I am not even sure it’s possible.

So if were’ not addressing addChild, then I think we must address setIS().

addChild could throw an exception in X3DConcreteNode.   IDK.   Just woke up pretty much.  I am pretty much ready to fall asleep again.

I have been leaving the Java solutions to you, because XSLT is painful.

I don’t believe the cast or wrap of the outer object is a good solution, because I think it may postpone the issue (we may have to cast for each set method, which I think would lead more code than the other “verbose” serializer).  But the idea seems sound, just verbose.

I am not addressing the setDEF problem because string wrappers solve it.  I am trying to address the problem that hasn’t been solved.  We can go back to solving more easier to address problems once the harder problems are solved.  If you think it’s the same pattern, I’m willing to put some effort in.

Addressing what’s returned from a JavaMethod in pyjnius is a good plan.   Great idea!

I am suspecting we could do something in this code in jnius_export_class.pxi, but it’s not compatible with most Java, we’d probably have to put some code with an extra predicate, something like and method_name starts with “set”
        elif r == 'L':
            with nogil:
                j_object = j_env[0].CallObjectMethodA(
                        j_env, j_self, self.j_method, j_args)
            if j_object != NULL:
                ret = convert_jobject_to_python(
                        j_env, self.definition_return, j_object)
                j_env[0].DeleteLocalRef(j_env, j_object)

and set ret to self, I guess.  Not really that sure.

If you think this is a good thing to pursue, I will look into it

I will wait until you have the word on setDEF.



Sent from Mail for Windows 10

From: Brutzman, Donald (Don) (CIV)
Sent: Thursday, May 16, 2019 5:38 AM
To: John Carlson; X3D Graphics public mailing list; aono at tut.jp
Subject: Re: Simple example of X3DConcreteNode/addChild problem

Hi John.  Thanks for continued sleuthing.

1. Chasing addChild() is probably not a good path forward however.

The addChild() method cannot be added to X3DConcreteNode because then any X3D node would be able to add a child node.  That obviously breaks the parent-child hierarchy restrictions of XxD scene graph.

As an example: all nodes can add a single MetadataFloat child, and (as you note) IS node (for IS/connect links within a ProtoBody).  However nodes like Material cannot add any other child nodes, since those are not part of the allowed X3D scene graph.

This strictness is part of the fundamental value of X3D structural validity.  It is similarly enforced by validation techniques such as XML Schema, JSON schema, XML DTD, XML Schematron, and X3DUOM.

I suspect that the error you are seeing from


matching (commented) legal subgraph

       <IS><!-- needs a connect statement--></IS>

is actually quite similar in nature to the other flawed (misdirecting) pyjnius errors we've been seeing with ViewpointObject, most recently re-diagnosed as a setDEF() problem.

Any time pyjnius says that it has a problem with X3DConcreteNode there is a problem in the matching of the .py python source to underlying X3DJSAIL classes.

Give me a chance to go further on the setDEF() problem.  Once that is resolvable, it will be similarly applied to USE and IS since all three are part of X3DConcreteNode.

"Abstract parent class for concrete X3D nodes, containing common methods and member variables."

Am currently looking at two potential paths for solution:

a. possibly omit DEF, USE from org.web3d.x3d.sai.Navigation.Viewpoint interface (still questionable)
b. get pyjnius to return class current object when returning from methods, rather than a superclass or interface (root cause of problem)

Summary: don't worry about "addChild()" since the root problem is elsewhere.

2. @Override annotation will never "work" because it has no action.  It is a Java compiler-related note that helps warnings ensure that programmer Object-oriented design intentions are met.

3. Great to hear that you are making some strides with Jupyter.  Recommend using an even-simpler example that current works, perhaps HelloTriangle.


p.s. looks like some of the online .py files didn't get updated, will recheck the build process.  Example attached.

On 5/14/2019 9:33 AM, John Carlson wrote:
> Example of error generated below.  (minimal amount of code) Jupyter export attached.  I hope you can address the issue sometime with X3DJSAIL.  My best guess is that pyjnius is going through getSuperclass() and finding the abstract classes’ method setIS().  We can try deleting getSuperclass call in pyjnius if you think it’s appropriate.
> My suggestion is to delete setIS from X3DConcreteNode.java or implement addChild in X3DConcreteNode.java, which may just cascade the error.  I think deleting setIS might be preferable, but test both cases.   Consider a wrapping, like:
> Transform(Transform().setIS(IS())).addChild(Shape())  # hasn’t been tested, but ew.
> A jnius.cast would work similarly.  We can go with a cast if you like.  Please look into a cast to see what you prefer.  Also, try converting to Java.
> Now do you see where the abstract class is coming from?  Do you agree on what’s introducing the abstract class (not me)?
> Good news is, I and Michael figured out how to run the code in Jupyter Lab (anaconda).  There are instructions online that work with the conda.bat command install jnius (see conda install on pyjnius website)  WooHoo! Highly recommended, but a bit stilted to start with.
> Code is back to you! Looking for changes to X3DConcreteNode.java.  I can make changes to the serializer if we decide wrapping or casting is appropriate.  I just think we’ll be wrapping the wrapping the wrapping.  It seems better to me to add or delete abstract methods.
> No, I don’t know why @Override didn’t work.
> # This code shows the error
> import jnius_config
> jnius_config.set_classpath('.', 'c:/x3d-code/www.web3d.org/x3d/stylesheets/java/jars/X3DJSAIL.3.3.full.jar')
> from jnius import autoclass
> Shape = autoclass('org.web3d.x3d.jsail.Shape.ShapeObject')
> Transform = autoclass('org.web3d.x3d.jsail.Grouping.TransformObject')
> IS = autoclass('org.web3d.x3d.jsail.Core.ISObject')
> Transform().setIS(IS()).addChild(Shape())
> *-------------------------------------------------------------------------*
> *AttributeError*                            Traceback (most recent call last)
> *<ipython-input-1-62dabff95a4e>*in <module>
>        8
>        9
> *---> 10***Transform*().*setIS*(*IS*()).*addChild*(*Shape*())*
> *AttributeError*: 'org.web3d.x3d.jsail.X3DConcreteNode' object has no attribute 'addChild'

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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20190518/9dff4ff5/attachment-0001.html>

More information about the x3d-public mailing list