/// <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;
        }
Exemplo n.º 2
0
 /** 箱。作成。
  */
 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);
 }
Exemplo n.º 3
0
        private void ApplyVertices()
        {
            var vertices = GetVertices();

            unityVertices.Clear();

            for (int i = 0; i < vertices.Length; ++i)
            {
                unityVertices.Add(vertices[i]);
            }

            unityMesh.SetVertices(unityVertices);
        }
Exemplo n.º 4
0
        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");
        }
Exemplo n.º 5
0
        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");
        }