예제 #1
0
        void CreateSea()
        {
            UVC3 LeftBottom  = new UVC3(0, 0, 0);
            UVC3 RightBottom = new UVC3(3 * WorldProps.Size.x, 0, 0);
            UVC3 LeftTop     = new UVC3(0, 0, 3 * WorldProps.Size.y);
            UVC3 RightTop    = new UVC3(3 * WorldProps.Size.x, 0, 3 * WorldProps.Size.y);

            UVC3[] Vertices = new UVC3[4];
            Vertices[0] = LeftTop;
            Vertices[1] = RightTop;
            Vertices[2] = LeftBottom;
            Vertices[3] = RightBottom;

            int[] Triangles = new int[6] {
                0, 1, 2, 2, 1, 3
            };

            UnityEngine.Mesh mesh = new UnityEngine.Mesh();
            mesh.vertices  = Vertices;
            mesh.triangles = Triangles;
            mesh.RecalculateNormals();
            UnityEngine.GameObject SPO = UnityEngine.GameObject.Find("SeaPlane");

            if (SPO == null)
            {
                SPO      = new UnityEngine.GameObject();
                SPO.name = "SeaPlane";
            }
            SPO.transform.position = new UVC3(-WorldProps.Size.x, 0, -WorldProps.Size.x);
            SPO.AddComponent <UnityEngine.MeshRenderer>().material.color = new UnityEngine.Color32(30, 97, 255, 255);
            SPO.AddComponent <UnityEngine.MeshFilter>().sharedMesh       = mesh;
        }
예제 #2
0
        public static UnityEngine.Mesh LoadData(this UnityEngine.Mesh mesh, MeshData data)
        {
            mesh.vertices  = data.Vertices.ToArray();
            mesh.triangles = data.Triangles.ToArray();
            mesh.uv        = data.UV.ToArray();

            mesh.RecalculateNormals();

            return(mesh);
        }
예제 #3
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);
 }
예제 #4
0
        public static UnityEngine.Mesh Create(IMesh mesh)
        {
            var triangleVertices = mesh.Triangles.Vertices();
            var unityMesh        = new UnityEngine.Mesh
            {
                vertices  = triangleVertices.Distinct().sorByIndex().Positions().ToArray(),
                triangles = triangleVertices.Indexes().ToArray()
            };

            unityMesh.RecalculateNormals();
            return(unityMesh);
        }
예제 #5
0
        private static void MenuItem_LoadBinaryWithAssetsPath()
        {
            //SaveBinaryWithAssetsPath
            {
                UnityEngine.Mesh t_mesh = new UnityEngine.Mesh();
                {
                    System.Collections.Generic.List <UnityEngine.Vector3> t_vertex_list = new System.Collections.Generic.List <UnityEngine.Vector3>();
                    System.Collections.Generic.List <UnityEngine.Vector3> t_nomal_list  = new System.Collections.Generic.List <UnityEngine.Vector3>();
                    System.Collections.Generic.List <int> t_index_list = new System.Collections.Generic.List <int>();
                    {
                        t_vertex_list.Add(new UnityEngine.Vector3(0.0f, 0.0f, 0.0f));
                        t_vertex_list.Add(new UnityEngine.Vector3(1.0f, 0.0f, 0.0f));
                        t_vertex_list.Add(new UnityEngine.Vector3(0.0f, 1.0f, 0.0f));
                        t_vertex_list.Add(new UnityEngine.Vector3(0.0f, 0.0f, 1.0f));
                        t_nomal_list.Add(new UnityEngine.Vector3(0.0f, 0.0f, 1.0f));
                        t_nomal_list.Add(new UnityEngine.Vector3(0.0f, 0.0f, 1.0f));
                        t_nomal_list.Add(new UnityEngine.Vector3(0.0f, 0.0f, 1.0f));
                        t_nomal_list.Add(new UnityEngine.Vector3(0.0f, 0.0f, 1.0f));
                        t_index_list.Add(0);
                        t_index_list.Add(2);
                        t_index_list.Add(1);
                        t_index_list.Add(0);
                        t_index_list.Add(1);
                        t_index_list.Add(3);
                        t_index_list.Add(1);
                        t_index_list.Add(2);
                        t_index_list.Add(3);

                        t_index_list.Add(2);
                        t_index_list.Add(0);
                        t_index_list.Add(3);
                    }
                    t_mesh.vertices  = t_vertex_list.ToArray();
                    t_mesh.normals   = t_nomal_list.ToArray();
                    t_mesh.triangles = t_index_list.ToArray();
                    t_mesh.RecalculateNormals();
                    t_mesh.RecalculateBounds();
                    t_mesh.RecalculateTangents();
                }

                BlueBack.AssetLib.Editor.CreateDirectoryWithAssetsPath.Create("Out");
                BlueBack.AssetLib.Editor.SaveAssetWithAssetsPath.SaveConverter(t_mesh, new BlueBack.AssetLib.StlConverterAssetToBinary(new UnityEngine.Vector3(50.0f, 50.0f, 50.0f)), "Out/test.stl");
                BlueBack.AssetLib.Editor.RefreshAssetDatabase.Refresh();
            }

            //LoadBinaryWithAssetsPath
            {
                UnityEngine.Mesh t_mesh = BlueBack.AssetLib.Editor.LoadAssetWithAssetsPath.LoadConverter(new BlueBack.AssetLib.StlConverterBinaryToAsset(new UnityEngine.Vector3(1.0f, 1.0f, 1.0f)), "Out/test.stl");
                UnityEngine.Debug.Log(t_mesh.triangles.Length.ToString());
            }
        }
예제 #6
0
        public static UnityEngine.Mesh projectedMesh(Unity.Mathematics.float4[] verts, int[] tris)
        {
            UnityEngine.Mesh mesh = new UnityEngine.Mesh();
            System.Collections.Generic.List <UnityEngine.Vector3> verticies =
                new System.Collections.Generic.List <UnityEngine.Vector3>();
            System.Collections.Generic.List <int> triangles = new System.Collections.Generic.List <int>();
            //Vector2[] uvs;
            //Vector3[] normals;
            //iterate through each face of the mesh

            if (SpencerStudyControl.ins.projectionMethod == ProjectionMethod.stereographic)
            {
                for (int i = 0; i < tris.Length / 3; i++)
                {
                    Unity.Mathematics.float4[] inputVerts =
                    { verts[tris[i * 3]], verts[tris[i * 3 + 1]], verts[tris[i * 3 + 2]] };
                    Unity.Mathematics.float3[] tmpVerts;
                    int[] tmpTris;
                    projectTriangle(inputVerts, IMRE.ScaleDimension.SpencerStudyControl.ins.subdiv,
                                    out tmpVerts, out tmpTris, IMRE.ScaleDimension.SpencerStudyControl.ins.projectionMethod);
                    //stich faces into common mesh

                    tmpTris.ToList().ForEach(idx => triangles.Add(idx + verticies.Count));
                    tmpVerts.ToList().ForEach(vert => verticies.Add(vert));

                    //TODO handle uvs;
                    //TODO handle normals;
                }
            }
            else
            {
                for (int i = 0; i < verts.Length; i++)
                {
                    verticies.Add(projectPosition(verts[i]));
                    ;
                }

                triangles = tris.ToList();
            }

            mesh.vertices  = verticies.ToArray();
            mesh.triangles = triangles.ToArray();
            //mesh.uv = uvs;
            //mesh.normals = normals;
            mesh.RecalculateNormals();
            mesh.RecalculateBounds();
            return(mesh);
        }
        public UnityEngine.Mesh GetOrCreateCube(float xScale, float yScale, float zScale)
        {
            lock (padlock)
            {
                if (this.cachedCubeMeshes == null)
                {
                    this.cachedCubeMeshes = new Dictionary <Tuple <float, float, float>, UnityEngine.Mesh>();
                }

                Tuple <float, float, float> key = new Tuple <float, float, float>(xScale, yScale, zScale);

                if (!this.cachedCubeMeshes.ContainsKey(key))
                {
                    //First create primitive geometry then apply scale
                    UnityEngine.Mesh      cubeMesh = new UnityEngine.Mesh();
                    UnityEngine.Vector3[] vertices =
                    {
                        new float3(0,      yScale,      0),
                        new float3(0,           0,      0),
                        new float3(xScale, yScale,      0),
                        new float3(xScale,      0,      0),

                        new float3(0,           0, zScale),
                        new float3(xScale,      0, zScale),
                        new float3(0,      yScale, zScale),
                        new float3(xScale, yScale, zScale),

                        new float3(0,      yScale,      0),
                        new float3(xScale, yScale,      0),

                        new float3(0,      yScale,      0),
                        new float3(0,      yScale, zScale),

                        new float3(xScale, yScale,      0),
                        new float3(xScale, yScale, zScale),
                    };
                    cubeMesh.vertices = vertices;

                    int[] triangles =
                    {
                        0,  2,  1, // front
                        1,  2,  3,
                        4,  5,  6, // back
                        5,  7,  6,
                        6,  7,  8, //top
                        7,  9,  8,
                        1,  3,  4, //bottom
                        3,  5,  4,
                        1, 11, 10, // left
                        1,  4, 11,
                        3, 12,  5, //right
                        5, 12, 13
                    };
                    cubeMesh.triangles = triangles;

                    UnityEngine.Vector2[] uv =
                    {
                        new float2(0,     0.66f),
                        new float2(0.25f, 0.66f),
                        new float2(0,     0.33f),
                        new float2(0.25f, 0.33f),

                        new float2(0.5f,  0.66f),
                        new float2(0.5f,  0.33f),
                        new float2(0.75f, 0.66f),
                        new float2(0.75f, 0.33f),

                        new float2(1,     0.66f),
                        new float2(1,     0.33f),

                        new float2(0.25f,     1),
                        new float2(0.5f,      1),

                        new float2(0.25f,     0),
                        new float2(0.5f,      0),
                    };

                    cubeMesh.Optimize();
                    cubeMesh.RecalculateNormals();

                    cubeMesh.RecalculateBounds();

                    this.cachedCubeMeshes.Add(key, cubeMesh);
                }

                return(this.cachedCubeMeshes[key]);
            }
        }