GitHubGet started

package mcp3d

import "github.com/nsgo-dev/game/pkg/mcp/mcp3d"

Overview

Package mcp3d is experimental: its API and documented formats may change in a minor release. See the API stability policy.

Package mcp3d defines optional serializable records and a provider contract for inspecting a running 3D scene over MCP: nodes, the active camera and raycast hits. It imports no renderer, scene3d or physics3d package, so pkg/mcp stays free of 3D code and the game keeps ownership of rendering and physics. Package game/mcp registers the game3d_* tools over a Provider set as mcp.Config.ThreeD.

Index

Variables

var ErrNotFound = errors.New("mcp3d: node not found")

ErrNotFound reports that no node has the requested path.

Types

type Camera struct {
	Position   Vec3    `json:"position"`
	Forward    Vec3    `json:"forward"`
	Projection string  `json:"projection"`
	FOV        float32 `json:"fov,omitempty"`
}

Camera is the active camera's pose and projection. Projection is "perspective" or "orthographic"; FOV is the vertical field of view in degrees for a perspective camera.

type Hit struct {
	NodePath string  `json:"nodePath"`
	Point    Vec3    `json:"point"`
	Normal   Vec3    `json:"normal"`
	Distance float32 `json:"distance"`
}

Hit is the nearest node a ray hits, with the world-space hit point and surface normal and the distance along the ray.

type Node struct {
	Path      string `json:"path"`
	Kind      string `json:"kind,omitempty"`
	Name      string `json:"name,omitempty"`
	Position  Vec3   `json:"position"`
	Scale     Vec3   `json:"scale"`
	BoundsMin Vec3   `json:"boundsMin"`
	BoundsMax Vec3   `json:"boundsMax"`
	Model     string `json:"model,omitempty"`
	Material  string `json:"material,omitempty"`
}

Node is one node of the 3D scene graph. Path is unique within the scene; BoundsMin and BoundsMax are the node's world-space axis-aligned bounds, and Model and Material name the assets it draws with, if any.

func Find(nodes []Node, path string) (Node, error)

Find returns the node whose path equals path, or ErrNotFound.

type Provider interface {
	Nodes() []Node
	Camera() Camera
	Raycast(origin, direction Vec3) (Hit, bool)
}

Provider is implemented by the game over its own scene, camera and physics. Raycast reports false when the ray hits nothing.

type Vec3 struct {
	X float32 `json:"x"`
	Y float32 `json:"y"`
	Z float32 `json:"z"`
}

Vec3 is a position, direction or scale in world space.