mirror of
https://git.do.srb2.org/STJr/UltimateZoneBuilder.git
synced 2024-12-04 01:22:29 +00:00
5eb438e3ba
Added map scripting capabilities to UDB (#656). Documentation at https://biwa.github.io/udbscript-docs/
41 lines
No EOL
976 B
JavaScript
41 lines
No EOL
976 B
JavaScript
`#name Jitter Vertices`;
|
|
|
|
`#description Jitters the selected vertices. If no vertices are selected all vertices in the map are jittered. Does not make sure that the resulting geometry is still valid.`;
|
|
|
|
`#scriptoptions
|
|
|
|
min
|
|
{
|
|
description = "Minimum jitter";
|
|
default = 0;
|
|
type = 1; // Integer
|
|
}
|
|
|
|
max
|
|
{
|
|
description = "Maximum jitter";
|
|
default = 16;
|
|
type = 1; // Integer
|
|
}
|
|
`;
|
|
|
|
// Gets a random value between min and max, then randomly make it negative
|
|
function getRandomValue(min, max)
|
|
{
|
|
return (Math.floor(Math.random() * (max-min)) + min) * (Math.random() < 0.5 ? 1 : -1);
|
|
}
|
|
|
|
// Get selected vertices
|
|
let vertices = Map.getSelectedVertices();
|
|
|
|
// No vertices selected? Get all vertices!
|
|
if(vertices.length == 0)
|
|
vertices = Map.getVertices();
|
|
|
|
// Jitter each vertex
|
|
vertices.forEach(v => {
|
|
v.position += [
|
|
getRandomValue(ScriptOptions.min, ScriptOptions.max),
|
|
getRandomValue(ScriptOptions.min, ScriptOptions.max),
|
|
];
|
|
});
|