Handles the mesh data of cloth and prepares it for cloth simulation. Also controls all the parameters of the cloth simulator and colliders.

// @input  Component.ClothVisual clothVisual
// @input Asset.RenderMesh mesh
// @input Asset.Material material

var clothVisual = script.clothVisual;

clothVisual.bendMode = ClothVisual.BendMode.Isometric;
clothVisual.mesh = script.mesh;
clothVisual.mainMaterial = script.material;
clothVisual.gravity = new vec3(0, -100, 0);
clothVisual.stretchStiffness = 0.1;
clothVisual.bendStiffness = 0.1;
clothVisual.friction = 0.1;
clothVisual.repulsionEnabled = true;
clothVisual.repulsionOffset = 0.1;
clothVisual.repulsionStiffness = 0.1;
clothVisual.repulsionFriction = 0.1;
clothVisual.iterationsPerStep = 60;
clothVisual.frameRate = 30;
clothVisual.colliders = script.Colliders;
clothVisual.debugModeEnabled = false;
clothVisual.drawCollider = true;
clothVisual.updateNormalsEnabled = true;
clothVisual.mergeCloseVerticesEnabled = true;
clothVisual.onInitialized = clothInitCallback;
clothVisual.updatePriority = 0;

function clothInitCallback(clothVisualArg) {
clothVisualArg.resetSimulation();
}
interface ClothVisual {
    bendMode: ClothVisual.BendMode;
    bendStiffness: number;
    bendStiffnessVertexWeight: number;
    colliders: ColliderComponent[];
    enabled: boolean;
    extentsTarget: ScreenTransform;
    externalBodyMeshWeight: number;
    friction: number;
    frictionVertexWeight: number;
    gravity: vec3;
    horizontalAlignment: HorizontalAlignment;
    iterationsPerStep: number;
    mainMaterial: Material;
    mainPass: Pass;
    mass: number;
    massVertexWeight: number;
    materials: Material[];
    maxAcceleration: number;
    mergeCloseVerticesEnabled: boolean;
    mergeCloseVerticesThreshold: number;
    mesh: RenderMesh;
    meshShadowMode: MeshShadowMode;
    onInitialized: ((clothVisual: ClothVisual) => void);
    repulsionEnabled: boolean;
    repulsionFriction: number;
    repulsionOffset: number;
    repulsionStiffness: number;
    sceneObject: SceneObject;
    shadowColor: vec4;
    shadowDensity: number;
    simulatedMesh: RenderMesh;
    stretchMode: StretchMode;
    stretchStiffness: number;
    stretchStiffnessVertexWeight: number;
    uniqueIdentifier: string;
    updateNormalsEnabled: boolean;
    verticalAlignment: VerticalAlignment;
    addCollider(colliderComponent: ColliderComponent): void;
    addMaterial(material: Material): void;
    clearColliders(): void;
    clearMaterials(): void;
    destroy(): void;
    getAllColors(): vec4[];
    getMaterial(index: number): Material;
    getMaterialsCount(): number;
    getPointColorByIndex(index: number): vec4;
    getPointIndicesByColor(color: vec4, colorMask: vec4b): number[];
    getPointIndicesByMask(colorMask: vec4b): number[];
    getRenderOrder(): number;
    getSceneObject(): SceneObject;
    getTransform(): Transform;
    getTypeName(): string;
    getVertexBinding(index: number): SceneObject;
    getVertexSettings(index: number): VertexSimulationSettings;
    isHardwareSupported(): boolean;
    isInitialized(): boolean;
    isOfType(type: string): boolean;
    isSame(other: ScriptObject): boolean;
    localAabbMax(): vec3;
    localAabbMin(): vec3;
    removeColliderByIndex(index: number): ColliderComponent;
    resetSimulation(): void;
    setRenderOrder(value: number): void;
    setVertexBinding(index: number, bindingObj: SceneObject): void;
    setVertexSettings(index: number, vertexSettings: VertexSimulationSettings): void;
    snap(camera: Camera): void;
    worldAabbMax(): vec3;
    worldAabbMin(): vec3;
}

Hierarchy (view full)

Properties

Select bend mode to use (Isometric bending/Linear bending).

bendStiffness: number

BendStiffness value.

bendStiffnessVertexWeight: number

BendStiffness value weight on all the VertexSettings.

colliders: ColliderComponent[]

List of colliders assigned.

enabled: boolean

If disabled, the Component will stop enacting its behavior.

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.

externalBodyMeshWeight: number

The influence of the external body mesh acting on the cloth visual.

friction: number

Friction value.

frictionVertexWeight: number

Friction value weight on all the VertexSettings.

gravity: vec3

Gravity force vector.

horizontalAlignment: HorizontalAlignment

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

iterationsPerStep: number

Number of simulation iterations to perform per each step. Higher number contributes to higher quality, but can be difficult for device performance.

mainMaterial: Material

Returns the first Material.

mainPass: Pass

Returns the mainPass of the mainMaterial.

mass: number

Mass value.

massVertexWeight: number

Mass value weight on all the VertexSettings.

materials: Material[]

Get the array of materials used by the MaterialMeshVisual.

maxAcceleration: number

Control for the acceleration on motion of vertices in cloth simulation, by default set to 2000.

mergeCloseVerticesEnabled: boolean

Whether to merge close vertices (Lens Studio might split vertices when loading FBX mesh). Changing this resets the simulation.

mergeCloseVerticesThreshold: number

Threshold of close vertices. Changing this value resets the simulation.

Attached mesh.

meshShadowMode: MeshShadowMode

None = 0, Caster = 1, Receiver = 2

onInitialized: ((clothVisual: ClothVisual) => void)

Function called when the ClothVisual is initialized.

repulsionEnabled: boolean

Indicates whether we will enable collision repulsion with collider models.

repulsionFriction: number

Collision friction to dampen relative motion.

repulsionOffset: number

Indicates the offset we set when the cloth mesh is too close to the colliders.

repulsionStiffness: number

Indicates the stiffness of repulsion when collision.

sceneObject: SceneObject
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.

shadowDensity: number

Density of shadows cast by this MeshVisual.

simulatedMesh: RenderMesh

Returns the modified simulated mesh which can be used in another RenderMeshVisual if the same simulated mesh is needed. Useful when creating effects that might require the same mesh to be rendered twice, such as with a mirror effect. Prevents the need to run a simulation twice.

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.

stretchStiffness: number

StretchStiffness Value.

stretchStiffnessVertexWeight: number

StretchStiffness Value weight on all the VertexSettings.

uniqueIdentifier: string
updateNormalsEnabled: boolean

Whether to update normals for the cloth mesh each frame in order to get reflection update.

verticalAlignment: VerticalAlignment

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

Methods

  • Adds a collider to the list of colliders.

    Parameters

    Returns void

  • Clears the colliders list.

    Returns void

  • Returns all available vertex colors on cloth mesh.

    Returns vec4[]

  • Returns the vertex color by vertex index.

    Parameters

    • index: number

    Returns vec4

  • Returns all the indices of vertices that are labeled by this color.

    Parameters

    Returns number[]

  • Returns all the indices on the cloth mesh that are matching the color mask. Match means that the color has value on the channels which in colorMask is true.

    Parameters

    Returns number[]

  • Gets binding SceneObject of the vertex.

    Parameters

    • index: number

    Returns SceneObject

  • Returns true if the Cloth Simulation feature is supported by the current device.

    Returns boolean

  • Returns true if the Cloth Simulation and resources are initialized. Always return false if device is not supported.

    Returns boolean

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

    Parameters

    • type: string

    Returns boolean

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

    Parameters

    Returns boolean

  • Resets the cloth simulation.

    Returns void

  • Sets the order of this Visual in the render queue.

    Parameters

    • value: number

    Returns void

  • Sets the binding SceneObject for the vertex.

    Parameters

    Returns void

  • Sets simulation settings of the vertex.

    Parameters

    Returns 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

    Returns void