Ich bin gerade dabei mir einen kleinen obj file loader zu schreiben das funktioniert auch recht gut nur ist die Texture total verzerrt.
Vieleicht kann mir von euch jemand weiterhelfen.
Hier mal der Code der Procedure
Code: Alles auswählen
; Load a model from an *.obj file (wavefront.obj) 
Procedure Model_LoadObjModel(*this.Model_Template, File.s, ObjectName.s = "-1")
  If FileSize(File) = -1 Or FileSize(File) = -2 : ProcedureReturn #False: EndIf
  
  Protected DataStr.s, Token.s
  Protected NewList tmpVertex.XMFLOAT3(), NewList tmpNormals.XMFLOAT3(), NewList tmpUVMap.UVMAP()
  Protected NewList tmpIndexList.s(), ObjectCount.l = 0, objName.s = ""
  Protected FilePath.s = GetPathPart(File), mtlFile.s
  Define *tmpColor.D3DXCOLOR = AllocateMemory(SizeOf(D3DXCOLOR))
  
  Protected FileID.l = ReadFile(#PB_Any, File)
  If FileID
    While Not Eof(FileID)       
      DataStr = ReadString(FileID)
      Token = LCase(StringField(DataStr, 1, " "))      
      
      Select Token
         Case "o"             
            If ObjectName = "" And ObjectCount > 0 : Break : EndIf
            If objName = ObjectName : Break : EndIf
            objName = StringField(DataStr, 2, " ")            
            ObjectCount   + 1 
            ClearList(tmpVertex())
            ClearList(tmpNormals())
            ClearList(tmpUVMap())
            ClearList(tmpIndexList())  
          Case "v"
            AddElement(tmpVertex())
            tmpVertex()\x = ValF(StringField(DataStr, 2, " "))
            tmpVertex()\y = ValF(StringField(DataStr, 3, " "))
            tmpVertex()\z = ValF(StringField(DataStr, 4, " "))
            
          Case "vn"
            AddElement(tmpNormals())
            tmpNormals()\x = ValF(StringField(DataStr, 2, " "))
            tmpNormals()\y = ValF(StringField(DataStr, 3, " "))
            tmpNormals()\z = ValF(StringField(DataStr, 4, " "))  
            
          Case "vt"  
            AddElement(tmpUVMap())
            tmpUVMap()\u = ValF(StringField(DataStr, 2, " "))
            tmpUVMap()\v = ValF(StringField(DataStr, 3, " "))            
            
          Case "mtllib"
            mtlFile = FilePath + StringField(DataStr, 2, " ")
            
          Case "usemtl"
            Protected Material.s = LCase(StringField(DataStr, 2, " "))            
            If FileSize(mtlFile) = -1 Or FileSize(mtlFile) = -2 : ProcedureReturn #False: EndIf            
            Protected mtlFileID.l = ReadFile(#PB_Any, mtlFile)            
            
            If mtlFileID
              Protected mtlStr.s, mtlToken.s, mtlMaterial.s
              While Not Eof(mtlFileID)
                
                mtlStr   = ReadString(mtlFileID)
                mtlToken = LCase(StringField(mtlStr, 1, " ")) 
                
                Select mtlToken
                  Case "newmtl"  
                    If Material = mtlMaterial : Break : EndIf
                    *tmpColor\r = #Null
                    *tmpColor\g = #Null
                    *tmpColor\b = #Null
                    *tmpColor\a = #Null                    
                    mtlMaterial = LCase(StringField(mtlStr, 2, " "))                     
                  Case "kd"                     
                    *tmpColor\r = ValF(StringField(mtlStr, 2, " "))
                    *tmpColor\g = ValF(StringField(mtlStr, 3, " "))
                    *tmpColor\b = ValF(StringField(mtlStr, 4, " "))                   
                    *tmpColor\a = 0.0  
                EndSelect 
                
              Wend
            EndIf
            
          Case "f"  
            Protected vts1.s = LCase(StringField(DataStr, 2, " "))
            Protected vts2.s = LCase(StringField(DataStr, 3, " "))
            Protected vts3.s = LCase(StringField(DataStr, 4, " "))            
            
            AddElement(tmpIndexList())
            tmpIndexList() = vts3
            AddElement(tmpIndexList())
            tmpIndexList() = vts2
            AddElement(tmpIndexList())            
            tmpIndexList() = vts1            
      EndSelect      
    Wend
  EndIf
  
  
  ResetList(tmpVertex())
  While NextElement(tmpVertex())
    *this\Primitive\AddVertex(tmpVertex()\x, tmpVertex()\y, tmpVertex()\z * -1.0)
  Wend
   
  ResetList(tmpIndexList())
  While NextElement(tmpIndexList())
    Index.l       = Val(StringField(tmpIndexList(), 1, "/")) - 1 
    UVIndex.l     = Val(StringField(tmpIndexList(), 2, "/")) - 1
    NormalIndex.l = Val(StringField(tmpIndexList(), 3, "/")) - 1
    
    *this\Primitive\AddIndex(Index)
    *this\Primitive\SetColor(*tmpColor) 
    *this\Primitive\SelectVertex(Index)
    
    If ListSize(tmpUVMap())
      SelectElement(tmpUVMap(), UVIndex)
      *this\Primitive\SetUV(tmpUVMap()\u,  1.0 - tmpUVMap()\v)
    EndIf
    SelectElement(tmpNormals(), NormalIndex)
    *this\Primitive\SetNormal(tmpNormals()\x, tmpNormals()\y, tmpNormals()\z * -1.0)
  Wend  
  ProcedureReturn #True
EndProcedurehttp://www.womba.net/SimpleDX11_rev_50_obj_test.zip
Das DX11 SDK muss Installiert sein, die Pfade in der SimpleDX11.pbi angepast werden und das DX11 subsytem muß aktiviert sein.
Zum testen am besten die Lighting_and_Sprite.pb Demo nehmen das ist die an der ich gerade getestet habe.
Vieleicht sieht von euch jemand wo der Fehler liegt ich steh grad bisl aufm schlauch.
Mfg Nero