Workflow for Accessing COLLADA Data
In addition to accessing data with the Crosswalk SDK Semantic Layer, you can supplement or modify the COLLADA content you generate by directly editing the COLLADA xml elements before writing them out. Use the following workflow:
1. Call the new CSLCOLLADAScene::Synchronize function to generate the COLLADA elements.
2. Perform any customizations on the COLLADA elements as needed.
3. Call the CSLCOLLADAScene::Write function with automatic COLLADA xml elements generation disabled to write the file to disk:
CSLCOLLADAScene::Write("<filename>", false);The following three examples are extracted from the DotXSIConverter example (under the <CrosswalkPath>\Examples folder) and demontrate this workflow:
• Example: Adding a COLLADA extra under the visual_scene element
• Example: Adding a COLLADA extra under the "cube" node element
• Example: Adding a COLLADA extra under the "Scene_Material" material element
Example: Adding a COLLADA extra under the visual_scene element
This example demonstrates how to add a COLLADA extra under the visual_scene element using the CSLCOLLADAScene::GetLibrary, CdotXSITemplates::FindByType and CCOLLADATemplate::AddExtra functions.
((CSLCOLLADAScene*)(in_pContext->ftkscene()))->ExportExtra((LONG)Extra.GetValue() ? TRUE : FALSE); // Commit the Semantic Layer to the IO layer - this builds all the COLLADA templates meant to be written in the file ((CSLCOLLADAScene*)(in_pContext->ftkscene()))->Synchronize(); CSLCOLLADALibrary* l_pCOLLADALibraryVisualScenes = ((CSLCOLLADAScene*)in_pContext->ftkscene())->GetLibrary("visual_scenes"); CCOLLADATemplate* l_pCOLLADAVisualScene = NULL; if (l_pCOLLADALibraryVisualScenes) { l_pCOLLADAVisualScene = (CCOLLADATemplate*)l_pCOLLADALibraryVisualScenes->Children().FindByType(CSIBCString("visual_scene")); } if (l_pCOLLADAVisualScene) { CCOLLADATemplate* l_pMyExtra = l_pCOLLADAVisualScene->AddExtra("MyVisualSceneExtra"); l_pMyExtra->AddParam("value", SI_VT_INT, 0); } // Write _SI_CALL(in_pContext->ftkscene()->Write(strFTKFileName, false), "Failed to write file");
Then you can add attributes of parameters to you extra using the COLLADATemplate functions AddAttribute and COLLADATemplate::AddParam. This example produces the following result:
<library_visual_scenes>
<visual_scene id="visual_scenes_0" name="visual_scenes_0">
<extra>
<technique profile="XSI">
<MyVisualSceneExtra>0</MyVisualSceneExtra>
</technique>
</extra>
</visual_scene>
</library_visual_scenes>
Example: Adding a COLLADA extra under the "cube" node element
This example demonstrates how to add a COLLADA extra under the "cube" node element node using the CSLCOLLADAScene::GetRootTemplate, COLLADATemplate::FindNestedTemplateByName, COLLADATemplate::FindNestedTemplateByID or ResolveTemplateURL and CCOLLADATemplate::AddExtra functions.
((CSLCOLLADAScene*)(in_pContext->ftkscene()))->ExportExtra((LONG)Extra.GetValue() ? TRUE : FALSE); // Commit the Semantic Layer to the IO layer - this builds all the COLLADA templates meant to be written in the file ((CSLCOLLADAScene*)(in_pContext->ftkscene()))->Synchronize(); CCOLLADATemplate* l_pRootTemplate = ((CSLCOLLADAScene*)in_pContext->ftkscene())->GetRootTemplate(); CCOLLADATemplate* l_pCOLLADAVisualScene = NULL; CCOLLADATemplate* l_pCOLLADACube = NULL; if (l_pRootTemplate) { // First find an element under which the element you're looking for is located l_pCOLLADAVisualScene = FindNestedTemplateByName(l_pRootTemplate, "visual_scene"); } if (l_pCOLLADAVisualScene) { // Remember that the node id are the full name of the Softimage objects. They're pre-fixed with their model name if there is one l_pCOLLADACube = FindNestedTemplateByID(l_pCOLLADAVisualScene, "cube"); } // You can also find the cube by doing this: // l_pCOLLADACube = ((CSLCOLLADAScene *) in_pContext->m_pScene)->Parser()->ResolveTemplateURL ( "library_visual_scenes", "cube"); if (l_pCOLLADACube) { // then you can add extra, attributes, parameters add or remove elements CCOLLADATemplate* l_pMyCubeExtra = l_pCOLLADACube->AddExtra("MyCubeExtra"); l_pMyCubeExtra->AddAttribute("MyAttibute", "MyAttribValue"); l_pMyCubeExtra->AddParam("MyStringParam", SI_VT_PCHAR, "MyStringParamValue"); l_pMyCubeExtra->AddParam("MyFloatParam", SI_VT_FLOAT, 1.23F); l_pMyCubeExtra->AddParam("MyIntParam", SI_VT_INT, 1); } // Write _SI_CALL(in_pContext->ftkscene()->Write(strFTKFileName, false), "Failed to write file");
This example produces the following result:
<library_visual_scenes>
<visual_scene id="visual_scenes_0" name="visual_scenes_0">
<node id="Scene_Root" name="Scene_Root">
<node id="cylinder" name="cylinder">
<node id="grid" name="grid">
<node id="cube" name="cube">
<instance_geometry url="#geometries_1">
<extra>
<technique profile="XSI">
<MyCubeExtra MyAttibute="MyAttribValue">MyStringParamValue 1.230000 1</MyCubeExtra>
</technique>
</extra>
</node>
</node>
</node>
</node>
</visual_scene>
</library_visual_scenes>
Example: Adding a COLLADA extra under the "Scene_Material" material element
This example demonstrates how to add a COLLADA extra under the "Scene_Material" material element using the CSLCOLLADAScene::GetLibrary, COLLADATemplate::FindNestedTemplateByID and CCOLLADATemplate::AddExtra functions.
((CSLCOLLADAScene*)(in_pContext->ftkscene()))->ExportExtra((LONG)Extra.GetValue() ? TRUE : FALSE); // Commit the Semantic Layer to the IO layer - this builds all the COLLADA templates meant to be written in the file ((CSLCOLLADAScene*)(in_pContext->ftkscene()))->Synchronize(); // First find the library under which the element you're looking for is located CSLCOLLADALibrary* l_pCOLLADALibraryEffects = ((CSLCOLLADAScene*)in_pContext->ftkscene())->GetLibrary("library_effects"); CCOLLADATemplate* l_pCOLLADASceneMaterialFx = NULL; CCOLLADATemplate* l_pCOLLADAprofile_GLSL = NULL; CCOLLADATemplate* l_pGLSLCode = NULL; CCOLLADATemplate* l_pGLSLTechnique = NULL; CCOLLADATemplate* l_pGLSLPass = NULL; CCOLLADATemplate* l_pGLSLShader = NULL; CCOLLADATemplate* l_pGLSLCompilerTarget = NULL; CCOLLADATemplate* l_pGLSLName = NULL; // In the effects library, the name of the effect is the name of the corresponding material with _fx // Find the effect corresponding to the Scene_Material if (l_pCOLLADALibraryEffects) { l_pCOLLADASceneMaterialFx = FindNestedTemplateByID(l_pCOLLADALibraryEffects, "Scene_Material_fx"); } // find the COLLADA element called profile_GLSL if (l_pCOLLADASceneMaterialFx) { l_pCOLLADAprofile_GLSL = FindNestedTemplateByName(l_pCOLLADASceneMaterialFx, "profile_GLSL"); } // create a COLLADA element called profile_GLSL if not found if (!l_pCOLLADAprofile_GLSL) { l_pCOLLADAprofile_GLSL = CreateCOLLADATemplate(l_pCOLLADASceneMaterialFx, "profile_GLSL"); } // add a new technique under the profile_GLSL if (l_pCOLLADAprofile_GLSL) { l_pGLSLCode = CreateCOLLADATemplate(l_pCOLLADAprofile_GLSL, "code"); l_pGLSLCode->AddAttribute("sid", "my_vp"); l_pGLSLCode->AddParam("", SI_VT_PCHAR, "//my GLSL code"); l_pGLSLTechnique = CreateCOLLADATemplate(l_pCOLLADAprofile_GLSL, "technique"); l_pGLSLTechnique->AddAttribute("sid", "default"); l_pGLSLPass = CreateCOLLADATemplate(l_pGLSLTechnique, "pass"); l_pGLSLShader = CreateCOLLADATemplate(l_pGLSLPass, "shader"); l_pGLSLShader->AddAttribute("stage", "VERTEXPROGRAM"); l_pGLSLCompilerTarget = CreateCOLLADATemplate(l_pGLSLShader, "compiler_target"); l_pGLSLCompilerTarget->AddParam("", SI_VT_INT, 110); l_pGLSLName = CreateCOLLADATemplate(l_pGLSLShader, "name"); l_pGLSLName->AddAttribute("source", "my_vp"); l_pGLSLName->AddParam("", SI_VT_PCHAR, "main"); } // Write _SI_CALL(in_pContext->ftkscene()->Write(strFTKFileName, false), "Failed to write file");
This example produces the following result:
<library_effects>
<effect id="Scene_Material_fx" name="Scene_Material_fx">
...
<profile_GLSL>
<code sid="my_vp">//my GLSL code</code>
<technique sid="default">
<pass>
<shader stage="VERTEXPROGRAM">
<compiler_target>110</compiler_target>
<name source="my_vp">main</name>
</shader>
</pass>
</technique>
</profile_GLSL>
</effect>
</library_effects>
Autodesk Crosswalk v5.0