當前位置: 首頁>>代碼示例>>C#>>正文


C# Mesh.CombineMeshes方法代碼示例

本文整理匯總了C#中UnityEngine.Mesh.CombineMeshes方法的典型用法代碼示例。如果您正苦於以下問題:C# Mesh.CombineMeshes方法的具體用法?C# Mesh.CombineMeshes怎麽用?C# Mesh.CombineMeshes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在UnityEngine.Mesh的用法示例。


在下文中一共展示了Mesh.CombineMeshes方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: CombineMeshes

        public static void CombineMeshes(Queue<CombineInstance> items
            , byte area
            , InputGeometryCompiler compiler)
        {
            const int MaxTris = 65000;

            List<CombineInstance> combineInstancesPart = new List<CombineInstance>();
            byte[] areas = NMGen.CreateAreaBuffer(MaxTris, area);

            while (items.Count != 0)
            {
                int vertCount = 0;

                while (items.Count > 0
                    && (vertCount + items.Peek().mesh.vertexCount < MaxTris))
                {
                    vertCount += items.Peek().mesh.vertexCount;
                    combineInstancesPart.Add(items.Dequeue());
                }

                Mesh meshPart = new Mesh();

                meshPart.CombineMeshes(combineInstancesPart.ToArray(), true, true);

                compiler.AddTriangles(meshPart.vertices, meshPart.vertexCount
                    , meshPart.triangles, areas, meshPart.triangles.Length / 3);

                Object.DestroyImmediate(meshPart);

                combineInstancesPart.Clear();
            }
        }
開發者ID:kbengine,項目名稱:unity3d_nav_critterai,代碼行數:32,代碼來源:MeshUtil.cs

示例2: LateUpdate

        protected virtual void LateUpdate()
        {
            if(_hasRenderer)
                return;


            _hasRenderer = true;
            

            foreach (KeyValuePair<Material, List<PCTrail>> keyValuePair in _matToTrailList)
            {
                CombineInstance[] combineInstances = new CombineInstance[keyValuePair.Value.Count];

                for (int i = 0; i < keyValuePair.Value.Count; i++)
                {
                    combineInstances[i] = new CombineInstance
                    {
                        mesh = keyValuePair.Value[i].Mesh,
                        subMeshIndex = 0,
                        transform = Matrix4x4.identity
                    };
                }

                Mesh combinedMesh = new Mesh();
                combinedMesh.CombineMeshes(combineInstances, true, false);
                _toClean.Add(combinedMesh);

                DrawMesh(combinedMesh, keyValuePair.Key);

                keyValuePair.Value.Clear();
            }
        }
開發者ID:at-anhgh,項目名稱:Game-RiotSamuraFight,代碼行數:32,代碼來源:TrailRenderer_Base.cs

示例3: GetCollider

    public override Collider GetCollider(GameObject parent, Vector3 pos) {
        //Get mesh filters
        MeshFilter[] meshFilters = GetPrefab().GetComponentsInChildren<MeshFilter>();
        CombineInstance[] meshes = new CombineInstance[meshFilters.Length];

        //Add meshes to array
        for (int i = 0; i < meshes.Length; i++) {
            meshes[i].mesh = meshFilters[i].sharedMesh;
            meshes[i].transform = meshFilters[i].transform.localToWorldMatrix;
        }

        //Combine meshes
        Mesh mesh = new Mesh();
        mesh.CombineMeshes(meshes);

        //Add position and rotate
        Vector3[] verticies = mesh.vertices;
        for (int i = 0; i < verticies.Length; i++) {
            verticies[i] += pos;
            verticies[i] = Quaternion.Euler(90, 0, 0) * verticies[i];
        }
        mesh.vertices = verticies;

        //Create mesh collider
        MeshCollider coll = parent.AddComponent<MeshCollider>();
        coll.sharedMesh = mesh;
        
        return coll;
    }
開發者ID:platformed,項目名稱:Platformed-Game,代碼行數:29,代碼來源:SpawnableBlock.cs

示例4: MergeMeshes

        public static GameObject MergeMeshes(PaintJob[] jobs)
        {
            if (jobs.Length == 0)
            return null;
             List<CombineInstance> meshes = new List<CombineInstance>();
             for (int i = 0; i < jobs.Length; ++i)
             {
            Mesh m = BakeDownMesh(jobs[i].meshFilter.sharedMesh, jobs[i].stream);
            CombineInstance ci = new CombineInstance();
            ci.mesh = m;
            ci.transform = jobs[i].meshFilter.transform.localToWorldMatrix;
            meshes.Add(ci);
             }

             Mesh mesh = new Mesh();
             mesh.CombineMeshes(meshes.ToArray());
             GameObject go = new GameObject("Combined Mesh");
             go.AddComponent<MeshRenderer>();
             var mf = go.AddComponent<MeshFilter>();
             mesh.Optimize();
             mesh.RecalculateBounds();
             mesh.UploadMeshData(false);
             mf.sharedMesh = mesh;
             for (int i = 0; i < meshes.Count; ++i)
             {
            GameObject.DestroyImmediate(meshes[i].mesh);
             }
             return go;
        }
開發者ID:slipster216,項目名稱:VertexPaint,代碼行數:29,代碼來源:VertexPainterUtilities.cs

示例5: FuseToChunkMesh

        public Mesh FuseToChunkMesh(MeshFilter ChunkMesh, MeshFilter[] NewMeshes, Vector3 ChunkPos, bool Restart = true)
        {
            //store old positions
            foreach (MeshFilter filter in NewMeshes)
            {
                filter.transform.position -= ChunkPos;
            }
            ChunkMesh.transform.position = Vector3.zero;
            CombineInstance[] combine = new CombineInstance[NewMeshes.Length + 1];
            List<MeshFilter> MeshList = new List<MeshFilter>(NewMeshes);
            for (int i = 0; i < combine.Length - 1; i++)
            {
                combine[i].mesh = MeshList[i].sharedMesh;
                combine[i].transform = MeshList[i].transform.localToWorldMatrix;
                DestroyImmediate(MeshList[i].gameObject);
            }

            MeshList.Add(ChunkMesh);

            combine[NewMeshes.Length].mesh = MeshList[NewMeshes.Length].sharedMesh;
            combine[NewMeshes.Length].transform = MeshList[NewMeshes.Length].transform.localToWorldMatrix;

            Mesh m = new Mesh();
            m.CombineMeshes(combine, true, true);

            ChunkMesh.transform.position = ChunkPos;

            return m;
        }
開發者ID:Dytonis,項目名稱:cube-war-game,代碼行數:29,代碼來源:ChunkFactory.cs

示例6: CreateMesh

        public Mesh CreateMesh()
        {
            Mesh m = new Mesh
            {
                vertices = Vertices.ToArray(),
                uv = UV1.ToArray(),
                uv2 = UV2.ToArray(),
                triangles = Triangles.ToArray(),
                colors = Colors.ToArray()
            };

            if(Submeshes.Count > 0)
            {
                CombineInstance[] instances = new CombineInstance[Submeshes.Count];
                for(int i = 0; i < Submeshes.Count; i++)
                {
                    CombineInstance ins = new CombineInstance
                    {
                        mesh = Submeshes[i].CreateMesh(),
                        transform = Matrix4x4.identity
                    };

                    instances[i] = ins;

                }
                m.CombineMeshes(instances, false);
            }

            m.RecalculateNormals();
            m.RecalculateBounds();
            m.Optimize();

            return m;
        }
開發者ID:Arcanum2010,項目名稱:UnityVoxelTest,代碼行數:34,代碼來源:IMesher.cs

示例7: BaselessPyramid

        public static Mesh BaselessPyramid(Vector3 baseCenter, Vector3 apex, float radius, int segments,
            bool inverted = false)
        {
            var segmentAngle = Mathf.PI*2/segments;
            var currentAngle = 0f;

            var v = new Vector3[segments + 1];
            v[0] = apex;
            for (var i = 1; i <= segments; i++)
            {
                v[i] = new Vector3(radius*Mathf.Sin(currentAngle), 0,
                    radius*Mathf.Cos(currentAngle)) + baseCenter;
                if (inverted) currentAngle -= segmentAngle;
                else currentAngle += segmentAngle;
            }

            var combine = new CombineInstance[segments];
            for (var i = 0; i < segments - 1; i++)
            {
                combine[i].mesh = Triangle(v[0], v[i + 1], v[i + 2]);
            }
            combine[combine.Length - 1].mesh = Triangle(v[0], v[v.Length - 1], v[1]);

            var mesh = new Mesh();
            mesh.CombineMeshes(combine, true, false);
            return mesh;
        }
開發者ID:BasmanovDaniil,項目名稱:Whoosh,代碼行數:27,代碼來源:MeshE.cs

示例8: CombinedMeshes

    public Mesh[] CombinedMeshes(List<Mesh> meshObjectList)
    {
        List<Mesh> meshs = new List<Mesh>();

        // combine meshes
        List<CombineInstance> combine = new List<CombineInstance>();
        int i = 0;
        while (i < meshObjectList.Count)
        {
            CombineInstance instance = new CombineInstance();
            instance.mesh = meshObjectList[i];
            instance.transform = transform.localToWorldMatrix;

            combine.Add(instance);

            i++;
        }

        Mesh combinedMesh = new Mesh();
        combinedMesh.CombineMeshes(combine.ToArray());
        meshs.Add(combinedMesh);
        combine = new List<CombineInstance>();

        return meshs.ToArray();
    }
開發者ID:MusicalCreeper01,項目名稱:BasicUnityVoxelTerrain,代碼行數:25,代碼來源:CubicTerrainGenerator.cs

示例9: PolygonizeContours

    // Returns a flat 3D polygonized mesh from 2D outer/inner contours
    public static Mesh PolygonizeContours( List<Contour> a_rDominantContoursList, float a_fScale, Vector3 a_f3PivotPoint, float a_fWidth, float a_fHeight )
    {
        // The mesh to build
        Mesh oCombinedMesh = new Mesh( );

        int iContourCount = a_rDominantContoursList.Count; //a_rDominantContoursList.Count;

        // Step 2: Ear clip outer contour
        CombineInstance[ ] oCombineMeshInstance = new CombineInstance[ iContourCount ];

        for( int iContourIndex = 0; iContourIndex < iContourCount; ++iContourIndex )
        {
            Vector3[ ] oVerticesArray;
            int[ ] oTrianglesArray;
            Vector2[ ] oUVs;
            Mesh oSubMesh = new Mesh( );

            EarClipping( a_rDominantContoursList[ iContourIndex ], a_fScale, a_f3PivotPoint, a_fWidth, a_fHeight, out oVerticesArray, out oTrianglesArray, out oUVs );

            oSubMesh.vertices  = oVerticesArray;
            oSubMesh.uv        = oUVs;
            oSubMesh.triangles = oTrianglesArray;
    
            oCombineMeshInstance[ iContourIndex ].mesh = oSubMesh;
        }

        // Step 3: Combine every sub meshes (merge, no transform)
        oCombinedMesh.CombineMeshes( oCombineMeshInstance, true, false );

        // Return!
        return oCombinedMesh;		
    }
開發者ID:kenzo0107,項目名稱:MamekoRun2D,代碼行數:33,代碼來源:Uni2DEditorPolygonTriangulationUtils.cs

示例10: Write

        public void Write(SceneWriter writer, object component)
        {
            Component script = component as Component;
            if (script == null)
            {
                throw new Exception(GetType() + " cannot export components of type " + component.GetType());
            }
            MeshFilter[] meshFilters = script.GetComponentsInChildren<MeshFilter>();
            CombineInstance[] combine = new CombineInstance[meshFilters.Length];
            for ( int i = 0; i < meshFilters.Length; i++) {
                combine[i].mesh = meshFilters[i].sharedMesh;
                combine[i].transform = meshFilters[i].transform.localToWorldMatrix;
            }
            Mesh mesh = new Mesh();
            mesh.CombineMeshes(combine);
            MeshRenderer mr = script.GetComponentInChildren<MeshRenderer>();
            writer.WriteElement("sharedMaterials", mr.sharedMaterials);
            writer.WriteElement("triangles", mesh.triangles);
            writer.WriteElement("vertices", mesh.vertices);
            //writer.WriteElement("normals", mesh.normals);
            writer.WriteElement("uv", mesh.uv);
            Debug.Log(script.name + " batched " + combine.Length + " objects into a mesh of " + (mesh.triangles.Length / 3) + " triangles and " + mesh.vertices.Length + " vertices.");

            if (mesh.vertices.Length > short.MaxValue)
            {
                Debug.LogWarning("BATCHED TOO MANY TRIANGLES!!");
            }
        }
開發者ID:Joelone,項目名稱:FFWD,代碼行數:28,代碼來源:StaticBatchExporter.cs

示例11: EarClipping

    // Return a polygonized mesh from 2D outer/inner contours
    public static Mesh EarClipping( List<Contour> a_rDominantContoursList, float a_fExtrusionDepth, float a_fScale, Vector3 a_f3PivotPoint )
    {
        // The mesh to build
        Mesh oCombinedMesh = new Mesh( );

        int iContourCount = a_rDominantContoursList.Count; //a_rDominantContoursList.Count;

        // Step 2: Ear clip outer contour
        CombineInstance[ ] oCombineMeshInstance = new CombineInstance[ iContourCount ];
        for( int iContourIndex = 0; iContourIndex < iContourCount; ++iContourIndex )
        {
            Vector3[ ] oVerticesArray;
            List<int> oTrianglesList;

            EarClippingSubMesh( a_rDominantContoursList[ iContourIndex ], a_fScale, a_f3PivotPoint, out oVerticesArray, out oTrianglesList );

            oCombineMeshInstance[ iContourIndex ].mesh = BuildExtrudedMeshFromPolygonizedContours( oVerticesArray, oTrianglesList, a_fExtrusionDepth ); // EarClippingSubMesh( a_rDominantContoursList[ iContourIndex ] );
        }

        // Step 3: Combine every sub meshes (merge, no transform)
        oCombinedMesh.CombineMeshes( oCombineMeshInstance, true, false );

        // Return!
        return oCombinedMesh;
    }
開發者ID:NemOry,項目名稱:EscapeTheNemories,代碼行數:26,代碼來源:Uni2DEditorUtilsPolygonTriangulation.cs

示例12: Init

    void Init ()
    {
        Component[] meshFilters = GetComponentsInChildren<MeshFilter>(true);
        Dictionary<Material, List<CombineInstance>> combineMeshInstanceDictionary = new Dictionary<Material, List<CombineInstance>> ();

        foreach (var mesh in meshFilters) {
            
            var mat = mesh.GetComponent<Renderer>().sharedMaterial ;
            
            if( mat == null )
                continue;
            
            if(!combineMeshInstanceDictionary.ContainsKey(mat) )
            {
                combineMeshInstanceDictionary.Add( mat, new List<CombineInstance>());
            }
            var instance = combineMeshInstanceDictionary[ mat ];
            var cmesh = new CombineInstance();
            cmesh.transform = mesh.transform.localToWorldMatrix;
            cmesh.mesh = ((MeshFilter) mesh).sharedMesh;
            instance.Add(cmesh);
        }
        
        gameObject.SetActive (false);
        gameObject.tag = "EditorOnly";
        
        
        if( generatedObject == null)
            generatedObject = new GameObject (name);

        foreach (var item in generatedObject.GetComponentsInChildren<Transform>()) {
            if( item == generatedObject.transform )
                continue;
            
            DestroyImmediate (item.gameObject);
        }
        
        generatedObject.isStatic = true;
        
        foreach (var dic in combineMeshInstanceDictionary) {
            
            var newObject = new GameObject(dic.Key.name);
            newObject.isStatic = true;
            
            var meshrenderer = newObject.AddComponent<MeshRenderer>();
            var meshfilter = newObject.AddComponent<MeshFilter>();
            
            meshrenderer.material = dic.Key;
            var mesh = new Mesh();
            mesh.CombineMeshes(dic.Value.ToArray());
            Unwrapping.GenerateSecondaryUVSet( mesh);
            meshfilter.sharedMesh = mesh;
            newObject.transform.parent = generatedObject.transform;

            Debug.Log(Application.loadedLevelName);
            System.IO.Directory.CreateDirectory( "Assets/" + Application.loadedLevelName + "/" + name );
            AssetDatabase.CreateAsset(mesh, "Assets/" + Application.loadedLevelName+ "/" + name + "/" + dic.Key.name + ".asset");
        }
    }
開發者ID:FairyHamaLab,項目名稱:Desertion,代碼行數:59,代碼來源:MeshCombiner.cs

示例13: CreateProxies

    public static Bounds CreateProxies(GameObject go, PropTools.Prop prop)
    {
        List<Mesh> proxyMeshes = new List<Mesh>();
        List<Material> proxyMaterials = new List<Material>();

        GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
        MeshFilter cubeMF = cube.GetComponent<MeshFilter>();
        Mesh cubeMesh = cubeMF.sharedMesh;

        foreach (PropTools.Proxy proxy in prop.proxies)
        {
            Vector3[] verts = cubeMesh.vertices;

            for (int i = 0; i < verts.Length; i++)
            {
                verts[i].Scale(proxy.size);
                verts[i] += proxy.center;
            }

            Mesh proxyMesh = new Mesh();
            proxyMesh.vertices = verts;
            proxyMesh.triangles = cubeMesh.triangles;
            proxyMesh.uv = cubeMesh.uv;
            proxyMesh.normals = cubeMesh.normals;

            Material proxyMat = new Material(Shader.Find("Diffuse"));
            proxyMat.color = proxy.color;
            proxyMat.hideFlags = HideFlags.HideInInspector | HideFlags.NotEditable;
            proxyMeshes.Add(proxyMesh);
            proxyMaterials.Add(proxyMat);
        }

        CombineInstance[] cI = new CombineInstance[proxyMeshes.Count];
        for (int i = 0; i < proxyMeshes.Count; i++)
        {
            cI[i].mesh = proxyMeshes[i];
        }

        Mesh combinedMesh = new Mesh();
        combinedMesh.CombineMeshes(cI, false, false);
        combinedMesh.RecalculateBounds();

        MeshFilter mf = go.AddComponent<MeshFilter>();
        mf.hideFlags = HideFlags.HideInInspector | HideFlags.NotEditable;
        mf.sharedMesh = combinedMesh;

        MeshRenderer mr = go.AddComponent<MeshRenderer>();
        mr.hideFlags = HideFlags.HideInInspector | HideFlags.NotEditable;
        mr.sharedMaterials = proxyMaterials.ToArray();

        DestroyImmediate(cube);
        for (int i = 0; i < proxyMeshes.Count; i++)
        {
            DestroyImmediate(proxyMeshes[i]);
        }

        return combinedMesh.bounds;
    }
開發者ID:gamers2000,項目名稱:kspcss,代碼行數:58,代碼來源:PropObject.cs

示例14: BiPyramid

        public static Mesh BiPyramid(float radius, int segments, float heignt)
        {
            var combine = new CombineInstance[2];
            combine[0].mesh = BaselessPyramid(radius, segments, heignt);
            combine[1].mesh = BaselessPyramid(radius, segments, heignt, true);

            var mesh = new Mesh();
            mesh.CombineMeshes(combine, true, false);
            return mesh;
        }
開發者ID:BasmanovDaniil,項目名稱:Whoosh,代碼行數:10,代碼來源:MeshE.cs

示例15: Start

    private void Start()
    {
        GameObject model = UnityEditor.AssetDatabase.LoadAssetAtPath(meshPath, typeof(GameObject)) as GameObject;
        GameObject prefab = UnityEditor.AssetDatabase.LoadAssetAtPath(prefabPath, typeof(GameObject)) as GameObject;

        // combine meshes
        MeshFilter[] meshFilters = model.GetComponentsInChildren<MeshFilter>(true);
        List<CombineInstance> combine = new List<CombineInstance>();
        for (int i = 0; i < meshFilters.Length; i++)
        {
            Transform child = meshFilters[i].transform;
            CombineInstance combineInstance = new CombineInstance
            {
                mesh = meshFilters[i].sharedMesh,
                subMeshIndex = 0,
                transform = Matrix4x4.TRS(child.localPosition, child.localRotation, child.localScale)
            };
            combine.Add(combineInstance);
        }

        // save mesh as asset
        Mesh mesh = new Mesh();
        mesh.CombineMeshes(combine.ToArray(), false);
        mesh.Optimize();

        // prefab
        string path = meshPath.Substring(0, meshPath.Length - 10) + "_Mesh.asset";
        UnityEditor.AssetDatabase.CreateAsset(mesh, path);
        prefab.GetComponent<MeshFilter>().sharedMesh = (Mesh)UnityEditor.AssetDatabase.LoadAssetAtPath(path, typeof(Mesh));
        
        // labels
        List<string> labels = UnityEditor.AssetDatabase.GetLabels(prefab).ToList();
        labels.Add("CUBE");
        labels.Add(CUBE.GetInfo(name).type.ToString());
        UnityEditor.AssetDatabase.SetLabels(prefab, labels.ToArray());

        // materials
        int materialCount = meshFilters.Length;
        Material[] alphaMats = new Material[materialCount];
        for (int i = 0; i < materialCount; i++)
        {
            alphaMats[i] = VertexColor_Mat;
        }
        prefab.renderer.sharedMaterials = alphaMats;
        prefab.AddComponent<ColorVertices>().colors = new int[materialCount];

        // delete model
        UnityEditor.AssetDatabase.DeleteAsset(meshPath);       

        Debugger.Log("Imported " + name);

        // delete self
        Resources.UnloadUnusedAssets();
        DestroyImmediate(gameObject);
    }
開發者ID:syeager,項目名稱:Space-CUBEs,代碼行數:55,代碼來源:CUBEImporter.cs


注:本文中的UnityEngine.Mesh.CombineMeshes方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。