Node::NodeSP SceneLoader::_LoadNode(const QDomElement& og_node, Node::NodeSP dt_parent) { Node::NodeSP node = nullptr; if(!og_node.isNull()) { node = Node::NodeSP(new Node(og_node.attribute(SL_NAME))); if(dt_parent) { dt_parent->addChildNode(node.get()); } else { mScene->addChildNode(node.get()); } QDomElement pos = og_node.firstChildElement(SL_POS); QDomElement rot = og_node.firstChildElement(SL_ROT); QDomElement scale = og_node.firstChildElement(SL_SCALE); node->setPosition(pos.attribute(SL_X).toFloat(), pos.attribute(SL_Y).toFloat(), pos.attribute(SL_Z).toFloat()); node->setRotation(Ogre::Quaternion(rot.attribute(SL_QW).toFloat(), rot.attribute(SL_QX).toFloat(), rot.attribute(SL_QY).toFloat(), rot.attribute(SL_QZ).toFloat())); node->setScale(Ogre::Vector3(scale.attribute(SL_X).toFloat(), scale.attribute(SL_Y).toFloat(), scale.attribute(SL_Z).toFloat())); for(QDomElement node_child = scale.nextSiblingElement(); !node_child.isNull(); node_child = node_child.nextSiblingElement()) { _LoadElement(node_child, node); } } return node; }
Node::NodeSP SceneLoader::_LoadMesh(const QDomElement& og_component, Node::NodeSP dt_node) { Node::NodeSP node = dt_node; if(!og_component.isNull()) { QString name = og_component.attribute(SL_NAME); if(node == nullptr) { node = mScene->addChildNode(new Node(name + "_node")); QDomElement pos = og_component.firstChildElement(SL_POS); QDomElement rot = og_component.firstChildElement(SL_ROT); QDomElement scale = og_component.firstChildElement(SL_SCALE); node->setPosition(pos.attribute(SL_X).toFloat(), pos.attribute(SL_Y).toFloat(), pos.attribute(SL_Z).toFloat()); node->setRotation(Ogre::Quaternion(rot.attribute(SL_QW).toFloat(), rot.attribute(SL_QX).toFloat(), rot.attribute(SL_QY).toFloat(), rot.attribute(SL_QZ).toFloat())); node->setScale(Ogre::Vector3(scale.attribute(SL_X).toFloat(), scale.attribute(SL_Y).toFloat(), scale.attribute(SL_Z).toFloat())); } //entity QDomElement unknown_mesh = og_component.firstChildElement(SL_SCALE).nextSiblingElement(); if(unknown_mesh.nodeName() == SL_ENTITY) { const QDomElement& entity = unknown_mesh; std::shared_ptr<MeshComponent> mesh = node->addComponent<MeshComponent>(new MeshComponent( entity.attribute(SL_MESH_HANDLE), "", entity.attribute(SL_NAME))); for(QDomElement mat = entity.firstChildElement(); !mat.isNull(); mat = mat.nextSiblingElement()) { QString material_handle = mat.attribute(SL_MATERIALNAME); uint32_t index = mat.attribute(SL_INDEX).toUInt(); mesh->getOgreEntity()->getSubEntity(index)->setMaterialName(material_handle.toStdString()); } mesh->setCastShadows(entity.attribute(SL_CAST_SHADOWS).toInt()); } else if(unknown_mesh.nodeName() == SL_PLANE) { //plane const QDomElement& plane = unknown_mesh; if(!plane.isNull()) { //create mesh OgreProcedural::PlaneGenerator() .setSizeX(plane.attribute(SL_SIZEX).toFloat()) .setSizeY(plane.attribute(SL_SIZEY).toFloat()) .setEnableNormals(plane.attribute(SL_ENABLENORMALS).toInt()) .setNumSegX(plane.attribute(SL_SEGMENTSX).toInt()) .setNumSegY(plane.attribute(SL_SEGMENTSY).toInt()) .setNumTexCoordSet(plane.attribute(SL_NUMTEXCOORD).toInt()) .setUTile(plane.attribute(SL_UTILE).toFloat()) .setVTile(plane.attribute(SL_VTILE).toFloat()) .setNormal(Ogre::Vector3( plane.firstChildElement(SL_NORMAL).attribute(SL_X).toFloat(), plane.firstChildElement(SL_NORMAL).attribute(SL_Y).toFloat(), plane.firstChildElement(SL_NORMAL).attribute(SL_Z).toFloat())) .realizeMesh(plane.attribute(SL_NAME).toStdString()); //add entity node->addComponent<MeshComponent>(new MeshComponent( plane.attribute(SL_NAME), plane.attribute(SL_MATERIAL), plane.attribute(SL_NAME))); } } } return node; }