Open Inventor Release 2024.2.0
 
Loading...
Searching...
No Matches
Specifying Part Names

Suppose you have created the three node-kit classes shown in Three Node-Kit Classes for Making “Goons” (see Creating a Node Kit for information on how to subclass node kits):

  • An SoGoonKit, which defines the complete creature, a goon. This goon consists of an SoAppearanceKit, two instances of SoLegKit for leg1 and leg2, and an SoCone for body.
  • An SoLegKit, which defines a leg for a goon. This class contains an SoAppearanceKit, an SoFootKit, and an SoCylinder for thigh.
  • An SoFootKit, which defines a foot for a goon. This class contains an SoAppearanceKit, an SoCube for toe1, and an SoCube for toe2. After creating an instance of SoGoonKit (myGoon), you can be very specific when asking for the parts. For example:

C++ :

myCube = SO_GET_PART( myGoon, "toe1", SoCube );

C# :

myCube = ( SoCube )myGoon.GetPart( "toe1", true );

Java :

myCube = ( SoCube )myGoon.getPart( "toe1", true );

first looks in the catalog of myGoon for toe1. If it doesn't find toe1 and some children in the catalog are node kits, it looks inside the leaf node kits for toe1 and uses the first match it finds. Here, the match would be found in the foot of leg1. But what if you really want toe1 in leg2? In that case, you may specify:

C++ :

myCube = SO_GET_PART( myGoon, "leg2.toe1", SoCube );

C# :

myCube = ( SoCube )myGoon.GetPart( "leg2.toe1", true );

Java :

myCube = ( SoCube )myGoon.getPart( "leg2.toe1", true );

which returns toe1 in leg2. This is equivalent to leg2.foot.toe1.

You can also refer to parts by indexing into any part that is defined as a list in the catalog—for example, “childList[0]” or “callbackList[2].”

The following excerpts illustrate three different ways to create node-kit parts and set their values. These excerpts assume you have subclassed to create your own class, derived from SoBaseKit, an SoGoonKit (see Creating a Node Kit). This goon has a body, legs, and feet, as described earlier.

This fragment shows setting each part individually:

C++ :

SoGoonKit* myGoon = new SoGoonKit();
myGoon->set( "body.material", "diffuseColor [1 0 0 ]" );
// makes body red
myGoon->set( "leg2.toe1", "width 2 height 3 depth 1" );
// creates toe with proper dimensions

C# :

SoGoonKit myGoon = new SoGoonKit();
myGoon.Set( "body.material", "diffuseColor [1 0 0 ]" );
// makes body red
myGoon.Set( "leg2.toe1", "width 2 height 3 depth 1" );
// creates toe with proper dimensions

**Java : **

SoGoonKit myGoon = new SoGoonKit();
myGoon.set("body.material", "diffuseColor [1 0 0 ]");
// makes body red
myGoon.set("leg2.toe1", "width 2 height 3 depth 1");
// creates toe with proper dimensions*

Three Node-Kit Classes for Making “Goons”

This fragment shows getting parts and editing them :

**C++ : **

SoGoonKit *myGoon = new SoGoonKit();
SoMaterial *bodyMtl;
SoCube *toe;
bodyMtl = SO_GET_PART(myGoon, "body.material", SoMaterial);
bodyMtl->diffuseColor.setValue(1, 0, 0);
toe = SO_GET_PART(myGoon, "leg2.toe1", SoCube);
toe->width.setValue(2);
toe->height.setValue(3);
toe->depth.setValue(1);

**C # : **

SoGoonKit myGoon = new SoGoonKit();
SoMaterial bodyMtl = new SoMaterial();
SoCube toe = new SoCube();
bodyMtl = (SoMaterial)myGoon.GetPart("body.material", true);
bodyMtl.diffuseColor.SetValue(1f, 0f, 0f);
toe = (SoCube)myGoon.GetPart("leg2.toe1", true);
toe.width.alue = 2f;
toe.height.Value = 3f;
toe.depth.Value = 1f;

**Java : **

SoGoonKit myGoon = new SoGoonKit();
SoMaterial bodyMtl = new SoMaterial();
SoCube toe = new SoCube();
bodyMtl = (SoMaterial)myGoon.getPart("body.material", true);
bodyMtl.diffuseColor.setValue(1f, 0f, 0f);
toe = (SoCube)myGoon.getPart("leg2.toe1", true);
toe.width.setValue(2f);
toe.height.setValue(3f);
toe.depth.setValue(1f);

This fragment shows setting both parts in one command :

**C++ : **

SoGoonKit *myGoon = new SoGoonKit();
myGoon->set("body.material { diffuseColor [ 1 0 0 ] }
leg2.toe1 { width 2
height 3
depth 1 }");

**C # : **

SoGoonKit myGoon = new SoGoonKit();
myGoon.Set("body.material { diffuseColor [ 1 0 0 ] }" +
"leg2.toe1 #160{ width 2" +
"height 3" +
"depth 1 }");

**Java : **

SoGoonKit myGoon = new SoGoonKit();
myGoon.set("body.material { diffuseColor [ 1 0 0 ] }" +
"leg2.toe1 #160{ width 2" +
"height 3" +
"depth 1 }");