AddMorphTarget ( mesh,pose_mesh[,name$][,attributes] )

Parameters

mesh - destination mesh node that stores the captured target

pose_mesh - donor mesh with matching ordered surfaces, vertex counts, triangles and triangle index order

name$ (optional) - unique target name, compared without case; "" selects an unused "Morph N" name (default)

attributes (optional) - bit mask of captured attributes; zero and unknown bits are errors:
1: position (default)
2: normal
4: tangent XYZ

Description

Captures a reusable morph target from a donor mesh and returns its zero-based index.

The target stores donor CPU base attributes minus destination CPU base attributes in mesh-local coordinates. Both arguments address their own mesh node; children are not searched. Entity transforms, current weights, skin poses, materials and shader displacement are ignored. All data is copied, so the donor may be freed immediately.

Matching counts alone cannot establish semantic vertex correspondence. For a single surface, CopyMesh is a convenient donor. CopyMesh may merge multi-surface meshes that share materials; build a matching donor explicitly in that case. All surfaces and selected values are validated before capture. Invalid inputs, duplicate names or allocation failure leave the destination unchanged.

Position-only capture does not recalculate normals. Prepare donor normals with UpdateNormals before using bit 2. Tangent capture requires valid authored/generated tangents on both inputs, matching tangent handedness, and finite values. Tangent W is retained, never blended.

Definitions are shared by CopyEntity instances. Each copy starts the new slot at zero and retains its previous weights. Use SetMorphWeight to change a pose; finite negative and above-one weights are supported. Older animation keys and crossfades treat newly appended slots as zero.

Vertex queries and mesh collision continue to use CPU base vertices. Coordinate edits change the shared base while captured deltas remain offsets. Whole-mesh transforms and FlipMesh preserve target correspondence. Topology changes require ClearMorphTargets first. CopyMesh continues to produce independent static base geometry.

Capture is rejected while any entity sharing the destination geometry has LOD levels, or while the destination is referenced as another entity's LOD. Clear those LOD relationships before capture. Morph targets do not make geometry eligible for rigid LOD or planar receivers.

For a larger walkthrough, see the complete interactive captured-target sample.


See also: ClearMorphTargets, CountMorphTargets, FindMorphTarget, MorphWeight, SetMorphWeight.

Example

; AddMorphTarget Example
; ----------------------

Graphics3D 640,480,0,2
SetBuffer BackBuffer()

camera=CreateCamera()
PositionEntity camera,0,0,-6

light=CreateLight()
RotateEntity light,30,20,0

; Capture a stretched pose of a sphere as a reusable morph target
base=CreateSphere(20)
EntityColor base,80,180,240

; The donor: a copy of the base mesh, reshaped, with normals prepared
pose=CopyMesh(base)
ScaleMesh pose,1,1.5,0.65
UpdateNormals pose

; Capture positions and normals (attributes 1+2); the donor can then go
target=AddMorphTarget(base,pose,"Stretch",3)
FreeEntity pose

weight#=0

While Not KeyDown(1)

    ; [ / ] blend the captured pose in and out (negative weights work too)
    If KeyDown(26) Then weight=weight-0.02
    If KeyDown(27) Then weight=weight+0.02
    SetMorphWeight base,target,weight

    ; Arrow keys move the camera
    If KeyDown(200) Then MoveEntity camera,0,0,0.1
    If KeyDown(208) Then MoveEntity camera,0,0,-0.1
    If KeyDown(203) Then TurnEntity camera,0,1,0
    If KeyDown(205) Then TurnEntity camera,0,-1,0

    RenderWorld

    Text 0,0,"Arrow keys: move camera   [ / ] : morph weight   Esc: exit"
    Text 0,20,"AddMorphTarget captured slot "+target+"   SetMorphWeight base,"+target+","+weight
    Text 0,40,"Vertex queries and collision still use the base sphere"

    Flip

Wend

End

Index