ObjectARX
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Brep "tutorial"

6 REPLIES 6
Reply
Message 1 of 7
Anonymous
1820 Views, 6 Replies

Brep "tutorial"

Hello everybody!

In the last days i often consulted this forum and now i want to give something back...

// AcBr used to generate mesh:
/////////////////////////////////////////////////////////////////////////////////////////////
//cast into Brep entity
AcBrEntity* pBrEnt = new AcBrBrep();
AcDbObjectIdArray objIdList;
AcDb::SubentType subType = AcDb::kNullSubentType;
AcDbFullSubentPath subPath;
AcDb3dSolid* pSolid = NULL;
AcBr::ErrorStatus returnValue = AcBr::eOk;


objIdList.append(ObjId);

if ((pSolid = AcDb3dSolid::cast(pObj)) != NULL)
{
subPath = kNullSubent;
subPath.objectIds() = objIdList;
}
returnValue = ((AcBrBrep*)pBrEnt)->set(subPath);
if (returnValue != AcBr::eOk)
{
acutPrintf(ACRX_T("\n Error in AcBrEntity::set:"));
acutPrintf(ACRX_T(" AutoCAD Error Code: %d\n"), returnValue);
delete pBrEnt;
return false;
}

acutPrintf(ACRX_T("\ncreated BrEnt\n"));
///////////////////////////////////////
// Make mesh control and MeshFilter(Entity and refinement) and then GENERATE mesh
AcBrMesh2dControl meshCtrl;
meshCtrl.setMinSubdivisionsInU();
meshCtrl.setMinSubdivisionsInV();
meshCtrl.setMaxSubdivisions();
meshCtrl.setMaxNodeSpacing();
meshCtrl.setAngTol(Winkelfehler * kDeg2Rad);
meshCtrl.setDistTol(0.8);
meshCtrl.setMaxAspectRatio(0);
meshCtrl.setElementShape(AcBr::kAllTriangles);

AcBrMesh2dFilter meshFilter;
meshFilter.insert(make_pair((const AcBrEntity*&) pBrEnt, (const AcBrMesh2dControl)meshCtrl));

AcBrMesh2d faceMesh;
if ((returnValue = faceMesh.generate(meshFilter)) != eOk) {
acutPrintf(ACRX_T("\n Error in AcBrMesh2d::generate:"));
acutPrintf(ACRX_T(" AutoCAD Error Code: %d\n"), returnValue);
}
/////////////////////////////////////////
// make a global element traverser
AcBrMesh2dElement2dTraverser meshElemTrav;
returnValue = meshElemTrav.setMesh(faceMesh);
if (returnValue != AcBr::eOk) {
acutPrintf(ACRX_T("\n Error in AcBrMesh2dElement2dTraverser::setMesh:"));
acutPrintf(ACRX_T(" AutoCAD Error Code: %d\n"), returnValue);
return false;
}
// traverse through the elements
while (!meshElemTrav.done() && (returnValue == AcBr::eOk) && !acedUsrBrk()) {
// convert the nodes into a 3d point array for AcDbPolyline
AcBrElement2dNodeTraverser elemNodeTrav;
returnValue = elemNodeTrav.setElement(meshElemTrav);
if (returnValue != AcBr::eOk) {
acutPrintf(ACRX_T("\n Error in AcBrElement2dNodeTraverser::setElement:"));
acutPrintf(ACRX_T(" AutoCAD Error Code: %d\n"), returnValue);
return false;
}
while (!elemNodeTrav.done() && (returnValue == AcBr::eOk)) {
AcBrNode node;
returnValue = elemNodeTrav.getNode(node);
if (returnValue != AcBr::eOk) {
acutPrintf(ACRX_T("\n Error in AcBrElement2dNodeTraverser::getNode:"));
acutPrintf(ACRX_T(" AutoCAD Error Code: %d\n"), returnValue);
return false;
}

// add the point from the patch to FEDaten
AcGePoint3d temp;
node.getPoint(temp);
FeDaten.Patches.append(FeDaten.AddPunkte(temp));
TEMPCOUNT++;

returnValue = elemNodeTrav.next();
if (returnValue != AcBr::eOk) {
acutPrintf(ACRX_T("\n Error in AcBrElement2dNodeTraverser::next:"));
acutPrintf(ACRX_T(" AutoCAD Error Code: %d\n"), returnValue);
return false;
}
} // end element while
returnValue = meshElemTrav.next();
if (returnValue != AcBr::eOk) {
acutPrintf(ACRX_T("\n Error in AcBrMesh2dElement2dTraverser::next:"));
acutPrintf(ACRX_T(" AutoCAD Error Code: %d\n"), returnValue);
return false;
}

} // end mesh while
delete pBrEnt;
////////////////////////////////////////////////////////////////////////////////////////////////

this is the code of a mesh generator in arx if you wonder how the "brmesh " function in the utils/brep/samples/ works, this is what you should try for your programm

PS: the ObjId and Wnkelfehler (angleerror) ar just a acdbobjectID and a double...
6 REPLIES 6
Message 2 of 7
Anonymous
in reply to: Anonymous

Thanks Mathias 🙂

I will give this a look and see how it works.

The next step is to have this function make an AcDbPolygonMesh or an AcDbPolyFaceMesh 🙂
Message 3 of 7
Anonymous
in reply to: Anonymous

Hey doug

I know you could use it 😉
I solved this step allready:

// add the point from the patch to FEDaten
AcGePoint3d temp;
node.getPoint(temp);
FeDaten.Patches.append(FeDaten.AddPunkte(temp));

you only need to add the temp Point to your structure (for example a AcWhateverMesh) It took a $/(/%$( long time to do that!

Next Step also mesh surfaces!!!
Message 4 of 7
Anonymous
in reply to: Anonymous

Yes, but how do you know which order to put the points into the mesh? For simple shapes it may be easy, but I think for complex ones just having the points, and not information on how they are organized, will make meshing tough.

Or maybe Ithere is something in your function which could handle this?

EDIT: for example imagine a small tube intersecting into the side of a larger tube...meshing this is not straightforward like meshing a sphere...and i mean a *complete* mesh, like the two in AcDb, not just individual triangular faces. Message was edited by: dougk16
Message 5 of 7
Anonymous
in reply to: Anonymous

hmm when there are intersecting each otherthis two solid's become one AcDb3dSolid so there are one ot not? So you allways mesh the whole solid no matter of complexity! I tried it even for on "NURB Surface builded solids" coming from Pro E.

It hink you should get into the traverser thing!! First you iterate each POLYGON then ech NODE( acge3dPoint) so you become each point of the mesh! you can easily draw them now( i have a own custom entity for that purpose, but in the end Its just a Array of Triangles!!)

hope this helps
Message 6 of 7
Anonymous
in reply to: Anonymous

I want to create triangle strip in C++ for AutoCAD.

need help.

how to do it.

Message 7 of 7
Anonymous
in reply to: Anonymous

Does anybody get a crash here:

 

faceMesh.generate(meshFilter))

 

I've tried different ways to create AcBrBrep entities - by directly setting 3dSolid entity, by using SubentPath like in this example, by getting solid data usgin ASMBodyCopy and setting to newly created AcDbBody. But I'm always getting exception during attempt to generate AcBrMesh2d....

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost