Adding same SoNode several times screws up Material...

Adding same SoNode several times screws up Material...

Post by Christopher Oezbe » Mon, 12 May 2003 20:18:29



Hello,
  I have a problem that adding the same node several times in a row changes
the way the SoMaterial node influences the Object. I have the following
layout

SoSeparator
|->red Material
|->object
.
.
. |->object
|->glass Material
|->object
.
.
.
\->object

It's always the same object/node (encapsulated in a SoSeparator Node). The
Problem is, that as soon as I add more than one object with redMaterial all
glass Objects are screwed up. They display much brighter than they should.
If I reload the object from file and use it separately for the glass
Objects everything works fine. I'm sorry that I can't provide a screenshot,
but Gimp refuses to take one.

Did I miss some important fact about lighting? Any culmulative effects? I'm
sure I checked carefully from docu and net, but couldn't find any clues
about this problem.

I'm using Open Inventor from SGI (2.1) under Linux.

Thanks a lot for your help,
  Christopher

This is the source code:

  SoSeparator *hearts = new SoSeparator();
  // Red Hearts
  SoSeparator *redHeart = readFile("heart.iv");
  SoMaterial *redMaterial = new SoMaterial();
  redMaterial->ambientColor.setValue(0.0, 0.0, 0.0);
  redMaterial->diffuseColor.setValue(0.5, 0.0, 0.0);
  redMaterial->specularColor.setValue(0.3, 0.0, 0.0);
  redMaterial->emissiveColor.setValue(0.0, 0.0, 0.0);
  redMaterial->shininess = 0.7;

  // Glass Hearts
  SoSeparator *glassHeart = readFile("heart.iv");    // I don't want to
load twice
  SoMaterial *glassMaterial = new SoMaterial();
  glassMaterial->ambientColor.setValue(0.05, 0.05, 0.7);
  glassMaterial->diffuseColor.setValue(0.3, 0.3, 0.6);
  glassMaterial->specularColor.setValue(0.5, 0.5, 0.5);
  glassMaterial->shininess = 0.4;
  glassMaterial->transparency = 0.7;

  SoTranslation *spaceBetweenHearts = new SoTranslation();
  spaceBetweenHearts->translation.setValue(0.2, 0.0, 0.0);

  hearts->addChild(redMaterial);

  // NO.1
  SoSwitch *sw1 = new SoSwitch();
  sw1->addChild(glassMaterial);
  hearts->addChild(sw1);

  hearts->addChild(redHeart);
  hearts->addChild(spaceBetweenHearts);
  // NO.2
  SoSwitch *sw2 = new SoSwitch();
  sw2->addChild(glassMaterial);
  //    sw2->whichChild = 0;             // If I switch this one on,
everything looks nice
  hearts->addChild(sw2);

  hearts->addChild(redHeart);
  hearts->addChild(spaceBetweenHearts);

  // NO.3
  SoSwitch *sw3 = new SoSwitch();
  sw3->addChild(glassMaterial);
  //  sw3->whichChild = 0;              // If I use this, all following
hearts are too bright hearts->addChild(sw3);

  hearts->addChild(redHeart);
  hearts->addChild(spaceBetweenHearts);

  // NO.4
  SoSwitch *sw4 = new SoSwitch();
  sw4->addChild(glassMaterial);
  hearts->addChild(sw4);

  hearts->addChild(redHeart);
  hearts->addChild(spaceBetweenHearts);

  // NO.5
  SoSwitch *sw5 = new SoSwitch();
  sw5->addChild(glassMaterial);      // If 3 is on and I use the glass
heart 5 does display correct   hearts->addChild(sw5);

  hearts->addChild(glassHeart);