Merge pull request #1017 from ey6es/master

Use diffuse color, specular color, and shininess from FBX file.
This commit is contained in:
Stephen Birarda 2013-10-04 17:11:11 -07:00
commit e3f830ec09
4 changed files with 60 additions and 8 deletions

View file

@ -88,8 +88,7 @@ bool BlendFace::render(float alpha) {
// enable normalization under the expectation that the GPU can do it faster
glEnable(GL_NORMALIZE);
glEnable(GL_TEXTURE_2D);
glColor4f(_owningHead->getSkinColor().r, _owningHead->getSkinColor().g, _owningHead->getSkinColor().b, alpha);
glDisable(GL_COLOR_MATERIAL);
for (int i = 0; i < networkMeshes.size(); i++) {
const NetworkMesh& networkMesh = networkMeshes.at(i);
@ -118,12 +117,15 @@ bool BlendFace::render(float alpha) {
}
}
glMultMatrixf((const GLfloat*)&mesh.transform);
// apply material properties
glm::vec4 diffuse = glm::vec4(mesh.diffuseColor, alpha);
glm::vec4 specular = glm::vec4(mesh.specularColor, alpha);
glMaterialfv(GL_FRONT, GL_AMBIENT, (const float*)&diffuse);
glMaterialfv(GL_FRONT, GL_DIFFUSE, (const float*)&diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, (const float*)&specular);
glMaterialf(GL_FRONT, GL_SHININESS, mesh.shininess);
// all meshes after the first are white
if (i == 1) {
glColor4f(1.0f, 1.0f, 1.0f, alpha);
}
glMultMatrixf((const GLfloat*)&mesh.transform);
glBindTexture(GL_TEXTURE_2D, texture == NULL ? 0 : texture->getID());
@ -191,6 +193,9 @@ bool BlendFace::render(float alpha) {
glPopMatrix();
// restore all the default material settings
Application::getInstance()->setupWorldLight(*Application::getInstance()->getCamera());
return true;
}

View file

@ -313,6 +313,9 @@ void Head::render(float alpha, bool isMine) {
}
void Head::setScale (float scale) {
if (_scale == scale) {
return;
}
_scale = scale;
createMohawk();

View file

@ -346,6 +346,13 @@ void printNode(const FBXNode& node, int indent) {
}
}
class Material {
public:
glm::vec3 diffuse;
glm::vec3 specular;
float shininess;
};
FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping) {
QHash<qint64, FBXMesh> meshes;
QVector<ExtractedBlendshape> blendshapes;
@ -354,6 +361,7 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping)
QHash<qint64, Transform> localTransforms;
QHash<qint64, glm::mat4> transformLinkMatrices;
QHash<qint64, QByteArray> textureFilenames;
QHash<qint64, Material> materials;
QHash<qint64, qint64> diffuseTextures;
QHash<qint64, qint64> bumpTextures;
@ -578,6 +586,31 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping)
textureFilenames.insert(object.properties.at(0).value<qint64>(), filename);
}
}
} else if (object.name == "Material") {
Material material = { glm::vec3(1.0f, 1.0f, 1.0f), glm::vec3(1.0f, 1.0f, 1.0f), 96.0f };
foreach (const FBXNode& subobject, object.children) {
if (subobject.name == "Properties70") {
foreach (const FBXNode& property, subobject.children) {
if (property.name == "P") {
if (property.properties.at(0) == "DiffuseColor") {
material.diffuse = glm::vec3(property.properties.at(4).value<double>(),
property.properties.at(5).value<double>(),
property.properties.at(6).value<double>());
} else if (property.properties.at(0) == "SpecularColor") {
material.specular = glm::vec3(property.properties.at(4).value<double>(),
property.properties.at(5).value<double>(),
property.properties.at(6).value<double>());
} else if (property.properties.at(0) == "Shininess") {
material.shininess = property.properties.at(4).value<double>();
}
}
}
}
}
materials.insert(object.properties.at(0).value<qint64>(), material);
} else if (object.name == "Deformer") {
if (object.properties.at(2) == "Cluster") {
foreach (const FBXNode& subobject, object.children) {
@ -641,8 +674,15 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping)
qint64 modelID = parentMap.value(it.key());
glm::mat4 modelTransform = getGlobalTransform(parentMap, localTransforms, modelID);
// look for textures
// look for textures, material properties
foreach (qint64 childID, childMap.values(modelID)) {
if (!materials.contains(childID)) {
continue;
}
Material material = materials.value(childID);
mesh.diffuseColor = material.diffuse;
mesh.specularColor = material.specular;
mesh.shininess = material.shininess;
qint64 diffuseTextureID = diffuseTextures.value(childID);
if (diffuseTextureID != 0) {
mesh.diffuseFilename = textureFilenames.value(diffuseTextureID);

View file

@ -51,6 +51,10 @@ public:
bool isEye;
glm::vec3 diffuseColor;
glm::vec3 specularColor;
float shininess;
QByteArray diffuseFilename;
QByteArray normalFilename;