<?xml version="1.0" ?>
<!--
  To generate sdf file using this erb template,
  run `erb actors_population.sdf.erb > actors_population.sdf`
  To specify number of actors,
  run `erb r=10 c=10 actors_population.sdf.erb > actors_population.sdf`
  where `r` means row, `c` means column, and population = r * c.
-->
<sdf version="1.6">
  <world name="actors">
    <plugin
      filename="gz-sim-physics-system"
      name="gz::sim::systems::Physics">
    </plugin>
    <plugin
      filename="gz-sim-user-commands-system"
      name="gz::sim::systems::UserCommands">
    </plugin>
    <plugin
      filename="gz-sim-scene-broadcaster-system"
      name="gz::sim::systems::SceneBroadcaster">
    </plugin>

    <light type="directional" name="sun">
      <cast_shadows>true</cast_shadows>
      <pose>0 0 10 0 0 0</pose>
      <diffuse>0.8 0.8 0.8 1</diffuse>
      <specular>0.2 0.2 0.2 1</specular>
      <attenuation>
        <range>1000</range>
        <constant>0.9</constant>
        <linear>0.01</linear>
        <quadratic>0.001</quadratic>
      </attenuation>
      <direction>-0.5 0.1 -0.9</direction>
    </light>

    <model name="ground_plane">
      <static>true</static>
      <link name="link">
        <collision name="collision">
          <geometry>
            <plane>
              <normal>0.0 0.0 1</normal>
              <size>100 100</size>
            </plane>
          </geometry>
        </collision>
        <visual name="visual">
          <geometry>
            <plane>
              <normal>0.0 0.0 1</normal>
              <size>100 100</size>
            </plane>
          </geometry>
          <material>
            <ambient>0.8 0.8 0.8 1</ambient>
            <diffuse>0.8 0.8 0.8 1</diffuse>
            <specular>0.8 0.8 0.8 1</specular>
          </material>
        </visual>
      </link>
    </model>

    <%
      vars = ARGV.take_while {|arg| arg[/^\w+=/]}
      ARGV.slice!(0, vars.size)
      vars.each do |var|
      k, v = var.split('=', 2)
      TOPLEVEL_BINDING.eval %Q(#{k} = "#{v}")
      end
      # population = column * row, default to 100 actors
      column = 10
      row = 10
      if (defined? c)
        column = c.to_i
      end
      for j in (0..column-1)
        if (defined? r)
          row = r.to_i
        end
        for i in (0..row-1)
    %>

    <actor name="actor_<%= j*column + i %>">
      <skin>
        <filename>https://fuel.gazebosim.org/1.0/Mingfei/models/actor/tip/files/meshes/talk_b.dae</filename>
        <scale>1.0</scale>
      </skin>
      <animation name="talk_b">
        <filename>https://fuel.gazebosim.org/1.0/Mingfei/models/actor/tip/files/meshes/talk_b.dae</filename>
        <scale>0.055</scale>
        <interpolate_x>true</interpolate_x>
      </animation>
      <script>
        <loop>true</loop>
        <auto_start>true</auto_start>
        <trajectory id="<%= j*column + i %>" type="talk_b">
          <waypoint>
            <time>0</time>
            <pose><%= -(row/2) + i %> <%= j %> 1.0 0 0 0</pose>
          </waypoint>
          <waypoint>
            <time>30</time>
            <pose><%= -(row/2) + i %> <%= j %> 1.0 0 0 0</pose>
          </waypoint>
        </trajectory>
      </script>
    </actor>

    <%
        end
      end
    %>
  </world>
</sdf>
