本文整理汇总了C#中UnityEngine.Mesh.RecalculateBounds方法的典型用法代码示例。如果您正苦于以下问题:C# Mesh.RecalculateBounds方法的具体用法?C# Mesh.RecalculateBounds怎么用?C# Mesh.RecalculateBounds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.Mesh
的用法示例。
在下文中一共展示了Mesh.RecalculateBounds方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FileToMesh
// Use this for initialization
public static Mesh FileToMesh(string filePath)
{
meshStruct newMesh = createMeshStruct(filePath);
populateMeshStruct(ref newMesh);
Vector3[] newVerts = new Vector3[newMesh.faceData.Length];
Vector2[] newUVs = new Vector2[newMesh.faceData.Length];
Vector3[] newNormals = new Vector3[newMesh.faceData.Length];
int i = 0;
/* The following foreach loops through the facedata and assigns the appropriate vertex, uv, or normal
* for the appropriate Unity mesh array.
*/
foreach (Vector3 v in newMesh.faceData)
{
newVerts[i] = newMesh.vertices[(int)v.x - 1];
if (v.y >= 1)
newUVs[i] = newMesh.uv[(int)v.y - 1];
if (v.z >= 1)
newNormals[i] = newMesh.normals[(int)v.z - 1];
i++;
}
Mesh mesh = new Mesh();
mesh.vertices = newVerts;
mesh.uv = newUVs;
mesh.normals = newNormals;
mesh.triangles = newMesh.triangles;
mesh.RecalculateBounds();
mesh.Optimize();
return mesh;
}
示例2: Start
public void Start()
{
_mushroom = new GameObject("Mushroom");
_mushroom.AddComponent<MeshFilter>();
_mushroom.AddComponent<MeshRenderer>();
_mesh = new Mesh();
_vertices = new List<Vector3>();
_indices = new List<int>();
_uvs = new List<Vector2>();
_mesh.Clear();
GenerateVertices();
GenerateIndices();
GenerateUvs();
//DrawVertices();
_mesh.vertices = _vertices.ToArray();
_mesh.triangles = _indices.ToArray();
_mesh.uv = _uvs.ToArray();
_mesh.RecalculateBounds();
_mesh.RecalculateNormals();
_mushroom.GetComponent<MeshFilter>().mesh = _mesh;
_mushroom.renderer.material.color = Color.grey;
}
示例3: Start
void Start()
{
// Create Vector2 vertices
Vector3[] vertices3D = new Vector3[] {
new Vector3(5, 10, 0),
new Vector3(10, -5, 0),
new Vector3(-7, -3, 0),
new Vector3(-2, -8, 0),
new Vector3(9, -10, 0),
};
// Use the triangulator to get indices for creating triangles
MidpointTriangulator tr = new MidpointTriangulator(vertices3D);
Vector3[] vertices = tr.Triangulate().ToArray();
int[] indices = new int[vertices.Length];
// Create the Vector3 vertices
for (int i = 0; i < vertices.Length; i++)
{
indices[i] = i;
}
// Create the mesh
Mesh msh = new Mesh();
msh.vertices = vertices;
msh.triangles = indices;
msh.RecalculateNormals();
msh.RecalculateBounds();
// Set up game object with mesh;
MeshFilter filter = gameObject.AddComponent(typeof(MeshFilter)) as MeshFilter;
filter.mesh = msh;
}
示例4: AddLine
void AddLine(Mesh m, Vector3[] quad, bool tmp)
{
int vl = m.vertices.Length;
Vector3[] vs = m.vertices;
if(!tmp || vl == 0) vs = resizeVertices(vs, 4);
else vl -= 4;
vs[vl] = quad[0];
vs[vl+1] = quad[1];
vs[vl+2] = quad[2];
vs[vl+3] = quad[3];
int tl = m.triangles.Length;
int[] ts = m.triangles;
if(!tmp || tl == 0) ts = resizeTraingles(ts, 6);
else tl -= 6;
ts[tl] = vl;
ts[tl+1] = vl+1;
ts[tl+2] = vl+2;
ts[tl+3] = vl+1;
ts[tl+4] = vl+3;
ts[tl+5] = vl+2;
m.vertices = vs;
m.triangles = ts;
m.RecalculateBounds();
}
示例5: CreateConvexHull
public static void CreateConvexHull(ConvexHullShape shape, Mesh mesh)
{
ShapeHull hull = new ShapeHull(shape);
hull.BuildHull(shape.Margin);
List<UnityEngine.Vector3> verts = new List<UnityEngine.Vector3>();
List<int> tris = new List<int>();
//int vertexCount = hull.NumVertices;
UIntArray indices = hull.Indices;
Vector3Array points = hull.Vertices;
for (int i = 0; i < indices.Count; i+=3)
{
verts.Add(points[(int)indices[i]].ToUnity());
verts.Add(points[(int)indices[i+1]].ToUnity());
verts.Add(points[(int)indices[i+2]].ToUnity());
tris.Add(i);
tris.Add(i + 1);
tris.Add(i + 2);
}
mesh.vertices = verts.ToArray();
mesh.triangles = tris.ToArray();
mesh.RecalculateBounds();
mesh.RecalculateNormals();
}
示例6: GenerateMesh
public Mesh GenerateMesh(Map map, float squareSize)
{
vertices = new List<Vector3>();
triangles = new List<int>();
triangleDictionary = new Dictionary<int, List<Triangle>>();
outlines = new List<List<int>>();
checkedVertices = new HashSet<int>();
squareGrid = new SquareGrid(map, squareSize);
for (int x = 0; x < squareGrid.squares.GetLength(0); x ++) {
for (int y = 0; y < squareGrid.squares.GetLength(1); y ++) {
TriangulateSquare(squareGrid.squares[x,y]);
}
}
Mesh mesh = new Mesh();
mesh.vertices = vertices.ToArray();
mesh.triangles = triangles.ToArray();
mesh.RecalculateNormals();
mesh.RecalculateBounds();
if(generateColliders) {
Generate2DColliders();
}
return mesh;
}
示例7: CreateLattice
private static Mesh CreateLattice(int meshDim)
{
Mesh m = new Mesh();
ConstructMesh(m, meshDim);
m.RecalculateBounds();
return m;
}
示例8: CloneMesh
static Mesh CloneMesh(Mesh mesh)
{
Mesh clonemesh = new Mesh();
clonemesh.vertices = mesh.vertices;
clonemesh.uv1 = mesh.uv1;
clonemesh.uv2 = mesh.uv2;
clonemesh.uv = mesh.uv;
clonemesh.normals = mesh.normals;
clonemesh.tangents = mesh.tangents;
clonemesh.colors = mesh.colors;
clonemesh.subMeshCount = mesh.subMeshCount;
for ( int s = 0; s < mesh.subMeshCount; s++ )
{
clonemesh.SetTriangles(mesh.GetTriangles(s), s);
}
//clonemesh.triangles = mesh.triangles;
clonemesh.boneWeights = mesh.boneWeights;
clonemesh.bindposes = mesh.bindposes;
clonemesh.name = mesh.name + "_copy";
clonemesh.RecalculateBounds();
return clonemesh;
}
示例9: ratio
float gr = (1.0f + Mathf.Sqrt(5.0f)) / 2.0f; //golen ratio (a+b is to a as a is to b)
#endregion Fields
#region Methods
void Start()
{
Nose = GameObject.Find("Nose");
Nose.AddComponent<MeshFilter>();
Nose.AddComponent<MeshRenderer>();
noseMesh = GetComponent<MeshFilter>().mesh;//attach mesh to nose
noseMesh.Clear();
noseMesh.vertices = new Vector3[] {//construct pyramid for nose
new Vector3( gr, 1, 0),
new Vector3( gr-1, -gr*0.6f, -gr*0.75f),
new Vector3( gr-1, -gr*0.6f, gr*0.75f),
new Vector3( gr*1.5f, -gr*0.6f, 0)};
List<int> noseTrianglesIndices = new List<int>() {//arrange triangles
0, 1, 2,
0, 3, 1,
0, 2, 3,
1, 3, 2};
noseMesh.triangles = noseTrianglesIndices.ToArray();
//Set Colour
Material material = new Material(Shader.Find("Standard"));
Color fleshtone = new Color(10, 205, 180);
material.SetColor("fleshtone", fleshtone);
Nose.GetComponent<Renderer>().material = material;
noseMesh.RecalculateBounds();
noseMesh.RecalculateNormals();
noseMesh.Optimize();
}
示例10: JoinMeshes
// todo : make extensdion method
public static Mesh JoinMeshes( Mesh first, Mesh second )
{
int newVertLength = first.vertices.Length + second.vertices.Length;
int newTriLength = first.triangles.Length + second.triangles.Length;
Vector3[] newVerts = new Vector3[ newVertLength ];
Vector2[] newUVs = new Vector2[ newVertLength ];
int[] newTris = new int[ newTriLength ];
for ( int v=0; v<newVertLength; v++ )
{
if ( v == second.vertices.Length ) break;
newVerts[ v ] = v >= first.vertices.Length ? second.vertices[ v ] : first.vertices[ v ];
newUVs[ v ] = v >= first.vertices.Length ? second.uv[ v ] : first.uv[ v ];
}
for ( int t=0; t<newTriLength; t++ )
{
if ( t == second.triangles.Length ) break;
newTris[ t ] = t >= first.triangles.Length ? second.triangles[ t ] : first.triangles[ t ];
}
Mesh newMesh = new Mesh();
newMesh.vertices = newVerts;
newMesh.uv = newUVs;
newMesh.triangles = newTris;
newMesh.RecalculateNormals();
newMesh.RecalculateBounds();
return newMesh;
}
示例11: Update
// Update is called once per frame
void Update()
{
if (!Application.isPlaying) {
triangulator = new Triangulator ();
Vector2[] vertex = polyCollider.points;
triangulator.UpdatePoints (vertex);
int[] index = triangulator.Triangulate ();
Vector3[] vertex3D = new Vector3[vertex.Length];
for (int i = 0; i < vertex.Length; i++) {
vertex3D [i] = vertex [i];
}
Vector2[] uvs = new Vector2[vertex.Length];
for (int i=0; i < uvs.Length; i++) {
uvs [i] = new Vector2 (vertex [i].x, vertex [i].y);
}
Mesh msh = new Mesh ();
msh.vertices = vertex3D;
msh.triangles = index;
msh.uv = uvs;
msh.RecalculateBounds ();
msh.RecalculateNormals ();
mshFilter.mesh = msh;
}
}
示例12: MergeMeshes
public static GameObject MergeMeshes(PaintJob[] jobs)
{
if (jobs.Length == 0)
return null;
List<CombineInstance> meshes = new List<CombineInstance>();
for (int i = 0; i < jobs.Length; ++i)
{
Mesh m = BakeDownMesh(jobs[i].meshFilter.sharedMesh, jobs[i].stream);
CombineInstance ci = new CombineInstance();
ci.mesh = m;
ci.transform = jobs[i].meshFilter.transform.localToWorldMatrix;
meshes.Add(ci);
}
Mesh mesh = new Mesh();
mesh.CombineMeshes(meshes.ToArray());
GameObject go = new GameObject("Combined Mesh");
go.AddComponent<MeshRenderer>();
var mf = go.AddComponent<MeshFilter>();
mesh.Optimize();
mesh.RecalculateBounds();
mesh.UploadMeshData(false);
mf.sharedMesh = mesh;
for (int i = 0; i < meshes.Count; ++i)
{
GameObject.DestroyImmediate(meshes[i].mesh);
}
return go;
}
示例13: CreateMesh
public static void CreateMesh()
{
Mesh mesh = new Mesh();
Vector3[] vertices = new Vector3[] {
Vector3.zero, // lowerLeft
new Vector3(0,0,1080), //upperLeft
new Vector3(1920,0,1080), //upperRight
new Vector3(1920,0,0), // lowerRight
};
Vector2[] uv = new Vector2[] {
new Vector2(0,0),
new Vector2(0,1),
new Vector2(1,1),
new Vector2(1,0)
};
mesh.vertices = vertices;
mesh.uv = uv;
mesh.triangles = new int[] {
0,1,2,
0,2,3,
};
mesh.RecalculateNormals();
mesh.RecalculateBounds();
AssetDatabase.CreateAsset(mesh, "Assets/AntsVsMice/Levels/boardMesh.asset");
AssetDatabase.SaveAssets ();
}
示例14: Go
public static void Go()
{
Mesh mesh = new Mesh();
mesh.vertices = new Vector3[]{
new Vector3(-0.5f, -0.5f, 1),
new Vector3(+0.5f, -0.5f, 1),
new Vector3(-0.5f, +0.5f, 0),
new Vector3(+0.5f, +0.5f, 0)
};
mesh.uv = new Vector2[]{
new Vector2(0, 0),
new Vector2(1, 0),
new Vector2(0, 1),
new Vector2(1, 1)
};
mesh.triangles = new int[]{
0, 2, 1,
2, 3, 1
};
mesh.RecalculateNormals();
mesh.RecalculateBounds();
AssetDatabase.CreateAsset(mesh, "Assets/Angled Plane.asset");
}
示例15: UpdateCollisionMesh
/// <summary>
/// Manually recalculates the collision mesh of the skinned mesh on this object.
/// </summary>
public void UpdateCollisionMesh()
{
Mesh mesh = new Mesh();
Vector3[] newVert = new Vector3[skinnedMeshRenderer.sharedMesh.vertices.Length];
// Now get the local positions of all weighted indices...
foreach ( CWeightList wList in nodeWeights )
{
foreach ( CVertexWeight vw in wList.weights )
{
newVert[vw.index] += wList.transform.localToWorldMatrix.MultiplyPoint3x4( vw.localPosition ) * vw.weight;
}
}
// Now convert each point into local coordinates of this object.
for ( int i = 0 ; i < newVert.Length ; i++ )
{
newVert[i] = transform.InverseTransformPoint( newVert[i] );
}
// Update the mesh ( collider) with the updated vertices
mesh.vertices = newVert;
mesh.uv = skinnedMeshRenderer.sharedMesh.uv; // is this even needed here?
mesh.triangles = skinnedMeshRenderer.sharedMesh.triangles;
mesh.RecalculateBounds();
mesh.MarkDynamic(); // says it should improve performance, but I couldn't see it happening
meshCollider.sharedMesh = mesh;
}