Extending ColladaConv

From Horde3D Wiki
Jump to: navigation, search

Contents

Extending ColladaConv

Synopsis: This will be a tutorial on extending ColladaConv to take into account extra features that modellers such as Maya can add to the Collada specifications.

Obviously, the converter ignores these by default, so this tutorial will show you how to edit the converter to pick them up, and do what you like with them.

This will only cover the editing of the converter to understand the extra attributes, not Horde itself!

For the moment - http://www.stuckiegamez.co.uk/misc/Horde/ConverterSource.7z - contains the entire source code that I will be updating to Horde 1.0 Beta 2 throughout this tutorial. The code should match Beta 1. Seeing as I haven't updated this much, I thought I should at least upload ALL the code in case it's useful for someone :)

Disclaimer

This code literally came from Plight of The Weedunks, and has been tweaked just enough to allow it to be integrated into Horde 1.0 Beta 2.Please be aware that this is quite badly written as we only had ten weeks to create the entire game, as well as add bits of engine code, link in with Horde and everything else!

That said, the code does work for the purposes we required.. and it does serve as a basis to build your own implementations from and as it's something I had to figure out, I thought I should share that knowledge with other people - or at least start it so that others may build upon it!

Please feel free to edit this code, fix the bugs, make it your own, and adapt it in any way that you see fit.

Introduction

When creating Plight of The Weedunks, we wanted to create as much of the level as we could in Maya. We wanted to offload the burden of setting up all the scripted objects, lights and and physics attributes from us - the programmers - to the designer.

Luckily, Maya can export it's lights and cameras with ease - but of course they were not picked up by default when we were coding the game! Physics wise, FCollada does support handing out physics data, but we needed a custom solution to fit our needs... so our technical artist coded up a quick little script which literally just added "Additional Attributes" in Maya in a nice little GUI, though we ended up just using it to set up the attribute section and right-clicking Maya's attribute box and adding our own in as needed.

This little tutorial will walk you through what I did to the converter in order to pick up the extra bits we had Maya add to the Collada file, and also show you how we then spat this information out into custom Lua scripts for the engine to pick up on. You may want to do something else with this information, but the methods of getting it back from the Collada Document is exactly the same.

Let There Be Light!

Adding Lights to converter.cpp
  1. void Converter::writeLights( ColladaDocument &doc, const string &name )
    
  2. {
    
  3.         std::string folder;
    
  4.         folder = ( "levels/" + name + "/lights" );
    
  5.         _mkdir( "levels" );
    
  6.         _mkdir( ( "levels/" + name ).c_str() );
    
  7.         _mkdir( folder.c_str() );
    
  8.  
    
  9.         ofstream outf;
    
  10.         outf.open( ( folder + "/" + name + ".lights.lua").c_str(), ios::out );
    
  11.  
    
  12.         outf << "       -- Plight of The Weedunks\n
    
  13.                         -- (c) Team Caffiene 2008\n
    
  14.                         -------------------------\n" << endl;
    
  15.         outf << "-- Light Information for " << name << ".\n";
    
  16.  
    
  17.         outf << "function " << name << "_LIGHTS()" << endl;
    
  18.  
    
  19.         for( unsigned int i = 0; i < _lights.size(); ++i )
    
  20.         {
    
  21.                 string id = _lights[i]->daeInstance->url;
    
  22.                 DaeLight *light = doc.libLights.findLight( id );
    
  23.                 if (light)
    
  24.                 {
    
  25.                         Vec3f trans, rot, scale;
    
  26.                         _lights[i]->matRel.decompose( trans, rot, scale );
    
  27.                         rot.x = radToDeg( rot.x );
    
  28.                         rot.y = radToDeg( rot.y );
    
  29.                         rot.z = radToDeg( rot.z );
    
  30.  
    
  31.                         outf    << "\t" << light->name 
    
  32.                                 << " = Horde:AddLightNode( 0, \"" << light->name 
    
  33.                                 << "\", LightMat, \"LIGHTING\", \"SHADOWMAP\" );"  
    
  34.                                 << endl;
    
  35.  
    
  36.                         outf    << "\tHorde:SetNodeTransform( " 
    
  37.                                 << light->name 
    
  38.                                 << ", " << trans.x << ", " << trans.y << ", " << trans.z 
    
  39.                                 << ", " << rot.x << ", " << rot.y << ", " << rot.z 
    
  40.                                 << ", " << scale.x << ", " << scale.y << ", " << scale.z 
    
  41.                                 << " );" << endl;
    
  42.                         if(light->point)
    
  43.                         {
    
  44.                                 outf    << "\tHorde:SetNodeParamFloat( " 
    
  45.                                         << light->name 
    
  46.                                         << ", \"FOV\", 360 );" 
    
  47.                                         << endl;
    
  48.  
    
  49.                                 outf    << "\tHorde:SetNodeParamFloat( " 
    
  50.                                         << light->name 
    
  51.                                         << ", \"Radius\", 100 );" 
    
  52.                                         << endl;
    
  53.                         }
    
  54.                         if(light->spot)
    
  55.                         {
    
  56.                                 outf    << "\tHorde:SetNodeParamFloat( " 
    
  57.                                         << light->name 
    
  58.                                         << ", \"FOV\", " << light->outer_cone << " );" 
    
  59.                                         << endl;
    
  60.  
    
  61.                                 outf    << "\tHorde:SetNodeParamFloat( " 
    
  62.                                         << light->name 
    
  63.                                         << ", \"Radius\", 400 );" 
    
  64.                                         << endl;
    
  65.                         }
    
  66.                         outf    << "\tHorde:SetNodeParamInt( " 
    
  67.                                 << light->name 
    
  68.                                 << ", \"ShadowMapCount\", 3 );" 
    
  69.                                 << endl;
    
  70.  
    
  71.                         outf    << "\tHorde:SetNodeParamFloat( " 
    
  72.                                 << light->name 
    
  73.                                 << ", \"ShadowSplitLambda\", 0.9 );" 
    
  74.                                 << endl;
    
  75.  
    
  76.                         outf    << "\tHorde:SetNodeParamFloat( " 
    
  77.                                 << light->name 
    
  78.                                 << ", \"ShadowMapBias\", 0.001 );" 
    
  79.                                 << endl;
    
  80.  
    
  81.                         outf    << "\tHorde:SetNodeParamFloat( " 
    
  82.                                 << light->name 
    
  83.                                 << ", \"Col_R\", " << light->r * light->intensity << " );" 
    
  84.                                 << endl;
    
  85.  
    
  86.                         outf    << "\tHorde:SetNodeParamFloat( " 
    
  87.                                 << light->name 
    
  88.                                 << ", \"Col_G\", " << light->g * light->intensity << " );" 
    
  89.                                 << endl;
    
  90.  
    
  91.                         outf    << "\tHorde:SetNodeParamFloat( " 
    
  92.                                 << light->name 
    
  93.                                 << ", \"Col_B\", " << light->b * light->intensity << " );" 
    
  94.                                 << endl;
    
  95.  
    
  96.                         outf    << endl;
    
  97.                 }
    
  98.         }
    
  99.  
    
  100.         outf << "end" << endl;
    
  101.         outf.close();
    
  102. }
    

Cameras For All

Adding Cameras to converter.cpp
  1. void Converter::writeCameras( ColladaDocument &doc,const string &name )
    
  2. {
    
  3.         std::string folder;
    
  4.         folder = ( "levels/" + name + "/cameras" );
    
  5.         _mkdir( folder.c_str()  );
    
  6.         ofstream outf;
    
  7.         outf.open( (folder + "/" + name + ".camera.lua").c_str(), ios::out );
    
  8.  
    
  9.         outf << "       -- Plight of The Weedunks\n
    
  10.                         -- (c) Team Caffiene 2008\n
    
  11.                         -------------------------\n" << endl;
    
  12.  
    
  13.         outf << "-- Camera Information for " << name << ".\n";
    
  14.  
    
  15.         outf << "function " << name << "_CAMERAS()" << endl;
    
  16.  
    
  17.         for( unsigned int i = 0; i < _cameras.size(); ++i )
    
  18.         {
    
  19.                 string id = _cameras[i]->daeInstance->url;
    
  20.                 DaeCamera *camera = doc.libCameras.findCamera( id );
    
  21.                 if (camera)
    
  22.                 {
    
  23.                         Vec3f trans, rot, scale;
    
  24.                         _cameras[i]->matRel.decompose( trans, rot, scale );
    
  25.                         rot.x = radToDeg( rot.x );
    
  26.                         rot.y = radToDeg( rot.y );
    
  27.                         rot.z = radToDeg( rot.z );
    
  28.  
    
  29.                         outf    << "\t" << camera->name << " = Horde:AddCameraNode( 0, \"" 
    
  30.                                 << camera->name << "\", PipeRes );" 
    
  31.                                 << endl;
    
  32.  
    
  33.                         outf    << "\tHorde:SetupCameraView( " << camera->name << ", " 
    
  34.                                 << camera->yfov << ", " 
    
  35.                                 << camera->aspect << ", " 
    
  36.                                 << camera->znear << ", " 
    
  37.                                 << camera->zfar << ");" 
    
  38.                                 << endl;
    
  39.  
    
  40.                         outf    << "\tHorde:SetNodeTransform( " 
    
  41.                                 << camera->name << ", " 
    
  42.                                 << trans.x << ", " << trans.y << ", " << trans.z << ", " 
    
  43.                                 << rot.x << ", " << rot.y << ", " << rot.z << ", " 
    
  44.                                 << scale.x << ", " << scale.y << ", " << scale.z << " );" 
    
  45.                                 << endl;
    
  46.  
    
  47.                         outf    << endl;
    
  48.                 }
    
  49.         }
    
  50.  
    
  51.         outf << "end" << endl;
    
  52.         outf.close();
    
  53.  
    
  54. }
    

Scripted Physics and Objects

Adding Entity Info to converter.cpp
  1. void Converter::writePhysics(ColladaDocument &doc, const string &name )
    
  2. {
    
  3.         std::string folder;
    
  4.         folder = ( "levels/" + name + "/physics/static" );
    
  5.         _mkdir( ("levels/" + name + "/physics").c_str() );
    
  6.         _mkdir( folder.c_str() );
    
  7.         ofstream outf, outg, outh;
    
  8.         outf.open( ( folder + "/" + name + ".physics.static.lua" ).c_str(), ios::out );
    
  9.         outg.open( "StaticMovingMaterials.txt", ios::out );
    
  10.         outh.open( "DynamicMaterials.txt", ios::out );
    
  11.  
    
  12.         outf << "       -- Plight of The Weedunks\n
    
  13.                         -- (c) Team Caffiene 2008\n
    
  14.                         -------------------------\n" << endl;
    
  15.  
    
  16.         outf << "-- Physics Information for " << name << ".\n";
    
  17.         outf << "function " << name << "_STATIC_PHYSICS()" << endl;
    
  18.  
    
  19.         for( unsigned int i = 0; i < _meshes.size(); ++i )
    
  20.         {
    
  21.                 Vec3f trans, rot, scale;
    
  22.                 _meshes[i]->matRel.decompose( trans, rot, scale );
    
  23.                 rot.x = -radToDeg( rot.x );
    
  24.                 rot.y = -radToDeg( rot.y );
    
  25.                 rot.z = -radToDeg( rot.z );
    
  26.  
    
  27.                 if (strcmp( _meshes[i]->daeNode->physicsObjectType.c_str(), "static" ) == 0)
    
  28.                 {
    
  29.                         outg << _meshes[i]->daeNode->physicsMaterial << endl;
    
  30.                         outf    << "\t" << _meshes[i]->daeNode->name << "_static = ODE:CreateStaticBox( " 
    
  31.                                 << scale.x << ", " << scale.y << ", " << scale.z << ", " 
    
  32.                                 << trans.x << ", " << trans.y << ", " << trans.z << ", " 
    
  33.                                 << rot.x << ", " << rot.y << ", " << rot.z << ", \"" 
    
  34.                                 << _meshes[i]->daeNode->physicsMaterial << "\" );" 
    
  35.                                 << endl;
    
  36.  
    
  37.                         outf    << endl;
    
  38.                 }
    
  39.         }
    
  40.  
    
  41.         outf << "end" << endl;
    
  42.         outf << endl;
    
  43.         outf.close();
    
  44.  
    
  45.         folder = ( "levels/" + name + "/physics/dynamic" );
    
  46.         _mkdir( folder.c_str() );
    
  47.         outf.open( ( folder + "/" + name + ".physics.dynamic.lua").c_str(), ios::out );
    
  48.  
    
  49.         outf << "       -- Plight of The Weedunks\n
    
  50.                         -- (c) Team Caffiene 2008\n
    
  51.                         -------------------------\n" << endl;
    
  52.  
    
  53.         outf << "-- Physics Information for " << name << ".\n";
    
  54.         outf << "function " << name << "_DYNAMIC_PHYSICS()" << endl;
    
  55.  
    
  56.         for( unsigned int i = 0; i < _meshes.size(); ++i )
    
  57.         {
    
  58.                 Vec3f trans, rot, scale;
    
  59.                 _meshes[i]->matRel.decompose( trans, rot, scale );
    
  60.                 rot.x = -radToDeg( rot.x );
    
  61.                 rot.y = -radToDeg( rot.y );
    
  62.                 rot.z = -radToDeg( rot.z );
    
  63.  
    
  64.                 if (strcmp( _meshes[i]->daeNode->physicsObjectType.c_str(), "dynamic" ) == 0)
    
  65.                 {
    
  66.                         outh << _meshes[i]->daeNode->physicsMaterial << endl;
    
  67.                         outf    << "\t" << _meshes[i]->daeNode->name << "_dynamic = ODE:CreateDynamicBox( " 
    
  68.                                 << scale.x << ", " << scale.y << ", " << scale.z << ", " 
    
  69.                                 << trans.x << ", " << trans.y << ", " << trans.z << ", " 
    
  70.                                 << rot.x << ", " << rot.y << ", " << rot.z << ", 10, \"" 
    
  71.                                 << _meshes[i]->daeNode->physicsMaterial << "\" );" 
    
  72.                                 << endl;
    
  73.  
    
  74.                         outf    << "\tHorde:FindNodes( LevelMod, \"" << _meshes[i]->daeNode->name << "\", \"Mesh\" );" 
    
  75.                                 << endl;
    
  76.  
    
  77.                         outf    << "\tnodeHandle = Horde:GetNodeFindResult(0);" << endl;
    
  78.  
    
  79.                         outf    << "\t" << name << "_DYNAMIC = { 
    
  80.                                 next = " << name << "_DYNAMIC, 
    
  81.                                 node = nodeHandle, 
    
  82.                                 physics = " << _meshes[i]->daeNode->name << "_dynamic 
    
  83.                                 };" << endl;
    
  84.  
    
  85.                         outf << endl;
    
  86.                 }
    
  87.         }
    
  88.  
    
  89.         outf << "end" << endl;
    
  90.         outf << endl;
    
  91.         outf.close();
    
  92.  
    
  93.         folder = ( "levels/" + name + "/physics/scripted" );
    
  94.         _mkdir( folder.c_str() );
    
  95.  
    
  96.         for( unsigned int i = 0; i < _meshes.size(); ++i )
    
  97.         {
    
  98.                 if (!_meshes[i]->daeNode->physicsMaterial.empty())
    
  99.                 {
    
  100.                         Vec3f trans, rot, scale;
    
  101.                         _meshes[i]->matRel.decompose( trans, rot, scale );
    
  102.                         rot.x = -radToDeg( rot.x );
    
  103.                         rot.y = -radToDeg( rot.y );
    
  104.                         rot.z = -radToDeg( rot.z );
    
  105.  
    
  106.                         if ((strcmp( _meshes[i]->daeNode->physicsObjectType.c_str(), "moving" ) == 0) 
    
  107.                         || (strcmp( _meshes[i]->daeNode->physicsObjectType.c_str(), "scripted" ) == 0))
    
  108.                         {
    
  109.                                 outf.open( ( folder + "/" + _meshes[i]->daeNode->name + ".physics.lua").c_str(), ios::out );
    
  110.                                 outg << _meshes[i]->daeNode->physicsMaterial << endl;
    
  111.  
    
  112.                                 outf << "       -- Plight of The Weedunks\n
    
  113.                                                 -- (c) Team Caffiene 2008\n
    
  114.                                                 -------------------------\n" << endl;
    
  115.  
    
  116.                                 outf << "-- Physics Information for " <<  _meshes[i]->daeNode->name << ".\n";
    
  117.                                 outf << "function " << _meshes[i]->daeNode->name << "_OBJECT ()" << endl;
    
  118.                                 outf    << "\t" << _meshes[i]->daeNode->name 
    
  119.                                         << "_scripted = ODE:CreateMovingBox( " 
    
  120.                                         << scale.x << ", " << scale.y << ", " << scale.z << ", " 
    
  121.                                         << trans.x << ", " << trans.y << ", " << trans.z << ", " 
    
  122.                                         << rot.x << ", " << rot.y << ", " << rot.z << ", \"" 
    
  123.                                         << _meshes[i]->daeNode->physicsMaterial << "\" );" 
    
  124.                                         << endl;
    
  125.  
    
  126.                                 outf    << "\tHorde:FindNodes( LevelMod, \"" 
    
  127.                                         << _meshes[i]->daeNode->name << "\", \"Mesh\" );" 
    
  128.                                         << endl;
    
  129.  
    
  130.                                 outf << "\tnodeHandle = Horde:GetNodeFindResult(0);" << endl;
    
  131.  
    
  132.                                 outf << "\t" << name << "_SCRIPTED = { 
    
  133.                                         next = " << name << "_SCRIPTED, 
    
  134.                                         node = nodeHandle, 
    
  135.                                         physics = " << _meshes[i]->daeNode->name << "_scripted 
    
  136.                                         };" << endl;
    
  137.  
    
  138.                                 outf << "\t" << _meshes[i]->daeNode->name << "_posX = " << trans.x << ";" << endl;
    
  139.                                 outf << "\t" << _meshes[i]->daeNode->name << "_posY = " << trans.y << ";" << endl;
    
  140.                                 outf << "\t" << _meshes[i]->daeNode->name << "_posZ = " << trans.z << ";" << endl;
    
  141.                                 outf << "\t" << _meshes[i]->daeNode->name << "_rotX = " << rot.x << ";" << endl;
    
  142.                                 outf << "\t" << _meshes[i]->daeNode->name << "_rotY = " << rot.y << ";" << endl;
    
  143.                                 outf << "\t" << _meshes[i]->daeNode->name << "_rotZ = " << rot.z << ";" << endl;
    
  144.  
    
  145.                                 outf << "end" << endl;
    
  146.                                 outf << endl;
    
  147.                                 outf.close();
    
  148.                         }
    
  149.                 }
    
  150.         }
    
  151.         outg.close();
    
  152.         outh.close();
    
  153. }
    

Building The Level Loader

Adding Level Loader Info to converter.cpp
  1. void Converter::writeLevel( ColladaDocument &doc,const string &name )
    
  2. {
    
  3.         std::string folder;
    
  4.         folder = ( "levels/" + name );
    
  5.         ofstream outf;
    
  6.         outf.open( ( folder + "/" + name + ".load.lua" ).c_str(), ios::out );
    
  7.  
    
  8.         outf << "       -- Plight of The Weedunks\n
    
  9.                         -- (c) Team Caffiene 2008\n
    
  10.                         -------------------------\n" << endl;
    
  11.  
    
  12.         outf << "-- Load Level Data" << endl;
    
  13.         outf << "dofile (\"data/scripts/" << folder << "/" << name << ".spawners.lua\");" << endl;
    
  14.         outf << "dofile (\"data/scripts/" << folder << "/" << name << ".targets.lua\");" << endl;
    
  15.         outf << "dofile (\"data/scripts/" << folder << "/" << name << ".waypoints.lua\");" << endl;
    
  16.         outf << "dofile (\"data/scripts/" << folder << "/cameras/" << name << ".camera.lua\");" << endl;
    
  17.         outf << "dofile (\"data/scripts/" << folder << "/lights/" << name << ".lights.lua\");" << endl;
    
  18.         outf << "dofile (\"data/scripts/" << folder << "/physics/static/" << name << ".physics.static.lua\");" << endl;
    
  19.         outf << "dofile (\"data/scripts/" << folder << "/physics/dynamic/" << name << ".physics.dynamic.lua\");" << endl;
    
  20.  
    
  21.         for( unsigned int i = 0; i < _meshes.size(); ++i )
    
  22.                 if (!_meshes[i]->daeNode->physicsMaterial.empty())
    
  23.                         if ((strcmp( _meshes[i]->daeNode->physicsObjectType.c_str(), "moving" ) == 0) 
    
  24.                         || (strcmp( _meshes[i]->daeNode->physicsObjectType.c_str(), "scripted" ) == 0))
    
  25.                                 outf    << "dofile (\"data/scripts/" 
    
  26.                                         << folder 
    
  27.                                         << "/physics/scripted/" 
    
  28.                                         << _meshes[i]->daeNode->name 
    
  29.                                         << ".physics.lua\");" 
    
  30.                                         << endl;
    
  31.  
    
  32.         outf << "\n-- Call Function\n" << endl;
    
  33.         outf << "function " << name << "_LOAD()" << endl;
    
  34.         outf << "\t" << name << "_CAMERAS();" << endl;
    
  35.         outf << "\t" << name << "_LIGHTS();" << endl;
    
  36.         outf << "\t" << name << "_STATIC_PHYSICS();" << endl;
    
  37.         outf << "\t" << name << "_DYNAMIC_PHYSICS();" << endl;
    
  38.         outf << "\t" << "setWaypoints();" << endl;
    
  39.         outf << "\t" << "createSpawners();" << endl;
    
  40.         outf << "\t" << "setTargetables();" << endl;
    
  41.  
    
  42.         for( unsigned int i = 0; i < _meshes.size(); ++i )
    
  43.                 if (!_meshes[i]->daeNode->physicsMaterial.empty())
    
  44.                         if ((strcmp( _meshes[i]->daeNode->physicsObjectType.c_str(), "moving" ) == 0) 
    
  45.                         || (strcmp( _meshes[i]->daeNode->physicsObjectType.c_str(), "scripted" ) == 0))
    
  46.                                 outf << "\t" << _meshes[i]->daeNode->name << "_OBJECT();" << endl;
    
  47.  
    
  48.         outf << "end" << endl;
    
  49.  
    
  50.         outf.close();
    
  51.  
    
  52.         outf.open( ( folder + "/" + name + ".update.lua" ).c_str(), ios::out );
    
  53.         outf << "       -- Plight of The Weedunks\n
    
  54.                         -- (c) Team Caffiene 2008\n
    
  55.                         -------------------------\n" << endl;
    
  56.  
    
  57.         outf << name << "_SCRIPTED = nil;" << endl;
    
  58.         outf << name << "_DYNAMIC = nil;\n" << endl;
    
  59.  
    
  60.         outf << "function " << name << "_UPDATE()\n" << endl;
    
  61.         outf << "\tlocal list = " << name << "_DYNAMIC;" << endl;
    
  62.         outf << "\twhile list do" << endl;
    
  63.         outf << "\t\tHorde:SetNodeTransformODEDynamicNoScale( list.node, list.physics );" << endl;
    
  64.         outf << "\t\tlist = list.next;" << endl;
    
  65.         outf << "\tend" << endl;
    
  66.  
    
  67.         outf << "\tlocal list = " << name << "_SCRIPTED;" << endl;
    
  68.         outf << "\twhile list do" << endl;
    
  69.         outf << "\t\tHorde:SetNodeTransformODEScriptedNoScale( list.node, list.physics );" << endl;
    
  70.         outf << "\t\tlist = list.next;" << endl;
    
  71.         outf << "\tend" << endl;
    
  72.         outf << "end" << endl;
    
  73.  
    
  74.         outf.close();
    
  75.  
    
  76.         outf.open( ( folder + "/" + name + ".targets.lua" ).c_str(), ios::out );
    
  77.         outf << "       -- Plight of The Weedunks\n
    
  78.                         -- (c) Team Caffiene 2008\n
    
  79.                         -------------------------\n" << endl;
    
  80.  
    
  81.         outf << "function setTargetables()" << endl;
    
  82.         for( unsigned int i = 0; i < _meshes.size(); ++i )
    
  83.                 if (!_meshes[i]->daeNode->targetable.empty())
    
  84.                 {
    
  85.                         Vec3f trans, rot, scale;
    
  86.                         _meshes[i]->matRel.decompose( trans, rot, scale );
    
  87.                         rot.x = -radToDeg( rot.x );
    
  88.                         rot.y = -radToDeg( rot.y );
    
  89.                         rot.z = -radToDeg( rot.z );
    
  90.  
    
  91.                         outf << "\tTARGETS = { 
    
  92.                         next = TARGETS,  
    
  93.                         x = " << trans.x << ", y = " << trans.y << ", z = " << trans.z << ", 
    
  94.                         name = \"" << _meshes[i]->daeNode->name << "\" 
    
  95.                         };" << endl;
    
  96.                 }
    
  97.         outf << "end" << endl;
    
  98.         outf.close();
    
  99.  
    
  100.         outf.open( ( folder + "/" + name + ".waypoints.lua" ).c_str(), ios::out );
    
  101.         outf << "       -- Plight of The Weedunks\n
    
  102.                         -- (c) Team Caffiene 2008\n
    
  103.                         -------------------------\n" << endl;
    
  104.  
    
  105.         outf << "function setWaypoints()" << endl;
    
  106.         for( unsigned int i = 0; i < _meshes.size(); ++i )
    
  107.                 if (!_meshes[i]->daeNode->waypointType.empty())
    
  108.                 {
    
  109.                         Vec3f trans, rot, scale;
    
  110.                         _meshes[i]->matRel.decompose( trans, rot, scale );
    
  111.                         rot.x = -radToDeg( rot.x );
    
  112.                         rot.y = -radToDeg( rot.y );
    
  113.                         rot.z = -radToDeg( rot.z );
    
  114.  
    
  115.                         outf    << "\tAI:AddWayPoint( " << _meshes[i]->daeNode->waypointType << ", \"" 
    
  116.                                 << _meshes[i]->daeNode->name << "\", " 
    
  117.                                 << trans.x << ", " << trans.y << ", " << trans.z << " ); " 
    
  118.                                 << endl;
    
  119.  
    
  120.                 }
    
  121.         outf << "end" << endl;
    
  122.         outf.close();
    
  123.  
    
  124.         outf.open( ( folder + "/" + name + ".spawners.lua" ).c_str(), ios::out );
    
  125.         outf << "       -- Plight of The Weedunks\n
    
  126.                         -- (c) Team Caffiene 2008\n
    
  127.                         -------------------------\n" << endl;
    
  128.  
    
  129.         outf << "function createSpawners()" << endl;
    
  130.         for( unsigned int i = 0; i < _meshes.size(); ++i )
    
  131.                 if (!_meshes[i]->daeNode->SpawnDelay.empty())
    
  132.                 {
    
  133.                         Vec3f trans, rot, scale;
    
  134.                         _meshes[i]->matRel.decompose( trans, rot, scale );
    
  135.                         rot.x = -radToDeg( rot.x );
    
  136.                         rot.y = -radToDeg( rot.y );
    
  137.                         rot.z = -radToDeg( rot.z );
    
  138.  
    
  139.                         outf << "\tSPAWNERS = { 
    
  140.                         next = SPAWNERS, 
    
  141.                         x = " << trans.x << ", y = " << trans.y + scale.y/2 + 5 << ", z = " << trans.z << ", 
    
  142.                         numofbert = " << _meshes[i]->daeNode->NumberofBert << ", 
    
  143.                         numofernie = " << _meshes[i]->daeNode->NumberofErnie << ", 
    
  144.                         timer = 0, 
    
  145.                         bert = 0, 
    
  146.                         ernie = 0, 
    
  147.                         delay = " << _meshes[i]->daeNode->SpawnDelay << ", 
    
  148.                         name = \"" << _meshes[i]->daeNode->name << "\" 
    
  149.                         };" << endl;
    
  150.                 }
    
  151.         outf << "end" << endl;
    
  152.         outf.close();
    
  153. }
    
Extending ColladaConv
H3DPlaceHolder.png
Example on Extending ColladaConv
Version: 0.0
Compatible with Horde3D: 1.0 beta2
Release date: W.I.P
Author(s): Steven "Stuckie" Campbell
Personal tools