Author Topic: There are many ways to go to Rome.  (Read 53386 times)

Michael Lobko-Lobanovsky

  • Administrator
  • *****
  • Posts: 1481
Re: There are many ways to go to Rome.
« Reply #90 on: March 22, 2019, 11:23:13 pm »
Thank you! :)

This is a vertex color, not UV, editor so the UV boxes aren't draggable because the vertices stay put. But there's nothing to prevent us from making them draggable and redraw their position (and the associated wireframe triangles, and the associated tex map looks) in real time to immediately see the changes in both 3D and 2D viewports. 8)

The 2D UVs/3D vertices are selectable in the area mode (through the respective selection boxes as shown in the video clip) or one-by-one through point-and-click. The cursor shape changes according to the current selection mode. The video shows the cursors changing randomly but this is not how it looks in reality. (there was obviously a glitch in the obsolete video caption software I was using a decade ago)
« Last Edit: March 23, 2019, 02:59:00 am by Michael Lobko-Lobanovsky »
Mike
(3.6GHz Intel Core i5 Quad w/ 16GB RAM, nVidia GTX 1060Ti w/ 6GB VRAM, Windows 7 Ultimate Sp1)

Patrice Terrier

  • Administrator
  • *****
  • Posts: 1980
    • zapsolution
Re: There are many ways to go to Rome.
« Reply #91 on: March 23, 2019, 10:11:33 am »
Quote
But there's nothing to prevent us from making them draggable and redraw their position (and the associated wireframe triangles, and the associated tex map looks) in real time to immediately see the changes in both 3D and 2D viewports.
This is what i wanted to do, but so far i was unable to build the correct XY array, i am able to retrieve the correct hot spot location (the triangle corners), but the polypolygon drawing is not correct because of the XY array order.
This is the main problem i have to sort out. My goal is to produce the transparent overlay shown on my video, and fulfill each of the triangle with a unique transparent color ranging from 1 to 16581375 (255x255x255) to ease the triangle detection. About GDI32 all drawing must be done in 32-bit to support the alpha channel, this is a mandatory when working in composited mode (Pandora internally works with 32-bit DIB bitmap to encompass the 16 GB limitation).
I shall have to try another approach to render correctly the transparent UV's map (overlay).
Patrice
(Always working with the latest Windows version available...)

Michael Lobko-Lobanovsky

  • Administrator
  • *****
  • Posts: 1481
Re: There are many ways to go to Rome.
« Reply #92 on: March 23, 2019, 11:43:03 am »
... the polypolygon drawing is not correct because of the XY array order.

:o

Can you please illustrate this statement in some simple way, perhaps using that initial square test mesh?

The correct order of triangle corners for PolyPolygon is derived in POINT triplets transparently from the discrete vertex array (the one you're also using for the red bullets) based on the OpenGL index array -- the way we did it in our initial messages ## 65 through 76. The index array stores the indices of discrete vertex array elements (and hence, also their UVs) in triplets, duplicating/cloning the indices of unique vertices/UVs as needed to reuse them in individual triangles.

And that's also exactly how OpenGL draws its texture and wireframe triangles but using floating-point coords instead of PolyPolygon's literal integer POINTs.
Mike
(3.6GHz Intel Core i5 Quad w/ 16GB RAM, nVidia GTX 1060Ti w/ 6GB VRAM, Windows 7 Ultimate Sp1)

Michael Lobko-Lobanovsky

  • Administrator
  • *****
  • Posts: 1481
Re: There are many ways to go to Rome.
« Reply #93 on: March 23, 2019, 11:52:42 am »
Re. "transparency" in 24-bit GDI, it can be emulated by bit-blitting the 24-bit black-background wireframe over the 24-bit texture image using some raster op that's more advanced than the usual simple SRCCOPY (like SRCPAINT or SRCAND) to create the effect of combining the two "layers" in what Photoshop would call the "SCREEN" overlay mode in 32 bits.
Mike
(3.6GHz Intel Core i5 Quad w/ 16GB RAM, nVidia GTX 1060Ti w/ 6GB VRAM, Windows 7 Ultimate Sp1)

Patrice Terrier

  • Administrator
  • *****
  • Posts: 1980
    • zapsolution
Re: There are many ways to go to Rome.
« Reply #94 on: March 23, 2019, 12:29:45 pm »
I can provide a valid pandora DC to draw on, like this:

    HDC hIC = zDisplayDC();
    HBITMAP hBitmap = zCreateDIBSection(hIC, nW, nH, 32);
    HDC hDC = CreateCompatibleDC(hIC);
    SelectObject(hDC, hBitmap);
    DeleteDC(hIC);

draw polygon to DC

    then assign the hBitmap as an overlay into the zoom control

    DeleteDC(hDC);


I can also provide a dedicated gpDrawPoygon, build upon the GdipDrawPolygonI API (working with graphics).

Give me some time to write the correct code with the simple test.obj (Wife needs some attention first).


« Last Edit: March 23, 2019, 12:53:00 pm by Patrice Terrier »
Patrice
(Always working with the latest Windows version available...)

Michael Lobko-Lobanovsky

  • Administrator
  • *****
  • Posts: 1481
Re: There are many ways to go to Rome.
« Reply #95 on: March 23, 2019, 01:09:41 pm »
If you're planning to draw the wireframe to a transparent overlay, then it's probably more reasonable to use GdipDrawPolygonI(). OTOH some basic GDI graphics primitives are hardware accelerated while GDI+ is not, and PolyPolygon may arguably be significantly faster than its GDI+ GdipDrawPolygonI counterpart. ???
Mike
(3.6GHz Intel Core i5 Quad w/ 16GB RAM, nVidia GTX 1060Ti w/ 6GB VRAM, Windows 7 Ultimate Sp1)

Patrice Terrier

  • Administrator
  • *****
  • Posts: 1980
    • zapsolution
Re: There are many ways to go to Rome.
« Reply #96 on: March 23, 2019, 03:06:30 pm »
Quote
and PolyPolygon may arguably be significantly faster than its GDI+ GdipDrawPolygonI counterpart.
This is not the case with the current OS, anyway here is a patch to let you try with the simple Test.obj model.

Look at the wip CreateUVmap subroutine, and see what happens with the triangle drawing.
(select the texture on the contact sheet to display the corresponding UV's map overlay).

Patrice
(Always working with the latest Windows version available...)

Patrice Terrier

  • Administrator
  • *****
  • Posts: 1980
    • zapsolution
Re: There are many ways to go to Rome.
« Reply #97 on: March 23, 2019, 05:54:16 pm »
if you try it with dragon.obj, please add the code shown in red at the end of the subroutine.

    GdipDeletePen(pen);
    GdipDeleteGraphics(graphics);
    DeleteDC(hDC);
    newID = IncrID();
    ZD_DrawBitmapToCtrl(gT.hZoomCtrl, 0, 0, hBitmap, ZD_ColorARGB(255, 0), newID, ZS_VISIBLE);
    ZD_SetObjectScroll(newID, TRUE);
    ZI_UpdateWindow(gT.hZoomCtrl, FALSE);
}

This is to apply the same scrolling to the UV's map overlay than the underlaying texture when zooming.

Note: This array problem is what i have been asking to you, since the first Tor release, because i was unable to get the correct XY point location to draw each triangle polygon correctly :(

...
« Last Edit: March 23, 2019, 06:05:37 pm by Patrice Terrier »
Patrice
(Always working with the latest Windows version available...)

Michael Lobko-Lobanovsky

  • Administrator
  • *****
  • Posts: 1481
Re: There are many ways to go to Rome.
« Reply #98 on: March 23, 2019, 07:22:37 pm »
Actually, indexing appeared easier than I thought. But anyway, I warned you there might be bugs in the untested code, didn't I? ;)

Use the following code in void CreateUVmap():


void CreateUVmap(IN long selected) { // 03-20-2019
    MobjMesh* pMesh = &gtm_meshes[selected];
    long index = gnm_indexBuffer[pMesh->startIndex];
    long vertsTotal = pMesh->triangleCount * 3;

    long x = 0, y = 0, w = 0, h = 0, nW = 0, nH = 0, newID = 0, nIDtoClone = 0, nSpriteCount = 0, color = 0;

    ZI_GetImageSizeFromControl(gT.hZoomCtrl, nW, nH);

    HDC hIC = zDisplayDC();
    HBITMAP hBitmap = zCreateDIBSection(hIC, nW, nH, 32);
    HDC hDC = CreateCompatibleDC(hIC);
    SelectObject(hDC, hBitmap);
    DeleteDC(hIC);

    POINT pt[3] = { 0 };
    LONG_PTR graphics = 0, pen = 0, brush = 0;
    GdipCreateFromHDC(hDC, graphics);
    // Create a pen to draw with
    GdipCreatePen1(ZD_ColorARGB(255, RGB(255,0,0)), 1.0f, UnitPixel, pen);

    WCHAR zAf[64] = { 0 };
    long count = 0;
    for (int j = 0; j < vertsTotal; j++, index++) {
        MobjVertexT* vertex = &gtm_vertexBuffer[gnm_indexBuffer[index]];

        pt[count].x = x = (long) ((nW - 1) * vertex->texCoord[0]);
        pt[count].y = y = (long) ((nH - 1) * (1.0f - vertex->texCoord[1]));
        count++;
        if (count == 3) {
            // MLL: This is equivalent to GDI Polygon(), not PolyPolygon(), and is quite
            // slow to redraw large meshes in real time due to function call overhead... :(

            GdipCreateSolidFill(ZD_ColorARGB(32, color), brush); color++; // Use a unique color for each triangle
            GdipFillPolygon2I(graphics, brush, pt[0], count);
            GdipDeleteBrush(brush);

            GdipDrawPolygonI(graphics, pen, pt[0], count);
            count = 0;
        }

        //StringCchPrintf(zAf, strSize(zAf), L"%d: %f, %f   x = %2d, y = %2d", j+1, vertex->texCoord[0], vertex->texCoord[1], x, y);
        //zTrace(zAf);
    }

    GdipDeletePen(pen);
    GdipDeleteGraphics(graphics);
    DeleteDC(hDC);
    newID = IncrID();
    ZD_DrawBitmapToCtrl(gT.hZoomCtrl, 0, 0, hBitmap, ZD_ColorARGB(255, 0), newID, ZS_VISIBLE);
    ZD_SetObjectScroll(newID, TRUE);
    ZI_UpdateWindow(gT.hZoomCtrl, FALSE);
}


and enjoy your UV wireframes! :)
Mike
(3.6GHz Intel Core i5 Quad w/ 16GB RAM, nVidia GTX 1060Ti w/ 6GB VRAM, Windows 7 Ultimate Sp1)

Patrice Terrier

  • Administrator
  • *****
  • Posts: 1980
    • zapsolution
Re: There are many ways to go to Rome.
« Reply #99 on: March 23, 2019, 07:32:57 pm »
Thank you very much my friend!

In the final version, the overlay shall be locked, to avoid unwanted move.

GdipFillPolygon2I is for test purpose only.

Now that we have the correct coordinates, we can try with polypolygon, to check for speed.
« Last Edit: March 23, 2019, 07:40:51 pm by Patrice Terrier »
Patrice
(Always working with the latest Windows version available...)

Michael Lobko-Lobanovsky

  • Administrator
  • *****
  • Posts: 1481
Re: There are many ways to go to Rome.
« Reply #100 on: March 23, 2019, 07:44:23 pm »
Due to re-triangulation in Mobj_importGeometry2ndPass(), our index array also appeared to be indexed linearly starting with pMesh->startIndex! So, my initial pointer-based indexing was yielding indices into the index array, rather than indices into the vertex array... :D
Mike
(3.6GHz Intel Core i5 Quad w/ 16GB RAM, nVidia GTX 1060Ti w/ 6GB VRAM, Windows 7 Ultimate Sp1)

Patrice Terrier

  • Administrator
  • *****
  • Posts: 1980
    • zapsolution
Re: There are many ways to go to Rome.
« Reply #101 on: March 23, 2019, 09:49:46 pm »
I am happy, because now we can move on, without throwing the baby out with the bathwater.  8)
Patrice
(Always working with the latest Windows version available...)

Patrice Terrier

  • Administrator
  • *****
  • Posts: 1980
    • zapsolution
Re: There are many ways to go to Rome.
« Reply #102 on: March 24, 2019, 12:19:32 pm »
Mike

What is the purpose of pMaterial->dispMapFilename ?

and pMaterial->dispMapFilename (d or dis) VS pMaterial->colorMapFilename (map_Kd) ?

To compute the correct mesh index for CreateUVmap(nMes), i am using this
nMesh = TorUVmesh();
if (nMesh > -1) {
    CreateUVmap(nMesh);
}


Code: [Select]
long TorUVmesh() {
    long nRet = -1, nI = 0;
    MobjMesh* pMesh;
    MobjMat* pMaterial;
    char zTex[MAX_PATH] = { 0 };
    WideCharToMultiByte(CP_ACP, 0, gT.zTex, -1, zTex, MAX_PATH, 0, 0);
    for (nI = 0; nI < gM.numberOfMeshes; ++nI) {
        pMesh = &gtm_meshes[nI];
        pMaterial = pMesh->pMaterial;
        if (_stricmp(zTex, (char*)pMaterial->colorMapFilename.c_str()) == 0) {
            nRet = nI; break; }
        if (_stricmp(zTex, (char*)pMaterial->bumpMapFilename.c_str()) == 0) {
            nRet = nI; break; }
        if (_stricmp(zTex, (char*)pMaterial->ambiMapFilename.c_str()) == 0) {
            nRet = nI; break; }
        if (_stricmp(zTex, (char*)pMaterial->specMapFilename.c_str()) == 0) {
            nRet = nI; break; }
        //if (_stricmp(zTex, (char*)pMaterial->reflMapFilename.c_str()) == 0) {
        //    nRet = nI; break; }
        if (_stricmp(zTex, (char*)pMaterial->dispMapFilename.c_str()) == 0) {
            nRet = nI; break; }
        if (_stricmp(zTex, (char*)pMaterial->emitMapFilename.c_str()) == 0) {
            nRet = nI; break; }
        if (_stricmp(zTex, (char*)pMaterial->glossMapFilename.c_str()) == 0) {
            nRet = nI; break; }
    }
    return nRet;
}

Does that is fine with you?

Note: there is still a bug in CreateUVmap when selecting a mesh greater than 0 (we must compute the correct index offset)

« Last Edit: March 24, 2019, 12:45:36 pm by Patrice Terrier »
Patrice
(Always working with the latest Windows version available...)

Michael Lobko-Lobanovsky

  • Administrator
  • *****
  • Posts: 1481
Re: There are many ways to go to Rome.
« Reply #103 on: March 24, 2019, 01:48:22 pm »
What is the purpose of pMaterial->dispMapFilename ?

The displacement (or height) map is a map that, in OR's context, is supposed to work in conjunction with the normal map to implement the parallax and/or bent normals effects. Both effects still need fixes but they will be eventually operable as expected.

Quote
... (d or dis) ...

It's neither d nor dis but disp in the material file.

Quote
Does that is fine with you?

If it works flawlessly for your purposes then it's perfectly OK with me.

Quote
Note: there is still a bug in CreateUVmap when selecting a mesh greater than 0 (we must compute the correct index offset)

Try this:

void CreateUVmap(IN long selected) { // 03-20-2019
    MobjMesh* pMesh = &gtm_meshes[selected];
    long index = pMesh->startIndex; // gnm_indexBuffer[pMesh->startIndex];
    long vertsTotal = pMesh->triangleCount * 3;
........


and tell me if it allows for correct selection of meshes > 0.
Mike
(3.6GHz Intel Core i5 Quad w/ 16GB RAM, nVidia GTX 1060Ti w/ 6GB VRAM, Windows 7 Ultimate Sp1)

Patrice Terrier

  • Administrator
  • *****
  • Posts: 1980
    • zapsolution
Re: There are many ways to go to Rome.
« Reply #104 on: March 24, 2019, 02:36:03 pm »
Quote
and tell me if it allows for correct selection of meshes > 0.
Yes, now it retrieves the correct location, thank you!

In TorUVmesh(), there is no need to check for ambiMapFilename (dito reflMapFilename).

I think to add a button to save the UV's map (could be handy when reworking material with PSD), your thought ?

Now, i shall have to go outside to work in the garden for a couple hours (sculpting trees to make them look like bonzaï)  :D
Patrice
(Always working with the latest Windows version available...)