Panda3D

assimpLoader.h
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 assimpLoader.h
10 * @author rdb
11 * @date 2011-03-29
12 */
13
14 #ifndef ASSIMPLOADER_H
15 #define ASSIMPLOADER_H
16
17 #include "config_assimp.h"
18 #include "filename.h"
19 #include "modelRoot.h"
20 #include "texture.h"
21 #include "pmap.h"
22
23 #include <assimp/scene.h>
24 #include <assimp/Importer.hpp>
25
26 class Character;
27 class CharacterJointBundle;
28 class PartGroup;
29 class AnimBundle;
30 class AnimGroup;
31
32 struct char_cmp {
33 bool operator () (const char *a, const char *b) const {
34 return strcmp(a,b) < 0;
35 }
36 };
37 typedef pmap<const char *, const aiNode *, char_cmp> BoneMap;
38 typedef pmap<const char *, PT(Character), char_cmp> CharacterMap;
39
40 /**
41 * Class that interfaces with Assimp and builds Panda nodes to represent the
42 * Assimp structures. The loader should be reusable.
43 */
44 class AssimpLoader : public TypedReferenceCount {
45 public:
46 AssimpLoader();
47 virtual ~AssimpLoader();
48
49 void get_extensions(std::string &ext) const;
50
51 bool read(const Filename &filename);
52 void build_graph();
53
54 public:
55 bool _error;
56 PT(ModelRoot) _root;
57 Filename _filename;
58 Mutex _lock;
59
60 private:
61 Assimp::Importer _importer;
62 const aiScene *_scene;
63
64 // These arrays are temporarily used during the build_graph run.
65 PT(Texture) *_textures;
66 CPT(RenderState) *_mat_states;
67 PT(Geom) *_geoms;
68 unsigned int *_geom_matindices;
69 BoneMap _bonemap;
70 CharacterMap _charmap;
71
72 const aiNode *find_node(const aiNode &root, const aiString &name);
73
74 void load_texture(size_t index);
75 void load_texture_stage(const aiMaterial &mat, const aiTextureType &ttype, CPT(TextureAttrib) &tattr);
76 void load_material(size_t index);
77 void create_joint(Character *character, CharacterJointBundle *bundle, PartGroup *parent, const aiNode &node);
78 void create_anim_channel(const aiAnimation &anim, AnimBundle *bundle, AnimGroup *parent, const aiNode &node);
79 void load_mesh(size_t index);
80 void load_node(const aiNode &node, PandaNode *parent);
81 void load_light(const aiLight &light);
82 };
83
84 #include "assimpLoader.I"
85
86 #endif
assimpLoader.I
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
AnimBundle
This is the root of an AnimChannel hierarchy.
Definition: animBundle.h:29
AnimGroup
This is the base class for AnimChannel and AnimBundle.
Definition: animGroup.h:33
AssimpLoader
Class that interfaces with Assimp and builds Panda nodes to represent the Assimp structures.
Definition: assimpLoader.h:44
AssimpLoader::get_extensions
void get_extensions(std::string &ext) const
Returns a space-separated list of extensions that Assimp can load, without the leading dots.
Definition: assimpLoader.cxx:83
AssimpLoader::read
bool read(const Filename &filename)
Reads from the indicated file.
Definition: assimpLoader.cxx:103
AssimpLoader::build_graph
void build_graph()
Converts scene graph structures into a Panda3D scene graph, with _root being the root node.
Definition: assimpLoader.cxx:158
CharacterJointBundle
The collection of all the joints and sliders in the character.
Definition: characterJointBundle.h:28
Character
An animated character, with skeleton-morph animation and either soft- skinned or hard-skinned vertice...
Definition: character.h:38
Filename
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:39
Geom
A container for geometry primitives.
Definition: geom.h:54
ModelRoot
A node of this type is created automatically at the root of each model file that is loaded.
Definition: modelRoot.h:27
Mutex
A standard mutex, or mutual exclusion lock.
Definition: pmutex.h:40
PandaNode
A basic node of the scene graph or data graph.
Definition: pandaNode.h:65
PartGroup
This is the base class for PartRoot and MovingPart.
Definition: partGroup.h:43
RenderState
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
Definition: renderState.h:47
TextureAttrib
Indicates the set of TextureStages and their associated Textures that should be applied to (or remove...
Definition: textureAttrib.h:31
Texture
Represents a texture object, which is typically a single 2-d image but may also represent a 1-d or 3-...
Definition: texture.h:71
TypedReferenceCount
A base class for things which need to inherit from both TypedObject and from ReferenceCount.
Definition: typedReferenceCount.h:31
pmap< const char *, const aiNode *, char_cmp >
config_assimp.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
filename.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
modelRoot.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pmap.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
char_cmp
Definition: assimpLoader.h:32
texture.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.