diff --git a/CREDITS b/CREDITS index febb4c29e..eabf562d2 100644 --- a/CREDITS +++ b/CREDITS @@ -104,11 +104,14 @@ Contributed a fix for the Normalize method in aiQuaternion. - dbburgess Contributes a Android-specific build issue: log the hardware architecture for ARM. -- alfiereinre7 +- alfiereinre7 Contributes a obj-fileparser fix: missing tokens in the obj-token list. - Roman Kharitonov Contributes a fix for the configure script environment. --rdb +- Ed Diana +Contributed AssimpDelphi (/port/AssimpDelphi). + +- rdb Contributes a bundle of fixes and improvments for the bsp-importer. diff --git a/port/AssimpDelphi/Readme.txt b/port/AssimpDelphi/Readme.txt new file mode 100644 index 000000000..c9aed7b0f --- /dev/null +++ b/port/AssimpDelphi/Readme.txt @@ -0,0 +1,6 @@ +This is a set of Delphi units for using the Assimp C DLL. This was created for use with Delphi 7, but should be usable as-is or with minimal modifications with later Delphi versions. + +This set of headers is enough to load and display a model with external textures. Since I'm not familiar with animated models and some of the other functionality of the assimp library, I did not convert the headers for those features. + +See http://sourceforge.net/tracker/?func=detail&aid=3212646&group_id=226462&atid=1067634 for the original patch + diff --git a/port/AssimpDelphi/aiColor4D.pas b/port/AssimpDelphi/aiColor4D.pas new file mode 100644 index 000000000..0bc5d2a6b --- /dev/null +++ b/port/AssimpDelphi/aiColor4D.pas @@ -0,0 +1,17 @@ +unit aiColor4D; + +interface + +const AI_MAX_NUMBER_OF_COLOR_SETS = $04; + +type TaiColor4D = packed record + r, g, b, a: single; +end; +type PaiColor4D = ^TaiColor4D; + +type TaiColor4DArray = array[0..0] of TaiColor4D; +type PTaiColor4DArray = ^TaiColor4DArray; + +implementation + +end. diff --git a/port/AssimpDelphi/aiMaterial.pas b/port/AssimpDelphi/aiMaterial.pas new file mode 100644 index 000000000..ffd810991 --- /dev/null +++ b/port/AssimpDelphi/aiMaterial.pas @@ -0,0 +1,153 @@ +unit aiMaterial; + +interface + +uses aiTypes, aiVector2D, aiVector3D; + +{This following directive causes enums to be stored as double words (32bit), to be compatible with + the assimp C Dll} +{$Z4} + +type TaiTextureOp = ( + aiTextureOp_Multiply = $0, + aiTextureOp_Add = $1, + aiTextureOp_Subtract = $2, + aiTextureOp_Divide = $3, + aiTextureOp_SmoothAdd = $4, + aiTextureOp_SignedAdd = $5 + //_aiTextureOp_Force32Bit = 0x9fffffff +); + +type TaiTextureMapMode = ( + aiTextureMapMode_Wrap = $0, + aiTextureMapMode_Clamp = $1, + aiTextureMapMode_Decal = $3, + aiTextureMapMode_Mirror = $2 + //_aiTextureMapMode_Force32Bit = 0x9fffffff +); + +type TaiTextureMapping = ( + aiTextureMapping_UV = $0, + aiTextureMapping_SPHERE = $1, + aiTextureMapping_CYLINDER = $2, + aiTextureMapping_BOX = $3, + aiTextureMapping_PLANE = $4, + aiTextureMapping_OTHER = $5 + //_aiTextureMapping_Force32Bit = 0x9fffffff +); + +type TaiTextureType = ( + aiTextureType_NONE = $0, + aiTextureType_DIFFUSE = $1, + aiTextureType_SPECULAR = $2, + aiTextureType_AMBIENT = $3, + aiTextureType_EMISSIVE = $4, + aiTextureType_HEIGHT = $5, + aiTextureType_NORMALS = $6, + aiTextureType_SHININESS = $7, + aiTextureType_OPACITY = $8, + aiTextureType_DISPLACEMENT = $9, + aiTextureType_LIGHTMAP = $A, + aiTextureType_REFLECTION = $B, + aiTextureType_UNKNOWN = $C + //_aiTextureType_Force32Bit = 0x9fffffff +); + +const AI_TEXTURE_TYPE_MAX = aiTextureType_UNKNOWN; + +type TaiShadingMode = ( + aiShadingMode_Flat = $1, + aiShadingMode_Gouraud = $2, + aiShadingMode_Phong = $3, + aiShadingMode_Blinn = $4, + aiShadingMode_Toon = $5, + aiShadingMode_OrenNayar = $6, + aiShadingMode_Minnaert = $7, + aiShadingMode_CookTorrance = $8, + aiShadingMode_NoShading = $9, + aiShadingMode_Fresnel = $A + //_aiShadingMode_Force32Bit = 0x9fffffff +); + + +type TaiTextureFlags = ( + aiTextureFlags_Invert = $1, + aiTextureFlags_UseAlpha = $2, + aiTextureFlags_IgnoreAlpha = $4 + //_aiTextureFlags_Force32Bit = 0x9fffffff +); + +type TaiBlendMode = ( + aiBlendMode_Default = $0, + aiBlendMode_Additive = $1 + //_aiBlendMode_Force32Bit = 0x9fffffff +); + +type TaiUVTransform = packed record + mTranslation: TaiVector2D; + mScaling: TaiVector2D; + mRotation: single; +end; + +type TaiPropertyTypeInfo = ( + aiPTI_Float = $1, + aiPTI_String = $3, + aiPTI_Integer = $4, + aiPTI_Buffer = $5 + // _aiPTI_Force32Bit = 0x9fffffff +); + +type TaiMaterialProperty = packed record + mKey: aiString; + mSemantic: Cardinal; + mIndex: Cardinal; + mDataLength: Cardinal; + mType: TaiPropertyTypeInfo; + mData: PChar; +end; +type PaiMaterialProperty = ^TaiMaterialProperty; + +type TaiMaterial = packed record + mProperties: pointer; + mNumProperties: Cardinal; + mNumAllocated: Cardinal; +end; +type PaiMaterial = ^TaiMaterial; +type PaiMaterialArray = array[0..0] of PaiMaterial; +type PPaiMaterialArray = ^PaiMaterialArray; + +const AI_MATKEY_NAME = '?mat.name'; +const AI_MATKEY_TWOSIDED = '$mat.twosided'; +const AI_MATKEY_SHADING_MODEL = '$mat.shadingm'; +const AI_MATKEY_ENABLE_WIREFRAME = '$mat.wireframe'; +const AI_MATKEY_BLEND_FUNC = '$mat.blend'; +const AI_MATKEY_OPACITY = '$mat.opacity'; +const AI_MATKEY_BUMPSCALING = '$mat.bumpscaling'; +const AI_MATKEY_SHININESS = '$mat.shininess'; +const AI_MATKEY_REFLECTIVITY = '$mat.reflectivity'; +const AI_MATKEY_SHININESS_STRENGTH = '$mat.shinpercent'; +const AI_MATKEY_REFRACTI = '$mat.refracti'; +const AI_MATKEY_COLOR_DIFFUSE = '$clr.diffuse'; +const AI_MATKEY_COLOR_AMBIENT = '$clr.ambient'; +const AI_MATKEY_COLOR_SPECULAR = '$clr.specular'; +const AI_MATKEY_COLOR_EMISSIVE = '$clr.emissive'; +const AI_MATKEY_COLOR_TRANSPARENT = '$clr.transparent'; +const AI_MATKEY_COLOR_REFLECTIVE = '$clr.reflective'; +const AI_MATKEY_GLOBAL_BACKGROUND_IMAGE = '?bg.global'; + +const _AI_MATKEY_TEXTURE_BASE = '$tex.file'; +const _AI_MATKEY_UVWSRC_BASE = '$tex.uvwsrc'; +const _AI_MATKEY_TEXOP_BASE = '$tex.op'; +const _AI_MATKEY_MAPPING_BASE = '$tex.mapping'; +const _AI_MATKEY_TEXBLEND_BASE = '$tex.blend'; +const _AI_MATKEY_MAPPINGMODE_U_BASE = '$tex.mapmodeu'; +const _AI_MATKEY_MAPPINGMODE_V_BASE = '$tex.mapmodev'; +const _AI_MATKEY_TEXMAP_AXIS_BASE = '$tex.mapaxis'; +const _AI_MATKEY_UVTRANSFORM_BASE = '$tex.uvtrafo'; +const _AI_MATKEY_TEXFLAGS_BASE = '$tex.flags'; + + + +implementation + +end. diff --git a/port/AssimpDelphi/aiMatrix3x3.pas b/port/AssimpDelphi/aiMatrix3x3.pas new file mode 100644 index 000000000..a90f11f27 --- /dev/null +++ b/port/AssimpDelphi/aiMatrix3x3.pas @@ -0,0 +1,16 @@ +unit aiMatrix3x3; + +interface + +type TaiMatrix3x3 = packed record + a1, a2, a3, a4: single; + b1, b2, b3, b4: single; + c1, c2, c3, c4: single; +end; +PaiMatrix3x3 = ^TaiMatrix3x3; + + + +implementation + +end. diff --git a/port/AssimpDelphi/aiMatrix4x4.pas b/port/AssimpDelphi/aiMatrix4x4.pas new file mode 100644 index 000000000..45e0fafd6 --- /dev/null +++ b/port/AssimpDelphi/aiMatrix4x4.pas @@ -0,0 +1,16 @@ +unit aiMatrix4x4; + +interface + +type TaiMatrix4x4 = packed record + a1, a2, a3, a4: single; + b1, b2, b3, b4: single; + c1, c2, c3, c4: single; + d1, d2, d3, d4: single; +end; +PaiMatrix4x4 = ^TaiMatrix4x4; + + +implementation + +end. diff --git a/port/AssimpDelphi/aiMesh.pas b/port/AssimpDelphi/aiMesh.pas new file mode 100644 index 000000000..a05a0f200 --- /dev/null +++ b/port/AssimpDelphi/aiMesh.pas @@ -0,0 +1,71 @@ +unit aiMesh; + +interface + +uses aiTypes, aiMatrix4x4, aiVector3D, aiColor4D; + +const + AI_MAX_NUMBER_OF_COLOR_SETS = $4; + AI_MAX_NUMBER_OF_TEXTURECOORDS = $4; + +type TaiFace = packed record + mNumIndicies: cardinal; + mIndices: PCardinalArray; +end; +type PaiFace = ^TaiFace; +type PaiFaceArray = array [0..0] of PaiFace; + +type TaiFaceArray = array [0..0] of TaiFace; +type PTaiFaceArray = ^TaiFaceArray; + +type TaiVertexWeight = packed record + mVertexId: cardinal; + mWeight: single; +end; + +type TaiBone = packed record + mName: aiString; + mNumWeights: cardinal; + mWeights: Pointer; + mOffsetMatrix: TaiMatrix4x4; +end; +type PaiBone = ^TaiBone; + +type TaiPrimitiveType = + ( + aiPrimitiveType_POINT = $1, + aiPrimitiveType_LINE = $2, + aiPrimitiveType_TRIANGLE = $4, + aiPrimitiveType_POLYGON = $8 + //,_aiPrimitiveType_Force32Bit = $9fffffff + ); + +type TaiMesh = packed record + mPrimitiveTypes: cardinal; + mNumVertices: cardinal; + mNumFaces: cardinal; + mVertices: PTaiVector3DArray; + mNormals: PTaiVector3DArray; + mTangents: PaiVector3DArray; + mBitangents: PaiVector3DArray; + mColors: array[0..3] of PTaiColor4Darray; //array [0..3] of PaiColor4DArray; //array of 4 + mTextureCoords: array [0..3] of PTaiVector3DArray; //array of 4 + mNumUVComponents: array[0..AI_MAX_NUMBER_OF_TEXTURECOORDS -1] of cardinal; + mFaces: PTaiFaceArray; + mNumBones: cardinal; + mBones: PaiBone; + mMaterialIndex: cardinal; + mName: aiString; + mNumAniMeshes: cardinal; + mAniMeshes: pointer; +end; +type PaiMesh = ^TaiMesh; +type PPaiMesh = ^PaiMesh; +type PaiMeshArray = array [0..0] of PaiMesh; +type PPaiMeshArray = ^PaiMeshArray; + + + +implementation + +end. diff --git a/port/AssimpDelphi/aiQuaternion.pas b/port/AssimpDelphi/aiQuaternion.pas new file mode 100644 index 000000000..d5550de91 --- /dev/null +++ b/port/AssimpDelphi/aiQuaternion.pas @@ -0,0 +1,12 @@ +unit aiQuaternion; + +interface + +type TaiQuaternion = packed record + w, x, y, z: single; +end; +type PaiQuaternion = ^TaiQuaternion; + +implementation + +end. diff --git a/port/AssimpDelphi/aiScene.pas b/port/AssimpDelphi/aiScene.pas new file mode 100644 index 000000000..28cebf165 --- /dev/null +++ b/port/AssimpDelphi/aiScene.pas @@ -0,0 +1,46 @@ +unit aiScene; + +interface + +uses aiTypes, aiMatrix4x4, aiMesh, aiMaterial, aiTexture; + + +type + PaiNode = ^TaiNode; + PPaiNode = ^PaiNode; + PaiNodeArray = array[0..0] of PaiNode; + PPaiNodeArray = ^PaiNodeArray; + + TaiNode = packed record + mName: aiString; + mTransformation: TaiMatrix4x4; + mParent: PPaiNode; + mNumChildren: cardinal; + mChildren: PPaiNodeArray; + mNumMeshes: cardinal; + mMeshes: PCardinalArray; + end; + + + +type TaiScene = packed record + mFlags: cardinal; + mRootNode: PaiNode; + mNumMeshes: Cardinal; + mMeshes: PPaiMeshArray; //? + mNumMaterials: Cardinal; + mMaterials: PPaiMaterialArray; + mNumAnimations: Cardinal; + mAnimations: Pointer; + mNumTextures: Cardinal; + mTextures: PPaiTextureArray; + mNumLights: Cardinal; + mLights: Pointer; + mNumCameras: Cardinal; + mCameras: Pointer; +end; +type PaiScene = ^TaiScene; + +implementation + +end. diff --git a/port/AssimpDelphi/aiTexture.pas b/port/AssimpDelphi/aiTexture.pas new file mode 100644 index 000000000..55e246f2f --- /dev/null +++ b/port/AssimpDelphi/aiTexture.pas @@ -0,0 +1,26 @@ +unit aiTexture; + +interface + +type TaiTexel = packed record + b, g, r, a: byte; +end; +PaiTexel = ^TaiTexel; +TaiTexelArray = array[0..0] of TaiTexel; +PaiTexelArray = ^TaiTexelArray; + +type TaiTexture = packed record + mWidth: Cardinal; //width in pixels, OR total embedded file size if texture is a jpg/png/etc + mHeight: Cardinal; //0 if texture is an embedded file + achFormatHint: array[0..3] of byte; + pcData: PaiTexelArray; +end; +PaiTexture = ^TaiTexture; +PaiTextureArray = array [0..0] of PaiTexture; +PPaiTextureArray = ^PaiTextureArray; + + + +implementation + +end. diff --git a/port/AssimpDelphi/aiTypes.pas b/port/AssimpDelphi/aiTypes.pas new file mode 100644 index 000000000..b7924e87f --- /dev/null +++ b/port/AssimpDelphi/aiTypes.pas @@ -0,0 +1,53 @@ +unit aiTypes; + +interface + +//added for Delphi interface +type + TCardinalArray = array [0..0] of Cardinal; + PCardinalArray = ^TCardinalArray; + + TSingleArray = array[0..0] of Single; + PSingleArray = ^TSingleArray; + +type aiString = packed record + length: Cardinal; + data: array [0..1023] of char; +end; +type PaiString = ^aiString; + +type aiReturn = ( + aiReturn_SUCCESS = $0, + aiReturn_FAILURE = -$1, + aiReturn_OUTOFMEMORY = -$3, + _AI_ENFORCE_ENUM_SIZE = $7fffffff +); + +const AI_SUCCESS = aiReturn_SUCCESS; +const AI_FAILURE = aiReturn_FAILURE; +const AI_OUTOFMEMORY = aiReturn_OUTOFMEMORY; + + + + +function aiStringToDelphiString( a: aiString): AnsiString; + + +implementation + +function aiStringToDelphiString( a: aiString): AnsiString; +var + i: integer; +begin + result := ''; + if a.length > 0 then + begin + SetLength( result, a.length); + for i := 1 to a.length do + begin + result[i] := a.data[i-1]; + end; + end; +end; + +end. diff --git a/port/AssimpDelphi/aiVector2D.pas b/port/AssimpDelphi/aiVector2D.pas new file mode 100644 index 000000000..1e88209ca --- /dev/null +++ b/port/AssimpDelphi/aiVector2D.pas @@ -0,0 +1,13 @@ +unit aiVector2D; + +interface + +type TaiVector2D = packed record + x, y: single; +end; +type PaiVector2D = ^TaiVector2D; + + +implementation + +end. diff --git a/port/AssimpDelphi/aiVector3D.pas b/port/AssimpDelphi/aiVector3D.pas new file mode 100644 index 000000000..2081bb452 --- /dev/null +++ b/port/AssimpDelphi/aiVector3D.pas @@ -0,0 +1,16 @@ +unit aiVector3D; + +interface + +type TaiVector3D = packed record + x, y, z: single; +end; +type PaiVector3D = ^TaiVector3D; +type PaiVector3DArray = array [0..0] of PaiVector3D; + +type TaiVector3DArray = array[0..0] of TaiVector3D; +type PTaiVector3DArray = ^TaiVector3DArray; + +implementation + +end. diff --git a/port/AssimpDelphi/assimp.pas b/port/AssimpDelphi/assimp.pas new file mode 100644 index 000000000..d5bf31dc1 --- /dev/null +++ b/port/AssimpDelphi/assimp.pas @@ -0,0 +1,58 @@ +unit assimp; + +interface + +uses aiTypes, aiMatrix4x4, aiMatrix3x3, aiMesh, aiScene, aiMaterial, aiColor4d, aiVector3D; + +const ASSIMP_DLL = 'assimp32.dll'; + +function aiImportFile(filename: pchar; pFlags: integer): PaiScene; cdecl; external ASSIMP_DLL; +procedure aiReleaseImport( pScene: pointer); cdecl; external ASSIMP_DLL; +function aiGetErrorString(): PChar; cdecl; external ASSIMP_DLL; + +//procedure aiDecomposeMatrix( var mat: TaiMatrix4x4; var scaling: TaiVector3D; var rotation: TaiQuaternion; var position: TaiVector3D); cdecl; external ASSIMP_DLL; +procedure aiTransposeMatrix4( var mat: TaiMatrix4x4); cdecl; external ASSIMP_DLL; +procedure aiTransposeMatrix3( var mat: TaiMatrix3x3); cdecl; external ASSIMP_DLL; +procedure aiTransformVecByMatrix3( var vec: TaiVector3D; var mat: TaiMatrix3x3); cdecl; external ASSIMP_DLL; +procedure aiTransformVecByMatrix4( var vec: TaiVector3D; var mat: TaiMatrix4x4); cdecl; external ASSIMP_DLL; + +procedure aiMultiplyMatrix4(var dst: TaiMatrix4x4; var src: TaiMatrix4x4); cdecl; external ASSIMP_DLL; +procedure aiMultiplyMatrix3(var dst: TaiMatrix3x3; var src: TaiMatrix3x3); cdecl; external ASSIMP_DLL; + + +procedure aiIdentityMatrix3(var mat: TaiMatrix3x3); cdecl; external ASSIMP_DLL; +procedure aiIdentityMatrix4(var mat: TaiMatrix4x4); cdecl; external ASSIMP_DLL; + + +//----- from aiMaterial.h +function aiGetMaterialProperty( pMat: PaiMaterial; pKey: PChar; nType: Cardinal; nIndex: Cardinal; pPropOut: pointer): aiReturn; cdecl; external ASSIMP_DLL; +function aiGetMaterialFloatArray( var pMat: TaiMaterial; pKey: PChar; nType: Cardinal; nIndex: Cardinal; var pOut: Single; var pMax: Cardinal): aiReturn; cdecl; external ASSIMP_DLL; +function aiGetMaterialFloat( var pMat: TaiMaterial; pKey: PChar; nType: Cardinal; nIndex: Cardinal; var pOut: Single): aiReturn; +function aiGetMaterialIntegerArray(var pMat: TaiMaterial; pKey: PChar; nType: Cardinal; nIndex: Cardinal; var pOut: Integer; var pMax: Cardinal): aiReturn; cdecl; external ASSIMP_DLL; +function aiGetMaterialInteger(var pMat: TaiMaterial; pKey: PChar; nType: Cardinal; nIndex: Cardinal; var pOut: Integer): aiReturn; +function aiGetMaterialColor(var pMat: TaiMaterial; pKey: PChar; nType: Cardinal; nIndex: Cardinal; var pOut: TaiColor4d): aiReturn; cdecl; external ASSIMP_DLL; +function aiGetMaterialString(var pMat: TaiMaterial; pKey: PChar; nType: Cardinal; nIndex: Cardinal; var pOut: aiString): aiReturn; cdecl; external ASSIMP_DLL; +function aiGetMaterialTextureCount(var pMat: TaiMaterial; nType: TaiTextureType): Cardinal; cdecl; external ASSIMP_DLL; +function aiGetMaterialTexture(var mat: TaiMaterial; nType: TaiTextureType; nIndex: Cardinal; var path: aiString; var mapping: TaiTextureMapping; var uvindex: Cardinal; var blend: single; var op: TaiTextureOp; var mapmode: TaiTextureMapMode; var flags: Cardinal): aiReturn; cdecl; external ASSIMP_DLL; + + + +implementation + +function aiGetMaterialFloat( var pMat: TaiMaterial; pKey: PChar; nType: Cardinal; nIndex: Cardinal; var pOut: Single): aiReturn; +var + n: cardinal; +begin + n := 0; + result := aiGetMaterialFloatArray( pMat, pKey, nType, nIndex, pOut, n); +end; + +function aiGetMaterialInteger(var pMat: TaiMaterial; pKey: PChar; nType: Cardinal; nIndex: Cardinal; var pOut: integer): aiReturn; +var + n: cardinal; +begin + n := 0; + result := aiGetMaterialIntegerArray( pMat, pKey, nType, nIndex, pOut, n); +end; + +end.