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

📄 surface.cpp

📁 最新osg包
💻 CPP
📖 第 1 页 / 共 2 页
字号:
                {                    unit = unitmap[ channel ];                    if (block.get_image_map().clip)                    {                        std::string image_file = block.get_image_map().clip->get_still_filename();                        if (!image_file.empty())                        {                            if (unit >= max_tex_units && max_tex_units > 0)                            {                                osg::notify(osg::WARN) << "Warning: lwosg::Surface: maximum number of texture units (" << max_tex_units << ") has been reached, skipping incoming blocks" << std::endl;                                break;                            }                            osg::ref_ptr<osg::Texture2D> texture = new osg::Texture2D;                            if (force_arb_compression)                                texture->setInternalFormatMode(osg::Texture::USE_ARB_COMPRESSION);                            texture->setImage(osgDB::readImageFile(image_file, db_options));                            texture->setWrap(osg::Texture::WRAP_S, osg_wrap_mode(block.get_image_map().width_wrap));                            texture->setWrap(osg::Texture::WRAP_T, osg_wrap_mode(block.get_image_map().height_wrap));                            texture->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR_MIPMAP_LINEAR);                            texture->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR);                            stateset_->setTextureAttributeAndModes(unit, texture.get());                            osg::ref_ptr<osg::TexEnvCombine> tec = new osg::TexEnvCombine;                            switch (block.get_opacity_type())                            {                                case Block::NORMAL:                                {                                    float s = block.get_opacity_amount();                                    if (unit == 0)                                    {                                        tec->setCombine_RGB(osg::TexEnvCombine::MODULATE);                                        osg::Vec3 color(diffuse_, diffuse_, diffuse_);                                        color = color * s + base_color_ * (1 - s);                                        material->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4(color, 1-transparency_));                                        material->setAmbient(osg::Material::FRONT_AND_BACK, material->getDiffuse(osg::Material::FRONT_AND_BACK));                                        material->setColorMode(osg::Material::OFF);                                    }                                    else                                    {                                        tec->setCombine_RGB(osg::TexEnvCombine::INTERPOLATE);                                        tec->setConstantColor(osg::Vec4(s, s, s, s));                                    }                                }                                break;                                case Block::ADDITIVE:                                    tec->setCombine_RGB(osg::TexEnvCombine::ADD);                                    break;                                case Block::SUBTRACTIVE:                                    osg::notify(osg::WARN) << "Warning: lwosg::Surface: 'Subtractive' blending mode is not supported, falling back to 'Difference' mode" << std::endl;                                case Block::DIFFERENCE:                                    tec->setCombine_RGB(osg::TexEnvCombine::SUBTRACT);                                    break;                                case Block::MULTIPLY:                                    tec->setCombine_RGB(osg::TexEnvCombine::MODULATE);                                    break;                                case Block::DIVIDE:                                    osg::notify(osg::WARN) << "Warning: lwosg::Surface: 'Divide' blending mode is not supported" << std::endl;                                    break;                                case Block::ALPHA:                                    osg::notify(osg::WARN) << "Warning: lwosg::Surface: 'Alpha' blending mode is not supported" << std::endl;                                    break;                                case Block::TEXTURE_DISPLACEMENT:                                    osg::notify(osg::WARN) << "Warning: lwosg::Surface: 'Texture Displacement' blending mode is not supported" << std::endl;                                    break;                                default:                                break;                            };                            stateset_->setTextureAttributeAndModes(unit, tec.get());                            ++unit;                        }                    }                }                else                {                    osg::notify(osg::WARN) << "Warning: lwosg::Surface: texture channels of type '" << block.get_channel() << "' are not supported, this block will be ignored" << std::endl;                }            }        }    }}osg::Group *Surface::apply(osg::Geometry *geo, const VertexMap_map *texture_maps, const VertexMap_map *rgb_maps, const VertexMap_map *rgba_maps, int max_tex_units, bool use_osgfx, bool force_arb_compression, const VertexMap_binding_map &texmap_bindings, const osgDB::ReaderWriter::Options* db_options) const{    int num_points = 0;    if (geo->getVertexArray()) {        num_points = static_cast<int>(geo->getVertexArray()->getNumElements());    }    generate_stateset(max_tex_units, force_arb_compression, db_options);    geo->setStateSet(stateset_.get());    int unit = 0;    for (Block_map::const_iterator i=blocks_.begin(); i!=blocks_.end(); ++i) {        const Block &block = i->second;        if (block.get_type() == "IMAP" && block.get_channel() == "COLR" && block.get_image_map().clip) {            std::string image_file = block.get_image_map().clip->get_still_filename();            if (!image_file.empty()) {                if (block.get_image_map().projection == Image_map::UV) {                    VertexMap_map::const_iterator i = texture_maps->find(block.get_image_map().uv_map);                    if (i != texture_maps->end()) {                        geo->setTexCoordArray(unit, i->second->asVec2Array(num_points));                    } else {                        osg::notify(osg::WARN) << "Warning: lwosg::Surface: surface '" << name_ << "' needs texture map named '" << block.get_image_map().uv_map << "' but I can't find it" << std::endl;                    }                }                ++unit;            }        }    }    for (VertexMap_binding_map::const_iterator vi=texmap_bindings.begin(); vi!=texmap_bindings.end(); ++vi)    {        for (VertexMap_map::const_iterator j=texture_maps->begin(); j!=texture_maps->end(); ++j)        {            if (j->first == vi->first)            {                if (geo->getTexCoordArray(vi->second) != 0)                {                    osg::notify(osg::WARN) << "Warning: lwosg::Surface: explicing binding of texture map '" << vi->first << "' to texunit " << vi->second << " will replace existing texture map" << std::endl;                }                geo->setTexCoordArray(vi->second, j->second->asVec2Array(num_points));            }            else            {                osg::notify(osg::WARN) << "Warning: lwosg::Surface: explicit binding of texture map '" << vi->first << "' to texunit " << vi->second << " was requested but there is no such map in this LWO file" << std::endl;            }        }    }        osg::Vec4 color = osg::Vec4(base_color_, 1-transparency_);    const VertexMap_map *color_maps = 0;    if (color_map_type_ == "RGB ") {        color_maps = rgb_maps;    }    if (color_map_type_ == "RGBA") {        color_maps = rgba_maps;    }    if (color_maps) {        VertexMap_map::const_iterator i = color_maps->find(color_map_name_);        if (i != color_maps->end() && !i->second->empty()) {            geo->setColorArray(i->second->asVec4Array(num_points, color * color_map_intensity_, color * color_map_intensity_));            geo->setColorBinding(osg::Geometry::BIND_PER_VERTEX);        } else {            osg::notify(osg::WARN) << "Warning: lwosg::Surface: surface '" << name_ << "' needs color map named '" << color_map_name_ << "' but I can't find it" << std::endl;        }    }    // create osgFX specularity if needed    if (use_osgfx && glossiness_ > 0 && specularity_ > 0) {        if (unit >= max_tex_units && max_tex_units > 0) {            osg::notify(osg::WARN) << "Warning: lwosg::Surface: can't apply osgFX specular lighting: maximum number of texture units (" << max_tex_units << ") has been reached" << std::endl;        } else {            osg::ref_ptr<osgFX::SpecularHighlights> sh = new osgFX::SpecularHighlights;            sh->setTextureUnit(unit);            osg::Material *material = dynamic_cast<osg::Material *>(stateset_->getAttribute(osg::StateAttribute::MATERIAL));            if (material) {                sh->setSpecularColor(material->getSpecular(osg::Material::FRONT_AND_BACK));                sh->setSpecularExponent(powf(2, 10 * glossiness_ + 2));                material->setSpecular(osg::Material::FRONT_AND_BACK, osg::Vec4(0, 0, 0, 0));                material->setShininess(osg::Material::FRONT_AND_BACK, 0);            }            return sh.release();        }    }    return 0;}

⌨️ 快捷键说明

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