1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-05 18:16:23 +03:00

0030810: Data Exchange, RWObj_CafReader - fix material assignment

RWObj_MtlReader fixed incorrect folder iteration within findRelativePath().
Fixed discarding texture-only material.
RWObj_TriangulationReader::addMesh() - fixed usage of wrong material for flushing previous group.
This commit is contained in:
kgv 2019-06-25 23:26:58 +03:00 committed by apn
parent 88c3accd1a
commit d9dd07545d
3 changed files with 31 additions and 3 deletions

View File

@ -63,7 +63,18 @@ namespace
theRelativePath = aRelPath; theRelativePath = aRelPath;
return true; return true;
} }
aPath = aFolder; aPath = aFolder;
for (; aPath.Length() >= 2;)
{
if (aPath.Value (aPath.Length()) == '/'
|| aPath.Value (aPath.Length()) == '\\')
{
aPath = aPath.SubString (1, aPath.Length() - 1);
continue;
}
break;
}
} }
} }
} }
@ -195,6 +206,7 @@ bool RWObj_MtlReader::Read (const TCollection_AsciiString& theFolder,
if (validateColor (aColor)) if (validateColor (aColor))
{ {
aMat.SpecularColor = Quantity_Color (aColor.r(), aColor.g(), aColor.b(), Quantity_TOC_RGB); aMat.SpecularColor = Quantity_Color (aColor.r(), aColor.g(), aColor.b(), Quantity_TOC_RGB);
hasAspect = true;
} }
} }
else if (::memcmp (aPos, "Ns", 2) == 0 else if (::memcmp (aPos, "Ns", 2) == 0
@ -207,6 +219,7 @@ bool RWObj_MtlReader::Read (const TCollection_AsciiString& theFolder,
if (aSpecular >= 0.0) if (aSpecular >= 0.0)
{ {
aMat.Shininess = (float )Min (aSpecular / 1000.0, 1.0); aMat.Shininess = (float )Min (aSpecular / 1000.0, 1.0);
hasAspect = true;
} }
} }
else if (::memcmp (aPos, "Tr", 2) == 0 else if (::memcmp (aPos, "Tr", 2) == 0
@ -220,6 +233,7 @@ bool RWObj_MtlReader::Read (const TCollection_AsciiString& theFolder,
&& aTransp <= 0.99) && aTransp <= 0.99)
{ {
aMat.Transparency = (float )aTransp; aMat.Transparency = (float )aTransp;
hasAspect = true;
} }
} }
else if (*aPos == 'd' && IsSpace (aPos[1])) else if (*aPos == 'd' && IsSpace (aPos[1]))
@ -233,6 +247,7 @@ bool RWObj_MtlReader::Read (const TCollection_AsciiString& theFolder,
&& anAlpha >= 0.01) && anAlpha >= 0.01)
{ {
aMat.Transparency = float(1.0 - anAlpha); aMat.Transparency = float(1.0 - anAlpha);
hasAspect = true;
} }
} }
else if (::memcmp (aPos, "map_Kd", 6) == 0 else if (::memcmp (aPos, "map_Kd", 6) == 0
@ -242,6 +257,7 @@ bool RWObj_MtlReader::Read (const TCollection_AsciiString& theFolder,
if (RWObj_Tools::ReadName (aPos, aMat.DiffuseTexture)) if (RWObj_Tools::ReadName (aPos, aMat.DiffuseTexture))
{ {
processTexturePath (aMat.DiffuseTexture, theFolder); processTexturePath (aMat.DiffuseTexture, theFolder);
hasAspect = true;
} }
} }
else if (::memcmp (aPos, "map_Ks", 6) == 0 else if (::memcmp (aPos, "map_Ks", 6) == 0
@ -251,6 +267,7 @@ bool RWObj_MtlReader::Read (const TCollection_AsciiString& theFolder,
if (RWObj_Tools::ReadName (aPos, aMat.SpecularTexture)) if (RWObj_Tools::ReadName (aPos, aMat.SpecularTexture))
{ {
processTexturePath (aMat.SpecularTexture, theFolder); processTexturePath (aMat.SpecularTexture, theFolder);
hasAspect = true;
} }
} }
else if (::memcmp (aPos, "map_Bump", 8) == 0 else if (::memcmp (aPos, "map_Bump", 8) == 0
@ -260,6 +277,7 @@ bool RWObj_MtlReader::Read (const TCollection_AsciiString& theFolder,
if (RWObj_Tools::ReadName (aPos, aMat.BumpTexture)) if (RWObj_Tools::ReadName (aPos, aMat.BumpTexture))
{ {
processTexturePath (aMat.BumpTexture, theFolder); processTexturePath (aMat.BumpTexture, theFolder);
hasAspect = true;
} }
} }
/*else if (::memcmp (aPos, "illum", 5) == 0) /*else if (::memcmp (aPos, "illum", 5) == 0)

View File

@ -32,7 +32,6 @@ Standard_Boolean RWObj_TriangulationReader::addMesh (const RWObj_SubMesh& theMes
return Standard_False; return Standard_False;
} }
const RWObj_Material* aMaterial = myMaterials.Seek (theMesh.Material);
if (Handle(Poly_Triangulation) aTris = GetTriangulation()) if (Handle(Poly_Triangulation) aTris = GetTriangulation())
{ {
myNodes.Clear(); myNodes.Clear();
@ -46,7 +45,11 @@ Standard_Boolean RWObj_TriangulationReader::addMesh (const RWObj_SubMesh& theMes
{ {
if (myShapeReceiver != NULL) if (myShapeReceiver != NULL)
{ {
myShapeReceiver->BindNamedShape (myLastGroupShape, theMesh.Group, myLastGroupShape.ShapeType() == TopAbs_FACE ? aMaterial : NULL, Standard_False); const RWObj_Material* aMaterial = myLastGroupShape.ShapeType() == TopAbs_FACE
&& !myLastFaceMaterial.IsEmpty()
? myMaterials.Seek (myLastFaceMaterial)
: NULL;
myShapeReceiver->BindNamedShape (myLastGroupShape, myLastGroupName, aMaterial, Standard_False);
} }
} }
myLastGroupShape = TopoDS_Shape(); myLastGroupShape = TopoDS_Shape();
@ -57,8 +60,10 @@ Standard_Boolean RWObj_TriangulationReader::addMesh (const RWObj_SubMesh& theMes
BRep_Builder aBuilder; BRep_Builder aBuilder;
aBuilder.MakeFace (aNewFace, aTris); aBuilder.MakeFace (aNewFace, aTris);
addSubShape (myLastGroupShape, aNewFace, Standard_True); addSubShape (myLastGroupShape, aNewFace, Standard_True);
myLastFaceMaterial = theMesh.Material;
if (myShapeReceiver != NULL) if (myShapeReceiver != NULL)
{ {
const RWObj_Material* aMaterial = myMaterials.Seek (theMesh.Material);
myShapeReceiver->BindNamedShape (aNewFace, "", aMaterial, Standard_False); myShapeReceiver->BindNamedShape (aNewFace, "", aMaterial, Standard_False);
} }
} }
@ -70,7 +75,11 @@ Standard_Boolean RWObj_TriangulationReader::addMesh (const RWObj_SubMesh& theMes
{ {
if (myShapeReceiver != NULL) if (myShapeReceiver != NULL)
{ {
myShapeReceiver->BindNamedShape (myLastGroupShape, theMesh.Group, myLastGroupShape.ShapeType() == TopAbs_FACE ? aMaterial : NULL, Standard_False); const RWObj_Material* aMaterial = myLastGroupShape.ShapeType() == TopAbs_FACE
&& !myLastFaceMaterial.IsEmpty()
? myMaterials.Seek (myLastFaceMaterial)
: NULL;
myShapeReceiver->BindNamedShape (myLastGroupShape, myLastGroupName, aMaterial, Standard_False);
} }
} }
myLastGroupShape = TopoDS_Shape(); myLastGroupShape = TopoDS_Shape();

View File

@ -117,6 +117,7 @@ protected:
TopoDS_Compound myLastObjectShape; //!< Compound containing current object groups TopoDS_Compound myLastObjectShape; //!< Compound containing current object groups
TopoDS_Shape myLastGroupShape; //!< current group shape - either a single Face or Compound of Faces TopoDS_Shape myLastGroupShape; //!< current group shape - either a single Face or Compound of Faces
TCollection_AsciiString myLastGroupName; //!< current group name TCollection_AsciiString myLastGroupName; //!< current group name
TCollection_AsciiString myLastFaceMaterial;//!< last face material name
Standard_Boolean myToCreateShapes; //!< create a single triangulation Standard_Boolean myToCreateShapes; //!< create a single triangulation
}; };