bp-cloner
Version:
More info and explanations here - https://doc.babylonjs.com/communityExtensions/clonerSystem
164 lines (163 loc) • 6.49 kB
TypeScript
import { Matrix, Vector3 } from '@babylonjs/core/Maths/math.vector';
import { Scene } from '@babylonjs/core/scene';
import { InstancedMesh, Mesh } from '@babylonjs/core/Meshes/';
export declare class CMesh extends Mesh {
_cloner: Cloner | null;
_index: number;
constructor(name: string, scene: Scene, parent: Mesh | null, cloner?: Cloner | null);
createClone(item: Cloner | Mesh, useInstances: boolean, name: string, isPickable: boolean): void | Mesh | InstancedMesh;
delete(): void;
}
export declare class Cloner {
static vOne: Vector3;
static vZero: Vector3;
_rootNode: Mesh | null;
_mesh: Array<Mesh>;
_scene: Scene;
_clones: Array<CMesh>;
_frame: number;
_index: number;
_count: number | undefined;
_effectors: Array<IEffector>;
createClone(_parent: Mesh): void;
/**
* Deletes all Cloner's children and disposes the root Node.
*/
delete(): void;
/**
* set the cloner's root node to the state of the flag (true=enabled)
*
* @param enabled
*/
setEnabled(enabled: boolean): void;
update(): void;
/**
* Adds an effector to this Cloner and sets the sensitivity (1=full sensitivity, 0=no sensitivity ==ignore effector)
*
* @param effector
* @param sensitivity
*/
addEffector(effector: RandomEffector, sensitivity: number): void;
get effectors(): IEffector[];
eScale(vec: Vector3): Vector3;
eRotate(vec: Vector3): Vector3;
ePosition(vec: Vector3): Vector3;
eReset(): void;
getScene(): Scene;
/**
* Converts the Cloner to thin instances, then deletes this Cloner and returns an array of Cloner meshes. The source meshes are cloned, their clones set enabled. To display them use addSelf = true.
* All cloned source meshes get the new parent with the rootName.
* Be aware that the original Cloner will be disposed, so Cloner methods will not work anymore. Use the root node and its individual child meshes for further processing.
*
* @param addSelf If true, adds the source mesh to the matrix. Default false.
* @param rootName Allow to define the name of the root mesh which will be the parent of cloned source meshes and all thin instances.
* If empty, Cloner class name will be used for the name.
*/
toThin(addSelf?: boolean, rootName?: string): Mesh[];
/**
* Converts all Cloner meshes to thin instances from the original meshes, then deletes this Cloner and returns an array of Cloner meshes.
* Be aware that instances of all those original meshes become disabled as well, so if they are used in other Cloners one may want to use toThin() method instead.
* If you don't need animations and so on you may convert Cloner to thin instances. It greatly reduces the number of objects iterating in the render loop.
* @param addSelf If true, adds the source mesh to the matrix. Default false.
* @returns The array of original meshes: Mesh[]
*/
toThinOriginals(addSelf?: boolean): Mesh[];
/**
* Returns an array of matrices (scaling, rotation, position) of the Cloner meshes.
**/
toMatrix(): Matrix[];
}
export interface IEffector {
effector: RandomEffector;
sensitivity: number;
}
/**
* Each Cloner can have a set of Effectors assigned.
* The Effector influences properties of the clones cloned by a Cloner.
* The RandomEffector can influence all transfomation properties (scale/rotation/position) with repeatable random values.
* Different random sequences can be achieved with a different seed value.
* The RandomEffector can serve more than one cloner but it has only one property to control the strength of the random values.
* Therefore each cloner has a property sensitivity to accept either all or only a portion of the cloners strength.
* Note: the scaling transformation will be done in two different ways depending on the property uniformScale:
* if this property is set to true, only one random value will be used for all three scaling components (x,y,z) and the y/z componets of the scale property will be ignored.
* If set to false, each direction is scaled independently with an extra random value.
* @param seed The the seed value for generating different sequences of random values. Default 42.
* @param strength Sets the strength of the generator (range 0 to 1).
* @param uniformScale true => all scaling directions with one value, false independently scaling.
* @param position Sets position values in the range 0 to {x: number, y: number, z: number}.
* @param scale Sets scaling values in the range 0 to {x: number, y: number, z: number}.
* @param rotation Sets rotation values in the range 0 to {x: number, y: number, z: number}.
*/
export declare class RandomEffector {
private _seed;
private _s;
private _rfunction;
private _strength;
private _position;
private _rotation;
private _scale;
private _uniformScale;
private _clients;
constructor(seed?: number);
random(): number;
reset(): void;
updateRotation(vec: Vector3): Vector3;
updatePosition(vec: Vector3): Vector3;
updateScale(vec: Vector3): Vector3;
addClient(c: Cloner): void;
/**
* Call this function after creating and setting the effector to update instances/clones transforms.
*/
updateClients(): this;
get strength(): number;
set strength(s: number);
str(s: number): this;
set position(p: {
x: number;
y: number;
z: number;
});
get position(): Vector3;
set scale(s: {
x: number;
y: number;
z: number;
});
get scale(): Vector3;
set rotation(r: {
x: number;
y: number;
z: number;
});
get rotation(): Vector3;
rot(r: {
x: number;
y: number;
z: number;
}): this;
pos(p: {
x: number;
y: number;
z: number;
}): this;
set seed(s: number);
get seed(): number;
set uniformScale(flag: boolean);
get uniformScale(): boolean;
getRandomColor(): number;
getRandomInt({ min, max }?: {
min?: number | undefined;
max?: number | undefined;
}): number;
}
export declare class RandomNumberGen {
private _min;
private _max;
private _generator;
constructor({ min, max, seed }?: {
min?: number | undefined;
max?: number | undefined;
seed?: number | undefined;
});
nextInt(): number;
}