Dreikblack Posted July 17, 2023 Share Posted July 17, 2023 Happens on mesh->AddPrimitive(1, 2, 4, 3); (54 line) Trying to remake tetrahedron as a model here. #include "UltraEngine.h" using namespace UltraEngine; int main(int argc, const char* argv[]) { //Get the displays auto displays = GetDisplays(); //Create a window auto window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR); //Create a framebuffer auto framebuffer = CreateFramebuffer(window); //Create a world auto world = CreateWorld(); //Create a camera auto camera = CreateCamera(world); camera->SetClearColor(0.8); camera->Turn(35, 0, 0); camera->Move(0, 0, -2); //Create light auto light = CreateBoxLight(world); light->SetRange(-20, 20); light->SetArea(20, 20); light->SetRotation(35, 35, 0); auto unlitMaterial = CreateMaterial(); auto unlitShader = LoadShaderFamily("Shaders/Unlit.json"); unlitMaterial->SetShaderFamily(unlitShader); int width = 4, height = 2, length = 6; auto model = CreateModel(world); auto mesh = model->AddMesh(); mesh->AddVertex(0, 0, 0); //S mesh->AddVertex(-width * 0.5, -height * 0.5, length);//NW mesh->AddVertex(width * 0.5, -height * 0.5, length);//NE mesh->AddPrimitive(0, 1, 2);//S , NW, NE mesh->AddVertex(-width * 0.5, height * 0.5, length);//NW h mesh->AddVertex(width * 0.5, height * 0.5, length);//NE h mesh->AddPrimitive(0, 3, 4);//S , NW h, NE h mesh->AddPrimitive(0, 1, 3);//left mesh->AddPrimitive(1, 2); //"face" mesh->AddPrimitive(2, 4); //"face" mesh->AddPrimitive(4, 3); //"face" mesh->AddPrimitive(1, 3); //"face" mesh->AddPrimitive(2, 4, 0); //"right" model->SetColor(0.5f, 0.8f, 0, 0.25f); auto& mat = unlitMaterial; mat->SetTransparent(true); model->SetMaterial(mat); auto collider = CreateConvexHullCollider(model); model->SetCollider(collider); auto modelLine = CreateModel(world); auto meshLine = modelLine->AddMesh(MESH_LINES); meshLine->AddVertex(0, 0, 0); //S meshLine->AddVertex(-width * 0.5, -height * 0.5, length);//NW meshLine->AddVertex(width * 0.5, -height * 0.5, length);//NE meshLine->AddPrimitive(0, 1, 2);//S , NW, NE meshLine->AddVertex(-width * 0.5, height * 0.5, length);//NW h meshLine->AddVertex(width * 0.5, height * 0.5, length);//NE h meshLine->AddPrimitive(0, 3);//S , NW h, NE h meshLine->AddPrimitive(3, 4);//S , NW h, NE h meshLine->AddPrimitive(0, 4);//S , NW h, NE h meshLine->AddPrimitive(0, 1);//left meshLine->AddPrimitive(1, 3);//left meshLine->AddPrimitive(0, 3);//left meshLine->AddPrimitive(1, 2); //"face" meshLine->AddPrimitive(2, 4); //"face" meshLine->AddPrimitive(4, 3); //"face" meshLine->AddPrimitive(1, 3); //"face" meshLine->AddPrimitive(2, 4, 0); //"right" //Finalize the brush modelLine->SetColor(0.5f, 0.8f, 0, 0.25f); auto matLine = unlitMaterial; matLine->SetLineStipple(LINE_STIPPLE_DASHED); modelLine->SetMaterial(matLine); //Main loop while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false) { world->Update(); world->Render(framebuffer); } return 0; } Quote Link to comment Share on other sites More sharing options...
Solution SpiderPig Posted July 17, 2023 Solution Share Posted July 17, 2023 For a line mesh AddPrimitive() should only take 2 arguments. 1 vertex for each end of a line. Quote Link to comment Share on other sites More sharing options...
Dreikblack Posted July 17, 2023 Author Share Posted July 17, 2023 It was in usual mesh code. Anyway after changing it still keep happening at 53rd line - mesh->AddPrimitive(1, 2); Quote Link to comment Share on other sites More sharing options...
Dreikblack Posted July 17, 2023 Author Share Posted July 17, 2023 Tried even set it to MESH_QUADS, but now it crahses at mesh->AddPrimitive(0, 1, 2); Should it really always match each other? Quote Link to comment Share on other sites More sharing options...
Dreikblack Posted July 17, 2023 Author Share Posted July 17, 2023 Made it work but i have strange triangle at bottom #include "UltraEngine.h" using namespace UltraEngine; int main(int argc, const char* argv[]) { //Get the displays auto displays = GetDisplays(); //Create a window auto window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR); //Create a framebuffer auto framebuffer = CreateFramebuffer(window); //Create a world auto world = CreateWorld(); //Create a camera auto camera = CreateCamera(world); camera->SetClearColor(0.8); camera->Turn(35, 0, 0); camera->Move(0, 0, -1); //Create light auto light = CreateBoxLight(world); light->SetRange(-20, 20); light->SetArea(20, 20); light->SetRotation(35, 35, 0); auto unlitMaterial = CreateMaterial(); auto unlitShader = LoadShaderFamily("Shaders/Unlit.json"); unlitMaterial->SetShaderFamily(unlitShader); int width = 4, height = 2, length = 6; auto model = CreateModel(world); auto mesh = model->AddMesh(); mesh->AddVertex(0, 0, 0); //S mesh->AddVertex(-width * 0.5, -height * 0.5, length);//NW mesh->AddVertex(width * 0.5, -height * 0.5, length);//NE mesh->AddPrimitive(0, 1, 2);//S , NW, NE mesh->AddVertex(-width * 0.5, height * 0.5, length);//NW h mesh->AddVertex(width * 0.5, height * 0.5, length);//NE h mesh->AddPrimitive(0, 3, 4);//S , NW h, NE h mesh->AddPrimitive(0, 1, 3);//left mesh->AddPrimitive(1, 3, 4); //"face" mesh->AddPrimitive(1, 4, 2); //"face" mesh->AddPrimitive(2, 4, 0); //"right" model->SetColor(0.5f, 0.8f, 0, 0.25f); auto& mat = unlitMaterial; mat->SetTransparent(true); model->SetMaterial(mat); auto collider = CreateConvexHullCollider(model); model->SetCollider(collider); auto modelLine = CreateModel(world); auto meshLine = modelLine->AddMesh(MESH_LINES); meshLine->AddVertex(0, 0, 0); //S meshLine->AddVertex(-width * 0.5, -height * 0.5, length);//NW meshLine->AddVertex(width * 0.5, -height * 0.5, length);//NE meshLine->AddPrimitive(0, 1);//S , NW, NE meshLine->AddPrimitive(1, 2);//S , NW, NE meshLine->AddPrimitive(0, 2);//S , NW, NE meshLine->AddVertex(-width * 0.5, height * 0.5, length);//NW h meshLine->AddVertex(width * 0.5, height * 0.5, length);//NE h meshLine->AddPrimitive(0, 3);//S , NW h, NE h meshLine->AddPrimitive(3, 4);//S , NW h, NE h meshLine->AddPrimitive(0, 4);//S , NW h, NE h meshLine->AddPrimitive(0, 1);//left meshLine->AddPrimitive(1, 3);//left meshLine->AddPrimitive(0, 3);//left meshLine->AddPrimitive(1, 2); //"face" meshLine->AddPrimitive(2, 4); //"face" meshLine->AddPrimitive(4, 3); //"face" meshLine->AddPrimitive(1, 3); //"face" meshLine->AddPrimitive(2, 4); //"right" meshLine->AddPrimitive(4, 0); //"right" meshLine->AddPrimitive(2, 0); //"right" //Finalize the brush modelLine->SetColor(0, 0, 0, 1); auto matLine = unlitMaterial; matLine->SetLineStipple(LINE_STIPPLE_DASHED); modelLine->SetMaterial(matLine); //Main loop while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false) { world->Update(); world->Render(framebuffer); } return 0; } Quote Link to comment Share on other sites More sharing options...
Josh Posted July 17, 2023 Share Posted July 17, 2023 If you are using transparency, I am thinking the darker surface may just be due to the ordering of the polygons. Maybe if you enable backface culling and make all the faces pointing out, you won't have overlapping polygons. 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...
Dreikblack Posted July 17, 2023 Author Share Posted July 17, 2023 camera->SetBackfaceCulling(1); does nothing in my case and with 0 argument another triangle also became darker Brush with same shape worked fine btw without extra culling settings. Quote Link to comment Share on other sites More sharing options...
Josh Posted July 17, 2023 Share Posted July 17, 2023 When I ran your code I did not see any visible object. 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...
Dreikblack Posted July 17, 2023 Author Share Posted July 17, 2023 Strange. I even copy-pasted my code from a message two posts above just to mask sure: Quote Link to comment Share on other sites More sharing options...
Josh Posted July 17, 2023 Share Posted July 17, 2023 Unlit.fam 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...
Josh Posted July 17, 2023 Share Posted July 17, 2023 I think some of your faces are flipped inwards and if you make them all point outwards you won't get the overlapping faces that cause some areas to be darker. 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...
Dreikblack Posted July 17, 2023 Author Share Posted July 17, 2023 Just now, Josh said: Unlit.fam I guess something changed in last updates? Was not updating because it could break something again XD Quote Link to comment Share on other sites More sharing options...
Dreikblack Posted July 17, 2023 Author Share Posted July 17, 2023 1 minute ago, Josh said: faces are flipped inwards and if you make them all point outward How to point them in other direction? Quote Link to comment Share on other sites More sharing options...
Josh Posted July 17, 2023 Share Posted July 17, 2023 Add the indices in the reverse order. 1 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...
Dreikblack Posted July 17, 2023 Author Share Posted July 17, 2023 Makes sense 1 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.