Skip to main content

HairVisual

Class

Used to simulate and render hairstyles with realistic lighting and physics.

  • Available on all platforms
Platform details: Snapchat, SPECS, Camera Kit Web, Camera Kit Mobile fully supported.

Platform details

  • Snapchat — Fully supported.

  • SPECS — Fully supported.

  • Camera Kit Web — Fully supported.

  • Camera Kit Mobile — Fully supported.

Index

Example

//@input Component.HairVisual hair

var width = 1;
var wind = new vec3(5,0,0);

script.hair.onInitialized = InitializeHair;

function InitializeHair(hv){
//change hair width
hv.strandWidth = width;

//add wind to hair
hv.windEnabled = true;
hv.windForce = wind;
}

Extends

Properties

clumpDensity

clumpDensity: number

Density of each clump, higher number would result in "messier" looking hair.

Default Value

0

clumpRadius

clumpRadius: number

Offset amount of hair roots.

Default Value

0.5

clumpTipScale

clumpTipScale: number

Offset amount of hair tips.

Default Value

0

colliders

colliders: ColliderComponent[]

List of all colliders assigned to the hair simulation of the current hair visual.

Since

Lens Scripting Version 138

Default Value

[]

collisionEnabled

collisionEnabled: boolean

Determines if collision is enabled for hair.

Default Value

true

collisionFriction

collisionFriction: number

Determines amount of friction for collision between hair strands.

Default Value

1

collisionOffset

collisionOffset: number

Determines how much position offset collision will cause.

Default Value

1

collisionStiffness

collisionStiffness: number

Determines how stiff the collision is.

Default Value

5

damp

damp: number

Higher value of damp will cause hair to have less free movement.

Since

Lens Scripting Version 138

Default Value

5

density

density: number

Amount of density created to thicken hair.

Default Value

0

enabled

enabled: boolean

If disabled, the Component will stop enacting its behavior.

Default Value

true

Inherited from

BaseMeshVisual.enabled


extentsTarget

extentsTarget: ScreenTransform

When a ScreenTransform is present on this SceneObject, and extentsTarget is a child of this SceneObject, extentsTarget will be repositioned to match the exact area this MeshVisual is being rendered. Very useful for Image and Text components.

Default Value

null

Inherited from

BaseMeshVisual.extentsTarget


fallbackModeEnabled

fallbackModeEnabled: boolean

This enables fallback mode which turns off physics simulations; it is recommended to enable fallback mode on lower-end devices. It will be enabled automatically if device doesn't support hair simulation feature.

Default Value

false

friction

friction: number

Amount of friction for hair strands.

Since

Lens Scripting Version 138

Default Value

0.2

gravity

gravity: vec3

Gravity force that gets added for hair's physics simulation.

Since

Lens Scripting Version 138

Default Value

(0, -1, 0)

hairMaterial

hairMaterial: Material

Material used by this simulation to render hair.

Default Value

null

hairResolution

hairResolution: number

Determines the amount of vertices on each strand. 0 means using original number of the strands. 1 is the smallest resolution for hair. Keep in mind when you change this property, the hair geometry will be regenerated.

Default Value

0

horizontalAlignment

horizontalAlignment: HorizontalAlignment

When a ScreenTransform is attached to the same SceneObject, this controls how the mesh will be positioned horizontally depending on stretchMode.

Default Value

HorizontalAlignment.Center

Inherited from

BaseMeshVisual.horizontalAlignment


isBeingDestroyed

readonly isBeingDestroyed: boolean

Returns true if this Component is currently being destroyed. Becomes true as soon as destruction begins via Component#destroy or destruction of its owning SceneObject, before any OnDestroyEvent callbacks fire.

Since

Lens Scripting Version 364

Example

if (!script.isBeingDestroyed) {
// Component is still fully alive
}

Inherited from

BaseMeshVisual.isBeingDestroyed


isEnabledInHierarchy

readonly isEnabledInHierarchy: boolean

Returns true if this Component, its SceneObject, and all of that SceneObjects parents are enabled.

Inherited from

BaseMeshVisual.isEnabledInHierarchy


meshShadowMode

meshShadowMode: MeshShadowMode

None = 0, Caster = 1, Receiver = 2

Default Value

MeshShadowMode.None

Inherited from

BaseMeshVisual.meshShadowMode


noise

noise: number

Offset of hair density.

Default Value

0

onInitialized

onInitialized: (hairVisual) => void

This function gets called when the hair visual is initialized in the Lens.

Parameters

ParameterType
hairVisualHairVisual

Returns

void

Since

Lens Scripting Version 138

Default Value

null

renderOrder

renderOrder: number

The order in which the visual should be rendered.

Since

Lens Scripting Version 323

Default Value

0

Inherited from

BaseMeshVisual.renderOrder


sceneObject

readonly sceneObject: SceneObject

The SceneObject this component is on.

Inherited from

BaseMeshVisual.sceneObject


selfCollisionEnabled

selfCollisionEnabled: boolean

If enabled, hair strands will collide with themselves.

Default Value

false

selfCollisionFriction

selfCollisionFriction: number

Friction of collisions between hair strands.

Since

Lens Scripting Version 138

Default Value

1

selfCollisionRadius

selfCollisionRadius: number

Radius limit of collisions between hair strands.

Default Value

2

selfCollisionStiffness

selfCollisionStiffness: number

Determines how stiff collision between hair strands are.

Default Value

1

shadowColor

shadowColor: vec4

Affects the color of shadows being cast by this MeshVisual. The color of the cast shadow is a mix between shadowColor and the material's base texture color. The alpha value of shadowColor controls the mixing of these two colors, with 0 = shadowColor and 1 = shadowColor * textureColor.

Default Value

(1, 1, 1, 1)

Inherited from

BaseMeshVisual.shadowColor


shadowDensity

shadowDensity: number

Density of shadows cast by this MeshVisual.

Default Value

1

Inherited from

BaseMeshVisual.shadowDensity


stiffness

stiffness: number

Higher value of stiffness will make hair move less.

Default Value

0.1

strandTaper

strandTaper: number

The taper size of each hair towards the tip.

Default Value

0

strandWidth

strandWidth: number

The Width of each hair strand.

Since

Lens Scripting Version 138

Default Value

1

stretchMode

stretchMode: StretchMode

When a ScreenTransform is attached to the same SceneObject, this controls how the mesh will be stretched relative to the ScreenTransform's boundaries.

Default Value

StretchMode.Stretch

Inherited from

BaseMeshVisual.stretchMode


uniqueIdentifier

readonly uniqueIdentifier: string

Since

Lens Scripting Version 176

Inherited from

BaseMeshVisual.uniqueIdentifier


verticalAlignment

verticalAlignment: VerticalAlignment

When a ScreenTransform is attached to the same SceneObject, this controls how the mesh will be positioned vertically depending on stretchMode.

Default Value

VerticalAlignment.Center

Inherited from

BaseMeshVisual.verticalAlignment


windEnabled

windEnabled: boolean

If checked will add wind force to hair simulation.

Default Value

false

windForce

windForce: vec3

Amount of wind force added to hair simulation.

Since

Lens Scripting Version 138

Default Value

(1, 0, 0)

Methods

addCollider()

addCollider(colliderComponent): void

Adds a collider to the simulation.

Parameters

ParameterType
colliderComponentColliderComponent

Returns

void

Since

Lens Scripting Version 138


clearColliders()

clearColliders(): void

Removes all hair colliders from the hair simulation.

Returns

void

Since

Lens Scripting Version 138


destroy()

destroy(): void

Destroys the component.

Returns

void

Inherited from

BaseMeshVisual.destroy


getRenderOrder()

getRenderOrder(): number

Returns the order of this Visual in the render queue.

Returns

number

Inherited from

BaseMeshVisual.getRenderOrder


getSceneObject()

getSceneObject(): SceneObject

Returns the SceneObject the component is attached to.

Returns

SceneObject

Inherited from

BaseMeshVisual.getSceneObject


getTransform()

getTransform(): Transform

Returns the Transform this component is attached to.

Returns

Transform

Inherited from

BaseMeshVisual.getTransform


getTypeName()

static getTypeName(): TypeName<HairVisual>

Returns the fully-qualified JavaScript type name for this class (for example, "Component.Camera"). This is a static accessor (no instance required) and returns the same value as the instance getTypeName().

Returns

TypeName<HairVisual>

Overrides

BaseMeshVisual.getTypeName


getTypeName()

getTypeName(): string

Returns the name of this object's type.

Returns

string

Inherited from

BaseMeshVisual.getTypeName


isHardwareSupported()

isHardwareSupported(): boolean

Returns true if hair simulation is supported by the device.

Returns

boolean

Since

Lens Scripting Version 138


isInitialized()

isInitialized(): boolean

Returns true if the hair resources are initialized.

Returns

boolean

Since

Lens Scripting Version 138


isOfType()

isOfType(type): boolean

Returns true if the object matches or derives from the passed in type.

Parameters

ParameterType
typestring

Returns

boolean

Inherited from

BaseMeshVisual.isOfType


isSame()

isSame(other): boolean

Returns true if this object is the same as other. Useful for checking if two references point to the same thing.

Parameters

ParameterType
otherScriptObject

Returns

boolean

Inherited from

BaseMeshVisual.isSame


localAabbMax()

localAabbMax(): vec3

Range maximum of the local-space axis-aligned bounding box (AABB) of the visual.

Returns

vec3

Since

Lens Scripting Version 156

Inherited from

BaseMeshVisual.localAabbMax


localAabbMin()

localAabbMin(): vec3

Range minimum of the local-space axis-aligned bounding box (AABB) of the visual.

Returns

vec3

Since

Lens Scripting Version 156

Inherited from

BaseMeshVisual.localAabbMin


removeColliderByIndex()

removeColliderByIndex(index): ColliderComponent

Removes a collider from the simulation by index and returns it.

Parameters

ParameterType
indexnumber

Returns

ColliderComponent

Since

Lens Scripting Version 138


resetSimulation()

resetSimulation(): void

Resets the simulation. May be called if the object with the hair simulation is toggled between enabled and disabled.

Returns

void

Since

Lens Scripting Version 138


setRenderOrder()

setRenderOrder(value): void

Sets the order of this Visual in the render queue.

Parameters

ParameterType
valuenumber

Returns

void

Inherited from

BaseMeshVisual.setRenderOrder


snap()

snap(camera): void

Projects screen positions from camera's view onto the mesh's UVs. If the MeshVisual's material uses the same texture as the camera input, the MeshVisual will look identical to the part of the screen it covers.

Parameters

ParameterType
cameraCamera

Returns

void

Inherited from

BaseMeshVisual.snap


worldAabbMax()

worldAabbMax(): vec3

Range maximum of the world-space axis-aligned bounding box (AABB) of the visual.

Returns

vec3

Since

Lens Scripting Version 156

Inherited from

BaseMeshVisual.worldAabbMax


worldAabbMin()

worldAabbMin(): vec3

Range minimum of the world-space axis-aligned bounding box (AABB) of the visual.

Returns

vec3

Since

Lens Scripting Version 156

Inherited from

BaseMeshVisual.worldAabbMin

See also