Xmath Usageのロゴ

Xmath Usage

組織
indiesoftby
xmath-usage

Defold向けのxmath APIリファレンスと、インプレースでの数値計算の最適化パターンを提供します。パフォーマンスが重要な数値計算コードの作成、ベクトル・クォータニオン・行列演算の最適化、またはユーザーがxmath、ゼロアロケーションの数値計算、Lua GC負荷の削減に言及した場合に使用してください。

Add to TypingMind

概要

公開者indiesoftby
リポジトリdefold-agent-config
スキル名xmath-usage
スター
104
フォーク
10
同梱ファイル
指示のみ
リンク
  • Markdown形式の指示

    モデルが必要に応じて読み込むSKILL.mdファイルです。関連するリクエストがあったときだけトークンを消費します。

  • どのLLMでも利用可能

    AIスキルはプロバイダー固有のコードではなく、通常のMarkdownなので、GPT、Claude、Gemini、Grok、ローカルモデルで利用できます。

  • 指示だけで完結

    モデルに必要なものはすべて指示に含まれているため、別途同期するファイルはありません。

  • オープンソース

    indiesoftbyがGitHubで公開しています。インストールする前にソースを確認してください。

インストール

AIスキル「Xmath Usage」をTypingMindにインストールすれば、どのLLMでも利用できます。SKILL.mdを読み取れる別のAIエージェントに追加することもできます。

1

TypingMindにインストール

TypingMindはGitHubフォルダから直接スキルをインストールします。SKILL.mdを読み取り、リソースファイルをまとめてローカルに保存します。

  1. アプリを開き、「プラグイン」→「スキル」に移動します。
  2. 「GitHubからインストール」を選択します。
  3. 以下のスキルフォルダのURLを貼り付けて確定します。
    https://github.com/indiesoftby/defold-agent-config/tree/main/.agents/skills/xmath-usage
  4. スキルを利用したいチャットごとに、そのスキルを有効にしてください。
「プラグイン」→「スキル」→「スキルを追加」→「GitHubのURLから」を選択し、フォルダのURLを貼り付けて「続行」を押します。
2

別のAIエージェントにインストール

Agent Skills形式を読み取れるAIエージェントなら、このスキルを利用できます。フォルダをそのAIエージェントのスキルディレクトリにコピーしてください。

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
コピー後、新しいスキルを読み込むためにClaude Codeを再起動してください。

TypingMindで使用

TypingMindのチャットでXmath Usageを有効にするだけで、あとはモデルが対応します。名前と説明がシステムプロンプトに含まれ、関連するリクエストがあると、モデルが指示の全文を自動で読み込みます。手動で呼び出す必要はなく、実際に使用されるまでトークンを消費しません。

関連するリクエストがあるとすぐに、モデルが自動的にXmath Usageを読み込みます。

どのAIモデルでも利用可能

AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、Xmath Usageは作成時に想定されたモデルに縛られません。TypingMindに一度インストールすれば、ご自身のAPIキーを使って、GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama、またはご自身で実行するローカルモデルで利用できます。

  • 必要なときだけ読み込み

    システムプロンプトには名前と説明だけが含まれます。関連するリクエストが初めてあったときに指示を取得するため、スキルを使わない間は指示の読み込みにトークンを消費しません。

  • チャットの途中でモデルを切り替え

    スキルはコードではなく指示なので、モデルを切り替えてもそのまま使えます。次のモデルも同じSKILL.mdを読み込みます。

スキルの指示

モデルが読み込むSKILL.mdの内容です。スキルはモデルが従う指示なので、インストールする前に確認してください。

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

よくある質問

AIスキル「Xmath Usage」では何ができますか?

Defold向けのxmath APIリファレンスと、インプレースでの数値計算の最適化パターンを提供します。パフォーマンスが重要な数値計算コードの作成、ベクトル・クォータニオン・行列演算の最適化、またはユーザーがxmath、ゼロアロケーションの数値計算、Lua GC負荷の削減に言及した場合に使用してください。

TypingMindでXmath Usageを使うメリットは何ですか?

一度インストールすれば、どのモデルでも使えるからです。Xmath Usageはプロバイダー固有のコードではなく、通常のMarkdownで記述されているため、同じスキルをGPT-5、Claude、Gemini、Grok、ローカルモデルで利用できます。チャットの途中でモデルを切り替えても、そのまま使い続けられます。TypingMindは自分のAPIキーで動作するため、シート単位のサブスクリプションではなく、プロバイダーに直接料金を支払います。スキルとチャットは自分のストレージに保持されます。

TypingMindにXmath Usageをインストールするにはどうすればよいですか?

TypingMindで「プラグイン」→「スキル」→「GitHubからインストール」を開き、https://github.com/indiesoftby/defold-agent-config/tree/main/.agents/skills/xmath-usageを貼り付けてください。TypingMindがSKILL.mdを読み込み、チャットごとに有効にできるスキルとしてインストールします。

Xmath Usageを使えるAIモデルはどれですか?

TypingMindに接続したどのモデルでも利用できます。AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、GPT、Claude、Gemini、Grok、ローカルモデルのいずれも、リクエストの内容がこのスキルの用途に合ったときに、このスキルを読み込めます。

Xmath Usageで使えるAIモデルの数に制限はありますか?

数に制限はありません。スキルに対応したモデルであれば、GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llamaなど、どのモデルでもXmath Usageを利用できます。すべてTypingMind上で、自分のAPIキーを使って利用できます。

AIスキル「Xmath Usage」は無料ですか?

indiesoftbyがGitHubで公開しています。ライセンス条件はリポジトリでご確認ください。ご利用のAIプロバイダーに支払うのは、使用したトークンの料金だけです。

AIスキルとは何ですか?

AIスキルは、特定のタスクの実行方法をAIモデルに教える、再利用可能な指示のセットです。オープンなAgent Skills形式に従い、名前と説明を含むSKILL.mdファイルに加え、モデルが必要とするスクリプト、テンプレート、参照ファイルで構成されます。モデルはリクエストがスキルに合致したときだけ指示を読み込むため、インストール済みのスキルも、使うまでは費用がかかりません。

AIスキルは、プラグインやMCPサーバーとどう違いますか?

プラグインやMCPサーバーは、モデルが呼び出せる新しいツールを提供します。ツールとは、どこかで実行され、結果を返すコードです。一方、AIスキルは、タスクへの取り組み方、従うべき手順、望ましい出力の例といった知識や進め方をモデルに伝えます。スキルは通常のMarkdownで記述されているため、サーバー、APIキー、実行環境は不要で、どのモデルでも利用できます。

すべて見る

今すぐ自分専用のAIワークスペースを作成

ニュースレターに登録すると、新機能や今後のプレゼント企画のお知らせが届きます👇