Description

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

Example

// @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) => void);
    repulsionEnabled: boolean;
    repulsionFriction: number;
    repulsionOffset: number;
    repulsionStiffness: number;
    shadowColor: vec4;
    shadowDensity: number;
    simulatedMesh: RenderMesh;
    stretchMode: StretchMode;
    stretchStiffness: number;
    stretchStiffnessVertexWeight: number;
    uniqueIdentifier: string;
    updateNormalsEnabled: boolean;
    verticalAlignment: VerticalAlignment;
    addCollider(colliderComponent): void;
    addMaterial(material): void;
    clearColliders(): void;
    clearMaterials(): void;
    destroy(): void;
    getAllColors(): vec4[];
    getMaterial(index): Material;
    getMaterialsCount(): number;
    getPointColorByIndex(index): vec4;
    getPointIndicesByColor(color, colorMask): number[];
    getPointIndicesByMask(colorMask): number[];
    getRenderOrder(): number;
    getSceneObject(): SceneObject;
    getTransform(): Transform;
    getTypeName(): string;
    getVertexBinding(index): SceneObject;
    getVertexSettings(index): VertexSimulationSettings;
    isHardwareSupported(): boolean;
    isInitialized(): boolean;
    isOfType(type): boolean;
    isSame(other): boolean;
    localAabbMax(): vec3;
    localAabbMin(): vec3;
    removeColliderByIndex(index): ColliderComponent;
    resetSimulation(): void;
    setRenderOrder(value): void;
    setVertexBinding(index, bindingObj): void;
    setVertexSettings(index, vertexSettings): void;
    snap(camera): void;
    worldAabbMax(): vec3;
    worldAabbMin(): vec3;
}

Hierarchy (view full)

Properties

Description

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

bendStiffness: number

Description

BendStiffness value.

bendStiffnessVertexWeight: number

Description

BendStiffness value weight on all the VertexSettings.

colliders: ColliderComponent[]

Description

List of colliders assigned.

enabled: boolean

Description

If disabled, the Component will stop enacting its behavior.

extentsTarget: ScreenTransform

Description

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

Description

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

friction: number

Description

Friction value.

frictionVertexWeight: number

Description

Friction value weight on all the VertexSettings.

gravity: vec3

Description

Gravity force vector.

horizontalAlignment: HorizontalAlignment

Description

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

iterationsPerStep: number

Description

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

mainMaterial: Material

Description

Returns the first Material.

mainPass: Pass

Description

Returns the mainPass of the mainMaterial.

mass: number

Description

Mass value.

massVertexWeight: number

Description

Mass value weight on all the VertexSettings.

materials: Material[]

Description

Get the array of materials used by the MaterialMeshVisual.

maxAcceleration: number

Description

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

mergeCloseVerticesEnabled: boolean

Description

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

mergeCloseVerticesThreshold: number

Description

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

Description

Attached mesh.

meshShadowMode: MeshShadowMode

Description

None = 0, Caster = 1, Receiver = 2

onInitialized: ((clothVisual) => void)

Type declaration

    • (clothVisual): void
    • Parameters

      Returns void

      Description

      Function called when the ClothVisual is initialized.

Description

Function called when the ClothVisual is initialized.

repulsionEnabled: boolean

Description

Indicates whether we will enable collision repulsion with collider models.

repulsionFriction: number

Description

Collision friction to dampen relative motion.

repulsionOffset: number

Description

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

repulsionStiffness: number

Description

Indicates the stiffness of repulsion when collision.

shadowColor: vec4

Description

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

Description

Density of shadows cast by this MeshVisual.

simulatedMesh: RenderMesh

Description

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

Description

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

Description

StretchStiffness Value.

stretchStiffnessVertexWeight: number

Description

StretchStiffness Value weight on all the VertexSettings.

uniqueIdentifier: string
updateNormalsEnabled: boolean

Description

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

verticalAlignment: VerticalAlignment

Description

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

Methods

  • Parameters

    Returns void

    Description

    Adds a collider to the list of colliders.

  • Returns void

    Description

    Clears the colliders list.

  • Returns vec4[]

    Description

    Returns all available vertex colors on cloth mesh.

  • Parameters

    • index: number

    Returns vec4

    Description

    Returns the vertex color by vertex index.

  • Parameters

    Returns number[]

    Description

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

  • Parameters

    Returns number[]

    Description

    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

    • index: number

    Returns SceneObject

    Description

    Gets binding SceneObject of the vertex.

  • Returns boolean

    Description

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

  • Returns boolean

    Description

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

  • Parameters

    • type: string

    Returns boolean

    Description

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

  • Parameters

    Returns boolean

    Description

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

  • Parameters

    • index: number

    Returns ColliderComponent

    Description

    Removes collider by its index and returns the removed collider.

  • Returns void

    Description

    Resets the cloth simulation.

  • Parameters

    • value: number

    Returns void

    Description

    Sets the order of this Visual in the render queue.

  • Parameters

    Returns void

    Description

    Sets the binding SceneObject for the vertex.

  • Parameters

    Returns void

    Description

    Sets simulation settings of the vertex.

  • Parameters

    Returns void

    Description

    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.

Generated using TypeDoc