NightQuest Posted February 24, 2015 Share Posted February 24, 2015 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? :/ Quote Link to comment Share on other sites More sharing options...
Josh Posted February 25, 2015 Share Posted February 25, 2015 You're missing texture coordinates. This example does what you are looking for: http://www.leadwerks.com/werkspace/page/documentation/_/command-reference/model/modelbox-r346 2 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
NightQuest Posted February 25, 2015 Author Share Posted February 25, 2015 Oh, thanks! I feel like an idiot, haha. Works now, though 2 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.