Panda3D

Loading...
Searching...
No Matches
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 "textureStage.h"
22#include "pmap.h"
23
24#include <assimp/scene.h>
25#include <assimp/Importer.hpp>
26
27 class Character;
28 class CharacterJointBundle;
29 class PartGroup;
30 class AnimBundle;
31 class AnimGroup;
32
33 struct char_cmp {
34 bool operator () (const char *a, const char *b) const {
35 return strcmp(a,b) < 0;
36 }
37};
38 typedef pmap<const char *, const aiNode *, char_cmp> BoneMap;
39 typedef pmap<const char *, PT(Character), char_cmp> CharacterMap;
40
41/**
42 * Class that interfaces with Assimp and builds Panda nodes to represent the
43 * Assimp structures. The loader should be reusable.
44 */
45 class AssimpLoader : public TypedReferenceCount {
46 public:
47 AssimpLoader();
48 virtual ~AssimpLoader();
49
50 void get_extensions(std::string &ext) const;
51
52 bool read(const Filename &filename);
53 void build_graph();
54
55 public:
56 bool _error;
57 PT(ModelRoot) _root;
58 Filename _filename;
59 Mutex _lock;
60
61 private:
62 Assimp::Importer _importer;
63 const aiScene *_scene;
64
65 struct Geoms {
66 PT(Geom) _points;
67 PT(Geom) _lines;
68 PT(Geom) _triangles;
69 unsigned int _mat_index = 0;
70 };
71
72 // These arrays are temporarily used during the build_graph run.
73 PT(Texture) *_textures;
74 CPT(RenderState) *_mat_states;
75 Geoms *_geoms;
76 BoneMap _bonemap;
77 CharacterMap _charmap;
78
79 const aiNode *find_node(const aiNode &root, const aiString &name);
80
81 void load_texture(size_t index);
82 void load_texture_stage(const aiMaterial &mat, const aiTextureType &ttype,
83 TextureStage::Mode mode, CPT(TextureAttrib) &tattr,
84 CPT(TexMatrixAttrib) &tmattr);
85 void load_material(size_t index);
86 void create_joint(Character *character, CharacterJointBundle *bundle, PartGroup *parent, const aiNode &node);
87 void create_anim_channel(const aiAnimation &anim, AnimBundle *bundle, AnimGroup *parent, const aiNode &node);
88 void load_mesh(size_t index);
89 void load_node(const aiNode &node, PandaNode *parent);
90 void load_light(const aiLight &light);
91};
92
93#include "assimpLoader.I"
94
95#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::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:121
AssimpLoader::read
bool read(const Filename &filename)
Reads from the indicated file.
Definition assimpLoader.cxx:141
AssimpLoader::build_graph
void build_graph()
Converts scene graph structures into a Panda3D scene graph, with _root being the root node.
Definition assimpLoader.cxx:196
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:44
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
TexMatrixAttrib
Applies a transform matrix to UV's before they are rendered.
Definition texMatrixAttrib.h:30
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:72
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:33
textureStage.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
texture.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.