Creating <##any> in an <extra>

Greetings,

Does anyone have a quick example demonstrating how create the “##any” child of a <technique> inside an <extra>?

For example, I’d like to add pivot coordinates to a node :

domExtra *pivot = daeSafeCast<domExtra>(domnode->createAndPlace(COLLADA_ELEMENT_EXTRA));
pivot->setName(“pivot”);
std::string pid = std::string(domnode->getID())+std::string("-pivot");
pivot->setId(pid.c_str());
domTechnique *pTech = daeSafeCast<domTechnique>(pivot->createAndPlace(COLLADA_ELEMENT_TECHNIQUE));
pTech->setProfile(“PivotMan”);
.
.
.

How would I go about adding a domFloat3 or any other information to this technique?

Cheers!

The key to custom COLLADA data in the DOM is the domAny element. Below is some example code that should illustrate how it works.

void testExtra2() {
	daeDocument* document = 0;
	char* file = "file:///c:/models/nodeExtra.dae";
	database->createDocument(file, &document);

	// Create <library_nodes> and <node>
	daeElement* element = document->getDomRoot();
	element = element->createAndPlace(COLLADA_ELEMENT_LIBRARY_NODES);
	domNode* node = daeSafeCast<domNode>(element->createAndPlace(COLLADA_ELEMENT_NODE));
	node->setId("myNode");

	// Create the <extra> and <technique>
	domExtra* extra = daeSafeCast<domExtra>(element->createAndPlace(COLLADA_ELEMENT_EXTRA));
	extra->setType("pivot");
	extra->setId((string(node->getId()) + "-pivot").c_str());
	domTechnique* technique = daeSafeCast<domTechnique>(extra->createAndPlace(COLLADA_ELEMENT_TECHNIQUE));
	technique->setProfile("PivotMan");

	// Add our custom data (note: do not use daeSafeCast with domAny)
	domAny* myElement = (domAny*)technique->createAndPlace("myElement");
	myElement->setAttribute("myAttr", "heya");
	myElement->setValue("0 1 2");

	dae.save(file);
}

This creates a document like this:

<?xml version="1.0"?>
<COLLADA xmlns="http://www.collada.org/2005/11/COLLADASchema" version="1.4.1">
    <library_nodes>
        <node id="myNode"/>
        <extra id="myNode-pivot" type="pivot">
            <technique profile="PivotMan">
                <myElement myAttr="heya">0 1 2</myElement>
            </technique>
        </extra>
    </library_nodes>
</COLLADA>

Wow, Thanks Sthomas!

I don’t think I would have ever figured that out quickly. :wink:

So I went to look for the source code for domAny and lo and behold I could not find any. Does this mean we need to create our own version of domAny? I am assuming the answer to this is yes.

But what confuses me is why would they place a description for this element type in the Reference with defined attributes and not provide the class code? Is there something I am missing about the nature of domAny?

Cheers.

You’re right, it would be pretty silly to talk about domAny in the documentation but not provide it in the code. domAny is implemented in src/dae/domAny.cpp and include/dae/domAny.h. It should be there, otherwise the DOM won’t build correctly.

I thought so :lol:

Thanks for the sanity check. I am going to re-download the libraries and see where I have misplaced that pesky class.

Cheers!

:oops:

I found them!

I didn’t look in the “dae” subdirectories. I guess I had my head up my “dom”.
:wink:

Cheers.