#include <OSG3DSSceneFileType.h>
Inheritance diagram for OSG::A3DSSceneFileType:

Public Types | ||||
| typedef std::vector< FieldContainerPtr > | FCPtrStore | |||
Flags | ||||
| enum | { OSG_READ_SUPPORTED = 1, OSG_WRITE_SUPPORTED = 2 } | |||
Public Member Functions | ||||
| virtual | ~A3DSSceneFileType (void) | |||
| ||||
| virtual const Char8 * | getName (void) const | |||
| ||||
| virtual NodePtr | read (std::istream &is, const Char8 *fileNameOrExtension) const | |||
| ||||
Set | ||||
| void | setOptions (const Char8 *options) | |||
Get | ||||
| virtual std::list< IDString > & | suffixList (void) | |||
| bool | doOverride (void) | |||
| UInt32 | getOverridePriority (void) | |||
| UInt32 | getFlags (void) | |||
| const Char8 * | getOptions (void) | |||
Read | ||||
| virtual NodePtr | readFile (const Char8 *fileName) const | |||
Write | ||||
| virtual bool | write (const NodePtr &node, std::ostream &os, const Char8 *fileNameOrExtension) const | |||
| virtual bool | writeFile (const NodePtr &node, const Char8 *fileName) const | |||
Debug | ||||
| void | print (void) | |||
Static Public Member Functions | ||||
| static A3DSSceneFileType & | the (void) | |||
| ||||
Protected Member Functions | ||||
| A3DSSceneFileType (const Char8 *suffixArray[], UInt16 suffixByteCount, bool override, UInt32 overridePriority, UInt32 flags) | ||||
| ||||
| A3DSSceneFileType (const A3DSSceneFileType &obj) | ||||
| ||||
Protected Attributes | ||||
Member | ||||
| std::list< IDString > | _suffixList | |||
| bool | _override | |||
| UInt32 | _overridePriority | |||
| UInt32 | _flags | |||
| std::string | _options | |||
Static Protected Attributes | ||||
| static const Char8 * | _suffixA [] = {"3ds"} | |||
| static A3DSSceneFileType | _the | |||
Private Types | ||||
| typedef std::map< UInt32, MaterialPtr >::iterator | materialIt | |||
Private Member Functions | ||||
| NodePtr | createMesh (L3DS &scene, LMesh &mesh) const | |||
| ||||
| MaterialPtr | createMaterial (L3DS &scene, UInt32 id) const | |||
Private Attributes | ||||
| std::map< UInt32, MaterialPtr > | _materials | |||
Definition at line 62 of file OSG3DSSceneFileType.h.
typedef std::map<UInt32, MaterialPtr>::iterator OSG::A3DSSceneFileType::materialIt [private] |
Definition at line 93 of file OSG3DSSceneFileType.h.
typedef std::vector<FieldContainerPtr> OSG::SceneFileType::FCPtrStore [inherited] |
Reimplemented in OSG::VRMLSceneFileType, and OSG::OSGSceneFileType.
Definition at line 66 of file OSGSceneFileType.h.
anonymous enum [inherited] |
| OSG_READ_SUPPORTED | The file type supports reading. |
| OSG_WRITE_SUPPORTED | The file type supports writing. |
Definition at line 79 of file OSGSceneFileType.h.
00080 { 00081 OSG_READ_SUPPORTED = 1, 00082 OSG_WRITE_SUPPORTED = 2 00083 };
| A3DSSceneFileType::~A3DSSceneFileType | ( | void | ) | [virtual] |
| A3DSSceneFileType::A3DSSceneFileType | ( | const Char8 * | suffixArray[], | |
| UInt16 | suffixByteCount, | |||
| bool | override, | |||
| UInt32 | overridePriority, | |||
| UInt32 | flags | |||
| ) | [protected] |
Definition at line 113 of file OSG3DSSceneFileType.cpp.
00117 : 00118 SceneFileType(suffixArray, 00119 suffixByteCount, 00120 override, 00121 overridePriority, 00122 flags) 00123 { 00124 }
| A3DSSceneFileType::A3DSSceneFileType | ( | const A3DSSceneFileType & | obj | ) | [protected] |
Definition at line 154 of file OSG3DSSceneFileType.cpp.
00154 : 00155 SceneFileType(obj), 00156 _materials() 00157 { 00158 return; 00159 }
| A3DSSceneFileType & A3DSSceneFileType::the | ( | void | ) | [static] |
Definition at line 132 of file OSG3DSSceneFileType.cpp.
References _the.
00133 { 00134 return _the; 00135 }
| const Char8 * A3DSSceneFileType::getName | ( | void | ) | const [virtual] |
| NodePtr A3DSSceneFileType::read | ( | std::istream & | is, | |
| const Char8 * | fileNameOrExtension | |||
| ) | const [virtual] |
Reimplemented from OSG::SceneFileType.
Definition at line 80 of file OSG3DSSceneFileType.cpp.
References _materials, OSG::GroupBase::create(), createMesh(), LImporter::GetMesh(), LImporter::GetMeshCount(), L3DS::Load(), NullFC, and SWARNING.
00081 { 00082 if(!is) 00083 return NullFC; 00084 00085 _materials.clear(); 00086 00087 L3DS scene; 00088 if(!scene.Load(is)) 00089 { 00090 SWARNING << "Couldn't read from stream!" << std::endl; 00091 return NullFC; 00092 } 00093 00094 NodePtr root = Node::create(); 00095 GroupPtr group = Group::create(); 00096 root->setCore(group); 00097 00098 for(uint i=0;i<scene.GetMeshCount();++i) 00099 { 00100 NodePtr mesh = createMesh(scene, scene.GetMesh(i)); 00101 if(mesh != NullFC) 00102 root->addChild(mesh); 00103 } 00104 00105 return root; 00106 }
Definition at line 177 of file OSG3DSSceneFileType.cpp.
References OSG::GeometryBase::create(), createMaterial(), OSG::getDefaultMaterial(), LMesh::GetMaterial(), LMesh::GetMaterialCount(), LObject::GetName(), LMesh::GetTriangle2(), LMesh::GetTriangleCount(), NullFC, and OSG::setName().
Referenced by read().
00178 { 00179 if(mesh.GetTriangleCount() == 0) 00180 return NullFC; 00181 00182 NodePtr node = Node::create(); 00183 GeometryPtr geo = Geometry::create(); 00184 00185 node->setCore(geo); 00186 00187 OSG::setName(node, mesh.GetName().c_str()); 00188 00189 GeoPnt3fPropertyPtr points = GeoPnt3fProperty::create(); 00190 GeoVec3fPropertyPtr normals = GeoVec3fProperty::create(); 00191 GeoVec2fPropertyPtr texcoords = GeoVec2fProperty::create(); 00192 00193 for(UInt32 i=0;i<mesh.GetTriangleCount();++i) 00194 { 00195 const LTriangle2 &t = mesh.GetTriangle2(i); 00196 00197 points->push_back(Pnt3f(t.vertices[0].x, t.vertices[0].y, t.vertices[0].z)); 00198 points->push_back(Pnt3f(t.vertices[1].x, t.vertices[1].y, t.vertices[1].z)); 00199 points->push_back(Pnt3f(t.vertices[2].x, t.vertices[2].y, t.vertices[2].z)); 00200 00201 normals->push_back(Vec3f(t.vertexNormals[0].x, t.vertexNormals[0].y, t.vertexNormals[0].z)); 00202 normals->push_back(Vec3f(t.vertexNormals[1].x, t.vertexNormals[1].y, t.vertexNormals[1].z)); 00203 normals->push_back(Vec3f(t.vertexNormals[2].x, t.vertexNormals[2].y, t.vertexNormals[2].z)); 00204 00205 texcoords->push_back(Vec2f(t.textureCoords[0].x, t.textureCoords[0].y)); 00206 texcoords->push_back(Vec2f(t.textureCoords[1].x, t.textureCoords[1].y)); 00207 texcoords->push_back(Vec2f(t.textureCoords[2].x, t.textureCoords[2].y)); 00208 } 00209 00210 // create material opensg supports only one material per geometry! 00211 MaterialPtr mat = OSG::getDefaultMaterial(); 00212 if(mesh.GetMaterialCount() > 0) 00213 mat = createMaterial(scene, mesh.GetMaterial(0)); 00214 00215 int nv = mesh.GetTriangleCount() * 3; 00216 00217 GeoUInt32PropertyPtr indices = GeoUInt32Property::create(); 00218 indices->editFieldPtr()->reserve(nv); 00219 for (int i = 0; i < nv; ++i) 00220 indices->push_back(i); 00221 00222 GeoUInt32PropertyPtr lengths = GeoUInt32Property::create(); 00223 lengths->push_back(nv); 00224 00225 GeoUInt8PropertyPtr types = GeoUInt8Property::create(); 00226 types->push_back(GL_TRIANGLES); 00227 00228 geo->setMaterial(mat); 00229 geo->setPositions(points); 00230 geo->setNormals(normals); 00231 geo->setTexCoords(texcoords); 00232 geo->setIndices(indices); 00233 geo->setLengths(lengths); 00234 geo->setTypes(types); 00235 00236 //createSharedIndex(geo); 00237 //OSG::calcVertexNormals(geo); 00238 00239 return node; 00240 }
| MaterialPtr A3DSSceneFileType::createMaterial | ( | L3DS & | scene, | |
| UInt32 | id | |||
| ) | const [private] |
Definition at line 242 of file OSG3DSSceneFileType.cpp.
References _materials, OSG::BlendChunkBase::create(), OSG::TextureEnvChunkBase::create(), OSG::TextureObjChunkBase::create(), OSG::ImageBase::create(), OSG::MaterialChunkBase::create(), OSG::ChunkMaterialBase::create(), FWARNING, LImporter::GetMaterial(), GL_CLAMP_TO_EDGE, LMap::mapName, NullFC, OSG::setName(), and LMap::tiling.
Referenced by createMesh().
00243 { 00244 materialIt mi = _materials.find(id); 00245 if(mi != _materials.end()) 00246 return (*mi).second; 00247 00248 LMaterial m = scene.GetMaterial(id); 00249 00250 ChunkMaterialPtr cmat = ChunkMaterial::create(); 00251 00252 OSG::setName(cmat, m.GetName()); 00253 00254 MaterialChunkPtr matc = MaterialChunk::create(); 00255 00256 cmat->addChunk(matc); 00257 00258 Real32 t = m.GetTransparency(); 00259 00260 matc->setAmbient(Color4f(m.GetAmbientColor().r, m.GetAmbientColor().g, 00261 m.GetAmbientColor().b, 1.0f - t)); 00262 matc->setDiffuse(Color4f(m.GetDiffuseColor().r, m.GetDiffuseColor().g, 00263 m.GetDiffuseColor().b, 1.0f - t)); 00264 matc->setSpecular(Color4f(m.GetSpecularColor().r, m.GetSpecularColor().g, 00265 m.GetSpecularColor().b, 1.0f - t)); 00266 matc->setEmission(Color4f(0.0f, 0.0f, 0.0f, 1.0f - t)); 00267 matc->setShininess(m.GetShininess() * 128.0f); 00268 00269 00270 // create a texture chunk 00271 LMap &map = m.GetTextureMap1(); 00272 const char *texname = map.mapName; 00273 ImagePtr image = NullFC; 00274 if(texname != NULL && strlen(texname) > 0) 00275 { 00276 image = Image::create(); 00277 bool img_ok = image->read(texname); 00278 00279 if(!img_ok) 00280 { 00281 std::string casename(texname); 00282 for(std::string::reverse_iterator it = casename.rbegin(); 00283 it != casename.rend() && *it != '/' && *it != '\\'; 00284 ++it) 00285 { 00286 if(*it >= 'a' && *it <= 'z') 00287 { 00288 *it = 'A' + *it - 'a'; 00289 } 00290 else 00291 if(*it >= 'A' && *it <= 'Z') 00292 { 00293 *it = 'a' + *it - 'A'; 00294 } 00295 00296 } 00297 00298 FWARNING(("Couldn't load image '%s', trying case " 00299 "reversed version '%s'! \n", texname, 00300 casename.c_str())); 00301 00302 img_ok = image->read(casename.c_str()); 00303 } 00304 00305 if(img_ok) 00306 { 00307 image->setForceAlphaBinary(image->calcIsAlphaBinary()); 00308 00309 TextureObjChunkPtr texc = TextureObjChunk::create(); 00310 TextureEnvChunkPtr texec = TextureEnvChunk::create(); 00311 00312 texc->setImage(image); 00313 00314 // 0x0008 means no tiling. 00315 GLenum wm = (map.tiling & 0x0008) ? GL_CLAMP_TO_EDGE : GL_REPEAT; 00316 texc->setWrapS(wm); 00317 texc->setWrapT(wm); 00318 00319 texec->setEnvMode(GL_MODULATE); 00320 texc ->setMinFilter(GL_LINEAR_MIPMAP_LINEAR); 00321 texc ->setMagFilter(GL_LINEAR); 00322 00323 cmat->addChunk(texc); 00324 cmat->addChunk(texec); 00325 } 00326 } 00327 00328 // add a blend chunk for transparency 00329 if(t > 0.0 || 00330 ( image != NullFC && 00331 image->hasAlphaChannel() 00332 )) 00333 { 00334 BlendChunkPtr blendc = BlendChunk::create(); 00335 00336 if(image != NullFC && image->isAlphaBinary()) 00337 { 00338 blendc->setAlphaFunc(GL_NOTEQUAL); 00339 blendc->setAlphaValue(0); 00340 } 00341 else 00342 { 00343 blendc->setSrcFactor(GL_SRC_ALPHA); 00344 blendc->setDestFactor(GL_ONE_MINUS_SRC_ALPHA); 00345 } 00346 00347 cmat->addChunk(blendc); 00348 } 00349 00350 _materials.insert(std::pair<UInt32, MaterialPtr>(id, cmat)); 00351 00352 return cmat; 00353 }
| void SceneFileType::setOptions | ( | const Char8 * | options | ) | [inherited] |
Definition at line 143 of file OSGSceneFileType.cpp.
References OSG::SceneFileType::_options.
Referenced by OSG::SceneFileHandlerBase::setOptions().
00144 { 00145 _options = options; 00146 }
| std::list< IDString > & SceneFileType::suffixList | ( | void | ) | [virtual, inherited] |
Definition at line 172 of file OSGSceneFileType.cpp.
References OSG::SceneFileType::_suffixList.
Referenced by OSG::SceneFileHandlerBase::addSceneFileType(), and OSG::SceneFileHandlerBase::subSceneFileType().
00173 { 00174 return _suffixList; 00175 }
| bool SceneFileType::doOverride | ( | void | ) | [inherited] |
Definition at line 179 of file OSGSceneFileType.cpp.
References OSG::SceneFileType::_override.
Referenced by OSG::SceneFileHandlerBase::addSceneFileType(), and OSG::SceneFileHandlerBase::FindOverride::operator()().
00180 { 00181 return _override; 00182 }
| UInt32 SceneFileType::getOverridePriority | ( | void | ) | [inherited] |
Definition at line 186 of file OSGSceneFileType.cpp.
References OSG::SceneFileType::_overridePriority.
Referenced by OSG::SceneFileHandlerBase::addSceneFileType(), and OSG::SceneFileHandlerBase::FindOverride::operator()().
00187 { 00188 return _overridePriority; 00189 }
| UInt32 SceneFileType::getFlags | ( | void | ) | [inherited] |
Definition at line 193 of file OSGSceneFileType.cpp.
References OSG::SceneFileType::_flags.
Referenced by OSG::SceneFileHandlerBase::print().
00194 { 00195 return _flags; 00196 }
| const Char8 * SceneFileType::getOptions | ( | void | ) | [inherited] |
Return the current options string for the loader.
Definition at line 203 of file OSGSceneFileType.cpp.
References OSG::SceneFileType::_options.
Referenced by OSG::SceneFileHandlerBase::getOptions().
00204 { 00205 return _options.c_str(); 00206 }
| virtual NodePtr OSG::SceneFileType::readFile | ( | const Char8 * | fileName | ) | const [virtual, inherited] |
Referenced by OSG::SceneFileHandlerBase::read().
| virtual bool OSG::SceneFileType::write | ( | const NodePtr & | node, | |
| std::ostream & | os, | |||
| const Char8 * | fileNameOrExtension | |||
| ) | const [virtual, inherited] |
Reimplemented in OSG::NFIOSceneFileType, OSG::VRMLSceneFileType, OSG::OBJSceneFileType, and OSG::OSGSceneFileType.
Referenced by OSG::SceneFileHandlerBase::write().
| virtual bool OSG::SceneFileType::writeFile | ( | const NodePtr & | node, | |
| const Char8 * | fileName | |||
| ) | const [virtual, inherited] |
Referenced by OSG::SceneFileHandlerBase::write().
| void SceneFileType::print | ( | void | ) | [inherited] |
Definition at line 150 of file OSGSceneFileType.cpp.
References OSG::SceneFileType::_suffixList, OSG::SceneFileType::getName(), OSG::LOG_DEBUG, and OSG::osgLog().
00151 { 00152 std::list<IDString>::iterator sI; 00153 00154 osgLog() << getName(); 00155 00156 if (_suffixList.empty()) 00157 { 00158 osgLog() << "NONE"; 00159 } 00160 else 00161 { 00162 for (sI = _suffixList.begin(); sI != _suffixList.end(); sI++) 00163 { 00164 osgLog().stream(OSG::LOG_DEBUG) << sI->str() << " "; 00165 } 00166 } 00167 osgLog() << std::endl; 00168 }
const Char8 * A3DSSceneFileType::_suffixA = {"3ds"} [static, protected] |
Definition at line 76 of file OSG3DSSceneFileType.h.
A3DSSceneFileType A3DSSceneFileType::_the [static, protected] |
std::map<UInt32, MaterialPtr> OSG::A3DSSceneFileType::_materials [mutable, private] |
std::list<IDString> OSG::SceneFileType::_suffixList [protected, inherited] |
Definition at line 155 of file OSGSceneFileType.h.
Referenced by OSG::SceneFileType::print(), OSG::SceneFileType::SceneFileType(), and OSG::SceneFileType::suffixList().
bool OSG::SceneFileType::_override [protected, inherited] |
List of valid suffixes for this loader.
Definition at line 157 of file OSGSceneFileType.h.
Referenced by OSG::SceneFileType::doOverride().
UInt32 OSG::SceneFileType::_overridePriority [protected, inherited] |
If true loader can override others.
Definition at line 158 of file OSGSceneFileType.h.
Referenced by OSG::SceneFileType::getOverridePriority().
UInt32 OSG::SceneFileType::_flags [protected, inherited] |
The priority for overriding.
Definition at line 159 of file OSGSceneFileType.h.
Referenced by OSG::SceneFileType::getFlags().
std::string OSG::SceneFileType::_options [protected, inherited] |
String list of options to use with the loader.
Definition at line 162 of file OSGSceneFileType.h.
Referenced by OSG::SceneFileType::getOptions(), OSG::NFIOSceneFileType::read(), OSG::SceneFileType::setOptions(), OSG::VRMLSceneFileType::write(), and OSG::NFIOSceneFileType::write().