/// <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, System.Collections.Generic.List <UnityEngine.Vector2> a_uv_list) { UnityEngine.Mesh t_mesh = new UnityEngine.Mesh(); { t_mesh.SetVertices(a_vertex_list); t_mesh.SetTriangles(a_index_list, 0); t_mesh.SetUVs(0, a_uv_list); 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"); }
private void ApplyTextureCoordinates() { for (int channelId = 0; channelId < 4; ++channelId) { var textureCoordinates = GetTextureCoordinates(channelId); if (textureCoordinates != null) { unityTextureCoordinates.Clear(); for (int i = 0; i < textureCoordinates.Length; ++i) { unityTextureCoordinates.Add(textureCoordinates[i]); } unityMesh.SetUVs(channelId, unityTextureCoordinates); } } }
public UnityEngine.Mesh ToMesh() { return(ab); var mesh = new UnityEngine.Mesh(); // mesh.uv=uv.ToArray(); // mesh.triangles = Faces.ToArray(); for (int i = 0; i < Vertices.Count; i++) { var v = Vertices[i]; v.x -= 30; Vertices[i] = v; // Vertices[i]=new UnityEngine.Vector3(); } mesh.vertices = (Vertices).ToArray(); UnityEngine.Debug.Log("count" + uv.Count); var wr = Faces.ToArray(); Array.Resize(ref wr, Vertices.Count); mesh.SetIndices(wr, UnityEngine.MeshTopology.Triangles, 0); var tw = uv.ToArray(); Array.Resize(ref tw, Vertices.Count); // uv.ToArray(); //var sz= new UnityEngine.Vector3[] { normal }; // Array.Resize(ref sz, Vertices.Count); // mesh.normals = sz; mesh.SetUVs(0, tw.ToList()); // mesh.normals = new UnityEngine.Vector3[] { normal }; return(mesh); }
public static UnityEngine.Mesh ToUnityMesh(File file) { if (file.FileType != File.Type.Model) { return(null); } Assimp.AssimpContext ctx = new Assimp.AssimpContext(); Assimp.Scene s = ctx.ImportFileFromStream(file.StreamData, Assimp.PostProcessSteps.Triangulate); if (!s.HasMeshes) { return(null); } var mesh = s.Meshes[0]; var newMesh = new UnityEngine.Mesh(); newMesh.vertices = mesh.Vertices.ConvertAll(v => v.ToV3()).ToArray(); //int[] indicies = mesh.GetIndices(); List <int> indicies = new List <int>(); foreach (var face in mesh.Faces) { indicies.AddRange(face.Indices); } newMesh.triangles = indicies.ToArray(); for (int i = 0; i < mesh.TextureCoordinateChannelCount; ++i) { newMesh.SetUVs(i, mesh.TextureCoordinateChannels[i].ConvertAll(v => v.ToV2())); } return(newMesh); }