Skip to main content

Asset

Library for reading assets of all types from the filesystem.

Functions

Asset.loadModel

Loads a 3D model at the given path from the virtual filesystem.

The given path should not contain a file extension, as this is determined automatically from a list of supported formats:

  • .glb - Binary glTF
  • .gltf - Text glTF
  • .mdl - Source Engine MDL
Asset.loadModel(path: string): Asset3d

Parameters

NameTypeDefault ValueDescription
pathstringRequiredPath to the model in the VFS, minus an extension.

Returns

NameTypeDescription
assetAsset3dThe loaded asset.

Asset.loadMap

Loads a map at the given path from the virtual filesystem.

The given path should not contain a file extension, as this is determined automatically from a list of supported formats:

  • .bsp - Source Engine BSP
Asset.loadMap(path: string): Map

Parameters

NameTypeDefault ValueDescription
pathstringRequiredPath to the map in the VFS, minus an extension.

Returns

NameTypeDescription
assetMapThe loaded asset.

Types

Asset3dRigidBody

Internal structure of Asset3d describing the physics motion of a node.

type Asset3dRigidBody = { isStatic: boolean }

Properties

FieldTypeDescription
isStaticbooleanWhether this rigid-body is static (generates collisions but cannot move).

Asset3dNode

Internal structure of Asset3d which can be considered 1:1 with TASBox entities.

type Asset3dNode = { isRoot: boolean, shouldPrune: boolean, name: string, children: number[], position: vector, orientation: Quaternion, scale: vector, rigidBody: Asset3dRigidBody?, colliderIndex: number?, meshIndex: number?, skeletonIndex: number? }

Properties

FieldTypeDescription
isRootbooleanWhether this node is at the root of the hierarchy (i.e. has no parent).
shouldPrunebooleanWhether this node should be discarded when loading (i.e. should not create an entity).
namestringOptional display name for the entity.
childrennumber[]Indices of this node's children in the asset's nodes array.
positionvectorPosition of this node relative to its parent.
orientationQuaternionOrientation of this node relative to its parent.
scalevectorScale of this node relative to its parent.
rigidBodyAsset3dRigidBody?Optional rigid-body motion for this node.
colliderIndexnumber?Optional index of a physics collider to attach to this node.
meshIndexnumber?Optional index of a mesh to attach to this node.
skeletonIndexnumber?Optional index of a skeleton to attach to this node.

Asset3dInverseBindPose

Internal structure of Asset3d describing the inverse bind pose of a bone.

type Asset3dInverseBindPose = { position: vector, orientation: Quaternion }

Properties

FieldTypeDescription
positionvectorNo description
orientationQuaternionNo description

Asset3dBone

Internal structure of Asset3d describing the bone of a skeleton.

type Asset3dBone = { nodeIndex: number, inverseBindPose: Asset3dInverseBindPose }

Properties

FieldTypeDescription
nodeIndexnumberIndex of the bone's node in the asset's node array.
inverseBindPoseAsset3dInverseBindPoseInverse bind pose of the bone used for pre-transforming the mesh during skinning.

Asset3dSkeleton

Internal structure of Asset3d listing nodes to use as bone positions for skinned meshes.

type Asset3dSkeleton = { bones: Asset3dBone }

Properties

FieldTypeDescription
bonesAsset3dBoneList of bones which skinned meshes that reference this skeleton index into.

Asset3dArticulationLimit

Internal structure of Asset3d describing a limit on a single degree of freedom of an articulation link's constraint.

type Asset3dArticulationLimit = { min: number, max: number, isFixed: boolean }

Properties

FieldTypeDescription
minnumberMinimum rotation about this degree of freedom in radians.
maxnumberMaximum rotation about this degree of freedom in radians.
isFixedbooleanWhether the limit is fixed (min and max are within a small tolerance).

Asset3dArticulationLimits

Internal structure of Asset3d describing the limits of an articulation link's constraint.

type Asset3dArticulationLimits = { angularX: Asset3dArticulationLimit, angularY: Asset3dArticulationLimit, angularZ: Asset3dArticulationLimit, jointType: JointType }

Properties

FieldTypeDescription
angularXAsset3dArticulationLimitLimit on rotation about the joint's local X axis (in radians).
angularYAsset3dArticulationLimitLimit on rotation about the joint's local Y axis (in radians).
angularZAsset3dArticulationLimitLimit on rotation about the joint's local Z axis (in radians).
jointTypeJointTypeJoint type with the minimum number of degrees of freedom for these limits.

Asset3dArticulationConstraint

Internal structure of Asset3d describing the constraint formed by an articulation link.

type Asset3dArticulationConstraint = { limits: Asset3dArticulationLimits }

Properties

FieldTypeDescription
limitsAsset3dArticulationLimitsLimits of the constraint about each degree of freedom.

Internal structure of Asset3d describing a link between two nodes in an articulation.

type Asset3dArticulationLink = { parentNodeIndex: number, childNodeIndex: number, constraint: Asset3dArticulationConstraint }

Properties

FieldTypeDescription
parentNodeIndexnumberIndex of the link's parent in the asset's node array.
childNodeIndexnumberIndex of the link's child in the asset's node array.
constraintAsset3dArticulationConstraintDetails about the constraint between the parent and child nodes.

Asset3dArticulation

Internal structure of Asset3d describing a physics reduced coordinate articulation.

type Asset3dArticulation = { rootNodeIndex: number, links: Asset3dArticulationLink[] }

Properties

FieldTypeDescription
rootNodeIndexnumberIndex of the articulation root in the asset's node array.
linksAsset3dArticulationLink[]Links between nodes in the articulation.

Asset3dCollider

Internal structure of Asset3d describing a geometry with mass properties.

type Asset3dCollider = { geometry: PhysicsGeometry, mass: number, centreOfMass: vector }

Properties

FieldTypeDescription
geometryPhysicsGeometryNo description
massnumberNo description
centreOfMassvectorNo description

Asset3d

A 3D model or prefab containing materials, meshes, physics objects and more. Roughly follows the glTF structure.

type Asset3d = { nodes: Asset3dNode[], skeletons: Asset3dSkeleton[], articulations: Asset3dArticulation[], colliders: Asset3dCollider[], meshes: Mesh[], materials: Material[] }

Properties

FieldTypeDescription
nodesAsset3dNode[]Primary structure of the asset, defining a hierarchy of nodes (which can be considered 1:1 with entities).
skeletonsAsset3dSkeleton[]Visual skeletons referenced by skinned mesh nodes.
articulationsAsset3dArticulation[]Physics articulations joining nodes together into a single reduced coordinate system for simulation stability.
collidersAsset3dCollider[]Physics colliders comprised of geometry and mass properties.
meshesMesh[]Visual meshes referenced by nodes.
materialsMaterial[]Visual materials referenced by meshes.

MapEntity

Internal structure of Map representing properties of an entity to spawn.

type MapEntity = { position: vector, orientation: Quaternion, asset: Asset3d }

Properties

FieldTypeDescription
positionvectorPosition of the entity in world space.
orientationQuaternionOrientation of the entity in world space.
assetAsset3dOptional asset to spawn at the entity's position and orientation.

Map

A map containing many entities.

type Map = { entities: MapEntity[] }

Properties

FieldTypeDescription
entitiesMapEntity[]List of entities in the map.