Author Topic: 64-bit DirectX 11 - Part 3 - Planets and Asteroid / Blender  (Read 533 times)

AW

  • Member
  • *****
  • Posts: 1360
  • Let's Make ASM Great Again!
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, it is too big to lodge here.



Siekmanski

  • Member
  • *****
  • Posts: 1553
Re: 64-bit DirectX 11 - Part 3 - Planets and Asteroid / Blender
« Reply #1 on: June 12, 2018, 09:56:17 PM »
Cool, and in high resolution.  :t
Creative coders use backward thinking techniques as their strategy.

AW

  • Member
  • *****
  • Posts: 1360
  • Let's Make ASM Great Again!
Re: 64-bit DirectX 11 - Part 3 - Planets and Asteroid / Blender
« Reply #2 on: June 12, 2018, 10:01:52 PM »
Cool, and in high resolution.  :t
Yes, a huge number of vertices   :biggrin:

felipe

  • Member
  • ****
  • Posts: 867
  • Eagles are just great!
Re: 64-bit DirectX 11 - Part 3 - Planets and Asteroid / Blender
« Reply #3 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:
Felipe.

AW

  • Member
  • *****
  • Posts: 1360
  • Let's Make ASM Great Again!
Re: 64-bit DirectX 11 - Part 3 - Planets and Asteroid / Blender
« Reply #4 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.

felipe

  • Member
  • ****
  • Posts: 867
  • Eagles are just great!
Re: 64-bit DirectX 11 - Part 3 - Planets and Asteroid / Blender
« Reply #5 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:
Felipe.

AW

  • Member
  • *****
  • Posts: 1360
  • Let's Make ASM Great Again!
Re: 64-bit DirectX 11 - Part 3 - Planets and Asteroid / Blender
« Reply #6 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.

Caché GB

  • Regular Member
  • *
  • Posts: 44
  • MASM IS HOT
Re: 64-bit DirectX 11 - Part 3 - Planets and Asteroid / Blender
« Reply #7 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.
Caché GB's 1 and 0-nly language:MASM

AW

  • Member
  • *****
  • Posts: 1360
  • Let's Make ASM Great Again!
Re: 64-bit DirectX 11 - Part 3 - Planets and Asteroid / Blender
« Reply #8 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.


daydreamer

  • Member
  • ***
  • Posts: 471
Re: 64-bit DirectX 11 - Part 3 - Planets and Asteroid / Blender
« Reply #9 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



Quote from Flashdance
Nick  :  When you give up your dream, you die.
*wears a flameproof asbestos suit*

AW

  • Member
  • *****
  • Posts: 1360
  • Let's Make ASM Great Again!
Re: 64-bit DirectX 11 - Part 3 - Planets and Asteroid / Blender
« Reply #10 on: June 13, 2018, 09:02:20 PM »
Please post it

All right, download from here.
It includes as sample the sphere .obj file obtained from Blender.

Caché GB

  • Regular Member
  • *
  • Posts: 44
  • MASM IS HOT
Re: 64-bit DirectX 11 - Part 3 - Planets and Asteroid / Blender
« Reply #11 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

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

« Last Edit: June 14, 2018, 02:40:22 PM by Caché GB »
Caché GB's 1 and 0-nly language:MASM

AW

  • Member
  • *****
  • Posts: 1360
  • Let's Make ASM Great Again!
Re: 64-bit DirectX 11 - Part 3 - Planets and Asteroid / Blender
« Reply #12 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.   

Caché GB

  • Regular Member
  • *
  • Posts: 44
  • MASM IS HOT
Re: 64-bit DirectX 11 - Part 3 - Planets and Asteroid / Blender
« Reply #13 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.
Caché GB's 1 and 0-nly language:MASM

AW

  • Member
  • *****
  • Posts: 1360
  • Let's Make ASM Great Again!
Re: 64-bit DirectX 11 - Part 3 - Planets and Asteroid / Blender
« Reply #14 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.