Skip to content

Using the library (Coding)

KillzXGaming edited this page Sep 2, 2021 · 11 revisions

Required references.

KclLibrary.dll
System.Numerics.dll
Syroot.BinaryData.dll (in project folder)
Syroot.Maths.dll (in project folder)
BymlExt.dll (in project folder, only needs for .byml usage that can store attribute info)

Namespaces:

using KclLibrary;
using System.Numerics;

Loading a new KCL file and also saving it.

KCLFile kclFile = new KCLFile("map.kcl");
kclFile.Save("savedMap.kcl");

Changing platform byte order (little endian for Switch, big endian for Wii U)

KCLFile kcl = new KCLFile("map.kcl");
kcl.ByteOrder = ByteOrder.LittleEndian;
kcl.Save("mapSwitch.kcl");

Turning it into a .obj

KCLFile kclFile = new KCLFile("map.kcl");
ObjModel obj = kclFile.CreateGenericModel();
obj.Save("map.obj");

Loading vertex information.

KCLFile kclFile = new KCLFile("map.kcl");
foreach (var model in kclFile.Models) {
    foreach (var Prism in model.Prisms) {
        //Stores 3 vertex positions and a normal
        Triangle triangle = model.GetTriangle(Prism);

        Vector3 positionA = triangle.Vertices[0];
        Vector3 positionB = triangle.Vertices[1];
        Vector3 positionC = triangle.Vertices[1];
        Vector3 normal = triangle.Normal;

        //The material flag
        ushort materialAttribute = Prism.CollisionFlags;
    }
}

Creating a new KCL from a .obj.

ObjModel obj = new ObjModel("map.obj");
//Customized settings for generating a collision.
//Settings can vary between games.
var settings = new CollisionImportSettings()
{
	//Octree Settings
	PaddingMax = new System.Numerics.Vector3(1, 1, 1),
	PaddingMin = new System.Numerics.Vector3(-1, -1, -1),
	MaxRootSize = 1024,
	MinRootSize = 128,
	MinCubeSize = 128,
	MaxTrianglesInCube = 50,
	//Model Settings
	PrismThickness = 1,
};

//Turn the .obj file into triangles used to make a collision file.
//FileVersion determines the version.
//GC is Gamecube
//Wii for Wii
//DS for Nintendo DS
//3DS for Nintendo 3DS
//Version 2 for Wii U and Switch.
//The boolean configures big endian or little endian.
//Settings configure specific settings for generating the collision.

KCLFile kclFile = new KCLFile(obj.ToTriangles(), FileVersion.VersionGC, true, settings);
kclFile.Save("gamecubeCol.kcl");

Checking point hits. Returns the hit prism. (WIP)

KCLFile kclFile = new KCLFile("map.kcl");
var collisionHit = kclFile.CheckHit(new Vector3(10, 200.15f, 40.0f));
//Stores Prism and distance info
var Prism = collisionHit.Prism;
var dist = collisionHit.Distance;
Clone this wiki locally