mirror of
https://github.com/Relintai/godot_fastnoise.git
synced 2024-11-12 10:15:21 +01:00
Added project
This commit is contained in:
commit
89d29c083a
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
*.obj
|
||||
*.pyc
|
12
LICENSE.md
Normal file
12
LICENSE.md
Normal file
@ -0,0 +1,12 @@
|
||||
MIT License (MIT)
|
||||
=======================
|
||||
|
||||
Copyright © 2016 Marc Gilleron <moc.liamg@norellig.cram> (reverse email)
|
||||
|
||||
FastNoise C++ library license: [lib/LICENSE](lib/LICENSE)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
4
SCsub
Normal file
4
SCsub
Normal file
@ -0,0 +1,4 @@
|
||||
Import('env')
|
||||
|
||||
env.add_source_files(env.modules_sources,"*.cpp")
|
||||
env.add_source_files(env.modules_sources,"lib/*.cpp")
|
11
config.py
Normal file
11
config.py
Normal file
@ -0,0 +1,11 @@
|
||||
|
||||
|
||||
def can_build(platform):
|
||||
return True
|
||||
|
||||
|
||||
def configure(env):
|
||||
pass
|
||||
|
||||
|
||||
|
2436
lib/FastNoise.cpp
Normal file
2436
lib/FastNoise.cpp
Normal file
File diff suppressed because it is too large
Load Diff
192
lib/FastNoise.h
Normal file
192
lib/FastNoise.h
Normal file
@ -0,0 +1,192 @@
|
||||
// FastNoise.h
|
||||
//
|
||||
// MIT License
|
||||
//
|
||||
// Copyright(c) 2016 Jordan Peck
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files(the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions :
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// The developer's email is jorzixdan.me2@gzixmail.com (for great email, take
|
||||
// off every 'zix'.)
|
||||
//
|
||||
|
||||
#ifndef __FASTNOISE_H__
|
||||
#define __FASTNOISE_H__
|
||||
|
||||
// Added by Marc Gilleron for Godot integration (ability to put a namespace and free FastNoise name)
|
||||
#define FASTNOISE_NAMESPACE fastnoise
|
||||
#ifdef FASTNOISE_NAMESPACE
|
||||
#define FASTNOISE_NAMESPACE_BEGIN namespace FASTNOISE_NAMESPACE {
|
||||
#define FASTNOISE_NAMESPACE_END }
|
||||
#else
|
||||
#define FASTNOISE_NAMESPACE_BEGIN
|
||||
#define FASTNOISE_NAMESPACE_END
|
||||
#endif
|
||||
|
||||
FASTNOISE_NAMESPACE_BEGIN
|
||||
|
||||
class FastNoise
|
||||
{
|
||||
public:
|
||||
FastNoise(int seed = 0) { m_seed = seed; }
|
||||
~FastNoise() { delete m_cellularNoiseLookup; }
|
||||
|
||||
enum NoiseType { Value, ValueFractal, Gradient, GradientFractal, Simplex, SimplexFractal, Cellular, CellularHQ, WhiteNoise };
|
||||
enum Interp { InterpLinear = 0, InterpHermite = 1, InterpQuintic = 2 };
|
||||
enum FractalType { FBM, Billow, RigidMulti };
|
||||
enum CellularDistanceFunction { Euclidean, Manhattan, Natural };
|
||||
enum CellularReturnType { CellValue, NoiseLookup, Distance2Center, Distance2CenterXValue, Distance2CenterSq, Distance2CenterSqXValue, Distance2Edge, Distance2EdgeXValue, Distance2EdgeSq, Distance2EdgeSqXValue };
|
||||
|
||||
void SetSeed(int seed) { m_seed = seed; }
|
||||
int GetSeed(void) { return m_seed; }
|
||||
void SetFrequency(float frequency) { m_frequency = frequency; }
|
||||
void SetInterp(Interp interp) { m_interp = interp; }
|
||||
void SetNoiseType(NoiseType noiseType) { m_noiseType = noiseType; }
|
||||
|
||||
void SetFractalOctaves(unsigned int octaves) { m_octaves = octaves; }
|
||||
void SetFractalLacunarity(float lacunarity) { m_lacunarity = lacunarity; }
|
||||
void SetFractalGain(float gain) { m_gain = gain; }
|
||||
void SetFractalType(FractalType fractalType) { m_fractalType = fractalType; }
|
||||
|
||||
void SetCellularDistanceFunction(CellularDistanceFunction cellularDistanceFunction) { m_cellularDistanceFunction = cellularDistanceFunction; }
|
||||
void SetCellularReturnType(CellularReturnType cellularReturnType) { m_cellularReturnType = cellularReturnType; }
|
||||
void SetCellularNoiseLookup(FastNoise* noise) { m_cellularNoiseLookup = noise; }
|
||||
|
||||
/*
|
||||
Timing below are averages of time taken for 1 million iterations on a single thread
|
||||
Default noise settings
|
||||
CPU: i7 4790k @ 4.0Ghz
|
||||
VS 2013 - C++ Console Application
|
||||
*/
|
||||
|
||||
//3D // Win32 x64
|
||||
float GetValue(float x, float y, float z); // 14 ms 14 ms
|
||||
float GetValueFractal(float x, float y, float z); // 48 ms 49 ms
|
||||
|
||||
float GetGradient(float x, float y, float z); // 23 ms 22 ms
|
||||
float GetGradientFractal(float x, float y, float z);// 80 ms 73 ms
|
||||
|
||||
float GetSimplex(float x, float y, float z); // 30 ms 30 ms
|
||||
float GetSimplexFractal(float x, float y, float z); // 98 ms 101 ms
|
||||
|
||||
float GetCellular(float x, float y, float z); // 123 ms 113 ms
|
||||
float GetCellularHQ(float x, float y, float z); // 433 ms 449 ms
|
||||
|
||||
float GetWhiteNoise(float x, float y, float z); // 1.5 ms 1.5 ms
|
||||
float GetWhiteNoiseInt(int x, int y, int z);
|
||||
|
||||
float GetNoise(float x, float y, float z);
|
||||
|
||||
//2D // Win32 x64
|
||||
float GetValue(float x, float y); // 8 ms 8 ms
|
||||
float GetValueFractal(float x, float y); // 29 ms 29 ms
|
||||
|
||||
float GetGradient(float x, float y); // 12 ms 11 ms
|
||||
float GetGradientFractal(float x, float y); // 43 ms 40 ms
|
||||
|
||||
float GetSimplex(float x, float y); // 17 ms 17 ms
|
||||
float GetSimplexFractal(float x, float y); // 55 ms 52 ms
|
||||
|
||||
float GetCellular(float x, float y); // 35 ms 33 ms
|
||||
float GetCellularHQ(float x, float y); // 96 ms 90 ms
|
||||
|
||||
float GetWhiteNoise(float x, float y); // 1 ms 1 ms
|
||||
float GetWhiteNoiseInt(int x, int y); // 1 ms 1 ms
|
||||
|
||||
float GetNoise(float x, float y);
|
||||
|
||||
//4D
|
||||
float GetSimplex(float x, float y, float z, float w);
|
||||
|
||||
float GetWhiteNoise(float x, float y, float z, float w);
|
||||
float GetWhiteNoiseInt(int x, int y, int z, int w);
|
||||
|
||||
protected:
|
||||
int m_seed = 0;
|
||||
float m_frequency = 0.01f;
|
||||
Interp m_interp = InterpQuintic;
|
||||
NoiseType m_noiseType = Value;
|
||||
|
||||
unsigned int m_octaves = 3;
|
||||
float m_lacunarity = 2.0f;
|
||||
float m_gain = 0.5f;
|
||||
FractalType m_fractalType = FBM;
|
||||
|
||||
CellularDistanceFunction m_cellularDistanceFunction = Euclidean;
|
||||
CellularReturnType m_cellularReturnType = CellValue;
|
||||
FastNoise* m_cellularNoiseLookup = nullptr;
|
||||
|
||||
//3D
|
||||
float _ValueFractalFBM(float x, float y, float z);
|
||||
float _ValueFractalBillow(float x, float y, float z);
|
||||
float _ValueFractalRigidMulti(float x, float y, float z);
|
||||
float _Value(int seed, float x, float y, float z);
|
||||
|
||||
float _GradientFractalFBM(float x, float y, float z);
|
||||
float _GradientFractalBillow(float x, float y, float z);
|
||||
float _GradientFractalRigidMulti(float x, float y, float z);
|
||||
float _Gradient(int seed, float x, float y, float z);
|
||||
|
||||
float _SimplexFractalFBM(float x, float y, float z);
|
||||
float _SimplexFractalBillow(float x, float y, float z);
|
||||
float _SimplexFractalRigidMulti(float x, float y, float z);
|
||||
float _Simplex(int seed, float x, float y, float z);
|
||||
|
||||
float _Cellular(float x, float y, float z);
|
||||
float _CellularHQ(float x, float y, float z);
|
||||
float _Cellular2Edge(float x, float y, float z);
|
||||
float _Cellular2EdgeHQ(float x, float y, float z);
|
||||
|
||||
inline static int CoordLUTIndex(int seed, int x, int y, int z);
|
||||
inline float GetValCoord(int seed, int x, int y, int z);
|
||||
inline float GetGradCoord(int seed, int xi, int yi, int zi, float x, float y, float z);
|
||||
|
||||
//2D
|
||||
float _ValueFractalFBM(float x, float y);
|
||||
float _ValueFractalBillow(float x, float y);
|
||||
float _ValueFractalRigidMulti(float x, float y);
|
||||
float _Value(int seed, float x, float y);
|
||||
|
||||
float _GradientFractalFBM(float x, float y);
|
||||
float _GradientFractalBillow(float x, float y);
|
||||
float _GradientFractalRigidMulti(float x, float y);
|
||||
float _Gradient(int seed, float x, float y);
|
||||
|
||||
float _SimplexFractalFBM(float x, float y);
|
||||
float _SimplexFractalBillow(float x, float y);
|
||||
float _SimplexFractalRigidMulti(float x, float y);
|
||||
float _Simplex(int seed, float x, float y);
|
||||
|
||||
float _Cellular(float x, float y);
|
||||
float _CellularHQ(float x, float y);
|
||||
float _Cellular2Edge(float x, float y);
|
||||
float _Cellular2EdgeHQ(float x, float y);
|
||||
|
||||
inline int CoordLUTIndex(int seed, int x, int y);
|
||||
inline float GetValCoord(int seed, int x, int y);
|
||||
inline float GetGradCoord(int seed, int xi, int yi, float x, float y);
|
||||
|
||||
//4D
|
||||
float _Simplex(float x, float y, float z, float w);
|
||||
inline static int CoordLUTIndex(int seed, int x, int y, int z, int w);
|
||||
};
|
||||
|
||||
FASTNOISE_NAMESPACE_END
|
||||
|
||||
#endif
|
21
lib/LICENSE
Normal file
21
lib/LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2016 Jordan Peck
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
108
noise.cpp
Normal file
108
noise.cpp
Normal file
@ -0,0 +1,108 @@
|
||||
/*************************************************************************/
|
||||
/* noise.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
||||
/* This file is (c) 2016 Marc Gilleron <moc.liamg@norellig.cram> */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "noise.h"
|
||||
|
||||
|
||||
FastNoise::FastNoise() : Reference() {
|
||||
|
||||
}
|
||||
|
||||
void FastNoise::set_cellular_noise_lookup(Ref<FastNoise> other_noise) {
|
||||
|
||||
_cellular_lookup_ref = other_noise;
|
||||
|
||||
if (_cellular_lookup_ref.is_null())
|
||||
_noise.SetCellularNoiseLookup(NULL);
|
||||
else
|
||||
_noise.SetCellularNoiseLookup(&_cellular_lookup_ref->_noise);
|
||||
}
|
||||
|
||||
void FastNoise::_bind_methods() {
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("set_seed", "seed"), &FastNoise::set_seed);
|
||||
ObjectTypeDB::bind_method(_MD("get_seed"), &FastNoise::get_seed);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("set_noise_type", "type"), &FastNoise::set_noise_type);
|
||||
ObjectTypeDB::bind_method(_MD("set_interpolation", "interp"), &FastNoise::set_interpolation);
|
||||
ObjectTypeDB::bind_method(_MD("set_frequency", "freq"), &FastNoise::set_frequency);
|
||||
ObjectTypeDB::bind_method(_MD("set_fractal_gain", "gain"), &FastNoise::set_fractal_gain);
|
||||
ObjectTypeDB::bind_method(_MD("set_fractal_type", "type"), &FastNoise::set_fractal_type);
|
||||
ObjectTypeDB::bind_method(_MD("set_fractal_octaves", "octave_count"), &FastNoise::set_fractal_octaves);
|
||||
ObjectTypeDB::bind_method(_MD("set_fractal_lacunarity", "lacunarity"), &FastNoise::set_fractal_lacunarity);
|
||||
ObjectTypeDB::bind_method(_MD("set_cellular_distance_function", "func"), &FastNoise::set_cellular_distance_function);
|
||||
ObjectTypeDB::bind_method(_MD("set_cellular_return_type", "ret"), &FastNoise::set_cellular_return_type);
|
||||
ObjectTypeDB::bind_method(_MD("set_cellular_noise_lookup", "other_noise:FastNoise"), &FastNoise::set_cellular_noise_lookup);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("get_noise_2d", "x", "y"), &FastNoise::get_noise_2d);
|
||||
ObjectTypeDB::bind_method(_MD("get_noise_2dv", "pos"), &FastNoise::get_noise_2dv);
|
||||
ObjectTypeDB::bind_method(_MD("get_noise_3d", "x", "y", "z"), &FastNoise::get_noise_3d);
|
||||
ObjectTypeDB::bind_method(_MD("get_noise_3dv", "pos"), &FastNoise::get_noise_3dv);
|
||||
ObjectTypeDB::bind_method(_MD("get_simplex_4d", "x", "y", "z", "w"), &FastNoise::get_simplex_4d);
|
||||
ObjectTypeDB::bind_method(_MD("get_white_noise_4d", "x", "y", "z", "w"), &FastNoise::get_white_noise_4d);
|
||||
// TODO Bind intermediary functions?
|
||||
|
||||
BIND_CONSTANT( TYPE_VALUE );
|
||||
BIND_CONSTANT( TYPE_VALUE_FRACTAL );
|
||||
BIND_CONSTANT( TYPE_GRADIENT );
|
||||
BIND_CONSTANT( TYPE_GRADIENT_FRACTAL );
|
||||
BIND_CONSTANT( TYPE_SIMPLEX );
|
||||
BIND_CONSTANT( TYPE_SIMPLEX_FRACTAL );
|
||||
BIND_CONSTANT( TYPE_CELLULAR );
|
||||
BIND_CONSTANT( TYPE_CELLULAR_HQ );
|
||||
BIND_CONSTANT( TYPE_WHITE_NOISE );
|
||||
|
||||
BIND_CONSTANT( INTERP_LINEAR );
|
||||
BIND_CONSTANT( INTERP_QUINTIC );
|
||||
BIND_CONSTANT( INTERP_HERMITE );
|
||||
|
||||
BIND_CONSTANT( FRACTAL_FBM );
|
||||
BIND_CONSTANT( FRACTAL_BILLOW );
|
||||
BIND_CONSTANT( FRACTAL_RIGID_MULTI );
|
||||
|
||||
BIND_CONSTANT( DISTANCE_EUCLIDEAN );
|
||||
BIND_CONSTANT( DISTANCE_MANHATTAN );
|
||||
BIND_CONSTANT( DISTANCE_NATURAL );
|
||||
|
||||
BIND_CONSTANT( RETURN_CELL_VALUE );
|
||||
BIND_CONSTANT( RETURN_NOISE_LOOKUP );
|
||||
BIND_CONSTANT( RETURN_DISTANCE_2_CENTER );
|
||||
BIND_CONSTANT( RETURN_DISTANCE_2_CENTER_X_VALUE );
|
||||
BIND_CONSTANT( RETURN_DISTANCE_2_CENTER_SQ );
|
||||
BIND_CONSTANT( RETURN_DISTANCE_2_CENTER_SQ_X_VALUE );
|
||||
BIND_CONSTANT( RETURN_DISTANCE_2_EDGE );
|
||||
BIND_CONSTANT( RETURN_DISTANCE_2_EDGE_X_VALUE );
|
||||
BIND_CONSTANT( RETURN_DISTANCE_2_EDGE_SQ );
|
||||
BIND_CONSTANT( RETURN_DISTANCE_2_EDGE_SQ_X_VALUE );
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
130
noise.h
Normal file
130
noise.h
Normal file
@ -0,0 +1,130 @@
|
||||
#ifndef FASTNOISE_NOISE_H
|
||||
#define FASTNOISE_NOISE_H
|
||||
|
||||
#include <reference.h>
|
||||
#include "lib/FastNoise.h"
|
||||
|
||||
typedef fastnoise::FastNoise _FastNoise;
|
||||
|
||||
class FastNoise : public Reference {
|
||||
OBJ_TYPE(FastNoise, Reference);
|
||||
|
||||
public:
|
||||
|
||||
// Enums Godot-style (same values)
|
||||
|
||||
enum Type {
|
||||
TYPE_VALUE = _FastNoise::Value,
|
||||
TYPE_VALUE_FRACTAL = _FastNoise::ValueFractal,
|
||||
TYPE_GRADIENT = _FastNoise::Gradient,
|
||||
TYPE_GRADIENT_FRACTAL = _FastNoise::GradientFractal,
|
||||
TYPE_SIMPLEX = _FastNoise::Simplex,
|
||||
TYPE_SIMPLEX_FRACTAL = _FastNoise::SimplexFractal,
|
||||
TYPE_CELLULAR = _FastNoise::Cellular,
|
||||
TYPE_CELLULAR_HQ = _FastNoise::CellularHQ,
|
||||
TYPE_WHITE_NOISE = _FastNoise::WhiteNoise
|
||||
};
|
||||
|
||||
enum Interpolation {
|
||||
INTERP_LINEAR = _FastNoise::InterpLinear,
|
||||
INTERP_QUINTIC = _FastNoise::InterpQuintic,
|
||||
INTERP_HERMITE = _FastNoise::InterpHermite
|
||||
};
|
||||
|
||||
enum FractalType {
|
||||
FRACTAL_FBM = _FastNoise::FBM,
|
||||
FRACTAL_BILLOW = _FastNoise::Billow,
|
||||
FRACTAL_RIGID_MULTI = _FastNoise::RigidMulti
|
||||
};
|
||||
|
||||
enum CellularDistanceFunction {
|
||||
DISTANCE_EUCLIDEAN = _FastNoise::Euclidean,
|
||||
DISTANCE_MANHATTAN = _FastNoise::Manhattan,
|
||||
DISTANCE_NATURAL = _FastNoise::Natural
|
||||
};
|
||||
|
||||
enum CellularReturnType {
|
||||
RETURN_CELL_VALUE = _FastNoise::CellValue,
|
||||
RETURN_NOISE_LOOKUP = _FastNoise::NoiseLookup,
|
||||
RETURN_DISTANCE_2_CENTER = _FastNoise::Distance2Center,
|
||||
RETURN_DISTANCE_2_CENTER_X_VALUE = _FastNoise::Distance2CenterXValue,
|
||||
RETURN_DISTANCE_2_CENTER_SQ = _FastNoise::Distance2CenterSq,
|
||||
RETURN_DISTANCE_2_CENTER_SQ_X_VALUE = _FastNoise::Distance2CenterSqXValue,
|
||||
RETURN_DISTANCE_2_EDGE = _FastNoise::Distance2Edge,
|
||||
RETURN_DISTANCE_2_EDGE_X_VALUE = _FastNoise::Distance2EdgeXValue,
|
||||
RETURN_DISTANCE_2_EDGE_SQ = _FastNoise::Distance2EdgeSq,
|
||||
RETURN_DISTANCE_2_EDGE_SQ_X_VALUE = _FastNoise::Distance2EdgeSqXValue
|
||||
};
|
||||
|
||||
FastNoise();
|
||||
|
||||
// Methods (Godot-style mappings to FastNoise)
|
||||
|
||||
int get_seed() { return _noise.GetSeed(); } // TODO should be const
|
||||
void set_seed(int seed) { _noise.SetSeed(seed); }
|
||||
|
||||
void set_noise_type(Type noise_type) { _noise.SetNoiseType((_FastNoise::NoiseType)noise_type); }
|
||||
void set_interpolation(Interpolation interp) { _noise.SetInterp((_FastNoise::Interp)interp); }
|
||||
void set_frequency(float freq) { _noise.SetFrequency(freq); }
|
||||
void set_fractal_gain(float gain) { _noise.SetFractalGain(gain); }
|
||||
void set_fractal_type(FractalType type) { _noise.SetFractalType((_FastNoise::FractalType)type); }
|
||||
void set_fractal_octaves(unsigned int octave_count) { _noise.SetFractalOctaves(octave_count); }
|
||||
void set_fractal_lacunarity(float lacunarity) { _noise.SetFractalLacunarity(lacunarity); }
|
||||
void set_cellular_distance_function(CellularDistanceFunction func) { _noise.SetCellularDistanceFunction((_FastNoise::CellularDistanceFunction)func); }
|
||||
void set_cellular_return_type(CellularReturnType ret) { _noise.SetCellularReturnType((_FastNoise::CellularReturnType)ret); }
|
||||
|
||||
// TODO Q: how can I do that properly?
|
||||
void set_cellular_noise_lookup(Ref<FastNoise> other_noise);
|
||||
|
||||
// 2D
|
||||
|
||||
float get_noise_2d(float x, float y) { return _noise.GetNoise(x, y); }
|
||||
|
||||
//float get_gradient_2d(float x, float y) { return _noise.GetGradient(x, y); }
|
||||
//float get_simplex_2d(float x, float y) { return _noise.GetSimplex(x, y); }
|
||||
//float get_cellular_2d(float x, float y) { return _noise.GetCellular(x, y); }
|
||||
//float get_cellular_hq_2d(float x, float y) { return _noise.GetCellularHQ(x, y); }
|
||||
//float get_white_noise_2d(float x, float y) { return _noise.GetWhiteNoise(x, y); }
|
||||
//float get_value_2d(float x, float y) { return _noise.GetValue(x, y); }
|
||||
|
||||
// 3D
|
||||
|
||||
float get_noise_3d(float x, float y, float z) { return _noise.GetNoise(x, y, z); }
|
||||
|
||||
//float get_gradient_3d(float x, float y, float z) { return _noise.GetGradient(x, y, z); }
|
||||
//float get_simplex_3d(float x, float y, float z) { return _noise.GetSimplex(x, y, z); }
|
||||
//float get_cellular_3d(float x, float y, float z) { return _noise.GetCellular(x, y, z); }
|
||||
//float get_cellular_hq_3d(float x, float y, float z) { return _noise.GetCellularHQ(x, y, z); }
|
||||
//float get_white_noise_3d(float x, float y, float z) { return _noise.GetWhiteNoise(x, y, z); }
|
||||
//float get_value_2d(float x, float y, float z) { return _noise.GetValue(x, y, z); }
|
||||
|
||||
// 4D
|
||||
|
||||
float get_simplex_4d(float x, float y, float z, float w) { return _noise.GetSimplex(x, y, z, w); }
|
||||
float get_white_noise_4d(float x, float y, float z, float w) { return _noise.GetWhiteNoise(x, y, z, w); }
|
||||
|
||||
// Convenience
|
||||
|
||||
float get_noise_2dv(Vector2 pos) { return _noise.GetNoise(pos.x, pos.y); }
|
||||
float get_noise_3dv(Vector3 pos) { return _noise.GetNoise(pos.x, pos.y, pos.z); }
|
||||
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
_FastNoise _noise;
|
||||
Ref<FastNoise> _cellular_lookup_ref;
|
||||
|
||||
};
|
||||
|
||||
// Make Variant happy with custom enums
|
||||
VARIANT_ENUM_CAST(FastNoise::Type);
|
||||
VARIANT_ENUM_CAST(FastNoise::FractalType);
|
||||
VARIANT_ENUM_CAST(FastNoise::Interpolation);
|
||||
VARIANT_ENUM_CAST(FastNoise::CellularDistanceFunction);
|
||||
VARIANT_ENUM_CAST(FastNoise::CellularReturnType);
|
||||
|
||||
|
||||
#endif // FASTNOISE_NOISE_H
|
||||
|
17
register_types.cpp
Normal file
17
register_types.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
#include "register_types.h"
|
||||
#include "object_type_db.h"
|
||||
|
||||
#include "noise.h"
|
||||
|
||||
|
||||
void register_fastnoise_types() {
|
||||
|
||||
ObjectTypeDB::register_type<FastNoise>();
|
||||
}
|
||||
|
||||
|
||||
void unregister_fastnoise_types() {
|
||||
|
||||
}
|
||||
|
||||
|
2
register_types.h
Normal file
2
register_types.h
Normal file
@ -0,0 +1,2 @@
|
||||
void register_fastnoise_types();
|
||||
void unregister_fastnoise_types();
|
Loading…
Reference in New Issue
Block a user