0.3.3 • Published 4 years ago

sparkar-autofit v0.3.3

Weekly downloads
5
License
MIT
Repository
github
Last release
4 years ago

Autofit

indexAutofit is a Spark AR utility to make object's texture keep in correct ratio.

Both Patch and Script version are included.

You can also Click Here to Download Sample Projects. The PickerHandler in script-usage demo projects is not necessary, it's just used to assist in demo.

For Patch Editor

Install

  1. Download Autofit.arp

  2. Drag/Drop or import it to Spark AR

Usage

image-20200524193954384

Input

ValueTypeDescription
Plane ScaleVector2Generally is the the scale of a plane's transform, or scale of rectangle.
Texture SizeVector2The Dimensions value of input texture. Find the value and fill it manually.
TextureTexture🖼️
Expand / ShrinkBooleanIf true, the mode is Expand. If false, the mode is Shrink.
Background ColorColorThe background color is filled in the empty space in ENVELOPE mode.

Output

ValueTypeDescription
OutputTextureThe result can be used in material texture slot.
UVVector2The scaled UV.

For Script

Import

  1. Download Autofit.js (Right click and Save as)

  2. Drag/Drop or import it to Spark AR.

  3. Load in the required module.

    const Autofit = require('./Autofit');
    // Your script...

npm

  1. Add package with yarn or npm.

    yarn add sparkar-autofit

    or

    npm i sparkar-autofit
  2. Load in the required module.

    const Autofit = require('sparkar-autofit');
    // Your script...

Usage

const Scene = require('Scene');
const Autofit = require('./Autofit');

Scene.root.findFirst('plane0').then(plane0 =>
   Autofit.fitTexture(plane0, Autofit.TextureScaleMode.FIT))
);

Scene.root.findFirst('plane0').then(plane0 =>
   Autofit.fitObject(plane0, Autofit.ObjectScaleMode.BASED_ON_HEIGHT))
);

Reference

Autofit

MethodDescription
fitTexture(sceneObject: SceneObjectBase, scaleMode: Autofit.TextureScaleMode, backgroundColor: Point4DSignal): Promise<void>Fit object's texture scale in ratio.
getFitTextureUV(sceneObject: SceneObjectBase, scaleMode: Autofit.TextureScaleMode): Promise<ScaleSignal>Get the ScaleSignal that for object to fit scale by texture's ratio.
fitObject(sceneObject: SceneObjectBase, scaleMode: Autofit.ObjectScaleMode): Promise<void>Fit object's scale by texture's ratio.
getFitObjectScale(sceneObject: SceneObjectBase, scaleMode: Autofit.ObjectScaleMode): Promise<ScaleSignal>Get the ScaleSignal that for object to fit scale by texture's ratio.

Autofit.ObjectScaleMode

ValueDescription
BASED_ON_HEIGHTScale based on height mode.
BASED_ON_WIDTHScale based on width mode.
BASED_ON_1024Scale based on resolution 1024 mode.

Autofit.TextureScaleMode

ValueDescription
ExpandScale in expand mode.
ShrinkScale in shrink mode.
StretchScale in strech mode.

Donations

If this is useful for you, please consider a donation🙏🏼. One-time donations can be made with PayPal.

npm.io