stream >> atom >> materials_.back().shininess;
stream >> atom >> materials_.back().diffuse[3]; // transparency
- materials_.back().diffuse[3] = 1.0;
+ materials_.back().diffuse[3] = 1.0; // FIXME: temporary
log_info("read material", materials_.back().name,
materials_.back().diffuse);
int numrefs = 0;
stream >> numrefs;
- ASSERT(numrefs == 3 || numrefs == 4);
+ ASSERT(numrefs >= 3);
if ((int)obj->faces.size() <= material)
{
}
material_group& face = obj->faces[material];
- for (int j = 0; j < numrefs; ++j)
+
+ int vert;
+ stream >> vert;
+ vector2 uv = read_pair(stream);
+ face.triangles.push_back(vert);
+ face.triangles_uv.push_back(uv);
+
+ unsigned first = face.triangles.back();
+ vector2 first_uv = face.triangles_uv.back();
+
+ stream >> vert;
+ uv = read_pair(stream);
+ face.triangles.push_back(vert);
+ face.triangles_uv.push_back(uv);
+
+ stream >> vert;
+ uv = read_pair(stream);
+ face.triangles.push_back(vert);
+ face.triangles_uv.push_back(uv);
+
+ unsigned last = face.triangles.back();
+ vector2 last_uv = face.triangles_uv.back();
+
+ for (int j = 3; j < numrefs; ++j)
{
- int vert;
+ // first
+ face.triangles.push_back(first);
+ face.triangles_uv.push_back(first_uv);
+
+ // last
+ face.triangles.push_back(last);
+ face.triangles_uv.push_back(last_uv);
+
stream >> vert;
+ uv = read_pair(stream);
+ face.triangles.push_back(vert);
+ face.triangles_uv.push_back(uv);
- vector2 uv = read_pair(stream);
-
- if (numrefs == 3)
- {
- face.triangles.push_back(vert);
- face.triangles_uv.push_back(uv);
- }
- else
- {
- face.quads.push_back(vert);
- face.quads_uv.push_back(uv);
- }
+ last = face.triangles.back();
+ last_uv = face.triangles_uv.back();
}
}
}
void mesh::set_material(const material& material) const
{
- //glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, material.diffuse.data());
- //glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, material.ambient.data());
- //glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, material.specular.data());
- //glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, material.emissive.data());
- //glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, material.shininess);
- glColor(material.diffuse);
+ glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, material.diffuse.data());
+ glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, material.ambient.data());
+ glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, material.specular.data());
+ glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, material.emissive.data());
+ glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, material.shininess);
+ //glColor(material.diffuse);
}
//glEnd();
//}
- glPolygonMode(GL_BACK, GL_LINE);
+ //glPolygonMode(GL_BACK, GL_LINE);
//glVertexPointer(3, GL_SCALAR, 0, verts[0].data());
if (texture) texture->bind();
else image::reset_binding();
- for (int i = 0; i < faces.size(); ++i)
+ for (size_t i = 0; i < faces.size(); ++i)
{
const material_group& face = faces[i];
mesh.set_material(i);
glVertex(verts[face.triangles[j+2]]);
glEnd();
}
-
- count = face.quads.size();
- for (int j = 0; j < count; j += 4)
- {
- glBegin(GL_QUADS);
- glTexCoord(face.quads_uv[j]);
- glVertex(verts[face.quads[j]]);
- glTexCoord(face.quads_uv[j+1]);
- glVertex(verts[face.quads[j+1]]);
- glTexCoord(face.quads_uv[j+2]);
- glVertex(verts[face.quads[j+2]]);
- glTexCoord(face.quads_uv[j+3]);
- glVertex(verts[face.quads[j+3]]);
- glEnd();
- }
}
std::vector<object_ptr>::const_iterator jt;
triangles.size(), GL_UNSIGNED_INT,
&triangles[0]);
}
-
- if (quads.size() > 0)
- {
- //log_info("drawing quads:", quads.size()/4);
- glTexCoordPointer(2, GL_SCALAR, 0, quads_uv[0].data());
- glDrawElements(GL_QUADS, quads.size(), GL_UNSIGNED_INT, &quads[0]);
- }
*/
}
};
- //typedef vector3 triangle[3];
- //typedef vector2 triangle_uv[3];
- //typedef vector3 quad[4];
- //typedef vector2 quad_uv[4];
-
- //struct triangle
- //{
- //vector3 verts[3];
- //vector3& operator [] (int i) { return verts[i]; }
- //const vector3& operator [] (int i) const { return verts[i]; }
- //};
-
- //struct triangle_uv
- //{
- //vector2 verts[3];
- //vector2& operator [] (int i) { return verts[i]; }
- //const vector2& operator [] (int i) const { return verts[i]; }
- //};
-
-
- //struct quad
- //{
- //vector3 verts[4];
- //vector3& operator [] (int i) { return verts[i]; }
- //const vector3& operator [] (int i) const { return verts[i]; }
- //};
-
-
- //struct quad_uv
- //{
- //vector2 verts[4];
- //vector2& operator [] (int i) { return verts[i]; }
- //const vector2& operator [] (int i) const { return verts[i]; }
- //};
-
-
void set_material(int index) const;
void set_material(const material& material) const;
{
material_group() {}
- std::vector<unsigned> triangles;
- std::vector<vector2> triangles_uv;
-
- std::vector<unsigned> quads;
- std::vector<vector2> quads_uv;
+ void draw(scalar alpha = SCALAR(0.0)) const;
- void draw(scalar alpha = SCALAR(0.0)) const;
+ std::vector<unsigned> triangles;
+ std::vector<vector2> triangles_uv;
};