Merge branch 'master' into blender2.8
authorCampbell Barton <ideasman42@gmail.com>
Thu, 14 Dec 2017 01:51:26 +0000 (12:51 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Thu, 14 Dec 2017 01:51:26 +0000 (12:51 +1100)
1  2 
source/blender/blenkernel/intern/particle.c
source/blender/collada/GeometryExporter.cpp

index 587f30b6eb8fbea63dcb079a361f4bab3eff641e,73b00fd07ecf6dfd3b729d01e1fee77d26ddc48c..c0d3c947ac1c3f7af45f7c7e39136524208e3b82
@@@ -417,10 -475,190 +417,189 @@@ void GeometryExporter::createPolylist(s
  
                texindex += loop_count;
        }
 -
 -      finishList(is_triangulated, facelist);
 -      delete facelist;
 +              
 +      polylist.finish();
  }
  
 -              std::string tpageid = (mtpolys && tp->tpage) ? id_name(tp->tpage) : "";
+ void GeometryExporter::createPolylists(std::set<Image *> uv_images,
+       bool has_uvs,
+       bool has_color,
+       Object *ob,
+       Mesh *me,
+       std::string& geom_id,
+       std::vector<BCPolygonNormalsIndices>& norind)
+ {
+       std::set<Image *>::iterator uv_images_iter;
+       for (uv_images_iter = uv_images.begin();
+               uv_images_iter != uv_images.end();
+               uv_images_iter++) {
+               Image *ima = *uv_images_iter;
+               std::string imageid(id_name(ima));
+               createPolylist(imageid, has_uvs,
+                       has_color,
+                       ob,
+                       me,
+                       geom_id,
+                       norind);
+       }
+       /* We msut add an additional collector for the case when 
+        * some parts of the object are not textured at all.
+        * The next call creates a polylist for all untextured polygons
+        */
+       createPolylist("", has_uvs,
+               has_color,
+               ob,
+               me,
+               geom_id,
+               norind);
+ }
+ /* ===========================================================================
+  * Export Meshes with UV Textures (export as materials, see also in 
+  * effectExporter and MaterialExporter)
+  * 
+  * If imageid is the empty string, then collect only untextured polygons
+  * =========================================================================== */ 
+ void GeometryExporter::createPolylist(std::string imageid,
+       bool has_uvs,
+       bool has_color,
+       Object *ob,
+       Mesh *me,
+       std::string& geom_id,
+       std::vector<BCPolygonNormalsIndices>& norind)
+ {
+       MPoly *mpolys = me->mpoly;
+       MLoop *mloops = me->mloop;
+       MTexPoly *mtpolys = me->mtpoly;
+       int totpolys = me->totpoly;
+       // <vcount>
+       int i;
+       int faces_in_polylist = 0;
+       std::vector<unsigned long> vcount_list;
+       bool is_triangulated = true;
+       // count faces with this material
+       for (i = 0; i < totpolys; i++) {
+               MTexPoly *tp = &mtpolys[i];
+               MPoly *p = &mpolys[i];
 -              std::string tpageid = (mtpolys && tp->tpage) ? id_name(tp->tpage) : "";
++              std::string tpageid = (tp->tpage) ? id_name(tp->tpage):"";
+               if (tpageid == imageid) {
+                       faces_in_polylist++;
+                       vcount_list.push_back(p->totloop);
+                       if (p->totloop != 3) {
+                               is_triangulated = false;
+                       }
+               }
+       }
+       // no faces using this imageid
+       if (faces_in_polylist == 0) {
+               if (imageid != "")
+                       fprintf(stderr, "%s: Image %s is not used.\n", id_name(ob).c_str(), imageid.c_str());
+               return;
+       }
+       COLLADASW::PrimitivesBase *facelist = getFacelist(is_triangulated, mSW);
+       // sets count attribute in <polylist>
+       facelist->setCount(faces_in_polylist);
+       if (imageid != "") {
+               // sets material name
+               std::string material_id = get_material_id_from_id(imageid);
+               std::ostringstream ostr;
+               ostr << translate_id(material_id);
+               facelist->setMaterial(ostr.str());
+       }
+       COLLADASW::InputList &til = facelist->getInputList();
+       // creates <input> in <polylist> for vertices 
+       COLLADASW::Input input1(COLLADASW::InputSemantic::VERTEX, getUrlBySemantics(geom_id, COLLADASW::InputSemantic::VERTEX), 0);
+       // creates <input> in <polylist> for normals
+       COLLADASW::Input input2(COLLADASW::InputSemantic::NORMAL, getUrlBySemantics(geom_id, COLLADASW::InputSemantic::NORMAL), 1);
+       til.push_back(input1);
+       til.push_back(input2);
+       // if mesh has uv coords writes <input> for TEXCOORD
+       int num_layers = CustomData_number_of_layers(&me->fdata, CD_MTFACE);
+       int active_uv_index = CustomData_get_active_layer_index(&me->fdata, CD_MTFACE) - 1;
+       for (i = 0; i < num_layers; i++) {
+               if (!this->export_settings->active_uv_only || i == active_uv_index) {
+                       std::string uv_name(bc_get_uvlayer_name(me, i));
+                       std::string effective_id = geom_id; // (uv_name == "") ? geom_id : uv_name;
+                       std::string layer_id = makeTexcoordSourceId(
+                               effective_id,
+                               i, this->export_settings->active_uv_only);
+                       /* Note: the third parameter denotes the offset of TEXCOORD in polylist elements
+                       For now this is always 2 (This may change sometime/maybe)
+                       */
+                       COLLADASW::Input input3(COLLADASW::InputSemantic::TEXCOORD,
+                               makeUrl(layer_id),
+                               2, // this is only until we have optimized UV sets
+                               (this->export_settings->active_uv_only) ? 0 : i  // only_active_uv exported -> we have only one set
+                               );
+                       til.push_back(input3);
+               }
+       }
+       int totlayer_mcol = CustomData_number_of_layers(&me->ldata, CD_MLOOPCOL);
+       if (totlayer_mcol > 0) {
+               int map_index = 0;
+               for (int a = 0; a < totlayer_mcol; a++) {
+                       char *layer_name = bc_CustomData_get_layer_name(&me->ldata, CD_MLOOPCOL, a);
+                       COLLADASW::Input input4(COLLADASW::InputSemantic::COLOR,
+                               makeUrl(makeVertexColorSourceId(geom_id, layer_name)),
+                               (has_uvs) ? 3 : 2,  // all color layers have same index order
+                               map_index           // set number equals color map index
+                               );
+                       til.push_back(input4);
+                       map_index++;
+               }
+       }
+       // performs the actual writing
+       prepareToAppendValues(is_triangulated, facelist, vcount_list);
+       // <p>
+       int texindex = 0;
+       for (i = 0; i < totpolys; i++) {
+               MTexPoly *tp = &mtpolys[i];
+               MPoly *p = &mpolys[i];
+               int loop_count = p->totloop;
++              std::string tpageid = (tp->tpage) ? id_name(tp->tpage) : "";
+               if (tpageid == imageid) {
+                       MLoop *l = &mloops[p->loopstart];
+                       BCPolygonNormalsIndices normal_indices = norind[i];
+                       for (int j = 0; j < loop_count; j++) {
+                               facelist->appendValues(l[j].v);
+                               facelist->appendValues(normal_indices[j]);
+                               if (has_uvs)
+                                       facelist->appendValues(texindex + j);
+                               if (has_color)
+                                       facelist->appendValues(texindex + j);
+                       }
+               }
+               texindex += loop_count;
+       }
+       finishList(is_triangulated, facelist);
+       delete facelist;
+ }
  
  // creates <source> for positions
  void GeometryExporter::createVertsSource(std::string geom_id, Mesh *me)