コード例 #1
0
void gkOgreParticleEmitter::_initParticle(Particle* pParticle)
{
	GK_ASSERT(m_creator);

	gkParticleSettingsProperties& props = m_creator->getParticleProperties();

	ParticleEmitter::_initParticle(pParticle);

	pParticle->direction = props.m_velocity;

	if (mParent)
	{
		Ogre::Any any = mParent->getUserAny();
		if (!any.isEmpty())
		{
			gkOgreParticleObject* pobj = Ogre::any_cast<gkOgreParticleObject*>(any);
			gkMesh* mesh = pobj->getParticleProperties().m_mesh;
			if (mesh)
			{

				if (props.m_emitfrom == gkParticleSettingsProperties::EF_VERTS)
				{
					UTsize count = mesh->getMeshVertexCount();
					int i = rand() % count;
					const gkVertex& v = mesh->getMeshVertex(i);

					pParticle->position = v.co;
					
					if (props.m_velNormal != 0)
						pParticle->direction = (pParticle->direction + v.no * props.m_velNormal)/2; 
				}
				else // if (props.m_emitfrom == gkParticleSettingsProperties::EF_FACES)
				{
					UTsize count = mesh->getMeshTriFaceCount();
					int i = rand() % count;
					gkTriFace face = mesh->getMeshTriFace(i);

					pParticle->position = randomInTri(face.p);

					if (props.m_velNormal != 0)
						pParticle->direction = (pParticle->direction + face.normal() * props.m_velNormal)/2; 
				}
			}
		}
	}


	//setStartTime(props.m_start);
			
	//setTimeToLive(props.m_lifetime);
	//setDirection(props.m_velocity);
	//setParticleVelocity(props.m_velocity.length());

	//pParticle->position = getPosition();
	//pParticle->setDimensions(props.m_size, props.m_size);
	
	//genEmissionColour(pParticle->colour);
    //genEmissionDirection(pParticle->direction);
	//genEmissionVelocity(pParticle->direction); //props.m_velocity

	gkParticleVisualData* data = static_cast<gkParticleVisualData*>(pParticle->getVisualData());
	if (data)
		data->m_initDir = pParticle->direction;

	gkScalar size = gkMax(0.01f, Ogre::Math::RangeRandom(props.m_size - props.m_sizeRandom, props.m_size + props.m_sizeRandom));
	pParticle->setDimensions(size, size);
	pParticle->timeToLive = pParticle->totalTimeToLive = props.m_lifetime; //genEmissionTTL();
}
コード例 #2
0
ファイル: OgreTools.cpp プロジェクト: banduladh/levelfour
//!
//! Deletes a whole scene node tree (including attached objects).
//!
//! \param sceneNode The scene node containing the tree to delete.
//! \param sceneManager The scene manager to use for destroying the scene node.
//! \param deleteRoot Flag to control whether to delete the given scene node.
//!
void OgreTools::deepDeleteSceneNode ( Ogre::SceneNode *sceneNode, Ogre::SceneManager *sceneManager /* = 0 */, bool deleteRoot /* = false */ )
{
    // make sure the given scene node is valid
    if (!sceneNode) {
        Log::error("The given scene node is invalid.", "OgreTools::deepDeleteSceneNode");
        return;
    }

    // make sure a valid scene manager is available
    if (!sceneManager)
        sceneManager = sceneNode->getCreator();
    if (!sceneManager) {
        Log::error("No valid scene manager available.", "OgreTools::deepDeleteSceneNode");
        return;
    }

    // iterate over the list of attached objects
    Ogre::SceneNode::ObjectIterator objectIterator = sceneNode->getAttachedObjectIterator();
    while (objectIterator.hasMoreElements()) {
        Ogre::MovableObject *movableObject = objectIterator.getNext();
        sceneNode->detachObject(movableObject);
        Ogre::SceneManager *movableSceneManager = movableObject->_getManager();
        if (!movableSceneManager) {
            Log::error("The Ogre scene manager could not be obtained.", "OgreTools::deepDeleteSceneNode");
            return;
        }
        Ogre::Any customData = movableObject->getUserAny();
        if (!customData.isEmpty()) {
            OgreContainer *ogreContainer = Ogre::any_cast<OgreContainer *>(customData);
            if (ogreContainer) {
                delete ogreContainer;
                ogreContainer = 0;
            }
        }
        movableSceneManager->destroyMovableObject(movableObject);
    }

    // iterate over the list of child nodes
    Ogre::SceneNode::ChildNodeIterator childNodeIterator = sceneNode->getChildIterator();
    while (childNodeIterator.hasMoreElements()) {
        Ogre::SceneNode *childSceneNode = dynamic_cast<Ogre::SceneNode *>(childNodeIterator.getNext());
        if (childSceneNode) {
            Ogre::Any customData = childSceneNode->getUserAny();
            if (!customData.isEmpty()) {
                OgreContainer *ogreContainer = Ogre::any_cast<OgreContainer *>(customData);
                if (ogreContainer) {
                    delete ogreContainer;
                    ogreContainer = 0;
                } else {
                    CameraInfo *cameraInfo = Ogre::any_cast<CameraInfo *>(customData);
                    if (cameraInfo) {
                        delete cameraInfo;
                        cameraInfo = 0;
                    }
                }
            }
            deepDeleteSceneNode(childSceneNode, sceneManager);
        }
    }

    // destroy all child nodes of the given scene node
    sceneNode->removeAndDestroyAllChildren();

    // check if the given scene node should be destroyed as well
    if (deleteRoot) {
        Ogre::Any customData = sceneNode->getUserAny();
        if (!customData.isEmpty()) {
            OgreContainer *ogreContainer = Ogre::any_cast<OgreContainer *>(customData);
            if (ogreContainer) {
                delete ogreContainer;
                ogreContainer = 0;
            } else {
                CameraInfo *cameraInfo = Ogre::any_cast<CameraInfo *>(customData);
                if (cameraInfo) {
                    delete cameraInfo;
                    cameraInfo = 0;
                }
            }
        }
        sceneManager->destroySceneNode(sceneNode);
    }
}
コード例 #3
0
void saveAsDotScene(const QString& path, QFile& file, Ogre::SceneManager* sceneManager)
{
    Ogre::MeshSerializer* mMeshSerializer = new Ogre::MeshSerializer();
    Ogre::MaterialSerializer* mMaterialSerializer = new Ogre::MaterialSerializer();

    int idCounter = 3;
    if (!file.open(QIODevice::WriteOnly))
    {
        /* show wrror message if not able to open file */
        QMessageBox::warning(0, "Read only", "The file is in read only mode");
    }
    else
    {
        Ogre::SceneManager::MovableObjectIterator iterator = sceneManager->getMovableObjectIterator("Entity");
        QXmlStreamWriter* xmlWriter = new QXmlStreamWriter();
        xmlWriter->setAutoFormatting(true);
        xmlWriter->setDevice(&file);
        xmlWriter->writeStartElement("scene");
        xmlWriter->writeAttribute("formatVersion","");

        xmlWriter->writeStartElement("nodes");
        while(iterator.hasMoreElements())
        {
            Ogre::Entity* e = static_cast<Ogre::Entity*>(iterator.getNext());
            Ogre::Any any = e->getParentNode()->getUserAny();
            Ogre::String widgetType("");
            if(!any.isEmpty()){
                widgetType = any_cast<Ogre::String>(any);
            }
            Ogre::String tmp(widgetType + ":" + e->getParentNode()->getName());
            QString nodeName(tmp.c_str());
            xmlWriter->writeStartElement("node");
            xmlWriter->writeAttribute("name", nodeName);
            xmlWriter->writeAttribute("id", QString::number(idCounter++));


            xmlWriter->writeStartElement("position");
            xmlWriter->writeAttribute("x", QString::number(e->getParentNode()->getPosition().x));
            xmlWriter->writeAttribute("y", QString::number(e->getParentNode()->getPosition().y));
            xmlWriter->writeAttribute("z", QString::number(e->getParentNode()->getPosition().z));
            xmlWriter->writeEndElement();

            xmlWriter->writeStartElement("scale");
            xmlWriter->writeAttribute("x", QString::number(e->getParentNode()->getScale().x));
            xmlWriter->writeAttribute("y", QString::number(e->getParentNode()->getScale().y));
            xmlWriter->writeAttribute("z", QString::number(e->getParentNode()->getScale().z));
            xmlWriter->writeEndElement();

            xmlWriter->writeStartElement("entity");
            xmlWriter->writeAttribute("name", nodeName);
            xmlWriter->writeAttribute("meshFile", nodeName.toLower() + QString(".mesh") );
            xmlWriter->writeAttribute("static", QString("false"));
            xmlWriter->writeEndElement();

            const Mesh* mesh = e->getMesh().getPointer();


            mMeshSerializer->exportMesh(mesh,String(path.toStdString() +
                                                    nodeName.toLower().toStdString() +
                                                    ".mesh" ));


            std::cout << "numeber" <<  mesh->getNumSubMeshes() << std::endl;


            for(int i = 0; i < e->getNumSubEntities(); i++){


                Ogre::Material *mat = static_cast<Ogre::Material*>
                        (Ogre::MaterialManager::getSingletonPtr()->getByName(e->getSubEntity(i)->getMaterialName()).getPointer());

                //e->getMesh().get()->getSubMesh()
                if(mat->getTechnique(0)->getPass(0)->getNumTextureUnitStates() !=0){
                Ogre::String str = mat->getTechnique(0)->getPass(0)->getTextureUnitState(0)->getTextureName();

            Ogre::MaterialPtr mMatPtr =e->getSubEntity(i)->getMaterial()    ;

            mMaterialSerializer->exportMaterial(mMatPtr ,
                                                String(path.toStdString() +
                                                       nodeName.toLower().toStdString() +
                                                       QString::number(i).toStdString() + ".material" ));
            Ogre::TexturePtr* mTexPtr = new Ogre::TexturePtr(Ogre::TextureManager::getSingletonPtr()->getByName(str));
            Ogre::Texture* mTex = mTexPtr->getPointer();
            Ogre::PixelFormat pxf = mTex->getFormat();
            Ogre::Image mImage;
            mTex->convertToImage(mImage);
            std::cout << str << std::endl;
            mImage.save(String(path.toStdString() +
                                 str));
                }
}
            //material file merge

            for(int i = 0; i < e->getNumSubEntities(); i++){
                Ogre::Material *mat = static_cast<Ogre::Material*>
                        (Ogre::MaterialManager::getSingletonPtr()->getByName(e->getSubEntity(i)->getMaterialName()).getPointer());


                QString mMatFilePath = QString((path.toStdString() +
                                               nodeName.toLower().toStdString() +
                                                ".material").c_str()) ;


                 QFile mFile(mMatFilePath);
                 if (!mFile.open(QIODevice::Append))
                 {
                     /* show wrror message if not able to open file */
                     QMessageBox::warning(0, "Read only", "The file is in read only mode");
                 }
                 else{
                     QTextStream out(&mFile);

                     QString mTempMatPath = QString((path + nodeName.toLower() + QString::number(i) + ".material"));

                     QFile mTempMatFile(mTempMatPath);
                     mTempMatFile.open(QIODevice::ReadOnly);

                     QTextStream src(&mTempMatFile);

                     mFile.write(src.readAll().toStdString().c_str());
                     mTempMatFile.remove();

                 }



            }


            xmlWriter->writeEndElement();


        }

        xmlWriter->writeEndElement();
        xmlWriter->writeEndDocument();
        delete xmlWriter;
    }

    delete mMeshSerializer;
    delete mMaterialSerializer;
}