mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-01 01:07:51 -04:00
Remove unfinished native COLLADA loader
This commit is contained in:
parent
a9dfd8352e
commit
d62c2bf132
@ -1,93 +0,0 @@
|
||||
/**
|
||||
* PANDA 3D SOFTWARE
|
||||
* Copyright (c) Carnegie Mellon University. All rights reserved.
|
||||
*
|
||||
* All use of this software is subject to the terms of the revised BSD
|
||||
* license. You should have received a copy of this license along
|
||||
* with this source code in a file named "LICENSE."
|
||||
*
|
||||
* @file colladaBindMaterial.cxx
|
||||
* @author rdb
|
||||
* @date 2011-05-26
|
||||
*/
|
||||
|
||||
#include "colladaBindMaterial.h"
|
||||
#include "colladaPrimitive.h"
|
||||
|
||||
// Collada DOM includes. No other includes beyond this point.
|
||||
#include "pre_collada_include.h"
|
||||
#include <dom/domBind_material.h>
|
||||
#include <dom/domEffect.h>
|
||||
#include <dom/domInstance_effect.h>
|
||||
#include <dom/domInstance_material.h>
|
||||
#include <dom/domMaterial.h>
|
||||
|
||||
#if PANDA_COLLADA_VERSION >= 15
|
||||
#include <dom/domFx_profile.h>
|
||||
#else
|
||||
#include <dom/domFx_profile_abstract.h>
|
||||
#define domFx_profile domFx_profile_abstract
|
||||
#define domFx_profile_Array domFx_profile_abstract_Array
|
||||
#define getFx_profile_array getFx_profile_abstract_array
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Returns the material to be applied to the given primitive, or NULL if there
|
||||
* was none bound.
|
||||
*/
|
||||
CPT(RenderState) ColladaBindMaterial::
|
||||
get_material(const ColladaPrimitive *prim) const {
|
||||
if (prim == nullptr || _states.count(prim->get_material()) == 0) {
|
||||
return nullptr;
|
||||
}
|
||||
return _states.find(prim->get_material())->second;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the bound material with the indicated symbol, or NULL if it was not
|
||||
* found.
|
||||
*/
|
||||
CPT(RenderState) ColladaBindMaterial::
|
||||
get_material(const std::string &symbol) const {
|
||||
if (_states.count(symbol) == 0) {
|
||||
return nullptr;
|
||||
}
|
||||
return _states.find(symbol)->second;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a bind_material object.
|
||||
*/
|
||||
void ColladaBindMaterial::
|
||||
load_bind_material(domBind_material &bind_mat) {
|
||||
domInstance_material_Array &mat_instances
|
||||
= bind_mat.getTechnique_common()->getInstance_material_array();
|
||||
|
||||
for (size_t i = 0; i < mat_instances.getCount(); ++i) {
|
||||
load_instance_material(*mat_instances[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads an instance_material object.
|
||||
*/
|
||||
void ColladaBindMaterial::
|
||||
load_instance_material(domInstance_material &inst) {
|
||||
domMaterialRef mat = daeSafeCast<domMaterial> (inst.getTarget().getElement());
|
||||
nassertv(mat != nullptr);
|
||||
|
||||
domInstance_effectRef einst = mat->getInstance_effect();
|
||||
nassertv(einst != nullptr);
|
||||
|
||||
domInstance_effect::domSetparam_Array &setparams = einst->getSetparam_array();
|
||||
|
||||
domEffectRef effect = daeSafeCast<domEffect>
|
||||
(mat->getInstance_effect()->getUrl().getElement());
|
||||
|
||||
// TODO: read params
|
||||
|
||||
const domFx_profile_Array &profiles = effect->getFx_profile_array();
|
||||
for (size_t i = 0; i < profiles.getCount(); ++i) {
|
||||
// profiles[i]->
|
||||
}
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
/**
|
||||
* PANDA 3D SOFTWARE
|
||||
* Copyright (c) Carnegie Mellon University. All rights reserved.
|
||||
*
|
||||
* All use of this software is subject to the terms of the revised BSD
|
||||
* license. You should have received a copy of this license along
|
||||
* with this source code in a file named "LICENSE."
|
||||
*
|
||||
* @file colladaBindMaterial.h
|
||||
* @author rdb
|
||||
* @date 2011-05-25
|
||||
*/
|
||||
|
||||
#ifndef COLLADABINDMATERIAL_H
|
||||
#define COLLADABINDMATERIAL_H
|
||||
|
||||
#include "config_collada.h"
|
||||
#include "renderState.h"
|
||||
#include "pmap.h"
|
||||
|
||||
class ColladaPrimitive;
|
||||
|
||||
class domBind_material;
|
||||
class domInstance_material;
|
||||
|
||||
/**
|
||||
* Class that deals with binding materials to COLLADA geometry.
|
||||
*/
|
||||
class ColladaBindMaterial {
|
||||
public:
|
||||
CPT(RenderState) get_material(const ColladaPrimitive *prim) const;
|
||||
CPT(RenderState) get_material(const std::string &symbol) const;
|
||||
|
||||
void load_bind_material(domBind_material &bind_mat);
|
||||
void load_instance_material(domInstance_material &inst);
|
||||
|
||||
private:
|
||||
pmap<std::string, CPT(RenderState)> _states;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,28 +0,0 @@
|
||||
/**
|
||||
* PANDA 3D SOFTWARE
|
||||
* Copyright (c) Carnegie Mellon University. All rights reserved.
|
||||
*
|
||||
* All use of this software is subject to the terms of the revised BSD
|
||||
* license. You should have received a copy of this license along
|
||||
* with this source code in a file named "LICENSE."
|
||||
*
|
||||
* @file colladaInput.I
|
||||
* @author rdb
|
||||
* @date 2011-05-23
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns true if this has a <vertices> element as source.
|
||||
*/
|
||||
bool ColladaInput::
|
||||
is_vertex_source() const {
|
||||
return (_semantic == "VERTEX");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the offset associated with this input.
|
||||
*/
|
||||
unsigned int ColladaInput::
|
||||
get_offset() const {
|
||||
return _offset;
|
||||
}
|
@ -1,265 +0,0 @@
|
||||
/**
|
||||
* PANDA 3D SOFTWARE
|
||||
* Copyright (c) Carnegie Mellon University. All rights reserved.
|
||||
*
|
||||
* All use of this software is subject to the terms of the revised BSD
|
||||
* license. You should have received a copy of this license along
|
||||
* with this source code in a file named "LICENSE."
|
||||
*
|
||||
* @file colladaInput.cxx
|
||||
* @author rdb
|
||||
* @date 2011-05-23
|
||||
*/
|
||||
|
||||
#include "colladaInput.h"
|
||||
#include "string_utils.h"
|
||||
#include "geomVertexArrayFormat.h"
|
||||
#include "geomVertexWriter.h"
|
||||
|
||||
// Collada DOM includes. No other includes beyond this point.
|
||||
#include "pre_collada_include.h"
|
||||
#include <dom/domAccessor.h>
|
||||
#include <dom/domP.h>
|
||||
#include <dom/domSource.h>
|
||||
#include <dom/domVertices.h>
|
||||
|
||||
#if PANDA_COLLADA_VERSION >= 15
|
||||
#include <dom/domInput_local_offset.h>
|
||||
#include <dom/domInput_local.h>
|
||||
#else
|
||||
#include <dom/domInputLocalOffset.h>
|
||||
#include <dom/domInputLocal.h>
|
||||
#define domList_of_floats domListOfFloats
|
||||
#define domList_of_uints domListOfUInts
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Pretty obvious what this does.
|
||||
*/
|
||||
ColladaInput::
|
||||
ColladaInput(const std::string &semantic) :
|
||||
_column_name (nullptr),
|
||||
_semantic (semantic),
|
||||
_offset (0),
|
||||
_have_set (false),
|
||||
_set (0) {
|
||||
|
||||
if (semantic == "POSITION") {
|
||||
_column_name = InternalName::get_vertex();
|
||||
_column_contents = GeomEnums::C_point;
|
||||
} else if (semantic == "COLOR") {
|
||||
_column_name = InternalName::get_color();
|
||||
_column_contents = GeomEnums::C_color;
|
||||
} else if (semantic == "NORMAL") {
|
||||
_column_name = InternalName::get_normal();
|
||||
_column_contents = GeomEnums::C_vector;
|
||||
} else if (semantic == "TEXCOORD") {
|
||||
_column_name = InternalName::get_texcoord();
|
||||
_column_contents = GeomEnums::C_texcoord;
|
||||
} else if (semantic == "TEXBINORMAL") {
|
||||
_column_name = InternalName::get_binormal();
|
||||
_column_contents = GeomEnums::C_vector;
|
||||
} else if (semantic == "TEXTANGENT") {
|
||||
_column_name = InternalName::get_tangent();
|
||||
_column_contents = GeomEnums::C_vector;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pretty obvious what this does.
|
||||
*/
|
||||
ColladaInput::
|
||||
ColladaInput(const std::string &semantic, unsigned int set) :
|
||||
_column_name (nullptr),
|
||||
_semantic (semantic),
|
||||
_offset (0),
|
||||
_have_set (true),
|
||||
_set (set) {
|
||||
|
||||
std::ostringstream setstr;
|
||||
setstr << _set;
|
||||
|
||||
if (semantic == "POSITION") {
|
||||
_column_name = InternalName::get_vertex();
|
||||
_column_contents = GeomEnums::C_point;
|
||||
} else if (semantic == "COLOR") {
|
||||
_column_name = InternalName::get_color();
|
||||
_column_contents = GeomEnums::C_color;
|
||||
} else if (semantic == "NORMAL") {
|
||||
_column_name = InternalName::get_normal();
|
||||
_column_contents = GeomEnums::C_vector;
|
||||
} else if (semantic == "TEXCOORD") {
|
||||
_column_name = InternalName::get_texcoord_name(setstr.str());
|
||||
_column_contents = GeomEnums::C_texcoord;
|
||||
} else if (semantic == "TEXBINORMAL") {
|
||||
_column_name = InternalName::get_binormal_name(setstr.str());
|
||||
_column_contents = GeomEnums::C_vector;
|
||||
} else if (semantic == "TEXTANGENT") {
|
||||
_column_name = InternalName::get_tangent_name(setstr.str());
|
||||
_column_contents = GeomEnums::C_vector;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ColladaInput object that represents the provided DOM input
|
||||
* element.
|
||||
*/
|
||||
ColladaInput *ColladaInput::
|
||||
from_dom(domInput_local_offset &input) {
|
||||
// If we already loaded it before, use that.
|
||||
if (input.getUserData() != nullptr) {
|
||||
return (ColladaInput *) input.getUserData();
|
||||
}
|
||||
|
||||
ColladaInput *new_input = new ColladaInput(input.getSemantic(), input.getSet());
|
||||
new_input->_offset = input.getOffset();
|
||||
|
||||
// If this has the VERTEX semantic, it points to a <vertices> element.
|
||||
if (new_input->is_vertex_source()) {
|
||||
domVertices *verts = daeSafeCast<domVertices> (input.getSource().getElement());
|
||||
nassertr(verts != nullptr, nullptr);
|
||||
daeTArray<domInput_localRef> &inputs = verts->getInput_array();
|
||||
|
||||
// Iterate over the <input> elements in <vertices>.
|
||||
for (size_t i = 0; i < inputs.getCount(); ++i) {
|
||||
PT(ColladaInput) vtx_input = ColladaInput::from_dom(*inputs[i]);
|
||||
new_input->_vertex_inputs.push_back(vtx_input);
|
||||
}
|
||||
} else {
|
||||
domSource *source = daeSafeCast<domSource> (input.getSource().getElement());
|
||||
nassertr(source != nullptr, nullptr);
|
||||
new_input->read_data(*source);
|
||||
}
|
||||
|
||||
return new_input;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ColladaInput object that represents the provided DOM input
|
||||
* element.
|
||||
*/
|
||||
ColladaInput *ColladaInput::
|
||||
from_dom(domInput_local &input) {
|
||||
// If we already loaded it before, use that.
|
||||
if (input.getUserData() != nullptr) {
|
||||
return (ColladaInput *) input.getUserData();
|
||||
}
|
||||
|
||||
ColladaInput *new_input = new ColladaInput(input.getSemantic());
|
||||
new_input->_offset = 0;
|
||||
|
||||
nassertr (!new_input->is_vertex_source(), nullptr);
|
||||
|
||||
domSource *source = daeSafeCast<domSource> (input.getSource().getElement());
|
||||
nassertr(source != nullptr, nullptr);
|
||||
new_input->read_data(*source);
|
||||
|
||||
return new_input;
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes a semantic and source URI, and adds a new column to the format. If
|
||||
* this is a vertex source, adds all of the inputs from the corresponding
|
||||
* <vertices> element. Returns the number of columns added to the format.
|
||||
*/
|
||||
int ColladaInput::
|
||||
make_vertex_columns(GeomVertexArrayFormat *format) const {
|
||||
|
||||
if (is_vertex_source()) {
|
||||
int counter = 0;
|
||||
Inputs::const_iterator it;
|
||||
for (it = _vertex_inputs.begin(); it != _vertex_inputs.end(); ++it) {
|
||||
counter += (*it)->make_vertex_columns(format);
|
||||
}
|
||||
return counter;
|
||||
}
|
||||
|
||||
nassertr(_column_name != nullptr, 0);
|
||||
|
||||
format->add_column(_column_name, _num_bound_params, GeomEnums::NT_stdfloat, _column_contents);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the data from the source and fills in _data.
|
||||
*/
|
||||
bool ColladaInput::
|
||||
read_data(domSource &source) {
|
||||
_data.clear();
|
||||
|
||||
// Get this, get that
|
||||
domFloat_array* float_array = source.getFloat_array();
|
||||
if (float_array == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
domList_of_floats &floats = float_array->getValue();
|
||||
domAccessor &accessor = *source.getTechnique_common()->getAccessor();
|
||||
domParam_Array ¶ms = accessor.getParam_array();
|
||||
|
||||
// Count the number of params that have a name attribute.
|
||||
_num_bound_params = 0;
|
||||
for (size_t p = 0; p < params.getCount(); ++p) {
|
||||
if (params[p]->getName()) {
|
||||
++_num_bound_params;
|
||||
}
|
||||
}
|
||||
|
||||
_data.reserve(accessor.getCount());
|
||||
|
||||
domUint pos = accessor.getOffset();
|
||||
for (domUint a = 0; a < accessor.getCount(); ++a) {
|
||||
domUint c = 0;
|
||||
// Yes, the last component defaults to 1 to work around a perspective
|
||||
// divide that Panda3D does internally for points.
|
||||
LVecBase4f v (0, 0, 0, 1);
|
||||
for (domUint p = 0; p < params.getCount(); ++p) {
|
||||
if (params[c]->getName()) {
|
||||
v[c++] = floats[pos + p];
|
||||
}
|
||||
}
|
||||
_data.push_back(v);
|
||||
pos += accessor.getStride();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes data to the indicated GeomVertexData using the given indices.
|
||||
*/
|
||||
void ColladaInput::
|
||||
write_data(GeomVertexData *vdata, int start_row, domP &p, unsigned int stride) const {
|
||||
if (is_vertex_source()) {
|
||||
Inputs::const_iterator it;
|
||||
for (it = _vertex_inputs.begin(); it != _vertex_inputs.end(); ++it) {
|
||||
(*it)->write_data(vdata, start_row, p, stride, _offset);
|
||||
}
|
||||
|
||||
} else {
|
||||
write_data(vdata, start_row, p, stride, _offset);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called internally by the other write_data.
|
||||
*/
|
||||
void ColladaInput::
|
||||
write_data(GeomVertexData *vdata, int start_row, domP &p, unsigned int stride, unsigned int offset) const {
|
||||
nassertv(_column_name != nullptr);
|
||||
GeomVertexWriter writer (vdata, _column_name);
|
||||
writer.set_row_unsafe(start_row);
|
||||
|
||||
domList_of_uints &indices = p.getValue();
|
||||
|
||||
// Allocate space for all the rows we're going to write.
|
||||
int min_length = start_row + indices.getCount() / stride;
|
||||
if (vdata->get_num_rows() < min_length) {
|
||||
vdata->unclean_set_num_rows(start_row);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < indices.getCount(); i += stride) {
|
||||
size_t index = indices[i + offset];
|
||||
writer.add_data4f(_data[index]);
|
||||
}
|
||||
}
|
@ -1,77 +0,0 @@
|
||||
/**
|
||||
* PANDA 3D SOFTWARE
|
||||
* Copyright (c) Carnegie Mellon University. All rights reserved.
|
||||
*
|
||||
* All use of this software is subject to the terms of the revised BSD
|
||||
* license. You should have received a copy of this license along
|
||||
* with this source code in a file named "LICENSE."
|
||||
*
|
||||
* @file colladaInput.h
|
||||
* @author rdb
|
||||
* @date 2011-05-23
|
||||
*/
|
||||
|
||||
#ifndef COLLADAINPUT_H
|
||||
#define COLLADAINPUT_H
|
||||
|
||||
#include "config_collada.h"
|
||||
#include "referenceCount.h"
|
||||
#include "pvector.h"
|
||||
#include "pta_LVecBase4.h"
|
||||
#include "internalName.h"
|
||||
#include "geomEnums.h"
|
||||
|
||||
class GeomPrimitive;
|
||||
class GeomVertexArrayFormat;
|
||||
class GeomVertexData;
|
||||
|
||||
#if PANDA_COLLADA_VERSION < 15
|
||||
#define domInput_local domInputLocal
|
||||
#define domInput_localRef domInputLocalRef
|
||||
#define domInput_local_offset domInputLocalOffset
|
||||
#define domInput_local_offsetRef domInputLocalOffsetRef
|
||||
#endif
|
||||
|
||||
class domInput_local;
|
||||
class domInput_local_offset;
|
||||
class domP;
|
||||
class domSource;
|
||||
|
||||
/**
|
||||
* Class that deals with COLLADA data sources.
|
||||
*/
|
||||
class ColladaInput : public ReferenceCount {
|
||||
public:
|
||||
static ColladaInput *from_dom(domInput_local_offset &input);
|
||||
static ColladaInput *from_dom(domInput_local &input);
|
||||
|
||||
int make_vertex_columns(GeomVertexArrayFormat *fmt) const;
|
||||
void write_data(GeomVertexData *vdata, int start_row, domP &p, unsigned int stride) const;
|
||||
|
||||
INLINE bool is_vertex_source() const;
|
||||
INLINE unsigned int get_offset() const;
|
||||
|
||||
private:
|
||||
ColladaInput(const std::string &semantic);
|
||||
ColladaInput(const std::string &semantic, unsigned int set);
|
||||
bool read_data(domSource &source);
|
||||
void write_data(GeomVertexData *vdata, int start_row, domP &p, unsigned int stride, unsigned int offset) const;
|
||||
|
||||
typedef pvector<PT(ColladaInput)> Inputs;
|
||||
Inputs _vertex_inputs;
|
||||
PTA_LVecBase4f _data;
|
||||
|
||||
// Only filled in when appropriate.
|
||||
PT(InternalName) _column_name;
|
||||
GeomEnums::Contents _column_contents;
|
||||
|
||||
unsigned int _num_bound_params;
|
||||
unsigned int _offset;
|
||||
std::string _semantic;
|
||||
bool _have_set;
|
||||
unsigned int _set;
|
||||
};
|
||||
|
||||
#include "colladaInput.I"
|
||||
|
||||
#endif
|
@ -1,12 +0,0 @@
|
||||
/**
|
||||
* PANDA 3D SOFTWARE
|
||||
* Copyright (c) Carnegie Mellon University. All rights reserved.
|
||||
*
|
||||
* All use of this software is subject to the terms of the revised BSD
|
||||
* license. You should have received a copy of this license along
|
||||
* with this source code in a file named "LICENSE."
|
||||
*
|
||||
* @file colladaLoader.I
|
||||
* @author rdb
|
||||
* @date 2011-03-16
|
||||
*/
|
@ -1,549 +0,0 @@
|
||||
/**
|
||||
* PANDA 3D SOFTWARE
|
||||
* Copyright (c) Carnegie Mellon University. All rights reserved.
|
||||
*
|
||||
* All use of this software is subject to the terms of the revised BSD
|
||||
* license. You should have received a copy of this license along
|
||||
* with this source code in a file named "LICENSE."
|
||||
*
|
||||
* @file colladaLoader.cxx
|
||||
* @author Xidram
|
||||
* @date 2010-12-21
|
||||
*/
|
||||
|
||||
#include "colladaLoader.h"
|
||||
#include "virtualFileSystem.h"
|
||||
#include "luse.h"
|
||||
#include "string_utils.h"
|
||||
#include "geomNode.h"
|
||||
#include "geomVertexWriter.h"
|
||||
#include "geomTriangles.h"
|
||||
#include "lightNode.h"
|
||||
#include "lightAttrib.h"
|
||||
#include "ambientLight.h"
|
||||
#include "directionalLight.h"
|
||||
#include "pointLight.h"
|
||||
#include "spotlight.h"
|
||||
|
||||
#include "colladaBindMaterial.h"
|
||||
#include "colladaPrimitive.h"
|
||||
|
||||
// Collada DOM includes. No other includes beyond this point.
|
||||
#include "pre_collada_include.h"
|
||||
#include <dom/domCOLLADA.h>
|
||||
#include <dom/domNode.h>
|
||||
#include <dom/domVisual_scene.h>
|
||||
#include <dom/domTranslate.h>
|
||||
#include <dom/domRotate.h>
|
||||
#include <dom/domMatrix.h>
|
||||
|
||||
#if PANDA_COLLADA_VERSION >= 15
|
||||
#include <dom/domInstance_with_extra.h>
|
||||
#else
|
||||
#include <dom/domInstanceWithExtra.h>
|
||||
#define domInstance_with_extra domInstanceWithExtra
|
||||
#define domTargetable_floatRef domTargetableFloatRef
|
||||
#endif
|
||||
|
||||
#define TOSTRING(x) (x == nullptr ? "" : x)
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
ColladaLoader::
|
||||
ColladaLoader() :
|
||||
_record (nullptr),
|
||||
_cs (CS_default),
|
||||
_error (false),
|
||||
_root (nullptr),
|
||||
_collada (nullptr) {
|
||||
|
||||
_dae = new DAE;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
ColladaLoader::
|
||||
~ColladaLoader() {
|
||||
delete _dae;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads from the indicated file.
|
||||
*/
|
||||
bool ColladaLoader::
|
||||
read(const Filename &filename) {
|
||||
_filename = filename;
|
||||
|
||||
std::string data;
|
||||
VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr();
|
||||
|
||||
if (!vfs->read_file(_filename, data, true)) {
|
||||
collada_cat.error()
|
||||
<< "Error reading " << _filename << "\n";
|
||||
_error = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
_collada = _dae->openFromMemory(_filename.to_os_specific(), data.c_str());
|
||||
_error = (_collada == nullptr);
|
||||
return !_error;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts scene graph structures into a Panda3D scene graph, with _root
|
||||
* being the root node.
|
||||
*/
|
||||
void ColladaLoader::
|
||||
build_graph() {
|
||||
nassertv(_collada); // read() must be called first
|
||||
nassertv(!_error); // and have succeeded
|
||||
|
||||
_root = new ModelRoot(_filename.get_basename());
|
||||
|
||||
domCOLLADA::domScene* scene = _collada->getScene();
|
||||
domInstance_with_extra* inst = scene->getInstance_visual_scene();
|
||||
domVisual_scene* vscene = daeSafeCast<domVisual_scene> (inst->getUrl().getElement());
|
||||
if (vscene) {
|
||||
load_visual_scene(*vscene, _root);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a visual scene structure.
|
||||
*/
|
||||
void ColladaLoader::
|
||||
load_visual_scene(domVisual_scene& scene, PandaNode *parent) {
|
||||
// If we already loaded it before, instantiate the stored node.
|
||||
if (scene.getUserData() != nullptr) {
|
||||
parent->add_child((PandaNode *) scene.getUserData());
|
||||
return;
|
||||
}
|
||||
|
||||
PT(PandaNode) pnode = new PandaNode(TOSTRING(scene.getName()));
|
||||
scene.setUserData((void *) pnode);
|
||||
parent->add_child(pnode);
|
||||
|
||||
// Load in any tags.
|
||||
domExtra_Array &extras = scene.getExtra_array();
|
||||
for (size_t i = 0; i < extras.getCount(); ++i) {
|
||||
load_tags(*extras[i], pnode);
|
||||
}
|
||||
|
||||
// Now load in the child nodes.
|
||||
domNode_Array &nodes = scene.getNode_array();
|
||||
for (size_t i = 0; i < nodes.getCount(); ++i) {
|
||||
load_node(*nodes[i], pnode);
|
||||
}
|
||||
|
||||
// Apply any lights we've encountered to the visual scene.
|
||||
if (_lights.size() > 0) {
|
||||
CPT(LightAttrib) lattr = DCAST(LightAttrib, LightAttrib::make());
|
||||
pvector<LightNode*>::iterator it;
|
||||
for (it = _lights.begin(); it != _lights.end(); ++it) {
|
||||
lattr = DCAST(LightAttrib, lattr->add_on_light(*it));
|
||||
}
|
||||
pnode->set_state(RenderState::make(lattr));
|
||||
|
||||
_lights.clear();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a COLLADA <node>.
|
||||
*/
|
||||
void ColladaLoader::
|
||||
load_node(domNode& node, PandaNode *parent) {
|
||||
// If we already loaded it before, instantiate the stored node.
|
||||
if (node.getUserData() != nullptr) {
|
||||
parent->add_child((PandaNode *) node.getUserData());
|
||||
return;
|
||||
}
|
||||
|
||||
// Create the node.
|
||||
PT(PandaNode) pnode;
|
||||
pnode = new PandaNode(TOSTRING(node.getName()));
|
||||
node.setUserData((void *) pnode);
|
||||
parent->add_child(pnode);
|
||||
|
||||
// Apply the transformation elements in reverse order.
|
||||
LMatrix4f transform (LMatrix4f::ident_mat());
|
||||
|
||||
daeElementRefArray &elements = node.getContents();
|
||||
for (size_t i = elements.getCount(); i > 0; --i) {
|
||||
daeElementRef &elem = elements[i - 1];
|
||||
|
||||
switch (elem->getElementType()) {
|
||||
case COLLADA_TYPE::LOOKAT: {
|
||||
// Didn't test this, but *should* be right.
|
||||
domFloat3x3 &l = (daeSafeCast<domLookat>(elem))->getValue();
|
||||
LPoint3f eye (l[0], l[1], l[2]);
|
||||
LVector3f up (l[6], l[7], l[8]);
|
||||
LVector3f forward = LPoint3f(l[3], l[4], l[5]) - eye;
|
||||
forward.normalize();
|
||||
LVector3f side = forward.cross(up);
|
||||
side.normalize();
|
||||
up = side.cross(forward);
|
||||
LMatrix4f mat (LMatrix4f::ident_mat());
|
||||
mat.set_col(0, side);
|
||||
mat.set_col(1, up);
|
||||
mat.set_col(2, -forward);
|
||||
transform *= mat;
|
||||
transform *= LMatrix4f::translate_mat(-eye);
|
||||
break;
|
||||
}
|
||||
case COLLADA_TYPE::MATRIX: {
|
||||
domFloat4x4 &m = (daeSafeCast<domMatrix>(elem))->getValue();
|
||||
transform *= LMatrix4f(
|
||||
m[0], m[4], m[ 8], m[12],
|
||||
m[1], m[5], m[ 9], m[13],
|
||||
m[2], m[6], m[10], m[14],
|
||||
m[3], m[7], m[11], m[15]);
|
||||
break;
|
||||
}
|
||||
case COLLADA_TYPE::ROTATE: {
|
||||
domFloat4 &r = (daeSafeCast<domRotate>(elem))->getValue();
|
||||
transform *= LMatrix4f::rotate_mat(r[3], LVecBase3f(r[0], r[1], r[2]));
|
||||
break;
|
||||
}
|
||||
case COLLADA_TYPE::SCALE: {
|
||||
domFloat3 &s = (daeSafeCast<domScale>(elem))->getValue();
|
||||
transform *= LMatrix4f::scale_mat(s[0], s[1], s[2]);
|
||||
break;
|
||||
}
|
||||
case COLLADA_TYPE::SKEW:
|
||||
// FIXME: implement skew
|
||||
collada_cat.error() << "<skew> not supported yet\n";
|
||||
break;
|
||||
case COLLADA_TYPE::TRANSLATE: {
|
||||
domFloat3 &t = (daeSafeCast<domTranslate>(elem))->getValue();
|
||||
transform *= LMatrix4f::translate_mat(t[0], t[1], t[2]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// TODO: convert coordinate systems transform *= LMatrix4f::convert_mat(XXX,
|
||||
// _cs);
|
||||
|
||||
// If there's a transform, set it.
|
||||
if (transform != LMatrix4f::ident_mat()) {
|
||||
pnode->set_transform(TransformState::make_mat(transform));
|
||||
}
|
||||
|
||||
// See if this node instantiates any cameras.
|
||||
domInstance_camera_Array &caminst = node.getInstance_camera_array();
|
||||
for (size_t i = 0; i < caminst.getCount(); ++i) {
|
||||
domCamera* target = daeSafeCast<domCamera> (caminst[i]->getUrl().getElement());
|
||||
load_camera(*target, pnode);
|
||||
}
|
||||
|
||||
// See if this node instantiates any controllers.
|
||||
domInstance_controller_Array &ctrlinst = node.getInstance_controller_array();
|
||||
for (size_t i = 0; i < ctrlinst.getCount(); ++i) {
|
||||
domController* target = daeSafeCast<domController> (ctrlinst[i]->getUrl().getElement());
|
||||
// TODO: implement controllers. For now, let's just read the geometry
|
||||
if (target->getSkin() != nullptr) {
|
||||
domGeometry* geom = daeSafeCast<domGeometry> (target->getSkin()->getSource().getElement());
|
||||
// TODO load_geometry(*geom, ctrlinst[i]->getBind_material(), pnode);
|
||||
}
|
||||
}
|
||||
|
||||
// See if this node instantiates any geoms.
|
||||
domInstance_geometry_Array &ginst = node.getInstance_geometry_array();
|
||||
for (size_t i = 0; i < ginst.getCount(); ++i) {
|
||||
load_instance_geometry(*ginst[i], pnode);
|
||||
}
|
||||
|
||||
// See if this node instantiates any lights.
|
||||
domInstance_light_Array &linst = node.getInstance_light_array();
|
||||
for (size_t i = 0; i < linst.getCount(); ++i) {
|
||||
domLight* target = daeSafeCast<domLight> (linst[i]->getUrl().getElement());
|
||||
load_light(*target, pnode);
|
||||
}
|
||||
|
||||
// And instantiate any <instance_nodes> elements.
|
||||
domInstance_node_Array &ninst = node.getInstance_node_array();
|
||||
for (size_t i = 0; i < ninst.getCount(); ++i) {
|
||||
domNode* target = daeSafeCast<domNode> (ninst[i]->getUrl().getElement());
|
||||
load_node(*target, pnode);
|
||||
}
|
||||
|
||||
// Now load in the child nodes.
|
||||
domNode_Array &nodes = node.getNode_array();
|
||||
for (size_t i = 0; i < nodes.getCount(); ++i) {
|
||||
load_node(*nodes[i], pnode);
|
||||
}
|
||||
|
||||
// Load in any tags.
|
||||
domExtra_Array &extras = node.getExtra_array();
|
||||
for (size_t i = 0; i < extras.getCount(); ++i) {
|
||||
load_tags(*extras[i], pnode);
|
||||
// TODO: load SI_Visibility under XSI profile TODO: support
|
||||
// OpenSceneGraph's switch nodes
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads tags specified in an <extra> element.
|
||||
*/
|
||||
void ColladaLoader::
|
||||
load_tags(domExtra &extra, PandaNode *node) {
|
||||
domTechnique_Array &techniques = extra.getTechnique_array();
|
||||
|
||||
for (size_t t = 0; t < techniques.getCount(); ++t) {
|
||||
if (cmp_nocase(techniques[t]->getProfile(), "PANDA3D") == 0) {
|
||||
const daeElementRefArray &children = techniques[t]->getChildren();
|
||||
|
||||
for (size_t c = 0; c < children.getCount(); ++c) {
|
||||
daeElement &child = *children[c];
|
||||
|
||||
if (cmp_nocase(child.getElementName(), "tag") == 0) {
|
||||
const std::string &name = child.getAttribute("name");
|
||||
if (name.size() > 0) {
|
||||
node->set_tag(name, child.getCharData());
|
||||
} else {
|
||||
collada_cat.warning() << "Ignoring <tag> without name attribute\n";
|
||||
}
|
||||
} else if (cmp_nocase(child.getElementName(), "param") == 0) {
|
||||
collada_cat.error() <<
|
||||
"Unknown <param> attribute in PANDA3D technique. "
|
||||
"Did you mean to use <tag> instead?\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a COLLADA <camera> as a Camera object.
|
||||
*/
|
||||
void ColladaLoader::
|
||||
load_camera(domCamera &cam, PandaNode *parent) {
|
||||
// If we already loaded it before, instantiate the stored node.
|
||||
if (cam.getUserData() != nullptr) {
|
||||
parent->add_child((PandaNode *) cam.getUserData());
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a COLLADA <instance_geometry> as a GeomNode object.
|
||||
*/
|
||||
void ColladaLoader::
|
||||
load_instance_geometry(domInstance_geometry &inst, PandaNode *parent) {
|
||||
// If we already loaded it before, instantiate the stored node.
|
||||
if (inst.getUserData() != nullptr) {
|
||||
parent->add_child((PandaNode *) inst.getUserData());
|
||||
return;
|
||||
}
|
||||
|
||||
domGeometry* geom = daeSafeCast<domGeometry> (inst.getUrl().getElement());
|
||||
nassertv(geom != nullptr);
|
||||
|
||||
// Create the node.
|
||||
PT(GeomNode) gnode = new GeomNode(TOSTRING(geom->getName()));
|
||||
inst.setUserData((void *) gnode);
|
||||
parent->add_child(gnode);
|
||||
|
||||
domBind_materialRef bind_mat = inst.getBind_material();
|
||||
ColladaBindMaterial cbm;
|
||||
if (bind_mat != nullptr) {
|
||||
cbm.load_bind_material(*bind_mat);
|
||||
}
|
||||
|
||||
load_geometry(*geom, gnode, cbm);
|
||||
|
||||
// Load in any tags.
|
||||
domExtra_Array &extras = geom->getExtra_array();
|
||||
for (size_t i = 0; i < extras.getCount(); ++i) {
|
||||
load_tags(*extras[i], gnode);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a COLLADA <geometry> and adds the primitives to the given GeomNode
|
||||
* object.
|
||||
*/
|
||||
void ColladaLoader::
|
||||
load_geometry(domGeometry &geom, GeomNode *gnode, ColladaBindMaterial &bind_mat) {
|
||||
domMesh* mesh = geom.getMesh();
|
||||
if (mesh == nullptr) {
|
||||
// TODO: support non-mesh geometry.
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: support other than just triangles.
|
||||
domLines_Array &lines_array = mesh->getLines_array();
|
||||
for (size_t i = 0; i < lines_array.getCount(); ++i) {
|
||||
PT(ColladaPrimitive) prim = ColladaPrimitive::from_dom(*lines_array[i]);
|
||||
if (prim != nullptr) {
|
||||
gnode->add_geom(prim->get_geom());
|
||||
}
|
||||
}
|
||||
|
||||
domLinestrips_Array &linestrips_array = mesh->getLinestrips_array();
|
||||
for (size_t i = 0; i < linestrips_array.getCount(); ++i) {
|
||||
PT(ColladaPrimitive) prim = ColladaPrimitive::from_dom(*linestrips_array[i]);
|
||||
if (prim != nullptr) {
|
||||
gnode->add_geom(prim->get_geom());
|
||||
}
|
||||
}
|
||||
|
||||
domPolygons_Array &polygons_array = mesh->getPolygons_array();
|
||||
for (size_t i = 0; i < polygons_array.getCount(); ++i) {
|
||||
PT(ColladaPrimitive) prim = ColladaPrimitive::from_dom(*polygons_array[i]);
|
||||
if (prim != nullptr) {
|
||||
gnode->add_geom(prim->get_geom());
|
||||
}
|
||||
}
|
||||
|
||||
domPolylist_Array &polylist_array = mesh->getPolylist_array();
|
||||
for (size_t i = 0; i < polylist_array.getCount(); ++i) {
|
||||
PT(ColladaPrimitive) prim = ColladaPrimitive::from_dom(*polylist_array[i]);
|
||||
if (prim != nullptr) {
|
||||
gnode->add_geom(prim->get_geom());
|
||||
}
|
||||
}
|
||||
|
||||
domTriangles_Array &triangles_array = mesh->getTriangles_array();
|
||||
for (size_t i = 0; i < triangles_array.getCount(); ++i) {
|
||||
PT(ColladaPrimitive) prim = ColladaPrimitive::from_dom(*triangles_array[i]);
|
||||
if (prim != nullptr) {
|
||||
gnode->add_geom(prim->get_geom());
|
||||
}
|
||||
}
|
||||
|
||||
domTrifans_Array &trifans_array = mesh->getTrifans_array();
|
||||
for (size_t i = 0; i < trifans_array.getCount(); ++i) {
|
||||
PT(ColladaPrimitive) prim = ColladaPrimitive::from_dom(*trifans_array[i]);
|
||||
if (prim != nullptr) {
|
||||
gnode->add_geom(prim->get_geom());
|
||||
}
|
||||
}
|
||||
|
||||
domTristrips_Array &tristrips_array = mesh->getTristrips_array();
|
||||
for (size_t i = 0; i < tristrips_array.getCount(); ++i) {
|
||||
PT(ColladaPrimitive) prim = ColladaPrimitive::from_dom(*tristrips_array[i]);
|
||||
if (prim != nullptr) {
|
||||
gnode->add_geom(prim->get_geom());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a COLLADA <light> as a LightNode object.
|
||||
*/
|
||||
void ColladaLoader::
|
||||
load_light(domLight &light, PandaNode *parent) {
|
||||
// If we already loaded it before, instantiate the stored node.
|
||||
if (light.getUserData() != nullptr) {
|
||||
parent->add_child((PandaNode *) light.getUserData());
|
||||
return;
|
||||
}
|
||||
|
||||
PT(LightNode) lnode;
|
||||
domLight::domTechnique_common &tc = *light.getTechnique_common();
|
||||
|
||||
// Check for an ambient light.
|
||||
domLight::domTechnique_common::domAmbientRef ambient = tc.getAmbient();
|
||||
if (ambient != nullptr) {
|
||||
PT(AmbientLight) alight = new AmbientLight(TOSTRING(light.getName()));
|
||||
lnode = DCAST(LightNode, alight);
|
||||
|
||||
domFloat3 &color = ambient->getColor()->getValue();
|
||||
alight->set_color(LColor(color[0], color[1], color[2], 1.0));
|
||||
}
|
||||
|
||||
// Check for a directional light.
|
||||
domLight::domTechnique_common::domDirectionalRef directional = tc.getDirectional();
|
||||
if (directional != nullptr) {
|
||||
PT(DirectionalLight) dlight = new DirectionalLight(TOSTRING(light.getName()));
|
||||
lnode = DCAST(LightNode, dlight);
|
||||
|
||||
domFloat3 &color = directional->getColor()->getValue();
|
||||
dlight->set_color(LColor(color[0], color[1], color[2], 1.0));
|
||||
dlight->set_direction(LVector3f(0, 0, -1));
|
||||
}
|
||||
|
||||
// Check for a point light.
|
||||
domLight::domTechnique_common::domPointRef point = tc.getPoint();
|
||||
if (point != nullptr) {
|
||||
PT(PointLight) plight = new PointLight(TOSTRING(light.getName()));
|
||||
lnode = DCAST(LightNode, plight);
|
||||
|
||||
domFloat3 &color = point->getColor()->getValue();
|
||||
plight->set_color(LColor(color[0], color[1], color[2], 1.0));
|
||||
|
||||
LVecBase3f atten (1.0f, 0.0f, 0.0f);
|
||||
domTargetable_floatRef fval = point->getConstant_attenuation();
|
||||
if (fval != nullptr) {
|
||||
atten[0] = fval->getValue();
|
||||
}
|
||||
fval = point->getLinear_attenuation();
|
||||
if (fval != nullptr) {
|
||||
atten[1] = fval->getValue();
|
||||
}
|
||||
fval = point->getQuadratic_attenuation();
|
||||
if (fval != nullptr) {
|
||||
atten[2] = fval->getValue();
|
||||
}
|
||||
|
||||
plight->set_attenuation(atten);
|
||||
}
|
||||
|
||||
// Check for a spot light.
|
||||
domLight::domTechnique_common::domSpotRef spot = tc.getSpot();
|
||||
if (spot != nullptr) {
|
||||
PT(Spotlight) slight = new Spotlight(TOSTRING(light.getName()));
|
||||
lnode = DCAST(LightNode, slight);
|
||||
|
||||
domFloat3 &color = spot->getColor()->getValue();
|
||||
slight->set_color(LColor(color[0], color[1], color[2], 1.0));
|
||||
|
||||
LVecBase3f atten (1.0f, 0.0f, 0.0f);
|
||||
domTargetable_floatRef fval = spot->getConstant_attenuation();
|
||||
if (fval != nullptr) {
|
||||
atten[0] = fval->getValue();
|
||||
}
|
||||
fval = spot->getLinear_attenuation();
|
||||
if (fval != nullptr) {
|
||||
atten[1] = fval->getValue();
|
||||
}
|
||||
fval = spot->getQuadratic_attenuation();
|
||||
if (fval != nullptr) {
|
||||
atten[2] = fval->getValue();
|
||||
}
|
||||
|
||||
slight->set_attenuation(atten);
|
||||
|
||||
fval = spot->getFalloff_angle();
|
||||
if (fval != nullptr) {
|
||||
slight->get_lens()->set_fov(fval->getValue());
|
||||
} else {
|
||||
slight->get_lens()->set_fov(180.0f);
|
||||
}
|
||||
|
||||
fval = spot->getFalloff_exponent();
|
||||
if (fval != nullptr) {
|
||||
slight->set_exponent(fval->getValue());
|
||||
} else {
|
||||
slight->set_exponent(0.0f);
|
||||
}
|
||||
}
|
||||
|
||||
if (lnode == nullptr) {
|
||||
return;
|
||||
}
|
||||
parent->add_child(lnode);
|
||||
_lights.push_back(lnode);
|
||||
light.setUserData((void*) lnode);
|
||||
|
||||
// Load in any tags.
|
||||
domExtra_Array &extras = light.getExtra_array();
|
||||
for (size_t i = 0; i < extras.getCount(); ++i) {
|
||||
load_tags(*extras[i], lnode);
|
||||
}
|
||||
}
|
@ -1,76 +0,0 @@
|
||||
/**
|
||||
* PANDA 3D SOFTWARE
|
||||
* Copyright (c) Carnegie Mellon University. All rights reserved.
|
||||
*
|
||||
* All use of this software is subject to the terms of the revised BSD
|
||||
* license. You should have received a copy of this license along
|
||||
* with this source code in a file named "LICENSE."
|
||||
*
|
||||
* @file colladaLoader.h
|
||||
* @author Xidram
|
||||
* @date 2010-12-21
|
||||
*/
|
||||
|
||||
#ifndef COLLADALOADER_H
|
||||
#define COLLADALOADER_H
|
||||
|
||||
#include "pandabase.h"
|
||||
#include "config_collada.h"
|
||||
#include "typedReferenceCount.h"
|
||||
#include "pandaNode.h"
|
||||
#include "modelRoot.h"
|
||||
#include "pvector.h"
|
||||
#include "pta_LVecBase4.h"
|
||||
|
||||
class ColladaBindMaterial;
|
||||
class BamCacheRecord;
|
||||
class GeomNode;
|
||||
class LightNode;
|
||||
|
||||
class domBind_material;
|
||||
class domCOLLADA;
|
||||
class domNode;
|
||||
class domVisual_scene;
|
||||
class domExtra;
|
||||
class domGeometry;
|
||||
class domInstance_geometry;
|
||||
class domLight;
|
||||
class domCamera;
|
||||
class domSource;
|
||||
class DAE;
|
||||
|
||||
/**
|
||||
* Object that interfaces with the COLLADA DOM library and loads the COLLADA
|
||||
* structures into Panda nodes.
|
||||
*/
|
||||
class ColladaLoader {
|
||||
public:
|
||||
ColladaLoader();
|
||||
virtual ~ColladaLoader();
|
||||
|
||||
bool _error;
|
||||
PT(ModelRoot) _root;
|
||||
BamCacheRecord *_record;
|
||||
CoordinateSystem _cs;
|
||||
Filename _filename;
|
||||
|
||||
bool read(const Filename &filename);
|
||||
void build_graph();
|
||||
|
||||
private:
|
||||
const domCOLLADA* _collada;
|
||||
DAE* _dae;
|
||||
pvector<LightNode*> _lights;
|
||||
|
||||
void load_visual_scene(domVisual_scene &scene, PandaNode *parent);
|
||||
void load_node(domNode &node, PandaNode *parent);
|
||||
void load_tags(domExtra &extra, PandaNode *node);
|
||||
void load_camera(domCamera &cam, PandaNode *parent);
|
||||
void load_instance_geometry(domInstance_geometry &inst, PandaNode *parent);
|
||||
void load_geometry(domGeometry &geom, GeomNode *parent, ColladaBindMaterial &bind_mat);
|
||||
void load_light(domLight &light, PandaNode *parent);
|
||||
};
|
||||
|
||||
#include "colladaLoader.I"
|
||||
|
||||
#endif
|
@ -1,40 +0,0 @@
|
||||
/**
|
||||
* PANDA 3D SOFTWARE
|
||||
* Copyright (c) Carnegie Mellon University. All rights reserved.
|
||||
*
|
||||
* All use of this software is subject to the terms of the revised BSD
|
||||
* license. You should have received a copy of this license along
|
||||
* with this source code in a file named "LICENSE."
|
||||
*
|
||||
* @file colladaPrimitive.I
|
||||
* @author rdb
|
||||
* @date 2011-05-23
|
||||
*/
|
||||
|
||||
/**
|
||||
* Adds a new ColladaInput to this primitive.
|
||||
*/
|
||||
INLINE void ColladaPrimitive::
|
||||
add_input(ColladaInput *input) {
|
||||
if (input->get_offset() >= _stride) {
|
||||
_stride = input->get_offset() + 1;
|
||||
}
|
||||
_inputs.push_back(input);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Geom associated with this primitive.
|
||||
*/
|
||||
INLINE PT(Geom) ColladaPrimitive::
|
||||
get_geom() const {
|
||||
return _geom;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of this primitive's material, or the empty string if none
|
||||
* was assigned.
|
||||
*/
|
||||
INLINE const std::string &ColladaPrimitive::
|
||||
get_material() const {
|
||||
return _material;
|
||||
}
|
@ -1,293 +0,0 @@
|
||||
/**
|
||||
* PANDA 3D SOFTWARE
|
||||
* Copyright (c) Carnegie Mellon University. All rights reserved.
|
||||
*
|
||||
* All use of this software is subject to the terms of the revised BSD
|
||||
* license. You should have received a copy of this license along
|
||||
* with this source code in a file named "LICENSE."
|
||||
*
|
||||
* @file colladaPrimitive.cxx
|
||||
* @author rdb
|
||||
* @date 2011-05-23
|
||||
*/
|
||||
|
||||
#include "colladaPrimitive.h"
|
||||
#include "geomLines.h"
|
||||
#include "geomLinestrips.h"
|
||||
#include "geomTriangles.h"
|
||||
#include "geomTrifans.h"
|
||||
#include "geomTristrips.h"
|
||||
|
||||
// Collada DOM includes. No other includes beyond this point.
|
||||
#include "pre_collada_include.h"
|
||||
#include <dom/domLines.h>
|
||||
#include <dom/domLinestrips.h>
|
||||
#include <dom/domPolygons.h>
|
||||
#include <dom/domPolylist.h>
|
||||
#include <dom/domTriangles.h>
|
||||
#include <dom/domTrifans.h>
|
||||
#include <dom/domTristrips.h>
|
||||
|
||||
#if PANDA_COLLADA_VERSION < 15
|
||||
#define domInput_local_offsetRef domInputLocalOffsetRef
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Why do I even bother documenting the simplest of constructors? A private
|
||||
* one at that.
|
||||
*/
|
||||
ColladaPrimitive::
|
||||
ColladaPrimitive(GeomPrimitive *prim, daeTArray<domInput_local_offsetRef> &inputs)
|
||||
: _stride (1), _gprim (prim) {
|
||||
|
||||
PT(GeomVertexArrayFormat) aformat = new GeomVertexArrayFormat;
|
||||
|
||||
// Add the inputs one by one.
|
||||
for (size_t in = 0; in < inputs.getCount(); ++in) {
|
||||
PT(ColladaInput) input = ColladaInput::from_dom(*inputs[in]);
|
||||
add_input(input);
|
||||
|
||||
input->make_vertex_columns(aformat);
|
||||
}
|
||||
|
||||
// Create the vertex data.
|
||||
PT(GeomVertexFormat) format = new GeomVertexFormat();
|
||||
format->add_array(aformat);
|
||||
_vdata = new GeomVertexData("", GeomVertexFormat::register_format(format), GeomEnums::UH_static);
|
||||
_geom = new Geom(_vdata);
|
||||
_geom->add_primitive(_gprim);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ColladaPrimitive object that represents the provided DOM input
|
||||
* element.
|
||||
*/
|
||||
ColladaPrimitive *ColladaPrimitive::
|
||||
from_dom(domLines &prim) {
|
||||
// If we already loaded it before, use that.
|
||||
if (prim.getUserData() != nullptr) {
|
||||
return (ColladaPrimitive *) prim.getUserData();
|
||||
}
|
||||
|
||||
ColladaPrimitive *new_prim =
|
||||
new ColladaPrimitive(new GeomLines(GeomEnums::UH_static),
|
||||
prim.getInput_array());
|
||||
new_prim->_material = prim.getMaterial();
|
||||
|
||||
prim.setUserData(new_prim);
|
||||
|
||||
domPRef p = prim.getP();
|
||||
if (p != nullptr) {
|
||||
new_prim->load_primitive(*p);
|
||||
}
|
||||
|
||||
return new_prim;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ColladaPrimitive object that represents the provided DOM input
|
||||
* element.
|
||||
*/
|
||||
ColladaPrimitive *ColladaPrimitive::
|
||||
from_dom(domLinestrips &prim) {
|
||||
// If we already loaded it before, use that.
|
||||
if (prim.getUserData() != nullptr) {
|
||||
return (ColladaPrimitive *) prim.getUserData();
|
||||
}
|
||||
|
||||
ColladaPrimitive *new_prim =
|
||||
new ColladaPrimitive(new GeomLinestrips(GeomEnums::UH_static),
|
||||
prim.getInput_array());
|
||||
new_prim->_material = prim.getMaterial();
|
||||
|
||||
prim.setUserData(new_prim);
|
||||
|
||||
new_prim->load_primitives(prim.getP_array());
|
||||
|
||||
return new_prim;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ColladaPrimitive object that represents the provided DOM input
|
||||
* element.
|
||||
*/
|
||||
ColladaPrimitive *ColladaPrimitive::
|
||||
from_dom(domPolygons &prim) {
|
||||
// If we already loaded it before, use that.
|
||||
if (prim.getUserData() != nullptr) {
|
||||
return (ColladaPrimitive *) prim.getUserData();
|
||||
}
|
||||
|
||||
// We use trifans to represent polygons, seems to be easiest. I tried using
|
||||
// tristrips instead, but for some reason, this resulted in a few flipped
|
||||
// polygons. Weird.
|
||||
ColladaPrimitive *new_prim =
|
||||
new ColladaPrimitive(new GeomTrifans(GeomEnums::UH_static),
|
||||
prim.getInput_array());
|
||||
new_prim->_material = prim.getMaterial();
|
||||
|
||||
prim.setUserData(new_prim);
|
||||
|
||||
new_prim->load_primitives(prim.getP_array());
|
||||
|
||||
if (prim.getPh_array().getCount() > 0) {
|
||||
collada_cat.error()
|
||||
<< "Polygons with holes are not supported!\n";
|
||||
}
|
||||
|
||||
return new_prim;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ColladaPrimitive object that represents the provided DOM input
|
||||
* element.
|
||||
*/
|
||||
ColladaPrimitive *ColladaPrimitive::
|
||||
from_dom(domPolylist &prim) {
|
||||
// If we already loaded it before, use that.
|
||||
if (prim.getUserData() != nullptr) {
|
||||
return (ColladaPrimitive *) prim.getUserData();
|
||||
}
|
||||
|
||||
// We use trifans to represent polygons, seems to be easiest. I tried using
|
||||
// tristrips instead, but for some reason, this resulted in a few flipped
|
||||
// polygons. Weird.
|
||||
PT(GeomPrimitive) gprim = new GeomTrifans(GeomEnums::UH_static);
|
||||
|
||||
ColladaPrimitive *new_prim =
|
||||
new ColladaPrimitive(gprim, prim.getInput_array());
|
||||
new_prim->_material = prim.getMaterial();
|
||||
|
||||
prim.setUserData(new_prim);
|
||||
|
||||
domPRef p = prim.getP();
|
||||
domPolylist::domVcountRef vcounts = prim.getVcount();
|
||||
if (p == nullptr || vcounts == nullptr) {
|
||||
return new_prim;
|
||||
}
|
||||
|
||||
new_prim->write_data(new_prim->_vdata, 0, *p);
|
||||
|
||||
daeTArray<domUint> &values = vcounts->getValue();
|
||||
for (size_t i = 0; i < values.getCount(); ++i) {
|
||||
unsigned int vcount = values[i];
|
||||
gprim->add_next_vertices(vcount);
|
||||
gprim->close_primitive();
|
||||
}
|
||||
|
||||
return new_prim;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ColladaPrimitive object that represents the provided DOM input
|
||||
* element.
|
||||
*/
|
||||
ColladaPrimitive *ColladaPrimitive::
|
||||
from_dom(domTriangles &prim) {
|
||||
// If we already loaded it before, use that.
|
||||
if (prim.getUserData() != nullptr) {
|
||||
return (ColladaPrimitive *) prim.getUserData();
|
||||
}
|
||||
|
||||
ColladaPrimitive *new_prim =
|
||||
new ColladaPrimitive(new GeomTriangles(GeomEnums::UH_static),
|
||||
prim.getInput_array());
|
||||
new_prim->_material = prim.getMaterial();
|
||||
|
||||
prim.setUserData(new_prim);
|
||||
|
||||
domPRef p = prim.getP();
|
||||
if (p != nullptr) {
|
||||
new_prim->load_primitive(*p);
|
||||
}
|
||||
|
||||
return new_prim;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ColladaPrimitive object that represents the provided DOM input
|
||||
* element.
|
||||
*/
|
||||
ColladaPrimitive *ColladaPrimitive::
|
||||
from_dom(domTrifans &prim) {
|
||||
// If we already loaded it before, use that.
|
||||
if (prim.getUserData() != nullptr) {
|
||||
return (ColladaPrimitive *) prim.getUserData();
|
||||
}
|
||||
|
||||
ColladaPrimitive *new_prim =
|
||||
new ColladaPrimitive(new GeomTrifans(GeomEnums::UH_static),
|
||||
prim.getInput_array());
|
||||
new_prim->_material = prim.getMaterial();
|
||||
|
||||
prim.setUserData(new_prim);
|
||||
|
||||
new_prim->load_primitives(prim.getP_array());
|
||||
|
||||
return new_prim;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ColladaPrimitive object that represents the provided DOM input
|
||||
* element.
|
||||
*/
|
||||
ColladaPrimitive *ColladaPrimitive::
|
||||
from_dom(domTristrips &prim) {
|
||||
// If we already loaded it before, use that.
|
||||
if (prim.getUserData() != nullptr) {
|
||||
return (ColladaPrimitive *) prim.getUserData();
|
||||
}
|
||||
|
||||
ColladaPrimitive *new_prim =
|
||||
new ColladaPrimitive(new GeomTristrips(GeomEnums::UH_static),
|
||||
prim.getInput_array());
|
||||
new_prim->_material = prim.getMaterial();
|
||||
|
||||
prim.setUserData(new_prim);
|
||||
|
||||
new_prim->load_primitives(prim.getP_array());
|
||||
|
||||
return new_prim;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the vertex data to the GeomVertexData. Returns the number of rows
|
||||
* written.
|
||||
*/
|
||||
unsigned int ColladaPrimitive::
|
||||
write_data(GeomVertexData *vdata, int start_row, domP &p) {
|
||||
unsigned int num_vertices = p.getValue().getCount() / _stride;
|
||||
|
||||
Inputs::iterator it;
|
||||
for (it = _inputs.begin(); it != _inputs.end(); ++it) {
|
||||
(*it)->write_data(vdata, start_row, p, _stride);
|
||||
}
|
||||
|
||||
return num_vertices;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the given indices to the primitive, and writes the relevant data to
|
||||
* the geom.
|
||||
*/
|
||||
void ColladaPrimitive::
|
||||
load_primitive(domP &p) {
|
||||
_gprim->add_next_vertices(write_data(_vdata, 0, p));
|
||||
_gprim->close_primitive();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the given indices to the primitive, and writes the relevant data to
|
||||
* the geom.
|
||||
*/
|
||||
void ColladaPrimitive::
|
||||
load_primitives(domP_Array &p_array) {
|
||||
int start_row = 0;
|
||||
|
||||
for (size_t i = 0; i < p_array.getCount(); ++i) {
|
||||
unsigned int num_vertices = write_data(_vdata, start_row, *p_array[i]);
|
||||
_gprim->add_next_vertices(num_vertices);
|
||||
_gprim->close_primitive();
|
||||
start_row += num_vertices;
|
||||
}
|
||||
}
|
@ -1,71 +0,0 @@
|
||||
/**
|
||||
* PANDA 3D SOFTWARE
|
||||
* Copyright (c) Carnegie Mellon University. All rights reserved.
|
||||
*
|
||||
* All use of this software is subject to the terms of the revised BSD
|
||||
* license. You should have received a copy of this license along
|
||||
* with this source code in a file named "LICENSE."
|
||||
*
|
||||
* @file colladaPrimitive.h
|
||||
* @author rdb
|
||||
* @date 2011-05-23
|
||||
*/
|
||||
|
||||
#ifndef COLLADAPRIMITIVE_H
|
||||
#define COLLADAPRIMITIVE_H
|
||||
|
||||
#include "config_collada.h"
|
||||
#include "referenceCount.h"
|
||||
#include "geomVertexData.h"
|
||||
#include "geom.h"
|
||||
#include "geomPrimitive.h"
|
||||
|
||||
#include "colladaInput.h"
|
||||
|
||||
class domP;
|
||||
class domLines;
|
||||
class domLinestrips;
|
||||
class domPolygons;
|
||||
class domPolylist;
|
||||
class domTriangles;
|
||||
class domTrifans;
|
||||
class domTristrips;
|
||||
|
||||
/**
|
||||
* Class that deals with COLLADA primitive structures, such as <triangles> and
|
||||
* <polylist>.
|
||||
*/
|
||||
class ColladaPrimitive : public ReferenceCount {
|
||||
public:
|
||||
static ColladaPrimitive *from_dom(domLines &lines);
|
||||
static ColladaPrimitive *from_dom(domLinestrips &linestrips);
|
||||
static ColladaPrimitive *from_dom(domPolygons &polygons);
|
||||
static ColladaPrimitive *from_dom(domPolylist &polylist);
|
||||
static ColladaPrimitive *from_dom(domTriangles &triangles);
|
||||
static ColladaPrimitive *from_dom(domTrifans &trifans);
|
||||
static ColladaPrimitive *from_dom(domTristrips &tristrips);
|
||||
|
||||
unsigned int write_data(GeomVertexData *vdata, int start_row, domP &p);
|
||||
|
||||
INLINE PT(Geom) get_geom() const;
|
||||
INLINE const std::string &get_material() const;
|
||||
|
||||
private:
|
||||
ColladaPrimitive(GeomPrimitive *prim, daeTArray<daeSmartRef<domInput_local_offset> > &inputs);
|
||||
void load_primitive(domP &p);
|
||||
void load_primitives(daeTArray<daeSmartRef<domP> > &p_array);
|
||||
INLINE void add_input(ColladaInput *input);
|
||||
|
||||
typedef pvector<PT(ColladaInput)> Inputs;
|
||||
Inputs _inputs;
|
||||
|
||||
unsigned int _stride;
|
||||
PT(Geom) _geom;
|
||||
PT(GeomVertexData) _vdata;
|
||||
PT(GeomPrimitive) _gprim;
|
||||
std::string _material;
|
||||
};
|
||||
|
||||
#include "colladaPrimitive.I"
|
||||
|
||||
#endif
|
@ -1,87 +0,0 @@
|
||||
/**
|
||||
* PANDA 3D SOFTWARE
|
||||
* Copyright (c) Carnegie Mellon University. All rights reserved.
|
||||
*
|
||||
* All use of this software is subject to the terms of the revised BSD
|
||||
* license. You should have received a copy of this license along
|
||||
* with this source code in a file named "LICENSE."
|
||||
*
|
||||
* @file config_collada.cxx
|
||||
* @author Xidram
|
||||
* @date 2010-12-21
|
||||
*/
|
||||
|
||||
#include "config_collada.h"
|
||||
|
||||
#include "dconfig.h"
|
||||
#include "loaderFileTypeDae.h"
|
||||
#include "loaderFileTypeRegistry.h"
|
||||
|
||||
#if !defined(CPPPARSER) && !defined(LINK_ALL_STATIC) && !defined(BUILDING_COLLADA)
|
||||
#error Buildsystem error: BUILDING_COLLADA not defined
|
||||
#endif
|
||||
|
||||
ConfigureDef(config_collada);
|
||||
NotifyCategoryDef(collada, "");
|
||||
|
||||
ConfigVariableBool collada_flatten
|
||||
("collada-flatten", false,
|
||||
PRC_DESC("This is normally true to flatten out useless nodes after loading "
|
||||
"a collada file. Set it false if you want to see the complete "
|
||||
"and true hierarchy as specified in the file (although the "
|
||||
"extra nodes may have a small impact on render performance)."));
|
||||
|
||||
ConfigVariableDouble collada_flatten_radius
|
||||
("collada-flatten-radius", 0.0,
|
||||
PRC_DESC("This specifies the minimum cull radius in the egg file. Nodes "
|
||||
"whose bounding volume is smaller than this radius will be "
|
||||
"flattened tighter than nodes larger than this radius, to "
|
||||
"reduce the node count even further. The idea is that small "
|
||||
"objects will not need to have their individual components "
|
||||
"culled separately, but large environments should. This allows "
|
||||
"the user to specify what should be considered \"small\". Set "
|
||||
"it to 0.0 to disable this feature."));
|
||||
|
||||
ConfigVariableBool collada_unify
|
||||
("collada-unify", true,
|
||||
PRC_DESC("When this is true, then in addition to flattening the scene graph "
|
||||
"nodes, the collada loader will also combine as many Geoms as "
|
||||
"possible within "
|
||||
"a given node into a single Geom. This has theoretical performance "
|
||||
"benefits, especially on higher-end graphics cards, but it also "
|
||||
"slightly slows down collada loading."));
|
||||
|
||||
ConfigVariableBool collada_combine_geoms
|
||||
("collada-combine-geoms", false,
|
||||
PRC_DESC("Set this true to combine sibling GeomNodes into a single GeomNode, "
|
||||
"when possible."));
|
||||
|
||||
ConfigVariableBool collada_accept_errors
|
||||
("collada-accept-errors", true,
|
||||
PRC_DESC("When this is true, certain kinds of recoverable errors (not syntax "
|
||||
"errors) in a collada file will be allowed and ignored when a "
|
||||
"collada file is loaded. When it is false, only perfectly pristine "
|
||||
"collada files may be loaded."));
|
||||
|
||||
ConfigureFn(config_collada) {
|
||||
init_libcollada();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the library. This must be called at least once before any of
|
||||
* the functions or classes in this library can be used. Normally it will be
|
||||
* called by the static initializers and need not be called explicitly, but
|
||||
* special cases exist.
|
||||
*/
|
||||
void
|
||||
init_libcollada() {
|
||||
static bool initialized = false;
|
||||
if (initialized) {
|
||||
return;
|
||||
}
|
||||
initialized = true;
|
||||
|
||||
LoaderFileTypeRegistry *reg = LoaderFileTypeRegistry::get_global_ptr();
|
||||
|
||||
reg->register_type(new LoaderFileTypeDae);
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
/**
|
||||
* PANDA 3D SOFTWARE
|
||||
* Copyright (c) Carnegie Mellon University. All rights reserved.
|
||||
*
|
||||
* All use of this software is subject to the terms of the revised BSD
|
||||
* license. You should have received a copy of this license along
|
||||
* with this source code in a file named "LICENSE."
|
||||
*
|
||||
* @file config_collada.h
|
||||
* @author Xidram
|
||||
* @date 2010-12-21
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_COLLADA_H
|
||||
#define CONFIG_COLLADA_H
|
||||
|
||||
#include "pandabase.h"
|
||||
|
||||
#include "notifyCategoryProxy.h"
|
||||
#include "dconfig.h"
|
||||
|
||||
template<class T> class daeTArray;
|
||||
template<class T> class daeSmartRef;
|
||||
|
||||
ConfigureDecl(config_collada, EXPCL_COLLADA, EXPTP_COLLADA);
|
||||
NotifyCategoryDecl(collada, EXPCL_COLLADA, EXPTP_COLLADA);
|
||||
|
||||
extern EXPCL_COLLADA ConfigVariableBool collada_flatten;
|
||||
extern EXPCL_COLLADA ConfigVariableBool collada_unify;
|
||||
extern EXPCL_COLLADA ConfigVariableDouble collada_flatten_radius;
|
||||
extern EXPCL_COLLADA ConfigVariableBool collada_combine_geoms;
|
||||
extern EXPCL_COLLADA ConfigVariableBool collada_accept_errors;
|
||||
|
||||
extern EXPCL_COLLADA void init_libcollada();
|
||||
|
||||
#endif
|
@ -1,92 +0,0 @@
|
||||
/**
|
||||
* PANDA 3D SOFTWARE
|
||||
* Copyright (c) Carnegie Mellon University. All rights reserved.
|
||||
*
|
||||
* All use of this software is subject to the terms of the revised BSD
|
||||
* license. You should have received a copy of this license along
|
||||
* with this source code in a file named "LICENSE."
|
||||
*
|
||||
* @file load_collada_file.cxx
|
||||
* @author rdb
|
||||
* @date 2011-03-16
|
||||
*/
|
||||
|
||||
#include "load_collada_file.h"
|
||||
#include "colladaLoader.h"
|
||||
#include "config_collada.h"
|
||||
#include "sceneGraphReducer.h"
|
||||
#include "virtualFileSystem.h"
|
||||
#include "config_putil.h"
|
||||
#include "bamCacheRecord.h"
|
||||
|
||||
static PT(PandaNode)
|
||||
load_from_loader(ColladaLoader &loader) {
|
||||
loader.build_graph();
|
||||
|
||||
if (loader._error && !collada_accept_errors) {
|
||||
collada_cat.error()
|
||||
<< "Errors in collada file.\n";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (loader._root != nullptr && collada_flatten) {
|
||||
SceneGraphReducer gr;
|
||||
|
||||
int combine_siblings_bits = 0;
|
||||
if (collada_combine_geoms) {
|
||||
combine_siblings_bits |= SceneGraphReducer::CS_geom_node;
|
||||
}
|
||||
if (collada_flatten_radius > 0.0) {
|
||||
combine_siblings_bits |= SceneGraphReducer::CS_within_radius;
|
||||
gr.set_combine_radius(collada_flatten_radius);
|
||||
}
|
||||
|
||||
int num_reduced = gr.flatten(loader._root, combine_siblings_bits);
|
||||
collada_cat.info() << "Flattened " << num_reduced << " nodes.\n";
|
||||
|
||||
if (collada_unify) {
|
||||
// We want to premunge before unifying, since otherwise we risk
|
||||
// needlessly duplicating vertices.
|
||||
if (premunge_data) {
|
||||
gr.premunge(loader._root, RenderState::make_empty());
|
||||
}
|
||||
gr.collect_vertex_data(loader._root);
|
||||
gr.unify(loader._root, true);
|
||||
if (collada_cat.is_debug()) {
|
||||
collada_cat.debug() << "Unified.\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return DCAST(ModelRoot, loader._root);
|
||||
}
|
||||
|
||||
/**
|
||||
* A convenience function. Loads up the indicated dae file, and returns the
|
||||
* root of a scene graph. Returns NULL if the file cannot be read for some
|
||||
* reason. Does not search along the model path for the filename first.
|
||||
*/
|
||||
PT(PandaNode)
|
||||
load_collada_file(const Filename &filename, CoordinateSystem cs,
|
||||
BamCacheRecord *record) {
|
||||
|
||||
VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr();
|
||||
|
||||
if (record != nullptr) {
|
||||
record->add_dependent_file(filename);
|
||||
}
|
||||
|
||||
ColladaLoader loader;
|
||||
loader._filename = filename;
|
||||
loader._cs = cs;
|
||||
loader._record = record;
|
||||
|
||||
collada_cat.info()
|
||||
<< "Reading " << filename << "\n";
|
||||
|
||||
if (!loader.read(filename)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return load_from_loader(loader);
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
/**
|
||||
* PANDA 3D SOFTWARE
|
||||
* Copyright (c) Carnegie Mellon University. All rights reserved.
|
||||
*
|
||||
* All use of this software is subject to the terms of the revised BSD
|
||||
* license. You should have received a copy of this license along
|
||||
* with this source code in a file named "LICENSE."
|
||||
*
|
||||
* @file load_collada_file.h
|
||||
* @author rdb
|
||||
* @date 2011-03-16
|
||||
*/
|
||||
|
||||
#ifndef LOAD_COLLADA_FILE_H
|
||||
#define LOAD_COLLADA_FILE_H
|
||||
|
||||
#include "pandabase.h"
|
||||
|
||||
#include "pandaNode.h"
|
||||
#include "filename.h"
|
||||
#include "coordinateSystem.h"
|
||||
|
||||
class BamCacheRecord;
|
||||
|
||||
BEGIN_PUBLISH
|
||||
/**
|
||||
* A convenience function; the primary interface to this package. Loads up
|
||||
* the indicated DAE file, and returns the root of a scene graph. Returns
|
||||
* NULL if the file cannot be read for some reason.
|
||||
*/
|
||||
EXPCL_COLLADA PT(PandaNode)
|
||||
load_collada_file(const Filename &filename, CoordinateSystem cs = CS_default,
|
||||
BamCacheRecord *record = nullptr);
|
||||
END_PUBLISH
|
||||
|
||||
#endif
|
@ -1,74 +0,0 @@
|
||||
/**
|
||||
* PANDA 3D SOFTWARE
|
||||
* Copyright (c) Carnegie Mellon University. All rights reserved.
|
||||
*
|
||||
* All use of this software is subject to the terms of the revised BSD
|
||||
* license. You should have received a copy of this license along
|
||||
* with this source code in a file named "LICENSE."
|
||||
*
|
||||
* @file loaderFileTypeDae.cxx
|
||||
* @author rdb
|
||||
* @date 2009-08-23
|
||||
*/
|
||||
|
||||
#include "loaderFileTypeDae.h"
|
||||
#include "load_collada_file.h"
|
||||
|
||||
TypeHandle LoaderFileTypeDae::_type_handle;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
LoaderFileTypeDae::
|
||||
LoaderFileTypeDae() {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
std::string LoaderFileTypeDae::
|
||||
get_name() const {
|
||||
#if PANDA_COLLADA_VERSION == 14
|
||||
return "COLLADA 1.4";
|
||||
#elif PANDA_COLLADA_VERSION == 15
|
||||
return "COLLADA 1.5";
|
||||
#else
|
||||
return "COLLADA";
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
std::string LoaderFileTypeDae::
|
||||
get_extension() const {
|
||||
return "dae";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a space-separated list of extension, in addition to the one
|
||||
* returned by get_extension(), that are recognized by this loader.
|
||||
*/
|
||||
std::string LoaderFileTypeDae::
|
||||
get_additional_extensions() const {
|
||||
return "zae";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this file type can transparently load compressed files
|
||||
* (with a .pz or .gz extension), false otherwise.
|
||||
*/
|
||||
bool LoaderFileTypeDae::
|
||||
supports_compressed() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
PT(PandaNode) LoaderFileTypeDae::
|
||||
load_file(const Filename &path, const LoaderOptions &,
|
||||
BamCacheRecord *record) const {
|
||||
PT(PandaNode) result = load_collada_file(path, CS_default, record);
|
||||
return result;
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
/**
|
||||
* PANDA 3D SOFTWARE
|
||||
* Copyright (c) Carnegie Mellon University. All rights reserved.
|
||||
*
|
||||
* All use of this software is subject to the terms of the revised BSD
|
||||
* license. You should have received a copy of this license along
|
||||
* with this source code in a file named "LICENSE."
|
||||
*
|
||||
* @file loaderFileTypeDae.h
|
||||
* @author rdb
|
||||
* @date 2009-08-23
|
||||
*/
|
||||
|
||||
#ifndef LOADERFILETYPEDAE_H
|
||||
#define LOADERFILETYPEDAE_H
|
||||
|
||||
#include "pandabase.h"
|
||||
|
||||
#include "loaderFileType.h"
|
||||
|
||||
/**
|
||||
* This defines the Loader interface to read Dae files.
|
||||
*/
|
||||
class EXPCL_COLLADA LoaderFileTypeDae : public LoaderFileType {
|
||||
public:
|
||||
LoaderFileTypeDae();
|
||||
|
||||
virtual std::string get_name() const;
|
||||
virtual std::string get_extension() const;
|
||||
virtual std::string get_additional_extensions() const;
|
||||
virtual bool supports_compressed() const;
|
||||
|
||||
virtual PT(PandaNode) load_file(const Filename &path, const LoaderOptions &options,
|
||||
BamCacheRecord *record) const;
|
||||
|
||||
public:
|
||||
static TypeHandle get_class_type() {
|
||||
return _type_handle;
|
||||
}
|
||||
static void init_type() {
|
||||
LoaderFileType::init_type();
|
||||
register_type(_type_handle, "LoaderFileTypeDae",
|
||||
LoaderFileType::get_class_type());
|
||||
}
|
||||
virtual TypeHandle get_type() const {
|
||||
return get_class_type();
|
||||
}
|
||||
virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
|
||||
|
||||
private:
|
||||
static TypeHandle _type_handle;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,3 +0,0 @@
|
||||
#include "config_collada.cxx"
|
||||
#include "load_collada_file.cxx"
|
||||
#include "loaderFileTypeDae.cxx"
|
@ -1,28 +0,0 @@
|
||||
/**
|
||||
* PANDA 3D SOFTWARE
|
||||
* Copyright (c) Carnegie Mellon University. All rights reserved.
|
||||
*
|
||||
* All use of this software is subject to the terms of the revised BSD
|
||||
* license. You should have received a copy of this license along
|
||||
* with this source code in a file named "LICENSE."
|
||||
*
|
||||
* @file pre_collada_include.h
|
||||
* @author rdb
|
||||
* @date 2011-05-23
|
||||
*/
|
||||
|
||||
// This header file should be included before including any of the COLLADA DOM
|
||||
// headers. It should only be included in a .cxx file (not in a header file)
|
||||
// and no Panda3D headers should be included after the pre_collada_include.h
|
||||
// include.
|
||||
|
||||
#ifdef PRE_COLLADA_INCLUDE_H
|
||||
#error Don't include any Panda headers after including pre_collada_include.h!
|
||||
#endif
|
||||
#define PRE_COLLADA_INCLUDE_H
|
||||
|
||||
// Undef some macros that conflict with COLLADA.
|
||||
#undef INLINE
|
||||
#undef tolower
|
||||
|
||||
#include <dae.h>
|
Loading…
x
Reference in New Issue
Block a user