Monday, October 6, 2014

New Pumpkin Templates

Gearing up for this halloween, here's a few templates I made.  Click the pic for a link to the pdf.

Enjoy!




Previous Years Pumpkin Templates

Click to see these lit up!
Despical Me:



Click to see this one lit up!
Man of Steel (See this post for more details)





Tuesday, April 29, 2014

Backreferences Visual Studio Find/Replace regex

Here's another post of soemthing nifty that I want to remember later.

In Unity, I was getting an error: "CompareBaseObjectsInternal can only be called from the main thread"

It turned out, if you try to do  something of the form
 if( instance == null)  
in anything that isn't the main thread (or called by the main thread) you get an error because unity implements its own comparison operation that is not thread safe (and not documented anywhere.)

 The solution, which is pointed out elsewhere was to use C#'s Object.Reference.Equals function. Instead of going through every file (at this point, there's around 100 source files), I did a find and replace with regex.

I always seem to forget about backreferences (hence this post).

I needed to find every instance of  if( instance == null ) and replace it with if( ReferenceEquals(instance,null)) but for any variable name. Backreferences  in regular expressions seek to let you do just that.

My find string was this:

 if[^\S\r\n]*([^\S\r\n]*(?<var>.*)[^\S\r\n]*==[^\S\r\n]*null[^\S\r\n]*)  

ignoring all the whitespace chars, the string is this

 if ( (?<var>.*) == null )  

which basically says to save any string of characters into a backreference named 'var'

My replace string:
 if( ReferenceEquals(${var}, null) )  

then uses that backreference.

Find and Replacing in files found 75 instances where I had compared a variable (or some reference) directly to null. I did scroll through the whole list first, before I actually allowed it to replace.

Annoying problem, simple solution.


Friday, June 14, 2013

Network Connection between Unity 3.x and Unity 4.x

It can be done!
The trick is that both scenes need to have a network view with the same view ID. I can't figure out how to manually change the view ID since it is greyed out, but creating new network views changes the ID and once they match, it will work.

That's all. I'm just posting this to remember it later

Tuesday, October 30, 2012

Pumpkin Carving 2012, Man Of Steel

This year, my wife was out of town the Friday before Halloween. I put on Prometheus (and then Dune,and then Iron Man 2) and designed and carved a pumpkin.

I was inspired by this neat pumpkin I saw on imgur here. The premise was simple, just a silhouette of Batman with a glowing background. I wanted to use the same premise with a different superhero. Since very few superheroes have a distinct silhouette, I decided to do Superman with a lit up cape and lit up chest logo, on a glowing background.

Here's a link to the pdf pattern that I made in inkscape.

I originally made the pattern for the ThinkGeek pumpkin carving contest but after spending so long on the design, I really wanted to carve it.

After staying up late and many hours of painstaking scraping and gouging, here's my result.

Lit up with a lamp, inside, lights on.

Lit with lamp, lights off!

I was really happy with the end result. I spent a lot of time gouging the cape so that it would actually look 3D, like it was fluttering in the wind and I think it turned out well.
I'd love some constructive feedback!


Friday, October 12, 2012

Unity3d, Rotate around axis glitch with scale

For the record, Let me state that I'm posting this solely because I spent a LONG (2+wks) time debugging this problem and finally figured out what is going on. I've submitted a bug report to Unity3d, but in reality, I'm not entirely sure it's a glitch, because I can't figure out the expected behavior, and the Unity3d Rotate documentation is worthless.




This is my scenario, and I make no claims that this is the same for other situations:

I have a game object that is scaled to be -1, 1, 1 ( basically to mirror a model.) Inside of that object I have some child objects in a hierarchy :  Parent -> Child1 -> Child2.  Parent has a behavior script on it that uses both children. The goal is to make a non-trivial axis from the center of Child1 and rotate around that axis. Child2 should follow since of the hierarchy. The problem is that with the object scaled to -1 in the x direction, the rotation  doesn't work around the correct axis.


Here's the example. On the right side of the screen, there's the object with normal (1,1,1) scaling. The yellow debug line represents the rotation axis and the blue lines represent rotating the red sphere around that line (36 times, at 10degree intervals). As expected, the cone of lines has the axis in the center.

On the left side of the screen is the same object,but with scaling of (-1,1,1). With this scaling, the cone is clearly not along the axis. Now, in this case it's pretty clear that the cone is not around the axis, but in my actual project, the axis was nearly vertical, so instead of being way off, it was just slightly off and hard to debug.

Anyway, after some quick math and toying around, I decided to add a new debug line, that is the same axis but with scaling of (-1,1,1) applied to it. Here's the picture with that line turned on as well (in purple).


Visually the purple line seems to be correct on the left and the yellow line is correct on the right (and in my actual project I have means to verify it's exactly correct, not just visually.)


Here's some code:


void Start () {
   rotAxis = new Vector3(1,.5f,0);
            rotAxis.Normalize();
}
void Update () {
 shoulder.transform.rotation = Quaternion.identity;
        Debug.DrawLine(shoulder.transform.position, shoulder.transform.position + 11 * rotAxis, Color.yellow);

   for (int i = 0; i < 36; i++)
   {
       shoulder.transform.Rotate(rotAxis,10);
            Debug.DrawLine(shoulder.transform.position, elbow.transform.position, Color.blue);
   }

            Debug.DrawLine(shoulder.transform.position, shoulder.transform.position + new Vector3(-11 * rotAxis[0], 11 * rotAxis[1], 11 * rotAxis[2]), Color.magenta);
}



Basically I'm using Transform.rotate(axis, angle). So it seems to me, moral of the story is that if your parent object has scaling,  you need to apply the same scaling to a rotation axis. I'm not entirely sure what you should do if multiple parents have scaling, but my guess is that you'd have to apply all of those scalings, but that's my guess.

Anyway, I'm posting this just so I can find this again, and in case anyone else has the issue.

If you want to play with my example, here's the scene
RotateGlitch.zip
If you open the project and click play, it runs with the yellow line displayed, when you hit spacebar it also shows the purple scene.

Thursday, September 15, 2011

New Decor: 20$ Wall Art


Disclaimer: I've been trying to figure out how to write up this post for awhile because the wall art I made is heavily based on another person's work. I've decided that the best thing to do is be completely open about it and if the original artist wants me to take this down, then I will.  For the record, I'm okay with this post because I'm not ever intending to sale the wall art, its strictly for personal use.

I've been trying to find something to put over the couch for awhile. Our living room is very brown so I wanted some color. After browsing on Art.com I found this set and really liked it, but I just can't afford to spend 150$ on art right now. I had an idea to recreate this art with simple materials and cheaply.


I had this idea to cut some 12x12 wooden squares, paint them in fall colors, and then cut out standard white printer paper and  glue those on the wood, which is exactly what I did. I bought a four foot long 1x12 piece of wood and cut it into four equal pieces. I painted them with some acrylic paint, which surprisingly let the wood grain show through a little bit. After this dried I was a little disappointed with the colors, because they turned out a lot brighter than I hoped. I picked up an antiquing glaze at Lowe's and applied it to the wood. This stuff was magic. It rubs on as this dark green black oil but then when you wipe it off it leaves your colors looking aged. I started with the yellow board and almost was a bit worried when it was black green before I rubbed it out.  Once I wiped it off though, I really liked the look.


  
Before glaze, too bright    After glaze, much better!


For the silhouettes I made a pattern on the computer, printed it out and cut it out with an Xacto knife.  My plan was to use spray adhesive on the cutouts and then somehow get them to the wood and glue them on. I didn't have a solid plan here but accidentally discovered a neat method.  I had put the cutouts on some old cardstock before I sprayed the adhesive. Interestingly enough, the overspray was enough to hold the cutouts to the cardstock, which allowed me to easily transfer the cutout to the wood by just putting the cardstock on the wood, applying a little pressure and removing the cardstock. I'm pretty happy with the results.
After spraying with spray adhesive
I ended up hanging these with picture frame hanging wire. I just wrapped the wire around a machine screw, twisted it around, and then screwed in the screw. I did the same thing for the other side, screwing it in when the wire was pretty tight.  Here's a couple pictures of the process.





I hung these using a level and some nails and I love the result.  I really liked the final result and I'm keeping this idea around for future projects. 

Until next time, keep having fun!