diff --git a/src/Fbx2Raw.cpp b/src/Fbx2Raw.cpp index b3ac439..8153183 100644 --- a/src/Fbx2Raw.cpp +++ b/src/Fbx2Raw.cpp @@ -458,10 +458,11 @@ static bool TriangleTexturePolarity(const Vec2f &uv0, const Vec2f &uv1, const Ve } static RawMaterialType -GetMaterialType(const RawModel &raw, const int textures[RAW_TEXTURE_USAGE_MAX], const bool skinned) +GetMaterialType(const RawModel &raw, const int textures[RAW_TEXTURE_USAGE_MAX], const bool vertexTransparency, const bool skinned) { - if ((raw.GetVertexAttributes() & RAW_VERTEX_ATTRIBUTE_COLOR) != 0) { - return skinned ? RAW_MATERIAL_TYPE_SKINNED_VERTEX_COLORED : RAW_MATERIAL_TYPE_VERTEX_COLORED; + // if there is vertex transparency, definitely transparent + if (vertexTransparency) { + return skinned ? RAW_MATERIAL_TYPE_SKINNED_TRANSPARENT : RAW_MATERIAL_TYPE_TRANSPARENT; } // Determine material type based on texture occlusion. @@ -588,12 +589,8 @@ static void ReadMesh(RawModel &raw, FbxScene *pScene, FbxNode *pNode, const std: maybeAddTexture(matProps.texShininess, RAW_TEXTURE_USAGE_SHININESS); } - const RawMaterialType materialType = GetMaterialType(raw, textures, skinning.IsSkinned()); - const int rawMaterialIndex = raw.AddMaterial( - materialName, shadingModel, materialType, textures, - toVec3f(ambient), toVec4f(diffuse), toVec3f(specular), toVec3f(emissive), shininess); - RawVertex rawVertices[3]; + bool vertexTransparency = false; for (int vertexIndex = 0; vertexIndex < 3; vertexIndex++, polygonVertexIndex++) { const int controlPointIndex = pMesh->GetPolygonVertex(polygonIndex, vertexIndex); @@ -636,6 +633,9 @@ static void ReadMesh(RawModel &raw, FbxScene *pScene, FbxNode *pNode, const std: vertex.jointWeights = skinning.GetVertexWeights(controlPointIndex); vertex.polarityUv0 = false; + // flag this triangle as transparent if any of its corner vertices substantially deviates from fully opaque + vertexTransparency |= (fabs(fbxColor.mAlpha - 1.0) > 1e-3); + rawSurface.bounds.AddPoint(vertex.position); if (skinning.IsSkinned()) { @@ -690,6 +690,11 @@ static void ReadMesh(RawModel &raw, FbxScene *pScene, FbxNode *pNode, const std: rawVertexIndices[vertexIndex] = raw.AddVertex(rawVertices[vertexIndex]); } + const RawMaterialType materialType = GetMaterialType(raw, textures, vertexTransparency, skinning.IsSkinned()); + const int rawMaterialIndex = raw.AddMaterial( + materialName, shadingModel, materialType, textures, + toVec3f(ambient), toVec4f(diffuse), toVec3f(specular), toVec3f(emissive), shininess); + raw.AddTriangle(rawVertexIndices[0], rawVertexIndices[1], rawVertexIndices[2], rawMaterialIndex, rawSurfaceIndex); } } diff --git a/src/Raw2Gltf.cpp b/src/Raw2Gltf.cpp index 5e5d383..1dc3139 100644 --- a/src/Raw2Gltf.cpp +++ b/src/Raw2Gltf.cpp @@ -410,8 +410,6 @@ ModelData *Raw2Gltf( for (int materialIndex = 0; materialIndex < raw.GetMaterialCount(); materialIndex++) { const RawMaterial &material = raw.GetMaterial(materialIndex); const bool isTransparent = - material.type == RAW_MATERIAL_TYPE_VERTEX_COLORED || - material.type == RAW_MATERIAL_TYPE_SKINNED_VERTEX_COLORED || material.type == RAW_MATERIAL_TYPE_TRANSPARENT || material.type == RAW_MATERIAL_TYPE_SKINNED_TRANSPARENT; diff --git a/src/RawModel.h b/src/RawModel.h index ec86746..e0b01b9 100644 --- a/src/RawModel.h +++ b/src/RawModel.h @@ -136,10 +136,8 @@ enum RawMaterialType { RAW_MATERIAL_TYPE_OPAQUE, RAW_MATERIAL_TYPE_TRANSPARENT, - RAW_MATERIAL_TYPE_VERTEX_COLORED, RAW_MATERIAL_TYPE_SKINNED_OPAQUE, RAW_MATERIAL_TYPE_SKINNED_TRANSPARENT, - RAW_MATERIAL_TYPE_SKINNED_VERTEX_COLORED }; struct RawMaterial