예제 #1
0
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;
}
예제 #2
0
Node::NodeSP SceneLoader::_LoadCamera(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);

            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->addComponent<CameraComponent>(new CameraComponent(name));
    }

    return node;
}
예제 #3
0
Node::NodeSP SceneLoader::__loadCamera(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);

            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()));
        }

        //add camera component
        auto camera = node->addComponent<CameraComponent>(new CameraComponent(name));
        auto og_camera = camera->getCamera();
        QDomElement clipping = og_component.firstChildElement(SL_CAMERA_CLIPPING);

        //set camera attributes
        og_camera->setPolygonMode(Ogre::PolygonMode(og_component.attribute(SL_CAMERA_POLYGON_MODE).toInt()));
        og_camera->setFOVy(Ogre::Radian(og_component.attribute(SL_CAMERA_FOV).toFloat()));
        og_camera->setNearClipDistance(Ogre::Real(clipping.attribute(SL_CAMERA_CLIPPING_NEAR).toFloat()));
        og_camera->setFarClipDistance(Ogre::Real(clipping.attribute(SL_CAMERA_CLIPPING_FAR).toFloat()));

        camera->enable();
    }

    return node;
}
예제 #4
0
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;
}