Panda3D
loaderFileTypeAssimp.cxx
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file loaderFileTypeAssimp.cxx
10  * @author rdb
11  * @date 2011-03-29
12  */
13 
14 #include "loaderFileTypeAssimp.h"
15 #include "config_assimp.h"
16 #include "assimpLoader.h"
17 
18 #include <assimp/cimport.h>
19 
20 using std::string;
21 
22 TypeHandle LoaderFileTypeAssimp::_type_handle;
23 
24 /**
25  *
26  */
27 LoaderFileTypeAssimp::
28 LoaderFileTypeAssimp() : _loader(nullptr) {
29 }
30 
31 /**
32  *
33  */
34 LoaderFileTypeAssimp::
35 ~LoaderFileTypeAssimp() {
36 }
37 
38 /**
39  *
40  */
41 string LoaderFileTypeAssimp::
42 get_name() const {
43  return "Assimp Importer";
44 }
45 
46 /**
47  *
48  */
49 string LoaderFileTypeAssimp::
50 get_extension() const {
51  return "";
52 }
53 
54 /**
55  * Returns a space-separated list of extension, in addition to the one
56  * returned by get_extension(), that are recognized by this converter.
57  */
60  aiString aexts;
61  aiGetExtensionList(&aexts);
62 
63  // The format is like: *.mdc;*.mdl;*.mesh.xml;*.mot
64  std::string ext;
65  char *sub = strtok(aexts.data, ";");
66  while (sub != nullptr) {
67  ext += sub + 2;
68  sub = strtok(nullptr, ";");
69 
70  if (sub != nullptr) {
71  ext += ' ';
72  }
73  }
74 
75  return ext;
76 }
77 
78 /**
79  * Returns true if this file type can transparently load compressed files
80  * (with a .pz or .gz extension), false otherwise.
81  */
83 supports_compressed() const {
84  return true;
85 }
86 
87 /**
88  *
89  */
90 PT(PandaNode) LoaderFileTypeAssimp::
91 load_file(const Filename &path, const LoaderOptions &options,
92  BamCacheRecord *record) const {
93 
94  assimp_cat.info()
95  << "Reading " << path << "\n";
96 
97  AssimpLoader loader;
98  loader.local_object();
99 
100  if (!loader.read(path)) {
101  return nullptr;
102  }
103 
104  loader.build_graph();
105  return DCAST(PandaNode, loader._root);
106 }
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Class that interfaces with Assimp and builds Panda nodes to represent the Assimp structures.
Definition: assimpLoader.h:44
An instance of this class is written to the front of a Bam or Txo file to make the file a cached inst...
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:39
virtual std::string get_additional_extensions() const
Returns a space-separated list of extension, in addition to the one returned by get_extension(),...
virtual bool supports_compressed() const
Returns true if this file type can transparently load compressed files (with a .pz or ....
Specifies parameters that may be passed to the loader.
Definition: loaderOptions.h:23
A basic node of the scene graph or data graph.
Definition: pandaNode.h:65
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.