Archive 17/01/2023.

[SOLVED]I cannot seem to create my own custom mesh manually

GoogleBot42

I used the pretty much used the theoretically working code from here exactly: http://discourse.urho3d.io/t/solved-how-to-create-mesh/35 This post is a bit old so maybe things have changed a bit?

It simply doesn’t render correctly depending on the direction and position of the camera. It seems to fail whenever the camera is close or when the object almost falls off of the camera.

Here is it messing up

But when I back up a bit it works

    float dirLightVertexData[] =
    {
        -1, 1, 0,
        1, 1, 0,
        1, -1, 0,
        -1, -1, 0,
    };

    unsigned short dirLightIndexData[] =
    {
        0, 1, 2,
        2, 3, 0,
    };

    SharedPtr<VertexBuffer> dlvb(new VertexBuffer(context_));
    dlvb->SetShadowed(true);
    dlvb->SetSize(4, MASK_POSITION);
    dlvb->SetData(dirLightVertexData);

    SharedPtr<IndexBuffer> dlib(new IndexBuffer(context_));
    dlib->SetShadowed(true);
    dlib->SetSize(6, false);
    dlib->SetData(dirLightIndexData);

    Geometry *dirLightGeometry_ = new Geometry(context_);
    dirLightGeometry_->SetVertexBuffer(0, dlvb);
    dirLightGeometry_->SetIndexBuffer(dlib);
    dirLightGeometry_->SetDrawRange(TRIANGLE_LIST, 0, dlib->GetIndexCount());

    SharedPtr<Model> testModel(new Model(context_));
    Vector<SharedPtr<VertexBuffer> > dlvbVector;
    Vector<SharedPtr<IndexBuffer> > dlibVector;
    dlvbVector.Push(dlvb);
    dlibVector.Push(dlib);
    testModel->SetNumGeometries(1);
    testModel->SetNumGeometryLodLevels(0, 1);
    testModel->SetGeometry(0, 0, dirLightGeometry_);

    // Define the model buffers and bounding box
    PODVector<unsigned> emptyMorphRange;
    testModel->SetVertexBuffers(dlvbVector, emptyMorphRange, emptyMorphRange);
    testModel->SetIndexBuffers(dlibVector);
    testModel->SetBoundingBox(BoundingBox(Vector3(-1.0f, -1.0f, 0.0f), Vector3(1.0f, 1.0f, 0.0f)));

    Node* testnodea = scene_->CreateChild("testasdasd");
    testnodea->SetScale(Vector3(1.0f, 1.0f, 1.0f));
    StaticModel* testObjecta = testnodea->CreateComponent<StaticModel>();
    testObjecta->SetModel(testModel);
    testObjecta->SetMaterial(cache->GetResource<Material>("Materials/BlueUnlit.xml"));
    testnodea->SetPosition(Vector3(-1.0f, 5.0f, 2.0f));

Any help is nice! Thanks!

1vanK

“Materials/BlueUnlit.xml” uses VColor?

GoogleBot42

Turns out that material doesn’t exist. Whoops. I should have checked before I copied the code. But it is not the problem. :unamused:

You can see this bellow. Now both of the quads you can see are both the same material. The other quad is using “Models/Plane.mdl” included in the standard urho3d assets. The two should be identical just scaled differently.

cadaver

If you want the model to be lit and texture mapped, it needs normals and UVs.

GoogleBot42

Thanks! I was just being dumb. That should have been obvious to me. :joy: So that problem I was having has been solved.

EDIT: Never mind I figured it out. See here: https://urho3d.github.io/documentation/1.6/class_urho3_d_1_1_index_buffer.html#acad3ececff56c39f52703e514b730364

Alright, now I am running into an issue in that I need more greater than a unsigned short for my indices. Granted I am not being entirely efficient but I want to do some testing to see how much I can render in one draw call.

Is there a way I can set 32bit indices?

Here I am trying to make a 14x14x14 big cube of cubes. As you can see, it falls a bit short because I go over the index of 65,535.

1vanK

SetSize (unsigned indexCount, bool largeIndices, bool dynamic=false)

GoogleBot42

Yeah I figured it out. Thanks though :slight_smile:

GoogleBot42

Here is a working screenshot if anyone is a bit curious. Much bigger.

Also I got the basics of polyvox running (soon to be textured too :wink:).

bloop

That is looking great! I am starting to look at PolyVox and Urho as well. Did you implement a bespoke shaders?