Josh Posted July 27, 2023 Posted July 27, 2023 This is the code I used to create the terrain gizmo the editor uses: auto terrainwidget = CreateModel(NULL); int sides = 128; float th = 0.5 * 0.1; float x, y, a; int i = 0; CreateModel(NULL)->SetParent(terrainwidget); CreateModel(NULL)->SetParent(terrainwidget); auto mtl = CreateMaterial(); mtl->SetShaderFamily(LoadShaderFamily("Shaders/Unlit.fam")); mtl->SetTexture(LoadTexture(GetPath(PATH_DESKTOP) + "/terraingizmo.dds")); for (int i = 0; i < 2; ++i) { auto mesh = terrainwidget->kids[i]->As<Model>()->AddMesh(); if (i == 1) terrainwidget->kids[i]->SetColor(1, 1, 0, 1); mesh->SetMaterial(mtl); for (int n = 0; n < sides; ++n) { a = float(n) / float(sides) * 360.0f; x = Cos(a); y = Sin(a); mesh->AddVertex(x * (1.0 - float(i) * 0.5), 0, y * (1.0 - float(i) * 0.5), 0, 1, 0, 1, 0); mesh->AddVertex(x * (1.0 - float(i) * 0.5 - th), 0, y * (1.0 - float(i) * 0.5 - th), 0, 1, 0, 0, 0); if (n > 0) { mesh->AddPrimitive(n * 2 + 1, n * 2 + 0, (n - 1) * 2 + 0); mesh->AddPrimitive((n - 1) * 2 + 0, (n - 1) * 2 + 1, n * 2 + 1); if (n == sides - 1) { mesh->AddPrimitive(1, 0, n * 2 + 0); mesh->AddPrimitive(n * 2 + 0, n * 2 + 1, 1); } } } } terrainwidget->Save(GetPath(PATH_DESKTOP) + "/terrain.gltf"); 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without.
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.