Sunday, November 23, 2014

Update

T.StartPost();

Well it's been a decent while since I posted last, like usual since the last time there has been some changes to the ole life.

For starters I am all graduated and edumicated.  I also now work for the University that I just graduated from as the Community Manager (it's a pretty fun fit if I do say so myself).  I will honestly say I wasn't sure how different it would be, transitioning from student to faculty and I must say it's been quite easy and smooth.  Slowly but surely I'm learning all the in's and outs of the work environment and it's hierarchy.

The transition means that I take on some more responsibilities and do a lot of the stuff I did as a student still, but in a more "professional" way...So our weekly study nights still continue (and this year have FLOURISHED with each week usually having 100+ students compared to our last years of 30-40 average) and I now also follow up with the new/current international students that are enrolled in DAE.

It does feel strange sometimes knowing that I'm no longer a student but faculty but I try to keep it to a minimum so that way I can still stay in tune with the community as much as possible.

Other than that there's obviously the whole "need to keep my skills up" portion of life which has started again as well (I did take a hiatus from all the stuff I was doing over the summer and Sept and most of Oct as well....mainly because I needed the break)

So one of the things I've been looking at and picking up is Substance Designer. I've had SD for probably 1-2 years now I think but I've never had the time to A) figure it out B ) have a chance to use it, so I figured I would correct that by doing some "research" aka messing around with a small goal in mind.
I originally was going to just try and make a hand painted texture for a model I'm working on (just something small at the moment to get back into the swing of things) and then figured instead of actually painting it all why don't I see if I can actually make use of Substance Designers proceduralness ...since you know...it is one of the reasons to use SD.

So after playing with it for a few days here and there I've come up with something that is (in my opinion) starting to get close to what I want which in the end is more of a stylized-normal map- texture. I do like the look of it so far and just want to try and add some more knots into it.

I have it now where the floor boards are procedural as well so you can control if it is few or more boards, spacing between, variance of the layout etc.

Originally it started out as a Stylized/PBR material but I ended up needing to be able to see it in Max 2015 (which as far as I can tell isn't quite up to the PBR stage yet.. :( ) so I grabbed my nodes and put it in a new file for Diff/Spec/Gloss/Norm and this is what I've got so far.  Granted I don't know much when it comes to hand painted so not only is the program new to me, the style is new too, but I think it's getting there. Thanks to my girlfriend Jessie Van Aelst who tells me when it sucks and helps me to understand when and why it sucks :P 

Anyway I have a game idea in mind as well but since I'm not sure on the style I want to make it in yet I'm just kind of messing around till something pops for me I think and we'll go from there :)

T.Out();

Wednesday, April 30, 2014

Some WPF Treeview Tips/Tricks

T.StartPost();

Hey everyone/anyone reading, been a long while but I have just been quite busy with my internship and being a tools code monkey :D  It's been pretty fun, interesting and at times, VERY FRUSTRATING.

Now anyone that has done WPF has probably run into any number of things that wants to make you pull your hair out and flip some tables onto small children, but after many hours searching and trying different things I've come across somethings that are VERY VERY handy for tools in WPF. I'll probably just update this post as I come across more to keep them all in once place but for starters, here is a few things that I've learned to make dealing with the dreaded and yet very powerful TreeView.

WPF TreeView is probably the best and the most frustrating thing I've had to deal with on a constant basis in the last few months; it's so handy for presenting data in a hierarchical way but there are things that you just can't do directly with TreeView without searching and searching and searching the internet to find the answers to such as:


  • How can I force TreeView to change the SelectedItem?
          Now this I will say has stunned me for a while and I actually JUST found the answer to this problem Here on Stack Overflow.  So what are we to do here? Well if you're lucky enough to have your project presenting with a inherited model (cause you should be at least using the MVVM programming pattern while doing WPF tools) for your data then you can do this quite easily.  You need about 2-3 things,
1. Keep track of your selectedItem via clicks/keyboard navigation 
2. Add to your base model type, a property like 
        private bool _isSelected;
        public bool IsSelected { get { return _isSelected; } set { Set(ref _isSelected, value); } }
    *NOTE* the Set is just raising INotifyPropertyChanged so how ever you are handling yours is how you should do it here as well *NOTE*
3. In your treeview, you'll need to have at least this line from the link
<Setter Property="IsSelected"
                        Value="{Binding IsSelected, Mode=TwoWay}" />
What this is going to do is allow you to toggle IsSelected in your data Model and since the treeview is bound to it, it will automatically set and be set to IsSelected.  Now some people may think, "Why wouldn't you just do it in code behind or something like that?"  Well that's because IsSelected is a read-only property, so you can't just set it all willy-nilly like that and from all the proposed ways I've seen so far, this is the easiest to setup.

This also goes for being able to select what IS and ISN'T expanded in your treeview programmatically, make a property and bind with the Setter in your treeview.

Search Results




  • How to implement a simple and easy to use Search Filter for your TreeView
Searchable WPF TreeView on Code Project
Thankfully, Already made a great article on this. If you don't need/want the super fancy search box (was a bit overkill for what I needed) then the really relevant parts of the article are having some more setter properties in your Treeview for

<Setter Property="IsExpanded" Value="{Binding Path=IsExpanded, Mode=TwoWay}" />
                <Setter Property="Visibility" Value="{Binding Path=IsMatch, Mode=OneWay, Converter={StaticResource ResourceKey=boolToVisibility}}"/>
This lets you setup your TreeView to work with a method that you will call in your code that will search through your Data (that is bound to the tree) and set Expanded to true/false and Visibility to true/false as well which will effectively hide anything that doesn't match your results in your textbox and expand open to the result, anything that does match. Much like the IsSelected above, you'll add the IsExpanded and IsMatch(I did IsVisible myself) to your data Model.

The next important piece of code that you will need is this
public void ApplyCriteria(string criteria, Stack<TreeNodeViewModel> ancestors) {
    if (IsCriteriaMatched(criteria)) {
        IsMatch = true;
        foreach (var ancestor in ancestors) {
            ancestor.IsMatch = true;
            ancestor.IsExpanded = !String.IsNullOrEmpty(criteria);
        }
    } 
    else
        IsMatch = false;

    ancestors.Push(this);
    foreach (var child in Children)
        child.ApplyCriteria(criteria, ancestors);

    ancestors.Pop();
}
        
The method that determines if this node is a match is in this article a simple string comparison;
private bool IsCriteriaMatched(string criteria) {
    return String.IsNullOrEmpty(criteria) || name.Contains(criteria);
}
The methods will check for anything matching the searchText you give it (I hooked up an extra method from my codebehind that when the text changes in my textbox, call the method which passes the text to the Apply Criteria.) and expand or hide accordingly.

*NOTE* if you want to make the search just a bit more functional change the IsCriteriaMatched to
name.ToLower().Contains(criteria.ToLower());  This will make it that no matter if you have say Matilda or matilda, it will still show up if you gave the search box MaTilDa for example *NOTE*

The only change to this method that I really made was that I also pass the current node you're checking so you can get the name of the node like


private bool IsCriteriaMatched(string criteria, NodeWithName check)
{
    return String.IsNullOrEmpty(criteria) || check.Name.ToLower().Contains(criteria.ToLower());
}

The only part left is in your WPF you have a textbox and choose whether you want it live filtering (as the user types it filters) or keypress filtering (hit enter, it does the search) and make sure that you save/bind to the textbox text in a viewmodel (pretty much the same place you do the above search methods is as good a place as any)

Those are the two biggest things that I've run into and it's taken a while to find good working answers to (I've never used the Setter myself before this so it was a good experience to learn that I could bind to it).

Hopefully people stumble across this post and find these answers instead of searching for a long time.

T.Out();

Monday, March 3, 2014

WPF and Child Code...

T.StartPost();

Just a quick post because you never know who might need to do something like this as well (and maybe this can save them a few days of trying stuff/searching for different things/implementing things that don't work...)

So while making a tool for my internship, I had to implement a UI that would display data in a parent/child relationship. Ok, shouldn't be to bad, but the thing is that it could also have the same parent data in a list as well.

After trying for a while to get this setup to work I finally got something that displayed correctly by just getting the object and stripping the strings from it and displaying that and then more or less "discarding" the object (not discarding but not saving it in my UI for retrieval)

Then I was told we would be able to get things back by the unique ID that they would have (which also put me in a pickle because I wasn't using a Unique ID in my test data...Where I thought this might save me, it put me deeper into the, "Oh crap, how am I going to get the object back and get that ID?"

This is where StackOverflow came in to save the day...finally...after a week of searching different questions on there haha.

http://stackoverflow.com/questions/1912481/wpf-treeview-hierarchicaldatatemplate-binding-to-object-with-multiple-child-co?answertab=votes#tab-top

This answer is the answer that finally gave me the puzzle piece to get my Data Object into the UI as well as being able to get it back after (instead of just getting the strings and displaying that.)

Hopefully someone can find this helpful cause man that took way to long to get that to work..I must have tried over 15 different ways to do the datatemplates and none of them worked till this one so yeah.

Edit:

One thing to note as well, when doing the data templates, if you're doing it in a treeview like I am/the example as well, you don't want to put a TreeViewItem into the datatemplate if you want to be able to click on the text to get selection.  I didn't realize I had done this till yesterday and was trying to figure out why you had to click on this tiny spot between the > and the text.  Apparently TreeView automatically wraps whatever you put in the template in a TreeViewItem anyways so you can just display with textblock/label etc. etc.

T.Out();


Tuesday, February 11, 2014

Let the work begin!

T.StartPost();

So, with the finishing of the last semester (my final semester with in class courses) it fades into the distance and the new semester begins and with it brings ..."The Internship"

An exciting and scary adventure awaits me in the coming months.  I'm elated that I'm able to do my internship with the fellows over at Conatus Creative, who are doing River City Ransom : Underground.
The original River City Ransom game (Street Gangs for EU) was a game on the NES that really is in the top 5 of my favorite games of all time.  The amount of time I've spent beating the gangs up in that game is ridiculous.

RCR:U is the first licensed sequel to RCR and also first to be developed by a western developer (there are a lot of other games in the RCR lineage in Japan), so the fact that I can work on this is amazing to me.  I'm super excited to be apart of this project and of course a bit scared to be working on an IP that I've loved for so long.

I just got back from our school trip to the US/Canada where we got to go on some tours to places like Valve, ArenaNet and EA (Vancouver). Was fun to be on that side of the pond again, even if for only 10 days ish.

Well,  back to work now.

T.Out();



Friday, November 29, 2013

Unity, Localization and oh so much anger...

T.StartPost();

Unity.

So powerful, pretty easy to use and so annoying when something breaks.

For the game we're making in our Integration Projects 3 class, we are making our game in Unity.  The class states that the game has to be localized for English, Dutch, French and German, as well as Win 8  Store ready.

We thought everything was A-OK till this last week when we went to do a Win 8 build (cause the school finally got the tablets for us to test on...) and that's when we found out something that hinges our whole localization code and throws it in the the garbage...

Since our game is going to be using quite a bit of text we decided to spend some time making sure our localization would work flawlessly from the start instead of going back and doing it after (since that seems like a dumb idea anyway...)

So we came up with a system that is basically as follows:

One class - GlobalData -> basically keeps track of what language the game should be in.

Holds an Enum,

 LanguageEnum {English, Nederlands, French, German}  

and an int that is CurrentLanguage which of course keeps track of our language by casting the LanguageEnum to an int and storing it.

Then for each class that will have text in it, we have an xml file with a pretty basic structure that is like this:

 <?xml version="1.0" encoding="utf-8"?>  
 <MainMenu>  
  <Title>  
   <Eng Text="Main Menu"/>  
   <Nl Text="Hoofdmenu"/>  
   <Fr Text="Menu Principal"/>  
   <Ger Text="Hauptmenü"/>  
  </Title>  
  <NewGame>  
   <Eng Text="New Game"/>  
   <Nl Text="Nieuw Spel"/>  
   <Fr Text="Nouveaux Jeu"/>  
   <Ger Text="Neues Spiel"/>  
  </NewGame>  
 </MainMenu>  

Then in our class with text we have two things, another Enum that corresponds with the Elements in our xml such as:
 public enum MenuStringKey  
 { Title, NewGame, Controls, Options, Credits, Exit }  

And a public void  LoadStrings(); method which is as follows:

 // Open Xml Document with tranlations.  
     XmlDocument xmlDoc = new XmlDocument();  
     xmlDoc.Load(@"Assets\Localization\MenuText.xml");  
     // Loop over all needed option strings. (By looping over OptionStringKey enums.)  
     foreach (MenuStringKey neededStr in Enum.GetValues(typeof(MenuStringKey)))  
     {  
       // Get all possible translations for the needed string.  
       XmlNodeList languageList = xmlDoc.GetElementsByTagName(neededStr.ToString());  
       // Get needed translation.  
       foreach (XmlNode translations in languageList)  
       {  
         //Get the attribute that goes with the localization.  
         MenuStrings.Add(neededStr, translations.ChildNodes.Item((int)GlobalData.CurrentLanguage).Attributes["Text"].Value);  
       }  
     }  

We store our localized strings in a Dictionary of
 Dictionary<MenuStringKey, string>   

 Or whichever Enum it is.

And whenever we wanted to get the localized string it is just
 MenuStrings[MenuStringKey.Title]  //Gets the corresponding string in whichever language

We had to do our loading with relative paths as for some reason, Resources didn't want to work us before (it does in our new code but it didn't back then...)

This also made another problem we didn't at first notice, because we're referring to the assets/localization folder, we also have to copy that folder structure over to the build else, no text, no working game.

But hey, not a big deal right?

Well, this was working fine for us up till this week, as I said before.  When we went to build for Win 8 app store, we found that XmlDocument and friends are not supported...Great...
 Just GREAT...

So now we have to figure out how to get our xml reading to work again with XDocument which is actually what I wanted to use in the first place but at the time (only a few weeks ago) Unity didn't support which is why we had to use the xmlDocument instead of XDocument and LINQ (which is sooo much nicer)

So after messing around and trying to get used to XDocument and LINQ again, I have finally come up with an actually, even more elegant solution which solves 2 problems for us.

It solves the having to copy over the folder structure as well as our xml loading problems.


So we still have the same setup with the enums and such, the only change I have made is in the GlobalData one by changing it from the original (see above) to
 LanguageEnum {Eng, Nl, Fre, Ger}  
 This makes it so when we use it for LINQ it auto finds the same tag in our XML.

So I changed our LoadStrings to

 var textAsset = (TextAsset)Resources.Load("Localization/MenuText");  
     var doc = new XDocument(XDocument.Parse(textAsset.text));  
     var root = doc.Root;  
     foreach (MenuStringKey neededStr in Enum.GetValues(typeof(MenuStringKey)))  
     {  
       MenuStrings.Add(neededStr,  
         root.Element(neededStr.ToString()).Element(GlobalData.CurrentLanguage.ToString()).FirstAttribute.Value);  
     }  
Now there is a few things I can say about this chunk of code besides it being one foreach instead of 2 and actually one line :P

 var textAsset = (TextAsset)Resources.Load("Localization/MenuText");  

This is using the Resources of Unity.  What is Resources?  It's a folder called Resources inside your Assets folder. It apparently is quite handy for a lot of things not only limited to loading text files and such.

So I moved our localization folder from the Assets into our Resources folder. I kept it in our Localization folder just cause you never know what else we're gonna throw in there (order and stuff...)

So for resource loading of xmls, you don't put the .xml, just the file name and Unity will actually look where you tell it and find the file that matches what you want. I tested because some documentation says you can just say the file name and it will search ALL folders in your resources folder but this seems to not be completely true, so be warned that if you have a sub folder, make sure you are including that folder name in your path as well like above.

The second thing is
 var doc = new XDocument(XDocument.Parse(textAsset.text));</code></pre>  
 Which was actually a pretty annoying thing to get figured out. &nbsp;A lot of online sources say use XDocument.load which doesn't seem to work. I did finally stumble across someone saying doing this current line which made it work correctly.  

Now for our XML structure, we only have the one attribute in our Element which is the text for that language.
 MenuStrings.Add(neededStr,   
      root.Element(neededStr.ToString()).Element(GlobalData.CurrentLanguage.ToString()).FirstAttribute.Value);   
 .  
Since this is inside our ForEach, we check for each Enum that is in MenuStringKey and try to find the element that corresponds with it and then finding the element in that one that corresponds to our CurrentLanguage and then finally the attribute which is the Text="" part
This works quite nicely and actually makes it so we can keep all the other code (so far, I do have to check to make sure it will Build for Win 8 after I get this all re done in the other classes...)for the actual using of our text and such, which is great.

I'll do an edit when I've found out if this will completely fix our build problem.
Thanks for reading and hopefully this has helped someone :D
EDIT:
This code has made it so I was able to make a Win 8 App store build with no problems. Cheers, hope it helps.

 T.Out();


Friday, October 25, 2013

Still got them, problems

T.StartPost();

So it's been awhile yet again since my last post.

Been working on a shader to replicate an old CRT for HLSL shader model 3 for XNA 4.0. There's of course some strange stuff that I didn't know about XNA 4.0, such as if you make a shader that only implements the pixel shader, the spritebatch (which I am using for this shader as it's all post processing) will make a ShaderModel 2.0 vertex shader to pass things through. This wouldn't be a problem if there wasn't s 64 instruction limit on pixel shaders math calculations. A shader I found to base myself on for the start of the scan lines goes over that limit and of course the poster even said, "Fixed it by putting it on shaderModel 3."

Now the problem with that is if you just put your pixel shader on 3.0 and still don't define a vertexShader of 3.0 as well, XNA will give you a compilation error which basically says "Fool, you're trying to mix a VertexShader of ShaderModel 2 with a PixelShader of ShadeModel 3...You duuuumb."

I had to search for a couple different things to finally come across a way of just passing everything through the VertexShader to not affect the outcome of the post processing (if you try to just do something like pass the input position to the output in the vertexShader, it will give you a one color screen instead of what you want.).  Thankfully someone has already done a great service by figuring out a way to make a pass through without affecting the actual image (much, he claims it might make it a bit blurry but I don't really see it)

http://gamedev.sleptlate.org/blog/165-implementing-a-pass-through-3vertex-shader-for-games-without-vertices/

A few lines of code later and you've got a model 3 vertex shader that passes through and doesn't mess with your pixel shader.  So I got that working...And then I found out I needed to actually be working on this for GLSL so here goes nothing (with learning GLSL/OpenGl) and trying to paste some shaders together and check their performance

UNITY PROBLEMS

Something else that has popped up is Unity and XML reading. Now I figured since we're using the C# scripting it would be just regular C# that I could use to read it all in and work with it. I figured hey, I like LINQ and I've gotten quite a bit of experience working with it and XML together in my P90X WoT  project so we'll just use that for our localization and be done with it.

Oh How Wrong Was I. Unity doesn't use a high enough C# version to access XDocument which is what I had done all my previous work with so I had to scour the internet to find a new way to do it and after researching...and, you guess it, PROBLEMS GALORE, I finally have it working.

One of the pages about XML loading and Unity I found was this,
http://unitynoobs.blogspot.be/2011/02/xml-loading-data-from-xml-file.html

Which almost worked for me. Some of the code was needed for me to get it working again but one of the lines that did give me errors no matter what is this one

 Line 29 xmlDoc.LoadXml(GameAsset.text); // load the file.

I found a bunch of things about how when you save XML as UTF-8 it sometimes adds a BOM (Byte Order Mark) which Unity reads as white space. It's supposed to be in there to let things know what the endianess of the code is but Unity just reads it as white space and will actually just say, "NO".  So after probably a literal hour or two searching and trying different solutions all to no avail, I tried something else which I originally didn't know was there....

If you do xmlDoc.Load(GameAsset.text);

It will go without a hitch and load it. Strange but it works and I curse it every time I look at it.

LOCALIZATION PROBLEMS

I'm just starting with localization for the first time and we're going to be developing a text heavy game (dialogues for characters and their actions and progress reports etc. etc.) which has to be localized from English to Dutch, French and German as well...Now that the XML is loading finally we can start on things because we felt that we had to get this in place before we even started developing the game. I feel it's a good thing because if I would have to go back and change all this stuff to load different things based on languages I'd probably rip my hair out and throw myself through a wall..

But anyways, that's all my problems for now.

T.Out();





Sunday, September 1, 2013

Oh long and busy summer...

T.StartPost();

Oh long time no write.

So it's been quite a while since I posted...sorry, but I have been pretty busy as of late.
Since it summer, it is my time to work..as much as possible. This summer I'm being a pipeliner in the oil and gas industry (yeah, makes sense right and isn't a complete and polar opposite of what I go to school for right?) which is a definite go go go job most of the time, 12 hour shifts for 21 days straight...so you can see why I've been busy.

But anyways I have been doing some Youtube videos here and there throughout the summer as well as semi-"apprenticing" a few people on 3D techniques and the work flow for making game ready models (sometimes it's pretty hard getting ideas through haha)

I figured I would make a small update about myself to make sure that anyone that does happen across this doesn't think I'm dead to the world, because "I'm Not Dead Yet!" (Quest for the Holy Grail - anyone?)

Some stress outside of the work is looking for the internship I'll need in my second semester this year so I can end up graduating from ma, edu-mi-cation ;)...I've been finding it's next to impossible finding an internship as a Technical Artist, which is somewhat disheartening. Might have to go for 3D or gameplay...or even just tools dev I guess, we'll see what ole fate gives me.

If for some reason you can't find my youtube channel, you can find it at
http://www.youtube.com/user/TJE3
 where I uploaded some stuff I did this year as well and some videos that I've been uploading about some 3D tips/Tricks (and a forth coming series on the quick and dirty workflow )


Well I guess that it's for now,

T.Out();