[x3d-public] X3DJSAIL org/web3d/x3d/jsail/HAnim/HAnimHumanoid.java returns void?

Don Brutzman brutzman at nps.edu
Sat Nov 21 00:39:48 PST 2020


1. General approach:  if you identify an example model and the valid XML, next step is to check the converted java.

that will be your preferred approach.

if you then compare alternative java source intended to do the same thing, i can tell you if that is a desirable approach.

in general, as with many libraries out there, typically there is a "best" (i.e. strictest) way to do things effectively.

* Don't repeat yourself (DRY) principle
   https://en.wikipedia.org/wiki/Don't_repeat_yourself

---

2. Looking at "public void setSegments(org.web3d.x3d.sai.Core.X3DNode" that is definitely not the method you want to use.

notice that the package "org.web3d.x3d.sai" is totally abstract and designed to match X3D Java Programming Language binding.

you will want to find the correct method that will be something like "public HAnimHumanoid setSegments(org.web3d.x3d.x3djsail.Core"

i looked in javadoc, there are two methods (for array[] and List, respectively) right where you might expect to find them:

* http://www.web3d.org/specifications/java/javadoc/index.html

* http://www.web3d.org/specifications/java/javadoc/org/web3d/x3d/jsail/HAnim/HAnimHumanoid.html

* http://www.web3d.org/specifications/java/javadoc/org/web3d/x3d/jsail/HAnim/HAnimHumanoid.html#setSegments(java.util.ArrayList)

* http://www.web3d.org/specifications/java/javadoc/org/web3d/x3d/jsail/HAnim/HAnimHumanoid.html#setSegments(org.web3d.x3d.sai.Core.X3DNode%5B%5D)

the first is preferred (you always want strong typing whenever possible), the second allows you to use a ProtoInstance object.

if you look around you will see similar methods for addSegments() clearSegments() getSegments() getSegmentsList() and hasSegments() so you can do pretty much whatever you want.

each method returns HAnimHumanoid so yes, you can to progressive calls on myHuman.setSegments(...).setSites(...) etc.  once again, the online converted examples show this.  each has self-validation checks so they pretty much all compile and run successfully, and you can be confident about the code patterns.

For example, excerpt follows (there are many of these in the HAnim example archives)

==========
https://www.web3d.org/x3d/content/examples/HumanoidAnimation/Characters/JinLOA1Index.html

https://www.web3d.org/x3d/content/examples/HumanoidAnimation/Characters/JinLOA1.java

// X3D, head/meta, Scene/HAnimHumanoid

     .addChild(new HAnimHumanoid("hanim_JinLOA1").setName("JinLOA1").setLoa(1).setScale(0.0225,0.0225,0.0225).setVersion("2.0")
       .setMetadata(new MetadataSet().setName("HAnimHumanoid.info").setReference("https://www.web3d.org/documents/specifications/19774/V2.0/Architecture/ObjectInterfaces.html#Humanoid")
         .setMetadata(new MetadataString().setName("authorName").setValue(new String[] {"Jin Hoon Lee and Min Joo Lee, Chul Hee Jung and Myeong Won Lee"}))
         .setMetadata(new MetadataString().setName("authorEmail").setValue(new String[] {"myeongwonlee at gmail.com"}))
         .setMetadata(new MetadataString().setName("creationDate").setValue(new String[] {"31 March 2011"}))
         .setMetadata(new MetadataString().setName("gender").setValue(new String[] {"female"}))
         .setMetadata(new MetadataString().setName("height").setValue(new String[] {"1.5"}))
         .setMetadata(new MetadataString().setName("humanoidVersion").setValue(new String[] {"2.0"})))
       .addSkeleton(new HAnimJoint("hanim_humanoid_root").setName("humanoid_root").setCenter(0.0,30.530001,-0.707600)
etc.
==========

3. hmmm, i see that the X3dToJava.xslt converter can be tightened up better.  note that the MetadataString invocations above are creating arrays for single-string values, that is unnecessary work.  for example,

         .setMetadata(new MetadataString().setName("creationDate").setValue(new String[] {"31 March 2011"}))

is much simpler as

         .setMetadata(new MetadataString().setName("creationDate").setValue("31 March 2011"))

that should work, perhaps i should update the converter to be simpler in that regard.  OTOH if an author wants to have MFString, it is much more mysterious... so maybe more-verbose String[] array syntax is best approach for autoconverter examples.

---

4. apologies for the "bleah" diagnostic comments in the autogenerated X3DJSAIL source, those help me track down the precise where autogenerated code is created.  that stylesheet is over a MB large already, we passed "nontrivial" a while ago.  as you can see, they have no impact on user functionality or documentation.  will try to clean those up in the next release build.

5. thank for asking John!  much appreciated, and everything gets a little better each time.  8)


On 11/19/2020 11:21 PM, John Carlson wrote:
> 
> 
> public void setSegments(org.web3d.x3d.sai.Core.X3DNode /* bleah 1 add node typing */  newValue)
> 
> returns void.
> 
> Would it be okay if it followed the lead of the other setSegments and return HAnimHumanoid? I've got a follow-on .setSites() which can't be called on a void value.
> 
> Was there prior discussion of this?
> 
> It should be possible for me to create an array.  Or I can probably call addSegments(), addSites().
> 
> They probably should be adds.  I use addJoints above.
> 
> This seems to be working, but there's still a lot of work to get the conversion stuff working in X3DJSONLD.
> 
> I will proceed with getting X3DJSONLD.js changes into x3dom and x_ite after testing X3DJSONLD index.html

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