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
27class Character;
29class PartGroup;
30class AnimBundle;
31class AnimGroup;
32
33struct char_cmp {
34 bool operator () (const char *a, const char *b) const {
35 return strcmp(a,b) < 0;
36 }
37};
39typedef 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 */
46public:
48 virtual ~AssimpLoader();
49
50 void get_extensions(std::string &ext) const;
51
52 bool read(const Filename &filename);
53 void build_graph();
54
55public:
56 bool _error;
57 PT(ModelRoot) _root;
58 Filename _filename;
59 Mutex _lock;
60
61private:
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
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the root of an AnimChannel hierarchy.
Definition animBundle.h:29
This is the base class for AnimChannel and AnimBundle.
Definition animGroup.h:33
Class that interfaces with Assimp and builds Panda nodes to represent the Assimp structures.
void get_extensions(std::string &ext) const
Returns a space-separated list of extensions that Assimp can load, without the leading dots.
bool read(const Filename &filename)
Reads from the indicated file.
void build_graph()
Converts scene graph structures into a Panda3D scene graph, with _root being the root node.
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
The name of a file, such as a texture file or an Egg file.
Definition filename.h:44
A container for geometry primitives.
Definition geom.h:54
A node of this type is created automatically at the root of each model file that is loaded.
Definition modelRoot.h:27
A standard mutex, or mutual exclusion lock.
Definition pmutex.h:40
A basic node of the scene graph or data graph.
Definition pandaNode.h:65
This is the base class for PartRoot and MovingPart.
Definition partGroup.h:43
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
Definition renderState.h:47
Applies a transform matrix to UV's before they are rendered.
Indicates the set of TextureStages and their associated Textures that should be applied to (or remove...
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
A base class for things which need to inherit from both TypedObject and from ReferenceCount.
This is our own Panda specialization on the default STL map.
Definition pmap.h:49
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.