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

📄 object.cpp

📁 最新osg包
💻 CPP
📖 第 1 页 / 共 2 页
字号:
                        polygon.indices().push_back(index);                        current_layer.units().back().shares().at(index).push_back(current_layer.units().back().polygons().size());                    }                }                current_layer.units().back().polygons().push_back(polygon);            }        }        const lwo2::FORM::TAGS *tags = dynamic_cast<const lwo2::FORM::TAGS *>(*i);        if (tags) {            tag_strings = tags->tag_string;        }        const lwo2::FORM::PTAG *ptag = dynamic_cast<const lwo2::FORM::PTAG *>(*i);        if (ptag && !current_layer.units().empty()) {            std::string type(ptag->type.id, 4);            if (type == "SURF") {                for (lwo2::FORM::PTAG::Mapping_list::const_iterator i=ptag->mapping.begin(); i!=ptag->mapping.end(); ++i) {                    current_layer.units().back().polygons().at(i->poly.index).set_surface(&surfaces_[tag_strings.at(i->tag)]);                }            }            if (type == "PART") {                for (lwo2::FORM::PTAG::Mapping_list::const_iterator i=ptag->mapping.begin(); i!=ptag->mapping.end(); ++i) {                    current_layer.units().back().polygons().at(i->poly.index).set_part_name(tag_strings.at(i->tag));                }            }            if (type == "SMGP") {                for (lwo2::FORM::PTAG::Mapping_list::const_iterator i=ptag->mapping.begin(); i!=ptag->mapping.end(); ++i) {                    current_layer.units().back().polygons().at(i->poly.index).set_smoothing_group(tag_strings.at(i->tag));                }            }        }        const lwo2::FORM::VMAD *vmad = dynamic_cast<const lwo2::FORM::VMAD *>(*i);        if (vmad && !current_layer.units().empty()) {            std::string type(vmad->type.id, 4);            if (type == "WGHT") {                if (vmad->dimension != 1) {                    osg::notify(osg::WARN) << "Warning: Lwo2Object: invalid " << type << " discontinuous vertex map dimension: " << vmad->dimension << std::endl;                    continue;                }                for (lwo2::FORM::VMAD::Mapping_list::const_iterator i=vmad->mapping.begin(); i!=vmad->mapping.end(); ++i) {                    VertexMap *this_map = current_layer.units().back().polygons().at(i->poly.index).weight_maps()->getOrCreate(vmad->name);                    (*this_map)[i->vert.index] = osg::Vec4(i->value.at(0), 0, 0, 0);                }                            }            if (type == "TXUV") {                if (vmad->dimension != 2) {                    osg::notify(osg::WARN) << "Warning: Lwo2Object: invalid " << type << " discontinuous vertex map dimension: " << vmad->dimension << std::endl;                    continue;                }                for (lwo2::FORM::VMAD::Mapping_list::const_iterator i=vmad->mapping.begin(); i!=vmad->mapping.end(); ++i) {                    VertexMap *this_map = current_layer.units().back().polygons().at(i->poly.index).texture_maps()->getOrCreate(vmad->name);                    (*this_map)[i->vert.index] = osg::Vec4(i->value.at(0), i->value.at(1), 0, 0);                }                            }            if (type == "RGB ") {                if (vmad->dimension != 3) {                    osg::notify(osg::WARN) << "Warning: Lwo2Object: invalid " << type << " discontinuous vertex map dimension: " << vmad->dimension << std::endl;                    continue;                }                for (lwo2::FORM::VMAD::Mapping_list::const_iterator i=vmad->mapping.begin(); i!=vmad->mapping.end(); ++i) {                    VertexMap *this_map = current_layer.units().back().polygons().at(i->poly.index).rgb_maps()->getOrCreate(vmad->name);                    (*this_map)[i->vert.index] = osg::Vec4(i->value.at(0), i->value.at(1), i->value.at(2), 1);                }                            }            if (type == "RGBA") {                if (vmad->dimension != 4) {                    osg::notify(osg::WARN) << "Warning: Lwo2Object: invalid " << type << " discontinuous vertex map dimension: " << vmad->dimension << std::endl;                    continue;                }                for (lwo2::FORM::VMAD::Mapping_list::const_iterator i=vmad->mapping.begin(); i!=vmad->mapping.end(); ++i) {                    VertexMap *this_map = current_layer.units().back().polygons().at(i->poly.index).rgba_maps()->getOrCreate(vmad->name);                    (*this_map)[i->vert.index] = osg::Vec4(i->value.at(0), i->value.at(1), i->value.at(2), i->value.at(3));                }                            }        }        const lwo2::FORM::DESC *desc = dynamic_cast<const lwo2::FORM::DESC *>(*i);        if (desc) {            description_ = desc->description_line;        }        const lwo2::FORM::TEXT *text = dynamic_cast<const lwo2::FORM::TEXT *>(*i);        if (text) {            comment_ = text->comment;        }    }    if (!current_layer.units().empty() || current_layer.get_layer_chunk()) {        layers_[current_layer.number()] = current_layer;    }}void Object::generate_normals(){    for (Layer_map::iterator i=layers_.begin(); i!=layers_.end(); ++i) {        for (Layer::Unit_list::iterator j=i->second.units().begin(); j!=i->second.units().end(); ++j) {            j->generate_normals();        }    }}void Object::generate_auto_texture_maps(){    for (Surface_map::iterator i=surfaces_.begin(); i!=surfaces_.end(); ++i) {        for (Surface::Block_map::iterator j=i->second.blocks().begin(); j!=i->second.blocks().end(); ++j) {            Block &block = j->second;            if (block.get_type() == "IMAP") {                if (block.get_image_map().projection == Image_map::UV) continue;                Image_map::Axis_type axis = block.get_image_map().axis;                std::ostringstream oss;                oss << "Auto_map_" << &block;                std::string map_name = oss.str();                osg::notify(osg::DEBUG_INFO) << "DEBUG INFO: lwosg::Object: creating automatic texture map '" << map_name << "'\n";                for (Layer_map::iterator k=layers_.begin(); k!=layers_.end(); ++k) {                    for (Layer::Unit_list::iterator h=k->second.units().begin(); h!=k->second.units().end(); ++h) {                        osg::ref_ptr<VertexMap> new_map = new VertexMap;                        (*h->texture_maps())[map_name] = new_map.get();                        if (block.get_image_map().projection == Image_map::FRONT_PROJECTION) {                            osg::notify(osg::WARN) << "Warning: lwosg::Object: front projection is not supported" << std::endl;                        }                        if (block.get_image_map().projection == Image_map::CUBIC) {                            for (Unit::Polygon_list::iterator p=h->polygons().begin(); p!=h->polygons().end(); ++p) {                                Polygon &poly = *p;                                osg::ref_ptr<VertexMap> local_uv_map = poly.texture_maps()->getOrCreate(map_name);                                osg::Vec3 N = csf_->fix_vector(poly.face_normal(h->points()));                                Image_map::Axis_type axis = Image_map::X;                                if (N.y() > N.x() && N.y() > N.z()) axis = Image_map::Y;                                if (-N.y() > N.x() && -N.y() > N.z()) axis = Image_map::Y;                                if (N.z() > N.x() && N.z() > N.y()) axis = Image_map::Z;                                if (-N.z() > N.x() && -N.z() > N.y()) axis = Image_map::Z;                                for (Polygon::Index_list::iterator i=poly.indices().begin(); i!=poly.indices().end(); ++i) {                                    // fetch vertex                                    osg::Vec3 P = csf_->fix_point((*h->points())[*i]);                                    // setup scale/translation/rotation                                    P = block.setup_texture_point(P);                                    osg::Vec2 uv;                                    switch (axis) {                                        case Image_map::X: uv.set(P.z(), P.y()); break;                                        case Image_map::Y: uv.set(P.x(), P.z()); break;                                        case Image_map::Z: uv.set(P.x(), P.y()); break;                                        default: ;                                    }                                    uv += osg::Vec2(0.5f, 0.5f);                                    osg::Vec4 map_value(uv.x(), uv.y(), 0, 0);                                    if ((new_map->find(*i) != new_map->end()) && (map_value != (*new_map.get())[*i])) {                                        (*local_uv_map.get())[*i] = map_value;                                    } else {                                        (*new_map.get())[*i] = map_value;                                    }                                }                            }                        } else {                            for (unsigned p=0; p<h->points()->size(); ++p) {                                // fetch vertex                                osg::Vec3 P = csf_->fix_point((*h->points())[p]);                                // setup scale/translation/rotation                                P = block.setup_texture_point(P);                                osg::Vec2 uv;                                if (block.get_image_map().projection == Image_map::PLANAR) {                                    switch (axis) {                                        case Image_map::X: uv.set(P.z(), P.y()); break;                                        case Image_map::Y: uv.set(P.x(), P.z()); break;                                        case Image_map::Z: uv.set(P.x(), P.y()); break;                                        default: ;                                    }                                    uv += osg::Vec2(0.5f, 0.5f);                                }                                if (block.get_image_map().projection == Image_map::CYLINDRICAL) {                                    switch (axis) {                                        case Image_map::X: uv.set(cylindrical_angle(-P.z(), -P.y()), P.x()); break;                                        case Image_map::Y: uv.set(cylindrical_angle(P.x(), P.z()), P.y()); break;                                        case Image_map::Z: uv.set(cylindrical_angle(P.x(), -P.y()), P.z()); break;                                        default: ;                                    }                                                                    uv.x() *= block.get_image_map().wrap_amount_w;                                    uv += osg::Vec2(0, 0.5f);                                }                                if (block.get_image_map().projection == Image_map::SPHERICAL) {                                    float r = P.length();                                    if (r != 0) {                                        switch (axis) {                                            case Image_map::X: uv.set(cylindrical_angle(-P.z(), -P.y()), (asinf(P.x()/r) + osg::PI_2) / osg::PI); break;                                            case Image_map::Y: uv.set(cylindrical_angle(P.x(), P.z()), (asinf(P.y()/r) + osg::PI_2) / osg::PI); break;                                            case Image_map::Z: uv.set(cylindrical_angle(P.x(), -P.y()), (asinf(P.z()/r) + osg::PI_2) / osg::PI); break;                                            default: ;                                        }                                    }                                    uv.x() *= block.get_image_map().wrap_amount_w;                                    uv.y() *= block.get_image_map().wrap_amount_h;                                }                                (*new_map.get())[p] = osg::Vec4(uv.x(), uv.y(), 0, 0);                            }                        }                    }                }                block.get_image_map().uv_map = map_name;                block.get_image_map().projection = Image_map::UV;            }        }    }}

⌨️ 快捷键说明

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