Esempio n. 1
0
        // removeMaterial
        public void removeMaterial(string uid, bool destroy = true)
        {
            EditorMaterial materialToRemove = null;

            foreach (EditorMaterial material in _materials)
            {
                if (material.uid == uid)
                {
                    materialToRemove = material;
                    break;
                }
            }

            Debug.Assert(materialToRemove != null);

            _materials.Remove(materialToRemove);

            /*
             * try
             * {
             *  if (destroy)
             *      ResourceManager.destroy(uid);
             * }
             * catch (ResourceNotFoundException e)
             * {
             *  System.Windows.Forms.MessageBox.Show(String.Format("Could not destroy resource.\n{0}", e.Message), "Resource Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
             * }*/
        }
Esempio n. 2
0
        public override void OnInspectorGUI()
        {
            s_currentTab = MeshUtility.TabBar.OnGUI(s_currentTab);
            GUILayout.Space(10);

            switch (s_currentTab)
            {
            case Tabs.Model:
                base.OnInspectorGUI();
                break;

            case Tabs.Materials:
                if (m_parser != null)
                {
                    EditorMaterial.OnGUI(m_importer, m_parser, Vrm10MToonMaterialImporter.EnumerateAllTexturesDistinct);
                }
                break;

            case Tabs.Vrm:
                if (m_parser != null)
                {
                    EditorVrm.OnGUI(m_importer, m_parser, m_vrm);
                }
                break;
            }
        }
        public override void OnInspectorGUI()
        {
            if (!string.IsNullOrEmpty(m_message))
            {
                EditorGUILayout.HelpBox(m_message, MessageType.Error);
            }

            s_currentTab = MeshUtility.TabBar.OnGUI(s_currentTab);
            GUILayout.Space(10);

            switch (s_currentTab)
            {
            case Tabs.Model:
                base.OnInspectorGUI();
                break;

            case Tabs.Materials:
                if (m_parser != null)
                {
                    EditorMaterial.OnGUI(m_importer, m_parser, Vrm10MToonMaterialImporter.EnumerateAllTexturesDistinct);
                }
                break;

            case Tabs.Vrm:
                if (m_parser != null)
                {
                    EditorVrm.OnGUI(m_importer, m_parser, m_vrm);
                }
                break;
            }
        }
Esempio n. 4
0
        public override void OnInspectorGUI()
        {
            if (!string.IsNullOrEmpty(m_message))
            {
                EditorGUILayout.HelpBox(m_message, MessageType.Error);
            }

            s_currentTab = MeshUtility.TabBar.OnGUI(s_currentTab);
            GUILayout.Space(10);

            switch (s_currentTab)
            {
            case Tabs.Model:
                base.OnInspectorGUI();
                break;

            case Tabs.Materials:
                if (m_parser != null)
                {
                    EditorMaterial.OnGUI(m_importer, m_parser, Vrm10TextureEnumerator.EnumerateAllTexturesDistinct,
                                         assetPath => $"{Path.GetFileNameWithoutExtension(assetPath)}.vrm1.Textures",
                                         assetPath => $"{Path.GetFileNameWithoutExtension(assetPath)}.vrm1.Materials");
                }
                break;

            case Tabs.Vrm:
                if (m_parser != null)
                {
                    EditorVrm.OnGUI(m_importer, m_parser, m_vrm);
                }
                break;
            }
        }
Esempio n. 5
0
        private IEnumerator PickTextureCoroutine()
        {
            OpenFileDialog.Filter   = "Arx Texture Files (*.jpg|*.bmp)";
            OpenFileDialog.Title    = "Open Texture";
            OpenFileDialog.FileName = Path.Combine(EditorSettings.DataDir, PolygonSelector.CurrentlySelected.Material.TexturePath);

            var t = OpenFileDialog.OpenDialog();

            t.Start();
            while (!t.IsCompleted)
            {
                yield return(null);
            }
            if (t.Result == OpenFileDialog.DialogResult.OK)
            {
                var path = OpenFileDialog.FileName;
                if (!path.StartsWith(EditorSettings.DataDir))
                {
                    Debug.LogWarning("file is not in datadir, cant use it as a texture");
                }
                else
                {
                    var relPath = path.Replace(EditorSettings.DataDir, "");
                    var em      = new EditorMaterial(relPath, PolygonSelector.CurrentlySelected.info.polyType, PolygonSelector.CurrentlySelected.Material.TransVal);
                    PolygonSelector.CurrentlySelected.Material = em;
                    polyTextureImage.texture = em.Material.mainTexture;
                }
            }
        }
Esempio n. 6
0
 private void PolyTypeFlagChanged(PolyType flag)
 {
     if ((flag | EditorMaterial.materialPolyTypes) != PolyType.None) //if this changes any flag of the material we have to change material
     {
         Material = new EditorMaterial(Material.TexturePath, info.polyType, Material.TransVal);
     }
     if (flag == PolyType.QUAD)
     {
         UpdateMesh();
     }
 }
Esempio n. 7
0
        public void UpdatePrimitive(EditablePrimitiveInfo info, EditorMaterial mat)
        {
            this.info     = info;
            this.Material = mat;

            for (int i = 0; i < 4; i++)
            {
                vertObjs[i].transform.localPosition = info.vertices[i].position;
            }

            UpdateMesh();
        }
Esempio n. 8
0
        // createMaterial
        public void createMaterial(string uid)
        {
            // Check unsaved materials
            foreach (Material m in _materials)
            {
                if (m.uid == uid)
                {
                    System.Windows.Forms.MessageBox.Show(String.Format("An unsaved resource with the uid [{0}] already exists.", uid), "Material Error", System.Windows.Forms.MessageBoxButtons.OK);
                    return;
                }
            }

            EditorMaterial material = new EditorMaterial(uid);

            _materials.Add(material);
        }
Esempio n. 9
0
        // Clone material
        public void cloneMaterial(EditorMaterial source)
        {
            EditorMaterial material = source.clone();
            string         newUID   = material.uid + "_copy";

            while (EditorResourceManager.exists(newUID))
            {
                newUID = newUID + "_copy";
            }
            while (materialExists(newUID))
            {
                newUID = newUID + "_copy";
            }
            material.uid = newUID;
            _materials.Add(material);
        }
Esempio n. 10
0
        public MaterialMesh GetMaterialMesh(EditorMaterial key)
        {
            if (!materialMeshes.TryGetValue(key, out var retval))
            {
                var go = new GameObject();
                go.transform.SetParent(gameObject.transform);
                go.transform.localPosition    = Vector3.zero;
                go.transform.localEulerAngles = Vector3.zero;
                go.transform.localScale       = Vector3.one;
                go.layer = gameObject.layer;

                retval = go.AddComponent <MaterialMesh>();
                retval.EditorMaterial = key;

                materialMeshes[key] = retval;
            }
            return(retval);
        }
 public void AddPrimitive(EditorMaterial mat, EditablePrimitiveInfo prim)
 {
     primitives.Add(new Tuple <EditorMaterial, EditablePrimitiveInfo>(mat, prim));
 }
Esempio n. 12
0
        static void LoadMesh(Level lvl)
        {
            int       loadedPolys = 0;
            Stopwatch sw          = new Stopwatch();

            sw.Start();

            int lightIndex = 0;
            var fts        = lvl.ArxLevelNative.FTS;
            Dictionary <int, int> tcToIndex = new Dictionary <int, int>();

            //texture indices
            for (int i = 0; i < fts.textureContainers.Length; i++)
            {
                tcToIndex[fts.textureContainers[i].tc] = i;
            }

            //TODO: use external placeholder texture so it can be set to 0 on export
            var notFoundMaterialKey = new EditorMaterial(EditorSettings.DataDir + "graph\\interface\\misc\\default[icon].bmp", PolyType.GLOW, 0);

            for (int c = 0; c < fts.cells.Length; c++)
            {
                var cell = fts.cells[c];
                loadedPolys += cell.polygons.Length;
                for (int p = 0; p < cell.polygons.Length; p++)
                {
                    var poly = cell.polygons[p];

                    var matKey = notFoundMaterialKey;
                    if (tcToIndex.TryGetValue(poly.tex, out int textureIndex))
                    {
                        string texArxPath = ArxIOHelper.GetString(fts.textureContainers[textureIndex].fic);
                        string texPath    = TextureDatabase.GetRealTexturePath(EditorSettings.DataDir + texArxPath);
                        matKey = new EditorMaterial(texPath, poly.type, poly.transval); //TODO: speed up by using a pool of some sort?
                    }

                    MaterialMesh mm = lvl.EditableLevelMesh.GetMaterialMesh(matKey);

                    EditablePrimitiveInfo prim = new EditablePrimitiveInfo
                    {
                        polyType = poly.type,
                        norm     = poly.norm.ToVector3(),
                        norm2    = poly.norm2.ToVector3(),
                        area     = poly.area,
                        room     = poly.room,
                        paddy    = poly.paddy
                    };
                    int vertCount = prim.VertexCount;
                    for (int i = 0; i < vertCount; i++)
                    {
                        var vert = poly.vertices[i];
                        prim.vertices[i] = new EditableVertexInfo(new Vector3(vert.posX, vert.posY, vert.posZ),
                                                                  new Vector2(vert.texU, 1 - vert.texV),
                                                                  poly.normals[i].ToVector3(),
                                                                  ArxIOHelper.FromBGRA(lvl.ArxLevelNative.LLF.lightColors[lightIndex++]));
                    }

                    if (prim.IsTriangle)
                    {
                        //load 4th vertex manually as it has no lighting value and would break lighting otherwise
                        var lastVert = poly.vertices[3];
                        prim.vertices[3] = new EditableVertexInfo(new Vector3(lastVert.posX, lastVert.posY, lastVert.posZ),
                                                                  new Vector2(lastVert.texU, 1 - lastVert.texV),
                                                                  poly.normals[3].ToVector3(),
                                                                  Color.white);
                    }

                    mm.AddPrimitive(prim);
                }
            }

            foreach (var kv in lvl.EditableLevelMesh.MaterialMeshes)
            {
                kv.Value.UpdateMesh();
            }
            UnityEngine.Debug.Log("total load time: " + sw.Elapsed);
            UnityEngine.Debug.Log("Loaded polys: " + loadedPolys);
        }