<?xml version="1.0" encoding="UTF-8"?>
<grammar xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0" xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
  <define name="qualityLevels">
    <choice>
      <data type="nonNegativeInteger">
        <param name="maxInclusive">255</param>
        <param name="minInclusive">0</param>
      </data>
      <choice>
        <value>low</value>
        <value>medium</value>
        <value>high</value>
      </choice>
    </choice>
  </define>
  <define name="qualitySettings">
    <optional>
      <attribute name="minquality">
        <a:help>Minimum quality - this is inclusive.</a:help>
        <ref name="qualityLevels"/>
      </attribute>
    </optional>
    <optional>
      <attribute name="maxquality">
        <a:help>Maximum quality - this is exclusive.</a:help>
        <ref name="qualityLevels"/>
      </attribute>
    </optional>
  </define>
  <define name="group">
    <element name="group">
      <ref name="qualitySettings"/>
      <zeroOrMore>
        <element name="variant">
          <ref name="qualitySettings"/>
          <interleave>
            <optional>
              <attribute name="name"/>
            </optional>
            <optional>
              <attribute name="file"/>
            </optional>
            <optional>
              <attribute name="frequency">
                <data type="nonNegativeInteger"/>
              </attribute>
            </optional>
            <optional>
              <element name="mesh">
                <text/>
              </element>
            </optional>
            <optional>
              <element name="textures">
                <zeroOrMore>
                  <element name="texture">
                    <interleave>
                      <optional>
                        <attribute name="file"/>
                      </optional>
                      <attribute name="name"/>
                    </interleave>
                  </element>
                </zeroOrMore>
              </element>
            </optional>
            <optional>
              <element name="decal">
                <interleave>
                  <attribute name="width">
                    <data type="float"/>
                  </attribute>
                  <!-- X -->
                  <attribute name="depth">
                    <data type="float"/>
                  </attribute>
                  <!-- Z -->
                  <attribute name="angle">
                    <data type="float"/>
                  </attribute>
                  <attribute name="offsetx">
                    <data type="float"/>
                  </attribute>
                  <attribute name="offsetz">
                    <data type="float"/>
                  </attribute>
                </interleave>
              </element>
            </optional>
            <optional>
              <element name="particles">
                <attribute name="file"/>
              </element>
            </optional>
            <optional>
              <element name="color">
                <list>
                  <group>
                    <data type="nonNegativeInteger"/>
                    <!-- R -->
                    <data type="nonNegativeInteger"/>
                    <!-- G -->
                    <data type="nonNegativeInteger"/>
                  </group>
                  <!-- B -->
                </list>
              </element>
            </optional>
            <optional>
              <element name="animations">
                <zeroOrMore>
                  <element name="animation">
                    <interleave>
                      <attribute name="name"/>
                      <optional>
                        <attribute name="id"/>
                      </optional>
                      <optional>
                        <attribute name="frequency">
                          <data type="nonNegativeInteger"/>
                        </attribute>
                      </optional>
                      <optional>
                        <attribute name="file"/>
                      </optional>
                      <attribute name="speed">
                        <data type="nonNegativeInteger"/>
                      </attribute>
                      <optional>
                        <attribute name="event">
                          <data type="decimal">
                            <param name="minInclusive">0</param>
                            <param name="maxInclusive">1</param>
                          </data>
                        </attribute>
                      </optional>
                      <optional>
                        <attribute name="load">
                          <data type="decimal">
                            <param name="minInclusive">0</param>
                            <param name="maxInclusive">1</param>
                          </data>
                        </attribute>
                      </optional>
                      <optional>
                        <attribute name="sound">
                          <data type="decimal">
                            <param name="minInclusive">0</param>
                            <param name="maxInclusive">1</param>
                          </data>
                        </attribute>
                      </optional>
                    </interleave>
                  </element>
                </zeroOrMore>
              </element>
            </optional>
            <optional>
              <element name="props">
                <zeroOrMore>
                  <element name="prop">
                    <interleave>
                      <optional>
                        <attribute name="actor"/>
                      </optional>
                      <attribute name="attachpoint"/>
                      <optional>
                        <attribute name="minheight">
                          <data type="float"/>
                        </attribute>
                      </optional>
                      <optional>
                        <attribute name="maxheight">
                          <data type="float"/>
                        </attribute>
                      </optional>
                      <optional>
                        <attribute name="selectable">
                          <choice>
                            <value>true</value>
                            <value>false</value>
                          </choice>
                        </attribute>
                      </optional>
                    </interleave>
                  </element>
                </zeroOrMore>
              </element>
            </optional>
          </interleave>
        </element>
      </zeroOrMore>
    </element>
  </define>
  <define name="actorDef">
    <interleave>
      <attribute name="version">
        <data type="positiveInteger"/>
      </attribute>
      <zeroOrMore>
        <ref name="group"/>
      </zeroOrMore>
      <optional>
        <element name="castshadow">
          <ref name="qualitySettings"/>
          <!-- flag; true if present -->
          <empty/>
        </element>
      </optional>
      <optional>
        <element name="float">
          <ref name="qualitySettings"/>
          <!-- flag; true if present -->
          <empty/>
        </element>
      </optional>
      <optional>
        <element name="material">
          <ref name="qualitySettings"/>
          <text/>
        </element>
      </optional>
    </interleave>
  </define>
  <start>
    <choice>
      <element name="actor">
        <ref name="actorDef"/>
      </element>
      <element name="qualitylevels">
        <interleave>
          <attribute name="version">
            <data type="positiveInteger"/>
          </attribute>
          <oneOrMore>
            <element name="actor">
              <optional>
                <attribute name="quality">
                  <a:help>The quality level to use for this actor. This is the maximum value at which this version of the actor will be used. If not specified, the maximum possible value is assumed.</a:help>
                  <ref name="qualityLevels"/>
                </attribute>
              </optional>
              <choice>
                <attribute name="inline">
                  <empty/>
                </attribute>
                <attribute name="file">
                  <text/>
                </attribute>
                <ref name="actorDef"/>
              </choice>
            </element>
          </oneOrMore>
          <optional>
            <element name="inline">
              <ref name="actorDef"/>
            </element>
          </optional>
        </interleave>
      </element>
    </choice>
  </start>
</grammar>
