コード例 #1
0
ファイル: VrmlNodeGroup.cpp プロジェクト: nixz/covise
void VrmlNodeGroup::addChildren(const VrmlMFNode &children)
{
    int nNow = d_children.size();
    int n = children.size();

    for (int i = 0; i < n; ++i)
    {
        VrmlNode *child = children[i];
        if (child == NULL)
        {
            continue;
        }

        child->parentList.push_back(this);
        if (child->getTraversalForce() > 0)
        {
            forceTraversal(false, child->getTraversalForce());
        }

        VrmlNodeProto *p = 0;

        // Add legal children and un-instantiated EXTERNPROTOs
        // Is it legal to add null children nodes?
        if (child == 0 || child->toChild() || ((p = child->toProto()) != 0 && p->size() == 0))
        {
            d_children.addNode(child);
            if (child)
            {
                child->addToScene(d_scene, d_relative.get());
                child->accumulateTransform(d_parentTransform);
            }
        }
        else
            System::the->error("Error: Attempt to add a %s node as a child of a %s node.\n",
                               child->nodeType()->getName(), nodeType()->getName());
    }

    if (nNow != d_children.size())
    {
        //??eventOut( d_scene->timeNow(), "children_changed", d_children );
        setModified();
    }
}
コード例 #2
0
ファイル: VrmlNodeILineSet.cpp プロジェクト: nixz/covise
Viewer::Object VrmlNodeILineSet::insertGeometry(Viewer *viewer)
{
    Viewer::Object obj = 0;
    if (d_coord.get())
    {
        VrmlMFVec3f &coord = d_coord.get()->toCoordinate()->coordinate();
        int nvert = coord.size();
        int ncoord = nvert;
        float *color = NULL;
        int nci = 0, *ci = NULL;
        int *localci = NULL;
        int *cdi = NULL, *localcdi = NULL;

        if (d_coordIndex.size() > 0)
        {
            cdi = &d_coordIndex[0];
            ncoord = d_coordIndex.size();
        }
        else
        {
            localcdi = new int[ncoord];
            cdi = localcdi;
            for (int i = 0; i < ncoord; i++)
            {
                cdi[i] = i;
            }
        }

        // check #colors is consistent with colorPerVtx, colorIndex...
        int componentsPerColor = 3;
        int cSize = -1;
        VrmlNode *colorNode = d_color.get();
        if (colorNode && (strcmp(colorNode->nodeType()->getName(), "ColorRGBA") == 0))
        {
            VrmlMFColorRGBA &c = d_color.get()->toColorRGBA()->color();
            color = &c[0][0];
            cSize = c.size();
            componentsPerColor = 4;
        }
        else if (d_color.get())
        {
            VrmlMFColor &c = d_color.get()->toColor()->color();
            color = &c[0][0];
            cSize = c.size();
        }
        if (cSize > -1)
        {
            nci = d_colorIndex.size();
            if (nci)
            {
                ci = d_colorIndex.get();
            }
            else
            {
                nci = cSize;
                localci = new int[cSize];
                ci = localci;
                for (int i = 0; i < nci; i++)
                {
                    ci[i] = i;
                }
            }
        }

        obj = viewer->insertLineSet(nvert, &coord[0][0],
                                    ncoord, cdi,
                                    d_colorPerVertex.get(),
                                    color, componentsPerColor,
                                    nci, ci, name());

        delete[] localcdi;
        delete[] localci;
    }

    if (d_color.get())
        d_color.get()->clearModified();
    if (d_coord.get())
        d_coord.get()->clearModified();

    return obj;
}
コード例 #3
0
ファイル: VrmlScene.cpp プロジェクト: DimondTheCat/xray
//
// The update method is where the events are processed. It should be
// called after each frame is rendered.
//
bool VrmlScene::update( double timeStamp )
{
  if (timeStamp <= 0.0) timeStamp = theSystem->time();
  VrmlSFTime now( timeStamp );

  d_deltaTime = DEFAULT_DELTA;

  // Update each of the timers.
  VrmlNodeList::iterator i, end = d_timers->end();
  for (i = d_timers->begin(); i != end; ++i)
    {
      VrmlNodeTimeSensor *t = (*i)->toTimeSensor();
      if (t) t->update( now );
    }

  // Update each of the clips.
  end = d_audioClips->end();
  for (i = d_audioClips->begin(); i != end; ++i)
    {
      VrmlNodeAudioClip *c = (*i)->toAudioClip();
      if (c) c->update( now );
    }

  // Update each of the scripts.
  end = d_scripts->end();
  for (i = d_scripts->begin(); i != end; ++i)
    {
      VrmlNodeScript *s = (*i)->toScript();
      if (s) s->update( now );
    }

  // Update each of the movies.
  end = d_movies->end();
  for (i = d_movies->begin(); i != end; ++i)
    {
      VrmlNodeMovieTexture *m =  (*i)->toMovieTexture();
      if (m) m->update( now );
    }


  // Pass along events to their destinations
  while (d_firstEvent != d_lastEvent &&
	 ! d_pendingUrl && ! d_pendingNodes)
    {
      Event *e = &d_eventMem[d_firstEvent];
      d_firstEvent = (d_firstEvent+1) % MAXEVENTS;

      // Ensure that the node is in the scene graph
      VrmlNode *n = e->toNode;
      if (this != n->scene())
	{
	  theSystem->debug("VrmlScene::update: %s::%s is not in the scene graph yet.\n",
			   n->nodeType()->getName(), n->name());
	  n->addToScene((VrmlScene*)this, urlDoc()->url() );
	}
      n->eventIn(e->timeStamp, e->toEventIn, e->value);
      // this needs to change if event values are shared...
      delete e->value;
    }

  if (d_pendingNodes)
    {
      replaceWorld( *d_pendingNodes, d_pendingScope );
      delete d_pendingNodes;
      d_pendingNodes = 0;
      d_pendingScope = 0;
    }
  else if (d_pendingUrl)
    {
      (void) loadUrl( d_pendingUrl, d_pendingParameters );
      delete d_pendingUrl;
      delete d_pendingParameters;
      d_pendingUrl = 0;
      d_pendingParameters = 0;
    }

  // Signal a redisplay if necessary
  return isModified();
}