void Parser::appendProperty(Token &prop) { ExpressionPtr &out = m_objects.back(); ExpressionPtr var = out; ExpressionPtr lvar = get_var_expr(var); if (prop->getMode() == Token::SingleName) { NamePtr name = prop->name(); out = NEW_EXP(ObjectProperty, lvar, name); Eval::ExprName *ename = dynamic_cast<Eval::ExprName*>(name.get()); if (ename) { ExpressionPtr nameExp = ename->getExp(); TempExpressionPtr temp = createOffset(var, nameExp); ename->setExp(temp); setOffset(out, var, nameExp); } else if (var->unsafe_cast<TempExpressionList>()) { setOffset(out, var, ExpressionPtr()); } } else { out = NEW_EXP(ObjectProperty, lvar, Name::fromExp(this, createOffset(var, prop->exp()))); setOffset(out, var, prop->exp()); } }
String Expression::getClassName(NamePtr name, VariableEnvironment &env) const { String clsname = name->get(env); if (strcasecmp(clsname.data(), "static") == 0) { if (name->getStatic() != clsname) { raise_error("\"static\" cannot be composed by expression in %s:%d", name->loc()->file, name->loc()->line1); } clsname = FrameInjection::GetStaticClassName(NULL); } return clsname; }
Action::ResultE check(NodePtr& node) { AttachmentPtr a = node->findAttachment(Name::getClassType()); if(a != NullFC) { NamePtr n = NamePtr::dcast(a); if(n->getField().getValue() == *_name) { _found = node; return Action::Quit; } } return Action::Continue; }
NamePtr Parser::procStaticClassName(Token &className, bool text) { NamePtr cname; if (text) { if (className.text() == "self") { cname = Name::fromString(this, peekClass()->name(), true); } else if (className.text() == "parent") { cname = Name::fromString(this, peekClass()->parent(), true); } else { cname = Name::fromString(this, className.text()); } cname->setOriginalText(className.text()); } else { cname = className->name(); if (haveClass() && cname->get()) { if (cname->get() == "self") { cname = Name::fromString(this, peekClass()->name(), true); cname->setOriginalText("self"); } else if (cname->get() == "parent") { cname = Name::fromString(this, peekClass()->parent(), true); cname->setOriginalText("parent"); } } } return cname; }
FieldContainerPtr NFIOName::readFC(const std::string &/*typeName*/) { FDEBUG(("NFIOName::readFC\n")); NamePtr name = Name::create(); UInt8 fcPtrType; _in->getValue(fcPtrType); UInt16 version; _in->getValue(version); if(version == 100) { std::string fieldName; std::string fieldType; UInt32 size = 0; // skip internal bool field _in->getValue(fieldName); _in->getValue(fieldType); _in->getValue(size); _in->skip(size); // read name field _in->getValue(fieldName); _in->getValue(fieldType); _in->getValue(size); SField<std::string> str; str.copyFromBin(*_in); name->editFieldPtr()->getValue().assign(str.getValue().c_str()); readEndMarker(); } else { readFCFields(name); } return name; }
ExpressionPtr SimpleFunctionCallExpression::make(EXPRESSION_ARGS, NamePtr name, const vector<ExpressionPtr> ¶ms, const Parser &p) { String sname = StringUtil::ToLower(name->getStatic()); if (!sname.isNull()) { if (sname == "get_class" && params.size() == 0) { if (p.currentClass()) { return new ScalarExpression(EXPRESSION_PASS, p.currentClass()->name()); } else { return new ScalarExpression(EXPRESSION_PASS, false); } } else if (sname == "get_parent_class" && params.size() == 0) { if (p.currentClass() && !p.currentClass()->parent().empty()) { return new ScalarExpression(EXPRESSION_PASS, p.currentClass()->parent()); } else { return new ScalarExpression(EXPRESSION_PASS, false); } } } return new SimpleFunctionCallExpression(EXPRESSION_PASS, name, params); }
StaticMethodExpression:: StaticMethodExpression(EXPRESSION_ARGS, const NamePtr &cname, const NamePtr &name, const vector<ExpressionPtr> ¶ms) : SimpleFunctionCallExpression(EXPRESSION_PASS, name, params), m_cname(cname), m_construct(name->getStatic() == "__construct") {}
/* Aufruf dieser Funktion erfolgt bei Traversierung des Szenengraphen mittels OpenSG-Funktion traverse(). Enthaelt ein Knoten verwertbare Geometrieinformation so tragen wir Zeiger auf seine Geometrie (OpenSG-Strukturen) im array gla_meshInfo_ ein. Nebenbei bestimmen wir für die Geometrie auch noch die World-Space- Transformation (evtl. existiert eine OpenSG-Funktion um diese Information zu erhalten, der Autor hat keine in der OpenSG-API entdeckt). */ Action::ResultE enter(NodePtr &node) { int i, j, h; Pnt3f v; int numFaces, numFaceVertices, vId, size; MeshInfo meshInfo; TinyMatrix transf; FaceIterator fit; int numQuads; NamePtr namePtr; char name[255]; namePtr = NamePtr::dcast(node->findAttachment(Name::getClassType().getGroupId())); if(namePtr == osg::NullFC) strcpy(name, ""); else { strcpy(name, namePtr->getFieldPtr()->getValue().c_str()); } SINFO << "Node name = '" << name << "'" << endl << endLog; GeometryPtr geo = GeometryPtr::dcast(node->getCore()); if(geo != NullFC) { GeoPLengthsUI32Ptr pLength = GeoPLengthsUI32Ptr::dcast(geo->getLengths()); GeoPTypesUI8Ptr pTypes = GeoPTypesUI8Ptr::dcast(geo->getTypes()); /* pLength and pTypes should not be NullFC, however VRML Importer/Exporter code is instable by now, so this can happen */ if((pLength != NullFC) && (pTypes != NullFC)) { GeoPLengthsUI32::StoredFieldType * pLengthField = pLength->getFieldPtr(); GeoPTypesUI8::StoredFieldType * pTypeField = pTypes->getFieldPtr(); size = pLengthField->size(); for(h = 0; h < size; h++) { if(((*pTypeField)[h] == GL_TRIANGLES) || ((*pTypeField)[h] == GL_QUADS)) { /* may quads appear in GL_TRIANGLES ? */ /* check if all triangles have three vertices */ numQuads = 0; fit = geo->beginFaces(); while(fit != geo->endFaces()) { numFaceVertices = fit.getLength(); if(numFaceVertices == 4) numQuads++; if(numFaceVertices > 4) { SWARNING << "More than 4 vertices in face!" << endl << endLog; return Action::Continue; // exit(1); } ++fit; } if(numQuads > 0) { SWARNING << "Quad encountered" << endl << endLog; } if(gl_sga->nodeDepth_ > 0) { for(i = 0; i < gl_sga->nodeDepth_; i++) { meshInfo.transf = meshInfo.transf * gl_sga->transf_[i]; } } else meshInfo.transf.identity(); /* access to vertices */ GeoPositions3fPtr pPos = GeoPositions3fPtr::dcast(geo->getPositions()); GeoPositions3f::StoredFieldType * pPosField = pPos->getFieldPtr(); /* access to faces */ numFaces = 0; fit = geo->beginFaces(); for(fit = geo->beginFaces(); fit != geo->endFaces(); ++fit) { numFaceVertices = fit.getLength(); for(j = 0; j < numFaceVertices; j++) { vId = fit.getPositionIndex(j); } numFaces++; } /* for fit */ /* set other mesh attributes */ meshInfo.numQuads = numQuads; meshInfo.geoPtr = geo; meshInfo.vPtr = pPosField; meshInfo.triangularFaces = (numQuads == 0); meshInfo.numVertices = pPosField->size(); meshInfo.numFaces = numFaces; gl_sga->meshInfo_.push_back(meshInfo); gl_sga->numGeometryNodes_++; } else { // SWARNING << "Neither triangle nor quad. Field type = " << // (*pTypeField)[h] << endl << endLog; } } /* for h */ } /* if pLength!=NullFC */ } else if(node->getCore()->getType().isDerivedFrom(Transform::getClassType())) { TransformPtr t = TransformPtr::dcast(node->getCore()); Matrix ma; ma = t->getMatrix(); SINFO << "Node type derived from transform, skipping children" << endl << endLog; for(i = 0; i < 4; i++) { for(j = 0; j < 4; j++) { transf[i][j] = ma[j][i]; /* the matrix is stored as columns/rows ? */ } } if(gl_sga->nodeDepth_ > gl_sga->maxNodeDepth_) { gl_sga->maxNodeDepth_ = gl_sga->nodeDepth_; gl_sga->transf_.push_back(transf); } else { gl_sga->transf_[gl_sga->nodeDepth_] = transf; } gl_sga->nodeDepth_++; } return Action::Continue; }
NamePtr formTmplName (NamePtr const & name, util::String const & args) { NamePtr result = name; name->accept (FormTmplName (args, result)); return result; }
// Initialize GLUT & OpenSG and set up the scene int main(int argc, char **argv) { // OSG init osgInit(argc,argv); // GLUT init int winid = setupGLUT(&argc, argv); // the connection between GLUT and OpenSG GLUTWindowPtr gwin = GLUTWindow::create(); gwin->setId(winid); gwin->init(); // load the scene NodePtr scene; if(argc < 2) { FWARNING(("No file given!\n")); scene = makeTorus(.5, 2, 16, 16); } else { /* All scene file loading is handled via the SceneFileHandler. */ scene = SceneFileHandler::the().read(argv[1]); } /* An Attachment is a special field container that can be attached to many of the internal classes like Nodes and NodeCores. There can be multiple Attachments attached to an object. Attachments can be attached to all FieldContainers that are derived from AttachmentContainer. This includes most higher-level classes in the system, like Nodes, NodeCores, Windows, Viewports etc. The only predefined kind of Attachment is the Name, which can keep the name of an object. Some of loaders (e.g. the WRL loader) create these kinds of Attachments for named nodes. */ /* An Attachment is a FieldContainer and as such needs to be created using ::create(). */ NamePtr name = Name::create(); /* The NameAttachment only has a single field, there's no need to use the mask here. */ beginEditCP(name); { name->getField().setValue("Scene"); } endEditCP (name); /* Attach the name to the scene node. */ beginEditCP(scene, Node::AttachmentsFieldMask); { scene->addAttachment(name); } endEditCP (scene, Node::AttachmentsFieldMask); /* Check if the scene has a Name attachment Attachments are categorized by the GroupID of their class. Every AttachmentContainer generally keeps only one attachment of a specific kind. */ AttachmentPtr a; a = scene->findAttachment(Name::getClassType()); if(a!=NullFC) { NamePtr n = NamePtr::dcast(a); SLOG << "Node name: " << n->getField().getValue() << endl; } else { SLOG << "Node has no name!" << endl; } // use the finder helper to find a named object finder f; NodePtr found; found = f.find(scene, "Scene"); SLOG << "Found object " << found << " named Scene." << endl; found = f.find(scene, "TF_DETAIL"); if(found == NullFC) { SLOG << "Found no object named TF_DETAIL (did you load the tie?)." << endl; } else { SLOG << "Found object " << found << " named TF_DETAIL." << endl; } // Use the simple attachment defined above MyAttachmentPtr mya = MyAttachment::create(); beginEditCP(mya); { mya->getField().setValue(42); } endEditCP (mya); // attach it to the scene beginEditCP(scene, Node::AttachmentsFieldMask); { scene->addAttachment(mya); } endEditCP (scene, Node::AttachmentsFieldMask); // and check if it's still there a = scene->findAttachment(MyAttachment::getClassType()); if(a!=NullFC) { MyAttachmentPtr m = MyAttachmentPtr::dcast(a); SLOG << "Node my value: " << m->getField().getValue() << endl; } else { SLOG << "Node has no myAttachment!" << endl; } // create the SimpleSceneManager helper mgr = new SimpleSceneManager; // tell the manager what to manage mgr->setWindow(gwin ); mgr->setRoot (scene); // show the whole scene mgr->showAll(); // GLUT main loop glutMainLoop(); return 0; }