// --------------------------------------------------------------------

        #region UI callbacks

        private void buttonImport_Click(object sender, System.EventArgs e)
        {
        
            if (mCurrentModel == null)
                return;

            if (mCurrentModel.HasMeshes)
                ImportMeshes();

            if (!SupportFileFound)
            {
                OnyxProjectAsset asset = ProjectManager.Instance.Content.AddModel(mSupportFile.FilePath, true, mSupportFile);
                mSupportFile.Guid = asset.Guid;
            }

            AssetStreamLoader<ModelSupportData>.Save(mSupportFile, mSupportFile.FilePath);

            if (MessageBox.Show("Do you want to create an entity from the imported mesh?", "Create Entity", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                CreateEntity();
            }

            ProjectLoader.Save();

            //LoadModel(mCurrentPath);
        }
Example #2
0
        public void Fill(Material mat)
        {
            mMaterial = mat;

            OnyxProjectAsset matAsset = mat.LinkedProjectAsset;

            textBoxGuid.Text = matAsset.Guid.ToString();
            textBoxName.Text = matAsset.Name;

            tableLayoutPanelProperties.Controls.Clear();
            tableLayoutPanelProperties.RowCount = mat.Properties.Count + 2;
            tableLayoutPanelProperties.RowStyles.Clear();
            int currentRow = 0;

            foreach (KeyValuePair <string, MaterialProperty> prop in mat.Properties.OrderBy(prop => prop.Value.Order))
            {
                MaterialPropertyControl propControl = new MaterialPropertyControl();
                propControl.Fill(prop.Key, prop.Value);
                propControl.Dock = DockStyle.Fill;
                propControl.OnPropertyChanged += OnPropertyChangedListener;
                tableLayoutPanelProperties.Controls.Add(propControl, 0, currentRow);
                tableLayoutPanelProperties.RowStyles.Add(new RowStyle(SizeType.Absolute, propControl.Size.Height));
                currentRow++;
            }
        }
        private void NewScene()
        {
            Stream         myStream;
            SaveFileDialog saveFileDialog1 = new SaveFileDialog();

            saveFileDialog1.InitialDirectory = "c:\\";
            saveFileDialog1.Filter           = "Onyx3d scene files (*.o3dscene)|*.o3dscene";
            saveFileDialog1.FilterIndex      = 2;
            saveFileDialog1.RestoreDirectory = true;

            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if ((myStream = saveFileDialog1.OpenFile()) != null)
                    {
                        string path  = saveFileDialog1.FileName;
                        Scene  scene = new Scene();

                        OnyxProjectAsset asset = new OnyxProjectAsset(saveFileDialog1.FileName, Path.GetFileName(path), 0);
                        ProjectManager.Instance.Content.Scenes.Add(asset);
                        UpdateScenes();

                        OnSceneSelected?.Invoke(scene);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                }
            }
        }
Example #4
0
        private void textBoxName_TextChanged(object sender, EventArgs e)
        {
            OnyxProjectAsset matAsset = mMaterial.LinkedProjectAsset;

            matAsset.Name = textBoxName.Text;
            //PropertyChanged.Invoke(this, null);
        }
Example #5
0
        private void CreateNewTexture(string path)
        {
            mCurrentTexture = new OnyxProjectAsset(path);
            ProjectManager.Instance.Content.Textures.Add(mCurrentTexture);

            UpdateTextureInfo();
            FillTexturesList();
        }
Example #6
0
        private void OnTextureSelected(object sender, EventArgs e)
        {
            OnyxProjectAsset textureEntry = mTextureIds[listViewTextures.SelectedItems[0].Index];

            SelectedTexture = new Texture(textureEntry.Path);
            TextureSelected.Invoke(this, null);
            Close();
        }
Example #7
0
        private void AddTexture(OnyxProjectAsset t)
        {
            Bitmap bmp       = new Bitmap(t.AbsolutePath);
            Image  small_img = bmp.GetThumbnailImage(64, 64, null, IntPtr.Zero);

            listViewTextures.SmallImageList.Images.Add(small_img);
            listViewTextures.Items.Add(new ListViewItem(t.Guid.ToString(), mTextureIds.Count));
            mTextureIds.Add(t);
        }
        // --------------------------------------------------------------------

        public static void New()
        {
            mActiveSceneAsset = null;
            mActiveScene      = new Scene();

            EditorSceneObjectUtils.AddReflectionProbe(false);
            EditorSceneObjectUtils.AddPrimitive(BuiltInMesh.Quad, "Quad");

            OnSceneChanged?.Invoke(mActiveScene);
        }
Example #9
0
 private void listViewTextures_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (listViewTextures.SelectedIndices.Count > 0)
     {
         mCurrentTexture = ProjectManager.Instance.Content.Textures[listViewTextures.SelectedIndices[0]];
         UpdateTextureInfo();
     }
     else
     {
         ClearTextureInfo();
     }
 }
        // --------------------------------------------------------------------

        private void CreateEntity()
        {
            NewEntityWindow window = new NewEntityWindow();
            if (window.ShowDialog() == DialogResult.OK)
            {
                SceneObject root = ParseNode(mCurrentModel.RootNode, false, null);
                OnyxProjectAsset entity = ProjectManager.Instance.Content.GetEntityByName(window.EntityName);
                if (entity == null)
                    EditorEntityUtils.Create(root, window.EntityName);
                else
                    AssetLoader<Entity>.Save(new Entity(root), entity.Path);
            }
		}
        private void OnTextureSelected(object sender, EventArgs e)
        {
            TextureMaterialProperty tmp = (TextureMaterialProperty)mProperty;

            tmp.TextureGuid = mTextureSelector.SelectedTexture.Guid;

            PictureBox       pb    = (PictureBox)mPropertyControl;
            OnyxProjectAsset asset = ProjectManager.Instance.Content.GetAsset(tmp.TextureGuid);

            pb.Image = new Bitmap(asset.AbsolutePath).GetThumbnailImage(64, 64, null, IntPtr.Zero);

            OnPropertyChanged();
        }
        // --------------------------------------------------------------------

        public static void LoadInitScene()
        {
            mActiveSceneAsset = ProjectManager.Instance.Content.GetInitScene();
            if (mActiveSceneAsset == null)
            {
                New();
                return;
            }

            mActiveScene = AssetLoader <Scene> .Load(mActiveSceneAsset.Path, true, Onyx3DEngine.Instance);

            OnSceneChanged?.Invoke(mActiveScene);
        }
Example #13
0
        private void toolStripButtonOpen_Click(object sender, EventArgs e)
        {
            string[] filePaths = OpenFileSelector(ProjectManager.Instance.CurrentProjectPath);
            if (filePaths != null)
            {
                foreach (string filePath in filePaths)
                {
                    mCurrentTexture = ProjectManager.Instance.Content.AddTexture(filePath);
                }

                UpdateTextureInfo();
                FillTexturesList();
            }
        }
Example #14
0
        // --------------------------------------------------------------------

        protected void AddElement(OnyxProjectAsset t, int index, int selectedGuid)
        {
            Bitmap bmp       = GeneratePreview(t.Guid);
            Image  small_img = bmp.GetThumbnailImage(mPreviewSize, mPreviewSize, null, IntPtr.Zero);

            listView.LargeImageList.Images.Add(small_img);
            listView.Items.Add(new ListViewItem(t.Name, index));

            if (t.Guid == selectedGuid)
            {
                listView.SelectedIndices.Add(index);
            }

            mAssets.Add(t);
        }
Example #15
0
        // --------------------------------------------------------------------

        private void AddElement(OnyxProjectAsset asset, int index, int selectedGuid)
        {
            Bitmap bmp       = GenerateMaterialPreview(asset.Guid);
            Image  small_img = bmp.GetThumbnailImage(mPreviewSize, mPreviewSize, null, IntPtr.Zero);

            listViewMaterials.LargeImageList.Images.Add(small_img);

            listViewMaterials.Items.Add(new ListViewItem(asset.Name, index));

            mMaterials.Add(asset);

            if (asset.Guid == selectedGuid)
            {
                listViewMaterials.SelectedIndices.Add(index);
            }
        }
        // --------------------------------------------------------------------

        private int ImportMesh(Assimp.Mesh newMesh, List<ModelSupportData.MeshData> previousMeshes)
        {
            Onyx3D.Mesh onyxMesh = newMesh.ToOnyx3D();
            onyxMesh.Scale(sMeshScalar);
            string name = GetSafeFileName(newMesh.Name);
            string meshPath = ProjectContent.GetMeshPath(name);
            AssetLoader<Onyx3D.Mesh>.Save(onyxMesh, meshPath, false);

            int id = -1;
            for (int prevIndex = 0; prevIndex < previousMeshes.Count; ++prevIndex)
            {
                ModelSupportData.MeshData mesh = previousMeshes[prevIndex];
                if (mesh.Name == name)
                {
                    id = mesh.Id;
                    previousMeshes.Remove(mesh);
                    break;
                }
            }

            if (id < 0)
            {
                id = ProjectManager.Instance.Content.AddMesh(meshPath, false, onyxMesh).Guid;
            }
            else
            {
                OnyxProjectAsset asset = ProjectManager.Instance.Content.GetAsset(id);
                if (asset == null)
                {
                    ProjectManager.Instance.Content.AddObject(meshPath, false, ProjectManager.Instance.Content.Meshes, id, onyxMesh);
                }
                else
                {
                    onyxMesh.LinkedProjectAsset = asset;
                }
            }


            ModelSupportData.MeshData data = new ModelSupportData.MeshData();
            data.Id = id;
            data.Name = name;
            mSupportFile.Meshes.Add(data);
            
            ProjectManager.Instance.Content.MarkDirty(id);

            return id;
        }
        private void SetTextureLayout(MaterialProperty prop)
        {
            TextureMaterialProperty tmp = (TextureMaterialProperty)prop;
            PictureBox pic = new PictureBox();

            pic.Size      = new Size(64, 64);
            pic.BackColor = Color.Black;

            OnyxProjectAsset asset = ProjectManager.Instance.Content.GetAsset(tmp.TextureGuid);

            pic.Image = new Bitmap(asset.AbsolutePath).GetThumbnailImage(64, 64, null, IntPtr.Zero);
            panelPropertyValue.Controls.Add(pic);
            panelPropertyValue.Size = new Size(panelPropertyValue.Size.Width, 70);
            this.Size  = new Size(this.Size.Width, 70);
            pic.Click += OnPictureBoxClicked;

            mPropertyControl = pic;
        }
        // --------------------------------------------------------------------

        public static Entity Create(SceneObject obj, string name)
        {
            Vector3 position = obj.Transform.Position;

            SceneObject rootNode = new SceneObject(name);

            obj.Parent = rootNode;
            obj.Transform.LocalPosition = Vector3.Zero;

            Entity entity     = new Entity(rootNode);
            string entityPath = ProjectContent.GetEntityPath(name);

            AssetLoader <Entity> .Save(entity, entityPath, false);

            OnyxProjectAsset asset = ProjectManager.Instance.Content.AddEntity(entityPath, false, entity);

            asset.Name = name;
            return(entity);
        }
        // ----------------------------s----------------------------------------

        public static Entity Create(List <SceneObject> objects, string name, Vector3 position)
        {
            SceneObject rootNode = new SceneObject(name);

            rootNode.Transform.Position = position;

            foreach (SceneObject obj in objects)
            {
                obj.Parent = rootNode;
            }

            rootNode.Transform.Position = Vector3.Zero;

            Entity entity     = new Entity(rootNode);
            string entityPath = ProjectContent.GetEntityPath(name);

            AssetLoader <Entity> .Save(entity, entityPath, false);

            OnyxProjectAsset asset = ProjectManager.Instance.Content.AddEntity(entityPath, false, entity);

            asset.Name = name;
            return(entity);
        }
 private void OnTextureSelected(object sender, EventArgs e)
 {
     SelectedTexture = mTextureIds[listViewTextures.SelectedItems[0].Index];
     TextureSelected.Invoke(this, null);
     Close();
 }
 private void AddTextureToList(OnyxProjectAsset t)
 {
     listViewTextures.SmallImageList.Images.Add(GetThumbnail(t.AbsolutePath));
     listViewTextures.Items.Add(new ListViewItem(t.Guid.ToString(), mTextureIds.Count));
     mTextureIds.Add(t);
 }