Panda3D

Loading...
Searching...
No Matches
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 */
27LoaderFileTypeAssimp::
28LoaderFileTypeAssimp() : _loader(nullptr) {
29}
30
31/**
32 *
33 */
34LoaderFileTypeAssimp::
35~LoaderFileTypeAssimp() {
36}
37
38/**
39 *
40 */
41 string LoaderFileTypeAssimp::
42get_name() const {
43 return "Assimp Importer";
44}
45
46/**
47 *
48 */
49 string LoaderFileTypeAssimp::
50get_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 */
58 string LoaderFileTypeAssimp::
59 get_additional_extensions() const {
60 // This may be called at static init time, so ensure it is constructed now.
61 static ConfigVariableString assimp_disable_extensions
62 ("assimp-disable-extensions", "",
63 PRC_DESC("A list of extensions (without preceding dot) that should not be "
64 "loaded via the Assimp loader, even if Assimp supports these "
65 "formats. It is useful to set this for eg. gltf and glb files "
66 "to prevent them from being accidentally loaded via the Assimp "
67 "plug-in instead of via a superior plug-in like panda3d-gltf."));
68
69 bool has_disabled_exts = !assimp_disable_extensions.empty();
70
71 aiString aexts;
72 aiGetExtensionList(&aexts);
73
74 char *buffer = (char *)alloca(aexts.length + 2);
75 char *p = buffer;
76
77 // The format is like: *.mdc;*.mdl;*.mesh.xml;*.mot
78 char *sub = strtok(aexts.data, ";");
79 while (sub != nullptr) {
80 bool enabled = true;
81 if (has_disabled_exts) {
82 for (size_t i = 0; i < assimp_disable_extensions.get_num_words(); ++i) {
83 std::string disabled_ext = assimp_disable_extensions.get_word(i);
84 if (strcmp(sub + 2, disabled_ext.c_str()) == 0) {
85 enabled = false;
86 break;
87 }
88 }
89 }
90 if (enabled) {
91 *(p++) = ' ';
92 size_t len = strlen(sub + 2);
93 memcpy(p, sub + 2, len);
94 p += len;
95 }
96
97 sub = strtok(nullptr, ";");
98 }
99
100 // Strip first space
101 ++buffer;
102 return std::string(buffer, p - buffer);
103}
104
105/**
106 * Returns true if this file type can transparently load compressed files
107 * (with a .pz or .gz extension), false otherwise.
108 */
109 bool LoaderFileTypeAssimp::
110 supports_compressed() const {
111 return true;
112}
113
114/**
115 *
116 */
117PT(PandaNode) LoaderFileTypeAssimp::
118load_file(const Filename &path, const LoaderOptions &options,
119 BamCacheRecord *record) const {
120
121 assimp_cat.info()
122 << "Reading " << path << "\n";
123
124 AssimpLoader loader;
125 loader.local_object();
126
127 if (!loader.read(path)) {
128 return nullptr;
129 }
130
131 loader.build_graph();
132 return DCAST(PandaNode, loader._root);
133}
assimpLoader.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
AssimpLoader
Class that interfaces with Assimp and builds Panda nodes to represent the Assimp structures.
Definition assimpLoader.h:45
BamCacheRecord
An instance of this class is written to the front of a Bam or Txo file to make the file a cached inst...
Definition bamCacheRecord.h:36
ConfigVariableString
This is a convenience class to specialize ConfigVariable as a string type.
Definition configVariableString.h:23
ConfigVariableString::get_word
std::string get_word(size_t n) const
Returns the variable's nth value.
Definition configVariableString.I:151
ConfigVariable::get_num_words
size_t get_num_words() const
Returns the number of words in the variable's value.
Definition configVariable.I:100
Filename
The name of a file, such as a texture file or an Egg file.
Definition filename.h:44
LoaderFileTypeAssimp::get_additional_extensions
virtual std::string get_additional_extensions() const
Returns a space-separated list of extension, in addition to the one returned by get_extension(),...
Definition loaderFileTypeAssimp.cxx:59
LoaderFileTypeAssimp::supports_compressed
virtual bool supports_compressed() const
Returns true if this file type can transparently load compressed files (with a .pz or ....
Definition loaderFileTypeAssimp.cxx:110
LoaderOptions
Specifies parameters that may be passed to the loader.
Definition loaderOptions.h:23
PandaNode
A basic node of the scene graph or data graph.
Definition pandaNode.h:65
ReferenceCount::local_object
void local_object()
This function should be called, once, immediately after creating a new instance of some ReferenceCoun...
Definition referenceCount.I:229
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
config_assimp.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
loaderFileTypeAssimp.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.