国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

Unity描邊平滑法線存UV7腳本



using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using UnityEditor;


public class SmoothNormals : MonoBehaviour

{


? ? private Renderer[] allRenderers;


? ? public struct NormalWeight {

? ? ? ? public Vector3 normal;

? ? ? ? public float weight;

? ? }


#if UNITY_EDITOR

? ? void OnValidate()

? ? {

? ? ? ? void SmoothNormals(Mesh mesh)

? ? ? ? {

? ? ? ? ? ? Dictionary<Vector3, List<NormalWeight>> normalDict = new Dictionary<Vector3, List<NormalWeight>>();

? ? ? ? ? ? var triangles = mesh.triangles;

? ? ? ? ? ? var vertices = mesh.vertices;

? ? ? ? ? ? var normals = mesh.normals;

? ? ? ? ? ? var tangents = mesh.tangents;

? ? ? ? ? ? var smoothNormals = mesh.normals;


? ? ? ? ? ? for (int i = 0; i < triangles.Length - 3; i += 3)

? ? ? ? ? ? {

? ? ? ? ? ? ? ? int[] triangle = new int[] {triangles[i], triangles[i+1], triangles[i+2]};

? ? ? ? ? ? ? ? for (int j = 0; j < 3; j++)

? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? int vertexIndex = triangle[j];

? ? ? ? ? ? ? ? ? ? Vector3 vertex = vertices[vertexIndex];

? ? ? ? ? ? ? ? ? ? if (!normalDict.ContainsKey(vertex))

? ? ? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? ? ? normalDict.Add(vertex, new List<NormalWeight>());

? ? ? ? ? ? ? ? ? ? }


? ? ? ? ? ? ? ? ? ? NormalWeight nw;

? ? ? ? ? ? ? ? ? ? nw.normal = normals[vertexIndex];

? ? ? ? ? ? ? ? ? ? Vector3 lineA = Vector3.zero;

? ? ? ? ? ? ? ? ? ? Vector3 lineB = Vector3.zero;

? ? ? ? ? ? ? ? ? ? if (j == 0)

? ? ? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? ? ? lineA = vertices[triangle[1]] - vertex;

? ? ? ? ? ? ? ? ? ? ? ? lineB = vertices[triangle[2]] - vertex;

? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? ? ? else if (j == 1)

? ? ? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? ? ? lineA = vertices[triangle[0]] - vertex;

? ? ? ? ? ? ? ? ? ? ? ? lineB = vertices[triangle[2]] - vertex;

? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? ? ? else

? ? ? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? ? ? lineA = vertices[triangle[0]] - vertex;

? ? ? ? ? ? ? ? ? ? ? ? lineB = vertices[triangle[1]] - vertex;

? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? ? ? float angle = Mathf.Acos(Mathf.Max(Mathf.Min(Vector3.Dot(lineA, lineB)/(lineA.magnitude ?* lineB.magnitude), 1), -1));

? ? ? ? ? ? ? ? ? ? nw.weight = angle;

? ? ? ? ? ? ? ? ? ? normalDict[vertex].Add(nw);

? ? ? ? ? ? ? ? }

? ? ? ? ? ? }


? ? ? ? ? ? for (int i = 0; i < vertices.Length; i++) {

? ? ? ? ? ? ? ? Vector3 vertex = vertices[i];

? ? ? ? ? ? ? ? List<NormalWeight> normalList = normalDict[vertex];


? ? ? ? ? ? ? ? Vector3 smoothNormal = Vector3.zero;

? ? ? ? ? ? ? ? float weightSum = 0;

? ? ? ? ? ? ? ? for (int j = 0; j < normalList.Count; j++)

? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? NormalWeight nw = normalList[j];

? ? ? ? ? ? ? ? ? ? weightSum += nw.weight;

? ? ? ? ? ? ? ? }


? ? ? ? ? ? ? ?

? ? ? ? ? ? ? ? for (int j = 0; j < normalList.Count; j++)

? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? NormalWeight nw = normalList[j];

? ? ? ? ? ? ? ? ? ? smoothNormal += nw.normal * nw.weight/weightSum;

? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ?


? ? ? ? ? ? ? ? smoothNormal = smoothNormal.normalized;

? ? ? ? ? ? ? ? smoothNormals[i] = smoothNormal;

? ? ? ? ? ? ? ?

? ? ? ? ? ? ? ? var normal = normals[i];

? ? ? ? ? ? ? ? var tangent = tangents[i];

? ? ? ? ? ? ? ? var binormal = (Vector3.Cross(normal, tangent) * tangent.w).normalized;

? ? ? ? ? ? ? ? var tbn = new Matrix4x4(tangent, binormal, normal, Vector3.zero);

? ? ? ? ? ? ? ? tbn = tbn.transpose;

? ? ? ? ? ? ? ? smoothNormals[i] = tbn.MultiplyVector(smoothNormals[i]).normalized;

? ? ? ? ? ? }

? ? ? ? ? ? mesh.SetUVs(7, smoothNormals);

? ? ? ? }


? ? ? ? foreach (var item in GetComponentsInChildren<MeshFilter>())

? ? ? ? {

? ? ? ? ? ? SmoothNormals(item.sharedMesh);

? ? ? ? }

? ? ? ? foreach (var item in GetComponentsInChildren<SkinnedMeshRenderer>())

? ? ? ? {

? ? ? ? ? ? SmoothNormals(item.sharedMesh);

? ? ? ? }

? ? }

#endif

}

AppData
Vertex Shader


Unity描邊平滑法線存UV7腳本的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國家法律
古田县| 土默特右旗| 西和县| 阳新县| 都安| 南投市| 辉县市| 米泉市| 曲阜市| 前郭尔| 永寿县| 涪陵区| 山西省| 龙南县| 璧山县| 深水埗区| 突泉县| 孟州市| 新龙县| 西和县| 新邵县| 丹棱县| 岐山县| 玉龙| 江华| 海安县| 合肥市| 会昌县| 郎溪县| 安溪县| 蒙城县| 溧水县| 扎鲁特旗| 松江区| 河津市| 体育| 定结县| 芦山县| 泸西县| 洪湖市| 桦南县|