rhodonite
    Preparing search index...

    Class SkeletalComponent

    SkeletalComponent manages skeletal animation for entities. This component handles bone transformations, joint matrices, and skinning calculations for 3D models with skeletal animation systems.

    Hierarchy (View Summary)

    Index
    • Creates a new SkeletalComponent instance. Initializes the component with skeletal animation capabilities and reserves global data resources.

      Parameters

      • engine: Engine

        The engine instance

      • entityUid: number

        The unique identifier of the entity this component belongs to

      • componentSid: number

        The component's system identifier

      • entityRepository: EntityRepository

        The repository managing entities

      • isReUse: boolean

        Whether this component is being reused from a pool

      Returns SkeletalComponent

    __currentProcessStage: ProcessStageEnum = ProcessStage.Load
    __engine: Engine
    __entityRepository: EntityRepository

    the instance of EntityRepository

    __entityUid: number

    the entity unique Id which this component belongs to

    __isReUse: boolean = false
    __memoryManager: MemoryManager

    the instance of MemoryManager

    _bindShapeMatrix?: Matrix44
    _isAlive: boolean = true
    _isCulled: boolean = false
    _jointIndices: number[] = []
    _tags: RnTags = {}

    Collection of tags associated with this object

    isSkinning: boolean = true
    topOfJointsHierarchy?: SceneGraphComponent
    _processStages: ProcessStageEnum[] = ...
    _variableLengthLocationRadix: 65536

    The radix used to split the location of a variable-length array member into two floats (location = x * radix + y), so that both are exactly representable as 32-bit floats.

    currentMaxObjectCount: number = 0

    Current maximum object count for UID generation

    InvalidObjectUID: -1

    Invalid object UID constant

    • get _componentMemoryRegistry(): ComponentMemoryRegistry

      Gets the ComponentMemoryRegistry for this component's engine.

      Returns ComponentMemoryRegistry

    • get boneDataArray(): TypedArray

      Gets the GPU bone data array of all joints. The layout depends on the bone data type (see the boneDataType getter).

      Returns TypedArray

      The Float32Array containing the bone data

    • get boneDataInfo(): MutableVector4

      Gets the bone data info (xyz: translation dequantization factors for Vec4x1, w: bone data type index).

      Returns MutableVector4

      The bone data info vector

    • get boneDataType(): EnumIO

      Gets the effective bone data type of this component. If Config.boneDataType is set, it overrides the bone data type of each component.

      Returns EnumIO

      The effective bone data type

    • get componentSID(): number

      Gets the Scoped ID of this Component instance. The SID is unique within the component type and represents the instance index.

      Returns number

      The component scoped ID

    • get componentTID(): number

      Gets the component type identifier for this instance.

      Returns number

      The component type identifier

    • get currentProcessStage(): ProcessStageEnum

      Gets the current process stage of the component. This determines which update methods are currently being called.

      Returns ProcessStageEnum

      The current process stage

    • get entity(): ISkeletalEntity

      Gets the entity that owns this component.

      Returns ISkeletalEntity

      The entity with skeletal capabilities that has this component

    • get entityUID(): number

      Gets the unique ID of the entity that owns this component.

      Returns number

      The entity unique ID

    • get isJointGizmosVisible(): boolean

      Gets the visibility state of the joint gizmo.

      Returns boolean

      True if the joint gizmo is visible, false otherwise

    • set isJointGizmosVisible(flg: boolean): void

      Sets the visibility of the joint gizmo that visualizes skeletal joints.

      Parameters

      • flg: boolean

        True to show the joint gizmo, false to hide it

      Returns void

    • get isWorldMatrixUpdated(): boolean

      Checks if the world matrix has been updated from its initial state.

      Returns boolean

      True if the world matrix has been modified, false otherwise

    • get jointMatrices(): number[] | undefined

      Gets the computed joint matrices array.

      Returns number[] | undefined

      The joint matrices array

    • get objectUID(): number

      Gets the unique object identifier

      Returns number

      The object's UID

    • get rootJointWorldMatrixInner(): MutableMatrix44 | undefined

      Gets the world matrix of the root joint in the hierarchy.

      Returns MutableMatrix44 | undefined

      The world matrix of the top joint, or undefined if no top joint exists

    • get uniqueName(): string

      Gets the unique name of this object

      Returns string

      The unique name string

    • get worldMatrix(): MutableMatrix44

      Gets a copy of the world matrix.

      Returns MutableMatrix44

      A cloned copy of the world matrix

    • get worldMatrixInner(): MutableMatrix44

      Gets the internal world matrix (direct reference).

      Returns MutableMatrix44

      The internal world matrix

    • get componentTID(): 10

      Gets the static component type identifier for SkeletalComponent.

      Returns 10

      The component type identifier

    • Internal

      Copies tag data from another RnObject instance to this object

      Parameters

      • rnObject: RnObject

        The source RnObject to copy tags from

      Returns void

    • Protected

      Destroys this component and cleans up resources.

      Returns void

    • Returns the per-instance array length of the bone data for memory allocation.

      Parameters

      • memberName: string

        The name of the member field

      Returns number | undefined

      The array length, or undefined for other members

    • Protected

      Performs a shallow copy from another SkeletalComponent. Copies all relevant skeletal data without deep cloning complex objects.

      Parameters

      • component_: Component

        The source component to copy from

      Returns void

    • Performs the logic update for skeletal animation. Calculates joint transformations and updates bone data arrays based on the configured bone data type. This method is called during the Logic processing stage.

      This method implements a two-level optimization for VRM models with shared skeleton:

      SkeletalComponents with the same joint structure and animation state share skinning results. The first SkeletalComponent ("leader") computes skinning, others reuse the cached result.

      When skinning cache hits, we track the joint EntityUIDs. In the next frame, AnimationComponent can early return for these joints, skipping animation calculations.

      Key concepts:

      • Leader: The SkeletalComponent that computes skinning (cache miss)
      • Follower: SkeletalComponents that reuse skinning cache (cache hit)
      • Leader Joints: Joints belonging to leaders - these MUST continue animating
      • Cached Entity UIDs: Follower joints that can skip animation in the next frame

      The leader's joints are protected (__leaderJointEntityUIDs) to ensure animation continues. Only follower joints are registered for early return (__currentFrameCachedEntityUIDs).

      Returns void

    • Gets the inverse bind matrices accessor.

      Returns Accessor | undefined

      The accessor containing inverse bind matrices, or undefined if not set

    • Gets a copy of the joints array.

      Returns SceneGraphComponent[]

      A copy of the SceneGraphComponents representing the joints

    • Retrieves a complete tag object (name and value) for the specified tag name

      Parameters

      • tagName: string

        The name of the tag to retrieve

      Returns Tag

      A Tag object containing the name and value

    • Retrieves the value associated with a specific tag name

      Parameters

      • tagName: string

        The name of the tag whose value to retrieve

      Returns any

      The tag value, or undefined if the tag doesn't exist

    • Checks whether this object has a tag with the specified name

      Parameters

      • tagName: string

        The name of the tag to check for

      Returns boolean

      True if the tag exists (value is not null/undefined), false otherwise

    • Checks whether the specified ProcessStage method exists in this Component instance. This is used to determine if this component can handle a particular process stage.

      Parameters

      Returns boolean

      True if the method exists, false otherwise

    • Checks if this object has a tag with the specified name and value

      Parameters

      • tagName: string

        The tag name to match

      • tagValue: string

        The tag value to match

      Returns boolean

      True if the object has a matching tag, false otherwise

    • Checks if this object has all the specified tags with exactly matching values

      Parameters

      • tags: RnTags

        Object containing tag names as keys and expected values

      Returns boolean

      True if all specified tags exist with matching values, false otherwise

    • Checks if the object's combined tag string contains all the provided search strings. This allows for flexible searching within tag names and values.

      Parameters

      • stringArray: string[]

        Array of strings that must all be present in the combined tag string

      Returns boolean

      True if all strings are found in the combined tag string, false otherwise

    • Transitions the component to a different process stage. This affects which update methods will be called during the frame processing.

      Parameters

      Returns void

    • Registers a dependency relationship with another component. This method is intended for future use in managing component dependencies.

      Parameters

      Returns void

      This method is not used yet and needs implementation

    • Removes a tag from this object

      Parameters

      • tagName: string

        The name of the tag to remove

      Returns void

    • Sets the bone data type of this component. Mat43x1 is the most precise (and the largest), Vec4x2 supports non-uniform scale, and Vec4x1 is the most compact but supports only uniform scale. If joints are already set and the GPU data layout changes, the bone data is re-allocated. Note that Config.boneDataType, if set, takes precedence over this value.

      If a non-uniform scale is found at runtime with Vec4x1, an automatically selected Vec4x1 is switched to Vec4x2, while an explicitly specified Vec4x1 is kept (the largest scale is used, and a warning is logged once).

      Parameters

      • boneDataType: EnumIO

        The bone data type to use

      • isAutoSelected: boolean = false

        True if the type was chosen automatically (e.g. by the glTF importer) rather than specified by the user

      Returns void

    • Sets the accessor for inverse bind matrices used in skeletal animation. These matrices transform vertices from model space to bone space.

      Parameters

      • inverseBindMatricesAccessor: Accessor

        The accessor containing inverse bind matrices data

      Returns void

    • Sets the joint hierarchy for this skeletal component. Initializes the appropriate data arrays based on the configured bone data type.

      Parameters

      Returns void

    • Allocates memory for all member fields of this component instance. This method is called during component initialization to set up memory layout and allocate space for the specified number of entities.

      Parameters

      • componentCountPerBufferView: number

        The number of components per buffer view

      • isReUse: boolean

        Whether to reuse existing memory allocations

      Returns void

    • Attempts to set a tag on this object. If the tag already exists, it will be replaced.

      Parameters

      • tag: Tag

        The tag object containing the name and value to set

      Returns boolean

      True if the tag was successfully set, false if the tag name contains invalid characters

    • Attempts to set a unique name for this object

      Parameters

      • name: string

        The desired unique name

      • toAddNameIfConflict: boolean

        If true, appends UID to make name unique when conflicts occur; if false, fails on conflict

      Returns boolean

      True if the name was successfully set, false if there was a conflict and toAddNameIfConflict was false

    • Unregisters this object from all tracking collections. Should be called when the object is being destroyed.

      Returns void

    • Lightweight joint update for remapping during shallow copy. Only updates joint references without reinitializing buffers. Used when joints are remapped to new entities during shallow copy.

      Parameters

      Returns void

    • Validates that a tag string contains only allowed characters (alphanumeric and underscore)

      Parameters

      • val: string

        The string to validate

      Returns boolean

      True if the string contains only valid characters, false if it contains invalid characters

    • Gets the name of the member which holds the location of a variable-length array member.

      Parameters

      • memberName: string

        The name of the variable-length array member

      Returns string

      The name of the location member

    • Registers the bone data info member (one vec4 per component).

      Returns void

    • Registers the bone data member and its location member. The bone data is a variable-length member, so its size is decided per component (see _getArrayLengthForAllocation).

      Returns void

    • Internal

      Resets all static object tracking data. Used primarily for testing.

      Returns void

    • Checks whether the specified ProcessStage method exists in the given Component class. This is used to determine if a component can handle a particular process stage.

      Parameters

      Returns boolean

      True if the method exists, false otherwise

    • Gets the array length of a specific member field in a component class.

      Parameters

      Returns Map<typeof Component, Map<string, number>>

      The array length map of the component

    • Gets the number of components per buffer view for the component.

      Parameters

      Returns Map<typeof Component, number>

      The number of components per buffer view for the component

    • Gets the ComponentType of a specific member field in a component class. This is useful for understanding the primitive data type of component members.

      Parameters

      • _engine: Engine
      • memberName: string

        The name of the member field

      • componentClass: typeof Component

        The component class to query

      Returns ComponentTypeEnum | undefined

      The ComponentType of the member or undefined if not found

    • Gets the CompositionType of a specific member field in a component class. This is useful for understanding the data structure of component members.

      Parameters

      • _engine: Engine
      • memberName: string

        The name of the member field

      • componentClass: typeof Component

        The component class to query

      Returns CompositionTypeEnum | undefined

      The CompositionType of the member or undefined if not found

    • Gets the pixel location offset in the buffer for a specific member of a component type. This is useful for GPU texture-based data access where locations are measured in pixels.

      Parameters

      • engine: Engine

        The engine instance

      • componentType: typeof Component

        The component class type

      • memberName: string

        The name of the member field

      Returns number[]

      The pixel location offset in the buffer

    • Gets the member info of the component. This is useful for getting the member info of the component.

      Parameters

      Returns Map<typeof Component, Map<string, MemberInfo>>

      The member info of the component

    • Retrieves an RnObject instance by its unique identifier

      Parameters

      • objectUid: number

        The unique identifier of the object to retrieve

      Returns RnObject | undefined

      The RnObject instance or undefined if not found or garbage collected

    • Retrieves an RnObject instance by its unique name

      Parameters

      • uniqueName: string

        The unique name of the object to retrieve

      Returns RnObject | undefined

      The RnObject instance or undefined if not found or garbage collected

    • Gets the state version of the component memory layout. This is incremented whenever the component's memory layout changes.

      Parameters

      • engine: Engine

        The engine instance

      Returns number

      The state version number

    • Checks if an entity's AnimationComponent can perform early return.

      This is called by AnimationComponent.$logic to determine if animation calculations can be skipped. An entity is considered "cached" if:

      1. Its SkeletalComponent had a skinning cache hit in the previous frame
      2. It is NOT a "leader" joint (leaders must continue animating)

      This method also handles the frame transition (swapping current/previous cached UIDs) since AnimationComponent.$logic runs before SkeletalComponent.$logic in each frame.

      Parameters

      • entityUID: number

        The entity UID to check (typically a joint/bone entity)

      • engine: Engine

        The engine instance for multi-engine support

      Returns boolean

      True if the entity can skip animation calculation, false if it must animate

    • Processes all components of a given type for a specific process stage. This method iterates through all components of the specified type and calls their corresponding process stage method if they are in that stage.

      Parameters

      Returns void

    • Registers a member field of the component class for memory allocation. This method defines the memory layout and characteristics of component data members.

      Variable-length array members (isVariableLength: true) are allocated per instance with the length returned by _getArrayLengthForAllocation, instead of the fixed slot layout shared by the components of a buffer view. Shaders find the data through a Vec4 member named ${memberName}Location, which must be registered before the variable-length member.

      Parameters

      • this: typeof Component
      • bufferUse: {
            arrayLength?: number;
            bufferUse: EnumIO;
            componentSID?: number;
            componentType: ComponentTypeEnum;
            compositionType: CompositionTypeEnum;
            convertToBool?: boolean;
            dataClassType: DataClassType;
            initValues: number[] | VectorN;
            isVariableLength?: boolean;
            memberName: string;
            shaderType: EnumIO;
        }

        The intended purpose/type of buffer use

      Returns void

    • Searches for the first object that has a specific tag with the given value

      Parameters

      • tag: string

        The tag name to search for

      • value: string

        The tag value to match

      Returns WeakRef<RnObject> | undefined

      WeakRef to the first matching object, or undefined if not found

    • Updates components specifically for the render stage with render pass context. This method calls the sort_$render method of the component class to handle render-specific processing and sorting.

      Parameters

      Returns any

      The result of the sort_$render method