Skip to content
Christian Schlinkmann edited this page Mar 31, 2016 · 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"></mesh>

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"></data>

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 to the XML3D code inside of (X)HTML documents. Any resource inside the XML3D scene graph that is referred via document id can be separated into external XML documents (with the exception of <view>). This currently includes the elements <data>, <dataflow>, <material>,and <transform>

Example #1 - Mesh with Shader

XML3D Code (Inline):

<material id="blueShader" model="urn:xml3d:material:phong">
    <float name="ambientIntensity">0.5</float>
    <float3 name="diffuseColor">0 0 1</float3>
    <float3 name="specularColor">0.5 0.5 0.5</float3>
    <float name="shininess">0.2</float>
</material>

<group material="#blueShader" >
    <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>
</group>

XML3D Code (Reference):

<group material="external.xml#blueShader" >
    <mesh type="triangles" src="external.xml#mesh"></mesh>
</group>

File external.xml:

<?xml version="1.0" encoding="UTF-8"?>
<xml3d xmlns="http://www.w3.org/1999/xhtml">

    <material id="blueShader" model="urn:xml3d:material:phong">
        <float name="ambientIntensity">0.5</float>
        <float3 name="diffuseColor">0 0 1</float3>
        <float3 name="specularColor">0.5 0.5 0.5</float3>
        <float name="shininess">0.2</float>
    </material>

    <data id="mesh" >
        <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>
    </data>

</xml3d>

Example #2 - Base Data with submeshes

XML3D Code (Inline):

<data id="base">
    <float3 name="position" >1.84219 -0.437992 -3.88327 ... </float3>
    <float3 name="normal" >0.24334 0.952436 -0.183441 ... </float3>
    <float2 name="texcoord" >0.033889 0.487598 0.0335 ... </float2>
</data>

<mesh type="triangles" >
    <int name="index">0 1 2 ... </int>
    <data src="#base"></data>
</mesh>
<mesh type="triangles" >
    <int name="index">5226 5227 5228 ... </int>
    <data src="#base"></data>
</mesh>

XML3D Code (Reference):

<mesh type="triangles" src="resource/object.xml#mesh1"></mesh>
<mesh type="triangles" src="resource/object.xml#mesh2"></mesh>

File external.xml:

<?xml version="1.0" encoding="UTF-8"?>
<xml3d xmlns="http://www.w3.org/1999/xhtml">
    <data id="base">
        <float3 name="position" >1.84219 -0.437992 -3.88327 ... </float3>
        <float3 name="normal" >0.24334 0.952436 -0.183441 ... </float3>
        <float2 name="texcoord" >0.033889 0.487598 0.0335 ... </float2>
    </data>
    <data id="mesh1">
        <int name="index">0 1 2 ... </int>
        <data src="#base"></data>
    </data>
    <data id="mesh2">
        <int name="index">5226 5227 5228 ... </int>
        <data src="#base"></data>
    </data>
</xml3d>

Note: The external file can use local id references as well.

External Xflow Operators

If your application uses custom Xflow operators these can also be loaded and registered with Xflow from external resources. To do this, simply include a <script> tag with a reference to a JavaScript file containing the operator definition in your <data> or <dataflow> elements that use this operator. For example:

Example #1 inside data elements

<data id="base" compute="position = xflow.randomizePositions(position)">
    <script name="xflow.randomizePositions" src="scripts/randomizePositions.js" type="text/javascript"></script>
    <data src="meshes/meshdata.xml#meshdata"></data>
</data>

Example #2 inside dataflow elements

 <dataflow id="exampleData" out="position"> 
    <float3 param="true" name="position"></float3>
    <float3 param="true" name="offset"></float3>
    <script name="xflow.addA" src="scripts/addA.js" type="text/javascript"></script>
    <script name="xflow.addB" src="scripts/addB.js" type="text/javascript"></script>	
    <compute>
        position = xflow.addA(position, offset);
        position = xflow.addB(position, offset);				
    </compute>
  </dataflow>

Note the name attribute of the script tag. This name must match the name of the operator as it was registered (with Xflow.registerOperator).

Clone this wiki locally