NodeTransitPtr OctreeVisualization::createNodeGeo(OctreePtr, const Octree::OTNodePtr node, Material* GeoMaterial, const Node* BaseGeo) { //Make the Geoemtry NodeRecPtr box = deepCloneTree(BaseGeo); dynamic_cast<Geometry*>(box->getCore())->setMaterial(GeoMaterial); Matrix m; TransformRecPtr box_trans; NodeRecPtr trans_node = makeCoredNode<Transform>(&box_trans); Pnt3f Center; node->getVolume().getCenter(Center); m.setTranslate( Center.x(), Center.y(), Center.z()); const Real32 Offset(0.0f); Vec3f Size; node->getVolume().getSize(Size); m.setScale(Size.x()-(Size.x()*Offset), Size.y()-(Size.y()*Offset), Size.z()-(Size.z()*Offset)); box_trans->setMatrix(m); trans_node->addChild(box); return NodeTransitPtr(trans_node); }
/* virtual */ NodeTransitPtr OFLongIDRecord::convert(Node *pNode) { NodeUnrecPtr returnValue(pNode); if(pNode != NULL) { setName(pNode, longId); } return NodeTransitPtr(returnValue); }
/* virtual */ NodeTransitPtr OFMatrixRecord::convert(Node *pNode) { NodeUnrecPtr returnValue(NULL); if(pNode != NULL) { TransformUnrecPtr pXform = Transform::create(); pXform->setMatrix(matrix); returnValue = makeNodeFor(pXform); returnValue->addChild(pNode); } return NodeTransitPtr(returnValue); }
// // create an arbitrarly complex render scene // static NodeTransitPtr createStaticScene() { NodeUnrecPtr root = makeCoredNode<Group>(); typedef boost::mt19937 base_generator_type; static base_generator_type generator(0); static boost::uniform_01<float> value; static boost::variate_generator< base_generator_type, boost::uniform_01<float> > die(generator, value); for (int i = 0; i < max_tori; ++i) { NodeUnrecPtr scene = makeTorus(.5, 2, 32, 32); TransformUnrecPtr transformCore = Transform::create(); Matrix mat; mat.setIdentity(); float x = 500.f * die(); float y = 500.f * die(); float z = 500.f * die(); float e1 = die(); float e2 = die(); float e3 = die(); Vec3f v(e1,e2,e3); v.normalize(); float a = TwoPi * die(); Quaternion q(v, a); mat.setTranslate(x,y,z); mat.setRotate(q); transformCore->setMatrix(mat); NodeUnrecPtr trafo = makeNodeFor(transformCore); trafo->addChild(scene); root->addChild(trafo); } return NodeTransitPtr(root); }
NodeTransitPtr buildScene(void) { NodeUnrecPtr geoN = makeBox(1.f, 1.f, 1.f, 1, 1, 1); ComponentTransformUnrecPtr xform = ComponentTransform::create(); NodeUnrecPtr xformN = makeNodeFor(xform); setTargetId(xform, "xform0"); gXForm = xform; NodeUnrecPtr groupN = makeCoredNode<Group>(); xformN->addChild(geoN ); groupN->addChild(xformN); return NodeTransitPtr(groupN); }
NodeTransitPtr createTorus(void) { // Make Object Nodes NodeRecPtr ExampleTorusGeo = makeTorus(90, 270, 16, 16); // Preform transformations on them Matrix mat; // On Torus mat.setTranslate(0.0,100.0,-200.0); TransformRecPtr TorusTranCore = Transform::create(); TorusTranCore->setMatrix(mat); NodeRecPtr ExampleTorus = Node::create(); ExampleTorus->setCore(TorusTranCore); ExampleTorus->addChild(ExampleTorusGeo); ExampleTorus->setTravMask(0); return NodeTransitPtr(ExampleTorus); }
NodeTransitPtr createSphere(void) { // Make Object Nodes NodeRecPtr ExampleSphereGeo = makeSphere(4, 100); MaterialRecPtr RedMaterial = createMaterial(Color4f(1.0f,0.0f,0.0f,1.0f)); dynamic_cast<Geometry*>(ExampleSphereGeo->getCore())->setMaterial(RedMaterial); Matrix mat; mat.setTranslate(250.0,0.0,0.0); TransformRecPtr SphereTranCore = Transform::create(); SphereTranCore->setMatrix(mat); NodeRecPtr ExampleSphere = Node::create(); ExampleSphere->setCore(SphereTranCore); ExampleSphere->addChild(ExampleSphereGeo); ExampleSphere->setTravMask(0); return NodeTransitPtr(ExampleSphere); }
NodeTransitPtr createBox(void) { // Make Object Nodes NodeRecPtr ExampleBoxGeo = makeBox(100, 100, 100, 1, 1, 1); MaterialRecPtr GreenMaterial = createMaterial(Color4f(0.0f,1.0f,0.0f,1.0f)); dynamic_cast<Geometry*>(ExampleBoxGeo->getCore())->setMaterial(GreenMaterial); Matrix mat; mat.setTranslate(250.0,250.0,0.0); TransformRecPtr ExampleBoxTranCore = Transform::create(); ExampleBoxTranCore->setMatrix(mat); NodeRecPtr ExampleBox = Node::create(); ExampleBox->setCore(ExampleBoxTranCore); ExampleBox->addChild(ExampleBoxGeo); ExampleBox->setTravMask(0); return NodeTransitPtr(ExampleBox); }
NodeTransitPtr OctreeVisualization::createNodeDistanceLOD(OctreePtr, const Octree::OTNodePtr node, Material* GeoMaterial, const Node* BaseGeo, Real32 Range ) { NodeRecPtr box = deepCloneTree(BaseGeo); dynamic_cast<Geometry*>(box->getCore())->setMaterial(GeoMaterial); //DistanceLOD node DistanceLODRecPtr LOD = DistanceLOD::create(); LOD->editMFRange()->push_back(10.0); NodeRecPtr LODNode = makeNodeFor(LOD); LODNode->addChild(box); LODNode->addChild(makeCoredNode<Group>()); Matrix m; TransformRecPtr box_trans; NodeRecPtr trans_node = makeCoredNode<Transform>(&box_trans); Pnt3f Center; node->getVolume().getCenter(Center); m.setTranslate(Center.x(), Center.y(), Center.z()); const Real32 Offset(0.0f); Vec3f Size; node->getVolume().getSize(Size); m.setScale(Size.x()-(Size.x()*Offset), Size.y()-(Size.y()*Offset), Size.z()-(Size.z()*Offset)); box_trans->setMatrix(m); trans_node->addChild(LODNode); return NodeTransitPtr(trans_node); }
NodeTransitPtr createCone(void) { // Make Object Nodes NodeRecPtr ExampleConeGeo = makeCone(150, 50, 16, true, true); MaterialRecPtr BlueMaterial = createMaterial(Color4f(0.0f,0.0f,1.0f,1.0f)); dynamic_cast<Geometry*>(ExampleConeGeo->getCore())->setMaterial(BlueMaterial); // Preform transformations on them Matrix mat; // On Cone mat.setTranslate(0.0,0.0,-250.0); TransformRecPtr ConeTranCore = Transform::create(); ConeTranCore->setMatrix(mat); NodeRecPtr ExampleCone = Node::create(); ExampleCone->setCore(ConeTranCore); ExampleCone->addChild(ExampleConeGeo); ExampleCone->setTravMask(0); return NodeTransitPtr(ExampleCone); }
static NodeTransitPtr createDynamicScene() { NodeUnrecPtr scene = makeCylinder(30, 100, 16, true, true, true); return NodeTransitPtr(scene); }
OSG_BEGIN_NAMESPACE NodeTransitPtr OctreeVisualization::createOctreeVisualization(OctreePtr tree, Int32 MaxDepth, bool filledGeometry, bool onlyLeaf) { OTNodeGeometryCreateFunc GeoCreateFunc; OTNodeMaterialCreateFunc MatCreateFunc; OTNodeIsVisibleFunc IsVisibleFunc; IsVisibleFunc = boost::bind(&OctreeVisualization::isNodeLeaf,_1, _2, false); NodeRecPtr VisRootNode = makeCoredNode<Group>(); if(filledGeometry) { NodeRecPtr BaseBox = makeBox(1.0f,1.0f,1.0f, 1, 1, 1); GeoCreateFunc = boost::bind(&OctreeVisualization::createNodeDistanceLOD,_1, _2, _3, BaseBox.get(), 10.0f); BlendChunkRecPtr DefaultBlendChunk = BlendChunk::create(); DefaultBlendChunk->setSrcFactor(GL_SRC_ALPHA); DefaultBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA); PolygonChunkRecPtr DefaultPolygonChunk = PolygonChunk::create(); DefaultPolygonChunk->setCullFace(GL_BACK); MatCreateFunc = boost::bind(&OctreeVisualization::createMatFilled,_1, _2, Color3f(0.0f,1.0f,0.0f), Color3f(1.0f,0.0f,0.0f), 0.15f, DefaultBlendChunk.get(), DefaultPolygonChunk.get()); createOctreeVisualizationRec(tree, tree->getRoot(), VisRootNode, osgMin<UInt32>(tree->getDepth(),MaxDepth), GeoCreateFunc, MatCreateFunc, IsVisibleFunc); } else { //*******************Create the Geometry for the box GeoUInt8PropertyRecPtr type = GeoUInt8Property::create(); //Volume bound box type->push_back(GL_LINE_STRIP); type->push_back(GL_LINES); GeoUInt32PropertyRefPtr lens = GeoUInt32Property::create(); //Volume bound box lens->push_back(10); lens->push_back(6); GeoUInt32PropertyRefPtr index = GeoUInt32Property::create(); //Volume bound box index->push_back(0); index->push_back(1); index->push_back(3); index->push_back(2); index->push_back(0); index->push_back(4); index->push_back(5); index->push_back(7); index->push_back(6); index->push_back(4); index->push_back(1); index->push_back(5); index->push_back(2); index->push_back(6); index->push_back(3); index->push_back(7); GeoPnt3fPropertyRefPtr highlightPoints = GeoPnt3fProperty::create(); //Volume bound box highlightPoints->push_back(Pnt3f(-1, -1, -1)); highlightPoints->push_back(Pnt3f( 1, -1, -1)); highlightPoints->push_back(Pnt3f(-1, 1, -1)); highlightPoints->push_back(Pnt3f( 1, 1, -1)); highlightPoints->push_back(Pnt3f(-1, -1, 1)); highlightPoints->push_back(Pnt3f( 1, -1, 1)); highlightPoints->push_back(Pnt3f(-1, 1, 1)); highlightPoints->push_back(Pnt3f( 1, 1, 1)); //Colors Color4f BoundBoxColor(1.0f,1.0f,1.0,1.00f); GeoVec4fPropertyRefPtr highlightColors = GeoVec4fProperty::create(); //Volume bound box highlightColors->push_back(BoundBoxColor); highlightColors->push_back(BoundBoxColor); highlightColors->push_back(BoundBoxColor); highlightColors->push_back(BoundBoxColor); highlightColors->push_back(BoundBoxColor); highlightColors->push_back(BoundBoxColor); highlightColors->push_back(BoundBoxColor); highlightColors->push_back(BoundBoxColor); GeometryRecPtr BoxGeo =Geometry::create(); BoxGeo->setTypes (type); BoxGeo->setLengths (lens); BoxGeo->setIndices (index); BoxGeo->setPositions (highlightPoints); BoxGeo->setColors (highlightColors); //Highlight Bound Box Node NodeRecPtr BaseBox = makeNodeFor(BoxGeo); GeoCreateFunc = boost::bind(&OctreeVisualization::createNodeDistanceLOD,_1, _2, _3, BaseBox.get(), 10.0f); //*******************Create the Geometry for the highlight BlendChunkRecPtr DefaultBlendChunk = BlendChunk::create(); DefaultBlendChunk->setSrcFactor(GL_SRC_ALPHA); DefaultBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA); LineChunkRecPtr DefaultLineChunk = LineChunk::create(); DefaultLineChunk->setSmooth(true); MatCreateFunc = boost::bind(&OctreeVisualization::createMatLine,_1, _2, Color3f(1.0f,0.0f,0.0f), Color3f(0.0f,0.0f,1.0f), 0.55f, DefaultBlendChunk.get(), DefaultLineChunk.get()); createOctreeVisualizationRec(tree, tree->getRoot(), VisRootNode, osgMin<UInt32>(tree->getDepth(),MaxDepth), GeoCreateFunc, MatCreateFunc, IsVisibleFunc); } return NodeTransitPtr(VisRootNode); }
NodeTransitPtr SceneFileHandlerBase::read(const Char8 *fileName, GraphOpSeq *graphOpSeq, Resolver resolver, bool bWarnNotFound ) { NodeTransitPtr returnValue(NULL); if(fileName == NULL) { SWARNING << "cannot read NULL file" << std::endl; return NodeTransitPtr(NULL); } std::string fullFilePath = initPathHandler(fileName); if(fullFilePath.empty() == true) { if(_readFP != NULL) { // that's a fallback could be a url so the callback // can handle this correctly. SceneFileType *type = getFileType(fileName); if(type != NULL) { // create a dummy stream with the bad flag set. std::ifstream in; in.setstate(std::ios::badbit); returnValue = _readFP(type, in, fileName); } else { if(bWarnNotFound == true) SWARNING << "Couldn't open file " << fileName << std::endl; } } else { if(bWarnNotFound == true) SWARNING << "Couldn't open file " << fileName << std::endl; } commitChanges(); return returnValue; } SceneFileType *type = getFileType(fullFilePath.c_str()); NodeUnrecPtr scene = NULL; if(type != NULL) { triggerReadBegin(fullFilePath.c_str()); updateReadProgress(0); SINFO << "try to read " << fullFilePath << " as " << type->getName() << std::endl; std::ifstream in(fullFilePath.c_str(), std::ios::binary); if(in) { scene = read(in, fullFilePath.c_str(), graphOpSeq); in.close(); if(scene != NULL) { triggerReadEnd(fullFilePath.c_str()); FileContextAttachmentUnrecPtr pFContext = dynamic_cast<FileContextAttachment *>( scene->findAttachment( FileContextAttachment::getClassGroupId())); if(pFContext == NULL) { pFContext = FileContextAttachment::create(); pFContext->setResolvedName(fullFilePath); scene->addAttachment(pFContext); } } } else { if(bWarnNotFound == true) { SWARNING << "Couldn't open input stream for file " << fullFilePath << std::endl; } } #ifndef OSG_DISABLE_DEPRECATED // Ok stream interface didn't work try via filename if(scene == NULL) scene = type->readFile(fullFilePath.c_str()); if(scene != NULL) { if(graphOpSeq != NULL) graphOpSeq->run(scene); SINFO << "read ok:" << std::endl; } else { if(bWarnNotFound == true) SWARNING << "could not read " << std::endl; } #endif #if 0 if(scene != NULL && graphOpSeq != NULL) { SINFO << "Running GraphOps..." << std::endl; graphOpSeq->run(scene); } #endif } else { if(bWarnNotFound == true) { SWARNING << "could not read " << fullFilePath << "; unknown file format" << std::endl; } } commitChanges(); return NodeTransitPtr(scene); }
/* virtual */ NodeTransitPtr OFIgnoredTransformRecord::convert(Node *pNode) { return NodeTransitPtr(pNode); }
NodeTransitPtr deepCloneTree( const OSG::Node *rootNode, const std::vector<const OSG::ReflexiveContainerType *> &shareTypes, const std::vector<const OSG::ReflexiveContainerType *> &ignoreTypes, const std::vector<OSG::UInt16> &shareGroupIds, const std::vector<OSG::UInt16> &ignoreGroupIds) { NodeUnrecPtr rootClone(NULL); if(rootNode != NULL) { NodeUnrecPtr childClone; NodeCore *core = rootNode->getCore(); rootClone = Node::create(); rootClone->setTravMask(rootNode->getTravMask()); deepCloneAttachments(rootNode, rootClone, shareTypes, ignoreTypes, shareGroupIds, ignoreGroupIds); if(core != NULL) { NodeCoreUnrecPtr coreClone(NULL); const FieldContainerType &coreType = core->getType(); // test if core type should NOT be ignored if(!TypePredicates::typeInGroupIds ( ignoreGroupIds.begin(), ignoreGroupIds.end(), coreType) && !TypePredicates::typeDerivedFrom( ignoreTypes.begin(), ignoreTypes.end(), coreType) ) { // test if core should be shared if(TypePredicates::typeInGroupIds ( shareGroupIds.begin(), shareGroupIds.end(), coreType) || TypePredicates::typeDerivedFrom( shareTypes.begin(), shareTypes.end(), coreType) ) { // share core coreClone = core; } else { // clone core coreClone = dynamic_pointer_cast<NodeCore>( deepClone(core, shareTypes, ignoreTypes, shareGroupIds, ignoreGroupIds)); } } rootClone->setCore(coreClone); } for(UInt32 i = 0; i < rootNode->getNChildren(); ++i) { childClone = deepCloneTree(rootNode->getChild(i), shareTypes, ignoreTypes, shareGroupIds, ignoreGroupIds); rootClone->addChild(childClone); } } return NodeTransitPtr(rootClone); }
//---------------------------- // Function name: read //---------------------------- // //Parameters: //p: Scene &image, const char *fileName //GlobalVars: //g: //Returns: //r:bool // Caution //c: //Assumations: //a: //Describtions: //d: read the image from the given file //SeeAlso: //s: // //------------------------------ NodeTransitPtr OBJSceneFileType::read( std::istream &is, const Char8 *, Resolver ) const { NodeUnrecPtr rootPtr, nodePtr; std::string elem; std::map<std::string, DataElem>::const_iterator elemI; Vec3f vec3r; Pnt3f pnt3r; Vec2f vec2r; Real32 x,y,z; GeoPnt3fPropertyUnrecPtr coordPtr = GeoPnt3fProperty::create(); GeoVec2fPropertyUnrecPtr texCoordPtr = GeoVec2fProperty::create(); GeoVec3fPropertyUnrecPtr normalPtr = GeoVec3fProperty::create(); GeometryUnrecPtr geoPtr; GeoIntegralPropertyUnrecPtr posIndexPtr, texIndexPtr, normalIndexPtr; GeoIntegralPropertyUnrecPtr lensPtr; GeoIntegralPropertyUnrecPtr typePtr; DataElem dataElem; DataElem lastDataElem; Char8 strBuf[8192], *token, *nextToken; Int32 strBufSize = sizeof(strBuf)/sizeof(Char8); Int32 index, posIndex = 0, indexType; Int32 i,j,n,primCount[3]; std::list<Mesh> meshList; std::map<std::string, SimpleTexturedMaterialUnrecPtr> mtlMap; std::map<std::string, SimpleTexturedMaterialUnrecPtr>::iterator mtlI; Mesh emptyMesh; Face emptyFace; TiePoint emptyTie; Int32 indexMask, meshIndexMask; std::list<Face>::iterator faceI; std::list<Mesh>::iterator meshI; bool isSingleIndex; // create the first mesh entry meshList.push_back(emptyMesh); meshI = meshList.begin(); if(is) { primCount[0] = 0; primCount[1] = 0; primCount[2] = 0; for(is >> elem; is.eof() == false; is >> elem) { if(elem[0] == '#' || elem[0] == '$') { is.ignore(INT_MAX, '\n'); } else { SceneFileHandler::the()->updateReadProgress(); elemI = _dataElemMap.find(elem); dataElem = ((elemI == _dataElemMap.end()) ? UNKNOWN_DE : elemI->second ); switch (dataElem) { case OBJECT_DE: case GROUP_DE: case SMOOTHING_GROUP_DE: is.ignore(INT_MAX, '\n'); break; case VERTEX_DE: primCount[0]++; is >> x >> y >> z; pnt3r.setValues(x,y,z); coordPtr->addValue(pnt3r); break; case VERTEX_TEXTURECOORD_DE: primCount[1]++; is >> x >> y; vec2r.setValues(x,y); texCoordPtr->addValue(vec2r); break; case VERTEX_NORMAL_DE: primCount[2]++; is >> x >> y >> z; vec3r.setValues(x,y,z); normalPtr->addValue(vec3r); break; case LIB_MTL_DE: is >> elem; readMTL ( elem.c_str(), mtlMap ); is.ignore(INT_MAX, '\n'); break; case USE_MTL_DE: is >> elem; if (meshI->faceList.empty() == false) { meshList.push_front(emptyMesh); meshI = meshList.begin(); } mtlI = mtlMap.find(elem); if (mtlI == mtlMap.end()) { FFATAL (("Unkown mtl %s\n", elem.c_str())); } else { meshI->mtlPtr = mtlI->second; } break; case FACE_DE: meshI->faceList.push_front(emptyFace); faceI = meshI->faceList.begin(); is.get(strBuf,strBufSize); token = strBuf; indexType = 0; while(token && *token) { // some tools use line continuation for long // face definitions - these use a \ at the line // end if(*token == '\\') { is.ignore(1, '\n'); is.get(strBuf,strBufSize); token = strBuf; indexType = 0; continue; } for (; *token == '/'; token++) indexType++; for (; isspace(*token); token++) indexType = 0; index = strtol(token, &nextToken, 10); if (token == nextToken) break; if (indexType == 0) faceI->tieVec.push_back(emptyTie); if (index >= 0) index--; else index = primCount[indexType] + index; faceI->tieVec.back().index[indexType] = index; token = nextToken; } break; case UNKNOWN_DE: default: // don't warn about 3rd tex coord if(lastDataElem != VERTEX_TEXTURECOORD_DE) { FWARNING (( "Unkown obj data elem: %s\n", elem.c_str())); } is.ignore(INT_MAX, '\n'); break; } lastDataElem = dataElem; } } #if 0 std::cerr << "------------------------------------------------" << std::endl; i = 0; for (meshI = meshList.begin(); meshI != meshList.end(); meshI++) { std::cerr << "Mesh " << i << " faceCount :" << meshI->faceList.size() << std::endl; j = 0 ; for ( faceI = meshI->faceList.begin(); faceI != meshI->faceList.end(); faceI++) std::cerr << "MESH " << i << "face: " << j++ << "tie num: " << faceI->tieVec.size() << std::endl; i++; } std::cerr << "------------------------------------------------" << std::endl; #endif // create Geometry objects for (meshI = meshList.begin(); meshI != meshList.end(); meshI++) { geoPtr = Geometry::create(); posIndexPtr = NULL; texIndexPtr = NULL; normalIndexPtr = NULL; lensPtr = GeoUInt32Property::create(); typePtr = GeoUInt8Property ::create(); // create and check mesh index mask meshIndexMask = 0; isSingleIndex = true; if ( meshI->faceList.empty() == false) { for ( faceI = meshI->faceList.begin(); faceI != meshI->faceList.end(); faceI++) { indexMask = 0; n = UInt32(faceI->tieVec.size()); for (i = 0; i < n; i++) { for (j = 0; j < 3; j++) { if ((index = (faceI->tieVec[i].index[j])) >= 0) { indexMask |= (1 << j); if (j) isSingleIndex &= (posIndex == index); else posIndex = index; } } } if (meshIndexMask == 0) { meshIndexMask = indexMask; } else if (meshIndexMask != indexMask) { // consider this real-world example: // [...] // f 1603//1747 1679//1744 1678//1743 // s 1 // f 9/1/10 5/2/9 1680/3/1748 1681/4/174 // [...] // Some faces contain texture coords and others do not. // The old version did just skip this geometry. // This version should continue if there's at least // the vertex index // I've seen the change in the maskIndex only after a smooth group, // so it's perhaps smarter to not ignore the smooth group further up in this code if( !(indexMask & 1) ) { // if there are vertex indices there's no reason to get in here FFATAL (( "IndexMask unmatch, can not create geo\n")); meshIndexMask = 0; break; } else { // consider the minimum similarities of mesh masks meshIndexMask &= indexMask; } } } } else { FWARNING (("Mesh with empty faceList\n")); } // fill the geo properties if (meshIndexMask) { geoPtr->setPositions ( coordPtr ); posIndexPtr = GeoUInt32Property::create(); if(!isSingleIndex) geoPtr->setIndex(posIndexPtr, Geometry::PositionsIndex); geoPtr->setLengths ( lensPtr ); geoPtr->setTypes ( typePtr ); if ( (meshIndexMask & 2) && texCoordPtr->size() > 0 ) { geoPtr->setTexCoords ( texCoordPtr ); texIndexPtr = GeoUInt32Property::create(); if(!isSingleIndex) geoPtr->setIndex(texIndexPtr, Geometry::TexCoordsIndex); } else { geoPtr->setTexCoords ( NULL ); } if ( (meshIndexMask & 4) && normalPtr->size() > 0 ) { geoPtr->setNormals ( normalPtr ); normalIndexPtr = GeoUInt32Property::create(); if(!isSingleIndex) geoPtr->setIndex(normalIndexPtr, Geometry::NormalsIndex); } else { geoPtr->setNormals ( NULL ); } if (meshI->mtlPtr == NULL) { meshI->mtlPtr = SimpleTexturedMaterial::create(); meshI->mtlPtr->setDiffuse( Color3f( .8f, .8f, .8f ) ); meshI->mtlPtr->setSpecular( Color3f( 1.f, 1.f, 1.f ) ); meshI->mtlPtr->setShininess( 20.f ); } geoPtr->setMaterial ( meshI->mtlPtr ); for ( faceI = meshI->faceList.begin(); faceI != meshI->faceList.end(); faceI++) { n = UInt32(faceI->tieVec.size()); // add the lens entry lensPtr->push_back(n); // add the type entry typePtr->push_back(GL_POLYGON); // create the index values for (i = 0; i < n; i++) { if (isSingleIndex) { posIndexPtr->push_back(faceI->tieVec[i].index[0]); } else { posIndexPtr->push_back(faceI->tieVec[i].index[0]); if(texIndexPtr != NULL) texIndexPtr->push_back(faceI->tieVec[i].index[1]); if(normalIndexPtr != NULL) normalIndexPtr->push_back(faceI->tieVec[i].index[2]); } } } if(isSingleIndex) { geoPtr->setIndex(posIndexPtr, Geometry::PositionsIndex); geoPtr->setIndex(posIndexPtr, Geometry::NormalsIndex ); geoPtr->setIndex(posIndexPtr, Geometry::TexCoordsIndex); } // need to port the geometry functions ... createSharedIndex( geoPtr ); // check if we have normals // need to port the geometry functions ... if(geoPtr->getNormals() == NULL) calcVertexNormals(geoPtr); // create and link the node nodePtr = Node::create(); nodePtr->setCore( geoPtr ); if (meshList.size() > 1) { if (rootPtr == NULL) { rootPtr = Node::create(); GroupUnrecPtr tmpPtr = Group::create(); rootPtr->setCore ( tmpPtr ); rootPtr->addChild(nodePtr); } else { rootPtr->addChild(nodePtr); } } else { rootPtr = nodePtr; } } } } SceneFileHandler::the()->updateReadProgress(100); commitChanges(); return NodeTransitPtr(rootPtr); }
NodeTransitPtr SceneFileHandlerBase::read( std::istream &is, const Char8 *fileNameOrExtension, GraphOpSeq *graphOpSeq , Resolver resolver ) { SceneFileType *type = getFileType(fileNameOrExtension); NodeUnrecPtr scene = NULL; if(!fileNameOrExtension) { SWARNING << "cannot read NULL extension" << std::endl; return NodeTransitPtr(scene); } if(type != NULL) { SINFO << "try to read stream as " << type->getName() << std::endl; // check for fileio read callback if(_readFP != NULL) { initReadProgress(is); scene = _readFP(type, is, fileNameOrExtension); terminateReadProgress(); } else { if(isGZip(is)) { SINFO << "Detected gzip compressed stream." << std::endl; #ifdef OSG_WITH_ZLIB initReadProgress(is); zip_istream unzipper(is); scene = type->read(unzipper, fileNameOrExtension, resolver ? resolver : _oGlobalResolver); if(scene != NULL) { if(unzipper.check_crc() == true) { SINFO << "Compressed stream has correct checksum." << std::endl; } else { SWARNING << "Compressed stream has wrong checksum." << std::endl; } } terminateReadProgress(); #else SFATAL << "Compressed streams are not supported! Configure " << "with --enable-png --with-png=DIR options." << std::endl; #endif } else { initReadProgress(is); scene = type->read(is, fileNameOrExtension, resolver ? resolver : _oGlobalResolver); terminateReadProgress(); } } if(scene != NULL) { if(graphOpSeq != NULL) graphOpSeq->traverse(scene); SINFO << "read ok:" << std::endl; } else { SWARNING << "could not read " << std::endl; } } else { SWARNING << "could not read unknown file format" << std::endl; } commitChanges(); return NodeTransitPtr(scene); }