9 #include "COLLADABUUtils.h"
10 #include "COLLADASWPrimitves.h"
11 #include "COLLADASWSource.h"
12 #include "COLLADASWVertices.h"
31 Scene *sce = blender_context.get_scene();
36 sce, *
this, this->export_settings.get_export_set());
43 bool use_instantiation = this->export_settings.get_use_object_instantiation();
46 this->export_settings.get_export_mesh_type(),
47 this->export_settings.get_apply_modifiers(),
48 this->export_settings.get_triangulate());
51 std::vector<Normal>
nor;
52 std::vector<BCPolygonNormalsIndices> norind;
55 if (use_instantiation && exportedGeometry.find(geom_id) != exportedGeometry.end()) {
62 exportedGeometry.insert(geom_id);
69 openMesh(geom_id, geom_name);
89 COLLADASW::Vertices
verts(mSW);
91 COLLADASW::InputList &input_list =
verts.getInputList();
92 COLLADASW::Input
input(COLLADASW::InputSemantic::POSITION,
94 input_list.push_back(
input);
116 if (this->export_settings.get_include_shapekeys()) {
122 for (; kb; kb = kb->
next) {
135 std::vector<Normal>
nor;
136 std::vector<BCPolygonNormalsIndices> norind;
138 if (exportedGeometry.find(geom_id) != exportedGeometry.end()) {
142 std::string geom_name = kb->
name;
144 exportedGeometry.insert(geom_id);
151 openMesh(geom_id, geom_name);
172 COLLADASW::Vertices
verts(mSW);
174 COLLADASW::InputList &input_list =
verts.getInputList();
175 COLLADASW::Input
input(COLLADASW::InputSemantic::POSITION,
177 input_list.push_back(
input);
202 int edges_in_linelist = 0;
203 std::vector<unsigned int> edge_list;
208 for (index = 0; index < totedges; index++) {
209 MEdge *edge = &medges[index];
212 edges_in_linelist += 1;
213 edge_list.push_back(edge->v1);
214 edge_list.push_back(edge->v2);
218 if (edges_in_linelist > 0) {
220 COLLADASW::Lines lines(mSW);
222 lines.setCount(edges_in_linelist);
224 COLLADASW::InputList &til = lines.getInputList();
227 COLLADASW::Input input1(COLLADASW::InputSemantic::VERTEX,
230 til.push_back(input1);
232 lines.prepareToAppendValues();
234 for (index = 0; index < edges_in_linelist; index++) {
235 lines.appendValues(edge_list[2 * index + 1]);
236 lines.appendValues(edge_list[2 * index]);
243 COLLADASW::PrimitivesBase &primitive_list,
244 std::vector<unsigned long> &vcount_list)
247 if (is_triangulated) {
248 ((COLLADASW::Triangles &)primitive_list).prepareToAppendValues();
252 primitive_list.setVCountList(vcount_list);
253 ((COLLADASW::Polylist &)primitive_list).prepareToAppendValues();
258 COLLADASW::PrimitivesBase *primitive_list)
260 if (is_triangulated) {
261 ((COLLADASW::Triangles *)primitive_list)->finish();
264 ((COLLADASW::Polylist *)primitive_list)->finish();
266 delete primitive_list;
270 COLLADASW::StreamWriter *mSW)
272 COLLADASW::PrimitivesBase *primitive_list;
274 if (is_triangulated) {
275 primitive_list =
new COLLADASW::Triangles(mSW);
278 primitive_list =
new COLLADASW::Polylist(mSW);
280 return primitive_list;
285 std::vector<unsigned long> &vcount_list)
289 bool is_triangulated =
true;
293 for (i = 0; i < totpolys; i++) {
294 MPoly *p = &mpolys[i];
295 if (p->
mat_nr == material_index) {
297 vcount_list.push_back(vertex_count);
298 if (vertex_count != 3) {
299 is_triangulated =
false;
303 return is_triangulated;
318 std::string &geom_id,
319 std::vector<BCPolygonNormalsIndices> &norind)
326 std::vector<unsigned long> vcount_list;
329 int polygon_count = vcount_list.size();
332 if (polygon_count == 0) {
334 stderr,
"%s: material with index %d is not used.\n",
id_name(ob).c_str(), material_index);
342 primitive_list->setCount(polygon_count);
347 std::ostringstream ostr;
349 primitive_list->setMaterial(ostr.str());
352 COLLADASW::Input vertex_input(COLLADASW::InputSemantic::VERTEX,
359 COLLADASW::InputList &til = primitive_list->getInputList();
360 til.push_back(vertex_input);
361 til.push_back(normals_input);
366 for (
int i = 0; i < num_layers; i++) {
368 if (!this->export_settings.get_active_uv_only() || layer_index == active_uv_index) {
371 COLLADASW::Input texcoord_input(
372 COLLADASW::InputSemantic::TEXCOORD,
375 (this->export_settings.get_active_uv_only()) ? 0 : layer_index - 1
377 til.push_back(texcoord_input);
382 if (totlayer_mcol > 0) {
385 for (
int a = 0;
a < totlayer_mcol;
a++) {
387 COLLADASW::Input input4(COLLADASW::InputSemantic::COLOR,
392 til.push_back(input4);
402 for (
int i = 0; i < totpolys; i++) {
403 MPoly *p = &mpolys[i];
406 if (p->
mat_nr == material_index) {
410 for (
int j = 0; j < loop_count; j++) {
411 primitive_list->appendValues(
l[j].
v);
412 primitive_list->appendValues(normal_indices[j]);
414 primitive_list->appendValues(texindex + j);
418 primitive_list->appendValues(texindex + j);
423 texindex += loop_count;
432 int totverts = dm->getNumVerts(dm);
438 COLLADASW::FloatSourceF source(mSW);
439 source.setId(
getIdBySemantics(geom_id, COLLADASW::InputSemantic::POSITION));
440 source.setArrayId(
getIdBySemantics(geom_id, COLLADASW::InputSemantic::POSITION) +
442 source.setAccessorCount(totverts);
443 source.setAccessorStride(3);
445 COLLADASW::SourceBase::ParameterNameList ¶m = source.getParameterNameList();
446 param.push_back(
"X");
447 param.push_back(
"Y");
448 param.push_back(
"Z");
451 source.prepareToAppendValues();
454 for (i = 0; i < totverts; i++) {
456 if (export_settings.get_apply_global_orientation()) {
462 source.appendValues(co[0], co[1], co[2]);
472 if (totlayer_mcol == 0) {
477 for (
int a = 0;
a < totlayer_mcol;
a++) {
483 COLLADASW::FloatSourceF source(mSW);
487 source.setId(layer_id);
489 source.setNodeName(layer_name);
491 source.setArrayId(layer_id + ARRAY_ID_SUFFIX);
492 source.setAccessorCount(me->
totloop);
493 source.setAccessorStride(4);
495 COLLADASW::SourceBase::ParameterNameList ¶m = source.getParameterNameList();
496 param.push_back(
"R");
497 param.push_back(
"G");
498 param.push_back(
"B");
499 param.push_back(
"A");
501 source.prepareToAppendValues();
505 for (i = 0, mpoly = me->
mpoly; i < me->totpoly; i++, mpoly++) {
507 for (
int j = 0; j < mpoly->
totloop; j++, mlc++) {
508 source.appendValues(mlc->
r / 255.0f, mlc->
g / 255.0f, mlc->
b / 255.0f, mlc->
a / 255.0f);
518 bool is_single_layer)
521 if (is_single_layer) {
525 sprintf(suffix,
"-%d", layer_index);
527 return getIdBySemantics(geom_id, COLLADASW::InputSemantic::TEXCOORD) + suffix;
542 for (
int a = 0;
a < num_layers;
a++) {
544 if (!this->export_settings.get_active_uv_only() || layer_index == active_uv_index) {
547 COLLADASW::FloatSourceF source(mSW);
549 geom_id,
a, this->export_settings.get_active_uv_only());
550 source.setId(layer_id);
551 source.setArrayId(layer_id + ARRAY_ID_SUFFIX);
553 source.setAccessorCount(totuv);
554 source.setAccessorStride(2);
555 COLLADASW::SourceBase::ParameterNameList ¶m = source.getParameterNameList();
556 param.push_back(
"S");
557 param.push_back(
"T");
559 source.prepareToAppendValues();
561 for (
int index = 0; index < totpoly; index++) {
562 MPoly *mpoly = mpolys + index;
564 for (
int j = 0; j < mpoly->
totloop; j++) {
565 source.appendValues(mloop[j].uv[0], mloop[j].uv[1]);
577 return a.x <
b.x || (
a.x ==
b.x && (
a.y <
b.y || (
a.y ==
b.y &&
a.z <
b.z)));
583 int totverts = dm->getNumVerts(dm);
587 COLLADASW::FloatSourceF source(mSW);
590 source.setAccessorCount((
unsigned long)
nor.size());
591 source.setAccessorStride(3);
592 COLLADASW::SourceBase::ParameterNameList ¶m = source.getParameterNameList();
593 param.push_back(
"X");
594 param.push_back(
"Y");
595 param.push_back(
"Z");
597 source.prepareToAppendValues();
599 std::vector<Normal>::iterator it;
600 for (it =
nor.begin(); it !=
nor.end(); it++) {
603 Vector no{n.
x, n.
y, n.
z};
604 if (export_settings.get_apply_global_orientation()) {
607 source.appendValues(no[0], no[1], no[2]);
614 std::vector<BCPolygonNormalsIndices> &polygons_normals,
617 std::map<Normal, unsigned int> shared_normal_indices;
618 int last_normal_index = -1;
623 const float(*lnors)[3] =
nullptr;
624 bool use_custom_normals =
false;
629 use_custom_normals =
true;
632 for (
int poly_index = 0; poly_index < me->
totpoly; poly_index++) {
634 bool use_vertex_normals = use_custom_normals || mpoly->
flag &
ME_SMOOTH;
636 if (!use_vertex_normals) {
648 for (
int loop_index = 0; loop_index < mpoly->
totloop; loop_index++) {
649 unsigned int loop_idx = mpoly->
loopstart + loop_index;
650 if (use_vertex_normals) {
653 if (use_custom_normals) {
662 if (shared_normal_indices.find(n) != shared_normal_indices.end()) {
663 poly_indices.
add_index(shared_normal_indices[n]);
667 poly_indices.
add_index(last_normal_index);
668 shared_normal_indices[n] = last_normal_index;
673 poly_indices.
add_index(last_normal_index);
677 polygons_normals.push_back(poly_indices);
682 COLLADASW::InputSemantic::Semantics
type,
683 std::string other_suffix)
685 return geom_id + getSuffixBySemantic(
type) + other_suffix;
689 COLLADASW::InputSemantic::Semantics
type,
690 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)
void BKE_keyblock_convert_to_mesh(const struct KeyBlock *kb, struct MVert *mvert, int totvert)
struct Key * BKE_key_from_object(struct Object *ob)
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)
const float(* BKE_mesh_vertex_normals_ensure(const struct Mesh *mesh))[3]
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 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)
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value NORMAL
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)
ccl_global KernelShaderEvalInput * input
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
MutableSpan< float3 > normals
void forEachMeshObjectInExportSet(Scene *sce, Functor &f, LinkNode *export_set)