/// <summary>Copies the contents of the generated mesh to a [UnityEngine.Mesh](https://docs.unity3d.com/ScriptReference/Mesh.html).</summary> /// <param name="mesh">The mesh to copy the <see cref="Chisel.Core.GeneratedMeshContents"/> into</param> /// <remarks><code> /// MeshDescription meshDescription = ... ; /// GeneratedMeshContents contents = tree.GetGeneratedMesh(meshDescription); /// UnityEngine.Mesh unityMesh = new UnityEngine.Mesh(); /// contents.CopyTo(unityMesh); /// </code> /// See the [Create Unity Meshes](~/documentation/createUnityMesh.md) article for more information. /// </remarks> /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="mesh"/> is null.</exception> /// <exception cref="System.ArgumentException">Thrown when <paramref name="mesh"/> is invalid. This can happen when the mesh has already been destroyed.</exception> public void CopyTo(UnityEngine.Mesh mesh) { if (object.ReferenceEquals(mesh, null)) { throw new ArgumentNullException("mesh"); } if (!mesh) { throw new ArgumentException("mesh", "mesh is not valid, it might have already been destroyed"); } if (description.vertexCount < 3 || description.indexCount < 3) { mesh.Clear(); return; } mesh.vertices = positions; if (normals != null) { mesh.normals = normals; } if (tangents != null) { mesh.tangents = tangents; } if (uv0 != null) { mesh.uv = uv0; } mesh.SetTriangles(indices, 0, false); mesh.bounds = bounds; }
/// <summary>Copies the contents of the generated mesh to a [UnityEngine.Mesh](https://docs.unity3d.com/ScriptReference/Mesh.html).</summary> /// <param name="mesh">The mesh to copy the <see cref="Chisel.Core.GeneratedMeshContents"/> into</param> /// <remarks><code> /// MeshDescription meshDescription = ... ; /// GeneratedMeshContents contents = tree.GetGeneratedMesh(meshDescription); /// UnityEngine.Mesh unityMesh = new UnityEngine.Mesh(); /// contents.CopyTo(unityMesh); /// </code> /// See the [Create Unity Meshes](~/documentation/createUnityMesh.md) article for more information. /// </remarks> /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="mesh"/> is null.</exception> /// <exception cref="System.ArgumentException">Thrown when <paramref name="mesh"/> is invalid. This can happen when the mesh has already been destroyed.</exception> public void CopyTo(UnityEngine.Mesh mesh) { if (object.ReferenceEquals(mesh, null)) { throw new ArgumentNullException("mesh"); } if (!mesh) { throw new ArgumentException("mesh", "mesh is not valid, it might have already been destroyed"); } if (description.vertexCount < 3 || description.indexCount < 3) { mesh.Clear(); return; } mesh.SetVertices(positions); if (normals.IsCreated) { mesh.SetNormals(normals); } if (tangents.IsCreated) { mesh.SetTangents(tangents); } if (uv0.IsCreated) { mesh.SetUVs(0, uv0); } mesh.SetTriangles(indices.ToArray(), 0, false); mesh.bounds = bounds; }
/** 箱。作成。 */ public static UnityEngine.Mesh CreateMesh(System.Collections.Generic.List <UnityEngine.Vector3> a_vertex_list, System.Collections.Generic.List <int> a_index_list) { UnityEngine.Mesh t_mesh = new UnityEngine.Mesh(); { t_mesh.SetVertices(a_vertex_list); t_mesh.SetTriangles(a_index_list, 0); t_mesh.RecalculateBounds(); t_mesh.RecalculateNormals(); t_mesh.RecalculateTangents(); } return(t_mesh); }
protected override void OnCreateManager() { base.OnCreateManager(); instanceMesh = new UnityEngine.Mesh(); instanceMesh.SetVertices( new System.Collections.Generic.List <UnityEngine.Vector3>() { new UnityEngine.Vector3(-0.25f, 0f, 0f), new UnityEngine.Vector3(-0.25f, 0.5f, 0f), new UnityEngine.Vector3(0.25f, 0f, 0f), new UnityEngine.Vector3(0.25f, 0.5f, 0f), } ); instanceMesh.SetUVs( 0, new System.Collections.Generic.List <UnityEngine.Vector2>() { new UnityEngine.Vector3(0f, 0f), new UnityEngine.Vector3(0f, 1f), new UnityEngine.Vector3(1f, 0f), new UnityEngine.Vector3(1f, 1f), } ); instanceMesh.SetTriangles( new System.Collections.Generic.List <int>() { 0, 1, 2, 3, 2, 1 }, 0 ); instanceMesh.UploadMeshData(true); instanceCount = 0; InsObjSize = System.Runtime.InteropServices.Marshal.SizeOf(typeof(InsObj)); argsBuffer = new UnityEngine.ComputeBuffer(1, args.Length * sizeof(uint), UnityEngine.ComputeBufferType.IndirectArguments); InsObjs = null; InsObjsID = UnityEngine.Shader.PropertyToID("InsObjs"); }
protected override void OnCreateManager() { base.OnCreateManager(); materialPropertyBlock = new UnityEngine.MaterialPropertyBlock(); instanceMesh = new UnityEngine.Mesh(); instanceMesh.SetVertices( new System.Collections.Generic.List <UnityEngine.Vector3>() { new UnityEngine.Vector3(-0.25f, 0f, 0f), new UnityEngine.Vector3(-0.25f, 0.5f, 0f), new UnityEngine.Vector3(0.25f, 0f, 0f), new UnityEngine.Vector3(0.25f, 0.5f, 0f), } ); instanceMesh.SetUVs( 0, new System.Collections.Generic.List <UnityEngine.Vector2>() { new UnityEngine.Vector3(0f, 0f), new UnityEngine.Vector3(0f, 1f), new UnityEngine.Vector3(1f, 0f), new UnityEngine.Vector3(1f, 1f), } ); instanceMesh.SetTriangles( new System.Collections.Generic.List <int>() { 0, 1, 2, 3, 2, 1 }, 0 ); instanceMesh.UploadMeshData(true); TRSs = new UnityEngine.Matrix4x4[INSTANCE_MAX]; columnIndx = new float[INSTANCE_MAX]; rowIndx = new float[INSTANCE_MAX]; ColumnID = UnityEngine.Shader.PropertyToID("_ColumnIndx"); RowID = UnityEngine.Shader.PropertyToID("_RowIndx"); }
public static object Serialize_UnityMesh(object obj, System.Type type, OverloadLevelConvertSerializer serializer) { uint version = serializer.Version; UnityEngine.Mesh mesh = (UnityEngine.Mesh)obj; int flags; if (version <= 3) { // old version, we just had 'colors' flags = 1; } else { // new version, use a flags value to report what we have if (serializer.IsWriting) { flags = 0; if (mesh.colors != null && mesh.colors.Length > 0) { flags |= 1; } if (mesh.colors32 != null && mesh.colors32.Length > 0) { flags |= 2; } serializer.SerializeOut_int32(flags); } else { flags = serializer.SerializeIn_int32(); } } serializer.SerializeX(mesh, x => x.name); serializer.SerializeX(mesh, x => x.vertices); // Note: vertices must come first since the other fields may check size invariants serializer.SerializeX(mesh, x => x.uv); serializer.SerializeX(mesh, x => x.uv2); serializer.SerializeX(mesh, x => x.uv3); serializer.SerializeX(mesh, x => x.normals); serializer.SerializeX(mesh, x => x.tangents); if ((flags & 1) != 0) { serializer.SerializeX(mesh, x => x.colors); } if ((flags & 2) != 0) { serializer.SerializeX(mesh, x => x.colors32); } if (version > 3) { serializer.SerializeX(mesh, x => x.boneWeights); serializer.SerializeX(mesh, x => x.bindposes); } if (serializer.IsWriting) { Int32 numSubmeshes = mesh.subMeshCount; serializer.SerializeOut_int32(numSubmeshes); for (Int32 i = 0; i < numSubmeshes; ++i) { Int32[] tris = mesh.GetTriangles(i); serializer.SerializeOut_array(typeof(Int32), tris); } } else { Int32 numSubmeshes = serializer.SerializeIn_int32(); mesh.subMeshCount = numSubmeshes; for (Int32 i = 0; i < numSubmeshes; ++i) { Int32[] tris = (Int32[])serializer.SerializeIn_array(typeof(Int32)); mesh.SetTriangles(tris, i); } } return(mesh); }
private static UMesh CreateMesh(UMatrix[] bindposes, UVector3[] vertices, Mesh destMesh, bool recalculateNormals) { // TODO: Support blend shapes also? if (recalculateNormals) { // If we recalculate the normals, we also recalculate the tangents destMesh.RecalculateNormals(); destMesh.RecalculateTangents(); } int subMeshCount = destMesh.SubMeshCount; var newNormals = FromSimplifyVec(destMesh.Normals); var newTangents = FromSimplifyVec(destMesh.Tangents); var newUV1 = FromSimplifyVec(destMesh.UV1); var newUV2 = FromSimplifyVec(destMesh.UV2); var newUV3 = FromSimplifyVec(destMesh.UV3); var newUV4 = FromSimplifyVec(destMesh.UV4); var newColors = FromSimplifyColor(destMesh.Colors); var newBoneWeights = FromSimplifyBoneWeights(destMesh.BoneWeights); UMesh newMesh = new UMesh(); if (bindposes != null) { newMesh.bindposes = bindposes; } newMesh.subMeshCount = subMeshCount; newMesh.vertices = vertices; if (newNormals != null) { newMesh.normals = newNormals; } if (newTangents != null) { newMesh.tangents = newTangents; } if (newUV1 != null) { newMesh.uv = newUV1; } if (newUV2 != null) { newMesh.uv2 = newUV2; } if (newUV3 != null) { newMesh.uv3 = newUV3; } if (newUV4 != null) { newMesh.uv4 = newUV4; } if (newColors != null) { newMesh.colors = newColors; } if (newBoneWeights != null) { newMesh.boneWeights = newBoneWeights; } for (int i = 0; i < subMeshCount; i++) { var subMeshIndices = destMesh.GetIndices(i); newMesh.SetTriangles(subMeshIndices, i); } newMesh.RecalculateBounds(); return(newMesh); }
private static UMesh CreateMesh(UMatrix[] bindposes, UVector3[] vertices, Mesh destMesh, bool recalculateNormals) { // TODO: Support blend shapes also? if (recalculateNormals) { // If we recalculate the normals, we also recalculate the tangents destMesh.RecalculateNormals(); destMesh.RecalculateTangents(); } int subMeshCount = destMesh.SubMeshCount; var newNormals = FromSimplifyVec(destMesh.Normals); var newTangents = FromSimplifyVec(destMesh.Tangents); var newUV1 = FromSimplifyVec(destMesh.UV1); var newUV2 = FromSimplifyVec(destMesh.UV2); var newUV3 = FromSimplifyVec(destMesh.UV3); var newUV4 = FromSimplifyVec(destMesh.UV4); var newColors = FromSimplifyColor(destMesh.Colors); var newBoneWeights = FromSimplifyBoneWeights(destMesh.BoneWeights); int maxIndex = 0; for (int i = 0; i < subMeshCount; i++) { var subMeshIndices = destMesh.GetIndices(i); for (int j = 0; j < subMeshIndices.Length; j++) { if (subMeshIndices[j] > maxIndex) { maxIndex = subMeshIndices[j]; } } } UMesh newMesh = new UMesh(); #if UNITY_2017_3 || !UNITY_2017_4 || UNITY_2018 newMesh.indexFormat = (maxIndex > ushort.MaxValue ? UnityEngine.Rendering.IndexFormat.UInt32 : UnityEngine.Rendering.IndexFormat.UInt16); #endif if (bindposes != null) { newMesh.bindposes = bindposes; } newMesh.subMeshCount = subMeshCount; newMesh.vertices = vertices; if (newNormals != null) { newMesh.normals = newNormals; } if (newTangents != null) { newMesh.tangents = newTangents; } if (newUV1 != null) { newMesh.uv = newUV1; } if (newUV2 != null) { newMesh.uv2 = newUV2; } if (newUV3 != null) { newMesh.uv3 = newUV3; } if (newUV4 != null) { newMesh.uv4 = newUV4; } if (newColors != null) { newMesh.colors = newColors; } if (newBoneWeights != null) { newMesh.boneWeights = newBoneWeights; } for (int i = 0; i < subMeshCount; i++) { var subMeshIndices = destMesh.GetIndices(i); newMesh.SetTriangles(subMeshIndices, i); } newMesh.RecalculateBounds(); return(newMesh); }