Jump to content

How to texture a plane?


NightQuest
 Share

Recommended Posts

I tried looking for a function to create a plane, but couldn't find one.

I threw this together in its place, which may be for the better since I needed a slightly weird kind of plane:

Leadwerks::Model* CreatePlane(unsigned int accross, unsigned int down)
{
   float halfAcross = ((float)accross) / 2;
   unsigned int rows = down + accross - 1;
   float halfRows = ((float)rows) / 2;
   unsigned int total = ((rows - 1) * accross) + 1;

   Leadwerks::Model* model = Leadwerks::Model::Create();
   Leadwerks::Surface* surface = model->AddSurface();

   float Z = 1.f;
   for( unsigned int row = 0; row < rows; row++ )
   {
       float X;
       if( row > 0 )
       {
           X = -1.f + ((1.f / halfAcross) / 2.f);
           for( unsigned int column = 0; column < accross - 1; column++ )
           {
               surface->AddVertex(Vec3(X, 0.f, Z));
               X += (1.f / halfAcross);
           }
           Z -= (1.f / halfRows);
           row++;
       }

       X = -1.f;
       for( unsigned int column = 0; column < accross; column++ )
       {
           surface->AddVertex(Vec3(X, 0.f, Z));
           X += (1.f / halfAcross);
       }
       Z -= (1.f / halfRows);
   }
   for( unsigned int done = 0; done < total; )
   {
       for( unsigned int column = 0; column < accross; column++, done++ )
       {
           if( column < accross - 1 && done < (total - 1) - accross) // Top
               surface->AddTriangle(done, done + 1, done + accross);

           if( column > 0 && done > rows - 1 ) // Right
               surface->AddTriangle(done, done - accross, done - rows);

           if( column < accross - 1 && done > rows - 1 ) // Bottom
               surface->AddTriangle(done, done - (accross - 1), done + 1);

           if( column < accross - 1 && done > rows - 1 ) // Left
               surface->AddTriangle(done, done - rows, done - (accross - 1));
       }
       done += (accross - 1);
   }

   surface->UpdateAABB();
   model->UpdateAABB(Entity::LocalAABB | Entity::GlobalAABB);
   return model;
}

 

It works pretty well,

Model* plane = CreatePlane(9, 9);
plane->SetColor(0.2f, 0.2f, 0.2f);
plane->SetPosition(0, 10, 5);
plane->SetScale(25.f);
plane->SetMaterial(Material::Load("Materials/Concrete/concrete_clean.mat"));

 

.. except for that last line. The material, for whatever reason, doesn't get applied.

 

However, the (relatively) same code works fine for a Box:

Model* box = Model::Box(9, 9, 9);
box->SetColor(0.2f, 0.2f, 0.2f);
box->SetPosition(0, 15, 5);
box->SetScale(1.f);
box->SetMaterial(Material::Load("Materials/Concrete/concrete_clean.mat"));

 

Any ideas? :/

post-103-0-18283100-1424816293_thumb.png

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...