rope处理
This commit is contained in:
89
Assets/Scripts/PhysicsTools/LinkMesh.cs
Normal file
89
Assets/Scripts/PhysicsTools/LinkMesh.cs
Normal file
@@ -0,0 +1,89 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace PhysicsTools
|
||||
{
|
||||
[Serializable]
|
||||
public class LinkMesh
|
||||
{
|
||||
[HideInInspector]
|
||||
public Mesh modifiedMesh;
|
||||
|
||||
[HideInInspector]
|
||||
public Matrix4x4 transform;
|
||||
|
||||
[HideInInspector]
|
||||
public Mesh defaultMesh;
|
||||
|
||||
[HideInInspector]
|
||||
public Material defaultMeshMaterial;
|
||||
|
||||
[HideInInspector]
|
||||
public Matrix4x4 defaultTransform;
|
||||
|
||||
public Mesh mesh;
|
||||
|
||||
public Material meshMaterial;
|
||||
|
||||
public Vector3 position;
|
||||
|
||||
public Vector3 rotation;
|
||||
|
||||
public Vector3 scale;
|
||||
|
||||
public LinkMesh()
|
||||
{
|
||||
mesh = null;
|
||||
position = new Vector3(0f, 0f, 0f);
|
||||
rotation = new Vector3(0f, 0f, 0f);
|
||||
scale = new Vector3(1f, 1f, 1f);
|
||||
defaultTransform = default(Matrix4x4);
|
||||
defaultTransform.SetTRS(position, Quaternion.Euler(rotation), scale);
|
||||
transform = default(Matrix4x4);
|
||||
transform.SetTRS(position, Quaternion.Euler(rotation), scale);
|
||||
}
|
||||
|
||||
public void update()
|
||||
{
|
||||
if (mesh == null)
|
||||
{
|
||||
mesh = defaultMesh;
|
||||
transform = defaultTransform;
|
||||
Quaternion rot;
|
||||
Utility.MatrixToTRS(transform, out position, out rot, out scale);
|
||||
rotation = rot.eulerAngles;
|
||||
}
|
||||
if (mesh != null)
|
||||
{
|
||||
modifiedMesh = UnityEngine.Object.Instantiate(mesh);
|
||||
}
|
||||
if (modifiedMesh != null)
|
||||
{
|
||||
transform.SetTRS(position, Quaternion.Euler(rotation), scale);
|
||||
ScaleMesh();
|
||||
}
|
||||
}
|
||||
|
||||
public void ScaleMesh()
|
||||
{
|
||||
Vector3[] vertices = modifiedMesh.vertices;
|
||||
for (int i = 0; i < vertices.Length; i++)
|
||||
{
|
||||
Vector3 point = vertices[i];
|
||||
point = transform.MultiplyPoint(point);
|
||||
vertices[i] = point;
|
||||
}
|
||||
modifiedMesh.vertices = vertices;
|
||||
}
|
||||
|
||||
public Mesh getMesh()
|
||||
{
|
||||
return modifiedMesh;
|
||||
}
|
||||
|
||||
public Material getMaterial()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user