6#include <glm/common.hpp>
7#include <glm/geometric.hpp>
12float hash3(
const glm::ivec3 &
p, std::uint32_t
seed) {
13 std::uint32_t
h =
seed ^ (std::uint32_t(
p.x) * 0x8da6b343u) ^
14 (std::uint32_t(
p.y) * 0xd8163841u) ^ (std::uint32_t(
p.z) * 0xcb1ab31fu);
18 return float(
h & 0x00ffffffu) / float(0x01000000u);
29 const int next = int(nodes_.size());
32 node.inputA = inputA >= 0 && inputA < next ? inputA : -1;
33 node.inputB = inputB >= 0 && inputB < next ? inputB : -1;
35 nodes_.push_back(
node);
42 : int(nodes_.size()) - 1;
45float VolumeDensityGraph::valueNoise(
const glm::vec3 &
p, std::uint32_t
seed) {
46 const glm::ivec3
cell = glm::ivec3(glm::floor(
p));
47 const glm::vec3
f = glm::fract(
p);
48 const glm::vec3
u =
f *
f * (3.f - 2.f *
f);
49 float corners[2][2][2];
50 for (
int z = 0;
z < 2; ++
z)
51 for (
int y = 0;
y < 2; ++
y)
52 for (
int x = 0;
x < 2; ++
x)
54 const float z0 = glm::mix(glm::mix(corners[0][0][0], corners[0][0][1],
u.x),
55 glm::mix(corners[0][1][0], corners[0][1][1],
u.x),
u.y);
56 const float z1 = glm::mix(glm::mix(corners[1][0][0], corners[1][0][1],
u.x),
57 glm::mix(corners[1][1][0], corners[1][1][1],
u.x),
u.y);
58 return glm::mix(z0, z1,
u.z);
62 if (nodes_.empty())
return 0.f;
63 std::vector<float>
values(nodes_.size(), 0.f);
64 for (std::size_t i = 0; i < nodes_.size(); ++i) {
65 const Node &
n = nodes_[i];
66 const float a =
n.inputA >= 0 ?
values[std::size_t(
n.inputA)] : 0.f;
67 const float b =
n.inputB >= 0 ?
values[std::size_t(
n.inputB)] : 0.f;
71 values[i] = std::exp(-std::max(
n.params.y, 0.f) *
72 std::max(worldPosition.y -
n.params.x, 0.f));
75 const float radius = std::max(
n.params.w, 1e-4f);
76 values[i] = std::clamp(1.f - glm::length(worldPosition - glm::vec3(
n.params)) /
81 const glm::vec3
q = glm::abs(worldPosition - glm::vec3(
n.params));
82 const float extent = std::max(
n.params.w, 1e-4f);
83 values[i] = std::clamp(1.f - std::max(std::max(
q.x,
q.y),
q.z) / extent,
88 const float scale = std::max(std::fabs(
n.params.x), 1e-4f);
89 const glm::vec3 wind(
n.params.y, 0.f,
n.params.z);
91 std::uint32_t(std::max(
n.params.w, 0.f)));
100 const int selected = output_ >= 0 ? output_ : int(nodes_.size()) - 1;
101 return values[std::size_t(selected)];
std::map< std::string, Var > values
std::array< double, 10 > q
std::array< float, 3 > scale
void clear()
Remove every node and reset the output.
float evaluate(const glm::vec3 &worldPosition, float time=0.f) const
Evaluate signed density at a world position and time.
void setOutput(int nodeIndex)
Select the node returned by evaluate; invalid indices select the last node.
int addNode(Op op, int inputA=-1, int inputB=-1, const glm::vec4 ¶ms=glm::vec4(0.f))
Append a node and return its stable index. Inputs must precede the node.
std::vector< ParamSpec > params
卡牌游戏 UI 工具模块:工厂 + 脚本绑定入口。 功能参考 ycarowr/UiCard:扇形手牌布局、抽牌/洗牌、悬浮放大、拖拽到落牌区、 敌方手牌(背面/偷看)、费用不足置灰,以及可实时调节的布局...