Models

Model Resources in Chilli Source are loaded from csmodel files. These are created from Collada files, a widely supported asset exchange format which can be exported from most 3d modeling packages, including 3ds Max, Maya or Blender.

Collada files can be converted to csmodel using the ColladaToCSModel java command line tool. This takes the input file path to the Collada file and the output file path to the csmodel file.

java -jar ColladaToCSModel.jar --input Model.DAE --output Model.csmodel

By default Chilli Source uses a left handled Y-up coordinate system, however many model packages are Z-up and some are right handled. To convert between the different coordinate systems the ColladaToCSModel tool allows transformations to be applied to the output model data. Handedness can be changed using the –swaphandedness flag and a Z-up coordinate system can be converted to Y-up (or vice versa) using the –swapyandz flag. As 3ds Max and Blender are left handled and Z-up the following would be needed to convert a model:

java -jar ColladaToCSModel.jar --input Model.DAE --output Model.csmodel --swapyandz

Maya is also Z-up, but right handed so instead this would be needed to convert a model:

java -jar ColladaToCSModel.jar --input Model.DAE --output Model.csmodel --swaphandedness --swapyandz

Once the output csmodel file has been created it should be added to /Content/AppResources. To render a model a Static Mesh Component is used. This is created through the Render Component Factory and simply takes a Mesh and a Material.

//load the model and material
CSCore::ResourcePool* resourcePool = CSCore::Application::Get()->GetResourcePool();
CSRendering::MeshCSPtr model = resourcePool->LoadResource(CSCore::StorageLocation::k_package, "Models/Model.csmodel");
CSRendering::MaterialCSPtr material = resourcePool->LoadResource(CSCore::StorageLocation::k_package, "Material/Model.csmaterial");

//Create the mesh component
CSRendering::RenderComponentFactory* renderComponentFactory = CSCore::Application::Get()->GetSystem();
CSRendering::StaticMeshComponentSPtr modelComponent = renderComponentFactory->CreateStaticMeshComponent(model, material);

//create the model entity and add the model component
CSCore::EntitySPtr modelEntity = CSCore::Entity::Create();
modelEntity->AddComponent(modelComponent);

//add the sprite to the scene
GetScene()->Add(modelEntity);