About Monkey 2 › Forums › Monkey 2 Code Library › mojo3d debugging: CountEntities and PrintEntities
Tagged: CountEntities, entity count, mojo3d
This topic contains 0 replies, has 1 voice, and was last updated by
DruggedBunny
7 months, 3 weeks ago.
-
AuthorPosts
-
August 27, 2018 at 9:54 pm #15338
Just whipped up these two mojo3d debugging functions:
- CountEntities: Returns number of entities in the current 3D scene;
- PrintEntities: Same basic code, but prints a recursive tree of all entities in the current scene.
(Currently helping me figure out what hasn’t been removed from my scene while moving to a new level!)
Monkey1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556Function CountEntities:Int (entity:Entity = Null, depth:Int = 0)Local scene:Scene = Scene.GetCurrent ()Assert (scene, "CountEntities: No current scene!")Local branch:Entity[]If Not entitybranch = scene.GetRootEntities ()Elsebranch = entity.ChildrenEndifLocal count:Int = branch.LengthFor Local e:Entity = Eachin branchcount = count + CountEntities (e, depth + 1)NextReturn countEndFunction PrintEntities:Int (e:Entity = Null, depth:Int = 0)Local scene:Scene = Scene.GetCurrent ()Assert (scene, "PrintEntities: No current scene!")Local branch:Entity[]If Not ebranch = scene.GetRootEntities ()Print "ROOT"Elsebranch = e.ChildrenEndifLocal tabs:StringFor Local tab:Int = 1 To depth + 1tabs = tabs + " "NextLocal count:Int = branch.LengthFor Local e:Entity = Eachin branchPrint tabs + "o " + e.Namecount = count + PrintEntities (e, depth + 1)NextReturn countEndSample output from current project:
Monkey12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576ROOTo Lighto Modelo Copy of Modelo Copy of Modelo Copy of Modelo Copy of Modelo Modelo Portal ring [spawned at Mon 27 Aug 2018 22:38:32]o Modelo Modelo SpaceGem [spawned at Mon 27 Aug 2018 22:38:32]o SpaceGem [spawned at Mon 27 Aug 2018 22:38:32]o SpaceGem [spawned at Mon 27 Aug 2018 22:38:32]o SpaceGem [spawned at Mon 27 Aug 2018 22:38:32]o SpaceGem [spawned at Mon 27 Aug 2018 22:38:32]o SpaceGem [spawned at Mon 27 Aug 2018 22:38:32]o SpaceGem [spawned at Mon 27 Aug 2018 22:38:32]o SpaceGem [spawned at Mon 27 Aug 2018 22:38:32]o Camera pivot [spawned at Mon 27 Aug 2018 22:38:32]o Camera [spawned at Mon 27 Aug 2018 22:38:32]o Modelo Lighto Modelo Copy of Modelo Copy of Modelo Copy of Modelo Copy of Modelo Modelo Portal ring [spawned at Mon 27 Aug 2018 22:39:31]o Modelo Modelo SpaceGem [spawned at Mon 27 Aug 2018 22:39:31]o SpaceGem [spawned at Mon 27 Aug 2018 22:39:31]o SpaceGem [spawned at Mon 27 Aug 2018 22:39:31]o SpaceGem [spawned at Mon 27 Aug 2018 22:39:31]o SpaceGem [spawned at Mon 27 Aug 2018 22:39:31]o SpaceGem [spawned at Mon 27 Aug 2018 22:39:31]o SpaceGem [spawned at Mon 27 Aug 2018 22:39:31]o SpaceGem [spawned at Mon 27 Aug 2018 22:39:31]o Camera pivot [spawned at Mon 27 Aug 2018 22:39:31]o Camera [spawned at Mon 27 Aug 2018 22:39:31]o Modelo Lighto Terrain [spawned at Mon 27 Aug 2018 22:40:32]o Modelo Copy of Modelo Copy of Modelo Copy of Modelo Copy of Modelo Modelo Portal ring [spawned at Mon 27 Aug 2018 22:40:32]o Modelo Modelo Pad [spawned at Mon 27 Aug 2018 22:40:32]o SpaceGem [spawned at Mon 27 Aug 2018 22:40:32]o Pad [spawned at Mon 27 Aug 2018 22:40:32]o SpaceGem [spawned at Mon 27 Aug 2018 22:40:32]o Pad [spawned at Mon 27 Aug 2018 22:40:32]o SpaceGem [spawned at Mon 27 Aug 2018 22:40:32]o Pad [spawned at Mon 27 Aug 2018 22:40:32]o SpaceGem [spawned at Mon 27 Aug 2018 22:40:32]o Pad [spawned at Mon 27 Aug 2018 22:40:32]o SpaceGem [spawned at Mon 27 Aug 2018 22:40:32]o Pad [spawned at Mon 27 Aug 2018 22:40:32]o Pad [spawned at Mon 27 Aug 2018 22:40:32]o SpaceGem [spawned at Mon 27 Aug 2018 22:40:32]o Pad [spawned at Mon 27 Aug 2018 22:40:32]o SpaceGem [spawned at Mon 27 Aug 2018 22:40:32]o Pad [spawned at Mon 27 Aug 2018 22:40:32]o SpaceGem [spawned at Mon 27 Aug 2018 22:40:32]o Rocket [spawned at Mon 27 Aug 2018 22:40:32]o Camera pivot [spawned at Mon 27 Aug 2018 22:40:32]o Camera [spawned at Mon 27 Aug 2018 22:40:32]o ModelNote that I haven’t yet named some entities, which show the default entity type, eg. “Model”, “Copy of Model”, “Light”, etc.
I’m naming models with their time of creation here, so I can see if they were spawned on creation of the new level, or are still left over from the previous level (because I’ve been stupid); like so:
Monkey123model = Model.CreateSphere (0.75, 8, 8, mat)model.Name = "Orb [spawned at " + Time.Now () + "]"I knew I had duplicate SpaceGems, but, YIKES, duplicate cameras, too!
-
AuthorPosts
You must be logged in to reply to this topic.