23 #include "COLLADABUUtils.h"
24 #include "COLLADASWPrimitves.h"
25 #include "COLLADASWSource.h"
26 #include "COLLADASWVertices.h"
45 Scene *sce = blender_context.get_scene();
50 sce, *
this, this->export_settings.get_export_set());
57 bool use_instantiation = this->export_settings.get_use_object_instantiation();
60 this->export_settings.get_export_mesh_type(),
61 this->export_settings.get_apply_modifiers(),
62 this->export_settings.get_triangulate());
65 std::vector<Normal>
nor;
66 std::vector<BCPolygonNormalsIndices> norind;
69 if (use_instantiation && exportedGeometry.find(geom_id) != exportedGeometry.end()) {
76 exportedGeometry.insert(geom_id);
83 openMesh(geom_id, geom_name);
103 COLLADASW::Vertices
verts(mSW);
105 COLLADASW::InputList &input_list =
verts.getInputList();
106 COLLADASW::Input input(COLLADASW::InputSemantic::POSITION,
108 input_list.push_back(input);
130 if (this->export_settings.get_include_shapekeys()) {
136 for (; kb; kb = kb->
next) {
149 std::vector<Normal>
nor;
150 std::vector<BCPolygonNormalsIndices> norind;
152 if (exportedGeometry.find(geom_id) != exportedGeometry.end()) {
156 std::string geom_name = kb->
name;
158 exportedGeometry.insert(geom_id);
165 openMesh(geom_id, geom_name);
186 COLLADASW::Vertices
verts(mSW);
188 COLLADASW::InputList &input_list =
verts.getInputList();
189 COLLADASW::Input input(COLLADASW::InputSemantic::POSITION,
191 input_list.push_back(input);
216 int edges_in_linelist = 0;
217 std::vector<unsigned int> edge_list;
222 for (index = 0; index < totedges; index++) {
223 MEdge *edge = &medges[index];
226 edges_in_linelist += 1;
227 edge_list.push_back(edge->
v1);
228 edge_list.push_back(edge->
v2);
232 if (edges_in_linelist > 0) {
234 COLLADASW::Lines lines(mSW);
236 lines.setCount(edges_in_linelist);
238 COLLADASW::InputList &til = lines.getInputList();
241 COLLADASW::Input input1(COLLADASW::InputSemantic::VERTEX,
244 til.push_back(input1);
246 lines.prepareToAppendValues();
248 for (index = 0; index < edges_in_linelist; index++) {
249 lines.appendValues(edge_list[2 * index + 1]);
250 lines.appendValues(edge_list[2 * index]);
257 COLLADASW::PrimitivesBase &primitive_list,
258 std::vector<unsigned long> &vcount_list)
261 if (is_triangulated) {
262 ((COLLADASW::Triangles &)primitive_list).prepareToAppendValues();
266 primitive_list.setVCountList(vcount_list);
267 ((COLLADASW::Polylist &)primitive_list).prepareToAppendValues();
272 COLLADASW::PrimitivesBase *primitive_list)
274 if (is_triangulated) {
275 ((COLLADASW::Triangles *)primitive_list)->finish();
278 ((COLLADASW::Polylist *)primitive_list)->finish();
280 delete primitive_list;
284 COLLADASW::StreamWriter *mSW)
286 COLLADASW::PrimitivesBase *primitive_list;
288 if (is_triangulated) {
289 primitive_list =
new COLLADASW::Triangles(mSW);
292 primitive_list =
new COLLADASW::Polylist(mSW);
294 return primitive_list;
299 std::vector<unsigned long> &vcount_list)
303 bool is_triangulated =
true;
307 for (i = 0; i < totpolys; i++) {
308 MPoly *p = &mpolys[i];
309 if (p->
mat_nr == material_index) {
311 vcount_list.push_back(vertex_count);
312 if (vertex_count != 3) {
313 is_triangulated =
false;
317 return is_triangulated;
333 std::string &geom_id,
334 std::vector<BCPolygonNormalsIndices> &norind)
341 std::vector<unsigned long> vcount_list;
344 int polygon_count = vcount_list.size();
347 if (polygon_count == 0) {
349 stderr,
"%s: material with index %d is not used.\n",
id_name(ob).c_str(), material_index);
357 primitive_list->setCount(polygon_count);
362 std::ostringstream ostr;
364 primitive_list->setMaterial(ostr.str());
367 COLLADASW::Input vertex_input(COLLADASW::InputSemantic::VERTEX,
374 COLLADASW::InputList &til = primitive_list->getInputList();
375 til.push_back(vertex_input);
376 til.push_back(normals_input);
381 for (
int i = 0; i < num_layers; i++) {
383 if (!this->export_settings.get_active_uv_only() || layer_index == active_uv_index) {
386 COLLADASW::Input texcoord_input(
387 COLLADASW::InputSemantic::TEXCOORD,
390 (this->export_settings.get_active_uv_only()) ? 0 : layer_index - 1
392 til.push_back(texcoord_input);
397 if (totlayer_mcol > 0) {
400 for (
int a = 0;
a < totlayer_mcol;
a++) {
402 COLLADASW::Input input4(COLLADASW::InputSemantic::COLOR,
407 til.push_back(input4);
417 for (
int i = 0; i < totpolys; i++) {
418 MPoly *p = &mpolys[i];
421 if (p->
mat_nr == material_index) {
425 for (
int j = 0; j < loop_count; j++) {
426 primitive_list->appendValues(
l[j].
v);
427 primitive_list->appendValues(normal_indices[j]);
429 primitive_list->appendValues(texindex + j);
433 primitive_list->appendValues(texindex + j);
438 texindex += loop_count;
448 int totverts = dm->getNumVerts(dm);
454 COLLADASW::FloatSourceF source(mSW);
455 source.setId(
getIdBySemantics(geom_id, COLLADASW::InputSemantic::POSITION));
456 source.setArrayId(
getIdBySemantics(geom_id, COLLADASW::InputSemantic::POSITION) +
458 source.setAccessorCount(totverts);
459 source.setAccessorStride(3);
461 COLLADASW::SourceBase::ParameterNameList ¶m = source.getParameterNameList();
462 param.push_back(
"X");
463 param.push_back(
"Y");
464 param.push_back(
"Z");
467 source.prepareToAppendValues();
470 for (i = 0; i < totverts; i++) {
472 if (export_settings.get_apply_global_orientation()) {
478 source.appendValues(co[0], co[1], co[2]);
488 if (totlayer_mcol == 0) {
493 for (
int a = 0;
a < totlayer_mcol;
a++) {
498 COLLADASW::FloatSourceF source(mSW);
502 source.setId(layer_id);
504 source.setNodeName(layer_name);
506 source.setArrayId(layer_id + ARRAY_ID_SUFFIX);
507 source.setAccessorCount(me->
totloop);
508 source.setAccessorStride(4);
510 COLLADASW::SourceBase::ParameterNameList ¶m = source.getParameterNameList();
511 param.push_back(
"R");
512 param.push_back(
"G");
513 param.push_back(
"B");
514 param.push_back(
"A");
516 source.prepareToAppendValues();
520 for (i = 0, mpoly = me->
mpoly; i < me->totpoly; i++, mpoly++) {
522 for (
int j = 0; j < mpoly->
totloop; j++, mlc++) {
523 source.appendValues(mlc->
r / 255.0f, mlc->
g / 255.0f, mlc->
b / 255.0f, mlc->
a / 255.0f);
533 bool is_single_layer)
536 if (is_single_layer) {
540 sprintf(suffix,
"-%d", layer_index);
542 return getIdBySemantics(geom_id, COLLADASW::InputSemantic::TEXCOORD) + suffix;
558 for (
int a = 0;
a < num_layers;
a++) {
560 if (!this->export_settings.get_active_uv_only() || layer_index == active_uv_index) {
563 COLLADASW::FloatSourceF source(mSW);
565 geom_id,
a, this->export_settings.get_active_uv_only());
566 source.setId(layer_id);
567 source.setArrayId(layer_id + ARRAY_ID_SUFFIX);
569 source.setAccessorCount(totuv);
570 source.setAccessorStride(2);
571 COLLADASW::SourceBase::ParameterNameList ¶m = source.getParameterNameList();
572 param.push_back(
"S");
573 param.push_back(
"T");
575 source.prepareToAppendValues();
577 for (
int index = 0; index < totpoly; index++) {
578 MPoly *mpoly = mpolys + index;
580 for (
int j = 0; j < mpoly->
totloop; j++) {
581 source.appendValues(mloop[j].uv[0], mloop[j].uv[1]);
593 return a.x < b.
x || (
a.x == b.
x && (
a.y < b.
y || (
a.y == b.
y &&
a.z < b.
z)));
600 int totverts = dm->getNumVerts(dm);
604 COLLADASW::FloatSourceF source(mSW);
607 source.setAccessorCount((
unsigned long)
nor.size());
608 source.setAccessorStride(3);
609 COLLADASW::SourceBase::ParameterNameList ¶m = source.getParameterNameList();
610 param.push_back(
"X");
611 param.push_back(
"Y");
612 param.push_back(
"Z");
614 source.prepareToAppendValues();
616 std::vector<Normal>::iterator it;
617 for (it =
nor.begin(); it !=
nor.end(); it++) {
620 Vector no{n.
x, n.
y, n.
z};
621 if (export_settings.get_apply_global_orientation()) {
624 source.appendValues(no[0], no[1], no[2]);
631 std::vector<BCPolygonNormalsIndices> &polygons_normals,
634 std::map<Normal, unsigned int> shared_normal_indices;
635 int last_normal_index = -1;
639 float(*lnors)[3] =
nullptr;
640 bool use_custom_normals =
false;
645 use_custom_normals =
true;
648 for (
int poly_index = 0; poly_index < me->
totpoly; poly_index++) {
650 bool use_vertex_normals = use_custom_normals || mpoly->
flag &
ME_SMOOTH;
652 if (!use_vertex_normals) {
664 for (
int loop_index = 0; loop_index < mpoly->
totloop; loop_index++) {
665 unsigned int loop_idx = mpoly->
loopstart + loop_index;
666 if (use_vertex_normals) {
669 if (use_custom_normals) {
678 if (shared_normal_indices.find(n) != shared_normal_indices.end()) {
679 poly_indices.
add_index(shared_normal_indices[n]);
683 poly_indices.
add_index(last_normal_index);
684 shared_normal_indices[n] = last_normal_index;
689 poly_indices.
add_index(last_normal_index);
693 polygons_normals.push_back(poly_indices);
698 COLLADASW::InputSemantic::Semantics
type,
699 std::string other_suffix)
701 return geom_id + getSuffixBySemantic(
type) + other_suffix;
705 COLLADASW::InputSemantic::Semantics
type,
706 std::string other_suffix)
typedef float(TangentPoint)[2]
CustomData interface, see also DNA_customdata_types.h.
int CustomData_get_active_layer_index(const struct CustomData *data, int type)
int CustomData_number_of_layers(const struct CustomData *data, int type)
bool CustomData_has_layer(const struct CustomData *data, int type)
int CustomData_get_layer_index_n(const struct CustomData *data, int type, int n)
void * CustomData_get_layer_n(const struct CustomData *data, int type, int n)
void * CustomData_get_layer(const struct CustomData *data, int type)
struct Key * BKE_key_from_object(const struct Object *ob)
void BKE_keyblock_convert_to_mesh(struct KeyBlock *kb, struct Mesh *me)
void BKE_id_free(struct Main *bmain, void *idv)
General operations, lookup, etc. for materials.
struct Material * BKE_object_material_get(struct Object *ob, short act)
void BKE_mesh_calc_poly_normal(const struct MPoly *mpoly, const struct MLoop *loopstart, const struct MVert *mvarray, float r_no[3])
void BKE_mesh_calc_normals_split(struct Mesh *mesh)
MINLINE float normalize_v3(float r[3])
MINLINE void normal_short_to_float_v3(float r[3], const short n[3])
MINLINE void copy_v3_v3(float r[3], const float a[3])
MINLINE float normalize_v3_v3(float r[3], const float a[3])
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
static COLLADASW::PrimitivesBase * create_primitive_list(bool is_triangulated, COLLADASW::StreamWriter *mSW)
static void finish_and_delete_primitive_List(bool is_triangulated, COLLADASW::PrimitivesBase *primitive_list)
static bool collect_vertex_counts_per_poly(Mesh *me, int material_index, std::vector< unsigned long > &vcount_list)
bool operator<(const Normal &a, const Normal &b)
static void prepareToAppendValues(bool is_triangulated, COLLADASW::PrimitivesBase &primitive_list, std::vector< unsigned long > &vcount_list)
ATTR_WARN_UNUSED_RESULT const BMLoop * l
ATTR_WARN_UNUSED_RESULT const BMVert * v
SIMD_FORCE_INLINE btVector3 normalized() const
Return a normalized version of this vector.
void add_index(unsigned int index)
void create_normals(std::vector< Normal > &nor, std::vector< BCPolygonNormalsIndices > &polygons_normals, Mesh *me)
COLLADASW::URI getUrlBySemantics(std::string geom_id, COLLADASW::InputSemantic::Semantics type, std::string other_suffix="")
COLLADASW::URI makeUrl(std::string id)
std::string makeTexcoordSourceId(std::string &geom_id, int layer_index, bool is_single_layer)
std::string makeVertexColorSourceId(std::string &geom_id, char *layer_name)
void export_key_mesh(Object *ob, Mesh *me, KeyBlock *kb)
void operator()(Object *ob)
void create_mesh_primitive_list(short material_index, bool has_uvs, bool has_color, Object *ob, Mesh *me, std::string &geom_id, std::vector< BCPolygonNormalsIndices > &norind)
void createVertexColorSource(std::string geom_id, Mesh *me)
std::string getIdBySemantics(std::string geom_id, COLLADASW::InputSemantic::Semantics type, std::string other_suffix="")
void createLooseEdgeList(Object *ob, Mesh *me, std::string &geom_id)
void createTexcoordsSource(std::string geom_id, Mesh *me)
void createVertsSource(std::string geom_id, Mesh *me)
void createNormalsSource(std::string geom_id, Mesh *me, std::vector< Normal > &nor)
std::string translate_id(const char *idString)
std::string get_geometry_id(Object *ob)
std::string get_material_id(Material *mat)
std::string encode_xml(std::string xml)
std::string id_name(void *id)
Mesh * bc_get_mesh_copy(BlenderContext &blender_context, Object *ob, BC_export_mesh_type export_mesh_type, bool apply_modifiers, bool triangulate)
void bc_add_global_transform(Matrix &to_mat, const Matrix &from_mat, const BCMatrix &global_transform, const bool invert)
char * bc_CustomData_get_layer_name(const CustomData *data, int type, int n)
static float normals[][3]
void forEachMeshObjectInExportSet(Scene *sce, Functor &f, LinkNode *export_set)
struct CustomData pdata ldata
struct CustomData vdata edata fdata