Incorrect face normal

Incorrect face normal

Anonymous
Not applicable
6,037 Views
13 Replies
Message 1 of 14

Incorrect face normal

Anonymous
Not applicable

I created two beams through different codes. Their FamilySymbols are the same. But their left faces' (marked as red in pic)normal are different!

The face normal of the left beam is the same as I expected(-1,0,0). 

The face normal of the right beam is wriong to me and I don't konw why. test.png

Attached is my project for your erfernce.

0 Likes
Accepted solutions (1)
6,038 Views
13 Replies
Replies (13)
Message 2 of 14

dragos.turmac
Autodesk
Autodesk

Hi @Anonymous,

It seems that one beam is bound to 标高2 as working plane, and the other one is unbound. Is this intended? This binding can influence the position of the FamilyInstance in WCS.

 



Turmac Dragos
Pr. SW. Engineer
0 Likes
Message 3 of 14

Anonymous
Not applicable

Hi dragos.turmac, Thanks for your quick response!

Bounding to a working plane is not my intention.

For the both beams I used Instance = Doc.Create.NewFamilyInstance(line, FamilySymbol, Level, StructuralType.Beam) to create them. 

How can i avoid bounding to a working plane when creaing? Why and how working plane influence the FamilyInstance? If I can't change the way of creating the right beam how can i get the correct face normal like the left beam? Thanks!

0 Likes
Message 4 of 14

dragos.turmac
Autodesk
Autodesk

You can try passing null for Level. Unfortunately it's not explicitly mentioned in the documentation, but the Level parameter is optional.

The beam, after all, it is a family; like every family, it has a local coordinate system. If you bind it to a plane, than it's LCS is might no longer be identical to WCS; it's local Z axis will correspond to the Z axis of the reference plane.

What you are seeing is the beam's face normal in LCS, that's why they differ even if they point in the same WCS direction.



Turmac Dragos
Pr. SW. Engineer
0 Likes
Message 5 of 14

Revitalizer
Advisor
Advisor

Hi,

 

in the RevitAPI.chm it says:

 

PlanarFace.FaceNormal property
This property is the "face normal" vector, and thus should return a vector consistently pointing out of the solid that this face is a boundary for (if it is a part of a solid).

 

There is also this method:


Face.ComputeNormal()
It will always be oriented to point out of a solid that contains the face.

 

 

So the answer is already given in the documentation.

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





0 Likes
Message 6 of 14

Revitalizer
Advisor
Advisor

Hi,

 

I've downloaded your sample file and investigated the FaceNormals.

 

For each of the two Elements, there are six sides having FaceNormal values as expected, all pointing outwards (making my previous post obsolete).

 

May it be that you compare the faces by index, meaning the first face in the left element's face list is compared to the first face in the second one's face list ?

 

The geometry objects are not returned in order but randomized.

 

As far as I can see, there is no problem at all.

 

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





0 Likes
Message 7 of 14

Anonymous
Not applicable

Hi dragos.turmac,

I passed null for Level and the right beam was bound to no working plane this time. But both beams' faces' normal are the same as previous.

New rvt file is atteched for your reference.

 

 

Hi Revitalizer,

I understand your points and thank you. Below is my test code to calculate the face normal and snapshot of the result. I was not using index to get the face.

 Reference refFace = null;
            while (true)
            {
                try
                {
                    refFace = sel.PickObject(ObjectType.Face, "select a face");
                    Element selectedElement = Doc.GetElement(refFace);
                    GeometryObject selectedGeoObject = selectedElement.GetGeometryObjectFromReference(refFace);
                    Face selectedFace = selectedGeoObject as Face;
                    PlanarFace selectedPlanarFace = selectedFace as PlanarFace;

                    BoundingBoxUV box = selectedFace.GetBoundingBox();
                    UV faceCenter = (box.Max + box.Min) / 2;

                    XYZ computedFaceNormal = selectedFace.ComputeNormal(faceCenter).Normalize();
                    XYZ faceNormal = selectedPlanarFace.FaceNormal;

                    MessageBox.Show($"computedFaceNormal: {computedFaceNormal.ToString()}, faceNormal: {faceNormal.ToString()}");
                }
                catch (Autodesk.Revit.Exceptions.OperationCanceledException e)
                {
                    return Result.Cancelled;
                }
            }

 

test.png

 

"there are six sides having FaceNormal values as expected" you mean the left face's normal of the right beam is (-1,0,0)?

0 Likes
Message 8 of 14

Revitalizer
Advisor
Advisor

Hi,

 

yes, I've just read the solid's faces via RevitLookup.

For both of the elements, there were six PlanarFaces, each with perfect FaceNormal values.

 

May it be that the selection function itself returns a false face ?

Seems to be the front face instead of the displayed lateral one.

 

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





0 Likes
Message 9 of 14

Anonymous
Not applicable

Hi,

 

 MessageBox.Show($"computedFaceNormal: {computedFaceNormal.ToString()}, faceNormal: {faceNormal.ToString()}, Area: {selectedFace.Area.ToString()}");

I tested it again. The area are correct, but the face normal...test.png

0 Likes
Message 10 of 14

Revitalizer
Advisor
Advisor

Hi,

 

when getting the solids and their faces, I draw the normals as ModelLines, starting at the faces' center points:

Normals.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

All right, this way.

 

When I pick a face, I get this result with the left one:

 

NormalsPickedLeft.png

But I get this when picking the right one:

 

NormalsPickedRight.png

What does it mean ?

In fact, the face returned is not transformed to the project context, the solid resides around the 0/0/0 project origin.

I've drawn the faces' boundaries, too:

 

NormalsPickedRightAllSides.png

Strange. No idea.

 

 

Revitalizer

 

 




Rudolf Honke
Software Developer
Mensch und Maschine





Message 11 of 14

Anonymous
Not applicable

Hi,

 

I did further investigation. I found that I've added coping on the left beam before. So when I adding coping on the right one it works right! Why? ...

0 Likes
Message 12 of 14

Revitalizer
Advisor
Advisor

Hi,

 

I think only The Factory itself can answer the "why" question.

 

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





0 Likes
Message 13 of 14

FAIR59
Advisor
Advisor
Accepted solution

Your comment on coping is the last piece of the puzzle.
When a familyinstance is

  • cut,
  • joined
  • coped
  • and apparently has been coped

Revit has to calculate the solids of the instance "in situ" as it will be different from the solids from the family definition. So the normal of the face will be relative to the project.

 

In all (??) other cases Revit treats the solids as "instances" of the solids from the family definition. And by some Revit-logic, when asked for Face.ComputeNormal() it gives the normal relative to the family. Quirkier still it gives the Face.Origin in project coordinates.

 

So with familyinstances that are not cut, joined or coped, you need to transform the faceNormal to project coordinates.
As you have a reference to the face you can easily test for this condition:
refFace.ConvertToStableRepresentation(doc).Contains("INSTANCE")
So add this to your code:

                    if (refFace.ConvertToStableRepresentation(doc).Contains("INSTANCE"))
                    {
                        Transform trans = (selectedElement as FamilyInstance).GetTransform();
                       computedFaceNormal = trans.OfVector(computedFaceNormal);
faceNormal =trans.OfVector( faceNormal));
}
Message 14 of 14

Anonymous
Not applicable

Classic! Thank you all so much!

0 Likes