mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 12:04:18 +02:00
Merge pull request #4607 from samcake/orange
Add support for Color attribute loading from FBX model
This commit is contained in:
commit
b55bb998d2
17 changed files with 108 additions and 17 deletions
|
@ -458,6 +458,18 @@ FBXNode parseFBX(QIODevice* device) {
|
|||
return top;
|
||||
}
|
||||
|
||||
QVector<glm::vec4> createVec4Vector(const QVector<double>& doubleVector) {
|
||||
QVector<glm::vec4> values;
|
||||
for (const double* it = doubleVector.constData(), *end = it + (doubleVector.size() / 4 * 4); it != end; ) {
|
||||
float x = *it++;
|
||||
float y = *it++;
|
||||
float z = *it++;
|
||||
float w = *it++;
|
||||
values.append(glm::vec4(x, y, z, w));
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
QVector<glm::vec3> createVec3Vector(const QVector<double>& doubleVector) {
|
||||
QVector<glm::vec3> values;
|
||||
for (const double* it = doubleVector.constData(), *end = it + (doubleVector.size() / 3 * 3); it != end; ) {
|
||||
|
@ -739,6 +751,11 @@ public:
|
|||
bool normalsByVertex;
|
||||
QVector<glm::vec3> normals;
|
||||
QVector<int> normalIndices;
|
||||
|
||||
bool colorsByVertex;
|
||||
QVector<glm::vec4> colors;
|
||||
QVector<int> colorIndices;
|
||||
|
||||
QVector<glm::vec2> texCoords;
|
||||
QVector<int> texCoordIndices;
|
||||
|
||||
|
@ -776,6 +793,23 @@ void appendIndex(MeshData& data, QVector<int>& indices, int index) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
glm::vec4 color;
|
||||
bool hasColors = (data.colors.size() > 1);
|
||||
if (hasColors) {
|
||||
int colorIndex = data.colorsByVertex ? vertexIndex : index;
|
||||
if (data.colorIndices.isEmpty()) {
|
||||
if (colorIndex < data.colors.size()) {
|
||||
color = data.colors.at(colorIndex);
|
||||
}
|
||||
} else if (colorIndex < data.colorIndices.size()) {
|
||||
colorIndex = data.colorIndices.at(colorIndex);
|
||||
if (colorIndex >= 0 && colorIndex < data.colors.size()) {
|
||||
color = data.colors.at(colorIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (data.texCoordIndices.isEmpty()) {
|
||||
if (index < data.texCoords.size()) {
|
||||
vertex.texCoord = data.texCoords.at(index);
|
||||
|
@ -810,6 +844,9 @@ void appendIndex(MeshData& data, QVector<int>& indices, int index) {
|
|||
data.extracted.mesh.vertices.append(position);
|
||||
data.extracted.mesh.normals.append(normal);
|
||||
data.extracted.mesh.texCoords.append(vertex.texCoord);
|
||||
if (hasColors) {
|
||||
data.extracted.mesh.colors.append(glm::vec3(color));
|
||||
}
|
||||
if (hasMoreTexcoords) {
|
||||
data.extracted.mesh.texCoords1.append(vertex.texCoord1);
|
||||
}
|
||||
|
@ -852,6 +889,28 @@ ExtractedMesh extractMesh(const FBXNode& object, unsigned int& meshIndex) {
|
|||
// hack to work around wacky Makehuman exports
|
||||
data.normalsByVertex = true;
|
||||
}
|
||||
} else if (child.name == "LayerElementColor") {
|
||||
data.colorsByVertex = false;
|
||||
bool indexToDirect = false;
|
||||
foreach (const FBXNode& subdata, child.children) {
|
||||
if (subdata.name == "Colors") {
|
||||
data.colors = createVec4Vector(getDoubleVector(subdata));
|
||||
|
||||
} else if (subdata.name == "ColorsIndex") {
|
||||
data.colorIndices = getIntVector(subdata);
|
||||
|
||||
} else if (subdata.name == "MappingInformationType" && subdata.properties.at(0) == "ByVertice") {
|
||||
data.colorsByVertex = true;
|
||||
|
||||
} else if (subdata.name == "ReferenceInformationType" && subdata.properties.at(0) == "IndexToDirect") {
|
||||
indexToDirect = true;
|
||||
}
|
||||
}
|
||||
if (indexToDirect && data.normalIndices.isEmpty()) {
|
||||
// hack to work around wacky Makehuman exports
|
||||
data.colorsByVertex = true;
|
||||
}
|
||||
|
||||
} else if (child.name == "LayerElementUV") {
|
||||
if (child.properties.at(0).toInt() == 0) {
|
||||
AttributeData attrib;
|
||||
|
|
|
@ -2505,7 +2505,7 @@ int Model::renderMeshesFromList(QVector<int>& list, gpu::Batch& batch, RenderMod
|
|||
}
|
||||
|
||||
if (mesh.colors.isEmpty()) {
|
||||
GLBATCH(glColor4f)(0.0f, 1.0f, 0.0f, 1.0f);
|
||||
GLBATCH(glColor4f)(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
}
|
||||
|
||||
qint64 offset = 0;
|
||||
|
|
|
@ -21,6 +21,9 @@ uniform sampler2D diffuseMap;
|
|||
// the interpolated normal
|
||||
varying vec4 normal;
|
||||
|
||||
varying vec3 color;
|
||||
|
||||
|
||||
void main(void) {
|
||||
// Fetch diffuse map
|
||||
vec4 diffuse = texture2D(diffuseMap, gl_TexCoord[0].st);
|
||||
|
@ -30,7 +33,7 @@ void main(void) {
|
|||
packDeferredFragment(
|
||||
normalize(normal.xyz),
|
||||
evalOpaqueFinalAlpha(getMaterialOpacity(mat), diffuse.a),
|
||||
getMaterialDiffuse(mat) * diffuse.rgb,
|
||||
getMaterialDiffuse(mat) * diffuse.rgb * color,
|
||||
getMaterialSpecular(mat),
|
||||
getMaterialShininess(mat));
|
||||
}
|
||||
|
|
|
@ -19,14 +19,15 @@ const int MAX_TEXCOORDS = 2;
|
|||
|
||||
uniform mat4 texcoordMatrices[MAX_TEXCOORDS];
|
||||
|
||||
|
||||
// the interpolated normal
|
||||
varying vec4 normal;
|
||||
|
||||
varying vec3 color;
|
||||
|
||||
void main(void) {
|
||||
|
||||
// pass along the diffuse color
|
||||
gl_FrontColor = gl_Color;
|
||||
color = gl_Color.xyz;
|
||||
|
||||
// and the texture coordinates
|
||||
gl_TexCoord[0] = texcoordMatrices[0] * vec4(gl_MultiTexCoord0.xy, 0.0, 1.0);
|
||||
|
|
|
@ -26,6 +26,8 @@ uniform vec2 emissiveParams;
|
|||
// the interpolated normal
|
||||
varying vec4 normal;
|
||||
|
||||
varying vec3 color;
|
||||
|
||||
// the interpolated texcoord1
|
||||
varying vec2 interpolatedTexcoord1;
|
||||
|
||||
|
@ -39,7 +41,7 @@ void main(void) {
|
|||
packDeferredFragmentLightmap(
|
||||
normalize(normal.xyz),
|
||||
evalOpaqueFinalAlpha(getMaterialOpacity(mat), diffuse.a),
|
||||
getMaterialDiffuse(mat) * diffuse.rgb,
|
||||
getMaterialDiffuse(mat) * diffuse.rgb * color,
|
||||
getMaterialSpecular(mat),
|
||||
getMaterialShininess(mat),
|
||||
(vec3(emissiveParams.x) + emissiveParams.y * emissive.rgb));
|
||||
|
|
|
@ -28,9 +28,12 @@ varying vec4 normal;
|
|||
// the interpolated texcoord1
|
||||
varying vec2 interpolatedTexcoord1;
|
||||
|
||||
varying vec3 color;
|
||||
|
||||
|
||||
void main(void) {
|
||||
// pass along the diffuse color
|
||||
gl_FrontColor = gl_Color;
|
||||
color = gl_Color.xyz;
|
||||
|
||||
// and the texture coordinates
|
||||
gl_TexCoord[0] = texcoordMatrices[0] * vec4(gl_MultiTexCoord0.xy, 0.0, 1.0);
|
||||
|
|
|
@ -34,6 +34,8 @@ varying vec4 interpolatedTangent;
|
|||
|
||||
varying vec2 interpolatedTexcoord1;
|
||||
|
||||
varying vec3 color;
|
||||
|
||||
void main(void) {
|
||||
// compute the view normal from the various bits
|
||||
vec3 normalizedNormal = normalize(vec3(interpolatedNormal));
|
||||
|
@ -52,7 +54,7 @@ void main(void) {
|
|||
packDeferredFragmentLightmap(
|
||||
normalize(viewNormal.xyz),
|
||||
evalOpaqueFinalAlpha(getMaterialOpacity(mat), diffuse.a),
|
||||
getMaterialDiffuse(mat) * diffuse.rgb,
|
||||
getMaterialDiffuse(mat) * diffuse.rgb * color,
|
||||
getMaterialSpecular(mat),
|
||||
getMaterialShininess(mat),
|
||||
(vec3(emissiveParams.x) + emissiveParams.y * emissive.rgb));
|
||||
|
|
|
@ -34,13 +34,15 @@ varying vec4 interpolatedTangent;
|
|||
// the interpolated texcoord1
|
||||
varying vec2 interpolatedTexcoord1;
|
||||
|
||||
varying vec3 color;
|
||||
|
||||
void main(void) {
|
||||
// transform and store the normal and tangent for interpolation
|
||||
//interpolatedNormal = gl_ModelViewMatrix * vec4(gl_Normal, 0.0);
|
||||
//interpolatedTangent = gl_ModelViewMatrix * vec4(tangent, 0.0);
|
||||
|
||||
// pass along the diffuse color
|
||||
gl_FrontColor = gl_Color;
|
||||
color = gl_Color.xyz;
|
||||
|
||||
// and the texture coordinates
|
||||
gl_TexCoord[0] = texcoordMatrices[0] * vec4(gl_MultiTexCoord0.xy, 0.0, 1.0);
|
||||
|
|
|
@ -37,6 +37,9 @@ varying vec4 interpolatedTangent;
|
|||
|
||||
varying vec2 interpolatedTexcoord1;
|
||||
|
||||
varying vec3 color;
|
||||
|
||||
|
||||
void main(void) {
|
||||
// compute the view normal from the various bits
|
||||
vec3 normalizedNormal = normalize(vec3(interpolatedNormal));
|
||||
|
@ -56,7 +59,7 @@ void main(void) {
|
|||
packDeferredFragmentLightmap(
|
||||
normalize(viewNormal.xyz),
|
||||
evalOpaqueFinalAlpha(getMaterialOpacity(mat), diffuse.a),
|
||||
getMaterialDiffuse(mat) * diffuse.rgb,
|
||||
getMaterialDiffuse(mat) * diffuse.rgb * color,
|
||||
specular, // no use of getMaterialSpecular(mat)
|
||||
getMaterialShininess(mat),
|
||||
(vec3(emissiveParams.x) + emissiveParams.y * emissive.rgb));
|
||||
|
|
|
@ -31,6 +31,8 @@ varying vec4 normal;
|
|||
|
||||
varying vec2 interpolatedTexcoord1;
|
||||
|
||||
varying vec3 color;
|
||||
|
||||
void main(void) {
|
||||
// set the diffuse, normal, specular data
|
||||
vec4 diffuse = texture2D(diffuseMap, gl_TexCoord[0].st);
|
||||
|
@ -42,7 +44,7 @@ void main(void) {
|
|||
packDeferredFragmentLightmap(
|
||||
normalize(normal.xyz),
|
||||
evalOpaqueFinalAlpha(getMaterialOpacity(mat), diffuse.a),
|
||||
getMaterialDiffuse(mat) * diffuse.rgb,
|
||||
getMaterialDiffuse(mat) * diffuse.rgb * color,
|
||||
specular, // no use of getMaterialSpecular(mat)
|
||||
getMaterialShininess(mat),
|
||||
(vec3(emissiveParams.x) + emissiveParams.y * emissive.rgb));
|
||||
|
|
|
@ -28,6 +28,8 @@ varying vec4 interpolatedNormal;
|
|||
// the interpolated tangent
|
||||
varying vec4 interpolatedTangent;
|
||||
|
||||
varying vec3 color;
|
||||
|
||||
void main(void) {
|
||||
// compute the view normal from the various bits
|
||||
vec3 normalizedNormal = normalize(vec3(interpolatedNormal));
|
||||
|
@ -44,7 +46,7 @@ void main(void) {
|
|||
packDeferredFragment(
|
||||
normalize(viewNormal.xyz),
|
||||
evalOpaqueFinalAlpha(getMaterialOpacity(mat), diffuse.a),
|
||||
getMaterialDiffuse(mat) * diffuse.rgb,
|
||||
getMaterialDiffuse(mat) * diffuse.rgb * color,
|
||||
getMaterialSpecular(mat),
|
||||
getMaterialShininess(mat));
|
||||
}
|
||||
|
|
|
@ -29,13 +29,15 @@ varying vec4 interpolatedNormal;
|
|||
// the interpolated tangent
|
||||
varying vec4 interpolatedTangent;
|
||||
|
||||
varying vec3 color;
|
||||
|
||||
void main(void) {
|
||||
// transform and store the normal and tangent for interpolation
|
||||
//interpolatedNormal = gl_ModelViewMatrix * vec4(gl_Normal, 0.0);
|
||||
//interpolatedTangent = gl_ModelViewMatrix * vec4(tangent, 0.0);
|
||||
|
||||
// pass along the diffuse color
|
||||
gl_FrontColor = gl_Color;
|
||||
color = gl_Color.xyz;
|
||||
|
||||
// and the texture coordinates
|
||||
gl_TexCoord[0] = texcoordMatrices[0] * vec4(gl_MultiTexCoord0.xy, 0.0, 1.0);
|
||||
|
|
|
@ -31,6 +31,8 @@ varying vec4 interpolatedNormal;
|
|||
// the interpolated tangent
|
||||
varying vec4 interpolatedTangent;
|
||||
|
||||
varying vec3 color;
|
||||
|
||||
void main(void) {
|
||||
// compute the view normal from the various bits
|
||||
vec3 normalizedNormal = normalize(vec3(interpolatedNormal));
|
||||
|
@ -49,7 +51,7 @@ void main(void) {
|
|||
packDeferredFragment(
|
||||
normalize(viewNormal.xyz),
|
||||
evalOpaqueFinalAlpha(getMaterialOpacity(mat), diffuse.a),
|
||||
getMaterialDiffuse(mat) * diffuse.rgb,
|
||||
getMaterialDiffuse(mat) * diffuse.rgb * color,
|
||||
specular, //getMaterialSpecular(mat),
|
||||
getMaterialShininess(mat));
|
||||
}
|
||||
|
|
|
@ -25,6 +25,8 @@ uniform sampler2D specularMap;
|
|||
// the interpolated normal
|
||||
varying vec4 normal;
|
||||
|
||||
varying vec3 color;
|
||||
|
||||
void main(void) {
|
||||
// set the diffuse, normal, specular data
|
||||
vec4 diffuse = texture2D(diffuseMap, gl_TexCoord[0].st);
|
||||
|
@ -35,7 +37,7 @@ void main(void) {
|
|||
packDeferredFragment(
|
||||
normalize(normal.xyz),
|
||||
evalOpaqueFinalAlpha(getMaterialOpacity(mat), diffuse.a),
|
||||
getMaterialDiffuse(mat) * diffuse.rgb,
|
||||
getMaterialDiffuse(mat) * diffuse.rgb * color,
|
||||
specular, //getMaterialSpecular(mat),
|
||||
getMaterialShininess(mat));
|
||||
}
|
||||
|
|
|
@ -21,6 +21,8 @@ uniform sampler2D diffuseMap;
|
|||
|
||||
varying vec4 normal;
|
||||
|
||||
varying vec3 color;
|
||||
|
||||
void main(void) {
|
||||
|
||||
// Fetch diffuse map
|
||||
|
@ -31,7 +33,7 @@ void main(void) {
|
|||
packDeferredFragmentTranslucent(
|
||||
normalize(normal.xyz),
|
||||
getMaterialOpacity(mat) * diffuse.a,
|
||||
getMaterialDiffuse(mat) * diffuse.rgb,
|
||||
getMaterialDiffuse(mat) * diffuse.rgb * color,
|
||||
getMaterialSpecular(mat),
|
||||
getMaterialShininess(mat));
|
||||
|
||||
|
|
|
@ -28,6 +28,8 @@ attribute vec4 clusterWeights;
|
|||
// the interpolated normal
|
||||
varying vec4 normal;
|
||||
|
||||
varying vec3 color;
|
||||
|
||||
void main(void) {
|
||||
vec4 position = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
normal = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
|
@ -39,7 +41,7 @@ void main(void) {
|
|||
}
|
||||
|
||||
// pass along the diffuse color
|
||||
gl_FrontColor = gl_Color;
|
||||
color = gl_Color.xyz;
|
||||
|
||||
// and the texture coordinates
|
||||
gl_TexCoord[0] = texcoordMatrices[0] * vec4(gl_MultiTexCoord0.xy, 0.0, 1.0);
|
||||
|
|
|
@ -34,6 +34,8 @@ varying vec4 interpolatedNormal;
|
|||
// the interpolated tangent
|
||||
varying vec4 interpolatedTangent;
|
||||
|
||||
varying vec3 color;
|
||||
|
||||
void main(void) {
|
||||
vec4 interpolatedPosition = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
interpolatedNormal = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
|
@ -47,7 +49,7 @@ void main(void) {
|
|||
}
|
||||
|
||||
// pass along the diffuse color
|
||||
gl_FrontColor = gl_Color;
|
||||
color = gl_Color.xyz;
|
||||
|
||||
// and the texture coordinates
|
||||
gl_TexCoord[0] = texcoordMatrices[0] * vec4(gl_MultiTexCoord0.xy, 0.0, 1.0);
|
||||
|
|
Loading…
Reference in a new issue