当前位置: 首页 > news >正文

建设购物网站的目的抖音seo怎么做的

建设购物网站的目的,抖音seo怎么做的,无人在线直播免费观看,新公司简介模板范文序之前,生成了地形图:(42条消息) 从灰度图到地形图_averagePerson的博客-CSDN博客那末,地形的法线贴图怎么获取?大概分为两个部分吧,先拿到法线数据,再画到纹理中去。关于法线计算Unity - Scripting API: M…

之前,生成了地形图:(42条消息) 从灰度图到地形图_averagePerson的博客-CSDN博客

那末,地形的法线贴图怎么获取?

大概分为两个部分吧,先拿到法线数据,再画到纹理中去。

关于法线

计算

Unity - Scripting API: Mesh.RecalculateNormals (unity3d.com)

这个链接讲的是法线的计算,它是什么空间下的?无所谓了……

这里也不对地形搞什么几何变换,而且它是方向,模型空间世界空间是一个结果。

获取

Unity - Scripting API: Mesh.normals (unity3d.com)

直接一个等于号,然后这个法线是对顶点不是对三角形面片。

就这两点,没了。

存到纹理中

构造

Unity - Scripting API: Texture2D (unity3d.com)

这个变量,好像在unity shader里也经常出现嘞

要把法线数据存到Texture2D里,首先得构造一下对象啊,构造函数是什么?

Unity - Scripting API: Texture2D.Texture2D (unity3d.com)

RGBA32,构造RenderTexture的时候也有你。

怎么赋值?

赋值

Unity - Scripting API: Texture2D.SetPixels (unity3d.com)

  1. 直接传数组

  1. 数组要展平【mesh.normals其实就是一维的,那就可以直接用了】

  1. 最后需要Apply

  1. 从左到右从下到上【地形顶点正好也是这个顺序的】

官方示例代码:

using UnityEngine;
using System.Collections;public class ExampleClass : MonoBehaviour
{void Start(){Renderer rend = GetComponent<Renderer>();// duplicate the original texture and assign to the materialTexture2D texture = Instantiate(rend.material.mainTexture) as Texture2D;rend.material.mainTexture = texture;// colors used to tint the first 3 mip levelsColor[] colors = new Color[3];colors[0] = Color.red;colors[1] = Color.green;colors[2] = Color.blue;int mipCount = Mathf.Min(3, texture.mipmapCount);// tint each mip levelfor (int mip = 0; mip < mipCount; ++mip){Color[] cols = texture.GetPixels(mip);for (int i = 0; i < cols.Length; ++i){cols[i] = Color.Lerp(cols[i], colors[mip], 0.33f);}texture.SetPixels(cols, mip);}// actually apply all SetPixels, don't recalculate mip levelstexture.Apply(false);}
}

试一试

根据文档,调api就行了。

代码

计算法线的

using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class Terrian : MonoBehaviour
{public int N = 10;public Texture2D texture2dHeightMap;[Range(1,100)]public float heightRatio = 30.0f;//一个系数,控制地形总体的高度的public Texture2D normalTex;MeshRenderer meshRenderer;MeshFilter meshFilter;// 用来存放顶点数据List<Vector3> verts;List<int> indices;Vector3[] normals;private void Awake(){}private void Start(){verts = new List<Vector3>();indices = new List<int>();meshRenderer = GetComponent<MeshRenderer>();meshFilter = GetComponent<MeshFilter>();//normalTex = new Texture2D(texture2dHeightMap.width, texture2dHeightMap.height, TextureFormat.RGB24,-1,false);normalTex = new Texture2D(N,N, TextureFormat.RGB24, -1, false);//2.5D的地形,顶点的法线,法线贴图规模不是灰度图规模}private void Update(){Generate();normals = new Vector3[N * N];normals = meshFilter.mesh.normals;for(int i = 0; i < 10; ++i){print(normals[i]);}Color[] colors = new Color[N * N];for(int i = 0; i < N * N; ++i){colors[i] = new Color(normals[i].x, normals[i].y, normals[i].z);}normalTex.SetPixels(colors);normalTex.Apply(false);}public void Generate(){ClearMeshData();// 把数据填写好AddMeshData();// 把数据传递给Mesh,生成真正的网格Mesh mesh = new Mesh();mesh.vertices = verts.ToArray();mesh.triangles = indices.ToArray();mesh.RecalculateNormals();mesh.RecalculateBounds();meshFilter.mesh = mesh;}void ClearMeshData(){verts.Clear();indices.Clear();}void AddMeshData(){//01填充顶点数据for (int z = 0; z < N; ++z)//按先x后z的顶点排列顺序,所以先循环的是z{for(int x = 0; x < N; ++x){int u = Mathf.FloorToInt(1.0f * x / N * texture2dHeightMap.width);int v = Mathf.FloorToInt(1.0f * z / N * texture2dHeightMap.height);float grayValue = texture2dHeightMap.GetPixel(u,v).grayscale;float height = grayValue*heightRatio;Vector3 temp = new Vector3(x, height, z);verts.Add(temp);}}//02填充索引数据for(int z = 0; z < N - 1; ++z){for(int x = 0; x < N - 1; ++x){int index_lb = z * N + x;//index of the left bottom vertex. lb = left bottomint index_lt = (z + 1) * N + x;int index_rt = (z + 1) * N + x + 1;int index_rb = z * N + x + 1;indices.Add(index_lb);indices.Add(index_lt);indices.Add(index_rt);indices.Add(index_rt);indices.Add(index_rb);indices.Add(index_lb);}}}}

显示法线贴图的。这个是在摄像机上的——屏幕后处理嘛!

using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class ShowTexture2D : MonoBehaviour
{public Terrian terrian;// Start is called before the first frame updatevoid Start(){}// Update is called once per framevoid Update(){}private void OnRenderImage(RenderTexture source, RenderTexture destination){Graphics.Blit(terrian.normalTex, destination);}}

结果

看着……走势差不多吧。而且,绿色的,表示向上,符合的。

对不对?在这种情况下,没法看出来。只能接着往下做,然后拔出萝卜带出泥巴。

纯平面是纯绿色

高度系数越大,颜色越深

http://www.rdtb.cn/news/21313.html

相关文章:

  • 网站如何重新备案外链吧
  • 兰州做it网站运营的怎么样百度高级搜索页面
  • vs2010做网站时间控件友情链接检查工具
  • wordpress上传本地主题seo优化推广专员招聘
  • 做各国民宿租赁的网站seo优化的方法有哪些
  • 做彩票网站犯法如何制作链接推广
  • 如何做外贸网站外贸网站制作公司
  • 怎么选择网站模板qq推广链接生成
  • 制作u盘启动盘seo网络优化专员
  • 望京 网站建设怎么做业务推广技巧
  • ps做素材下载网站专门发广告的app
  • 网站域名申请费用注册安全工程师
  • 柳州市建委网站国内最新的新闻
  • 沈阳网站建设的价格百度发布平台官网
  • 大兴做网站建设制作网站建设公司
  • 镇江网站制作sem优化是什么
  • 专业外贸网站建设百度站长工具平台登录
  • 怎么用宝塔做网站免费html网站制作成品
  • 网站开发图片素材wordpress建站
  • 怎么查询公司的注册信息seo网络营销的技术
  • 做标书有哪些网站能接到好口碑关键词优化
  • 十大景观设计公司排名seo这个职位是干什么的
  • 深圳网站制作的公司制作自己的网页
  • 楚雄市住房和城乡建设局网站互联网营销的方式有哪些
  • 阿里巴巴上怎样做自己的网站怎样创建自己的网站
  • 做网站海报央视新闻今天的内容
  • 深圳罗湖做网站东莞seo建站咨询
  • 农村自建房设计图及效果图福州短视频seo推荐
  • 免费域名注册微信下载广东企业网站seo哪里好
  • 兰州又发现一例郴州网站seo