Ejemplo n.º 1
0
 void OnEnable()
 {
     foreach (var previewTarget in targets)
     {
         var meshPreview = new MeshPreview(previewTarget as Mesh);
         meshPreview.settingsChanged += OnPreviewSettingsChanged;
         m_MeshPreviews.Add(previewTarget, meshPreview);
     }
 }
Ejemplo n.º 2
0
        static void ShowIndexInfo(Mesh mesh)
        {
            var indexCount    = CalcTotalIndices(mesh);
            var indexSize     = mesh.indexFormat == IndexFormat.UInt16 ? 2 : 4;
            var bufferSizeStr = EditorUtility.FormatBytes(indexCount * indexSize);

            EditorGUILayout.Space();
            EditorGUILayout.LabelField($"Indices: {indexCount}, {mesh.indexFormat} format ({bufferSizeStr})", EditorStyles.boldLabel);
            EditorGUI.indentLevel++;

            var    subMeshCount = mesh.subMeshCount;
            string subMeshText  = subMeshCount == 1 ? "submesh" : "submeshes";

            EditorGUILayout.LabelField($"{mesh.subMeshCount} {subMeshText}:");

            for (int i = 0; i < mesh.subMeshCount; i++)
            {
                var    subMesh    = mesh.GetSubMesh(i);
                string topology   = subMesh.topology.ToString().ToLowerInvariant();
                string baseVertex = subMesh.baseVertex == 0 ? "" : ", base vertex " + subMesh.baseVertex;

                var divisor = 3;
                switch (subMesh.topology)
                {
                case MeshTopology.Points: divisor = 1; break;

                case MeshTopology.Lines: divisor = 2; break;

                case MeshTopology.Triangles: divisor = 3; break;

                case MeshTopology.Quads: divisor = 4; break;

                case MeshTopology.LineStrip: divisor = 2; break;     // technically not correct, but eh
                }

                var primCount = subMesh.indexCount / divisor;
                if (subMeshCount > 1)
                {
                    GUILayout.BeginHorizontal();
                    var rect = GUILayoutUtility.GetRect(GUIContent.none, GUI.skin.label, GUILayout.Width(7));
                    rect.x += EditorGUI.indent;
                    var tint = MeshPreview.GetSubMeshTint(i);
                    DrawColorRect(rect, tint);
                }

                EditorGUILayout.LabelField($"#{i}: {primCount} {topology} ({subMesh.indexCount} indices starting from {subMesh.indexStart}){baseVertex}");
                if (subMeshCount > 1)
                {
                    GUILayout.EndHorizontal();
                }
            }
            EditorGUI.indentLevel--;
        }
Ejemplo n.º 3
0
        public override void OnPreviewSettings()
        {
            if (m_MeshPreviews.TryGetValue(target, out var targetMeshPreview))
            {
                targetMeshPreview.OnPreviewSettings();
            }

            if (m_DirtyMeshPreview != null)
            {
                foreach (var meshPreview in m_MeshPreviews.Values)
                {
                    if (meshPreview != m_DirtyMeshPreview)
                    {
                        meshPreview.CopySettings(m_DirtyMeshPreview);
                    }
                }

                m_DirtyMeshPreview = null;
            }
        }
        private void DoRenderPreview(bool shaded)
        {
            var billboard = target as BillboardAsset;

            Bounds bounds = new Bounds(
                new Vector3(0, (m_Height.floatValue + m_Bottom.floatValue) * 0.5f, 0),
                new Vector3(m_Width.floatValue, m_Height.floatValue, m_Width.floatValue));

            float halfSize = bounds.extents.magnitude;
            float distance = 8.0f * halfSize;

            var rotation = Quaternion.Euler(-m_Settings.previewDir.y, -m_Settings.previewDir.x, 0);

            m_PreviewUtility.camera.transform.rotation = rotation;
            m_PreviewUtility.camera.transform.position = rotation * (-Vector3.forward * distance);
            m_PreviewUtility.camera.nearClipPlane      = distance - halfSize * 1.1f;
            m_PreviewUtility.camera.farClipPlane       = distance + halfSize * 1.1f;

            m_PreviewUtility.lights[0].intensity          = 1.4f;
            m_PreviewUtility.lights[0].transform.rotation = rotation * Quaternion.Euler(40f, 40f, 0);
            m_PreviewUtility.lights[1].intensity          = 1.4f;
            m_PreviewUtility.ambientColor = new Color(.1f, .1f, .1f, 0);

            var tempPreviewDir = m_Settings.previewDir;

            m_Settings.previewDir = new Vector2(0, 0);
            if (shaded)
            {
                MakeRenderMesh(m_ShadedMesh, billboard);
                billboard.MakeMaterialProperties(m_ShadedMaterialProperties, m_PreviewUtility.camera);
                m_Settings.activeMaterial = billboard.material;
                MeshPreview.RenderMeshPreviewSkipCameraAndLighting(m_ShadedMesh, bounds, m_PreviewUtility, m_Settings, m_ShadedMaterialProperties, -1);
            }
            else
            {
                MakePreviewMesh(m_GeometryMesh, billboard);
                m_Settings.activeMaterial = m_GeometryMaterial;
                MeshPreview.RenderMeshPreviewSkipCameraAndLighting(m_GeometryMesh, bounds, m_PreviewUtility, m_Settings, null, -1);
            }
            m_Settings.previewDir = tempPreviewDir;
        }
Ejemplo n.º 5
0
 void OnPreviewSettingsChanged(MeshPreview preview)
 {
     m_DirtyMeshPreview = preview;
 }
Ejemplo n.º 6
0
 public override string GetInfoString() => MeshPreview.GetInfoString(target as Mesh);
Ejemplo n.º 7
0
 void OnEnable()
 {
     m_MeshPreview = new MeshPreview(targets?.FirstOrDefault(x => x is Mesh) as Mesh);
 }