Results 1 to 6 of 6

Thread: Creating <##any> in an <extra>

  1. #1
    RudeyPunk
    Guest

    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!

  2. #2
    Senior Member
    Join Date
    Jan 2006
    Location
    Foster City, CA
    Posts
    540
    The key to custom COLLADA data in the DOM is the domAny element. Below is some example code that should illustrate how it works.
    Code :
    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:
    Code :
    <?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>

  3. #3
    RudeyPunk
    Guest
    Wow, Thanks Sthomas!

    I don't think I would have ever figured that out quickly.

    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.

  4. #4
    Senior Member
    Join Date
    Jan 2006
    Location
    Foster City, CA
    Posts
    540
    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.

  5. #5
    RudeyPunk
    Guest
    I thought so

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

    Cheers!

  6. #6
    RudeyPunk
    Guest


    I found them!

    I didn't look in the "dae" subdirectories. I guess I had my head up my "dom".


    Cheers.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •