<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.wexosmk.xyz/index.php?action=history&amp;feed=atom&amp;title=KCL_%28File_Format%29%2FWii</id>
	<title>KCL (File Format)/Wii - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.wexosmk.xyz/index.php?action=history&amp;feed=atom&amp;title=KCL_%28File_Format%29%2FWii"/>
	<link rel="alternate" type="text/html" href="https://wiki.wexosmk.xyz/index.php?title=KCL_(File_Format)/Wii&amp;action=history"/>
	<updated>2026-05-06T17:56:16Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.41.1</generator>
	<entry>
		<id>https://wiki.wexosmk.xyz/index.php?title=KCL_(File_Format)/Wii&amp;diff=217&amp;oldid=prev</id>
		<title>Wexos: Imported from avsys wiki</title>
		<link rel="alternate" type="text/html" href="https://wiki.wexosmk.xyz/index.php?title=KCL_(File_Format)/Wii&amp;diff=217&amp;oldid=prev"/>
		<updated>2024-05-01T17:37:23Z</updated>

		<summary type="html">&lt;p&gt;Imported from avsys wiki&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;#039;&amp;#039;&amp;#039;KCL&amp;#039;&amp;#039;&amp;#039; files are collision files, which is the model the game runs collision against. KCL files has been used since at least [[Mario Kart DS]], but this documentation is about the format used in [[Nintendo DS]], [[Wii]] and [[Nintendo 3DS]]. The only differences is that [[Nintendo DS]] uses a specific format which replaces all floats. For other formats, see [[KCL (File Format)]].&lt;br /&gt;
&lt;br /&gt;
KCL stores triangle in a format which allow fast access and collision calculation, and has an octree which splits the world space into many cubes, to make the game test collision on less triangles, which allows for much faster collision detection.&lt;br /&gt;
&lt;br /&gt;
= File Format =&lt;br /&gt;
== Header ==&lt;br /&gt;
The header is a 0x3C byte structure as follows:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Offset !! Type !! Description&lt;br /&gt;
|-&lt;br /&gt;
| 0x00 || UInt32 || &amp;#039;&amp;#039;&amp;#039;Offset to [[#Vertices|vertex positions]]&amp;#039;&amp;#039;&amp;#039;, relative to the start of the file.&lt;br /&gt;
|-&lt;br /&gt;
| 0x04 || UInt32 || &amp;#039;&amp;#039;&amp;#039;Offset to [[#Directional Vectors|directional vectors]]&amp;#039;&amp;#039;&amp;#039;, relative to the start of the file.&lt;br /&gt;
|-&lt;br /&gt;
| 0x08 || UInt32 || &amp;#039;&amp;#039;&amp;#039;Offset to [[#Triangles|triangles]]&amp;#039;&amp;#039;&amp;#039; - 0x10, relative to the start of the file. To get the actual offset, add 0x10 to this value. It works like this because the [[#Octree|octree]] triangle indices are 1-based.&lt;br /&gt;
|-&lt;br /&gt;
| 0x0C || UInt32 || &amp;#039;&amp;#039;&amp;#039;Offset to [[#Octree|octree]]&amp;#039;&amp;#039;&amp;#039;, relative to the start of the file.&lt;br /&gt;
|-&lt;br /&gt;
| 0x10 || Float|| {{Unknown-left|&amp;#039;&amp;#039;&amp;#039;Unknown&amp;#039;&amp;#039;&amp;#039;. Always 300.}}&lt;br /&gt;
|-&lt;br /&gt;
| 0x14 || Float[3] || &amp;#039;&amp;#039;&amp;#039;[[#Octree|Octree]] origin&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
|-&lt;br /&gt;
| 0x20 || UInt32 || &amp;#039;&amp;#039;&amp;#039;X mask&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
|-&lt;br /&gt;
| 0x24 || UInt32 || &amp;#039;&amp;#039;&amp;#039;Y mask&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
|-&lt;br /&gt;
| 0x28 || UInt32 || &amp;#039;&amp;#039;&amp;#039;Z mask&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
|-&lt;br /&gt;
| 0x2C || UInt32 || &amp;#039;&amp;#039;&amp;#039;Coordinate shift&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
|-&lt;br /&gt;
| 0x30 || UInt32 || &amp;#039;&amp;#039;&amp;#039;Y shift&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
|-&lt;br /&gt;
| 0x34 || UInt32 || &amp;#039;&amp;#039;&amp;#039;Z shift&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
|-&lt;br /&gt;
| 0x38 || Float|| {{Unknown-left|&amp;#039;&amp;#039;&amp;#039;Unknown&amp;#039;&amp;#039;&amp;#039;. Always 250.}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Vertices ===&lt;br /&gt;
Section 1 is simply a large array of vertices, stored as 3 successive singles for x, y and z. The length of this array is not stored, but can usually be calculated by subtracting the section 1 offset from the section 2 offset and dividing by 0x0C.&lt;br /&gt;
&lt;br /&gt;
=== Directional Vectors ===&lt;br /&gt;
Section 2 is much the same as section 1, in that it is a large array of directional vectors. Again the values are stored as 3 successive singles for x, y and z. The length of this array is not stored, but can usually be calculated by subtracting the section 2 offset from the section 3 offset and dividing by 0x0C.&lt;br /&gt;
&lt;br /&gt;
=== Triangles ===&lt;br /&gt;
The third section is the section containing the actual model information. The structure of each entry in this section is a 0x10 byte structure given below.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Offset !! Type !! Description&lt;br /&gt;
|-&lt;br /&gt;
| 0x00 || Float || &amp;#039;&amp;#039;&amp;#039;Length&amp;#039;&amp;#039;&amp;#039; of triangle.&lt;br /&gt;
|-&lt;br /&gt;
| 0x04 || UInt16 || The index of the &amp;#039;&amp;#039;&amp;#039;first vertex position&amp;#039;&amp;#039;&amp;#039; into the [[#Vertices|vertex array]].&lt;br /&gt;
|-&lt;br /&gt;
| 0x06 || UInt16 || The index of the &amp;#039;&amp;#039;&amp;#039;normal&amp;#039;&amp;#039;&amp;#039; into the [[#Directional Vectors|directional vector array]].&lt;br /&gt;
|-&lt;br /&gt;
| 0x08 || UInt16 || The index of the &amp;#039;&amp;#039;&amp;#039;direction A&amp;#039;&amp;#039;&amp;#039; into the [[#Directional Vectors|directional vector array]].&lt;br /&gt;
|-&lt;br /&gt;
| 0x0A || UInt16 || The index of the &amp;#039;&amp;#039;&amp;#039;direction B&amp;#039;&amp;#039;&amp;#039; into the [[#Directional Vectors|directional vector array]].&lt;br /&gt;
|-&lt;br /&gt;
| 0x0C || UInt16 || The index of the &amp;#039;&amp;#039;&amp;#039;direction C&amp;#039;&amp;#039;&amp;#039; into the [[#Directional Vectors|directional vector array]].&lt;br /&gt;
|-&lt;br /&gt;
| 0x0E || UInt16 || &amp;#039;&amp;#039;&amp;#039;Collision attributes&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
All indices in this section are 0 indexed. The position index is an index for section 1, and the others are indices to section 2. The exact manner in which the values are used for collision detection is unknown, however a method for converting this form of triangle to a set of three coordinates is outlined below. The coordinate system is right handed.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CrossA = Cross(DirectionA, Normal)&lt;br /&gt;
CrossB = Cross(DirectionB, Normal)&lt;br /&gt;
Vertex1 = Position&lt;br /&gt;
Vertex2 = Position + CrossB * (Length / Dot(CrossB, DirectionC))&lt;br /&gt;
Vertex3 = Position + CrossA * (Length / Dot(CrossA, DirectionC))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
A method for converting three vertices into the KCL form is given below. This method assumes the vertices are arranged anti clockwise when viewed from the collidable side.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Position = Vertex1&lt;br /&gt;
Direction = Normalize(Cross(Vertex2 - Vertex1, Vertex3 - Vertex1 ))&lt;br /&gt;
DirectionA = Normalize(Cross(Normal, Vertex3 - Vertex1 ))&lt;br /&gt;
DirectionB = Normalize(-Cross(Normal, Vertex2 - Vertex1 ))&lt;br /&gt;
DirectionC = Normalize(Cross(Normal, Vertex2 - Vertex3 ))&lt;br /&gt;
Length = Dot(Vertex2 - Vertex1, DirectionC )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Octree ===&lt;br /&gt;
The octree subdivides the world space into cubes, to allow much faster triangle collision detection. The number of root [[#Node|nodes]] can be calculated by the following algorithm:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
NrRootNodes = (~MaskX &amp;gt;&amp;gt; CoordinateShift + 1) * (~MaskY &amp;gt;&amp;gt; CoordinateShift + 1) * (~MaskZ &amp;gt;&amp;gt; CoordinateShift + 1)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then the number of root nodes are written to the file. These nodes link to more nodes or triangle lists.&lt;br /&gt;
&lt;br /&gt;
==== Node ====&lt;br /&gt;
Each node has the following structure:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Offset !! Type !! Description&lt;br /&gt;
|-&lt;br /&gt;
| 0x00 || UInt32 || &amp;#039;&amp;#039;&amp;#039;Flag&amp;#039;&amp;#039;&amp;#039;: &amp;#039;&amp;#039;&amp;#039;ABBB BBBB BBBB BBBB BBBB BBBB BBBB BBBB&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;A&amp;#039;&amp;#039;&amp;#039;: 1 means it&amp;#039;s a leaf. See below.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;B&amp;#039;&amp;#039;&amp;#039;: Offset to next structure, relative to the parent node, or start of octree data if the node is a root node.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
If the node is a leaf, then it means it isn&amp;#039;t subdivided anymore and it contains triangle lists. This triangle list is terminated by 0, and contains 1-based indices of the [[#Triangles|triangles]] that are present in this subspace. If it&amp;#039;s not a leaf, then this node is subdivided into 8 more nodes, which the offset into the structure links to.&lt;br /&gt;
&lt;br /&gt;
= Tools =&lt;br /&gt;
The following tools can handle KCL files:&lt;br /&gt;
* [[Wexos&amp;#039;s Toolbox]], by [[Wexos]] (Wii)&lt;br /&gt;
* [[Wiimms SZS Tools]], by [[Wiimm]] (Wii)&lt;br /&gt;
&lt;br /&gt;
[[Category: 3DS File Formats]]&lt;br /&gt;
[[Category: DS File Formats]]&lt;br /&gt;
[[Category: Wii File Formats]]&lt;/div&gt;</summary>
		<author><name>Wexos</name></author>
	</entry>
</feed>