void FDPLoader::loadFDPItem(DOMNode* pFDPItem) { DOMNamedNodeMap* attrList = pFDPItem->getAttributes(); FDPItem* pItem = 0; // get the name (id) DOMNode* attr = attrList->getNamedItem(XercesString("name")); if(attr) { char* name = XMLString::transcode(attr->getNodeValue()); // create a new item (will be deleted in dtor of FDP class) pItem = new FDPItem(name); XMLString::release(&name); } else return; // get the control vertex index attr = attrList->getNamedItem(XercesString("index")); if(attr) { char* index = XMLString::transcode(attr->getNodeValue()); pItem->setControlPoint((unsigned short)atoi(index)); XMLString::release(&index); } // get the affecting mesh name attr = attrList->getNamedItem(XercesString("affects")); if(attr) { char* affects = XMLString::transcode(attr->getNodeValue()); pItem->setAffects(affects); XMLString::release(&affects); } DOMNodeIterator* iterator = m_pDoc->createNodeIterator(pFDPItem, DOMNodeFilter::SHOW_ELEMENT | DOMNodeFilter::SHOW_ATTRIBUTE, NULL, true); // use the tree walker to print out the text nodes. for ( DOMNode* current = iterator->nextNode(); current != 0; current = iterator->nextNode() ) { if(XercesString(current->getNodeName()) == "indices") { DOMNodeList* children = current->getChildNodes(); // we should have only one child, text node, just a safety net here if ( (children->getLength() == 1) && (children->item(0)->getNodeType() == DOMNode::TEXT_NODE) )//(XercesString(children->item(0)->getNodeName()) == "#text") ) { char* pStr = XMLString::transcode(children->item(0)->getNodeValue()); std::string str(pStr); processIndices(str, pItem); XMLString::release(&pStr); } } else if (XercesString(current->getNodeName()) == "influence") // can have multiple of those { // sample: <influence weight="0.25" fap="3" type="RaisedCosInfluenceWaveY" /> DOMNamedNodeMap* influenceAttr = current->getAttributes(); // get the weight float w = toFloat(influenceAttr->getNamedItem(XercesString("weight"))->getNodeValue()); unsigned short fap = (unsigned short)toFloat(influenceAttr->getNamedItem(XercesString("fap"))->getNodeValue()); char* type = XMLString::transcode(influenceAttr->getNamedItem(XercesString("type"))->getNodeValue()); IInfluenceCalculator* pInfluence = InfluenceCalculatorMaker::newInfluenceCalculator(type, w, fap); if(pInfluence) pItem->addInfluenceCalculator(pInfluence); } } m_pFDP->insertItem(pItem); }
/** * Processes all <Mesh> elements from the XML file. * * @param n: <Mesh> element * @param outfile: Binary file, opened as "wb", for output. * * @return: TRUE if successful, FALSE otherwise. */ int processMesh(xmlNode *n, FILE *outfile) { xmlChar name[] = "name"; xmlChar frameCount[] = "frameCount"; xmlChar vertexCount[] = "vertexCount"; xmlChar indexCount[] = "indexCount"; xmlChar specularPower[] = "specularPower"; xmlChar opacity[] = "opacity"; xmlChar twoSided[] = "twoSided"; xmlChar customColor[] = "customColor"; xmlChar diffuseTexture[] = "diffuseTexture"; float32 color[3]; struct MeshHeader mh; uint8 texname[NAMESIZE+1]; int foundFlag = FALSE; xmlNode *texn = NULL; xmlNode *curNode = NULL; /* make sure we're dealing with a <Mesh> element */ assert(strcmp((char*)n->name, "Mesh") == 0); /* populate the MeshHeader structure appropriately */ memset(&mh, 0, sizeof(struct MeshHeader)); strncpy((char*)mh.name, (char*)xmlGetProp(n, name), NAMESIZE-1); mh.frameCount = (uint32)atoi((char*)xmlGetProp(n, frameCount)); mh.vertexCount = (uint32)atoi((char*)xmlGetProp(n, vertexCount)); mh.indexCount = (uint32)atoi((char*)xmlGetProp(n, indexCount)); if (readColorChild(n, "Diffuse", color) == FALSE) return FALSE; mh.diffuseColor[0] = color[0]; mh.diffuseColor[1] = color[1]; mh.diffuseColor[2] = color[2]; if (readColorChild(n, "Specular", color) == FALSE) return FALSE; mh.specularColor[0] = color[0]; mh.specularColor[1] = color[1]; mh.specularColor[2] = color[2]; mh.specularPower = (float32)atof((char*)xmlGetProp(n, specularPower)); mh.opacity = (float32)atof((char*)xmlGetProp(n, opacity)); mh.properties = 0; if (strcmp((char*)xmlGetProp(n, twoSided), "true") == 0) mh.properties += (0x1 << mpfTwoSided); if (strcmp((char*)xmlGetProp(n, customColor), "true") == 0) mh.properties += (0x1 << mpfCustomColor); mh.textures = 0; if (strcmp((char*)xmlGetProp(n, diffuseTexture), "true") == 0) mh.textures = 1; /* write the MeshHeader */ fwrite(&mh, sizeof(struct MeshHeader), 1, outfile); /* if we have a texture, then also write its name */ foundFlag = FALSE; if (mh.textures) { for (texn=n->children; texn; texn = texn->next) { if (texn->type == XML_ELEMENT_NODE) { if (strcmp((char*)texn->name, "Texture") == 0) { foundFlag = TRUE; break; } } } if (foundFlag == FALSE) { printf("Could not find <Texture> element!\n"); return FALSE; } memset(texname, 0, NAMESIZE+1); strncpy((char*)texname, (char*)xmlGetProp(texn, (xmlChar*)"name"), NAMESIZE); fwrite(texname, NAMESIZE, 1, outfile); } /* write out vertices */ foundFlag = FALSE; for (curNode=n->children; curNode; curNode = curNode->next) { if (curNode->type == XML_ELEMENT_NODE) { if (strcmp((char*)curNode->name, "Vertices") == 0) { foundFlag = TRUE; if (processVertices(curNode, outfile, mh.vertexCount) == FALSE) { return FALSE; } } } } if (foundFlag == FALSE) { printf("No <Vertices> found!\n"); return FALSE; } /* write out normals */ foundFlag = FALSE; for (curNode=n->children; curNode; curNode = curNode->next) { if (curNode->type == XML_ELEMENT_NODE) { if (strcmp((char*)curNode->name, "Normals") == 0) { foundFlag = TRUE; if (processNormals(curNode, outfile, mh.vertexCount) == FALSE) { return FALSE; } } } } if (foundFlag == FALSE) { printf("No <Normals> found!\n"); return FALSE; } /* write out texture coordinates */ if (mh.textures) { foundFlag = FALSE; for (curNode=n->children; curNode; curNode = curNode->next) { if (curNode->type == XML_ELEMENT_NODE) { if (strcmp((char*)curNode->name, "TexCoords") == 0) { foundFlag = TRUE; if (processTexcoords(curNode, outfile, mh.vertexCount) == FALSE) { return FALSE; } } } } if (foundFlag == FALSE) { printf("No <TexCoords> found!\n"); return FALSE; } } /* write out indices */ foundFlag = FALSE; for (curNode=n->children; curNode; curNode = curNode->next) { if (curNode->type == XML_ELEMENT_NODE) { if (strcmp((char*)curNode->name, "Indices") == 0) { foundFlag = TRUE; if (processIndices(curNode, outfile, mh.indexCount) == FALSE) { return FALSE; } } } } if (foundFlag == FALSE) { printf("No <Indices> found!\n"); } return TRUE; }