Jump to content

NavMesh does not work with brushes


Dreikblack
 Share

Go to solution Solved by Josh,

Recommended Posts

NavMesh can't be seen (with setDebuggint(true)) or used if you use brushes as a scene instead of models.

#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->SetFov(70);
    camera->SetClearColor(0.125);
    camera->SetPosition(0, 3, -6);
    camera->SetRotation(35, 0, 0);

    //Create light
    auto light = CreateBoxLight(world);
    light->SetRange(-20, 20);
    light->SetArea(20, 20);
    light->SetRotation(35, 35, 0);
    light->SetColor(3);

    //Create scene
    //auto ground = CreateBox(world, 10, 1, 10);
    //ground->SetPosition(0, -0.5, 0);
    //ground->SetColor(0, 1, 0);
    //auto wall = CreateBox(world, 1, 2, 4);

    float w = 10, h = 1, d = 10;
    auto brush = CreateBrush(world);
    //Add brush vertices
    brush->AddVertex(w * 0.5, 0, d * 0.5);
    brush->AddVertex(-w * 0.5, 0, d * 0.5);
    brush->AddVertex(-w * 0.5, 0, -d * 0.5);
    brush->AddVertex(w * 0.5, 0, -d * 0.5);
    brush->AddVertex(w * 0.5, -h, d * 0.5);
    brush->AddVertex(-w * 0.5, -h, d * 0.5);
    brush->AddVertex(-w * 0.5, -h, -d * 0.5);
    brush->AddVertex(w * 0.5, -h, -d * 0.5);

    //Add faces
    auto face = brush->AddFace();
    face->AddIndice(0);
    face->AddIndice(1);
    face->AddIndice(2);
    face->AddIndice(3);

    face = brush->AddFace();
    face->AddIndice(4);
    face->AddIndice(5);
    face->AddIndice(6);
    face->AddIndice(7);

    face = brush->AddFace();
    face->AddIndice(0);
    face->AddIndice(1);
    face->AddIndice(5);
    face->AddIndice(4);

    face = brush->AddFace();
    face->AddIndice(2);
    face->AddIndice(3);
    face->AddIndice(7);
    face->AddIndice(6);

    face = brush->AddFace();
    face->AddIndice(1);
    face->AddIndice(2);
    face->AddIndice(6);
    face->AddIndice(5);

    face = brush->AddFace();
    face->AddIndice(0);
    face->AddIndice(3);
    face->AddIndice(7);
    face->AddIndice(4);
    brush->Build();

    //Create navmesh
    auto navmesh = CreateNavMesh(world, 10, 5, 10, 4, 4);
    navmesh->SetDebugging(true);

    navmesh->Build();

    //Create player
    auto player = CreateCylinder(world, 0.4, 1.8);
    player->SetColor(0, 0, 1);
    auto agent = CreateNavAgent(navmesh);
    player->Attach(agent);

    //Main loop
    while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
    {
        if (window->MouseHit(MOUSE_LEFT))
        {
            auto mousepos = window->GetMousePosition();
            auto rayinfo = camera->Pick(framebuffer, mousepos.x, mousepos.y);
            if (rayinfo.success)
            {
                agent->Navigate(rayinfo.position);
            }
        }

        world->Update();
        world->Render(framebuffer);
    }
    return 0;
}

image.thumb.png.ed6c0f8621413ed96e9121efa0301b75.png

  • Upvote 1
Link to comment
Share on other sites

  • 1 month later...

Currently it seems to not work at all:

#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->SetFov(70);
    camera->SetClearColor(0.125);
    camera->SetPosition(0, 3, -6);
    camera->SetRotation(35, 0, 0);

    //Create light
    auto light = CreateBoxLight(world);
    light->SetRange(-20, 20);
    light->SetArea(20, 20);
    light->SetRotation(35, 35, 0);
    light->SetColor(3);

    //Create scene
    auto ground = CreateBox(world, 10, 1, 10);
    ground->SetPosition(0, -0.5, 0);
    ground->SetColor(0, 1, 0);
    auto wall = CreateBox(world, 1, 2, 4);
    wall->SetPosition(3, 0, 0);

    //Create navmesh
    auto navmesh = CreateNavMesh(world, 10, 5, 10, 4, 4);
    navmesh->SetDebugging(true);
    navmesh->Build();

    //Create player
    auto player = CreateCylinder(world, 0.4, 1.8);
    player->SetColor(0, 0, 1);
    auto agent = CreateNavAgent(navmesh);
    player->Attach(agent);

    //Main loop
    while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
    {
        if (window->MouseHit(MOUSE_LEFT))
        {
            auto mousepos = window->GetMousePosition();
            auto rayinfo = camera->Pick(framebuffer, mousepos.x, mousepos.y);
            if (rayinfo.success)
            {
                agent->Navigate(rayinfo.position);
            }
        }
        world->Update();
        world->Render(framebuffer);
    }
    return 0;
}

 

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

  • Solution

Okay, this will be fixed in the next update.

It will be important to disable navigation on the player itself because mesh primitives are now being created with a collider added:

player->SetNavObstacle(false);

Scratch that, I added a check so if an entity is attached to an entity it will not contribute geometry into the navigation mesh.

  • Upvote 1

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