本文整理汇总了C#中UnityEngine.Mesh.CombineMeshes方法的典型用法代码示例。如果您正苦于以下问题:C# Mesh.CombineMeshes方法的具体用法?C# Mesh.CombineMeshes怎么用?C# Mesh.CombineMeshes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.Mesh
的用法示例。
在下文中一共展示了Mesh.CombineMeshes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CombineMeshes
public static void CombineMeshes(Queue<CombineInstance> items
, byte area
, InputGeometryCompiler compiler)
{
const int MaxTris = 65000;
List<CombineInstance> combineInstancesPart = new List<CombineInstance>();
byte[] areas = NMGen.CreateAreaBuffer(MaxTris, area);
while (items.Count != 0)
{
int vertCount = 0;
while (items.Count > 0
&& (vertCount + items.Peek().mesh.vertexCount < MaxTris))
{
vertCount += items.Peek().mesh.vertexCount;
combineInstancesPart.Add(items.Dequeue());
}
Mesh meshPart = new Mesh();
meshPart.CombineMeshes(combineInstancesPart.ToArray(), true, true);
compiler.AddTriangles(meshPart.vertices, meshPart.vertexCount
, meshPart.triangles, areas, meshPart.triangles.Length / 3);
Object.DestroyImmediate(meshPart);
combineInstancesPart.Clear();
}
}
示例2: LateUpdate
protected virtual void LateUpdate()
{
if(_hasRenderer)
return;
_hasRenderer = true;
foreach (KeyValuePair<Material, List<PCTrail>> keyValuePair in _matToTrailList)
{
CombineInstance[] combineInstances = new CombineInstance[keyValuePair.Value.Count];
for (int i = 0; i < keyValuePair.Value.Count; i++)
{
combineInstances[i] = new CombineInstance
{
mesh = keyValuePair.Value[i].Mesh,
subMeshIndex = 0,
transform = Matrix4x4.identity
};
}
Mesh combinedMesh = new Mesh();
combinedMesh.CombineMeshes(combineInstances, true, false);
_toClean.Add(combinedMesh);
DrawMesh(combinedMesh, keyValuePair.Key);
keyValuePair.Value.Clear();
}
}
示例3: GetCollider
public override Collider GetCollider(GameObject parent, Vector3 pos) {
//Get mesh filters
MeshFilter[] meshFilters = GetPrefab().GetComponentsInChildren<MeshFilter>();
CombineInstance[] meshes = new CombineInstance[meshFilters.Length];
//Add meshes to array
for (int i = 0; i < meshes.Length; i++) {
meshes[i].mesh = meshFilters[i].sharedMesh;
meshes[i].transform = meshFilters[i].transform.localToWorldMatrix;
}
//Combine meshes
Mesh mesh = new Mesh();
mesh.CombineMeshes(meshes);
//Add position and rotate
Vector3[] verticies = mesh.vertices;
for (int i = 0; i < verticies.Length; i++) {
verticies[i] += pos;
verticies[i] = Quaternion.Euler(90, 0, 0) * verticies[i];
}
mesh.vertices = verticies;
//Create mesh collider
MeshCollider coll = parent.AddComponent<MeshCollider>();
coll.sharedMesh = mesh;
return coll;
}
示例4: 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;
}
示例5: FuseToChunkMesh
public Mesh FuseToChunkMesh(MeshFilter ChunkMesh, MeshFilter[] NewMeshes, Vector3 ChunkPos, bool Restart = true)
{
//store old positions
foreach (MeshFilter filter in NewMeshes)
{
filter.transform.position -= ChunkPos;
}
ChunkMesh.transform.position = Vector3.zero;
CombineInstance[] combine = new CombineInstance[NewMeshes.Length + 1];
List<MeshFilter> MeshList = new List<MeshFilter>(NewMeshes);
for (int i = 0; i < combine.Length - 1; i++)
{
combine[i].mesh = MeshList[i].sharedMesh;
combine[i].transform = MeshList[i].transform.localToWorldMatrix;
DestroyImmediate(MeshList[i].gameObject);
}
MeshList.Add(ChunkMesh);
combine[NewMeshes.Length].mesh = MeshList[NewMeshes.Length].sharedMesh;
combine[NewMeshes.Length].transform = MeshList[NewMeshes.Length].transform.localToWorldMatrix;
Mesh m = new Mesh();
m.CombineMeshes(combine, true, true);
ChunkMesh.transform.position = ChunkPos;
return m;
}
示例6: CreateMesh
public Mesh CreateMesh()
{
Mesh m = new Mesh
{
vertices = Vertices.ToArray(),
uv = UV1.ToArray(),
uv2 = UV2.ToArray(),
triangles = Triangles.ToArray(),
colors = Colors.ToArray()
};
if(Submeshes.Count > 0)
{
CombineInstance[] instances = new CombineInstance[Submeshes.Count];
for(int i = 0; i < Submeshes.Count; i++)
{
CombineInstance ins = new CombineInstance
{
mesh = Submeshes[i].CreateMesh(),
transform = Matrix4x4.identity
};
instances[i] = ins;
}
m.CombineMeshes(instances, false);
}
m.RecalculateNormals();
m.RecalculateBounds();
m.Optimize();
return m;
}
示例7: BaselessPyramid
public static Mesh BaselessPyramid(Vector3 baseCenter, Vector3 apex, float radius, int segments,
bool inverted = false)
{
var segmentAngle = Mathf.PI*2/segments;
var currentAngle = 0f;
var v = new Vector3[segments + 1];
v[0] = apex;
for (var i = 1; i <= segments; i++)
{
v[i] = new Vector3(radius*Mathf.Sin(currentAngle), 0,
radius*Mathf.Cos(currentAngle)) + baseCenter;
if (inverted) currentAngle -= segmentAngle;
else currentAngle += segmentAngle;
}
var combine = new CombineInstance[segments];
for (var i = 0; i < segments - 1; i++)
{
combine[i].mesh = Triangle(v[0], v[i + 1], v[i + 2]);
}
combine[combine.Length - 1].mesh = Triangle(v[0], v[v.Length - 1], v[1]);
var mesh = new Mesh();
mesh.CombineMeshes(combine, true, false);
return mesh;
}
示例8: CombinedMeshes
public Mesh[] CombinedMeshes(List<Mesh> meshObjectList)
{
List<Mesh> meshs = new List<Mesh>();
// combine meshes
List<CombineInstance> combine = new List<CombineInstance>();
int i = 0;
while (i < meshObjectList.Count)
{
CombineInstance instance = new CombineInstance();
instance.mesh = meshObjectList[i];
instance.transform = transform.localToWorldMatrix;
combine.Add(instance);
i++;
}
Mesh combinedMesh = new Mesh();
combinedMesh.CombineMeshes(combine.ToArray());
meshs.Add(combinedMesh);
combine = new List<CombineInstance>();
return meshs.ToArray();
}
示例9: PolygonizeContours
// Returns a flat 3D polygonized mesh from 2D outer/inner contours
public static Mesh PolygonizeContours( List<Contour> a_rDominantContoursList, float a_fScale, Vector3 a_f3PivotPoint, float a_fWidth, float a_fHeight )
{
// The mesh to build
Mesh oCombinedMesh = new Mesh( );
int iContourCount = a_rDominantContoursList.Count; //a_rDominantContoursList.Count;
// Step 2: Ear clip outer contour
CombineInstance[ ] oCombineMeshInstance = new CombineInstance[ iContourCount ];
for( int iContourIndex = 0; iContourIndex < iContourCount; ++iContourIndex )
{
Vector3[ ] oVerticesArray;
int[ ] oTrianglesArray;
Vector2[ ] oUVs;
Mesh oSubMesh = new Mesh( );
EarClipping( a_rDominantContoursList[ iContourIndex ], a_fScale, a_f3PivotPoint, a_fWidth, a_fHeight, out oVerticesArray, out oTrianglesArray, out oUVs );
oSubMesh.vertices = oVerticesArray;
oSubMesh.uv = oUVs;
oSubMesh.triangles = oTrianglesArray;
oCombineMeshInstance[ iContourIndex ].mesh = oSubMesh;
}
// Step 3: Combine every sub meshes (merge, no transform)
oCombinedMesh.CombineMeshes( oCombineMeshInstance, true, false );
// Return!
return oCombinedMesh;
}
示例10: Write
public void Write(SceneWriter writer, object component)
{
Component script = component as Component;
if (script == null)
{
throw new Exception(GetType() + " cannot export components of type " + component.GetType());
}
MeshFilter[] meshFilters = script.GetComponentsInChildren<MeshFilter>();
CombineInstance[] combine = new CombineInstance[meshFilters.Length];
for ( int i = 0; i < meshFilters.Length; i++) {
combine[i].mesh = meshFilters[i].sharedMesh;
combine[i].transform = meshFilters[i].transform.localToWorldMatrix;
}
Mesh mesh = new Mesh();
mesh.CombineMeshes(combine);
MeshRenderer mr = script.GetComponentInChildren<MeshRenderer>();
writer.WriteElement("sharedMaterials", mr.sharedMaterials);
writer.WriteElement("triangles", mesh.triangles);
writer.WriteElement("vertices", mesh.vertices);
//writer.WriteElement("normals", mesh.normals);
writer.WriteElement("uv", mesh.uv);
Debug.Log(script.name + " batched " + combine.Length + " objects into a mesh of " + (mesh.triangles.Length / 3) + " triangles and " + mesh.vertices.Length + " vertices.");
if (mesh.vertices.Length > short.MaxValue)
{
Debug.LogWarning("BATCHED TOO MANY TRIANGLES!!");
}
}
示例11: EarClipping
// Return a polygonized mesh from 2D outer/inner contours
public static Mesh EarClipping( List<Contour> a_rDominantContoursList, float a_fExtrusionDepth, float a_fScale, Vector3 a_f3PivotPoint )
{
// The mesh to build
Mesh oCombinedMesh = new Mesh( );
int iContourCount = a_rDominantContoursList.Count; //a_rDominantContoursList.Count;
// Step 2: Ear clip outer contour
CombineInstance[ ] oCombineMeshInstance = new CombineInstance[ iContourCount ];
for( int iContourIndex = 0; iContourIndex < iContourCount; ++iContourIndex )
{
Vector3[ ] oVerticesArray;
List<int> oTrianglesList;
EarClippingSubMesh( a_rDominantContoursList[ iContourIndex ], a_fScale, a_f3PivotPoint, out oVerticesArray, out oTrianglesList );
oCombineMeshInstance[ iContourIndex ].mesh = BuildExtrudedMeshFromPolygonizedContours( oVerticesArray, oTrianglesList, a_fExtrusionDepth ); // EarClippingSubMesh( a_rDominantContoursList[ iContourIndex ] );
}
// Step 3: Combine every sub meshes (merge, no transform)
oCombinedMesh.CombineMeshes( oCombineMeshInstance, true, false );
// Return!
return oCombinedMesh;
}
示例12: Init
void Init ()
{
Component[] meshFilters = GetComponentsInChildren<MeshFilter>(true);
Dictionary<Material, List<CombineInstance>> combineMeshInstanceDictionary = new Dictionary<Material, List<CombineInstance>> ();
foreach (var mesh in meshFilters) {
var mat = mesh.GetComponent<Renderer>().sharedMaterial ;
if( mat == null )
continue;
if(!combineMeshInstanceDictionary.ContainsKey(mat) )
{
combineMeshInstanceDictionary.Add( mat, new List<CombineInstance>());
}
var instance = combineMeshInstanceDictionary[ mat ];
var cmesh = new CombineInstance();
cmesh.transform = mesh.transform.localToWorldMatrix;
cmesh.mesh = ((MeshFilter) mesh).sharedMesh;
instance.Add(cmesh);
}
gameObject.SetActive (false);
gameObject.tag = "EditorOnly";
if( generatedObject == null)
generatedObject = new GameObject (name);
foreach (var item in generatedObject.GetComponentsInChildren<Transform>()) {
if( item == generatedObject.transform )
continue;
DestroyImmediate (item.gameObject);
}
generatedObject.isStatic = true;
foreach (var dic in combineMeshInstanceDictionary) {
var newObject = new GameObject(dic.Key.name);
newObject.isStatic = true;
var meshrenderer = newObject.AddComponent<MeshRenderer>();
var meshfilter = newObject.AddComponent<MeshFilter>();
meshrenderer.material = dic.Key;
var mesh = new Mesh();
mesh.CombineMeshes(dic.Value.ToArray());
Unwrapping.GenerateSecondaryUVSet( mesh);
meshfilter.sharedMesh = mesh;
newObject.transform.parent = generatedObject.transform;
Debug.Log(Application.loadedLevelName);
System.IO.Directory.CreateDirectory( "Assets/" + Application.loadedLevelName + "/" + name );
AssetDatabase.CreateAsset(mesh, "Assets/" + Application.loadedLevelName+ "/" + name + "/" + dic.Key.name + ".asset");
}
}
示例13: CreateProxies
public static Bounds CreateProxies(GameObject go, PropTools.Prop prop)
{
List<Mesh> proxyMeshes = new List<Mesh>();
List<Material> proxyMaterials = new List<Material>();
GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
MeshFilter cubeMF = cube.GetComponent<MeshFilter>();
Mesh cubeMesh = cubeMF.sharedMesh;
foreach (PropTools.Proxy proxy in prop.proxies)
{
Vector3[] verts = cubeMesh.vertices;
for (int i = 0; i < verts.Length; i++)
{
verts[i].Scale(proxy.size);
verts[i] += proxy.center;
}
Mesh proxyMesh = new Mesh();
proxyMesh.vertices = verts;
proxyMesh.triangles = cubeMesh.triangles;
proxyMesh.uv = cubeMesh.uv;
proxyMesh.normals = cubeMesh.normals;
Material proxyMat = new Material(Shader.Find("Diffuse"));
proxyMat.color = proxy.color;
proxyMat.hideFlags = HideFlags.HideInInspector | HideFlags.NotEditable;
proxyMeshes.Add(proxyMesh);
proxyMaterials.Add(proxyMat);
}
CombineInstance[] cI = new CombineInstance[proxyMeshes.Count];
for (int i = 0; i < proxyMeshes.Count; i++)
{
cI[i].mesh = proxyMeshes[i];
}
Mesh combinedMesh = new Mesh();
combinedMesh.CombineMeshes(cI, false, false);
combinedMesh.RecalculateBounds();
MeshFilter mf = go.AddComponent<MeshFilter>();
mf.hideFlags = HideFlags.HideInInspector | HideFlags.NotEditable;
mf.sharedMesh = combinedMesh;
MeshRenderer mr = go.AddComponent<MeshRenderer>();
mr.hideFlags = HideFlags.HideInInspector | HideFlags.NotEditable;
mr.sharedMaterials = proxyMaterials.ToArray();
DestroyImmediate(cube);
for (int i = 0; i < proxyMeshes.Count; i++)
{
DestroyImmediate(proxyMeshes[i]);
}
return combinedMesh.bounds;
}
示例14: BiPyramid
public static Mesh BiPyramid(float radius, int segments, float heignt)
{
var combine = new CombineInstance[2];
combine[0].mesh = BaselessPyramid(radius, segments, heignt);
combine[1].mesh = BaselessPyramid(radius, segments, heignt, true);
var mesh = new Mesh();
mesh.CombineMeshes(combine, true, false);
return mesh;
}
示例15: Start
private void Start()
{
GameObject model = UnityEditor.AssetDatabase.LoadAssetAtPath(meshPath, typeof(GameObject)) as GameObject;
GameObject prefab = UnityEditor.AssetDatabase.LoadAssetAtPath(prefabPath, typeof(GameObject)) as GameObject;
// combine meshes
MeshFilter[] meshFilters = model.GetComponentsInChildren<MeshFilter>(true);
List<CombineInstance> combine = new List<CombineInstance>();
for (int i = 0; i < meshFilters.Length; i++)
{
Transform child = meshFilters[i].transform;
CombineInstance combineInstance = new CombineInstance
{
mesh = meshFilters[i].sharedMesh,
subMeshIndex = 0,
transform = Matrix4x4.TRS(child.localPosition, child.localRotation, child.localScale)
};
combine.Add(combineInstance);
}
// save mesh as asset
Mesh mesh = new Mesh();
mesh.CombineMeshes(combine.ToArray(), false);
mesh.Optimize();
// prefab
string path = meshPath.Substring(0, meshPath.Length - 10) + "_Mesh.asset";
UnityEditor.AssetDatabase.CreateAsset(mesh, path);
prefab.GetComponent<MeshFilter>().sharedMesh = (Mesh)UnityEditor.AssetDatabase.LoadAssetAtPath(path, typeof(Mesh));
// labels
List<string> labels = UnityEditor.AssetDatabase.GetLabels(prefab).ToList();
labels.Add("CUBE");
labels.Add(CUBE.GetInfo(name).type.ToString());
UnityEditor.AssetDatabase.SetLabels(prefab, labels.ToArray());
// materials
int materialCount = meshFilters.Length;
Material[] alphaMats = new Material[materialCount];
for (int i = 0; i < materialCount; i++)
{
alphaMats[i] = VertexColor_Mat;
}
prefab.renderer.sharedMaterials = alphaMats;
prefab.AddComponent<ColorVertices>().colors = new int[materialCount];
// delete model
UnityEditor.AssetDatabase.DeleteAsset(meshPath);
Debugger.Log("Imported " + name);
// delete self
Resources.UnloadUnusedAssets();
DestroyImmediate(gameObject);
}