GeometryUtility.TestPlanesAABB !isNormalized error

Hello guys,
I’m making a system to select many objects with the mouse.
For that I’m using GeometryUtility.TestPlanesAABB with custom frustum planes, generated by me from the mouse square drew with the mouse.

It’s working perfectly for my project, but sometimes I get about 8 !isNormalized error.
That happens when I try to make a small square.

btw, I’m testing in the editor, I’m not sure this will bug out in a compiled version too.

Anyways, I don’t want my project to bug in editor.

This is the square I’m drawing in the screen:
(left:566.50, top:65.00, width:16.00, height:-1.00)

and the 6 planes are:
(distance) :: (normal)
0 :: (0.0, 0.0, 0.0)
1.054068 :: (-1.0, 0.0, 0.1)
-0.8166769 :: (1.0, 0.0, -0.1)
3.422881 :: (0.0, 0.9, 0.4)
-3.411321 :: (0.0, -0.9, -0.4)
990 :: (0.0, 0.0, -1.0)

And the error I’m getting:
!IsNormalized (normal)
UnityEngine.GeometryUtility:TestPlanesAABB(Plane[ ], Bounds)
InputManager:LeftMouseUp(Vector2) (at Assets/Scripts/Input/InputManager.js:298)
InputManager:Update() (at Assets/Scripts/Input/InputManager.js:51)

Any clue?

Thanks in advance

why is the first plane 0 :: (0.0, 0.0, 0.0) and not 0 :: (0.0, 0.0, 1.0)?
You need a normal nonzero vector and a distance, no?

Yea what ivkoni said. 0 0 0 is not a unit vector

Very true. I was suspecting the an error would come from a plane like that, but the point is I’m creating these planes using Plane.Set3Points and using these points:

in this case, multiSelectionRect is (left:566.50, top:65.00, width:16.00, height:-1.00)

How can Unity generate a plane thats not an valid Unity plane?
And how come this happens only with small values of multiSelectionRect.width, multiSelectionRect.height?

if the other planes are alright, I would just hardcode the first plane (if I understand correctly, it is determined by the camera position and its forward vector) and is not affected by the rectangle you draw.

If you send it the same 3 points, maybe even two of the same it probably wont be able to calculate correctly.

You could check the plane manually.

if( multiSelecitionPlanes[0] == default(Plane) ) Debug.LogWarning(“Non unit plane”);

Ok, I got it… somehow _v1, _v2 and _v3 are the same point.

I can’t replicate the problem again… not sure why a ScreenToWorldPoint with different values would return the same point.

Anyways, I will verify for a not normilized plane normal before using GeometryUtility:TestPlanesAABB.

Thanks guys

I’m not sure why it would return the same point either. my first guess would be the screen point is not valid?

I probably should have mentioned in the first place this: Unity - Scripting API: GeometryUtility.CalculateFrustumPlanes

which i think does exactly what your looking for?

Yep, I’m using this approach. But the planes are not generated by the camera, as I want the area select via mouse.
So in this case, I had to create my own frustum planes.

Have you tried using the matrix4x4 overload? I think that a much better approach to take.

Matrix4x4 view = Matrix4x4.TRS( worldPoint, worldDirection, Vector3.one );
Matrix4x4 proj = Matrix4x4.Ortho( … );

Matrix4x4 viewProj = view * proj;

Hey BDev, I’m not sure how could I use this matrix approach to solve my problem.

Would I use this to generate my frustum planes?