For my exporter I have an unknown number of materials: library images for instance. So I need to declare an dynamic array of domUnits. I was trying to initialize it like any other object but it seems i’m not familiar enough with the API. Basically I tried this:
domAsset::domUnit* librimg = (domAsset::domUnit*)root->add("library_images");
domAsset::domUnit* library = new domAsset::domUnit[number_of_images];
for (size_t i = 0; i < number_of_images; i++) {
if (index[i].tga_diffuse_s > 0) {
library[i] = (domAsset::domUnit*) librimg->add("library");
library[i]->setCharData(image_library_array[i].diffuse);
}
}
I know this isn’t correct but maybe it will help clarify what i’m trying to achieve. Thanks!
domAsset::domUnit is trying to give the unit for measurement unit purposes. (for example, you want to specify translate of 1.0f unit in your document means 1 km).
For most of the time, you won’t need to use it.
To create an exporter to export “a mesh material with texture” you need to export at least 3 groups of things
<library_materials>
<materials> …
<library_effects>
<effect> …
<library_images>
<image> …
Here is a simple code to create 5 <image> elements from scratch.
domCOLLADA * c = dae->getRoot(file_name);
int num_of_images = 5; // let's say you have 5 texture files
domLibrary_images * li = (domLibrary_images*) c->add(COLLADA_ELEMENT_LIBRARY_IMAGES);
for(int i=0; i<num_of_images; i++)
{
domImage * image = (domImage*) li->add(COLLADA_ELEMENT_IMAGE); //add a new image to library
//image->setId(YOUR_UNIQUE_IMAGE_ID_FOR_IMAGE_i); //add more attribute to <image>
domImage::domInit_from * init_from = (domImage::domInit_from*) image->add(COLLADA_ELEMENT_INIT_FROM);
//init_from->setValue(YOUR_IMAGE_PATH_NAME_FOR_IMAGE_i); //add more element or attribute in <init_from>
}
After you set up your <material>, <effect>, and <image>, you have to make sure that they are being referenced correctly. A <material> links to a <effect> that could like to one or more <image>.
This is not easy for someone new to COLLADA. I suggest you to export “a mesh material without texture” first.
You will also need to “bind your mesh with a material in your scene” before you can actually see your result in a rendering scene or reference viewer.
This works, thanks! I didn’t realize the dom had lots of different classes for each subset but it seems obvious now…
Thanks for that! In return for all your help I’m willing to expand your wiki tutorials (its quite lacking). Once i’ve really got the hang of this of coarse heh