physics

package
v0.1.117 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 28, 2026 License: MIT Imports: 5 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package physics reads the collision shapes of a Source 2 model's PHYS block, a map's world_physics model included, as triangles in model space with the collision attribute that says what each shape blocks.

A model's physics is a list of parts, each with spheres, capsules, convex hulls and triangle meshes. A compiled map packs most of its world into compound shapes, each a bundle of hulls, meshes and capsules under one attribute. Shapes streams them all, one shape at a time, so a map's tens of thousands of hulls never sit in memory at once.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Attribute

type Attribute struct {
	Group        string
	InteractAs   []string
	InteractWith []string
	Exclude      []string
}

Attribute is a collision attribute: the collision group a shape belongs to and the interaction layers it is, collides with, and ignores, as the game names them, such as "solid", "blocklos" or "Citadel_Bullet".

type Physics

type Physics struct {
	// contains filtered or unexported fields
}

Physics is a decoded PHYS block.

func Read

func Read(blocks []resource.Block) (*Physics, error)

Read decodes the PHYS block of a compiled model's blocks.

func (*Physics) Attributes

func (p *Physics) Attributes() []Attribute

Attributes returns the collision attributes shapes refer to.

func (*Physics) Shapes

func (p *Physics) Shapes(fn func(Shape)) int

Shapes calls fn with each shape of every part, compounds included, and returns how many it passed. A shape it cannot read is left out. fn may keep the shape; Shapes builds a new one for each call.

type Shape

type Shape struct {
	Attribute int
	Solid     bool
	Points    []Vec3
	Triangles [][3]uint32
}

Shape is one collision shape as triangles: its points, placed by its part's bind pose, and triangles as three indices into Points. Attribute indexes Physics.Attributes, or is -1 when the shape names none. Solid is true for a closed convex volume, a sphere, capsule or hull, and false for a triangle mesh, which may be open, such as terrain.

type Vec3

type Vec3 [3]float64

Vec3 is a point or direction in model space.

func (Vec3) Add

func (a Vec3) Add(b Vec3) Vec3

Add returns a + b.

func (Vec3) Cross

func (a Vec3) Cross(b Vec3) Vec3

Cross returns a × b.

func (Vec3) Dot

func (a Vec3) Dot(b Vec3) float64

Dot returns a · b.

func (Vec3) Length

func (a Vec3) Length() float64

Length returns a's length.

func (Vec3) Scale

func (a Vec3) Scale(s float64) Vec3

Scale returns a times s.

func (Vec3) Sub

func (a Vec3) Sub(b Vec3) Vec3

Sub returns a - b.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL