Jump to content

Help me understand the KAnim format


Recommended Posts

Hi,

I'm trying to understand the KAnim format, and how to use and draw things using it, but I feel like I'm missing some information. Here is what I've managed to reverse engineer so far :

For example, let's say I'm trying to draw the placement art for the hydrogen generator on a 4x3 grid. Here is what I am doing so far :

  • Going into the prefab "HydrogenGenerator", then into the anim file "generatormerc_kanim"
  • I find the Anim named "place", the firstFrameIdx for this animation is frame 139
  • Inside this frame there is only one FrameElement, the firstElementIdx is 1927
  • This FrameElement gives me a Symbol name ("place"), as well as a frame to use for this Symbol
  • Looking in the Build for generatormerc_kanim, the frameLookup 0 of symbol "place" is frame 19)

This frame gives me UV information, as well as two bounding boxes, bboxMin and bboxMax. The UV information gives me this wonderful piece of art :

hydrogen place

The information inside the build gives me to bounding boxes which I don't know how to use yet, other than noting they look similar to the size of the texture :

	"bboxMin": {
		"x": -418.025,
		"y": -312.025
	},
	"bboxMax": {
		"x": 417.975,
		"y": 311.975
	}

 

The Frame gives me two bounding box information, I don't know what to do with these yet :

              "bboxMin": {
                "x": -1.99924994,
                "y": -0.09475006,
                "z": 0.0
              },
              "bboxMax": {
                "x": 2.0305,
                "y": 2.87149978,
                "z": 0.0
              },

 

The FrameElement gives me a transform Matrix, which is just a simple (3.15, -277.65) translation.

	"transform": {
		"m00": 1.0,
		"m01": 0.0,
		"m02": 3.15,
		"m10": 0.0,
		"m11": 1.0,
		"m12": -277.65
	},

 

Now I do have a lot of questions about this, specifically how to draw these on a grid like the game does. In game, the artwork for buildings will often be a bit bigger or smaller than the size they take on the grid, so I can't just fill my 4x3 grid with the placement texture for the hydrogen generator, or it will look weird. It seems that the transform matrix in the FrameElement should help me with that, but I don't know what the unit should be?

 

Drawing utilities is also a headache. For example, following the same path and trying to draw the "Left Right Down" connections for "WireRefinedHighWattage", I get these pieces of art :

electricoutline

Again, I'd like to draw these on a grid, and it seems like the transform, and the bouding boxes should be useful there. My hunch is that the unit for the transforms and the bounding boxes is 100 per grid square, but I can't quite seem to figure it out on my own...

Bounding box from the Build for the first image :

	  "bboxMin": {
		"x": -117.575,
		"y": -53.525
	  },
	  "bboxMax": {
		"x": 118.425,
		"y": 118.475
	  }

Thank you for your help !

Link to comment
Share on other sites

All right, so I'm still trying to drawn KAnims on "grid", so I did some tests and arrived at a partial solution, but there are still some problems.

What I am doing so far is this :

1) Applying the rotation and scaling contained in the FrameElement transform

2) Applying the following translation :

translation.x = transform.m02 / 2 + bboxMin.x / 2 + realsize.x / 2
translation.y = transform.m12 / 2 + bboxMin.y / 2 + realsize.y

In the above code, "transform" is the transform matrix from the FrameElement, bboxMin is the bounding box for this symbol (in the build), and realsize is the size of what I am trying to draw in cells x 100. (so a Pipe will be 100x100, a door will be 100x200, an electrolyzer will be 200x200, etc)

This seems to be working fairly well in most cases. For example, here are some doors, an AirFilter, an Electrolyzer, a RustDeoxidizer, and some bridges drawn on grid :

KcDdva3.png

The colored rectangles in this picture are a debug tool to show where the building should be drawn. The buildings are correctly drawn, the bridges align with the grid in the same position they are in game, even in edge cases like the high wattage bridge, where the building is actually 1x1, but the sprite extends to a 3x1 space.

However, this only works when the transform Matrix from the frame element has no rotation or scale. If the scale part of the matrix is a negative 1 of the x or y axis, everything breaks down. For example, in the game file, the placement art for the CO2 scrubber is actually upside down, and the matrix inside the FrameElement compensates for this by applying à -1 scale on the Y axis. Same thing for the gantry, the placement art is mirrored left-right, and the transform has a -1 scale on the X axis.

Here is what happens when I try to draw these using my method (ManualGenerator included for comparison):

uBgCohn.png

The sprite are correctly scaled (ie the CO2 scrubber is not upside down), but they are not drawn where they are supposed to. (Again, the color rectangles show where the buidlings should appear)

Below are the bbox and transform value for each object :

ManualGenerator
"transform":{"m00":1,"m01":0,"m02":-28.55,"m10":0,"m11":1,"m12":6.2}
"spritebboxMin":{"x":-230.575,"y":-436.5}
"spritebboxMax":{"x":257.425,"y":11.5}

CO2Scrubber
"transform":{"m00":1,"m01":0,"m02":-0.1,"m10":0,"m11":-1,"m12":-394.3}
"spritebboxMin":{"x":-224,"y":-417.35}
"spritebboxMax":{"x":224,"y":26.6499939}

Gantry
"transform":{"m00":-1,"m01":0,"m02":87.95,"m10":0,"m11":1,"m12":25.05}
"spritebboxMin":{"x":-544.75,"y":-466.275}
"spritebboxMax":{"x":739.25,"y":13.7250061}

 

The same issue appears when trying to draw utility pipes, which rely heavily on the FrameElement transform :

xSUZE9I.png

On the left, the Left-Right-Down connection seems fine, because the sprite is not scaled or rotated. On the right (Left-Right-Up connection), the central sprite is mirrored on the Y axis, and there is a noticeable disconnect between the pipes, the sprite does not fit neatly into the grid square. Transforms for these two below :

LRD
"transform":{"m00":1,"m01":0,"m02":-0.55,"m10":0,"m11":1,"m12":-102}
"spritebboxMin":{"x":-119.075,"y":-70.5}
"spritebboxMax":{"x":120.925,"y":129.5}

LRU
"transform":{"m00":1,"m01":0,"m02":0.35,"m10":0,"m11":-1,"m12":-99.2}
"spritebboxMin":{"x":-119.65,"y":-69.5}
"spritebboxMax":{"x":120.35,"y":126.5}

 

Some things I am not clear on :

There is a bboxMin and bboxMax for the frame itself. Are those values used at all when drawing the sprite (I don't currently)?

The rotation / scaling matrix is confusing to me. I'm not sure where the "pivot" for the matrix should be, what translations should be applied before using that matrix if any, ...

If anybody is familiar with the Kanim drawing process, (or the Spriter one since there seems to be a conversion possible between them), or if someone can point me to a place in the source code where I could look for answers, that would be great.

Thank you !

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...