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. Jquery 解决 H5 placeholder元素问题

    <style type="text/css"> .placeholder{ color: #cacaca; } </style> <script ty ...

  2. 转发:使用sql命令查询视图中所有引用的基础表

    转自:使用sql命令查询视图中所有引用的基础表 使用sql命令查询视图中所有引用的基础表 之前有写过如何利用sql查询视图中所有引用的表发现这个方法并不能查出视图中所有的基础表,如果视图中有嵌套视图就 ...

  3. 从ASP.NET传递参数给水晶报表

    原文 http://www.cnblogs.com/insus/p/3281114.html 上次Insus.NET有简单写了一篇文章<Visual Studio 2012使用水晶报表Cryst ...

  4. aix5.1 5.2 5.3 6.1 7.1运维技术总结

    ++++++++++++++++++++++++++++ + Ruiy 20014-10 zz + +Technology Area; + Tel:150 55198367 + QQ:5160 591 ...

  5. linux下主要是VirtualBox及GuestAdditions的安装

    Linux版本的VirtualBox下载:http://www.virtualbox.org/wiki/Linux_Downloads.请下载对应的版本. RedHat.RHEL:rpm -i vh ...

  6. Python学习笔记6-异常捕获取

    #--encoding:utf-8-- try: float('abc') except Exception,e: print e try: float(1.2) except Exception,e ...

  7. javascript数组去重算法-----2

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. leetCode 31.Next Permutation (下一个字典序排序) 解题思路和方法

    Next Permutation  Implement next permutation, which rearranges numbers into the lexicographically ne ...

  9. Clojure 学习入门(19)—— 数组

    1.创建数组 1.1 从集合创建数组 into-array into-array (into-array aseq) (into-array type aseq) 演示样例: user=> (i ...

  10. 垃圾回收算法简单介绍——JVM读书笔记&lt;二&gt;

    垃圾回收的过程主要包含两部分:找出已死去的对象.移除已死去的对象. 确定哪些对象存活有两种方式:引用计数算法.可达性分析算法. 方案一:引用计数算法 给对象中加入一个引用计数器.每当有一个地方引用它时 ...