*
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class TransformVertexNode : MeshProcessor
|
||||
{
|
||||
public Vector3 Offset = Vector3.zero;
|
||||
public Quaternion Rotation = Quaternion.identity;
|
||||
public Vector3 Scale = Vector3.one;
|
||||
|
||||
public override void Execute(ProceduralMeshData m){
|
||||
var transform = Matrix4x4.TRS(Offset, Rotation, Scale);
|
||||
int count = m.Vertices.Length;
|
||||
for (int i = 0; i < count; ++i){
|
||||
m.Vertices[i] = transform.MultiplyPoint3x4(m.Vertices[i]);
|
||||
}
|
||||
|
||||
var normalTransform = Matrix4x4.TRS(Vector3.zero, Rotation, Scale).inverse.transpose;
|
||||
|
||||
for (int i = 0; i < count; ++i) {
|
||||
m.Normals[i] = normalTransform.MultiplyPoint3x4(m.Normals[i]);
|
||||
}
|
||||
|
||||
if (m.Tangents != null)
|
||||
{
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
var t = normalTransform.MultiplyPoint3x4((Vector3)m.Tangents[i]);
|
||||
m.Tangents[i] = new Vector4(t.x, t.y, t.z, m.Tangents[i].w);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user