Skip to content

Instructions for porting code & Differences between the C and Kotlin version

gynt edited this page Dec 1, 2017 · 3 revisions

From now on,

  • Assimp in C++ is referred to as C++
  • Assimp Kotlin is referred to as Kotlin

In general

Matrices

Matrices are column-based in Kotlin and row-based in C++. Furthermore, Kotlin identifiers of Matrix components (a0, b2, etc.) starts counting at 0, C++ starts counting at 1. When porting the code, this means that you should first decrease all numbers: a1 becomes a0, d4 becomes d3. After this, you should swap rows and columns. This means that a1 becomes b0, because 'a' translates to 0, and 1 translates to 'b'.

Material system

TODO

mesh

AiMesh

textureCoords

When you are porting from C++ to Kotlin, you should remove hardcoded 0.0F whenever an vector is added to textureCoords. The 0.0F indicates there is no valid value for that component of the vector.
Kotlin uses a FloatArray instead of AiVector3D. Therefore, you should ignore the hardcoded value.
Example:

C++ code:
mesh->mTextureCoords[e][newIndex] = aiVector3D( tex.x, 1.0f - tex.y, 0.0f);

Kotlin code:
mesh.textureCoords[e][newIndex] = arrayOf(tex.x, 1.0f - tex.y)

Detailed explanation
Kotlin's FloatArray represents a structure that is similar to C++'s AiVector3D. However, in contrast to C++, Kotlin is not limited to 4 Dimensional arrays. If textureCoords[n] is two dimensional, C++ sets 0.0F for the z component of an AiVector3D. If textureCoords[n] is one dimensional, C++ sets 0.0F for the y, and z component of an AiVector3D. Kotlin does not set these dummy values that are ignored. The size of the FloatArray indicates the amount of dimensions.

Regular expressions

For-loops

To convert:

for(unsigned int n = 0; n < mesh.numVertices; ++n)

To:

for(n in 0 until mesh.numVertices)

You can use the following regular expression:

Find: [a-z ]+\s+([a-z])\s*=\s*([0-9]);\s*[a-z]\s*<\s*([a-zA-Z_\.]+);\s*(\+\+[a-z])|([a-z]\+\+)

Replace: $1 in $2 until $3

Properties

To convert:

scene.mNumTextures

To:

scene.numTextures

You can use the following regular expression:

Find: \.m([A-Z])([a-zA-Z]+)

Replace: .\l$1$2