Can anyone prepare a schema for AMF?

88 views
Skip to first unread message

Hod Lipson

unread,
Jan 16, 2013, 11:45:26 AM1/16/13
to st...@googlegroups.com

Can anyone volunteer to prepare a schema for AMF?

 

--hod

 

 

Jesse McGatha

unread,
Jan 19, 2013, 6:29:27 PM1/19/13
to st...@googlegroups.com
I'm drafting something in XSD. I found a few issues in the spec while I was working on this.
 
- Unit attribute of <amf> element - Why is "feet" plural when the others are singular? Seems peculiar.

- In table A1.1, element <texmap> is typod as <texmapl>

- In table A1.1 elements <vtext>, <vtex2>, and <vtex3> are typod as <ytext>, <ytex2>, and <ytex3>

- The texture tiled attribute is hard to schematize. Should be true|false, next best is only 0 or 1, but has to be any int. That presumably includes negatives. Should probably tighten to 0|1, given current spec.

- It is not clear what the rrange of values acceptable for rotation is: -360 - +360? This should be specified.

- Geometry restrictions in 6.6 are not schematizable (FYI).

- It would be very nice to require elements in a specific order for schematization. This would dramatically simplify schematization. For example, I have not found a good way to schematize the requirement for at least one <object> if the order of the elements under <amf> is not specified.
 
- In 5.3, it should talk about the "opening <amf> element" not the "opening </amf> element". 
 
- Formulae present a challenge for schematizing values that can take formulas. These can no longer be strongly typed because there is no indicator that the contents are a formula. e.g. the spec would have been better to do something like "<color>formula(1/z)</color>" rather than "<color>1/z</color>". Because formulas can be complex, there is not really a good way to write a regular expression style pattern to describe any pattern, so it just has to be a string that the consumer interprets. Because there is no regexp pattern that you can write to disambiguate between formulas or other values, this means you can't enforce valid ranges for non-formulae values either.
 
I may have additional comments when I get a bit further.
 
-Jesse McGatha

Jesse McGatha

unread,
Jan 20, 2013, 2:04:20 AM1/20/13
to st...@googlegroups.com
One other issue:
 
- Table A1.1 says <texmap> has the elements <utext>, <vtext> (typod as <ytext>), and <wtext>. Figure 4 says <texmap> has the elements <utex1>, <vtex1>, and <wtex1>. Section 9.2, the actual section on <texmap>, says nothing about what the elements are called, except: "the <texmap> element may be used to define u, v, and (optionally) w coordinates for each vertex of this triangle"... So it doesn't say what the correct child elements are (although it should). I'm assuming it should be <utex1>, <vtex1>, and <wtex1>, but it would be good to get confirmation.
 
-Jesse McGatha

Jesse McGatha

unread,
Jan 20, 2013, 5:13:09 PM1/20/13
to st...@googlegroups.com
Not sure if there's a better way to share this, but here's my draft schema. I was able to test it on a few test files from http://amf.wikispaces.com/AMF+test+files (by the way, the file Amf_Cube.amf has invalid markup per current spec). I'm sure there might still be some bugs in this, so I'd appreciate if folks could test against a wide range of files. Also, there are many things that could be improved with tighter specification, particularly by providing an order of elements.
 
-Jesse McGatha
 
------------
 
<?xml version="1.0" encoding="UTF-8"?>
<!-- A namespace should be declared in xs:schema, e.g. targetNamespace="http://schemas.astm.org/amf/2013/01" and xmlns="http://schemas.astm.org/amf/2013/01" -->
<xs:schema
 xmlns:xs="http://www.w3.org/2001/XMLSchema"
 xmlns:xml="http://www.w3.org/XML/1998/namespace"
 elementFormDefault="unqualified"
 attributeFormDefault="unqualified"
 blockDefault="#all">
 <xs:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="http://www.w3.org/2001/xml.xsd" />
 <xs:annotation>
  <xs:documentation>
  <![CDATA[
  Schema notes:
  Items within this schema follow a simple naming convention of appending a prefix indicating the type of element for references:
  Unprefixed: Element names
  CT_: Complex types
  ST_: Simple types
  AG_: Attribute groups
  Some format rules cannot be enforced with this schema; the burden is on the consumer to verify these. The un-enforced rules include:
  - There must be at least one <object> element as a child of the <amf> element
  - Restrictions on geometries described in 6.6 of the specification
  - Misuse of reserved metadata
  - No circular references in constellations
  ]]>
  </xs:documentation>
 </xs:annotation>
 <!-- Complex Types -->
 <xs:complexType name="CT_Amf">
  <xs:sequence>
   <xs:choice maxOccurs="unbounded">
    <xs:element ref="object" />
    <xs:element ref="material" minOccurs="0" />
    <xs:element ref="texture" minOccurs="0" />
    <xs:element ref="constellation" minOccurs="0" />
    <xs:element ref="metadata" minOccurs="0" maxOccurs="unbounded" />
   </xs:choice>
  </xs:sequence>
  <xs:attributeGroup ref="AG_Amf" />
 </xs:complexType>
 <xs:complexType name="CT_Object">
  <xs:sequence>
   <xs:choice maxOccurs="unbounded">
    <xs:element ref="color" minOccurs="0" />
    <xs:element ref="mesh" />
    <xs:element ref="metadata" minOccurs="0" maxOccurs="unbounded" />
   </xs:choice>
  </xs:sequence>
  <xs:attributeGroup ref="AG_Object" />
 </xs:complexType>
 
 <xs:complexType name="CT_Color">
  <xs:sequence>
   <xs:element ref="r" />
   <xs:element ref="g" />
   <xs:element ref="b" />
   <xs:element ref="a" minOccurs="0" />
  </xs:sequence>
 </xs:complexType>
 
 <xs:complexType name="CT_Mesh">
  <xs:sequence>
   <xs:element ref="vertices" />
   <xs:element ref="volume" />
  </xs:sequence>
 </xs:complexType>
 
 <xs:complexType name="CT_Vertices">
  <xs:sequence>
   <xs:element ref="vertex" maxOccurs="unbounded" />
   <xs:element ref="edge" minOccurs="0" maxOccurs="unbounded" />
  </xs:sequence>
 </xs:complexType>
 
 <xs:complexType name="CT_Vertex">
  <xs:sequence>
   <xs:choice maxOccurs="unbounded">
    <xs:element ref="metadata" minOccurs="0" maxOccurs="unbounded" />
    <xs:element ref="coordinates" />
    <xs:element ref="color" minOccurs="0" />
    <xs:element ref="normal" minOccurs="0" />
   </xs:choice>
  </xs:sequence>
 </xs:complexType>
 <xs:complexType name="CT_Coordinates">
  <xs:sequence>
   <xs:element ref="x" />
   <xs:element ref="y" />
   <xs:element ref="z" />
  </xs:sequence>
 </xs:complexType>
 <xs:complexType name="CT_Normal">
  <xs:sequence>
   <xs:element ref="nx" />
   <xs:element ref="ny" />
   <xs:element ref="nz" />
  </xs:sequence>
 </xs:complexType>
 <xs:complexType name="CT_Edge">
  <xs:sequence>
   <xs:element ref="v1" />
   <xs:element ref="dx1" />
   <xs:element ref="dy1" />
   <xs:element ref="dz1" />
   <xs:element ref="v2" />
   <xs:element ref="dx2" />
   <xs:element ref="dy2" />
   <xs:element ref="dz2" />
  </xs:sequence>
 </xs:complexType>
 <xs:complexType name="CT_Volume">
  <xs:sequence>
   <xs:choice minOccurs="4" maxOccurs="unbounded">
    <xs:element ref="metadata" minOccurs="0" maxOccurs="unbounded" />
    <xs:element ref="triangle" minOccurs="4" maxOccurs="unbounded" />
    <xs:element ref="color" minOccurs="0" />
   </xs:choice>
  </xs:sequence>
  <xs:attributeGroup ref="AG_Volume" />
 </xs:complexType>
 <xs:complexType name="CT_Triangle">
  <xs:sequence>
   <xs:choice maxOccurs="5">
    <xs:sequence>
     <xs:element ref="v1" />
     <xs:element ref="v2" />
     <xs:element ref="v3" />
     <xs:element ref="texmap" minOccurs="0" />
    </xs:sequence>
    <xs:element ref="color" minOccurs="0" />
   </xs:choice>
  </xs:sequence>
 </xs:complexType>
 <xs:complexType name="CT_Texture">
  <xs:simpleContent>
   <xs:extension base="ST_TextureBase">
    <xs:attributeGroup ref="AG_Texture" />
   </xs:extension>
  </xs:simpleContent>
 </xs:complexType>
 <xs:complexType name="CT_TexMap">
  <xs:sequence>
   <xs:element ref="utex1" />
   <xs:element ref="utex2" />
   <xs:element ref="utex3" />
   <xs:element ref="vtex1" />
   <xs:element ref="vtex2" />
   <xs:element ref="vtex3" />
   <xs:element ref="wtex1" minOccurs="0" />
   <xs:element ref="wtex2" minOccurs="0" />
   <xs:element ref="wtex3" minOccurs="0" />
  </xs:sequence>
  <xs:attributeGroup ref="AG_TexMap" />
 </xs:complexType>
 <xs:complexType name="CT_Material">
  <xs:sequence>
   <xs:element ref="metadata" minOccurs="0" maxOccurs="unbounded" />
   <xs:element ref="composite" minOccurs="0" maxOccurs="unbounded" />
  </xs:sequence>
  <xs:attributeGroup ref="AG_Material" />
 </xs:complexType>
 <xs:complexType name="CT_Composite">
  <xs:simpleContent>
   <xs:extension base="xs:string">
    <xs:attributeGroup ref="AG_Composite" />
   </xs:extension>
  </xs:simpleContent>
 </xs:complexType>
 <xs:complexType name="CT_Constellation">
  <xs:sequence>
   <xs:element ref="instance" minOccurs="2" maxOccurs="unbounded" />
  </xs:sequence>
  <xs:attributeGroup ref="AG_Constellation" />
 </xs:complexType>
 <xs:complexType name="CT_Instance">
  <xs:sequence>
   <xs:element ref="deltax" minOccurs="0" />
   <xs:element ref="deltay" minOccurs="0" />
   <xs:element ref="deltaz" minOccurs="0" />
   <xs:element ref="rx" minOccurs="0" />
   <xs:element ref="ry" minOccurs="0" />
   <xs:element ref="rz" minOccurs="0" />
  </xs:sequence>
  <xs:attributeGroup ref="AG_Instance" />
 </xs:complexType>
 <xs:complexType name="CT_Metadata">
  <xs:simpleContent>
   <xs:extension base="xs:string">
    <xs:attributeGroup ref="AG_Metadata" />
   </xs:extension>
  </xs:simpleContent>
 </xs:complexType>
 <!-- Simple Types -->
 <xs:simpleType name="ST_NegOneToOne">
  <xs:restriction base="ST_Double">
   <xs:minInclusive value="-1.0" />
   <xs:maxInclusive value="1.0" />
  </xs:restriction>
 </xs:simpleType>
 <xs:simpleType name="ST_Double">
  <xs:restriction base="xs:double">
   <xs:whiteSpace value="collapse" />
   <xs:pattern value="((\-|\+)?(([0-9]+(\.[0-9]+)?)|(\.[0-9]+))((e|E)(\-|\+)?[0-9]+)?)" />
  </xs:restriction>
 </xs:simpleType>
 <xs:simpleType name="ST_Degrees">
  <xs:restriction base="ST_Double">
   <xs:minInclusive value="-360" />
   <xs:maxInclusive value="360" />
  </xs:restriction>
 </xs:simpleType>
 <xs:simpleType name="ST_Unit">
  <xs:restriction base="xs:string">
   <xs:enumeration value="inch" />
   <xs:enumeration value="millimeter" />
   <xs:enumeration value="meter" />
   <xs:enumeration value="feet" />
   <xs:enumeration value="micron" />
  </xs:restriction>
 </xs:simpleType>
 <xs:simpleType name="ST_TextureBase">
  <xs:restriction base="xs:string">
   <xs:whiteSpace value="collapse" />
   <xs:pattern value="([0-9]|[a-z]|[A-Z]|\+|\/|\=)+" />
  </xs:restriction>
 </xs:simpleType>
 
 <xs:simpleType name="ST_TextureType">
  <xs:restriction base="xs:string">
   <xs:enumeration value="grayscale" />
  </xs:restriction>
 </xs:simpleType>
 <xs:simpleType name="ST_VolumeType">
  <xs:restriction base="xs:string">
   <xs:enumeration value="object" />
   <xs:enumeration value="support" />
  </xs:restriction>
 </xs:simpleType>
 <xs:simpleType name="ST_ColorValue">
  <xs:restriction base="xs:string">
  </xs:restriction>
 </xs:simpleType>
 <!-- Elements -->
 <xs:element name="amf" type="CT_Amf" />
 <xs:element name="object" type="CT_Object" />
 <xs:element name="color" type="CT_Color" />
 <xs:element name="r" type="ST_ColorValue" />
 <xs:element name="g" type="ST_ColorValue" />
 <xs:element name="b" type="ST_ColorValue" />
 <xs:element name="a" type="ST_ColorValue" />
 <xs:element name="mesh" type="CT_Mesh" />
 <xs:element name="vertices" type="CT_Vertices" />
 <xs:element name="vertex" type="CT_Vertex" />
 <xs:element name="coordinates" type="CT_Coordinates" />
 <xs:element name="x" type="ST_Double" />
 <xs:element name="y" type="ST_Double" />
 <xs:element name="z" type="ST_Double" />
 <xs:element name="normal" type="CT_Normal" />
 <xs:element name="edge" type="CT_Edge" />
 <xs:element name="dx1" type="ST_NegOneToOne" />
 <xs:element name="dy1" type="ST_NegOneToOne" />
 <xs:element name="dz1" type="ST_NegOneToOne" />
 <xs:element name="dx2" type="ST_NegOneToOne" />
 <xs:element name="dy2" type="ST_NegOneToOne" />
 <xs:element name="dz2" type="ST_NegOneToOne" />
 <xs:element name="nx" type="ST_NegOneToOne" />
 <xs:element name="ny" type="ST_NegOneToOne" />
 <xs:element name="nz" type="ST_NegOneToOne" />
 <xs:element name="volume" type="CT_Volume" />
 <xs:element name="triangle" type="CT_Triangle" />
 <xs:element name="v1" type="xs:nonNegativeInteger" />
 <xs:element name="v2" type="xs:nonNegativeInteger" />
 <xs:element name="v3" type="xs:nonNegativeInteger" />
 <xs:element name="texture" type="CT_Texture" />
 <xs:element name="texmap" type="CT_TexMap" />
 <xs:element name="utex1" type="ST_Double" />
 <xs:element name="utex2" type="ST_Double" />
 <xs:element name="utex3" type="ST_Double" />
 <xs:element name="vtex1" type="ST_Double" />
 <xs:element name="vtex2" type="ST_Double" />
 <xs:element name="vtex3" type="ST_Double" />
 <xs:element name="wtex1" type="ST_Double" />
 <xs:element name="wtex2" type="ST_Double" />
 <xs:element name="wtex3" type="ST_Double" />
 <xs:element name="material" type="CT_Material" />
 <xs:element name="composite" type="CT_Composite" />
 <xs:element name="constellation" type="CT_Constellation" />
 <xs:element name="instance" type="CT_Instance" />
 <xs:element name="deltax" type="ST_Double" />
 <xs:element name="deltay" type="ST_Double" />
 <xs:element name="deltaz" type="ST_Double" />
 <xs:element name="rx" type="ST_Degrees" />
 <xs:element name="ry" type="ST_Degrees" />
 <xs:element name="rz" type="ST_Degrees" />
 <xs:element name="metadata" type="CT_Metadata" />
 <!-- Attribute Groups -->
 <xs:attributeGroup name="AG_Amf">
  <xs:attribute name="unit" type="ST_Unit" />
  <xs:attribute name="version" type="ST_Double" />
  <xs:attribute ref="xml:lang" />
 </xs:attributeGroup>
 <xs:attributeGroup name="AG_Object">
  <xs:attribute name="id" type="xs:integer" />
 </xs:attributeGroup>
 <xs:attributeGroup name="AG_Volume">
  <xs:attribute name="materialid" type="xs:nonNegativeInteger" />
  <xs:attribute name="type" type="ST_VolumeType" />
 </xs:attributeGroup>
 <xs:attributeGroup name="AG_Texture">
  <xs:attribute name="id" type="xs:integer" />
  <xs:attribute name="width" type="xs:nonNegativeInteger" />
  <xs:attribute name="height" type="xs:nonNegativeInteger" />
  <xs:attribute name="depth" type="xs:nonNegativeInteger" />
  <xs:attribute name="tiled" type="xs:boolean" />
  <xs:attribute name="type" type="ST_TextureType" />
 </xs:attributeGroup>
 <xs:attributeGroup name="AG_TexMap">
  <xs:attribute name="rtexid" type="xs:nonNegativeInteger" />
  <xs:attribute name="gtexid" type="xs:nonNegativeInteger" />
  <xs:attribute name="btexid" type="xs:nonNegativeInteger" />
  <xs:attribute name="atexid" type="xs:nonNegativeInteger" />
 </xs:attributeGroup>
 <xs:attributeGroup name="AG_Material">
  <xs:attribute name="id" type="xs:integer" />
 </xs:attributeGroup>
 <xs:attributeGroup name="AG_Composite">
  <xs:attribute name="materialid" type="xs:nonNegativeInteger" />
 </xs:attributeGroup>
 <xs:attributeGroup name="AG_Constellation">
  <xs:attribute name="id" type="xs:integer" />
 </xs:attributeGroup>
 <xs:attributeGroup name="AG_Instance">
  <xs:attribute name="objectid" type="xs:nonNegativeInteger" />
 </xs:attributeGroup>
 <xs:attributeGroup name="AG_Metadata">
  <xs:attribute name="type" type="xs:string" />
 </xs:attributeGroup>
</xs:schema>

Reinoud Zandijk

unread,
Jan 22, 2013, 1:46:16 AM1/22/13
to st...@googlegroups.com
On Sat, Jan 19, 2013 at 03:29:27PM -0800, Jesse McGatha wrote:
> I'm drafting something in XSD. I found a few issues in the spec while I was
> working on this.

Thanks a lot :)

> - Formulae present a challenge for schematizing values that can take
> formulas. These can no longer be strongly typed because there is no
> indicator that the contents are a formula. e.g. the spec would have been
> better to do something like "<color>formula(1/z)</color>" rather than
> "<color>1/z</color>". Because formulas can be complex, there is not really
> a good way to write a regular expression style pattern to describe any
> pattern, so it just has to be a string that the consumer interprets.
> Because there is no regexp pattern that you can write to disambiguate
> between formulas or other values, this means you can't enforce valid ranges
> for non-formulae values either.

if you specify that <color>1</color> is a formula by default then '1' becomes
a constant in the formula. A formula can then be parsed as a series of terms
and products with the usual calculation rules. It can be written down in a
regular expression syntax if one is allowed to use recursion and expressions
but i have no experience with xml schema's nor with their specification
limits.

With regards,
Reinoud

Reply all
Reply to author
Forward
0 new messages