File Hosting Not logged in.
Login Register Emblem CTGP-Nitro
234 users
User list
 
Online users
 
 
News
 

KCL (File Type)



Example of a wrong or bad KCL

KCL files are the files used in MKDS (and some other games) for collision (solidity). If the KCL file is incorrect, you fall trough the ground, or you drive in the void (the 3d model is not the same as the KCL). This page describes the MKDS format.

Header


{{DataStructure}}
|0x00||0x04||UInt32||Vertex Offset
|-
|0x04||0x04||UInt32||Normal Offset
|-
|0x08||0x04||UInt32||Plane Offset (-0x10, this is because the octree uses one based indexing)
|-
|0x0C||0x04||UInt32||Octree Offset
|-
|0x10||0x04||[[Fx32]]||Unknown
|-
|0x14||0x0C||[[VecFx32]]||Octree Top-Left Coordinate
|-
|0x20||0x04||UInt32||X Mask
|-
|0x24||0x04||UInt32||Y Mask
|-
|0x28||0x04||UInt32||Z Mask
|-
|0x2C||0x04||UInt32||Co÷rdinate Shift
|-
|0x30||0x04||UInt32||Y Shift
|-
|0x34||0x04||UInt32||Z Shift
|-
|0x38||0x04||Fx32||Unknown
|}

Vertices


Section containing vertices.
Structure
{{DataStructure}}
|0x00||0x0C||VecFx32||Position
|}

Normals


In geometry, an object such as a line or vector is called a normal to another object if they are perpendicular to each other. For example, in the two-dimensional case, the normal line to a curve at a given point is the line perpendicular to the tangent line to the curve at the point.

In the three-dimensional case a surface normal, or simply normal, to a surface at a point P is a vector that is perpendicular to the tangent plane to that surface at P. The word "normal" is also used as an adjective: a line normal to a plane, the normal component of a force, the normal vector, etc. The concept of normality generalizes to orthogonality.

The concept has been generalized to differentiable manifolds of arbitrary dimension embedded in a Euclidean space. The normal vector space or normal space of a manifold at a point P is the set of the vectors which are orthogonal to the tangent space at P. In the case of differential curves, the curvature vector is a normal vector of special interest.

The normal is often used in computer graphics to determine a surface's orientation toward a light source for flat shading, or the orientation of each of the corners (vertices) to mimic a curved surface with Phong shading.
Normal (geometry)
Normals are used in kcl files to calculate the remaining 2 points of a triangle (the first one is in the vertices section). They're also used in mkds to calculate the exact point on a triangle (Get the Y for X + Z). (Like MKDS Course Modifier does for auto-height calculation)
Structure
{{DataStructure}}
|0x00||0x06||[[VecFx16]]||Normal
|}

Planes


The real triangle definitions.
Structure
{{DataStructure}}
|0x00||0x04||Fx32||Length
|-
|0x04||0x02||UInt16||Vertex Index
|-
|0x06||0x02||UInt16||Normal Index
|-
|0x08||0x02||UInt16||Normal A Index
|-
|0x0A||0x02||UInt16||Normal B Index
|-
|0x0C||0x02||UInt16||Normal C Index
|-
|0x0E||0x02||UInt16||[[KCL (File Format)/Collision ID|Collision Type]]
|}

Converting to Coordinates

CrossA = Cross(NormalA,Direction)
CrossB = Cross(NormalB,Direction)
Vertex1 = Position
Vertex2 = Position + CrossB * (Length / Dot(CrossB,NormalC))
Vertex3 = Position + CrossA * (Length / Dot(CrossA,NormalC))


Octrees


An octree is a tree data structure in which each internal node has exactly eight children. Octrees are most often used to partition a three dimensional space by recursively subdividing it into eight octants. Octrees are the three-dimensional analog of quadtrees. The name is formed from oct + tree, but note that it is normally written "octree" with only one "t". Octrees are often used in 3D graphics and 3D game engines.
Wikipedia: Octree
The octree divides the 3d space in cubes which contain triangles. This is to make it for mkds easier (and thus faster) to detect collision.
Technical information
Calculating the number of nodes (root niveau) goes like this:

NrNodes = ((~Xmask >> CoordinateShift) + 1) * ((~Ymask >> CoordinateShift) + 1) * ((~Zmask >> CoordinateShift) + 1)

Cube
Each cube got this structure:
OffsetSizeDescription
0x000x04Flags

If the last bit of the flag is set, it's a Leaf (a cube which is not divided anymore and contains triangles). Otherwise, it's a node (a cube which contains 8 more cubes). The remaining part of the flag is a '''relative offset''' to the data (triangle indices or more cubes).

IsLeaf = (Flag >> 31) == 1
ROffset = Flag & 0x7FFFFFFF

Leaf
If the cube is a leaf, the structure is like this:
{{DataStructure}}
|0x00||0x02||UInt16||Always zero. Indicates the start (and the end) of a leaf
|-
!colspan=4|The triangle indices follow (UInt16)
|}
After the zero, triangle indices follow. For reading them, just read until a zero index is found. Those indices are one based. This is because of the starting zero. This is also the reason that the plane offset in the header is offset by -0x10.
Structure Sample

  • Subnode 1: leaf

  • Subnode 2: node

  • Subnodes of Subnode 2


    • Subsubnode 1: Leaf

    • ...


      ...

  • Triangle indices of Subnode 1


    • 0 (start)

    • 5

    • 9

    • ...


  • Triangle indices of Subsubnode 1


    • 0 (start)

    • 7

    • 22

    • ...


  • ...


As you can see, all cubes of a node are directly behind each other. The data of those nodes in somewhere else

Opening a KCL file
There are a few programs available to open KCL files:

  • MKToolbox

  • Every File Explorer

  • Mario Kart DS Course Modifier





Last edit by Garhoogin on Tue Apr 09 21:10:39 CDT 2019