Difference between revisions of "Creating a KCL with Wiimms Tools"

From Custom Mario Kart
Jump to navigation Jump to search
m (Fixed link)
 
(41 intermediate revisions by 12 users not shown)
Line 1: Line 1:
 +
This page is a part of the '''Custom Track Tutorial'''. [[Custom Track Tutorial|Back to the main tutorial page]].
 +
 
== Introduction ==
 
== Introduction ==
 +
Each track needs a collision ([[KCL]]) file named ''course.kcl''. This collision file describes how players and items interact with the world. Therefore the collision file contains lists with triangles and an octree based system to find the triangles efficiently while playing. If touching a triangle, its [[KCL flag]] is used to determine the action, like boost, wall or fall down.
  
Each track needs a collision ([[KCL]]) file named ''course.kcl''. This collision file describes how players and items interact with the world. Therefor the collision file contains lists with triangles and an octree based system to find the triangles efficiently while playing. If touching a triangle, its [[KCL Flag]] is used to determine the action, like boost, wall or fall down.
+
Normally the KCL triangles are a copy of the 3D world you made with your favorite [[3D Tool]], but without any textures or color definitions. The KCL world can also have additional planes for invisible borders or for sound and effect triggering. Creation of this model is explained in the [[Solidity]] page.
  
Normally the KCL triangles are a copy of the 3D world you made with your favorite [[3D Tool]], but without any textures or color definitions. The KCL world can also have additionally planes for invisible borders or for sound and effect triggering.
+
This article describes how to create a KCL file using [[Wiimms SZS Tools]]. The new KCL is made from scratch with a maximum of 65535 triangles, the KCL internal limit.
  
This article describes, how to create a [[KCL]] file using [[Wiimms SZS Tools]]. The new KCL is made from scratch with a maximum of 65535 triangles, the KCL internal limit.
+
'''Notes'''
 
+
* Wiimms SZS Tools are ''command line tools'' (CLI). There is no graphical user interface (GUI). The user have to type the commands including options and parameters into a text console or as script (batch file). The results are printed to the text console, if not redirected. → [http://szs.wiimm.de/doc/cli more CLI details].
;Note: [[Wiimms SZS Tools]] are ''command line tools'' (CLI). There is no graphical user interface (GUI). The user have to type the commands including options and parameters into a text console or as script (batch file). The results are printed to the text console, if not redirected. → [http://szs.wiimm.de/doc/cli more CLI details].
+
* You can use [[Wiimm's Tool Manager]] if you're not familiar with ''CLI''.
  
 
== Create the KCL ==
 
== Create the KCL ==
 
The creation of a KCL is done in 3 steps:
 
The creation of a KCL is done in 3 steps:
# Export a collision model with your [[3D Tool]].
+
# Export a collision model with your 3D Tool.
# Create a [[KCL Flag]] assignment file.
+
# Create a KCL flag assignment file.
# Encode (create) the final [[KCL]] file.
+
# Encode (create) the final KCL file.
  
 
=== Create an OBJ file ===
 
=== Create an OBJ file ===
 +
This step is really easy. Just export your model as ''OBJ file''<ref>Wikipedia: [http://en.wikipedia.org/wiki/Wavefront_.obj_file Wavefront .obj file]</ref> with your favorite 3D Tool. See '''»[[Solidity]]«''' for more details. Unfortunately [[Wiimms SZS Tools]] do not work well with [[Blender]] OBJs so it is recommended to follow the below tutorial to export your model:
 +
{{youtube-box|tutorial|A6G_h0mvfdc|Using [[Wiimms SZS Tools]] with [[Blender]]}}
  
This step is really easy. Just export your world as ''OBJ file''<ref>WikiPedia: [http://en.wikipedia.org/wiki/Wavefront_.obj_file Wavefront .obj file]</ref> with your favorite [[3D Tool]]. See '''»[[Solidity]]«''' for more details.
 
  
The export may contain all groups of the world. For the [[KCL]] unneeded groups can easily filtered by setting KCL flag to -1 in the ''flag assignment file''. Graphics and textures are not needed and ignored by the KCL encoder.
+
The export may contain all groups of the KCL. If any models present in the OBJ are not needed, they can easily filtered by setting KCL flag to -1 in the ''flag assignment file''. Graphics and textures are not needed and ignored by the KCL encoder. If Blender is being used to export the OBJ, the option "Material Groups" needs to be checked in the export settings. This is unchecked by default.
  
 
=== Create a flag assignment file ===
 
=== Create a flag assignment file ===
 
+
A ''flag file'' should be created by the command [http://szs.wiimm.de/cmd/wkclt/cff wkclt CFF] ('''C'''reate '''F'''lag '''F'''ile), which is recommended. The CFF command reads a KCL or an OBJ file and creates a new ''flag file'' as template. If the ''flag file'' already exists, it is scanned and only new groups are appended at the end of the existing file. A batch file with this script is included in the pack. The file can also be created manually.
A ''flag file'' can be created manually or by using the command [http://szs.wiimm.de/cmd/wkclt/cff wkclt CFF] ('''C'''reate '''F'''lag '''F'''ile), which is recommend. The CFF command reads a KCL or an OBJ file and creates a new ''flag file'' as template. If the ''flag file'' already exists, it is scanned and only
 
new groups are appended at the end of the existing file.
 
  
 
The default filename for the ''flag file'' is the filename of the OBJ or KCL file with the new extension '''.flag''' (&raquo;my_track.obj&laquo; becomes &raquo;my_track.flag&laquo;). The old naming extension with ''.flag.txt'' is also supported. See option [http://szs.wiimm.de/opt/flag-file --flag-file] for more details.
 
The default filename for the ''flag file'' is the filename of the OBJ or KCL file with the new extension '''.flag''' (&raquo;my_track.obj&laquo; becomes &raquo;my_track.flag&laquo;). The old naming extension with ''.flag.txt'' is also supported. See option [http://szs.wiimm.de/opt/flag-file --flag-file] for more details.
Line 30: Line 32:
 
The ''flag file'' contains lines in the format:
 
The ''flag file'' contains lines in the format:
 
  object_group_name = flag_value
 
  object_group_name = flag_value
It is important to prefix each hexadecimal value with '0x', because the file is interpreted by the [http://szs.wiimm.de/doc/syntax text parser] of [[Wiimms SZS Tools]], which also allows decimal numbers and numerical expressions. If a flag is set to -1, the object group will not be included into the [[KCL]].
+
It is important to prefix each hexadecimal value with '0x', because the file is interpreted by the [http://szs.wiimm.de/doc/syntax text parser] of Wiimms SZS Tools, which also allows decimal numbers and numerical expressions. If a flag is set to -1, the object group will not be included into the KCL.
  
 
'''Example:'''
 
'''Example:'''
Line 42: Line 44:
 
</pre>
 
</pre>
  
It's no problem to enter your [[KCL Flag]]s separated by type and variant. Just create a function that will calculate the resulting KCL flag for you:
+
It's no problem to enter your [[KCL flag]]s separated by type and variant. Just create a function that will calculate the resulting KCL flag for you:
  
 
'''Example:'''
 
'''Example:'''
Line 61: Line 63:
 
</pre>
 
</pre>
  
The command [http://szs.wiimm.de/cmd/wkclt/cff wkclt CFF] will create a template including the user defined function f(). Read [http://szs.wiimm.de/info/kcl-guide.html#def-flag &raquo;Defining KCL flags&laquo;] for more details.
+
The command [http://szs.wiimm.de/cmd/wkclt/cff wkclt CFF] will create a template including the user defined functions f(type,variant), a(type,w,x,y,z) and i(type,z,index). Read [http://szs.wiimm.de/info/kcl-guide.html#def-flag &raquo;Defining KCL flags&laquo;] for more details.
  
 
=== Encode the KCL file ===
 
=== Encode the KCL file ===
 
+
The command to create the KCL is:
The command to create the [[KCL]] is:
 
 
  wkclt encode course.obj --kcl=drop
 
  wkclt encode course.obj --kcl=drop
 
The file ''course.flag.txt'' is read automatically, if it exists. This command creates the file ''course.kcl'', but only, if the file does not exist. The recommended option ''--kcl=drop'' is discussed below. To overwrite an existing file, add option ''--overwrite'' (or short ''-o''):
 
The file ''course.flag.txt'' is read automatically, if it exists. This command creates the file ''course.kcl'', but only, if the file does not exist. The recommended option ''--kcl=drop'' is discussed below. To overwrite an existing file, add option ''--overwrite'' (or short ''-o''):
 
  wkclt encode course.obj --kcl=drop -o
 
  wkclt encode course.obj --kcl=drop -o
  
It is a good idea, to write a script (batch file) that contains your creation command with all options. This allows to just click the script to execute the command(s).
+
It is a good idea to write a script ('''.bat''' batch file) that contains your creation command with all options. This allows to just click the script to execute the command(s). A batch file with this script is included in the pack.
  
 
'''Windows example:'''
 
'''Windows example:'''
Line 79: Line 80:
 
</pre>
 
</pre>
  
There are only some limits while creating the [[KCL]] file:
+
There are only some limits while creating the KCL file:
 
* The number of triangles can't exceed 65535 (0xFFFF), because the octree use only 16 bits for triangle references and value 0 is reserved as ''end of list'' marker.
 
* The number of triangles can't exceed 65535 (0xFFFF), because the octree use only 16 bits for triangle references and value 0 is reserved as ''end of list'' marker.
 
* The number of vertex and normal vectors can't exceed 65536 (0x10000) because of the 16 bit limit of indices. This is not a problem for the vertex section, because each triangle use exact 1 vertex vector. But a triangle needs 4 normal references. Therefore the KCL encoder tries to find duplicates of normals and vertex values to reduce the section size.
 
* The number of vertex and normal vectors can't exceed 65536 (0x10000) because of the 16 bit limit of indices. This is not a problem for the vertex section, because each triangle use exact 1 vertex vector. But a triangle needs 4 normal references. Therefore the KCL encoder tries to find duplicates of normals and vertex values to reduce the section size.
 
The new KCL file is always created from scratch. So the new KCL file is garbage free.
 
The new KCL file is always created from scratch. So the new KCL file is garbage free.
 +
 +
== Next ==
 +
If you're generating your KCL file from scratch now and don't need to set anything else, you should be done with it (for now); move on to the [[KMP Editing]] tutorial. You can also [[Testing a Track|test your track]] now to make sure the KCL works, but you might want to at least set a start position in the KMP before that.
 +
 +
== Additional/Advanced Info ==
  
 
==== Option --kcl ====
 
==== Option --kcl ====
 
 
The keyword list of option --kcl defines, how the OBJ+KCL processor internally works. There are different options to remove unwanted triangles, to change the vertex order, to define the material mode for OBJ export and much more. All options are explained in [http://szs.wiimm.de/opt/kcl Wiimms KCL Guide].
 
The keyword list of option --kcl defines, how the OBJ+KCL processor internally works. There are different options to remove unwanted triangles, to change the vertex order, to define the material mode for OBJ export and much more. All options are explained in [http://szs.wiimm.de/opt/kcl Wiimms KCL Guide].
  
 
==== Advanced usage ====
 
==== Advanced usage ====
 
 
If you need to scale and/or rotate the KCL, use the options [http://szs.wiimm.de/opt/scale --scale] and/or [http://szs.wiimm.de/opt/hrot --hrot]. Here is an Windows batch file example (filename ''create-kcl.bat''):
 
If you need to scale and/or rotate the KCL, use the options [http://szs.wiimm.de/opt/scale --scale] and/or [http://szs.wiimm.de/opt/hrot --hrot]. Here is an Windows batch file example (filename ''create-kcl.bat''):
 
<pre>
 
<pre>
Line 106: Line 110:
 
# overwrites an already existing file named ''course.kcl'' (-o).
 
# overwrites an already existing file named ''course.kcl'' (-o).
  
== Tune the KCL ==
+
=== Ignoring small triangles ===
 +
 
 +
Sometimes, the imported file contains very small triangles with an area smaller than 1 unit<sup>2</sup>. They were accidentally inserted into the model by the user. Because of the small size, the user will not see them in the model view of their [[3D Tool]]. However, machines like the [[KCL]] importer of these tools see them and insert them into the KCL &mdash; this is not a bug with the tools. The Wii has (mathematical) problems processing them correctly, resulting in KCL glitches like mini walls on the road.
 +
 
 +
Since v1.58a there are 2 new options: '''--tri-area=EXPR''' and '''--tri-height=EXPR'''[https://szs.wiimm.de/info/kcl-guide.html#tri-min] to filter out triangles that are too small.
 +
 
 +
Option [https://szs.wiimm.de/opt/tri-area --tri-area=EXPR] defines the minimal area size of KCL triangles. The intention is to '''ignore triangles that are generally too small'''. EXPR is a floating point number or expression. Triangles are invalidated if their area size is smaller than EXPR. Values between 0.01 and 4.0 are recommended. The careful value 1.0 is used as default. Value 0 disables this filter functionality.
 +
 
 +
Option [https://szs.wiimm.de/opt/tri-height --tri-height=EXPR] defines the minimal height of KCL triangles. The intention is to '''ignore deformed triangles (very slim, but long)'''. EXPR is a floating point number or expression. Triangles are invalidated if at least 1 of the 3 heights is smaller than EXPR. Values between 0.01 and 2.0 are recommended. The careful value 1.0 is used as default since v1.58b. Value 0 disables this filter functionality.
 +
 
 +
The tests for both options are executed after reading files, after transformations, and after calculating normals and lengths.
 +
 
 +
''' It is recommended to use v1.58b or later of Wiimm's SZS Tools if creating a [[KCL]].'''
 +
 
 +
'''Examples:'''
 +
<pre>
 +
# set minimal area size to 5.0 and minimal height to 0.5 (=1/2)
 +
wkclt encode --tri-area 5 --tri-height 1/2 ....
  
=== Remove garbage from old KCL files ===
+
# patch an existing track with same limits
 +
wszst patch track.szs --tri-area 5 --tri-height 1/2 --kcl new,drop
 +
</pre>
  
If some older tools create a KCL file, they use an already existing KCL file as base and inject it with the new data. This has 2 major issues:
+
=== Removing garbage from old KCL files ===
* The limited size of the base KCL limits the number of vertices, normals and triangles and also the size of the octree.
+
Some older tools create a KCL file, by using an already existing KCL file as base and injecting it with the new data. This has 2 major issues:
* The file contains old triangles, that uses any of the overwritten vertices and normals. The results are unreal triangles, sometimes with invalid vertex coordinates. These triangles are ignored by the KCL processing of the Wii, because they are not referenced by the octree. But if exporting or modifying the KCL, the triangles becomes valid with invalid values.
+
*The limited size of the base KCL limits the number of vertices, normals and triangles and also the size of the octree.
 +
*The file contains old triangles, that uses any of the overwritten vertices and normals. The results are unreal triangles, sometimes with invalid vertex coordinates. These triangles are ignored by the KCL processing of the Wii, because they are not referenced by the octree. But if exporting or modifying the KCL, the triangles becomes valid with invalid values.
  
 
These unreferenced/unused/invalid triangles can be removed by adding ''--kcl drop'' to any command.
 
These unreferenced/unused/invalid triangles can be removed by adding ''--kcl drop'' to any command.
Line 132: Line 156:
 
# show kcl flag statistics of a track file, but ignore unneeded triangles
 
# show kcl flag statistics of a track file, but ignore unneeded triangles
 
wkclt flags mytrack.szs --kcl drop
 
wkclt flags mytrack.szs --kcl drop
 +
</pre>
 +
 +
=== Create a small KCL ===
 +
The tools accept 3 keywords for option --kcl to control the size of the KCL. The main aspect is, how many faces of the neighborhood should be included into the face list of a cube. The keywords are:
 +
; SMALL: Set the parameters to values to get a relative small KCL file. The neighborhood distance is set to 200. Until now not any disadvantage of SMALL was found. But don't use small if you plan a track with [[Lap & Speed Modifier|speed factor]] &ge;1.5.
 +
; MEDIUM: This is the default. It is anywhere in the middle between SMALL and CHARY. The neighborhood distance is set to 400.
 +
;CHARY: The parameters are set to Nintendo-like values, that are very careful. This blows up the octree significantly, because of the large neighborhood distance of 600.
 +
 +
Creation of a small KCL may help to reduce the [[Slow Motion Bug]]. This is especially true, if the old KCL was made with other tools.
 +
 +
'''Examples:'''
 +
<pre>
 +
wkclt encode course.kcl --kcl small,drop,rm-facedown
 +
wszst patch track.szs --kcl new,small,drop,rm-facedown
 
</pre>
 
</pre>
  
 
=== Export to OBJ ===
 
=== Export to OBJ ===
 
+
If you want to make a KCL file visible in a 3D Tool, just export it as OBJ file. For custom tracks it is a good idea to remove unreferenced triangles ([[#Remove garbage from old KCL files|see above]]) and add ''--kcl drop'' to the command.
If you want to make a KCL file visible in a [[3D Tool]], just export it as OBJ file. For custom tracks it is a good idea to remove unreferenced triangles ([[#Remove garbage from old KCL files|see above]]) and add ''--kcl drop'' to the command.
 
  
 
'''Example:'''
 
'''Example:'''
Line 151: Line 188:
  
 
== Scripts ==
 
== Scripts ==
 
+
If using any of the wkclt commands, the option [https://szs.wiimm.de/opt/kcl-script --kcl-script=filename] allows to define a script to manipulate the the KCL data:
If using any of the wkclt commands, the option [http://szsz.wiimm.de/opt/kcl-script --kcl-script=filename] allows to define a script to manipulate the the KCL data:
+
*Remove existing triangles.
* Remove existing triangles.
+
*Add new triangles.
* Add new triangles.
+
*Change the positions of triangles.
* Change the positions of triangles.
+
*Change the KCL-Flag of triangles.
* Change the KCL-Flag of triangles.
 
 
For the selection of existing triangles, flag, vertex positions, normals and length can be used.
 
For the selection of existing triangles, flag, vertex positions, normals and length can be used.
  
Line 162: Line 198:
  
 
=== Remove face down roads ===
 
=== Remove face down roads ===
 
 
If roads are defined with face up and face down triangles, a KCL glitch is possible. It is because after jumps the driver can be some pixel below the road. In this case, the face down road becomes active for a short time and vehicle+driver drives in any unwanted direction and the camera view changes rapidly.  
 
If roads are defined with face up and face down triangles, a KCL glitch is possible. It is because after jumps the driver can be some pixel below the road. In this case, the face down road becomes active for a short time and vehicle+driver drives in any unwanted direction and the camera view changes rapidly.  
  
 
In general, there is no need for face down roads. This is also true for all other drivable KCL types like offroad, boost or trick ramp. The following script detects face down drivable triangles (by analyzing the KCL type and the first normal) and removes them:
 
In general, there is no need for face down roads. This is also true for all other drivable KCL types like offroad, boost or trick ramp. The following script detects face down drivable triangles (by analyzing the KCL type and the first normal) and removes them:
<pre>
+
 
 +
<spoiler text="Script: remove-face-down.txt"><pre>
 
#--- remove face down roads
 
#--- remove face down roads
  
Line 172: Line 208:
 
@def rm_count = 0 # reset status counter
 
@def rm_count = 0 # reset status counter
  
@for t=0; tri$n()-1 # for each tirangle (index 0 based)
+
@for t=0; tri$n()-1 # for each triangle (index 0 based)
 
     @pdef type = tri$flag(t) & 0x1f # get the KCL type
 
     @pdef type = tri$flag(t) & 0x1f # get the KCL type
     @if kcl$drive & (1<<type) # if it is a drivable KCL tpye
+
     @if kcl$drive & (1<<type) # if it is a drivable KCL type
 
@def norm = tri$normal(t,0) #    get the first normal
 
@def norm = tri$normal(t,0) #    get the first normal
 
@if norm.y < 0 #    if it is face down
 
@if norm.y < 0 #    if it is face down
 
    @def stat = tri$remove(t) #      remove the triangle
 
    @def stat = tri$remove(t) #      remove the triangle
    @def rm_count = rm_count + 1 #      incremtent the counter
+
    @def rm_count = rm_count + 1 #      increment the counter
 
@endif #    endif
 
@endif #    endif
 
     @endif # endif
 
     @endif # endif
Line 185: Line 221:
 
# print out a summary line
 
# print out a summary line
 
@echo "  - " rm_count " face down road triangles removed in " (mSec()-start) " msec."
 
@echo "  - " rm_count " face down road triangles removed in " (mSec()-start) " msec."
</pre>
+
</pre></spoiler>
 
 
 
To use the script, extend the command with --kcl-script remove-face-down.txt:
 
To use the script, extend the command with --kcl-script remove-face-down.txt:
 
  wkclt encode course.obj -o --kcl-script remove-face-down.txt
 
  wkclt encode course.obj -o --kcl-script remove-face-down.txt
Line 195: Line 230:
  
 
=== Lower walls ===
 
=== Lower walls ===
 +
You know the problem: Jumping over borders is impossible. If hitting the hard walls, you fall down immediately. This is not a problem of Nintendo's tracks and can be solved by lowering the walls about 20&ndash;50 units.
  
You know the problem: Jumping over borders is impossible. If hitting the hard walls, you fall down immediately. This is not a problem of Nintendos tracks and can be solved by lowering the walls about 20&ndash;50 units.
+
If creating the KCL, you can establish a script that can fix the walls. The script '''lower-walls.txt''' is part of the distribution and looks like this:
  
If creating the KCL, you can establish a script that can fix the walls. The script '''lower-walls.txt''' is part of the distribution and looks like this:
+
<spoiler text="Script: lower-walls.txt"><pre>
<pre>
+
###############################
 +
###  (c) Wiimm, 2015-12-18  ###
 +
###############################
  
 
# Setup
 
# Setup
Line 206: Line 244:
  
 
# Get the value for lowering the walls.
 
# Get the value for lowering the walls.
# If 'lower' is defined as number by option --const, use it.
+
# If 'lower' is defined as number by option --const => use it.
# Otherwise use the default of 50.
+
# Otherwise use the default of 30.
@def lower = isNumeric(lower) ? lower : 50
+
@def lower = isNumeric(lower) ? lower : 30
 +
 
 +
# Limit to walls with inclination <45 degree
 +
# If 'degree' is defined by option --const as number >0 => use it.
 +
# Otherwise use the default of 45 degrees.
 +
@def degree = isNumeric(degree) && degree > 0 ? degree : 45
 +
@def sin_degree = sin(degree)
  
 
# Define a function to test the KCL flag for walls
 
# Define a function to test the KCL flag for walls
Line 219: Line 263:
 
@for t=0;tri$n()-1
 
@for t=0;tri$n()-1
 
     @if isWall(tri$flag(t))
 
     @if isWall(tri$flag(t))
# Is it a wall? If yes, lower the wall & increment counter
+
    @def norm = tri$normal(t,0) #  get the first normal
@def status = tri$shift(t,-vy(lower))
+
    @if abs(norm.y) < sin_degree
@def mod_count = mod_count+1
+
    # it's a vertical wall -> lower the wall & increment counter
 +
    @def status = tri$shift(t,-vy(lower))
 +
    @def mod_count = mod_count+1
 +
@endif
 
     @endif
 
     @endif
 
@endfor
 
@endfor
Line 228: Line 275:
 
@echo "  - " mod_count " of " tri$n() " triangles lowered by " lower
 
@echo "  - " mod_count " of " tri$n() " triangles lowered by " lower
 
> " in " (mSec()-start) " msec."
 
> " in " (mSec()-start) " msec."
 
+
</pre></spoiler>
</pre>
 
 
 
 
To use the script, extend the command with ''--kcl-script lower-walls.txt'':
 
To use the script, extend the command with ''--kcl-script lower-walls.txt'':
 
  wkclt encode course.obj -o --kcl-script lower-walls.txt
 
  wkclt encode course.obj -o --kcl-script lower-walls.txt
  
If you want another value than 50 for lowering the walls, just define the contant 'lower' by setting for example ''--const lower=20''.
+
The default is to lower walls with inclination <45 degree by 30 units. Both values can be changed by the command line using option --const:
  wkclt encode course.obj -o --kcl-script lower-walls.txt --const lower=20
+
  wkclt encode course.obj -o --kcl-script lower-walls.txt --const lower=50,degree=30
  
Lowering the walls is also possible for existing [[KCL]] files. For custom tracks it is a good idea to remove unreferenced triangles ([[#Remove garbage from old KCL files|see above]]) and add ''--kcl drop'' to the command.
+
Lowering the walls is also possible for existing KCL files. For custom tracks it is a good idea to remove unreferenced triangles ([[#Remove garbage from old KCL files|see above]]) and add ''--kcl drop'' to the command.
 
  wkclt encode course.kcl --dest new.kcl --kcl-script lower-walls.txt --kcl drop
 
  wkclt encode course.kcl --dest new.kcl --kcl-script lower-walls.txt --kcl drop
  
Line 244: Line 289:
  
 
== Links ==
 
== Links ==
 
 
* Wiiki articles:
 
* Wiiki articles:
** [[Solidity]] (creating KCL)
 
** [[Custom Track Tutorial]]
 
 
** [[KCL (File Format)]]
 
** [[KCL (File Format)]]
** [[KCL Flag]]s
+
** [[KCL Flag|KCL flags]]
** [[KCL Tutorial (Wiimms Tools)/Script Example]]s
+
** [[Solidity]]
 +
** [[Creating a KCL with Wiimms Tools/Script Example]]s
 
* [[Wiimms SZS Tools]]
 
* [[Wiimms SZS Tools]]
 
** [http://szs.wiimm.de/doc/kcl KCL Guide]
 
** [http://szs.wiimm.de/doc/kcl KCL Guide]
Line 256: Line 299:
 
** [http://szs.wiimm.de/doc/syntax Text Parser Syntax]
 
** [http://szs.wiimm.de/doc/syntax Text Parser Syntax]
 
* [http://en.wikipedia.org/wiki/Wavefront_.obj_file Wavefront OBJ file] (file format)
 
* [http://en.wikipedia.org/wiki/Wavefront_.obj_file Wavefront OBJ file] (file format)
<br/>
 
  
 
=== Footnotes ===
 
=== Footnotes ===
 
<references/>
 
<references/>
 
 
{{Custom Track Tutorial}}
 
{{Custom Track Tutorial}}
[[category:Tutorials]][[category:Custom Track Tutorial]]
+
[[category:Tutorials]]
 +
[[category:Custom Track Tutorial]]
 +
[[Category:Wiimms SZS Tools]]

Latest revision as of 07:38, 30 September 2023

This page is a part of the Custom Track Tutorial. Back to the main tutorial page.

Introduction

Each track needs a collision (KCL) file named course.kcl. This collision file describes how players and items interact with the world. Therefore the collision file contains lists with triangles and an octree based system to find the triangles efficiently while playing. If touching a triangle, its KCL flag is used to determine the action, like boost, wall or fall down.

Normally the KCL triangles are a copy of the 3D world you made with your favorite 3D Tool, but without any textures or color definitions. The KCL world can also have additional planes for invisible borders or for sound and effect triggering. Creation of this model is explained in the Solidity page.

This article describes how to create a KCL file using Wiimms SZS Tools. The new KCL is made from scratch with a maximum of 65535 triangles, the KCL internal limit.

Notes

  • Wiimms SZS Tools are command line tools (CLI). There is no graphical user interface (GUI). The user have to type the commands including options and parameters into a text console or as script (batch file). The results are printed to the text console, if not redirected. → more CLI details.
  • You can use Wiimm's Tool Manager if you're not familiar with CLI.

Create the KCL

The creation of a KCL is done in 3 steps:

  1. Export a collision model with your 3D Tool.
  2. Create a KCL flag assignment file.
  3. Encode (create) the final KCL file.

Create an OBJ file

This step is really easy. Just export your model as OBJ file[1] with your favorite 3D Tool. See »Solidity« for more details. Unfortunately Wiimms SZS Tools do not work well with Blender OBJs so it is recommended to follow the below tutorial to export your model:


The export may contain all groups of the KCL. If any models present in the OBJ are not needed, they can easily filtered by setting KCL flag to -1 in the flag assignment file. Graphics and textures are not needed and ignored by the KCL encoder. If Blender is being used to export the OBJ, the option "Material Groups" needs to be checked in the export settings. This is unchecked by default.

Create a flag assignment file

A flag file should be created by the command wkclt CFF (Create Flag File), which is recommended. The CFF command reads a KCL or an OBJ file and creates a new flag file as template. If the flag file already exists, it is scanned and only new groups are appended at the end of the existing file. A batch file with this script is included in the pack. The file can also be created manually.

The default filename for the flag file is the filename of the OBJ or KCL file with the new extension .flag (»my_track.obj« becomes »my_track.flag«). The old naming extension with .flag.txt is also supported. See option --flag-file for more details.

The flag file contains lines in the format:

object_group_name = flag_value

It is important to prefix each hexadecimal value with '0x', because the file is interpreted by the text parser of Wiimms SZS Tools, which also allows decimal numbers and numerical expressions. If a flag is set to -1, the object group will not be included into the KCL.

Example:

grass_1    = 0x0083
grass_2    = 0x0084
boost      = 0x0006
wall       = 12 + 0x2b20  # numerical expression
decoration = -1           # ignore this group
*          = -1           # ignore all undefined groups

It's no problem to enter your KCL flags separated by type and variant. Just create a function that will calculate the resulting KCL flag for you:

Example:

# First, we define a flag function named f().
# This allows us to define type and variant as 2 values.
@function f # (type,variant)
    @return $1 | $2 << 5
@endfunction

# And now we assign the KCL flags to the group names
grass_1    = f(0x03,0x004)
grass_2    = f(0x04,0x004)
boost      = f(0x06,0x000)
wall       = 0x2b2c        # mixed usage is also possible
decoration = -1            # ignore this group
*          = -1            # ignore all undefined groups

The command wkclt CFF will create a template including the user defined functions f(type,variant), a(type,w,x,y,z) and i(type,z,index). Read »Defining KCL flags« for more details.

Encode the KCL file

The command to create the KCL is:

wkclt encode course.obj --kcl=drop

The file course.flag.txt is read automatically, if it exists. This command creates the file course.kcl, but only, if the file does not exist. The recommended option --kcl=drop is discussed below. To overwrite an existing file, add option --overwrite (or short -o):

wkclt encode course.obj --kcl=drop -o

It is a good idea to write a script (.bat batch file) that contains your creation command with all options. This allows to just click the script to execute the command(s). A batch file with this script is included in the pack.

Windows example:

@echo off
wkclt encode course.obj --kcl=drop -o
pause

There are only some limits while creating the KCL file:

  • The number of triangles can't exceed 65535 (0xFFFF), because the octree use only 16 bits for triangle references and value 0 is reserved as end of list marker.
  • The number of vertex and normal vectors can't exceed 65536 (0x10000) because of the 16 bit limit of indices. This is not a problem for the vertex section, because each triangle use exact 1 vertex vector. But a triangle needs 4 normal references. Therefore the KCL encoder tries to find duplicates of normals and vertex values to reduce the section size.

The new KCL file is always created from scratch. So the new KCL file is garbage free.

Next

If you're generating your KCL file from scratch now and don't need to set anything else, you should be done with it (for now); move on to the KMP Editing tutorial. You can also test your track now to make sure the KCL works, but you might want to at least set a start position in the KMP before that.

Additional/Advanced Info

Option --kcl

The keyword list of option --kcl defines, how the OBJ+KCL processor internally works. There are different options to remove unwanted triangles, to change the vertex order, to define the material mode for OBJ export and much more. All options are explained in Wiimms KCL Guide.

Advanced usage

If you need to scale and/or rotate the KCL, use the options --scale and/or --hrot. Here is an Windows batch file example (filename create-kcl.bat):

@echo off
wkclt encode export.obj -Nod course.kcl --kcl drop,rm-facedown --scale 1.45 --hrot 90
pause

The command wkclt encode ...

  1. reads the file export.obj as source, search the file export.flag for KCL flag assignments.
  2. drops all non regular triangles (--kcl drop).
  3. remove all face down roads (and other drivable faces) (--kcl rm-facedown).
  4. scales the model by factor 1.45 for all 3 dimensions (--scale 1.45).
  5. rotates the model horizontal counterclockwise by 90 degree (--hrot 90).
  6. do not make KCL checks (-N).
  7. stores the result as file course.kcl (-d course.kcl).
  8. overwrites an already existing file named course.kcl (-o).

Ignoring small triangles

Sometimes, the imported file contains very small triangles with an area smaller than 1 unit2. They were accidentally inserted into the model by the user. Because of the small size, the user will not see them in the model view of their 3D Tool. However, machines like the KCL importer of these tools see them and insert them into the KCL — this is not a bug with the tools. The Wii has (mathematical) problems processing them correctly, resulting in KCL glitches like mini walls on the road.

Since v1.58a there are 2 new options: --tri-area=EXPR and --tri-height=EXPR[1] to filter out triangles that are too small.

Option --tri-area=EXPR defines the minimal area size of KCL triangles. The intention is to ignore triangles that are generally too small. EXPR is a floating point number or expression. Triangles are invalidated if their area size is smaller than EXPR. Values between 0.01 and 4.0 are recommended. The careful value 1.0 is used as default. Value 0 disables this filter functionality.

Option --tri-height=EXPR defines the minimal height of KCL triangles. The intention is to ignore deformed triangles (very slim, but long). EXPR is a floating point number or expression. Triangles are invalidated if at least 1 of the 3 heights is smaller than EXPR. Values between 0.01 and 2.0 are recommended. The careful value 1.0 is used as default since v1.58b. Value 0 disables this filter functionality.

The tests for both options are executed after reading files, after transformations, and after calculating normals and lengths.

It is recommended to use v1.58b or later of Wiimm's SZS Tools if creating a KCL.

Examples:

 # set minimal area size to 5.0 and minimal height to 0.5 (=1/2)
 wkclt encode --tri-area 5 --tri-height 1/2 ....

 # patch an existing track with same limits
 wszst patch track.szs --tri-area 5 --tri-height 1/2 --kcl new,drop

Removing garbage from old KCL files

Some older tools create a KCL file, by using an already existing KCL file as base and injecting it with the new data. This has 2 major issues:

  • The limited size of the base KCL limits the number of vertices, normals and triangles and also the size of the octree.
  • The file contains old triangles, that uses any of the overwritten vertices and normals. The results are unreal triangles, sometimes with invalid vertex coordinates. These triangles are ignored by the KCL processing of the Wii, because they are not referenced by the octree. But if exporting or modifying the KCL, the triangles becomes valid with invalid values.

These unreferenced/unused/invalid triangles can be removed by adding --kcl drop to any command.

Examples:

# create a new KCL, drop unneeded triangles
wkclt encode course.kcl --dest new.kcl --kcl drop

# export to an object file, drop unneeded triangles
wkclt decode course.kcl --kcl drop

# short info dump of a kcl file, but ignore unneeded triangles
wkclt db course.kcl --kcl drop

# info dump of a kcl file in a track [[SZS]], but ignore unneeded triangles
wkclt dump mytrack.szs --kcl drop

# show kcl flag statistics of a track file, but ignore unneeded triangles
wkclt flags mytrack.szs --kcl drop

Create a small KCL

The tools accept 3 keywords for option --kcl to control the size of the KCL. The main aspect is, how many faces of the neighborhood should be included into the face list of a cube. The keywords are:

SMALL
Set the parameters to values to get a relative small KCL file. The neighborhood distance is set to 200. Until now not any disadvantage of SMALL was found. But don't use small if you plan a track with speed factor ≥1.5.
MEDIUM
This is the default. It is anywhere in the middle between SMALL and CHARY. The neighborhood distance is set to 400.
CHARY
The parameters are set to Nintendo-like values, that are very careful. This blows up the octree significantly, because of the large neighborhood distance of 600.

Creation of a small KCL may help to reduce the Slow Motion Bug. This is especially true, if the old KCL was made with other tools.

Examples:

wkclt encode course.kcl --kcl small,drop,rm-facedown
wszst patch track.szs --kcl new,small,drop,rm-facedown

Export to OBJ

If you want to make a KCL file visible in a 3D Tool, just export it as OBJ file. For custom tracks it is a good idea to remove unreferenced triangles (see above) and add --kcl drop to the command.

Example:

# decode an obj file
wkclt decode course.kcl --kcl drop

# cat the KCL in OBJ format to a destination
wkclt cat course.kcl --kcl drop >new.obj

# cat the KCL of a track in OBJ format to a destination
wkclt cat track.szs --kcl drop >new.obj

Scripts

If using any of the wkclt commands, the option --kcl-script=filename allows to define a script to manipulate the the KCL data:

  • Remove existing triangles.
  • Add new triangles.
  • Change the positions of triangles.
  • Change the KCL-Flag of triangles.

For the selection of existing triangles, flag, vertex positions, normals and length can be used.

The following sub sections show some examples for popular manipulations. If you want to use more than one of the example scripts, just copy them into one new script file.

Remove face down roads

If roads are defined with face up and face down triangles, a KCL glitch is possible. It is because after jumps the driver can be some pixel below the road. In this case, the face down road becomes active for a short time and vehicle+driver drives in any unwanted direction and the camera view changes rapidly.

In general, there is no need for face down roads. This is also true for all other drivable KCL types like offroad, boost or trick ramp. The following script detects face down drivable triangles (by analyzing the KCL type and the first normal) and removes them:

Script: remove-face-down.txt

To use the script, extend the command with --kcl-script remove-face-down.txt:

wkclt encode course.obj -o --kcl-script remove-face-down.txt

Since v1.02a it is possible to remove the face down roads directly without a script:

wkclt encode course.obj -o --kcl DROP,RM-FACEDOWN

The option --kcl RM-FACEDOWN does the same as the script above. The advantage of the script is the better fine control: The user can select KCL types and/or track areas to remove the triangles. Combine the RM-FACEDOWN option with DROP, so that additionally all invalid and unused triangles are removed.

Lower walls

You know the problem: Jumping over borders is impossible. If hitting the hard walls, you fall down immediately. This is not a problem of Nintendo's tracks and can be solved by lowering the walls about 20–50 units.

If creating the KCL, you can establish a script that can fix the walls. The script lower-walls.txt is part of the distribution and looks like this:

Script: lower-walls.txt

To use the script, extend the command with --kcl-script lower-walls.txt:

wkclt encode course.obj -o --kcl-script lower-walls.txt

The default is to lower walls with inclination <45 degree by 30 units. Both values can be changed by the command line using option --const:

wkclt encode course.obj -o --kcl-script lower-walls.txt --const lower=50,degree=30

Lowering the walls is also possible for existing KCL files. For custom tracks it is a good idea to remove unreferenced triangles (see above) and add --kcl drop to the command.

wkclt encode course.kcl --dest new.kcl --kcl-script lower-walls.txt --kcl drop

With version v0.39 of Wiimms SZS Tools you can also use the COPY command:

wkclt copy course.kcl new.kcl --kcl-script lower-walls.txt --kcl drop

Links

Footnotes