LoadAnimMesh,EntityPickMode and TerraEd

Blitz3D Forums/Blitz3D Programming/LoadAnimMesh,EntityPickMode and TerraEd

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Hi!

When using EntityPickMode=2, CameraPick and LinePick may not return the same handle that was returned by LoadAnimMesh. Instead, you may get the handle of a child of the object, and a direct comparison (of the value returned by LoadAnimMesh, to the value returned by CameraPick) will fail. This is not an issue with LoadMesh, since parent/child info does not get loaded by that method.

This issue (with EntityPickMode=2) comes up in TerraEd, because TerraEd calls LoadAnimMesh for everything.

Here is a solution to the problem.

;Typical use of CameraPick to select an object
MyPickEntity = CameraPick(Cam, GraphicsWidth()/2, GraphicsHeight()/2)
If MyPickEntity <> 0 Then
     For G.Game_Object=Each Game_Object
          If PickTest(G\Entity, MyPickEntity) Then
               ; Do Something
          Endif
     Next
Endif

;Function that makes it work
Function PickTest(TestEntity%, PickEntity%)
     If TestEntity = PickEntity Return True
	
     Children%=CountChildren(TestEntity)
	
     For n = 1 To Children%
          Test%=GetChild(TestEntity,n)
          EndSearch = PickTest(Test,PickEntity)
          If EndSearch Return True	
     Next
	
     Return False
End Function


Feel free to use the above code as needed.

Important: TerraEd has a function to get an object's Entity Handle: Ter_FindTerraObject(Name$). However, to use that function, A) the object must have "Culling" Reset, and (B) you must _first_ call Ter_UpdateTerra(Cam) - once for all objects - which sets the Entity Handles for all non-culled objects in the TerraEd map.

Regards,

Martonic