The MASM Forum

Projects => Game Development => Topic started by: AW on June 12, 2018, 09:15:51 PM

Title: 64-bit DirectX 11 - Part 3 - Planets and Asteroid / Blender
Post by: AW on June 12, 2018, 09:15:51 PM
In this example I have 3 types of textures and 2 types of objects (in the last demo, I had only 1 type of object).
As objects, we have a sphere and some complex object playing the role of asteroid.
I have used Blender to produce both the planets' and the asteroid's meshes.
As you can see, the planets are much better looking than when we used a sphere algorithm.
For people that does not know, Blender can export in a format called .obj (nothing to do with object files), which is well documented. All we had to do, is convert the .obj to be used with ASM (better said than done, of course).
You can download, source and .exe from this URL (http://www.atelierweb.com/a/dx11_64App5.zip), it is too big to lodge here.


Title: Re: 64-bit DirectX 11 - Part 3 - Planets and Asteroid / Blender
Post by: Siekmanski on June 12, 2018, 09:56:17 PM
Cool, and in high resolution.  :t
Title: Re: 64-bit DirectX 11 - Part 3 - Planets and Asteroid / Blender
Post by: AW on June 12, 2018, 10:01:52 PM
Cool, and in high resolution.  :t
Yes, a huge number of vertices   :biggrin:
Title: Re: 64-bit DirectX 11 - Part 3 - Planets and Asteroid / Blender
Post by: felipe on June 13, 2018, 03:25:40 AM
Nice! seems you are now the king of assembly programming with dx11  :t. Thanks for sharing!  :icon14:
Title: Re: 64-bit DirectX 11 - Part 3 - Planets and Asteroid / Blender
Post by: AW on June 13, 2018, 04:02:53 AM
Nice! seems you are now the king of assembly programming with dx11  :t. Thanks for sharing!  :icon14:
I am learning DirectX, I can only learn things by doing.
You know, who is the ASM DirectX king.
Title: Re: 64-bit DirectX 11 - Part 3 - Planets and Asteroid / Blender
Post by: felipe on June 13, 2018, 04:12:45 AM
 :biggrin: I will give the honour to siekmanski instead.
Btw, i was thinking: this 3d things can be applied to more than just games: Modeling (for design), simulation and scientific models, for engineering, etc.
Actually a big field of applications.  :idea:
Title: Re: 64-bit DirectX 11 - Part 3 - Planets and Asteroid / Blender
Post by: AW on June 13, 2018, 04:26:04 AM
Btw, i was thinking: this 3d things can be applied to more than just games: Modeling (for design), simulation and scientific models, for engineering, etc.
Actually a big field of applications.  :idea:
Indeed, because you can use physics as well. I also know of a 3D World online game (it is not really a game because there is no loser or winner in game terms) where you can even build 3D things inside it, even very sophisticated things like cars, airplanes and helicopters.
It is secondlife.com. Many people know it because of virtual sex, but this is only a side effect, there are amazing artists in there building it or testing prototypes for the real world.
Title: Re: 64-bit DirectX 11 - Part 3 - Planets and Asteroid / Blender
Post by: Caché GB on June 13, 2018, 05:38:03 PM
It's all about the poly count. 

Nice work AW. It is a pity Blender does not have a "export to masm data set".
I'll have to put on my to-do list coding a Blender.obj file parser. My to-do
list is not actually a list, it is more a paper towel roll.

felipe,  Virtual reality (VR) and Augmented Reality (AR) seem to be all the buzz
these days.

We all know, who the ASM DirectX king is.
A few of us just wish he would upgrade to 11.
Title: Re: 64-bit DirectX 11 - Part 3 - Planets and Asteroid / Blender
Post by: AW on June 13, 2018, 06:05:28 PM
Quote
I'll have to put on my to-do list coding a Blender.obj file parser
I had to do that, it parses v, vt, vn and f which is actually what I need. I may post it here if someone needs it, I mean if someone is doing a Blender model.

Title: Re: 64-bit DirectX 11 - Part 3 - Planets and Asteroid / Blender
Post by: daydreamer on June 13, 2018, 06:58:38 PM
Quote
I'll have to put on my to-do list coding a Blender.obj file parser
I had to do that, it parses v, vt, vn and f which is actually what I need. I may post it here if someone needs it, I mean if someone is doing a Blender model.
Nice "armaggeddon' demo
Please post it,it's kinda standard export/import 3d file format
There is untranslated. Dxf file format reader in game forum



Title: Re: 64-bit DirectX 11 - Part 3 - Planets and Asteroid / Blender
Post by: AW on June 13, 2018, 09:02:20 PM
Please post it

All right, download from here (http://www.atelierweb.com/a/dxobjconverter.zip).
It includes as sample the sphere .obj file obtained from Blender.
Title: Re: 64-bit DirectX 11 - Part 3 - Planets and Asteroid / Blender
Post by: Caché GB on June 14, 2018, 04:44:57 AM
 Thank you AW for your dxObjConverter utility

 Now all we have to do is:-

Code: [Select]
  INCLUDE  sphere.inc      ;; Add to Build Models Prodject
 
  ;; Then in shere.inc change this.
  ;; Sphere:
  ;; dd -0.881921, -0.471397, -0.000000, 0.050423, 0.521539, -0.882300, -0.470700, -0.000000
  ;; dd -0.923879, -0.382684, -0.000000, 0.053468, 0.490882, -0.924100, -0.382100, -0.000000

  ;; To this.

  ;; Sphere dd -0.881921, -0.471397, -0.000000, 0.050423, 0.521539, -0.882300, -0.470700, -0.000000
  ;; dd -0.923879, -0.382684, -0.000000, 0.053468, 0.490882, -0.924100, -0.382100, -0.000000

  ;; And for what ever model you want.

INCLUDE  pistol.inc
INCLUDE  katana.inc

  ;; Then 

VERTEX STRUCT QWORD
  Position   VECTOR3 <>
  TexCoord   VECTOR2 <>
  Normal     VECTOR3 <>
VERTEX ENDS

          invoke  WriteModelToFile, CSTR("sphere.dat"), addr Sphere, _SphereVerticesCount
                      ......
          invoke  WriteModelToFile, CSTR("pistol.dat"), addr Pistol, _PistolVerticesCount
          invoke  WriteModelToFile, CSTR("katana.dat"), addr Katana, _KatanaVerticesCount

;#############################################################################################################
 
WriteModelToFile  PROC pFile:PTR, pVertexData:PTR, NumOfVertices:DWORD

    local hFile:ptr
    local dwBytesRead:dword
    local dwOffsetLow:dword
    local dwBytesToWrite:dword

          mov  eax, sizeof(VERTEX)
         imul  eax, NumOfVertices
          mov  dwBytesToWrite, eax

       invoke  CreateFileA, pFile, GENERIC_WRITE or GENERIC_READ, 0, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0
          mov  hFile, eax
       invoke  SetFilePointer, hFile, 0, null, FILE_BEGIN
          mov  dwOffsetLow, eax
          mov  dwBytesRead, 0

       invoke  LockFile, hFile, dwOffsetLow, 0, dwBytesToWrite, 0
       invoke  WriteFile, hFile, pVertexData, dwBytesToWrite, addr dwBytesRead, null
       invoke  UnlockFile, hFile, dwOffsetLow, 0, dwBytesToWrite, 0
       invoke  CloseHandle, hFile

       return  true

WriteModelToFile ENDP

;#############################################################################################################
 

Then in our Game Prodject

Code: [Select]
.const

 _SphereVerticesCount EQU 8064
      .........
 _PistolVerticesCount EQU  ;; to bo determined
 _KatanaVerticesCount EQU  ;; to bo determined

 .data

     g_pSphereVertexBuffer       LPID3D11Buffer      null
      .........
     g_pPistolVertexBuffer       LPID3D11Buffer      null
     g_pKatanaVertexBuffer       LPID3D11Buffer      null

.code
SomeInitProc PROC

       invoke  CreateVertexBufferFromFile, CSTR("sphere.dat"), addr g_pSphereVertexBuffer, _SphereVerticesCount
                    ......   
       invoke  CreateVertexBufferFromFile, CSTR("pistol.dat"), addr g_pPistolVertexBuffer, _PistolVerticesCount
       invoke  CreateVertexBufferFromFile, CSTR("katana.dat"), addr g_pKatanaVertexBuffer, _KatanaVerticesCount

       return

SomeInitProc ENDP

;#############################################################################################################
 
;; Nore: error checking removed
CreateVertexBufferFromFile PROC pFile:PTR, pVertexBuffer:PTR, NumOfVertices:DWORD

   ;; Note: g_pd3dDevice is a valed pointer(public) to a ID3D11Device Interface

    local  BufferDesc:D3D11_BUFFER_DESC
    local  InitData:D3D11_SUBRESOURCE_DATA
    local  Vertices:ptr
    local  hMemory:ptr
    local  hFile:ptr
    local  dwVert:dword
    local  dwBytesRead:dword

          mov  eax, sizeof(VERTEX)
         imul  eax, NumOfVertices
          mov  dwVert, eax
       invoke  GlobalAlloc, GMEM_FIXED, eax    ;;  GHND = GMEM_MOVEABLE OR GMEM_ZEROINIT ; does GHND take longer ??? Todo: test
          mov  hMemory, eax
       invoke  GlobalLock, hMemory
          mov  Vertices, eax

       invoke  CreateFileA, pFile, GENERIC_READ, 0, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0
          mov  hFile, eax 
       invoke  SetFilePointer, hFile, 0, null, FILE_BEGIN
          mov  dwBytesRead, 0   
       invoke  ReadFile, hFile, Vertices, dwVert, addr dwBytesRead, null
       invoke  CloseHandle, hFile

          mov  eax, dwVert
          mov  BufferDesc.ByteWidth, eax
          mov  BufferDesc.Usage, D3D11_USAGE_DEFAULT
          mov  BufferDesc.BindFlags, D3D11_BIND_VERTEX_BUFFER
          mov  BufferDesc.CPUAccessFlags, 0
          mov  BufferDesc.MiscFlags, 0
          mov  BufferDesc.StructureByteStride, 0
                                         
          mov  eax, Vertices
          mov  InitData.pSysMem, eax
          mov  InitData.SysMemPitch, 0
          mov  InitData.SysMemSlicePitch, 0

     coinvoke  g_pd3dDevice, ID3D11Device, CreateBuffer, addr BufferDesc, addr InitData, pVertexBuffer

       invoke  GlobalUnlock, Vertices
       invoke  GlobalFree, hMemory

       return  true

CreateVertexBufferFromFile ENDP

;#############################################################################################################

Title: Re: 64-bit DirectX 11 - Part 3 - Planets and Asteroid / Blender
Post by: AW on June 14, 2018, 03:25:11 PM
You know that some objects are composed of a few different parts so things may complicate a bit.   
Title: Re: 64-bit DirectX 11 - Part 3 - Planets and Asteroid / Blender
Post by: Caché GB on June 14, 2018, 04:05:58 PM
Hi AW, if you are referring to the Index Buffer, yes that is the next issue to solve.
Title: Re: 64-bit DirectX 11 - Part 3 - Planets and Asteroid / Blender
Post by: AW on June 14, 2018, 04:36:22 PM
Hi Caché,

Actually, I could not find a away to use indexes with Blender models. Probably, not possible.
I am talking about a complex model like a car, that has tires, doors, windshields, etc. When I export it from Blender it will be in the form of a group of objects.
Title: Re: 64-bit DirectX 11 - Part 3 - Planets and Asteroid / Blender
Post by: daydreamer on June 14, 2018, 07:08:37 PM
Please post it

All right, download from here (http://www.atelierweb.com/a/dxobjconverter.zip).
It includes as sample the sphere .obj file obtained from Blender.
thanks

Title: Re: 64-bit DirectX 11 - Part 3 - Planets and Asteroid / Blender
Post by: Siekmanski on June 14, 2018, 11:13:40 PM
Hi AW,

Do you mean a vertex triangle list which have many equal vertices? ( connected to their neighbors triangles )
If so, make a copy of the vertex triangle list and remove all equal vertices except 1 and assign an index number to it.
loop thru the original triangle list and find the corresponding 3 index numbers per triangle and put them in an index buffer.
Title: Re: 64-bit DirectX 11 - Part 3 - Planets and Asteroid / Blender
Post by: daydreamer on June 15, 2018, 12:21:30 AM
I am talking about a complex model like a car, that has tires, doors, windshields, etc. When I export it from Blender it will be in the form of a group of objects.
if you want to make a fullfledged .obj fileimporter you might to read .mtl files too,it get exported together with .obj files for several different materials assigned in 3dmodel program,but maybe better than have textures hardcoded inside game program when it becomes large
Title: Re: 64-bit DirectX 11 - Part 3 - Planets and Asteroid / Blender
Post by: AW on June 15, 2018, 03:25:18 AM
Hi AW,

Do you mean a vertex triangle list which have many equal vertices? ( connected to their neighbors triangles )
If so, make a copy of the vertex triangle list and remove all equal vertices except 1 and assign an index number to it.
loop thru the original triangle list and find the corresponding 3 index numbers per triangle and put them in an index buffer.
YES! That's it.
Title: Re: 64-bit DirectX 11 - Part 3 - Planets and Asteroid / Blender
Post by: AW on June 15, 2018, 03:28:09 AM
if you want to make a fullfledged .obj fileimporter you might to read .mtl files too,it get exported together with .obj files for several different materials assigned in 3dmodel program,but maybe better than have textures hardcoded inside game program when it becomes large
I really don't want, but I may be forced to. Alternatively there some "deprecated" functions to convert .obj to the "deprecated" .x format.
Title: Re: 64-bit DirectX 11 - Part 3 - Planets and Asteroid / Blender
Post by: Raistlin on June 15, 2018, 03:46:41 AM
If anyone remembers the wife (Draakie) did a
3DS loader some time ago. Can't seem to find
it on the old forum (help = --hutch?)
It had some interesting code.
Maybe a universal loader is around the corner.  :t
Title: Re: 64-bit DirectX 11 - Part 3 - Planets and Asteroid / Blender
Post by: jj2007 on June 15, 2018, 03:56:46 AM
If anyone remembers the wife (Draakie) did a
3DS loader some time ago. Can't seem to find
it on the old forum (help = --hutch?)
It had some interesting code.
Maybe a universal loader is around the corner.  :t

We do remember Draakie :biggrin:
http://www.masmforum.com/board/index.php?topic=10318.0

Attachment deleted by admin. But I remember that Hutch posted a fat zip archive with lots of the deleted attachments.
Title: Re: 64-bit DirectX 11 - Part 3 - Planets and Asteroid / Blender
Post by: Raistlin on June 15, 2018, 04:28:29 AM
Sheesh she can over-comment (Just between us) @ jj2007

[I truely hope she doesn't see this] Anyhow,
it would be nice if we knew which post
on the old forum belonged to which codelet.
@hutch - do you still have an image with all?
Title: Re: 64-bit DirectX 11 - Part 3 - Planets and Asteroid / Blender
Post by: Caché GB on June 15, 2018, 04:44:17 AM
Hi Raistlin

Hoe gaan dit in die Kaap?

I found this:


www.masmforum.com/archive2012/9524_asmfr_MASMBLEND___Page.zip
 (http://www.masmforum.com/archive2012/9524_asmfr_MASMBLEND___Page.zip)

and this


http://www.masmforum.com/board/index.php?topic=10282.0
 (http://www.masmforum.com/board/index.php?topic=10282.0)
Title: Re: 64-bit DirectX 11 - Part 3 - Planets and Asteroid / Blender
Post by: Raistlin on June 15, 2018, 05:21:05 AM
@Cache-GB: Dis nogal nat hierso - die Kaap van storms.
Lyk my die droogte is amper oor.  :t

Thanks for the links. Unfortunately I don't see the wife's
code. It must be there someplace. She was on & on about
recursive algorithms at the time. I was sceptic. :eusa_boohoo:

Don't get me wrong - she is still the best non-KF (internal joke)
debugger I know. But she is more into management practice
these days.

Anyhow, hope to find her old code & critique her on it :P
Title: Re: 64-bit DirectX 11 - Part 3 - Planets and Asteroid / Blender
Post by: Caché GB on June 16, 2018, 05:02:28 PM
Hi Raistlin, gister het ek die ou forum deurgesoek, maar niks van die ontwykende 3DS model loader gevind nie.
Mense naam hulle zip files nie mooi nie. Die ou forum is beslis 'n skatkis. Ek het gehoor die load shedding het
weer begin. Oy vey.
Title: Re: 64-bit DirectX 11 - Part 3 - Planets and Asteroid / Blender
Post by: Siekmanski on June 16, 2018, 07:20:59 PM
Here is my version of a 3DS loader routine.
Based on the 2 included 3DS info text files.
And an executable to show the routine.
Title: Re: 64-bit DirectX 11 - Part 3 - Planets and Asteroid / Blender
Post by: Caché GB on June 16, 2018, 07:50:45 PM
Thanks a lot Siekmanski.

By the way, I am very upset that Oranje is not in the WC. Now I will just have to root for an underdog. Maybe Uruguay.
Title: Re: 64-bit DirectX 11 - Part 3 - Planets and Asteroid / Blender
Post by: Siekmanski on June 16, 2018, 08:05:59 PM
Thanks a lot Siekmanski.

By the way, I am very upset that Oranje is not in the WC. Now I will just have to root for an underdog. Maybe Uruguay.

They didn't deserve to enter the WC.
This Dutch generation of footballers think they are the sons of god.
They are just spoiled and arrogant.  :icon13:

Thought you were from South Africa, or are you Dutch?
Title: Re: 64-bit DirectX 11 - Part 3 - Planets and Asteroid / Blender
Post by: Caché GB on June 16, 2018, 08:23:16 PM
The Dutch footballers impressed me in 2010 WC. They played dam well.
Title: Re: 64-bit DirectX 11 - Part 3 - Planets and Asteroid / Blender
Post by: daydreamer on June 19, 2018, 03:37:09 AM
Nice! seems you are now the king of assembly programming with dx11  :t. Thanks for sharing!  :icon14:
I am learning DirectX, I can only learn things by doing.
You know, who is the ASM DirectX king.
but if you start to make code that use the improvements that came with dx10:texturearrays vs dx9 weakness slow change textures if you dont cheat with put all textures on a big texture and just use different UV coordinates for different textures,you contend the asm dx king with faster code :P