⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 readerwritervrml2.cpp

📁 最新osg包
💻 CPP
📖 第 1 页 / 共 2 页
字号:
                const openvrml::vrml97_node::material_node *vrml_material =                    dynamic_cast<const openvrml::vrml97_node::material_node *>(vrml_material_node.get());                //              std::cerr << "sfnode->Material OK" << std::endl << std::flush;                if (vrml_material != NULL)                 {                    osg_mat->setAmbient(osg::Material::FRONT_AND_BACK,                                         osg::Vec4(vrml_material->ambient_intensity(),                                                  vrml_material->ambient_intensity(),                                                  vrml_material->ambient_intensity(),                                                  1.0));                    osg_mat->setDiffuse(osg::Material::FRONT_AND_BACK,                                         osg::Vec4(vrml_material->diffuse_color().r(),                                                  vrml_material->diffuse_color().g(),                                                  vrml_material->diffuse_color().b(),                                                  1.0));                    osg_mat->setEmission(osg::Material::FRONT_AND_BACK,                                          osg::Vec4(vrml_material->emissive_color().r(),                                                   vrml_material->emissive_color().g(),                                                   vrml_material->emissive_color().b(),                                                   1.0));                    osg_mat->setSpecular(osg::Material::FRONT_AND_BACK,                                          osg::Vec4(vrml_material->specular_color().r(),                                                   vrml_material->specular_color().g(),                                                   vrml_material->specular_color().b(),                                                   1.0));                    osg_mat->setShininess(osg::Material::FRONT_AND_BACK, vrml_material->shininess() );                    if (vrml_material->transparency() > 0.0f)                    {                        osg_mat->setTransparency(osg::Material::FRONT_AND_BACK, vrml_material->transparency());                        osg_stateset->setMode(GL_BLEND, osg::StateAttribute::ON);                         osg_stateset->setAttribute(new osg::Depth(osg::Depth::LESS, 0.0, 1.0, false)); // GvdB: transparent objects do not write depth                        osg_stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);                    }                    else                    {                        osg_stateset->setMode(GL_BLEND, osg::StateAttribute::OFF);                          osg_stateset->setRenderingHint(osg::StateSet::OPAQUE_BIN);                    }                    osg_stateset->setAttributeAndModes(osg_mat.get());                }                const openvrml::vrml97_node::image_texture_node *vrml_texture =                    dynamic_cast<const openvrml::vrml97_node::image_texture_node *>(vrml_texture_node.get());                //              std::cerr << "TextureNode -> ImageTexture OK" << std::endl << std::flush;                // if texture is provided                if (vrml_texture != 0) {                    const openvrml::field_value &texture_url_fv = vrml_texture->field("url");                    const openvrml::mfstring &mfs = dynamic_cast<const openvrml::mfstring &>(texture_url_fv);                    //              std::cerr << "Texture URL FV -> mfstring OK" << std::endl << std::flush;                    const std::string &url = mfs.value[0];                    osg::ref_ptr<osg::Image> image = osgDB::readImageFile(url);                    if (image != 0) {                        osg::ref_ptr<osg::Texture2D> texture = new osg::Texture2D;                        texture->setImage(image.get());                        // defaults                        texture->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT);                        texture->setWrap(osg::Texture::WRAP_R, osg::Texture::REPEAT);                        texture->setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT);                        // get the real texture wrapping parameters (if any)                        try {                            const openvrml::field_value &wrap_fv = vrml_texture->field("repeatS");                            const openvrml::sfbool &sfb = dynamic_cast<const openvrml::sfbool &>(wrap_fv);                            if (!sfb.value) {                                texture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP);                            }                        } catch (...) {                            // nothing specified                        }                        try {                            const openvrml::field_value &wrap_fv = vrml_texture->field("repeatT");                            const openvrml::sfbool &sfb = dynamic_cast<const openvrml::sfbool &>(wrap_fv);                            if (!sfb.value) {                                texture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP);                            }                        } catch (...) {                            // nothing specified                        }                        osg_stateset->setTextureAttributeAndModes(0, texture.get());                        //osg_stateset->setMode(GL_BLEND,osg::StateAttribute::ON);  //bhbn                    }                     else {                        std::cerr << "texture file " << url << " not found !" << std::endl << std::flush;                    }                }            }        }        return osg_geode.get();    }     else     {        return 0;    }    /*       } else if(obj->type.id == "DirectionalLight")    // Handle lights       {           osg::Group* lightGroup = new osg::Group;           openvrml::vrml97_node::directional_light_node *vrml_light;           vrml_light = dynamic_cast<openvrml::vrml97_node::directional_light_node *>(obj);           // create light with global params           osg::Light* myLight = new osg::Light;           myLight->setLightNum(osgLightNum);           myLight->setAmbient(osg::Vec4(vrml_light->ambient_intensity(),vrml_light->ambient_intensity(),vrml_light->ambient_intensity(),vrml_light->ambient_intensity()));           float osgR = vrml_light->color().r()*vrml_light->intensity();           float osgG = vrml_light->color().g()*vrml_light->intensity();           float osgB = vrml_light->color().b()*vrml_light->intensity();           myLight->setDiffuse(osg::Vec4(osgR, osgG, osgB, 1.0f));           myLight->setSpecular(osg::Vec4(osgR, osgG, osgB, 1.0f));                      // configure light as DIRECTIONAL           openvrml::sfvec3f &dir = vrml_light->direction_;           myLight->setDirection(osg::Vec3(dir.value[0],dir.value[1],dir.value[2]));           myLight->setPosition(osg::Vec4(dir.value[0],dir.value[1],dir.value[2], 0.0f));                      // add the light in the scenegraph           osg::LightSource* lightS = new osg::LightSource;                   lightS->setLight(myLight);           if (vrml_light->on()) {        lightS->setLocalStateSetModes(osg::StateAttribute::ON);         //lightS->setStateSetModes(*rootStateSet,osg::StateAttribute::ON);             }                      lightGroup->addChild(lightS);           osgLightNum++;           return lightGroup;       } else if(obj->type.id == "PointLight")    // Handle lights       {           osg::Group* lightGroup = new osg::Group;           openvrml::vrml97_node::point_light_node *vrml_light;           vrml_light = dynamic_cast<openvrml::vrml97_node::point_light_node *>(obj);           // create light with global params           osg::Light* myLight = new osg::Light;           myLight->setLightNum(osgLightNum);           //std::cout<<"lightnum = "<<osgLightNum;                      openvrml::sfvec3f &pos = vrml_light->location_;           myLight->setPosition(osg::Vec4(pos.value[0], pos.value[1], pos.value[2], 1.0f));                      myLight->setAmbient(osg::Vec4(vrml_light->ambient_intensity(),vrml_light->ambient_intensity(),vrml_light->ambient_intensity(),vrml_light->ambient_intensity()));           float osgR = vrml_light->color().r()*vrml_light->intensity();           float osgG = vrml_light->color().g()*vrml_light->intensity();           float osgB = vrml_light->color().b()*vrml_light->intensity();           myLight->setDiffuse(osg::Vec4(osgR, osgG, osgB, 1.0f));           myLight->setSpecular(osg::Vec4(osgR, osgG, osgB, 1.0f));                      // configure light as POINT           myLight->setDirection(osg::Vec3(0.f,0.f,0.f));                      // add the light in the scenegraph           osg::LightSource* lightS = new osg::LightSource;                   lightS->setLight(myLight);           if (vrml_light->on()) {        lightS->setLocalStateSetModes(osg::StateAttribute::ON);         //lightS->setStateSetModes(*rootStateSet,osg::StateAttribute::ON);             }                      lightGroup->addChild(lightS);           osgLightNum++;           return lightGroup;       } else if(obj->type.id == "SpotLight")    // Handle lights       {           osg::Group* lightGroup = new osg::Group;           openvrml::vrml97_node::spot_light_node *vrml_light;           vrml_light = dynamic_cast<openvrml::vrml97_node::spot_light_node *>(obj);           // create light with global params           osg::Light* myLight = new osg::Light;           myLight->setLightNum(osgLightNum);           myLight->setPosition(osg::Vec4(0.0f, 0.0f, 0.0f, 1.0f));           myLight->setAmbient(osg::Vec4(vrml_light->ambient_intensity(),vrml_light->ambient_intensity(),vrml_light->ambient_intensity(),vrml_light->ambient_intensity()));           float osgR = vrml_light->color().r()*vrml_light->intensity();           float osgG = vrml_light->color().g()*vrml_light->intensity();           float osgB = vrml_light->color().b()*vrml_light->intensity();           myLight->setDiffuse(osg::Vec4(osgR, osgG, osgB, 1.0f));           myLight->setSpecular(osg::Vec4(osgR, osgG, osgB, 1.0f));                      // configure light as SPOT            openvrml::sfvec3f &dir = vrml_light->direction_;           myLight->setDirection(osg::Vec3(dir.value[0],dir.value[1],dir.value[2]));                      // The cutOff value in osg ranges from 0 to 90, we need           // to divide by 2 to avoid openGL error.           //      myLight->setSpotCutoff(ls.fallsize/2.0f);           // The bigger the differens is between fallsize and hotsize           // the bigger the exponent should be.           //      float diff = ls.fallsize - ls.hotsize;           //      myLight->setSpotExponent(diff);                      // add the light in the scenegraph           osg::LightSource* lightS = new osg::LightSource;                   lightS->setLight(myLight);           if (vrml_light->on()) {        lightS->setLocalStateSetModes(osg::StateAttribute::ON);         //lightS->setStateSetModes(*rootStateSet,osg::StateAttribute::ON);             }                      lightGroup->addChild(lightS);           osgLightNum++;           return lightGroup;       }  else {    return NULL;       }    */}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -