| 1 | #include <osg/Notify> |
|---|
| 2 | #include <osg/Group> |
|---|
| 3 | #include <osg/Geode> |
|---|
| 4 | #include <osg/Geometry> |
|---|
| 5 | #include <osg/Texture2D> |
|---|
| 6 | #include <osg/Material> |
|---|
| 7 | #include <osg/TexEnv> |
|---|
| 8 | #include <osg/ref_ptr> |
|---|
| 9 | #include <osg/MatrixTransform> |
|---|
| 10 | |
|---|
| 11 | #include <osgDB/Registry> |
|---|
| 12 | #include <osgDB/FileUtils> |
|---|
| 13 | #include <osgDB/FileNameUtils> |
|---|
| 14 | #include <osgDB/ReadFile> |
|---|
| 15 | |
|---|
| 16 | #include <osgUtil/TriStripVisitor> |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | #include <osg/NodeVisitor> |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | #include "file.h" |
|---|
| 23 | #include "mesh.h" |
|---|
| 24 | #include "material.h" |
|---|
| 25 | #include "vector.h" |
|---|
| 26 | #include "matrix.h" |
|---|
| 27 | #include "node.h" |
|---|
| 28 | #include "quat.h" |
|---|
| 29 | #include "readwrite.h" |
|---|
| 30 | |
|---|
| 31 | #include <stdlib.h> |
|---|
| 32 | #include <string.h> |
|---|
| 33 | |
|---|
| 34 | #include <set> |
|---|
| 35 | #include <map> |
|---|
| 36 | #include <iostream> |
|---|
| 37 | #include <sstream> |
|---|
| 38 | |
|---|
| 39 | using namespace std; |
|---|
| 40 | using namespace osg; |
|---|
| 41 | |
|---|
| 42 | class PrintVisitor : public NodeVisitor |
|---|
| 43 | { |
|---|
| 44 | |
|---|
| 45 | public: |
|---|
| 46 | |
|---|
| 47 | PrintVisitor(std::ostream& out): |
|---|
| 48 | NodeVisitor(NodeVisitor::TRAVERSE_ALL_CHILDREN), |
|---|
| 49 | _out(out) |
|---|
| 50 | { |
|---|
| 51 | _indent = 0; |
|---|
| 52 | _step = 4; |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | inline void moveIn() { _indent += _step; } |
|---|
| 56 | inline void moveOut() { _indent -= _step; } |
|---|
| 57 | inline void writeIndent() |
|---|
| 58 | { |
|---|
| 59 | for(int i=0;i<_indent;++i) _out << " "; |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | virtual void apply(Node& node) |
|---|
| 63 | { |
|---|
| 64 | moveIn(); |
|---|
| 65 | writeIndent(); _out << node.className() <<std::endl; |
|---|
| 66 | traverse(node); |
|---|
| 67 | moveOut(); |
|---|
| 68 | } |
|---|
| 69 | |
|---|
| 70 | virtual void apply(Geode& node) { apply((Node&)node); } |
|---|
| 71 | virtual void apply(Billboard& node) { apply((Geode&)node); } |
|---|
| 72 | virtual void apply(LightSource& node) { apply((Group&)node); } |
|---|
| 73 | virtual void apply(ClipNode& node) { apply((Group&)node); } |
|---|
| 74 | |
|---|
| 75 | virtual void apply(Group& node) { apply((Node&)node); } |
|---|
| 76 | virtual void apply(Transform& node) { apply((Group&)node); } |
|---|
| 77 | virtual void apply(Projection& node) { apply((Group&)node); } |
|---|
| 78 | virtual void apply(Switch& node) { apply((Group&)node); } |
|---|
| 79 | virtual void apply(LOD& node) { apply((Group&)node); } |
|---|
| 80 | |
|---|
| 81 | protected: |
|---|
| 82 | |
|---|
| 83 | PrintVisitor& operator = (const PrintVisitor&) { return *this; } |
|---|
| 84 | |
|---|
| 85 | std::ostream& _out; |
|---|
| 86 | int _indent; |
|---|
| 87 | int _step; |
|---|
| 88 | }; |
|---|
| 89 | |
|---|
| 90 | class ReaderWriter3DS : public osgDB::ReaderWriter |
|---|
| 91 | { |
|---|
| 92 | public: |
|---|
| 93 | |
|---|
| 94 | ReaderWriter3DS(); |
|---|
| 95 | |
|---|
| 96 | virtual const char* className() const { return "3DS Auto Studio Reader"; } |
|---|
| 97 | |
|---|
| 98 | virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) const; |
|---|
| 99 | virtual ReadResult readNode(std::istream& fin, const Options* options) const; |
|---|
| 100 | |
|---|
| 101 | protected: |
|---|
| 102 | ReadResult constructFrom3dsFile(Lib3dsFile *f,const std::string& filename, const Options* options) const; |
|---|
| 103 | |
|---|
| 104 | |
|---|
| 105 | class ReaderObject |
|---|
| 106 | { |
|---|
| 107 | public: |
|---|
| 108 | ReaderObject(); |
|---|
| 109 | |
|---|
| 110 | typedef std::map<std::string,osg::StateSet*> StateSetMap; |
|---|
| 111 | typedef std::vector<int> FaceList; |
|---|
| 112 | typedef std::map<std::string,osg::StateSet*> GeoStateMap; |
|---|
| 113 | |
|---|
| 114 | osg::Texture2D* createTexture(Lib3dsTextureMap *texture,const char* label,bool& transparancy, const osgDB::ReaderWriter::Options* options); |
|---|
| 115 | osg::StateSet* createStateSet(Lib3dsMaterial *materials, const osgDB::ReaderWriter::Options* options); |
|---|
| 116 | osg::Drawable* createDrawable(Lib3dsMesh *meshes,FaceList& faceList, Lib3dsMatrix* matrix); |
|---|
| 117 | |
|---|
| 118 | std::string _directory; |
|---|
| 119 | bool _useSmoothingGroups; |
|---|
| 120 | bool _usePerVertexNormals; |
|---|
| 121 | |
|---|
| 122 | |
|---|
| 123 | osg::Node* processMesh(StateSetMap& drawStateMap,osg::Group* parent,Lib3dsMesh* mesh, Lib3dsMatrix* matrix); |
|---|
| 124 | osg::Node* processNode(StateSetMap drawStateMap,Lib3dsFile *f,Lib3dsNode *node); |
|---|
| 125 | }; |
|---|
| 126 | }; |
|---|
| 127 | |
|---|
| 128 | |
|---|
| 129 | |
|---|
| 130 | REGISTER_OSGPLUGIN(3ds, ReaderWriter3DS) |
|---|
| 131 | |
|---|
| 132 | ReaderWriter3DS::ReaderWriter3DS() |
|---|
| 133 | { |
|---|
| 134 | supportsExtension("3ds","3D Studio model format"); |
|---|
| 135 | |
|---|
| 136 | setByteOrder(); |
|---|
| 137 | |
|---|
| 138 | #if 0 |
|---|
| 139 | osg::notify(osg::NOTICE)<<"3DS reader sizes:"<<std::endl; |
|---|
| 140 | osg::notify(osg::NOTICE)<<" sizeof(Lib3dsBool)="<<sizeof(Lib3dsBool)<<std::endl; |
|---|
| 141 | osg::notify(osg::NOTICE)<<" sizeof(Lib3dsByte)="<<sizeof(Lib3dsByte)<<std::endl; |
|---|
| 142 | osg::notify(osg::NOTICE)<<" sizeof(Lib3dsWord)="<<sizeof(Lib3dsWord)<<std::endl; |
|---|
| 143 | osg::notify(osg::NOTICE)<<" sizeof(Lib3dsDword)="<<sizeof(Lib3dsDword)<<std::endl; |
|---|
| 144 | osg::notify(osg::NOTICE)<<" sizeof(Lib3dsIntb)="<<sizeof(Lib3dsIntb)<<std::endl; |
|---|
| 145 | osg::notify(osg::NOTICE)<<" sizeof(Lib3dsIntw)="<<sizeof(Lib3dsIntw)<<std::endl; |
|---|
| 146 | osg::notify(osg::NOTICE)<<" sizeof(Lib3dsIntd)="<<sizeof(Lib3dsIntd)<<std::endl; |
|---|
| 147 | osg::notify(osg::NOTICE)<<" sizeof(Lib3dsFloat)="<<sizeof(Lib3dsFloat)<<std::endl; |
|---|
| 148 | osg::notify(osg::NOTICE)<<" sizeof(Lib3dsDouble)="<<sizeof(Lib3dsDouble)<<std::endl; |
|---|
| 149 | osg::notify(osg::NOTICE)<<" sizeof(Lib3dsVector)="<<sizeof(Lib3dsVector)<<std::endl; |
|---|
| 150 | osg::notify(osg::NOTICE)<<" sizeof(Lib3dsTexel)="<<sizeof(Lib3dsTexel)<<std::endl; |
|---|
| 151 | osg::notify(osg::NOTICE)<<" sizeof(Lib3dsQuat)="<<sizeof(Lib3dsQuat)<<std::endl; |
|---|
| 152 | osg::notify(osg::NOTICE)<<" sizeof(Lib3dsMatrix)="<<sizeof(Lib3dsMatrix)<<std::endl; |
|---|
| 153 | osg::notify(osg::NOTICE)<<" sizeof(Lib3dsRgb)="<<sizeof(Lib3dsRgb)<<std::endl; |
|---|
| 154 | osg::notify(osg::NOTICE)<<" sizeof(Lib3dsRgba)="<<sizeof(Lib3dsRgba)<<std::endl; |
|---|
| 155 | #endif |
|---|
| 156 | |
|---|
| 157 | } |
|---|
| 158 | |
|---|
| 159 | ReaderWriter3DS::ReaderObject::ReaderObject() |
|---|
| 160 | { |
|---|
| 161 | _useSmoothingGroups = true; |
|---|
| 162 | _usePerVertexNormals = true; |
|---|
| 163 | } |
|---|
| 164 | |
|---|
| 165 | |
|---|
| 166 | |
|---|
| 167 | |
|---|
| 168 | |
|---|
| 169 | void pad(int level) { |
|---|
| 170 | for(int i=0;i<level;i++) std::cout<<" "; |
|---|
| 171 | } |
|---|
| 172 | void print(Lib3dsMesh *mesh,int level); |
|---|
| 173 | void print(Lib3dsUserData *user,int level); |
|---|
| 174 | void print(Lib3dsNodeData *user,int level); |
|---|
| 175 | void print(Lib3dsObjectData *object,int level); |
|---|
| 176 | void print(Lib3dsNode *node, int level); |
|---|
| 177 | |
|---|
| 178 | void print(Lib3dsMatrix matrix,int level) { |
|---|
| 179 | pad(level); cout << matrix[0][0] <<" "<< matrix[0][1] <<" "<< matrix[0][2] <<" "<< matrix[0][3] << endl; |
|---|
| 180 | pad(level); cout << matrix[1][0] <<" "<< matrix[1][1] <<" "<< matrix[1][2] <<" "<< matrix[1][3] << endl; |
|---|
| 181 | pad(level); cout << matrix[2][0] <<" "<< matrix[2][1] <<" "<< matrix[2][2] <<" "<< matrix[2][3] << endl; |
|---|
| 182 | pad(level); cout << matrix[3][0] <<" "<< matrix[3][1] <<" "<< matrix[3][2] <<" "<< matrix[3][3] << endl; |
|---|
| 183 | } |
|---|
| 184 | void print(Lib3dsMesh *mesh,int level) { |
|---|
| 185 | if (mesh) { |
|---|
| 186 | pad(level); cout << "mesh name " << mesh->name << endl; |
|---|
| 187 | print(mesh->matrix,level); |
|---|
| 188 | } else { |
|---|
| 189 | pad(level); cout << "no mesh " << endl; |
|---|
| 190 | } |
|---|
| 191 | } |
|---|
| 192 | void print(Lib3dsUserData *user,int level) { |
|---|
| 193 | if (user) { |
|---|
| 194 | pad(level); cout << "user data" << endl; |
|---|
| 195 | |
|---|
| 196 | } else { |
|---|
| 197 | pad(level); cout << "no user data" << endl; |
|---|
| 198 | } |
|---|
| 199 | } |
|---|
| 200 | void print(Lib3dsNodeData *node,int level) { |
|---|
| 201 | if (node) { |
|---|
| 202 | pad(level); cout << "node data:" << endl; |
|---|
| 203 | |
|---|
| 204 | print((Lib3dsObjectData *)&node->object,level+1); |
|---|
| 205 | } else { |
|---|
| 206 | pad(level); cout << "no user data" << endl; |
|---|
| 207 | } |
|---|
| 208 | } |
|---|
| 209 | void print(Lib3dsObjectData *object,int level) { |
|---|
| 210 | if (object) { |
|---|
| 211 | pad(level); cout << "objectdata instance [" << object->instance << "]" << endl; |
|---|
| 212 | pad(level); cout << "pivot " << object->pivot[0] <<" "<< object->pivot[1] <<" "<< object->pivot[2] << endl; |
|---|
| 213 | pad(level); cout << "pos " << object->pos[0] <<" "<< object->pos[1] <<" "<< object->pos[2] << endl; |
|---|
| 214 | pad(level); cout << "scl " << object->scl[0] <<" "<< object->scl[1] <<" "<< object->scl[2] << endl; |
|---|
| 215 | pad(level); cout << "rot " << object->rot[0] <<" "<< object->rot[1] <<" "<< object->rot[2] <<" "<< object->rot[3] << endl; |
|---|
| 216 | } else { |
|---|
| 217 | pad(level); cout << "no object data" << endl; |
|---|
| 218 | } |
|---|
| 219 | } |
|---|
| 220 | |
|---|
| 221 | void print(Lib3dsNode *node, int level) { |
|---|
| 222 | |
|---|
| 223 | pad(level); cout << "node name [" << node->name << "]" << endl; |
|---|
| 224 | pad(level); cout << "node id " << node->node_id << endl; |
|---|
| 225 | pad(level); cout << "node parent id " << node->parent_id << endl; |
|---|
| 226 | pad(level); cout << "node matrix:" << endl; |
|---|
| 227 | print(node->matrix,level+1); |
|---|
| 228 | print(&node->data,level); |
|---|
| 229 | print(&node->user,level); |
|---|
| 230 | |
|---|
| 231 | |
|---|
| 232 | for(Lib3dsNode *child=node->childs; child; child=child->next) { |
|---|
| 233 | print(child,level+1); |
|---|
| 234 | } |
|---|
| 235 | |
|---|
| 236 | } |
|---|
| 237 | |
|---|
| 238 | void copyLib3dsMatrixToOsgMatrix(osg::Matrix& osg_matrix, const Lib3dsMatrix lib3ds_matrix) |
|---|
| 239 | { |
|---|
| 240 | osg_matrix.set( |
|---|
| 241 | lib3ds_matrix[0][0],lib3ds_matrix[0][1],lib3ds_matrix[0][2],lib3ds_matrix[0][3], |
|---|
| 242 | lib3ds_matrix[1][0],lib3ds_matrix[1][1],lib3ds_matrix[1][2],lib3ds_matrix[1][3], |
|---|
| 243 | lib3ds_matrix[2][0],lib3ds_matrix[2][1],lib3ds_matrix[2][2],lib3ds_matrix[2][3], |
|---|
| 244 | lib3ds_matrix[3][0],lib3ds_matrix[3][1],lib3ds_matrix[3][2],lib3ds_matrix[3][3]); |
|---|
| 245 | } |
|---|
| 246 | |
|---|
| 247 | |
|---|
| 248 | |
|---|
| 249 | |
|---|
| 250 | osg::Node* ReaderWriter3DS::ReaderObject::processMesh(StateSetMap& drawStateMap,osg::Group* parent,Lib3dsMesh* mesh, Lib3dsMatrix* matrix) { |
|---|
| 251 | typedef std::vector<int> FaceList; |
|---|
| 252 | typedef std::map<std::string,FaceList> MaterialFaceMap; |
|---|
| 253 | MaterialFaceMap materialFaceMap; |
|---|
| 254 | for (unsigned int i=0; i<mesh->faces; ++i) |
|---|
| 255 | { |
|---|
| 256 | materialFaceMap[mesh->faceL[i].material].push_back(i); |
|---|
| 257 | } |
|---|
| 258 | |
|---|
| 259 | if (materialFaceMap.empty()) |
|---|
| 260 | { |
|---|
| 261 | osg::notify(osg::NOTICE)<<"Warning : no triangles assigned to mesh '"<<mesh->name<<"'"<< std::endl; |
|---|
| 262 | return NULL; |
|---|
| 263 | } |
|---|
| 264 | else |
|---|
| 265 | { |
|---|
| 266 | |
|---|
| 267 | osg::Geode* geode = new osg::Geode; |
|---|
| 268 | geode->setName(mesh->name); |
|---|
| 269 | |
|---|
| 270 | for(MaterialFaceMap::iterator itr=materialFaceMap.begin(); |
|---|
| 271 | itr!=materialFaceMap.end(); |
|---|
| 272 | ++itr) |
|---|
| 273 | { |
|---|
| 274 | FaceList& faceList = itr->second; |
|---|
| 275 | |
|---|
| 276 | if (_useSmoothingGroups) |
|---|
| 277 | { |
|---|
| 278 | |
|---|
| 279 | typedef std::map<int,FaceList> SmoothingFaceMap; |
|---|
| 280 | SmoothingFaceMap smoothingFaceMap; |
|---|
| 281 | for (FaceList::iterator flitr=faceList.begin(); |
|---|
| 282 | flitr!=faceList.end(); |
|---|
| 283 | ++flitr) |
|---|
| 284 | { |
|---|
| 285 | smoothingFaceMap[mesh->faceL[*flitr].smoothing].push_back(*flitr); |
|---|
| 286 | } |
|---|
| 287 | |
|---|
| 288 | for(SmoothingFaceMap::iterator sitr=smoothingFaceMap.begin(); |
|---|
| 289 | sitr!=smoothingFaceMap.end(); |
|---|
| 290 | ++sitr) |
|---|
| 291 | { |
|---|
| 292 | |
|---|
| 293 | |
|---|
| 294 | |
|---|
| 295 | FaceList& smoothFaceMap = sitr->second; |
|---|
| 296 | |
|---|
| 297 | osg::Drawable* drawable = createDrawable(mesh,smoothFaceMap,matrix); |
|---|
| 298 | if (drawable) |
|---|
| 299 | { |
|---|
| 300 | drawable->setStateSet(drawStateMap[itr->first]); |
|---|
| 301 | geode->addDrawable(drawable); |
|---|
| 302 | } |
|---|
| 303 | } |
|---|
| 304 | } |
|---|
| 305 | else |
|---|
| 306 | { |
|---|
| 307 | osg::Drawable* drawable = createDrawable(mesh,faceList,matrix); |
|---|
| 308 | if (drawable) |
|---|
| 309 | { |
|---|
| 310 | drawable->setStateSet(drawStateMap[itr->first]); |
|---|
| 311 | geode->addDrawable(drawable); |
|---|
| 312 | } |
|---|
| 313 | } |
|---|
| 314 | } |
|---|
| 315 | |
|---|
| 316 | if (parent) parent->addChild(geode); |
|---|
| 317 | return geode; |
|---|
| 318 | } |
|---|
| 319 | } |
|---|
| 320 | |
|---|
| 321 | |
|---|
| 322 | |
|---|
| 323 | |
|---|
| 324 | |
|---|
| 325 | |
|---|
| 326 | |
|---|
| 327 | |
|---|
| 328 | |
|---|
| 329 | |
|---|
| 330 | |
|---|
| 331 | |
|---|
| 332 | |
|---|
| 333 | |
|---|
| 334 | |
|---|
| 335 | osg::Node* ReaderWriter3DS::ReaderObject::processNode(StateSetMap drawStateMap,Lib3dsFile *f,Lib3dsNode *node) { |
|---|
| 336 | |
|---|
| 337 | osg::Group* group=NULL; |
|---|
| 338 | |
|---|
| 339 | |
|---|
| 340 | |
|---|
| 341 | Lib3dsNode *p; |
|---|
| 342 | for (p=node->childs; p!=0; p=p->next) { |
|---|
| 343 | if (!group) { |
|---|
| 344 | group =new osg::Group; |
|---|
| 345 | if (strcmp(node->name, "$$$DUMMY") == 0) { |
|---|
| 346 | group->setName(node->data.object.instance); |
|---|
| 347 | } else { |
|---|
| 348 | group->setName(node->name); |
|---|
| 349 | } |
|---|
| 350 | } |
|---|
| 351 | group->addChild(processNode(drawStateMap,f,p)); |
|---|
| 352 | } |
|---|
| 353 | |
|---|
| 354 | |
|---|
| 355 | |
|---|
| 356 | Lib3dsMesh *mesh=lib3ds_file_mesh_by_name(f,node->name); |
|---|
| 357 | if (mesh) { |
|---|
| 358 | Lib3dsObjectData* object=&node->data.object; |
|---|
| 359 | Lib3dsMatrix mesh_inverse; |
|---|
| 360 | osg::Matrix osgmatrix; |
|---|
| 361 | |
|---|
| 362 | lib3ds_matrix_copy(mesh_inverse,mesh->matrix); |
|---|
| 363 | lib3ds_matrix_inv(mesh_inverse); |
|---|
| 364 | |
|---|
| 365 | Lib3dsMatrix M,N; |
|---|
| 366 | lib3ds_matrix_identity(M); |
|---|
| 367 | lib3ds_matrix_identity(N); |
|---|
| 368 | lib3ds_matrix_copy(M,node->matrix); |
|---|
| 369 | N[3][0]=-object->pivot[0]; |
|---|
| 370 | N[3][1]=-object->pivot[1]; |
|---|
| 371 | N[3][2]=-object->pivot[2]; |
|---|
| 372 | |
|---|
| 373 | bool pivoted=false; |
|---|
| 374 | if ( (object->pivot[0]!=0.0) || (object->pivot[1]!=0.0) || (object->pivot[2]!=0.0) ) { |
|---|
| 375 | pivoted=true; |
|---|
| 376 | } |
|---|
| 377 | |
|---|
| 378 | |
|---|
| 379 | |
|---|
| 380 | |
|---|
| 381 | |
|---|
| 382 | |
|---|
| 383 | if (pivoted) { |
|---|
| 384 | |
|---|
| 385 | osg::MatrixTransform* T=new osg::MatrixTransform; |
|---|
| 386 | copyLib3dsMatrixToOsgMatrix(osgmatrix, N); |
|---|
| 387 | T->setMatrix(osgmatrix); |
|---|
| 388 | T->setName("3DSPIVOTPOINT: Translate pivotpoint to (world) origin"); |
|---|
| 389 | |
|---|
| 390 | |
|---|
| 391 | |
|---|
| 392 | |
|---|
| 393 | osg::MatrixTransform* R=new osg::MatrixTransform; |
|---|
| 394 | copyLib3dsMatrixToOsgMatrix(osgmatrix, M); |
|---|
| 395 | R->setMatrix(osgmatrix); |
|---|
| 396 | R->setName("3DSPIVOTPOINT: Rotate"); |
|---|
| 397 | |
|---|
| 398 | |
|---|
| 399 | |
|---|
| 400 | |
|---|
| 401 | |
|---|
| 402 | |
|---|
| 403 | |
|---|
| 404 | |
|---|
| 405 | |
|---|
| 406 | |
|---|
| 407 | |
|---|
| 408 | |
|---|
| 409 | |
|---|
| 410 | |
|---|
| 411 | |
|---|
| 412 | |
|---|
| 413 | |
|---|
| 414 | |
|---|
| 415 | if (group) { |
|---|
| 416 | |
|---|
| 417 | group->addChild(R); |
|---|
| 418 | R->addChild(T); |
|---|
| 419 | processMesh(drawStateMap,T,mesh,&mesh_inverse); |
|---|
| 420 | return group; |
|---|
| 421 | } else { |
|---|
| 422 | |
|---|
| 423 | R->addChild(T); |
|---|
| 424 | processMesh(drawStateMap,T,mesh,&mesh_inverse); |
|---|
| 425 | return R; |
|---|
| 426 | } |
|---|
| 427 | } else { |
|---|
| 428 | if(group) { |
|---|
| 429 | |
|---|
| 430 | processMesh(drawStateMap,group,mesh,NULL); |
|---|
| 431 | return group; |
|---|
| 432 | } else { |
|---|
| 433 | |
|---|
| 434 | |
|---|
| 435 | return processMesh(drawStateMap,NULL,mesh,NULL); |
|---|
| 436 | } |
|---|
| 437 | } |
|---|
| 438 | |
|---|
| 439 | } else { |
|---|
| 440 | |
|---|
| 441 | |
|---|
| 442 | return group; |
|---|
| 443 | } |
|---|
| 444 | } |
|---|
| 445 | |
|---|
| 446 | osgDB::ReaderWriter::ReadResult ReaderWriter3DS::readNode(std::istream& fin, const osgDB::ReaderWriter::Options* options) const |
|---|
| 447 | { |
|---|
| 448 | osgDB::ReaderWriter::ReadResult result = ReadResult::FILE_NOT_HANDLED; |
|---|
| 449 | |
|---|
| 450 | std::string optFileName = ""; |
|---|
| 451 | if (options) |
|---|
| 452 | { |
|---|
| 453 | optFileName = options->getPluginStringData("STREAM_FILENAME"); |
|---|
| 454 | } |
|---|
| 455 | |
|---|
| 456 | Lib3dsFile *f = lib3ds_stream_load((iostream *) &fin); |
|---|
| 457 | if (f) |
|---|
| 458 | { |
|---|
| 459 | result = constructFrom3dsFile(f,optFileName,options); |
|---|
| 460 | lib3ds_file_free(f); |
|---|
| 461 | } |
|---|
| 462 | |
|---|
| 463 | return(result); |
|---|
| 464 | } |
|---|
| 465 | |
|---|
| 466 | osgDB::ReaderWriter::ReadResult ReaderWriter3DS::readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) const |
|---|
| 467 | { |
|---|
| 468 | osgDB::ReaderWriter::ReadResult result = ReadResult::FILE_NOT_HANDLED; |
|---|
| 469 | |
|---|
| 470 | std::string ext = osgDB::getLowerCaseFileExtension(file); |
|---|
| 471 | if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; |
|---|
| 472 | |
|---|
| 473 | std::string fileName = osgDB::findDataFile( file, options ); |
|---|
| 474 | if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; |
|---|
| 475 | |
|---|
| 476 | Lib3dsFile *f = lib3ds_file_load(fileName.c_str(),options); |
|---|
| 477 | |
|---|
| 478 | if (f) |
|---|
| 479 | { |
|---|
| 480 | osg::ref_ptr<Options> local_opt = options ? static_cast<Options*>(options->clone(osg::CopyOp::SHALLOW_COPY)) : new Options; |
|---|
| 481 | local_opt->getDatabasePathList().push_front(osgDB::getFilePath(fileName)); |
|---|
| 482 | |
|---|
| 483 | result = constructFrom3dsFile(f,file,local_opt.get()); |
|---|
| 484 | lib3ds_file_free(f); |
|---|
| 485 | } |
|---|
| 486 | |
|---|
| 487 | return result; |
|---|
| 488 | } |
|---|
| 489 | |
|---|
| 490 | osgDB::ReaderWriter::ReadResult ReaderWriter3DS::constructFrom3dsFile(Lib3dsFile *f,const std::string& fileName, const osgDB::ReaderWriter::Options* options) const |
|---|
| 491 | { |
|---|
| 492 | if (f==NULL) return ReadResult::FILE_NOT_HANDLED; |
|---|
| 493 | |
|---|
| 494 | |
|---|
| 495 | |
|---|
| 496 | |
|---|
| 497 | |
|---|
| 498 | lib3ds_file_eval(f,0.0f); |
|---|
| 499 | |
|---|
| 500 | ReaderObject reader; |
|---|
| 501 | |
|---|
| 502 | reader._directory = ( options && !options->getDatabasePathList().empty() ) ? options->getDatabasePathList().front() : osgDB::getFilePath(fileName); |
|---|
| 503 | |
|---|
| 504 | osg::Group* group = new osg::Group; |
|---|
| 505 | group->setName(fileName); |
|---|
| 506 | |
|---|
| 507 | ReaderObject::StateSetMap drawStateMap; |
|---|
| 508 | |
|---|
| 509 | for (Lib3dsMaterial *mat=f->materials; mat; mat=mat->next) |
|---|
| 510 | { |
|---|
| 511 | drawStateMap[mat->name] = reader.createStateSet(mat, options); |
|---|
| 512 | } |
|---|
| 513 | |
|---|
| 514 | if (osg::getNotifyLevel()>=osg::INFO) |
|---|
| 515 | { |
|---|
| 516 | int level=0; |
|---|
| 517 | std::cout << "NODE TRAVERSAL of 3ds file "<<f->name<<std::endl; |
|---|
| 518 | for(Lib3dsNode *node=f->nodes; node; node=node->next) { |
|---|
| 519 | print(node,level+1); |
|---|
| 520 | } |
|---|
| 521 | std::cout << "MESH TRAVERSAL of 3ds file "<<f->name<<std::endl; |
|---|
| 522 | for(Lib3dsMesh *mesh=f->meshes; mesh; mesh=mesh->next) { |
|---|
| 523 | print(mesh,level+1); |
|---|
| 524 | } |
|---|
| 525 | } |
|---|
| 526 | |
|---|
| 527 | |
|---|
| 528 | |
|---|
| 529 | |
|---|
| 530 | bool traverse_nodes=false; |
|---|
| 531 | |
|---|
| 532 | |
|---|
| 533 | |
|---|
| 534 | if (f->nodes == NULL) { |
|---|
| 535 | osg::notify(osg::WARN)<<"Warning: in 3ds loader: file has no nodes, traversing by meshes instead"<< std::endl; |
|---|
| 536 | traverse_nodes=true; |
|---|
| 537 | } |
|---|
| 538 | |
|---|
| 539 | if (traverse_nodes) { |
|---|
| 540 | for (Lib3dsMesh *mesh=f->meshes; mesh; mesh=mesh->next) { |
|---|
| 541 | reader.processMesh(drawStateMap,group,mesh,NULL); |
|---|
| 542 | } |
|---|
| 543 | } else { |
|---|
| 544 | for(Lib3dsNode *node=f->nodes; node; node=node->next) { |
|---|
| 545 | group->addChild(reader.processNode(drawStateMap,f,node)); |
|---|
| 546 | } |
|---|
| 547 | } |
|---|
| 548 | |
|---|
| 549 | if (osg::getNotifyLevel()>=osg::INFO) |
|---|
| 550 | { |
|---|
| 551 | osg::notify(osg::NOTICE) << "Final OSG node structure looks like this:"<< endl; |
|---|
| 552 | PrintVisitor pv(osg::notify(osg::NOTICE)); |
|---|
| 553 | group->accept(pv); |
|---|
| 554 | } |
|---|
| 555 | |
|---|
| 556 | return group; |
|---|
| 557 | } |
|---|
| 558 | |
|---|
| 559 | |
|---|
| 560 | |
|---|
| 561 | |
|---|
| 562 | osg::Drawable* ReaderWriter3DS::ReaderObject::createDrawable(Lib3dsMesh *m,FaceList& faceList,Lib3dsMatrix *matrix) |
|---|
| 563 | { |
|---|
| 564 | |
|---|
| 565 | osg::Geometry* geom = new osg::Geometry; |
|---|
| 566 | |
|---|
| 567 | unsigned int i; |
|---|
| 568 | |
|---|
| 569 | std::vector<int> orig2NewMapping; |
|---|
| 570 | for(i=0;i<m->points;++i) orig2NewMapping.push_back(-1); |
|---|
| 571 | |
|---|
| 572 | unsigned int noVertex=0; |
|---|
| 573 | FaceList::iterator fitr; |
|---|
| 574 | for (fitr=faceList.begin(); |
|---|
| 575 | fitr!=faceList.end(); |
|---|
| 576 | ++fitr) |
|---|
| 577 | { |
|---|
| 578 | |
|---|
| 579 | Lib3dsFace& face = m->faceL[*fitr]; |
|---|
| 580 | |
|---|
| 581 | if (orig2NewMapping[face.points[0]]<0) |
|---|
| 582 | orig2NewMapping[face.points[0]] = noVertex++; |
|---|
| 583 | |
|---|
| 584 | if (orig2NewMapping[face.points[1]]<0) |
|---|
| 585 | orig2NewMapping[face.points[1]] = noVertex++; |
|---|
| 586 | |
|---|
| 587 | if (orig2NewMapping[face.points[2]]<0) |
|---|
| 588 | orig2NewMapping[face.points[2]] = noVertex++; |
|---|
| 589 | |
|---|
| 590 | } |
|---|
| 591 | |
|---|
| 592 | |
|---|
| 593 | |
|---|
| 594 | osg::Vec3Array* osg_coords = new osg::Vec3Array(noVertex); |
|---|
| 595 | geom->setVertexArray(osg_coords); |
|---|
| 596 | |
|---|
| 597 | Lib3dsVector c; |
|---|
| 598 | |
|---|
| 599 | for (i=0; i<m->points; ++i) |
|---|
| 600 | { |
|---|
| 601 | if (orig2NewMapping[i]>=0) |
|---|
| 602 | { |
|---|
| 603 | if (matrix) |
|---|
| 604 | { |
|---|
| 605 | lib3ds_vector_transform(c,*matrix, m->pointL[i].pos); |
|---|
| 606 | (*osg_coords)[orig2NewMapping[i]].set(c[0],c[1],c[2]); |
|---|
| 607 | } |
|---|
| 608 | else |
|---|
| 609 | { |
|---|
| 610 | |
|---|
| 611 | (*osg_coords)[orig2NewMapping[i]].set(m->pointL[i].pos[0],m->pointL[i].pos[1],m->pointL[i].pos[2]); |
|---|
| 612 | } |
|---|
| 613 | } |
|---|
| 614 | } |
|---|
| 615 | |
|---|
| 616 | |
|---|
| 617 | if (m->texels>0) |
|---|
| 618 | { |
|---|
| 619 | if (m->texels==m->points) |
|---|
| 620 | { |
|---|
| 621 | osg::Vec2Array* osg_tcoords = new osg::Vec2Array(noVertex); |
|---|
| 622 | geom->setTexCoordArray(0,osg_tcoords); |
|---|
| 623 | for (i=0; i<m->texels; ++i) |
|---|
| 624 | { |
|---|
| 625 | if (orig2NewMapping[i]>=0) (*osg_tcoords)[orig2NewMapping[i]].set(m->texelL[i][0],m->texelL[i][1]); |
|---|
| 626 | } |
|---|
| 627 | } |
|---|
| 628 | else |
|---|
| 629 | { |
|---|
| 630 | osg::notify(osg::WARN)<<"Warning: in 3ds loader m->texels ("<<m->texels<<") != m->points ("<<m->points<<")"<< std::endl; |
|---|
| 631 | } |
|---|
| 632 | } |
|---|
| 633 | |
|---|
| 634 | |
|---|
| 635 | if (_usePerVertexNormals) |
|---|
| 636 | { |
|---|
| 637 | osg::Vec3Array* osg_normals = new osg::Vec3Array(noVertex); |
|---|
| 638 | |
|---|
| 639 | |
|---|
| 640 | for (i=0; i<noVertex; ++i) |
|---|
| 641 | { |
|---|
| 642 | (*osg_normals)[i].set(0.0f,0.0f,0.0f); |
|---|
| 643 | } |
|---|
| 644 | |
|---|
| 645 | for (fitr=faceList.begin(); |
|---|
| 646 | fitr!=faceList.end(); |
|---|
| 647 | ++fitr) |
|---|
| 648 | { |
|---|
| 649 | Lib3dsFace& face = m->faceL[*fitr]; |
|---|
| 650 | |
|---|
| 651 | (*osg_normals)[orig2NewMapping[face.points[0]]] += osg::Vec3(face.normal[0],face.normal[1],face.normal[2]);; |
|---|
| 652 | (*osg_normals)[orig2NewMapping[face.points[1]]] += osg::Vec3(face.normal[0],face.normal[1],face.normal[2]);; |
|---|
| 653 | (*osg_normals)[orig2NewMapping[face.points[2]]] += osg::Vec3(face.normal[0],face.normal[1],face.normal[2]);; |
|---|
| 654 | |
|---|
| 655 | } |
|---|
| 656 | |
|---|
| 657 | if (matrix) |
|---|
| 658 | { |
|---|
| 659 | osg::Matrix osg_matrix; |
|---|
| 660 | copyLib3dsMatrixToOsgMatrix(osg_matrix, *matrix); |
|---|
| 661 | for (i=0; i<noVertex; ++i) |
|---|
| 662 | { |
|---|
| 663 | (*osg_normals)[i] = osg::Matrix::transform3x3((*osg_normals)[i], osg_matrix); |
|---|
| 664 | } |
|---|
| 665 | } |
|---|
| 666 | |
|---|
| 667 | |
|---|
| 668 | for (i=0; i<noVertex; ++i) |
|---|
| 669 | { |
|---|
| 670 | (*osg_normals)[i].normalize(); |
|---|
| 671 | } |
|---|
| 672 | |
|---|
| 673 | geom->setNormalArray(osg_normals); |
|---|
| 674 | geom->setNormalBinding(osg::Geometry::BIND_PER_VERTEX); |
|---|
| 675 | |
|---|
| 676 | } |
|---|
| 677 | else |
|---|
| 678 | { |
|---|
| 679 | osg::Vec3Array* osg_normals = new osg::Vec3Array(faceList.size()); |
|---|
| 680 | osg::Vec3Array::iterator normal_itr = osg_normals->begin(); |
|---|
| 681 | for (fitr=faceList.begin(); |
|---|
| 682 | fitr!=faceList.end(); |
|---|
| 683 | ++fitr) |
|---|
| 684 | { |
|---|
| 685 | Lib3dsFace& face = m->faceL[*fitr]; |
|---|
| 686 | *(normal_itr++) = osg::Vec3(face.normal[0],face.normal[1],face.normal[2]); |
|---|
| 687 | } |
|---|
| 688 | geom->setNormalArray(osg_normals); |
|---|
| 689 | geom->setNormalBinding(osg::Geometry::BIND_PER_PRIMITIVE); |
|---|
| 690 | } |
|---|
| 691 | |
|---|
| 692 | osg::Vec4ubArray* osg_colors = new osg::Vec4ubArray(1); |
|---|
| 693 | (*osg_colors)[0].set(255,255,255,255); |
|---|
| 694 | geom->setColorArray(osg_colors); |
|---|
| 695 | geom->setColorBinding(osg::Geometry::BIND_OVERALL); |
|---|
| 696 | |
|---|
| 697 | |
|---|
| 698 | |
|---|
| 699 | int numIndices = faceList.size()*3; |
|---|
| 700 | DrawElementsUShort* elements = new osg::DrawElementsUShort(osg::PrimitiveSet::TRIANGLES,numIndices); |
|---|
| 701 | DrawElementsUShort::iterator index_itr = elements->begin(); |
|---|
| 702 | |
|---|
| 703 | for (fitr=faceList.begin(); |
|---|
| 704 | fitr!=faceList.end(); |
|---|
| 705 | ++fitr) |
|---|
| 706 | { |
|---|
| 707 | Lib3dsFace& face = m->faceL[*fitr]; |
|---|
| 708 | |
|---|
| 709 | *(index_itr++) = orig2NewMapping[face.points[0]]; |
|---|
| 710 | *(index_itr++) = orig2NewMapping[face.points[1]]; |
|---|
| 711 | *(index_itr++) = orig2NewMapping[face.points[2]]; |
|---|
| 712 | } |
|---|
| 713 | |
|---|
| 714 | geom->addPrimitiveSet(elements); |
|---|
| 715 | |
|---|
| 716 | #if 0 |
|---|
| 717 | osgUtil::TriStripVisitor tsv; |
|---|
| 718 | tsv.stripify(*geom); |
|---|
| 719 | #endif |
|---|
| 720 | |
|---|
| 721 | return geom; |
|---|
| 722 | } |
|---|
| 723 | |
|---|
| 724 | |
|---|
| 725 | osg::Texture2D* ReaderWriter3DS::ReaderObject::createTexture(Lib3dsTextureMap *texture,const char* label,bool& transparancy, const osgDB::ReaderWriter::Options* options) |
|---|
| 726 | { |
|---|
| 727 | if (texture && *(texture->name)) |
|---|
| 728 | { |
|---|
| 729 | osg::notify(osg::NOTICE)<<"texture->name="<<texture->name<<", _directory="<<_directory<<std::endl; |
|---|
| 730 | |
|---|
| 731 | |
|---|
| 732 | std::string fileName = osgDB::findFileInDirectory(texture->name,_directory,osgDB::CASE_INSENSITIVE); |
|---|
| 733 | if (fileName.empty()) |
|---|
| 734 | { |
|---|
| 735 | |
|---|
| 736 | fileName = osgDB::findDataFile(texture->name,options, osgDB::CASE_INSENSITIVE); |
|---|
| 737 | } |
|---|
| 738 | |
|---|
| 739 | if (fileName.empty()) |
|---|
| 740 | { |
|---|
| 741 | if (osgDB::containsServerAddress(_directory)) |
|---|
| 742 | { |
|---|
| 743 | |
|---|
| 744 | fileName = _directory + "/" + texture->name; |
|---|
| 745 | } else { |
|---|
| 746 | osg::notify(osg::WARN) << "texture '"<<texture->name<<"' not found"<< std::endl; |
|---|
| 747 | return NULL; |
|---|
| 748 | } |
|---|
| 749 | } |
|---|
| 750 | |
|---|
| 751 | if (label) osg::notify(osg::DEBUG_INFO) << label; |
|---|
| 752 | else osg::notify(osg::DEBUG_INFO) << "texture name"; |
|---|
| 753 | osg::notify(osg::DEBUG_INFO) << " '"<<texture->name<<"'"<< std::endl; |
|---|
| 754 | osg::notify(osg::DEBUG_INFO) << " texture flag "<<texture->flags<< std::endl; |
|---|
| 755 | osg::notify(osg::DEBUG_INFO) << " LIB3DS_DECALE "<<((texture->flags)&LIB3DS_DECALE)<< std::endl; |
|---|
| 756 | osg::notify(osg::DEBUG_INFO) << " LIB3DS_MIRROR "<<((texture->flags)&LIB3DS_MIRROR)<< std::endl; |
|---|
| 757 | osg::notify(osg::DEBUG_INFO) << " LIB3DS_NEGATE "<<((texture->flags)&LIB3DS_NEGATE)<< std::endl; |
|---|
| 758 | osg::notify(osg::DEBUG_INFO) << " LIB3DS_NO_TILE "<<((texture->flags)&LIB3DS_NO_TILE)<< std::endl; |
|---|
| 759 | osg::notify(osg::DEBUG_INFO) << " LIB3DS_SUMMED_AREA "<<((texture->flags)&LIB3DS_SUMMED_AREA)<< std::endl; |
|---|
| 760 | osg::notify(osg::DEBUG_INFO) << " LIB3DS_ALPHA_SOURCE "<<((texture->flags)&LIB3DS_ALPHA_SOURCE)<< std::endl; |
|---|
| 761 | osg::notify(osg::DEBUG_INFO) << " LIB3DS_TINT "<<((texture->flags)&LIB3DS_TINT)<< std::endl; |
|---|
| 762 | osg::notify(osg::DEBUG_INFO) << " LIB3DS_IGNORE_ALPHA "<<((texture->flags)&LIB3DS_IGNORE_ALPHA)<< std::endl; |
|---|
| 763 | osg::notify(osg::DEBUG_INFO) << " LIB3DS_RGB_TINT "<<((texture->flags)&LIB3DS_RGB_TINT)<< std::endl; |
|---|
| 764 | |
|---|
| 765 | osg::ref_ptr<osg::Image> osg_image = osgDB::readRefImageFile(fileName.c_str()); |
|---|
| 766 | if (!osg_image) |
|---|
| 767 | { |
|---|
| 768 | osg::notify(osg::NOTICE) << "Warning: Cannot create texture "<<texture->name<< std::endl; |
|---|
| 769 | return NULL; |
|---|
| 770 | } |
|---|
| 771 | |
|---|
| 772 | osg::Texture2D* osg_texture = new osg::Texture2D; |
|---|
| 773 | osg_texture->setImage(osg_image.get()); |
|---|
| 774 | |
|---|
| 775 | |
|---|
| 776 | transparancy = ((texture->flags)&LIB3DS_ALPHA_SOURCE)!=0; |
|---|
| 777 | |
|---|
| 778 | |
|---|
| 779 | osg::Texture2D::WrapMode wm = ((texture->flags)&LIB3DS_NO_TILE) ? |
|---|
| 780 | osg::Texture2D::CLAMP : |
|---|
| 781 | osg::Texture2D::REPEAT; |
|---|
| 782 | osg_texture->setWrap(osg::Texture2D::WRAP_S,wm); |
|---|
| 783 | osg_texture->setWrap(osg::Texture2D::WRAP_T,wm); |
|---|
| 784 | osg_texture->setWrap(osg::Texture2D::WRAP_R,wm); |
|---|
| 785 | |
|---|
| 786 | osg_texture->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::LINEAR_MIPMAP_NEAREST); |
|---|
| 787 | |
|---|
| 788 | return osg_texture; |
|---|
| 789 | } |
|---|
| 790 | else |
|---|
| 791 | return NULL; |
|---|
| 792 | } |
|---|
| 793 | |
|---|
| 794 | |
|---|
| 795 | osg::StateSet* ReaderWriter3DS::ReaderObject::createStateSet(Lib3dsMaterial *mat, const osgDB::ReaderWriter::Options* options) |
|---|
| 796 | { |
|---|
| 797 | if (mat==NULL) return NULL; |
|---|
| 798 | |
|---|
| 799 | osg::StateSet* stateset = new osg::StateSet; |
|---|
| 800 | |
|---|
| 801 | osg::Material* material = new osg::Material; |
|---|
| 802 | |
|---|
| 803 | float transparency = mat->transparency; |
|---|
| 804 | float alpha = 1.0f-transparency; |
|---|
| 805 | |
|---|
| 806 | osg::Vec4 ambient(mat->ambient[0],mat->ambient[1],mat->ambient[2],alpha); |
|---|
| 807 | osg::Vec4 diffuse(mat->diffuse[0],mat->diffuse[1],mat->diffuse[2],alpha); |
|---|
| 808 | osg::Vec4 specular(mat->specular[0],mat->specular[1],mat->specular[2],alpha); |
|---|
| 809 | specular *= mat->shin_strength; |
|---|
| 810 | |
|---|
| 811 | float shininess = mat->shininess; |
|---|
| 812 | material->setName(mat->name); |
|---|
| 813 | material->setAmbient(osg::Material::FRONT_AND_BACK,ambient); |
|---|
| 814 | material->setDiffuse(osg::Material::FRONT_AND_BACK,diffuse); |
|---|
| 815 | material->setSpecular(osg::Material::FRONT_AND_BACK,specular); |
|---|
| 816 | material->setShininess(osg::Material::FRONT_AND_BACK,shininess*128.0f); |
|---|
| 817 | |
|---|
| 818 | stateset->setAttribute(material); |
|---|
| 819 | |
|---|
| 820 | bool textureTransparancy=false; |
|---|
| 821 | osg::Texture2D* texture1_map = createTexture(&(mat->texture1_map),"texture1_map",textureTransparancy, options); |
|---|
| 822 | if (texture1_map) |
|---|
| 823 | { |
|---|
| 824 | stateset->setTextureAttributeAndModes(0,texture1_map,osg::StateAttribute::ON); |
|---|
| 825 | |
|---|
| 826 | if (!textureTransparancy) |
|---|
| 827 | { |
|---|
| 828 | |
|---|
| 829 | |
|---|
| 830 | |
|---|
| 831 | |
|---|
| 832 | |
|---|
| 833 | |
|---|
| 834 | |
|---|
| 835 | |
|---|
| 836 | #if 0 |
|---|
| 837 | |
|---|
| 838 | osg::Vec4 white(1.0f,1.0f,1.0f,alpha); |
|---|
| 839 | material->setAmbient(osg::Material::FRONT_AND_BACK,white); |
|---|
| 840 | material->setDiffuse(osg::Material::FRONT_AND_BACK,white); |
|---|
| 841 | material->setSpecular(osg::Material::FRONT_AND_BACK,white); |
|---|
| 842 | #else |
|---|
| 843 | |
|---|
| 844 | |
|---|
| 845 | material->setAmbient(osg::Material::FRONT_AND_BACK,osg::Vec4(0.2f,0.2f,0.2f,alpha)); |
|---|
| 846 | material->setDiffuse(osg::Material::FRONT_AND_BACK,osg::Vec4(0.8f,0.8f,0.8f,alpha)); |
|---|
| 847 | material->setSpecular(osg::Material::FRONT_AND_BACK,osg::Vec4(0.0f,0.0f,0.0f,alpha)); |
|---|
| 848 | #endif |
|---|
| 849 | } |
|---|
| 850 | |
|---|
| 851 | |
|---|
| 852 | |
|---|
| 853 | |
|---|
| 854 | |
|---|
| 855 | |
|---|
| 856 | |
|---|
| 857 | |
|---|
| 858 | |
|---|
| 859 | |
|---|
| 860 | |
|---|
| 861 | |
|---|
| 862 | |
|---|
| 863 | |
|---|
| 864 | |
|---|
| 865 | |
|---|
| 866 | |
|---|
| 867 | } |
|---|
| 868 | |
|---|
| 869 | if (transparency>0.0f || textureTransparancy) |
|---|
| 870 | { |
|---|
| 871 | stateset->setMode(GL_BLEND,osg::StateAttribute::ON); |
|---|
| 872 | stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); |
|---|
| 873 | } |
|---|
| 874 | |
|---|
| 875 | |
|---|
| 876 | |
|---|
| 877 | |
|---|
| 878 | |
|---|
| 879 | |
|---|
| 880 | |
|---|
| 881 | |
|---|
| 882 | |
|---|
| 883 | |
|---|
| 884 | |
|---|
| 885 | |
|---|
| 886 | |
|---|
| 887 | |
|---|
| 888 | |
|---|
| 889 | |
|---|
| 890 | |
|---|
| 891 | |
|---|
| 892 | return stateset; |
|---|
| 893 | } |
|---|