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;
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 };
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  */
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
A node of this type is created automatically at the root of each model file that is loaded.
Definition: modelRoot.h:27
bool read(const Filename &filename)
Reads from the indicated file.
A basic node of the scene graph or data graph.
Definition: pandaNode.h:64
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
The collection of all the joints and sliders in the character.
An animated character, with skeleton-morph animation and either soft- skinned or hard-skinned vertice...
Definition: character.h:38
This is the root of an AnimChannel hierarchy.
Definition: animBundle.h:29
void build_graph()
Converts scene graph structures into a Panda3D scene graph, with _root being the root node.
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
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void get_extensions(std::string &ext) const
Returns a space-separated list of extensions that Assimp can load, without the leading dots.
A base class for things which need to inherit from both TypedObject and from ReferenceCount.
A standard mutex, or mutual exclusion lock.
Definition: pmutex.h:38
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Indicates the set of TextureStages and their associated Textures that should be applied to (or remove...
Definition: textureAttrib.h:31
This is the base class for AnimChannel and AnimBundle.
Definition: animGroup.h:33
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:39
A container for geometry primitives.
Definition: geom.h:54
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
Definition: renderState.h:47
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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
This is the base class for PartRoot and MovingPart.
Definition: partGroup.h:43