00001 /*---------------------------------------------------------------------------*\ 00002 * OpenSG * 00003 * * 00004 * * 00005 * Copyright (C) 2000-2002 by the OpenSG Forum * 00006 * * 00007 * www.opensg.org * 00008 * * 00009 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de * 00010 * * 00011 \*---------------------------------------------------------------------------*/ 00012 /*---------------------------------------------------------------------------*\ 00013 * License * 00014 * * 00015 * This library is free software; you can redistribute it and/or modify it * 00016 * under the terms of the GNU Library General Public License as published * 00017 * by the Free Software Foundation, version 2. * 00018 * * 00019 * This library is distributed in the hope that it will be useful, but * 00020 * WITHOUT ANY WARRANTY; without even the implied warranty of * 00021 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00022 * Library General Public License for more details. * 00023 * * 00024 * You should have received a copy of the GNU Library General Public * 00025 * License along with this library; if not, write to the Free Software * 00026 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * 00027 * * 00028 \*---------------------------------------------------------------------------*/ 00029 /*---------------------------------------------------------------------------*\ 00030 * Changes * 00031 * * 00032 * * 00033 * * 00034 * * 00035 * * 00036 * * 00037 \*---------------------------------------------------------------------------*/ 00038 00039 00040 #ifndef _OSGMAKETRANSPARENTGRAPHOP_H_ 00041 #define _OSGMAKETRANSPARENTGRAPHOP_H_ 00042 #ifdef __sgi 00043 #pragma once 00044 #endif 00045 00046 #include <list> 00047 #include <map> 00048 00049 #include <OSGConfig.h> 00050 00051 #include <OSGSystemDef.h> 00052 #include <OSGGraphOp.h> 00053 #include <OSGAction.h> 00054 #include <OSGGeometry.h> 00055 #include <OSGMaterialGroup.h> 00056 00057 OSG_BEGIN_NAMESPACE 00058 00059 class OSG_SYSTEMLIB_DLLMAPPING MakeTransparentGraphOp : public GraphOp 00060 { 00061 public: 00062 class MaterialObject 00063 { 00064 public: 00065 MaterialObject(GeometryPtr geo) 00066 { 00067 _geo = geo; 00068 } 00069 00070 MaterialObject(MaterialGroupPtr mg) 00071 { 00072 _mg = mg; 00073 } 00074 00075 MaterialPtr getMaterial() 00076 { 00077 return (_geo != osg::NullFC 00078 ? _geo->getMaterial() 00079 : _mg->getMaterial()); 00080 } 00081 00082 void setMaterial(MaterialPtr mat) 00083 { 00084 if (_geo != osg::NullFC) 00085 { 00086 beginEditCP(_geo); 00087 _geo->setMaterial(mat); 00088 endEditCP(_geo); 00089 } 00090 else 00091 { 00092 beginEditCP(_mg); 00093 _mg->setMaterial(mat); 00094 endEditCP(_mg); 00095 } 00096 } 00097 00098 private: 00099 GeometryPtr _geo; 00100 MaterialGroupPtr _mg; 00101 }; 00102 00103 static const char *getClassname(void) { return "MakeTransparentGraphOp"; }; 00104 00105 MakeTransparentGraphOp(const char* name = "MakeTransparent"); 00106 00107 GraphOp* create(); 00108 00109 bool traverse(NodePtr& node); 00110 00111 void setParams(const std::string params); 00112 00113 std::string usage(void); 00114 00115 private: 00116 Action::ResultE traverseEnter(NodePtr& node); 00117 Action::ResultE traverseLeave(NodePtr& node, Action::ResultE res); 00118 00119 void addObject(MaterialObject m); 00120 void applyTransparency(MaterialPtr m); 00121 00122 typedef std::list<MaterialObject> MaterialObjectList; 00123 typedef std::map<MaterialPtr, MaterialObjectList> MaterialObjectMap; 00124 00125 MaterialObjectMap _materialObjects; 00126 00127 Real32 _transparency; 00128 }; 00129 00130 OSG_END_NAMESPACE 00131 00132 #endif
1.4.3