XSIA Importer/Exporter
This JScript example demonstrates writing your own importer/exporter for scene summary data using a XML file format.
The example makes use of the JScript objects, which can be used to emulate object oriented behaviour.
Scene summary files represent a textual (human readable) description of the scene, including referenced models with their
resolutions and deltas, groups, layers and passes. These files can be generated by the plugin to transport scenes or
parts of scenes, to rebuild scenes from their basic elements or to just change key scene data such as paths of models.
Furthermore having an ASCII scene description makes it possible to generate scenes externally, switch models externally etc...
Note: This example implements its own XML parsing mechanism, it does not use parsers such as Microsoft DOM, and
there are limitations to the XML file format used.
Example Files
Location |
|
Files |
xsia_plugin.js |
Running the Example
To install the example
To view the help page for an example
- Do one of the following:
- In the Plug-in Tree, expand the SDK examples workgroup, right-click the example add-on and then click Help.
-
Open a Net View and click to go to Softimage Net local. In the top navigation bar, click add-ons, and then click the SDK example add-on.
To run the exporter example
-
Select Referenced Models, Groups, Layers and/or Passes.
- On the main Softimage menubar, click on File, then on Export and finally on Export XSIA.
-
Input the filename in the file-save dialog and hit OK.
Notes
-
The xsia exporter outputs the an ASCII file looking like this:
<?xml version="1.0" encoding="iso-8859-1"?>
<xsia_file type="AssetSummaryFile" xsi_version="5.0.2005.0920" syntax_version="1.0">
<models>
<model name="Bobby" active_resolution="1">
<resolutions>
<resolution name="Offloaded" filename=""></resolution>
<resolution name="res1" filename="C:/XSI_Project/Models/Bobby.emdl"></resolution>
</resolutions>
<deltas>
<delta name="Delta" target="test" persist_modif="479" filename="C:/XSI_Project/Deltas/bobby_Delta.delta" status="2"></delta>
</deltas>
</model>
</models>
<layers>
<layer name="test" filename="e:/temp/layer_test.Preset" members=""></layer>
</layers>
<passes>
<pass name="Shadow" filename="e:/temp/pass_Shadow.Preset">
<partitions>
<partition name="Background_Objects_Partition" members="Bobby.cube"></partition>
<partition name="Partition" members=""></partition>
<partition name="Background_Lights_Partition" members="light"></partition>
</partitions>
</pass>
</passes>
</xsia_file>
The exporter also creates all of the preset files necessary in the same location as the xsia file.
Running the importer example
To run the importer example
- On the main Softimage menubar, click on File, then on Import and finally on Import XSIA.
-
Input the filename in the file-save dialog and hit OK.
Notes
The XSIA object model
Retrieving a XSIA object
-
In scripting, call the XSIA_GetXSIAObject. It returns a XSIA object.
Object Model Description
-
XSIA Object
The XSIA object respresents the content of a xsia file. It can contain data relevant for referenced models, groups, layers and passes.
Its methods are:
-
Clear() Resets/Clears the object.
-
AddItemFromScene(item) - Adds a description of an item to the xsia, where item can be a referenced model, a group, a layer or a pass.
-
AddItemsFromCollection(coll) - Adds descriptions of items to the xsia, where coll is a XSIACollection of items.
-
AddItemsFromArray(arr) - Adds descriptions of items to the xsia, where arr is a JavaScript Array of items.
-
WriteToFile(filename) - Outputs the descriptions of the XSIA object to a file with the given filename.
-
ReadFromFile(file) - Adds a description of all item of a given XSIA file to the XSIA object.
-
BuildInScene(parent) - Creates all items described in the XSIA object in the scene. parent is typically the current Scene_Root.
Its properties are:
-
type - A string storing "XSIA".
-
fso - An instance of the ActiveXObject "Scripting.FileSystemObject".
-
models - A XSICollection storing XSIAModel objects.
-
groups - A XSICollection storing XSIAGroup objects.
-
layers - A XSICollection storing XSIAGroup objects (for layers though).
-
passes - A XSICollection storing XSIAPass objects.
-
includes - A XSICollection storing nested XSIA objects.
-
XSIAModel Object
The XSIAModel object respresents the description of a referenced model.
Its methods are:
-
Clear() Resets/Clears the object.
-
SetFromScene(model) - Sets the description data of the XSIAModel based on the given model in the scene.
-
BuildInScene(parent) - Builds the model in the scene based on the description of the XSIAModel.
Its properties are:
-
type - A string storing "XSIAModel".
-
name - The name of the model.
-
active_resolution - The index of the active resolution of the referenced model.
-
scnPtr - The object in the scene (if existent)
-
resolutions - A XSICollection storing XSIAResolution objects.
-
deltas - A XSICollection storing XSIADelta objects.
-
XSIAResolution Object
The XSIAResolution object respresents the description of a resolution of a referenced model.
Its methods are:
-
Clear() Resets/Clears the object.
-
SetFromScene(index) - Sets the description data of the XSIAResolution based on the given index (on its parent model).
-
BuildInScene(model) - Builds the resolution on the given model.
Its properties are:
-
type - A string storing "XSIAResolution".
-
name - The name of the resolution.
-
filename - The filename of the EMDL used for this resolution.
-
XSIADelta Object
The XSIADelta object respresents the description of a delta object on a referenced model.
Its methods are:
-
Clear() Resets/Clears the object.
-
SetFromScene(delta) - Sets the description data of the XSIADelta based on the given delta in the scene.
-
BuildInScene(model) - Builds the delta in the scene based on the description of the XSIADelta as a child of the given model.
Its properties are:
-
type - A string storing "XSIADelta".
-
name - The name of the delta.
-
filename - The filename of the delta.
-
scnPtr - The object in the scene (if existent)
-
persist_modif - The value of the persist_modifications on the delta.
-
target - The name of the target model of the delta.
-
status - The value of the 'status' of the delta (offloaded/loaded)
-
XSIAGroup Object
The XSIAGroup object respresents the description of a group/layer/partition.
Its methods are:
-
Clear() Resets/Clears the object.
-
SetFromScene(group) - Sets the description of the XSIAGroup based on the given group/layer/partition in the scene.
-
BuildInScene(parent) - Builds the group in the scene. Normal groups are parent under the given parent.
Its properties are:
-
type - A string storing "XSIAGroup".
-
groupType - A string storing "group","layer" or "partition".
-
name - The name of the group.
-
filename - The filename of the preset used to create this group.
-
members - A XSICollection of all of the members of this group.
-
XSIAPass Object
The XSIAPass object respresents the description of a group/layer/partition.
Its methods are:
-
Clear() Resets/Clears the object.
-
SetFromScene(pass) - Sets the description of the XSIAPass based on the given pass in the scene.
-
BuildInScene() - Builds the pass in the scene.
Its properties are:
-
type - A string storing "XSIAPass".
-
name - The name of the pass.
-
filename - The filename of the preset used to create this pass.
-
partitions - A XSICollection of XSIAGroup objects representing the partitions of the pass.
Example uses of the object model
You cannot run these examples. They are examples of how to use the object model, not runnable scripts.
-
Create a new xsia object, add a model to it and write the file out.
(For this you will need a referenced model in the scene called "model1" and a directory on you machine called "C:/temp"
var xsia = XSIA_GetXSIAObject();
xsia.AddItemFromScene("model1");
xsia.WriteToFile("c:/temp/test.xsia");
-
Open an existing xsia file, get all "ant" - models in it and write them to a new file.
var xsia = XSIA_GetXSIAObject();
xsia.ReadFromFile("c:/temp/allModels.xsia");
var xsia_onlyAnts = XSIA_GetXSIAObject();
var r = new RegExp(/^ant/i);
for(var i=0;i>xsia.models.count;i++)
{
var match = r.exec(xsia.models(i).name);
if(match)
{
xsia_onlyAnts.models.Add(xsia.models(i));
}
}
xsia_onlyAnts.WriteToFile("c:/temp/onlyAnts.xsia");
-
Open an existing xsia file and remap a drive of all used models from drive "s:" to "\\server\share"
var xsia = XSIA_GetXSIAObject();
xsia.ReadFromFile("c:/temp/allModels.xsia");
for(var i=0;i>xsia.models.count;i++)
{
var model = xsia.models(i);
for(var j=0;j>model.resolutions.count)
{
var res = model.resolution(j);
res.filename = res.filename.replace(/s:/i,'\\\\server\\share');
}
}
xsia.WriteToFile("c:/temp/allModels_UNC.xsia");
-
Open two files and include the one file into the other one.
var xsia_1 = XSIA_GetXSIAObject();
var xsia_2 = XSIA_GetXSIAObject();
xsia_1.ReadFromFile("C:/temp/xsia_1.xsia");
xsia_2.ReadFromFile("C:/temp/xsia_1.xsia");
xsia_1.xsia_includes.Add(xsia_2);
xsia_1.WriteToFile("C:/temp/include.xsia");
-
Open an existing XSIA file and import just the passes.
var xsia = XSIA_GetXSIAObject();
xsia.ReadFromFile("C:/temp/passes.xsia");
for(var i=0;i>xsia.passes.count;i++)
{
xsia.passes(i).BuildInScene();
}
Keywords
This example uses the following keywords:
import, export, ascii, xsia, xml,
example, javascript, registercommand,
registermenu