API reference

GridSliceResizer Class

Extends MonoBehaviour
The GridSliceResizer is a versatile tool designed to maintain the proportions of specific areas of 3D meshes while allowing others to stretch during scaling.
The concept of the GridSliceResizer is similar to the popular 9-Slice-Scaling technique used in 2D graphics, which keeps the borders of sprites unstretched while the inner rectangle is stretched. In essence, the GridSliceResizer is a 27-Slice-Scaler for 3D meshes. The component operates by dividing the bounding box of a 3D mesh into 27 cuboids, as illustrated below. Not all cuboids are visible in this picture. Only the ones that are front facing:
         +-----+-----------+-----+
        /_____/___________/_____/|
       /_____/___________/_____/||
      /     /           /     /|||
     +-----+-----------+-----+ |||
     |  A  |     B     |  C  |/|||
     +-----+-----------+-----+ |||
     |     |           |     | |||
     |  D  |     E     |  F  | |||
     |     |           |     |/||/
     +-----+-----------+-----+ |/
     |  G  |     H     |  I  | /
     +-----+-----+-----+-----+
The scaling behaviour is as follows (assuming all other faces of the bounding box are divided as the front facing one): Center Cuboid (E): Vertices within this cuboid stretch on two axes (Y, Z). Corner Cuboids (A, C, G, I): These cuboids do not stretch on any axis. Middle Cuboids (B, H): These cuboids stretch horizontally but not vertically. Middle Cuboids (D, F): These cuboids stretch vertically but not horizontally. The slicing areas are defined by the PivotOffset and BorderXNegative, BorderXPositive, etc. These border values range from 0 to 1 and extend from the mesh's pivot (which may be offset by PivotOffset) to the maximum or minimum of the bounding box's axis. If all borders are set to 1, the mesh will stretch like a regular mesh during scaling. If set to 0, no stretching will occur. Typically, you'll want the pivot in the middle of the mesh and the borders set to around 0.8. You can visualize the borders and pivot either in the editor, in the prefab mode and during play. This component is only compatible with meshes that have read/write access enabled. It is usually used in conjunction with the AnchorPrefabSpawner component to dinamically instantiate and resize prefabs based on anchors without losing the proportions of specific sections of the mesh.

Fields

BorderXNegative : float
Specifies the proportion of the mesh along the negative X-axis that is protected from scaling.
Signature
float BorderXNegative
BorderXPositive : float
Specifies the proportion of the mesh along the positive X-axis that is protected from scaling.
Signature
float BorderXPositive
BorderYNegative : float
Specifies the proportion of the mesh along the negative Y-axis that is protected from scaling.
Signature
float BorderYNegative
BorderYPositive : float
Specifies the proportion of the mesh along the positive Y-axis that is protected from scaling.
Signature
float BorderYPositive
BorderZNegative : float
Specifies the proportion of the mesh along the negative Z-axis that is protected from scaling.
Signature
float BorderZNegative
BorderZPositive : float
Specifies the proportion of the mesh along the positive Z-axis that is protected from scaling.
Signature
float BorderZPositive
OriginalMesh : Mesh
The original mesh before any modifications.
This mesh is used as the baseline for all scaling operations
Signature
Mesh OriginalMesh
PivotOffset : Vector3
Represents the offset from the pivot point of the mesh.
This offset is used to adjust the origin of scaling operations.
Signature
Vector3 PivotOffset
ScalingX : Method
Specifies the proportion of the mesh along the positive X-axis that is protected from scaling.
Signature
Method ScalingX
ScalingY : Method
Defines the scaling method to be applied along the Y-axis of the mesh.
Signature
Method ScalingY
ScalingZ : Method
Defines the scaling method to be applied along the Z-axis of the mesh.
Signature
Method ScalingZ
StretchCenter : StretchCenterAxis
Specifies which axes should allow the center part of the object to stretch.
This setting is used to control the stretching behavior of the central section of the mesh allowing for selective stretching along specified axes.
Signature
StretchCenterAxis StretchCenter
UpdateInPlayMode : bool
Indicates whether the resizer should update the mesh in play mode.
When set to true, the mesh will continue to be updated based on the scaling settings during runtime. This can be useful for dynamic scaling effects but may impact performance if used excessively. When instantiating prefab through the AnchorPrefabSpawner component, this property should be set to true. ///
Signature
bool UpdateInPlayMode

Methods

ProcessVertices ()
Processes the vertices of the given mesh, applying scaling and border adjustments.
This function is expensive, as it access and modifies each vertex of the mesh. Avoid calling it every frame.
Signature
Mesh ProcessVertices()
Returns
Mesh  A new Mesh with processed vertices.

Inner Enums

Method Enum

Defines the method of scaling to be applied to different sections of the mesh.

Enumeration Constants

Member
SLICE
SLICE_WITH_ASYMMETRICAL_BORDER
SCALE

StretchCenterAxis Enum

This parameter determines whether the center part of the object should be scaled.
If set to false, the center vertices will remain stationary. This is particularly useful when you want to maintain the proportions of certain geometrical features in the center part, such as a doorknob. By keeping the center vertices in place, you can avoid unwanted stretching effects, resulting in a more visually appealing outcome. However, it's important to note that for a convincing visual effect, the texture applied to the object should also not stretch. If you encounter issues with texture stretching, consider adding a loop cut. This can help maintain the texture's proportions and prevent it from distorting.

Enumeration Constants

MemberValue
X
1 << 0
Y
1 << 1
Z
1 << 2