Beispiel #1
0
        void ProcessCommon(GameObject go, bool genLightmapUV, int lod)
        {
            MeshFilter[] mfs = go.GetComponentsInChildren <MeshFilter>();
            foreach (var mf in mfs)
            {
                if (mf && mf.sharedMesh)
                {
                    MeshTool mt = new MeshTool(mf.sharedMesh);

                    var normalMappedLogo = go.name.StartsWith("knob") && !go.name.EndsWith("C");

                    if (lod == 0)
                    {
                        mt.GenerateChamfer(1.0f / mf.transform.localScale.x);
                    }

                    if (normalMappedLogo)
                    {
                        mt.GenerateKnobNormalMapUVs();
                    }
                    else
                    {
                        mt.ClearNormalMapUVs();
                    }

                    mt.ApplyTo(mf.sharedMesh, normalMappedLogo, genLightmapUV);

                    EditorUtility.SetDirty(mf.sharedMesh);

                    System.GC.Collect();
                }
            }
        }
Beispiel #2
0
        void ProcessNew(GameObject go, bool genLightmapUV, int lod)
        {
            MeshFilter[] mfs = go.GetComponentsInChildren <MeshFilter>();
            foreach (var mf in mfs)
            {
                if (mf && mf.sharedMesh)
                {
                    // Get rid of knob, pin and tube geometry.
                    if (mf.name.StartsWith("knob_") || mf.name.StartsWith("pin_") || mf.name.StartsWith("tube_"))
                    {
                        Object.DestroyImmediate(mf.sharedMesh);
                        continue;
                    }

                    MeshTool mt = new MeshTool(mf.sharedMesh);

                    var decoration = mf.name.StartsWith("VME_");

                    // Skip decoration surfaces.
                    if (!decoration)
                    {
                        if (lod == 0)
                        {
                            mt.GenerateChamfer(1.0f / mf.transform.localScale.x);
                        }
                        mt.ClearNormalMapUVs();
                    }

                    mt.ApplyTo(mf.sharedMesh, false, genLightmapUV);

                    EditorUtility.SetDirty(mf.sharedMesh);

                    System.GC.Collect();
                }
            }

            // Get rid of knob and tube parent transforms.
            var knobs = go.transform.Find("Knobs");

            if (knobs)
            {
                Object.DestroyImmediate(knobs.gameObject);
            }
            var tubes = go.transform.Find("Tubes");

            if (tubes)
            {
                Object.DestroyImmediate(tubes.gameObject);
            }
        }
Beispiel #3
0
        void ProcessCommon(GameObject go, bool genLightmapUV, int lod)
        {
            MeshFilter[] mfs = go.GetComponentsInChildren <MeshFilter>();
            foreach (var mf in mfs)
            {
                if (mf && mf.sharedMesh)
                {
                    MeshTool mt = new MeshTool(mf.sharedMesh);

                    var normalMappedLogo = go.name.StartsWith("knob") && !go.name.EndsWith("C");

                    // Generate lowest possible LOD.
                    var bounds = mf.sharedMesh.bounds;
                    var knob   = go.name.StartsWith("knob");
                    var hollow = knob ? go.name.EndsWith("C") : go.name.StartsWith("tube");
                    PartUtility.CreateCommonPartLod2(go.name, bounds.size.y, bounds.extents.x, knob, hollow, bounds.extents.x - 0.08f, genLightmapUV);

                    if (lod == 0)
                    {
                        mt.GenerateChamfer(1.0f / mf.transform.localScale.x);
                    }

                    if (normalMappedLogo)
                    {
                        mt.GenerateKnobNormalMapUVs();
                    }
                    else
                    {
                        mt.ClearNormalMapUVs();
                    }

                    mt.ApplyTo(mf.sharedMesh, normalMappedLogo, genLightmapUV);

                    EditorUtility.SetDirty(mf.sharedMesh);

                    System.GC.Collect();
                }
            }
        }
Beispiel #4
0
        void ProcessLegacy(GameObject go, int knobTubeOrPinEdges, bool genLightmapUV, int lod)
        {
            MeshFilter[] mfs = go.GetComponentsInChildren <MeshFilter>();
            for (int m = 0; m < mfs.Length; ++m)
            {
                MeshFilter mf = mfs[m];

                if (mf && mf.sharedMesh)
                {
                    /*
                     * if (mf.sharedMesh.vertexCount > 16384)
                     * {
                     *  Debug.Log("Skipping find knobs on large mesh " + go.name, go);
                     *  return;
                     * }
                     */
                    MeshTool mt = new MeshTool(mf.sharedMesh);

                    // mt.traceDebug = true;

                    mt.LocateKnobsAndTubes(knobTubeOrPinEdges, mf.transform.localScale.x);

                    if (lod == 0)
                    {
                        mt.GenerateChamfer(1.0f / mf.transform.localScale.x);
                    }

                    Mesh[]   optmizedMeshes      = new Mesh[3];
                    bool[]   exists              = new bool[3];
                    string[] optimizedAssetsPath = new string[3];

                    string lodDir = lod == 0 ? PartUtility.lod0Dir : lod == 1 ? PartUtility.lod1Dir : PartUtility.lod2Dir;

                    optimizedAssetsPath[0] = Path.Combine(PartUtility.geometryPath, PartUtility.legacyDir, genLightmapUV ? PartUtility.lightmappedDir : "", "Optimized1", lodDir);
                    optimizedAssetsPath[1] = Path.Combine(PartUtility.geometryPath, PartUtility.legacyDir, genLightmapUV ? PartUtility.lightmappedDir : "", "Optimized2", lodDir);
                    optimizedAssetsPath[2] = Path.Combine(PartUtility.geometryPath, PartUtility.legacyDir, genLightmapUV ? PartUtility.lightmappedDir : "", "Optimized3", lodDir);

                    Directory.CreateDirectory(optimizedAssetsPath[0]);
                    Directory.CreateDirectory(optimizedAssetsPath[1]);
                    Directory.CreateDirectory(optimizedAssetsPath[2]);

                    for (int i = 0; i < optmizedMeshes.Length; ++i)
                    {
                        optimizedAssetsPath[i] = Path.Combine(optimizedAssetsPath[i], Path.GetFileNameWithoutExtension(assetPath) + ".asset");
                        optmizedMeshes[i]      = AssetDatabase.LoadAssetAtPath <Mesh>(optimizedAssetsPath[i]);
                        exists[i] = (optmizedMeshes[i] != null);
                        if (optmizedMeshes[i] == null)
                        {
                            optmizedMeshes[i]      = new Mesh();
                            optmizedMeshes[i].name = mf.sharedMesh.name + "_Optimized" + (i + 1);
                        }
                    }

                    mt.GenerateLegacyOptimizedMesh(optmizedMeshes[0], false, true, true, true);
                    mt.GenerateLegacyOptimizedMesh(optmizedMeshes[1], true, false, true, true);
                    mt.GenerateLegacyOptimizedMesh(optmizedMeshes[2], false, false, true, true);

                    for (int i = 0; i < optmizedMeshes.Length; ++i)
                    {
                        if (!exists[i])
                        {
                            AssetDatabase.CreateAsset(optmizedMeshes[i], optimizedAssetsPath[i]);
                        }
                    }

                    mt.ApplyTo(mf.sharedMesh, true, genLightmapUV);

                    EditorUtility.SetDirty(mf.sharedMesh);

                    System.GC.Collect();
                }
            }
        }