-
Notifications
You must be signed in to change notification settings - Fork 25
Assets and Model
In this section we describe how assets are declared in XML3D.
Note that assets can be declared inside the web document or in external files.
Here an example asset with 3 mesh entries:
<asset id="myAsset" >
<assetmesh src="#meshData1">
</assetmesh>
<assetmesh material=#someShader" transform="#someTransform" >
<data src="#meshData2"></data>
</assetmesh>
<assetmesh type="lines" style="transform: translateY(5px)" >
<data src="#meshData2"></data>
</assetmesh>
</asset>
This asset definition is the equivalent of the following <group>
and <mesh>
combination:
<group id="mygroup" >
<mesh src="#meshData1">
</mesh>
<mesh material=#someShader" transform="#someTransform" >
<data src="#meshData2"></data>
</mesh>
<mesh type="lines" style="transform: translateY(5px)" >
<data src="#meshData2"></data>
</mesh>
</group>
Take aways:
- An
<asset>
may include an arbitrary number of<assetmesh>
elements - An
<assetmesh>
describes a single mesh of that asset and has all attributes and content of a regular<mesh>
element
It is also possible to declare generic data within an asset with the <assetdata>
element. This data can than be shared among <assetmesh>
and other <assetdata>
entries:
<asset id="sharingDataAsset" >
<assetdata name="base" >
<float3 name="position" >...</float3>
<float3 name="normal">...</float3>
<float2 name="texcoord">...</float3>
</assetdata>
<assetmesh includes="base" material="#materialA" >
<int name="index">...</int>
</assetmesh>
<assetmesh includes="base" material="#materialB" >
<int name="index">...</int>
</assetmesh>
</asset>
An <assetdata>
element can be referred by its name via the includes attribute. It is also possible to list several names within includes to add multiple data blocks:
<asset id="sharingDataAsset" >
<assetdata name="base1" >
<!-- Content definition -->
</assetdata>
<assetdata name="base2" >
<!-- Content definition -->
</assetdata>
<!--
The following assetdata includes the base2 assetdata,
extending its data
-->
<assetdata name="base3" includes="base2" >
<!-- Content definition -->
</assetdata>
<assetmesh includes="base1, base2" ></assetmesh>
<assetmesh includes="base1, base3" ></assetmesh>
</asset>
Important: Within an <asset>
there must not be two <assetdata>
entries with the same name.
Take aways:
- An
<asset>
may include an arbitrary number of<assetdata>
elements - Each
<assetdata>
defines generic data and is assigned with a name - Both
<assetmesh>
and<assetdata>
may include the generic data of an<assetdata>
element, by referring it by name within the includes attribute - It's possible to refer multiple
<assetdata>
entries by writing comma-separated names within includes.
It is possible to extend an existing asset with the src attribute of <asset>
:
<!-- First we define our "base" asset -->
<asset id="baseAsset">
<assetdata name="base">
<float3 name="position" >...</float3>
<float3 name="normal" >...</float3>
<assetdata>
<assetmesh name="hair" material="#blondMaterial" includes="base" >
<int name="index">...</int>
</assetmesh>
<assetmesh name="clothes" material="#jeans" includes="base" >
<int name="index">...</int>
</assetmesh>
</asset>
<!-- Now we define a new asset that extends from the "base" asset -->
<asset id="extendedAsset" src="#baseAsset" >
<!-- We take the base entry and add a color vertex attribute -->
<assetdata name="base" >
<float3 name="color">...</float3>
</assetdata>
<!-- We also change the material of the hair assetmesh -->
<assetmesh name="hair" material="#brunetteMaterial" >
</assetmesh>
</asset>
In this example the "extendedAsset" will have both the "hair" and "clothes" assetmesh entries. Since the "base" assetdata has been extend, both assetmesh entries will include the new "color" vertex attribute. Note that it is also possible to extend individual assetmesh entries as long as they have name. In this example we overwrite the material of the "hair" assetmesh.
Take aways:
- It is possible to extend one asset from another asset with the src attribute
- The extended asset will include all assetmesh and assetdata entries of the source asset
- It is possible to extend the data of assetdata and assetmesh entries by redeclaring them with matching name
- In case of assetmesh entries, we can also overwrite the material and transformation
Assets are instantiated with the <model>
element:
<model src="#someAsset" ></model>
<model src="external.xml#asset"></model>
Just as with <asset>
, it is possible to extend the asset within a <model>
:
<model src="#someAsset" >
<assetdata name="base" >
<float3 name="color">...<float3>
</assetdata>
</model>