Skip to content
lachsen edited this page Dec 4, 2012 · 13 revisions

XML3D supports several formats for external resources

It is recommended to use external resources especially for large mesh data.

Table of Contents

XML3D JSON Format

The XML3D JSON Format supports generic data content as declared with a <data> element. The format currently only supports integer, bool and float datatypes, but no textures.

Definition

The format's structure with place holders:

{
  "format": "xml3d-json",
  "version": "0.4.0",
  "data": {
    "<INPUT-NAME>" : {
      "type": <TYPE>,
      "seq": [
        {
          "value": <INPUT-DATA-ARRAY>,
          "key" : <INPUT-KEY>
        },
        {
          "value": <INPUT-DATA-ARRAY>,
          "key" : <INPUT-KEY>
        },
        ...
      ]
    },
    "<INPUT-NAME>" : {
      "type": <TYPE>,
      "seq": [
        {
          "value": <INPUT-DATA-ARRAY>,
          "key" : <INPUT-KEY>
        },
        {
          "value": <INPUT-DATA-ARRAY>,
          "key" : <INPUT-KEY>
        },
        ...
      ]
    },
    ...
  }
}
Definitions of place holders:
INPUT-NAME
Name of the input element, corresponding to the name attribute of XML3D Input elements.
TYPE
Type of input element, corresponding to the tagname of XML3D Input elements (e.g. "int", "float", "float3", "float4x4" etc.)
INPUT-DATA-ARRAY
An array with the data of the input. Note: this data is provided as an array and not as string.
INPUT-KEY
The key of the input element, corresponding to the key attribute of XML3D Input elements. The "key" object property can be omitted and will be 0 in that case.

Examples #1 without sequences

XML3D Code (Inline):

<mesh type="triangles" >
	<int name='index'>0 1 2</int>
	<float3 name='position'>-9.480105 -13.51214 10.48553 -7.449495 -14.95502 10.49484 -7.61096 -10.68768 10.55452</float3>
	<float3 name='normal'>-0.4716944 -0.6363447 0.610385 -0.121907 -0.6732379 0.7293075 -0.006795116 -0.08907415 0.9960018 </float3>
</mesh>

XML3D Code (Reference):

<mesh type="triangles" src="external.json" />

File external.json:

{
  "format": "xml3d-json",
  "version": "0.4.0",
  "data": {
    "index" : {
      "type": "int",
      "seq": [
        {
          "value": [0, 1, 2]
        }
      ]
    },
    "position" : {
      "type": "float3",
      "seq": [
        {
          "value": [-9.480105, -13.51214, 10.48553, -7.449495, -14.95502, 10.49484, -7.61096, -10.68768, 10.55452]
        }
      ]
    },
    "normal" : {
      "type": "float3",
      "seq": [
        {
          "value": [-0.4716944, -0.6363447, 0.610385, -0.121907, -0.6732379, 0.7293075, -0.006795116, -0.08907415, 0.9960018 ]
        }
      ]
    }
  }
}

Examples #2 with sequences

XML3D Code (Inline):

<data id="morphData" >
    <float3 name="position" key="0"  >-5 0 5</float3>
    <float3 name="normal" key="0" >0 -1 0</float3>

    <float3 name="position" key="1" >-2.886751 2.113249 2.886751</float3>
    <float3 name="normal" key="1">-0.554395 -0.620718 0.554395</float3>

    <float3 name="position" key="2">-1.341089 4.649148 1.341089</float3>
    <float3 name="normal" key="2">-0.696886 0.169412 0.696886</float3>

    <float3 name="position" key="3" >-6.158403 1.408833 6.158403</float3>
    <float3 name="normal" key="3">-0.141341 -0.979819 0.141341</float3>
<data>

XML3D Code (Reference):

<data id="morphData" src="resource/morphData.json" />

File resource/morphData.json:

{
  "format": "xml3d-json",
  "version": "0.4.0",
  "data": {
    "position" : {
      "type": "float3",
      "seq": [
        {
          "value": [-5, 0, 5],
          "key": 0
        },
        {
          "value": [-2.886751, 2.113249, 2.886751],
          "key": 1
        },
        {
          "value": [-1.341089, 4.649148, 1.341089],
          "key": 2
        },
        {
          "value": [-6.158403, 1.408833, 6.158403],
          "key": 3
        }
      ]
    },
    "normal" : {
      "type": "float3",
      "seq": [
        {
          "value": [0, -1, 0],
          "key": 0
        },
        {
          "value": [-0.554395, -0.620718, 0.554395],
          "key": 1
        },
        {
          "value": [-0.696886, 0.169412, 0.696886],
          "key": 2
        },
        {
          "value": [-0.141341, -0.979819, 0.141341],
          "key": 3
        }
      ]
    }
  }
}

XML3D XML Format

XML3D supports external xml files. The format of external XML files is identical the XML3D code inside the (X)HTML document.

Clone this wiki locally