• osg fbx模型点击节点,对应节点染色


    class CPickHandler :public osgGA::GUIEventHandler
    {
    public:
        CPickHandler(osgViewer::Viewer *viewer) :mViewer(viewer) {}
        virtual bool handle(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa)
        {
            switch (ea.getEventType())
            {
            //case osgGA::GUIEventAdapter::PUSH:
            case osgGA::GUIEventAdapter::DOUBLECLICK:
                if (ea.getButton() == 1)
                {
                    Pick(ea.getX(), ea.getY());//可通过事件ea获得鼠标点击的坐标  
                }
                return true;
            }
            return false;
        }
    protected:
        void Pick(float x, float y)
        {
            osgUtil::LineSegmentIntersector::Intersections intersections;//声明一个相交测试的结果集  
            if (mViewer->computeIntersections(x, y, intersections))//利用view的computerIntersection函数来测试屏幕与场景相交结果存入到结果集中  
            {
                osgUtil::LineSegmentIntersector::Intersections::iterator hitr = intersections.begin();
                for (; hitr != intersections.end(); hitr++)
                {
                    if (!hitr->nodePath.empty() && !(hitr->nodePath.back()->getName().empty()))
                    {
                        
                        const osg::NodePath& np = hitr->nodePath;
                        //for (int i = np.size() - 1; i >= 0; --i)
                        //{
                            osg::Node *sc = hitr->nodePath.at(np.size() - 1);
                            //将场景中的模型动态转换为Scribe类型,如果场景的模型中有Scribe节点则返回的是实际的模型Scribe对象  
                            //osgFX::Scribe *sc = dynamic_cast<osgFX::Scribe*>(np[i]);
                            //osg::Node *sc = dynamic_cast<osg::Node*>(np[i]);
                            if (sc != NULL)//如果找到相应的sc,则隐藏起来  
                            {
                                //if (sc->getNodeMask() != 0)
                                //{
                                //    sc->setNodeMask(0);
                                //}
                                setNodeStateset(sc);
                            }
                        //}
                    }
                }
            }
        }
        osgViewer::Viewer *mViewer;
    };

  • 相关阅读:
    多表链接 Left join
    v2013调试无法访问此网站 localhost 拒绝了我们的连接请求
    随机不重复流水号。
    通过location对象的某些属性得到一个完整URL的各个部分。
    Vue.JS学习笔记
    前端名词录
    React学习札记一
    kraken-ejs创建一个项目【学习札记】
    express 学习札记
    nth-child & nth-of-type区别
  • 原文地址:https://www.cnblogs.com/herd/p/11148008.html
Copyright © 2020-2023  润新知