<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">

    <xsd:element name="model">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="rendering" minOccurs="0" maxOccurs="1">
                    <xsd:annotation>
                        <xsd:documentation xml:lang="en">
                            By default all models are rendered as they are, but with some parts of the world this might not be efficient enough. This element allows you to specify an alternative scheme of rendering. An example could be "forest" for forest rendering, where trees are batched together and used with impostors.
                        </xsd:documentation>
                    </xsd:annotation>
                    <xsd:complexType>
                        <xsd:attribute name="scheme" type="xsd:string" use="required"/>
                    </xsd:complexType>
                </xsd:element>
                <xsd:element name="contentoffset" type="vector3" minOccurs="0" maxOccurs="1">
                    <xsd:annotation>
                        <xsd:documentation xml:lang="en">
                            Allows you to specify how much contained entities should be offset from their initial position. This is useful for tables, where you want contained entities to lie on the table, or for instance a bridge where you want contained entities to appear to walk on the bridge.
                        </xsd:documentation>
                    </xsd:annotation>
                </xsd:element>
                <xsd:element name="translate" type="vector3" minOccurs="0" maxOccurs="1">
                    <xsd:annotation>
                        <xsd:documentation xml:lang="en">
                            How much the mesh should be translated in 3d space. This allows you to shift the model without having to regenerate the original mesh.
                        </xsd:documentation>
                    </xsd:annotation>
                </xsd:element>
                <xsd:element name="rotation" minOccurs="0" maxOccurs="1" type="rotation"/>
                <xsd:element name="submodels" minOccurs="0" maxOccurs="1">
                    <xsd:complexType>
                        <xsd:sequence>
                            <xsd:element name="submodel" minOccurs="1" maxOccurs="unbounded">
                                <xsd:complexType>
                                    <xsd:sequence>
                                        <xsd:element name="parts" minOccurs="0" maxOccurs="1">
                                            <xsd:complexType>
                                                <xsd:sequence>
                                                    <xsd:element name="part" minOccurs="0" maxOccurs="unbounded">
                                                        <xsd:complexType>
                                                            <xsd:sequence>
                                                                <xsd:element name="subentities" minOccurs="0" maxOccurs="1">
                                                                    <xsd:complexType>
                                                                        <xsd:sequence>
                                                                            <xsd:element name="subentity" minOccurs="1" maxOccurs="unbounded">
                                                                                <xsd:complexType>
                                                                                    <xsd:attribute name="name" type="xsd:string" use="optional"/>
                                                                                    <xsd:attribute name="index" type="xsd:string" use="optional"/>
                                                                                    <xsd:attribute name="material" type="xsd:string" use="optional"/>
                                                                                </xsd:complexType>
                                                                            </xsd:element>
                                                                        </xsd:sequence>
                                                                    </xsd:complexType>
                                                                </xsd:element>
                                                                <xsd:element name="lights" minOccurs="0" maxOccurs="1">
                                                                    <xsd:complexType>
                                                                        <xsd:sequence>
                                                                            <xsd:element name="light" minOccurs="0" maxOccurs="unbounded">
                                                                                <xsd:complexType>
                                                                                    <xsd:attribute name="name" type="xsd:string" use="required"/>
                                                                                    <xsd:attribute name="bone" type="xsd:string" use="required"/>
                                                                                    <xsd:attribute name="material" type="xsd:string" use="optional"/>
                                                                                </xsd:complexType>
                                                                            </xsd:element>
                                                                        </xsd:sequence>
                                                                    </xsd:complexType>
                                                                </xsd:element>
                                                            </xsd:sequence>
                                                            <xsd:attribute name="name" type="xsd:string" use="required"/>
                                                            <xsd:attribute name="show" type="xsd:boolean" use="required"/>
                                                            <xsd:attribute name="group" type="xsd:string" use="optional"/>
                                                        </xsd:complexType>
                                                    </xsd:element>
                                                </xsd:sequence>
                                            </xsd:complexType>
                                        </xsd:element>
                                    </xsd:sequence>
                                    <xsd:attribute name="mesh" type="xsd:string" use="required"/>
                                    <xsd:attribute name="shadowcaster" type="xsd:boolean"/>
                                </xsd:complexType>
                            </xsd:element>
                        </xsd:sequence>
                    </xsd:complexType>
                </xsd:element>
                <xsd:element name="actions" minOccurs="0" maxOccurs="1">
                    <xsd:complexType>
                        <xsd:sequence>
                            <xsd:element name="action" minOccurs="0" maxOccurs="unbounded">
                                <xsd:complexType>
                                    <xsd:sequence>
                                        <xsd:element name="activations" minOccurs="0" maxOccurs="1">
                                            <xsd:complexType>
                                                <xsd:sequence>
                                                    <xsd:element name="activation" minOccurs="0" maxOccurs="unbounded">
                                                        <xsd:complexType>
                                                            <xsd:simpleContent>
                                                                <xsd:extension base="xsd:string">
                                                                    <xsd:attribute name="type" type="activationTypeEnum" use="required"/>
                                                                </xsd:extension>
                                                            </xsd:simpleContent>
                                                        </xsd:complexType>
                                                    </xsd:element>
                                                </xsd:sequence>
                                            </xsd:complexType>
                                        </xsd:element>
                                        <xsd:element name="animations" minOccurs="0" maxOccurs="1">
                                            <xsd:complexType>
                                                <xsd:sequence>
                                                    <xsd:element name="animation" minOccurs="0" maxOccurs="unbounded">
                                                        <xsd:complexType>
                                                            <xsd:sequence>
                                                                <xsd:element name="animationpart" minOccurs="1" maxOccurs="unbounded">
                                                                    <xsd:complexType>
                                                                        <xsd:sequence>
                                                                            <xsd:element name="bonegrouprefs" minOccurs="0" maxOccurs="1">
                                                                                <xsd:complexType>
                                                                                    <xsd:sequence>
                                                                                        <xsd:element name="bonegroupref" minOccurs="0" maxOccurs="unbounded">
                                                                                            <xsd:complexType>
                                                                                                <xsd:attribute name="name" type="xsd:string" use="required"/>
                                                                                                <xsd:attribute name="weight" type="xsd:float" use="optional"/>
                                                                                            </xsd:complexType>
                                                                                        </xsd:element>
                                                                                    </xsd:sequence>
                                                                                </xsd:complexType>
                                                                            </xsd:element>
                                                                        </xsd:sequence>
                                                                        <xsd:attribute name="name" type="xsd:string" use="required"/>
                                                                    </xsd:complexType>
                                                                </xsd:element>
                                                            </xsd:sequence>
                                                            <xsd:attribute name="iterations" type="xsd:string" use="optional"/>
                                                        </xsd:complexType>
                                                    </xsd:element>
                                                </xsd:sequence>
                                            </xsd:complexType>
                                        </xsd:element>
                                        <xsd:element name="sounds" minOccurs="0" maxOccurs="1">
                                            <xsd:complexType>
                                                <xsd:sequence>
                                                    <xsd:element name="sound" minOccurs="0" maxOccurs="unbounded">
                                                        <xsd:complexType>
                                                            <xsd:attribute name="group" type="xsd:string" use="required"/>
                                                            <xsd:attribute name="playOrder" type="xsd:string" use="optional"/>
                                                        </xsd:complexType>
                                                    </xsd:element>
                                                </xsd:sequence>
                                            </xsd:complexType>
                                        </xsd:element>
                                    </xsd:sequence>
                                    <xsd:attribute name="name" type="xsd:string" use="required"/>
                                    <xsd:attribute name="speed" type="xsd:float" use="optional"/>
                                </xsd:complexType>
                            </xsd:element>
                        </xsd:sequence>
                    </xsd:complexType>
                </xsd:element>
                <xsd:element name="attachpoints" minOccurs="0" maxOccurs="1">
                    <xsd:complexType>
                        <xsd:sequence>
                            <xsd:element name="attachpoint" minOccurs="0" maxOccurs="unbounded">
                                <xsd:complexType>
                                    <xsd:sequence>
                                        <xsd:element name="rotation" minOccurs="0" maxOccurs="1" type="rotation"/>
                                        <xsd:element name="translation" minOccurs="0" maxOccurs="1" type="vector3"/>
                                    </xsd:sequence>
                                    <xsd:attribute name="name" type="xsd:string" use="required"/>
                                    <xsd:attribute name="bone" type="xsd:string" use="required"/>
                                    <xsd:attribute name="pose" type="xsd:string" use="optional"/>
                                </xsd:complexType>
                            </xsd:element>
                        </xsd:sequence>
                    </xsd:complexType>
                </xsd:element>

                <xsd:element name="particlesystems" minOccurs="0" maxOccurs="1">
                    <xsd:complexType>
                        <xsd:sequence>
                            <xsd:element name="particlesystem" minOccurs="0" maxOccurs="unbounded">
                                <xsd:complexType>
                                    <xsd:sequence>
                                        <xsd:element name="direction" minOccurs="0" maxOccurs="1" type="vector3"/>
                                        <xsd:element name="bindings" minOccurs="0" maxOccurs="1">
                                            <xsd:complexType>
                                                <xsd:sequence>
                                                    <xsd:element name="binding" minOccurs="0" maxOccurs="unbounded">
                                                        <xsd:complexType>
                                                            <xsd:attribute name="emittervar" type="xsd:string" use="required"/>
                                                            <xsd:attribute name="atlasattribute" type="xsd:string" use="required"/>
                                                        </xsd:complexType>
                                                    </xsd:element>
                                                </xsd:sequence>
                                            </xsd:complexType>
                                        </xsd:element>
                                    </xsd:sequence>
                                    <xsd:attribute name="script" type="xsd:string" use="required"/>
                                </xsd:complexType>
                            </xsd:element>
                        </xsd:sequence>
                    </xsd:complexType>
                </xsd:element>


                <xsd:element name="views" minOccurs="0" maxOccurs="1">
                    <xsd:complexType>
                        <xsd:sequence>
                            <xsd:element name="view" minOccurs="0" maxOccurs="unbounded">
                                <xsd:complexType>
                                    <xsd:sequence>
                                        <xsd:element name="distance" minOccurs="0" maxOccurs="1" type="xsd:string"/>
                                        <xsd:element name="rotation" minOccurs="0" maxOccurs="1" type="rotation"/>
                                    </xsd:sequence>
                                    <xsd:attribute name="name" type="xsd:string" use="required"/>
                                </xsd:complexType>
                            </xsd:element>
                        </xsd:sequence>
                    </xsd:complexType>
                </xsd:element>
                <xsd:element name="lights" minOccurs="0" maxOccurs="1">
                    <xsd:complexType>
                        <xsd:sequence>
                            <xsd:element name="light" minOccurs="0" maxOccurs="unbounded">
                                <xsd:complexType>
                                    <xsd:sequence>
                                        <xsd:element name="diffusecolour" minOccurs="0" maxOccurs="1" type="colour"/>
                                        <xsd:element name="specularcolour" minOccurs="0" maxOccurs="1" type="colour"/>
                                        <xsd:element name="attenuation" minOccurs="0" maxOccurs="1">
                                            <xsd:complexType>
                                                <xsd:attribute name="range" type="xsd:float" use="optional">
                                                    <xsd:annotation>
                                                        <xsd:documentation xml:lang="en">
                                                            The range of the light.
                                                        </xsd:documentation>
                                                    </xsd:annotation>
                                                </xsd:attribute>
                                                <xsd:attribute name="constant" type="xsd:float" use="optional">
                                                </xsd:attribute>
                                                <xsd:attribute name="linear" type="xsd:float" use="optional">
                                                </xsd:attribute>
                                                <xsd:attribute name="quadratic" type="xsd:float" use="optional">
                                                </xsd:attribute>
                                            </xsd:complexType>
                                        </xsd:element>
                                        <xsd:element name="position" minOccurs="0" maxOccurs="1" type="vector3"/>
                                    </xsd:sequence>
                                    <xsd:attribute name="type" type="xsd:string" use="required"/>
                                </xsd:complexType>
                            </xsd:element>
                        </xsd:sequence>
                    </xsd:complexType>
                </xsd:element>
                <xsd:element name="bonegroups" minOccurs="0" maxOccurs="1">
                    <xsd:complexType>
                        <xsd:sequence>
                            <xsd:element name="bonegroup" minOccurs="0" maxOccurs="unbounded">
                                <xsd:complexType>
                                    <xsd:sequence>
                                        <xsd:element name="bones" minOccurs="0" maxOccurs="1">
                                            <xsd:complexType>
                                                <xsd:sequence>
                                                    <xsd:element name="bone" minOccurs="0" maxOccurs="unbounded">
                                                        <xsd:complexType>
                                                            <xsd:attribute name="index" type="xsd:integer" use="required">
                                                            </xsd:attribute>
                                                        </xsd:complexType>
                                                    </xsd:element>
                                                </xsd:sequence>
                                            </xsd:complexType>
                                        </xsd:element>
                                    </xsd:sequence>
                                    <xsd:attribute name="name" type="xsd:string" use="required"/>
                                </xsd:complexType>
                            </xsd:element>
                        </xsd:sequence>
                    </xsd:complexType>
                </xsd:element>
                <xsd:element name="poses" minOccurs="0" maxOccurs="1">
                    <xsd:complexType>
                        <xsd:sequence>
                            <xsd:element name="pose" minOccurs="0" maxOccurs="unbounded">
                                <xsd:complexType>
                                    <xsd:sequence>
                                        <xsd:element name="translate" minOccurs="0" maxOccurs="1" type="vector3"/>
                                        <xsd:element name="rotate" minOccurs="0" maxOccurs="1" type="rotation"/>
                                    </xsd:sequence>
                                    <xsd:attribute name="name" type="xsd:string" use="required"/>
                                    <xsd:attribute name="ignoreEntityData" type="xsd:boolean" use="optional"/>
                                </xsd:complexType>
                            </xsd:element>
                        </xsd:sequence>
                    </xsd:complexType>
                </xsd:element>
            </xsd:sequence>
            <xsd:attribute name="name" type="xsd:string" use="required">
                <xsd:annotation>
                    <xsd:documentation xml:lang="en">
                        The unique name of the model definition.
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:attribute>
            <xsd:attribute name="rotation" type="xsd:string" use="optional">
                <xsd:annotation>
                    <xsd:documentation xml:lang="en">
                        A rotation in degrees around the y axis. This allows you to optionally rotate the model.
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:attribute>
            <xsd:attribute name="usescaleof" type="usescaleofEnum" use="optional">
                <xsd:annotation>
                    <xsd:documentation xml:lang="en">
                        The client scales the model to fit with the data sent from the server. However, different models would be scaled differently. If this is omitted, the model will be scaled in all dimensions to fit with the bounding box sent from the server. This will in most cases result in a distorted model, and is not desired. Instead you often want to use "width", "height" or "depth".
                        These will scale the model uniformly (no distortion) by using one of the axes as reference. Most character models for example are best suited to use the "height" scaling.
                        Using "none" will make sure that no scaling occurs: the model is unaffected by the data sent from the server. Note however that the attribute "scale" can still be used to scale the model.
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:attribute>
            <xsd:attribute name="scale" type="xsd:float" use="optional"/>
            <xsd:attribute name="showcontained" type="xsd:boolean" use="optional">
                <xsd:annotation>
                    <xsd:documentation xml:lang="en">
                        If true, contained entities will be rendered also. This is the default. Setting this to false might be useful for character entities, which are expected to carry with them an inventory, which we don't want to render.
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:attribute>
            <xsd:attribute name="renderingdistance" type="xsd:float" use="optional"/>
            <xsd:attribute name="icon" type="xsd:string" use="optional"/>
        </xsd:complexType>
    </xsd:element>


    <xsd:simpleType name="usescaleofEnum">
        <xsd:restriction base="xsd:string">
            <xsd:enumeration value="all"/>
            <xsd:enumeration value="height"/>
            <xsd:enumeration value="width"/>
            <xsd:enumeration value="depth"/>
            <xsd:enumeration value="none"/>
            <xsd:enumeration value="fit"/>
        </xsd:restriction>
    </xsd:simpleType>

    <xsd:simpleType name="activationTypeEnum">
        <xsd:restriction base="xsd:string">
            <xsd:enumeration value="movement"/>
            <xsd:enumeration value="action"/>
            <xsd:enumeration value="task"/>
        </xsd:restriction>
    </xsd:simpleType>

    <xsd:complexType name="rotation">
        <xsd:attribute name="x" type="xsd:string" use="required"/>
        <xsd:attribute name="y" type="xsd:string" use="required"/>
        <xsd:attribute name="z" type="xsd:string" use="required"/>
        <!-- how do we specify that at least one of the following must be present, but not both? -->
        <xsd:attribute name="degrees" type="xsd:float" use="optional"/>
        <xsd:attribute name="radians" type="xsd:boolean" use="optional"/>
    </xsd:complexType>
    <xsd:complexType name="vector3">
        <xsd:attribute name="x" type="xsd:string" use="required"/>
        <xsd:attribute name="y" type="xsd:string" use="required"/>
        <xsd:attribute name="z" type="xsd:string" use="required"/>
    </xsd:complexType>
    <xsd:complexType name="colour">
        <xsd:attribute name="r" type="xsd:float" use="required"/>
        <xsd:attribute name="g" type="xsd:float" use="required"/>
        <xsd:attribute name="b" type="xsd:float" use="required"/>
    </xsd:complexType>
</xsd:schema>
