SharedGroup usage

1 view
Skip to first unread message

W. Wood Harter

unread,
May 5, 2006, 4:49:26 PM5/5/06
to GameD...@googlegroups.com
I should have waited to talk about shared groups until after I had a sample. Here is a sample you can use.

Wood

    for (i=0;i<copies_to_add;i++)
    {
      // the position where this copy will be placed in the scene
      tilex = i*posx;
      tilez = i*posz;
     
      // create a transform for the leaf copy
      v3fTmp.set(tilex,0.0f,tilez);
      t3dTmp.set(v3fTmp);
      TransformGroup tg = new TransformGroup(t3dTmp);

      // create the main instance if it has not already been created
      // all leaf nodes will to refer to this branch group
      if (sharedItem==null)
      {
        // get the branch group from the model
        // since it is shared, this can never be added to a real scene
        // changes to this will be reflected in all the copies
        BranchGroup bg = sceneModel.getSceneGroup();

        // create the shared group
        sharedItem = new SharedGroup();

        // add the model to this SharedGroup
        sharedItem.addChild(bg);

        // compile it before referencing it
        sharedItem.compile();
      }
     
      // create the leaf node with a reference to the shared group
      Link leaf = new Link(sharedItem);

      // add the leaf to this copies transform group
      tg.addChild(leaf);

      // add the transform group to the overall model    
      bgParent.addChild(tg);
      } // for


--
http://www.memorize-it.com
Reply all
Reply to author
Forward
0 new messages