bool VrmlScene::load(const char *url, const char *localCopy) { // Look for '#Viewpoint' syntax. There ought to be a current // scene if this format is used. VrmlSFBool flag(true); if (*url == '#') { VrmlNode *vp = d_namespace ? d_namespace->findNode(url+1) : 0; // spec: ignore if named viewpoint not found if (vp) { vp->eventIn( theSystem->time(), "set_bind", &flag ); setModified(); } return true; } // Try to load a file. Prefer a local copy if available. Doc *tryUrl; if (localCopy) tryUrl = new Doc( localCopy, 0 ); else tryUrl = new Doc( url, d_url); VrmlNamespace *newScope = new VrmlNamespace(); VrmlMFNode *newNodes = readWrl( tryUrl, newScope ); if ( newNodes ) { Doc *sourceUrl = tryUrl, *urlLocal = 0; if (localCopy) { sourceUrl = new Doc( url ); urlLocal = tryUrl; } replaceWorld( *newNodes, newScope, sourceUrl, urlLocal ); delete newNodes; // Look for '#Viewpoint' syntax if ( sourceUrl->urlModifier() ) { VrmlNode *vp = d_namespace->findNode( sourceUrl->urlModifier()+1 ); double timeNow = theSystem->time(); if (vp) vp->eventIn( timeNow, "set_bind", &flag ); } return true; // Success. } delete tryUrl; return false; }
VrmlNodeType* VrmlScene::readPROTO( VrmlMFString *urls, Doc *relative ) { // This is a problem. The nodeType of the EXTERNPROTO has a namespace // that refers back to this namespace (protos), which will be invalid // after we exit this function. I guess it needs to be allocated and // ref counted too... VrmlNamespace protos; Doc urlDoc; VrmlNodeType* def = 0; int i, n = urls->size(); theSystem->debug("readPROTO\n"); for (i=0; i<n; ++i) { //theSystem->debug("Trying to read url '%s'\n", urls->get(i)); urlDoc.seturl( urls->get(i), relative ); VrmlMFNode *kids = VrmlScene::readWrl( &urlDoc, &protos ); if ( kids ) delete kids; // Grab the specified PROTO, or the first one. const char *whichProto = urlDoc.urlModifier(); if (*whichProto) def = (VrmlNodeType*) protos.findType( whichProto+1 ); else def = (VrmlNodeType*) protos.firstType(); if (def) { def->setActualUrl( urlDoc.url() ); break; } else if (i < n-1 && strncmp(urls->get(i),"urn:",4)) theSystem->warn("Couldn't read EXTERNPROTO url '%s': %s\n", urls->get(i), strerror( errno)); } return def; }