Xmath Usage logo

Xmath Usage

Organization
indiesoftby
xmath-usage

Provides xmath API reference and in-place math optimization patterns for Defold. Use when writing performance-critical math code, optimizing vector/quaternion/matrix operations, or when the user mentions xmath, zero-allocation math, or reducing Lua GC pressure.

Overview

Publisherindiesoftby
Repositorydefold-agent-config
Skill namexmath-usage
Stars
104
Forks
10
Bundled files
Instructions only
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by indiesoftby on GitHub. Read the source before you install it.

Installation

Install the Xmath Usage AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/indiesoftby/defold-agent-config/tree/main/.agents/skills/xmath-usage
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/indiesoftby/defold-agent-config.git /tmp/defold-agent-config
mkdir -p .claude/skills
cp -r /tmp/defold-agent-config/.agents/skills/xmath-usage .claude/skills/xmath-usage
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Xmath Usage in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Xmath Usage on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Xmath Usage is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Using xmath for Zero-Allocation Math in Defold

Prerequisite: Verify xmath Dependency

Before applying any guidance from this skill, you MUST confirm that the project uses xmath. Check the game.project file for a dependency URL containing thejustinwalsh/defold-xmath (e.g. dependencies#N = https://github.com/thejustinwalsh/defold-xmath/archive/...). Alternatively, check for the presence of xmath/ in the .deps/ directory.

If neither an xmath dependency in game.project nor a local xmath module is found, do NOT apply this skill. Inform the user that the project does not use xmath and suggest adding the dependency:

[project]
dependencies#N = https://github.com/thejustinwalsh/defold-xmath/archive/refs/heads/main.zip

Core Concept: In-Place Mutation to Eliminate Heap Allocations

Standard vmath creates a new Lua object on every operation, causing constant GC pressure in hot loops:

lua
-- BAD: vmath allocates 3 new objects every frame
function update(self, dt)
    local v = self.dir * 5 * dt    -- alloc #1
    local pos = go.get_position()  -- alloc #2
    local result = pos + v         -- alloc #3
    go.set_position(result)
end

xmath mutates an existing variable in place — the result is written into the first argument. You allocate once, reuse forever:

lua
-- GOOD: xmath reuses pre-allocated variables, zero allocations per frame
go.property("dir", vmath.vector3(0, 1, 0))

local v = vmath.vector3()  -- allocate ONCE at module scope

function update(self, dt)
    local pos = go.get_position()
    xmath.mul(v, self.dir, 5 * dt)  -- writes into v
    xmath.add(v, pos, v)            -- writes into v
    go.set_position(v)
end

Key Rules

  1. Pre-allocate scratch variables at module scope or in init() — never inside update() or on_message().
  2. The output variable is always the first argument — this is the fundamental calling convention difference from vmath.
  3. Functions return nothing — you cannot chain calls. Use a scratch variable at each step.
  4. Use vmath to create initial objects — vmath.vector3(), vmath.vector4(), vmath.quat(), vmath.matrix4() to allocate scratch buffers, then use xmath to operate on them.
  5. Type polymorphism — functions like xmath.lerp work for vector3, vector4, and quaternion based on the output argument type.

Optimization Pattern

lua
-- Scratch variables — allocated once
local temp_v = vmath.vector3()
local temp_q = vmath.quat()

function update(self, dt)
    -- Instead of: local dir = vmath.normalize(target - pos)
    xmath.sub(temp_v, self.target, self.pos)
    xmath.normalize(temp_v, temp_v)  -- can use same variable as both input and output

    -- Instead of: local rot = vmath.quat_rotation_z(angle)
    xmath.quat_rotation_z(temp_q, self.angle)

    -- Instead of: local rotated = vmath.rotate(rot, dir)
    xmath.rotate(temp_v, temp_q, temp_v)
end

Full API Reference

All functions write the result into the first argument. No return values.

Vector Operations (vector3 / vector4)

FunctionEquivalentDescription
xmath.add(out, v1, v2)out = v1 + v2Add two vectors
xmath.sub(out, v1, v2)out = v1 - v2Subtract two vectors
xmath.mul(out, v, n)out = v * nMultiply vector by scalar
xmath.div(out, v, n)out = v / nDivide vector by scalar
xmath.cross(out, v1, v2)out = cross(v1, v2)Cross product (vector3 only)
xmath.mul_per_elem(out, v1, v2)out.x = v1.x * v2.x, ...Element-wise multiplication
xmath.normalize(out, v)out = normalize(v)Normalize vector
xmath.rotate(out, q, v)out = rotate(q, v)Rotate vector3 by quaternion
xmath.vector(out)out = (0,0,0)Reset to zero vector

Interpolation (vector3 / vector4 / quaternion)

FunctionEquivalentDescription
xmath.lerp(out, t, v1, v2)out = lerp(t, v1, v2)Linear interpolation
xmath.slerp(out, t, v1, v2)out = slerp(t, v1, v2)Spherical interpolation

Quaternion Operations

FunctionDescription
xmath.quat(out)Reset to identity (0, 0, 0, 1)
xmath.conj(out, q)Conjugate of quaternion
xmath.quat_axis_angle(out, axis, angle)Quaternion from axis + angle
xmath.quat_basis(out, x, y, z)Quaternion from 3 basis vectors (vector3)
xmath.quat_from_to(out, v1, v2)Rotation quaternion from v1 to v2
xmath.quat_rotation_x(out, angle)Rotation around X axis
xmath.quat_rotation_y(out, angle)Rotation around Y axis
xmath.quat_rotation_z(out, angle)Rotation around Z axis

Matrix Operations (matrix4)

FunctionDescription
xmath.matrix(out [, m1])Reset to identity or copy from m1
xmath.matrix_axis_angle(out, axis, angle)Rotation matrix from axis + angle
xmath.matrix_from_quat(out, q)Matrix from quaternion
xmath.matrix_frustum(out, left, right, bottom, top, near, far)Frustum projection matrix
xmath.matrix_inv(out, m)Matrix inverse
xmath.matrix_look_at(out, eye, look_at, up)View matrix
xmath.matrix4_orthographic(out, left, right, bottom, top, near, far)Orthographic projection
xmath.matrix_ortho_inv(out, m)Orthographic inverse
xmath.matrix4_perspective(out, fov, aspect, near, far)Perspective projection
xmath.matrix_rotation_x(out, angle)Rotation around X axis
xmath.matrix_rotation_y(out, angle)Rotation around Y axis
xmath.matrix_rotation_z(out, angle)Rotation around Z axis
xmath.matrix_translation(out, position)Translation matrix from vector3/vector4

Frequently asked questions

What does the Xmath Usage AI skill do?

Provides xmath API reference and in-place math optimization patterns for Defold. Use when writing performance-critical math code, optimizing vector/quaternion/matrix operations, or when the user mentions xmath, zero-allocation math, or reducing Lua GC pressure.

Why use Xmath Usage on TypingMind?

Because you install it once and use it with any model. Xmath Usage is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Xmath Usage in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/indiesoftby/defold-agent-config/tree/main/.agents/skills/xmath-usage. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Xmath Usage?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Xmath Usage?

As many as you like. As long as a model supports skills, you can use Xmath Usage with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Xmath Usage AI skill free?

It is published on GitHub by indiesoftby. Check the repository for licensing terms. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇