-1

In my application I am using a PropertyGrid for setting attributes related to loading data, setting the scene, etc. I have a small issue though, when it comes to using a Vector3 as a property. It turns out that if I try to use an OpenTK Vector3 struct as a field of the PropertyGrid, it deactivates the field(it shows up as gray and cannot be altered). I am assuming that this is due to the fact that a struct is immutable, thus it cannot be edited. I want to know if there is a way around this though. I know that I could define my own Vector3 as a class, which would work, but I want to continue using the OpenTK Vector3.

Here is a screen grab of my application:

enter image description here

And here is the PropertyGrid settings class:

using System.ComponentModel;
using OpenTK;
using StardustModeling.Modeling.IOFilters;

namespace StardustModeling.Modeling
{
    public class ModelBuilderSceneSettings
    {
        [Description( "The name of the compiled model." ),
         Category( "Information" )]
        public string Name { get; set; } = "";

        [Description( "The geometry data for the model." ),
         Category( "Data" ),
            Editor(
            typeof( WavefrontModelFilter ) ,
            typeof( System.Drawing.Design.UITypeEditor ) )]
        public string GeometryMesh { get; set; } = "";

        [Description( "The Diffuse Texture of the model." ),
         Category( "Texturing" ), Editor(
            typeof( BitmapFilter ) ,
            typeof( System.Drawing.Design.UITypeEditor ) )]
        public string Diffuse { get; set; } = "";

        [Description( "The NormalMap for the model." ),
         Category( "Texturing" ), Editor(
            typeof( BitmapFilter ) ,
            typeof( System.Drawing.Design.UITypeEditor ) )]
        public string Normals { get; set; } = "";

        [Description( "Position of the scene lamp." ),
         Category( "Scene" )]
        public Vector3 Lamp { get; set; } = new Vector3(2,2,2);

        [Description( "Model Position." ),
         Category( "Scene" )]
        public Vector3 ModelLocation { get; set; } = new Vector3(); // Default 0,0,0
    }
}
Krythic
  • 4,184
  • 5
  • 26
  • 67
  • Why the vote to close? This is a valid question. – Krythic Oct 31 '15 at 19:36
  • 1
    Do you have access to the `Vector3` definition? Check if it has a `TypeConverter` associated like for instance [System.Drawing.Point]( http://referencesource.microsoft.com/#System.Drawing/commonui/System/Drawing/Point.cs,a041be61667d4c9a) – Ivan Stoev Oct 31 '15 at 19:41
  • @IvanStoev It does not: https://github.com/opentk/opentk/blob/develop/Source/OpenTK/Math/Vector3.cs – Krythic Oct 31 '15 at 19:44
  • 1
    Then you have to write it yourself. You can use this as example http://referencesource.microsoft.com/#System.Drawing/commonui/System/Drawing/PointConverter.cs,0e3a4309646c3111. Then simply associate it with your property using attribute. I think this is better base for doing your own implementation then the one in the SO link provided above. – Ivan Stoev Oct 31 '15 at 19:48

1 Answers1

0

A quick work around, while not being exactly what I intended, is to use a string instead, in the format of "x,y,z" and convert it to a Vector3 whenever the field is edited. I think this is what Visual Studio does for some of its fields.

Krythic
  • 4,184
  • 5
  • 26
  • 67