当前位置:网站首页>Method of establishing unity thermodynamic diagram
Method of establishing unity thermodynamic diagram
2022-06-24 14:09:00 【Xiaosheng yunmu】
Unity Method of establishing thermodynamic diagram
Realization effect
The basic idea
The method of generating thermal maps by assigning colors to mesh vertices has been written before . There is one big drawback , Requires a large number of grid points to support , Improved GPU Rendering pressure . So I changed my mind , Directly create and modify the color of picture pixels , In this way, a mesh with only four vertices can be used to generate thermal maps .
Before calculation fbs→97.5

After calculation fbs→96.5

Basically unaffected .
Problems and Solutions
Conversion of world coordinates and pixel coordinates ;
Initialization of pixels and weighted values of pixels ;
Configuration of the relationship between the color of the color block and the influence range ;
Adjustment of resolution and performance .
Conversion of world coordinates and pixel coordinates
Here are two points of attention , The first is the pivot point of the grid , Two is uv The axis of coordinates . The origin of the grid is specified by the model art , But when the world coordinates are converted to pixel coordinates , The origin needs to correspond to , So I want to change the origin of the mesh . There are two ways to change the origin ,1. Let the art modify , Change the origin of the mesh to uv Origin of coordinate system ;2. Add a parent object to the mesh , The position of the parent object is in the uv Coordinate origin . As shown in the figure below


After the origin is aligned , It is only necessary to ask for a proportion .
Vector3 modelSize = gameObject.GetComponent<Collider>().bounds.size;
float MapRatio = heatMapBase.Resolution / modelSize.x;
//heatMapBase.Resolution Is the defined picture pixel resolution .
//MapRatio Is the scale of the transformation between picture coordinates and world coordinates
Initialization of pixels and weighted values of pixels
Before running, the weight of all pixels should be reset to zero . The weighted reference points will affect the surrounding pixels , The scope of influence is related to its own weight , You can also introduce a variable here DisRatio, Used to change the influence range of the weight . When the pixel is weighted , Only values can override small values .
// Each pixel is initialized
List<Vector2> my_Pixels = new List<Vector2>();
List<float> my_Values = new List<float>();
for (int y = 0; y < texture.height; y++)
{
for (int x = 0; x < texture.width; x++)
{
Vector2 pixel = new Vector2(x, y);
my_Pixels.Add(pixel);
my_Values.Add(0);
}
}
int allLength = my_Pixels.Count;// So the number of pixels
int pointLength = heatMapInfos.Count;// Number of points of interest in the heat map
int colorLength = heatMapBase.HeatMapInfos.Count;// Color block grade
// Weighted value per pixel
for (int p = 0; p < pointLength; p++)
{
for (int a = 0; a < allLength; a++)
{
float my_Distance = Vector2.Distance(heatMapInfos[p].Pixel* MapRatio, my_Pixels[a]);
float my_MaxDis = heatMapBase.DisRatio * heatMapInfos[p].Amount;
if (my_Distance < my_MaxDis)
{
float value = (1 - (Mathf.Pow(my_Distance, 2) / Mathf.Pow(my_MaxDis, 2))) * heatMapInfos[p].Amount;
if (value > my_Values[a])
{
my_Values[a] = value;
}
}
}
}
Configuration of the relationship between the color of the color block and the influence range
Color selection of color block , A weight , The image resolution and influence range can be dynamically configured . A template is added here to control . For the convenience of pixel color assignment , Specify the weight from large to small .

public class HeatMapBase : ScriptableObject
{
public float DisRatio;// Distance ratio
public float Resolution;// The resolution of the
public List<HeatMapInfo> HeatMapInfos;
[Serializable]
public class HeatMapInfo
{
public float MaxAmount;// Maximum weight
public Color Color;// Color
}
}
Adjustment of resolution and performance
At the beginning of writing , Consider dynamically changing the resolution , The larger the mesh, the greater the resolution . But this undoubtedly increases the consumption of performance . So consider writing the resolution into the configuration table . Instead, a wide range of jagged images appear, as shown in the following figure . I've introduced color Interpolation operation of , Solve the problem perfectly .
No interpolation

Additive interpolation

// Each pixel is assigned a color
for (int i = 0; i < allLength; i++)
{
for (int j = 0; j < colorLength; j++)
{
float my_CurMaxAmount = heatMapBase.HeatMapInfos[j].MaxAmount;
if (my_Values[i] >= my_CurMaxAmount)
{
// The color of the current block
Color my_CurColor = heatMapBase.HeatMapInfos[j].Color;
if (j != 0)
{
float my_UpDiffValue = heatMapBase.HeatMapInfos[j - 1].MaxAmount - my_CurMaxAmount;
Color my_UpColor = heatMapBase.HeatMapInfos[j - 1].Color;
float t = (my_Values[i] - my_CurMaxAmount) / my_UpDiffValue;
texture.SetPixel((int)my_Pixels[i].x, (int)my_Pixels[i].y, Color.Lerp(my_CurColor, my_UpColor, t));
break;
}
else
{
texture.SetPixel((int)my_Pixels[i].x, (int)my_Pixels[i].y, my_CurColor);
break;
}
}
}
}
边栏推荐
- 项目经理搭建团队,需要看6个特征
- Zhiyuan community weekly 86: Gary Marcus talks about three linguistic factors that can be used for reference in large model research; Google puts forward the Wensheng graph model parti which is compar
- Redis面试题
- AQS初探
- 杰理之在所有模式下打开喊话增加 mic 自动 mute【篇】
- 4个不可不知的“安全左移”的理由
- HarmonyOS.2
- 百度地图API绘制点及提示信息
- [R language data science] (XIV): random variables and basic statistics
- 数学之英文写作——基本中英文词汇(几何与三角的常用词汇)
猜你喜欢

Second, the examinee must see | consolidate the preferred question bank to help the examinee make the final dash

Solution of channel management system for food and beverage industry: realize channel digital marketing layout
![Jerry's serial port receiving IO needs to set the digital function [chapter]](/img/04/48e7da42101a53827463d479952f67.png)
Jerry's serial port receiving IO needs to set the digital function [chapter]

HarmonyOS.2

快手实时数仓保障体系研发实践

Antd checkbox, limit the selected quantity

一键生成大学、专业甚至录取概率,AI填报志愿卡这么神奇?

Kunpeng arm server compilation and installation paddlepaddle

AntD checkbox,限制选中数量

#21Set经典案例
随机推荐
Halcon draw area into picture
知识经济时代,教会你做好知识管理
Kotlin composite suspend function
How to solve the problem that iterative semi supervised training is difficult to implement in ASR training? RTC dev Meetup
Operation of simulated test question bank and simulated test platform for safety production management personnel of fireworks and firecrackers production units in 2022
A review of text contrastive learning
谷歌WayMo提出R4D: 采用参考目标做远程距离估计
HarmonyOS. two
Daily question 8-515 Find the maximum value in each tree row
2022年江西省安全员B证考试题库模拟考试平台操作
Operation of simulated examination platform for examination questions of coal production and operation units (safety production management personnel) in 2022
One click to generate University, major and even admission probability. Is it so magical for AI to fill in volunteer cards?
Jerry added an input capture channel [chapter]
Promotion of Project Manager
2022 Quality Officer - Equipment direction - post skills (Quality Officer) recurrent training question bank and online simulation examination
鲲鹏arm服务器编译安装PaddlePaddle
食品饮料行业渠道商管理系统解决方案:实现渠道数字化营销布局
Jericho turns on shouting in all modes to increase mic automatic mute [chapter]
Harmony os. (2)
2022年氟化工艺考试模拟100题及答案
