void OculusWorldDemoApp::PopulatePreloadScene()
{
    // Load-screen screen shot image
    String fileName = MainFilePath;
    fileName.StripExtension();

    Ptr<File>    imageFile = *new SysFile(fileName + "_LoadScreen.tga");
    Ptr<Texture> imageTex;
    if (imageFile->IsValid())
        imageTex = *LoadTextureTgaTopDown(pRender, imageFile, TextureLoad_SrgbAware, 255);

    // Image is rendered as a single quad.
    if (imageTex)
    {
        imageTex->SetSampleMode(Sample_Anisotropic|Sample_Repeat);
        Ptr<Model> m = *new Model(Prim_Triangles);
        m->AddVertex(-0.5f,  0.5f,  0.0f, Color(255,255,255,255), 0.0f, 1.0f);
        m->AddVertex( 0.5f,  0.5f,  0.0f, Color(255,255,255,255), 1.0f, 1.0f);
        m->AddVertex( 0.5f, -0.5f,  0.0f, Color(255,255,255,255), 1.0f, 0.0f);
        m->AddVertex(-0.5f, -0.5f,  0.0f, Color(255,255,255,255), 0.0f, 0.0f);
        m->AddTriangle(2,1,0);
        m->AddTriangle(0,3,2);

        Ptr<ShaderFill> fill = *new ShaderFill(*pRender->CreateShaderSet());
        fill->GetShaders()->SetShader(pRender->LoadBuiltinShader(Shader_Vertex, VShader_MVP));
        fill->GetShaders()->SetShader(pRender->LoadBuiltinShader(Shader_Fragment, FShader_Texture));
        fill->SetTexture(0, imageTex);
        m->Fill = fill;

        LoadingScene.World.Add(m);
    }
}
Example #2
0
File: mesh.cpp Project: diboh/CPP
Mesh::Mesh(const String& filename)
{	
	//Analizamos JSON
	String content = String::Read( filename );

    rapidjson::Document json;

    if( json.Parse<0>( content.ToCString() ).HasParseError() ) return;

    rapidjson::Value& sub = json[ "submeshes" ];

    for( unsigned int index = 0; index < sub.Size(); index++ )
    {
        String tex = "";

		if ( sub[ index ].HasMember("texture") )
		{
			tex = sub[ index ][ "texture" ].GetString();

			String path = filename.ExtractDir();

			if ( path != "" )
			{
				tex = path + "/" + tex;
			}
		}

		Ptr< Texture > pTex = ResourceManager::Instance()->LoadTexture(tex);
        Ptr< Submesh > pSub = Submesh::Create( pTex );

		if ( sub[index].HasMember("color")		)
		{
			rapidjson::Value& color		= sub[ index ][ "color"		];
			if ( color.Size() != 3 ) return;
			//for (int nColor = 0; nColor < color.Size(); nColor++)
			//{
				float red = float(color[rapidjson::SizeType(0)].GetDouble());
				float green = float(color[rapidjson::SizeType(1)].GetDouble());
				float blue = float(color[rapidjson::SizeType(2)].GetDouble());
				pSub->SetColor(red, green, blue);
			//}
		}



		if ( sub[index].HasMember("shininess")	)
		{
				rapidjson::Value& shininess	= sub[ index ][ "shininess"	];
				pSub->SetShininess(shininess.GetInt());
		}
		
		
		if ( sub[index].HasMember("indices")	)
		{
			rapidjson::Value& indexes   = sub[ index ][ "indices"   ];

			for( unsigned int nIndex = 0; nIndex < indexes.Size(); nIndex += 3 )
			{
				pSub->AddTriangle( indexes[ nIndex ].GetInt(), indexes[ nIndex + 1 ].GetInt(), indexes[ nIndex + 2 ].GetInt() );
			}
		}

		
		Array< Vector3 > vertexPositions;
        if ( sub[index].HasMember("coords")		)
		{
			rapidjson::Value& coords    = sub[ index ][ "coords"    ];

			for( unsigned int nCoords = 0; nCoords < coords.Size(); nCoords += 3 )
			{
				vertexPositions.Add( 
									Vector3(
											static_cast<float>( coords[ nCoords     ].GetDouble() ), 
											static_cast<float>( coords[ nCoords + 1 ].GetDouble() ), 
											static_cast<float>( coords[ nCoords + 2 ].GetDouble() ) 
											)
								   );
			}
		}


		Array< Vector3 > normalPositions;
        if ( sub[index].HasMember("normals")		)
		{
			rapidjson::Value& coords    = sub[ index ][ "normals"    ];

			for( unsigned int nCoords = 0; nCoords < coords.Size(); nCoords += 3 )
			{
				normalPositions.Add( 
									Vector3(
											static_cast<float>( coords[ nCoords     ].GetDouble() ), 
											static_cast<float>( coords[ nCoords + 1 ].GetDouble() ), 
											static_cast<float>( coords[ nCoords + 2 ].GetDouble() ) 
											)
								   );
			}
		}

        Array< float > uTextCoords;
		Array< float > vTextCoords;
		if ( sub[index].HasMember("texcoords")	)		
		{
			rapidjson::Value& texCoords = sub[ index ][ "texcoords" ];

			for( unsigned int nTex = 0; nTex < texCoords.Size(); nTex += 2 )
			{
				//uTextCoords.Add( static_cast<float>( texCoords[nTex + 0].GetDouble() );
				//vTextCoords.Add( static_cast<float>( texCoords[nTex + 1].GetDouble() );

				float u = static_cast<float>( texCoords[ nTex     ].GetDouble() ); 
				float v = static_cast<float>( texCoords[ nTex + 1 ].GetDouble() );

				uTextCoords.Add(u);
				vTextCoords.Add(v);

				/*pSub->AddVertex( 
								Vertex( 
										vertexPositions[ nTex / 2 ],
										normalPositions[ nTex / 2 ],
										static_cast<float>( texCoords[ nTex     ].GetDouble() ), 
										static_cast<float>( texCoords[ nTex + 1 ].GetDouble() ) 
									   )
							   );*/
			}
		}

		

		for (unsigned int i = 0; i < vertexPositions.Size(); i++)
		{
			//if ( !uTextCoords[i] ) uTextCoords[i] = 0;
			//if ( !vTextCoords[i] ) uTextCoords[i] = 0;

			//pSub->AddVertex	( Vertex(vertexPositions[i], normalPositions[i], uTextCoords[i], vTextCoords[i]) );
			pSub->AddVertex	( Vertex(vertexPositions[i], normalPositions[i], 0, 0) );
		}
		
        
		//Add to mesh
        AddSubmesh( pSub );
    }
}