Scene-wide auto batching by name – ShiVa Engine

Scene-wide auto batching by name

This is a code sample to show you how to check your scene for models of the same name and batch them together automatically.
First, create a new object (platform). You can name it anything you want, but for the sake of this tutorial, we have named our model PlatformStatic. You can add Attributes like the Collider Attribute if you want, but controllers (Ai, Dynamics, ...) are not allowed for batching.
Next, execute this code after your scene has been loaded, e.g. in the onInit() handler of your main AI:

  1. -- Batching
  2. local name = "PlatformStatic"
  3. local hGroup = scene.createRuntimeObject ( hScene, "" )
  4. for i=0, scene.getObjectCount(hScene)-1 do
  5. local obj = scene.getObjectAt ( hScene, i )
  6. local nameFull = object.getModelName (obj)
  7. if (string.compare ( string.getSubString ( nameFull, 0, string.getLength(name ) ), name ) == 0) then
  8. object.setParent ( obj, hGroup, true )
  9. end
  10. end
  11. local hCombined = scene.combineRuntimeObjectsGroup ( hScene, hGroup )
  12. --scene.destroyRuntimeObject ( hScene, hGroup )
  13. object.setVisible (hGroup, false )
  14. object.setVisible (hCombined, true )



Need more answers?

  • slackBanner