当前位置:网站首页>[splishsplash] about how to receive / display user parameters, MVC mode and genparam on GUI and JSON
[splishsplash] about how to receive / display user parameters, MVC mode and genparam on GUI and JSON
2022-07-01 17:30:00 【beidou111】
principle :splishsplash Medium MVC Patterns and GenericParameter
splishsplash Have adopted the MVC Design patterns . The biggest feature of this design pattern is to separate the user interface from the back-end data calculation , It's also known as “ front end ” and “ Back end ” Separate . actually , As long as it involves GUI Or graphics program , Are almost more or less necessary MVC Design patterns .
MVC The three letters in represent Model View Controller
Model Be responsible for data calculation ,View Responsible user IO( That is, display the interface and receive user input ),Controller Be responsible for the communication between the two . adopt Controller, We completely cut off the back-end and front-end . The decoupling of the system is realized .
splishsplash Medium Model Don't need to say more , Is the main body of calculation , Think of it as FluidModel And other examples of calculation data .
View It stands for GUI, At present, the default is IMGUI.
and Controller, It is GenericParamerter This third-party library . This library is splishsplash Another project developed by the project team . stay splishsplash As a third-party library . Its purpose is to manage parameters . As long as you want to Model The parameters in and the parameters of the user interface communicate with each other , It can be GenericParameter As the parent of your current class .GenericParameter Will be responsible for and IMGUI Communicate with each other . that , For our code developers , Just need to be able to use GenericParameter Of API Can be realized with GUI Communication between .
You may ask why you want to add an intermediary , Instead of going directly to Unicom IMGUI Well ? as a result of 1)GUI There are many options for libraries ,IMGUI,TweakBar( Once the default GUI) wait . If I change GUI, Wouldn't all the code in the algorithm have to change ? So for the sake of unity API, Adding an intermediary is beneficial .2) If there is no intermediary Controller, The code of communication between the two , Or write it in the GUI In the source file of , Or write it in the source file of the algorithm , Both of them will cause very troublesome coupling problems .3) Simplified use .IMGUI There are many functions , But we only need to manage parameters here , What is superfluous is a burden for us .
therefore , Next, we only focus on this intermediary Controller( That is to say GenericParameters) Of API.
Explain how to use
Let's look at an example , Code from SurfaceTensionBase.cpp
SURFACE_TENSION = createNumericParameter("surfaceTension", "Surface tension coefficient", &m_surfaceTension);
setGroup(SURFACE_TENSION, "Surface tension");
setDescription(SURFACE_TENSION, "Coefficient for the surface tension computation");
RealParameter* rparam = static_cast<RealParameter*>(getParameter(SURFACE_TENSION));
rparam->setMinValue(0.0);
The function of this code is : Binding parameters m_surfaceTension To GUI Up ,GUI The parameters shown in are called surfaceTension.
We analyze it line by line :
first line
SURFACE_TENSION = createNumericParameter("surfaceTension", "Surface tension coefficient", &m_surfaceTension);
createNumericParameter This function is to create a numeric parameter . The name of this parameter is surfaceTension( This name also applies to json file ). Described as Surface tension coefficient, The bound parameter is m_surfaceTension( Note that the pointer is passed ). As for the integer variable returned , yes GUI Group number of . It must be a static Of ( Because static lifetime is required )
The second line
setGroup(SURFACE_TENSION, "Surface tension");
For the convenience of management , Parameters are usually grouped . This is in GUI The above effect is paging . Each group is a separate page to display .
The third line
setDescription(SURFACE_TENSION, "Coefficient for the surface tension computation");
Description displayed when the mouse hovers .
In the fourth row
RealParameter* rparam = static_cast<RealParameter*>(getParameter(SURFACE_TENSION));
Used to set the maximum and minimum value . This is to prevent users from entering incorrectly .
The fifth row
rparam->setMinValue(0.0);
Set minimum value
Let's modify the experimental effect
I've just finished talking about the principle and usage , So let's try to change something , See if the theory conforms to practice .
Change the name, description and initial value of the test
The first line is changed to
SURFACE_TENSION = createNumericParameter("thisIsName", "This is Discription", &m_surfaceTension);
Compile operation
We found that it was
Then whether it can pass json Change its parameters ? At present, the default is 0.05
We're in a json Change in
"Materials": [
{
"id": "Fluid",
"thisIsName": 1.11
}
],
function
It is found that the parameters are indeed read
Test groups
The second line is changed to
setGroup(SURFACE_TENSION, "A new group");
Compile operation
When you choose any SurfaceTension New groups will appear when the algorithm
And our previous parameter has also been moved to the new page .
Please note that : Decide whether your parameters are in the new page , Is the group of your parameters ( That is, the group number SURFACE_TENSION Determined by )
For example, the original Boundary surface tension coeff There is no new lease “A new group”
Test group description
Different from the previous one , This is a description of each variable in the Group
setDescription(SURFACE_TENSION, "This is the group discription");
Test the maximum and minimum values
The fifth line is changed to
rparam->setMinValue(1.0);
rparam->setMaxValue(5.0);
Suppose we type 0.9, Will automatically bounce back 1.0
The maximum is the same
边栏推荐
- Machine learning 11 clustering, outlier discrimination
- Redis 分布式鎖
- String class
- 6月刊 | AntDB数据库参与编写《数据库发展研究报告》 亮相信创产业榜单
- Technical secrets of ByteDance data platform: implementation and optimization of complex query based on Clickhouse
- Object. fromEntries()
- Mysql database - Advanced SQL statement (2)
- Research Report on China's enzyme Market Forecast and investment strategy (2022 Edition)
- 麦趣尔:媒体报道所涉两批次产品已下架封存,受理消费者诉求
- Shenyu gateway development: enable and run locally
猜你喜欢
Soft test network engineer full truth simulation question (including answer and analysis)
How wild are hackers' ways of making money? CTF reverse entry Guide
GameFramework食用指南
Introduction to software engineering - Chapter 6 - detailed design
PETRv2:一个多摄像头图像3D感知的统一框架
(1) CNN network structure
Basic usage of Frida
SQL question brushing 584 Looking for user references
(17) DAC conversion experiment
Shenyu gateway development: enable and run locally
随机推荐
Detailed explanation of string's trim() and substring()
多线程使用不当导致的 OOM
求求你们,别再刷 Star 了!这跟“爱国”没关系!
机器学习11-聚类,孤立点判别
In depth evaluation and development trend prediction report of China's ice cream market (2022 Edition)
Redis 分布式鎖
unity3d扩展工具栏
[C language supplement] judge which day tomorrow is (tomorrow's date)
【C语言基础】12 字符串
DNS
【牛客网刷题系列 之 Verilog快速入门】~ 优先编码器电路①
libcurl下载文件的代码示例
越来越多地使用 SLO 来实现可观测性|DevOps
中国一次性卫生用品生产设备行业深度调研报告(2022版)
String class
The difference between the lazy mode of singleton mode and the evil mode
Pyqt5, draw a histogram on the control
Redis distributed lock
Hidden Markov model (HMM): model parameter estimation
Vulnhub range hacker_ Kid-v1.0.1