Node * ColladaNode::createInstanceNode(ColladaInstInfo *colInstInfo, domNode *node) { OSG_COLLADA_LOG(("ColladaNode::createInstanceNode id [%s]\n", node->getId())); NodeLoaderState *state = getGlobal()->getLoaderStateAs<NodeLoaderState>(_loaderStateName); OSG_ASSERT(state != NULL); state->pushNodePath(node->getId() != NULL ? node->getId() : ""); state->dumpNodePath(); NodeUnrecPtr retVal = NULL; InstData instData; instData._nodePath = state->getNodePath(); const daeElementRefArray &contents = node->getContents(); // read "transform" child elements in the order // they occur in the document for(UInt32 i = 0; i < contents.getCount(); ++i) { switch(contents[i]->getElementType()) { case COLLADA_TYPE::LOOKAT: handleLookAt(daeSafeCast<domLookat>(contents[i]), instData); break; case COLLADA_TYPE::MATRIX: handleMatrix(daeSafeCast<domMatrix>(contents[i]), instData); break; case COLLADA_TYPE::ROTATE: handleRotate(daeSafeCast<domRotate>(contents[i]), instData); break; case COLLADA_TYPE::SCALE: handleScale(daeSafeCast<domScale>(contents[i]), instData); break; case COLLADA_TYPE::SKEW: handleSkew(daeSafeCast<domSkew>(contents[i]), instData); break; case COLLADA_TYPE::TRANSLATE: handleTranslate(daeSafeCast<domTranslate>(contents[i]), instData); break; } } // assert top and bottom are both set or both unset OSG_ASSERT((instData._topN != NULL && instData._bottomN != NULL) || (instData._topN == NULL && instData._bottomN == NULL) ); // if no xforms were created make a group for this <node> if(instData._topN == NULL && instData._bottomN == NULL) { instData._topN = makeCoredNode<Group>(); instData._bottomN = instData._topN; if(getGlobal()->getOptions()->getCreateNameAttachments() == true && node->getName() != NULL ) { setName(instData._topN, node->getName()); } } // update world matrix before we instantiate child nodes, etc. state->pushMatrix(instData._localMatrix); // add <node> child elements const domNode_Array &nodes = node->getNode_array(); for(UInt32 i = 0; i < nodes.getCount(); ++i) handleNode(nodes[i], instData); // add <instance_node> child elements const domInstance_node_Array &instNodes = node->getInstance_node_array(); for(UInt32 i = 0; i < instNodes.getCount(); ++i) handleInstanceNode(instNodes[i], instData); // add <instance_light> child elements const domInstance_light_Array &instLights = node->getInstance_light_array(); for(UInt32 i = 0; i < instLights.getCount(); ++i) handleInstanceLight(instLights[i], instData); // add <instance_geometry> child elements const domInstance_geometry_Array &instGeos = node->getInstance_geometry_array(); for(UInt32 i = 0; i < instGeos.getCount(); ++i) handleInstanceGeometry(instGeos[i], instData); // add <instance_controller> child elemnts const domInstance_controller_Array &instControllers = node->getInstance_controller_array(); for(UInt32 i = 0; i < instControllers.getCount(); ++i) handleInstanceController(instControllers[i], instData); editInstStore().push_back(instData._topN); _instDataStore .push_back(instData ); retVal = instData._topN; state->popMatrix (); state->popNodePath(); return retVal; }
void ColladaNode::read(void) { OSG_COLLADA_LOG(("ColladaNode::read\n")); domNodeRef node = getDOMElementAs<domNode>(); const daeElementRefArray &contents = node->getContents(); // handle "transform" child elements in the order // they occur in the document for(UInt32 i = 0; i < contents.getCount(); ++i) { switch(contents[i]->getElementType()) { case COLLADA_TYPE::LOOKAT: handleLookAt(daeSafeCast<domLookat>(contents[i])); break; case COLLADA_TYPE::MATRIX: handleMatrix(daeSafeCast<domMatrix>(contents[i])); break; case COLLADA_TYPE::ROTATE: handleRotate(daeSafeCast<domRotate>(contents[i])); break; case COLLADA_TYPE::SCALE: handleScale(daeSafeCast<domScale>(contents[i])); break; case COLLADA_TYPE::SKEW: handleSkew(daeSafeCast<domSkew>(contents[i])); break; case COLLADA_TYPE::TRANSLATE: handleTranslate(daeSafeCast<domTranslate>(contents[i])); break; } } // handle <node> child elements const domNode_Array &nodes = node->getNode_array(); for(UInt32 i = 0; i < nodes.getCount(); ++i) { handleNode(nodes[i]); } // handle <instance_node> child elements const domInstance_node_Array &instNodes = node->getInstance_node_array(); for(UInt32 i = 0; i < instNodes.getCount(); ++i) { handleInstanceNode(instNodes[i]); } // handle <instance_light> child elements const domInstance_light_Array &instLights = node->getInstance_light_array(); for(UInt32 i = 0; i < instLights.getCount(); ++i) { handleInstanceLight(instLights[i]); } // handle <instance_geometry> child elements const domInstance_geometry_Array &instGeos = node->getInstance_geometry_array(); for(UInt32 i = 0; i < instGeos.getCount(); ++i) { handleInstanceGeometry(instGeos[i]); } // handle <instance_controller> child elemnts const domInstance_controller_Array &instControllers = node->getInstance_controller_array(); for(UInt32 i = 0; i < instControllers.getCount(); ++i) { handleInstanceController(instControllers[i]); } // nothing created? build a dummy node if(_topN == NULL) { _topN = makeCoredNode<Group>(); if(getGlobal()->getOptions()->getCreateNameAttachments() == true && node->getName() != NULL ) { setName(_topN, node->getName()); } } if(_bottomN == NULL) { _bottomN = _topN; } }