Allow reading VRML models for glTF export.
Note that some VRML 2.0 models fill fail until our patches are integrated into OCCT 7.9.0.
This commit is contained in:
parent
5e5741edd3
commit
8fd12d8b7e
|
@ -86,6 +86,7 @@ set( OCC_LIBS_POST_78
|
|||
TKDEGLTF
|
||||
TKDESTEP
|
||||
TKDESTL
|
||||
TKDEVRML
|
||||
)
|
||||
|
||||
set(OCC_TYPE "OpenCASCADE Standard Edition")
|
||||
|
|
|
@ -118,6 +118,7 @@
|
|||
#include <GC_MakeCircle.hxx>
|
||||
|
||||
#include <RWGltf_CafWriter.hxx>
|
||||
#include <VrmlAPI_CafReader.hxx>
|
||||
|
||||
#include <macros.h>
|
||||
|
||||
|
@ -592,6 +593,46 @@ static Standard_Boolean rescaleShapes( const TDF_Label& theLabel, const gp_XYZ&
|
|||
}
|
||||
|
||||
|
||||
// Sets names in assembly to <aPrefix> (<old name>), or to <aPrefix>
|
||||
static Standard_Boolean prefixNames( const TDF_Label& aLabel,
|
||||
const TCollection_ExtendedString& aPrefix )
|
||||
{
|
||||
Handle( KI_XCAFDoc_AssemblyGraph ) aG = new KI_XCAFDoc_AssemblyGraph( aLabel );
|
||||
|
||||
if( aG.IsNull() )
|
||||
{
|
||||
Message::SendFail( "Couldn't create assembly graph." );
|
||||
return Standard_False;
|
||||
}
|
||||
|
||||
Standard_Boolean anIsDone = Standard_True;
|
||||
|
||||
for( Standard_Integer idx = 1; idx <= aG->NbNodes(); idx++ )
|
||||
{
|
||||
const TDF_Label& lbl = aG->GetNode( idx );
|
||||
Handle( TDataStd_Name ) nameHandle;
|
||||
|
||||
if( lbl.FindAttribute( TDataStd_Name::GetID(), nameHandle ) )
|
||||
{
|
||||
TCollection_ExtendedString name;
|
||||
|
||||
name += aPrefix;
|
||||
name += " (";
|
||||
name += nameHandle->Get();
|
||||
name += ")";
|
||||
|
||||
TDataStd_Name::Set( lbl, name );
|
||||
}
|
||||
else
|
||||
{
|
||||
TDataStd_Name::Set( lbl, aPrefix );
|
||||
}
|
||||
}
|
||||
|
||||
return anIsDone;
|
||||
}
|
||||
|
||||
|
||||
STEP_PCB_MODEL::STEP_PCB_MODEL( const wxString& aPcbName )
|
||||
{
|
||||
m_app = XCAFApp_Application::GetApplication();
|
||||
|
@ -2436,7 +2477,22 @@ bool STEP_PCB_MODEL::getModelLabel( const std::string& aFileNameUTF8, VECTOR3D a
|
|||
}
|
||||
}
|
||||
|
||||
return false; // No replacement model found
|
||||
// VRML models only work when exporting to glTF
|
||||
// Also OCCT < 7.9.0 fail to load most VRML 2.0 models because of Switch nodes
|
||||
if( readVRML( doc, aFileNameUTF8.c_str() ) )
|
||||
{
|
||||
Handle( XCAFDoc_ShapeTool ) shapeTool =
|
||||
XCAFDoc_DocumentTool::ShapeTool( doc->Main() );
|
||||
|
||||
prefixNames( shapeTool->Label(),
|
||||
TCollection_ExtendedString( baseName.c_str().AsChar() ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
ReportMessage( wxString::Format( wxT( "readVRML() failed on filename '%s'.\n" ),
|
||||
fileName ) );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else // Substitution is not allowed
|
||||
{
|
||||
|
@ -2624,6 +2680,21 @@ bool STEP_PCB_MODEL::readSTEP( Handle( TDocStd_Document )& doc, const char* fnam
|
|||
}
|
||||
|
||||
|
||||
bool STEP_PCB_MODEL::readVRML( Handle( TDocStd_Document ) & doc, const char* fname )
|
||||
{
|
||||
VrmlAPI_CafReader reader;
|
||||
RWMesh_CoordinateSystemConverter conv;
|
||||
conv.SetInputLengthUnit( 2.54 );
|
||||
reader.SetCoordinateSystemConverter( conv );
|
||||
reader.SetDocument( doc );
|
||||
|
||||
if( !reader.Perform( TCollection_AsciiString( fname ), Message_ProgressRange() ) )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
TDF_Label STEP_PCB_MODEL::transferModel( Handle( TDocStd_Document ) & source,
|
||||
Handle( TDocStd_Document ) & dest, VECTOR3D aScale )
|
||||
{
|
||||
|
|
|
@ -223,8 +223,9 @@ private:
|
|||
bool getModelLocation( bool aBottom, VECTOR2D aPosition, double aRotation, VECTOR3D aOffset,
|
||||
VECTOR3D aOrientation, TopLoc_Location& aLocation );
|
||||
|
||||
bool readIGES( Handle( TDocStd_Document )& m_doc, const char* fname );
|
||||
bool readSTEP( Handle( TDocStd_Document )& m_doc, const char* fname );
|
||||
bool readIGES( Handle( TDocStd_Document ) & aDoc, const char* aFname );
|
||||
bool readSTEP( Handle( TDocStd_Document ) & aDoc, const char* aFname );
|
||||
bool readVRML( Handle( TDocStd_Document ) & aDoc, const char* aFname );
|
||||
|
||||
TDF_Label transferModel( Handle( TDocStd_Document )& source, Handle( TDocStd_Document ) & dest,
|
||||
VECTOR3D aScale );
|
||||
|
|
Loading…
Reference in New Issue