15 #include "colladaInput.h" 16 #include "string_utils.h" 17 #include "geomVertexArrayFormat.h" 18 #include "geomVertexWriter.h" 21 #include "pre_collada_include.h" 22 #include <dom/domAccessor.h> 24 #include <dom/domSource.h> 25 #include <dom/domVertices.h> 27 #if PANDA_COLLADA_VERSION >= 15 28 #include <dom/domInput_local_offset.h> 29 #include <dom/domInput_local.h> 31 #include <dom/domInputLocalOffset.h> 32 #include <dom/domInputLocal.h> 33 #define domList_of_floats domListOfFloats 34 #define domList_of_uints domListOfUInts 42 ColladaInput(
const string &semantic) :
49 if (semantic ==
"POSITION") {
50 _column_name = InternalName::get_vertex();
51 _column_contents = GeomEnums::C_point;
52 }
else if (semantic ==
"COLOR") {
53 _column_name = InternalName::get_color();
54 _column_contents = GeomEnums::C_color;
55 }
else if (semantic ==
"NORMAL") {
56 _column_name = InternalName::get_normal();
57 _column_contents = GeomEnums::C_vector;
58 }
else if (semantic ==
"TEXCOORD") {
59 _column_name = InternalName::get_texcoord();
60 _column_contents = GeomEnums::C_texcoord;
61 }
else if (semantic ==
"TEXBINORMAL") {
62 _column_name = InternalName::get_binormal();
63 _column_contents = GeomEnums::C_vector;
64 }
else if (semantic ==
"TEXTANGENT") {
65 _column_name = InternalName::get_tangent();
66 _column_contents = GeomEnums::C_vector;
75 ColladaInput(
const string &semantic,
unsigned int set) :
85 if (semantic ==
"POSITION") {
86 _column_name = InternalName::get_vertex();
87 _column_contents = GeomEnums::C_point;
88 }
else if (semantic ==
"COLOR") {
89 _column_name = InternalName::get_color();
90 _column_contents = GeomEnums::C_color;
91 }
else if (semantic ==
"NORMAL") {
92 _column_name = InternalName::get_normal();
93 _column_contents = GeomEnums::C_vector;
94 }
else if (semantic ==
"TEXCOORD") {
95 _column_name = InternalName::get_texcoord_name(setstr.str());
96 _column_contents = GeomEnums::C_texcoord;
97 }
else if (semantic ==
"TEXBINORMAL") {
98 _column_name = InternalName::get_binormal_name(setstr.str());
99 _column_contents = GeomEnums::C_vector;
100 }
else if (semantic ==
"TEXTANGENT") {
101 _column_name = InternalName::get_tangent_name(setstr.str());
102 _column_contents = GeomEnums::C_vector;
114 if (input.getUserData() != NULL) {
119 new_input->_offset = input.getOffset();
123 domVertices *verts = daeSafeCast<domVertices> (input.getSource().getElement());
124 nassertr(verts != NULL, NULL);
128 for (
size_t i = 0; i < inputs.getCount(); ++i) {
130 new_input->_vertex_inputs.push_back(vtx_input);
133 domSource *source = daeSafeCast<domSource> (input.getSource().getElement());
134 nassertr(source != NULL, NULL);
135 new_input->read_data(*source);
149 if (input.getUserData() != NULL) {
154 new_input->_offset = 0;
158 domSource *source = daeSafeCast<domSource> (input.getSource().getElement());
159 nassertr(source != NULL, NULL);
160 new_input->read_data(*source);
178 Inputs::const_iterator it;
179 for (it = _vertex_inputs.begin(); it != _vertex_inputs.end(); ++it) {
180 counter += (*it)->make_vertex_columns(format);
185 nassertr(_column_name != NULL, 0);
187 format->add_column(_column_name, _num_bound_params, GeomEnums::NT_stdfloat, _column_contents);
196 read_data(domSource &source) {
200 domFloat_array* float_array = source.getFloat_array();
201 if (float_array == NULL) {
205 domList_of_floats &floats = float_array->getValue();
206 domAccessor &accessor = *source.getTechnique_common()->getAccessor();
207 domParam_Array ¶ms = accessor.getParam_array();
210 _num_bound_params = 0;
211 for (
size_t p = 0; p < params.getCount(); ++p) {
212 if (params[p]->getName()) {
217 _data.reserve(accessor.getCount());
219 domUint pos = accessor.getOffset();
220 for (domUint a = 0; a < accessor.getCount(); ++a) {
225 for (domUint p = 0; p < params.getCount(); ++p) {
226 if (params[c]->getName()) {
227 v[c++] = floats[pos + p];
231 pos += accessor.getStride();
245 Inputs::const_iterator it;
246 for (it = _vertex_inputs.begin(); it != _vertex_inputs.end(); ++it) {
247 (*it)->write_data(vdata, start_row, p, stride, _offset);
251 write_data(vdata, start_row, p, stride, _offset);
261 nassertv(_column_name != NULL);
265 domList_of_uints &indices = p.getValue();
268 int min_length = start_row + indices.getCount() / stride;
273 for (
size_t i = 0; i < indices.getCount(); i += stride) {
274 size_t index = indices[i + offset];
void add_data4f(float x, float y, float z, float w)
Sets the write row to a particular 4-component value, and advances the write row. ...
This object provides a high-level interface for quickly writing a sequence of numeric values from a v...
bool unclean_set_num_rows(int n)
This method behaves like set_num_rows(), except the new data is not initialized.
This defines the actual numeric vertex data stored in a Geom, in the structure defined by a particula...
int get_num_rows() const
Returns the number of rows stored within all the arrays.
This is the base class for all three-component vectors and points.
void set_row_unsafe(int row)
Sets the start row to the indicated value, without internal checks.