AttachMesh

Category: Objects / Display
Since engine version: 1.0 OC

Description

Attaches a mesh to another mesh. If mesh is an ID then the mesh of the corresponding definition is used. If mesh is an object then the current mesh of that object is used, including all its animations and attached meshes. However, in that case only the graphics will be attached - the object itself stays at its current position. The return value is a number that can be used to detach the mesh again via DetachMesh.

Syntax

int AttachMesh(any mesh, string parent_bone, string child_bone, array transformation, int flags, int attach_number);

Parameters

mesh:
ID or object of the mesh to be attached.
parent_bone:
Bone of the calling object's mesh at which to fix the mesh to be attached.
child_bone:
Bone of the object to be attached with which to fix it.
transformation:
[opt] Transformation to be applied on the attached mesh in its own frame of reference. The array should consist of 12 integer entries which make up a 3x4 matrix in which each vaule is given in promille (1000 = 100%). These matrices can be created via Trans_Identity, Trans_Translate, Trans_Rotate and Trans_Scale or they can be combined via Trans_Mul.
flags:
[opt] Additional flags to specify the behavior of the attached mesh. Multiple values can be separated with |. The following values are allowed:
Flag Description
AM_DrawBefore Normally the mesh of the object itself is drawn first and afterwards the attached mesh. If this flag is present then the attached mesh is drawn before the object's mesh is drawn. Note that normally this makes no difference since a Z buffer is used to make sure the drawing order is correct. However if one or both of the meshes make use of alpha blending then the drawing order becomes relevant so that a mesh is not hidden behind otherwise (partly) translucent parts of the other mesh.
AM_MatchSkeleton Normally the attached mesh uses its own animations. If this flag is set, then the attached mesh uses the animation data of the parent mesh for all bones that have the same name as a bone in the parent mesh skeleton.
attach_number:
[opt] If given, refers to the number of the attached mesh to which to attach this mesh. This results in nested mesh attachments. This parameter can only be used if it refers to an attached definition, not an attached object. In order to attach a mesh to attached objects, call this function directly on the attached object.

Remark

If an object is used for a mesh then the "MeshTransformation" property of the attached mesh will not be applied. Instead the parameter transformation can be used to transform the attached mesh.

Example

AttachMesh(Bow, "pos_hand1", "main");
If executed in the context of a clonk this script makes him carry a bow. The bow will be attached with its bone called "main" to the bone called "pos_hand1" of the clonk.
See also: DetachMesh, SetAttachBones, SetAttachTransform, Trans_Identitiy, Trans_Mul, Trans_Rotate, Trans_Scale, Trans_Translate
Clonk-Karl, 2010-04