3 Star 25 Fork 13

peridyno/peridyno

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
main.cpp 3.03 KB
一键复制 编辑 原始数据 按行查看 历史
clouddon 提交于 2024-07-12 13:08 . Reactor part of the codes
#include <GlfwApp.h>
#include <SceneGraph.h>
#include <Log.h>
#include <ParticleSystem/ParticleFluid.h>
#include <RigidBody/RigidBody.h>
#include <ParticleSystem/StaticBoundary.h>
#include "ParticleSystem/MakeParticleSystem.h"
#include <Module/CalculateNorm.h>
#include <GLRenderEngine.h>
#include <GLPointVisualModule.h>
#include <ColorMapping.h>
#include <ImColorbar.h>
#include <BasicShapes/CubeModel.h>
#include <ParticleSystem/CubeSampler.h>
using namespace std;
using namespace dyno;
std::shared_ptr<SceneGraph> createScene()
{
std::shared_ptr<SceneGraph> scn = std::make_shared<SceneGraph>();
scn->setUpperBound(Vec3f(1.5, 1, 1.5));
scn->setLowerBound(Vec3f(-0.5, 0, -0.5));
//Create a cube
auto cube = scn->addNode(std::make_shared<CubeModel<DataType3f>>());
cube->varLocation()->setValue(Vec3f(0.6, 0.5, 0.5));
cube->varLength()->setValue(Vec3f(0.2, 0.2, 0.2));
cube->graphicsPipeline()->disable();
//Create a sampler
auto sampler = scn->addNode(std::make_shared<CubeSampler<DataType3f>>());
sampler->varSamplingDistance()->setValue(0.005);
sampler->graphicsPipeline()->disable();
cube->outCube()->connect(sampler->inCube());
auto initialParticles = scn->addNode(std::make_shared<MakeParticleSystem<DataType3f>>());
sampler->statePointSet()->promoteOuput()->connect(initialParticles->inPoints());
auto fluid = scn->addNode(std::make_shared<ParticleFluid<DataType3f>>());
fluid->varReshuffleParticles()->setValue(true);
//fluid->loadParticles(Vec3f(0.5, 0.2, 0.4), Vec3f(0.7, 1.5, 0.6), 0.005);
initialParticles->connect(fluid->importInitialStates());
//Create a boundary
auto boundary = scn->addNode(std::make_shared<StaticBoundary<DataType3f>>()); ;
boundary->loadCube(Vec3f(-0.5, 0, -0.5), Vec3f(1.5, 2, 1.5), 0.02, true);
boundary->loadSDF(getAssetPath() + "bowl/bowl.sdf", false);
fluid->connect(boundary->importParticleSystems());
auto calculateNorm = std::make_shared<CalculateNorm<DataType3f>>();
fluid->stateVelocity()->connect(calculateNorm->inVec());
fluid->graphicsPipeline()->pushModule(calculateNorm);
auto colorMapper = std::make_shared<ColorMapping<DataType3f>>();
colorMapper->varMax()->setValue(5.0f);
calculateNorm->outNorm()->connect(colorMapper->inScalar());
fluid->graphicsPipeline()->pushModule(colorMapper);
auto ptRender = std::make_shared<GLPointVisualModule>();
ptRender->setColor(Color(1, 0, 0));
ptRender->setColorMapMode(GLPointVisualModule::PER_VERTEX_SHADER);
fluid->statePointSet()->connect(ptRender->inPointSet());
colorMapper->outColor()->connect(ptRender->inColor());
fluid->graphicsPipeline()->pushModule(ptRender);
// A simple color bar widget for node
auto colorBar = std::make_shared<ImColorbar>();
colorBar->varMax()->setValue(5.0f);
colorBar->varFieldName()->setValue("Velocity");
calculateNorm->outNorm()->connect(colorBar->inScalar());
// add the widget to app
fluid->graphicsPipeline()->pushModule(colorBar);
return scn;
}
int main()
{
GlfwApp app;
app.setSceneGraph(createScene());
// window.createWindow(2048, 1152);
app.initialize(1024, 768);
app.mainLoop();
return 0;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/peridyno/peridyno.git
git@gitee.com:peridyno/peridyno.git
peridyno
peridyno
peridyno
master

搜索帮助

Cb406eda 1850385 E526c682 1850385