Search in sources :

Example 6 with MutableVector3

use of com.fastasyncworldedit.core.math.MutableVector3 in project FastAsyncWorldEdit by IntellectualSites.

the class SplineBrush method getCentroid.

private Vector3 getCentroid(Collection<BlockVector3> points) {
    MutableVector3 sum = new MutableVector3();
    for (BlockVector3 p : points) {
        sum.mutX(sum.getX() + p.getX());
        sum.mutY(sum.getY() + p.getY());
        sum.mutZ(sum.getZ() + p.getZ());
    }
    return sum.multiply(1.0 / points.size());
}
Also used : MutableVector3(com.fastasyncworldedit.core.math.MutableVector3) BlockVector3(com.sk89q.worldedit.math.BlockVector3)

Example 7 with MutableVector3

use of com.fastasyncworldedit.core.math.MutableVector3 in project FastAsyncWorldEdit by IntellectualSites.

the class EditSession method makeBlob.

/**
 * Makes a distorted sphere.
 *
 * @param position   Center of blob
 * @param pattern    pattern to use
 * @param size       overall size of the blob
 * @param frequency  distortion amount (0 to 1)
 * @param amplitude  distortion amplitude (0 to 1)
 * @param radius     radii to multiply x/y/z by
 * @param sphericity how spherical to make the blob. 1 = very spherical, 0 = not
 * @return changes
 */
public int makeBlob(BlockVector3 position, Pattern pattern, double size, double frequency, double amplitude, Vector3 radius, double sphericity) {
    double seedX = ThreadLocalRandom.current().nextDouble();
    double seedY = ThreadLocalRandom.current().nextDouble();
    double seedZ = ThreadLocalRandom.current().nextDouble();
    int px = position.getBlockX();
    int py = position.getBlockY();
    int pz = position.getBlockZ();
    double distort = frequency / size;
    double modX = 1d / radius.getX();
    double modY = 1d / radius.getY();
    double modZ = 1d / radius.getZ();
    int r = (int) size;
    int radiusSqr = (int) (size * size);
    int sizeInt = (int) size * 2;
    if (sphericity == 1) {
        for (int x = -sizeInt; x <= sizeInt; x++) {
            double nx = seedX + x * distort;
            double d1 = x * x * modX;
            for (int y = -sizeInt; y <= sizeInt; y++) {
                double d2 = d1 + y * y * modY;
                double ny = seedY + y * distort;
                for (int z = -sizeInt; z <= sizeInt; z++) {
                    double nz = seedZ + z * distort;
                    double distance = d2 + z * z * modZ;
                    double noise = amplitude * SimplexNoise.noise(nx, ny, nz);
                    if (distance + distance * noise < radiusSqr) {
                        setBlock(px + x, py + y, pz + z, pattern);
                    }
                }
            }
        }
    } else {
        AffineTransform transform = new AffineTransform().rotateX(ThreadLocalRandom.current().nextInt(360)).rotateY(ThreadLocalRandom.current().nextInt(360)).rotateZ(ThreadLocalRandom.current().nextInt(360));
        double manScaleX = 1.25 + seedX * 0.5;
        double manScaleY = 1.25 + seedY * 0.5;
        double manScaleZ = 1.25 + seedZ * 0.5;
        MutableVector3 mutable = new MutableVector3();
        double roughness = 1 - sphericity;
        for (int xr = -sizeInt; xr <= sizeInt; xr++) {
            for (int yr = -sizeInt; yr <= sizeInt; yr++) {
                for (int zr = -sizeInt; zr <= sizeInt; zr++) {
                    // pt == mutable as it's a MutableVector3
                    // so it must be set each time
                    mutable.mutX(xr);
                    mutable.mutY(yr);
                    mutable.mutZ(zr);
                    Vector3 pt = transform.apply(mutable);
                    int x = MathMan.roundInt(pt.getX());
                    int y = MathMan.roundInt(pt.getY());
                    int z = MathMan.roundInt(pt.getZ());
                    double xScaled = Math.abs(x) * modX;
                    double yScaled = Math.abs(y) * modY;
                    double zScaled = Math.abs(z) * modZ;
                    double manDist = xScaled + yScaled + zScaled;
                    double distSqr = x * x * modX + z * z * modZ + y * y * modY;
                    double distance = Math.sqrt(distSqr) * sphericity + MathMan.max(manDist, xScaled * manScaleX, yScaled * manScaleY, zScaled * manScaleZ) * roughness;
                    double noise = amplitude * SimplexNoise.noise(seedX + x * distort, seedZ + z * distort, seedZ + z * distort);
                    if (distance + distance * noise < r) {
                        setBlock(px + xr, py + yr, pz + zr, pattern);
                    }
                }
            }
        }
    }
    return changes;
}
Also used : MutableVector3(com.fastasyncworldedit.core.math.MutableVector3) AffineTransform(com.sk89q.worldedit.math.transform.AffineTransform) MutableBlockVector3(com.fastasyncworldedit.core.math.MutableBlockVector3) MutableVector3(com.fastasyncworldedit.core.math.MutableVector3) BlockVector3(com.sk89q.worldedit.math.BlockVector3) Vector3(com.sk89q.worldedit.math.Vector3)

Example 8 with MutableVector3

use of com.fastasyncworldedit.core.math.MutableVector3 in project FastAsyncWorldEdit by IntellectualSites.

the class ScaleTransform method setBiome.

@Override
public boolean setBiome(int x1, int y1, int z1, BiomeType biome) {
    boolean result = false;
    MutableVector3 vector3 = getPos(x1, y1, z1);
    MutableBlockVector3 pos = new MutableBlockVector3();
    double sx = vector3.getX();
    double sy = vector3.getY();
    double sz = vector3.getZ();
    double ex = sx + dx;
    double ey = Math.max(minY, Math.min(maxy, sy + dy));
    double ez = sz + dz;
    for (pos.mutY(sy); pos.getY() < ey; pos.mutY(pos.getY() + 1)) {
        for (pos.mutZ(sz); pos.getZ() < ez; pos.mutZ(pos.getZ() + 1)) {
            for (pos.mutX(sx); pos.getX() < ex; pos.mutX(pos.getX() + 1)) {
                if (!getExtent().contains(pos)) {
                    continue;
                }
                result |= super.setBiome(pos, biome);
            }
        }
    }
    return result;
}
Also used : MutableVector3(com.fastasyncworldedit.core.math.MutableVector3) MutableBlockVector3(com.fastasyncworldedit.core.math.MutableBlockVector3)

Example 9 with MutableVector3

use of com.fastasyncworldedit.core.math.MutableVector3 in project FastAsyncWorldEdit by IntellectualSites.

the class ScaleTransform method setExtent.

@Override
public ResettableExtent setExtent(Extent extent) {
    min = null;
    mutable = new MutableVector3();
    this.minY = extent.getMinY();
    this.maxy = extent.getMaxY();
    return super.setExtent(extent);
}
Also used : MutableVector3(com.fastasyncworldedit.core.math.MutableVector3)

Example 10 with MutableVector3

use of com.fastasyncworldedit.core.math.MutableVector3 in project FastAsyncWorldEdit by IntellectualSites.

the class NoiseFilter method setNoiseGenerator.

/**
 * Set the noise generator.
 *
 * @param noiseGenerator a noise generator
 */
public void setNoiseGenerator(NoiseGenerator noiseGenerator) {
    checkNotNull(noiseGenerator);
    this.noiseGenerator = noiseGenerator;
    // FAWE start - mutable
    this.mutable = new MutableVector3();
// FAWE end
}
Also used : MutableVector3(com.fastasyncworldedit.core.math.MutableVector3)

Aggregations

MutableVector3 (com.fastasyncworldedit.core.math.MutableVector3)11 MutableBlockVector3 (com.fastasyncworldedit.core.math.MutableBlockVector3)5 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)2 Vector3 (com.sk89q.worldedit.math.Vector3)1 AffineTransform (com.sk89q.worldedit.math.transform.AffineTransform)1