本文整理汇总了C#中UnityEngine.Mesh.GetInstanceID方法的典型用法代码示例。如果您正苦于以下问题:C# Mesh.GetInstanceID方法的具体用法?C# Mesh.GetInstanceID怎么用?C# Mesh.GetInstanceID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.Mesh
的用法示例。
在下文中一共展示了Mesh.GetInstanceID方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DetectChange
public static bool DetectChange(int id, Mesh mesh, Transform transform = null)
{
if (mesh == null)
return false;
if (detectChangeTable.ContainsKey(id))
{
MeshDataMirror mirror = detectChangeTable[id];
bool change = false;
if (transform != null) {
change =
mirror.position != transform.position ||
mirror.rotation != transform.rotation ||
mirror.scale != transform.GetScale();
}
if (!change) {
change =
mirror.meshInstanceID != mesh.GetInstanceID() ||
mirror.vertexCount != mesh.vertexCount ||
mirror.blendShapeCount != mesh.blendShapeCount ||
mirror.subMeshCount != mesh.subMeshCount ||
//mirror.triangleCount != mesh.triangles.Length ||
//mirror.tangentCount != mesh.tangents.Length ||
//mirror.uvCount != mesh.uv.Length ||
mirror.extents != mesh.bounds.extents;
}
return change;
} else {
MeshDataMirror mirror = new MeshDataMirror();
mirror.meshInstanceID = mesh.GetInstanceID();
mirror.vertexCount = mesh.vertexCount;
mirror.blendShapeCount = mesh.blendShapeCount;
mirror.subMeshCount = mesh.subMeshCount;
//mirror.triangleCount = mesh.triangles.Length;
//mirror.tangentCount = mesh.tangents.Length;
//mirror.uvCount = mesh.uv.Length;
mirror.extents = mesh.bounds.extents;
if (transform != null) {
mirror.position = transform.position;
mirror.rotation = transform.rotation;
mirror.scale = transform.GetScale();
}
detectChangeTable.Add(id, mirror);
return true;
}
}
示例2: BakeMesh
public static SMesh BakeMesh(Transform transform, Mesh mesh, bool rendererEnabled, SVector3Array customVertices = null)
{
SMesh surrogate = new SMesh(transform, mesh.name, mesh.GetInstanceID(), transform.gameObject.activeInHierarchy && rendererEnabled);
surrogate.header.type = SMesh.Type.full;
CopyMeshData(mesh, surrogate, customVertices);
return surrogate;
}
示例3: ExportMesh
public void ExportMesh(Mesh mesh)
{
if (mesh == null) return;
string path = AssetDatabase.GetAssetPath(mesh.GetInstanceID());
if (String.IsNullOrEmpty(path)) return;
if (exportedMeshes.Contains(path)) return;
exportedMeshes.Add(path);
//path = Path.Combine(@"C:\Projects\PressPlay\Tentacles\Unity\Assets\Level Building Blocks\Worlds\_worlds_imports\XNA", Path.GetFileName(path));
string dest = Path.Combine(MeshDir, Path.GetFileName(path));
try
{
File.Copy(path, dest, true);
}
catch (Exception ex)
{
Debug.Log("Could not copy mesh '" + path + "' for " + mesh.name + ". " + ex.Message, mesh);
throw;
}
}
示例4: ClosestPoint
/// <summary>
/// Given a mesh, cycle through it and look for the nearest vertex. We'll use this
/// as a starting point for figuring out the closest point
/// </summary>
/// <param name="rPoint"></param>
/// <param name="rTransform"></param>
/// <param name="rMesh"></param>
/// <returns></returns>
public static Vector3 ClosestPoint(Vector3 rPoint, float rRadius, Transform rTransform, Mesh rMesh)
{
MeshOctree lMeshOctree = null;
int lID = rMesh.GetInstanceID();
if (MeshOctrees.ContainsKey(lID))
{
lMeshOctree = MeshOctrees[lID];
}
else
{
lMeshOctree = new MeshOctree(rMesh);
MeshOctrees.Add(lID, lMeshOctree);
}
//DebugTransform = rTransform;
//DebugDraw.DrawSphereMesh(rPoint, 0.05f, Color.green, 1f);
// Move the point to local space
Vector3 lLocalPoint = rTransform.InverseTransformPoint(rPoint);
// Now that we're in the root, find the closest point
Vector3 lClosestPoint = MeshOctrees[lID].ClosestPoint(lLocalPoint, rRadius);
if (lClosestPoint.x == float.MaxValue) { lClosestPoint = Vector3.zero; }
// Move the point to world space
if (lClosestPoint.sqrMagnitude != 0f)
{
lClosestPoint = rTransform.TransformPoint(lClosestPoint);
//DebugDraw.DrawSphereMesh(lClosestPoint, 0.05f, Color.red, 1f);
}
// Return the world space point
return lClosestPoint;
}
示例5: SaveMesh
public string SaveMesh(Mesh mesh)
{
int id = mesh.GetInstanceID();
string name = null;
if (savecache.TryGetValue(id, out name))
{
return name;
}
using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
{
BitHelper.WriteMesh(mesh, ms);
byte[] bs = ms.ToArray();
string sha1 = ResLibTool.ComputeHashString(bs);
name = sha1 + ".mesh.bin";
bufs[name] = bs;
}
savecache[id] = name;
return name;
}
示例6: MeshToGeometry
public static geometry MeshToGeometry(Mesh inputMesh)
{
string meshName = "Mesh-" + inputMesh.GetInstanceID();
geometry outputGeometry = new geometry();
mesh outputMesh = new mesh();
outputGeometry.id = meshName + "-lib";
outputGeometry.name = inputMesh.name + "-mesh";
outputGeometry.Item = outputMesh;
//vertex Positions
List<source> sourceList = new List<source>();
var inputVertices = inputMesh.vertices;
if (inputVertices.Length == 0)
return null;
sourceList.Add(ArrayToSource(inputMesh.vertices, meshName + "-POSITION"));
vertices vertexList = new vertices();
vertexList.id = meshName + "-VERTEX";
vertexList.input = new InputLocal[1];
vertexList.input[0] = new InputLocal();
vertexList.input[0].semantic = "POSITION";
vertexList.input[0].source = "#" + sourceList[0].id;
outputMesh.vertices = vertexList;
List<InputLocalOffset> offsetList = new List<InputLocalOffset>();
{
InputLocalOffset offset = new InputLocalOffset();
offset.semantic = "VERTEX";
offset.offset = 0;
offset.source = "#" + vertexList.id;
offsetList.Add(offset);
}
var inputNormals = inputMesh.normals;
if(inputNormals.Length > 0)
{
var array = ArrayToSource(inputNormals, meshName + "-Normal0");
InputLocalOffset offset = new InputLocalOffset();
offset.semantic = "NORMAL";
offset.offset = (ulong)sourceList.Count;
offset.source = "#" + array.id;
sourceList.Add(array);
offsetList.Add(offset);
}
var inputUV1s = inputMesh.uv;
if (inputUV1s.Length > 0)
{
var array = ArrayToSource(inputUV1s, meshName + "-UV0");
InputLocalOffset offset = new InputLocalOffset();
offset.semantic = "TEXCOORD";
offset.offset = (ulong)sourceList.Count;
offset.source = "#" + array.id;
offset.set = 0;
offset.setSpecified = true;
sourceList.Add(array);
offsetList.Add(offset);
}
var inputUV2s = inputMesh.uv2;
if (inputUV2s.Length > 0)
{
var array = ArrayToSource(inputUV2s, meshName + "-UV1");
InputLocalOffset offset = new InputLocalOffset();
offset.semantic = "TEXCOORD";
offset.offset = (ulong)sourceList.Count;
offset.source = "#" + array.id;
offset.set = 1;
offset.setSpecified = true;
sourceList.Add(array);
offsetList.Add(offset);
}
var inputColors = inputMesh.colors;
if (inputColors.Length > 0)
{
var array = ArrayToSource(inputColors, meshName + "-VERTEX_COLOR0");
InputLocalOffset offset = new InputLocalOffset();
offset.semantic = "COLOR";
offset.offset = (ulong)sourceList.Count;
offset.source = "#" + array.id;
offset.set = 0;
offset.setSpecified = true;
sourceList.Add(array);
offsetList.Add(offset);
}
outputMesh.source = sourceList.ToArray();
triangles triangleList = new triangles();
triangleList.input = offsetList.ToArray();
var inputTriangles = inputMesh.triangles;
triangleList.count = (ulong)inputTriangles.Length / 3;
if (triangleList.count == 0)
return null;
//.........这里部分代码省略.........
示例7: MeshToGeometry
public static geometry MeshToGeometry(Mesh inputMesh, string id = null)
{
string name;
if (string.IsNullOrEmpty(id))
name = "Mesh-" + inputMesh.GetInstanceID();
else
name = id;
return MeshToGeometry(new CPUMesh(inputMesh), name);
}