Adam's Lair Forum

game development and casual madness
It is currently 2020/02/25, 04:13

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: How do I handle SelObj?
PostPosted: 2015/01/31, 19:32 
Junior Member
Junior Member
User avatar

Joined: 2014/11/02, 03:44
Posts: 44
Role: Hobbyist
I am still trying to make a simple editor, and I need some clarification on SelObjs.

    1). What code/functions does Duality call when you select an object or multiple objects?
    2). When you extend SelObj, what vars are necessary or optional?
    3). If I want to select part of a component, like a vertex, how would I go about that in code?

Thank you. ;)

_________________
Haven't worked much with game engines, or visual studio; should be an interesting experience. :D


Top
 Profile  
 
PostPosted: 2015/01/31, 21:36 
Site Admin
Site Admin
User avatar

Joined: 2013/05/11, 22:30
Posts: 2073
Location: Germany
Role: Professional
0BobTheJanitor wrote:
    1). What code/functions does Duality call when you select an object or multiple objects?


In general, there is a global event when the selection changes, and the currently selected object(s) is a global, shared state.

In your specific case - implementing a custom CamViewState, I presume - you would need to register for this event in OnEnterState, unregister in OnLeaveState, and react accordingly to selection change events when your handler is called.

In your case (editing vertices of an object), this may or may not be the ideal approach, but more of that below.

0BobTheJanitor wrote:
    2). When you extend SelObj, what vars are necessary or optional?


It's pretty much defined by the interface - you'll have to implement all the abstract methods and properties and can decide whether you want anything in addition. It depends on what kind of object is selected. Does it have an angle? Can it be rotated? Can it be scaled? Your implementation answers these questions. If you only implement the abstract interface and do not override any virtual members, you'll get an unscalable, unrotatable object that can be moved around.

Take a look at the base class and at the Scene Editor implementation. They should guide you along your first steps.

0BobTheJanitor wrote:
    3). If I want to select part of a component, like a vertex, how would I go about that in code?


First, you'll have to understand what a SelObj really is. (aside from the fact that its badly named) Maybe you have already, but let's make sure before we go on:

  • It is a CamViewState-local wrapper object around the actual selection, which allows the base class to handle all of the boilerplate editing, without actually knowing the objects it's dealing with.



  • Your custom SelObj class will let the actual object (in your case, a vertex) communicate with the CamViewState base implementation and allow it to move it around.



  • It is best suited for distinct objects with a defined position in space, but you can actually have a custom CamViewState without ever defining any kind of SelObj.

    A Tilemap editor for example would likely not use them, as tiles on a grid do not map nicely to the concept of an object in space. Moving around individual vertices does sound like a nice fit though.



  • It has nothing to do with the global selection state as mentioned above, but Scene Editor and RigidBody Editor happen to mirror the global selection state.

    By reacting to the global event and firing it when changing selection, it is possible to select a GameObject in the Scene View and have it selected simultaneously in the Scene Editor. However, there is no obligation to do so with every CamViewState - your own state may or may not do this. You will have to decide whether you want each vertex to be selected globally or not:

    Global selection means, it will show up in the Object Inspector and potentially deselect other objects. Local selection means, you will have none of that and all of your selection and editing business happens within the editor you're writing.

You've opened up a big topic and I can't explain it in its entirety here, because that would equal writing a manual on Duality editor development. I do hope that my post shed some light on relevant areas anyway!

Don't hesitate to ask if you have further questions, but also feel encouraged to read a lot of Duality code that can serve you as an example. It can also be helpful to check out the Duality source code, build it yourself and set a few breakpoints ans step around, just to get a grasp on how it all works :)

_________________
Blog | GitHub | Twitter (@Adams_Lair)


Top
 Profile  
 
PostPosted: 2015/02/15, 21:18 
Junior Member
Junior Member
User avatar

Joined: 2014/11/02, 03:44
Posts: 44
Role: Hobbyist
I've been digging through some of the source code, and it is starting to make sense more. I do, however, have a few more questions, most of them about CamViewStates:

    1). For selObjs, what is the BoundRadius property used for?

    2). When registering SelectionChanged (and ObjectPropertyChanged) in OnEnterState, what is necessary for creating an EditorForm_ObjectPropertyChanged() style function? I've seen other examples just call Invalidate(), but is there more necessary?

    3). There are many overridden methods such as OnLostFocus() in the Rigidbody CamViewState, but which of these methods are necessary or optional (in context of certain situations) to get my plugin working?

Again, sorry if these are super simple questions, and to waste your time, but I still do not fully understand how the engine works. I also have not had a lot of time to program recently, but I do hope that I can be more productive once I learn more.

_________________
Haven't worked much with game engines, or visual studio; should be an interesting experience. :D


Top
 Profile  
 
PostPosted: 2015/02/15, 21:40 
Site Admin
Site Admin
User avatar

Joined: 2013/05/11, 22:30
Posts: 2073
Location: Germany
Role: Professional
0BobTheJanitor wrote:
1). For selObjs, what is the BoundRadius property used for?


For determining the radius of the "interaction circle" of a selected object. Click on one in the Scene View, or select multiple: The circle that is drawn around them is derived from this bounding radius.

0BobTheJanitor wrote:
2). When registering SelectionChanged (and ObjectPropertyChanged) in OnEnterState, what is necessary for creating an EditorForm_ObjectPropertyChanged() style function? I've seen other examples just call Invalidate(), but is there more necessary?


Not sure I understand the question, as you seem to be mixing various terms and cases here. ObjectPropertyChanges is a global event and you can easily subscribe to it like to any other event. For CamViewStates, you usually subscribe to it when entering and unsubscribe when leaving. There are no special requirements for subscribing to an event. ^^

0BobTheJanitor wrote:
3). There are many overridden methods such as OnLostFocus() in the Rigidbody CamViewState, but which of these methods are necessary or optional (in context of certain situations) to get my plugin working?


It depends on what you do. None of those methods are really necessary. Take a look at the Game View for a rather minimal example - even though it does override some methods, you could very well leave them out if you didn't need the associated functionality. Well, the StateName is necessary, but that's about it. :D

_________________
Blog | GitHub | Twitter (@Adams_Lair)


Top
 Profile  
 
PostPosted: 2015/02/15, 23:37 
Junior Member
Junior Member
User avatar

Joined: 2014/11/02, 03:44
Posts: 44
Role: Hobbyist
Thank you for the response. I am relatively new to events in c#, so I am not quite familiar to the correct terminology.

edit: One last thing: For my selobj, should return my whole mesh as ActualObject, or just the vertex assumed to be modified? (This is assuming my CamViewState handles the movement of a selObj, please correct me if I need to update this myself)

_________________
Haven't worked much with game engines, or visual studio; should be an interesting experience. :D


Top
 Profile  
 
PostPosted: 2015/02/16, 12:19 
Site Admin
Site Admin
User avatar

Joined: 2013/05/11, 22:30
Posts: 2073
Location: Germany
Role: Professional
Don't worry, you'll get into it. ^^ C# is a really well-designed language with very few core concepts, so you should be able to leave them past you relatively early in the learning curve. As far as events go, they're not really one of those core concepts themselves, but rather a different concept in disguise, but let's start from the beginning:

Type Categories: C# has a unified Type system, meaning that everything derives from object. Within that system, there are five basic categories of Types: Classes, Structures, Enumerations, Interfaces and Delegates.

Delegate: They are the C# equivalent of "function pointers", allowing you to take a method and pass it around in a variable. They are defined like so:
Code:
public delegate bool WillItBlend(object thing);

And used like so:
Code:
private WillItBlend someMethod = XY;
...
bool result = this.someMethod(someObject);

Note that all delegates are implicitly multicast delegates, meaning that each of them can point to multiple methods at once. They can be aggregated like this:
Code:
this.someMethod += SomeOther;
this.someMethod -= SomeOther;

If you now make a delegate field accessible through a public property, you almost have an event. Almost.

Event: An event is not some kind of base Type, it is not one of the five Type categories. Events in C# are specialized wrappers around delegates. They are public accessors to private delegate fields that, from outside your class, only allow subscribe (+=) and unsubscribe (-=) operations and are invokable only from inside your class. As you know, events are defined like Fields, but have the event keyword:
Code:
public event WillItBlend SomeEvent = null;

Now, internally this will expand to the following:
Code:
private WillItBlend someDelegate = null;
...
public WillItBlend SomeEvent
{
  add { this.someDelegate += value; }
  remove { this.someDelegate -= value; }
}

As you can see, this is very similar to the Field / Property kind of stuff. Events are like "specialized Properties" for Delegate fields.

You probably knew some of this already, but I didn't realize what events truly are until some years into programming C#, so I figured it couldn't hurt to mention it ^^

0BobTheJanitor wrote:
edit: One last thing: For my selobj, should return my whole mesh as ActualObject, or just the vertex assumed to be modified? (This is assuming my CamViewState handles the movement of a selObj, please correct me if I need to update this myself)


Well, the SelObj represents whatever thing you want to grab and move around, so if you're moving vertices, a SelObj should be a vertex! Keep in mind that you don't really need to create a SelObj until you need to select or hover it, so you don't have to create one SelObj for each vertex of each mesh - just for the ones the user starts to interact with. The CamViewState base class will handle most of the rest.

_________________
Blog | GitHub | Twitter (@Adams_Lair)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group