Added per-face materials exporting. If mesh has no materials it won't be
exported.
This commit is contained in:
@@ -165,7 +165,7 @@ public:
|
||||
//writes <source> for uv coords
|
||||
//if mesh has uv coords
|
||||
checkTexcoords = createTexcoordsSource(geom_name, dm, (Mesh*)ob->data);
|
||||
|
||||
|
||||
//<vertices>
|
||||
COLLADASW::Vertices verts(mSW);
|
||||
verts.setId(getIdBySemantics(geom_name, COLLADASW::VERTEX));
|
||||
@@ -174,109 +174,126 @@ public:
|
||||
getUrlBySemantics(geom_name, COLLADASW::POSITION));
|
||||
input_list.push_back(input);
|
||||
verts.add();
|
||||
|
||||
//polylist
|
||||
COLLADASW::Polylist polylist(mSW);
|
||||
|
||||
//sets count attribute in <polylist>
|
||||
polylist.setCount(totfaces);
|
||||
|
||||
COLLADASW::InputList &til = polylist.getInputList();
|
||||
|
||||
//creates list of attributes in <polylist> <input> for vertices
|
||||
COLLADASW::Input input2(COLLADASW::VERTEX, getUrlBySemantics
|
||||
(geom_name, COLLADASW::VERTEX), 0);
|
||||
//creates list of attributes in <polylist> <input> for normals
|
||||
COLLADASW::Input input3(COLLADASW::NORMAL, getUrlBySemantics
|
||||
(geom_name, COLLADASW::NORMAL), 0);
|
||||
|
||||
til.push_back(input2);
|
||||
til.push_back(input3);
|
||||
|
||||
//if mesh has uv coords writes <input> attributes for TEXCOORD
|
||||
if (checkTexcoords == true)
|
||||
{
|
||||
COLLADASW::Input input4(COLLADASW::TEXCOORD,
|
||||
getUrlBySemantics(geom_name, COLLADASW::TEXCOORD), 1, 0);
|
||||
til.push_back(input4);
|
||||
polylist.setMaterial("material-symbol");
|
||||
for(int a = 0; a < ob->totcol; a++) {
|
||||
//<vcount>
|
||||
int i;
|
||||
int faces_in_polylist = 0;
|
||||
std::vector<unsigned long> VCountList;
|
||||
for (i = 0; i < totfaces; i++) {
|
||||
MFace *f = &mfaces[i];
|
||||
if (f->mat_nr == a) {
|
||||
faces_in_polylist += 1;
|
||||
if (f->v4 == 0) {
|
||||
VCountList.push_back(3);
|
||||
}
|
||||
else {
|
||||
VCountList.push_back(4);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (faces_in_polylist == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
//<vcount>
|
||||
int i;
|
||||
std::vector<unsigned long> VCountList;
|
||||
for (i = 0; i < totfaces; i++) {
|
||||
MFace *f = &mfaces[i];
|
||||
|
||||
if (f->v4 == 0) {
|
||||
VCountList.push_back(3);
|
||||
}
|
||||
else {
|
||||
VCountList.push_back(4);
|
||||
Material *ma = give_current_material(ob, a+1);
|
||||
COLLADASW::Polylist polylist(mSW);
|
||||
|
||||
// sets count attribute in <polylist>
|
||||
polylist.setCount(faces_in_polylist);
|
||||
|
||||
// sets material name
|
||||
polylist.setMaterial(ma->id.name);
|
||||
|
||||
COLLADASW::InputList &til = polylist.getInputList();
|
||||
|
||||
//creates list of attributes in <polylist> <input> for vertices
|
||||
COLLADASW::Input input1(COLLADASW::VERTEX, getUrlBySemantics
|
||||
(geom_name, COLLADASW::VERTEX), 0);
|
||||
//creates list of attributes in <polylist> <input> for normals
|
||||
COLLADASW::Input input2(COLLADASW::NORMAL, getUrlBySemantics
|
||||
(geom_name, COLLADASW::NORMAL), 0);
|
||||
|
||||
til.push_back(input1);
|
||||
til.push_back(input2);
|
||||
|
||||
// if mesh has uv coords writes <input> attributes for TEXCOORD
|
||||
// XXX doesn't work when mesh has no uv channel
|
||||
if (checkTexcoords == true)
|
||||
{
|
||||
COLLADASW::Input input3(COLLADASW::TEXCOORD,
|
||||
getUrlBySemantics(geom_name, COLLADASW::TEXCOORD), 1, 0);
|
||||
til.push_back(input3);
|
||||
}
|
||||
// <vcount>
|
||||
polylist.setVCountList(VCountList);
|
||||
|
||||
//performs the actual writing
|
||||
polylist.prepareToAppendValues();
|
||||
|
||||
int texindex = 0;
|
||||
//<p>
|
||||
for (i = 0; i < totfaces; i++) {
|
||||
MFace *f = &mfaces[i];
|
||||
//if mesh has uv coords writes uv and
|
||||
//vertex indexes
|
||||
if (checkTexcoords == true && f->mat_nr == a) {
|
||||
// if triangle
|
||||
if (f->v4 == 0) {
|
||||
polylist.appendValues(f->v1);
|
||||
polylist.appendValues(texindex++);
|
||||
polylist.appendValues(f->v2);
|
||||
polylist.appendValues(texindex++);
|
||||
polylist.appendValues(f->v3);
|
||||
polylist.appendValues(texindex++);
|
||||
}
|
||||
// quad
|
||||
else {
|
||||
polylist.appendValues(f->v1);
|
||||
polylist.appendValues(texindex++);
|
||||
polylist.appendValues(f->v2);
|
||||
polylist.appendValues(texindex++);
|
||||
polylist.appendValues(f->v3);
|
||||
polylist.appendValues(texindex++);
|
||||
//tris.appendValues(f->v3);
|
||||
//tris.appendValues(texindex++);
|
||||
polylist.appendValues(f->v4);
|
||||
polylist.appendValues(texindex++);
|
||||
//tris.appendValues(f->v1);
|
||||
//tris.appendValues(texindex++);
|
||||
}
|
||||
}
|
||||
//if mesh has no uv coords writes only
|
||||
//vertex indexes
|
||||
else if(f->mat_nr == a){
|
||||
// if triangle
|
||||
if (f->v4 == 0) {
|
||||
polylist.appendValues(f->v1, f->v2, f->v3);
|
||||
}
|
||||
// quad
|
||||
else {
|
||||
polylist.appendValues(f->v1, f->v2, f->v3, f->v4);
|
||||
//tris.appendValues(f->v3, f->v4, f->v1);
|
||||
}
|
||||
}
|
||||
else if(f->mat_nr != a) {
|
||||
if (f->v4 == 0) {
|
||||
texindex += 3;
|
||||
}
|
||||
else {
|
||||
texindex += 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
//polylist.closeElement();
|
||||
polylist.finish();
|
||||
}
|
||||
polylist.setVCountList(VCountList);
|
||||
|
||||
//performs the actual writing
|
||||
polylist.prepareToAppendValues();
|
||||
|
||||
int texindex = 0;
|
||||
//<p>
|
||||
for (i = 0; i < totfaces; i++) {
|
||||
MFace *f = &mfaces[i];
|
||||
//if mesh has uv coords writes uv and
|
||||
//vertex indexes
|
||||
if (checkTexcoords == true) {
|
||||
// if triangle
|
||||
if (f->v4 == 0) {
|
||||
polylist.appendValues(f->v1);
|
||||
polylist.appendValues(texindex++);
|
||||
polylist.appendValues(f->v2);
|
||||
polylist.appendValues(texindex++);
|
||||
polylist.appendValues(f->v3);
|
||||
polylist.appendValues(texindex++);
|
||||
}
|
||||
// quad
|
||||
else {
|
||||
polylist.appendValues(f->v1);
|
||||
polylist.appendValues(texindex++);
|
||||
polylist.appendValues(f->v2);
|
||||
polylist.appendValues(texindex++);
|
||||
polylist.appendValues(f->v3);
|
||||
polylist.appendValues(texindex++);
|
||||
//tris.appendValues(f->v3);
|
||||
//tris.appendValues(texindex++);
|
||||
polylist.appendValues(f->v4);
|
||||
polylist.appendValues(texindex++);
|
||||
//tris.appendValues(f->v1);
|
||||
//tris.appendValues(texindex++);
|
||||
}
|
||||
}
|
||||
//if mesh has no uv coords writes only
|
||||
//vertex indexes
|
||||
else {
|
||||
// if triangle
|
||||
if (f->v4 == 0) {
|
||||
polylist.appendValues(f->v1, f->v2, f->v3);
|
||||
}
|
||||
// quad
|
||||
else {
|
||||
polylist.appendValues(f->v1, f->v2, f->v3, f->v4);
|
||||
//tris.appendValues(f->v3, f->v4, f->v1);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
polylist.closeElement();
|
||||
polylist.finish();
|
||||
|
||||
closeMesh();
|
||||
closeGeometry();
|
||||
|
||||
dm->release(dm);
|
||||
|
||||
|
||||
}
|
||||
|
||||
//creates <source> for positions
|
||||
@@ -507,12 +524,12 @@ public:
|
||||
COLLADASW::BindMaterial& bm = instGeom.getBindMaterial();
|
||||
COLLADASW::InstanceMaterialList& iml = bm.getInstanceMaterialList();
|
||||
std::string matid = std::string(ma->id.name);
|
||||
COLLADASW::InstanceMaterial im("material-symbol", COLLADASW::URI
|
||||
COLLADASW::InstanceMaterial im(matid, COLLADASW::URI
|
||||
(COLLADABU::Utils::EMPTY_STRING,
|
||||
matid));
|
||||
//iterate over all textures
|
||||
//if any add to list
|
||||
int c = 0;
|
||||
/*int c = 0;
|
||||
for (int b = 0; b < MAX_MTEX; b++) {
|
||||
MTex *mtex = ma->mtex[b];
|
||||
if (mtex && mtex->tex && mtex->tex->ima) {
|
||||
@@ -523,7 +540,7 @@ public:
|
||||
im.push_back(bvi);
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
iml.push_back(im);
|
||||
}
|
||||
|
||||
|
||||
@@ -351,7 +351,7 @@ public:
|
||||
}
|
||||
|
||||
COLLADAFW::Mesh *cmesh = (COLLADAFW::Mesh*)cgeom;
|
||||
|
||||
|
||||
// first check if we can import this mesh
|
||||
COLLADAFW::MeshPrimitiveArray& prim_arr = cmesh->getMeshPrimitives();
|
||||
|
||||
@@ -363,7 +363,7 @@ public:
|
||||
COLLADAFW::MeshPrimitive::PrimitiveType type = mp->getPrimitiveType();
|
||||
|
||||
const char *type_str = primTypeToStr(type);
|
||||
|
||||
|
||||
// OpenCollada passes POLYGONS type for <polylist>
|
||||
if (type == COLLADAFW::MeshPrimitive::POLYLIST || type == COLLADAFW::MeshPrimitive::POLYGONS) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user