1、用notepad++模型的obj格式文件,查找到模型各个部分的名称,命名规则:g mesh......,把名字改为规则命名。
 2、选择处理
#ifdef _DEBUG
#pragma comment(lib,"osgGAd.lib")
#pragma comment(lib,"osgViewerd.lib")
#pragma comment(lib,"osgDBd.lib")
#pragma comment(lib,"OpenThreadsd.lib")
#pragma comment(lib,"osgd.lib")
#pragma comment(lib,"osgWidgetd.lib")
#pragma comment(lib,"osgTextd.lib")
#pragma comment(lib,"osgManipulatord.lib")
#pragma comment(lib,"osgUtild.lib")
#pragma comment(lib,"osgParticled.lib")
#else
#pragma comment(lib,"osgGA.lib")
#pragma comment(lib,"osgViewer.lib")
#pragma comment(lib,"osgDB.lib")
#pragma comment(lib,"OpenThreads.lib")
#pragma comment(lib,"osg.lib")
#pragma comment(lib,"osgWidget.lib")
#pragma comment(lib,"osgText.lib")
#pragma comment(lib,"osgManipulator.lib")
#pragma comment(lib,"osgUtil.lib")
#pragma comment(lib,"osgParticle.lib")
#endif
#include <osgViewer/Viewer>
#include <osgGA/GUIEventHandler>
#include <osg/Group>
#include <osg/MatrixTransform>
#include <osg/Material>
#include <osgDB/ReadFile>
#include <osgUtil/LineSegmentIntersector>
#include <osg/ShapeDrawable>
#include <osgText/Text>
#include <vector>
osg::ref_ptr<osg::Node> cow;
class CPickHandler : public osgGA::GUIEventHandler{
osgViewer::Viewer * mViewer;
osg::Group * mGroup;
osg::Node * lastSelect;
public:
CPickHandler(osgViewer::Viewer * viewer, osg::Group *group) :mViewer(viewer),mGroup(group),lastSelect(){}
virtual bool handle(const osgGA::GUIEventAdapter & ea, osgGA::GUIActionAdapter & aa){
switch(ea.getEventType()){
case(osgGA::GUIEventAdapter::PUSH):{
if(lastSelect){
//osg::StateSet * state = lastSelect->getOrCreateStateSet();
//state->setMode(GL_BLEND, osg::StateAttribute::ON);
/*osg::ref_ptr<osg::Material> material = new osg::Material();
material->setTransparency(osg::Material::FRONT_AND_BACK, 1.0);
material->setEmission(osg::Material::FRONT_AND_BACK, osg::Vec4(1.0,0.0,0.0,1.0));
alarmSphere->getOrCreateStateSet()->setAttributeAndModes(material,osg::StateAttribute::ON);*/
//osg::Material * mtrl = dynamic_cast<osg::Material *>(state->getAttribute(osg::StateAttribute::MATERIAL));
//mtrl->setEmission(osg::Material::FRONT_AND_BACK, osg::Vec4(1.0, 1.0, 1.0, 1.0));
//state->setAttributeAndModes(mtrl, osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
//state->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
lastSelect = ;
}
Pick(ea.getX(),ea.getY()); //获得单击的鼠标坐标
}
return true;
}
return false;
}
protected:
void Pick(float x, float y){ 在pick函数中写触发函数
osgUtil::LineSegmentIntersector::Intersections intersections;
if(mViewer->computeIntersections(x, y, intersections)){
for(osgUtil::LineSegmentIntersector::Intersections::iterator hitr = intersections.begin(); hitr!= intersections.end(); ++hitr){
if(!hitr->nodePath.empty() && !(hitr->nodePath.back()->getName().empty())){
const osg::NodePath& np = hitr->nodePath;
for(int i = np.size() - ; i >= ; --i){
osg::Node* nd = dynamic_cast<osg::Node *> (np[i]);
if(nd){
//std::cout<< "************"<<std::endl;
std::cout << nd->getName() <<std::endl;
std::cout << np.size() <<std::endl;
if(nd->getName()=="Mesh12 Group4 Group1 Model"||nd->getName() == "Mesh18 Group6 Group1 Model"||nd->getName() == "Mesh6 Group2 Group1 Model"||nd->getName() == "Mesh16 Group6 Group1 Model"||nd->getName() == "Mesh10 Group4 Group1 Model"||nd->getName() == "Mesh4 Group2 Group1 Model"){
//osg::StateSet * state = nd->getOrCreateStateSet();
//state->setMode(GL_BLEND, osg::StateAttribute::ON);
//osg::Material *mtrl = dynamic_cast<osg::Material *>(state->getAttribute(osg::StateAttribute::MATERIAL));
//if(!mtrl){
//mtrl = new osg::Material;
//}
//osg::ref_ptr<osg::Material> material = new osg::Material();
//material->setTransparency(osg::Material::FRONT_AND_BACK, 0.5);
//material->setEmission(osg::Material::FRONT_AND_BACK, osg::Vec4(1.0,0.0,0.0,1.0));
//alarmSphere->getOrCreateStateSet()->setAttributeAndModes(material,osg::StateAttribute::ON);
////nd->setNodeMask(false);
//mtrl->setEmission(osg::Material::FRONT_AND_BACK, osg::Vec4(1.0, 0.0, 0.0, 1.0));
//state->setAttributeAndModes(mtrl, osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
//state->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
osg::Vec3 eye, center, up; //改变视角代码段
center = cow->computeBound()._center;
eye = center;
eye[] += cow->computeBound()._radius * ;
up.set( .f, .f, .f );
osg::Matrix mt;
mt.makeLookAt( eye, center, up );
mViewer->getCameraManipulator()->setByInverseMatrix( mt );
lastSelect = nd;
}
return ;
}
}
}
}
}
return ;
}
};
void main(){
osgViewer::Viewer viewer;
osg::ref_ptr<osg::Group> root = new osg::Group();
osg::ref_ptr<osg::MatrixTransform> mt = new osg::MatrixTransform;
cow = osgDB::readNodeFile("D:\\information of buaa\\LAST CHANCE\\lab\\NewModels\\toUse\\pipelineTeam_3_boiler2\\pipelineTeam1.ive");
//osg::ref_ptr<osg::Node> cow = osgDB::readNodeFile("cow.osg");
cow->setName("officeBuilding");
mt->addChild(cow);
mt->setName("officeBuilding");
root->addChild(mt);
//root->getChild(0);
//std::cout<< root->getChild(2)->getName() << std::endl;
/*osg::ref_ptr<osg::MatrixTransform> mtRobot = new osg::MatrixTransform;
osg::ref_ptr<osg::Node> robot = osgDB::readNodeFile("robot.osg");
mtRobot->setMatrix(osg::Matrix::translate(20,0,0));
robot->setName("robot");
mtRobot->addChild(robot);
root->addChild(mtRobot);*/
//std::cout << root->getChild(0)->getName() << std::endl;
//osg::ref_ptr<osg::Plane> Plane (new osg::Plane());
/*osg::ShapeDrawable *shapeBall=new osg::ShapeDrawable(new osg::Box(mt->computeBound()._center, mt->computeBound()._radius/3, mt->computeBound()._radius/10, mt->computeBound()._radius/3));
osg::ref_ptr<osg::Material> material = new osg::Material();
material->setTransparency(osg::Material::FRONT_AND_BACK, 1.0);
material->setEmission(osg::Material::FRONT_AND_BACK, osg::Vec4(1.0,0.0,0.0,1.0));
alarmSphere->getOrCreateStateSet()->setAttributeAndModes(material,osg::StateAttribute::ON);
alarmSphere->getOrCreateStateSet()->setMode(GL_BLEND,osg::StateAttribute::ON);
alarmSphere->getOrCreateStateSet()->setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF);
alarmSphere->addDrawable(shapeBall);
root->addChild(alarmSphere);
*/
viewer.setSceneData(root.get());
viewer.addEventHandler(new CPickHandler(&viewer, root));
viewer.realize();
viewer.run();
return ;
}

3D项目处理点选操作步骤的更多相关文章

  1. oa项目环境搭建的操作步骤详解

    dto:多表关联查询用单独建一个类,把查询数据放dto即可 vo:是view的缩写.单独定义一个类

  2. 将项目Demo上传到Github上的操作步骤

    之前我有很多代码直接上传到了CSDN上,主要是因为操作方便,今天我就说说将源码Demo上传到Github上的操作步骤. 首先,你要先确定自己在Github上有自己的账户名,账户邮箱和密码.如果没有可以 ...

  3. Windows2008 R2上完全卸载Oracle操作步骤

    Windows2008 R2上完全卸载Oracle操作步骤 1.关闭Oracle所有的服务,按[win+R]运行[services.msc]找到所有Oracle开头的服务,点击停止. 2.使用Orac ...

  4. Windows7上完全卸载Oracle 12c操作步骤

    注:本文来源于:< Windows7上完全卸载Oracle  12c操作步骤 > 1.关闭Oracle所有的服务,按[win+R]运行[services.msc]找到所有Oracle开头的 ...

  5. MFC绘图基础——上机操作步骤

    一.上机之前的介绍 软件环境:VC++6.0 目的:熟悉基本的MFC框架搭建和了解界面 二.MFC上机操作步骤 1,在Windows桌面上运行VC++6.0. 2,新建项目工程文件. 3,在MFC 应 ...

  6. Windows2008 R2上完全卸载Oracle操作步骤(转)

    最近现场项目,碰到了好几次oracle数据库被损坏,而且无法恢复的问题,没办法,只好卸载重装了.oracle卸载确实麻烦,都是从网上查的方法, 为了方便以后查询,在此就做一下记录. Windows20 ...

  7. 《Asp.Net Core3 + Vue3入坑教程》-Net Core项目搭建与Swagger配置步骤

    简介 <Asp.Net Core3 + Vue3入坑教程> 此教程仅适合新手入门或者前后端分离尝试者.可以根据图文一步一步进操作编码也可以选择直接查看源码.每一篇文章都有对应的源码 教程后 ...

  8. 物理机连接虚拟机中的数据库及Windows添加防火墙允许端口详细操作步骤

    公司项目中因为会使用到SQL server数据库,但是自己电脑无论安装2008R2或者2014版本都不成功,我想可能是和之前安装的一些Windows的软件存在冲突. 于是便单独创建了一台虚拟机,在虚拟 ...

  9. ABP创建数据库操作步骤

    1 ABP创建数据库操作步骤 1.1 SimpleTaskSystem.Web项目中的Web.config文件修改数据库配置. <add name="Default" pro ...

随机推荐

  1. 【.Net】从.NET平台调用Win32 API

    小序        Win32 API可以直接控制Microsoft Windows的核心,因为API(Application Programming Interface)本来就是微软留给我们直接控制 ...

  2. zoj1108 FatMouse's Speed

    给你每个物体两个参数,求最长的链要求第一个参数递增,第二个参数递减,要求输出任意最长路径. 首先第一反应根据第二个参数排个序,然后不就是最长上升子序列的问题吗? O(nlogn)的复杂度,当然这样可以 ...

  3. SurfaceView绘图机制

    一.为什么需要用SurfaceView绘图,不直接继承View绘图 它的特性是:可以在主线程之外的线程中向屏幕绘图上.这样可以避免画图任务繁重的时候造成主线程阻塞,从而提高了程序的反应速度.在游戏开发 ...

  4. 浅谈局域网ARP攻击的危害及防范方法(图)

    浅谈局域网ARP攻击的危害及防范方法(图)   作者:冰盾防火墙 网站:www.bingdun.com 日期:2015-03-03   自 去年5月份开始出现的校内局域网频繁掉线等问题,对正常的教育教 ...

  5. java代码收藏:获取HttpServletRequest中某一前缀的参数

    public static Map getParametersStartingWith(ServletRequest request, String prefix) { Enumeration par ...

  6. docker 创建新的镜像到私有仓库

    docker:/data# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES bd6db4127a9e centos &q ...

  7. GDOI模拟赛Round 1

    GDOI模拟赛Round 1 数据结构 题目描述:给出一个长度为\(n\)的序列,支持两种操作: 1.对某段区间都加上一个数 2.给出\(p.k\),求下面表示式对\((10^9+7)\)取模 \[\ ...

  8. nginx-gridfs 的安装配置和使用

    (一)安装nginx前的准备 安装nginx需要安装openssl和pcre,具体安装步骤请参考nginx安装的相关博文 (二)nginx和nginx-gridfs 联合编译安装 nginx-grid ...

  9. python cmd 模块

    command模块用于执行以字符串形式指定的简单系统命令,并将其输出以字符串形式返回.此模块尽在unix系统上有效.这个模型提供的功能与在unix shell脚本使用的反引号(就是~这个键下的那个反引 ...

  10. paip.QQ音乐导出歌单总结

    paip.QQ音乐导出歌单总结 作者Attilax ,  EMAIL:1466519819@qq.com  来源:attilax的专栏 地址:http://blog.csdn.net/attilax ...