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
15#include "config_assimp.h"
16#include "assimpLoader.h"
17
18#include <assimp/cimport.h>
19
20using std::string;
21
22TypeHandle LoaderFileTypeAssimp::_type_handle;
23
24/**
25 *
26 */
27LoaderFileTypeAssimp::
28LoaderFileTypeAssimp() : _loader(nullptr) {
29}
30
31/**
32 *
33 */
34LoaderFileTypeAssimp::
35~LoaderFileTypeAssimp() {
36}
37
38/**
39 *
40 */
41string LoaderFileTypeAssimp::
42get_name() const {
43 return "Assimp Importer";
44}
45
46/**
47 *
48 */
49string 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 */
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 */
110supports_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}
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Class that interfaces with Assimp and builds Panda nodes to represent the Assimp structures.
An instance of this class is written to the front of a Bam or Txo file to make the file a cached inst...
This is a convenience class to specialize ConfigVariable as a string type.
std::string get_word(size_t n) const
Returns the variable's nth value.
size_t get_num_words() const
Returns the number of words in the variable's value.
The name of a file, such as a texture file or an Egg file.
Definition filename.h:44
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.
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.