1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-09 13:22:24 +03:00

0029902: Data Exchange, XCAF - provide extended Material definition for visualization purposes

Introduced new attribute XCAFDoc_VisMaterial storing visualization material definition.

XCAFPrs_Style has been exteneded Material() property.
XCAFPrs_AISObject::DispatchStyles() maps new XCAFPrs_Style::Material() property onto graphics aspects.

RWGltf_GltfJsonParser and RWObj_CafReader now put Material definition into XCAF document instead of a color label.
RWGltf_MaterialMetallicRoughness - added missing properties AlphaMode, AlphaCutOff and IsDoubleSided;
fixed default values in constructor for Metallic and Roughness.

Added commands XGetAllVisMaterials, XGetVisMaterial, XAddVisMaterial,
XRemoveVisMaterial, XSetVisMaterial, XUnsetVisMaterial for working with
new visualization materials table in the document.
This commit is contained in:
kgv
2019-07-03 11:28:26 +03:00
committed by apn
parent ba00aab7a0
commit a4815d5509
49 changed files with 3252 additions and 256 deletions

View File

@@ -1,6 +1,7 @@
RWGltf_GltfAccessor.hxx
RWGltf_GltfAccessorCompType.hxx
RWGltf_GltfAccessorLayout.hxx
RWGltf_GltfAlphaMode.hxx
RWGltf_GltfArrayType.hxx
RWGltf_GltfBufferView.hxx
RWGltf_GltfBufferViewTarget.hxx

View File

@@ -0,0 +1,46 @@
// Author: Kirill Gavrilov
// Copyright (c) 2019 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef _RWGltf_GltfAlphaMode_HeaderFile
#define _RWGltf_GltfAlphaMode_HeaderFile
#include <Standard_CString.hxx>
//! Low-level glTF enumeration defining Alpha Mode.
enum RWGltf_GltfAlphaMode
{
RWGltf_GltfAlphaMode_Opaque, //!< alpha value is ignored and the rendered output is fully opaque
RWGltf_GltfAlphaMode_Mask, //!< rendered output is either fully opaque or fully transparent depending on the alpha value and the specified alpha cutoff value
RWGltf_GltfAlphaMode_Blend, //!< alpha value is used to composite the source and destination areas
};
//! Parse RWGltf_GltfAlphaMode from string.
inline RWGltf_GltfAlphaMode RWGltf_GltfParseAlphaMode (const char* theType)
{
if (IsEqual ("OPAQUE", theType))
{
return RWGltf_GltfAlphaMode_Opaque;
}
else if (IsEqual ("MASK", theType))
{
return RWGltf_GltfAlphaMode_Mask;
}
else if (IsEqual ("BLEND", theType))
{
return RWGltf_GltfAlphaMode_Blend;
}
return RWGltf_GltfAlphaMode_Opaque;
}
#endif // _RWGltf_GltfAlphaMode_HeaderFile

View File

@@ -308,6 +308,7 @@ void RWGltf_GltfJsonParser::gltfParseMaterials()
}
aMat->Id = aMatId.GetString();
myMaterialsCommon.Bind (aMat->Id, aMat);
gltfBindMaterial (Handle(RWGltf_MaterialMetallicRoughness)(), aMat);
}
}
else if (aMatList->IsArray())
@@ -342,10 +343,98 @@ void RWGltf_GltfJsonParser::gltfParseMaterials()
aMatCommon->Id = TCollection_AsciiString ("mat_") + aMatIndex;
myMaterialsCommon.Bind (TCollection_AsciiString (aMatIndex), aMatCommon);
}
gltfBindMaterial (aMatPbr, aMatCommon);
}
}
}
// =======================================================================
// function : gltfBindMaterial
// purpose :
// =======================================================================
void RWGltf_GltfJsonParser::gltfBindMaterial (const Handle(RWGltf_MaterialMetallicRoughness)& theMatPbr,
const Handle(RWGltf_MaterialCommon)& theMatCommon)
{
if (theMatPbr.IsNull()
&& theMatCommon.IsNull())
{
return;
}
Handle(XCAFDoc_VisMaterial) aMat = new XCAFDoc_VisMaterial();
if (!theMatCommon.IsNull())
{
XCAFDoc_VisMaterialCommon aMatXde;
aMatXde.IsDefined = true;
aMatXde.AmbientColor = theMatCommon->AmbientColor;
aMatXde.DiffuseColor = theMatCommon->DiffuseColor;
aMatXde.SpecularColor = theMatCommon->SpecularColor;
aMatXde.EmissiveColor = theMatCommon->EmissiveColor;
aMatXde.Shininess = theMatCommon->Shininess;
aMatXde.Transparency = theMatCommon->Transparency;
aMatXde.DiffuseTexture = theMatCommon->DiffuseTexture;
if (aMatXde.DiffuseTexture.IsNull()
&& !theMatCommon->AmbientTexture.IsNull())
{
aMatXde.DiffuseTexture = theMatCommon->AmbientTexture;
}
aMat->SetCommonMaterial (aMatXde);
if (!theMatCommon->Name.IsEmpty())
{
aMat->SetRawName (new TCollection_HAsciiString (theMatCommon->Name));
}
}
if (!theMatPbr.IsNull())
{
XCAFDoc_VisMaterialPBR aMatXde;
aMatXde.IsDefined = true;
aMatXde.MetallicRoughnessTexture = theMatPbr->MetallicRoughnessTexture;
aMatXde.BaseColorTexture = theMatPbr->BaseColorTexture;
aMatXde.EmissiveTexture = theMatPbr->EmissiveTexture;
aMatXde.OcclusionTexture = theMatPbr->OcclusionTexture;
aMatXde.NormalTexture = theMatPbr->NormalTexture;
aMatXde.BaseColor = theMatPbr->BaseColor;
aMatXde.EmissiveFactor = theMatPbr->EmissiveFactor;
aMatXde.Metallic = theMatPbr->Metallic;
aMatXde.Roughness = theMatPbr->Roughness;
aMat->SetPbrMaterial (aMatXde);
Graphic3d_AlphaMode anAlphaMode = Graphic3d_AlphaMode_BlendAuto;
switch (theMatPbr->AlphaMode)
{
case RWGltf_GltfAlphaMode_Opaque:
{
anAlphaMode = Graphic3d_AlphaMode_Opaque;
if (aMatXde.BaseColor.Alpha() < 1.0f)
{
Message::DefaultMessenger()->Send ("glTF reader - material with non-zero Transparency specifies Opaque AlphaMode", Message_Warning);
}
break;
}
case RWGltf_GltfAlphaMode_Mask:
{
anAlphaMode = Graphic3d_AlphaMode_Mask;
break;
}
case RWGltf_GltfAlphaMode_Blend:
{
anAlphaMode = Graphic3d_AlphaMode_Blend;
break;
}
}
aMat->SetAlphaMode (anAlphaMode, theMatPbr->AlphaCutOff);
aMat->SetDoubleSided (theMatPbr->IsDoubleSided);
if (!theMatPbr->Name.IsEmpty())
{
aMat->SetRawName (new TCollection_HAsciiString (theMatPbr->Name));
}
}
myMaterials.Bind (!theMatPbr.IsNull() ? theMatPbr->Id : theMatCommon->Id, aMat);
}
// =======================================================================
// function : gltfParseStdMaterial
// purpose :
@@ -450,6 +539,9 @@ bool RWGltf_GltfJsonParser::gltfParsePbrMaterial (Handle(RWGltf_MaterialMetallic
const RWGltf_JsonValue* anEmissFactorVal = findObjectMember (theMatNode, "emissiveFactor");
const RWGltf_JsonValue* anEmissTexVal = findObjectMember (theMatNode, "emissiveTexture");
const RWGltf_JsonValue* anOcclusionTexVal = findObjectMember (theMatNode, "occlusionTexture");
const RWGltf_JsonValue* aDoubleSidedVal = findObjectMember (theMatNode, "doubleSided");
const RWGltf_JsonValue* anAlphaModeVal = findObjectMember (theMatNode, "alphaMode");
const RWGltf_JsonValue* anAlphaCutoffVal = findObjectMember (theMatNode, "alphaCutoff");
if (aMetalRoughVal == NULL)
{
return false;
@@ -462,6 +554,22 @@ bool RWGltf_GltfJsonParser::gltfParsePbrMaterial (Handle(RWGltf_MaterialMetallic
const RWGltf_JsonValue* aRoughnessFactorVal = findObjectMember (*aMetalRoughVal, "roughnessFactor");
const RWGltf_JsonValue* aMetalRoughTexVal = findObjectMember (*aMetalRoughVal, "metallicRoughnessTexture");
if (aDoubleSidedVal != NULL
&& aDoubleSidedVal->IsBool())
{
theMat->IsDoubleSided = aDoubleSidedVal->GetBool();
}
if (anAlphaCutoffVal != NULL
&& anAlphaCutoffVal->IsNumber())
{
theMat->AlphaCutOff = (float )anAlphaCutoffVal->GetDouble();
}
if (anAlphaModeVal != NULL
&& anAlphaModeVal->IsString())
{
theMat->AlphaMode = RWGltf_GltfParseAlphaMode (anAlphaModeVal->GetString());
}
if (aBaseColorTexVal != NULL
&& aBaseColorTexVal->IsObject())
{
@@ -1116,7 +1224,14 @@ bool RWGltf_GltfJsonParser::gltfParseMesh (TopoDS_Shape& theMeshShape,
{
RWMesh_NodeAttributes aShapeAttribs;
aShapeAttribs.RawName = aUserName;
aShapeAttribs.Style.SetColorSurf (aMeshData->BaseColor());
// assign material and not color
//aShapeAttribs.Style.SetColorSurf (aMeshData->BaseColor());
Handle(XCAFDoc_VisMaterial) aMat;
myMaterials.Find (!aMeshData->MaterialPbr().IsNull() ? aMeshData->MaterialPbr()->Id : aMeshData->MaterialCommon()->Id, aMat);
aShapeAttribs.Style.SetMaterial (aMat);
myAttribMap->Bind (aFace, aShapeAttribs);
}
myFaceList.Append (aFace);
@@ -1586,7 +1701,12 @@ void RWGltf_GltfJsonParser::bindNamedShape (TopoDS_Shape& theShape,
{
if (aLateData->HasStyle())
{
aShapeAttribs.Style.SetColorSurf (aLateData->BaseColor());
// assign material and not color
//aShapeAttribs.Style.SetColorSurf (aLateData->BaseColor());
Handle(XCAFDoc_VisMaterial) aMat;
myMaterials.Find (!aLateData->MaterialPbr().IsNull() ? aLateData->MaterialPbr()->Id : aLateData->MaterialCommon()->Id, aMat);
aShapeAttribs.Style.SetMaterial (aMat);
}
if (aShapeAttribs.Name.IsEmpty()
&& myUseMeshNameAsFallback)

View File

@@ -150,6 +150,10 @@ protected:
Standard_EXPORT bool gltfParseTexture (Handle(Image_Texture)& theTexture,
const RWGltf_JsonValue* theTextureId);
//! Bind material definition to the map.
Standard_EXPORT void gltfBindMaterial (const Handle(RWGltf_MaterialMetallicRoughness)& theMatPbr,
const Handle(RWGltf_MaterialCommon)& theMatCommon);
protected:
//! Parse scene array of nodes recursively.
@@ -397,6 +401,7 @@ protected:
NCollection_DataMap<TCollection_AsciiString, Handle(RWGltf_MaterialMetallicRoughness)> myMaterialsPbr;
NCollection_DataMap<TCollection_AsciiString, Handle(RWGltf_MaterialCommon)> myMaterialsCommon;
NCollection_DataMap<TCollection_AsciiString, Handle(XCAFDoc_VisMaterial)> myMaterials;
NCollection_DataMap<TCollection_AsciiString, TopoDS_Shape> myShapeMap[2];
NCollection_DataMap<TCollection_AsciiString, bool> myProbedFiles;

View File

@@ -17,6 +17,7 @@
#include <Graphic3d_Vec.hxx>
#include <Quantity_ColorRGBA.hxx>
#include <RWGltf_GltfAlphaMode.hxx>
#include <Standard_Transient.hxx>
#include <TCollection_AsciiString.hxx>
@@ -38,12 +39,18 @@ public:
Graphic3d_Vec3 EmissiveFactor; //!< emissive color; [0.0, 0.0, 0.0] by default
Standard_ShortReal Metallic; //!< metalness (or scale factor to the texture) within range [0.0, 1.0]; 1.0 by default
Standard_ShortReal Roughness; //!< roughness (or scale factor to the texture) within range [0.0, 1.0]; 1.0 by default
Standard_ShortReal AlphaCutOff; //!< alpha cutoff value; 0.5 by default
RWGltf_GltfAlphaMode AlphaMode; //!< alpha mode; RWGltf_GltfAlphaMode_Opaque by default
Standard_Boolean IsDoubleSided; //!< specifies whether the material is double sided; FALSE by default
RWGltf_MaterialMetallicRoughness()
RWGltf_MaterialMetallicRoughness()
: BaseColor (1.0f, 1.0f, 1.0f, 1.0f),
EmissiveFactor (0.0f, 0.0f, 0.0f),
Metallic (0.0f),
Roughness (0.0f) {}
Metallic (1.0f),
Roughness (1.0f),
AlphaCutOff (0.5f),
AlphaMode (RWGltf_GltfAlphaMode_Opaque),
IsDoubleSided (Standard_False) {}
};