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

urgent! please help, custom object hiding problem

10 REPLIES 10
Reply
Message 1 of 11
hyperandey
449 Views, 10 Replies

urgent! please help, custom object hiding problem

I use ObjectARX to create a custom object. It is 3D shell structure with several space surfaces. I set different colors for these surfaces. When changing side view or some views other than plane, parts of some surface should not be visible because they fall in other side of the view. But actively these parts are still visible in my program. They are not hidden by the surfaces in front of them. Any ideas about this problem would be appreciated. Currently, I use shell() to draw the surface in worldDraw. Do I need setup some parameters for AcGiViewportDraw in order to hide those surface behind the front surface? As I need display the colors on these surfaces, if I use the shade/hide mode, it may solve this problem but the colors on the surface will disappear. This is not what I want.
10 REPLIES 10
Message 2 of 11
amiltonf
in reply to: hyperandey

If you post the code I'll see if I can help you.

Regards,
Andy F.
Message 3 of 11
hyperandey
in reply to: hyperandey

Hi Andy, Thanks for your reply. Here are the codes:

[code]
Adesk::Boolean FEMRegion::worldDraw(AcGiWorldDraw* mode)
{
assertReadEnabled();
if(GLOBAL_VARS[FEM_SHOW_REGIONS] != 1.0)
return Adesk::kTrue;
AcGePoint3d mPts[4];
const Adesk::UInt32 numVerts = 4;
short oldColor = mode->subEntityTraits().color();
AcGiFillType oldFill = mode->subEntityTraits().fillType();
GeneralDict* pDict;
if(!get_general_dictionary(pDict, AcDb::kForRead, database()))
return false;
static Adesk::Int32 faceList[] = {4,0,1,2,3};
const Adesk::UInt32 faceListLength = 5;
Adesk::UInt8 pFaceVis[1];
AcGiEdgeData edgeData;
AcGiFaceData faceData;
short colors[4];
short colorface[1];
for(int i=0; i {
mPts[0] = mPts[3] = mNodes[mElements.mNodes[0]].mPoint;
mPts[1] = mNodes[mElements.mNodes[1]].mPoint;
mPts[2] = mNodes[mElements.mNodes[2]].mPoint;
if(pDict->getDisplayMode() == DM_ELEMENT_STRESS &&
mElements.mStressSet)
{
mode->subEntityTraits().setColor(pDict->getStressColor(mElements.mStress, DM_ELEMENT_STRESS));
mode->subEntityTraits().setFillType(kAcGiFillAlways);
colors[0] = colors[1] = colors[2] = colors[3] = pDict->getStressColor(mElements.mStress, DM_ELEMENT_STRESS);
edgeData.setColors(colors); //shell
colorface[0] = pDict->getStressColor(mElements.mStress,
DM_ELEMENT_STRESS);//shell
faceData.setColors(colorface);//shell
mode->geometry().shell(numVerts, mPts, faceListLength,faceList, &edgeData, &faceData);
mode->subEntityTraits().setColor(250);
mode->subEntityTraits().setFillType(kAcGiFillNever);
colors[0] = colors[1] = colors[2] = colors[3] = 250; //shell
edgeData.setColors(colors); //shell
colorface[0] = 250; //shell
faceData.setColors(colorface);//shell
mode->geometry().shell(numVerts, mPts, faceListLength,faceList, &edgeData, &faceData);
}
else if(pDict->getDisplayMode() == DM_ELEMENT_ANGLE && mElements.mElementAngleSet)
{
mode->subEntityTraits().setColor(pDict->getStressColor(mElements.mElementAngle, DM_ELEMENT_ANGLE));
mode->subEntityTraits().setFillType(kAcGiFillAlways);
colors[0] = colors[1] = colors[2] = colors[3] = pDict->getStressColor(mElements.mElementAngle, DM_ELEMENT_ANGLE);
edgeData.setColors(colors); //shell
colorface[0] = pDict->getStressColor(mElements.mElementAngle, DM_ELEMENT_ANGLE);//shell
faceData.setColors(colorface);//shell
mode->geometry().shell(numVerts, mPts, faceListLength,faceList, &edgeData, &faceData);
mode->subEntityTraits().setColor(250);
mode->subEntityTraits().setFillType(kAcGiFillNever);
colors[0] = colors[1] = colors[2] = colors[3] = 250; //shell
edgeData.setColors(colors); //shell
colorface[0] = 250; //shell
faceData.setColors(colorface);//shell
mode->geometry().shell(numVerts, mPts, faceListLength,faceList, &edgeData, &faceData);
}
else if(mElements.mWCSet)
{
mode->subEntityTraits().setColor(10 + ((short)((mElements.mWC)*8))*10);
mode->subEntityTraits().setFillType(kAcGiFillAlways);
colors[0] = colors[1] = colors[2] = colors[3] = 10 + ((short)((mElements.mWC)*8))*10;
edgeData.setColors(colors); //shell
colorface[0] = 10 + ((short)((mElements.mWC)*8))*10; //shell
faceData.setColors(colorface);//shell
mode->geometry().shell(numVerts, mPts, faceListLength,faceList, &edgeData, &faceData);
}
else
{
mode->subEntityTraits().setColor(GetRegionColor(getFEMNumber()));
mode->geometry().polyline(4, mPts);
}
}
pDict->close();
mode->subEntityTraits().setColor(oldColor);
mode->subEntityTraits().setFillType(oldFill);
return Adesk::kFalse;
}

void FEMRegion::viewportDraw(AcGiViewportDraw* pVpDraw)
{
assertReadEnabled();
AcDbObjectIdArray AllRegionIds;
TNTNumberDict* pDict;
if(!get_numbering_dictionary(pDict, AcDb::kForRead, database()))
return;
pDict->getAllFEMObjects(AllRegionIds, FT_REGION);
pDict->close();
long elementOffset = 0;
for(int i=0; i< AllRegionIds.length(); ++i)
{
if(AllRegionIds == objectId())
break;
AcDbObjectPointer pRegion(AllRegionIds, AcDb::kForRead);
if(pRegion.openStatus() == Acad::eOk)
{
elementOffset += pRegion->getElementCount();
}
}
if(GLOBAL_VARS[FEM_SHOW_ELEMENT_NUMBERS])
{
for(int i=0; i {
AcGeVector3d ViewDir = pVpDraw->viewport().viewDir();
AcGeVector3d UpVector;
pVpDraw->viewport().getCameraUpVector(UpVector);
AcGeVector3d SideVec = UpVector.crossProduct(ViewDir).normal();
double numberSize = GLOBAL_VARS[TNT_NUMBER_SIZE];
AcGePoint2d PixelPerUnit;
pVpDraw->viewport().getNumPixelsInUnitSquare(position(),PixelPerUnit);
{
numberSize = numberSize/PixelPerUnit[0];
}
AcGePoint3d pt = mNodes[mElements.mNodes[0]].mPoint + mNodes[mElements.mNodes[1]].mPoint.asVector() + mNodes[mElements.mNodes[2]].mPoint.asVector();
pt = pt/3.0;
char string[32];
sprintf(string, "%d", elementOffset + i+1);
pVpDraw->geometry().text(pt + (numberSize)*SideVec - (numberSize/2)UpVector,ViewDir,SideVec,numberSize,1.0,0.0,string);
}
}
}
[/code]

FEMRegion is custom object. Attachment is the picture showing hiding problem. Message was edited by: hyperandey
Message 4 of 11
amiltonf
in reply to: hyperandey

If the big "Z" in the bmp is part of the ucs icon then am I correct in assuming your custom object is very small?

At first glance your code looks fine and, if the object is very small, I suspect you're running into a Z-buffer resolution issue within Acad itself. AFAIK there's not much you can do about it short of writing your own hiding code which is a big pain in the neck.

Regards,
Andy F.
Message 5 of 11
hyperandey
in reply to: hyperandey

Hi Andy, thanks for your reply. Actively the big "Z" is the scale of coordinate. As the hidden parts of surface have many very smaller elements, it is quiet likely as you said, it is due to Z-buffer resolution. In fact the top surface and side surface is meshed into many elements which are drawn by shell function. From the attached picture, you can see some big elements are visible but some smaller elements are hidden. Could you explain a little bit more about Z-buffer resolution? How can I solve this problem?
Message 6 of 11
OysteinW
in reply to: hyperandey

Hi hyperandey.

Impressive triangulation-routine you've got there!

I'm struggeling a bit with my own triangulation routine, which I'm going to use in a terrain model... I have currently implemented a Delauney-triangulation routine, which works on a point-group, but would like to add breaklines and non-convex boundaries..
I see you have all that in your model.

Is there some theory and/or code-samples somewhere that you could point me to?

Best regards,
OysteinW.
Message 7 of 11
amiltonf
in reply to: hyperandey

Well, I'm not positive about the Z-buffer resolution issue but from what I've noticed in my own programming it appears that Acad's graphic system only resolves the Z-buffer using 32-bits so when you get down to very small fractions on the vector pointing directly into the screen (the eye Z-axis) Acad can't tell if one object is behind another and just draws the first thing it comes across which is often the parts that are supposed to be hidden. The problem is solvable though since the ARX geometry API is mostly 64-bit and you can write your own hiding routines using objects and functions available through viewportDraw. For me this was very time consuming as I have a hard time with lower level geometry code, but I know for sure that it is do-able.

One thing you might want to check before you jump into hiding them yourself is the Graphic System Options Dialog just to be sure Acad isn't set to use the video card's on-board processing. I can't remember the specific setting and I'm not on the machine that has Acad installed but when you find the correct dialog it's a check box in the lower right quadrant. I've found that the on-board video processing has a lower bit-depth for Z-buffer processing but have only tested it out on the other end of the extreme (very very large objects) so I only suspect that it goes the other way too (very small objects).

Still, though, with very small objects I've run into the same problem you're having and had to spend weeks learning how to use device and eye coords to be able to write my own hiding code which was never CPU efficient enough for satisfaction and was eventually scrapped.

The workaround I'm using currently is to make the object translucent through the use of materials. It doesn't look great and it's bringing up other issues but at least the parts of the object needed to get the job done are visible that way.
Message 8 of 11
hyperandey
in reply to: hyperandey

Hi Andy. Thanks a lot for your reply. Appreciate your help. About the Z-buffer processing setting you mentioned, I wonder if you can point out where I can set this check box. I have searched all the dialogs within AutoCAD. There is only one dialog which is probably relevant to graphic system. It is from menu Tools->Optiions->System: Current 3D Graphics Display-> Properties: some setting about 3D Graphics System Configuration. But there is no Z-buffer processing setting in this dialog. I am currently using AutoCAD 2004. Is that setting in higher acad version?
Message 9 of 11
Anonymous
in reply to: hyperandey

Copied from the arx docs:
"The orientation of vertices in a shell's face list indicates the visible
side of the face. For example, if the vertices are specified as clockwise
and the vertices for a given face are listed in clockwise order, then that
face is visible."

Is it possible that the orientation flag in the vertex data is reversed for
the problematic faces?

wrote in message news:5053330@discussion.autodesk.com...
I use ObjectARX to create a custom object. It is 3D shell structure with
several space surfaces. I set different colors for these surfaces. When
changing side view or some views other than plane, parts of some surface
should not be visible because they fall in other side of the view. But
actively these parts are still visible in my program. They are not hidden by
the surfaces in front of them. Any ideas about this problem would be
appreciated. Currently, I use shell() to draw the surface in worldDraw. Do I
need setup some parameters for AcGiViewportDraw in order to hide those
surface behind the front surface? As I need display the colors on these
surfaces, if I use the shade/hide mode, it may solve this problem but the
colors on the surface will disappear. This is not what I want.
Message 10 of 11
OysteinW
in reply to: hyperandey

One possibillity is that it is the triangulation-algorithm that is messing with you... All the triangulation-routines I know of works on a convex set, and removes unwanted triangles afterwards, (to make non-convex boundaries)..
Maybe it's removing the wrong triangles?
Message 11 of 11
amiltonf
in reply to: hyperandey

afaik there is no setting for Z-buffer processing directly. The dialog you found is the one I was referring to but I was only talking about it in reference to the "Acceleration" area and to make sure the "software" radio button was checked instead of the "hardware" radio button as I've found some cards lower the bit depth of Acad's GS. Also, if the other answer regarding triangle winding is correct then I think you should be able to uncheck the "discard back faces" box to solve the problem (if that's what the problem is). I'm pretty sure from your bitmap though that this is not the problem. You also might wanna try raising the "Dynamic Tesselation" sliders to max detail / more memory.

Come to think of it...
To test and see if it's a Z-buffer issue at all just push a transform matrix onto the draw stack and make the entity larger (make sure to pop the matrix before exiting worldDraw / viewportDraw). If the hiding issue goes away then it's the Z-buffer thing. If not then it's something else.

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

Post to forums  

Autodesk Design & Make Report

”Boost