Wed, 01/13/2021 - 18:47
Hi,
Im preparing small app converting IGES to VRML. Process consist:
-opening IGES file,
-creating TDocStd_Document,
-meshing all shapes in document,
-writing mesh to WRL file.
Application works as intended, with one small exception. When I use test files from FreeCAD (eg. containing cylinder) output WRL cylinder mesh imported to FreeCAD as desired is smooth on the side and flat on both caps. When using IGES file from other software (MicroStation) output mesh imported to FreeCAD is flat shaded everywhere. Is there any way to set smooth edges according to face angle value during shape meshing or VRML writing process ?
Regards
Adam
Wed, 01/13/2021 - 19:09
Any screenshots / test models in IGES and VRML formats / code snippets to look at and suggest what could be wrong?
Wed, 01/13/2021 - 22:44
App reads IGES file and saves each shape to separate VRML file. Platform: Linux(Ubuntu) OpenCascade v7.3.0
Reade Setup:
IGESCAFControl_Reader reader;
reader.SetColorMode(colorsFlag);//true
reader.SetLayerMode(layersFlag);//false
reader.SetNameMode(namesFlag);//true
Handle(TDocStd_Document) doc= new TDocStd_Document("MDTV-Standard");
IFSelect_ReturnStatus status=reader.ReadFile(aFilePath.ToCString());
Shape processing:
for(int element=1;element<=shapeLabels.Length();element++){
TopoDS_Shape shape;
const TDF_Label& label=shapeLabels.Value(element);
XCAFDoc_DocumentTool::ShapeTool (doc->Main())->GetShape(label,shape);
string fileOut=destPath+separator()+prefix+"_"+to_string(element)+".wrl";
procesThread(shape,fileOut);
}
Meshing:
void FileConverter::shapeToMesh(TopoDS_Shape& shape)
{
BRepMesh_IncrementalMesh mesher(shape, linearDeflection, Standard_False, angularDeflection);
mesher.Perform();
}
VRML write :
bool FileConverter::writeShapeToVRML(TopoDS_Shape &shape, const TCollection_AsciiString &destinationPath)
{
TopoDS_Compound res;
BRep_Builder builder;
VrmlAPI_Writer writer;
builder.MakeCompound( res );
if(!shape.IsNull()){
builder.Add(res,shape);
writer.Write(res,destinationPath.ToCString());
return true;
}else{
return false;
}
}
Sceens:
FreeCad Iges:
https://photos.app.goo.gl/46t7BzPgsodyXnw8A
FreeCad VRML:
https://photos.app.goo.gl/s3fLLkjnNbN2PzPE6
MicroStation iges:
https://photos.app.goo.gl/WiTiV1aqNiN5axJ6A
Microstation VRML rounded caps:
https://photos.app.goo.gl/zYT7aTAzALTcGfkg7
As you can see rounded cylinder caps are smooth shaded. cylinder side is not.
Microsation VRML flat caps:
https://photos.app.goo.gl/bo3fBHqBe5MvAfir7
Regards
Adam
Wed, 01/13/2021 - 23:30
App reads IGES file and saves each shape to separate VRML file. Platform: Linux(Ubuntu) OpenCascade v7.3.0
Reade Setup:
IGESCAFControl_Reader reader;
reader.SetColorMode(colorsFlag);//true
reader.SetLayerMode(layersFlag);//false
reader.SetNameMode(namesFlag);//true
Handle(TDocStd_Document) doc= new TDocStd_Document("MDTV-Standard");
IFSelect_ReturnStatus status=reader.ReadFile(aFilePath.ToCString());
Shape processing:
for(int element=1;element<=shapeLabels.Length();element++){
TopoDS_Shape shape;
const TDF_Label& label=shapeLabels.Value(element);
XCAFDoc_DocumentTool::ShapeTool (doc->Main())->GetShape(label,shape);
string fileOut=destPath+separator()+prefix+"_"+to_string(element)+".wrl";
procesThread(shape,fileOut);
}
Meshing:
void FileConverter::shapeToMesh(TopoDS_Shape& shape)
{
BRepMesh_IncrementalMesh mesher(shape, linearDeflection, Standard_False, angularDeflection);
mesher.Perform();
}
VRML write :
bool FileConverter::writeShapeToVRML(TopoDS_Shape &shape, const TCollection_AsciiString &destinationPath)
{
TopoDS_Compound res;
BRep_Builder builder;
VrmlAPI_Writer writer;
builder.MakeCompound( res );
if(!shape.IsNull()){
builder.Add(res,shape);
writer.Write(res,destinationPath.ToCString());
return true;
}else{
return false;
}
}
Sceens:
FreeCad Iges:
https://photos.app.goo.gl/46t7BzPgsodyXnw8A
FreeCad VRML:
https://photos.app.goo.gl/s3fLLkjnNbN2PzPE6
MicroStation iges:
https://photos.app.goo.gl/WiTiV1aqNiN5axJ6A
Microstation VRML rounded caps:
https://photos.app.goo.gl/zYT7aTAzALTcGfkg7
As you can see rounded cylinder caps are smooth shaded. cylinder side is not.
Microsation VRML flat caps:
https://photos.app.goo.gl/bo3fBHqBe5MvAfir7
Regards
Adam
Thu, 01/14/2021 - 12:23
App reads IGES file and saves each shape to separate VRML file. Platform: Linux(Ubuntu) OpenCascade v7.3.0
Reader Setup:
IGESCAFControl_Reader reader;
reader.SetColorMode(colorsFlag);//true
reader.SetLayerMode(layersFlag);//false
reader.SetNameMode(namesFlag);//true
Handle(TDocStd_Document) doc= new TDocStd_Document("MDTV-Standard");
IFSelect_ReturnStatus status=reader.ReadFile(aFilePath.ToCString());
Shape processing:
for(int element=1;element<=shapeLabels.Length();element++){
TopoDS_Shape shape;
const TDF_Label& label=shapeLabels.Value(element);
XCAFDoc_DocumentTool::ShapeTool (doc->Main())->GetShape(label,shape);
string fileOut=destPath+separator()+prefix+"_"+to_string(element)+".wrl";
procesThread(shape,fileOut);
}
Meshing:
void FileConverter::shapeToMesh(TopoDS_Shape& shape)
{
BRepMesh_IncrementalMesh mesher(shape, linearDeflection, Standard_False, angularDeflection);//linearDeflection=0.5;angularDeflection=15
mesher.Perform();
}
VRML write :
bool FileConverter::writeShapeToVRML(TopoDS_Shape &shape, const TCollection_AsciiString &destinationPath)
{
TopoDS_Compound res;
BRep_Builder builder;
VrmlAPI_Writer writer;
builder.MakeCompound( res );
if(!shape.IsNull()){
builder.Add(res,shape);
writer.Write(res,destinationPath.ToCString());
return true;
}else{
return false;
}
}
Regards
Adam
Wed, 01/13/2021 - 22:16
Hi. code splits each iges shape to separate VRML file. Platform linux (Ubuntu) opencascade version 7.3.0
iges reader setup:
IGESCAFControl_Reader reader;
reader.SetColorMode(colorsFlag);//true
reader.SetLayerMode(layersFlag);//false
reader.SetNameMode(namesFlag);//true
const TCollection_ExtendedString storageFormat="MDTV-Standard";
Handle(TDocStd_Document) doc= new TDocStd_Document(storageFormat);
IFSelect_ReturnStatus status=reader.ReadFile(aFilePath.ToCString());
Processing each shape:
for(int element=1;element<=shapeLabels.Length();element++){
TopoDS_Shape shape;
const TDF_Label& label=shapeLabels.Value(element);
XCAFDoc_DocumentTool::ShapeTool (doc->Main())->GetShape(label,shape);
string fileOut=destPath+separator()+prefix+"_"+to_string(element)+".wrl";
procesThread(shape,fileOut);
}
meshing shape:
void FileConverter::shapeToMesh(TopoDS_Shape& shape)
{
//linearDeflection=2;
//angularDeflection=15
BRepMesh_IncrementalMesh mesher(shape, linearDeflection, Standard_False, angularDeflection);
mesher.Perform();
}
Save VRML:
bool FileConverter::writeShapeToVRML(TopoDS_Shape &shape, const TCollection_AsciiString &destinationPath)
{
TopoDS_Compound res;
BRep_Builder builder;
VrmlAPI_Writer writer;
builder.MakeCompound( res );
if(!shape.IsNull()){
builder.Add(res,shape);
writer.Write(res,destinationPath.ToCString());
return true;
}else{
return false;
}
}
FreeCad Iges screen:
https://photos.app.goo.gl/JsRLiKrrvoP7r5r86
FreeCad VRML screen:
https://photos.app.goo.gl/RRrsaUZS8QYRaLBa9
Microstation Iges screen:
https://photos.app.goo.gl/SwB4zzTLLP1gVCm29
Microstation VRML screen:
https://photos.app.goo.gl/5y96rSgk6V7Kyhi56
Thu, 01/14/2021 - 09:04
App reads IGES file and saves each shape to separate VRML file. Platform: Linux(Ubuntu) OpenCascade v7.3.0
Reade Setup:
IGESCAFControl_Reader reader;
reader.SetColorMode(colorsFlag);//true
reader.SetLayerMode(layersFlag);//false
reader.SetNameMode(namesFlag);//true
Handle(TDocStd_Document) doc= new TDocStd_Document("MDTV-Standard");
IFSelect_ReturnStatus status=reader.ReadFile(aFilePath.ToCString());
Shape processing:
for(int element=1;element<=shapeLabels.Length();element++){
TopoDS_Shape shape;
const TDF_Label& label=shapeLabels.Value(element);
XCAFDoc_DocumentTool::ShapeTool (doc->Main())->GetShape(label,shape);
string fileOut=destPath+separator()+prefix+"_"+to_string(element)+".wrl";
procesThread(shape,fileOut);
}
Meshing:
void FileConverter::shapeToMesh(TopoDS_Shape& shape)
{
BRepMesh_IncrementalMesh mesher(shape, linearDeflection, Standard_False, angularDeflection);
mesher.Perform();
}
VRML write :
bool FileConverter::writeShapeToVRML(TopoDS_Shape &shape, const TCollection_AsciiString &destinationPath)
{
TopoDS_Compound res;
BRep_Builder builder;
VrmlAPI_Writer writer;
builder.MakeCompound( res );
if(!shape.IsNull()){
builder.Add(res,shape);
writer.Write(res,destinationPath.ToCString());
return true;
}else{
return false;
}
}
Sceens:
FreeCad Iges:
https://photos.app.goo.gl/46t7BzPgsodyXnw8A
FreeCad VRML:
https://photos.app.goo.gl/s3fLLkjnNbN2PzPE6
MicroStation iges:
https://photos.app.goo.gl/WiTiV1aqNiN5axJ6A
Microstation VRML rounded caps:
https://photos.app.goo.gl/zYT7aTAzALTcGfkg7
As you can see rounded cylinder caps are smooth shaded. cylinder side is not.
Microsation VRML flat caps:
https://photos.app.goo.gl/bo3fBHqBe5MvAfir7
Regards
Adam
Thu, 01/14/2021 - 12:18
For some reason I cant submit my reply
Regards
Adam
Thu, 01/14/2021 - 16:19
Hi.
I have one more question regarding meshing shapes and write them toVRML format.
VrmlAPI_Wrier creates wrl file with default material definition:
Shape {
appearance DEF __defaultMaterialFace Appearance {
material Material {
ambientIntensity 1
diffuseColor 0.780392 0.568627 0.113725
emissiveColor 0.329412 0.223529 0.027451
shininess 0.022
specularColor 0.992157 0.941176 0.807843
}
}
Where in OpenCascade can I find methods to change This default material parameters?
Thanks in advance
Adam
Thu, 01/14/2021 - 16:27
You may just grep "__defaultMaterialFace" in OCCT source code to find where it is defined. I'm not familiar with VRML writer API though to say if/how it can be overridden.
Fri, 01/15/2021 - 04:09
Thanks for help. I red through source code and finally to get my own material written as default I had to subclass VrmlAPI_Writer. Still don't know why some meshes shading is solid not smooth.
Regards
Adam