Panda3D
 All Classes Functions Variables Enumerations
load_collada_file.cxx
1 // Filename: load_dae_file.cxx
2 // Created by: rdb (16Mar11)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "load_collada_file.h"
16 #include "colladaLoader.h"
17 #include "config_collada.h"
18 #include "sceneGraphReducer.h"
19 #include "virtualFileSystem.h"
20 #include "config_util.h"
21 #include "bamCacheRecord.h"
22 
23 static PT(PandaNode)
24 load_from_loader(ColladaLoader &loader) {
25  loader.build_graph();
26 
27  if (loader._error && !collada_accept_errors) {
28  collada_cat.error()
29  << "Errors in collada file.\n";
30  return NULL;
31  }
32 
33  if (loader._root != NULL && collada_flatten) {
35 
36  int combine_siblings_bits = 0;
37  if (collada_combine_geoms) {
38  combine_siblings_bits |= SceneGraphReducer::CS_geom_node;
39  }
40  if (collada_flatten_radius > 0.0) {
41  combine_siblings_bits |= SceneGraphReducer::CS_within_radius;
42  gr.set_combine_radius(collada_flatten_radius);
43  }
44 
45  int num_reduced = gr.flatten(loader._root, combine_siblings_bits);
46  collada_cat.info() << "Flattened " << num_reduced << " nodes.\n";
47 
48  if (collada_unify) {
49  // We want to premunge before unifying, since otherwise we risk
50  // needlessly duplicating vertices.
51  if (premunge_data) {
52  gr.premunge(loader._root, RenderState::make_empty());
53  }
54  gr.collect_vertex_data(loader._root);
55  gr.unify(loader._root, true);
56  if (collada_cat.is_debug()) {
57  collada_cat.debug() << "Unified.\n";
58  }
59  }
60  }
61 
62  return DCAST(ModelRoot, loader._root);
63 }
64 
65 ////////////////////////////////////////////////////////////////////
66 // Function: load_collada_file
67 // Description: A convenience function. Loads up the indicated
68 // dae file, and returns the root of a scene graph.
69 // Returns NULL if the file cannot be read for some
70 // reason. Does not search along the model path for
71 // the filename first.
72 ////////////////////////////////////////////////////////////////////
73 PT(PandaNode)
74 load_collada_file(const Filename &filename, CoordinateSystem cs,
75  BamCacheRecord *record) {
76 
78 
79  if (record != (BamCacheRecord *)NULL) {
80  record->add_dependent_file(filename);
81  }
82 
83  ColladaLoader loader;
84  loader._filename = filename;
85  loader._cs = cs;
86  loader._record = record;
87 
88  collada_cat.info()
89  << "Reading " << filename << "\n";
90 
91  if (!loader.read(filename)) {
92  return NULL;
93  }
94 
95  return load_from_loader(loader);
96 }
A node of this type is created automatically at the root of each model file that is loaded...
Definition: modelRoot.h:31
Object that interfaces with the COLLADA DOM library and loads the COLLADA structures into Panda nodes...
Definition: colladaLoader.h:48
A basic node of the scene graph or data graph.
Definition: pandaNode.h:72
int collect_vertex_data(PandaNode *root, int collect_bits=~0)
Collects all different GeomVertexData blocks that have compatible formats at this node and below into...
A hierarchy of directories and files that appears to be one continuous file system, even though the files may originate from several different sources that may not be related to the actual OS&#39;s file system.
An interface for simplifying (&quot;flattening&quot;) scene graphs by eliminating unneeded nodes and collapsing...
void set_combine_radius(PN_stdfloat combine_radius)
Specifies the radius that is used in conjunction with CS_within_radius to decide whether a subgraph&#39;s...
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:44
void unify(PandaNode *root, bool preserve_order)
Calls unify() on every GeomNode at this level and below.
An instance of this class is written to the front of a Bam or Txo file to make the file a cached inst...
static VirtualFileSystem * get_global_ptr()
Returns the default global VirtualFileSystem.
void premunge(PandaNode *root, const RenderState *initial_state)
Walks the scene graph rooted at this node and below, and uses the indicated GSG to premunge every Geo...
int flatten(PandaNode *root, int combine_siblings_bits)
Simplifies the graph by removing unnecessary nodes and nodes.
bool read(const Filename &filename)
Reads from the indicated file.