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:

   -- Batching
   local name = "PlatformStatic"
   local hGroup = scene.createRuntimeObject ( hScene, "" )
   for i=0, scene.getObjectCount(hScene)-1 do
       local obj = scene.getObjectAt ( hScene, i )
       local nameFull = object.getModelName (obj)
       if ( ( string.getSubString ( nameFull, 0, string.getLength(name ) ), name ) == 0) then
           object.setParent ( obj, hGroup, true )
   local hCombined = scene.combineRuntimeObjectsGroup ( hScene, hGroup )
   --scene.destroyRuntimeObject ( hScene, hGroup )
   object.setVisible (hGroup, false )
   object.setVisible (hCombined, true )

Need more answers?

  • slackBanner