Example #1
0
//-------------------------------------------------------
Ogre::MeshPtr Ground::CreateRegion(size_t id, const std::string & material, const Ogre::Box & roi, const Ogre::Vector3 & offset, const Ogre::Vector3 & steps, const Ogre::Vector2 & texOffset)
{
    assert(mSceneManager != nullptr);

    Ogre::ManualObject* object = mSceneManager->createManualObject();
    object->begin(material, Ogre::RenderOperation::OT_TRIANGLE_LIST);
    {
        size_t lastIdx = 0;
        for (size_t y = 0; y < REGION_SIZE; ++y)
        {
            size_t texY = static_cast<size_t>(static_cast<float>(y) / REGION_SIZE * (roi.getHeight() - 1));
            size_t texYn = static_cast<size_t>(static_cast<float>(y + 1) / REGION_SIZE * (roi.getHeight() - 1));

            //Flip texture vertically
            texY  = roi.getHeight() - 1 - texY;
            texYn = roi.getHeight() - 1 - texYn;

            float texCrdT = texOffset[1] + static_cast<float>(texY) / (mImage->getHeight() - 1);
            float texCrdTn = texOffset[1] + static_cast<float>(texYn) / (mImage->getHeight() - 1);

            for (size_t x = 0; x < REGION_SIZE; ++x)
            {
                size_t texX = static_cast<size_t>(static_cast<float>(x) / REGION_SIZE * (roi.getWidth() - 1));
                size_t texXn = static_cast<size_t>(static_cast<float>(x + 1) / REGION_SIZE * (roi.getWidth() - 1));

                float texCrdS = texOffset[0] + static_cast<float>(texX) / (mImage->getWidth() - 1);
                float texCrdSn = texOffset[0] + static_cast<float>(texXn) / (mImage->getWidth() - 1);

                float h00 = mImage->getColourAt(roi.left + texX,  roi.top + texY, 0)[0];
                float h10 = mImage->getColourAt(roi.left + texXn, roi.top + texY, 0)[0];
                float h01 = mImage->getColourAt(roi.left + texX,  roi.top + texYn, 0)[0];
                float h11 = mImage->getColourAt(roi.left + texXn, roi.top + texYn, 0)[0];

                object->position(x * steps[0] + offset[0], y * steps[1] + offset[1], h00 * steps[2]);
                object->textureCoord(texCrdS, texCrdT);
                object->colour(h00, h00, h00);
                
                object->position((x + 1) * steps[0] + offset[0], y * steps[1] + offset[1], h10 * steps[2]);
                object->textureCoord(texCrdSn, texCrdT);
                object->colour(h10, h10, h10);

                object->position(x * steps[0] + offset[0], (y + 1) * steps[1] + offset[1], h01 * steps[2]);
                object->textureCoord(texCrdS, texCrdTn);
                object->colour(h01, h01, h01);

                object->position((x + 1) * steps[0] + offset[0], (y + 1) * steps[1] + offset[1], h11 * steps[2]);
                object->textureCoord(texCrdSn, texCrdTn);
                object->colour(h11, h11, h11);

                object->triangle(lastIdx + 1, lastIdx + 2, lastIdx);
                object->triangle(lastIdx + 3, lastIdx + 2, lastIdx + 1);
                lastIdx += 4;
            }
        }
    }
    object->end();
    return object->convertToMesh("Mesh/" + CLASS_NAME  + "/" + mName + "/" + std::to_string(id));
}
Ogre::MeshPtr STLLoader::toMesh(const std::string& name)
{
  Ogre::ManualObject* object = new Ogre::ManualObject( "the one and only" );
  object->begin( "BaseWhiteNoLighting", Ogre::RenderOperation::OT_TRIANGLE_LIST );

  unsigned int vertexCount = 0;
  V_Triangle::const_iterator it = triangles_.begin();
  V_Triangle::const_iterator end = triangles_.end();
  for (; it != end; ++it )
  {
    if( vertexCount >= 2004 )
    {
      // Subdivide large meshes into submeshes with at most 2004
      // vertices to prevent problems on some graphics cards.
      object->end();
      object->begin( "BaseWhiteNoLighting", Ogre::RenderOperation::OT_TRIANGLE_LIST );
      vertexCount = 0;
    }

    const STLLoader::Triangle& tri = *it;

    float u, v;
    u = v = 0.0f;
    object->position( tri.vertices_[0] );
    object->normal( tri.normal_);
    calculateUV( tri.vertices_[0], u, v );
    object->textureCoord( u, v );

    object->position( tri.vertices_[1] );
    object->normal( tri.normal_);
    calculateUV( tri.vertices_[1], u, v );
    object->textureCoord( u, v );

    object->position( tri.vertices_[2] );
    object->normal( tri.normal_);
    calculateUV( tri.vertices_[2], u, v );
    object->textureCoord( u, v );

    object->triangle( vertexCount + 0, vertexCount + 1, vertexCount + 2 );

    vertexCount += 3;
  }

  object->end();

  Ogre::MeshPtr mesh = object->convertToMesh( name, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME );
  mesh->buildEdgeList();

  delete object;

  return mesh;
}
void addQuad(
	const std::vector<Ogre::Vector3>& i_clockwiseQuad,
	const Ogre::Vector3& i_normal,
	size_t i_nRows,
	size_t i_nCols,
	const Ogre::String& i_material,
	Ogre::ManualObject& io_object)
{
	assert(i_clockwiseQuad.size() == 4);
	assert(i_nRows != 0 && i_nCols != 0);

	const std::vector<Ogre::Vector3>& box = i_clockwiseQuad;
	const Ogre::Vector3& n = i_normal;
	float ratioCol = 1.f / (float)(i_nCols);
	float ratioRow = 1.f / (float)(i_nRows);
	Ogre::Vector3 stepCol = (box[1] - box[0]) * ratioCol;
	Ogre::Vector3 stepRow = (box[3] - box[0]) * ratioRow;

	std::vector<Ogre::Vector3> cur(4);

	for (size_t r = 0; r < i_nRows; ++r)
	{
		io_object.begin(i_material, Ogre::RenderOperation::OT_TRIANGLE_LIST);
		for (size_t c = 0; c < i_nCols; ++c)
		{
			cur[0] = box[0] + stepRow * (float)r + stepCol * (float)c;
			cur[1] = box[0] + stepRow * (float)r + stepCol * (float)(c+1);
			cur[2] = box[0] + stepRow * (float)(r+1) + stepCol * (float)(c+1);
			cur[3] = box[0] + stepRow * (float)(r+1) + stepCol * (float)(c);

			io_object.position(cur[0].x, cur[0].y, cur[0].z);
			io_object.normal(n.x, n.y, n.z);
			io_object.textureCoord(ratioRow*(float)r, ratioCol*(float)c);

			io_object.position(cur[3].x, cur[3].y, cur[3].z);
			io_object.normal(n.x, n.y, n.z);
			io_object.textureCoord(ratioRow*(float)(r+1), ratioCol*(float)c);

			io_object.position(cur[1].x, cur[1].y, cur[1].z);
			io_object.normal(n.x, n.y, n.z);
			io_object.textureCoord(ratioRow*(float)r, ratioCol*(float)(c+1));

			io_object.position(cur[1].x, cur[1].y, cur[1].z);
			io_object.normal(n.x, n.y, n.z);
			io_object.textureCoord(ratioRow*(float)r, ratioCol*(float)(c + 1));

			io_object.position(cur[3].x, cur[3].y, cur[3].z);
			io_object.normal(n.x, n.y, n.z);
			io_object.textureCoord(ratioRow*(float)(r + 1), ratioCol*(float)c);

			io_object.position(cur[2].x, cur[2].y, cur[2].z);
			io_object.normal(n.x, n.y, n.z);
			io_object.textureCoord(ratioRow*(float)(r+1), ratioCol*(float)(c + 1));

		}
		io_object.end();
	}
}
Example #4
0
void OgreExporter_c::ExportWallMesh(Ogre::ManualObject &manualMesh, int floorHeight, int ceilingHeight, Name_u textureName, int offsetX, int offsetY, const Vertex_s *vertices, const LineDef_s &lineDef, const WadFile_c &wad)
{
	std::stringstream stream;
	stream << textureName.ToString();
	manualMesh.begin(stream.str(), Ogre::RenderOperation::OT_TRIANGLE_LIST);

	const Texture_s &tex = wad.GetTextureInfo(textureName);

	const Vertex_s &startVertex = vertices[lineDef.iStartVertex];
	const Vertex_s &endVertex = vertices[lineDef.iEndVertex];

	int height = ceilingHeight - floorHeight;	
	int width = Ogre::Vector2(startVertex.iX, startVertex.iY).distance(Ogre::Vector2(endVertex.iX, endVertex.iY));
	
	float offsetU = offsetX / (float) tex.uWidth;
	float offsetV = offsetY / (float) tex.uHeight;	

	float endV = (height / (float)tex.uHeight) + offsetV;
	float endU = (width / (float) tex.uWidth) + offsetU;

	manualMesh.position(-startVertex.iX, floorHeight, startVertex.iY);
	manualMesh.textureCoord(offsetU, endV);

	manualMesh.position(-startVertex.iX, ceilingHeight, startVertex.iY);
	manualMesh.textureCoord(offsetU, offsetV);
	
	manualMesh.position(-endVertex.iX, ceilingHeight, endVertex.iY);
	manualMesh.textureCoord(endU, offsetV);		

	manualMesh.position(-endVertex.iX, floorHeight, endVertex.iY);
	manualMesh.textureCoord(endU, endV);	

	manualMesh.triangle(2, 1, 0);
	manualMesh.triangle(0, 3, 2);

	manualMesh.end();
}
//-------------------------------------------------------------------------------------
Ogre::ManualObject* const DigitalForensicsVisualisation::rectangle(std::string matName)
{

	char* name = (char*) malloc (32);
	sprintf(name, "rect%d", app.rectCount++);

	Ogre::ManualObject* rect = mSceneMgr->createManualObject(name);
	rect->begin(matName, Ogre::RenderOperation::OT_TRIANGLE_LIST);

	rect->position(100,100.1,0);
	rect->textureCoord(1,0);
	rect->normal(50,500,50);

	rect->position(0,100.1,100);
	rect->textureCoord(0,1);
	rect->normal(50,500,50);

	rect->position(0,100.1,0);
	rect->textureCoord(0,0);
	rect->normal(50,500,50);

	rect->position(100,100.1,100);
	rect->textureCoord(1,1);
	rect->normal(50,500,50);

	rect->triangle(2,1,0);
	rect->triangle(1,3,0);
	
	rect->end();
	free(name);


	return rect;


}
Example #6
0
 void RenderSystem::RenderLightMesh3DWithTexture(std::string meshName, std::string materialName, const MagicDGP::LightMesh3D* pMesh)
 {
     InfoLog << "RenderSystem::RenderMesh3D" << std::endl;
     Ogre::ManualObject* pMObj = NULL;
     if (mpSceneMgr->hasManualObject(meshName))
     {
         pMObj = mpSceneMgr->getManualObject(meshName);
         pMObj->clear();
     }
     else
     {
         pMObj = mpSceneMgr->createManualObject(meshName);
         if (mpSceneMgr->hasSceneNode("ModelNode"))
         {
             mpSceneMgr->getSceneNode("ModelNode")->attachObject(pMObj);
         }
         else
         {
             mpSceneMgr->getRootSceneNode()->createChildSceneNode("ModelNode")->attachObject(pMObj);
         }
     }
     pMObj->begin(materialName, Ogre::RenderOperation::OT_TRIANGLE_LIST);
     int vertNum = pMesh->GetVertexNumber();
     for (int i = 0; i < vertNum; i++)
     {
         const MagicDGP::Vertex3D* pVert = pMesh->GetVertex(i);
         MagicMath::Vector3 pos = pVert->GetPosition();
         MagicMath::Vector3 nor = pVert->GetNormal();
         MagicMath::Vector3 texCord = pVert->GetTexCord();
         pMObj->position(pos[0], pos[1], pos[2]);
         pMObj->normal(nor[0], nor[1], nor[2]);
         pMObj->textureCoord(texCord[0], texCord[1]);
     }
     int faceNum = pMesh->GetFaceNumber();
     for (int i = 0; i < faceNum; i++)
     {
         MagicDGP::FaceIndex faceIdx = pMesh->GetFace(i);
         pMObj->triangle(faceIdx.mIndex[0], faceIdx.mIndex[1], faceIdx.mIndex[2]);
     }
     pMObj->end();
 }
Example #7
0
Ogre::ManualObject* TerrainManager::createTerrainDecal(Ogre::String& name, Ogre::String& material, Ogre::String& resourceGroup)
{
	if(!_OgreManager)
		return NULL;

	Ogre::ManualObject* meshDecal = new Ogre::ManualObject(name);

	_OgreManager->getSceneManager()->getRootSceneNode()->attachObject(meshDecal);
	
	int x_size = 4;  // number of polygons
	int z_size = 4;
 
	meshDecal->begin(material, Ogre::RenderOperation::OT_TRIANGLE_LIST, resourceGroup);
	for (int i=0; i<=x_size; i++)
	{
		for (int j=0; j<=z_size; j++)
		{
			meshDecal->position(Ogre::Vector3(i, 0, j));
			meshDecal->textureCoord((float)i / (float)x_size, (float)j / (float)z_size);
		}
	}
 
	for (int i=0; i<x_size; i++)
	{
		for (int j=0; j<z_size; j++)
		{
			meshDecal->quad( i * (x_size+1) + j,
							 i * (x_size+1) + j + 1,
							(i + 1) * (x_size+1) + j + 1,
							(i + 1) * (x_size+1) + j);
		}
	}
	meshDecal->end();

	return meshDecal;
}
// Given a scene node for a terrain, find the manual object on that scene node and
// update the manual object with the heightmap passed. If  there is no manual object on
// the scene node, remove all it's attachments and add the manual object.
// The heightmap is passed in a 1D array ordered by width rows (for(width) {for(length) {hm[w,l]}})
// This must be called between frames since it touches the scene graph
// BETWEEN FRAME OPERATION
void Region::UpdateTerrain(const int hmWidth, const int hmLength, const float* hm) {
	Ogre::SceneNode* node = this->TerrainSceneNode;
	LG::Log("Region::UpdateTerrain: updating terrain for region %s", this->Name.c_str());

	if (node == NULL) {
		LG::Log("Region::UpdateTerrain: terrain scene node doesn't exist. Not updating terrain.");
		return;
	}

	// Find the movable object attached to the scene node. If not found remove all.
	if (node->numAttachedObjects() > 0) {
		Ogre::MovableObject* attached = node->getAttachedObject(0);
		if (attached->getMovableType() != "ManualObject") {
            // don't know why this would ever happen but clean out the odd stuff
            LG::Log("Found extra stuff on terrain scene node");
			node->detachAllObjects();
		}
	}
	// if there is not a manual object on the node, create a new one
	if (node->numAttachedObjects() == 0) {
		LG::Log("Region::UpdateTerrain: creating terrain ManualObject for region %s", this->Name.c_str());
        // if no attached objects, we add our dynamic ManualObject
		Ogre::ManualObject* mob = LG::RendererOgre::Instance()->m_sceneMgr->createManualObject("ManualObject/" + node->getName());
		mob->addQueryFlags(Ogre::SceneManager::WORLD_GEOMETRY_TYPE_MASK);
		mob->setDynamic(true);
		mob->setCastShadows(true);
		mob->setVisible(true);
		node->attachObject(mob);
		// m_visCalc->RecalculateVisibility();
	}

	Ogre::ManualObject* mo = (Ogre::ManualObject*)node->getAttachedObject(0);

	// stuff our heightmap information into the dynamic manual object
	mo->estimateVertexCount(hmWidth * hmLength);
	mo->estimateIndexCount(hmWidth * hmLength * 6);

	if (mo->getNumSections() == 0) {
		// if first time
		mo->begin(LG::GetParameter("Renderer.Ogre.DefaultTerrainMaterial"));
	}
	else {
		mo->beginUpdate(0);					// we've been here before
	}

	int loc = 0;
	for (int xx = 0; xx < hmWidth; xx++) {
		for (int yy = 0; yy < hmLength; yy++) {
			mo->position((Ogre::Real)xx, (Ogre::Real)yy, hm[loc++]);
			mo->textureCoord((float)xx / (float)hmWidth, (float)yy / (float)hmLength);
			mo->normal(0.0, 1.0, 0.0);	// always up (for the moment)
		}
	}

	for (int px = 0; px < hmLength-1; px++) {
		for (int py = 0; py < hmWidth-1; py++) {
			mo->quad(px      + py       * hmWidth,
					 px      + (py + 1) * hmWidth,
					(px + 1) + (py + 1) * hmWidth,
					(px + 1) + py       * hmWidth
					 );
		}
	}

	mo->end();

	return;
}
//Copied from BetaCairo demo : http://www.ogre3d.org/forums/viewtopic.php?t=26987 (created by betajaen)
Ogre::ManualObject* OgreAppLogic::createCubeMesh(const std::string& name, const std::string& matName)
{
	Ogre::ManualObject* cube = new Ogre::ManualObject(name);
	cube->begin(matName);

	cube->position(0.500000,-0.500000,1.000000);
	cube->normal(0.408248f,-0.816497f,0.408248f);
	cube->textureCoord(1,0);


	cube->position(-0.500000,-0.500000,0.000000);
	cube->normal(-0.408248f,-0.816497f,-0.408248f);
	cube->textureCoord(0,1);

	cube->position(0.500000,-0.500000,0.000000);
	cube->normal(0.666667f,-0.333333f,-0.666667f);
	cube->textureCoord(1,1);

	cube->position(-0.500000,-0.500000,1.000000);
	cube->normal(-0.666667f,-0.333333f,0.666667f);
	cube->textureCoord(0,0);

	cube->position(0.500000,0.500000,1.000000);
	cube->normal(0.666667f,0.333333f,0.666667f);
	cube->textureCoord(1,0);

	cube->position(-0.500000,-0.500000,1.000000);
	cube->normal(-0.666667f,-0.333333f,0.666667f);
	cube->textureCoord(0,1);

	cube->position(0.500000,-0.500000,1.000000);
	cube->normal(0.408248f,-0.816497f,0.408248f);
	cube->textureCoord(1,1);

	cube->position(-0.500000,0.500000,1.000000);
	cube->normal(-0.408248f,0.816497f,0.408248f);
	cube->textureCoord(0,0);

	cube->position(-0.500000,0.500000,0.000000);
	cube->normal(-0.666667f,0.333333f,-0.666667f);
	cube->textureCoord(0,1);

	cube->position(-0.500000,-0.500000,0.000000);
	cube->normal(-0.408248f,-0.816497f,-0.408248f);
	cube->textureCoord(1,1);

	cube->position(-0.500000,-0.500000,1.000000);
	cube->normal(-0.666667f,-0.333333f,0.666667f);
	cube->textureCoord(1,0);

	cube->position(0.500000,-0.500000,0.000000);
	cube->normal(0.666667f,-0.333333f,-0.666667f);
	cube->textureCoord(0,1);

	cube->position(0.500000,0.500000,0.000000);
	cube->normal(0.408248f,0.816497f,-0.408248f);
	cube->textureCoord(1,1);

	cube->position(0.500000,-0.500000,1.000000);
	cube->normal(0.408248f,-0.816497f,0.408248f);
	cube->textureCoord(0,0);

	cube->position(0.500000,-0.500000,0.000000);
	cube->normal(0.666667f,-0.333333f,-0.666667f);
	cube->textureCoord(1,0);

	cube->position(-0.500000,-0.500000,0.000000);
	cube->normal(-0.408248f,-0.816497f,-0.408248f);
	cube->textureCoord(0,0);

	cube->position(-0.500000,0.500000,1.000000);
	cube->normal(-0.408248f,0.816497f,0.408248f);
	cube->textureCoord(1,0);

	cube->position(0.500000,0.500000,0.000000);
	cube->normal(0.408248f,0.816497f,-0.408248f);
	cube->textureCoord(0,1);

	cube->position(-0.500000,0.500000,0.000000);
	cube->normal(-0.666667f,0.333333f,-0.666667f);
	cube->textureCoord(1,1);

	cube->position(0.500000,0.500000,1.000000);
	cube->normal(0.666667f,0.333333f,0.666667f);
	cube->textureCoord(0,0);

	cube->triangle(0,1,2);
	cube->triangle(3,1,0);
	cube->triangle(4,5,6);
	cube->triangle(4,7,5);
	cube->triangle(8,9,10);
	cube->triangle(10,7,8);
	cube->triangle(4,11,12);
	cube->triangle(4,13,11);
	cube->triangle(14,8,12);
	cube->triangle(14,15,8);
	cube->triangle(16,17,18);
	cube->triangle(16,19,17);
	cube->end(); 

	return cube;

}
Example #10
0
void Map::generateMesh(std::string materialName)
{
    Ogre::ManualObject* plane = new Ogre::ManualObject("plane");
    plane->estimateIndexCount(m_length * m_width * 8);
    plane->estimateVertexCount(m_length * m_width * 8);
    plane->clear();
    plane->begin(materialName);

    Ogre::Vector3 pos = Ogre::Vector3(0, 0, 0);
    Ogre::Quaternion quat;
    Ogre::Quaternion quatNext;
    unsigned long planeNum = 0;

    for (unsigned int i = 0; i < m_length; i++) {
        quat = m_rotationalSpline.getPoint(i);
        quatNext = m_rotationalSpline.getPoint(i + 1);

        for (int x = -100 * (m_width / (double) 2), j = 0; (unsigned) j < m_width; j++, x += 100) {
            int back = -100;
            int left = x;
            int right = x + 100;
            int down = -20 ;

            Ogre::Vector3 nextPos =             pos + quat * Ogre::Vector3(0, 0, back);
            Ogre::Vector3 posMinus50 =          pos + quat * Ogre::Vector3(left, 0, 0);
            Ogre::Vector3 posPlus50 =           pos + quat * Ogre::Vector3(right, 0, 0);
            Ogre::Vector3 nextPosMinus50 =      nextPos + quatNext * Ogre::Vector3(left, 0, 0);
            Ogre::Vector3 nextPosPlus50 =       nextPos + quatNext * Ogre::Vector3(right, 0, 0);

            //TODO: fix normals?
            plane->position(posMinus50);
            plane->normal((quat * Vector3(0, 1, 0)).normalisedCopy());
            plane->textureCoord(1, 1);
            plane->position(nextPosMinus50);
            plane->normal((quat * Vector3(0, 1, 0)).normalisedCopy());
            plane->textureCoord(1, 0);
            plane->position(posPlus50);
            plane->normal((quat * Vector3(0, 1, 0)).normalisedCopy());
            plane->textureCoord(0, 1);
            plane->position(nextPosPlus50);
            plane->normal((quat * Vector3(0, 1, 0)).normalisedCopy());
            plane->textureCoord(0, 0);

            Ogre::Vector3 nextPosDown =         nextPos + quat * Ogre::Vector3(0, down, 0);
            Ogre::Vector3 posMinus50Down =      posMinus50 + quat * Ogre::Vector3(0, down, 0);
            Ogre::Vector3 posPlus50Down =       posPlus50 + quat * Ogre::Vector3(0, down, 0);
            Ogre::Vector3 nextPosMinus50Down =  nextPosMinus50 + quatNext * Ogre::Vector3(0, down, 0);
            Ogre::Vector3 nextPosPlus50Down =   nextPosPlus50 + quatNext * Ogre::Vector3(0, down, 0);

            //TODO: fix normals?
            plane->position(posMinus50Down);
            plane->normal((quat * Vector3(-1, -1, 1)).normalisedCopy());
            plane->textureCoord(0, 0);
            plane->position(nextPosMinus50Down);
            plane->normal((quat * Vector3(-1, -1, -1)).normalisedCopy());
            plane->textureCoord(0, 1);
            plane->position(posPlus50Down);
            plane->normal((quat * Vector3(1, -1, 1)).normalisedCopy());
            plane->textureCoord(1, 0);
            plane->position(nextPosPlus50Down);
            plane->normal((quat * Vector3(1, -1, -1)).normalisedCopy());
            plane->textureCoord(1, 1);

            if (m_cubes[planeNum / (double) m_width][planeNum % m_width] != HOLE) {
                //if (m_cubes[planeNum / (double) m_width][planeNum % m_width] == NORMAL)
                //{
                //top
                plane->triangle(0 + planeNum * 8, 1 + planeNum * 8, 2 + planeNum * 8);
                plane->triangle(2 + planeNum * 8, 1 + planeNum * 8, 0 + planeNum * 8);
                plane->triangle(1 + planeNum * 8, 3 + planeNum * 8, 2 + planeNum * 8);
                plane->triangle(2 + planeNum * 8, 3 + planeNum * 8, 1 + planeNum * 8);
                //}

                //bottom
                plane->triangle(4 + planeNum * 8, 5 + planeNum * 8, 6 + planeNum * 8);
                plane->triangle(6 + planeNum * 8, 5 + planeNum * 8, 4 + planeNum * 8);
                plane->triangle(5 + planeNum * 8, 7 + planeNum * 8, 6 + planeNum * 8);
                plane->triangle(6 + planeNum * 8, 7 + planeNum * 8, 5 + planeNum * 8);

                if (planeNum % m_width == 0 || m_cubes[planeNum / (double) m_width][(planeNum - 1) % m_width] == HOLE) {
                    //left
                    plane->triangle(0 + planeNum * 8, 4 + planeNum * 8, 5 + planeNum * 8);
                    plane->triangle(5 + planeNum * 8, 4 + planeNum * 8, 0 + planeNum * 8);
                    plane->triangle(0 + planeNum * 8, 1 + planeNum * 8, 5 + planeNum * 8);
                    plane->triangle(5 + planeNum * 8, 1 + planeNum * 8, 0 + planeNum * 8);
                }

                if (planeNum % m_width == m_width - 1 || m_cubes[planeNum / (double) m_width][(planeNum + 1) % m_width] == HOLE) {
                    //right
                    plane->triangle(2 + planeNum * 8, 6 + planeNum * 8, 7 + planeNum * 8);
                    plane->triangle(7 + planeNum * 8, 6 + planeNum * 8, 2 + planeNum * 8);
                    plane->triangle(2 + planeNum * 8, 3 + planeNum * 8, 7 + planeNum * 8);
                    plane->triangle(7 + planeNum * 8, 3 + planeNum * 8, 2 + planeNum * 8);
                }

                if (planeNum / (double) m_width >= m_length - 1 || m_cubes[(planeNum + m_width) / (double) m_width][planeNum % m_width] == HOLE) {
                    //back
                    plane->triangle(5 + planeNum * 8, 7 + planeNum * 8, 1 + planeNum * 8);
                    plane->triangle(1 + planeNum * 8, 7 + planeNum * 8, 5 + planeNum * 8);
                    plane->triangle(1 + planeNum * 8, 3 + planeNum * 8, 7 + planeNum * 8);
                    plane->triangle(7 + planeNum * 8, 3 + planeNum * 8, 1 + planeNum * 8);
                }

                if (planeNum / (double) m_width <= m_width || m_cubes[(planeNum - m_width) / (double) m_width][planeNum % m_width] == HOLE) {
                    //front
                    plane->triangle(2 + planeNum * 8, 6 + planeNum * 8, 4 + planeNum * 8);
                    plane->triangle(4 + planeNum * 8, 6 + planeNum * 8, 2 + planeNum * 8);
                    plane->triangle(0 + planeNum * 8, 4 + planeNum * 8, 2 + planeNum * 8);
                    plane->triangle(2 + planeNum * 8, 4 + planeNum * 8, 0 + planeNum * 8);
                }

            }

            planeNum++;
        }

        pos = pos + quat * Ogre::Vector3(0, 0, -100);
    }

    plane->end();
    plane->setCastShadows(false);
    m_mapMainNode->attachObject(plane);
    MeshPtr ptr = plane->convertToMesh("planeMesh");
    Entity* planeEntity = m_pSceneMgr->createEntity("planeEntity", "planeMesh");
}
void CTransparentMaterialView::EngineSetup(void)
{
	Ogre::Root *Root = ((CTransparentMaterialApp*)AfxGetApp())->m_Engine->GetRoot();

	Ogre::SceneManager *SceneManager = NULL;

	SceneManager = Root->createSceneManager(Ogre::ST_GENERIC, "MFCOgre");

    //
    // Create a render window
    // This window should be the current ChildView window using the externalWindowHandle
    // value pair option.
    //

    Ogre::NameValuePairList parms;
    parms["externalWindowHandle"] = Ogre::StringConverter::toString((long)m_hWnd);
    parms["vsync"] = "true";

	CRect   rect;
    GetClientRect(&rect);

	Ogre::RenderTarget *RenderWindow = Root->getRenderTarget("Ogre in MFC");

	if (RenderWindow == NULL)
	{
	try
	{
		m_RenderWindow = Root->createRenderWindow("Ogre in MFC", rect.Width(), rect.Height(), false, &parms);
	}
    catch(...)
	{
		MessageBox("Cannot initialize\nCheck that graphic-card driver is up-to-date", "Initialize Render System", MB_OK | MB_ICONSTOP);
		exit(EXIT_SUCCESS);
	}
	}
// Load resources
	Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();

    // Create the camera
    m_Camera = SceneManager->createCamera("Camera");
    m_Camera->setNearClipDistance(0.5);
	m_Camera->setFarClipDistance(5000); 
	m_Camera->setCastShadows(false);
	m_Camera->setUseRenderingDistance(true);
	m_Camera->setPosition(Ogre::Vector3(320.0, 240.0, 500.0));
	Ogre::SceneNode *CameraNode = NULL;
	CameraNode = SceneManager->getRootSceneNode()->createChildSceneNode("CameraNode");

	Ogre::Viewport* Viewport = NULL;
	
	if (0 == m_RenderWindow->getNumViewports())
	{
		Viewport = m_RenderWindow->addViewport(m_Camera);
		Viewport->setBackgroundColour(Ogre::ColourValue(0.8f, 1.0f, 0.8f));
	}

    // Alter the camera aspect ratio to match the viewport
    m_Camera->setAspectRatio(Ogre::Real(rect.Width()) / Ogre::Real(rect.Height()));

	Ogre::ManualObject *Screen = SceneManager->createManualObject("Screen");
	Screen->setDynamic(true);
	Screen->begin("window", Ogre::RenderOperation::OT_TRIANGLE_LIST);

	Screen->position(-100,-100,50);
	Screen->textureCoord(0,0);

	Screen->position(300,-100,50);
	Screen->textureCoord(1,0);

	Screen->position(300,300,50);
	Screen->textureCoord(1,1);

	Screen->triangle(0, 1, 2);
		
	Screen->position(-100,-100,50);
	Screen->textureCoord(0,0);

	Screen->position(300,300,50);
	Screen->textureCoord(1,1);

	Screen->position(-100,300,50);
	Screen->textureCoord(0,1);

	Screen->triangle(3, 4, 5);
	 
	Screen->end();
	
	Ogre::Entity *RobotEntity = SceneManager->createEntity("Robot", "robot.mesh");
	Ogre::SceneNode *RobotNode = SceneManager->getRootSceneNode()->createChildSceneNode();
	RobotNode->attachObject(RobotEntity);

	Ogre::SceneNode *WindowNode = SceneManager->getRootSceneNode()->createChildSceneNode();
	WindowNode->attachObject(Screen);
}
int DecalManager::addTerrainDecal(Ogre::Vector3 position, Ogre::Vector2 size, Ogre::Vector2 numSeg, Ogre::Real rotation, Ogre::String materialname, Ogre::String normalname)
{
#if 0
	Ogre::ManualObject *mo = gEnv->ogreSceneManager->createManualObject();
	String oname = mo->getName();
	SceneNode *mo_node = terrain_decals_snode->createChildSceneNode();

	mo->begin(materialname, Ogre::RenderOperation::OT_TRIANGLE_LIST);
	AxisAlignedBox *aab=new AxisAlignedBox();
	float uTile = 1, vTile = 1;

	Vector3 normal = Vector3(0,1,0); // UP
	
	int offset = 0;
	float ground_dist = 0.001f;

	Ogre::Vector3 vX = normal.perpendicular();
	Ogre::Vector3 vY = normal.crossProduct(vX);
	Ogre::Vector3 delta1 = size.x / numSeg.x * vX;
	Ogre::Vector3 delta2 = size.y / numSeg.y * vY;
	// build one corner of the square
	Ogre::Vector3 orig = -0.5*size.x*vX - 0.5*size.y*vY;

	for (int i1 = 0; i1<=numSeg.x; i1++)
		for (int i2 = 0; i2<=numSeg.y; i2++)
		{
			Vector3 pos = orig+i1*delta1+i2*delta2 + position;
			pos.y = hfinder->getHeightAt(pos.x, pos.z) + ground_dist;
			mo->position(pos);
			aab->merge(pos);
			mo->textureCoord(i1/(Ogre::Real)numSeg.x*uTile, i2/(Ogre::Real)numSeg.y*vTile);
			mo->normal(normal);
		}

	bool reverse = false;
	if (delta1.crossProduct(delta2).dotProduct(normal)>0)
		reverse= true;
	for (int n1 = 0; n1<numSeg.x; n1++)
	{
		for (int n2 = 0; n2<numSeg.y; n2++)
		{
			if (reverse)
			{
				mo->index(offset+0);
				mo->index(offset+(numSeg.y+1));
				mo->index(offset+1);
				mo->index(offset+1);
				mo->index(offset+(numSeg.y+1));
				mo->index(offset+(numSeg.y+1)+1);
			}
			else
			{
				mo->index(offset+0);
				mo->index(offset+1);
				mo->index(offset+(numSeg.y+1));
				mo->index(offset+1);
				mo->index(offset+(numSeg.y+1)+1);
				mo->index(offset+(numSeg.y+1));
			}
			offset++;
		}
		offset++;
	}
	offset+=numSeg.y+1;

	mo->end();
	mo->setBoundingBox(*aab);
	// some optimizations
	mo->setCastShadows(false);
	mo->setDynamic(false);
	delete(aab);

	MeshPtr mesh = mo->convertToMesh(oname+"_mesh");

	// build edgelist
	mesh->buildEdgeList();

	// remove the manualobject again, since we dont need it anymore
	gEnv->ogreSceneManager->destroyManualObject(mo);

	unsigned short src, dest;
	if (!mesh->suggestTangentVectorBuildParams(VES_TANGENT, src, dest))
	{
		mesh->buildTangentVectors(VES_TANGENT, src, dest);
	}
	
	Entity *ent = gEnv->ogreSceneManager->createEntity(oname+"_ent", oname+"_mesh");
	mo_node->attachObject(ent);

	mo_node->setVisible(true);
	//mo_node->showBoundingBox(true);
	mo_node->setPosition(Vector3::ZERO); //(position.x, 0, position.z));


	// RTSS
	//Ogre::RTShader::ShaderGenerator::getSingleton().createShaderBasedTechnique(materialname, Ogre::MaterialManager::DEFAULT_SCHEME_NAME, Ogre::RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME);
	//Ogre::RTShader::ShaderGenerator::getSingleton().invalidateMaterial(RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME, materialname);
	RTSSgenerateShadersForMaterial(materialname, normalname);

#endif
	return 0;
}
Ogre::ManualObject * CCone::CreateCone(Ogre::Real Intensity)
{
	Ogre::ManualObject *Cone = NULL;
	Ogre::SceneManager *SceneManager = Ogre::Root::getSingleton().getSceneManager("DynamicEffects");
	Cone = SceneManager->createManualObject("Cone");
	Cone->setDynamic(false);
    Cone->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_TRIANGLE_LIST);

	Ogre::Real deltaAngle = (Ogre::Math::TWO_PI / m_BaseSegments);
	Ogre::Real deltaHeight = m_Height/(Ogre::Real)m_HeightSegments;
	
	Ogre::Vector3 Normal = Ogre::Vector3(m_Radius, m_Height, 0.f).normalisedCopy();
	Ogre::Quaternion Quaternion;
	
	int Offset = 0;

	for (int HeightSegmentIndex = 0; HeightSegmentIndex <= m_HeightSegments; HeightSegmentIndex++)
	{
		Ogre::Real Radius = m_Radius * (1 - HeightSegmentIndex / (Ogre::Real)m_HeightSegments);
		
		for (int BaseSegmentIndex = 0; BaseSegmentIndex <= m_BaseSegments; BaseSegmentIndex++)
		{
			Ogre::Real x = Radius* cosf(BaseSegmentIndex * deltaAngle);
			Ogre::Real z = Radius * sinf(BaseSegmentIndex * deltaAngle);
			Cone->position(x, HeightSegmentIndex * deltaHeight, z);
			
			Cone->colour(Intensity, Intensity, 0.0, 1.0);
			Quaternion.FromAngleAxis(Ogre::Radian(-BaseSegmentIndex*deltaAngle), Ogre::Vector3::NEGATIVE_UNIT_Y);
			Cone->normal(Quaternion * Normal);
			Cone->textureCoord(BaseSegmentIndex / (Ogre::Real)m_BaseSegments, HeightSegmentIndex / (Ogre::Real)m_HeightSegments);

			if (HeightSegmentIndex != m_HeightSegments && BaseSegmentIndex != m_BaseSegments)
			{
				Cone->index(Offset + m_BaseSegments + 2);
				Cone->index(Offset);
				Cone->index(Offset + m_BaseSegments + 1);
				Cone->index(Offset + m_BaseSegments + 2);
				Cone->index(Offset + 1);
				Cone->index(Offset);
			}

			Offset++;
		}
	}

	int centerIndex = Offset;
	
	Cone->position(0,0,0);
	Cone->normal(Ogre::Vector3::NEGATIVE_UNIT_Y);
	Cone->textureCoord(0.0,1);
	Offset++;
	
	for (int BaseSegmentIndex=0; BaseSegmentIndex <= m_BaseSegments; BaseSegmentIndex++)
	{
		Ogre::Real x = m_Radius * cosf(BaseSegmentIndex*deltaAngle);
		Ogre::Real z = m_Radius * sinf(BaseSegmentIndex*deltaAngle);

		Cone->position(x, 0.0f, z);
		Cone->colour(Intensity, Intensity, 0.0, 0.0);
		Cone->normal(Ogre::Vector3::NEGATIVE_UNIT_Y);
		Cone->textureCoord(BaseSegmentIndex/(Ogre::Real)m_BaseSegments,0.0);
		if (BaseSegmentIndex != m_BaseSegments)
		{
			Cone->index(centerIndex);
			Cone->index(Offset);
			Cone->index(Offset+1);
		}
		Offset++;
	}

	Cone->end();

	return Cone;
}
void AerialMapDisplay::assembleScene() {
  if (!dirty_) {
    return; //  nothing to update
  }
  dirty_ = false;
  
  if (!loader_) {
    return; //  no tiles loaded, don't do anything
  }
  
  //  get rid of old geometry, we will re-build this
  clearGeometry();
  
  //  iterate over all tiles and create an object for each of them
  const double resolution = loader_->resolution();
  const std::vector<TileLoader::MapTile> &tiles = loader_->tiles();
  for (const TileLoader::MapTile &tile : tiles) {
    const int w = tile.image().width();
    const int h = tile.image().height();
    //  we here assume that the tiles are uniformly sized...
    const double tileW = w * resolution;
    const double tileH = h * resolution;
    const double origin_x = -loader_->originX() * tileW;
    const double origin_y = -(1 - loader_->originY()) * tileH;

    //  determine location of this tile
    const double x = (tile.x() - loader_->tileX()) * tileW + origin_x;
    const double y = -(tile.y() - loader_->tileY()) * tileH + origin_y;
    //  don't re-use any ids
    const std::string name_suffix =
        std::to_string(tile.x()) + "_" + std::to_string(tile.y()) + "_" +
        std::to_string(map_id_) + "_" + std::to_string(scene_id_);

    Ogre::TexturePtr tex;
    if (tile.hasImage()) {
      //  one material per texture
      std::string matName = "material_" + name_suffix;
      Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().create(
          matName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
      material->setReceiveShadows(false);
      material->getTechnique(0)->setLightingEnabled(false);
      material->setDepthBias(-16.0f,
                             0.0f); /// @todo: what the f**k does this do?
      material->setCullingMode(Ogre::CULL_NONE);
      material->setDepthWriteEnabled(false);

      //  create textureing unit
      Ogre::Pass *pass = material->getTechnique(0)->getPass(0);
      Ogre::TextureUnitState *tex_unit = NULL;
      if (pass->getNumTextureUnitStates() > 0) {
        tex_unit = pass->getTextureUnitState(0);
      } else {
        tex_unit = pass->createTextureUnitState();
      }

      //  only add if we have a texture for it
      tex = textureFromImage(tile.image(), "texture_" + name_suffix);

      ROS_INFO("Rendering with texture: %s", tex->getName().c_str());
      tex_unit->setTextureName(tex->getName());
      tex_unit->setTextureFiltering(Ogre::TFO_BILINEAR);

      //  create an object
      const std::string obj_name = "object_" + name_suffix;
      Ogre::ManualObject *obj = scene_manager_->createManualObject(obj_name);
      scene_node_->attachObject(obj);

      //  configure depth & alpha properties
      if (alpha_ >= 0.9998) {
        material->setDepthWriteEnabled(!draw_under_);
        material->setSceneBlending(Ogre::SBT_REPLACE);
      } else {
        material->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
        material->setDepthWriteEnabled(false);
      }

      if (draw_under_) {
        obj->setRenderQueueGroup(Ogre::RENDER_QUEUE_4);
      } else {
        obj->setRenderQueueGroup(Ogre::RENDER_QUEUE_MAIN);
      }

      tex_unit->setAlphaOperation(Ogre::LBX_SOURCE1, Ogre::LBS_MANUAL,
                                  Ogre::LBS_CURRENT, alpha_);

      //  create a quad for this tile
      obj->begin(material->getName(), Ogre::RenderOperation::OT_TRIANGLE_LIST);

      //  bottom left
      obj->position(x, y, 0.0f);
      obj->textureCoord(0.0f, 0.0f);
      obj->normal(0.0f, 0.0f, 1.0f);

      // top right
      obj->position(x + tileW, y + tileH, 0.0f);
      obj->textureCoord(1.0f, 1.0f);
      obj->normal(0.0f, 0.0f, 1.0f);

      // top left
      obj->position(x, y + tileH, 0.0f);
      obj->textureCoord(0.0f, 1.0f);
      obj->normal(0.0f, 0.0f, 1.0f);

      //  bottom left
      obj->position(x, y, 0.0f);
      obj->textureCoord(0.0f, 0.0f);
      obj->normal(0.0f, 0.0f, 1.0f);

      // bottom right
      obj->position(x + tileW, y, 0.0f);
      obj->textureCoord(1.0f, 0.0f);
      obj->normal(0.0f, 0.0f, 1.0f);

      // top right
      obj->position(x + tileW, y + tileH, 0.0f);
      obj->textureCoord(1.0f, 1.0f);
      obj->normal(0.0f, 0.0f, 1.0f);

      obj->end();

      if (draw_under_property_->getValue().toBool()) {
        //  render under everything else
        obj->setRenderQueueGroup(Ogre::RENDER_QUEUE_4);
      }

      MapObject object;
      object.object = obj;
      object.texture = tex;
      object.material = material;
      objects_.push_back(object);
    }
  }
  scene_id_++;
}
void ParticleFactory::CreateThrusterParticleGeometry(Ogre::String object_name, int num_particles, float loop_radius, float circle_radius){

	//try {
		/* Retrieve scene manager and root scene node */
       // Ogre::SceneManager* scene_manager = ogre_root_->getSceneManager("MySceneManager");
        Ogre::SceneNode* root_scene_node = scene_manager->getRootSceneNode();

        /* Create the 3D object */
        Ogre::ManualObject* object = NULL;
        object = scene_manager->createManualObject(object_name);
        object->setDynamic(false);
/*
        /* Create point list for the object */
		object->begin("", Ogre::RenderOperation::OT_POINT_LIST);

		/* Initialize random numbers */
		std::srand(std::time(0));

		/* Create a set of points which will be the particles */
		/* This is similar to drawing a torus: we will sample points on the surface of the torus */

		
		float maxspray = 1.5; // This is how much we allow the points to wander around
		float u, v, w, theta, phi, spray; // Work variables
		for (int i = 0; i < num_particles; i++){
			
			// Randomly select two numbers to define a point on the torus
			u = ((double) rand() / (RAND_MAX));
            v = ((double) rand() / (RAND_MAX));
            
			// Use u and v to define the point on the torus
            theta = u * Ogre::Math::TWO_PI;
			phi = v * Ogre::Math::TWO_PI;
			Ogre::Vector3 center = Ogre::Vector3(loop_radius*cos(theta), loop_radius*sin(theta), 0.0);
            Ogre::Vector3 normal = Ogre::Vector3(cos(theta)*cos(phi), sin(theta)*cos(phi), sin(phi));
			object->position(center + normal*circle_radius); // Position of the point
			object->colour(Ogre::ColourValue(((float) i)/((float) num_particles), 0.0, 1.0 - (((float) i)/((float) num_particles))));
			object->textureCoord(Ogre::Vector2(0.0, 0.0));

			// Now sample a point on a sphere to define a direction for points to wander around
			u = ((double) rand() / (RAND_MAX));
            v = ((double) rand() / (RAND_MAX));
			w = ((double) rand() / (RAND_MAX));
			
			theta = u * Ogre::Math::TWO_PI;
			phi = acos(2.0*v * -1.0);
			spray = maxspray*pow((float) w, (float) (1.0/4.0)); // Cubic root
			Ogre::Vector3 wander = Ogre::Vector3(spray*cos(theta)*cos(phi), spray*cos(theta)*sin(phi), sin(phi)*-2);

			object->normal(wander);
		}

		object->position(Ogre::Vector3(0.0f, 0.0f, -30.0f));
		object->colour(Ogre::ColourValue(0.0f, 0.0f, 0.0f));
		object->textureCoord(Ogre::Vector2(0.0f, 0.0f));
		object->normal(Ogre::Vector3(0.0f, 0.0f, -30.0f));

        object->end();
		
		
		
        /* Convert triangle list to a mesh */
        object->convertToMesh(object_name);
  /*  }
    catch (Ogre::Exception &e){
        throw(OgreAppException(std::string("Ogre::Exception: ") + std::string(e.what())));
    }
    catch(std::exception &e){
        throw(OgreAppException(std::string("std::Exception: ") + std::string(e.what())));
    }*/
}
Example #16
0
void CubeWorld::createChunkWater (const int StartX, const int StartY, const int StartZ)
{
	block_t LastBlock = 0;

	int iVertex = 0;
	block_t Block;
	block_t Block1;

	/* Only create visible faces of chunk */
	block_t DefaultBlock = 1;
	int SX = 0;
	int SY = 0;
	int SZ = 0;
	int MaxSize = WORLD_SIZE;

	float BlockLight;
	float BlockLight1;
	float BlockLight2;

	float V1, V2;

	Ogre::ManualObject* MeshChunk = new Ogre::ManualObject("MeshWaterChunk" + Ogre::StringConverter::toString(m_ChunkID));
	MeshChunk->setDynamic(true);
	MeshChunk->begin("WaterTest");

	for (int z = StartZ; z < CHUNK_SIZE + StartZ; ++z)
	{
		for (int y = StartY; y < CHUNK_SIZE + StartY; ++y)
		{
			for (int x = StartX; x < CHUNK_SIZE + StartX; ++x)
			{
				Block = GetBlock(x,y,z);
				if (Block != 5) continue;   //Only create water meshes


				BlockLight  = GetBlockLight(x, y, z) / 255.0f;
				BlockLight1 = BlockLight * 0.9f;
				BlockLight2 = BlockLight * 0.8f;


				V1 = 1.0f/5.0f * (float)(Block - 1);
				V2 = V1 + 1.0f/5.0f;

				//x-1
				Block1 = DefaultBlock;
				if (x > SX) Block1 = GetBlock(x-1,y,z);

				if (Block1 != 5)
				{
                                        //create face of block
					MeshChunk->position(x, y,   z+1); MeshChunk->normal(-1,0,0);	MeshChunk->textureCoord(0, V2); MeshChunk->colour(BlockLight, BlockLight, BlockLight);
					MeshChunk->position(x, y+1, z+1); MeshChunk->normal(-1,0,0);	MeshChunk->textureCoord(1, V2); MeshChunk->colour(BlockLight, BlockLight, BlockLight);
					MeshChunk->position(x, y+1, z);	  MeshChunk->normal(-1,0,0);	MeshChunk->textureCoord(1, V1); MeshChunk->colour(BlockLight, BlockLight, BlockLight);
					MeshChunk->position(x, y,   z);	  MeshChunk->normal(-1,0,0);	MeshChunk->textureCoord(0, V1); MeshChunk->colour(BlockLight, BlockLight, BlockLight);

					MeshChunk->triangle(iVertex, iVertex+1, iVertex+2);
					MeshChunk->triangle(iVertex+2, iVertex+3, iVertex);

					iVertex += 4;
                                }

				//x+1
				Block1 = DefaultBlock;
				if (x < SX + MaxSize - 1)
					Block1 = GetBlock(x+1,y,z);

				if (Block1 != 5)
				    {
					    MeshChunk->position(x+1, y,   z);	MeshChunk->normal(1,0,0); MeshChunk->textureCoord(0, V2); MeshChunk->colour(BlockLight, BlockLight, BlockLight);
					    MeshChunk->position(x+1, y+1, z);	MeshChunk->normal(1,0,0); MeshChunk->textureCoord(1, V2); MeshChunk->colour(BlockLight, BlockLight, BlockLight);
					    MeshChunk->position(x+1, y+1, z+1);	MeshChunk->normal(1,0,0); MeshChunk->textureCoord(1, V1); MeshChunk->colour(BlockLight, BlockLight, BlockLight);
					    MeshChunk->position(x+1, y,   z+1);	MeshChunk->normal(1,0,0); MeshChunk->textureCoord(0, V1); MeshChunk->colour(BlockLight, BlockLight, BlockLight);

					    MeshChunk->triangle(iVertex, iVertex+1, iVertex+2);
					    MeshChunk->triangle(iVertex+2, iVertex+3, iVertex);

					    iVertex += 4;
				    }

				//y-1
				Block1 = DefaultBlock;
				if (y > SY)
					Block1 = GetBlock(x,y-1,z);

				if (Block1 != 5)
				    {
					    MeshChunk->position(x,   y, z);		MeshChunk->normal(0,-1,0); MeshChunk->textureCoord(0, V2); MeshChunk->colour(BlockLight2, BlockLight2, BlockLight2);
					    MeshChunk->position(x+1, y, z);		MeshChunk->normal(0,-1,0); MeshChunk->textureCoord(1, V2); MeshChunk->colour(BlockLight2, BlockLight2, BlockLight2);
					    MeshChunk->position(x+1, y, z+1);	MeshChunk->normal(0,-1,0); MeshChunk->textureCoord(1, V1); MeshChunk->colour(BlockLight2, BlockLight2, BlockLight2);
					    MeshChunk->position(x,   y, z+1);	MeshChunk->normal(0,-1,0); MeshChunk->textureCoord(0, V1); MeshChunk->colour(BlockLight2, BlockLight2, BlockLight2);

					    MeshChunk->triangle(iVertex, iVertex+1, iVertex+2);
					    MeshChunk->triangle(iVertex+2, iVertex+3, iVertex);

					    iVertex += 4;
				    }


				//y+1
				Block1 = DefaultBlock;
				if (y < SY + MaxSize - 1)
					Block1 = GetBlock(x,y+1,z);

				if (Block1 != 5)
				    {
					    MeshChunk->position(x,   y+1, z+1);		MeshChunk->normal(0,1,0); MeshChunk->textureCoord(0, V2); MeshChunk->colour(BlockLight2, BlockLight2, BlockLight2);
					    MeshChunk->position(x+1, y+1, z+1);		MeshChunk->normal(0,1,0); MeshChunk->textureCoord(1, V2); MeshChunk->colour(BlockLight2, BlockLight2, BlockLight2);
					    MeshChunk->position(x+1, y+1, z);		MeshChunk->normal(0,1,0); MeshChunk->textureCoord(1, V1); MeshChunk->colour(BlockLight2, BlockLight2, BlockLight2);
					    MeshChunk->position(x,   y+1, z);		MeshChunk->normal(0,1,0); MeshChunk->textureCoord(0, V1); MeshChunk->colour(BlockLight2, BlockLight2, BlockLight2);

					    MeshChunk->triangle(iVertex, iVertex+1, iVertex+2);
					    MeshChunk->triangle(iVertex+2, iVertex+3, iVertex);

					    iVertex += 4;
				    }

				//z-1
				Block1 = DefaultBlock;
				if (z > SZ)
					Block1 = GetBlock(x,y,z-1);

				if (Block1 != 5)
				    {
					    MeshChunk->position(x,   y+1, z);		MeshChunk->normal(0,0,-1); MeshChunk->textureCoord(0, V2); MeshChunk->colour(BlockLight1, BlockLight1, BlockLight1);
					    MeshChunk->position(x+1, y+1, z);		MeshChunk->normal(0,0,-1); MeshChunk->textureCoord(1, V2); MeshChunk->colour(BlockLight1, BlockLight1, BlockLight1);
					    MeshChunk->position(x+1, y,   z);		MeshChunk->normal(0,0,-1); MeshChunk->textureCoord(1, V1); MeshChunk->colour(BlockLight1, BlockLight1, BlockLight1);
					    MeshChunk->position(x,   y,   z);		MeshChunk->normal(0,0,-1); MeshChunk->textureCoord(0, V1); MeshChunk->colour(BlockLight1, BlockLight1, BlockLight1);

					    MeshChunk->triangle(iVertex, iVertex+1, iVertex+2);
					    MeshChunk->triangle(iVertex+2, iVertex+3, iVertex);

					    iVertex += 4;
				    }


				//z+1
				Block1 = DefaultBlock;
				if (z < SZ + MaxSize - 1)
					Block1 = GetBlock(x,y,z+1);

				if (Block1 != 5)
				    {
					    MeshChunk->position(x,   y,   z+1);		MeshChunk->normal(0,0,1); MeshChunk->textureCoord(0, V2); MeshChunk->colour(BlockLight1, BlockLight1, BlockLight1);
					    MeshChunk->position(x+1, y,   z+1);		MeshChunk->normal(0,0,1); MeshChunk->textureCoord(1, V2); MeshChunk->colour(BlockLight1, BlockLight1, BlockLight1);
					    MeshChunk->position(x+1, y+1, z+1);		MeshChunk->normal(0,0,1); MeshChunk->textureCoord(1, V1); MeshChunk->colour(BlockLight1, BlockLight1, BlockLight1);
					    MeshChunk->position(x,   y+1, z+1);		MeshChunk->normal(0,0,1); MeshChunk->textureCoord(0, V1); MeshChunk->colour(BlockLight1, BlockLight1, BlockLight1);

					    MeshChunk->triangle(iVertex, iVertex+1, iVertex+2);
					    MeshChunk->triangle(iVertex+2, iVertex+3, iVertex);

					    iVertex += 4;
				    }
			}
		}
	}
	MeshChunk->end();
	mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(MeshChunk);
	++m_ChunkID;

}
Example #17
0
/***
Creates a chunk at (chunk_x,chunk_y,chunk_z) in chunk coordinates.
Allocations:
 - pos: position of chunk in real coordinates
 - sn: chunk's scenenode
 - mo: chunk's mesh (manualobject)
 - vertices: memoization of mesh's vertices
 - trimesh: holds triangle data for bullet
 - tms: collision shape using trimesh
 - ms: motion state
 - rb: chunk's rigidbody

***/
void ChunkManager::createChunk(int chunk_x, int chunk_y, int chunk_z) {
    if (hasChunkAtChunkCoords(chunk_x, chunk_y, chunk_z)) {
        // Don't do anything if we already have a chunk there.
        return;
    }
    mName = new Ogre::String("Chunk_"+Ogre::StringConverter::toString(chunk_x)+"_"+Ogre::StringConverter::toString(chunk_y)+"_"+Ogre::StringConverter::toString(chunk_z));
    Ogre::Vector3 pos = chunkToRealCoords(chunk_x,chunk_y,chunk_z);
    Ogre::SceneNode* sn = mGame->createSceneNode(pos);
    clock_t t;
    Game::log(TAG, "Creating chunk...");
    t = clock();
    Landscape* landscape = mGame->getLandscape();
    Ogre::ManualObject* mo = new Ogre::ManualObject("ChunkManualObject" + *mName);

    /*** The following code is to memoize the mesh creation process. I don't know if it will make things faster (most likely will), but
    I'll keep it here for now to test later in case the speed of this function is slow.***/

    Ogre::Vector3** vertices = new Ogre::Vector3* [(SIZES::CHUNK_SIZE+2)*(SIZES::CHUNK_SIZE+2)]; // + 2 to account for the edge vertices

    for (int i = 0; i < (SIZES::CHUNK_SIZE+2)*(SIZES::CHUNK_SIZE+2); i++) {
        vertices[i] = NULL;
    }

    // Create the meshes
    //mo->begin("Astral/Grass");
    mo->begin("Examples/GrassFloor");
    for (int x = 0; x < SIZES::CHUNK_SIZE; x++) {
        for (int z = 0; z < SIZES::CHUNK_SIZE; z++) {
            // vx, vy, vz define the next vertex we want to add to the manualobject.
            int vx = x + pos.x;
            int vz = z + pos.z;
            Ogre::Vector3 v = *getVector(vx,vz,landscape,vertices);
            // add the vertex
            mo->position(v);

            // now we need to find the faces this vertex touches
            Ogre::Vector3 ll = *getVector(vx-1,vz-1,landscape,vertices);
            Ogre::Vector3 lm = *getVector(vx,vz-1,landscape,vertices);
            Ogre::Vector3 lr = *getVector(vx+1,vz-1,landscape,vertices);
            Ogre::Vector3 ml = *getVector(vx-1,vz,landscape,vertices);
            Ogre::Vector3 mr = *getVector(vx+1,vz,landscape,vertices);
            Ogre::Vector3 ul = *getVector(vx-1,vz+1,landscape,vertices);
            Ogre::Vector3 um = *getVector(vx,vz+1,landscape,vertices);
            Ogre::Vector3 ur = *getVector(vx+1,vz+1,landscape,vertices);


            Ogre::Vector3 normal = Ogre::Vector3(0,0,0);

            normal += (v - ll).crossProduct(lm - ll).normalisedCopy();
            normal += (ml - ll).crossProduct(v - ll).normalisedCopy();
            normal += (um - ml).crossProduct(v - ml).normalisedCopy();
            normal += (ul - ml).crossProduct(um - ml).normalisedCopy();
            normal += (um - v).crossProduct(ur - v).normalisedCopy();
            normal += (ur - v).crossProduct(mr - v).normalisedCopy();
            normal += (v - lm).crossProduct(mr - lm).normalisedCopy();
            normal += (mr - lm).crossProduct(lr - lm).normalisedCopy();

            mo->normal(normal.normalisedCopy());

            mo->textureCoord((float)x/(float)SIZES::CHUNK_TEXTURE_TILE,(float)z/(float)SIZES::CHUNK_TEXTURE_TILE);

        }
    }
    Game::log(TAG, "Vertices created");

    btTriangleMesh* trimesh = new btTriangleMesh();
    for (int x = 0; x < SIZES::CHUNK_SIZE - 1; x++) {
        for (int z = 0; z < SIZES::CHUNK_SIZE - 1; z++) {
            mo->triangle((x * SIZES::CHUNK_SIZE) + z + 1,
                         ((x + 1) * SIZES::CHUNK_SIZE) + z,
                         (x * SIZES::CHUNK_SIZE) + z);

            mo->triangle((x * SIZES::CHUNK_SIZE) + z + 1,
                         ((x + 1) * SIZES::CHUNK_SIZE) + z + 1,
                         ((x + 1) * SIZES::CHUNK_SIZE) + z);

            Ogre::Vector3* a = vertices[(x+1)*(SIZES::CHUNK_SIZE+2)+z+2];
            Ogre::Vector3* b = vertices[(x+2)*(SIZES::CHUNK_SIZE+2)+z+1];
            Ogre::Vector3* c = vertices[(x+1)*(SIZES::CHUNK_SIZE+2)+z+1];
            Ogre::Vector3* d = vertices[(x+2)*(SIZES::CHUNK_SIZE+2)+z+2];
            trimesh->addTriangle(btVector3(a->x,a->y,a->z),
                                 btVector3(b->x,b->y,b->z),
                                 btVector3(c->x,c->y,c->z));
            trimesh->addTriangle(btVector3(a->x,a->y,a->z),
                                 btVector3(d->x,d->y,d->z),
                                 btVector3(b->x,b->y,b->z));
        }
    }
    mo->end();
    sn->attachObject(mo);
    Game::log(TAG, "mo attached");

    btBvhTriangleMeshShape* tms = new btBvhTriangleMeshShape(trimesh,
                                                             true); //useQuantizedAabbCompression
//    btShapeHull* hull = new btShapeHull(tms);
//    btScalar margin = tms->getMargin();
//    hull->buildHull(margin);
//    btConvexHullShape* chs = new btConvexHullShape((btScalar*)hull->getVertexPointer(), hull->numVertices());
    // I give it this motionstate and not an Ogre one because chunks shouldn't move anyways
    btDefaultMotionState* ms = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(pos.x,pos.y,pos.z)));
    btRigidBody::btRigidBodyConstructionInfo info(0,ms,tms);
    btRigidBody* rb = new btRigidBody(info);
    Game::log(TAG, "rb created");

    mGame->addRigidBody(rb);
    Game::log(TAG, "rb added");

    // Clean up
    for (int i = 0; i < (SIZES::CHUNK_SIZE+2)*(SIZES::CHUNK_SIZE+2); i++) {
        delete vertices[i];
    }
    delete [] vertices;

    // Time stats
    t = clock() - t;
    Game::log(TAG, "Done creating chunk mesh.");
    Game::log(TAG, "Mesh created in "+Ogre::StringConverter::toString((long)t)+" ticks.");
    mChunks[chunk_x][chunk_y][chunk_z] = new Chunk(sn, mo, trimesh, tms, ms, rb);
}
Example #18
0
void OgreApplication::CreateWall(Ogre::String material_name){
	    
	try {

		/* Create two rectangles */

        /* Retrieve scene manager and root scene node */
        Ogre::SceneManager* scene_manager = ogre_root_->getSceneManager("MySceneManager");
        Ogre::SceneNode* root_scene_node = scene_manager->getRootSceneNode();

        /* Create the 3D object */
        Ogre::ManualObject* object = NULL;
        Ogre::String object_name = "Wall";
        object = scene_manager->createManualObject(object_name);
        object->setDynamic(false);

        /* Create triangle list for the object */
        object->begin(material_name, Ogre::RenderOperation::OT_TRIANGLE_LIST);

		/* Add vertices */
		/* One side of the "wall" */
		object->position(-1.0,-1.0,0.0);
		object->normal(0.0, 0.0, -1.0);
		object->tangent(-1.0, 0.0, 0.0);
		object->textureCoord(1.0, 0.0);

        object->position(-1.0,1.0,0.0);
		object->normal(0.0, 0.0, -1.0);
		object->tangent(-1.0, 0.0, 0.0);
		object->textureCoord(1.0, 1.0);

        object->position(1.0,1.0,0.0);
		object->normal(0.0, 0.0, -1.0);
		object->tangent(-1.0, 0.0, 0.0);
		object->textureCoord(0.0, 1.0);

        object->position(1.0,-1.0,0.0);
		object->normal(0.0, 0.0, -1.0);
		object->tangent(-1.0, 0.0, 0.0);
		object->textureCoord(0.0, 0.0);

		/* The other side of the "wall" */
        object->position(-1.0,-1.0,0.0);
		object->normal(0.0, 0.0, 1.0);
		object->tangent(1.0, 0.0, 0.0);
		object->textureCoord(0.0, 0.0);

        object->position(-1.0,1.0,0.0);
		object->normal(0.0, 0.0, 1.0);
		object->tangent(1.0, 0.0, 0.0);
		object->textureCoord(0.0, 1.0);

        object->position(1.0,1.0,0.0);
		object->normal(0.0, 0.0, 1.0);
		object->tangent(1.0, 0.0, 0.0);
		object->textureCoord(1.0, 1.0);

        object->position(1.0,-1.0,0.0);
		object->normal(0.0, 0.0, 1.0);
		object->tangent(1.0, 0.0, 0.0);
		object->textureCoord(1.0, 0.0);
        
		/* Add triangles */
		/* One side */
		object->triangle(0, 1, 2);
        object->triangle(0, 2, 3);
		/* The other side */
        object->triangle(4, 7, 6);
        object->triangle(4, 6, 5);
        
		/* We finished the object */
        object->end();
		
        /* Convert triangle list to a mesh */
        Ogre::String mesh_name = "Wall";
        object->convertToMesh(mesh_name);

        /* Create one instance of the sphere (one entity) */
		/* The same object can have multiple instances or entities */
        Ogre::Entity* entity = scene_manager->createEntity(mesh_name);

		/* Apply a material to the entity to give it color */
		/* We already did that above, so we comment it out here */
		/* entity->setMaterialName(material_name); */
		/* But, this call is useful if we have multiple entities with different materials */

		/* Create a scene node for the entity */
		/* The scene node keeps track of the entity's position */
        Ogre::SceneNode* scene_node = root_scene_node->createChildSceneNode(mesh_name);
        scene_node->attachObject(entity);

        /* Position and rotate the entity with the scene node */
		//scene_node->rotate(Ogre::Vector3(0, 1, 0), Ogre::Degree(60));
		//scene_node->rotate(Ogre::Vector3(1, 0, 0), Ogre::Degree(30));
		//scene_node->rotate(Ogre::Vector3(1, 0, 0), Ogre::Degree(-90));
        //scene_node->translate(0.0, 0.0, 0.0);
		scene_node->scale(0.5, 0.5, 0.5);
    }
    catch (Ogre::Exception &e){
        throw(OgreAppException(std::string("Ogre::Exception: ") + std::string(e.what())));
    }
    catch(std::exception &e){
        throw(OgreAppException(std::string("std::Exception: ") + std::string(e.what())));
    }
}
Example #19
0
Ogre::ManualObject* BasicTutorial2::createCubeMesh (Ogre::String name, Ogre::String matName) 
{
   Ogre::ManualObject* cube = new Ogre::ManualObject(name);
   cube->begin(matName);
 
   cube->position(0.5f,-0.5f,1.0f);cube->normal(0.408248f,-0.816497f,0.408248f);cube->textureCoord(1,0);
   cube->position(-0.5f,-0.5f,0.0f);cube->normal(-0.408248f,-0.816497f,-0.408248f);cube->textureCoord(0,1);
   cube->position(0.5f,-0.5f,0.0f);cube->normal(0.666667f,-0.333333f,-0.666667f);cube->textureCoord(1,1);
   cube->position(-0.5f,-0.5f,1.0f);cube->normal(-0.666667f,-0.333333f,0.666667f);cube->textureCoord(0,0);
   cube->position(0.5f,0.5f,1.0f);cube->normal(0.666667f,0.333333f,0.666667f);cube->textureCoord(1,0);
   cube->position(-0.5,-0.5,1.0);cube->normal(-0.666667f,-0.333333f,0.666667f);cube->textureCoord(0,1);
   cube->position(0.5,-0.5,1.0);cube->normal(0.408248,-0.816497,0.408248f);cube->textureCoord(1,1);
   cube->position(-0.5,0.5,1.0);cube->normal(-0.408248,0.816497,0.408248);cube->textureCoord(0,0);
   cube->position(-0.5,0.5,0.0);cube->normal(-0.666667,0.333333,-0.666667);cube->textureCoord(0,1);
   cube->position(-0.5,-0.5,0.0);cube->normal(-0.408248,-0.816497,-0.408248);cube->textureCoord(1,1);
   cube->position(-0.5,-0.5,1.0);cube->normal(-0.666667,-0.333333,0.666667);cube->textureCoord(1,0);
   cube->position(0.5,-0.5,0.0);cube->normal(0.666667,-0.333333,-0.666667);cube->textureCoord(0,1);
   cube->position(0.5,0.5,0.0);cube->normal(0.408248,0.816497,-0.408248);cube->textureCoord(1,1);
   cube->position(0.5,-0.5,1.0);cube->normal(0.408248,-0.816497,0.408248);cube->textureCoord(0,0);
   cube->position(0.5,-0.5,0.0);cube->normal(0.666667,-0.333333,-0.666667);cube->textureCoord(1,0);
   cube->position(-0.5,-0.5,0.0);cube->normal(-0.408248,-0.816497,-0.408248);cube->textureCoord(0,0);
   cube->position(-0.5,0.5,1.0);cube->normal(-0.408248,0.816497,0.408248);cube->textureCoord(1,0);
   cube->position(0.5,0.5,0.0);cube->normal(0.408248,0.816497,-0.408248);cube->textureCoord(0,1);
   cube->position(-0.5,0.5,0.0);cube->normal(-0.666667,0.333333,-0.666667);cube->textureCoord(1,1);
   cube->position(0.5,0.5,1.0);cube->normal(0.666667,0.333333,0.666667);cube->textureCoord(0,0);
 
   cube->triangle(0,1,2);      cube->triangle(3,1,0);
   cube->triangle(4,5,6);      cube->triangle(4,7,5);
   cube->triangle(8,9,10);      cube->triangle(10,7,8);
   cube->triangle(4,11,12);   cube->triangle(4,13,11);
   cube->triangle(14,8,12);   cube->triangle(14,15,8);
   cube->triangle(16,17,18);   cube->triangle(16,19,17);
   cube->end();
 
   return cube;
}
Example #20
0
void Map::generateMeshObstacles(std::string materialName)
{
    Ogre::ManualObject* obstacles = new Ogre::ManualObject("obstacles");
    obstacles->estimateIndexCount(m_length * m_width * 8);
    obstacles->estimateVertexCount(m_length * m_width * 8);
    obstacles->clear();
    obstacles->begin(materialName);

    Ogre::Vector3 pos = Ogre::Vector3(0, 0, 0);
    Ogre::Quaternion quat;
    Ogre::Quaternion quatNext;
    unsigned long planeNum = 0;

    m_obstaclePositions.clear();

    for (unsigned int i = 0; i < m_length; i++) {
        quat = m_rotationalSpline.getPoint(i);
        quatNext = m_rotationalSpline.getPoint(i + 1);

        for (int x = -100 * (m_width / (double) 2), j = 0; (unsigned) j < m_width; j++, x += 100) {
            int back = -100;
            int left = x;
            int right = x + 100;
            int up = 100;

            Ogre::Vector3 nextPos =             pos + quat * Ogre::Vector3(0, 0, back);
            Ogre::Vector3 posMinus50 =          pos + quat * Ogre::Vector3(left, 0, 0);
            Ogre::Vector3 posPlus50 =           pos + quat * Ogre::Vector3(right, 0, 0);
            Ogre::Vector3 nextPosMinus50 =      nextPos + quatNext * Ogre::Vector3(left, 0, 0);
            Ogre::Vector3 nextPosPlus50 =       nextPos + quatNext * Ogre::Vector3(right, 0, 0);

            //TODO: fix normals
            obstacles->position(posMinus50);
            obstacles->normal((quat * Vector3(0, 1, 0)).normalisedCopy());
            obstacles->textureCoord(1, 1);
            obstacles->position(nextPosMinus50);
            obstacles->normal((quat * Vector3(0, 1, 0)).normalisedCopy());
            obstacles->textureCoord(1, 0);
            obstacles->position(posPlus50);
            obstacles->normal((quat * Vector3(0, 1, 0)).normalisedCopy());
            obstacles->textureCoord(0, 1);
            obstacles->position(nextPosPlus50);
            obstacles->normal((quat * Vector3(0, 1, 0)).normalisedCopy());
            obstacles->textureCoord(0, 0);

            Ogre::Vector3 nextPosUp =           nextPos + quat * Ogre::Vector3(0, up, 0);
            Ogre::Vector3 posMinus50Up =        posMinus50 + quat * Ogre::Vector3(0, up, 0);
            Ogre::Vector3 posPlus50Up =         posPlus50 + quat * Ogre::Vector3(0, up, 0);
            Ogre::Vector3 nextPosMinus50Up =    nextPosMinus50 + quatNext * Ogre::Vector3(0, up, 0);
            Ogre::Vector3 nextPosPlus50Up =     nextPosPlus50 + quatNext * Ogre::Vector3(0, up, 0);

            //TODO: fix normals
            obstacles->position(posMinus50Up);
            obstacles->normal((quat * Vector3(-1, 1, 1)).normalisedCopy());
            obstacles->textureCoord(0, 0);
            obstacles->position(nextPosMinus50Up);
            obstacles->normal((quat * Vector3(-1, 1, -1)).normalisedCopy());
            obstacles->textureCoord(0, 1);
            obstacles->position(posPlus50Up);
            obstacles->normal((quat * Vector3(1, 1, 1)).normalisedCopy());
            obstacles->textureCoord(1, 0);
            obstacles->position(nextPosPlus50Up);
            obstacles->normal((quat * Vector3(1, 1, -1)).normalisedCopy());
            obstacles->textureCoord(1, 1);

            if (m_cubes[planeNum / (double) m_width][planeNum % m_width] == OBSTACLE) {

                //TODO: check if this hack works..
                m_obstaclePositions.push_back(posMinus50);

                //top
                obstacles->triangle(4 + planeNum * 8, 5 + planeNum * 8, 6 + planeNum * 8);
                obstacles->triangle(6 + planeNum * 8, 5 + planeNum * 8, 4 + planeNum * 8);
                obstacles->triangle(5 + planeNum * 8, 7 + planeNum * 8, 6 + planeNum * 8);
                obstacles->triangle(6 + planeNum * 8, 7 + planeNum * 8, 5 + planeNum * 8);

                if (planeNum % m_width == 0 || m_cubes[planeNum / (double) m_width][(planeNum - 1) % m_width] != OBSTACLE) {
                    //left
                    obstacles->triangle(0 + planeNum * 8, 4 + planeNum * 8, 5 + planeNum * 8);
                    obstacles->triangle(5 + planeNum * 8, 4 + planeNum * 8, 0 + planeNum * 8);
                    obstacles->triangle(0 + planeNum * 8, 1 + planeNum * 8, 5 + planeNum * 8);
                    obstacles->triangle(5 + planeNum * 8, 1 + planeNum * 8, 0 + planeNum * 8);
                }

                if (planeNum % m_width == m_width - 1 || m_cubes[planeNum / (double) m_width][(planeNum + 1) % m_width] != OBSTACLE) {
                    //right
                    obstacles->triangle(2 + planeNum * 8, 6 + planeNum * 8, 7 + planeNum * 8);
                    obstacles->triangle(7 + planeNum * 8, 6 + planeNum * 8, 2 + planeNum * 8);
                    obstacles->triangle(2 + planeNum * 8, 3 + planeNum * 8, 7 + planeNum * 8);
                    obstacles->triangle(7 + planeNum * 8, 3 + planeNum * 8, 2 + planeNum * 8);
                }

                if (planeNum / (double) m_width >= m_length - 1 || m_cubes[(planeNum + m_width) / (double) m_width][planeNum % m_width] != OBSTACLE) {
                    //back
                    obstacles->triangle(5 + planeNum * 8, 7 + planeNum * 8, 1 + planeNum * 8);
                    obstacles->triangle(1 + planeNum * 8, 7 + planeNum * 8, 5 + planeNum * 8);
                    obstacles->triangle(1 + planeNum * 8, 3 + planeNum * 8, 7 + planeNum * 8);
                    obstacles->triangle(7 + planeNum * 8, 3 + planeNum * 8, 1 + planeNum * 8);
                }

                if (planeNum / (double) m_width <= m_width || m_cubes[(planeNum - m_width) / (double) m_width][planeNum % m_width] != OBSTACLE) {
                    //front
                    obstacles->triangle(2 + planeNum * 8, 6 + planeNum * 8, 4 + planeNum * 8);
                    obstacles->triangle(4 + planeNum * 8, 6 + planeNum * 8, 2 + planeNum * 8);
                    obstacles->triangle(0 + planeNum * 8, 4 + planeNum * 8, 2 + planeNum * 8);
                    obstacles->triangle(2 + planeNum * 8, 4 + planeNum * 8, 0 + planeNum * 8);
                }
            }

            planeNum++;
        }

        pos = pos + quat * Ogre::Vector3(0, 0, -100);
    }

    obstacles->end();
    obstacles->setCastShadows(true);

    //TODO: fix graphics bug when no obstacles
    /*if (m_obstaclePositions.size() <= 0)
    {
        return;
    }*/

    m_mapMainNode->attachObject(obstacles);

    MeshPtr ptr = obstacles->convertToMesh("obstaclesMesh");
    Entity* obstaclesEntity = m_pSceneMgr->createEntity("obstaclesEntity", "obstaclesMesh");
}
		void SetUpCustomContent()
		{
			Ogre::String CustomCameraName = "TestRenderTargetCamera";
			Ogre::String CustomTextureName = "TestRenderTargetTexture";
			Ogre::String CustomMaterialName = "CustomRenderTargetMaterial";
			Ogre::String CustomWorkSpaceName = "TestCustomRenderTargetWorkSpaceName";

			m_CustomRTTCamera = mSceneManager->createCamera(CustomCameraName);
			m_CustomRTTCamera->setPosition(0, 30, 0);
			m_CustomRTTCamera->lookAt(0, 0, 0);
			m_CustomRTTCamera->setFarClipDistance(1000);
			m_CustomRTTCamera->setNearClipDistance(0.1);

			m_CustomRenderTexture = Ogre::TextureManager::getSingleton().createManual(CustomTextureName, 
				Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, 
				512, 512, 1, Ogre::PF_A8B8G8R8, Ogre::TU_RENDERTARGET);
			m_CustomRenderTexture->load();

			Ogre::RenderTexture* rtt = m_CustomRenderTexture->getBuffer(0)->getRenderTarget();


			Ogre::CompositorManager2 *compositorManager = mRoot->getCompositorManager2();

			const Ogre::IdString workspaceName(CustomWorkSpaceName);
			if( !compositorManager->hasWorkspaceDefinition( workspaceName ) )
			{
				compositorManager->createBasicWorkspaceDef( workspaceName, mBackgroundColour,
					Ogre::IdString() );
			}

			m_CustomRenderTarget = compositorManager->addWorkspace( mSceneManager, (Ogre::RenderTarget*)rtt, m_CustomRTTCamera,
					workspaceName, false );
			//m_CustomRenderTarget->setEnabled(false);			// not auto update
#if 0
			// create manual object
			Ogre::MaterialPtr CustomMaterial = Ogre::MaterialManager::getSingleton().create(CustomMaterialName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
			CustomMaterial->getTechnique(0)->removeAllPasses();
			Ogre::Pass* pass = CustomMaterial->getTechnique(0)->createPass();
			Ogre::TextureUnitState* tu = pass->createTextureUnitState();
			tu->setTextureName(CustomTextureName);
#endif
			Ogre::HlmsManager *hlmsManager = Ogre::Root::getSingleton().getHlmsManager();
			Ogre::Hlms *hlms = hlmsManager->getHlms( Ogre::HLMS_UNLIT );
			Ogre::HlmsDatablock *datablock = hlms->createDatablock( CustomMaterialName, CustomMaterialName,
				Ogre::HlmsMacroblock(), Ogre::HlmsBlendblock(), Ogre::HlmsParamVec() );
			Ogre::HlmsUnlitDatablock *unlitDb = static_cast<Ogre::HlmsUnlitDatablock*>( datablock );
			unlitDb->setTexture( 0, 0, m_CustomRenderTexture );
			
#if 1
			Ogre::ManualObject* CustomManualObject = mSceneManager->createManualObject();
			CustomManualObject->begin(CustomMaterialName);
			CustomManualObject->position(-100, -100, -100);
			CustomManualObject->textureCoord(0, 0);
			CustomManualObject->position(100, -100, -100);
			CustomManualObject->textureCoord(1, 0);
			CustomManualObject->position(100, 100, -100);
			CustomManualObject->textureCoord(1, 1);
			CustomManualObject->position(-100, 100, -100);
			CustomManualObject->textureCoord(0, 1);
			CustomManualObject->quad(0, 1, 2, 3);
			CustomManualObject->end();
//			CustomManualObject->setDatablock(0, CustomMaterialName);

			Ogre::SceneNode *sceneNodeLines = mSceneManager->getRootSceneNode( Ogre::SCENE_DYNAMIC )->
				createChildSceneNode( Ogre::SCENE_DYNAMIC );
			sceneNodeLines->attachObject(CustomManualObject);
			sceneNodeLines->scale(0.4f, 0.4f, 0.4f);
			sceneNodeLines->translate(0.0f, 0.0f, 0.0f, Ogre::SceneNode::TS_WORLD);
#endif
		}
Ogre::MeshPtr Loader::getMeshFromMdl(unsigned int id){
    if(!models[id].isNull()){
        return models[id];
    }
    std::string name = "mesh"+Utils::toStr(id);
    std::ifstream stream;
    stream.open(("Models/"+name+".mdl").c_str(),std::ios::in|std::ios::binary);
    
    Ogre::ManualObject* obj = OgreFramework::getSingletonPtr()->m_pSceneMgr->createManualObject();
     unsigned int texture, normalmap, vertices, indices;
     short endian;
     stream.read((char*)&endian,sizeof(short));
     stream.read((char*)&texture,sizeof(unsigned int));
     stream.read((char*)&normalmap,sizeof(unsigned int));
     stream.read((char*)&vertices,sizeof(unsigned int));
     stream.read((char*)&indices,sizeof(unsigned int));
     float bounds[6];//{minX,minY,minZ,maxX,maxY,maxZ}
     stream.read((char*)bounds,sizeof(float)*6);
     std::string textureFName,normalMapFName;
     for(int i=0;i<texture;i++){
         char c;
         stream.read((char*)&c,sizeof(char));
         textureFName+=c;
     }
     if(normalmap>0){
        for(int i=0;i<texture;i++){
            char c;
            stream.read((char*)&c,sizeof(char));
            normalMapFName+=c;
        }
     }
     if(normalmap>0)
        obj->begin("NormalMapTexture");
     else
        obj->begin("PlainTexture");
    float * arrayV = new float[vertices*(3+3+2)];
    stream.read((char*)arrayV,sizeof(float)*(3+3+2)*vertices);//should also work - automatically grab ALL vertex data to array in one operation :) C++ is great
    
    for(int i=0;i<vertices;i++){
        int ptr = i*(3+3+2);
        obj->position(arrayV[ptr],arrayV[ptr+1],arrayV[ptr+2]);
        obj->normal(arrayV[ptr+3],arrayV[ptr+4],arrayV[ptr+5]);
        obj->textureCoord(arrayV[ptr+6],arrayV[ptr+7]);
    }
    
    delete [] arrayV;
    unsigned int * arrayI = new unsigned int[indices];
    stream.read((char*)arrayI,sizeof(unsigned int)*indices);
    
    for(int i=0;i<indices;i++){
        obj->index(arrayI[i]);
    }
    
    delete [] arrayI;
    
    obj->end();
    /*if(normalmap>0){
        obj->setMaterialName("NormalMapTexture");
        obj->addTextureAlias("normalmap",normalMapFName);
    }
    else{
        obj->setMaterialName("OneTexture");
    }
    obj->addTextureAlias("textura",textureFName);*/
    OgreFramework::getSingletonPtr()->m_pSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(obj);
    Ogre::MeshPtr mesh = obj->convertToMesh(name);
    mesh->getSubMesh(0)->addTextureAlias("textura",textureFName);//TODO normalmap
    return mesh;
    
    /*Ogre::MeshPtr meshM = Ogre::MeshManager::getSingletonPtr()->createManual(name,"General");
     unsigned int texture, normalmap, vertices, indices;
     short endian;
     stream.read((char*)&endian,sizeof(short));
     stream.read((char*)&texture,sizeof(unsigned int));
     stream.read((char*)&normalmap,sizeof(unsigned int));
     stream.read((char*)&vertices,sizeof(unsigned int));
     stream.read((char*)&indices,sizeof(unsigned int));
     float bounds[6];//{minX,minY,minZ,maxX,maxY,maxZ}
     stream.read((char*)bounds,sizeof(float)*6);
     std::string textureFName,normalMapFName;
     for(int i=0;i<texture;i++){
         char c;
         stream.read((char*)&c,sizeof(char));
         textureFName+=c;
     }
     if(normalmap>0){
        for(int i=0;i<texture;i++){
            char c;
            stream.read((char*)&c,sizeof(char));
            normalMapFName+=c;
        }
     }
     Ogre::SubMesh* mesh = meshM->createSubMesh();
        // We first create a VertexData
     Ogre::VertexData* data = new Ogre::VertexData();
    // Then, we link it to our Mesh/SubMesh :
     #ifdef SHARED_GEOMETRY
        meshM->sharedVertexData = data;
     #else
        mesh->useSharedVertices = false; // This value is 'true' by default
        mesh->vertexData = data;
     #endif
    // We have to provide the number of verteices we'll put into this Mesh/SubMesh
     data->vertexCount = vertices;
    // Then we can create our VertexDeclaration
     Ogre::VertexDeclaration* decl = data->vertexDeclaration;
     size_t offset = 0;
    decl->addElement(0, offset, Ogre::VET_FLOAT3, Ogre::VES_POSITION);
    offset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3);
    decl->addElement(0, offset, Ogre::VET_FLOAT3, Ogre::VES_NORMAL);
    offset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3);
    decl->addElement(0, offset, Ogre::VET_FLOAT2, Ogre::VES_TEXTURE_COORDINATES);
    offset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT2);//you can't animate because one buffer
    Ogre::HardwareVertexBufferSharedPtr vbuf = Ogre::HardwareBufferManager::getSingleton().createVertexBuffer(
        decl->getVertexSize(0),                     // This value is the size of a vertex in memory
        vertices,                                 // The number of vertices you'll put into this buffer
        Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY // Properties
    );
    float * arrayV = new float[vertices*(3+3+2)];

    stream.read((char*)arrayV,sizeof(float)*(3+3+2)*vertices);//should also work - automatically grab ALL vertex data to array in one operation :) C++ is great
    vbuf->writeData(0, vbuf->getSizeInBytes(), arrayV, true);
    delete [] arrayV;
    // "data" is the Ogre::VertexData* we created before
    Ogre::VertexBufferBinding* bind = data->vertexBufferBinding;
    bind->setBinding(0, vbuf);
    Ogre::HardwareIndexBufferSharedPtr ibuf = Ogre::HardwareBufferManager::getSingleton().createIndexBuffer(
        Ogre::HardwareIndexBuffer::IT_16BIT,        // You can use several different value types here
        indices,                                  // The number of indices you'll put in that buffer
        Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY // Properties
    );
    mesh->indexData->indexBuffer = ibuf;     // The pointer to the index buffer
    mesh->indexData->indexCount = indices; // The number of indices we'll use
    mesh->indexData->indexStart = 0;
    unsigned int * arrayI = new unsigned int[indices];
    stream.read((char*)arrayI,sizeof(unsigned int)*indices);
    ibuf->writeData(0, ibuf->getSizeInBytes(), arrayI, true);
    delete [] arrayI;
    if(normalmap>0){
        mesh->setMaterialName("NormalMapTexture");
        mesh->addTextureAlias("normalmap",normalMapFName);
    }
    else{
        //mesh->setMaterialName("OneTexture");
    }
    mesh->addTextureAlias("textura",textureFName);
    meshM->_setBounds(Ogre::AxisAlignedBox(bounds[0],bounds[1],bounds[2],bounds[3],bounds[4],bounds[5]));
    meshM->_setBoundingSphereRadius(std::max(bounds[3]-bounds[0], std::max(bounds[4]-bounds[1], bounds[5]-bounds[2]))/2.0f);
    meshM->load();//TODO need?
    return meshM;*/
}
void  ParticleFactory::CreateSplineParticleGeometry(Ogre::String object_name, int num_particles, float loop_radius, float circle_radius){

		/* Retrieve scene manager and root scene node */
        Ogre::SceneNode* root_scene_node = scene_manager->getRootSceneNode();

        /* Create the 3D object */
        Ogre::ManualObject* object = NULL;
        object = scene_manager->createManualObject(object_name);
        object->setDynamic(false);
        
		/* Create point list for the object */
		object->begin("", Ogre::RenderOperation::OT_POINT_LIST);

		/* Initialize random numbers */
		std::srand(std::time(0));

		/* Create a set of points which will be the particles */
		/* This is similar to drawing a torus: we will sample points on a torus, but will allow the points to also
		   deviate a bit from the torus along the direction of a random vector */
        float maxspray = 0.5; // This is how much we allow the points to deviate along a normalized vector
		float u, v, w, theta, phi, spray; // Work variables
		for (int i = 0; i < num_particles; i++){
			
			// Get two random numbers
			u = ((double) rand() / (RAND_MAX));
            v = ((double) rand() / (RAND_MAX));
            
			// Use u and v to define a point on the torus with angles theta and phi
            theta = u * Ogre::Math::TWO_PI;
			phi = v * Ogre::Math::TWO_PI;

			// Get center of loop and point's normal on the torus
			Ogre::Vector3 center = Ogre::Vector3(loop_radius*cos(theta), loop_radius*sin(theta), 0.0);
            Ogre::Vector3 normal = Ogre::Vector3(cos(theta)*cos(phi), sin(theta)*cos(phi), sin(phi));

			// Next, we want to let the points deviate along the direction of a random vector
			// To obtain a random vector, we sample a point on the sphere
			// The point on the sphere minus the origin (0, 0) is the random vector

			// Randomly select two numbers to define a point in spherical coordinates
			u = ((double) rand() / (RAND_MAX));
            v = ((double) rand() / (RAND_MAX));
			
			// Use u to define the angle theta along one direction of a sphere
			theta = u * Ogre::Math::TWO_PI;
			// Use v to define the angle phi along the other direction of the sphere
			phi = acos(2.0*v - 1.0);
			// Get the point on the sphere (equivalent to a normalized direction vector since the origin is zero)
			Ogre::Vector3 direct = Ogre::Vector3(cos(theta)*sin(phi), sin(theta)*sin(phi), -cos(phi));
			// We need z = -cos(phi) to make sure that the z coordinate runs from -1 to 1 as phi runs from 0 to pi

			// Now, multiply a random amount of deviation by this vector, which is the deviation we will add to the point on the torus
			w = ((double) rand() / (RAND_MAX));
			spray = maxspray*pow((float) w, (float) (1.0/3.0)); // cbrt(w);
			Ogre::Vector3 wander = Ogre::Vector3(spray*direct.x, spray*direct.y, direct.z);
				
			// Add computed quantities to the object
			object->position(center + normal*circle_radius);
			object->normal(wander);
			object->colour(Ogre::ColourValue(((float) i)/((float) num_particles), 0.0, 0.0)); // Store particle id in the red channel as a float
			object->textureCoord(Ogre::Vector2(0.0, 0.0));
		}
		
		/* We finished the object */
        object->end();
		
        /* Convert triangle list to a mesh */
        object->convertToMesh(object_name);
   
}
Example #24
0
void CubeWorld::createChunkWFaces (const int StartX, const int StartY, const int StartZ)
{
	Ogre::ManualObject* MeshChunk = new Ogre::ManualObject("MeshManChunk" + Ogre::StringConverter::toString(m_ChunkID));
	MeshChunk->begin("TerrainImage");

	int iVertex = 0;
	block_t Block;
	block_t Block1;
	float V1, V2;


	for (int z = StartZ; z < CHUNK_SIZE + StartZ; ++z)
	{
		for (int y = StartY; y < CHUNK_SIZE + StartY; ++y)
		{
			for (int x = StartX; x < CHUNK_SIZE + StartX; ++x)
			{
				Block = GetBlock(x,y,z);
				if (Block == 0) continue;

					//x-1
				Block1 = 0;
				if (x > StartX) Block1 = GetBlock(x-1,y,z);

				//Compute the block's texture coordinates
				V1 = 0.25f * (float)(Block - 1);
				V2 = V1 + 0.25f;

                                if (Block1 == 0)
				{
					MeshChunk->position(x, y,   z+1);	MeshChunk->normal(-1,0,0);	MeshChunk->textureCoord(0, V2);
					MeshChunk->position(x, y+1, z+1);	MeshChunk->normal(-1,0,0);	MeshChunk->textureCoord(1, V2);
					MeshChunk->position(x, y+1, z);		MeshChunk->normal(-1,0,0);	MeshChunk->textureCoord(1, V1);
					MeshChunk->position(x, y,   z);		MeshChunk->normal(-1,0,0);	MeshChunk->textureCoord(0, V1);

					MeshChunk->triangle(iVertex, iVertex+1, iVertex+2);
					MeshChunk->triangle(iVertex+2, iVertex+3, iVertex);

					iVertex += 4;
				}

					//x+1
				Block1 = 0;
				if (x < StartX + CHUNK_SIZE - 1) Block1 = GetBlock(x+1,y,z);

				if (Block1 == 0)
				{
					MeshChunk->position(x+1, y,   z);	MeshChunk->normal(1,0,0); MeshChunk->textureCoord(0, V2);
					MeshChunk->position(x+1, y+1, z);	MeshChunk->normal(1,0,0); MeshChunk->textureCoord(1, V2);
					MeshChunk->position(x+1, y+1, z+1);	MeshChunk->normal(1,0,0); MeshChunk->textureCoord(1, V1);
					MeshChunk->position(x+1, y,   z+1);	MeshChunk->normal(1,0,0); MeshChunk->textureCoord(0, V1);

					MeshChunk->triangle(iVertex, iVertex+1, iVertex+2);
					MeshChunk->triangle(iVertex+2, iVertex+3, iVertex);

					iVertex += 4;
				}

					//y-1
				Block1 = 0;
				if (y > StartY) Block1 = GetBlock(x,y-1,z);

				if (Block1 == 0)
				{
					MeshChunk->position(x,   y, z);		MeshChunk->normal(0,-1,0); MeshChunk->textureCoord(0, V2);
					MeshChunk->position(x+1, y, z);		MeshChunk->normal(0,-1,0); MeshChunk->textureCoord(1, V2);
					MeshChunk->position(x+1, y, z+1);	MeshChunk->normal(0,-1,0); MeshChunk->textureCoord(1, V1);
					MeshChunk->position(x,   y, z+1);	MeshChunk->normal(0,-1,0); MeshChunk->textureCoord(0, V1);

					MeshChunk->triangle(iVertex, iVertex+1, iVertex+2);
					MeshChunk->triangle(iVertex+2, iVertex+3, iVertex);

					iVertex += 4;
				}


					//y+1
				Block1 = 0;
				if (y < StartY + CHUNK_SIZE - 1) Block1 = GetBlock(x,y+1,z);

				if (Block1 == 0)
				{
					MeshChunk->position(x,   y+1, z+1);		MeshChunk->normal(0,1,0); MeshChunk->textureCoord(0, V2);
					MeshChunk->position(x+1, y+1, z+1);		MeshChunk->normal(0,1,0); MeshChunk->textureCoord(1, V2);
					MeshChunk->position(x+1, y+1, z);		MeshChunk->normal(0,1,0); MeshChunk->textureCoord(1, V1);
					MeshChunk->position(x,   y+1, z);		MeshChunk->normal(0,1,0); MeshChunk->textureCoord(0, V1);

					MeshChunk->triangle(iVertex, iVertex+1, iVertex+2);
					MeshChunk->triangle(iVertex+2, iVertex+3, iVertex);

					iVertex += 4;
				}

					//z-1
				Block1 = 0;
				if (z > StartZ) Block1 = GetBlock(x,y,z-1);

				if (Block1 == 0)
				{
					MeshChunk->position(x,   y+1, z);		MeshChunk->normal(0,0,-1); MeshChunk->textureCoord(0, V2);
					MeshChunk->position(x+1, y+1, z);		MeshChunk->normal(0,0,-1); MeshChunk->textureCoord(1, V2);
					MeshChunk->position(x+1, y,   z);		MeshChunk->normal(0,0,-1); MeshChunk->textureCoord(1, V1);
					MeshChunk->position(x,   y,   z);		MeshChunk->normal(0,0,-1); MeshChunk->textureCoord(0, V1);

					MeshChunk->triangle(iVertex, iVertex+1, iVertex+2);
					MeshChunk->triangle(iVertex+2, iVertex+3, iVertex);

					iVertex += 4;
				}


					//z+1
				Block1 = 0;
				if (z < StartZ + CHUNK_SIZE - 1) Block1 = GetBlock(x,y,z+1);

				if (Block1 == 0)
				{
					MeshChunk->position(x,   y,   z+1);		MeshChunk->normal(0,0,1); MeshChunk->textureCoord(0, V2);
					MeshChunk->position(x+1, y,   z+1);		MeshChunk->normal(0,0,1); MeshChunk->textureCoord(1, V2);
					MeshChunk->position(x+1, y+1, z+1);		MeshChunk->normal(0,0,1); MeshChunk->textureCoord(1, V1);
					MeshChunk->position(x,   y+1, z+1);		MeshChunk->normal(0,0,1); MeshChunk->textureCoord(0, V1);

					MeshChunk->triangle(iVertex, iVertex+1, iVertex+2);
					MeshChunk->triangle(iVertex+2, iVertex+3, iVertex);

					iVertex += 4;
				}
			}
		}
	}

	MeshChunk->end();
	mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(MeshChunk);

	++m_ChunkID;
}
int DecalManager::addTerrainSplineDecal(Ogre::SimpleSpline *spline, float width, Ogre::Vector2 numSeg, Ogre::Vector2 uvSeg, Ogre::String materialname, float ground_offset, Ogre::String export_fn, bool debug)
{
#if 0
	Ogre::ManualObject *mo = gEnv->ogreSceneManager->createManualObject();
	String oname = mo->getName();
	SceneNode *mo_node = terrain_decals_snode->createChildSceneNode();

	mo->begin(materialname, Ogre::RenderOperation::OT_TRIANGLE_LIST);
	AxisAlignedBox *aab=new AxisAlignedBox();

	int offset = 0;

	// how width is the road?
	float delta_width = width / numSeg.x;

	float steps_len = 1.0f / numSeg.x;

	for (int l = 0; l<=numSeg.x; l++)
	{
		// get current position on that spline
		Vector3 pos_cur  = spline->interpolate(steps_len * (float)l);
		Vector3 pos_next = spline->interpolate(steps_len * (float)(l + 1));
        Ogre::Vector3 direction = (pos_next - pos_cur);
		if (l == numSeg.x)
		{
			// last segment uses previous position
			pos_next = spline->interpolate(steps_len * (float)(l - 1));
			direction = (pos_cur - pos_next);
		}


		for (int w = 0; w<=numSeg.y; w++)
		{
			// build vector for the width
			Vector3 wn = direction.normalisedCopy().crossProduct(Vector3::UNIT_Y);
			
			// calculate the offset, spline in the middle
			Vector3 offset = (-0.5 * wn * width) + (w/numSeg.y) * wn * width;

			// push everything together
			Ogre::Vector3 pos = pos_cur + offset;
			// get ground height there
			pos.y = hfinder->getHeightAt(pos.x, pos.z) + ground_offset;

			// add the position to the mesh
			mo->position(pos);
			aab->merge(pos);
			mo->textureCoord(l/(Ogre::Real)numSeg.x*uvSeg.x, w/(Ogre::Real)numSeg.y*uvSeg.y);
			mo->normal(Vector3::UNIT_Y);
		}
	}

	bool reverse = false;
	for (int n1 = 0; n1<numSeg.x; n1++)
	{
		for (int n2 = 0; n2<numSeg.y; n2++)
		{
			if (reverse)
			{
				mo->index(offset+0);
				mo->index(offset+(numSeg.y+1));
				mo->index(offset+1);
				mo->index(offset+1);
				mo->index(offset+(numSeg.y+1));
				mo->index(offset+(numSeg.y+1)+1);
			}
			else
			{
				mo->index(offset+0);
				mo->index(offset+1);
				mo->index(offset+(numSeg.y+1));
				mo->index(offset+1);
				mo->index(offset+(numSeg.y+1)+1);
				mo->index(offset+(numSeg.y+1));
			}
			offset++;
		}
		offset++;
	}
	offset+=numSeg.y+1;

	mo->end();
	mo->setBoundingBox(*aab);
	// some optimizations
	mo->setCastShadows(false);
	mo->setDynamic(false);
	delete(aab);

	MeshPtr mesh = mo->convertToMesh(oname+"_mesh");

	// build edgelist
	mesh->buildEdgeList();

	// remove the manualobject again, since we dont need it anymore
	gEnv->ogreSceneManager->destroyManualObject(mo);

	unsigned short src, dest;
	if (!mesh->suggestTangentVectorBuildParams(VES_TANGENT, src, dest))
	{
		mesh->buildTangentVectors(VES_TANGENT, src, dest);
	}
	
	Entity *ent = gEnv->ogreSceneManager->createEntity(oname+"_ent", oname+"_mesh");
	mo_node->attachObject(ent);

	mo_node->setVisible(true);
	//mo_node->showBoundingBox(true);
	mo_node->setPosition(Vector3::ZERO); //(position.x, 0, position.z));


	if (!export_fn.empty())
	{
		MeshSerializer *ms = new MeshSerializer();
		ms->exportMesh(mesh.get(), export_fn);
		LOG("spline mesh exported as " + export_fn);
		delete(ms);
	}

	// TBD: RTSS
	//Ogre::RTShader::ShaderGenerator::getSingleton().createShaderBasedTechnique(materialname, Ogre::MaterialManager::DEFAULT_SCHEME_NAME, Ogre::RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME);
	//Ogre::RTShader::ShaderGenerator::getSingleton().invalidateMaterial(RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME, materialname);
	RTSSgenerateShadersForMaterial(materialname, "");

#endif
	return 0;
}
//-------------------------------------------------------------------------------------
Ogre::ManualObject* const DigitalForensicsVisualisation::cube (bool isFrustum, ColorMap cm)
{
	Ogre::ColourValue cv;
	cv.r = cm.r; cv.g = cm.g; cv.b = cm.b; cv.a = 0.65;


	char* name = (char*) malloc (32);
	sprintf(name, "cube%d", app.cubeCount++);
	Ogre::ManualObject* cube = mSceneMgr->createManualObject(name);

	cube->begin("MyMaterial1", Ogre::RenderOperation::OT_TRIANGLE_LIST);



	Ogre::Vector3 centre(50, 50, 50);
	Ogre::Vector3 position;
	//bottom points
	//0
	position.z = position. y = 0; 
	position.x = 0;
	Ogre::Vector3 normal = (position - centre);	normal.normalise();
	cube->position(position);
	cube->textureCoord(0,1,1);
	cube->colour(cv);
	cube->normal(normal);
	//1
	position.x = 100; // 100, 0, 0
	normal = (position - centre);	normal.normalise();
	cube->position(position);
	cube->textureCoord(1,0,1);
	cube->colour(cv);
	cube->normal(normal);
	//2
	position.z = 100; position.x = 0; 
	normal = (position - centre);	normal.normalise();
	cube->position(position);
	cube->textureCoord(1,1,1);
	cube->colour(cv);
	cube->normal(normal);
	////3
	position.x = 100;
	normal = (position - centre); normal.normalise();
	cube->position(position);
	cube->textureCoord(0,0,1);
	cube->colour(cv);
	cube->normal(normal);
	////top points
	////4
	position.y = 100;
	position.x = isFrustum ? 25 : 0;
	position.z = isFrustum ? 25 : 0; 
	normal = (position - centre);	normal.normalise();
	cube->position(position);
	cube->textureCoord(0,1,0);
	cube->colour(cv);
	cube->normal(normal);
	////5
	position.x = isFrustum ? 75 : 100;
	normal = (position - centre);	normal.normalise();
	cube->position(position);
	cube->textureCoord(1,0,0);
	cube->colour(cv);
	cube->normal(normal);
	////6
	position.x = isFrustum ? 25 : 0; position.z = isFrustum ? 75 : 100;
	normal = (position - centre);	normal.normalise();
	cube->position(position);
	cube->textureCoord(1,1,0);
	cube->colour(cv);
	cube->normal(normal);
	////7
	position.x = isFrustum ? 75 : 100;
	normal = (position - centre); normal.normalise();
	cube->position(position);
	cube->textureCoord(0,0,0);
	cube->colour(cv);
	cube->normal(normal);

	
	cube->triangle(0,1,2);//NEGATIVE
	cube->triangle(3,2,1);

	cube->triangle(6,5,4);//POSITIVE
	cube->triangle(5,6,7);

	cube->triangle(0,2,4);
	cube->triangle(6,4,2);
	
	cube->triangle(5,3,1); 
	cube->triangle(3,5,7);
	
	cube->triangle(2,3,6);
	cube->triangle(7,6,3);
	
	cube->triangle(4,1,0);
	cube->triangle(1,4,5);


	cube->end();
	free (name);

	return cube;


}
Example #27
0
void Oculus::setupOgreOculus( Ogre::SceneManager *sm, Ogre::RenderWindow* win, Ogre::Root* root )
{
	mSceneMgr = root->createSceneManager(Ogre::ST_GENERIC);
	mSceneMgr->setAmbientLight( Ogre::ColourValue( 0.5, 0.5, 0.5 ) );
	mSceneMgr->setShadowTechnique(Ogre::SHADOWTYPE_TEXTURE_ADDITIVE_INTEGRATED);
	

	Ogre::SceneNode* meshNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();


	// Configure Render Textures:
	Sizei recommendedTex0Size = ovrHmd_GetFovTextureSize( mHMD, ovrEye_Left,
			mHMD->DefaultEyeFov[0], 1.0f );
	Sizei recommendedTex1Size = ovrHmd_GetFovTextureSize( mHMD, ovrEye_Right,
			mHMD->DefaultEyeFov[1], 1.0f );

	// Generate a texture for each eye, as a rendertarget:
	mLeftEyeRenderTexture = Ogre::TextureManager::getSingleton().createManual(
			"RiftRenderTextureLeft", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
			Ogre::TEX_TYPE_2D, recommendedTex0Size.w, recommendedTex0Size.h, 0, Ogre::PF_X8B8G8R8,
			Ogre::TU_RENDERTARGET );
	mRightEyeRenderTexture = Ogre::TextureManager::getSingleton().createManual(
			"RiftRenderTextureRight", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
			Ogre::TEX_TYPE_2D, recommendedTex1Size.w, recommendedTex1Size.h, 0, Ogre::PF_X8B8G8R8,
			Ogre::TU_RENDERTARGET );

	// Assign the textures to the eyes used later:
	mMatLeft = Ogre::MaterialManager::getSingleton().getByName( "Oculus/LeftEye" );
	mMatLeft->getTechnique(0)->getPass(0)->getTextureUnitState(0)->
		setTexture( mLeftEyeRenderTexture );
		
	mMatRight = Ogre::MaterialManager::getSingleton().getByName( "Oculus/RightEye" );
	mMatRight->getTechnique(0)->getPass(0)->getTextureUnitState(0)->
		setTexture( mRightEyeRenderTexture );
		
	ovrEyeRenderDesc eyeRenderDesc[2];

	eyeRenderDesc[0] = ovrHmd_GetRenderDesc( mHMD, ovrEye_Left, mHMD->DefaultEyeFov[0] );
	eyeRenderDesc[1] = ovrHmd_GetRenderDesc( mHMD, ovrEye_Right, mHMD->DefaultEyeFov[1] );

	ovrVector2f UVScaleOffset[2];
	ovrRecti viewports[2];
	viewports[0].Pos.x = 0;
	viewports[0].Pos.y = 0;
	viewports[0].Size.w = recommendedTex0Size.w;
	viewports[0].Size.h = recommendedTex0Size.h;
	viewports[1].Pos.x = recommendedTex0Size.w;
	viewports[1].Pos.y = 0;
	viewports[1].Size.w = recommendedTex1Size.w;
	viewports[1].Size.h = recommendedTex1Size.h;
	Ogre::ManualObject* manual;
	// Create the Distortion Meshes:
	for ( int eyeNum = 0; eyeNum < 2; eyeNum ++ )
	{
		ovrDistortionMesh meshData;
		ovrHmd_CreateDistortionMesh( mHMD,
				eyeRenderDesc[eyeNum].Eye,
				eyeRenderDesc[eyeNum].Fov,
				0,
				&meshData );

		Ogre::GpuProgramParametersSharedPtr params;

		if( eyeNum == 0 )
		{
			ovrHmd_GetRenderScaleAndOffset( eyeRenderDesc[eyeNum].Fov,
					recommendedTex0Size, viewports[eyeNum],
					UVScaleOffset);
			params = mMatLeft->getTechnique(0)->getPass(0)->getVertexProgramParameters();
		} else {
			ovrHmd_GetRenderScaleAndOffset( eyeRenderDesc[eyeNum].Fov,
					recommendedTex1Size, viewports[eyeNum],
					UVScaleOffset);
			params = mMatRight->getTechnique(0)->getPass(0)->getVertexProgramParameters();
		}

		params->setNamedConstant( "eyeToSourceUVScale",
				Ogre::Vector4( UVScaleOffset[0].x, UVScaleOffset[0].y,0,0 ) );
		params->setNamedConstant( "eyeToSourceUVOffset",
				Ogre::Vector4( UVScaleOffset[1].x, UVScaleOffset[1].y,0,0 ) );

		std::cout << "UVScaleOffset[0]: " << UVScaleOffset[0].x << ", " << UVScaleOffset[0].y << std::endl;
		std::cout << "UVScaleOffset[1]: " << UVScaleOffset[1].x << ", " << UVScaleOffset[1].y << std::endl;

		// create ManualObject
		// TODO: Destroy the manual objects!!
			
		if( eyeNum == 0 )
		{
			manual = mSceneMgr->createManualObject("RiftRenderObjectLeft");
			manual->begin("Oculus/LeftEye", Ogre::RenderOperation::OT_TRIANGLE_LIST);
			//manual->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_TRIANGLE_LIST);
		}
		else
		{
			manual = mSceneMgr->createManualObject("RiftRenderObjectRight");
			manual->begin("Oculus/RightEye", Ogre::RenderOperation::OT_TRIANGLE_LIST);
			//manual->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_TRIANGLE_LIST);
		}

		for( unsigned int i = 0; i < meshData.VertexCount; i++ )
		{
			ovrDistortionVertex v = meshData.pVertexData[i];
			manual->position( v.ScreenPosNDC.x,
					v.ScreenPosNDC.y, 0 );
			manual->textureCoord( v.TanEyeAnglesR.x,//*UVScaleOffset[0].x + UVScaleOffset[1].x,
					v.TanEyeAnglesR.y);//*UVScaleOffset[0].y + UVScaleOffset[1].y);
			manual->textureCoord( v.TanEyeAnglesG.x,//*UVScaleOffset[0].x + UVScaleOffset[1].x,
					v.TanEyeAnglesG.y);//*UVScaleOffset[0].y + UVScaleOffset[1].y);
			manual->textureCoord( v.TanEyeAnglesB.x,//*UVScaleOffset[0].x + UVScaleOffset[1].x,
					v.TanEyeAnglesB.y);//*UVScaleOffset[0].y + UVScaleOffset[1].y);
			//float vig = std::max( v.VignetteFactor, (float)0.0 );
			//manual->colour( vig, vig, vig, vig );
			manual->colour( 1, 1, 1, 1 );

		}
		for( unsigned int i = 0; i < meshData.IndexCount; i++ )
		{
			manual->index( meshData.pIndexData[i] );
		}

		// tell Ogre, your definition has finished
		manual->end();

		ovrHmd_DestroyDistortionMesh( &meshData );

		meshNode->attachObject( manual );
	}
	
	// Set up IPD in meters:
	mIPD = ovrHmd_GetFloat(mHMD, OVR_KEY_IPD,  0.064f);
	
	// Set a default value for interpupillary distance:
	mIPD = 0.064f;
	
	// Create a camera in the (new, external) scene so the mesh can be rendered onto it:
	mCamera = mSceneMgr->createCamera("OculusRiftExternalCamera");
	mCamera->setFarClipDistance(1000000.0f);
	mCamera->setNearClipDistance( 0.1f );
	mCamera->setProjectionType( Ogre::PT_ORTHOGRAPHIC );
	mCamera->setOrthoWindow(2 , 2);
	mCamera->lookAt( 0, 0, -1 );
	

	mSceneMgr->getRootSceneNode()->attachObject( mCamera );

	meshNode->setPosition( 0, 0, -1 );
	meshNode->setScale( 1, 1, -0.1f );

	mViewport = m_window->addViewport( mCamera);
	mViewport->setBackgroundColour(Ogre::ColourValue::Black);
	mViewport->setOverlaysEnabled(true);
}
//-------------------------------------------------------------------------------------
void Ogre3DRendererPlugin::createDesktopObject() {
  // Create the texture
    GLTexturePtr t = GLTextureManager::getSingleton().createManual("DynamicTexture", // name
        Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
        Ogre::TEX_TYPE_2D,      // type
        1280, 800,         // width & height
        1, //depth
        MIP_DEFAULT,//0,                // number of mipmaps
        Ogre::PF_BYTE_RGBA,     // pixel format
        Ogre::TU_DYNAMIC_WRITE_ONLY_DISCARDABLE,
        0);//TU_DEFAULT);

  t->_fireLoadingComplete(true);
  std::cerr << "**** DESKTOP TEXTURE: " << this->desktopTexture << std::endl;
  desktopTexture = t->getHandle();//getGLID();//texture->getHandle();
  std::cerr << "**** DESKTOP TEXTURE: " << this->desktopTexture << std::endl;

// Create a material using the texture
 /*Ogre::MaterialPtr */material = Ogre::MaterialManager::getSingleton().create(
     "DynamicTextureMaterial", // name
     Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);

 material->getTechnique(0)->getPass(0)->createTextureUnitState("DynamicTexture");
 material->getTechnique(0)->getPass(0)->setSceneBlending(Ogre::SBT_REPLACE);//SBT_TRANSPARENT_ALPHA);
//return;
//  ogreHead->setMaterial(material);

 Ogre::ManualObject* manual = mSceneMgr->createManualObject("manual");
//  manual->begin("DynamicTextureMaterial", Ogre::RenderOperation::OT_TRIANGLE_STRIP, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
 manual->begin("BlankWhiteMaterial", Ogre::RenderOperation::OT_TRIANGLE_STRIP, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);

 manual->textureCoord(0, 0);
 manual->position(-40.0, -40.0, 0.0);  // start position
 manual->textureCoord(1, 0);
 manual->position( 40.0, -40.0, 0.0);  // draw first line
 manual->textureCoord(0, 1);
 manual->position(-40.0, 40.0, 0.0);
 manual->textureCoord(1, 1);
 manual->position(40.0,  40.0, 0.0);

 manual->end();
//  mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(manual);


  ManualObject *manObj; // we will use this Manual Object as a reference point for the native rendering
  manObj = mSceneMgr->createManualObject("sampleArea");

  Ogre::AxisAlignedBox b(-40, -40, -40, 40, 40, 40);
  manObj->setBoundingBox(b);

  // Attach to child of root node, better for culling (otherwise bounds are the combination of the 2)
  Ogre::SceneNode *desktopNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
  desktopNode->attachObject(manObj);
  desktopNode->setPosition(40, 15, 0);

  String RenderSystemName = mSceneMgr->getDestinationRenderSystem()->getName();
  mRenderSystemCommandsRenderQueueListener = new OpenGLNativeRenderSystemCommandsRenderQueueListener(manObj, mCamera2, mSceneMgr);

  mSceneMgr->addRenderQueueListener(mRenderSystemCommandsRenderQueueListener);

  std::cerr << "***** DONE CONFIGURE and INIT SCENE" << std::endl;
}
Example #29
0
void Client::initScene() {
	Ogre::Vector3 lightPosition = Ogre::Vector3(0,10,50);
	
	// Set the scene's ambient light
	mSceneMgr->setAmbientLight(Ogre::ColourValue(.1f, .1f, .1f));
	Ogre::Light* pointLight = mSceneMgr->createLight("pointLight");
	pointLight->setType(Ogre::Light::LT_POINT);
	pointLight->setPosition(lightPosition);
	// create a marker where the light is
	Ogre::Entity* ogreHead2 = mSceneMgr->createEntity( "Head2", "ogrehead.mesh" );
	Ogre::SceneNode* headNode2 = mSceneMgr->getRootSceneNode()->createChildSceneNode( "HeadNode2", lightPosition );
	headNode2->attachObject( ogreHead2 );
	headNode2->scale( .5, .5, .5 );
	
	// make a quad
	Ogre::ManualObject* lManualObject = NULL;
	Ogre::String lNameOfTheMesh = "TestQuad";
	{
		// params
		Ogre::String lManualObjectName = "TestQuad";
		bool lDoIWantToUpdateItLater = false;
		// code
		lManualObject = mSceneMgr->createManualObject(lManualObjectName);
		lManualObject->setDynamic(lDoIWantToUpdateItLater);
		lManualObject->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_TRIANGLE_LIST);
		{	// Specify Vertices
			float xmin = 0.0f, xmax = 100.0f, zmin = -100.0f, zmax = 0.0f, ymin = -50.0f, ymax = 0.0f;
			
			lManualObject->position(xmin, ymin, zmin);// a vertex
			lManualObject->colour(Ogre::ColourValue::Red);
			lManualObject->textureCoord(0.0,0.0);
			
			lManualObject->position(xmax, ymin, zmin);// a vertex
			lManualObject->colour(Ogre::ColourValue::Green);
			lManualObject->textureCoord(1.0,0.0);
			
			lManualObject->position(xmin, ymin, zmax);// a vertex
			lManualObject->colour(Ogre::ColourValue::Blue);
			lManualObject->textureCoord(0.0,1.0);
			
			lManualObject->position(xmax, ymin, zmax);// a vertex
			lManualObject->colour(Ogre::ColourValue::Blue);
			lManualObject->textureCoord(1.0,1.0);
		}
		{	// specify geometry
			lManualObject->triangle(0,2,1);
			lManualObject->triangle(3,1,2);
		}
		lManualObject->end();
		lManualObject->convertToMesh(lNameOfTheMesh);
	}
	Ogre::Entity* lEntity = mSceneMgr->createEntity(lNameOfTheMesh);
	Ogre::SceneNode* lNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
	lNode->attachObject(lEntity);
	Ogre::Entity* ogreHead = mSceneMgr->createEntity("Head", "ogrehead.mesh");
	// Create a SceneNode and attach the Entity to it
	Ogre::SceneNode* headNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("HeadNode",Ogre::Vector3(0,-20,0));
	headNode->attachObject(ogreHead);
	ogreHead->setMaterialName("Hatching");
	
	lEntity->setMaterialName("Hatching");
	// postprocessing effects
	//Ogre::CompositorManager::getSingleton().addCompositor(mViewport,"Sobel" );
	//Ogre::CompositorManager::getSingleton().setCompositorEnabled(mCamera->getViewport(), "Sobel", true);
	//Ogre::CompositorManager::getSingleton().addCompositor(mViewport,"CelShading" );
	//Ogre::CompositorManager::getSingleton().setCompositorEnabled(mCamera->getViewport(), "CelShading", true);
}
void AssetLoader::readModel(Ogre::SceneManager* sceneMgr, Ogre::SceneNode* scnNode, const aiScene* scene, aiNode* nd)
{
	for (size_t n = 0; n < nd->mNumChildren; n++) 
	{	
		aiNode* cnd = nd->mChildren[n];
		Ogre::SceneNode* cnode = createChildSceneNodeWithTransform(scnNode, cnd);

		for (size_t i = 0; i < cnd->mNumMeshes; i++) {
			aiMesh* m = scene->mMeshes[cnd->mMeshes[i]];	
			aiMaterial* mat = scene->mMaterials[m->mMaterialIndex];

			std::string nodeName = getFullPathName(cnd);
			Ogre::MaterialPtr omat = createMaterial(Ogre::String(nodeName), m->mMaterialIndex, mat);

			aiVector3D* vec  = m->mVertices;
			aiVector3D* norm = m->mNormals;
			aiVector3D* uv   = m->mTextureCoords[0];
			aiColor4D*  vcol = NULL;	
			if (m->HasVertexColors(0)) vcol = m->mColors[0];

			// 頂点情報の読み込み
			Ogre::AxisAlignedBox aab;
			Ogre::ManualObject* mobj = new Ogre::ManualObject(nodeName+"_MObj");
			mobj->begin(omat->getName());
			//mobj->begin("Ogre/Skin");
			for (size_t n = 0; n < m->mNumVertices; n ++) {
				Ogre::Vector3 position(vec->x, vec->y, vec->z);
				aab.merge(position);

				mobj->position(vec->x, vec->y, vec->z); 
				vec++;  

				mobj->normal(norm->x, norm->y, norm->z);
				norm++; 

				if (uv)   { 
					mobj->textureCoord(uv->x, uv->y);        
					uv++;   
				}
				if (vcol) { 
					mobj->colour(vcol->r, vcol->g, vcol->b, vcol->a); 
					vcol++;
				}
			}

			// ポリゴンの構築
			for (size_t n = 0; n < m->mNumFaces; n++) {
				aiFace* face = &m->mFaces[n];
				for (size_t k = 0; k < face->mNumIndices; k++) {
					mobj->index(face->mIndices[k]);
				}
			}
			mobj->end();
			mobj->setBoundingBox(aab);

			Ogre::String meshName(nodeName+"_Mesh");
			mobj->convertToMesh(meshName);
			delete mobj;

			Ogre::String entityName(nodeName+"_Entity");
			std::cout << "entity: " << entityName << std::endl;
			Ogre::Entity* ent = sceneMgr->createEntity(entityName, meshName);
			cnode->attachObject(ent);
		}

		readModel(sceneMgr, cnode, scene, cnd);
	}
}