News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

64-bit DirectX 11 - Part 3 - Planets and Asteroid / Blender

Started by aw27, June 12, 2018, 09:15:51 PM

Previous topic - Next topic

aw27

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

Creative coders use backward thinking techniques as a strategy.

aw27


felipe

Nice! seems you are now the king of assembly programming with dx11  :t. Thanks for sharing!  :icon14:

aw27

Quote from: 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:
I am learning DirectX, I can only learn things by doing.
You know, who is the ASM DirectX king.

felipe

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

aw27

Quote from: felipe on June 13, 2018, 04:12:45 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

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

aw27

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

Quote from: 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.
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



my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

aw27

Quote from: daydreamer on June 13, 2018, 06:58:38 PM
Please post it

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

Caché GB

 Thank you AW for your dxObjConverter utility

Now all we have to do is:-


  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


.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

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

Caché GB's 1 and 0-nly language:MASM

aw27

You know that some objects are composed of a few different parts so things may complicate a bit.   

Caché GB

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

aw27

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.