Jump to content

"Wrong number of primitive indices"


Dreikblack
 Share

Go to solution Solved by SpiderPig,

Recommended Posts

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;
}

 

Link to comment
Share on other sites

Made it work but i have strange triangle at bottom

image.png.90bacf2eb3decbb1c60565f4cd04b2f6.png

#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;
}

 

Link to comment
Share on other sites

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.

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

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.

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

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...